@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-goal",
3
- "version": "0.53.3",
3
+ "version": "0.54.1",
4
4
  "description": "Pi extension for autonomous single-objective /goal completion.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  "typescript": "7.0.2"
51
51
  },
52
52
  "dependencies": {
53
- "@narumitw/pi-tui-kit": "^0.58.0"
53
+ "@narumitw/pi-tui-kit": "^0.58.2"
54
54
  },
55
55
  "repository": {
56
56
  "type": "git",
package/src/commands.ts CHANGED
@@ -76,15 +76,14 @@ export class GoalCommandController {
76
76
  }
77
77
  }
78
78
 
79
- // Unlock lazy visibility only after final workflow admission. In always mode,
80
- // a missing tool means another policy or allowlist intentionally removed it.
79
+ // Tool registration keeps the Goal schema stable. A missing tool means another
80
+ // policy or allowlist intentionally removed it, so activation must not widen it.
81
81
  if (isRequestCurrent && !isRequestCurrent()) return;
82
82
  const retainedOwner = this.runtime.ownsWorkflow(existingGoal);
83
83
  if (!this.runtime.acquireWorkflow(ctx.sessionManager)) return this.reportWorkflowBusy(ctx);
84
84
  const acquiredForRequest = !retainedOwner;
85
- const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
86
85
  try {
87
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
86
+ this.runtime.assertGoalToolsAvailable();
88
87
  } catch (error) {
89
88
  notifyTerminal(ctx.ui, `Cannot start /goal: ${formatError(error)}`, "error");
90
89
  if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
@@ -168,7 +167,6 @@ export class GoalCommandController {
168
167
  }
169
168
  }
170
169
  if (rolledBackStartedGoal) {
171
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
172
170
  if (acquiredForRequest && !this.runtime.ownsWorkflow(existingGoal)) {
173
171
  this.runtime.releaseWorkflow();
174
172
  }
@@ -249,9 +247,8 @@ export class GoalCommandController {
249
247
  this.reportWorkflowBusy(ctx);
250
248
  return;
251
249
  }
252
- const goalToolVisibilityBeforeActivation = this.runtime.toolPolicy.snapshot();
253
250
  try {
254
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
251
+ this.runtime.assertGoalToolsAvailable();
255
252
  } catch (error) {
256
253
  notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
257
254
  this.runtime.releaseWorkflow();
@@ -296,7 +293,6 @@ export class GoalCommandController {
296
293
  if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
297
294
  this.runtime.blockStaleGoalToolCalls();
298
295
  }
299
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
300
296
  this.runtime.releaseWorkflow();
301
297
  }
302
298
  return;
@@ -323,7 +319,7 @@ export class GoalCommandController {
323
319
  return;
324
320
  }
325
321
  try {
326
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
322
+ this.runtime.assertGoalToolsAvailable();
327
323
  } catch (error) {
328
324
  notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
329
325
  return;
@@ -404,12 +400,9 @@ export class GoalCommandController {
404
400
  return;
405
401
  }
406
402
  const acquiredForEdit = intendsActive && !retainedOwner;
407
- const goalToolVisibilityBeforeActivation = intendsActive
408
- ? this.runtime.toolPolicy.snapshot()
409
- : undefined;
410
403
  if (intendsActive) {
411
404
  try {
412
- this.runtime.toolPolicy.prepareActivation(this.runtime.settings.toolVisibility, ctx);
405
+ this.runtime.assertGoalToolsAvailable();
413
406
  } catch (error) {
414
407
  notifyTerminal(ctx.ui, `Cannot reactivate /goal: ${formatError(error)}`, "error");
415
408
  if (currentGoal.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
@@ -476,9 +469,6 @@ export class GoalCommandController {
476
469
  this.runtime.persistGoal(this.runtime.activeGoal);
477
470
  this.runtime.updateStatus(ctx, this.runtime.activeGoal);
478
471
  }
479
- if (goalToolVisibilityBeforeActivation) {
480
- this.runtime.toolPolicy.restore(goalToolVisibilityBeforeActivation);
481
- }
482
472
  if (acquiredForEdit && previousStatus !== "active") {
483
473
  this.runtime.releaseWorkflow();
484
474
  }
package/src/lifecycle.ts CHANGED
@@ -14,7 +14,6 @@ import {
14
14
  abortCurrentTurn,
15
15
  blocksStaleGoalToolCalls,
16
16
  findFinalAssistantMessage,
17
- formatError,
18
17
  type GoalRuntime,
19
18
  incrementGoal,
20
19
  isGoalContextOverflow,
@@ -59,7 +58,6 @@ export function registerGoalLifecycle(
59
58
  runtime.legacyQueueState = undefined;
60
59
  runtime.legacyExperimentalGoalsSetting = false;
61
60
  runtime.clearTerminalDetails();
62
- const previousToolVisibility = runtime.settings.toolVisibility;
63
61
  const settingsResult = readGoalSettings(options.settingsPath);
64
62
  const loaded = loadGoalStateFromSession(ctx);
65
63
  runtime.settings =
@@ -96,18 +94,6 @@ export function registerGoalLifecycle(
96
94
  return;
97
95
  }
98
96
  runtime.activeGoal = loaded.goal;
99
- try {
100
- runtime.toolPolicy.prepareSessionStart(
101
- runtime.settings.toolVisibility,
102
- previousToolVisibility,
103
- );
104
- } catch (error) {
105
- notifyTerminal(
106
- ctx.ui,
107
- `Could not restore always-visible goal tools: ${formatError(error)}`,
108
- "error",
109
- );
110
- }
111
97
  if (runtime.activeGoal.safetyResetPending) {
112
98
  // Resume/edit activation is persisted before its owned prompt starts. A
113
99
  // reload must commit that promised reset before enforcing the old limits.
@@ -118,10 +104,7 @@ export function registerGoalLifecycle(
118
104
  if (runtime.enforceAutomaticTurnLimit(ctx, false) || runtime.enforceNoProgressLimit(ctx)) {
119
105
  return;
120
106
  }
121
- // On lazy restore, an earlier restrictive session-start policy still wins:
122
- // reconciliation unlocks ownership without widening the active tool set.
123
- runtime.toolPolicy.reconcileRestoredState(runtime.settings.toolVisibility, true);
124
- if (!runtime.toolPolicy.toolsAvailable()) {
107
+ if (!runtime.goalToolsAvailable()) {
125
108
  runtime.pauseGoalForUnavailableTools(ctx, false);
126
109
  return;
127
110
  }
@@ -142,34 +125,6 @@ export function registerGoalLifecycle(
142
125
  }
143
126
 
144
127
  runtime.activeGoal = loaded.goal;
145
- let appliedInactivePolicy = false;
146
- let inactivePolicyFailed = false;
147
- try {
148
- appliedInactivePolicy = runtime.withTemporaryWorkflowAccess(() => {
149
- runtime.toolPolicy.prepareSessionStart(
150
- runtime.settings.toolVisibility,
151
- previousToolVisibility,
152
- );
153
- runtime.toolPolicy.reconcileRestoredState(
154
- runtime.settings.toolVisibility,
155
- runtime.activeGoal !== undefined && runtime.legacyQueueState === undefined,
156
- );
157
- });
158
- } catch (error) {
159
- inactivePolicyFailed = true;
160
- notifyTerminal(
161
- ctx.ui,
162
- `Could not restore always-visible goal tools: ${formatError(error)}`,
163
- "error",
164
- );
165
- }
166
- if (!appliedInactivePolicy && !inactivePolicyFailed) {
167
- notifyTerminal(
168
- ctx.ui,
169
- "Goal tool visibility was deferred because another workflow is active in this session.",
170
- "warning",
171
- );
172
- }
173
128
  if (runtime.legacyQueueState) {
174
129
  ctx.ui.setStatus(STATUS_KEY, undefined);
175
130
  notifyTerminal(ctx.ui, REMOVED_PERSISTED_QUEUE_WARNING, "warning");
@@ -437,7 +392,7 @@ export function registerGoalLifecycle(
437
392
  runtime.persistGoal(runtime.activeGoal);
438
393
  runtime.updateStatus(ctx, runtime.activeGoal);
439
394
  if (runtime.limitActiveGoalForBudget(ctx, true)) return;
440
- if (!runtime.toolPolicy.toolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
395
+ if (!runtime.goalToolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
441
396
  });
442
397
 
443
398
  pi.on("before_agent_start", (event, ctx) => {
@@ -485,7 +440,7 @@ export function registerGoalLifecycle(
485
440
  }
486
441
  if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
487
442
  runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
488
- if (runtime.activeGoal?.status === "active" && !runtime.toolPolicy.toolsAvailable()) {
443
+ if (runtime.activeGoal?.status === "active" && !runtime.goalToolsAvailable()) {
489
444
  runtime.pauseGoalForUnavailableTools(ctx, false);
490
445
  }
491
446
  abortCurrentTurn(ctx);
@@ -495,7 +450,7 @@ export function registerGoalLifecycle(
495
450
  return goalContractBoundaryResult(ctx);
496
451
  }
497
452
  runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
498
- if (!runtime.toolPolicy.toolsAvailable()) {
453
+ if (!runtime.goalToolsAvailable()) {
499
454
  runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== undefined);
500
455
  return goalContractBoundaryResult(ctx);
501
456
  }
@@ -528,6 +483,11 @@ export function registerGoalLifecycle(
528
483
 
529
484
  pi.on("turn_end", (event, ctx) => {
530
485
  runtime.recordAutomaticTurn(ctx, event.message);
486
+ // goal_complete clears state synchronously, but its inactive contract must wait
487
+ // until Pi has persisted the real tool result at this turn boundary.
488
+ if (runtime.activeGoal?.status !== "active") {
489
+ runtime.ensureInactiveGoalContextContract(ctx);
490
+ }
531
491
  });
532
492
 
533
493
  pi.on("agent_end", (event, ctx) => {
@@ -567,7 +527,7 @@ export function registerGoalLifecycle(
567
527
  if (isRetryableGoalInterruption(finalAssistant)) {
568
528
  if (run.origin === "automatic" && runtime.enforceAutomaticTurnLimit(ctx, true)) return;
569
529
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
570
- if (!runtime.toolPolicy.toolsAvailable()) {
530
+ if (!runtime.goalToolsAvailable()) {
571
531
  runtime.pauseGoalForUnavailableTools(ctx);
572
532
  return;
573
533
  }
@@ -595,7 +555,7 @@ export function registerGoalLifecycle(
595
555
  runtime.clearGoalRecoveryForGoal(goalId);
596
556
 
597
557
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
598
- if (!runtime.toolPolicy.toolsAvailable()) {
558
+ if (!runtime.goalToolsAvailable()) {
599
559
  runtime.pauseGoalForUnavailableTools(ctx);
600
560
  return;
601
561
  }
package/src/runtime.ts CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  type GoalSettings,
37
37
  type GoalSettingsLoadIssue,
38
38
  } from "./settings.js";
39
- import { GoalToolPolicy, type GoalToolVisibilitySnapshot } from "./tool-policy.js";
39
+ import { assertGoalToolsAvailable, goalToolsAvailable } from "./tool-policy.js";
40
40
  import { type GoalWait, GoalWaitTimer } from "./wait.js";
41
41
  import { WorkflowMutex, type WorkflowMutexOwner } from "./workflow-mutex.js";
42
42
 
@@ -174,7 +174,6 @@ export interface GoalSettingsRuntimeSnapshot {
174
174
  staleGoalToolCallsBlocked: boolean;
175
175
  cancelledContinuationMarkers: Array<[string, string]>;
176
176
  terminalDetails?: GoalTerminalDetails;
177
- toolVisibility: GoalToolVisibilitySnapshot;
178
177
  }
179
178
 
180
179
  interface PendingGoalPrompt {
@@ -205,7 +204,7 @@ const CONTRADICTORY_COMPLETION_PATTERNS = [
205
204
  // and the cross-cutting invariants used by command and lifecycle orchestration.
206
205
  // Keep this state machine cohesive despite its size: prompt ownership, continuation,
207
206
  // budget, safety, external-wait, and queue transitions share ordering-sensitive invariants.
208
- // Tool visibility and generic wait-timer mechanics are delegated to focused collaborators.
207
+ // Tool availability and generic wait-timer mechanics are delegated to focused collaborators.
209
208
  // Cohesion justification: Goal transitions, continuation and wait ownership, queue state, and
210
209
  // budget/retry recovery share one generation-guarded runtime; separating them further would
211
210
  // duplicate stale-turn, timer, and persistence invariants across modules.
@@ -237,7 +236,6 @@ export class GoalRuntime {
237
236
  agentRunToolAttempted = false;
238
237
  guardAbortGoalId?: string;
239
238
  staleGoalToolCallsBlocked = false;
240
- readonly toolPolicy: GoalToolPolicy;
241
239
  private readonly workflowMutex: WorkflowMutex;
242
240
  private workflowOwner?: WorkflowMutexOwner;
243
241
  private workflowSession?: object;
@@ -255,7 +253,14 @@ export class GoalRuntime {
255
253
  constructor(pi: ExtensionAPI) {
256
254
  this.pi = pi;
257
255
  this.workflowMutex = new WorkflowMutex(pi);
258
- this.toolPolicy = new GoalToolPolicy(pi);
256
+ }
257
+
258
+ goalToolsAvailable() {
259
+ return goalToolsAvailable(this.pi);
260
+ }
261
+
262
+ assertGoalToolsAvailable() {
263
+ assertGoalToolsAvailable(this.pi);
259
264
  }
260
265
 
261
266
  bindWorkflowSession(session: object) {
@@ -292,31 +297,6 @@ export class GoalRuntime {
292
297
  if (!this.workflowMutex.isOwner(owner)) this.workflowOwner = undefined;
293
298
  }
294
299
 
295
- beginTemporaryWorkflowAccess(session?: unknown) {
296
- if (session && typeof session === "object" && this.workflowSession !== session) {
297
- this.bindWorkflowSession(session);
298
- }
299
- const alreadyOwned = this.workflowMutex.isOwner(this.workflowOwner);
300
- if (!alreadyOwned && !this.acquireWorkflow()) return undefined;
301
- let released = false;
302
- return () => {
303
- if (released) return;
304
- released = true;
305
- if (!alreadyOwned) this.releaseWorkflow();
306
- };
307
- }
308
-
309
- withTemporaryWorkflowAccess(action: () => void, session?: unknown) {
310
- const release = this.beginTemporaryWorkflowAccess(session);
311
- if (!release) return false;
312
- try {
313
- action();
314
- return true;
315
- } finally {
316
- release();
317
- }
318
- }
319
-
320
300
  hasLegacyQueueInterface() {
321
301
  return this.legacyExperimentalGoalsSetting || this.legacyQueueState !== undefined;
322
302
  }
@@ -434,7 +414,7 @@ export class GoalRuntime {
434
414
  return false;
435
415
  }
436
416
  if (!intent) return false;
437
- if (this.activeGoal?.status === "active" && !this.toolPolicy.toolsAvailable()) {
417
+ if (this.activeGoal?.status === "active" && !this.goalToolsAvailable()) {
438
418
  this.pauseGoalForUnavailableTools(ctx);
439
419
  return false;
440
420
  }
@@ -1254,6 +1234,15 @@ export class GoalRuntime {
1254
1234
  }
1255
1235
 
1256
1236
  clearActiveGoal(ctx: StatusContext, reason = "goal cleared", releaseWorkflow = true) {
1237
+ this.clearActiveGoalState(ctx, reason, releaseWorkflow);
1238
+ this.ensureInactiveGoalContextContract(ctx);
1239
+ }
1240
+
1241
+ clearCompletedGoal(ctx: StatusContext) {
1242
+ this.clearActiveGoalState(ctx, "goal cleared", true);
1243
+ }
1244
+
1245
+ private clearActiveGoalState(ctx: StatusContext, reason: string, releaseWorkflow: boolean) {
1257
1246
  const clearedGoal = this.activeGoal;
1258
1247
  this.clearGoalWaitTimer();
1259
1248
  this.cancelContinuationWork();
@@ -1263,11 +1252,8 @@ export class GoalRuntime {
1263
1252
  this.activeGoal = undefined;
1264
1253
  this.legacyQueueState = undefined;
1265
1254
  this.clearPersistedGoal(ctx.cwd, clearedGoal, reason);
1266
- this.ensureInactiveGoalContextContract(ctx);
1267
1255
  ctx.ui.setStatus(STATUS_KEY, undefined);
1268
1256
  if (releaseWorkflow) this.releaseWorkflow();
1269
- // Do not relock toolPolicy: after first activation, keep tools visible for the
1270
- // rest of this extension runtime to avoid repeated tool-schema churn.
1271
1257
  }
1272
1258
 
1273
1259
  snapshotSettingsApplicationState(): GoalSettingsRuntimeSnapshot {
@@ -1288,7 +1274,6 @@ export class GoalRuntime {
1288
1274
  staleGoalToolCallsBlocked: this.staleGoalToolCallsBlocked,
1289
1275
  cancelledContinuationMarkers: [...this.cancelledContinuationMarkers],
1290
1276
  terminalDetails: this.terminalDetails ? structuredClone(this.terminalDetails) : undefined,
1291
- toolVisibility: this.toolPolicy.snapshot(),
1292
1277
  };
1293
1278
  }
1294
1279
 
@@ -1316,7 +1301,6 @@ export class GoalRuntime {
1316
1301
  this.terminalDetails = snapshot.terminalDetails
1317
1302
  ? structuredClone(snapshot.terminalDetails)
1318
1303
  : undefined;
1319
- this.toolPolicy.restore(snapshot.toolVisibility);
1320
1304
  }
1321
1305
 
1322
1306
  pauseGoalForUnavailableTools(ctx: StatusContext, abortTurn = true, recordUsage = true) {
@@ -19,8 +19,6 @@ interface GoalSettingsApplyOptions {
19
19
  save?: (settings: GoalSettings) => void;
20
20
  }
21
21
 
22
- class WorkflowBusyError extends Error {}
23
-
24
22
  type LimitField = "automaticTurns" | "noProgressTurns";
25
23
  type LimitSelection = "unlimited" | "default" | "custom" | "off";
26
24
  export async function showGoalSettings(
@@ -50,7 +48,6 @@ export async function showGoalSettings(
50
48
  | "open-no-progress"
51
49
  | "choose-automatic"
52
50
  | "choose-no-progress"
53
- | "set-visibility"
54
51
  | "set-rpc";
55
52
  const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
56
53
  start: invalid ? "invalid" : (options.initialScreen ?? "settings"),
@@ -78,14 +75,6 @@ export async function showGoalSettings(
78
75
  ),
79
76
  action: "open-no-progress",
80
77
  },
81
- {
82
- id: "toolVisibility",
83
- label: "Goal tools",
84
- description: "Keep terminal Goal tools visible, or reveal them after the first goal.",
85
- currentValue: visibilityLabel(runtime.settings.toolVisibility),
86
- values: ["Always", "After first goal"],
87
- action: "set-visibility",
88
- },
89
78
  {
90
79
  id: "rpcEnabled",
91
80
  label: "Managed run RPC",
@@ -106,7 +95,6 @@ export async function showGoalSettings(
106
95
  `Invalid settings file. Pi-goal is using built-in defaults. Fix ${safeTerminalText(settingsPath)} and run /reload. The file will not be overwritten.`,
107
96
  `Automatic-work limit: ${formatAutomaticWork(runtime.settings.continuationLimits.automaticTurns)}`,
108
97
  `No-progress guard: ${formatNoProgressProtection(runtime.settings.continuationLimits.noProgressTurns)}`,
109
- `Goal tools: ${visibilityLabel(runtime.settings.toolVisibility)}`,
110
98
  `Managed run RPC: ${runtime.settings.rpc.enabled ? "On" : "Off"}`,
111
99
  ],
112
100
  hint: "back",
@@ -143,24 +131,6 @@ export async function showGoalSettings(
143
131
  previewGoalIds.get("noProgressTurns") ?? null,
144
132
  isMenuCurrent,
145
133
  ),
146
- "set-visibility": async ({ value }) => {
147
- const nextVisibility = value === "Always" ? "always" : "after-first-goal";
148
- if (nextVisibility === runtime.settings.toolVisibility) return { kind: "stay" };
149
- try {
150
- const next = {
151
- ...structuredClone(runtime.settings),
152
- toolVisibility: nextVisibility,
153
- } satisfies GoalSettings;
154
- applyGoalSettings(runtime, next, ctx, {
155
- save: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),
156
- });
157
- notifyTerminal(ctx.ui, `Goal tools: ${value}.`, "info");
158
- return { kind: "stay" };
159
- } catch (error) {
160
- notifySettingsFailure(ctx, settingsPath, error);
161
- return { kind: "rejected" };
162
- }
163
- },
164
134
  "set-rpc": async ({ value }) => {
165
135
  const enabled = value === "On";
166
136
  if (enabled === runtime.settings.rpc.enabled) return { kind: "stay" };
@@ -326,59 +296,44 @@ export function applyGoalSettings(
326
296
  options: GoalSettingsApplyOptions = {},
327
297
  ) {
328
298
  const snapshot = runtime.snapshotSettingsApplicationState();
329
- const visibilityChanges = snapshot.settings.toolVisibility !== next.toolVisibility;
330
- const releaseWorkflow = visibilityChanges
331
- ? runtime.beginTemporaryWorkflowAccess(ctx.sessionManager)
332
- : () => undefined;
333
- if (!releaseWorkflow) {
334
- throw new WorkflowBusyError(
335
- "Another workflow is active in this session. Goal tool visibility was not changed.",
336
- );
337
- }
338
-
339
299
  let fileSaved = false;
340
300
  try {
301
+ runtime.settings = structuredClone(next);
302
+ options.save?.(next);
303
+ fileSaved = options.save !== undefined;
304
+ const activeGoalId = runtime.activeGoal?.id;
305
+ const abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;
306
+ const pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);
307
+ if (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);
308
+ if (runtime.activeGoal) {
309
+ runtime.updateStatus(ctx, runtime.activeGoal);
310
+ }
311
+ } catch (error) {
312
+ const rollbackErrors: unknown[] = [];
341
313
  try {
342
- applyToolVisibility(runtime, snapshot.settings, next, ctx);
343
- runtime.settings = structuredClone(next);
344
- options.save?.(next);
345
- fileSaved = options.save !== undefined;
346
- const activeGoalId = runtime.activeGoal?.id;
347
- const abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;
348
- const pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);
349
- if (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);
350
- if (runtime.activeGoal) {
351
- runtime.updateStatus(ctx, runtime.activeGoal);
352
- }
353
- } catch (error) {
354
- const rollbackErrors: unknown[] = [];
314
+ runtime.restoreSettingsApplicationState(snapshot);
315
+ } catch (rollbackError) {
316
+ rollbackErrors.push(rollbackError);
317
+ }
318
+ if (fileSaved) {
355
319
  try {
356
- runtime.restoreSettingsApplicationState(snapshot);
320
+ options.save?.(snapshot.settings);
357
321
  } catch (rollbackError) {
358
322
  rollbackErrors.push(rollbackError);
359
323
  }
360
- if (fileSaved) {
361
- try {
362
- options.save?.(snapshot.settings);
363
- } catch (rollbackError) {
364
- rollbackErrors.push(rollbackError);
365
- }
366
- try {
367
- restorePersistedRuntime(runtime, ctx);
368
- } catch (rollbackError) {
369
- rollbackErrors.push(rollbackError);
370
- }
371
- }
372
- if (rollbackErrors.length > 0) {
373
- throw new AggregateError(
374
- [error, ...rollbackErrors],
375
- `pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,
376
- );
324
+ try {
325
+ restorePersistedRuntime(runtime, ctx);
326
+ } catch (rollbackError) {
327
+ rollbackErrors.push(rollbackError);
377
328
  }
378
- throw error;
379
329
  }
380
- } finally {
381
- releaseWorkflow();
330
+ if (rollbackErrors.length > 0) {
331
+ throw new AggregateError(
332
+ [error, ...rollbackErrors],
333
+ `pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,
334
+ );
335
+ }
336
+ throw error;
382
337
  }
383
338
  }
384
339
 
@@ -430,21 +385,6 @@ async function resolveLimitSelection(
430
385
  }
431
386
  }
432
387
 
433
- function applyToolVisibility(
434
- runtime: GoalRuntime,
435
- previous: GoalSettings,
436
- next: GoalSettings,
437
- ctx: ExtensionCommandContext,
438
- ) {
439
- if (previous.toolVisibility === next.toolVisibility) return;
440
- runtime.toolPolicy.applyVisibilityChange(
441
- previous.toolVisibility,
442
- next.toolVisibility,
443
- runtime.activeGoal !== undefined,
444
- ctx,
445
- );
446
- }
447
-
448
388
  function restorePersistedRuntime(runtime: GoalRuntime, ctx: ExtensionCommandContext) {
449
389
  if (runtime.activeGoal) {
450
390
  runtime.persistGoal(runtime.activeGoal);
@@ -507,10 +447,6 @@ function isLimitSelection(value: string): value is LimitSelection {
507
447
  return value === "unlimited" || value === "default" || value === "custom" || value === "off";
508
448
  }
509
449
 
510
- function visibilityLabel(value: GoalSettings["toolVisibility"]) {
511
- return value === "always" ? "Always" : "After first goal";
512
- }
513
-
514
450
  function notifySettingsFailure(ctx: ExtensionCommandContext, settingsPath: string, error: unknown) {
515
451
  const path = safeTerminalText(settingsPath);
516
452
  const detail = safeTerminalText(formatError(error));
package/src/settings.ts CHANGED
@@ -4,13 +4,10 @@ import { basename, dirname, join } from "node:path";
4
4
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
5
5
 
6
6
  export const GOAL_SETTINGS_FILE = "pi-goal.json";
7
- export const GOAL_TOOL_VISIBILITIES = ["always", "after-first-goal"] as const;
8
7
 
9
- export type GoalToolVisibility = (typeof GOAL_TOOL_VISIBILITIES)[number];
10
8
  export type ContinuationLimit = number | null;
11
9
 
12
10
  export interface GoalSettings {
13
- toolVisibility: GoalToolVisibility;
14
11
  rpc: {
15
12
  enabled: boolean;
16
13
  };
@@ -21,7 +18,6 @@ export interface GoalSettings {
21
18
  }
22
19
 
23
20
  export const DEFAULT_GOAL_SETTINGS: GoalSettings = {
24
- toolVisibility: "after-first-goal",
25
21
  rpc: { enabled: false },
26
22
  continuationLimits: { automaticTurns: 25, noProgressTurns: 3 },
27
23
  };
@@ -42,10 +38,6 @@ interface GoalSettingsSaveFileSystem {
42
38
 
43
39
  export function normalizeGoalSettings(value: unknown): GoalSettings | undefined {
44
40
  if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;
45
- const toolVisibility = Object.hasOwn(value, "toolVisibility")
46
- ? Reflect.get(value, "toolVisibility")
47
- : DEFAULT_GOAL_SETTINGS.toolVisibility;
48
- if (!GOAL_TOOL_VISIBILITIES.includes(toolVisibility as GoalToolVisibility)) return undefined;
49
41
 
50
42
  const rpcValue = Object.hasOwn(value, "rpc") ? Reflect.get(value, "rpc") : undefined;
51
43
  if (
@@ -86,7 +78,6 @@ export function normalizeGoalSettings(value: unknown): GoalSettings | undefined
86
78
  if (automaticTurns === undefined || noProgressTurns === undefined) return undefined;
87
79
 
88
80
  return {
89
- toolVisibility: toolVisibility as GoalToolVisibility,
90
81
  rpc: { enabled: rpcEnabled },
91
82
  continuationLimits: { automaticTurns, noProgressTurns },
92
83
  };
@@ -128,7 +119,6 @@ export function saveGoalSettings(
128
119
  const document = `${JSON.stringify(
129
120
  {
130
121
  ...raw,
131
- toolVisibility: normalized.toolVisibility,
132
122
  rpc: { ...rpc, enabled: normalized.rpc.enabled },
133
123
  continuationLimits: {
134
124
  ...continuationLimits,