(params: {
basePrompt: string
trigger: AutonomyTriggerKind
rootDir?: string
currentDir?: string
nowMs?: number
})
| 474 | } |
| 475 | |
| 476 | export async function prepareAutonomyTurnPrompt(params: { |
| 477 | basePrompt: string |
| 478 | trigger: AutonomyTriggerKind |
| 479 | rootDir?: string |
| 480 | currentDir?: string |
| 481 | nowMs?: number |
| 482 | }): Promise<PreparedAutonomyTurn> { |
| 483 | const snapshot = await loadAutonomyAuthority({ |
| 484 | rootDir: params.rootDir, |
| 485 | currentDir: params.currentDir, |
| 486 | }) |
| 487 | const nowMs = params.nowMs ?? Date.now() |
| 488 | const dueHeartbeatTasks = |
| 489 | params.trigger === 'proactive-tick' |
| 490 | ? collectDueHeartbeatTasks(snapshot, nowMs) |
| 491 | : [] |
| 492 | const duePromptTasks = dueHeartbeatTasks.filter( |
| 493 | task => task.steps.length === 0, |
| 494 | ) |
| 495 | |
| 496 | const sections: string[] = [] |
| 497 | if (snapshot.agentsContent) { |
| 498 | sections.push( |
| 499 | `Workspace authority from ${AUTONOMY_AGENTS_FILENAME}:\n${snapshot.agentsContent}`, |
| 500 | ) |
| 501 | } |
| 502 | if (snapshot.heartbeatContent) { |
| 503 | sections.push( |
| 504 | `Workspace heartbeat guidance from ${AUTONOMY_HEARTBEAT_FILENAME}:\n${snapshot.heartbeatContent}`, |
| 505 | ) |
| 506 | } |
| 507 | if (duePromptTasks.length > 0) { |
| 508 | sections.push( |
| 509 | [ |
| 510 | `Due ${AUTONOMY_HEARTBEAT_FILENAME} tasks:`, |
| 511 | ...duePromptTasks.map( |
| 512 | task => `- ${task.name} (${task.interval}): ${task.prompt}`, |
| 513 | ), |
| 514 | ].join('\n'), |
| 515 | ) |
| 516 | } |
| 517 | |
| 518 | if (sections.length === 0) { |
| 519 | return { |
| 520 | rootDir: snapshot.rootDir, |
| 521 | currentDir: snapshot.currentDir, |
| 522 | trigger: params.trigger, |
| 523 | prompt: params.basePrompt, |
| 524 | dueHeartbeatTasks, |
| 525 | nowMs, |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | const prelude = |
| 530 | params.trigger === 'proactive-tick' |
| 531 | ? 'This is an autonomous proactive turn. Follow the workspace authority below before acting.' |
| 532 | : 'This prompt was generated automatically. Follow the workspace authority below before acting.' |
| 533 |
no test coverage detected