@ashx-j/lunr 0.1.7 → 0.2.1
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.
- package/dist/builtin-extensions/lunr-todos.d.ts +7 -6
- package/dist/builtin-extensions/lunr-todos.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-todos.js +24 -11
- package/dist/builtin-extensions/lunr-todos.js.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.d.ts.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.js +9 -5
- package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.js.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js +31 -3
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.d.ts +1 -0
- package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js +14 -4
- package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +4 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +12 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +3 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +8 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +22 -2
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.js +38 -230
- package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/render-search-chrome.d.ts +35 -0
- package/dist/builtin-extensions/pi-web-access/render-search-chrome.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-web-access/render-search-chrome.js +93 -0
- package/dist/builtin-extensions/pi-web-access/render-search-chrome.js.map +1 -0
- package/dist/catalog/models.json +1 -1
- package/dist/catalog/providers/amazon-bedrock.json +1 -1
- package/dist/catalog/providers/cloudflare-workers-ai.json +1 -1
- package/dist/catalog/providers/huggingface.json +1 -1
- package/dist/catalog/providers/opencode-go.json +1 -1
- package/dist/catalog/providers/opencode.json +1 -1
- package/dist/catalog/providers/openrouter.json +1 -1
- package/dist/catalog/providers/vercel-ai-gateway.json +1 -1
- package/dist/catalog/publication.json +3 -3
- package/dist/core/context-breakdown.d.ts +21 -1
- package/dist/core/context-breakdown.d.ts.map +1 -1
- package/dist/core/context-breakdown.js +58 -2
- package/dist/core/context-breakdown.js.map +1 -1
- package/dist/core/permission-mode-control.d.ts +27 -0
- package/dist/core/permission-mode-control.d.ts.map +1 -0
- package/dist/core/permission-mode-control.js +39 -0
- package/dist/core/permission-mode-control.js.map +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +0 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +14 -20
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +2 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +10 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +1 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/context-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/context-view.js +3 -1
- package/dist/modes/interactive/components/context-view.js.map +1 -1
- package/dist/modes/interactive/components/plan-message.d.ts +17 -0
- package/dist/modes/interactive/components/plan-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/plan-message.js +43 -0
- package/dist/modes/interactive/components/plan-message.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +18 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/usage-view.d.ts +4 -25
- package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/usage-view.js +17 -69
- package/dist/modes/interactive/components/usage-view.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +1 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +1 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +17 -6
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +200 -120
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/smooth-streaming.d.ts +39 -6
- package/dist/modes/interactive/smooth-streaming.d.ts.map +1 -1
- package/dist/modes/interactive/smooth-streaming.js +160 -73
- package/dist/modes/interactive/smooth-streaming.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +7 -3
- package/dist/utils/clipboard-image.js.map +1 -1
- package/docs/terminal-setup.md +13 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../../src/builtin-extensions/narumiruna-pi-goal/src/commands.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,EACN,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,YAAY,IAAI,kBAAkB,EAClC,cAAc,IAAI,oBAAoB,EACtC,QAAQ,IAAI,cAAc,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EAEX,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,UAAU,EAEV,kBAAkB,EAClB,cAAc,GACd,MAAM,cAAc,CAAC;AAEtB,kFAAkF;AAClF,8EAA8E;AAC9E,MAAM,OAAO,qBAAqB;IAChB,OAAO,CAAc;IAEtC,YAAY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,YAAY,CAAC;gBACvC,IAAI,YAAY,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;oBACxC,IAAI,CAAC,OAAO,CAAC,kBAAkB,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;gBAClF,CAAC;qBAAM,IAAI,wBAAwB,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1D,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;gBACxC,CAAC;YACF,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACxD,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,0BAA0B,CAAC,CAAC;YACnE,OAAO,KAAK,CAAC;QACd,CAAC;QACD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,qBAAqB,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["// @ts-nocheck\nimport { currentTokenTotal } from \"./accounting.js\";\nimport { validateObjective } from \"./command.js\";\nimport { buildGoalPrompt, buildObjectiveUpdatedPrompt, buildResumePrompt } from \"./prompts.js\";\nimport {\n\tactivateQueuedGoal,\n\tappendGoal,\n\tcreateQueuedGoal,\n\tdropLastGoal as dropLastQueuedGoal,\n\tprioritizeGoal as prioritizeQueuedGoal,\n\tskipGoal as skipQueuedGoal,\n} from \"./queue.js\";\nimport {\n\tabortCurrentTurn,\n\tblocksStaleGoalToolCalls,\n\tcreateGoal,\n\teditedGoalStatus,\n\tformatBudget,\n\tformatError,\n\ttype GoalRuntime,\n\tgoalSummary,\n\thasPendingMessages,\n\tisResumableGoalStatus,\n\tnextGoalInstance,\n\tSTATUS_KEY,\n\ttype StatusContext,\n\tstoppedStatusLabel,\n\ttransitionGoal,\n} from \"./runtime.js\";\n\n// User-command mutations are kept separate from Pi event wiring. Every controller\n// receives exactly one per-factory GoalRuntime, preserving session isolation.\nexport class GoalCommandController {\n\tprivate readonly runtime: GoalRuntime;\n\n\tconstructor(runtime: GoalRuntime) {\n\t\tthis.runtime = runtime;\n\t}\n\n\tasync startGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst existingGoal =\n\t\t\tthis.runtime.activeGoal?.status !== \"complete\" ? this.runtime.activeGoal : undefined;\n\t\tconst existingQueuedGoals = [...this.runtime.queuedGoals];\n\t\tif (existingGoal) {\n\t\t\tconst shouldReplace = await ctx.ui.confirm(\n\t\t\t\t\"Replace goal?\",\n\t\t\t\t`Current goal: ${existingGoal.text}\\n\\nNew goal: ${objective}`,\n\t\t\t);\n\t\t\tif (!shouldReplace) {\n\t\t\t\tctx.ui.notify(`Goal kept: ${existingGoal.text}`, \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Unlock lazy visibility only for a real activation. In always mode, a\n\t\t// missing tool means another policy or allowlist intentionally removed it.\n\t\tconst goalToolVisibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot start /goal: ${formatError(error)}`, \"error\");\n\t\t\tif (existingGoal?.status === \"active\") this.runtime.pauseGoalForUnavailableTools(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.queuedGoals = [];\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tthis.runtime.activeGoal = createGoal(objective, tokenBudget, currentTokenTotal(ctx));\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst startedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tstartedGoal.id,\n\t\t\tbuildGoalPrompt(startedGoal),\n\t\t);\n\t\tif (!sent) {\n\t\t\tlet rolledBackStartedGoal = false;\n\t\t\tif (this.runtime.activeGoal?.id === startedGoal.id) {\n\t\t\t\trolledBackStartedGoal = true;\n\t\t\t\tif (existingGoal) {\n\t\t\t\t\tthis.runtime.queuedGoals = existingQueuedGoals;\n\t\t\t\t\tthis.runtime.recordGoalUsage(existingGoal, ctx);\n\t\t\t\t\tif (existingGoal.status === \"active\") {\n\t\t\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\t\t\tthis.runtime.activeGoal = transitionGoal(existingGoal, \"paused\");\n\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.runtime.activeGoal = existingGoal;\n\t\t\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\t} else {\n\t\t\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (rolledBackStartedGoal) {\n\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\texistingGoal ? `Goal replaced: ${objective}` : `Goal started: ${objective}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tasync addGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.queuedGoals = appendGoal(\n\t\t\tthis.runtime.queuedGoals,\n\t\t\tcreateQueuedGoal(objective, tokenBudget),\n\t\t);\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tctx.ui.notify(\n\t\t\t`Goal added at position ${this.runtime.queuedGoals.length + 1}: ${objective}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tasync prioritizeGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.pendingQueueAction = { kind: \"prioritize\", objective, tokenBudget };\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tif (ctx.isIdle?.() !== true || hasPendingMessages(ctx)) {\n\t\t\tctx.ui.notify(`Priority goal queued until Pi settles: ${objective}`, \"info\");\n\t\t\treturn;\n\t\t}\n\t\tawait this.dispatchPendingQueueActionIfSettled(ctx);\n\t}\n\n\tdropLastGoal(ctx: StatusContext) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tctx.ui.notify(\"No goals to drop.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tconst result = dropLastQueuedGoal(currentGoal, this.runtime.queuedGoals);\n\t\tif (!result.goal) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tctx.ui.notify(`Goal dropped: ${result.removed?.text ?? currentGoal.text}`, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.queuedGoals = result.queue;\n\t\tthis.runtime.persistGoal(result.goal);\n\t\tctx.ui.notify(`Goal dropped: ${result.removed?.text ?? \"unknown goal\"}`, \"warning\");\n\t}\n\n\tasync skipGoal(ctx: StatusContext) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tctx.ui.notify(\"No goals to skip.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.runtime.queuedGoals.length === 0) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tctx.ui.notify(`Goal skipped: ${currentGoal.text}. No goals remain.`, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (currentGoal.status === \"active\") this.runtime.recordGoalUsage(currentGoal, ctx);\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.pendingQueueAction = {\n\t\t\tkind: \"advance\",\n\t\t\tgoalId: currentGoal.id,\n\t\t\treason: \"skip\",\n\t\t\tcompletedText: currentGoal.text,\n\t\t};\n\t\tthis.runtime.persistGoal(currentGoal);\n\t\tctx.ui.notify(`Goal skip queued until Pi settles: ${currentGoal.text}`, \"info\");\n\t\tif (ctx.isIdle?.() === true && !hasPendingMessages(ctx)) {\n\t\t\tawait this.dispatchPendingQueueActionIfSettled(ctx);\n\t\t}\n\t}\n\n\tasync dispatchPendingQueueActionIfSettled(ctx: StatusContext) {\n\t\tconst pending = this.runtime.pendingQueueAction;\n\t\tif (!pending || this.runtime.queueFrozen) return false;\n\t\tif (ctx.isIdle?.() !== true || hasPendingMessages(ctx)) return false;\n\t\tif (pending.kind === \"prioritize\") {\n\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\treturn this.activatePrioritizedGoal(\n\t\t\t\tpending.objective,\n\t\t\t\tpending.tokenBudget,\n\t\t\t\tctx,\n\t\t\t\tpending.displacedUsageFinalized === true,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t!this.runtime.activeGoal ||\n\t\t\tthis.runtime.activeGoal.id !== pending.goalId ||\n\t\t\t(this.runtime.activeGoal.status !== \"complete\" && pending.reason === \"complete\")\n\t\t) {\n\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\tif (this.runtime.activeGoal) this.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\treturn false;\n\t\t}\n\n\t\tconst previousText = pending.completedText;\n\t\tconst reason = pending.reason;\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tconst next = skipQueuedGoal(this.runtime.queuedGoals);\n\t\tthis.runtime.queuedGoals = next.queue;\n\t\tthis.runtime.activeGoal = next.goal\n\t\t\t? activateQueuedGoal(next.goal, currentTokenTotal(ctx))\n\t\t\t: undefined;\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tctx.ui.notify(\n\t\t\t\treason === \"complete\"\n\t\t\t\t\t? `Goal complete: ${previousText}. No goals remain.`\n\t\t\t\t\t: `Goal skipped: ${previousText}. No goals remain.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t}\n\t\t\tctx.ui.notify(\n\t\t\t\t`${reason === \"complete\" ? \"Goal complete\" : \"Goal skipped\"}: ${previousText}. Next goal remains ${this.runtime.activeGoal.status}: ${this.runtime.activeGoal.text}`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tthis.runtime.activeGoal = transitionGoal(this.runtime.activeGoal, \"paused\");\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tctx.ui.notify(`Cannot start the next /goal: ${formatError(error)}`, \"error\");\n\t\t\treturn false;\n\t\t}\n\t\tconst activatedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tactivatedGoal.id,\n\t\t\tbuildGoalPrompt(activatedGoal),\n\t\t);\n\t\tif (!sent && this.runtime.activeGoal?.id === activatedGoal.id) {\n\t\t\tthis.runtime.activeGoal = transitionGoal(activatedGoal, \"paused\");\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tctx.ui.notify(\n\t\t\t\t`Next goal paused after prompt delivery failed: ${activatedGoal.text}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn false;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\t`${reason === \"complete\" ? \"Goal complete\" : \"Goal skipped\"}: ${previousText}. Started next goal: ${activatedGoal.text}`,\n\t\t\t\"info\",\n\t\t);\n\t\treturn true;\n\t}\n\n\tnotifyFrozenQueue(ctx: StatusContext) {\n\t\tctx.ui.notify(\n\t\t\t\"The experimental goal queue is frozen. Re-enable experimental.goals in pi-goal.json and run /reload, or use /goal clear.\",\n\t\t\t\"warning\",\n\t\t);\n\t}\n\n\tpauseGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\tabortCurrentTurn(ctx);\n\t\tthis.runtime.activeGoal = transitionGoal(this.runtime.activeGoal, \"paused\");\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tctx.ui.notify(`Goal paused: ${this.runtime.activeGoal.text}`, \"info\");\n\t}\n\n\tasync resumeGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (!isResumableGoalStatus(this.runtime.activeGoal.status)) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal is ${this.runtime.activeGoal.status}; only paused, blocked, usage-limited, or budget-limited goals can be resumed.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tthis.runtime.activeGoal.tokenBudget !== undefined &&\n\t\t\tthis.runtime.activeGoal.tokensUsed >= this.runtime.activeGoal.tokenBudget\n\t\t) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst goalToolVisibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot resume /goal: ${formatError(error)}`, \"error\");\n\t\t\treturn;\n\t\t}\n\t\tconst stoppedGoal = this.runtime.activeGoal;\n\t\tconst stoppedStatus = stoppedGoal.status;\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.activeGoal = transitionGoal(nextGoalInstance(this.runtime.activeGoal), \"active\");\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst resumedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tresumedGoal.id,\n\t\t\tbuildResumePrompt(resumedGoal, stoppedStatus),\n\t\t);\n\t\tif (!sent) {\n\t\t\tif (\n\t\t\t\tthis.runtime.activeGoal?.id === resumedGoal.id &&\n\t\t\t\tthis.runtime.activeGoal.status === \"active\"\n\t\t\t) {\n\t\t\t\tthis.runtime.activeGoal = stoppedGoal;\n\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t}\n\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\t`Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tclearGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\tthis.runtime.cancelContinuationWork();\n\t\t\tthis.runtime.clearGoalRecovery();\n\t\t\tthis.runtime.clearBudgetWrapUp();\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\tthis.runtime.clearPersistedGoal(ctx.cwd);\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\n\t\tconst stoppedGoal = this.runtime.activeGoal.text;\n\t\tthis.runtime.clearActiveGoal(ctx);\n\t\tctx.ui.notify(`Goal cleared: ${stoppedGoal}`, \"warning\");\n\t}\n\n\tasync editGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal. Use /goal <objective> to start one.\", \"warning\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\tconst previousGoal = { ...this.runtime.activeGoal };\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tconst previousStatus = this.runtime.activeGoal.status;\n\t\tconst nextGoal = transitionGoal(\n\t\t\t{\n\t\t\t\t...nextGoalInstance(this.runtime.activeGoal),\n\t\t\t\ttext: objective,\n\t\t\t\ttokenBudget: tokenBudget ?? this.runtime.activeGoal.tokenBudget,\n\t\t\t},\n\t\t\teditedGoalStatus(previousStatus),\n\t\t);\n\t\tconst goalToolVisibilityBeforeActivation =\n\t\t\tnextGoal.status === \"active\" ? this.runtime.snapshotGoalToolVisibility() : undefined;\n\t\tif (nextGoal.status === \"active\") {\n\t\t\ttry {\n\t\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`Cannot reactivate /goal: ${formatError(error)}`, \"error\");\n\t\t\t\tif (this.runtime.activeGoal?.status === \"active\") {\n\t\t\t\t\tthis.runtime.pauseGoalForUnavailableTools(ctx);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.runtime.activeGoal = nextGoal;\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst editedGoal = this.runtime.activeGoal;\n\t\tif (!editedGoal) return;\n\t\tif (editedGoal.status === \"active\") {\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\t\tctx,\n\t\t\t\teditedGoal.id,\n\t\t\t\tbuildObjectiveUpdatedPrompt(editedGoal),\n\t\t\t);\n\t\t\tif (!sent) {\n\t\t\t\tif (this.runtime.activeGoal?.id === editedGoal.id) {\n\t\t\t\t\tif (previousStatus === \"active\") {\n\t\t\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\t\t\tthis.runtime.activeGoal = transitionGoal(previousGoal, \"paused\");\n\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.runtime.activeGoal = previousGoal;\n\t\t\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\t\tif (goalToolVisibilityBeforeActivation) {\n\t\t\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t} else if (blocksStaleGoalToolCalls(editedGoal.status)) {\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t} else {\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t}\n\t\tctx.ui.notify(`Goal updated: ${objective}`, \"info\");\n\t}\n\n\tshowGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"Usage: /goal <objective>\\nNo goal is currently set.\", \"info\");\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.queueFrozen) {\n\t\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t}\n\t\tctx.ui.notify(\n\t\t\tgoalSummary(\n\t\t\t\tthis.runtime.activeGoal,\n\t\t\t\tthis.runtime.queuedGoals,\n\t\t\t\tthis.runtime.settings.experimental.goals,\n\t\t\t\tthis.runtime.queueFrozen,\n\t\t\t),\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tprivate async activatePrioritizedGoal(\n\t\tobjective: string,\n\t\ttokenBudget: number | undefined,\n\t\tctx: StatusContext,\n\t\tdisplacedUsageFinalized = false,\n\t) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn true;\n\t\t}\n\t\tif (currentGoal.status === \"active\" && !displacedUsageFinalized) {\n\t\t\tthis.runtime.recordGoalUsage(currentGoal, ctx);\n\t\t}\n\t\tconst previousGoal = { ...currentGoal };\n\t\tconst previousQueue = [...this.runtime.queuedGoals];\n\t\tconst visibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot prioritize /goal: ${formatError(error)}`, \"error\");\n\t\t\tif (currentGoal.status === \"complete\") {\n\t\t\t\t// Completion already committed, so retain the priority intent for a\n\t\t\t\t// later /reload after the tool policy is restored.\n\t\t\t\tthis.runtime.pendingQueueAction = {\n\t\t\t\t\tkind: \"prioritize\",\n\t\t\t\t\tobjective,\n\t\t\t\t\ttokenBudget,\n\t\t\t\t\t...(displacedUsageFinalized ? { displacedUsageFinalized: true } : {}),\n\t\t\t\t};\n\t\t\t\tthis.runtime.persistGoal(currentGoal);\n\t\t\t} else {\n\t\t\t\t// Roll back an activation that never started. An active displaced goal\n\t\t\t\t// cannot continue safely without its terminal tools, so make it resumable.\n\t\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\t\tif (currentGoal.status === \"active\") {\n\t\t\t\t\tthis.runtime.pauseGoalForUnavailableTools(ctx, true, !displacedUsageFinalized);\n\t\t\t\t} else {\n\t\t\t\t\tthis.runtime.persistGoal(currentGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tconst prioritized = createGoal(objective, tokenBudget, currentTokenTotal(ctx));\n\t\tconst next =\n\t\t\tcurrentGoal.status === \"complete\"\n\t\t\t\t? { goal: prioritized, queue: [...this.runtime.queuedGoals] }\n\t\t\t\t: prioritizeQueuedGoal(currentGoal, this.runtime.queuedGoals, prioritized);\n\t\tthis.runtime.activeGoal = next.goal;\n\t\tthis.runtime.queuedGoals = next.queue;\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tif (!this.runtime.activeGoal) return false;\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tthis.runtime.activeGoal.id,\n\t\t\tbuildGoalPrompt(this.runtime.activeGoal),\n\t\t);\n\t\tif (!sent && this.runtime.activeGoal.id === prioritized.id) {\n\t\t\tthis.runtime.queuedGoals = previousQueue;\n\t\t\tif (previousGoal.status === \"active\") {\n\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\tthis.runtime.activeGoal = transitionGoal(previousGoal, \"paused\");\n\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t} else {\n\t\t\t\tthis.runtime.activeGoal = previousGoal;\n\t\t\t\tif (previousGoal.status === \"complete\") {\n\t\t\t\t\tthis.runtime.pendingQueueAction = { kind: \"prioritize\", objective, tokenBudget };\n\t\t\t\t} else if (blocksStaleGoalToolCalls(previousGoal.status)) {\n\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tthis.runtime.restoreGoalToolVisibility(visibilityBeforeActivation);\n\t\t\treturn false;\n\t\t}\n\t\tctx.ui.notify(`Goal prioritized: ${objective}`, \"info\");\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../../src/builtin-extensions/narumiruna-pi-goal/src/commands.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cA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ts-nocheck\nimport { currentTokenTotal } from \"./accounting.js\";\nimport { validateObjective } from \"./command.js\";\nimport { buildGoalPrompt, buildObjectiveUpdatedPrompt, buildResumePrompt } from \"./prompts.js\";\nimport {\n\tactivateQueuedGoal,\n\tappendGoal,\n\tcreateQueuedGoal,\n\tdropLastGoal as dropLastQueuedGoal,\n\tprioritizeGoal as prioritizeQueuedGoal,\n\tskipGoal as skipQueuedGoal,\n} from \"./queue.js\";\nimport {\n\tabortCurrentTurn,\n\tblocksStaleGoalToolCalls,\n\tcreateGoal,\n\teditedGoalStatus,\n\tformatBudget,\n\tformatError,\n\ttype GoalRuntime,\n\tgoalSummary,\n\thasPendingMessages,\n\tisResumableGoalStatus,\n\tnextGoalInstance,\n\tSTATUS_KEY,\n\ttype StatusContext,\n\tstoppedStatusLabel,\n\ttransitionGoal,\n} from \"./runtime.js\";\n\n// User-command mutations are kept separate from Pi event wiring. Every controller\n// receives exactly one per-factory GoalRuntime, preserving session isolation.\nexport class GoalCommandController {\n\tprivate readonly runtime: GoalRuntime;\n\n\tconstructor(runtime: GoalRuntime) {\n\t\tthis.runtime = runtime;\n\t}\n\n\tasync startGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst existingGoal =\n\t\t\tthis.runtime.activeGoal?.status !== \"complete\" ? this.runtime.activeGoal : undefined;\n\t\tconst existingQueuedGoals = [...this.runtime.queuedGoals];\n\t\tif (existingGoal) {\n\t\t\tconst shouldReplace = await ctx.ui.confirm(\n\t\t\t\t\"Replace goal?\",\n\t\t\t\t`Current goal: ${existingGoal.text}\\n\\nNew goal: ${objective}`,\n\t\t\t);\n\t\t\tif (!shouldReplace) {\n\t\t\t\tctx.ui.notify(`Goal kept: ${existingGoal.text}`, \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Unlock lazy visibility only for a real activation. In always mode, a\n\t\t// missing tool means another policy or allowlist intentionally removed it.\n\t\tconst goalToolVisibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot start /goal: ${formatError(error)}`, \"error\");\n\t\t\tif (existingGoal?.status === \"active\") this.runtime.pauseGoalForUnavailableTools(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.queuedGoals = [];\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tthis.runtime.activeGoal = createGoal(objective, tokenBudget, currentTokenTotal(ctx));\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst startedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tstartedGoal.id,\n\t\t\tbuildGoalPrompt(startedGoal),\n\t\t);\n\t\tif (!sent) {\n\t\t\tlet rolledBackStartedGoal = false;\n\t\t\tif (this.runtime.activeGoal?.id === startedGoal.id) {\n\t\t\t\trolledBackStartedGoal = true;\n\t\t\t\tif (existingGoal) {\n\t\t\t\t\tthis.runtime.queuedGoals = existingQueuedGoals;\n\t\t\t\t\tthis.runtime.recordGoalUsage(existingGoal, ctx);\n\t\t\t\t\tif (existingGoal.status === \"active\") {\n\t\t\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\t\t\tthis.runtime.activeGoal = transitionGoal(existingGoal, \"paused\");\n\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.runtime.activeGoal = existingGoal;\n\t\t\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\t} else {\n\t\t\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (rolledBackStartedGoal) {\n\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\texistingGoal ? `Goal replaced: ${objective}` : `Goal started: ${objective}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tasync addGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.queuedGoals = appendGoal(\n\t\t\tthis.runtime.queuedGoals,\n\t\t\tcreateQueuedGoal(objective, tokenBudget),\n\t\t);\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tctx.ui.notify(\n\t\t\t`Goal added at position ${this.runtime.queuedGoals.length + 1}: ${objective}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tasync prioritizeGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.pendingQueueAction = { kind: \"prioritize\", objective, tokenBudget };\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tif (ctx.isIdle?.() !== true || hasPendingMessages(ctx)) {\n\t\t\tctx.ui.notify(`Priority goal queued until Pi settles: ${objective}`, \"info\");\n\t\t\treturn;\n\t\t}\n\t\tawait this.dispatchPendingQueueActionIfSettled(ctx);\n\t}\n\n\tdropLastGoal(ctx: StatusContext) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tctx.ui.notify(\"No goals to drop.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tconst result = dropLastQueuedGoal(currentGoal, this.runtime.queuedGoals);\n\t\tif (!result.goal) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tctx.ui.notify(`Goal dropped: ${result.removed?.text ?? currentGoal.text}`, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.queuedGoals = result.queue;\n\t\tthis.runtime.persistGoal(result.goal);\n\t\tctx.ui.notify(`Goal dropped: ${result.removed?.text ?? \"unknown goal\"}`, \"warning\");\n\t}\n\n\tasync skipGoal(ctx: StatusContext) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tctx.ui.notify(\"No goals to skip.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.runtime.queuedGoals.length === 0) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tctx.ui.notify(`Goal skipped: ${currentGoal.text}. No goals remain.`, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (currentGoal.status === \"active\") this.runtime.recordGoalUsage(currentGoal, ctx);\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.pendingQueueAction = {\n\t\t\tkind: \"advance\",\n\t\t\tgoalId: currentGoal.id,\n\t\t\treason: \"skip\",\n\t\t\tcompletedText: currentGoal.text,\n\t\t};\n\t\tthis.runtime.persistGoal(currentGoal);\n\t\tctx.ui.notify(`Goal skip queued until Pi settles: ${currentGoal.text}`, \"info\");\n\t\tif (ctx.isIdle?.() === true && !hasPendingMessages(ctx)) {\n\t\t\tawait this.dispatchPendingQueueActionIfSettled(ctx);\n\t\t}\n\t}\n\n\tasync dispatchPendingQueueActionIfSettled(ctx: StatusContext) {\n\t\tconst pending = this.runtime.pendingQueueAction;\n\t\tif (!pending || this.runtime.queueFrozen) return false;\n\t\tif (ctx.isIdle?.() !== true || hasPendingMessages(ctx)) return false;\n\t\tif (pending.kind === \"prioritize\") {\n\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\treturn this.activatePrioritizedGoal(\n\t\t\t\tpending.objective,\n\t\t\t\tpending.tokenBudget,\n\t\t\t\tctx,\n\t\t\t\tpending.displacedUsageFinalized === true,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t!this.runtime.activeGoal ||\n\t\t\tthis.runtime.activeGoal.id !== pending.goalId ||\n\t\t\t(this.runtime.activeGoal.status !== \"complete\" && pending.reason === \"complete\")\n\t\t) {\n\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\tif (this.runtime.activeGoal) this.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\treturn false;\n\t\t}\n\n\t\tconst previousText = pending.completedText;\n\t\tconst reason = pending.reason;\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tconst next = skipQueuedGoal(this.runtime.queuedGoals);\n\t\tthis.runtime.queuedGoals = next.queue;\n\t\tthis.runtime.activeGoal = next.goal\n\t\t\t? activateQueuedGoal(next.goal, currentTokenTotal(ctx))\n\t\t\t: undefined;\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tthis.runtime.clearActiveGoal(ctx);\n\t\t\tif (reason !== \"complete\") {\n\t\t\t\tctx.ui.notify(`Goal skipped: ${previousText}. No goals remain.`, \"info\");\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t}\n\t\t\tif (reason !== \"complete\") {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal skipped: ${previousText}. Next goal remains ${this.runtime.activeGoal.status}: ${this.runtime.activeGoal.text}`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tthis.runtime.activeGoal = transitionGoal(this.runtime.activeGoal, \"paused\");\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tctx.ui.notify(`Cannot start the next /goal: ${formatError(error)}`, \"error\");\n\t\t\treturn false;\n\t\t}\n\t\tconst activatedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tactivatedGoal.id,\n\t\t\tbuildGoalPrompt(activatedGoal),\n\t\t);\n\t\tif (!sent && this.runtime.activeGoal?.id === activatedGoal.id) {\n\t\t\tthis.runtime.activeGoal = transitionGoal(activatedGoal, \"paused\");\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tctx.ui.notify(\n\t\t\t\t`Next goal paused after prompt delivery failed: ${activatedGoal.text}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn false;\n\t\t}\n\t\tif (reason !== \"complete\") {\n\t\t\tctx.ui.notify(`Goal skipped: ${previousText}. Started next goal: ${activatedGoal.text}`, \"info\");\n\t\t}\n\t\treturn true;\n\t}\n\n\tnotifyFrozenQueue(ctx: StatusContext) {\n\t\tctx.ui.notify(\n\t\t\t\"The experimental goal queue is frozen. Re-enable experimental.goals in pi-goal.json and run /reload, or use /goal clear.\",\n\t\t\t\"warning\",\n\t\t);\n\t}\n\n\tpauseGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\tabortCurrentTurn(ctx);\n\t\tthis.runtime.activeGoal = transitionGoal(this.runtime.activeGoal, \"paused\");\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tctx.ui.notify(`Goal paused: ${this.runtime.activeGoal.text}`, \"info\");\n\t}\n\n\tasync resumeGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tif (!isResumableGoalStatus(this.runtime.activeGoal.status)) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal is ${this.runtime.activeGoal.status}; only paused, blocked, usage-limited, or budget-limited goals can be resumed.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tthis.runtime.activeGoal.tokenBudget !== undefined &&\n\t\t\tthis.runtime.activeGoal.tokensUsed >= this.runtime.activeGoal.tokenBudget\n\t\t) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst goalToolVisibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot resume /goal: ${formatError(error)}`, \"error\");\n\t\t\treturn;\n\t\t}\n\t\tconst stoppedGoal = this.runtime.activeGoal;\n\t\tconst stoppedStatus = stoppedGoal.status;\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tthis.runtime.activeGoal = transitionGoal(nextGoalInstance(this.runtime.activeGoal), \"active\");\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tif (this.runtime.activeGoal.status !== \"active\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst resumedGoal = this.runtime.activeGoal;\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tresumedGoal.id,\n\t\t\tbuildResumePrompt(resumedGoal, stoppedStatus),\n\t\t);\n\t\tif (!sent) {\n\t\t\tif (\n\t\t\t\tthis.runtime.activeGoal?.id === resumedGoal.id &&\n\t\t\t\tthis.runtime.activeGoal.status === \"active\"\n\t\t\t) {\n\t\t\t\tthis.runtime.activeGoal = stoppedGoal;\n\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t}\n\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\t`Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tclearGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal.\", \"info\");\n\t\t\tthis.runtime.cancelContinuationWork();\n\t\t\tthis.runtime.clearGoalRecovery();\n\t\t\tthis.runtime.clearBudgetWrapUp();\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\tthis.runtime.clearPersistedGoal(ctx.cwd);\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\n\t\tconst stoppedGoal = this.runtime.activeGoal.text;\n\t\tthis.runtime.clearActiveGoal(ctx);\n\t\tctx.ui.notify(`Goal cleared: ${stoppedGoal}`, \"warning\");\n\t}\n\n\tasync editGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {\n\t\tconst validationError = validateObjective(objective);\n\t\tif (validationError) {\n\t\t\tctx.ui.notify(validationError, \"warning\");\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"No active goal. Use /goal <objective> to start one.\", \"warning\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\tconst previousGoal = { ...this.runtime.activeGoal };\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tconst previousStatus = this.runtime.activeGoal.status;\n\t\tconst nextGoal = transitionGoal(\n\t\t\t{\n\t\t\t\t...nextGoalInstance(this.runtime.activeGoal),\n\t\t\t\ttext: objective,\n\t\t\t\ttokenBudget: tokenBudget ?? this.runtime.activeGoal.tokenBudget,\n\t\t\t},\n\t\t\teditedGoalStatus(previousStatus),\n\t\t);\n\t\tconst goalToolVisibilityBeforeActivation =\n\t\t\tnextGoal.status === \"active\" ? this.runtime.snapshotGoalToolVisibility() : undefined;\n\t\tif (nextGoal.status === \"active\") {\n\t\t\ttry {\n\t\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`Cannot reactivate /goal: ${formatError(error)}`, \"error\");\n\t\t\t\tif (this.runtime.activeGoal?.status === \"active\") {\n\t\t\t\t\tthis.runtime.pauseGoalForUnavailableTools(ctx);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.runtime.activeGoal = nextGoal;\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst editedGoal = this.runtime.activeGoal;\n\t\tif (!editedGoal) return;\n\t\tif (editedGoal.status === \"active\") {\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\t\tctx,\n\t\t\t\teditedGoal.id,\n\t\t\t\tbuildObjectiveUpdatedPrompt(editedGoal),\n\t\t\t);\n\t\t\tif (!sent) {\n\t\t\t\tif (this.runtime.activeGoal?.id === editedGoal.id) {\n\t\t\t\t\tif (previousStatus === \"active\") {\n\t\t\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\t\t\tthis.runtime.activeGoal = transitionGoal(previousGoal, \"paused\");\n\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.runtime.activeGoal = previousGoal;\n\t\t\t\t\t\tif (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {\n\t\t\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\t\t\tif (goalToolVisibilityBeforeActivation) {\n\t\t\t\t\t\tthis.runtime.restoreGoalToolVisibility(goalToolVisibilityBeforeActivation);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t} else if (blocksStaleGoalToolCalls(editedGoal.status)) {\n\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t} else {\n\t\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\t}\n\t\tctx.ui.notify(`Goal updated: ${objective}`, \"info\");\n\t}\n\n\tshowGoal(ctx: StatusContext) {\n\t\tif (!this.runtime.activeGoal) {\n\t\t\tctx.ui.notify(\"Usage: /goal <objective>\\nNo goal is currently set.\", \"info\");\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.runtime.queueFrozen) {\n\t\t\tthis.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t}\n\t\tctx.ui.notify(\n\t\t\tgoalSummary(\n\t\t\t\tthis.runtime.activeGoal,\n\t\t\t\tthis.runtime.queuedGoals,\n\t\t\t\tthis.runtime.settings.experimental.goals,\n\t\t\t\tthis.runtime.queueFrozen,\n\t\t\t),\n\t\t\t\"info\",\n\t\t);\n\t}\n\n\tprivate async activatePrioritizedGoal(\n\t\tobjective: string,\n\t\ttokenBudget: number | undefined,\n\t\tctx: StatusContext,\n\t\tdisplacedUsageFinalized = false,\n\t) {\n\t\tconst currentGoal = this.runtime.activeGoal;\n\t\tif (!currentGoal) {\n\t\t\tawait this.startGoal(objective, tokenBudget, ctx);\n\t\t\treturn true;\n\t\t}\n\t\tif (currentGoal.status === \"active\" && !displacedUsageFinalized) {\n\t\t\tthis.runtime.recordGoalUsage(currentGoal, ctx);\n\t\t}\n\t\tconst previousGoal = { ...currentGoal };\n\t\tconst previousQueue = [...this.runtime.queuedGoals];\n\t\tconst visibilityBeforeActivation = this.runtime.snapshotGoalToolVisibility();\n\t\ttry {\n\t\t\tthis.runtime.prepareGoalToolsForActivation(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(`Cannot prioritize /goal: ${formatError(error)}`, \"error\");\n\t\t\tif (currentGoal.status === \"complete\") {\n\t\t\t\t// Completion already committed, so retain the priority intent for a\n\t\t\t\t// later /reload after the tool policy is restored.\n\t\t\t\tthis.runtime.pendingQueueAction = {\n\t\t\t\t\tkind: \"prioritize\",\n\t\t\t\t\tobjective,\n\t\t\t\t\ttokenBudget,\n\t\t\t\t\t...(displacedUsageFinalized ? { displacedUsageFinalized: true } : {}),\n\t\t\t\t};\n\t\t\t\tthis.runtime.persistGoal(currentGoal);\n\t\t\t} else {\n\t\t\t\t// Roll back an activation that never started. An active displaced goal\n\t\t\t\t// cannot continue safely without its terminal tools, so make it resumable.\n\t\t\t\tthis.runtime.pendingQueueAction = undefined;\n\t\t\t\tif (currentGoal.status === \"active\") {\n\t\t\t\t\tthis.runtime.pauseGoalForUnavailableTools(ctx, true, !displacedUsageFinalized);\n\t\t\t\t} else {\n\t\t\t\t\tthis.runtime.persistGoal(currentGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.runtime.cancelContinuationWork();\n\t\tthis.runtime.clearGoalRecovery();\n\t\tthis.runtime.clearBudgetWrapUp();\n\t\tthis.runtime.clearStaleGoalToolCallBlock();\n\t\tconst prioritized = createGoal(objective, tokenBudget, currentTokenTotal(ctx));\n\t\tconst next =\n\t\t\tcurrentGoal.status === \"complete\"\n\t\t\t\t? { goal: prioritized, queue: [...this.runtime.queuedGoals] }\n\t\t\t\t: prioritizeQueuedGoal(currentGoal, this.runtime.queuedGoals, prioritized);\n\t\tthis.runtime.activeGoal = next.goal;\n\t\tthis.runtime.queuedGoals = next.queue;\n\t\tthis.runtime.pendingQueueAction = undefined;\n\t\tif (!this.runtime.activeGoal) return false;\n\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\tconst sent = await this.runtime.sendOwnedGoalPrompt(\n\t\t\tctx,\n\t\t\tthis.runtime.activeGoal.id,\n\t\t\tbuildGoalPrompt(this.runtime.activeGoal),\n\t\t);\n\t\tif (!sent && this.runtime.activeGoal.id === prioritized.id) {\n\t\t\tthis.runtime.queuedGoals = previousQueue;\n\t\t\tif (previousGoal.status === \"active\") {\n\t\t\t\tabortCurrentTurn(ctx);\n\t\t\t\tthis.runtime.activeGoal = transitionGoal(previousGoal, \"paused\");\n\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t} else {\n\t\t\t\tthis.runtime.activeGoal = previousGoal;\n\t\t\t\tif (previousGoal.status === \"complete\") {\n\t\t\t\t\tthis.runtime.pendingQueueAction = { kind: \"prioritize\", objective, tokenBudget };\n\t\t\t\t} else if (blocksStaleGoalToolCalls(previousGoal.status)) {\n\t\t\t\t\tthis.runtime.blockStaleGoalToolCalls();\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.runtime.persistGoal(this.runtime.activeGoal);\n\t\t\tthis.runtime.updateStatus(ctx, this.runtime.activeGoal);\n\t\t\tthis.runtime.restoreGoalToolVisibility(visibilityBeforeActivation);\n\t\t\treturn false;\n\t\t}\n\t\tctx.ui.notify(`Goal prioritized: ${objective}`, \"info\");\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goal.d.ts","sourceRoot":"","sources":["../../../../src/builtin-extensions/narumiruna-pi-goal/src/goal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAkDpE,UAAU,WAAW;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAg5BD,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,GAAE,WAAgB,QAEvE;AAED,OAAO,EACN,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,EACd,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EACN,yBAAyB,EACzB,YAAY,EACZ,gCAAgC,EAChC,2BAA2B,EAC3B,8BAA8B,GAC9B,MAAM,cAAc,CAAC","sourcesContent":["// @ts-nocheck\n// lunr: defineTool imported from the concrete module, NOT the package barrel —\n// the barrel re-exports main.ts which imports this extension (cycle).\nimport { defineTool } from \"../../../core/extensions/types.js\";\nimport { isCronFire } from \"../../../core/cron/fire-guard.js\";\nimport type { ExtensionAPI } from \"@ashx-j/lunr\";\nimport { Type } from \"typebox\";\nimport { currentTokenTotal } from \"./accounting.js\";\nimport { completeGoalArguments, parseCommand } from \"./command.js\";\nimport { GoalCommandController } from \"./commands.js\";\nimport { type ActiveGoal, loadGoalStateFromSession } from \"./persistence.js\";\nimport { buildGoalPrompt, buildGoalSystemPrompt } from \"./prompts.js\";\nimport { activateQueuedGoal } from \"./queue.js\";\nimport {\n\ttype AssistantMessageLike,\n\tabortCurrentTurn,\n\tblocksStaleGoalToolCalls,\n\tfindFinalAssistantMessage,\n\tformatError,\n\tformatStatus,\n\tGOAL_BLOCKED_TOOL,\n\tGOAL_COMPLETE_TOOL,\n\tGoalRuntime,\n\tgoalIdRejectionReason,\n\tincrementGoal,\n\tisContradictoryCompletionSummary,\n\tisGoalContextOverflow,\n\tisRetryableGoalInterruption,\n\tisUsageLimitedGoalInterruption,\n\tparseUsageResetTimeMs,\n\tSTATUS_KEY,\n\ttype StatusContext,\n\ttransitionGoal,\n\ttruncateNotification,\n} from \"./runtime.js\";\nimport { DEFAULT_GOAL_SETTINGS, readGoalSettings } from \"./settings.js\";\n\n// goal.ts is the Pi-facing composition root: it keeps tool contracts and event\n// ordering together. Per-session mechanisms live in runtime.ts, while user command\n// transitions live in commands.ts. Each factory constructs isolated instances.\n\ninterface GoalCompleteDetails {\n\tgoal: string;\n\tgoal_id: string;\n\tsummary: string;\n}\n\ninterface GoalBlockedDetails {\n\tgoal: string;\n\tgoal_id: string;\n\treason: string;\n\tevidence: string;\n\trepeated_turns: number;\n}\n\ninterface GoalOptions {\n\tsettingsPath?: string;\n}\n\nconst EXPERIMENTAL_GOALS_WARNING =\n\t\"Experimental ordered goals are enabled for pi-goal. Queue behavior and persisted state may change.\";\nconst MAX_BLOCKER_REASON_LENGTH = 1_000;\nconst MAX_BLOCKER_EVIDENCE_LENGTH = 4_000;\n\nfunction registerGoalRuntime(pi: ExtensionAPI, options: GoalOptions = {}) {\n\tconst runtime = new GoalRuntime(pi);\n\tconst commands = new GoalCommandController(runtime);\n\n\t// Bind per-factory runtime operations once so event orchestration stays concise\n\t// without reintroducing module-global mutable state.\n\tconst clearCompletionStatusTimer = runtime.clearCompletionStatusTimer.bind(runtime);\n\t// lunr: footer refresh timer cleanup\n\tconst clearStatusRefreshTimer = runtime.clearStatusRefreshTimer.bind(runtime);\n\tconst clearContinuationTracking = runtime.clearContinuationTracking.bind(runtime);\n\tconst clearPendingGoalPrompts = runtime.clearPendingGoalPrompts.bind(runtime);\n\tconst clearGoalRecovery = runtime.clearGoalRecovery.bind(runtime);\n\tconst clearBudgetWrapUp = runtime.clearBudgetWrapUp.bind(runtime);\n\tconst clearStaleGoalToolCallBlock = runtime.clearStaleGoalToolCallBlock.bind(runtime);\n\tconst persistGoal = runtime.persistGoal.bind(runtime);\n\tconst updateGoalUsage = runtime.recordGoalUsage.bind(runtime);\n\tconst updateStatus = runtime.updateStatus.bind(runtime);\n\tconst limitActiveGoalForBudget = runtime.limitActiveGoalForBudget.bind(runtime);\n\tconst hideGoalToolsIfLocked = runtime.hideGoalToolsIfLocked.bind(runtime);\n\tconst goalToolsAvailable = runtime.goalToolsAvailable.bind(runtime);\n\tconst pauseGoalForUnavailableTools = runtime.pauseGoalForUnavailableTools.bind(runtime);\n\tconst isPiOwnedCompactionRetry = runtime.isPiOwnedCompactionRetry.bind(runtime);\n\tconst requestContinuation = runtime.requestContinuation.bind(runtime);\n\tconst dispatchContinuationIfSettled = runtime.dispatchContinuationIfSettled.bind(runtime);\n\tconst isGoalToolName = runtime.isGoalToolName.bind(runtime);\n\tconst queueBudgetWrapUp = runtime.queueBudgetWrapUp.bind(runtime);\n\tconst clearGoalRecoveryForGoal = runtime.clearGoalRecoveryForGoal.bind(runtime);\n\tconst blockStaleGoalToolCalls = runtime.blockStaleGoalToolCalls.bind(runtime);\n\tconst cancelContinuationWork = runtime.cancelContinuationWork.bind(runtime);\n\tconst consumeCancelledContinuationPrompt =\n\t\truntime.consumeCancelledContinuationPrompt.bind(runtime);\n\tconst consumeStaleOwnedGoalPrompt = runtime.consumeStaleOwnedGoalPrompt.bind(runtime);\n\tconst consumePendingGoalPrompt = runtime.consumeOwnedGoalPrompt.bind(runtime);\n\tconst markContinuationStarted = runtime.markContinuationStarted.bind(runtime);\n\tconst hasContinuationWorkForGoal = runtime.hasContinuationWorkForGoal.bind(runtime);\n\tconst clearActiveGoal = runtime.clearActiveGoal.bind(runtime);\n\tconst showCompletionStatus = runtime.showCompletionStatus.bind(runtime);\n\tconst restoreGoalToolsHiddenByPolicy = runtime.restoreGoalToolsHiddenByPolicy.bind(runtime);\n\tconst sendOwnedGoalPrompt = (\n\t\t_pi: ExtensionAPI,\n\t\tctx: StatusContext,\n\t\tgoalId: string,\n\t\tprompt: string,\n\t) => runtime.sendOwnedGoalPrompt(ctx, goalId, prompt);\n\tconst dispatchPendingQueueActionIfSettled =\n\t\tcommands.dispatchPendingQueueActionIfSettled.bind(commands);\n\n\tconst goalCompleteTool = defineTool({\n\t\tname: GOAL_COMPLETE_TOOL,\n\t\tlabel: \"Goal Complete\",\n\t\tdescription:\n\t\t\t\"Mark the active /goal as complete after all required work is done and verified, using the current goal_id stale-turn guard. Do not use for partial progress, blockers, failing, or unverified work.\",\n\t\tpromptSnippet:\n\t\t\t\"Mark the active /goal as complete after fully finishing and verifying it, with the current goal_id\",\n\t\tpromptGuidelines: [\n\t\t\t\"When a /goal is active, keep working until the goal is complete; do not stop with only a plan or partial progress.\",\n\t\t\t\"Before calling goal_complete, audit the active goal requirement by requirement against the current files, command output, tests, or external state.\",\n\t\t\t\"Pass the exact goal_id shown in the current /goal prompt; never reuse a goal_id from an older, stopped, replaced, or cleared turn.\",\n\t\t\t\"Call goal_complete only after the requested goal is fully implemented, verified, and no known required work remains; otherwise keep working.\",\n\t\t],\n\t\tparameters: Type.Object({\n\t\t\tgoal_id: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"The exact goal_id shown in the current active /goal prompt. Used only to reject stale completion calls from older turns.\",\n\t\t\t}),\n\t\t\tsummary: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"State what was completed and what evidence verified it. Do not use this tool to report partial progress, blockers, failures, or remaining work.\",\n\t\t\t}),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst completedGoal = runtime.activeGoal;\n\t\t\tconst goal = completedGoal?.text ?? \"unknown goal\";\n\t\t\tconst requestedGoalId = typeof params.goal_id === \"string\" ? params.goal_id.trim() : \"\";\n\t\t\tconst summary = typeof params.summary === \"string\" ? params.summary.trim() : \"\";\n\n\t\t\tif (!completedGoal) {\n\t\t\t\tconst rejection = \"Goal completion rejected: no active goal.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst completingDuringBudgetWrapUp = runtime.hasActiveBudgetWrapUp();\n\t\t\tif (!runtime.canRecordGoalUsage() && !completingDuringBudgetWrapUp) {\n\t\t\t\tconst rejection = \"Goal completion rejected: current run does not own the active goal.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (hasPendingSkipForGoal(completedGoal.id)) {\n\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\tclearBudgetWrapUp();\n\t\t\t\tconst rejection = \"Goal completion rejected: goal is queued to be skipped.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst staleGoalRejection = goalIdRejectionReason(completedGoal, requestedGoalId);\n\t\t\tif (staleGoalRejection) {\n\t\t\t\tconst rejection = `Goal completion rejected: ${staleGoalRejection}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\tif (completingDuringBudgetWrapUp) {\n\t\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\t\tclearBudgetWrapUp();\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: completingDuringBudgetWrapUp || undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (completedGoal.status !== \"active\" && !completingDuringBudgetWrapUp) {\n\t\t\t\tconst rejection = `Goal completion rejected: goal is ${completedGoal.status}, not active.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst rejectionReason = !summary\n\t\t\t\t? \"summary is empty\"\n\t\t\t\t: isContradictoryCompletionSummary(summary)\n\t\t\t\t\t? \"summary says the goal is not complete\"\n\t\t\t\t\t: undefined;\n\t\t\tif (rejectionReason) {\n\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\tconst rejection = `Goal completion rejected: ${rejectionReason}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\tif (completingDuringBudgetWrapUp) clearBudgetWrapUp();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: rejection,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: completingDuringBudgetWrapUp || undefined,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\truntime.activeGoal = transitionGoal(completedGoal, \"complete\");\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tif (runtime.pendingQueueAction?.kind === \"prioritize\") {\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"complete\");\n\t\t\t\tctx.ui.notify(`Goal complete: ${goal}. Priority goal waits for Pi to settle.`, \"info\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Goal complete: ${summary}` }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\tsummary,\n\t\t\t\t\t} satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (runtime.queuedGoals.length > 0) {\n\t\t\t\truntime.pendingQueueAction = {\n\t\t\t\t\tkind: \"advance\",\n\t\t\t\t\tgoalId: runtime.activeGoal.id,\n\t\t\t\t\treason: \"complete\",\n\t\t\t\t\tcompletedText: goal,\n\t\t\t\t};\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"complete\");\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal complete: ${goal}. Next goal queued: ${runtime.queuedGoals[0]?.text}`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Goal complete: ${summary}\\nNext goal queued: ${runtime.queuedGoals[0]?.text}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\tsummary,\n\t\t\t\t\t} satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\n\t\t\tctx.ui.setStatus(STATUS_KEY, formatStatus(runtime.activeGoal));\n\t\t\tclearActiveGoal(ctx);\n\t\t\tshowCompletionStatus(ctx);\n\t\t\tctx.ui.notify(`Goal complete: ${goal}`, \"info\");\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `Goal complete: ${summary}` }],\n\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t},\n\t});\n\n\tconst goalBlockedTool = defineTool({\n\t\tname: GOAL_BLOCKED_TOOL,\n\t\tlabel: \"Goal Blocked\",\n\t\tdescription:\n\t\t\t\"Stop the active /goal only at a true impasse after the same blocker recurs for at least three consecutive goal turns, with the current goal_id and concrete evidence that user or external action is required. Do not use for ordinary clarification, uncertainty, or recoverable failures.\",\n\t\tpromptSnippet:\n\t\t\t\"Mark the active /goal blocked only after the same blocker recurs for three consecutive goal turns\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use goal_blocked only for a true impasse after the same blocker recurs for at least three consecutive goal turns and concrete evidence shows user or external action is required.\",\n\t\t\t\"After a blocked goal is resumed, start a fresh three-turn blocker audit before using goal_blocked again.\",\n\t\t\t\"Do not use goal_blocked for ordinary clarification, incomplete work, uncertainty, difficult tasks, or recoverable tool/provider failures.\",\n\t\t\t\"Pass goal_blocked the exact current goal_id; never reuse a goal_id from an older, stopped, replaced, or cleared goal turn.\",\n\t\t],\n\t\tparameters: Type.Object({\n\t\t\tgoal_id: Type.String({\n\t\t\t\tdescription: \"The exact goal_id shown in the current active /goal prompt.\",\n\t\t\t}),\n\t\t\treason: Type.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: MAX_BLOCKER_REASON_LENGTH,\n\t\t\t\tdescription: \"The specific user or external action required to unblock the goal.\",\n\t\t\t}),\n\t\t\tevidence: Type.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: MAX_BLOCKER_EVIDENCE_LENGTH,\n\t\t\t\tdescription: \"Concrete evidence from the repeated attempts that proves the impasse.\",\n\t\t\t}),\n\t\t\trepeated_turns: Type.Integer({\n\t\t\t\tminimum: 3,\n\t\t\t\tdescription: \"Number of separate turns spent trying to resolve this same blocker.\",\n\t\t\t}),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst blockedGoal = runtime.activeGoal;\n\t\t\tconst goal = blockedGoal?.text ?? \"unknown goal\";\n\t\t\tconst requestedGoalId = typeof params.goal_id === \"string\" ? params.goal_id.trim() : \"\";\n\t\t\tconst reason = typeof params.reason === \"string\" ? params.reason.trim() : \"\";\n\t\t\tconst evidence = typeof params.evidence === \"string\" ? params.evidence.trim() : \"\";\n\t\t\tconst repeatedTurns =\n\t\t\t\ttypeof params.repeated_turns === \"number\" ? params.repeated_turns : Number.NaN;\n\t\t\tconst reject = (rejectionReason: string, terminate = false) => {\n\t\t\t\tconst rejection = `goal_blocked rejected: ${rejectionReason}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: rejection }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\treason: reason.slice(0, MAX_BLOCKER_REASON_LENGTH),\n\t\t\t\t\t\tevidence: evidence.slice(0, MAX_BLOCKER_EVIDENCE_LENGTH),\n\t\t\t\t\t\trepeated_turns: Number.isFinite(repeatedTurns) ? repeatedTurns : 0,\n\t\t\t\t\t} satisfies GoalBlockedDetails,\n\t\t\t\t\t...(terminate ? { terminate: true as const } : {}),\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tif (!blockedGoal) return reject(\"no active goal\");\n\t\t\tif (!runtime.canRecordGoalUsage()) {\n\t\t\t\treturn reject(\"current run does not own the active goal\");\n\t\t\t}\n\t\t\tif (hasPendingSkipForGoal(blockedGoal.id)) {\n\t\t\t\tupdateGoalUsage(blockedGoal, ctx);\n\t\t\t\tpersistGoal(blockedGoal);\n\t\t\t\tupdateStatus(ctx, blockedGoal);\n\t\t\t\tclearBudgetWrapUp();\n\t\t\t\treturn reject(\"goal is queued to be skipped\", true);\n\t\t\t}\n\t\t\tconst staleGoalRejection = goalIdRejectionReason(blockedGoal, requestedGoalId);\n\t\t\tif (staleGoalRejection) return reject(staleGoalRejection);\n\t\t\tif (blockedGoal.status !== \"active\") {\n\t\t\t\treturn reject(`goal is ${blockedGoal.status}, not active`);\n\t\t\t}\n\t\t\tif (!reason) return reject(\"reason is empty\");\n\t\t\tif (reason.length > MAX_BLOCKER_REASON_LENGTH) return reject(\"reason is too long\");\n\t\t\tif (!evidence) return reject(\"evidence is empty\");\n\t\t\tif (evidence.length > MAX_BLOCKER_EVIDENCE_LENGTH) return reject(\"evidence is too long\");\n\t\t\tif (!Number.isInteger(repeatedTurns)) return reject(\"repeated_turns must be a whole number\");\n\t\t\tif (repeatedTurns < 3) return reject(\"repeated_turns must be at least 3\");\n\n\t\t\tupdateGoalUsage(blockedGoal, ctx);\n\t\t\tcancelContinuationWork();\n\t\t\tclearBudgetWrapUp();\n\t\t\tclearGoalRecoveryForGoal(blockedGoal.id);\n\t\t\tblockStaleGoalToolCalls();\n\t\t\truntime.activeGoal = transitionGoal(blockedGoal, \"blocked\");\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tctx.ui.notify(`Goal blocked: ${truncateNotification(reason)}`, \"warning\");\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `Goal blocked: ${reason}` }],\n\t\t\t\tdetails: {\n\t\t\t\t\tgoal,\n\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\treason,\n\t\t\t\t\tevidence,\n\t\t\t\t\trepeated_turns: repeatedTurns,\n\t\t\t\t} satisfies GoalBlockedDetails,\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t},\n\t});\n\n\tpi.registerTool(goalCompleteTool);\n\tpi.registerTool(goalBlockedTool);\n\t// Do not touch the active tool set during factory registration: ExtensionAPI\n\t// actions are unbound until the session binds the runtime. session_start applies\n\t// baseline visibility once actions work; later hooks only enforce goal safety.\n\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>\",\n\t\tgetArgumentCompletions: (prefix) =>\n\t\t\tcompleteGoalArguments(prefix, {\n\t\t\t\texperimentalGoals: runtime.settings.experimental.goals,\n\t\t\t}),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst result = parseCommand(args, {\n\t\t\t\texperimentalGoals: runtime.settings.experimental.goals,\n\t\t\t});\n\t\t\tif (typeof result === \"string\") {\n\t\t\t\tctx.ui.notify(result, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (runtime.queueFrozen) {\n\t\t\t\tif (result.kind === \"show\") commands.showGoal(ctx);\n\t\t\t\telse if (result.kind === \"clear\") commands.clearGoal(ctx);\n\t\t\t\telse commands.notifyFrozenQueue(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (runtime.pendingQueueAction && result.kind !== \"show\" && result.kind !== \"clear\") {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\"A queued goal change is waiting for Pi to settle. Retry after it finishes.\",\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tswitch (result.kind) {\n\t\t\t\tcase \"show\":\n\t\t\t\t\tcommands.showGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"pause\":\n\t\t\t\t\tcommands.pauseGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"resume\":\n\t\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"clear\":\n\t\t\t\t\tcommands.clearGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"edit\":\n\t\t\t\t\tawait commands.editGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"add\":\n\t\t\t\t\tawait commands.addGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"prioritize\":\n\t\t\t\t\tawait commands.prioritizeGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"drop-last\":\n\t\t\t\t\tcommands.dropLastGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"skip\":\n\t\t\t\t\tawait commands.skipGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"start\":\n\t\t\t\t\tawait commands.startGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tclearCompletionStatusTimer();\n\t\tclearStatusRefreshTimer(); // lunr\n\t\tclearContinuationTracking();\n\t\tclearPendingGoalPrompts();\n\t\truntime.agentRunGoalId = undefined;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t\truntime.queuedGoals = [];\n\t\truntime.pendingQueueAction = undefined;\n\t\truntime.queueFrozen = false;\n\t\tconst previousToolVisibility = runtime.settings.toolVisibility;\n\t\tconst settingsResult = readGoalSettings(options.settingsPath);\n\t\truntime.settings =\n\t\t\tsettingsResult.kind === \"loaded\" ? settingsResult.settings : DEFAULT_GOAL_SETTINGS;\n\t\tif (settingsResult.kind === \"invalid\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`pi-goal settings ignored: ${settingsResult.reason}. Using default settings.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t}\n\t\tif (runtime.settings.experimental.goals) {\n\t\t\tctx.ui.notify(EXPERIMENTAL_GOALS_WARNING, \"warning\");\n\t\t}\n\t\tif (\n\t\t\truntime.settings.toolVisibility === \"after-first-goal\" &&\n\t\t\tpreviousToolVisibility === \"always\"\n\t\t) {\n\t\t\truntime.goalToolsUnlocked = false;\n\t\t}\n\t\tif (runtime.settings.toolVisibility === \"always\") {\n\t\t\tif (runtime.goalToolsHiddenByPolicy.size > 0) {\n\t\t\t\ttry {\n\t\t\t\t\trestoreGoalToolsHiddenByPolicy();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Could not restore always-visible goal tools: ${formatError(error)}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\truntime.goalToolsUnlocked = true;\n\t\t}\n\n\t\tconst loaded = loadGoalStateFromSession(ctx);\n\t\truntime.activeGoal = loaded.goal;\n\t\truntime.queuedGoals = loaded.queue;\n\t\truntime.pendingQueueAction = loaded.pendingAction;\n\t\truntime.queueFrozen = loaded.hasExperimentalQueueState && !runtime.settings.experimental.goals;\n\t\tif (runtime.queueFrozen) {\n\t\t\tif (runtime.activeGoal) persistGoal(runtime.activeGoal);\n\t\t\tctx.ui.setStatus(STATUS_KEY, \"queue off\");\n\t\t\tctx.ui.notify(\n\t\t\t\t\"An experimental goal queue is frozen because experimental.goals is disabled. Re-enable it and run /reload to continue, or use /goal clear.\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tlet startRestoredQueuedGoal = false;\n\t\tif (runtime.activeGoal?.status === \"queued\" && !runtime.pendingQueueAction) {\n\t\t\truntime.activeGoal = activateQueuedGoal(runtime.activeGoal, currentTokenTotal(ctx));\n\t\t\tstartRestoredQueuedGoal = runtime.activeGoal.status === \"active\";\n\t\t}\n\t\tif (runtime.pendingQueueAction) await dispatchPendingQueueActionIfSettled(ctx);\n\t\tif (runtime.activeGoal) {\n\t\t\tif (runtime.activeGoal.status === \"active\") {\n\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\t\t}\n\t\t\tif (runtime.settings.toolVisibility === \"after-first-goal\") {\n\t\t\t\t// Registered tools are already active on an unrestricted fresh runtime.\n\t\t\t\t// If an earlier session_start handler removed them, that restrictive\n\t\t\t\t// policy wins: mark lazy visibility unlocked without widening its set.\n\t\t\t\truntime.goalToolsUnlocked = true;\n\t\t\t\truntime.goalToolsHiddenByPolicy.clear();\n\t\t\t}\n\t\t\tif (runtime.activeGoal.status === \"active\" && !goalToolsAvailable()) {\n\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tif (startRestoredQueuedGoal) {\n\t\t\t\tconst restoredGoal = runtime.activeGoal;\n\t\t\t\tconst sent = await sendOwnedGoalPrompt(\n\t\t\t\t\truntime.pi,\n\t\t\t\t\tctx,\n\t\t\t\t\trestoredGoal.id,\n\t\t\t\t\tbuildGoalPrompt(restoredGoal),\n\t\t\t\t);\n\t\t\t\tif (!sent && runtime.activeGoal?.id === restoredGoal.id) {\n\t\t\t\t\truntime.activeGoal = transitionGoal(restoredGoal, \"paused\");\n\t\t\t\t\tblockStaleGoalToolCalls();\n\t\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (runtime.settings.toolVisibility === \"after-first-goal\" && !runtime.goalToolsUnlocked) {\n\t\t\t\thideGoalToolsIfLocked();\n\t\t\t}\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\tif (runtime.activeGoal) {\n\t\t\tif (!runtime.queueFrozen && runtime.activeGoal.status === \"active\") {\n\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx, false);\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t}\n\t\tclearContinuationTracking();\n\t\tclearPendingGoalPrompts();\n\t\truntime.agentRunGoalId = undefined;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t\truntime.activeGoal = undefined;\n\t\truntime.queuedGoals = [];\n\t\truntime.pendingQueueAction = undefined;\n\t\truntime.queueFrozen = false;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tclearCompletionStatusTimer();\n\t\tclearStatusRefreshTimer(); // lunr\n\t});\n\n\tpi.on(\"session_before_compact\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (runtime.activeGoal?.status === \"budget_limited\") {\n\t\t\tif ((event as { willRetry?: boolean }).willRetry === true) return { cancel: true as const };\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") return;\n\t\tif (!updateGoalUsage(runtime.activeGoal, ctx)) return;\n\t\tcancelContinuationWork();\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\tif (runtime.pendingQueueAction) return;\n\t\tif (limitActiveGoalForBudget(ctx, false)) return { cancel: true as const };\n\t});\n\n\tpi.on(\"session_compact\", async (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (runtime.activeGoal?.status !== \"active\") {\n\t\t\tclearGoalRecovery();\n\t\t\tif (runtime.pendingQueueAction) await dispatchPendingQueueActionIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tconst restoredState = loadGoalStateFromSession(ctx);\n\t\tif (restoredState.goal?.id === runtime.activeGoal.id) {\n\t\t\truntime.activeGoal = restoredState.goal;\n\t\t\truntime.queuedGoals = restoredState.queue;\n\t\t\truntime.pendingQueueAction = restoredState.pendingAction;\n\t\t}\n\t\tconst usageRecorded = updateGoalUsage(runtime.activeGoal, ctx);\n\t\tif (usageRecorded) {\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t}\n\t\tif (runtime.pendingQueueAction) {\n\t\t\tawait dispatchPendingQueueActionIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (!usageRecorded) return;\n\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\n\t\tconst wasPiRetry = isPiOwnedCompactionRetry(event, runtime.activeGoal.id);\n\t\tclearGoalRecoveryForGoal(runtime.activeGoal.id);\n\t\tif (wasPiRetry) return;\n\t\trequestContinuation(runtime.activeGoal);\n\t\t// Manual compaction does not emit agent_settled. This common dispatcher is\n\t\t// therefore the narrow fallback; threshold compaction leaves the intent for\n\t\t// agent_settled when Pi is still busy.\n\t\tdispatchContinuationIfSettled(ctx);\n\t});\n\n\tpi.on(\"input\", (event) => {\n\t\tif (event.source === \"extension\") {\n\t\t\tif (\n\t\t\t\tconsumeCancelledContinuationPrompt(event.text) ||\n\t\t\t\tconsumeStaleOwnedGoalPrompt(event.text)\n\t\t\t) {\n\t\t\t\treturn { action: \"handled\" as const };\n\t\t\t}\n\t\t\tif (runtime.queueFrozen) return;\n\t\t\tclearGoalRecovery();\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.queueFrozen) return;\n\t\tif (/^\\/goal(?:\\s|$)/u.test(event.text.trimStart())) return;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t});\n\n\t// lunr: the previous context-event filter dropped superseded budget\n\t// wrap-up messages from request context. That breaks Anthropic prefix\n\t// continuity (full cache miss from the cut). The wrap-up custom message\n\t// is small; keeping history unfiltered is cheaper than a cache rewrite.\n\t// keepBudgetWrapUpMessage remains on the runtime if a future token-saving\n\t// path can prove the wrap-up was never sent.\n\n\tpi.on(\"tool_call\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) {\n\t\t\tif (!isGoalToolName(event.toolName)) return;\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t\"The experimental goal queue is frozen. Re-enable experimental.goals and run /reload, or use /goal clear.\",\n\t\t\t};\n\t\t}\n\t\t// lunr: mask locked goal tools instead of removing them from the active\n\t\t// list (setActiveTools churn busts the tools+system cache prefix).\n\t\tif (isGoalToolName(event.toolName) && runtime.areGoalToolsLocked()) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: \"Goal tools are locked until a /goal is activated.\",\n\t\t\t};\n\t\t}\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id &&\n\t\t\tevent.toolName !== \"goal_complete\"\n\t\t) {\n\t\t\t// A blocked tool result would normally trigger another model call. Abort the\n\t\t\t// wrap-up instead so a tool-seeking model cannot create an unbounded loop.\n\t\t\tabortCurrentTurn(ctx);\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: \"Goal token budget is exhausted; only goal_complete is allowed during wrap-up.\",\n\t\t\t};\n\t\t}\n\t\tif (!runtime.staleGoalToolCallsBlocked) return;\n\t\tif (!runtime.activeGoal || !blocksStaleGoalToolCalls(runtime.activeGoal.status)) {\n\t\t\tclearStaleGoalToolCallBlock();\n\t\t\treturn;\n\t\t}\n\t\treturn {\n\t\t\tblock: true,\n\t\t\treason: \"Blocked stale /goal tool call after the goal stopped or was interrupted.\",\n\t\t};\n\t});\n\n\tpi.on(\"tool_execution_end\", (_event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id &&\n\t\t\t!runtime.budgetWrapUp.delivered\n\t\t) {\n\t\t\tqueueBudgetWrapUp(ctx, runtime.activeGoal);\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") return;\n\n\t\t// AgentSession persists assistant message_end before tool execution events,\n\t\t// so the completed assistant call's usage is authoritative at this boundary.\n\t\tif (!updateGoalUsage(runtime.activeGoal, ctx)) return;\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\tif (limitActiveGoalForBudget(ctx, true)) return;\n\t\tif (!goalToolsAvailable()) pauseGoalForUnavailableTools(ctx);\n\t});\n\n\tpi.on(\"before_agent_start\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) {\n\t\t\truntime.agentRunGoalId = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst goalPromptGoalId = consumePendingGoalPrompt(event.prompt);\n\t\tconst continuationGoalId = goalPromptGoalId ? undefined : markContinuationStarted(event.prompt);\n\t\tconst ownedPromptGoalId = goalPromptGoalId ?? continuationGoalId;\n\t\tconst activeBudgetWrapUp = runtime.hasActiveBudgetWrapUp();\n\t\tconst activeGoalRecovery = runtime.hasActiveGoalRecovery();\n\t\t// lunr: auto-resume a usage_limited goal on a wake-up turn. Two triggers:\n\t\t// - resumeAfter was parsed from the provider error and has elapsed (any turn\n\t\t// resumes — the reset time is known, so the goal should not stay parked);\n\t\t// - no reset time was parseable: only a cron-fired turn resumes (the user\n\t\t// scheduled the wake-up explicitly; ordinary manual turns don't hijack —\n\t\t// /goal resume stays the manual path).\n\t\t// Gateway cron fires are headless and cannot see this session's goal.\n\t\tconst resumeAfter = runtime.activeGoal?.resumeAfter;\n\t\tconst resumeDue = resumeAfter !== undefined && Date.now() >= resumeAfter;\n\t\tconst cronWakeUp = resumeAfter === undefined && isCronFire();\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"usage_limited\" &&\n\t\t\t(resumeDue || cronWakeUp) &&\n\t\t\t!ownedPromptGoalId &&\n\t\t\t!activeBudgetWrapUp &&\n\t\t\t!activeGoalRecovery\n\t\t) {\n\t\t\tconst resumed = runtime.reactivateGoalForResume(ctx);\n\t\t\tif (resumed) {\n\t\t\t\truntime.agentRunGoalId = resumed.id;\n\t\t\t\tif (!goalToolsAvailable()) {\n\t\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tsystemPrompt: event.systemPrompt + \"\\n\\n\" + buildGoalSystemPrompt(runtime.activeGoal),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"prioritize\" &&\n\t\t\t!activeBudgetWrapUp &&\n\t\t\t!activeGoalRecovery\n\t\t) {\n\t\t\t// A turn that starts after priority intent is committed belongs to neither\n\t\t\t// the displaced goal nor the not-yet-activated urgent goal. Persist the\n\t\t\t// displaced goal's final accounting boundary so reload cannot absorb this run.\n\t\t\tif (!runtime.pendingQueueAction.displacedUsageFinalized) {\n\t\t\t\tif (runtime.activeGoal?.status === \"active\") {\n\t\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx, false);\n\t\t\t\t}\n\t\t\t\truntime.pendingQueueAction.displacedUsageFinalized = true;\n\t\t\t\tif (runtime.activeGoal) {\n\t\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t\truntime.agentRunGoalId = null;\n\t\t\tif (ownedPromptGoalId) abortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (activeBudgetWrapUp && runtime.activeGoal) {\n\t\t\truntime.agentRunGoalId = runtime.activeGoal.id;\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.goalId === runtime.activeGoal?.id\n\t\t) {\n\t\t\truntime.agentRunGoalId = ownedPromptGoalId ?? runtime.activeGoal.id;\n\t\t\tif (ownedPromptGoalId) abortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {\n\t\t\truntime.agentRunGoalId = ownedPromptGoalId;\n\t\t\tif (runtime.activeGoal?.status === \"active\" && !goalToolsAvailable()) {\n\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t}\n\t\t\tabortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") {\n\t\t\truntime.agentRunGoalId = undefined;\n\t\t\treturn;\n\t\t}\n\t\truntime.agentRunGoalId = runtime.activeGoal.id;\n\t\tif (!goalToolsAvailable()) {\n\t\t\tpauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== undefined);\n\t\t\treturn;\n\t\t}\n\n\t\treturn {\n\t\t\tsystemPrompt: `${event.systemPrompt}\\n\\n${buildGoalSystemPrompt(runtime.activeGoal)}`,\n\t\t};\n\t});\n\n\tpi.on(\"agent_end\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tconst agentRunGoalId = runtime.agentRunGoalId;\n\t\truntime.agentRunGoalId = undefined;\n\t\tif (\n\t\t\tagentRunGoalId === null ||\n\t\t\t(!runtime.canRecordGoalUsage() && !runtime.hasActiveBudgetWrapUp())\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (agentRunGoalId && agentRunGoalId !== runtime.activeGoal?.id) return;\n\t\tif (!runtime.activeGoal) return;\n\t\tif (\n\t\t\truntime.activeGoal.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id\n\t\t) {\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tclearBudgetWrapUp();\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal.status !== \"active\") return;\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.goalId === runtime.activeGoal.id\n\t\t) {\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\treturn;\n\t\t}\n\n\t\tconst goalId = runtime.activeGoal.id;\n\t\tconst alreadyAwaitingContinuation = hasContinuationWorkForGoal(goalId);\n\t\tconst finalAssistant = findFinalAssistantMessage(event.messages);\n\n\t\tif (!alreadyAwaitingContinuation) runtime.activeGoal = incrementGoal(runtime.activeGoal);\n\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\n\t\tif (finalAssistant?.stopReason === \"aborted\") {\n\t\t\tclearGoalRecoveryForGoal(goalId);\n\t\t\tstopGoalAfterAgentEnd(ctx, runtime.activeGoal, finalAssistant, \"paused\");\n\t\t\treturn;\n\t\t}\n\n\t\tif (finalAssistant?.stopReason === \"error\") {\n\t\t\tif (isRetryableGoalInterruption(finalAssistant)) {\n\t\t\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\t\t\tif (!goalToolsAvailable()) {\n\t\t\t\t\tpauseGoalForUnavailableTools(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\truntime.goalRecovery = {\n\t\t\t\t\tgoalId,\n\t\t\t\t\tkind: isGoalContextOverflow(finalAssistant) ? \"compaction_retry\" : \"provider_retry\",\n\t\t\t\t};\n\t\t\t\tcancelContinuationWork();\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclearGoalRecoveryForGoal(goalId);\n\t\t\tstopGoalAfterAgentEnd(\n\t\t\t\tctx,\n\t\t\t\truntime.activeGoal,\n\t\t\t\tfinalAssistant,\n\t\t\t\tisUsageLimitedGoalInterruption(finalAssistant) ? \"usage_limited\" : \"blocked\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tclearGoalRecoveryForGoal(goalId);\n\n\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\tif (!goalToolsAvailable()) {\n\t\t\tpauseGoalForUnavailableTools(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\n\t\tconst currentGoal = runtime.activeGoal;\n\t\tif (!currentGoal || currentGoal.id !== goalId || currentGoal.status !== \"active\") return;\n\t\tif (runtime.pendingQueueAction?.kind === \"prioritize\") return;\n\t\trequestContinuation(currentGoal);\n\t});\n\n\tpi.on(\"agent_settled\", (_event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (!runtime.pendingQueueAction) {\n\t\t\tdispatchContinuationIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\t\treturn dispatchPendingQueueActionIfSettled(ctx).then((dispatched) => {\n\t\t\tif (!dispatched) dispatchContinuationIfSettled(ctx);\n\t\t});\n\t});\n\n\tfunction hasPendingSkipForGoal(goalId: string) {\n\t\treturn (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.reason === \"skip\" &&\n\t\t\truntime.pendingQueueAction.goalId === goalId\n\t\t);\n\t}\n\n\tfunction stopGoalAfterAgentEnd(\n\t\tctx: StatusContext,\n\t\tgoal: ActiveGoal,\n\t\tassistant: AssistantMessageLike,\n\t\tstatus: \"paused\" | \"blocked\" | \"usage_limited\",\n\t) {\n\t\tcancelContinuationWork();\n\t\tclearBudgetWrapUp();\n\t\tblockStaleGoalToolCalls();\n\t\tabortCurrentTurn(ctx);\n\t\t// lunr: if the provider error carries a reset time, pre-fill resumeAfter so a\n\t\t// one-shot /cron wake-up auto-resumes the goal without a manual /goal resume.\n\t\tconst resumeAfter = status === \"usage_limited\" ? parseUsageResetTimeMs(assistant.errorMessage) : undefined;\n\t\tconst goalWithResume = resumeAfter !== undefined ? { ...goal, resumeAfter } : goal;\n\t\truntime.activeGoal = transitionGoal(goalWithResume, status);\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\n\t\tconst details = assistant.errorMessage\n\t\t\t? ` (${truncateNotification(assistant.errorMessage)})`\n\t\t\t: \"\";\n\t\tif (status === \"paused\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal paused after interruption${details}. Run /goal resume to continue.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (status === \"usage_limited\") {\n\t\t\tconst when = resumeAfter !== undefined ? ` Auto-resume scheduled for ${new Date(resumeAfter).toLocaleString()}.` : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal usage-limited${details}.${when} Run /goal resume when usage resets, or schedule a one-shot /cron firing \"continue\" into this session to wake it.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\t`Goal blocked after agent error${details}. Resolve the blocker or run /goal resume to retry.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nexport default function goal(pi: ExtensionAPI, options: GoalOptions = {}) {\n\tregisterGoalRuntime(pi, options);\n}\n\nexport {\n\tassistantUsageTokens,\n\tcumulativeAssistantTokens,\n\tformatDuration,\n\tformatTokenCount,\n} from \"./accounting.js\";\n\nexport {\n\tcompleteGoalArguments,\n\tparseCommand,\n\tparseTokenBudget,\n\tvalidateObjective,\n} from \"./command.js\";\n\nexport { buildGoalSystemPrompt } from \"./prompts.js\";\n\nexport {\n\tfindFinalAssistantMessage,\n\tformatStatus,\n\tisContradictoryCompletionSummary,\n\tisRetryableGoalInterruption,\n\tisUsageLimitedGoalInterruption,\n} from \"./runtime.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"goal.d.ts","sourceRoot":"","sources":["../../../../src/builtin-extensions/narumiruna-pi-goal/src/goal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAmDpE,UAAU,WAAW;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AA06BD,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,GAAE,WAAgB,QAEvE;AAED,OAAO,EACN,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,EACd,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EACN,yBAAyB,EACzB,YAAY,EACZ,gCAAgC,EAChC,2BAA2B,EAC3B,8BAA8B,GAC9B,MAAM,cAAc,CAAC","sourcesContent":["// @ts-nocheck\n// lunr: defineTool imported from the concrete module, NOT the package barrel —\n// the barrel re-exports main.ts which imports this extension (cycle).\nimport { defineTool } from \"../../../core/extensions/types.js\";\nimport { isCronFire } from \"../../../core/cron/fire-guard.js\";\nimport type { ExtensionAPI } from \"@ashx-j/lunr\";\nimport { Type } from \"typebox\";\nimport { Container, Markdown, Text } from \"@ashx-j/lunr-tui\";\nimport { currentTokenTotal } from \"./accounting.js\";\nimport { completeGoalArguments, parseCommand } from \"./command.js\";\nimport { GoalCommandController } from \"./commands.js\";\nimport { type ActiveGoal, loadGoalStateFromSession } from \"./persistence.js\";\nimport { buildGoalPrompt, buildGoalSystemPrompt } from \"./prompts.js\";\nimport { activateQueuedGoal } from \"./queue.js\";\nimport {\n\ttype AssistantMessageLike,\n\tabortCurrentTurn,\n\tblocksStaleGoalToolCalls,\n\tfindFinalAssistantMessage,\n\tformatError,\n\tformatStatus,\n\tGOAL_BLOCKED_TOOL,\n\tGOAL_COMPLETE_TOOL,\n\tGoalRuntime,\n\tgoalIdRejectionReason,\n\tincrementGoal,\n\tisContradictoryCompletionSummary,\n\tisGoalContextOverflow,\n\tisRetryableGoalInterruption,\n\tisUsageLimitedGoalInterruption,\n\tparseUsageResetTimeMs,\n\tSTATUS_KEY,\n\ttype StatusContext,\n\ttransitionGoal,\n\ttruncateNotification,\n} from \"./runtime.js\";\nimport { DEFAULT_GOAL_SETTINGS, readGoalSettings } from \"./settings.js\";\n\n// goal.ts is the Pi-facing composition root: it keeps tool contracts and event\n// ordering together. Per-session mechanisms live in runtime.ts, while user command\n// transitions live in commands.ts. Each factory constructs isolated instances.\n\ninterface GoalCompleteDetails {\n\tgoal: string;\n\tgoal_id: string;\n\tsummary: string;\n}\n\ninterface GoalBlockedDetails {\n\tgoal: string;\n\tgoal_id: string;\n\treason: string;\n\tevidence: string;\n\trepeated_turns: number;\n}\n\ninterface GoalOptions {\n\tsettingsPath?: string;\n}\n\nconst GOAL_COMPLETE_MESSAGE_TYPE = \"goal-complete\";\nconst EXPERIMENTAL_GOALS_WARNING =\n\t\"Experimental ordered goals are enabled for pi-goal. Queue behavior and persisted state may change.\";\nconst MAX_BLOCKER_REASON_LENGTH = 1_000;\nconst MAX_BLOCKER_EVIDENCE_LENGTH = 4_000;\n\nfunction registerGoalRuntime(pi: ExtensionAPI, options: GoalOptions = {}) {\n\tconst runtime = new GoalRuntime(pi);\n\tconst commands = new GoalCommandController(runtime);\n\n\t// Bind per-factory runtime operations once so event orchestration stays concise\n\t// without reintroducing module-global mutable state.\n\tconst clearCompletionStatusTimer = runtime.clearCompletionStatusTimer.bind(runtime);\n\t// lunr: footer refresh timer cleanup\n\tconst clearStatusRefreshTimer = runtime.clearStatusRefreshTimer.bind(runtime);\n\tconst clearContinuationTracking = runtime.clearContinuationTracking.bind(runtime);\n\tconst clearPendingGoalPrompts = runtime.clearPendingGoalPrompts.bind(runtime);\n\tconst clearGoalRecovery = runtime.clearGoalRecovery.bind(runtime);\n\tconst clearBudgetWrapUp = runtime.clearBudgetWrapUp.bind(runtime);\n\tconst clearStaleGoalToolCallBlock = runtime.clearStaleGoalToolCallBlock.bind(runtime);\n\tconst persistGoal = runtime.persistGoal.bind(runtime);\n\tconst updateGoalUsage = runtime.recordGoalUsage.bind(runtime);\n\tconst updateStatus = runtime.updateStatus.bind(runtime);\n\tconst limitActiveGoalForBudget = runtime.limitActiveGoalForBudget.bind(runtime);\n\tconst hideGoalToolsIfLocked = runtime.hideGoalToolsIfLocked.bind(runtime);\n\tconst goalToolsAvailable = runtime.goalToolsAvailable.bind(runtime);\n\tconst pauseGoalForUnavailableTools = runtime.pauseGoalForUnavailableTools.bind(runtime);\n\tconst isPiOwnedCompactionRetry = runtime.isPiOwnedCompactionRetry.bind(runtime);\n\tconst requestContinuation = runtime.requestContinuation.bind(runtime);\n\tconst dispatchContinuationIfSettled = runtime.dispatchContinuationIfSettled.bind(runtime);\n\tconst isGoalToolName = runtime.isGoalToolName.bind(runtime);\n\tconst queueBudgetWrapUp = runtime.queueBudgetWrapUp.bind(runtime);\n\tconst clearGoalRecoveryForGoal = runtime.clearGoalRecoveryForGoal.bind(runtime);\n\tconst blockStaleGoalToolCalls = runtime.blockStaleGoalToolCalls.bind(runtime);\n\tconst cancelContinuationWork = runtime.cancelContinuationWork.bind(runtime);\n\tconst consumeCancelledContinuationPrompt =\n\t\truntime.consumeCancelledContinuationPrompt.bind(runtime);\n\tconst consumeStaleOwnedGoalPrompt = runtime.consumeStaleOwnedGoalPrompt.bind(runtime);\n\tconst consumePendingGoalPrompt = runtime.consumeOwnedGoalPrompt.bind(runtime);\n\tconst markContinuationStarted = runtime.markContinuationStarted.bind(runtime);\n\tconst hasContinuationWorkForGoal = runtime.hasContinuationWorkForGoal.bind(runtime);\n\tconst clearActiveGoal = runtime.clearActiveGoal.bind(runtime);\n\tconst showCompletionStatus = runtime.showCompletionStatus.bind(runtime);\n\tconst restoreGoalToolsHiddenByPolicy = runtime.restoreGoalToolsHiddenByPolicy.bind(runtime);\n\tconst sendOwnedGoalPrompt = (\n\t\t_pi: ExtensionAPI,\n\t\tctx: StatusContext,\n\t\tgoalId: string,\n\t\tprompt: string,\n\t) => runtime.sendOwnedGoalPrompt(ctx, goalId, prompt);\n\tconst dispatchPendingQueueActionIfSettled =\n\t\tcommands.dispatchPendingQueueActionIfSettled.bind(commands);\n\n\tconst emitGoalCompleteMessage = (summary: string) => {\n\t\tconst text = summary.startsWith(\"Goal complete\") ? summary : summary;\n\t\tpi.sendMessage({\n\t\t\tcustomType: GOAL_COMPLETE_MESSAGE_TYPE,\n\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\tdisplay: true,\n\t\t});\n\t};\n\n\tpi.registerMessageRenderer(GOAL_COMPLETE_MESSAGE_TYPE, (message, _options, theme) => {\n\t\tconst raw =\n\t\t\ttypeof message.content === \"string\"\n\t\t\t\t? message.content\n\t\t\t\t: message.content\n\t\t\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t\t\t.map((block) => (\"text\" in block ? block.text : \"\"))\n\t\t\t\t\t\t.join(\"\\n\");\n\t\tconst c = new Container();\n\t\tc.addChild(new Markdown(`● ${raw}`, 1, 0, undefined, {\n\t\t\tcolor: (content) => theme.fg(\"text\", content),\n\t\t}));\n\t\treturn c;\n\t});\n\n\tconst goalCompleteTool = defineTool({\n\t\tname: GOAL_COMPLETE_TOOL,\n\t\tlabel: \"Goal Complete\",\n\t\tdescription:\n\t\t\t\"Mark the active /goal as complete after all required work is done and verified, using the current goal_id stale-turn guard. Do not use for partial progress, blockers, failing, or unverified work.\",\n\t\tpromptSnippet:\n\t\t\t\"Mark the active /goal as complete after fully finishing and verifying it, with the current goal_id\",\n\t\tpromptGuidelines: [\n\t\t\t\"When a /goal is active, keep working until the goal is complete; do not stop with only a plan or partial progress.\",\n\t\t\t\"Before calling goal_complete, audit the active goal requirement by requirement against the current files, command output, tests, or external state.\",\n\t\t\t\"Pass the exact goal_id shown in the current /goal prompt; never reuse a goal_id from an older, stopped, replaced, or cleared turn.\",\n\t\t\t\"Call goal_complete only after the requested goal is fully implemented, verified, and no known required work remains; otherwise keep working.\",\n\t\t],\n\t\tparameters: Type.Object({\n\t\t\tgoal_id: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"The exact goal_id shown in the current active /goal prompt. Used only to reject stale completion calls from older turns.\",\n\t\t\t}),\n\t\t\tsummary: Type.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"State what was completed and what evidence verified it. Do not use this tool to report partial progress, blockers, failures, or remaining work.\",\n\t\t\t}),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst completedGoal = runtime.activeGoal;\n\t\t\tconst goal = completedGoal?.text ?? \"unknown goal\";\n\t\t\tconst requestedGoalId = typeof params.goal_id === \"string\" ? params.goal_id.trim() : \"\";\n\t\t\tconst summary = typeof params.summary === \"string\" ? params.summary.trim() : \"\";\n\n\t\t\tif (!completedGoal) {\n\t\t\t\tconst rejection = \"Goal completion rejected: no active goal.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst completingDuringBudgetWrapUp = runtime.hasActiveBudgetWrapUp();\n\t\t\tif (!runtime.canRecordGoalUsage() && !completingDuringBudgetWrapUp) {\n\t\t\t\tconst rejection = \"Goal completion rejected: current run does not own the active goal.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (hasPendingSkipForGoal(completedGoal.id)) {\n\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\tclearBudgetWrapUp();\n\t\t\t\tconst rejection = \"Goal completion rejected: goal is queued to be skipped.\";\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst staleGoalRejection = goalIdRejectionReason(completedGoal, requestedGoalId);\n\t\t\tif (staleGoalRejection) {\n\t\t\t\tconst rejection = `Goal completion rejected: ${staleGoalRejection}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\tif (completingDuringBudgetWrapUp) {\n\t\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\t\tclearBudgetWrapUp();\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: completingDuringBudgetWrapUp || undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (completedGoal.status !== \"active\" && !completingDuringBudgetWrapUp) {\n\t\t\t\tconst rejection = `Goal completion rejected: goal is ${completedGoal.status}, not active.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: rejection }],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst rejectionReason = !summary\n\t\t\t\t? \"summary is empty\"\n\t\t\t\t: isContradictoryCompletionSummary(summary)\n\t\t\t\t\t? \"summary says the goal is not complete\"\n\t\t\t\t\t: undefined;\n\t\t\tif (rejectionReason) {\n\t\t\t\tupdateGoalUsage(completedGoal, ctx);\n\t\t\t\tpersistGoal(completedGoal);\n\t\t\t\tupdateStatus(ctx, completedGoal);\n\t\t\t\tconst rejection = `Goal completion rejected: ${rejectionReason}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\tif (completingDuringBudgetWrapUp) clearBudgetWrapUp();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: rejection,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: completingDuringBudgetWrapUp || undefined,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\truntime.activeGoal = transitionGoal(completedGoal, \"complete\");\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tif (runtime.pendingQueueAction?.kind === \"prioritize\") {\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"complete\");\n\t\t\t\temitGoalCompleteMessage(summary);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Goal complete: ${summary}` }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\tsummary,\n\t\t\t\t\t} satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (runtime.queuedGoals.length > 0) {\n\t\t\t\truntime.pendingQueueAction = {\n\t\t\t\t\tkind: \"advance\",\n\t\t\t\t\tgoalId: runtime.activeGoal.id,\n\t\t\t\t\treason: \"complete\",\n\t\t\t\t\tcompletedText: goal,\n\t\t\t\t};\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"complete\");\n\t\t\t\temitGoalCompleteMessage(summary);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Goal complete: ${summary}\\nNext goal queued: ${runtime.queuedGoals[0]?.text}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\tsummary,\n\t\t\t\t\t} satisfies GoalCompleteDetails,\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\n\t\t\tctx.ui.setStatus(STATUS_KEY, formatStatus(runtime.activeGoal));\n\t\t\tclearActiveGoal(ctx);\n\t\t\tshowCompletionStatus(ctx);\n\t\t\temitGoalCompleteMessage(summary);\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `Goal complete: ${summary}` }],\n\t\t\t\tdetails: { goal, goal_id: requestedGoalId, summary } satisfies GoalCompleteDetails,\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t},\n\t\trenderResult(_result, { isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"Completing goal...\"), 0, 0);\n\t\t\treturn { render: () => [], invalidate() {} };\n\t\t},\n\t});\n\n\tconst goalBlockedTool = defineTool({\n\t\tname: GOAL_BLOCKED_TOOL,\n\t\tlabel: \"Goal Blocked\",\n\t\tdescription:\n\t\t\t\"Stop the active /goal only at a true impasse after the same blocker recurs for at least three consecutive goal turns, with the current goal_id and concrete evidence that user or external action is required. Do not use for ordinary clarification, uncertainty, or recoverable failures.\",\n\t\tpromptSnippet:\n\t\t\t\"Mark the active /goal blocked only after the same blocker recurs for three consecutive goal turns\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use goal_blocked only for a true impasse after the same blocker recurs for at least three consecutive goal turns and concrete evidence shows user or external action is required.\",\n\t\t\t\"After a blocked goal is resumed, start a fresh three-turn blocker audit before using goal_blocked again.\",\n\t\t\t\"Do not use goal_blocked for ordinary clarification, incomplete work, uncertainty, difficult tasks, or recoverable tool/provider failures.\",\n\t\t\t\"Pass goal_blocked the exact current goal_id; never reuse a goal_id from an older, stopped, replaced, or cleared goal turn.\",\n\t\t],\n\t\tparameters: Type.Object({\n\t\t\tgoal_id: Type.String({\n\t\t\t\tdescription: \"The exact goal_id shown in the current active /goal prompt.\",\n\t\t\t}),\n\t\t\treason: Type.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: MAX_BLOCKER_REASON_LENGTH,\n\t\t\t\tdescription: \"The specific user or external action required to unblock the goal.\",\n\t\t\t}),\n\t\t\tevidence: Type.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: MAX_BLOCKER_EVIDENCE_LENGTH,\n\t\t\t\tdescription: \"Concrete evidence from the repeated attempts that proves the impasse.\",\n\t\t\t}),\n\t\t\trepeated_turns: Type.Integer({\n\t\t\t\tminimum: 3,\n\t\t\t\tdescription: \"Number of separate turns spent trying to resolve this same blocker.\",\n\t\t\t}),\n\t\t}),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst blockedGoal = runtime.activeGoal;\n\t\t\tconst goal = blockedGoal?.text ?? \"unknown goal\";\n\t\t\tconst requestedGoalId = typeof params.goal_id === \"string\" ? params.goal_id.trim() : \"\";\n\t\t\tconst reason = typeof params.reason === \"string\" ? params.reason.trim() : \"\";\n\t\t\tconst evidence = typeof params.evidence === \"string\" ? params.evidence.trim() : \"\";\n\t\t\tconst repeatedTurns =\n\t\t\t\ttypeof params.repeated_turns === \"number\" ? params.repeated_turns : Number.NaN;\n\t\t\tconst reject = (rejectionReason: string, terminate = false) => {\n\t\t\t\tconst rejection = `goal_blocked rejected: ${rejectionReason}.`;\n\t\t\t\tctx.ui.notify(rejection, \"warning\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: rejection }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\t\treason: reason.slice(0, MAX_BLOCKER_REASON_LENGTH),\n\t\t\t\t\t\tevidence: evidence.slice(0, MAX_BLOCKER_EVIDENCE_LENGTH),\n\t\t\t\t\t\trepeated_turns: Number.isFinite(repeatedTurns) ? repeatedTurns : 0,\n\t\t\t\t\t} satisfies GoalBlockedDetails,\n\t\t\t\t\t...(terminate ? { terminate: true as const } : {}),\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tif (!blockedGoal) return reject(\"no active goal\");\n\t\t\tif (!runtime.canRecordGoalUsage()) {\n\t\t\t\treturn reject(\"current run does not own the active goal\");\n\t\t\t}\n\t\t\tif (hasPendingSkipForGoal(blockedGoal.id)) {\n\t\t\t\tupdateGoalUsage(blockedGoal, ctx);\n\t\t\t\tpersistGoal(blockedGoal);\n\t\t\t\tupdateStatus(ctx, blockedGoal);\n\t\t\t\tclearBudgetWrapUp();\n\t\t\t\treturn reject(\"goal is queued to be skipped\", true);\n\t\t\t}\n\t\t\tconst staleGoalRejection = goalIdRejectionReason(blockedGoal, requestedGoalId);\n\t\t\tif (staleGoalRejection) return reject(staleGoalRejection);\n\t\t\tif (blockedGoal.status !== \"active\") {\n\t\t\t\treturn reject(`goal is ${blockedGoal.status}, not active`);\n\t\t\t}\n\t\t\tif (!reason) return reject(\"reason is empty\");\n\t\t\tif (reason.length > MAX_BLOCKER_REASON_LENGTH) return reject(\"reason is too long\");\n\t\t\tif (!evidence) return reject(\"evidence is empty\");\n\t\t\tif (evidence.length > MAX_BLOCKER_EVIDENCE_LENGTH) return reject(\"evidence is too long\");\n\t\t\tif (!Number.isInteger(repeatedTurns)) return reject(\"repeated_turns must be a whole number\");\n\t\t\tif (repeatedTurns < 3) return reject(\"repeated_turns must be at least 3\");\n\n\t\t\tupdateGoalUsage(blockedGoal, ctx);\n\t\t\tcancelContinuationWork();\n\t\t\tclearBudgetWrapUp();\n\t\t\tclearGoalRecoveryForGoal(blockedGoal.id);\n\t\t\tblockStaleGoalToolCalls();\n\t\t\truntime.activeGoal = transitionGoal(blockedGoal, \"blocked\");\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tctx.ui.notify(`Goal blocked: ${truncateNotification(reason)}`, \"warning\");\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: `Goal blocked: ${reason}` }],\n\t\t\t\tdetails: {\n\t\t\t\t\tgoal,\n\t\t\t\t\tgoal_id: requestedGoalId,\n\t\t\t\t\treason,\n\t\t\t\t\tevidence,\n\t\t\t\t\trepeated_turns: repeatedTurns,\n\t\t\t\t} satisfies GoalBlockedDetails,\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t},\n\t});\n\n\tpi.registerTool(goalCompleteTool);\n\tpi.registerTool(goalBlockedTool);\n\t// Do not touch the active tool set during factory registration: ExtensionAPI\n\t// actions are unbound until the session binds the runtime. session_start applies\n\t// baseline visibility once actions work; later hooks only enforce goal safety.\n\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>\",\n\t\tgetArgumentCompletions: (prefix) =>\n\t\t\tcompleteGoalArguments(prefix, {\n\t\t\t\texperimentalGoals: runtime.settings.experimental.goals,\n\t\t\t}),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst result = parseCommand(args, {\n\t\t\t\texperimentalGoals: runtime.settings.experimental.goals,\n\t\t\t});\n\t\t\tif (typeof result === \"string\") {\n\t\t\t\tctx.ui.notify(result, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (runtime.queueFrozen) {\n\t\t\t\tif (result.kind === \"show\") commands.showGoal(ctx);\n\t\t\t\telse if (result.kind === \"clear\") commands.clearGoal(ctx);\n\t\t\t\telse commands.notifyFrozenQueue(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (runtime.pendingQueueAction && result.kind !== \"show\" && result.kind !== \"clear\") {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\"A queued goal change is waiting for Pi to settle. Retry after it finishes.\",\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tswitch (result.kind) {\n\t\t\t\tcase \"show\":\n\t\t\t\t\tcommands.showGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"pause\":\n\t\t\t\t\tcommands.pauseGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"resume\":\n\t\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"clear\":\n\t\t\t\t\tcommands.clearGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"edit\":\n\t\t\t\t\tawait commands.editGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"add\":\n\t\t\t\t\tawait commands.addGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"prioritize\":\n\t\t\t\t\tawait commands.prioritizeGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"drop-last\":\n\t\t\t\t\tcommands.dropLastGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"skip\":\n\t\t\t\t\tawait commands.skipGoal(ctx);\n\t\t\t\t\treturn;\n\t\t\t\tcase \"start\":\n\t\t\t\t\tawait commands.startGoal(result.objective ?? \"\", result.tokenBudget, ctx);\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tclearCompletionStatusTimer();\n\t\tclearStatusRefreshTimer(); // lunr\n\t\tclearContinuationTracking();\n\t\tclearPendingGoalPrompts();\n\t\truntime.agentRunGoalId = undefined;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t\truntime.queuedGoals = [];\n\t\truntime.pendingQueueAction = undefined;\n\t\truntime.queueFrozen = false;\n\t\tconst previousToolVisibility = runtime.settings.toolVisibility;\n\t\tconst settingsResult = readGoalSettings(options.settingsPath);\n\t\truntime.settings =\n\t\t\tsettingsResult.kind === \"loaded\" ? settingsResult.settings : DEFAULT_GOAL_SETTINGS;\n\t\tif (settingsResult.kind === \"invalid\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`pi-goal settings ignored: ${settingsResult.reason}. Using default settings.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t}\n\t\tif (runtime.settings.experimental.goals) {\n\t\t\tctx.ui.notify(EXPERIMENTAL_GOALS_WARNING, \"warning\");\n\t\t}\n\t\tif (\n\t\t\truntime.settings.toolVisibility === \"after-first-goal\" &&\n\t\t\tpreviousToolVisibility === \"always\"\n\t\t) {\n\t\t\truntime.goalToolsUnlocked = false;\n\t\t}\n\t\tif (runtime.settings.toolVisibility === \"always\") {\n\t\t\tif (runtime.goalToolsHiddenByPolicy.size > 0) {\n\t\t\t\ttry {\n\t\t\t\t\trestoreGoalToolsHiddenByPolicy();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Could not restore always-visible goal tools: ${formatError(error)}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\truntime.goalToolsUnlocked = true;\n\t\t}\n\n\t\tconst loaded = loadGoalStateFromSession(ctx);\n\t\truntime.activeGoal = loaded.goal;\n\t\truntime.queuedGoals = loaded.queue;\n\t\truntime.pendingQueueAction = loaded.pendingAction;\n\t\truntime.queueFrozen = loaded.hasExperimentalQueueState && !runtime.settings.experimental.goals;\n\t\tif (runtime.queueFrozen) {\n\t\t\tif (runtime.activeGoal) persistGoal(runtime.activeGoal);\n\t\t\tctx.ui.setStatus(STATUS_KEY, \"queue off\");\n\t\t\tctx.ui.notify(\n\t\t\t\t\"An experimental goal queue is frozen because experimental.goals is disabled. Re-enable it and run /reload to continue, or use /goal clear.\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tlet startRestoredQueuedGoal = false;\n\t\tif (runtime.activeGoal?.status === \"queued\" && !runtime.pendingQueueAction) {\n\t\t\truntime.activeGoal = activateQueuedGoal(runtime.activeGoal, currentTokenTotal(ctx));\n\t\t\tstartRestoredQueuedGoal = runtime.activeGoal.status === \"active\";\n\t\t}\n\t\tif (runtime.pendingQueueAction) await dispatchPendingQueueActionIfSettled(ctx);\n\t\tif (runtime.activeGoal) {\n\t\t\tif (runtime.activeGoal.status === \"active\") {\n\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\t\t}\n\t\t\tif (runtime.settings.toolVisibility === \"after-first-goal\") {\n\t\t\t\t// Registered tools are already active on an unrestricted fresh runtime.\n\t\t\t\t// If an earlier session_start handler removed them, that restrictive\n\t\t\t\t// policy wins: mark lazy visibility unlocked without widening its set.\n\t\t\t\truntime.goalToolsUnlocked = true;\n\t\t\t\truntime.goalToolsHiddenByPolicy.clear();\n\t\t\t}\n\t\t\tif (runtime.activeGoal.status === \"active\" && !goalToolsAvailable()) {\n\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tif (startRestoredQueuedGoal) {\n\t\t\t\tconst restoredGoal = runtime.activeGoal;\n\t\t\t\tconst sent = await sendOwnedGoalPrompt(\n\t\t\t\t\truntime.pi,\n\t\t\t\t\tctx,\n\t\t\t\t\trestoredGoal.id,\n\t\t\t\t\tbuildGoalPrompt(restoredGoal),\n\t\t\t\t);\n\t\t\t\tif (!sent && runtime.activeGoal?.id === restoredGoal.id) {\n\t\t\t\t\truntime.activeGoal = transitionGoal(restoredGoal, \"paused\");\n\t\t\t\t\tblockStaleGoalToolCalls();\n\t\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (runtime.settings.toolVisibility === \"after-first-goal\" && !runtime.goalToolsUnlocked) {\n\t\t\t\thideGoalToolsIfLocked();\n\t\t\t}\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\tif (runtime.activeGoal) {\n\t\t\tif (!runtime.queueFrozen && runtime.activeGoal.status === \"active\") {\n\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx, false);\n\t\t\t}\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t}\n\t\tclearContinuationTracking();\n\t\tclearPendingGoalPrompts();\n\t\truntime.agentRunGoalId = undefined;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t\truntime.activeGoal = undefined;\n\t\truntime.queuedGoals = [];\n\t\truntime.pendingQueueAction = undefined;\n\t\truntime.queueFrozen = false;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tclearCompletionStatusTimer();\n\t\tclearStatusRefreshTimer(); // lunr\n\t});\n\n\tpi.on(\"session_before_compact\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (runtime.activeGoal?.status === \"budget_limited\") {\n\t\t\tif ((event as { willRetry?: boolean }).willRetry === true) return { cancel: true as const };\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") return;\n\t\tif (!updateGoalUsage(runtime.activeGoal, ctx)) return;\n\t\tcancelContinuationWork();\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\tif (runtime.pendingQueueAction) return;\n\t\tif (limitActiveGoalForBudget(ctx, false)) return { cancel: true as const };\n\t});\n\n\tpi.on(\"session_compact\", async (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (runtime.activeGoal?.status !== \"active\") {\n\t\t\tclearGoalRecovery();\n\t\t\tif (runtime.pendingQueueAction) await dispatchPendingQueueActionIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tconst restoredState = loadGoalStateFromSession(ctx);\n\t\tif (restoredState.goal?.id === runtime.activeGoal.id) {\n\t\t\truntime.activeGoal = restoredState.goal;\n\t\t\truntime.queuedGoals = restoredState.queue;\n\t\t\truntime.pendingQueueAction = restoredState.pendingAction;\n\t\t}\n\t\tconst usageRecorded = updateGoalUsage(runtime.activeGoal, ctx);\n\t\tif (usageRecorded) {\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t}\n\t\tif (runtime.pendingQueueAction) {\n\t\t\tawait dispatchPendingQueueActionIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (!usageRecorded) return;\n\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\n\t\tconst wasPiRetry = isPiOwnedCompactionRetry(event, runtime.activeGoal.id);\n\t\tclearGoalRecoveryForGoal(runtime.activeGoal.id);\n\t\tif (wasPiRetry) return;\n\t\trequestContinuation(runtime.activeGoal);\n\t\t// Manual compaction does not emit agent_settled. This common dispatcher is\n\t\t// therefore the narrow fallback; threshold compaction leaves the intent for\n\t\t// agent_settled when Pi is still busy.\n\t\tdispatchContinuationIfSettled(ctx);\n\t});\n\n\tpi.on(\"input\", (event) => {\n\t\tif (event.source === \"extension\") {\n\t\t\tif (\n\t\t\t\tconsumeCancelledContinuationPrompt(event.text) ||\n\t\t\t\tconsumeStaleOwnedGoalPrompt(event.text)\n\t\t\t) {\n\t\t\t\treturn { action: \"handled\" as const };\n\t\t\t}\n\t\t\tif (runtime.queueFrozen) return;\n\t\t\tclearGoalRecovery();\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.queueFrozen) return;\n\t\tif (/^\\/goal(?:\\s|$)/u.test(event.text.trimStart())) return;\n\t\tclearGoalRecovery();\n\t\tclearBudgetWrapUp();\n\t\tclearStaleGoalToolCallBlock();\n\t});\n\n\t// lunr: the previous context-event filter dropped superseded budget\n\t// wrap-up messages from request context. That breaks Anthropic prefix\n\t// continuity (full cache miss from the cut). The wrap-up custom message\n\t// is small; keeping history unfiltered is cheaper than a cache rewrite.\n\t// keepBudgetWrapUpMessage remains on the runtime if a future token-saving\n\t// path can prove the wrap-up was never sent.\n\n\tpi.on(\"tool_call\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) {\n\t\t\tif (!isGoalToolName(event.toolName)) return;\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t\"The experimental goal queue is frozen. Re-enable experimental.goals and run /reload, or use /goal clear.\",\n\t\t\t};\n\t\t}\n\t\t// lunr: mask locked goal tools instead of removing them from the active\n\t\t// list (setActiveTools churn busts the tools+system cache prefix).\n\t\tif (isGoalToolName(event.toolName) && runtime.areGoalToolsLocked()) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: \"Goal tools are locked until a /goal is activated.\",\n\t\t\t};\n\t\t}\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id &&\n\t\t\tevent.toolName !== \"goal_complete\"\n\t\t) {\n\t\t\t// A blocked tool result would normally trigger another model call. Abort the\n\t\t\t// wrap-up instead so a tool-seeking model cannot create an unbounded loop.\n\t\t\tabortCurrentTurn(ctx);\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: \"Goal token budget is exhausted; only goal_complete is allowed during wrap-up.\",\n\t\t\t};\n\t\t}\n\t\tif (!runtime.staleGoalToolCallsBlocked) return;\n\t\tif (!runtime.activeGoal || !blocksStaleGoalToolCalls(runtime.activeGoal.status)) {\n\t\t\tclearStaleGoalToolCallBlock();\n\t\t\treturn;\n\t\t}\n\t\treturn {\n\t\t\tblock: true,\n\t\t\treason: \"Blocked stale /goal tool call after the goal stopped or was interrupted.\",\n\t\t};\n\t});\n\n\tpi.on(\"tool_execution_end\", (_event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id &&\n\t\t\t!runtime.budgetWrapUp.delivered\n\t\t) {\n\t\t\tqueueBudgetWrapUp(ctx, runtime.activeGoal);\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") return;\n\n\t\t// AgentSession persists assistant message_end before tool execution events,\n\t\t// so the completed assistant call's usage is authoritative at this boundary.\n\t\tif (!updateGoalUsage(runtime.activeGoal, ctx)) return;\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\tif (limitActiveGoalForBudget(ctx, true)) return;\n\t\tif (!goalToolsAvailable()) pauseGoalForUnavailableTools(ctx);\n\t});\n\n\tpi.on(\"before_agent_start\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) {\n\t\t\truntime.agentRunGoalId = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst goalPromptGoalId = consumePendingGoalPrompt(event.prompt);\n\t\tconst continuationGoalId = goalPromptGoalId ? undefined : markContinuationStarted(event.prompt);\n\t\tconst ownedPromptGoalId = goalPromptGoalId ?? continuationGoalId;\n\t\tconst activeBudgetWrapUp = runtime.hasActiveBudgetWrapUp();\n\t\tconst activeGoalRecovery = runtime.hasActiveGoalRecovery();\n\t\t// lunr: auto-resume a usage_limited goal on a wake-up turn. Two triggers:\n\t\t// - resumeAfter was parsed from the provider error and has elapsed (any turn\n\t\t// resumes — the reset time is known, so the goal should not stay parked);\n\t\t// - no reset time was parseable: only a cron-fired turn resumes (the user\n\t\t// scheduled the wake-up explicitly; ordinary manual turns don't hijack —\n\t\t// /goal resume stays the manual path).\n\t\t// Gateway cron fires are headless and cannot see this session's goal.\n\t\tconst resumeAfter = runtime.activeGoal?.resumeAfter;\n\t\tconst resumeDue = resumeAfter !== undefined && Date.now() >= resumeAfter;\n\t\tconst cronWakeUp = resumeAfter === undefined && isCronFire();\n\t\tif (\n\t\t\truntime.activeGoal?.status === \"usage_limited\" &&\n\t\t\t(resumeDue || cronWakeUp) &&\n\t\t\t!ownedPromptGoalId &&\n\t\t\t!activeBudgetWrapUp &&\n\t\t\t!activeGoalRecovery\n\t\t) {\n\t\t\tconst resumed = runtime.reactivateGoalForResume(ctx);\n\t\t\tif (resumed) {\n\t\t\t\truntime.agentRunGoalId = resumed.id;\n\t\t\t\tif (!goalToolsAvailable()) {\n\t\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tsystemPrompt: event.systemPrompt + \"\\n\\n\" + buildGoalSystemPrompt(runtime.activeGoal),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"prioritize\" &&\n\t\t\t!activeBudgetWrapUp &&\n\t\t\t!activeGoalRecovery\n\t\t) {\n\t\t\t// A turn that starts after priority intent is committed belongs to neither\n\t\t\t// the displaced goal nor the not-yet-activated urgent goal. Persist the\n\t\t\t// displaced goal's final accounting boundary so reload cannot absorb this run.\n\t\t\tif (!runtime.pendingQueueAction.displacedUsageFinalized) {\n\t\t\t\tif (runtime.activeGoal?.status === \"active\") {\n\t\t\t\t\tupdateGoalUsage(runtime.activeGoal, ctx, false);\n\t\t\t\t}\n\t\t\t\truntime.pendingQueueAction.displacedUsageFinalized = true;\n\t\t\t\tif (runtime.activeGoal) {\n\t\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\t}\n\t\t\t}\n\t\t\truntime.agentRunGoalId = null;\n\t\t\tif (ownedPromptGoalId) abortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (activeBudgetWrapUp && runtime.activeGoal) {\n\t\t\truntime.agentRunGoalId = runtime.activeGoal.id;\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.goalId === runtime.activeGoal?.id\n\t\t) {\n\t\t\truntime.agentRunGoalId = ownedPromptGoalId ?? runtime.activeGoal.id;\n\t\t\tif (ownedPromptGoalId) abortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {\n\t\t\truntime.agentRunGoalId = ownedPromptGoalId;\n\t\t\tif (runtime.activeGoal?.status === \"active\" && !goalToolsAvailable()) {\n\t\t\t\tpauseGoalForUnavailableTools(ctx, false);\n\t\t\t}\n\t\t\tabortCurrentTurn(ctx);\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal?.status !== \"active\") {\n\t\t\truntime.agentRunGoalId = undefined;\n\t\t\treturn;\n\t\t}\n\t\truntime.agentRunGoalId = runtime.activeGoal.id;\n\t\tif (!goalToolsAvailable()) {\n\t\t\tpauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== undefined);\n\t\t\treturn;\n\t\t}\n\n\t\treturn {\n\t\t\tsystemPrompt: `${event.systemPrompt}\\n\\n${buildGoalSystemPrompt(runtime.activeGoal)}`,\n\t\t};\n\t});\n\n\tpi.on(\"agent_end\", (event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tconst agentRunGoalId = runtime.agentRunGoalId;\n\t\truntime.agentRunGoalId = undefined;\n\t\tif (\n\t\t\tagentRunGoalId === null ||\n\t\t\t(!runtime.canRecordGoalUsage() && !runtime.hasActiveBudgetWrapUp())\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (agentRunGoalId && agentRunGoalId !== runtime.activeGoal?.id) return;\n\t\tif (!runtime.activeGoal) return;\n\t\tif (\n\t\t\truntime.activeGoal.status === \"budget_limited\" &&\n\t\t\truntime.budgetWrapUp?.goalId === runtime.activeGoal.id\n\t\t) {\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\tclearBudgetWrapUp();\n\t\t\treturn;\n\t\t}\n\t\tif (runtime.activeGoal.status !== \"active\") return;\n\t\tif (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.goalId === runtime.activeGoal.id\n\t\t) {\n\t\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\treturn;\n\t\t}\n\n\t\tconst goalId = runtime.activeGoal.id;\n\t\tconst alreadyAwaitingContinuation = hasContinuationWorkForGoal(goalId);\n\t\tconst finalAssistant = findFinalAssistantMessage(event.messages);\n\n\t\tif (!alreadyAwaitingContinuation) runtime.activeGoal = incrementGoal(runtime.activeGoal);\n\t\tupdateGoalUsage(runtime.activeGoal, ctx);\n\n\t\tif (finalAssistant?.stopReason === \"aborted\") {\n\t\t\tclearGoalRecoveryForGoal(goalId);\n\t\t\tstopGoalAfterAgentEnd(ctx, runtime.activeGoal, finalAssistant, \"paused\");\n\t\t\treturn;\n\t\t}\n\n\t\tif (finalAssistant?.stopReason === \"error\") {\n\t\t\tif (isRetryableGoalInterruption(finalAssistant)) {\n\t\t\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\t\t\tif (!goalToolsAvailable()) {\n\t\t\t\t\tpauseGoalForUnavailableTools(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\truntime.goalRecovery = {\n\t\t\t\t\tgoalId,\n\t\t\t\t\tkind: isGoalContextOverflow(finalAssistant) ? \"compaction_retry\" : \"provider_retry\",\n\t\t\t\t};\n\t\t\t\tcancelContinuationWork();\n\t\t\t\tpersistGoal(runtime.activeGoal);\n\t\t\t\tupdateStatus(ctx, runtime.activeGoal);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclearGoalRecoveryForGoal(goalId);\n\t\t\tstopGoalAfterAgentEnd(\n\t\t\t\tctx,\n\t\t\t\truntime.activeGoal,\n\t\t\t\tfinalAssistant,\n\t\t\t\tisUsageLimitedGoalInterruption(finalAssistant) ? \"usage_limited\" : \"blocked\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tclearGoalRecoveryForGoal(goalId);\n\n\t\tif (limitActiveGoalForBudget(ctx, false)) return;\n\t\tif (!goalToolsAvailable()) {\n\t\t\tpauseGoalForUnavailableTools(ctx);\n\t\t\treturn;\n\t\t}\n\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\n\t\tconst currentGoal = runtime.activeGoal;\n\t\tif (!currentGoal || currentGoal.id !== goalId || currentGoal.status !== \"active\") return;\n\t\tif (runtime.pendingQueueAction?.kind === \"prioritize\") return;\n\t\trequestContinuation(currentGoal);\n\t});\n\n\tpi.on(\"agent_settled\", (_event, ctx) => {\n\t\tif (runtime.queueFrozen) return;\n\t\tif (!runtime.pendingQueueAction) {\n\t\t\tdispatchContinuationIfSettled(ctx);\n\t\t\treturn;\n\t\t}\n\t\treturn dispatchPendingQueueActionIfSettled(ctx).then((dispatched) => {\n\t\t\tif (!dispatched) dispatchContinuationIfSettled(ctx);\n\t\t});\n\t});\n\n\tfunction hasPendingSkipForGoal(goalId: string) {\n\t\treturn (\n\t\t\truntime.pendingQueueAction?.kind === \"advance\" &&\n\t\t\truntime.pendingQueueAction.reason === \"skip\" &&\n\t\t\truntime.pendingQueueAction.goalId === goalId\n\t\t);\n\t}\n\n\tfunction stopGoalAfterAgentEnd(\n\t\tctx: StatusContext,\n\t\tgoal: ActiveGoal,\n\t\tassistant: AssistantMessageLike,\n\t\tstatus: \"paused\" | \"blocked\" | \"usage_limited\",\n\t) {\n\t\tcancelContinuationWork();\n\t\tclearBudgetWrapUp();\n\t\tblockStaleGoalToolCalls();\n\t\tabortCurrentTurn(ctx);\n\t\t// lunr: if the provider error carries a reset time, pre-fill resumeAfter so a\n\t\t// one-shot /cron wake-up auto-resumes the goal without a manual /goal resume.\n\t\tconst resumeAfter = status === \"usage_limited\" ? parseUsageResetTimeMs(assistant.errorMessage) : undefined;\n\t\tconst goalWithResume = resumeAfter !== undefined ? { ...goal, resumeAfter } : goal;\n\t\truntime.activeGoal = transitionGoal(goalWithResume, status);\n\t\tpersistGoal(runtime.activeGoal);\n\t\tupdateStatus(ctx, runtime.activeGoal);\n\n\t\tconst details = assistant.errorMessage\n\t\t\t? ` (${truncateNotification(assistant.errorMessage)})`\n\t\t\t: \"\";\n\t\tif (status === \"paused\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal paused after interruption${details}. Run /goal resume to continue.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (status === \"usage_limited\") {\n\t\t\tconst when = resumeAfter !== undefined ? ` Auto-resume scheduled for ${new Date(resumeAfter).toLocaleString()}.` : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal usage-limited${details}.${when} Run /goal resume when usage resets, or schedule a one-shot /cron firing \"continue\" into this session to wake it.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tctx.ui.notify(\n\t\t\t`Goal blocked after agent error${details}. Resolve the blocker or run /goal resume to retry.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nexport default function goal(pi: ExtensionAPI, options: GoalOptions = {}) {\n\tregisterGoalRuntime(pi, options);\n}\n\nexport {\n\tassistantUsageTokens,\n\tcumulativeAssistantTokens,\n\tformatDuration,\n\tformatTokenCount,\n} from \"./accounting.js\";\n\nexport {\n\tcompleteGoalArguments,\n\tparseCommand,\n\tparseTokenBudget,\n\tvalidateObjective,\n} from \"./command.js\";\n\nexport { buildGoalSystemPrompt } from \"./prompts.js\";\n\nexport {\n\tfindFinalAssistantMessage,\n\tformatStatus,\n\tisContradictoryCompletionSummary,\n\tisRetryableGoalInterruption,\n\tisUsageLimitedGoalInterruption,\n} from \"./runtime.js\";\n"]}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { defineTool } from "../../../core/extensions/types.js";
|
|
5
5
|
import { isCronFire } from "../../../core/cron/fire-guard.js";
|
|
6
6
|
import { Type } from "typebox";
|
|
7
|
+
import { Container, Markdown, Text } from "@ashx-j/lunr-tui";
|
|
7
8
|
import { currentTokenTotal } from "./accounting.js";
|
|
8
9
|
import { completeGoalArguments, parseCommand } from "./command.js";
|
|
9
10
|
import { GoalCommandController } from "./commands.js";
|
|
@@ -12,6 +13,7 @@ import { buildGoalPrompt, buildGoalSystemPrompt } from "./prompts.js";
|
|
|
12
13
|
import { activateQueuedGoal } from "./queue.js";
|
|
13
14
|
import { abortCurrentTurn, blocksStaleGoalToolCalls, findFinalAssistantMessage, formatError, formatStatus, GOAL_BLOCKED_TOOL, GOAL_COMPLETE_TOOL, GoalRuntime, goalIdRejectionReason, incrementGoal, isContradictoryCompletionSummary, isGoalContextOverflow, isRetryableGoalInterruption, isUsageLimitedGoalInterruption, parseUsageResetTimeMs, STATUS_KEY, transitionGoal, truncateNotification, } from "./runtime.js";
|
|
14
15
|
import { DEFAULT_GOAL_SETTINGS, readGoalSettings } from "./settings.js";
|
|
16
|
+
const GOAL_COMPLETE_MESSAGE_TYPE = "goal-complete";
|
|
15
17
|
const EXPERIMENTAL_GOALS_WARNING = "Experimental ordered goals are enabled for pi-goal. Queue behavior and persisted state may change.";
|
|
16
18
|
const MAX_BLOCKER_REASON_LENGTH = 1_000;
|
|
17
19
|
const MAX_BLOCKER_EVIDENCE_LENGTH = 4_000;
|
|
@@ -53,6 +55,27 @@ function registerGoalRuntime(pi, options = {}) {
|
|
|
53
55
|
const restoreGoalToolsHiddenByPolicy = runtime.restoreGoalToolsHiddenByPolicy.bind(runtime);
|
|
54
56
|
const sendOwnedGoalPrompt = (_pi, ctx, goalId, prompt) => runtime.sendOwnedGoalPrompt(ctx, goalId, prompt);
|
|
55
57
|
const dispatchPendingQueueActionIfSettled = commands.dispatchPendingQueueActionIfSettled.bind(commands);
|
|
58
|
+
const emitGoalCompleteMessage = (summary) => {
|
|
59
|
+
const text = summary.startsWith("Goal complete") ? summary : summary;
|
|
60
|
+
pi.sendMessage({
|
|
61
|
+
customType: GOAL_COMPLETE_MESSAGE_TYPE,
|
|
62
|
+
content: [{ type: "text", text }],
|
|
63
|
+
display: true,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
pi.registerMessageRenderer(GOAL_COMPLETE_MESSAGE_TYPE, (message, _options, theme) => {
|
|
67
|
+
const raw = typeof message.content === "string"
|
|
68
|
+
? message.content
|
|
69
|
+
: message.content
|
|
70
|
+
.filter((block) => block.type === "text")
|
|
71
|
+
.map((block) => ("text" in block ? block.text : ""))
|
|
72
|
+
.join("\n");
|
|
73
|
+
const c = new Container();
|
|
74
|
+
c.addChild(new Markdown(`● ${raw}`, 1, 0, undefined, {
|
|
75
|
+
color: (content) => theme.fg("text", content),
|
|
76
|
+
}));
|
|
77
|
+
return c;
|
|
78
|
+
});
|
|
56
79
|
const goalCompleteTool = defineTool({
|
|
57
80
|
name: GOAL_COMPLETE_TOOL,
|
|
58
81
|
label: "Goal Complete",
|
|
@@ -160,7 +183,7 @@ function registerGoalRuntime(pi, options = {}) {
|
|
|
160
183
|
if (runtime.pendingQueueAction?.kind === "prioritize") {
|
|
161
184
|
persistGoal(runtime.activeGoal);
|
|
162
185
|
ctx.ui.setStatus(STATUS_KEY, "complete");
|
|
163
|
-
|
|
186
|
+
emitGoalCompleteMessage(summary);
|
|
164
187
|
return {
|
|
165
188
|
content: [{ type: "text", text: `Goal complete: ${summary}` }],
|
|
166
189
|
details: {
|
|
@@ -180,7 +203,7 @@ function registerGoalRuntime(pi, options = {}) {
|
|
|
180
203
|
};
|
|
181
204
|
persistGoal(runtime.activeGoal);
|
|
182
205
|
ctx.ui.setStatus(STATUS_KEY, "complete");
|
|
183
|
-
|
|
206
|
+
emitGoalCompleteMessage(summary);
|
|
184
207
|
return {
|
|
185
208
|
content: [
|
|
186
209
|
{
|
|
@@ -200,13 +223,18 @@ function registerGoalRuntime(pi, options = {}) {
|
|
|
200
223
|
ctx.ui.setStatus(STATUS_KEY, formatStatus(runtime.activeGoal));
|
|
201
224
|
clearActiveGoal(ctx);
|
|
202
225
|
showCompletionStatus(ctx);
|
|
203
|
-
|
|
226
|
+
emitGoalCompleteMessage(summary);
|
|
204
227
|
return {
|
|
205
228
|
content: [{ type: "text", text: `Goal complete: ${summary}` }],
|
|
206
229
|
details: { goal, goal_id: requestedGoalId, summary },
|
|
207
230
|
terminate: true,
|
|
208
231
|
};
|
|
209
232
|
},
|
|
233
|
+
renderResult(_result, { isPartial }, theme) {
|
|
234
|
+
if (isPartial)
|
|
235
|
+
return new Text(theme.fg("warning", "Completing goal..."), 0, 0);
|
|
236
|
+
return { render: () => [], invalidate() { } };
|
|
237
|
+
},
|
|
210
238
|
});
|
|
211
239
|
const goalBlockedTool = defineTool({
|
|
212
240
|
name: GOAL_BLOCKED_TOOL,
|