@narumitw/pi-goal 0.46.0 → 0.49.0

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/src/runtime.ts CHANGED
@@ -29,6 +29,9 @@ import {
29
29
  type GoalSettings,
30
30
  type GoalSettingsLoadIssue,
31
31
  } from "./settings.js";
32
+ import { GoalToolPolicy, type GoalToolVisibilitySnapshot } from "./tool-policy.js";
33
+
34
+ export { GOAL_BLOCKED_TOOL, GOAL_COMPLETE_TOOL, GOAL_TOOL_NAMES } from "./tool-policy.js";
32
35
 
33
36
  export interface ContinuationTicket {
34
37
  goalId: string;
@@ -59,6 +62,39 @@ export interface CompletedGoalRun {
59
62
  toolAttempted: boolean;
60
63
  }
61
64
 
65
+ type StoppedGoalStatus = "paused" | "blocked" | "usage_limited" | "budget_limited";
66
+
67
+ export type GoalStopRequest =
68
+ | { kind: "explicit_pause"; expectedGoalId: string }
69
+ | { kind: "budget_limit"; expectedGoalId: string; reason: string }
70
+ | {
71
+ kind: "safety_pause";
72
+ expectedGoalId: string;
73
+ cause: SafetyPauseCause;
74
+ abortTurn: boolean;
75
+ reason: string;
76
+ }
77
+ | { kind: "retry_exhausted"; expectedGoalId: string; reason: string }
78
+ | {
79
+ kind: "tools_unavailable";
80
+ expectedGoalId: string;
81
+ abortTurn: boolean;
82
+ recordUsage: boolean;
83
+ }
84
+ | { kind: "blocker_report"; expectedGoalId: string; reason: string }
85
+ | {
86
+ kind: "agent_interruption";
87
+ expectedGoalId: string;
88
+ status: "paused" | "blocked" | "usage_limited";
89
+ reason: string;
90
+ }
91
+ | {
92
+ kind: "activation_rollback";
93
+ expectedGoalId: string;
94
+ restoreGoal: ActiveGoal;
95
+ abortTurn: boolean;
96
+ };
97
+
62
98
  export interface StatusContext {
63
99
  cwd: string;
64
100
  mode?: "tui" | "rpc" | "json" | "print";
@@ -73,17 +109,8 @@ export interface StatusContext {
73
109
  sessionManager?: unknown;
74
110
  }
75
111
 
76
- export interface GoalToolVisibilitySnapshot {
77
- activeTools: string[];
78
- goalToolsUnlocked: boolean;
79
- goalToolsHiddenByPolicy: string[];
80
- }
81
-
82
112
  export const STATUS_KEY = "goal";
83
113
  export const GOAL_STATE_ENTRY_TYPE = "goal-state";
84
- export const GOAL_COMPLETE_TOOL = "goal_complete";
85
- export const GOAL_BLOCKED_TOOL = "goal_blocked";
86
- export const GOAL_TOOL_NAMES = [GOAL_COMPLETE_TOOL, GOAL_BLOCKED_TOOL] as const;
87
114
 
88
115
  /** Canonical Goal state passed to the in-process managed-run publisher. */
89
116
  export type GoalStateSnapshotStatus = GoalStatus | "cleared";
@@ -160,10 +187,11 @@ const CONTRADICTORY_COMPLETION_PATTERNS = [
160
187
  // One instance belongs to one extension factory. It owns all mutable session state
161
188
  // and the cross-cutting invariants used by command and lifecycle orchestration.
162
189
  // Keep this state machine cohesive despite its size: prompt ownership, continuation,
163
- // budget, safety, and tool-policy transitions share ordering-sensitive invariants.
190
+ // budget, safety, and queue transitions share ordering-sensitive invariants. Tool visibility is
191
+ // delegated to GoalToolPolicy.
164
192
  // Cohesion justification: Goal transitions, continuation ownership, queue state, and budget/retry
165
- // recovery share one generation-guarded runtime; separating them would duplicate stale-turn and
166
- // persistence invariants across modules.
193
+ // recovery share one generation-guarded runtime; separating them further would duplicate stale-turn
194
+ // and persistence invariants across modules.
167
195
  export class GoalRuntime {
168
196
  settings: GoalSettings = DEFAULT_GOAL_SETTINGS;
169
197
  settingsLoadIssue?: GoalSettingsLoadIssue;
@@ -186,10 +214,7 @@ export class GoalRuntime {
186
214
  agentRunToolAttempted = false;
187
215
  guardAbortGoalId?: string;
188
216
  staleGoalToolCallsBlocked = false;
189
- /** Once true, goal tools stay in the active set for this runtime (prompt-cache stable). */
190
- goalToolsUnlocked = false;
191
- /** Exact lazy goal tools this runtime removed and may restore on a mode change. */
192
- goalToolsHiddenByPolicy = new Set<string>();
217
+ readonly toolPolicy: GoalToolPolicy;
193
218
  pendingGoalPromptMarkers = new Map<string, PendingGoalPrompt>();
194
219
  claimedGoalPromptMarkers = new Set<string>();
195
220
  cancelledContinuationMarkers = new Set<string>();
@@ -202,6 +227,7 @@ export class GoalRuntime {
202
227
 
203
228
  constructor(pi: ExtensionAPI) {
204
229
  this.pi = pi;
230
+ this.toolPolicy = new GoalToolPolicy(pi);
205
231
  }
206
232
 
207
233
  setGoalStateSink(sink: ((snapshot: GoalStateSnapshot) => void) | undefined) {
@@ -318,7 +344,7 @@ export class GoalRuntime {
318
344
  dispatchContinuationIfSettled(ctx: StatusContext) {
319
345
  const intent = this.continuationIntent;
320
346
  if (!intent) return false;
321
- if (this.activeGoal?.status === "active" && !this.goalToolsAvailable()) {
347
+ if (this.activeGoal?.status === "active" && !this.toolPolicy.toolsAvailable()) {
322
348
  this.pauseGoalForUnavailableTools(ctx);
323
349
  return false;
324
350
  }
@@ -360,7 +386,103 @@ export class GoalRuntime {
360
386
 
361
387
  updateStatus(ctx: StatusContext, goal: ActiveGoal) {
362
388
  this.clearCompletionStatusTimer();
363
- ctx.ui.setStatus(STATUS_KEY, formatStatus(goal));
389
+ ctx.ui.setStatus(
390
+ STATUS_KEY,
391
+ formatStatus(goal, this.settings.continuationLimits.automaticTurns),
392
+ );
393
+ }
394
+
395
+ stopActiveGoal(ctx: StatusContext, request: GoalStopRequest) {
396
+ const currentGoal = this.activeGoal;
397
+ if (!currentGoal || currentGoal.id !== request.expectedGoalId) return undefined;
398
+
399
+ let goal = currentGoal;
400
+ let status: StoppedGoalStatus;
401
+ let terminalReason: string | undefined;
402
+ switch (request.kind) {
403
+ case "explicit_pause":
404
+ this.recordGoalUsage(goal, ctx);
405
+ this.cancelContinuationWork();
406
+ this.clearGoalRecoveryForGoal(goal.id);
407
+ this.clearBudgetWrapUp();
408
+ this.blockStaleGoalToolCalls();
409
+ abortCurrentTurn(ctx);
410
+ status = "paused";
411
+ break;
412
+ case "budget_limit":
413
+ this.cancelContinuationWork();
414
+ this.clearGoalRecoveryForGoal(goal.id);
415
+ this.clearBudgetWrapUp();
416
+ status = "budget_limited";
417
+ terminalReason = request.reason;
418
+ break;
419
+ case "safety_pause":
420
+ this.cancelContinuationWork();
421
+ this.clearGoalRecoveryForGoal(goal.id);
422
+ this.clearBudgetWrapUp();
423
+ this.blockStaleGoalToolCalls();
424
+ if (request.abortTurn) {
425
+ this.guardAbortGoalId = goal.id;
426
+ abortCurrentTurn(ctx);
427
+ }
428
+ goal = { ...goal, safetyPauseCause: request.cause };
429
+ status = "paused";
430
+ terminalReason = request.reason;
431
+ break;
432
+ case "retry_exhausted":
433
+ this.clearGoalRecoveryForGoal(goal.id);
434
+ this.cancelContinuationWork();
435
+ this.clearBudgetWrapUp();
436
+ this.blockStaleGoalToolCalls();
437
+ status = "blocked";
438
+ terminalReason = request.reason;
439
+ break;
440
+ case "tools_unavailable":
441
+ if (request.recordUsage) this.recordGoalUsage(goal, ctx);
442
+ this.cancelContinuationWork();
443
+ this.clearGoalRecoveryForGoal(goal.id);
444
+ this.clearBudgetWrapUp();
445
+ if (request.abortTurn) {
446
+ this.blockStaleGoalToolCalls();
447
+ abortCurrentTurn(ctx);
448
+ } else {
449
+ this.clearStaleGoalToolCallBlock();
450
+ }
451
+ status = "paused";
452
+ break;
453
+ case "blocker_report":
454
+ this.recordGoalUsage(goal, ctx);
455
+ this.cancelContinuationWork();
456
+ this.clearBudgetWrapUp();
457
+ this.clearGoalRecoveryForGoal(goal.id);
458
+ this.blockStaleGoalToolCalls();
459
+ status = "blocked";
460
+ terminalReason = request.reason;
461
+ break;
462
+ case "agent_interruption":
463
+ this.cancelContinuationWork();
464
+ this.clearBudgetWrapUp();
465
+ this.blockStaleGoalToolCalls();
466
+ abortCurrentTurn(ctx);
467
+ status = request.status;
468
+ terminalReason = request.reason;
469
+ break;
470
+ case "activation_rollback":
471
+ goal = request.restoreGoal;
472
+ if (request.abortTurn) abortCurrentTurn(ctx);
473
+ this.blockStaleGoalToolCalls();
474
+ status = "paused";
475
+ break;
476
+ }
477
+
478
+ this.activeGoal = transitionGoal(goal, status);
479
+ if (terminalReason !== undefined) this.setTerminalReason(this.activeGoal.id, terminalReason);
480
+ const stoppedGoal = this.activeGoal;
481
+ this.persistGoal(stoppedGoal);
482
+ if (this.activeGoal?.id === stoppedGoal.id && this.activeGoal.status === stoppedGoal.status) {
483
+ this.updateStatus(ctx, stoppedGoal);
484
+ }
485
+ return stoppedGoal;
364
486
  }
365
487
 
366
488
  blockStaleGoalToolCalls() {
@@ -450,18 +572,14 @@ export class GoalRuntime {
450
572
  return false;
451
573
  }
452
574
 
453
- this.cancelContinuationWork();
454
- this.clearGoalRecoveryForGoal(goal.id);
455
- this.clearBudgetWrapUp();
456
- this.activeGoal = transitionGoal(goal, "budget_limited");
457
- this.setTerminalReason(
458
- this.activeGoal.id,
459
- `token budget reached (${formatBudget(this.activeGoal)})`,
460
- );
461
- this.persistGoal(this.activeGoal);
462
- this.updateStatus(ctx, this.activeGoal);
463
- ctx.ui.notify(`Goal token budget reached: ${formatBudget(this.activeGoal)}`, "warning");
464
- if (sendWrapUp) this.queueBudgetWrapUp(ctx, this.activeGoal);
575
+ const stoppedGoal = this.stopActiveGoal(ctx, {
576
+ kind: "budget_limit",
577
+ expectedGoalId: goal.id,
578
+ reason: `token budget reached (${formatBudget(goal)})`,
579
+ });
580
+ if (!stoppedGoal) return false;
581
+ ctx.ui.notify(`Goal token budget reached: ${formatBudget(stoppedGoal)}`, "warning");
582
+ if (sendWrapUp) this.queueBudgetWrapUp(ctx, stoppedGoal);
465
583
  return true;
466
584
  }
467
585
 
@@ -519,27 +637,23 @@ export class GoalRuntime {
519
637
  pauseGoalForSafety(ctx: StatusContext, cause: SafetyPauseCause, abortTurn: boolean) {
520
638
  const goal = this.activeGoal;
521
639
  if (goal?.status !== "active") return false;
522
- this.cancelContinuationWork();
523
- this.clearGoalRecoveryForGoal(goal.id);
524
- this.clearBudgetWrapUp();
525
- this.blockStaleGoalToolCalls();
526
- if (abortTurn) {
527
- this.guardAbortGoalId = goal.id;
528
- abortCurrentTurn(ctx);
529
- }
530
- this.activeGoal = transitionGoal({ ...goal, safetyPauseCause: cause }, "paused");
640
+ const automaticLimit = this.settings.continuationLimits.automaticTurns;
531
641
  const count =
532
642
  cause === "continuation_limit"
533
- ? `${this.activeGoal.automaticModelTurns} automatic model responses`
534
- : `no progress across ${this.activeGoal.toolFreeRepeatCount} automatic runs`;
535
- this.setTerminalReason(
536
- this.activeGoal.id,
537
- `${cause} (${count}; ${formatTokenCount(this.activeGoal.tokensUsed)} tokens)`,
538
- );
539
- this.persistGoal(this.activeGoal);
540
- this.updateStatus(ctx, this.activeGoal);
643
+ ? `${goal.automaticModelTurns} of ${automaticLimit ?? "Unlimited"} automatic model responses`
644
+ : `no progress across ${goal.toolFreeRepeatCount} automatic runs`;
645
+ const stoppedGoal = this.stopActiveGoal(ctx, {
646
+ kind: "safety_pause",
647
+ expectedGoalId: goal.id,
648
+ cause,
649
+ abortTurn,
650
+ reason: `${cause} (${count}; ${formatTokenCount(goal.tokensUsed)} tokens)`,
651
+ });
652
+ if (!stoppedGoal) return false;
541
653
  ctx.ui.notify(
542
- `Goal paused: ${count}; ${formatTokenCount(this.activeGoal.tokensUsed)} cumulative tokens. Run /goal resume to continue.`,
654
+ cause === "continuation_limit"
655
+ ? `Automatic-work limit reached: ${stoppedGoal.automaticModelTurns} of ${automaticLimit} responses. Goal progress is saved with ${formatTokenCount(stoppedGoal.tokensUsed)} cumulative tokens. Open /goal to review and continue.`
656
+ : `Goal paused: ${count}; ${formatTokenCount(stoppedGoal.tokensUsed)} cumulative tokens. Open /goal to review and continue.`,
543
657
  "warning",
544
658
  );
545
659
  return true;
@@ -561,14 +675,13 @@ export class GoalRuntime {
561
675
  this.goalRecovery = undefined;
562
676
  const goal = this.activeGoal;
563
677
  if (goal?.id !== recovery.goalId || goal.status !== "active") return false;
564
- this.cancelContinuationWork();
565
- this.clearBudgetWrapUp();
566
- this.blockStaleGoalToolCalls();
567
- this.activeGoal = transitionGoal(goal, "blocked");
568
678
  const details = recovery.errorMessage ? `: ${truncateNotification(recovery.errorMessage)}` : "";
569
- this.setTerminalReason(this.activeGoal.id, `agent error after retries${details}`);
570
- this.persistGoal(this.activeGoal);
571
- this.updateStatus(ctx, this.activeGoal);
679
+ const stoppedGoal = this.stopActiveGoal(ctx, {
680
+ kind: "retry_exhausted",
681
+ expectedGoalId: goal.id,
682
+ reason: `agent error after retries${details}`,
683
+ });
684
+ if (!stoppedGoal) return false;
572
685
  ctx.ui.notify(
573
686
  `Goal blocked after agent error retries were exhausted${details}. Resolve the blocker or run /goal resume to retry.`,
574
687
  "warning",
@@ -786,99 +899,8 @@ export class GoalRuntime {
786
899
  this.queueFreezeAwaitingSettle = false;
787
900
  this.clearPersistedGoal(ctx.cwd, clearedGoal, reason);
788
901
  ctx.ui.setStatus(STATUS_KEY, undefined);
789
- // Do not clear goalToolsUnlocked: after first activation, keep tools visible
790
- // for the rest of this extension runtime to avoid repeated goal-tool schema
791
- // churn within the same runtime.
792
- }
793
-
794
- isGoalToolName(name: string) {
795
- return (GOAL_TOOL_NAMES as readonly string[]).includes(name);
796
- }
797
-
798
- goalToolsAvailable() {
799
- const active = new Set(this.pi.getActiveTools());
800
- return GOAL_TOOL_NAMES.every((name) => active.has(name));
801
- }
802
-
803
- hideGoalToolsIfLocked() {
804
- if (this.goalToolsUnlocked) return;
805
- const active = this.pi.getActiveTools();
806
- const hidden = active.filter((name) => this.isGoalToolName(name));
807
- if (hidden.length === 0) return;
808
- this.pi.setActiveTools(active.filter((name) => !this.isGoalToolName(name)));
809
- for (const name of hidden) this.goalToolsHiddenByPolicy.add(name);
810
- }
811
-
812
- restoreGoalToolsHiddenByPolicy() {
813
- const activeBeforeRestore = this.pi.getActiveTools();
814
- const activeSet = new Set(activeBeforeRestore);
815
- const missingOwnedTools = [...this.goalToolsHiddenByPolicy].filter(
816
- (name) => !activeSet.has(name),
817
- );
818
- if (missingOwnedTools.length === 0) {
819
- this.goalToolsHiddenByPolicy.clear();
820
- return;
821
- }
822
- try {
823
- this.pi.setActiveTools([...activeBeforeRestore, ...missingOwnedTools]);
824
- const restored = new Set(this.pi.getActiveTools());
825
- if (missingOwnedTools.some((name) => !restored.has(name))) {
826
- throw new Error("the active tool policy rejected a previously hidden goal tool");
827
- }
828
- this.goalToolsHiddenByPolicy.clear();
829
- } catch (error) {
830
- this.pi.setActiveTools(activeBeforeRestore);
831
- throw error;
832
- }
833
- }
834
-
835
- assertGoalToolsAvailable() {
836
- if (this.goalToolsAvailable()) return;
837
- throw new Error(
838
- "goal_complete and goal_blocked are unavailable; include them in the active tool allowlist or leave the restrictive tool mode first.",
839
- );
840
- }
841
-
842
- ensureGoalToolsVisible() {
843
- const active = this.pi.getActiveTools();
844
- const activeSet = new Set(active);
845
- const missing = GOAL_TOOL_NAMES.filter((name) => !activeSet.has(name));
846
- if (missing.length > 0) this.pi.setActiveTools([...active, ...missing]);
847
- this.assertGoalToolsAvailable();
848
- }
849
-
850
- prepareGoalToolsForActivation(ctx: StatusContext) {
851
- if (this.settings.toolVisibility === "after-first-goal") {
852
- if (!this.goalToolsAvailable() && ctx.isIdle?.() !== true) {
853
- throw new Error("wait until Pi is idle before revealing the goal tools");
854
- }
855
- this.revealGoalTools();
856
- return;
857
- }
858
- this.assertGoalToolsAvailable();
859
- }
860
-
861
- /** Mark lazy tools permanently desired for this runtime and make them active now. */
862
- revealGoalTools() {
863
- const activeBeforeReveal = this.pi.getActiveTools();
864
- const wasUnlocked = this.goalToolsUnlocked;
865
- try {
866
- this.ensureGoalToolsVisible();
867
- this.goalToolsUnlocked = true;
868
- this.goalToolsHiddenByPolicy.clear();
869
- } catch (error) {
870
- this.pi.setActiveTools(activeBeforeReveal);
871
- this.goalToolsUnlocked = wasUnlocked;
872
- throw error;
873
- }
874
- }
875
-
876
- snapshotGoalToolVisibility(): GoalToolVisibilitySnapshot {
877
- return {
878
- activeTools: this.pi.getActiveTools(),
879
- goalToolsUnlocked: this.goalToolsUnlocked,
880
- goalToolsHiddenByPolicy: [...this.goalToolsHiddenByPolicy],
881
- };
902
+ // Do not relock toolPolicy: after first activation, keep tools visible for the
903
+ // rest of this extension runtime to avoid repeated tool-schema churn.
882
904
  }
883
905
 
884
906
  snapshotSettingsApplicationState(): GoalSettingsRuntimeSnapshot {
@@ -899,7 +921,7 @@ export class GoalRuntime {
899
921
  staleGoalToolCallsBlocked: this.staleGoalToolCallsBlocked,
900
922
  cancelledContinuationMarkers: [...this.cancelledContinuationMarkers],
901
923
  terminalDetails: this.terminalDetails ? structuredClone(this.terminalDetails) : undefined,
902
- toolVisibility: this.snapshotGoalToolVisibility(),
924
+ toolVisibility: this.toolPolicy.snapshot(),
903
925
  };
904
926
  }
905
927
 
@@ -922,34 +944,19 @@ export class GoalRuntime {
922
944
  this.terminalDetails = snapshot.terminalDetails
923
945
  ? structuredClone(snapshot.terminalDetails)
924
946
  : undefined;
925
- this.restoreGoalToolVisibility(snapshot.toolVisibility);
926
- }
927
-
928
- restoreGoalToolVisibility(snapshot: GoalToolVisibilitySnapshot) {
929
- this.pi.setActiveTools(snapshot.activeTools);
930
- this.goalToolsUnlocked = snapshot.goalToolsUnlocked;
931
- this.goalToolsHiddenByPolicy.clear();
932
- for (const name of snapshot.goalToolsHiddenByPolicy) {
933
- this.goalToolsHiddenByPolicy.add(name);
934
- }
947
+ this.toolPolicy.restore(snapshot.toolVisibility);
935
948
  }
936
949
 
937
950
  pauseGoalForUnavailableTools(ctx: StatusContext, abortTurn = true, recordUsage = true) {
938
951
  const goal = this.activeGoal;
939
952
  if (goal?.status !== "active") return false;
940
- if (recordUsage) this.recordGoalUsage(goal, ctx);
941
- this.cancelContinuationWork();
942
- this.clearGoalRecoveryForGoal(goal.id);
943
- this.clearBudgetWrapUp();
944
- if (abortTurn) {
945
- this.blockStaleGoalToolCalls();
946
- abortCurrentTurn(ctx);
947
- } else {
948
- this.clearStaleGoalToolCallBlock();
949
- }
950
- this.activeGoal = transitionGoal(goal, "paused");
951
- this.persistGoal(this.activeGoal);
952
- this.updateStatus(ctx, this.activeGoal);
953
+ const stoppedGoal = this.stopActiveGoal(ctx, {
954
+ kind: "tools_unavailable",
955
+ expectedGoalId: goal.id,
956
+ abortTurn,
957
+ recordUsage,
958
+ });
959
+ if (!stoppedGoal) return false;
953
960
  ctx.ui.notify(
954
961
  "Goal tools are unavailable, so the active goal was paused. Restore the tools and run /goal resume.",
955
962
  "warning",
@@ -1071,16 +1078,32 @@ export function incrementGoal(goal: ActiveGoal): ActiveGoal {
1071
1078
  return { ...goal, iteration: goal.iteration + 1, updatedAt: Date.now() };
1072
1079
  }
1073
1080
 
1074
- export function formatStatus(goal: ActiveGoal | undefined) {
1081
+ export function formatStatus(
1082
+ goal: ActiveGoal | undefined,
1083
+ automaticTurnLimit: number | null = DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns,
1084
+ ) {
1075
1085
  if (!goal) return undefined;
1076
1086
  if (goal.status === "complete") return "complete";
1077
- if (goal.status === "queued") return "queued";
1078
- if (goal.status === "paused") return "paused";
1079
- if (goal.status === "blocked") return "blocked";
1080
- if (goal.status === "usage_limited") return "usage";
1081
- if (goal.status === "budget_limited") return `budget ${formatBudget(goal)}`;
1082
- if (goal.tokenBudget !== undefined) return `active ${formatBudget(goal)}`;
1083
- return `active ${formatDuration(goal.timeUsedSeconds)}`;
1087
+ const automatic =
1088
+ automaticTurnLimit === null
1089
+ ? "automatic Unlimited"
1090
+ : `automatic ${goal.automaticModelTurns}/${automaticTurnLimit}`;
1091
+ if (goal.status === "queued") return `queued · ${automatic}`;
1092
+ if (goal.status === "paused" && goal.safetyPauseCause === "continuation_limit") {
1093
+ if (automaticTurnLimit === null) {
1094
+ return `paused · previous automatic limit at ${goal.automaticModelTurns}`;
1095
+ }
1096
+ if (goal.automaticModelTurns < automaticTurnLimit) {
1097
+ return `paused · automatic ${goal.automaticModelTurns}/${automaticTurnLimit}`;
1098
+ }
1099
+ return `paused · automatic limit ${goal.automaticModelTurns}/${automaticTurnLimit}`;
1100
+ }
1101
+ if (goal.status === "paused") return `paused · ${automatic}`;
1102
+ if (goal.status === "blocked") return `blocked · ${automatic}`;
1103
+ if (goal.status === "usage_limited") return `usage · ${automatic}`;
1104
+ if (goal.status === "budget_limited") return `budget ${formatBudget(goal)} · ${automatic}`;
1105
+ if (goal.tokenBudget !== undefined) return `active ${formatBudget(goal)} · ${automatic}`;
1106
+ return `active ${formatDuration(goal.timeUsedSeconds)} · ${automatic}`;
1084
1107
  }
1085
1108
 
1086
1109
  export function formatBudget(goal: ActiveGoal) {
@@ -1093,18 +1116,23 @@ export function goalSummary(
1093
1116
  experimentalGoals = false,
1094
1117
  queueFrozen = false,
1095
1118
  pendingAction?: PendingQueueAction,
1119
+ automaticTurnLimit: number | null = DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns,
1096
1120
  ) {
1097
1121
  const summary = [
1098
1122
  `Goal: ${goal.text}`,
1099
1123
  `Status: ${queueFrozen ? "queue off" : goal.status}`,
1100
1124
  `Iteration: ${goal.iteration}`,
1101
- `Automatic model responses: ${goal.automaticModelTurns}`,
1125
+ automaticTurnLimit === null
1126
+ ? `Automatic work: ${goal.automaticModelTurns} responses · Unlimited`
1127
+ : `Automatic work: ${goal.automaticModelTurns} of ${automaticTurnLimit} responses`,
1102
1128
  `Active elapsed: ${formatDuration(goal.timeUsedSeconds)}`,
1103
1129
  `Tokens: ${goal.tokenBudget === undefined ? formatTokenCount(goal.tokensUsed) : formatBudget(goal)}`,
1104
1130
  ];
1105
1131
  if (goal.safetyPauseCause) {
1106
1132
  summary.push(
1107
- `Safety pause: ${goal.safetyPauseCause === "continuation_limit" ? "automatic response limit" : "no progress"}`,
1133
+ goal.safetyPauseCause === "continuation_limit"
1134
+ ? `Safety pause: automatic-work limit reached (${goal.automaticModelTurns} of ${automaticTurnLimit ?? "Unlimited"} responses). Progress is saved; open /goal to review and continue.`
1135
+ : "Safety pause: no progress. Progress is saved; open /goal to review and continue.",
1108
1136
  );
1109
1137
  }
1110
1138
  if (experimentalGoals || queuedGoals.length > 0 || queueFrozen || pendingAction) {