@narumitw/pi-goal 0.53.1 → 0.54.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-goal",
3
- "version": "0.53.1",
3
+ "version": "0.54.0",
4
4
  "description": "Pi extension for autonomous single-objective /goal completion.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -41,16 +41,16 @@
41
41
  "typebox": "*"
42
42
  },
43
43
  "devDependencies": {
44
- "@biomejs/biome": "2.5.9",
45
- "@earendil-works/pi-ai": "0.84.2",
46
- "@earendil-works/pi-coding-agent": "0.84.2",
47
- "@earendil-works/pi-tui": "0.84.2",
44
+ "@biomejs/biome": "2.5.10",
45
+ "@earendil-works/pi-ai": "0.84.3",
46
+ "@earendil-works/pi-coding-agent": "0.84.3",
47
+ "@earendil-works/pi-tui": "0.84.3",
48
48
  "esbuild": "0.28.2",
49
- "typebox": "1.3.16",
49
+ "typebox": "1.3.18",
50
50
  "typescript": "7.0.2"
51
51
  },
52
52
  "dependencies": {
53
- "@narumitw/pi-tui-kit": "^0.57.0"
53
+ "@narumitw/pi-tui-kit": "^0.58.0"
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
  }
@@ -2,7 +2,13 @@ import type { GoalPromptContext } from "./prompts.js";
2
2
  import { buildGoalContextPrompt } from "./prompts.js";
3
3
 
4
4
  export const GOAL_CONTRACT_MESSAGE_TYPE = "goal-contract";
5
- export const GOAL_CONTRACT_VERSION = 1;
5
+ export const GOAL_CONTRACT_VERSION = 2;
6
+
7
+ const INACTIVE_GOAL_CONTRACT_CONTENT = [
8
+ "Goal mode is inactive.",
9
+ "This Goal contract supersedes every earlier goal-contract message.",
10
+ "Do not treat an earlier Goal objective, goal_id, Goal-mode rule, or summary of them as current unless a later Goal contract explicitly reactivates Goal mode.",
11
+ ].join("\n");
6
12
 
7
13
  interface ContractMessage {
8
14
  role?: string;
@@ -10,40 +16,86 @@ interface ContractMessage {
10
16
  content?: unknown;
11
17
  }
12
18
 
19
+ interface ContractSessionEntry extends ContractMessage {
20
+ type?: string;
21
+ message?: unknown;
22
+ }
23
+
13
24
  export function createGoalContextContract(goal: GoalPromptContext) {
14
25
  return {
15
26
  role: "custom" as const,
16
27
  customType: GOAL_CONTRACT_MESSAGE_TYPE,
17
- content: buildGoalContextPrompt(goal),
28
+ content: [
29
+ "This Goal contract supersedes every earlier goal-contract message.",
30
+ "Only the objective and goal_id in this latest Goal contract are current.",
31
+ buildGoalContextPrompt(goal),
32
+ ].join("\n\n"),
18
33
  display: false,
19
- details: { version: GOAL_CONTRACT_VERSION, goalId: goal.id },
34
+ details: { version: GOAL_CONTRACT_VERSION, state: "active", goalId: goal.id },
35
+ timestamp: 0,
36
+ };
37
+ }
38
+
39
+ export function createInactiveGoalContextContract() {
40
+ return {
41
+ role: "custom" as const,
42
+ customType: GOAL_CONTRACT_MESSAGE_TYPE,
43
+ content: INACTIVE_GOAL_CONTRACT_CONTENT,
44
+ display: false,
45
+ details: { version: GOAL_CONTRACT_VERSION, state: "inactive" },
20
46
  timestamp: 0,
21
47
  };
22
48
  }
23
49
 
24
50
  export function reconcileGoalContextContract(messages: unknown[], goal: GoalPromptContext) {
51
+ return reconcileContract(messages, createGoalContextContract(goal));
52
+ }
53
+
54
+ export function reconcileInactiveGoalContextContract(messages: unknown[]) {
55
+ return reconcileContract(messages, createInactiveGoalContextContract());
56
+ }
57
+
58
+ export function hasGoalContextContract(entries: unknown[], goal: GoalPromptContext) {
59
+ return latestGoalContractContent(entries) === createGoalContextContract(goal).content;
60
+ }
61
+
62
+ export function hasInactiveGoalContextContract(entries: unknown[]) {
63
+ return latestGoalContractContent(entries) === INACTIVE_GOAL_CONTRACT_CONTENT;
64
+ }
65
+
66
+ export function hasGoalContextContractHistory(entries: unknown[]) {
67
+ return entries.some(isGoalContextContract);
68
+ }
69
+
70
+ export function isGoalContextContract(message: unknown) {
71
+ return unwrapMessage(message).customType === GOAL_CONTRACT_MESSAGE_TYPE;
72
+ }
73
+
74
+ function reconcileContract(
75
+ messages: unknown[],
76
+ expected: {
77
+ role: "custom";
78
+ customType: string;
79
+ content: string;
80
+ display: boolean;
81
+ details: object;
82
+ timestamp: number;
83
+ },
84
+ ) {
85
+ if (latestGoalContractContent(messages) === expected.content) return messages;
25
86
  const summaryBoundary = leadingSummaryBoundary(messages);
26
- const expected = createGoalContextContract(goal);
27
- const contractIndexes = messages.flatMap((message, index) =>
28
- unwrapMessage(message).customType === GOAL_CONTRACT_MESSAGE_TYPE ? [index] : [],
29
- );
30
- if (
31
- contractIndexes.length === 1 &&
32
- contractIndexes[0] === summaryBoundary &&
33
- unwrapMessage(messages[summaryBoundary]).content === expected.content
34
- ) {
35
- return messages;
87
+ if (!hasGoalContextContractHistory(messages) && summaryBoundary > 0) {
88
+ return [...messages.slice(0, summaryBoundary), expected, ...messages.slice(summaryBoundary)];
36
89
  }
90
+ return [...messages, expected];
91
+ }
37
92
 
38
- const withoutContracts = messages.filter(
39
- (message) => unwrapMessage(message).customType !== GOAL_CONTRACT_MESSAGE_TYPE,
40
- );
41
- const insertionIndex = leadingSummaryBoundary(withoutContracts);
42
- return [
43
- ...withoutContracts.slice(0, insertionIndex),
44
- expected,
45
- ...withoutContracts.slice(insertionIndex),
46
- ];
93
+ function latestGoalContractContent(messages: readonly unknown[]) {
94
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
95
+ const message = messages[index];
96
+ if (isGoalContextContract(message)) return unwrapMessage(message).content;
97
+ }
98
+ return undefined;
47
99
  }
48
100
 
49
101
  function leadingSummaryBoundary(messages: readonly unknown[]) {
@@ -57,6 +109,7 @@ function leadingSummaryBoundary(messages: readonly unknown[]) {
57
109
  }
58
110
 
59
111
  function unwrapMessage(message: unknown): ContractMessage {
60
- const entry = message as { message?: unknown } | undefined;
112
+ const entry = message as ContractSessionEntry | undefined;
113
+ if (entry?.type === "custom_message") return entry;
61
114
  return (entry?.message ?? message ?? {}) as ContractMessage;
62
115
  }
package/src/lifecycle.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { currentTokenTotal } from "./accounting.js";
3
3
  import { notifyTerminal } from "./errors.js";
4
- import { reconcileGoalContextContract } from "./goal-contract.js";
4
+ import {
5
+ GOAL_CONTRACT_MESSAGE_TYPE,
6
+ isGoalContextContract,
7
+ reconcileGoalContextContract,
8
+ reconcileInactiveGoalContextContract,
9
+ } from "./goal-contract.js";
5
10
  import { type ActiveGoal, loadGoalStateFromSession } from "./persistence.js";
6
11
  import type { GoalRunController } from "./run-protocol.js";
7
12
  import {
@@ -9,7 +14,6 @@ import {
9
14
  abortCurrentTurn,
10
15
  blocksStaleGoalToolCalls,
11
16
  findFinalAssistantMessage,
12
- formatError,
13
17
  type GoalRuntime,
14
18
  incrementGoal,
15
19
  isGoalContextOverflow,
@@ -54,7 +58,6 @@ export function registerGoalLifecycle(
54
58
  runtime.legacyQueueState = undefined;
55
59
  runtime.legacyExperimentalGoalsSetting = false;
56
60
  runtime.clearTerminalDetails();
57
- const previousToolVisibility = runtime.settings.toolVisibility;
58
61
  const settingsResult = readGoalSettings(options.settingsPath);
59
62
  const loaded = loadGoalStateFromSession(ctx);
60
63
  runtime.settings =
@@ -81,6 +84,7 @@ export function registerGoalLifecycle(
81
84
  if (!runtime.acquireWorkflow()) {
82
85
  runtime.activeGoal = transitionGoal(loaded.goal, "paused");
83
86
  runtime.persistGoal(runtime.activeGoal);
87
+ runtime.ensureInactiveGoalContextContract(ctx);
84
88
  runtime.updateStatus(ctx, runtime.activeGoal);
85
89
  notifyTerminal(
86
90
  ctx.ui,
@@ -90,18 +94,6 @@ export function registerGoalLifecycle(
90
94
  return;
91
95
  }
92
96
  runtime.activeGoal = loaded.goal;
93
- try {
94
- runtime.toolPolicy.prepareSessionStart(
95
- runtime.settings.toolVisibility,
96
- previousToolVisibility,
97
- );
98
- } catch (error) {
99
- notifyTerminal(
100
- ctx.ui,
101
- `Could not restore always-visible goal tools: ${formatError(error)}`,
102
- "error",
103
- );
104
- }
105
97
  if (runtime.activeGoal.safetyResetPending) {
106
98
  // Resume/edit activation is persisted before its owned prompt starts. A
107
99
  // reload must commit that promised reset before enforcing the old limits.
@@ -112,49 +104,27 @@ export function registerGoalLifecycle(
112
104
  if (runtime.enforceAutomaticTurnLimit(ctx, false) || runtime.enforceNoProgressLimit(ctx)) {
113
105
  return;
114
106
  }
115
- // On lazy restore, an earlier restrictive session-start policy still wins:
116
- // reconciliation unlocks ownership without widening the active tool set.
117
- runtime.toolPolicy.reconcileRestoredState(runtime.settings.toolVisibility, true);
118
- if (!runtime.toolPolicy.toolsAvailable()) {
107
+ if (!runtime.goalToolsAvailable()) {
119
108
  runtime.pauseGoalForUnavailableTools(ctx, false);
120
109
  return;
121
110
  }
122
111
  runtime.persistGoal(runtime.activeGoal);
123
112
  if (!runtime.ownsWorkflow(runtime.activeGoal)) return;
113
+ const restoredGoalId = runtime.activeGoal.id;
114
+ runtime.ensureGoalContextContract(ctx, runtime.activeGoal);
115
+ if (
116
+ runtime.activeGoal?.id !== restoredGoalId ||
117
+ runtime.activeGoal.status !== "active" ||
118
+ !runtime.ownsWorkflow(runtime.activeGoal)
119
+ ) {
120
+ return;
121
+ }
124
122
  runtime.updateStatus(ctx, runtime.activeGoal);
125
123
  runtime.restoreGoalWaitTimer(ctx);
126
124
  return;
127
125
  }
128
126
 
129
127
  runtime.activeGoal = loaded.goal;
130
- let appliedInactivePolicy = false;
131
- let inactivePolicyFailed = false;
132
- try {
133
- appliedInactivePolicy = runtime.withTemporaryWorkflowAccess(() => {
134
- runtime.toolPolicy.prepareSessionStart(
135
- runtime.settings.toolVisibility,
136
- previousToolVisibility,
137
- );
138
- runtime.toolPolicy.reconcileRestoredState(
139
- runtime.settings.toolVisibility,
140
- runtime.activeGoal !== undefined && runtime.legacyQueueState === undefined,
141
- );
142
- });
143
- } catch (error) {
144
- inactivePolicyFailed = true;
145
- notifyTerminal(
146
- ctx.ui,
147
- `Could not restore always-visible goal tools: ${formatError(error)}`,
148
- "error",
149
- );
150
- }
151
- if (!appliedInactivePolicy && !inactivePolicyFailed) {
152
- notifyTerminal(
153
- ctx.ui,
154
- "Goal tool visibility was deferred because another workflow is active in this session.",
155
- "warning",
156
- );
157
- }
158
128
  if (runtime.legacyQueueState) {
159
129
  ctx.ui.setStatus(STATUS_KEY, undefined);
160
130
  notifyTerminal(ctx.ui, REMOVED_PERSISTED_QUEUE_WARNING, "warning");
@@ -162,8 +132,10 @@ export function registerGoalLifecycle(
162
132
  }
163
133
  if (runtime.activeGoal) {
164
134
  runtime.persistGoal(runtime.activeGoal);
135
+ runtime.ensureInactiveGoalContextContract(ctx);
165
136
  runtime.updateStatus(ctx, runtime.activeGoal);
166
137
  } else {
138
+ runtime.ensureInactiveGoalContextContract(ctx);
167
139
  ctx.ui.setStatus(STATUS_KEY, undefined);
168
140
  }
169
141
  });
@@ -226,8 +198,17 @@ export function registerGoalLifecycle(
226
198
  runtime.persistGoal(runtime.activeGoal);
227
199
  runtime.updateStatus(ctx, runtime.activeGoal);
228
200
  }
229
- if (!usageRecorded) return;
230
201
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
202
+ const compactedGoalId = runtime.activeGoal.id;
203
+ runtime.ensureGoalContextContract(ctx, runtime.activeGoal);
204
+ if (
205
+ runtime.activeGoal?.id !== compactedGoalId ||
206
+ runtime.activeGoal.status !== "active" ||
207
+ !runtime.ownsWorkflow(runtime.activeGoal)
208
+ ) {
209
+ return;
210
+ }
211
+ if (!usageRecorded) return;
231
212
 
232
213
  const wasPiRetry = runtime.isPiOwnedCompactionRetry(event, runtime.activeGoal.id);
233
214
  if (wasPiRetry) return;
@@ -287,6 +268,7 @@ export function registerGoalLifecycle(
287
268
  return;
288
269
  }
289
270
  if (message.role === "custom") {
271
+ if (Reflect.get(message, "customType") === GOAL_CONTRACT_MESSAGE_TYPE) return;
290
272
  if (runtime.isActiveBudgetWrapUpMessage(message)) return;
291
273
  if (runtime.activeGoal?.waiting) runtime.clearGoalWait(ctx, runtime.activeGoal.id);
292
274
  if (runtime.guardAbortGoalId === runtime.activeGoal?.id) {
@@ -340,10 +322,14 @@ export function registerGoalLifecycle(
340
322
  const keptMessages = event.messages.filter((message) =>
341
323
  runtime.keepBudgetWrapUpMessage(message),
342
324
  );
325
+ const hasGoalContractHistory =
326
+ keptMessages.some(isGoalContextContract) || runtime.hasGoalContextContractHistory(ctx);
343
327
  const messages =
344
328
  runtime.activeGoal?.status === "active" && runtime.ownsWorkflow(runtime.activeGoal)
345
329
  ? reconcileGoalContextContract(keptMessages, runtime.activeGoal)
346
- : keptMessages;
330
+ : hasGoalContractHistory
331
+ ? reconcileInactiveGoalContextContract(keptMessages)
332
+ : keptMessages;
347
333
  if (
348
334
  runtime.activeGoal?.status === "paused" &&
349
335
  runtime.guardAbortGoalId === runtime.activeGoal.id
@@ -406,7 +392,7 @@ export function registerGoalLifecycle(
406
392
  runtime.persistGoal(runtime.activeGoal);
407
393
  runtime.updateStatus(ctx, runtime.activeGoal);
408
394
  if (runtime.limitActiveGoalForBudget(ctx, true)) return;
409
- if (!runtime.toolPolicy.toolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
395
+ if (!runtime.goalToolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
410
396
  });
411
397
 
412
398
  pi.on("before_agent_start", (event, ctx) => {
@@ -450,29 +436,30 @@ export function registerGoalLifecycle(
450
436
  : "manual";
451
437
  if (activeBudgetWrapUp && runtime.activeGoal) {
452
438
  runtime.beginAgentRun(runtime.activeGoal.id, "manual");
453
- return;
439
+ return goalContractBoundaryResult(ctx);
454
440
  }
455
441
  if (ownedPromptGoalId && ownedPromptGoalId !== runtime.activeGoal?.id) {
456
442
  runtime.beginAgentRun(ownedPromptGoalId, runOrigin);
457
- if (runtime.activeGoal?.status === "active" && !runtime.toolPolicy.toolsAvailable()) {
443
+ if (runtime.activeGoal?.status === "active" && !runtime.goalToolsAvailable()) {
458
444
  runtime.pauseGoalForUnavailableTools(ctx, false);
459
445
  }
460
446
  abortCurrentTurn(ctx);
461
447
  return;
462
448
  }
463
449
  if (runtime.activeGoal?.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
464
- return;
450
+ return goalContractBoundaryResult(ctx);
465
451
  }
466
452
  runtime.beginAgentRun(runtime.activeGoal.id, runOrigin);
467
- if (!runtime.toolPolicy.toolsAvailable()) {
453
+ if (!runtime.goalToolsAvailable()) {
468
454
  runtime.pauseGoalForUnavailableTools(ctx, ownedPromptGoalId !== undefined);
469
- return;
455
+ return goalContractBoundaryResult(ctx);
470
456
  }
471
457
  if (goalPrompt?.resetSafetyEpoch && goalPromptGoalId === runtime.activeGoal.id) {
472
458
  runtime.activeGoal = resetGoalSafetyEpoch(runtime.activeGoal);
473
459
  runtime.persistGoal(runtime.activeGoal);
474
460
  runtime.updateStatus(ctx, runtime.activeGoal);
475
461
  }
462
+ return goalContractBoundaryResult(ctx, runtime.activeGoal);
476
463
  });
477
464
 
478
465
  pi.on("agent_start", (_event, _ctx) => {
@@ -535,7 +522,7 @@ export function registerGoalLifecycle(
535
522
  if (isRetryableGoalInterruption(finalAssistant)) {
536
523
  if (run.origin === "automatic" && runtime.enforceAutomaticTurnLimit(ctx, true)) return;
537
524
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
538
- if (!runtime.toolPolicy.toolsAvailable()) {
525
+ if (!runtime.goalToolsAvailable()) {
539
526
  runtime.pauseGoalForUnavailableTools(ctx);
540
527
  return;
541
528
  }
@@ -563,7 +550,7 @@ export function registerGoalLifecycle(
563
550
  runtime.clearGoalRecoveryForGoal(goalId);
564
551
 
565
552
  if (runtime.limitActiveGoalForBudget(ctx, false)) return;
566
- if (!runtime.toolPolicy.toolsAvailable()) {
553
+ if (!runtime.goalToolsAvailable()) {
567
554
  runtime.pauseGoalForUnavailableTools(ctx);
568
555
  return;
569
556
  }
@@ -600,6 +587,11 @@ export function registerGoalLifecycle(
600
587
  runtime.clearSettledSafetyTracking();
601
588
  });
602
589
 
590
+ function goalContractBoundaryResult(ctx: StatusContext, goal?: ActiveGoal) {
591
+ const message = runtime.goalContextContractForPrompt(ctx, goal);
592
+ return message ? { message } : undefined;
593
+ }
594
+
603
595
  function beginNonGoalFollowUp(ctx: StatusContext, resetSafetyEpoch: boolean) {
604
596
  runtime.clearGoalRecovery();
605
597
  runtime.clearStaleGoalToolCallBlock();