@code-yeongyu/senpi 2026.8.9 → 2026.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/core/agent-session.d.ts +4 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +19 -2
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/extensions/builtin/cache-keepalive/index.d.ts +30 -0
  7. package/dist/core/extensions/builtin/cache-keepalive/index.d.ts.map +1 -0
  8. package/dist/core/extensions/builtin/cache-keepalive/index.js +281 -0
  9. package/dist/core/extensions/builtin/cache-keepalive/index.js.map +1 -0
  10. package/dist/core/extensions/builtin/compaction/index.js +9 -9
  11. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  12. package/dist/core/extensions/builtin/goal/cache-warm-renderer.d.ts.map +1 -1
  13. package/dist/core/extensions/builtin/goal/cache-warm-renderer.js +21 -8
  14. package/dist/core/extensions/builtin/goal/cache-warm-renderer.js.map +1 -1
  15. package/dist/core/extensions/builtin/goal/cache-warm.d.ts +11 -2
  16. package/dist/core/extensions/builtin/goal/cache-warm.d.ts.map +1 -1
  17. package/dist/core/extensions/builtin/goal/cache-warm.js +16 -0
  18. package/dist/core/extensions/builtin/goal/cache-warm.js.map +1 -1
  19. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  20. package/dist/core/extensions/builtin/goal/index.js +31 -1
  21. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  22. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +2 -1
  23. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
  24. package/dist/core/extensions/builtin/goal/monitor-continuation.js +115 -54
  25. package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
  26. package/dist/core/extensions/builtin/goal/prompt.d.ts.map +1 -1
  27. package/dist/core/extensions/builtin/goal/prompt.js +4 -4
  28. package/dist/core/extensions/builtin/goal/prompt.js.map +1 -1
  29. package/dist/core/extensions/builtin/goal/store-changed-event.d.ts +8 -0
  30. package/dist/core/extensions/builtin/goal/store-changed-event.d.ts.map +1 -0
  31. package/dist/core/extensions/builtin/goal/store-changed-event.js +9 -0
  32. package/dist/core/extensions/builtin/goal/store-changed-event.js.map +1 -0
  33. package/dist/core/extensions/builtin/goal/wait-progress.js +5 -5
  34. package/dist/core/extensions/builtin/goal/wait-progress.js.map +1 -1
  35. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  36. package/dist/core/extensions/builtin/index.js +2 -0
  37. package/dist/core/extensions/builtin/index.js.map +1 -1
  38. package/dist/core/extensions/builtin/monitor-state-event.d.ts +16 -0
  39. package/dist/core/extensions/builtin/monitor-state-event.d.ts.map +1 -1
  40. package/dist/core/extensions/builtin/monitor-state-event.js +15 -0
  41. package/dist/core/extensions/builtin/monitor-state-event.js.map +1 -1
  42. package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
  43. package/dist/core/extensions/builtin/terminal/extension.js +7 -8
  44. package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
  45. package/dist/core/extensions/builtin/terminal/session-bundle.d.ts +3 -3
  46. package/dist/core/extensions/builtin/terminal/session-bundle.d.ts.map +1 -1
  47. package/dist/core/extensions/builtin/terminal/session-bundle.js.map +1 -1
  48. package/dist/core/extensions/index.d.ts +1 -1
  49. package/dist/core/extensions/index.d.ts.map +1 -1
  50. package/dist/core/extensions/index.js.map +1 -1
  51. package/dist/core/extensions/loader.d.ts.map +1 -1
  52. package/dist/core/extensions/loader.js +7 -0
  53. package/dist/core/extensions/loader.js.map +1 -1
  54. package/dist/core/extensions/runner.d.ts +4 -0
  55. package/dist/core/extensions/runner.d.ts.map +1 -1
  56. package/dist/core/extensions/runner.js +19 -2
  57. package/dist/core/extensions/runner.js.map +1 -1
  58. package/dist/core/extensions/types.d.ts +50 -0
  59. package/dist/core/extensions/types.d.ts.map +1 -1
  60. package/dist/core/extensions/types.js.map +1 -1
  61. package/dist/core/omo-native-detect.d.ts +1 -1
  62. package/dist/core/omo-native-detect.d.ts.map +1 -1
  63. package/dist/core/omo-native-detect.js +7 -1
  64. package/dist/core/omo-native-detect.js.map +1 -1
  65. package/dist/core/omo-native-detect.test.d.ts +2 -0
  66. package/dist/core/omo-native-detect.test.d.ts.map +1 -0
  67. package/dist/core/omo-native-detect.test.js +47 -0
  68. package/dist/core/omo-native-detect.test.js.map +1 -0
  69. package/dist/core/resource-loader.d.ts +4 -0
  70. package/dist/core/resource-loader.d.ts.map +1 -1
  71. package/dist/core/resource-loader.js +6 -0
  72. package/dist/core/resource-loader.js.map +1 -1
  73. package/dist/core/session-manager.d.ts +1 -1
  74. package/dist/core/session-manager.d.ts.map +1 -1
  75. package/dist/core/session-manager.js.map +1 -1
  76. package/dist/core/settings-manager.d.ts +10 -0
  77. package/dist/core/settings-manager.d.ts.map +1 -1
  78. package/dist/core/settings-manager.js +14 -0
  79. package/dist/core/settings-manager.js.map +1 -1
  80. package/dist/core/tools/edit.d.ts +3 -1
  81. package/dist/core/tools/edit.d.ts.map +1 -1
  82. package/dist/core/tools/edit.js +12 -0
  83. package/dist/core/tools/edit.js.map +1 -1
  84. package/dist/core/tools/filesystem-policy.d.ts +10 -0
  85. package/dist/core/tools/filesystem-policy.d.ts.map +1 -0
  86. package/dist/core/tools/filesystem-policy.js +59 -0
  87. package/dist/core/tools/filesystem-policy.js.map +1 -0
  88. package/dist/core/tools/find.d.ts +3 -1
  89. package/dist/core/tools/find.d.ts.map +1 -1
  90. package/dist/core/tools/find.js +15 -0
  91. package/dist/core/tools/find.js.map +1 -1
  92. package/dist/core/tools/grep.d.ts +3 -1
  93. package/dist/core/tools/grep.d.ts.map +1 -1
  94. package/dist/core/tools/grep.js +16 -1
  95. package/dist/core/tools/grep.js.map +1 -1
  96. package/dist/core/tools/ls.d.ts +3 -1
  97. package/dist/core/tools/ls.d.ts.map +1 -1
  98. package/dist/core/tools/ls.js +11 -0
  99. package/dist/core/tools/ls.js.map +1 -1
  100. package/dist/core/tools/read.d.ts +3 -1
  101. package/dist/core/tools/read.d.ts.map +1 -1
  102. package/dist/core/tools/read.js +13 -0
  103. package/dist/core/tools/read.js.map +1 -1
  104. package/dist/core/tools/write.d.ts +3 -1
  105. package/dist/core/tools/write.d.ts.map +1 -1
  106. package/dist/core/tools/write.js +12 -0
  107. package/dist/core/tools/write.js.map +1 -1
  108. package/dist/index.d.ts +1 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js.map +1 -1
  111. package/dist/modes/app-server/threads/goal-handlers.d.ts.map +1 -1
  112. package/dist/modes/app-server/threads/goal-handlers.js +7 -0
  113. package/dist/modes/app-server/threads/goal-handlers.js.map +1 -1
  114. package/dist/modes/interactive/components/footer-omo-native-badge.test.d.ts +2 -0
  115. package/dist/modes/interactive/components/footer-omo-native-badge.test.d.ts.map +1 -0
  116. package/dist/modes/interactive/components/footer-omo-native-badge.test.js +52 -0
  117. package/dist/modes/interactive/components/footer-omo-native-badge.test.js.map +1 -0
  118. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  119. package/dist/modes/interactive/components/footer.js +3 -1
  120. package/dist/modes/interactive/components/footer.js.map +1 -1
  121. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  122. package/dist/modes/interactive/interactive-mode.js +1 -0
  123. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  124. package/docs/extensions.md +76 -0
  125. package/docs/providers.md +23 -3
  126. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +26 -0
  127. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  128. package/node_modules/@code-yeongyu/senpi-codemode/src/extension/{resumption-channel.ts → wake-source-state.ts} +9 -9
  129. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +7 -7
  130. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +12 -11
  131. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  132. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts +3 -1
  133. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  134. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +13 -0
  135. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  136. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  137. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +6 -3
  138. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
  139. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
  140. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +6 -2
  141. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  142. package/node_modules/@earendil-works/pi-ai/dist/api/warm-prompt-cache.d.ts +17 -0
  143. package/node_modules/@earendil-works/pi-ai/dist/api/warm-prompt-cache.d.ts.map +1 -0
  144. package/node_modules/@earendil-works/pi-ai/dist/api/warm-prompt-cache.js +52 -0
  145. package/node_modules/@earendil-works/pi-ai/dist/api/warm-prompt-cache.js.map +1 -0
  146. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -1
  147. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  148. package/node_modules/@earendil-works/pi-ai/dist/index.js +2 -1
  149. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  150. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  151. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  152. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
  153. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  154. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  155. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  156. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/recovery-stream.d.ts.map +1 -1
  157. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/recovery-stream.js +120 -1
  158. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/recovery-stream.js.map +1 -1
  159. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +2 -0
  160. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  161. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  162. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.d.ts +3 -1
  163. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
  164. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js +17 -3
  165. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js.map +1 -1
  166. package/node_modules/@earendil-works/pi-ai/package.json +1 -1
  167. package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
  168. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  169. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  170. package/package.json +6 -6
  171. package/dist/core/extensions/builtin/resumption-channel-event.d.ts +0 -13
  172. package/dist/core/extensions/builtin/resumption-channel-event.d.ts.map +0 -1
  173. package/dist/core/extensions/builtin/resumption-channel-event.js +0 -13
  174. package/dist/core/extensions/builtin/resumption-channel-event.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,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-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { continueGoalAfterAgentEnd } from \"./agent-end-continuation.ts\";\nimport { GOAL_CACHE_WARMUP_ENTRY_TYPE } from \"./cache-warm.ts\";\nimport { renderGoalCacheWarmupEntry } from \"./cache-warm-renderer.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { GOAL_CONTINUATION_CAP } from \"./continuation.ts\";\nimport { continuationCapRecoveryHint, PROVIDER_ERROR_BLOCKED_REASON } from \"./continuation-recovery.ts\";\nimport { GoalDirectInputLifecycle } from \"./direct-input-lifecycle.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { isResumeOfStoppedGoal, queueGoalContinuation } from \"./lifecycle-helpers.ts\";\nimport { MonitorAwareGoalContinuation } from \"./monitor-continuation.ts\";\nimport { migrateLegacyGoalFile } from \"./persistence.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { goalStoreRef as buildGoalStoreRef } from \"./store-ref.ts\";\nimport { didTerminalProviderErrorEndTurn } from \"./terminal-provider-error.ts\";\nimport { staleGoalTodoReminder, todoResultAddsOpenTasks } from \"./todo-gate.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport { TurnUsageTracker } from \"./turn-usage.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\nimport { GOAL_WAIT_STATUS_KEY, GoalWaitTicker } from \"./wait-ticker.ts\";\n\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_STOPPED_CHOICE = \"Leave stopped\";\nconst STALE_EXTENSION_CONTEXT_ERROR_PREFIX = \"This extension ctx is stale after session replacement or reload.\";\n\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet staleGoalReminderSentThisTurn = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet blockedThisTurnGoalId: string | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\tlet continuationPending = false;\n\tconst turnUsage = new TurnUsageTracker();\n\tconst goalWaitTicker = new GoalWaitTicker({\n\t\trender: (renderCtx, status) => {\n\t\t\ttry {\n\t\t\t\trenderCtx.ui.setStatus(GOAL_WAIT_STATUS_KEY, status);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\tconst monitorContinuation = new MonitorAwareGoalContinuation(\n\t\tpi,\n\t\t() => continuationPending,\n\t\t() => {\n\t\t\tcontinuationPending = true;\n\t\t},\n\t\tgoalWaitTicker,\n\t);\n\tconst directInputLifecycle = new GoalDirectInputLifecycle({\n\t\tmonitor: monitorContinuation,\n\t\tgoalStoreRef,\n\t\tbeginAgentGoalAccounting,\n\t\trefreshGoalUi: refreshGoalUiBestEffort,\n\t});\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => {\n\t\t\ttry {\n\t\t\t\tupdateGoalUi(renderCtx, renderGoal, live);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry);\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting: (goal) => {\n\t\t\tmonitorContinuation.noteContinuationStarted();\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t},\n\t\tmarkGoalBlockedThisTurn,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation: (extensionApi, commandCtx, goal) => {\n\t\t\tvoid queueGoalContinuationForCurrentSession(extensionApi, commandCtx, goal);\n\t\t},\n\t\trefreshGoalUi,\n\t});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tmonitorContinuation.start(ctx);\n\t\tdirectInputLifecycle.reset();\n\t\tconst ref = goalStoreRef(ctx);\n\t\tawait migrateLegacyGoalFile(ref);\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumeStoppedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\t// A config reload must not auto-start an agent that was stopped. Only a fresh\n\t\t// startup or explicit resume may re-engage an active goal via a continuation.\n\t\tif (goal && event.reason !== \"reload\") {\n\t\t\t// Migration-lite admission: a resumed session carrying a trailing flood of\n\t\t\t// historical continuations must not reignite on load. Skip the auto-queue,\n\t\t\t// leave the goal active (no status rewrite), and tell the user how to resume.\n\t\t\tconst trailingContinuations = countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch());\n\t\t\tif (trailingContinuations >= GOAL_CONTINUATION_CAP) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal auto-continuation suppressed for this resumed session (${trailingContinuations} historical continuations). Send a message to resume.`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t\t}\n\t\t}\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onInput(event, ctx);\n\t});\n\n\tpi.on(\"input_disposition\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onDisposition(event, ctx);\n\t});\n\n\tpi.on(\"turn_start\", async () => {\n\t\tstaleGoalReminderSentThisTurn = false;\n\t});\n\n\t// When the model starts tracking new open todo work while the thread has no\n\t// goal (or only a stale, already-complete one), append a system reminder to\n\t// the todo result so the model registers the goal when the work warrants it.\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tif (event.toolName !== \"todo\" || event.isError || staleGoalReminderSentThisTurn) return undefined;\n\t\tif (!todoResultAddsOpenTasks(event.details)) return undefined;\n\t\tconst reminder = staleGoalTodoReminder(await readGoal(goalStoreRef(ctx)));\n\t\tif (reminder === undefined) return undefined;\n\t\tstaleGoalReminderSentThisTurn = true;\n\t\treturn { content: [...event.content, { type: \"text\" as const, text: reminder }] };\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst continuationStarted = continuationPending;\n\t\tcontinuationPending = false;\n\t\tif (continuationStarted) monitorContinuation.noteContinuationStarted();\n\t\tagentTurnInProgress = true;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tturnUsage.reset();\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"message_end\", async (event) => {\n\t\tturnUsage.noteMessageEnd(event.message);\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode =\n\t\t\tblockedThisTurnGoalId !== null\n\t\t\t\t? \"activeOrBlocked\"\n\t\t\t\t: completedThisTurnGoalId === null\n\t\t\t\t\t? \"active\"\n\t\t\t\t\t: \"activeOrComplete\";\n\t\tlet goal = await accountCurrentAgentTurn(ctx, mode, event.messages);\n\t\tagentTurnInProgress = false;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (event.aborted === true && event.abortSource === \"user\" && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t} else if (didTerminalProviderErrorEndTurn(event) && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: PROVIDER_ERROR_BLOCKED_REASON },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tif (ctx.hasUI) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}\\n${continuationCapRecoveryHint(PROVIDER_ERROR_BLOCKED_REASON)}`,\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tconst continuationGoal = await continueGoalAfterAgentEnd(monitorContinuation, { ctx, event, goal });\n\t\tif (continuationGoal !== goal) {\n\t\t\tgoal = continuationGoal;\n\t\t\tsyncContinuationGoal(ctx, goal);\n\t\t}\n\t});\n\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tconst goal = await monitorContinuation.afterAgentSettled();\n\t\tif (goal !== undefined) syncContinuationGoal(ctx, goal);\n\t});\n\n\tpi.on(\"session_abort\", async (_event, ctx) => {\n\t\tcontinuationPending = false;\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status !== \"active\") return;\n\t\tconst accounted = await accountCurrentAgentTurn(ctx, \"active\");\n\t\tif (accounted?.status === \"active\") {\n\t\t\tconst blocked = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, blocked);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t\tmonitorContinuation.dispose();\n\t});\n\n\tasync function maybePromptResumeStoppedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfStoppedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume ${goal.status} goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_STOPPED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" }, \"user\");\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tasync function queueGoalContinuationForCurrentSession(\n\t\textensionApi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tgoal: Goal,\n\t): Promise<void> {\n\t\tconst continuedGoal = await queueGoalContinuation(extensionApi, ctx, goal, {\n\t\t\tcontinuationPending,\n\t\t\tmarkContinuationPending: () => {\n\t\t\t\tcontinuationPending = true;\n\t\t\t},\n\t\t});\n\t\tif (continuedGoal.status === goal.status) return;\n\t\tif (continuedGoal.status === \"active\") beginAgentGoalAccounting(continuedGoal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, continuedGoal);\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tturnUsage.discardPending();\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalBlockedThisTurn(goal: Goal): void {\n\t\tif (agentTurnInProgress) blockedThisTurnGoalId = goal.id;\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (blockedThisTurnGoalId === goalId) {\n\t\t\tblockedThisTurnGoalId = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction syncContinuationGoal(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tif (goal?.status === \"active\") beginAgentGoalAccounting(goal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tmonitorContinuation.syncGoal(goal);\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tmode: GoalAccountingMode,\n\t\tagentRunMessages?: unknown[],\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst usage =\n\t\t\tagentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\n/**\n * Counts goal-continuation entries queued since the most recent real user message\n * in the current branch (mirrors the todo-gate / todo-bridge backward branch read).\n * A real user message is the only reset: the assistant turns in between are exactly\n * the unattended loop this admission guard exists to stop.\n */\nfunction countTrailingGoalContinuationEntries(entries: readonly SessionEntry[]): number {\n\tlet count = 0;\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type === \"message\" && entry.message.role === \"user\") break;\n\t\tif (entry?.type === \"custom_message\" && entry.customType === GOAL_CONTINUATION_MESSAGE_TYPE) count += 1;\n\t}\n\treturn count;\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\treturn buildGoalStoreRef(ctx.sessionManager, ctx.cwd);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AACxG,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,iCAAiC,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B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AC;QAC7B,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM;QACtE,IAAI,KAAK,EAAE,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,UAAU,KAAK,8BAA8B;YAAE,KAAK,IAAI,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,GAAqB;IAC1C,OAAO,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { GOAL_CONTINUATION_MESSAGE_TYPE } from \"../../../messages.ts\";\nimport type { SessionEntry } from \"../../../session-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { continueGoalAfterAgentEnd } from \"./agent-end-continuation.ts\";\nimport { GOAL_CACHE_WARMUP_ENTRY_TYPE } from \"./cache-warm.ts\";\nimport { renderGoalCacheWarmupEntry } from \"./cache-warm-renderer.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { GOAL_CONTINUATION_CAP } from \"./continuation.ts\";\nimport { continuationCapRecoveryHint, PROVIDER_ERROR_BLOCKED_REASON } from \"./continuation-recovery.ts\";\nimport { GoalDirectInputLifecycle } from \"./direct-input-lifecycle.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { isResumeOfStoppedGoal, queueGoalContinuation } from \"./lifecycle-helpers.ts\";\nimport { GOAL_CONTINUATION_SCHEDULED_EVENT, MonitorAwareGoalContinuation } from \"./monitor-continuation.ts\";\nimport { migrateLegacyGoalFile } from \"./persistence.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { GOAL_STORE_CHANGED_EVENT, isGoalStoreChangedEvent } from \"./store-changed-event.ts\";\nimport { goalStoreRef as buildGoalStoreRef } from \"./store-ref.ts\";\nimport { didTerminalProviderErrorEndTurn } from \"./terminal-provider-error.ts\";\nimport { staleGoalTodoReminder, todoResultAddsOpenTasks } from \"./todo-gate.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport { TurnUsageTracker } from \"./turn-usage.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\nimport { GOAL_WAIT_STATUS_KEY, GoalWaitTicker } from \"./wait-ticker.ts\";\n\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_STOPPED_CHOICE = \"Leave stopped\";\nconst STALE_EXTENSION_CONTEXT_ERROR_PREFIX = \"This extension ctx is stale after session replacement or reload.\";\n\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet staleGoalReminderSentThisTurn = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet blockedThisTurnGoalId: string | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\tlet continuationPending = false;\n\tlet activeContext: ExtensionContext | undefined;\n\tconst turnUsage = new TurnUsageTracker();\n\tconst goalWaitTicker = new GoalWaitTicker({\n\t\trender: (renderCtx, status) => {\n\t\t\ttry {\n\t\t\t\trenderCtx.ui.setStatus(GOAL_WAIT_STATUS_KEY, status);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\tconst monitorContinuation = new MonitorAwareGoalContinuation(\n\t\tpi,\n\t\t() => continuationPending,\n\t\t() => {\n\t\t\tcontinuationPending = true;\n\t\t},\n\t\tgoalWaitTicker,\n\t);\n\tconst directInputLifecycle = new GoalDirectInputLifecycle({\n\t\tmonitor: monitorContinuation,\n\t\tgoalStoreRef,\n\t\tbeginAgentGoalAccounting,\n\t\trefreshGoalUi: refreshGoalUiBestEffort,\n\t});\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => {\n\t\t\ttry {\n\t\t\t\tupdateGoalUi(renderCtx, renderGoal, live);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry);\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting: (goal) => {\n\t\t\tmonitorContinuation.noteContinuationStarted();\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t},\n\t\tmarkGoalBlockedThisTurn,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation: (extensionApi, commandCtx, goal) => {\n\t\t\tvoid queueGoalContinuationForCurrentSession(extensionApi, commandCtx, goal);\n\t\t},\n\t\trefreshGoalUi,\n\t});\n\n\tconst unsubscribeGoalStoreChanged =\n\t\tpi.events?.on(GOAL_STORE_CHANGED_EVENT, async (data) => {\n\t\t\tif (!isGoalStoreChangedEvent(data)) return;\n\t\t\tconst ctx = data.ctx ?? activeContext;\n\t\t\tif (\n\t\t\t\tctx === undefined ||\n\t\t\t\tctx.sessionManager.getSessionId() !== data.threadId ||\n\t\t\t\t!ctx.isIdle() ||\n\t\t\t\tctx.hasPendingMessages()\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\t\tif (goal?.status !== \"active\") return;\n\t\t\tmonitorContinuation.syncGoal(goal);\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\t\tpi.events?.emit(GOAL_CONTINUATION_SCHEDULED_EVENT, {\n\t\t\t\tgoalId: goal.id,\n\t\t\t\tdelayMs: 0,\n\t\t\t\tactiveMonitorCount: 0,\n\t\t\t\twakeSources: {},\n\t\t\t\treason: GOAL_STORE_CHANGED_EVENT,\n\t\t\t});\n\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t}) ?? (() => {});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tactiveContext = ctx;\n\t\tmonitorContinuation.start(ctx);\n\t\tdirectInputLifecycle.reset();\n\t\tconst ref = goalStoreRef(ctx);\n\t\tawait migrateLegacyGoalFile(ref);\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumeStoppedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\t// A config reload must not auto-start an agent that was stopped. Only a fresh\n\t\t// startup or explicit resume may re-engage an active goal via a continuation.\n\t\tif (goal && event.reason !== \"reload\") {\n\t\t\t// Migration-lite admission: a resumed session carrying a trailing flood of\n\t\t\t// historical continuations must not reignite on load. Skip the auto-queue,\n\t\t\t// leave the goal active (no status rewrite), and tell the user how to resume.\n\t\t\tconst trailingContinuations = countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch());\n\t\t\tif (trailingContinuations >= GOAL_CONTINUATION_CAP) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal auto-continuation suppressed for this resumed session (${trailingContinuations} historical continuations). Send a message to resume.`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t\t}\n\t\t}\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onInput(event, ctx);\n\t});\n\n\tpi.on(\"input_disposition\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onDisposition(event, ctx);\n\t});\n\n\tpi.on(\"turn_start\", async () => {\n\t\tstaleGoalReminderSentThisTurn = false;\n\t});\n\n\t// When the model starts tracking new open todo work while the thread has no\n\t// goal (or only a stale, already-complete one), append a system reminder to\n\t// the todo result so the model registers the goal when the work warrants it.\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tif (event.toolName !== \"todo\" || event.isError || staleGoalReminderSentThisTurn) return undefined;\n\t\tif (!todoResultAddsOpenTasks(event.details)) return undefined;\n\t\tconst reminder = staleGoalTodoReminder(await readGoal(goalStoreRef(ctx)));\n\t\tif (reminder === undefined) return undefined;\n\t\tstaleGoalReminderSentThisTurn = true;\n\t\treturn { content: [...event.content, { type: \"text\" as const, text: reminder }] };\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst continuationStarted = continuationPending;\n\t\tcontinuationPending = false;\n\t\tif (continuationStarted) monitorContinuation.noteContinuationStarted();\n\t\tagentTurnInProgress = true;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tturnUsage.reset();\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"message_end\", async (event) => {\n\t\tturnUsage.noteMessageEnd(event.message);\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode =\n\t\t\tblockedThisTurnGoalId !== null\n\t\t\t\t? \"activeOrBlocked\"\n\t\t\t\t: completedThisTurnGoalId === null\n\t\t\t\t\t? \"active\"\n\t\t\t\t\t: \"activeOrComplete\";\n\t\tlet goal = await accountCurrentAgentTurn(ctx, mode, event.messages);\n\t\tagentTurnInProgress = false;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (event.aborted === true && event.abortSource === \"user\" && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t} else if (didTerminalProviderErrorEndTurn(event) && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: PROVIDER_ERROR_BLOCKED_REASON },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tif (ctx.hasUI) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}\\n${continuationCapRecoveryHint(PROVIDER_ERROR_BLOCKED_REASON)}`,\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tconst continuationGoal = await continueGoalAfterAgentEnd(monitorContinuation, { ctx, event, goal });\n\t\tif (continuationGoal !== goal) {\n\t\t\tgoal = continuationGoal;\n\t\t\tsyncContinuationGoal(ctx, goal);\n\t\t}\n\t});\n\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tconst goal = await monitorContinuation.afterAgentSettled();\n\t\tif (goal !== undefined) syncContinuationGoal(ctx, goal);\n\t});\n\n\tpi.on(\"session_abort\", async (_event, ctx) => {\n\t\tcontinuationPending = false;\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status !== \"active\") return;\n\t\tconst accounted = await accountCurrentAgentTurn(ctx, \"active\");\n\t\tif (accounted?.status === \"active\") {\n\t\t\tconst blocked = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, blocked);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tactiveContext = undefined;\n\t\tunsubscribeGoalStoreChanged();\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t\tmonitorContinuation.dispose();\n\t});\n\n\tasync function maybePromptResumeStoppedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfStoppedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume ${goal.status} goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_STOPPED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" }, \"user\");\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tasync function queueGoalContinuationForCurrentSession(\n\t\textensionApi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tgoal: Goal,\n\t): Promise<void> {\n\t\tconst continuedGoal = await queueGoalContinuation(extensionApi, ctx, goal, {\n\t\t\tcontinuationPending,\n\t\t\tmarkContinuationPending: () => {\n\t\t\t\tcontinuationPending = true;\n\t\t\t},\n\t\t});\n\t\tif (continuedGoal.status === goal.status) return;\n\t\tif (continuedGoal.status === \"active\") beginAgentGoalAccounting(continuedGoal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, continuedGoal);\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tturnUsage.discardPending();\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalBlockedThisTurn(goal: Goal): void {\n\t\tif (agentTurnInProgress) blockedThisTurnGoalId = goal.id;\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (blockedThisTurnGoalId === goalId) {\n\t\t\tblockedThisTurnGoalId = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction syncContinuationGoal(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tif (goal?.status === \"active\") beginAgentGoalAccounting(goal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tmonitorContinuation.syncGoal(goal);\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tmode: GoalAccountingMode,\n\t\tagentRunMessages?: unknown[],\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst usage =\n\t\t\tagentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\n/**\n * Counts goal-continuation entries queued since the most recent real user message\n * in the current branch (mirrors the todo-gate / todo-bridge backward branch read).\n * A real user message is the only reset: the assistant turns in between are exactly\n * the unattended loop this admission guard exists to stop.\n */\nfunction countTrailingGoalContinuationEntries(entries: readonly SessionEntry[]): number {\n\tlet count = 0;\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type === \"message\" && entry.message.role === \"user\") break;\n\t\tif (entry?.type === \"custom_message\" && entry.customType === GOAL_CONTINUATION_MESSAGE_TYPE) count += 1;\n\t}\n\treturn count;\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\treturn buildGoalStoreRef(ctx.sessionManager, ctx.cwd);\n}\n"]}
@@ -1,10 +1,11 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "../../types.ts";
2
+ export { GOAL_MONITOR_CONTINUATION_FALLBACK_DELAY_MS } from "./cache-warm.ts";
2
3
  import type { AgentEndOptions, SystemAbortOptions } from "./monitor-continuation-types.ts";
3
4
  import type { Goal } from "./types.ts";
4
5
  import type { GoalWaitTicker } from "./wait-ticker.ts";
5
- export declare const GOAL_MONITOR_CONTINUATION_DELAY_MS = 240000;
6
6
  export declare const GOAL_CONTINUATION_SCHEDULED_EVENT = "goal_continuation_scheduled";
7
7
  export declare const GOAL_CONTINUATION_RESUMED_EVENT = "goal_continuation_resumed";
8
+ export declare const GOAL_CONTINUATION_TIMER_STATE_EVENT = "goal_continuation_timer_state";
8
9
  export declare const GOAL_MONITOR_STALL_EVENT = "goal_monitor_continuation_stall";
9
10
  export declare class MonitorAwareGoalContinuation {
10
11
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"monitor-continuation.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/monitor-continuation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAyBrE,OAAO,KAAK,EACX,eAAe,EAKf,kBAAkB,EAClB,MAAM,iCAAiC,CAAC;AAKzC,OAAO,KAAK,EAAE,IAAI,EAAsB,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,eAAO,MAAM,kCAAkC,SAAU,CAAC;AAC1D,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAC/E,eAAO,MAAM,+BAA+B,8BAA8B,CAAC;AAC3E,eAAO,MAAM,wBAAwB,oCAAoC,CAAC;AAE1E,qBAAa,4BAA4B;;IA0BxC,YACC,EAAE,EAAE,YAAY,EAChB,qBAAqB,GAAE,MAAM,OAAqB,EAClD,uBAAuB,GAAE,MAAM,IAAe,EAC9C,UAAU,CAAC,EAAE,cAAc,EAO3B;IAED,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CASjC;IAEK,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAsDlE;IAEK,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAaxE;IAEK,iBAAiB,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAK1D;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAOhC;IAED,mGAAmG;IACnG,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAkBrC;IAED,6FAA6F;IAC7F,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAW3D;IAED,sEAAsE;IACtE,cAAc,IAAI,IAAI,CAIrB;IAED,mGAAmG;IACnG,uBAAuB,IAAI,IAAI,CAE9B;IAED,OAAO,IAAI,IAAI,CAUd;CAkRD"}
1
+ {"version":3,"file":"monitor-continuation.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/monitor-continuation.ts"],"names":[],"mappings":"AACA,OA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;IACnG,uBAAuB,IAAI,IAAI,CAE9B;IAED,OAAO,IAAI,IAAI,CAUd;CAgUD"}
@@ -1,6 +1,6 @@
1
- import { isTerminalMonitorStateEvent, TERMINAL_MONITOR_STATE_EVENT } from "../monitor-state-event.js";
2
- import { isResumptionChannelStateEvent, RESUMPTION_CHANNEL_STATE_EVENT } from "../resumption-channel-event.js";
3
- import { estimateCacheWarmMetrics, GOAL_CACHE_WARMUP_ENTRY_TYPE, } from "./cache-warm.js";
1
+ import { isTerminalMonitorStateEvent, isWakeSourceStateEvent, TERMINAL_MONITOR_STATE_EVENT, WAKE_SOURCE_STATE_EVENT, } from "../monitor-state-event.js";
2
+ import { estimateCacheWarmMetrics, GOAL_CACHE_WARMUP_ENTRY_TYPE, GOAL_MONITOR_CONTINUATION_FALLBACK_DELAY_MS, resolveGoalMonitorContinuationDelayMs, } from "./cache-warm.js";
3
+ export { GOAL_MONITOR_CONTINUATION_FALLBACK_DELAY_MS } from "./cache-warm.js";
4
4
  import { continuationTurnUsedTools, evaluateGoalContinuation, GOAL_USER_GRACE_DELAY_MS, hasGoalContinuationProgress, hashAssistantText, normalizeAssistantText, } from "./continuation.js";
5
5
  import { lastAssistantMessage } from "./last-assistant-message.js";
6
6
  import { admitAndQueueGoalContinuation, buildCurrentGoalContinuationSignature, lastAssistantText, } from "./lifecycle-helpers.js";
@@ -8,16 +8,16 @@ import { buildContinuationPrompt, buildGoalStallNotice, buildTruncationRecoveryP
8
8
  import { resetContinuationStreak } from "./store.js";
9
9
  import { goalStoreRef } from "./store-ref.js";
10
10
  import { collectAssistantUsage } from "./turn-usage.js";
11
- export const GOAL_MONITOR_CONTINUATION_DELAY_MS = 240_000;
12
11
  export const GOAL_CONTINUATION_SCHEDULED_EVENT = "goal_continuation_scheduled";
13
12
  export const GOAL_CONTINUATION_RESUMED_EVENT = "goal_continuation_resumed";
13
+ export const GOAL_CONTINUATION_TIMER_STATE_EVENT = "goal_continuation_timer_state";
14
14
  export const GOAL_MONITOR_STALL_EVENT = "goal_monitor_continuation_stall";
15
15
  export class MonitorAwareGoalContinuation {
16
16
  #pi;
17
17
  #isContinuationPending;
18
18
  #markContinuationPending;
19
19
  #waitTicker;
20
- #channelCounts = new Map();
20
+ #wakeSources = new Map();
21
21
  #hasStarted = false;
22
22
  #ctx;
23
23
  #goal = null;
@@ -34,6 +34,9 @@ export class MonitorAwareGoalContinuation {
34
34
  #scheduledAtMs;
35
35
  #scheduledDueAtMs;
36
36
  #scheduledCache;
37
+ #scheduledDelayMs;
38
+ #cacheWarmIteration = 0;
39
+ #scheduledCacheWarmIteration;
37
40
  #heldTimer;
38
41
  #directInputHolds = new Set();
39
42
  #pendingSystemRecovery;
@@ -48,7 +51,7 @@ export class MonitorAwareGoalContinuation {
48
51
  this.#cancelTimer();
49
52
  this.#ctx = ctx;
50
53
  if (this.#hasStarted)
51
- this.#channelCounts.clear();
54
+ this.#wakeSources.clear();
52
55
  else
53
56
  this.#hasStarted = true;
54
57
  this.#goal = null;
@@ -58,7 +61,7 @@ export class MonitorAwareGoalContinuation {
58
61
  }
59
62
  async afterAgentEnd(options) {
60
63
  if (options.goal?.id !== this.#goal?.id)
61
- this.#resetToollessContinuationStreak();
64
+ this.#resetContinuationState();
62
65
  this.#ctx = options.ctx;
63
66
  this.#goal = options.goal;
64
67
  this.#lastAgentEndMessages = options.messages;
@@ -68,6 +71,7 @@ export class MonitorAwareGoalContinuation {
68
71
  this.#recordAssistantOutput(options.messages, turnUsedTools);
69
72
  if (options.goal?.status !== "active") {
70
73
  this.#cancelTimer();
74
+ this.#resetContinuationState();
71
75
  return options.goal;
72
76
  }
73
77
  this.#recordToollessContinuationTurn(options.goal, turnUsedTools);
@@ -103,7 +107,7 @@ export class MonitorAwareGoalContinuation {
103
107
  }
104
108
  if (immediateVerdict.kind === "deny" && immediateVerdict.reason === "not-eligible")
105
109
  return goal;
106
- if (this.#activeChannelCount() === 0) {
110
+ if (this.#activeWakeSourceCount() === 0) {
107
111
  this.#cancelTimer();
108
112
  const admission = await this.#admitAndQueue(options.ctx, goal, "immediate", options.messages);
109
113
  return admission.goal;
@@ -113,14 +117,20 @@ export class MonitorAwareGoalContinuation {
113
117
  }
114
118
  async afterSystemAbort(options) {
115
119
  this.noteContinuationStarted();
120
+ if (options.goal?.id !== this.#goal?.id)
121
+ this.#resetContinuationState();
116
122
  this.#pendingSystemRecovery = undefined;
117
123
  this.#ctx = options.ctx;
118
124
  this.#goal = options.goal;
119
125
  this.#lastAgentEndMessages = options.messages;
120
126
  this.#lastTurnUsage = collectAssistantUsage([...options.messages]);
121
- if (options.willRetry || options.goal?.status !== "active")
127
+ if (options.goal?.status !== "active") {
128
+ this.#resetContinuationState();
122
129
  return options.goal;
123
- if (this.#activeChannelCount() > 0)
130
+ }
131
+ if (options.willRetry)
132
+ return options.goal;
133
+ if (this.#activeWakeSourceCount() > 0)
124
134
  this.#schedule(options.goal, "monitor");
125
135
  else if (lastAssistantMessage(options.messages)?.stopReason === "error") {
126
136
  this.#pendingSystemRecovery = options;
@@ -153,9 +163,13 @@ export class MonitorAwareGoalContinuation {
153
163
  this.#scheduledContinuationKind === undefined) {
154
164
  return;
155
165
  }
166
+ const heldAtMs = Date.now();
156
167
  this.#heldTimer = {
157
168
  kind: this.#scheduledContinuationKind,
158
- remainingMs: Math.max(0, (this.#scheduledDueAtMs ?? Date.now()) - Date.now()),
169
+ remainingMs: Math.max(0, (this.#scheduledDueAtMs ?? heldAtMs) - heldAtMs),
170
+ heldAtMs,
171
+ totalMs: this.#scheduledDelayMs ?? GOAL_USER_GRACE_DELAY_MS,
172
+ drainFire: false,
159
173
  };
160
174
  clearTimeout(this.#timer);
161
175
  this.#timer = undefined;
@@ -175,7 +189,8 @@ export class MonitorAwareGoalContinuation {
175
189
  return;
176
190
  const held = this.#heldTimer;
177
191
  this.#heldTimer = undefined;
178
- this.#armTimer(held.kind, held.remainingMs);
192
+ const elapsedWhileHeldMs = Math.max(0, Date.now() - held.heldAtMs);
193
+ this.#armTimer(held.kind, Math.max(0, held.remainingMs - elapsedWhileHeldMs), held.totalMs, held.drainFire);
179
194
  }
180
195
  /** An accepted real user prompt starts a grace-governed user turn. */
181
196
  noteUserPrompt() {
@@ -194,7 +209,7 @@ export class MonitorAwareGoalContinuation {
194
209
  this.#channelStateUnsubscribers = [];
195
210
  this.#ctx = undefined;
196
211
  this.#goal = null;
197
- this.#channelCounts.clear();
212
+ this.#wakeSources.clear();
198
213
  this.#lastAgentEndMessages = [];
199
214
  this.#directInputHolds.clear();
200
215
  this.#resetContinuationState();
@@ -202,52 +217,62 @@ export class MonitorAwareGoalContinuation {
202
217
  #schedule(goal, kind) {
203
218
  if (this.#scheduledContinuationKind !== undefined)
204
219
  return;
205
- const delayMs = kind === "monitor" ? GOAL_MONITOR_CONTINUATION_DELAY_MS : GOAL_USER_GRACE_DELAY_MS;
220
+ const delayMs = kind === "monitor"
221
+ ? resolveGoalMonitorContinuationDelayMs(this.#ctx?.getPromptCacheSafeWaitSeconds?.(), this.#ctx?.getPromptCacheGoalBackstopMaxSeconds?.())
222
+ : GOAL_USER_GRACE_DELAY_MS;
223
+ this.#scheduledDelayMs = delayMs;
206
224
  if (kind === "monitor") {
225
+ this.#cacheWarmIteration += 1;
226
+ this.#scheduledCacheWarmIteration = this.#cacheWarmIteration;
227
+ const iteration = this.#scheduledCacheWarmIteration;
207
228
  const cache = estimateCacheWarmMetrics(this.#ctx?.model, process.env, this.#lastTurnUsage);
208
- const channelCounts = this.#channelCountSnapshot();
229
+ const wakeSources = this.#wakeSourceSnapshot();
209
230
  this.#scheduledCache = cache;
210
231
  this.#scheduledAtMs = Date.now();
211
232
  this.#pi.events?.emit(GOAL_CONTINUATION_SCHEDULED_EVENT, {
212
233
  goalId: goal.id,
213
234
  delayMs,
214
- activeMonitorCount: this.#activeTerminalMonitorCount(),
215
- channelCounts,
235
+ iteration,
236
+ activeMonitorCount: this.#activeWakeSourceCount(),
237
+ wakeSources,
216
238
  cache,
217
239
  });
218
240
  this.#appendWarmupEntry({
219
241
  phase: "scheduled",
220
242
  goalId: goal.id,
221
243
  delayMs,
222
- activeMonitorCount: this.#activeTerminalMonitorCount(),
223
- channelCounts,
244
+ iteration,
245
+ activeMonitorCount: this.#activeWakeSourceCount(),
246
+ wakeSources,
224
247
  ...(cache !== undefined ? { cache } : {}),
225
248
  });
226
249
  }
227
250
  else {
228
251
  this.#scheduledAtMs = undefined;
229
252
  this.#scheduledCache = undefined;
253
+ this.#scheduledCacheWarmIteration = undefined;
230
254
  }
231
255
  this.#scheduledContinuationKind = kind;
256
+ this.#pi.events?.emit(GOAL_CONTINUATION_TIMER_STATE_EVENT, { armed: true, kind });
232
257
  if (this.#directInputHolds.size > 0) {
233
- this.#heldTimer = { kind, remainingMs: delayMs };
258
+ this.#heldTimer = { kind, remainingMs: delayMs, heldAtMs: Date.now(), totalMs: delayMs, drainFire: false };
234
259
  return;
235
260
  }
236
- this.#armTimer(kind, delayMs);
261
+ this.#armTimer(kind, delayMs, delayMs);
237
262
  }
238
- #armTimer(kind, delayMs) {
263
+ #armTimer(kind, delayMs, totalMs, drainFire = false) {
239
264
  this.#scheduledDueAtMs = Date.now() + delayMs;
240
265
  const ctx = this.#ctx;
241
266
  if (ctx?.hasUI) {
242
267
  this.#waitTicker?.sync(ctx, {
243
268
  kind,
244
269
  remainingMs: delayMs,
245
- totalMs: kind === "monitor" ? GOAL_MONITOR_CONTINUATION_DELAY_MS : GOAL_USER_GRACE_DELAY_MS,
246
- channelCounts: this.#channelCountSnapshot(),
270
+ totalMs,
271
+ channelCounts: this.#wakeSourceSnapshot(),
247
272
  });
248
273
  }
249
274
  this.#timer = setTimeout(() => {
250
- void this.#continueIfEligible(kind).catch((error) => {
275
+ void this.#continueIfEligible(kind, drainFire).catch((error) => {
251
276
  if (this.#ctx?.hasUI) {
252
277
  const message = error instanceof Error ? error.message : String(error);
253
278
  this.#ctx.ui.notify(`Goal continuation delivery failed: ${message}`, "error");
@@ -255,32 +280,38 @@ export class MonitorAwareGoalContinuation {
255
280
  });
256
281
  }, delayMs);
257
282
  }
258
- async #continueIfEligible(kind) {
283
+ async #continueIfEligible(kind, drainFire = false) {
259
284
  this.#timer = undefined;
260
285
  this.#scheduledDueAtMs = undefined;
261
286
  this.#scheduledContinuationKind = undefined;
287
+ this.#pi.events?.emit(GOAL_CONTINUATION_TIMER_STATE_EVENT, { armed: false, kind });
262
288
  this.#waitTicker?.stop();
263
- const delayMs = kind === "monitor" ? GOAL_MONITOR_CONTINUATION_DELAY_MS : GOAL_USER_GRACE_DELAY_MS;
289
+ const delayMs = this.#scheduledDelayMs ??
290
+ (kind === "monitor" ? GOAL_MONITOR_CONTINUATION_FALLBACK_DELAY_MS : GOAL_USER_GRACE_DELAY_MS);
264
291
  const waitedMs = this.#scheduledAtMs === undefined ? delayMs : Math.max(0, Date.now() - this.#scheduledAtMs);
265
292
  const cache = this.#scheduledCache;
293
+ const iteration = this.#scheduledCacheWarmIteration;
266
294
  this.#scheduledAtMs = undefined;
267
295
  this.#scheduledCache = undefined;
296
+ this.#scheduledDelayMs = undefined;
297
+ this.#scheduledCacheWarmIteration = undefined;
268
298
  const ctx = this.#ctx;
269
299
  const goal = this.#goal;
270
300
  if (ctx === undefined || goal?.status !== "active" || !ctx.isIdle() || ctx.hasPendingMessages())
271
301
  return;
272
- if (kind === "monitor" && this.#activeChannelCount() === 0)
302
+ if (kind === "monitor" && this.#activeWakeSourceCount() === 0 && !drainFire)
273
303
  return;
274
304
  const admission = await this.#admitAndQueue(ctx, goal, kind === "monitor" ? "monitorDelayed" : "userGrace", this.#lastAgentEndMessages);
275
- if (kind !== "monitor" || !admission.admitted)
305
+ if (kind !== "monitor" || !admission.admitted || iteration === undefined)
276
306
  return;
277
- const channelCounts = this.#channelCountSnapshot();
307
+ const wakeSources = this.#wakeSourceSnapshot();
278
308
  this.#pi.events?.emit(GOAL_CONTINUATION_RESUMED_EVENT, {
279
309
  goalId: goal.id,
280
310
  delayMs,
281
311
  waitedMs,
282
- activeMonitorCount: this.#activeTerminalMonitorCount(),
283
- channelCounts,
312
+ iteration,
313
+ activeMonitorCount: this.#activeWakeSourceCount(),
314
+ wakeSources,
284
315
  cache,
285
316
  });
286
317
  this.#appendWarmupEntry({
@@ -288,10 +319,13 @@ export class MonitorAwareGoalContinuation {
288
319
  goalId: goal.id,
289
320
  delayMs,
290
321
  waitedMs,
291
- activeMonitorCount: this.#activeTerminalMonitorCount(),
292
- channelCounts,
322
+ iteration,
323
+ activeMonitorCount: this.#activeWakeSourceCount(),
324
+ wakeSources,
293
325
  ...(cache !== undefined ? { cache } : {}),
294
326
  });
327
+ if (drainFire || admission.goal.status !== "active")
328
+ this.#resetCacheWarmIteration();
295
329
  }
296
330
  async #admitAndQueue(ctx, goal, path, messages) {
297
331
  const input = this.#buildVerdictInput(ctx, goal, path, messages);
@@ -334,7 +368,7 @@ export class MonitorAwareGoalContinuation {
334
368
  let content = verdict.prompt === "minimal" ? buildTruncationRecoveryPrompt() : buildContinuationPrompt(goal);
335
369
  if (!verdict.stallNotice)
336
370
  return content;
337
- const liveSources = this.#liveChannelSources();
371
+ const liveSources = this.#liveWakeSources();
338
372
  this.#pi.events?.emit(GOAL_MONITOR_STALL_EVENT, {
339
373
  goalId: goal.id,
340
374
  consecutiveContinuations: this.#toollessContinuationStreak,
@@ -383,41 +417,58 @@ export class MonitorAwareGoalContinuation {
383
417
  this.#channelStateUnsubscribers.push(events.on(TERMINAL_MONITOR_STATE_EVENT, (data) => {
384
418
  if (!isTerminalMonitorStateEvent(data))
385
419
  return;
386
- this.#setChannelCount("terminal-monitor", data.activeCount);
387
- }), events.on(RESUMPTION_CHANNEL_STATE_EVENT, (data) => {
388
- if (!isResumptionChannelStateEvent(data))
420
+ this.#setWakeSourceCount("terminal-monitors", data.activeCount);
421
+ }), events.on(WAKE_SOURCE_STATE_EVENT, (data) => {
422
+ if (!isWakeSourceStateEvent(data))
389
423
  return;
390
- this.#setChannelCount(data.source, data.activeCount);
424
+ this.#setWakeSourceCount(data.source, data.activeCount);
391
425
  }));
392
426
  }
393
- #setChannelCount(source, activeCount) {
394
- const previousTotal = this.#activeChannelCount();
395
- this.#channelCounts.set(source, activeCount);
396
- const nextTotal = this.#activeChannelCount();
427
+ #setWakeSourceCount(source, activeCount) {
428
+ const previousTotal = this.#activeWakeSourceCount();
429
+ this.#wakeSources.set(source, activeCount);
430
+ const nextTotal = this.#activeWakeSourceCount();
397
431
  if (previousTotal > 0 && nextTotal === 0) {
398
432
  if (this.#scheduledContinuationKind === "monitor")
399
- this.#cancelTimer();
433
+ this.#armDrainFire();
434
+ else
435
+ this.#resetCacheWarmIteration();
400
436
  this.#resetToollessContinuationStreak();
401
437
  return;
402
438
  }
403
439
  if (this.#scheduledContinuationKind === "monitor") {
404
- this.#waitTicker?.setChannelCounts(this.#channelCountSnapshot());
440
+ this.#waitTicker?.setChannelCounts(this.#wakeSourceSnapshot());
441
+ }
442
+ }
443
+ #armDrainFire() {
444
+ if (this.#directInputHolds.size > 0) {
445
+ this.#heldTimer = {
446
+ kind: "monitor",
447
+ remainingMs: 1_000,
448
+ heldAtMs: Date.now(),
449
+ totalMs: 1_000,
450
+ drainFire: true,
451
+ };
452
+ return;
405
453
  }
454
+ if (this.#timer !== undefined)
455
+ clearTimeout(this.#timer);
456
+ this.#timer = undefined;
457
+ this.#scheduledDueAtMs = undefined;
458
+ this.#waitTicker?.stop();
459
+ this.#armTimer("monitor", 1_000, 1_000, true);
406
460
  }
407
- #activeChannelCount() {
461
+ #activeWakeSourceCount() {
408
462
  let total = 0;
409
- for (const count of this.#channelCounts.values())
463
+ for (const count of this.#wakeSources.values())
410
464
  total += count;
411
465
  return total;
412
466
  }
413
- #activeTerminalMonitorCount() {
414
- return this.#channelCounts.get("terminal-monitor") ?? 0;
467
+ #wakeSourceSnapshot() {
468
+ return Object.fromEntries([...this.#wakeSources.entries()].sort(([left], [right]) => left.localeCompare(right)));
415
469
  }
416
- #channelCountSnapshot() {
417
- return Object.fromEntries([...this.#channelCounts.entries()].sort(([left], [right]) => left.localeCompare(right)));
418
- }
419
- #liveChannelSources() {
420
- return [...this.#channelCounts.entries()]
470
+ #liveWakeSources() {
471
+ return [...this.#wakeSources.entries()]
421
472
  .filter(([, count]) => count > 0)
422
473
  .map(([source]) => source)
423
474
  .sort();
@@ -427,20 +478,30 @@ export class MonitorAwareGoalContinuation {
427
478
  this.#consecutiveLengthRecoveries.clear();
428
479
  this.#recentNormalizedOutputHashes = [];
429
480
  this.#resetToollessContinuationStreak();
481
+ this.#resetCacheWarmIteration();
482
+ }
483
+ #resetCacheWarmIteration() {
484
+ this.#cacheWarmIteration = 0;
485
+ this.#scheduledCacheWarmIteration = undefined;
430
486
  }
431
487
  #resetToollessContinuationStreak() {
432
488
  this.#toollessContinuationStreak = 0;
433
489
  this.#toollessStreakGoalId = null;
434
490
  }
435
491
  #cancelTimer() {
492
+ const kind = this.#scheduledContinuationKind;
436
493
  this.#scheduledAtMs = undefined;
437
494
  this.#scheduledDueAtMs = undefined;
438
495
  this.#scheduledCache = undefined;
496
+ this.#scheduledDelayMs = undefined;
497
+ this.#scheduledCacheWarmIteration = undefined;
439
498
  this.#heldTimer = undefined;
440
499
  if (this.#timer !== undefined)
441
500
  clearTimeout(this.#timer);
442
501
  this.#timer = undefined;
443
502
  this.#scheduledContinuationKind = undefined;
503
+ if (kind !== undefined)
504
+ this.#pi.events?.emit(GOAL_CONTINUATION_TIMER_STATE_EVENT, { armed: false, kind });
444
505
  this.#waitTicker?.stop();
445
506
  }
446
507
  }