buildMissedTaskNotification function
Build the missed-task notification text.
Implementation
String buildMissedTaskNotification(List<CronTask> missed) {
final plural = missed.length > 1;
final header =
'The following one-shot scheduled task${plural ? 's were' : ' was'} '
'missed while Neomage was not running. '
'${plural ? 'They have' : 'It has'} already been removed from '
'.neomage/scheduled_tasks.json.\n\n'
'Do NOT execute ${plural ? 'these prompts' : 'this prompt'} yet. '
'First use the AskUserQuestion tool to ask whether to run '
'${plural ? 'each one' : 'it'} now. '
'Only execute if the user confirms.';
final blocks = missed.map((t) {
final meta =
'[${cronToHuman(t.cron)}, created ${DateTime.fromMillisecondsSinceEpoch(t.createdAt)}]';
// Use a fence one longer than any backtick run in the prompt.
final longestRun = RegExp(r'`+')
.allMatches(t.prompt)
.fold(0, (maxVal, match) => max(maxVal, match.group(0)!.length));
final fence = '`' * max(3, longestRun + 1);
return '$meta\n$fence\n${t.prompt}\n$fence';
}).toList();
return '$header\n\n${blocks.join('\n\n')}';
}