(jobRecord: {
id: string
jobTitle: string | null
prompt: string | null
lifecycle: string
successCondition: string | null
runCount: number
maxRuns: number | null
sourceTaskName: string | null
sourceChatId: string | null
jobHistory: Array<{ timestamp: string; summary: string }> | null
})
| 986 | } |
| 987 | |
| 988 | function buildJobPrompt(jobRecord: { |
| 989 | id: string |
| 990 | jobTitle: string | null |
| 991 | prompt: string | null |
| 992 | lifecycle: string |
| 993 | successCondition: string | null |
| 994 | runCount: number |
| 995 | maxRuns: number | null |
| 996 | sourceTaskName: string | null |
| 997 | sourceChatId: string | null |
| 998 | jobHistory: Array<{ timestamp: string; summary: string }> | null |
| 999 | }): string { |
| 1000 | const parts: string[] = [] |
| 1001 | |
| 1002 | parts.push('--- JOB EXECUTION ---') |
| 1003 | parts.push(`Job ID: ${jobRecord.id}`) |
| 1004 | if (jobRecord.jobTitle) parts.push(`Title: ${jobRecord.jobTitle}`) |
| 1005 | |
| 1006 | if (jobRecord.lifecycle === 'until_complete') { |
| 1007 | parts.push(`Lifecycle: until_complete`) |
| 1008 | if (jobRecord.successCondition) { |
| 1009 | parts.push(`Success Condition: ${jobRecord.successCondition}`) |
| 1010 | } |
| 1011 | const runDisplay = jobRecord.maxRuns |
| 1012 | ? `${jobRecord.runCount + 1} / ${jobRecord.maxRuns}` |
| 1013 | : `${jobRecord.runCount + 1}` |
| 1014 | parts.push(`Run: ${runDisplay}`) |
| 1015 | } |
| 1016 | |
| 1017 | parts.push('') |
| 1018 | parts.push('TASK:') |
| 1019 | parts.push(jobRecord.prompt || '') |
| 1020 | |
| 1021 | if (jobRecord.sourceTaskName) { |
| 1022 | parts.push('') |
| 1023 | parts.push(`RELATED TASK: ${jobRecord.sourceTaskName}`) |
| 1024 | } |
| 1025 | |
| 1026 | if (jobRecord.sourceChatId) { |
| 1027 | parts.push("Read the task's session.md in the VFS for conversation context.") |
| 1028 | } |
| 1029 | |
| 1030 | if (jobRecord.jobHistory && jobRecord.jobHistory.length > 0) { |
| 1031 | parts.push('') |
| 1032 | parts.push('PREVIOUS RUN HISTORY (for idempotency -- do NOT reprocess items already handled):') |
| 1033 | const recentHistory = jobRecord.jobHistory.slice(-10) |
| 1034 | for (const entry of recentHistory) { |
| 1035 | parts.push(`- [${entry.timestamp}] ${entry.summary}`) |
| 1036 | } |
| 1037 | parts.push('') |
| 1038 | parts.push( |
| 1039 | 'Use this history to avoid duplicate work. After completing meaningful work this run, call update_scheduled_task_history to record what you did.' |
| 1040 | ) |
| 1041 | } else if (jobRecord.runCount > 0) { |
| 1042 | parts.push('') |
| 1043 | parts.push( |
| 1044 | 'No previous run history recorded. After completing meaningful work, call update_scheduled_task_history to record what you did for future runs.' |
| 1045 | ) |
no test coverage detected