@narumitw/pi-goal 0.53.3 → 0.54.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.
@@ -6,13 +6,11 @@ import {
6
6
  notifyTerminal,
7
7
  safeTerminalText,
8
8
  saveGoalSettings
9
- } from "./chunk-2ARA24RR.js";
9
+ } from "./chunk-UQRRW4CY.js";
10
10
 
11
11
  // src/settings-ui.ts
12
12
  import { join } from "node:path";
13
13
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
14
- var WorkflowBusyError = class extends Error {
15
- };
16
14
  async function showGoalSettings(runtime, ctx, options = {}) {
17
15
  const settingsPath = options.settingsPath ?? join(getAgentDir(), GOAL_SETTINGS_FILE);
18
16
  if (ctx.mode !== "tui") {
@@ -55,14 +53,6 @@ async function showGoalSettings(runtime, ctx, options = {}) {
55
53
  ),
56
54
  action: "open-no-progress"
57
55
  },
58
- {
59
- id: "toolVisibility",
60
- label: "Goal tools",
61
- description: "Keep terminal Goal tools visible, or reveal them after the first goal.",
62
- currentValue: visibilityLabel(runtime.settings.toolVisibility),
63
- values: ["Always", "After first goal"],
64
- action: "set-visibility"
65
- },
66
56
  {
67
57
  id: "rpcEnabled",
68
58
  label: "Managed run RPC",
@@ -82,7 +72,6 @@ async function showGoalSettings(runtime, ctx, options = {}) {
82
72
  `Invalid settings file. Pi-goal is using built-in defaults. Fix ${safeTerminalText(settingsPath)} and run /reload. The file will not be overwritten.`,
83
73
  `Automatic-work limit: ${formatAutomaticWork(runtime.settings.continuationLimits.automaticTurns)}`,
84
74
  `No-progress guard: ${formatNoProgressProtection(runtime.settings.continuationLimits.noProgressTurns)}`,
85
- `Goal tools: ${visibilityLabel(runtime.settings.toolVisibility)}`,
86
75
  `Managed run RPC: ${runtime.settings.rpc.enabled ? "On" : "Off"}`
87
76
  ],
88
77
  hint: "back"
@@ -117,24 +106,6 @@ async function showGoalSettings(runtime, ctx, options = {}) {
117
106
  previewGoalIds.get("noProgressTurns") ?? null,
118
107
  isMenuCurrent
119
108
  ),
120
- "set-visibility": async ({ value }) => {
121
- const nextVisibility = value === "Always" ? "always" : "after-first-goal";
122
- if (nextVisibility === runtime.settings.toolVisibility) return { kind: "stay" };
123
- try {
124
- const next = {
125
- ...structuredClone(runtime.settings),
126
- toolVisibility: nextVisibility
127
- };
128
- applyGoalSettings(runtime, next, ctx, {
129
- save: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath)
130
- });
131
- notifyTerminal(ctx.ui, `Goal tools: ${value}.`, "info");
132
- return { kind: "stay" };
133
- } catch (error) {
134
- notifySettingsFailure(ctx, settingsPath, error);
135
- return { kind: "rejected" };
136
- }
137
- },
138
109
  "set-rpc": async ({ value }) => {
139
110
  const enabled = value === "On";
140
111
  if (enabled === runtime.settings.rpc.enabled) return { kind: "stay" };
@@ -261,56 +232,44 @@ async function applyLimitChoice(runtime, ctx, options, settingsPath, field, item
261
232
  }
262
233
  function applyGoalSettings(runtime, next, ctx, options = {}) {
263
234
  const snapshot = runtime.snapshotSettingsApplicationState();
264
- const visibilityChanges = snapshot.settings.toolVisibility !== next.toolVisibility;
265
- const releaseWorkflow = visibilityChanges ? runtime.beginTemporaryWorkflowAccess(ctx.sessionManager) : () => void 0;
266
- if (!releaseWorkflow) {
267
- throw new WorkflowBusyError(
268
- "Another workflow is active in this session. Goal tool visibility was not changed."
269
- );
270
- }
271
235
  let fileSaved = false;
272
236
  try {
237
+ runtime.settings = structuredClone(next);
238
+ options.save?.(next);
239
+ fileSaved = options.save !== void 0;
240
+ const activeGoalId = runtime.activeGoal?.id;
241
+ const abortOwnedRun = activeGoalId !== void 0 && runtime.agentRunGoalId === activeGoalId;
242
+ const pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);
243
+ if (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);
244
+ if (runtime.activeGoal) {
245
+ runtime.updateStatus(ctx, runtime.activeGoal);
246
+ }
247
+ } catch (error) {
248
+ const rollbackErrors = [];
273
249
  try {
274
- applyToolVisibility(runtime, snapshot.settings, next, ctx);
275
- runtime.settings = structuredClone(next);
276
- options.save?.(next);
277
- fileSaved = options.save !== void 0;
278
- const activeGoalId = runtime.activeGoal?.id;
279
- const abortOwnedRun = activeGoalId !== void 0 && runtime.agentRunGoalId === activeGoalId;
280
- const pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);
281
- if (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);
282
- if (runtime.activeGoal) {
283
- runtime.updateStatus(ctx, runtime.activeGoal);
284
- }
285
- } catch (error) {
286
- const rollbackErrors = [];
250
+ runtime.restoreSettingsApplicationState(snapshot);
251
+ } catch (rollbackError) {
252
+ rollbackErrors.push(rollbackError);
253
+ }
254
+ if (fileSaved) {
287
255
  try {
288
- runtime.restoreSettingsApplicationState(snapshot);
256
+ options.save?.(snapshot.settings);
289
257
  } catch (rollbackError) {
290
258
  rollbackErrors.push(rollbackError);
291
259
  }
292
- if (fileSaved) {
293
- try {
294
- options.save?.(snapshot.settings);
295
- } catch (rollbackError) {
296
- rollbackErrors.push(rollbackError);
297
- }
298
- try {
299
- restorePersistedRuntime(runtime, ctx);
300
- } catch (rollbackError) {
301
- rollbackErrors.push(rollbackError);
302
- }
303
- }
304
- if (rollbackErrors.length > 0) {
305
- throw new AggregateError(
306
- [error, ...rollbackErrors],
307
- `pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`
308
- );
260
+ try {
261
+ restorePersistedRuntime(runtime, ctx);
262
+ } catch (rollbackError) {
263
+ rollbackErrors.push(rollbackError);
309
264
  }
310
- throw error;
311
265
  }
312
- } finally {
313
- releaseWorkflow();
266
+ if (rollbackErrors.length > 0) {
267
+ throw new AggregateError(
268
+ [error, ...rollbackErrors],
269
+ `pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`
270
+ );
271
+ }
272
+ throw error;
314
273
  }
315
274
  }
316
275
  function parseGoalLimit(value) {
@@ -350,15 +309,6 @@ async function resolveLimitSelection(field, selection, previous, ctx, isCurrent)
350
309
  );
351
310
  }
352
311
  }
353
- function applyToolVisibility(runtime, previous, next, ctx) {
354
- if (previous.toolVisibility === next.toolVisibility) return;
355
- runtime.toolPolicy.applyVisibilityChange(
356
- previous.toolVisibility,
357
- next.toolVisibility,
358
- runtime.activeGoal !== void 0,
359
- ctx
360
- );
361
- }
362
312
  function restorePersistedRuntime(runtime, ctx) {
363
313
  if (runtime.activeGoal) {
364
314
  runtime.persistGoal(runtime.activeGoal);
@@ -405,9 +355,6 @@ function formatLimitSuccess(field, value) {
405
355
  function isLimitSelection(value) {
406
356
  return value === "unlimited" || value === "default" || value === "custom" || value === "off";
407
357
  }
408
- function visibilityLabel(value) {
409
- return value === "always" ? "Always" : "After first goal";
410
- }
411
358
  function notifySettingsFailure(ctx, settingsPath, error) {
412
359
  const path = safeTerminalText(settingsPath);
413
360
  const detail = safeTerminalText(formatError(error));
@@ -425,4 +372,4 @@ export {
425
372
  parseGoalLimit,
426
373
  showGoalSettings
427
374
  };
428
- //# sourceMappingURL=settings-ui-LBFJ7TOX.js.map
375
+ //# sourceMappingURL=settings-ui-MVYTTBHW.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/settings-ui.ts"],
4
+ "sourcesContent": ["import { join } from \"node:path\";\nimport { type ExtensionCommandContext, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport { notifyTerminal, safeTerminalText } from \"./errors.js\";\nimport type { GoalRuntime } from \"./runtime.js\";\nimport {\n\tDEFAULT_GOAL_SETTINGS,\n\tGOAL_SETTINGS_FILE,\n\ttype GoalSettings,\n\tsaveGoalSettings,\n} from \"./settings.js\";\n\ninterface GoalSettingsUiOptions {\n\tsettingsPath?: string;\n\tinitialScreen?: \"settings\" | \"automatic\";\n\tsave?: (settings: GoalSettings, settingsPath: string) => void;\n}\n\ninterface GoalSettingsApplyOptions {\n\tsave?: (settings: GoalSettings) => void;\n}\n\ntype LimitField = \"automaticTurns\" | \"noProgressTurns\";\ntype LimitSelection = \"unlimited\" | \"default\" | \"custom\" | \"off\";\nexport async function showGoalSettings(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsUiOptions = {},\n) {\n\tconst settingsPath = options.settingsPath ?? join(getAgentDir(), GOAL_SETTINGS_FILE);\n\tif (ctx.mode !== \"tui\") {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t`Edit pi-goal settings manually: ${safeTerminalText(settingsPath)}`,\n\t\t\t\"info\",\n\t\t);\n\t\treturn;\n\t}\n\tconst generation = runtime.menuGeneration;\n\tconst isMenuCurrent = () =>\n\t\tgeneration === runtime.menuGeneration && !runtime.menuController.signal.aborted;\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isMenuCurrent()) return;\n\tconst invalid = runtime.settingsLoadIssue?.kind === \"invalid\";\n\tconst previewGoalIds = new Map<LimitField, string | null>();\n\ttype Screen = \"settings\" | \"automatic\" | \"no-progress\" | \"invalid\";\n\ttype Action =\n\t\t| \"open-automatic\"\n\t\t| \"open-no-progress\"\n\t\t| \"choose-automatic\"\n\t\t| \"choose-no-progress\"\n\t\t| \"set-rpc\";\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({\n\t\tstart: invalid ? \"invalid\" : (options.initialScreen ?? \"settings\"),\n\t\tscreens: {\n\t\t\tsettings: () => ({\n\t\t\t\tkind: \"settings\",\n\t\t\t\ttitle: \"Pi Goal Settings\",\n\t\t\t\tlines: [`User settings \u00B7 ${safeTerminalText(settingsPath)}`],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"automaticTurns\",\n\t\t\t\t\t\tlabel: \"Automatic-work limit\",\n\t\t\t\t\t\tdescription: \"Pause automatic Goal work after a visible number of model responses.\",\n\t\t\t\t\t\tcurrentValue: formatAutomaticSettingValue(\n\t\t\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taction: \"open-automatic\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"noProgressTurns\",\n\t\t\t\t\t\tlabel: \"No-progress guard\",\n\t\t\t\t\t\tdescription: \"Pause after repeated or empty tool-free automatic runs.\",\n\t\t\t\t\t\tcurrentValue: formatNoProgressSettingValue(\n\t\t\t\t\t\t\truntime.settings.continuationLimits.noProgressTurns,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taction: \"open-no-progress\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"rpcEnabled\",\n\t\t\t\t\t\tlabel: \"Managed run RPC\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Allow trusted installed extensions to start and cancel Goal runs; this is not an extension sandbox.\",\n\t\t\t\t\t\tcurrentValue: runtime.settings.rpc.enabled ? \"On\" : \"Off\",\n\t\t\t\t\t\tvalues: [\"Off\", \"On\"],\n\t\t\t\t\t\taction: \"set-rpc\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}),\n\t\t\tautomatic: () => limitChoiceScreen(runtime, \"automaticTurns\", \"choose-automatic\"),\n\t\t\t\"no-progress\": () => limitChoiceScreen(runtime, \"noProgressTurns\", \"choose-no-progress\"),\n\t\t\tinvalid: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Goal Settings \u00B7 Read only\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Invalid settings file. Pi-goal is using built-in defaults. Fix ${safeTerminalText(settingsPath)} and run /reload. The file will not be overwritten.`,\n\t\t\t\t\t`Automatic-work limit: ${formatAutomaticWork(runtime.settings.continuationLimits.automaticTurns)}`,\n\t\t\t\t\t`No-progress guard: ${formatNoProgressProtection(runtime.settings.continuationLimits.noProgressTurns)}`,\n\t\t\t\t\t`Managed run RPC: ${runtime.settings.rpc.enabled ? \"On\" : \"Off\"}`,\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\t\"open-automatic\": async () => {\n\t\t\t\tpreviewGoalIds.set(\"automaticTurns\", runtime.activeGoal?.id ?? null);\n\t\t\t\treturn { kind: \"to\", screen: \"automatic\" };\n\t\t\t},\n\t\t\t\"open-no-progress\": async () => {\n\t\t\t\tpreviewGoalIds.set(\"noProgressTurns\", runtime.activeGoal?.id ?? null);\n\t\t\t\treturn { kind: \"to\", screen: \"no-progress\" };\n\t\t\t},\n\t\t\t\"choose-automatic\": async ({ itemId }) =>\n\t\t\t\tapplyLimitChoice(\n\t\t\t\t\truntime,\n\t\t\t\t\tctx,\n\t\t\t\t\toptions,\n\t\t\t\t\tsettingsPath,\n\t\t\t\t\t\"automaticTurns\",\n\t\t\t\t\titemId,\n\t\t\t\t\tpreviewGoalIds.get(\"automaticTurns\") ?? null,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t),\n\t\t\t\"choose-no-progress\": async ({ itemId }) =>\n\t\t\t\tapplyLimitChoice(\n\t\t\t\t\truntime,\n\t\t\t\t\tctx,\n\t\t\t\t\toptions,\n\t\t\t\t\tsettingsPath,\n\t\t\t\t\t\"noProgressTurns\",\n\t\t\t\t\titemId,\n\t\t\t\t\tpreviewGoalIds.get(\"noProgressTurns\") ?? null,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t),\n\t\t\t\"set-rpc\": async ({ value }) => {\n\t\t\t\tconst enabled = value === \"On\";\n\t\t\t\tif (enabled === runtime.settings.rpc.enabled) return { kind: \"stay\" };\n\t\t\t\ttry {\n\t\t\t\t\tconst next = {\n\t\t\t\t\t\t...structuredClone(runtime.settings),\n\t\t\t\t\t\trpc: { enabled },\n\t\t\t\t\t} satisfies GoalSettings;\n\t\t\t\t\tapplyGoalSettings(runtime, next, ctx, {\n\t\t\t\t\t\tsave: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n\t\t\t\t\t});\n\t\t\t\t\tnotifyTerminal(ctx.ui, `Managed run RPC: ${enabled ? \"On\" : \"Off\"}.`, \"info\");\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifySettingsFailure(ctx, settingsPath, error);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: runtime.menuController.signal,\n\t\tisCurrent: isMenuCurrent,\n\t});\n}\n\nfunction limitChoiceScreen(\n\truntime: GoalRuntime,\n\tfield: LimitField,\n\taction: \"choose-automatic\" | \"choose-no-progress\",\n) {\n\tconst value = runtime.settings.continuationLimits[field];\n\tconst goal = runtime.activeGoal;\n\treturn {\n\t\tkind: \"actions\" as const,\n\t\ttitle: field === \"automaticTurns\" ? \"Automatic-work limit\" : \"No-progress guard\",\n\t\tlines: [\n\t\t\tfield === \"automaticTurns\"\n\t\t\t\t? `Current: ${formatAutomaticWork(value)}`\n\t\t\t\t: `Current: ${formatNoProgressProtection(value)}`,\n\t\t\t...(field === \"automaticTurns\"\n\t\t\t\t? [\n\t\t\t\t\t\t`Set a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t\t...(goal\n\t\t\t\t? [\n\t\t\t\t\t\tfield === \"automaticTurns\"\n\t\t\t\t\t\t\t? `Active goal: ${goal.automaticModelTurns} automatic responses used`\n\t\t\t\t\t\t\t: `Active goal: ${goal.toolFreeRepeatCount} repeated or empty runs detected`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t\titems: limitChoices(field, value, goal?.automaticModelTurns).map((item) => ({\n\t\t\tid: item.value,\n\t\t\tlabel: item.label,\n\t\t\tdescription: item.description,\n\t\t\taction,\n\t\t})),\n\t\thint: \"back\" as const,\n\t};\n}\n\nfunction limitChoices(\n\tfield: LimitField,\n\tvalue: number | null,\n\tautomaticTurnsUsed: number | undefined,\n): Array<{ value: LimitSelection; label: string; description: string }> {\n\tif (field === \"automaticTurns\") {\n\t\tconst unlimitedDescription =\n\t\t\tvalue === null\n\t\t\t\t? \"No response-count cap. Completion, manual pause, blockers, provider limits, and other configured guards still apply.\"\n\t\t\t\t: automaticTurnsUsed === undefined\n\t\t\t\t\t? `Remove the current ${value}-response cap. Goal work will have no response-count cap; other configured stop conditions remain.`\n\t\t\t\t\t: `Remove the current ${value}-response cap. The active goal has used ${automaticTurnsUsed} responses; other configured stop conditions remain.`;\n\t\treturn [\n\t\t\t{\n\t\t\t\tvalue: \"custom\",\n\t\t\t\tlabel: \"Set response limit\u2026\",\n\t\t\t\tdescription: `Choose a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n\t\t\t},\n\t\t\t{ value: \"unlimited\", label: \"Unlimited\u2026\", description: unlimitedDescription },\n\t\t];\n\t}\n\tconst defaultLimit = DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns;\n\treturn [\n\t\t{\n\t\t\tvalue: \"default\",\n\t\t\tlabel: `After ${defaultLimit} repeated runs (default)`,\n\t\t\tdescription: \"Pause after the default number of repeated or empty tool-free runs.\",\n\t\t},\n\t\t{\n\t\t\tvalue: \"custom\",\n\t\t\tlabel: \"Set threshold\u2026\",\n\t\t\tdescription: \"Choose a whole number of repeated or empty runs before pausing.\",\n\t\t},\n\t\t{\n\t\t\tvalue: \"off\",\n\t\t\tlabel: \"Off\",\n\t\t\tdescription: \"Do not pause based on repeated or empty tool-free runs.\",\n\t\t},\n\t];\n}\n\nasync function applyLimitChoice(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsUiOptions,\n\tsettingsPath: string,\n\tfield: LimitField,\n\titemId: string,\n\tactiveGoalId: string | null,\n\tisCurrent: () => boolean,\n) {\n\tif (!isCurrent() || !isLimitSelection(itemId)) return { kind: \"rejected\" as const };\n\tif ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while the safety setting was open. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\tconst previous = runtime.settings.continuationLimits[field];\n\tconst limit = await resolveLimitSelection(field, itemId, previous, ctx, isCurrent);\n\tif (!isCurrent()) return { kind: \"rejected\" as const };\n\tif (limit === undefined || limit === previous) return { kind: \"back\" as const };\n\tif ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while editing the safety setting. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\tconst confirmation = await confirmLowerActiveLimit(runtime, ctx, field, limit);\n\tif (!isCurrent() || !confirmation.apply) return { kind: \"rejected\" as const };\n\tif (confirmation.goalId !== undefined && runtime.activeGoal?.id !== confirmation.goalId) {\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t\"The active goal changed while confirming the limit. No settings were changed.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n\ttry {\n\t\tapplyGoalSettings(runtime, withLimit(runtime.settings, field, limit), ctx, {\n\t\t\tsave: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n\t\t});\n\t\tnotifyTerminal(ctx.ui, formatLimitSuccess(field, limit), \"info\");\n\t\treturn { kind: \"back\" as const };\n\t} catch (error) {\n\t\tnotifySettingsFailure(ctx, settingsPath, error);\n\t\treturn { kind: \"rejected\" as const };\n\t}\n}\n\nexport function applyGoalSettings(\n\truntime: GoalRuntime,\n\tnext: GoalSettings,\n\tctx: ExtensionCommandContext,\n\toptions: GoalSettingsApplyOptions = {},\n) {\n\tconst snapshot = runtime.snapshotSettingsApplicationState();\n\tlet fileSaved = false;\n\ttry {\n\t\truntime.settings = structuredClone(next);\n\t\toptions.save?.(next);\n\t\tfileSaved = options.save !== undefined;\n\t\tconst activeGoalId = runtime.activeGoal?.id;\n\t\tconst abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;\n\t\tconst pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);\n\t\tif (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);\n\t\tif (runtime.activeGoal) {\n\t\t\truntime.updateStatus(ctx, runtime.activeGoal);\n\t\t}\n\t} catch (error) {\n\t\tconst rollbackErrors: unknown[] = [];\n\t\ttry {\n\t\t\truntime.restoreSettingsApplicationState(snapshot);\n\t\t} catch (rollbackError) {\n\t\t\trollbackErrors.push(rollbackError);\n\t\t}\n\t\tif (fileSaved) {\n\t\t\ttry {\n\t\t\t\toptions.save?.(snapshot.settings);\n\t\t\t} catch (rollbackError) {\n\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\trestorePersistedRuntime(runtime, ctx);\n\t\t\t} catch (rollbackError) {\n\t\t\t\trollbackErrors.push(rollbackError);\n\t\t\t}\n\t\t}\n\t\tif (rollbackErrors.length > 0) {\n\t\t\tthrow new AggregateError(\n\t\t\t\t[error, ...rollbackErrors],\n\t\t\t\t`pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport function parseGoalLimit(value: string): number | undefined {\n\tconst normalized = value.trim();\n\tif (!/^\\d+$/u.test(normalized)) return undefined;\n\tconst parsed = Number(normalized);\n\treturn Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nasync function resolveLimitSelection(\n\tfield: LimitField,\n\tselection: LimitSelection,\n\tprevious: number | null,\n\tctx: ExtensionCommandContext,\n\tisCurrent: () => boolean,\n): Promise<number | null | undefined> {\n\tif (selection === \"off\") return null;\n\tif (selection === \"unlimited\") {\n\t\tif (previous === null) return null;\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Allow Unlimited automatic work?\",\n\t\t\t\"Tool loops can continue without a response-count limit and may consume substantial tokens and provider cost. Completion, manual pause, blockers, provider limits, and the no-progress guard still apply.\",\n\t\t);\n\t\treturn isCurrent() && confirmed ? null : undefined;\n\t}\n\tif (selection === \"default\") {\n\t\treturn DEFAULT_GOAL_SETTINGS.continuationLimits[field];\n\t}\n\twhile (true) {\n\t\tconst raw =\n\t\t\tfield === \"automaticTurns\"\n\t\t\t\t? await ctx.ui.editor(\n\t\t\t\t\t\t`Automatic-work response limit (whole number greater than 0) \u00B7 Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}`,\n\t\t\t\t\t\tString(previous ?? DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns),\n\t\t\t\t\t)\n\t\t\t\t: await ctx.ui.input(\n\t\t\t\t\t\t\"Repeated-run threshold (whole number greater than 0)\",\n\t\t\t\t\t\tprevious === null ? \"Positive whole number\" : String(previous),\n\t\t\t\t\t);\n\t\tif (!isCurrent() || raw === undefined) return undefined;\n\t\tconst parsed = parseGoalLimit(raw);\n\t\tif (parsed !== undefined) return parsed;\n\t\tnotifyTerminal(\n\t\t\tctx.ui,\n\t\t\t`Enter a whole number greater than 0. Choose ${field === \"automaticTurns\" ? \"Unlimited\" : \"Off\"} from the previous screen if you do not want a limit.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nfunction restorePersistedRuntime(runtime: GoalRuntime, ctx: ExtensionCommandContext) {\n\tif (runtime.activeGoal) {\n\t\truntime.persistGoal(runtime.activeGoal);\n\t\truntime.updateStatus(ctx, runtime.activeGoal);\n\t\truntime.restoreGoalWaitTimer(ctx);\n\t}\n}\n\nasync function confirmLowerActiveLimit(\n\truntime: GoalRuntime,\n\tctx: ExtensionCommandContext,\n\tfield: LimitField,\n\tlimit: number | null,\n) {\n\tconst goal = runtime.activeGoal;\n\tif (goal?.status !== \"active\" || limit === null) return { apply: true };\n\tconst used = field === \"automaticTurns\" ? goal.automaticModelTurns : goal.toolFreeRepeatCount;\n\tif (used < limit) return { apply: true };\n\treturn {\n\t\tapply: await ctx.ui.confirm(\n\t\t\t\"Apply limit and pause now?\",\n\t\t\t`The active goal has already used ${used}. Setting this limit to ${limit} will pause it immediately without deleting progress.`,\n\t\t),\n\t\tgoalId: goal.id,\n\t};\n}\n\nfunction withLimit(settings: GoalSettings, field: LimitField, value: number | null): GoalSettings {\n\treturn {\n\t\t...structuredClone(settings),\n\t\tcontinuationLimits: { ...settings.continuationLimits, [field]: value },\n\t};\n}\n\nfunction formatAutomaticSettingValue(value: number | null) {\n\treturn value === null ? \"Unlimited\" : `${value} responses`;\n}\n\nfunction formatNoProgressSettingValue(value: number | null) {\n\tif (value === null) return \"Off\";\n\treturn `${value} ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatAutomaticWork(value: number | null) {\n\treturn value === null ? \"Unlimited\" : `Up to ${value} responses`;\n}\n\nfunction formatNoProgressProtection(value: number | null) {\n\tif (value === null) return \"Off\";\n\treturn `After ${value} repeated ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatLimitSuccess(field: LimitField, value: number | null) {\n\treturn field === \"automaticTurns\"\n\t\t? `Automatic-work limit: ${formatAutomaticWork(value)}.`\n\t\t: `No-progress guard: ${formatNoProgressProtection(value)}.`;\n}\n\nfunction isLimitSelection(value: string): value is LimitSelection {\n\treturn value === \"unlimited\" || value === \"default\" || value === \"custom\" || value === \"off\";\n}\n\nfunction notifySettingsFailure(ctx: ExtensionCommandContext, settingsPath: string, error: unknown) {\n\tconst path = safeTerminalText(settingsPath);\n\tconst detail = safeTerminalText(formatError(error));\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\terror instanceof AggregateError\n\t\t\t? `Could not apply Goal settings, and rollback was incomplete. Check ${path}, run /reload, and verify the effective settings before retrying: ${detail}`\n\t\t\t: `Could not save Goal settings; the previous value remains. Check ${path} and retry: ${detail}`,\n\t\t\"error\",\n\t);\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAuC,mBAAmB;AAsB1D,eAAsB,iBACrB,SACA,KACA,UAAiC,CAAC,GACjC;AACD,QAAM,eAAe,QAAQ,gBAAgB,KAAK,YAAY,GAAG,kBAAkB;AACnF,MAAI,IAAI,SAAS,OAAO;AACvB;AAAA,MACC,IAAI;AAAA,MACJ,mCAAmC,iBAAiB,YAAY,CAAC;AAAA,MACjE;AAAA,IACD;AACA;AAAA,EACD;AACA,QAAM,aAAa,QAAQ;AAC3B,QAAM,gBAAgB,MACrB,eAAe,QAAQ,kBAAkB,CAAC,QAAQ,eAAe,OAAO;AACzE,QAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,OAAO,sBAAsB;AACnE,MAAI,CAAC,cAAc,EAAG;AACtB,QAAM,UAAU,QAAQ,mBAAmB,SAAS;AACpD,QAAM,iBAAiB,oBAAI,IAA+B;AAQ1D,QAAM,OAAO,WAA+D;AAAA,IAC3E,OAAO,UAAU,YAAa,QAAQ,iBAAiB;AAAA,IACvD,SAAS;AAAA,MACR,UAAU,OAAO;AAAA,QAChB,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO,CAAC,sBAAmB,iBAAiB,YAAY,CAAC,EAAE;AAAA,QAC3D,OAAO;AAAA,UACN;AAAA,YACC,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,aAAa;AAAA,YACb,cAAc;AAAA,cACb,QAAQ,SAAS,mBAAmB;AAAA,YACrC;AAAA,YACA,QAAQ;AAAA,UACT;AAAA,UACA;AAAA,YACC,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,aAAa;AAAA,YACb,cAAc;AAAA,cACb,QAAQ,SAAS,mBAAmB;AAAA,YACrC;AAAA,YACA,QAAQ;AAAA,UACT;AAAA,UACA;A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ACD;AAEA,SAAS,4BAA4B,OAAsB;AAC1D,SAAO,UAAU,OAAO,cAAc,GAAG,KAAK;AAC/C;AAEA,SAAS,6BAA6B,OAAsB;AAC3D,MAAI,UAAU,KAAM,QAAO;AAC3B,SAAO,GAAG,KAAK,IAAI,UAAU,IAAI,QAAQ,MAAM;AAChD;AAEA,SAAS,oBAAoB,OAAsB;AAClD,SAAO,UAAU,OAAO,cAAc,SAAS,KAAK;AACrD;AAEA,SAAS,2BAA2B,OAAsB;AACzD,MAAI,UAAU,KAAM,QAAO;AAC3B,SAAO,SAAS,KAAK,aAAa,UAAU,IAAI,QAAQ,MAAM;AAC/D;AAEA,SAAS,mBAAmB,OAAmB,OAAsB;AACpE,SAAO,UAAU,mBACd,yBAAyB,oBAAoB,KAAK,CAAC,MACnD,sBAAsB,2BAA2B,KAAK,CAAC;AAC3D;AAEA,SAAS,iBAAiB,OAAwC;AACjE,SAAO,UAAU,eAAe,UAAU,aAAa,UAAU,YAAY,UAAU;AACxF;AAEA,SAAS,sBAAsB,KAA8B,cAAsB,OAAgB;AAClG,QAAM,OAAO,iBAAiB,YAAY;AAC1C,QAAM,SAAS,iBAAiB,YAAY,KAAK,CAAC;AAClD;AAAA,IACC,IAAI;AAAA,IACJ,iBAAiB,iBACd,qEAAqE,IAAI,qEAAqE,MAAM,KACpJ,mEAAmE,IAAI,eAAe,MAAM;AAAA,IAC/F;AAAA,EACD;AACD;AAEA,SAAS,YAAY,OAAgB;AACpC,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
6
+ "names": []
7
+ }
package/dist/index.ts CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  stoppedStatusLabel,
44
44
  transitionGoal,
45
45
  validateObjective
46
- } from "./chunks/chunk-ZT3VZXYO.js";
46
+ } from "./chunks/chunk-UC6U2RFG.js";
47
47
  import {
48
48
  DEFAULT_GOAL_SETTINGS,
49
49
  currentTokenTotal,
@@ -58,15 +58,15 @@ import {
58
58
  safeGoalMenuText,
59
59
  safeTerminalText,
60
60
  truncateNotification
61
- } from "./chunks/chunk-2ARA24RR.js";
61
+ } from "./chunks/chunk-UQRRW4CY.js";
62
62
 
63
63
  // src/command-registration.ts
64
64
  function registerGoalCommand(pi, runtime, commands, options = {}) {
65
65
  const loadGoalManager = cachedModuleLoader(
66
- options.loadGoalManager ?? (() => import("./chunks/menu-H3C3LAQW.js"))
66
+ options.loadGoalManager ?? (() => import("./chunks/menu-R2B7UE3T.js"))
67
67
  );
68
68
  const loadGoalSettings = cachedModuleLoader(
69
- options.loadGoalSettings ?? (() => import("./chunks/settings-ui-LBFJ7TOX.js"))
69
+ options.loadGoalSettings ?? (() => import("./chunks/settings-ui-MVYTTBHW.js"))
70
70
  );
71
71
  pi.registerCommand("goal", {
72
72
  description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
@@ -201,9 +201,8 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
201
201
  const retainedOwner = this.runtime.ownsWorkflow(existingGoal);
202
202
  if (!this.runtime.acquireWorkflow(ctx.sessionManager)) return this.reportWorkflowBusy(ctx);
203
203
  const acquiredForRequest = !retainedOwner;
204
- const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
205
204
  try {
206
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
205
+ this.runtime.assertGoalToolsAvailable();
207
206
  } catch (error) {
208
207
  notifyTerminal(ctx.ui, `Cannot start /goal: ${formatError(error)}`, "error");
209
208
  if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
@@ -278,7 +277,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
278
277
  }
279
278
  }
280
279
  if (rolledBackStartedGoal) {
281
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
282
280
  if (acquiredForRequest && !this.runtime.ownsWorkflow(existingGoal)) {
283
281
  this.runtime.releaseWorkflow();
284
282
  }
@@ -343,9 +341,8 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
343
341
  this.reportWorkflowBusy(ctx);
344
342
  return;
345
343
  }
346
- const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
347
344
  try {
348
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
345
+ this.runtime.assertGoalToolsAvailable();
349
346
  } catch (error) {
350
347
  notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
351
348
  this.runtime.releaseWorkflow();
@@ -387,7 +384,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
387
384
  if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
388
385
  this.runtime.blockStaleGoalToolCalls();
389
386
  }
390
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
391
387
  this.runtime.releaseWorkflow();
392
388
  }
393
389
  return;
@@ -409,7 +405,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
409
405
  return;
410
406
  }
411
407
  try {
412
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
408
+ this.runtime.assertGoalToolsAvailable();
413
409
  } catch (error) {
414
410
  notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
415
411
  return;
@@ -482,10 +478,9 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
482
478
  return;
483
479
  }
484
480
  const acquiredForEdit = intendsActive && !retainedOwner;
485
- const goalToolVisibilityBeforeActivation = intendsActive ? this.runtime.toolPolicy.snapshot() : void 0;
486
481
  if (intendsActive) {
487
482
  try {
488
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
483
+ this.runtime.assertGoalToolsAvailable();
489
484
  } catch (error) {
490
485
  notifyTerminal(ctx.ui, `Cannot reactivate /goal: ${formatError(error)}`, "error");
491
486
  if (currentGoal.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
@@ -548,9 +543,6 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
548
543
  this.runtime.persistGoal(this.runtime.activeGoal);
549
544
  this.runtime.updateStatus(ctx, this.runtime.activeGoal);
550
545
  }
551
- if (goalToolVisibilityBeforeActivation) {
552
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
553
- }
554
546
  if (acquiredForEdit && previousStatus !== "active") {
555
547
  this.runtime.releaseWorkflow();
556
548
  }
@@ -627,7 +619,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
627
619
  runtime.legacyQueueState = void 0;
628
620
  runtime.legacyExperimentalGoalsSetting = false;
629
621
  runtime.clearTerminalDetails();
630
- const previousToolVisibility = runtime.settings.toolVisibility;
631
622
  const settingsResult = readGoalSettings(options.settingsPath);
632
623
  const loaded = loadGoalStateFromSession(ctx);
633
624
  runtime.settings = settingsResult.kind === "loaded" ? settingsResult.settings : DEFAULT_GOAL_SETTINGS;
@@ -660,18 +651,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
660
651
  return;
661
652
  }
662
653
  runtime.activeGoal = loaded.goal;
663
- try {
664
- runtime.toolPolicy.prepareSessionStart(
665
- runtime.settings.toolVisibility,
666
- previousToolVisibility
667
- );
668
- } catch (error) {
669
- notifyTerminal(
670
- ctx.ui,
671
- `Could not restore always-visible goal tools: ${formatError(error)}`,
672
- "error"
673
- );
674
- }
675
654
  if (runtime.activeGoal.safetyResetPending) {
676
655
  runtime.activeGoal = resetGoalSafetyEpoch(runtime.activeGoal);
677
656
  }
@@ -680,8 +659,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
680
659
  if (runtime.enforceAutomaticTurnLimit(ctx, false) || runtime.enforceNoProgressLimit(ctx)) {
681
660
  return;
682
661
  }
683
- runtime.toolPolicy.reconcileRestoredState(runtime.settings.toolVisibility, true);
684
- if (!runtime.toolPolicy.toolsAvailable()) {
662
+ if (!runtime.goalToolsAvailable()) {
685
663
  runtime.pauseGoalForUnavailableTools(ctx, false);
686
664
  return;
687
665
  }
@@ -697,34 +675,6 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
697
675
  return;
698
676
  }
699
677
  runtime.activeGoal = loaded.goal;
700
- let appliedInactivePolicy = false;
701
- let inactivePolicyFailed = false;
702
- try {
703
- appliedInactivePolicy = runtime.withTemporaryWorkflowAccess(() => {
704
- runtime.toolPolicy.prepareSessionStart(
705
- runtime.settings.toolVisibility,
706
- previousToolVisibility
707
- );
708
- runtime.toolPolicy.reconcileRestoredState(
709
- runtime.settings.toolVisibility,
710
- runtime.activeGoal !== void 0 && runtime.legacyQueueState === void 0
711
- );
712
- });
713
- } catch (error) {
714
- inactivePolicyFailed = true;
715
- notifyTerminal(
716
- ctx.ui,
717
- `Could not restore always-visible goal tools: ${formatError(error)}`,
718
- "error"
719
- );
720
- }
721
- if (!appliedInactivePolicy && !inactivePolicyFailed) {
722
- notifyTerminal(
723
- ctx.ui,
724
- "Goal tool visibility was deferred because another workflow is active in this session.",
725
- "warning"
726
- );
727
- }
728
678
  if (runtime.legacyQueueState) {
729
679
  ctx.ui.setStatus(STATUS_KEY, void 0);
730
680
  notifyTerminal(ctx.ui, REMOVED_PERSISTED_QUEUE_WARNING, "warning");
@@ -925,7 +875,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
925
875
  runtime.persistGoal(runtime.activeGoal);
926
876
  runtime.updateStatus(ctx, runtime.activeGoal);
927
877
  if (runtime.limitActiveGoalForBudget(ctx, true)) return;
928
- if (!runtime.toolPolicy.toolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
878
+ if (!runtime.goalToolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
929
879
  });
930
880
  pi.on("before_agent_start", (event, ctx) => {
931
881
  runtime.clearAgentRun();
@@ -961,7 +911,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
961
911
  }
962
912
  if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
963
913
  runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
964
- if (runtime.activeGoal?.status === "active" && !runtime.toolPolicy.toolsAvailable()) {
914
+ if (runtime.activeGoal?.status === "active" && !runtime.goalToolsAvailable()) {
965
915
  runtime.pauseGoalForUnavailableTools(ctx, false);
966
916
  }
967
917
  abortCurrentTurn(ctx);
@@ -971,7 +921,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
971
921
  return goalContractBoundaryResult(ctx);
972
922
  }
973
923
  runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
974
- if (!runtime.toolPolicy.toolsAvailable()) {
924
+ if (!runtime.goalToolsAvailable()) {
975
925
  runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== void 0);
976
926
  return goalContractBoundaryResult(ctx);
977
927
  }
@@ -996,6 +946,9 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
996
946
  });
997
947
  pi.on("turn_end", (event, ctx) => {
998
948
  runtime.recordAutomaticTurn(ctx, event.message);
949
+ if (runtime.activeGoal?.status !== "active") {
950
+ runtime.ensureInactiveGoalContextContract(ctx);
951
+ }
999
952
  });
1000
953
  pi.on("agent_end", (event, ctx) => {
1001
954
  const run = runtime.finishAgentRun();
@@ -1027,7 +980,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
1027
980
  if (isRetryableGoalInterruption(finalAssistant)) {
1028
981
  if (run.origin === "automatic" && runtime.enforceAutomaticTurnLimit(ctx, true)) return;
1029
982
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
1030
- if (!runtime.toolPolicy.toolsAvailable()) {
983
+ if (!runtime.goalToolsAvailable()) {
1031
984
  runtime.pauseGoalForUnavailableTools(ctx);
1032
985
  return;
1033
986
  }
@@ -1053,7 +1006,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
1053
1006
  }
1054
1007
  runtime.clearGoalRecoveryForGoal(goalId);
1055
1008
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
1056
- if (!runtime.toolPolicy.toolsAvailable()) {
1009
+ if (!runtime.goalToolsAvailable()) {
1057
1010
  runtime.pauseGoalForUnavailableTools(ctx);
1058
1011
  return;
1059
1012
  }
@@ -1421,14 +1374,7 @@ function registerGoalTools(pi, runtime) {
1421
1374
  const goalCompleteTool = defineTool({
1422
1375
  name: GOAL_COMPLETE_TOOL,
1423
1376
  label: "Goal Complete",
1424
- description: "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.",
1425
- promptSnippet: "Mark the active /goal as complete after fully finishing and verifying it, with the current goal_id",
1426
- promptGuidelines: [
1427
- "When a /goal is active, keep working until the goal is complete; do not stop with only a plan or partial progress.",
1428
- "Before calling goal_complete, audit the active goal requirement by requirement against the current files, command output, tests, or external state.",
1429
- "Pass the exact goal_id shown in the current /goal prompt; never reuse a goal_id from an older, stopped, replaced, or cleared turn.",
1430
- "Call goal_complete only after the requested goal is fully implemented, verified, and no known required work remains; otherwise keep working."
1431
- ],
1377
+ description: "Mark an active /goal complete only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and every requirement is verified. Tool visibility alone does not activate Goal mode. Never call for ordinary work, partial progress, blockers, failures, or unverified work.",
1432
1378
  parameters: Type.Object({
1433
1379
  goal_id: Type.String({
1434
1380
  minLength: 1,
@@ -1515,7 +1461,7 @@ function registerGoalTools(pi, runtime) {
1515
1461
  runtime.recordGoalUsage(runtime.activeGoal, ctx);
1516
1462
  runtime.persistGoal(runtime.activeGoal);
1517
1463
  ctx.ui.setStatus(STATUS_KEY, formatStatus(runtime.activeGoal));
1518
- runtime.clearActiveGoal(ctx);
1464
+ runtime.clearCompletedGoal(ctx);
1519
1465
  runtime.showCompletionStatus(ctx);
1520
1466
  notifyTerminal(ctx.ui, `Goal complete: ${goal2}`, "info");
1521
1467
  return {
@@ -1528,14 +1474,7 @@ function registerGoalTools(pi, runtime) {
1528
1474
  const goalBlockedTool = defineTool({
1529
1475
  name: GOAL_BLOCKED_TOOL,
1530
1476
  label: "Goal Blocked",
1531
- description: "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.",
1532
- promptSnippet: "Mark the active /goal blocked only after the same blocker recurs for three consecutive goal turns",
1533
- promptGuidelines: [
1534
- "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.",
1535
- "After a blocked goal is resumed, start a fresh three-turn blocker audit before using goal_blocked again.",
1536
- "Do not use goal_blocked for ordinary clarification, incomplete work, uncertainty, difficult tasks, or recoverable tool/provider failures.",
1537
- "Pass goal_blocked the exact current goal_id; never reuse a goal_id from an older, stopped, replaced, or cleared goal turn."
1538
- ],
1477
+ description: "Stop an active /goal only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and the same evidenced external blocker recurred for at least three consecutive Goal turns. Tool visibility alone does not activate Goal mode. Never call for ordinary clarification, uncertainty, incomplete work, or recoverable failures.",
1539
1478
  parameters: Type.Object({
1540
1479
  goal_id: Type.String({
1541
1480
  minLength: 1,
@@ -1607,15 +1546,7 @@ function registerGoalTools(pi, runtime) {
1607
1546
  const goalWaitTool = defineTool({
1608
1547
  name: GOAL_WAIT_TOOL,
1609
1548
  label: "Goal Wait",
1610
- description: `Keep the active /goal alive but quiet while an external event is expected. Call goal_wait alone after arranging a wake message, or provide resume_after_ms as a safety deadline. Requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms. Do not use it for ordinary unfinished work.`,
1611
- promptSnippet: "Wait quietly for an external event without stopping the active /goal or starting automatic continuations",
1612
- promptGuidelines: [
1613
- "Use goal_wait only when progress depends on a later non-goal message, or when resume_after_ms provides a bounded safety wake-up rather than a polling interval.",
1614
- `Prefer longer waits measured in minutes to avoid busy polling; goal_wait requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms.`,
1615
- "Arrange the external monitor or wake source before calling goal_wait, and call goal_wait alone because parallel sibling tools can prevent immediate turn termination.",
1616
- "Pass the exact current goal_id so a stale turn cannot put a replacement goal into waiting.",
1617
- "Do not use goal_blocked for a recoverable external wait that can be resumed by a message or deadline."
1618
- ],
1549
+ description: `Keep an active /goal quiet only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and progress depends on an arranged external wake event or one safety deadline. Tool visibility alone does not activate Goal mode. Call goal_wait alone. Requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms. Never call for ordinary unfinished work.`,
1619
1550
  parameters: Type.Object({
1620
1551
  goal_id: Type.String({
1621
1552
  minLength: 1,