@astralyn/pi 0.84.7 → 0.84.9

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 (68) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/core/compaction/compaction.d.ts +2 -0
  3. package/dist/core/compaction/compaction.d.ts.map +1 -1
  4. package/dist/core/compaction/compaction.js +7 -7
  5. package/dist/core/compaction/compaction.js.map +1 -1
  6. package/dist/extensions/background/index.d.ts.map +1 -1
  7. package/dist/extensions/background/index.js +48 -72
  8. package/dist/extensions/background/index.js.map +1 -1
  9. package/dist/extensions/background/manager.d.ts.map +1 -1
  10. package/dist/extensions/background/manager.js +5 -3
  11. package/dist/extensions/background/manager.js.map +1 -1
  12. package/dist/extensions/background/registry.d.ts +11 -13
  13. package/dist/extensions/background/registry.d.ts.map +1 -1
  14. package/dist/extensions/background/registry.js +71 -80
  15. package/dist/extensions/background/registry.js.map +1 -1
  16. package/dist/extensions/background/render.d.ts.map +1 -1
  17. package/dist/extensions/background/render.js +8 -3
  18. package/dist/extensions/background/render.js.map +1 -1
  19. package/dist/extensions/deepwiki/constants.d.ts +2 -2
  20. package/dist/extensions/deepwiki/constants.d.ts.map +1 -1
  21. package/dist/extensions/deepwiki/constants.js +5 -5
  22. package/dist/extensions/deepwiki/constants.js.map +1 -1
  23. package/dist/extensions/deepwiki/schema.js +1 -1
  24. package/dist/extensions/deepwiki/schema.js.map +1 -1
  25. package/dist/extensions/question/constants.d.ts +2 -2
  26. package/dist/extensions/question/constants.d.ts.map +1 -1
  27. package/dist/extensions/question/constants.js +5 -2
  28. package/dist/extensions/question/constants.js.map +1 -1
  29. package/dist/extensions/subagent/activity.d.ts +9 -0
  30. package/dist/extensions/subagent/activity.d.ts.map +1 -1
  31. package/dist/extensions/subagent/activity.js +21 -0
  32. package/dist/extensions/subagent/activity.js.map +1 -1
  33. package/dist/extensions/subagent/agents.d.ts.map +1 -1
  34. package/dist/extensions/subagent/agents.js +7 -3
  35. package/dist/extensions/subagent/agents.js.map +1 -1
  36. package/dist/extensions/subagent/constants.d.ts +1 -0
  37. package/dist/extensions/subagent/constants.d.ts.map +1 -1
  38. package/dist/extensions/subagent/constants.js +4 -0
  39. package/dist/extensions/subagent/constants.js.map +1 -1
  40. package/dist/extensions/subagent/index.js +4 -4
  41. package/dist/extensions/subagent/index.js.map +1 -1
  42. package/dist/extensions/subagent/render.d.ts +6 -2
  43. package/dist/extensions/subagent/render.d.ts.map +1 -1
  44. package/dist/extensions/subagent/render.js +143 -138
  45. package/dist/extensions/subagent/render.js.map +1 -1
  46. package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
  47. package/dist/extensions/subagent/sdk-runner.js +19 -0
  48. package/dist/extensions/subagent/sdk-runner.js.map +1 -1
  49. package/dist/extensions/subagent/state.d.ts +9 -0
  50. package/dist/extensions/subagent/state.d.ts.map +1 -1
  51. package/dist/extensions/subagent/state.js +33 -2
  52. package/dist/extensions/subagent/state.js.map +1 -1
  53. package/dist/extensions/todo/constants.d.ts +1 -1
  54. package/dist/extensions/todo/constants.d.ts.map +1 -1
  55. package/dist/extensions/todo/constants.js +10 -27
  56. package/dist/extensions/todo/constants.js.map +1 -1
  57. package/dist/extensions/todo/state.d.ts.map +1 -1
  58. package/dist/extensions/todo/state.js +27 -16
  59. package/dist/extensions/todo/state.js.map +1 -1
  60. package/dist/extensions/todo/view.d.ts.map +1 -1
  61. package/dist/extensions/todo/view.js +16 -5
  62. package/dist/extensions/todo/view.js.map +1 -1
  63. package/docs/bundled/extensions/background.md +3 -3
  64. package/docs/bundled/extensions/subagent.md +40 -23
  65. package/docs/bundled/extensions/todo.md +2 -2
  66. package/docs/compaction.md +2 -0
  67. package/npm-shrinkwrap.json +2 -2
  68. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-runner.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/sdk-runner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAA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UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAiGD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsOzE"}
@@ -200,6 +200,25 @@ export async function runSdkTask(options) {
200
200
  emitImmediate();
201
201
  return;
202
202
  }
203
+ if (event.type === "compaction_start") {
204
+ dispatch({ type: "compaction_started", startedAt: Date.now() });
205
+ emitImmediate();
206
+ return;
207
+ }
208
+ if (event.type === "compaction_end") {
209
+ // A worker has no status line of its own, so the compaction's outcome —
210
+ // especially the reason a failed one blocks the next request — only
211
+ // reaches the caller through the activity log.
212
+ dispatch({
213
+ type: "compaction_ended",
214
+ tokensBefore: event.result?.tokensBefore,
215
+ tokensAfter: event.result?.estimatedTokensAfter,
216
+ error: event.errorMessage,
217
+ endedAt: Date.now(),
218
+ });
219
+ emitImmediate();
220
+ return;
221
+ }
203
222
  if (event.type === "message_end" && event.message.role === "assistant") {
204
223
  if (!seenAssistantMessages.has(event.message)) {
205
224
  seenAssistantMessages.add(event.message);
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-runner.js","sourceRoot":"","sources":["../../../src/extensions/subagent/sdk-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiBnD,SAAS,kBAAkB,CAAC,IAAwB,EAAE,IAA0B;IAC/E,OAAO;QACN,IAAI;QACJ,wBAAwB,IAAI,CAAC,KAAK,CAAC,IAAI,iDAAiD;QACxF,wIAAwI;QACxI,6GAA6G;QAC7G,8EAA8E;QAC9E,iEAAiE;QACjE,oGAAoG;Q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O,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACnG,CAAC;IACF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1B,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,SAAS;gBAClB,MAAM;gBACN,KAAK,EAAE,uBAAuB;gBAC9B,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,QAAQ;gBACjB,MAAM;gBACN,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE,CAAC;QACpB,WAAW,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,aAAa,EAAE,CAAC;IACjB,CAAC;AACF,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { DefaultResourceLoader } from \"../../core/resource-loader.ts\";\nimport { createAgentSession } from \"../../core/sdk.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { finalAssistantText } from \"./activity.ts\";\nimport type { RunCancellation } from \"./cancellation.ts\";\nimport type { SubagentRunEvent } from \"./state.ts\";\nimport type { ResolvedSubagentTask } from \"./types.ts\";\n\nexport interface SdkRunnerOptions {\n\ttask: ResolvedSubagentTask;\n\t/** Cancellation scope covering this attempt (queued through session end). */\n\tscope: RunCancellation;\n\t/** Reducer input; the adapter never touches run state directly. */\n\tdispatch: (event: SubagentRunEvent) => void;\n\tmodelRuntime: ModelRuntime;\n\tagentDir: string;\n\tprojectTrusted: boolean;\n\tonProgress?: () => void;\n}\n\nfunction workerSystemPrompt(base: string | undefined, task: ResolvedSubagentTask): string {\n\treturn [\n\t\tbase,\n\t\t`You are Pi subagent \"${task.agent.name}\", working independently on one delegated task.`,\n\t\t\"You cannot see the parent conversation; rely entirely on the task briefing and repository context available in your working directory.\",\n\t\t\"Only your final message is returned to the caller; nothing you write in earlier turns is visible to anyone.\",\n\t\t\"Complete the task fully—do not gold-plate it, but do not leave it half-done.\",\n\t\t\"Stay inside the assigned working directory and delegated scope.\",\n\t\t\"Do not ask the end user questions. If blocked, report the exact blocker and what would resolve it.\",\n\t\t\"Do not spawn subagents or invoke tools outside the configured tool list.\",\n\t\t\"When referencing files in the final report, use paths relative to the task's working directory so the caller can locate them unambiguously.\",\n\t\t\"Include code snippets only when the exact text is load-bearing (a bug you found, a signature the caller asked for); do not recap code you merely read.\",\n\t\t\"End with a concise report covering findings or changes, verification performed, blockers, and unresolved risks. The caller will relay it to the user, so include only the essentials.\",\n\t\ttask.agent.systemPrompt,\n\t]\n\t\t.filter((part): part is string => Boolean(part?.trim()))\n\t\t.join(\"\\n\\n\");\n}\n\nfunction lastAssistantMessage(session: { messages: readonly AgentMessage[] }) {\n\tfor (let index = session.messages.length - 1; index >= 0; index--) {\n\t\tconst message = session.messages[index];\n\t\tif (message?.role === \"assistant\") return message;\n\t}\n\treturn undefined;\n}\n\nfunction assistantError(message: ReturnType<typeof lastAssistantMessage>): string | undefined {\n\tif (!message || message.role !== \"assistant\") return undefined;\n\treturn message.errorMessage;\n}\n\ninterface ThrottledEmitter {\n\temit: () => void;\n\t/** Drops any pending timer so nothing fires after the run has settled. */\n\tcancel: () => void;\n}\n\nfunction createThrottledEmitter(onProgress: (() => void) | undefined): ThrottledEmitter {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\treturn {\n\t\temit: () => {\n\t\t\tif (!onProgress || timer) return;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\ttimer = undefined;\n\t\t\t\tonProgress();\n\t\t\t}, 80);\n\t\t},\n\t\tcancel: () => {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t},\n\t};\n}\n\ntype InitializationOutcome =\n\t| { kind: \"created\"; session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] }\n\t| { kind: \"aborted\" }\n\t| { kind: \"error\"; error: unknown };\n\n// Neither resource loading nor session creation takes an abort signal, and\n// both can hang on network work; race both against the scope. The losing\n// chain keeps running, so its eventual result or rejection is always\n// consumed by a no-op handler.\nasync function raceInitialization(\n\tchain: Promise<InitializationOutcome>,\n\tscope: RunCancellation,\n): Promise<InitializationOutcome> {\n\treturn new Promise<InitializationOutcome>((resolve) => {\n\t\tlet settled = false;\n\t\tconst finish = (outcome: InitializationOutcome): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tscope.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve(outcome);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\tfinish({ kind: \"aborted\" });\n\t\t};\n\t\tif (scope.signal.aborted) {\n\t\t\tonAbort();\n\t\t\tvoid chain.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tscope.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid chain.then(\n\t\t\t(outcome) => finish(outcome),\n\t\t\t(error) => finish({ kind: \"error\", error }),\n\t\t);\n\t});\n}\n\n/**\n * Runs one worker attempt as a pure adapter: it owns the worker session's\n * lifecycle and translates AgentSessionEvents into SubagentRunEvents; every\n * state transition happens in the reducer on the other side of dispatch.\n */\nexport async function runSdkTask(options: SdkRunnerOptions): Promise<void> {\n\tconst { task, scope, dispatch, modelRuntime, agentDir, projectTrusted, onProgress } = options;\n\tconst throttled = createThrottledEmitter(onProgress);\n\tlet unsubscribe: (() => void) | undefined;\n\tlet unregisterAbort: (() => void) | undefined;\n\tlet session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] | undefined;\n\t// Streaming updates carry no semantic weight; the settled messages are\n\t// where usage is accounted, and worker sessions can replay them.\n\tconst seenAssistantMessages = new Set<unknown>();\n\tconst emitImmediate = (): void => onProgress?.();\n\tconst emitThrottled = throttled.emit;\n\n\tunregisterAbort = scope.onAbort(async () => {\n\t\tif (session) await session.abort();\n\t});\n\n\ttry {\n\t\tif (scope.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted before it started.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsManager = SettingsManager.create(task.cwd, agentDir, { projectTrusted });\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: task.cwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tnoExtensions: true,\n\t\t\tnoSkills: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t\t// Read-only explorers skip AGENTS.md/CLAUDE.md: they don't need\n\t\t\t// commit/PR/style rules, and the parent interprets their results.\n\t\t\tnoContextFiles: task.agent.omitContextFiles ?? false,\n\t\t\tsystemPromptOverride: (base) => workerSystemPrompt(base, task),\n\t\t});\n\t\tconst initialization = (async (): Promise<InitializationOutcome> => {\n\t\t\tawait resourceLoader.reload();\n\t\t\tif (scope.signal.aborted) return { kind: \"aborted\" };\n\t\t\tconst created = await createAgentSession({\n\t\t\t\tcwd: task.cwd,\n\t\t\t\tagentDir,\n\t\t\t\tmodelRuntime,\n\t\t\t\tmodel: task.model,\n\t\t\t\tthinkingLevel: task.thinking,\n\t\t\t\ttools: task.agent.tools,\n\t\t\t\tresourceLoader,\n\t\t\t\tsessionManager: SessionManager.inMemory(task.cwd),\n\t\t\t\tsettingsManager,\n\t\t\t});\n\t\t\treturn { kind: \"created\", session: created.session };\n\t\t})();\n\t\tconst outcome = await raceInitialization(initialization, scope);\n\t\tif (outcome.kind === \"error\") throw outcome.error;\n\t\tif (outcome.kind === \"aborted\") {\n\t\t\t// The initialization chain cannot be cancelled. Dispose the\n\t\t\t// session if it eventually resolves, and swallow a late rejection\n\t\t\t// after this run has already settled.\n\t\t\tvoid initialization.then(\n\t\t\t\t(late) => {\n\t\t\t\t\tif (late.kind === \"created\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlate.session.dispose();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// The aborted run has no remaining channel for cleanup errors.\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tsession = outcome.session;\n\t\tif (scope.aborted) {\n\t\t\tawait session.abort();\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tunsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\tif (event.type === \"auto_retry_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"auto_retry_start\",\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tdeadline: Date.now() + event.delayMs,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"auto_retry_end\") {\n\t\t\t\tdispatch({ type: \"auto_retry_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"turn_end\") {\n\t\t\t\tdispatch({ type: \"turn_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\tif (!seenAssistantMessages.has(event.message)) {\n\t\t\t\t\tseenAssistantMessages.add(event.message);\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: event.message.usage });\n\t\t\t\t} else {\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: undefined });\n\t\t\t\t}\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_started\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_update\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_updated\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t});\n\t\t\t\temitThrottled();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_ended\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t}\n\t\t});\n\t\tawait session.prompt(task.prompt);\n\t\tconst finalMessage = lastAssistantMessage(session);\n\t\tconst report = finalAssistantText(session.messages);\n\t\tconst error = assistantError(finalMessage);\n\t\tif (scope.signal.aborted || finalMessage?.stopReason === \"aborted\") {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else if (finalMessage?.stopReason === \"error\" || error) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent failed.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({ type: \"settle\", verdict: \"completed\", report, error: undefined, endedAt: Date.now() });\n\t\t}\n\t} catch (error) {\n\t\tconst report = session ? finalAssistantText(session.messages) : \"\";\n\t\tif (scope.signal.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tthrottled.cancel();\n\t\tunregisterAbort?.();\n\t\tunsubscribe?.();\n\t\tsession?.dispose();\n\t\temitImmediate();\n\t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;IACF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1B,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,SAAS;gBAClB,MAAM;gBACN,KAAK,EAAE,uBAAuB;gBAC9B,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,QAAQ;gBACjB,MAAM;gBACN,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE,CAAC;QACpB,WAAW,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,aAAa,EAAE,CAAC;IACjB,CAAC;AACF,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { DefaultResourceLoader } from \"../../core/resource-loader.ts\";\nimport { createAgentSession } from \"../../core/sdk.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { finalAssistantText } from \"./activity.ts\";\nimport type { RunCancellation } from \"./cancellation.ts\";\nimport type { SubagentRunEvent } from \"./state.ts\";\nimport type { ResolvedSubagentTask } from \"./types.ts\";\n\nexport interface SdkRunnerOptions {\n\ttask: ResolvedSubagentTask;\n\t/** Cancellation scope covering this attempt (queued through session end). */\n\tscope: RunCancellation;\n\t/** Reducer input; the adapter never touches run state directly. */\n\tdispatch: (event: SubagentRunEvent) => void;\n\tmodelRuntime: ModelRuntime;\n\tagentDir: string;\n\tprojectTrusted: boolean;\n\tonProgress?: () => void;\n}\n\nfunction workerSystemPrompt(base: string | undefined, task: ResolvedSubagentTask): string {\n\treturn [\n\t\tbase,\n\t\t`You are Pi subagent \"${task.agent.name}\", working independently on one delegated task.`,\n\t\t\"You cannot see the parent conversation; rely entirely on the task briefing and repository context available in your working directory.\",\n\t\t\"Only your final message is returned to the caller; nothing you write in earlier turns is visible to anyone.\",\n\t\t\"Complete the task fully—do not gold-plate it, but do not leave it half-done.\",\n\t\t\"Stay inside the assigned working directory and delegated scope.\",\n\t\t\"Do not ask the end user questions. If blocked, report the exact blocker and what would resolve it.\",\n\t\t\"Do not spawn subagents or invoke tools outside the configured tool list.\",\n\t\t\"When referencing files in the final report, use paths relative to the task's working directory so the caller can locate them unambiguously.\",\n\t\t\"Include code snippets only when the exact text is load-bearing (a bug you found, a signature the caller asked for); do not recap code you merely read.\",\n\t\t\"End with a concise report covering findings or changes, verification performed, blockers, and unresolved risks. The caller will relay it to the user, so include only the essentials.\",\n\t\ttask.agent.systemPrompt,\n\t]\n\t\t.filter((part): part is string => Boolean(part?.trim()))\n\t\t.join(\"\\n\\n\");\n}\n\nfunction lastAssistantMessage(session: { messages: readonly AgentMessage[] }) {\n\tfor (let index = session.messages.length - 1; index >= 0; index--) {\n\t\tconst message = session.messages[index];\n\t\tif (message?.role === \"assistant\") return message;\n\t}\n\treturn undefined;\n}\n\nfunction assistantError(message: ReturnType<typeof lastAssistantMessage>): string | undefined {\n\tif (!message || message.role !== \"assistant\") return undefined;\n\treturn message.errorMessage;\n}\n\ninterface ThrottledEmitter {\n\temit: () => void;\n\t/** Drops any pending timer so nothing fires after the run has settled. */\n\tcancel: () => void;\n}\n\nfunction createThrottledEmitter(onProgress: (() => void) | undefined): ThrottledEmitter {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\treturn {\n\t\temit: () => {\n\t\t\tif (!onProgress || timer) return;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\ttimer = undefined;\n\t\t\t\tonProgress();\n\t\t\t}, 80);\n\t\t},\n\t\tcancel: () => {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t},\n\t};\n}\n\ntype InitializationOutcome =\n\t| { kind: \"created\"; session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] }\n\t| { kind: \"aborted\" }\n\t| { kind: \"error\"; error: unknown };\n\n// Neither resource loading nor session creation takes an abort signal, and\n// both can hang on network work; race both against the scope. The losing\n// chain keeps running, so its eventual result or rejection is always\n// consumed by a no-op handler.\nasync function raceInitialization(\n\tchain: Promise<InitializationOutcome>,\n\tscope: RunCancellation,\n): Promise<InitializationOutcome> {\n\treturn new Promise<InitializationOutcome>((resolve) => {\n\t\tlet settled = false;\n\t\tconst finish = (outcome: InitializationOutcome): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tscope.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve(outcome);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\tfinish({ kind: \"aborted\" });\n\t\t};\n\t\tif (scope.signal.aborted) {\n\t\t\tonAbort();\n\t\t\tvoid chain.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tscope.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid chain.then(\n\t\t\t(outcome) => finish(outcome),\n\t\t\t(error) => finish({ kind: \"error\", error }),\n\t\t);\n\t});\n}\n\n/**\n * Runs one worker attempt as a pure adapter: it owns the worker session's\n * lifecycle and translates AgentSessionEvents into SubagentRunEvents; every\n * state transition happens in the reducer on the other side of dispatch.\n */\nexport async function runSdkTask(options: SdkRunnerOptions): Promise<void> {\n\tconst { task, scope, dispatch, modelRuntime, agentDir, projectTrusted, onProgress } = options;\n\tconst throttled = createThrottledEmitter(onProgress);\n\tlet unsubscribe: (() => void) | undefined;\n\tlet unregisterAbort: (() => void) | undefined;\n\tlet session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] | undefined;\n\t// Streaming updates carry no semantic weight; the settled messages are\n\t// where usage is accounted, and worker sessions can replay them.\n\tconst seenAssistantMessages = new Set<unknown>();\n\tconst emitImmediate = (): void => onProgress?.();\n\tconst emitThrottled = throttled.emit;\n\n\tunregisterAbort = scope.onAbort(async () => {\n\t\tif (session) await session.abort();\n\t});\n\n\ttry {\n\t\tif (scope.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted before it started.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsManager = SettingsManager.create(task.cwd, agentDir, { projectTrusted });\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: task.cwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tnoExtensions: true,\n\t\t\tnoSkills: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t\t// Read-only explorers skip AGENTS.md/CLAUDE.md: they don't need\n\t\t\t// commit/PR/style rules, and the parent interprets their results.\n\t\t\tnoContextFiles: task.agent.omitContextFiles ?? false,\n\t\t\tsystemPromptOverride: (base) => workerSystemPrompt(base, task),\n\t\t});\n\t\tconst initialization = (async (): Promise<InitializationOutcome> => {\n\t\t\tawait resourceLoader.reload();\n\t\t\tif (scope.signal.aborted) return { kind: \"aborted\" };\n\t\t\tconst created = await createAgentSession({\n\t\t\t\tcwd: task.cwd,\n\t\t\t\tagentDir,\n\t\t\t\tmodelRuntime,\n\t\t\t\tmodel: task.model,\n\t\t\t\tthinkingLevel: task.thinking,\n\t\t\t\ttools: task.agent.tools,\n\t\t\t\tresourceLoader,\n\t\t\t\tsessionManager: SessionManager.inMemory(task.cwd),\n\t\t\t\tsettingsManager,\n\t\t\t});\n\t\t\treturn { kind: \"created\", session: created.session };\n\t\t})();\n\t\tconst outcome = await raceInitialization(initialization, scope);\n\t\tif (outcome.kind === \"error\") throw outcome.error;\n\t\tif (outcome.kind === \"aborted\") {\n\t\t\t// The initialization chain cannot be cancelled. Dispose the\n\t\t\t// session if it eventually resolves, and swallow a late rejection\n\t\t\t// after this run has already settled.\n\t\t\tvoid initialization.then(\n\t\t\t\t(late) => {\n\t\t\t\t\tif (late.kind === \"created\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlate.session.dispose();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// The aborted run has no remaining channel for cleanup errors.\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tsession = outcome.session;\n\t\tif (scope.aborted) {\n\t\t\tawait session.abort();\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tunsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\tif (event.type === \"auto_retry_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"auto_retry_start\",\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tdeadline: Date.now() + event.delayMs,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"auto_retry_end\") {\n\t\t\t\tdispatch({ type: \"auto_retry_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"turn_end\") {\n\t\t\t\tdispatch({ type: \"turn_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"compaction_start\") {\n\t\t\t\tdispatch({ type: \"compaction_started\", startedAt: Date.now() });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"compaction_end\") {\n\t\t\t\t// A worker has no status line of its own, so the compaction's outcome —\n\t\t\t\t// especially the reason a failed one blocks the next request — only\n\t\t\t\t// reaches the caller through the activity log.\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"compaction_ended\",\n\t\t\t\t\ttokensBefore: event.result?.tokensBefore,\n\t\t\t\t\ttokensAfter: event.result?.estimatedTokensAfter,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\tif (!seenAssistantMessages.has(event.message)) {\n\t\t\t\t\tseenAssistantMessages.add(event.message);\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: event.message.usage });\n\t\t\t\t} else {\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: undefined });\n\t\t\t\t}\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_started\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_update\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_updated\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t});\n\t\t\t\temitThrottled();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_ended\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t}\n\t\t});\n\t\tawait session.prompt(task.prompt);\n\t\tconst finalMessage = lastAssistantMessage(session);\n\t\tconst report = finalAssistantText(session.messages);\n\t\tconst error = assistantError(finalMessage);\n\t\tif (scope.signal.aborted || finalMessage?.stopReason === \"aborted\") {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else if (finalMessage?.stopReason === \"error\" || error) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent failed.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({ type: \"settle\", verdict: \"completed\", report, error: undefined, endedAt: Date.now() });\n\t\t}\n\t} catch (error) {\n\t\tconst report = session ? finalAssistantText(session.messages) : \"\";\n\t\tif (scope.signal.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tthrottled.cancel();\n\t\tunregisterAbort?.();\n\t\tunsubscribe?.();\n\t\tsession?.dispose();\n\t\temitImmediate();\n\t}\n}\n"]}
@@ -51,6 +51,15 @@ export type SubagentRunEvent = {
51
51
  result: unknown;
52
52
  isError: boolean;
53
53
  endedAt: number;
54
+ } | {
55
+ type: "compaction_started";
56
+ startedAt: number;
57
+ } | {
58
+ type: "compaction_ended";
59
+ tokensBefore: number | undefined;
60
+ tokensAfter: number | undefined;
61
+ error: string | undefined;
62
+ endedAt: number;
54
63
  } | {
55
64
  type: "settle";
56
65
  verdict: "completed" | "failed" | "aborted";
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAWnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1G;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC3D,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,oEAAoE;AACpE,MAAM,MAAM,gBAAgB,GACzB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC5C;IACA,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO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,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAUvF;AAqBD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAmJ5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAIpE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,kBAAkB,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CASvF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG,OAAO,CAK1F;AAiBD,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAE9D;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,SAAa,GAAG,iBAAiB,GAAG,SAAS,CAY7G"}
@@ -1,6 +1,6 @@
1
1
  import { relative } from "node:path";
2
- import { activitySummary, addUsage, emptyUsage, resultSummary } from "./activity.js";
3
- import { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, ERROR_TEXT_LIMIT, RETRY_ERROR_TEXT_LIMIT, TASK_OUTPUT_LIMIT, } from "./constants.js";
2
+ import { activitySummary, addUsage, compactionError, compactionSummary, emptyUsage, resultSummary, } from "./activity.js";
3
+ import { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, COMPACTION_ACTIVITY_ID, ERROR_TEXT_LIMIT, RETRY_ERROR_TEXT_LIMIT, TASK_OUTPUT_LIMIT, } from "./constants.js";
4
4
  import { modelId } from "./model-selection.js";
5
5
  import { boundText } from "./text.js";
6
6
  function runId(batchId, index) {
@@ -200,6 +200,37 @@ export function reduceRun(state, event) {
200
200
  }
201
201
  draft.currentActivity = deriveCurrentActivity(draft);
202
202
  });
203
+ case "compaction_started":
204
+ // Auto-compaction is a synthetic activity: it has a start, an end and a
205
+ // failure mode just like a tool call, so it reuses the activity log and its
206
+ // budgets. It is not a tool call, so it never counts toward toolUses.
207
+ return withRevision(state, (draft) => {
208
+ clearRetry(draft);
209
+ appendActivity(draft.activities, {
210
+ id: COMPACTION_ACTIVITY_ID,
211
+ toolName: COMPACTION_ACTIVITY_ID,
212
+ summary: "Compacting context…",
213
+ status: "running",
214
+ startedAt: event.startedAt,
215
+ });
216
+ draft.currentActivity = deriveCurrentActivity(draft);
217
+ });
218
+ case "compaction_ended":
219
+ return withRevision(state, (draft) => {
220
+ clearRetry(draft);
221
+ // Only one compaction runs at a time, so the newest running entry with
222
+ // this id is always the one that just ended.
223
+ const activity = [...draft.activities]
224
+ .reverse()
225
+ .find((candidate) => candidate.id === COMPACTION_ACTIVITY_ID && candidate.status === "running");
226
+ if (activity) {
227
+ activity.status = event.error ? "failed" : "succeeded";
228
+ activity.endedAt = event.endedAt;
229
+ activity.summary = compactionSummary(event.tokensBefore, event.tokensAfter);
230
+ activity.resultSummary = event.error ? compactionError(event.error) : undefined;
231
+ }
232
+ draft.currentActivity = deriveCurrentActivity(draft);
233
+ });
203
234
  case "settle":
204
235
  return withRevision(state, (draft) => {
205
236
  draft.status = event.verdict;
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/extensions/subagent/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,gBAAgB,CAAC;AACxB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AAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IAChE,OAAO;QACN,OAAO;QACP,WAAW;QACX,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/E,KAAK,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC","sourcesContent":["import { relative } from \"node:path\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport { activitySummary, addUsage, emptyUsage, resultSummary } from \"./activity.ts\";\nimport {\n\tACTIVITY_LIMIT,\n\tACTIVITY_TEXT_LIMIT,\n\tERROR_TEXT_LIMIT,\n\tRETRY_ERROR_TEXT_LIMIT,\n\tTASK_OUTPUT_LIMIT,\n} from \"./constants.ts\";\nimport { modelId } from \"./model-selection.ts\";\nimport { boundText } from \"./text.ts\";\nimport type { ResolvedSubagentTask, SubagentDetails, SubagentRunDetails, ToolActivity } from \"./types.ts\";\n\n/**\n * Mutable-run state plus an internal revision counter. All transitions go\n * through {@link reduceRun}; the batch runner compares version sums instead\n * of diffing rendered fields.\n */\nexport interface SubagentRunState extends SubagentRunDetails {\n\t/** Monotonic per-run revision; bumped by every applied event. */\n\tversion: number;\n}\n\n/** The adapter layer's only output and the reducer's only input. */\nexport type SubagentRunEvent =\n\t| { type: \"slot_acquired\"; startedAt: number }\n\t| {\n\t\t\ttype: \"retry_scheduled\";\n\t\t\tattempt: number;\n\t\t\tmaxAttempts: number;\n\t\t\tdeadline: number;\n\t\t\terror: string | undefined;\n\t }\n\t| { type: \"retry_started\" }\n\t| { type: \"auto_retry_start\"; attempt: number; maxAttempts: number; deadline: number; error: string }\n\t| { type: \"auto_retry_end\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"assistant_message_settled\"; usage: Usage | undefined }\n\t| { type: \"tool_started\"; toolCallId: string; toolName: string; args: unknown; startedAt: number }\n\t| { type: \"tool_updated\"; toolCallId: string; toolName: string; args: unknown }\n\t| { type: \"tool_ended\"; toolCallId: string; result: unknown; isError: boolean; endedAt: number }\n\t| {\n\t\t\ttype: \"settle\";\n\t\t\tverdict: \"completed\" | \"failed\" | \"aborted\";\n\t\t\treport: string;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| { type: \"abort_while_queued\"; endedAt: number }\n\t| { type: \"abort_while_retrying\"; endedAt: number };\n\nfunction runId(batchId: string | undefined, index: number): string {\n\tif (!batchId) return `subagent-${index + 1}`;\n\t// toolCallIds are provider-shaped (\"call_ABC...\"); keep the readable\n\t// prefix, then disambiguate truncated collisions with a deterministic\n\t// hash of the full id.\n\tconst sanitized = batchId.replace(/[^A-Za-z0-9-]+/gu, \"-\").replace(/^-+|-+$/gu, \"\");\n\tconst hash = hashRunId(batchId);\n\tconst prefix = sanitized.length > 24 ? `${sanitized.slice(0, 24)}-${hash}` : sanitized || `run-${hash}`;\n\treturn `${prefix}-${index + 1}`;\n}\n\nfunction hashRunId(value: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < value.length; index++) {\n\t\thash ^= value.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36).padStart(6, \"0\").slice(0, 6);\n}\n\nexport function createRunState(\n\ttask: ResolvedSubagentTask,\n\tindex: number,\n\tbatchId: string | undefined,\n\tparentCwd: string,\n): SubagentRunState {\n\treturn {\n\t\tid: runId(batchId, index),\n\t\tagent: task.agent.name,\n\t\tdescription: task.description,\n\t\t// Display-only relative path; the worker session itself uses the\n\t\t// resolved absolute task.cwd. Empty means \"same as the parent\".\n\t\tcwd: relative(parentCwd, task.cwd),\n\t\tmodel: modelId(task.model),\n\t\tthinking: task.thinking,\n\t\tstatus: \"queued\",\n\t\tactivities: [],\n\t\treport: \"\",\n\t\tusage: emptyUsage(),\n\t\tversion: 0,\n\t};\n}\n\n/** Strips internal fields for projection into the public details shape. */\nexport function toRunDetails(state: SubagentRunState): SubagentRunDetails {\n\tconst { version: _version, ...details } = state;\n\treturn details;\n}\n\n// The live \"current activity\" line is derived, never imperative: a pending\n// retry wins, then the most recent still-running tool. This is what keeps a\n// parallel batch's line correct when tools end out of order.\nexport function deriveCurrentActivity(state: SubagentRunState): string | undefined {\n\tif (state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\") return undefined;\n\tif (state.retry) return `Retrying (${state.retry.attempt}/${state.retry.maxAttempts})…`;\n\tfor (let index = state.activities.length - 1; index >= 0; index--) {\n\t\tconst activity = state.activities[index];\n\t\tif (activity?.status === \"running\") return activity.summary;\n\t}\n\treturn undefined;\n}\n\nfunction positiveInteger(value: number, fallback: number): number {\n\treturn Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;\n}\n\nfunction retryError(error: string): string {\n\tconst normalized = error.replace(/\\s+/gu, \" \").trim();\n\treturn boundText(normalized, RETRY_ERROR_TEXT_LIMIT).replace(/\\s+/gu, \" \").trim();\n}\n\nfunction makeRetry(attempt: number, maxAttempts: number, deadline: number, error: string): SubagentRunState[\"retry\"] {\n\tconst normalizedAttempt = positiveInteger(attempt, 1);\n\treturn {\n\t\tattempt: normalizedAttempt,\n\t\tmaxAttempts: Math.max(normalizedAttempt, positiveInteger(maxAttempts, normalizedAttempt)),\n\t\tdeadline,\n\t\terror: retryError(error),\n\t};\n}\n\n// The in-memory activity log keeps the newest entries within both the count\n// and text budgets; a bounded O(ACTIVITY_LIMIT) rescan per event replaces\n// incremental byte bookkeeping. Exported for direct budget tests: real\n// events bound every summary, so the text-budget eviction is otherwise\n// purely defensive.\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nfunction isTerminal(state: SubagentRunState): boolean {\n\treturn state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\";\n}\n\nfunction withRevision(state: SubagentRunState, mutate: (draft: SubagentRunState) => void): SubagentRunState {\n\tconst draft: SubagentRunState = {\n\t\t...state,\n\t\tactivities: state.activities.map((activity) => ({ ...activity })),\n\t\tusage: { ...state.usage },\n\t};\n\tmutate(draft);\n\tdraft.version = state.version + 1;\n\treturn draft;\n}\n\nfunction clearRetry(draft: SubagentRunState): void {\n\tdraft.retry = undefined;\n}\n\n/**\n * Pure transition function; timestamps and deadlines arrive in the event.\n * Events applied after a terminal verdict are ignored (settle is idempotent)\n * — except retry_scheduled, the one sanctioned reopening transition.\n */\nexport function reduceRun(state: SubagentRunState, event: SubagentRunEvent): SubagentRunState {\n\tif (isTerminal(state) && event.type !== \"retry_scheduled\") return state;\n\n\tswitch (event.type) {\n\t\tcase \"slot_acquired\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.status = \"running\";\n\t\t\t\tdraft.startedAt = event.startedAt;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_scheduled\":\n\t\t\t// The full reset matrix from the historical resetRunForRetry: only\n\t\t\t// runs that produced nothing are retried, so nothing of value is\n\t\t\t// discarded. The retry view stays visible through the backoff.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tconst error = draft.error ?? \"Subagent failed before retry.\";\n\t\t\t\tdraft.status = \"queued\";\n\t\t\t\tdraft.error = undefined;\n\t\t\t\tdraft.startedAt = undefined;\n\t\t\t\tdraft.endedAt = undefined;\n\t\t\t\tdraft.report = \"\";\n\t\t\t\tdraft.activities = [];\n\t\t\t\tdraft.usage = emptyUsage();\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_start\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, event.error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"turn_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.turns++;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"assistant_message_settled\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\taddUsage(draft.usage, event.usage);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.toolUses++;\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\tsummary: activitySummary(event.toolName, event.args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_updated\": {\n\t\t\tconst summary = activitySummary(event.toolName, event.args);\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity =\n\t\t\t\t\tdraft.activities.find(\n\t\t\t\t\t\t(candidate) => candidate.id === event.toolCallId && candidate.status === \"running\",\n\t\t\t\t\t) ?? [...draft.activities].reverse().find((candidate) => candidate.status === \"running\");\n\t\t\t\tif (activity) activity.summary = summary;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\t}\n\t\tcase \"tool_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity = draft.activities.find((candidate) => candidate.id === event.toolCallId);\n\t\t\t\tif (activity && activity.status === \"running\") {\n\t\t\t\t\tactivity.status = event.isError ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.resultSummary = resultSummary(event.result) || undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"settle\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = event.verdict;\n\t\t\t\tdraft.report = boundText(event.report, TASK_OUTPUT_LIMIT);\n\t\t\t\tdraft.error = event.error ? boundText(event.error, ERROR_TEXT_LIMIT) : undefined;\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity({ ...draft, status: event.verdict });\n\t\t\t});\n\t\tcase \"abort_while_queued\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while queued.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t\tcase \"abort_while_retrying\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while waiting to retry.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t}\n}\n\nexport function versionSum(runs: readonly SubagentRunState[]): number {\n\tlet total = 0;\n\tfor (const run of runs) total += run.version;\n\treturn total;\n}\n\nexport function statusOf(runs: readonly SubagentRunDetails[]): SubagentDetails[\"status\"] {\n\tif (runs.length === 0) return \"running\";\n\t// Active beats terminal: any queued or running run keeps the batch\n\t// \"running\" regardless of what the others have settled to.\n\tif (runs.some((run) => run.status === \"queued\" || run.status === \"running\")) return \"running\";\n\tif (runs.every((run) => run.status === \"completed\")) return \"completed\";\n\tif (runs.some((run) => run.status === \"completed\")) return \"partial\";\n\tif (runs.every((run) => run.status === \"aborted\")) return \"aborted\";\n\treturn \"failed\";\n}\n\nexport function isSubagentError(details: Pick<SubagentDetails, \"status\" | \"runs\">): boolean {\n\tif (details.status !== \"failed\" && details.status !== \"aborted\") return false;\n\t// A batch with any successful run is a partial result, not an error:\n\t// per-run status is already reported in the content sections.\n\treturn !details.runs.some((run) => run.status === \"completed\");\n}\n\nfunction statusText(details: SubagentDetails): string {\n\tif (details.runs.length === 0) return \"Initializing…\";\n\tconst running = details.runs.filter((run) => run.status === \"running\").length;\n\tconst queued = details.runs.filter((run) => run.status === \"queued\").length;\n\tconst completed = details.runs.filter((run) => run.status === \"completed\").length;\n\tconst failed = details.runs.filter((run) => run.status === \"failed\").length;\n\tconst aborted = details.runs.filter((run) => run.status === \"aborted\").length;\n\tconst parts = [`${completed}/${details.runs.length} complete`];\n\tif (running) parts.push(`${running} running`);\n\tif (queued) parts.push(`${queued} queued`);\n\tif (failed) parts.push(`${failed} failed`);\n\tif (aborted) parts.push(`${aborted} aborted`);\n\treturn parts.join(\" · \");\n}\n\nexport function statusSummary(details: SubagentDetails): string {\n\treturn statusText(details);\n}\n\nexport interface SubagentRetryView {\n\tattempt: number;\n\tmaxAttempts: number;\n\tremainingSeconds: number;\n\terror: string;\n}\n\nexport function getSubagentRetryView(run: SubagentRunDetails, now = Date.now()): SubagentRetryView | undefined {\n\tconst retry = run.retry;\n\tif (!retry || !Number.isFinite(retry.deadline)) return undefined;\n\tconst attempt = positiveInteger(retry.attempt, 1);\n\tconst maxAttempts = Math.max(attempt, positiveInteger(retry.maxAttempts, attempt));\n\tconst currentTime = Number.isFinite(now) ? now : retry.deadline;\n\treturn {\n\t\tattempt,\n\t\tmaxAttempts,\n\t\tremainingSeconds: Math.max(0, Math.ceil((retry.deadline - currentTime) / 1000)),\n\t\terror: retryError(typeof retry.error === \"string\" ? retry.error : \"\"),\n\t};\n}\n"]}
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/extensions/subagent/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EACN,eAAe,EACf,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAiDtC,SAAS,KAAK,CAAC,OAA2B,EAAE,KAAa;IACxD,IAAI,CAAC,OAAO;QAAE,OAAO,YAAY,KAAK,GAAG,CAAC,EAAE,CAAC;IAC7C,qEAAqE;IACrE,sEAAsE;IACtE,uBAAuB;IACvB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACpF,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,C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KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC","sourcesContent":["import { relative } from \"node:path\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport {\n\tactivitySummary,\n\taddUsage,\n\tcompactionError,\n\tcompactionSummary,\n\temptyUsage,\n\tresultSummary,\n} from \"./activity.ts\";\nimport {\n\tACTIVITY_LIMIT,\n\tACTIVITY_TEXT_LIMIT,\n\tCOMPACTION_ACTIVITY_ID,\n\tERROR_TEXT_LIMIT,\n\tRETRY_ERROR_TEXT_LIMIT,\n\tTASK_OUTPUT_LIMIT,\n} from \"./constants.ts\";\nimport { modelId } from \"./model-selection.ts\";\nimport { boundText } from \"./text.ts\";\nimport type { ResolvedSubagentTask, SubagentDetails, SubagentRunDetails, ToolActivity } from \"./types.ts\";\n\n/**\n * Mutable-run state plus an internal revision counter. All transitions go\n * through {@link reduceRun}; the batch runner compares version sums instead\n * of diffing rendered fields.\n */\nexport interface SubagentRunState extends SubagentRunDetails {\n\t/** Monotonic per-run revision; bumped by every applied event. */\n\tversion: number;\n}\n\n/** The adapter layer's only output and the reducer's only input. */\nexport type SubagentRunEvent =\n\t| { type: \"slot_acquired\"; startedAt: number }\n\t| {\n\t\t\ttype: \"retry_scheduled\";\n\t\t\tattempt: number;\n\t\t\tmaxAttempts: number;\n\t\t\tdeadline: number;\n\t\t\terror: string | undefined;\n\t }\n\t| { type: \"retry_started\" }\n\t| { type: \"auto_retry_start\"; attempt: number; maxAttempts: number; deadline: number; error: string }\n\t| { type: \"auto_retry_end\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"assistant_message_settled\"; usage: Usage | undefined }\n\t| { type: \"tool_started\"; toolCallId: string; toolName: string; args: unknown; startedAt: number }\n\t| { type: \"tool_updated\"; toolCallId: string; toolName: string; args: unknown }\n\t| { type: \"tool_ended\"; toolCallId: string; result: unknown; isError: boolean; endedAt: number }\n\t| { type: \"compaction_started\"; startedAt: number }\n\t| {\n\t\t\ttype: \"compaction_ended\";\n\t\t\ttokensBefore: number | undefined;\n\t\t\ttokensAfter: number | undefined;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| {\n\t\t\ttype: \"settle\";\n\t\t\tverdict: \"completed\" | \"failed\" | \"aborted\";\n\t\t\treport: string;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| { type: \"abort_while_queued\"; endedAt: number }\n\t| { type: \"abort_while_retrying\"; endedAt: number };\n\nfunction runId(batchId: string | undefined, index: number): string {\n\tif (!batchId) return `subagent-${index + 1}`;\n\t// toolCallIds are provider-shaped (\"call_ABC...\"); keep the readable\n\t// prefix, then disambiguate truncated collisions with a deterministic\n\t// hash of the full id.\n\tconst sanitized = batchId.replace(/[^A-Za-z0-9-]+/gu, \"-\").replace(/^-+|-+$/gu, \"\");\n\tconst hash = hashRunId(batchId);\n\tconst prefix = sanitized.length > 24 ? `${sanitized.slice(0, 24)}-${hash}` : sanitized || `run-${hash}`;\n\treturn `${prefix}-${index + 1}`;\n}\n\nfunction hashRunId(value: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < value.length; index++) {\n\t\thash ^= value.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36).padStart(6, \"0\").slice(0, 6);\n}\n\nexport function createRunState(\n\ttask: ResolvedSubagentTask,\n\tindex: number,\n\tbatchId: string | undefined,\n\tparentCwd: string,\n): SubagentRunState {\n\treturn {\n\t\tid: runId(batchId, index),\n\t\tagent: task.agent.name,\n\t\tdescription: task.description,\n\t\t// Display-only relative path; the worker session itself uses the\n\t\t// resolved absolute task.cwd. Empty means \"same as the parent\".\n\t\tcwd: relative(parentCwd, task.cwd),\n\t\tmodel: modelId(task.model),\n\t\tthinking: task.thinking,\n\t\tstatus: \"queued\",\n\t\tactivities: [],\n\t\treport: \"\",\n\t\tusage: emptyUsage(),\n\t\tversion: 0,\n\t};\n}\n\n/** Strips internal fields for projection into the public details shape. */\nexport function toRunDetails(state: SubagentRunState): SubagentRunDetails {\n\tconst { version: _version, ...details } = state;\n\treturn details;\n}\n\n// The live \"current activity\" line is derived, never imperative: a pending\n// retry wins, then the most recent still-running tool. This is what keeps a\n// parallel batch's line correct when tools end out of order.\nexport function deriveCurrentActivity(state: SubagentRunState): string | undefined {\n\tif (state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\") return undefined;\n\tif (state.retry) return `Retrying (${state.retry.attempt}/${state.retry.maxAttempts})…`;\n\tfor (let index = state.activities.length - 1; index >= 0; index--) {\n\t\tconst activity = state.activities[index];\n\t\tif (activity?.status === \"running\") return activity.summary;\n\t}\n\treturn undefined;\n}\n\nfunction positiveInteger(value: number, fallback: number): number {\n\treturn Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;\n}\n\nfunction retryError(error: string): string {\n\tconst normalized = error.replace(/\\s+/gu, \" \").trim();\n\treturn boundText(normalized, RETRY_ERROR_TEXT_LIMIT).replace(/\\s+/gu, \" \").trim();\n}\n\nfunction makeRetry(attempt: number, maxAttempts: number, deadline: number, error: string): SubagentRunState[\"retry\"] {\n\tconst normalizedAttempt = positiveInteger(attempt, 1);\n\treturn {\n\t\tattempt: normalizedAttempt,\n\t\tmaxAttempts: Math.max(normalizedAttempt, positiveInteger(maxAttempts, normalizedAttempt)),\n\t\tdeadline,\n\t\terror: retryError(error),\n\t};\n}\n\n// The in-memory activity log keeps the newest entries within both the count\n// and text budgets; a bounded O(ACTIVITY_LIMIT) rescan per event replaces\n// incremental byte bookkeeping. Exported for direct budget tests: real\n// events bound every summary, so the text-budget eviction is otherwise\n// purely defensive.\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nfunction isTerminal(state: SubagentRunState): boolean {\n\treturn state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\";\n}\n\nfunction withRevision(state: SubagentRunState, mutate: (draft: SubagentRunState) => void): SubagentRunState {\n\tconst draft: SubagentRunState = {\n\t\t...state,\n\t\tactivities: state.activities.map((activity) => ({ ...activity })),\n\t\tusage: { ...state.usage },\n\t};\n\tmutate(draft);\n\tdraft.version = state.version + 1;\n\treturn draft;\n}\n\nfunction clearRetry(draft: SubagentRunState): void {\n\tdraft.retry = undefined;\n}\n\n/**\n * Pure transition function; timestamps and deadlines arrive in the event.\n * Events applied after a terminal verdict are ignored (settle is idempotent)\n * — except retry_scheduled, the one sanctioned reopening transition.\n */\nexport function reduceRun(state: SubagentRunState, event: SubagentRunEvent): SubagentRunState {\n\tif (isTerminal(state) && event.type !== \"retry_scheduled\") return state;\n\n\tswitch (event.type) {\n\t\tcase \"slot_acquired\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.status = \"running\";\n\t\t\t\tdraft.startedAt = event.startedAt;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_scheduled\":\n\t\t\t// The full reset matrix from the historical resetRunForRetry: only\n\t\t\t// runs that produced nothing are retried, so nothing of value is\n\t\t\t// discarded. The retry view stays visible through the backoff.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tconst error = draft.error ?? \"Subagent failed before retry.\";\n\t\t\t\tdraft.status = \"queued\";\n\t\t\t\tdraft.error = undefined;\n\t\t\t\tdraft.startedAt = undefined;\n\t\t\t\tdraft.endedAt = undefined;\n\t\t\t\tdraft.report = \"\";\n\t\t\t\tdraft.activities = [];\n\t\t\t\tdraft.usage = emptyUsage();\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_start\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, event.error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"turn_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.turns++;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"assistant_message_settled\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\taddUsage(draft.usage, event.usage);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.toolUses++;\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\tsummary: activitySummary(event.toolName, event.args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_updated\": {\n\t\t\tconst summary = activitySummary(event.toolName, event.args);\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity =\n\t\t\t\t\tdraft.activities.find(\n\t\t\t\t\t\t(candidate) => candidate.id === event.toolCallId && candidate.status === \"running\",\n\t\t\t\t\t) ?? [...draft.activities].reverse().find((candidate) => candidate.status === \"running\");\n\t\t\t\tif (activity) activity.summary = summary;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\t}\n\t\tcase \"tool_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity = draft.activities.find((candidate) => candidate.id === event.toolCallId);\n\t\t\t\tif (activity && activity.status === \"running\") {\n\t\t\t\t\tactivity.status = event.isError ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.resultSummary = resultSummary(event.result) || undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"compaction_started\":\n\t\t\t// Auto-compaction is a synthetic activity: it has a start, an end and a\n\t\t\t// failure mode just like a tool call, so it reuses the activity log and its\n\t\t\t// budgets. It is not a tool call, so it never counts toward toolUses.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: COMPACTION_ACTIVITY_ID,\n\t\t\t\t\ttoolName: COMPACTION_ACTIVITY_ID,\n\t\t\t\t\tsummary: \"Compacting context…\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"compaction_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\t// Only one compaction runs at a time, so the newest running entry with\n\t\t\t\t// this id is always the one that just ended.\n\t\t\t\tconst activity = [...draft.activities]\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((candidate) => candidate.id === COMPACTION_ACTIVITY_ID && candidate.status === \"running\");\n\t\t\t\tif (activity) {\n\t\t\t\t\tactivity.status = event.error ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.summary = compactionSummary(event.tokensBefore, event.tokensAfter);\n\t\t\t\t\tactivity.resultSummary = event.error ? compactionError(event.error) : undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"settle\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = event.verdict;\n\t\t\t\tdraft.report = boundText(event.report, TASK_OUTPUT_LIMIT);\n\t\t\t\tdraft.error = event.error ? boundText(event.error, ERROR_TEXT_LIMIT) : undefined;\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity({ ...draft, status: event.verdict });\n\t\t\t});\n\t\tcase \"abort_while_queued\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while queued.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t\tcase \"abort_while_retrying\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while waiting to retry.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t}\n}\n\nexport function versionSum(runs: readonly SubagentRunState[]): number {\n\tlet total = 0;\n\tfor (const run of runs) total += run.version;\n\treturn total;\n}\n\nexport function statusOf(runs: readonly SubagentRunDetails[]): SubagentDetails[\"status\"] {\n\tif (runs.length === 0) return \"running\";\n\t// Active beats terminal: any queued or running run keeps the batch\n\t// \"running\" regardless of what the others have settled to.\n\tif (runs.some((run) => run.status === \"queued\" || run.status === \"running\")) return \"running\";\n\tif (runs.every((run) => run.status === \"completed\")) return \"completed\";\n\tif (runs.some((run) => run.status === \"completed\")) return \"partial\";\n\tif (runs.every((run) => run.status === \"aborted\")) return \"aborted\";\n\treturn \"failed\";\n}\n\nexport function isSubagentError(details: Pick<SubagentDetails, \"status\" | \"runs\">): boolean {\n\tif (details.status !== \"failed\" && details.status !== \"aborted\") return false;\n\t// A batch with any successful run is a partial result, not an error:\n\t// per-run status is already reported in the content sections.\n\treturn !details.runs.some((run) => run.status === \"completed\");\n}\n\nfunction statusText(details: SubagentDetails): string {\n\tif (details.runs.length === 0) return \"Initializing…\";\n\tconst running = details.runs.filter((run) => run.status === \"running\").length;\n\tconst queued = details.runs.filter((run) => run.status === \"queued\").length;\n\tconst completed = details.runs.filter((run) => run.status === \"completed\").length;\n\tconst failed = details.runs.filter((run) => run.status === \"failed\").length;\n\tconst aborted = details.runs.filter((run) => run.status === \"aborted\").length;\n\tconst parts = [`${completed}/${details.runs.length} complete`];\n\tif (running) parts.push(`${running} running`);\n\tif (queued) parts.push(`${queued} queued`);\n\tif (failed) parts.push(`${failed} failed`);\n\tif (aborted) parts.push(`${aborted} aborted`);\n\treturn parts.join(\" · \");\n}\n\nexport function statusSummary(details: SubagentDetails): string {\n\treturn statusText(details);\n}\n\nexport interface SubagentRetryView {\n\tattempt: number;\n\tmaxAttempts: number;\n\tremainingSeconds: number;\n\terror: string;\n}\n\nexport function getSubagentRetryView(run: SubagentRunDetails, now = Date.now()): SubagentRetryView | undefined {\n\tconst retry = run.retry;\n\tif (!retry || !Number.isFinite(retry.deadline)) return undefined;\n\tconst attempt = positiveInteger(retry.attempt, 1);\n\tconst maxAttempts = Math.max(attempt, positiveInteger(retry.maxAttempts, attempt));\n\tconst currentTime = Number.isFinite(now) ? now : retry.deadline;\n\treturn {\n\t\tattempt,\n\t\tmaxAttempts,\n\t\tremainingSeconds: Math.max(0, Math.ceil((retry.deadline - currentTime) / 1000)),\n\t\terror: retryError(typeof retry.error === \"string\" ? retry.error : \"\"),\n\t};\n}\n"]}
@@ -10,7 +10,7 @@ export declare const TODO_MAX_BATCH_ITEMS = 20;
10
10
  /** Input limits keep task snapshots and model-facing output bounded. */
11
11
  export declare const TODO_MAX_SUBJECT_LENGTH = 160;
12
12
  export declare const TODO_MAX_DESCRIPTION_LENGTH = 500;
13
- export declare const TODO_TOOL_DESCRIPTION = "Manage the conversation's task list for multi-step coding work.\n\n## When to Use\n- Work with three or more meaningful steps, a user-provided task list, or a long session where progress can drift\n- Capture new user requirements as tasks right away; after completing a task, add follow-up tasks discovered during implementation\n\n## When NOT to Use\n- Trivial single-step tasks and simple Q&A \u2014 just do the work\n\n## Actions\n- create: atomically add one or many pending tasks from the ordered items array (1 to 20 items); each item needs a short imperative subject and a description of what done means\n- update: edit one task by id \u2014 subject, description, or status; all transitions and reopens are allowed\n- list: show every remaining task with its description, active first\n- delete: remove obsolete tasks by ids (1 to 20, duplicates ignored)\n- The current list holds at most 20 tasks; parameters that do not apply to the chosen action are rejected\n\n## Status Workflow\npending -> in_progress -> completed. Keep exactly one task in_progress: marking one active demotes any other active task to pending. Mark a task in_progress BEFORE starting the work, and completed only when its description is satisfied and relevant checks pass; never with failing tests or partial work. Reopen instead of duplicating. When blocked, do not fake completion: return the task to pending, create a task for the blocker, and finish the blocker first.\n\n## Examples\n{\"action\": \"create\", \"items\": [{\"subject\": \"Wire parser\", \"description\": \"Parser handles the config format\"}, {\"subject\": \"Test parser\", \"description\": \"Parser tests pass\"}]}\n{\"action\": \"update\", \"id\": 2, \"status\": \"in_progress\"}\n{\"action\": \"update\", \"id\": 2, \"status\": \"completed\", \"description\": \"Parser verified against config fixtures\"}\n{\"action\": \"delete\", \"ids\": [3]}\n\n## Tips\n- list before create to avoid duplicates; prefer working in id order \u2014 earlier tasks usually set up context for later ones\n- delete obsolete tasks promptly so the list stays short and accurate";
13
+ export declare const TODO_TOOL_DESCRIPTION = "Manage the conversation's task list for multi-step coding work. create atomically adds pending tasks; update edits one task by id and requires at least one of subject, description, or status; list returns every remaining task with its description, active first; delete removes tasks by ids. The list holds at most 20 tasks including completed ones, and ids are never reused. Exactly one task may be in_progress, so setting one demotes any other active task to pending; any transition is allowed, including reopening a completed task. A call that fails validation, including a delete naming an id that does not exist, leaves the list unchanged.\n\n{\"action\": \"create\", \"items\": [{\"subject\": \"Wire parser\", \"description\": \"Parser handles the config format\"}, {\"subject\": \"Test parser\", \"description\": \"Parser tests pass\"}]}\n{\"action\": \"update\", \"id\": 2, \"status\": \"in_progress\"}\n{\"action\": \"update\", \"id\": 2, \"status\": \"completed\", \"description\": \"Parser verified against config fixtures\"}\n{\"action\": \"delete\", \"ids\": [3]}";
14
14
  export declare const TODO_PROMPT_SNIPPET = "Track multi-step coding work with a small outcome-oriented task list";
15
15
  export declare const TODO_PROMPT_GUIDELINES: string[];
16
16
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/todo/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,0EAA0E;AAC1E,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,eAAO,MAAM,qBAAqB,kkEA2BoC,CAAC;AAEvE,eAAO,MAAM,mBAAmB,yEAAyE,CAAC;AAE1G,eAAO,MAAM,sBAAsB,UAIlC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/todo/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,0EAA0E;AAC1E,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAM/C,eAAO,MAAM,qBAAqB,wjCAKD,CAAC;AAElC,eAAO,MAAM,mBAAmB,yEAAyE,CAAC;AAE1G,eAAO,MAAM,sBAAsB,UAKlC,CAAC"}
@@ -10,38 +10,21 @@ export const TODO_MAX_BATCH_ITEMS = 20;
10
10
  /** Input limits keep task snapshots and model-facing output bounded. */
11
11
  export const TODO_MAX_SUBJECT_LENGTH = 160;
12
12
  export const TODO_MAX_DESCRIPTION_LENGTH = 500;
13
- export const TODO_TOOL_DESCRIPTION = `Manage the conversation's task list for multi-step coding work.
13
+ // Mechanism plus the cross-field rules TodoParamsSchema cannot state (total
14
+ // capacity, id reuse, the update-needs-one-field rule). Per-parameter bounds and
15
+ // wording live in the schema. The single-in_progress rule is stated in both
16
+ // places on purpose: it is the invariant models break most often.
17
+ export const TODO_TOOL_DESCRIPTION = `Manage the conversation's task list for multi-step coding work. create atomically adds pending tasks; update edits one task by id and requires at least one of subject, description, or status; list returns every remaining task with its description, active first; delete removes tasks by ids. The list holds at most 20 tasks including completed ones, and ids are never reused. Exactly one task may be in_progress, so setting one demotes any other active task to pending; any transition is allowed, including reopening a completed task. A call that fails validation, including a delete naming an id that does not exist, leaves the list unchanged.
14
18
 
15
- ## When to Use
16
- - Work with three or more meaningful steps, a user-provided task list, or a long session where progress can drift
17
- - Capture new user requirements as tasks right away; after completing a task, add follow-up tasks discovered during implementation
18
-
19
- ## When NOT to Use
20
- - Trivial single-step tasks and simple Q&A — just do the work
21
-
22
- ## Actions
23
- - create: atomically add one or many pending tasks from the ordered items array (1 to 20 items); each item needs a short imperative subject and a description of what done means
24
- - update: edit one task by id — subject, description, or status; all transitions and reopens are allowed
25
- - list: show every remaining task with its description, active first
26
- - delete: remove obsolete tasks by ids (1 to 20, duplicates ignored)
27
- - The current list holds at most 20 tasks; parameters that do not apply to the chosen action are rejected
28
-
29
- ## Status Workflow
30
- pending -> in_progress -> completed. Keep exactly one task in_progress: marking one active demotes any other active task to pending. Mark a task in_progress BEFORE starting the work, and completed only when its description is satisfied and relevant checks pass; never with failing tests or partial work. Reopen instead of duplicating. When blocked, do not fake completion: return the task to pending, create a task for the blocker, and finish the blocker first.
31
-
32
- ## Examples
33
19
  {"action": "create", "items": [{"subject": "Wire parser", "description": "Parser handles the config format"}, {"subject": "Test parser", "description": "Parser tests pass"}]}
34
20
  {"action": "update", "id": 2, "status": "in_progress"}
35
21
  {"action": "update", "id": 2, "status": "completed", "description": "Parser verified against config fixtures"}
36
- {"action": "delete", "ids": [3]}
37
-
38
- ## Tips
39
- - list before create to avoid duplicates; prefer working in id order — earlier tasks usually set up context for later ones
40
- - delete obsolete tasks promptly so the list stays short and accurate`;
22
+ {"action": "delete", "ids": [3]}`;
41
23
  export const TODO_PROMPT_SNIPPET = "Track multi-step coding work with a small outcome-oriented task list";
42
24
  export const TODO_PROMPT_GUIDELINES = [
43
- "Use `todo` for work with three or more meaningful steps, user-provided task lists, or long sessions where progress can drift; list first when tasks may already exist, and create one or many tasks with the ordered items array.",
44
- "Keep exactly one `todo` task in_progress: mark it in_progress before starting work and completed only after verification — never while tests fail or work is partial; reopen instead of duplicating, and when blocked leave the `todo` task pending and create a task for the blocker.",
45
- "Keep the `todo` list short and outcome-oriented; prefer working in id order and delete obsolete `todo` items promptly.",
25
+ "Use `todo` for work with three or more meaningful steps, for user-provided task lists, and in long sessions where progress can drift; skip it for trivial single-step tasks and simple Q&A.",
26
+ "Keep exactly one `todo` task in_progress: mark it before starting the work, and completed only after its description is satisfied — never while tests fail or work is partial.",
27
+ "When blocked, leave the `todo` task pending and create a task for the blocker instead of faking completion.",
28
+ "Keep the `todo` list short: list before create to avoid duplicates, work in id order, and delete obsolete tasks promptly.",
46
29
  ];
47
30
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/extensions/todo/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;sEA2BiC,CAAC;AAEvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,sEAAsE,CAAC;AAE1G,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,mOAAmO;IACnO,wRAAwR;IACxR,wHAAwH;CACxH,CAAC","sourcesContent":["/**\n * todo/constants.ts — tool identity, command name, input bounds, and prompt copy.\n */\n\nexport const TODO_TOOL_NAME = \"todo\";\nexport const TODO_TOOL_LABEL = \"Todo\";\nexport const TODOS_COMMAND_NAME = \"todos\";\n\n/** Hard capacity of the task list and of a single create/delete batch. */\nexport const TODO_MAX_ITEMS = 20;\nexport const TODO_MAX_BATCH_ITEMS = 20;\n\n/** Input limits keep task snapshots and model-facing output bounded. */\nexport const TODO_MAX_SUBJECT_LENGTH = 160;\nexport const TODO_MAX_DESCRIPTION_LENGTH = 500;\n\nexport const TODO_TOOL_DESCRIPTION = `Manage the conversation's task list for multi-step coding work.\n\n## When to Use\n- Work with three or more meaningful steps, a user-provided task list, or a long session where progress can drift\n- Capture new user requirements as tasks right away; after completing a task, add follow-up tasks discovered during implementation\n\n## When NOT to Use\n- Trivial single-step tasks and simple Q&A — just do the work\n\n## Actions\n- create: atomically add one or many pending tasks from the ordered items array (1 to 20 items); each item needs a short imperative subject and a description of what done means\n- update: edit one task by id — subject, description, or status; all transitions and reopens are allowed\n- list: show every remaining task with its description, active first\n- delete: remove obsolete tasks by ids (1 to 20, duplicates ignored)\n- The current list holds at most 20 tasks; parameters that do not apply to the chosen action are rejected\n\n## Status Workflow\npending -> in_progress -> completed. Keep exactly one task in_progress: marking one active demotes any other active task to pending. Mark a task in_progress BEFORE starting the work, and completed only when its description is satisfied and relevant checks pass; never with failing tests or partial work. Reopen instead of duplicating. When blocked, do not fake completion: return the task to pending, create a task for the blocker, and finish the blocker first.\n\n## Examples\n{\"action\": \"create\", \"items\": [{\"subject\": \"Wire parser\", \"description\": \"Parser handles the config format\"}, {\"subject\": \"Test parser\", \"description\": \"Parser tests pass\"}]}\n{\"action\": \"update\", \"id\": 2, \"status\": \"in_progress\"}\n{\"action\": \"update\", \"id\": 2, \"status\": \"completed\", \"description\": \"Parser verified against config fixtures\"}\n{\"action\": \"delete\", \"ids\": [3]}\n\n## Tips\n- list before create to avoid duplicates; prefer working in id order — earlier tasks usually set up context for later ones\n- delete obsolete tasks promptly so the list stays short and accurate`;\n\nexport const TODO_PROMPT_SNIPPET = \"Track multi-step coding work with a small outcome-oriented task list\";\n\nexport const TODO_PROMPT_GUIDELINES = [\n\t\"Use `todo` for work with three or more meaningful steps, user-provided task lists, or long sessions where progress can drift; list first when tasks may already exist, and create one or many tasks with the ordered items array.\",\n\t\"Keep exactly one `todo` task in_progress: mark it in_progress before starting work and completed only after verification — never while tests fail or work is partial; reopen instead of duplicating, and when blocked leave the `todo` task pending and create a task for the blocker.\",\n\t\"Keep the `todo` list short and outcome-oriented; prefer working in id order and delete obsolete `todo` items promptly.\",\n];\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/extensions/todo/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C,4EAA4E;AAC5E,iFAAiF;AACjF,4EAA4E;AAC5E,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;iCAKJ,CAAC;AAElC,MAAM,CAAC,MAAM,mBAAmB,GAAG,sEAAsE,CAAC;AAE1G,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,6LAA6L;IAC7L,gLAAgL;IAChL,6GAA6G;IAC7G,2HAA2H;CAC3H,CAAC","sourcesContent":["/**\n * todo/constants.ts — tool identity, command name, input bounds, and prompt copy.\n */\n\nexport const TODO_TOOL_NAME = \"todo\";\nexport const TODO_TOOL_LABEL = \"Todo\";\nexport const TODOS_COMMAND_NAME = \"todos\";\n\n/** Hard capacity of the task list and of a single create/delete batch. */\nexport const TODO_MAX_ITEMS = 20;\nexport const TODO_MAX_BATCH_ITEMS = 20;\n\n/** Input limits keep task snapshots and model-facing output bounded. */\nexport const TODO_MAX_SUBJECT_LENGTH = 160;\nexport const TODO_MAX_DESCRIPTION_LENGTH = 500;\n\n// Mechanism plus the cross-field rules TodoParamsSchema cannot state (total\n// capacity, id reuse, the update-needs-one-field rule). Per-parameter bounds and\n// wording live in the schema. The single-in_progress rule is stated in both\n// places on purpose: it is the invariant models break most often.\nexport const TODO_TOOL_DESCRIPTION = `Manage the conversation's task list for multi-step coding work. create atomically adds pending tasks; update edits one task by id and requires at least one of subject, description, or status; list returns every remaining task with its description, active first; delete removes tasks by ids. The list holds at most 20 tasks including completed ones, and ids are never reused. Exactly one task may be in_progress, so setting one demotes any other active task to pending; any transition is allowed, including reopening a completed task. A call that fails validation, including a delete naming an id that does not exist, leaves the list unchanged.\n\n{\"action\": \"create\", \"items\": [{\"subject\": \"Wire parser\", \"description\": \"Parser handles the config format\"}, {\"subject\": \"Test parser\", \"description\": \"Parser tests pass\"}]}\n{\"action\": \"update\", \"id\": 2, \"status\": \"in_progress\"}\n{\"action\": \"update\", \"id\": 2, \"status\": \"completed\", \"description\": \"Parser verified against config fixtures\"}\n{\"action\": \"delete\", \"ids\": [3]}`;\n\nexport const TODO_PROMPT_SNIPPET = \"Track multi-step coding work with a small outcome-oriented task list\";\n\nexport const TODO_PROMPT_GUIDELINES = [\n\t\"Use `todo` for work with three or more meaningful steps, for user-provided task lists, and in long sessions where progress can drift; skip it for trivial single-step tasks and simple Q&A.\",\n\t\"Keep exactly one `todo` task in_progress: mark it before starting the work, and completed only after its description is satisfied — never while tests fail or work is partial.\",\n\t\"When blocked, leave the `todo` task pending and create a task for the blocker instead of faking completion.\",\n\t\"Keep the `todo` list short: list before create to avoid duplicates, work in id order, and delete obsolete tasks promptly.\",\n];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/extensions/todo/state.ts"],"names":[],"mappings":"AAYA,OAAO,EAIN,KAAK,UAAU,EACf,KAAK,WAAW,EAEhB,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AAgErB,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAE1D;AAiGD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,S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,EAAE,SAAS,GAAG,WAAW,CAElF;AAED,MAAM,WAAW,SAAS;IACzB,QAAQ,IAAI,SAAS,CAAC;IACtB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAAC;CACzC;AAQD,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAiB9D;AAwCD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE;IAAE,cAAc,EAAE;QAAE,SAAS,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAA;KAAE,CAAA;CAAE,GAAG,SAAS,CAoB5G"}
@@ -73,7 +73,7 @@ function applyCreate(state, params) {
73
73
  if (rawItems.length > TODO_MAX_BATCH_ITEMS)
74
74
  throw new Error(`items exceeds ${TODO_MAX_BATCH_ITEMS} tasks`);
75
75
  if (state.items.length + rawItems.length > TODO_MAX_ITEMS) {
76
- throw new Error(`todo list is full (max ${TODO_MAX_ITEMS} tasks)`);
76
+ throw new Error(`todo list is full (max ${TODO_MAX_ITEMS} tasks); delete completed or obsolete tasks first`);
77
77
  }
78
78
  if (!Number.isSafeInteger(state.nextId) || state.nextId < 1)
79
79
  throw new Error("next id is invalid");
@@ -188,10 +188,10 @@ export function applyTodoAction(state, params) {
188
188
  /** Derive the operation model for one call from the before/after states. */
189
189
  export function buildTodoChange(params, before, after) {
190
190
  switch (params.action) {
191
- case "create": {
192
- const count = Array.isArray(params.items) ? params.items.length : 0;
193
- return { kind: "create", ids: after.items.slice(after.items.length - count).map((item) => item.id) };
194
- }
191
+ // Derived from the validated before/after states rather than params.items,
192
+ // which is external input and could read differently on a second access.
193
+ case "create":
194
+ return { kind: "create", ids: after.items.slice(before.items.length).map((item) => item.id) };
195
195
  case "update": {
196
196
  const id = params.id;
197
197
  if (!isPositiveSafeInteger(id))
@@ -245,7 +245,15 @@ export function createTodoStore(initial) {
245
245
  },
246
246
  };
247
247
  }
248
- /** Validate an external v2 snapshot; returns undefined when malformed. */
248
+ /**
249
+ * Validate an external v2 snapshot; returns undefined when malformed.
250
+ *
251
+ * Snapshot text must already be in normalizeText() form, which makes that
252
+ * function's output part of the v2 persistence contract: relaxing or changing
253
+ * it would silently invalidate every historical snapshot, falling back to an
254
+ * earlier one or to the empty state with no diagnostic. Change normalizeText
255
+ * only together with TODO_DETAILS_SCHEMA_VERSION.
256
+ */
249
257
  function normalizeSnapshotState(value) {
250
258
  if (!isRecord(value) || !Array.isArray(value.items) || !isPositiveSafeInteger(value.nextId))
251
259
  return undefined;
@@ -295,22 +303,25 @@ function normalizeSnapshotState(value) {
295
303
  export function replayTodosFromBranch(ctx) {
296
304
  const branch = Array.from(ctx.sessionManager.getBranch());
297
305
  for (let index = branch.length - 1; index >= 0; index--) {
298
- const entry = branch[index];
299
- if (!isRecord(entry) || entry.type !== "message")
300
- continue;
301
- const message = entry.message;
302
- if (!isRecord(message) || message.role !== "toolResult" || message.toolName !== TODO_TOOL_NAME)
303
- continue;
304
- const details = message.details;
305
- if (!isRecord(details) || details.schemaVersion !== TODO_DETAILS_SCHEMA_VERSION)
306
- continue;
306
+ // Session history is external input, so every field read stays inside the
307
+ // guard: a hostile entry falls through to an earlier snapshot instead of
308
+ // escaping to the lifecycle handler.
307
309
  try {
310
+ const entry = branch[index];
311
+ if (!isRecord(entry) || entry.type !== "message")
312
+ continue;
313
+ const message = entry.message;
314
+ if (!isRecord(message) || message.role !== "toolResult" || message.toolName !== TODO_TOOL_NAME)
315
+ continue;
316
+ const details = message.details;
317
+ if (!isRecord(details) || details.schemaVersion !== TODO_DETAILS_SCHEMA_VERSION)
318
+ continue;
308
319
  const state = normalizeSnapshotState(details.state);
309
320
  if (state)
310
321
  return state;
311
322
  }
312
323
  catch {
313
- // Session history is external input; keep scanning for an earlier valid v2.
324
+ // Keep scanning for an earlier valid v2 snapshot.
314
325
  }
315
326
  }
316
327
  return cloneTodoState(EMPTY_TODO_STATE);