@narumitw/pi-goal 0.54.4 → 0.54.6

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.
Files changed (39) hide show
  1. package/README.md +41 -166
  2. package/dist/chunks/{chunk-UQRRW4CY.js → chunk-6T3MHA45.js} +7 -6
  3. package/dist/chunks/chunk-6T3MHA45.js.map +7 -0
  4. package/dist/chunks/{chunk-QWIUWKRW.js → chunk-WLIH47XO.js} +57 -77
  5. package/dist/chunks/chunk-WLIH47XO.js.map +7 -0
  6. package/dist/chunks/{menu-WEFDREGC.js → menu-RGCRCQJK.js} +7 -22
  7. package/dist/chunks/menu-RGCRCQJK.js.map +7 -0
  8. package/dist/chunks/{settings-ui-MVYTTBHW.js → settings-ui-BAWNTINU.js} +6 -18
  9. package/dist/chunks/settings-ui-BAWNTINU.js.map +7 -0
  10. package/dist/index.ts +92 -126
  11. package/dist/index.ts.map +2 -2
  12. package/docs/managing-goals.md +47 -0
  13. package/docs/settings.md +91 -0
  14. package/package.json +55 -55
  15. package/src/accounting.ts +62 -66
  16. package/src/command-registration.ts +104 -102
  17. package/src/command.ts +101 -112
  18. package/src/commands.ts +465 -501
  19. package/src/errors.ts +127 -122
  20. package/src/goal-contract.ts +64 -64
  21. package/src/goal.ts +25 -25
  22. package/src/lifecycle.ts +615 -628
  23. package/src/markers.ts +6 -6
  24. package/src/menu.ts +565 -591
  25. package/src/persistence.ts +177 -192
  26. package/src/prompts.ts +53 -67
  27. package/src/run-protocol.ts +299 -325
  28. package/src/runtime.ts +1422 -1495
  29. package/src/safety.ts +51 -51
  30. package/src/settings-ui.ts +366 -393
  31. package/src/settings.ts +134 -147
  32. package/src/tool-policy.ts +6 -6
  33. package/src/tools.ts +360 -371
  34. package/src/wait.ts +47 -51
  35. package/src/workflow-mutex.ts +68 -68
  36. package/dist/chunks/chunk-QWIUWKRW.js.map +0 -7
  37. package/dist/chunks/chunk-UQRRW4CY.js.map +0 -7
  38. package/dist/chunks/menu-WEFDREGC.js.map +0 -7
  39. package/dist/chunks/settings-ui-MVYTTBHW.js.map +0 -7
package/src/commands.ts CHANGED
@@ -3,529 +3,493 @@ import { validateObjective } from "./command.js";
3
3
  import { notifyTerminal, safeGoalMenuText } from "./errors.js";
4
4
  import type { ActiveGoal } from "./persistence.js";
5
5
  import {
6
- buildGoalPrompt,
7
- buildObjectiveUpdatedPrompt,
8
- buildResumePrompt,
9
- buildWaitingResumePrompt,
6
+ buildGoalPrompt,
7
+ buildObjectiveUpdatedPrompt,
8
+ buildResumePrompt,
9
+ buildWaitingResumePrompt,
10
10
  } from "./prompts.js";
11
11
  import {
12
- blocksStaleGoalToolCalls,
13
- createGoal,
14
- editedGoalStatus,
15
- formatBudget,
16
- formatError,
17
- type GoalRuntime,
18
- goalSummary,
19
- isResumableGoalStatus,
20
- nextGoalInstance,
21
- queueGoalSafetyReset,
22
- STATUS_KEY,
23
- type StatusContext,
24
- stoppedStatusLabel,
25
- transitionGoal,
12
+ blocksStaleGoalToolCalls,
13
+ createGoal,
14
+ editedGoalStatus,
15
+ formatBudget,
16
+ formatError,
17
+ type GoalRuntime,
18
+ goalSummary,
19
+ isResumableGoalStatus,
20
+ nextGoalInstance,
21
+ queueGoalSafetyReset,
22
+ STATUS_KEY,
23
+ type StatusContext,
24
+ stoppedStatusLabel,
25
+ transitionGoal,
26
26
  } from "./runtime.js";
27
27
 
28
28
  // User-command mutations are kept separate from Pi event wiring. Every controller
29
29
  // receives exactly one per-factory GoalRuntime, preserving session isolation.
30
30
  export class GoalCommandController {
31
- private readonly runtime: GoalRuntime;
31
+ private readonly runtime: GoalRuntime;
32
32
 
33
- constructor(runtime: GoalRuntime) {
34
- this.runtime = runtime;
35
- }
33
+ constructor(runtime: GoalRuntime) {
34
+ this.runtime = runtime;
35
+ }
36
36
 
37
- async startGoal(
38
- objective: string,
39
- tokenBudget: number | undefined,
40
- ctx: StatusContext,
41
- onActivated?: (goal: ActiveGoal) => void,
42
- isActivationCurrent?: (goal: ActiveGoal) => boolean,
43
- isRequestCurrent?: () => boolean,
44
- ) {
45
- if (isRequestCurrent && !isRequestCurrent()) return;
46
- const validationError = validateObjective(objective);
47
- if (validationError) {
48
- notifyTerminal(ctx.ui, validationError, "warning");
49
- return;
50
- }
37
+ async startGoal(
38
+ objective: string,
39
+ tokenBudget: number | undefined,
40
+ ctx: StatusContext,
41
+ onActivated?: (goal: ActiveGoal) => void,
42
+ isActivationCurrent?: (goal: ActiveGoal) => boolean,
43
+ isRequestCurrent?: () => boolean,
44
+ ) {
45
+ if (isRequestCurrent && !isRequestCurrent()) return;
46
+ const validationError = validateObjective(objective);
47
+ if (validationError) {
48
+ notifyTerminal(ctx.ui, validationError, "warning");
49
+ return;
50
+ }
51
51
 
52
- const existingGoal =
53
- this.runtime.activeGoal?.status !== "complete" ? this.runtime.activeGoal : undefined;
54
- const legacyQueueBeforeActivation = existingGoal
55
- ? undefined
56
- : this.runtime.legacyQueueState
57
- ? structuredClone(this.runtime.legacyQueueState)
58
- : undefined;
59
- if (existingGoal) {
60
- const shouldReplace = await ctx.ui.confirm(
61
- "Replace goal?",
62
- `Current goal: ${safeGoalMenuText(existingGoal.text, 4_000)}\n\nNew goal: ${safeGoalMenuText(objective, 4_000)}`,
63
- );
64
- if (!shouldReplace) {
65
- notifyTerminal(ctx.ui, `Goal kept: ${existingGoal.text}`, "info");
66
- return;
67
- }
68
- if (isRequestCurrent && !isRequestCurrent()) return;
69
- if (this.runtime.activeGoal?.id !== existingGoal.id) {
70
- notifyTerminal(
71
- ctx.ui,
72
- "The active goal changed while confirmation was open. Try again.",
73
- "warning",
74
- );
75
- return;
76
- }
77
- }
52
+ const existingGoal = this.runtime.activeGoal?.status !== "complete" ? this.runtime.activeGoal : undefined;
53
+ const legacyQueueBeforeActivation = existingGoal
54
+ ? undefined
55
+ : this.runtime.legacyQueueState
56
+ ? structuredClone(this.runtime.legacyQueueState)
57
+ : undefined;
58
+ if (existingGoal) {
59
+ const shouldReplace = await ctx.ui.confirm(
60
+ "Replace goal?",
61
+ `Current goal: ${safeGoalMenuText(existingGoal.text, 4_000)}\n\nNew goal: ${safeGoalMenuText(objective, 4_000)}`,
62
+ );
63
+ if (!shouldReplace) {
64
+ notifyTerminal(ctx.ui, `Goal kept: ${existingGoal.text}`, "info");
65
+ return;
66
+ }
67
+ if (isRequestCurrent && !isRequestCurrent()) return;
68
+ if (this.runtime.activeGoal?.id !== existingGoal.id) {
69
+ notifyTerminal(ctx.ui, "The active goal changed while confirmation was open. Try again.", "warning");
70
+ return;
71
+ }
72
+ }
78
73
 
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
- if (isRequestCurrent && !isRequestCurrent()) return;
82
- const retainedOwner = this.runtime.ownsWorkflow(existingGoal);
83
- if (!this.runtime.acquireWorkflow(ctx.sessionManager)) return this.reportWorkflowBusy(ctx);
84
- const acquiredForRequest = !retainedOwner;
85
- try {
86
- this.runtime.assertGoalToolsAvailable();
87
- } catch (error) {
88
- notifyTerminal(ctx.ui, `Cannot start /goal: ${formatError(error)}`, "error");
89
- if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
90
- else if (acquiredForRequest) this.runtime.releaseWorkflow();
91
- return;
92
- }
74
+ // Tool registration keeps the Goal schema stable. A missing tool means another
75
+ // policy or allowlist intentionally removed it, so activation must not widen it.
76
+ if (isRequestCurrent && !isRequestCurrent()) return;
77
+ const retainedOwner = this.runtime.ownsWorkflow(existingGoal);
78
+ if (!this.runtime.acquireWorkflow(ctx.sessionManager)) return this.reportWorkflowBusy(ctx);
79
+ const acquiredForRequest = !retainedOwner;
80
+ try {
81
+ this.runtime.assertGoalToolsAvailable();
82
+ } catch (error) {
83
+ notifyTerminal(ctx.ui, `Cannot start /goal: ${formatError(error)}`, "error");
84
+ if (existingGoal?.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
85
+ else if (acquiredForRequest) this.runtime.releaseWorkflow();
86
+ return;
87
+ }
93
88
 
94
- this.runtime.clearGoalWaitTimer();
95
- this.runtime.cancelContinuationWork();
96
- this.runtime.clearGoalRecovery();
97
- this.runtime.clearBudgetWrapUp();
98
- this.runtime.clearStaleGoalToolCallBlock();
99
- if (!legacyQueueBeforeActivation) this.runtime.legacyQueueState = undefined;
100
- this.runtime.activeGoal = createGoal(objective, tokenBudget, currentTokenTotal(ctx));
101
- const startedGoal = this.runtime.activeGoal;
102
- onActivated?.(startedGoal);
103
- if (!legacyQueueBeforeActivation) this.runtime.persistGoal(startedGoal);
104
- if (
105
- this.runtime.activeGoal?.id !== startedGoal.id ||
106
- !this.runtime.ownsWorkflow(this.runtime.activeGoal)
107
- ) {
108
- return;
109
- }
110
- this.runtime.updateStatus(ctx, startedGoal);
111
- const sent = await this.runtime.sendOwnedGoalPrompt(
112
- ctx,
113
- startedGoal.id,
114
- buildGoalPrompt(startedGoal),
115
- true,
116
- () => (isRequestCurrent?.() ?? true) && (isActivationCurrent?.(startedGoal) ?? true),
117
- );
118
- if (
119
- sent &&
120
- legacyQueueBeforeActivation &&
121
- this.runtime.activeGoal?.id === startedGoal.id &&
122
- this.runtime.activeGoal.status === "active"
123
- ) {
124
- this.runtime.legacyQueueState = undefined;
125
- this.runtime.persistGoal(startedGoal);
126
- }
127
- if (isActivationCurrent && !isActivationCurrent(startedGoal)) return;
128
- if (!sent) {
129
- let rolledBackStartedGoal = false;
130
- if (this.runtime.activeGoal?.id === startedGoal.id) {
131
- rolledBackStartedGoal = true;
132
- if (existingGoal) {
133
- this.runtime.recordGoalUsage(existingGoal, ctx);
134
- if (existingGoal.status === "active" && existingGoal.waiting) {
135
- this.runtime.activeGoal = existingGoal;
136
- this.runtime.clearStaleGoalToolCallBlock();
137
- this.runtime.persistGoal(existingGoal);
138
- this.runtime.updateStatus(ctx, existingGoal);
139
- this.runtime.restoreGoalWaitTimer(ctx);
140
- } else if (existingGoal.status === "active") {
141
- this.runtime.activeGoal = existingGoal;
142
- this.runtime.clearStaleGoalToolCallBlock();
143
- this.runtime.persistGoal(existingGoal);
144
- if (this.runtime.activeGoal?.id === existingGoal.id) {
145
- this.runtime.updateStatus(ctx, existingGoal);
146
- }
147
- } else {
148
- this.runtime.activeGoal = existingGoal;
149
- if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
150
- this.runtime.blockStaleGoalToolCalls();
151
- } else {
152
- this.runtime.clearStaleGoalToolCallBlock();
153
- }
154
- this.runtime.persistGoal(this.runtime.activeGoal);
155
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
156
- }
157
- } else if (legacyQueueBeforeActivation) {
158
- this.runtime.activeGoal = undefined;
159
- this.runtime.legacyQueueState = legacyQueueBeforeActivation;
160
- this.runtime.cancelContinuationWork();
161
- this.runtime.clearGoalRecovery();
162
- this.runtime.clearBudgetWrapUp();
163
- this.runtime.clearStaleGoalToolCallBlock();
164
- ctx.ui.setStatus(STATUS_KEY, undefined);
165
- } else {
166
- this.runtime.clearActiveGoal(ctx, "goal activation rolled back", false);
167
- }
168
- }
169
- if (rolledBackStartedGoal) {
170
- if (acquiredForRequest && !this.runtime.ownsWorkflow(existingGoal)) {
171
- this.runtime.releaseWorkflow();
172
- }
173
- }
174
- return;
175
- }
176
- if (
177
- this.runtime.activeGoal?.id !== startedGoal.id ||
178
- !this.runtime.ownsWorkflow(this.runtime.activeGoal)
179
- ) {
180
- return;
181
- }
182
- const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
183
- notifyTerminal(
184
- ctx.ui,
185
- `${existingGoal ? "Goal replaced" : "Goal started"}: ${objective}. ${
186
- startedGoal.tokenBudget === undefined
187
- ? ""
188
- : `Token budget: ${formatTokenCount(startedGoal.tokenBudget)} cumulative; the final model call may exceed it. `
189
- }${
190
- automaticLimit === null
191
- ? "Automatic work is Unlimited; tool loops may consume substantial tokens and provider cost. Open /goal to monitor."
192
- : `Automatic work pauses after ${automaticLimit} responses; open /goal to monitor progress.`
193
- }`,
194
- automaticLimit === null ? "warning" : "info",
195
- );
196
- }
89
+ this.runtime.clearGoalWaitTimer();
90
+ this.runtime.cancelContinuationWork();
91
+ this.runtime.clearGoalRecovery();
92
+ this.runtime.clearBudgetWrapUp();
93
+ this.runtime.clearStaleGoalToolCallBlock();
94
+ if (!legacyQueueBeforeActivation) this.runtime.legacyQueueState = undefined;
95
+ this.runtime.activeGoal = createGoal(objective, tokenBudget, currentTokenTotal(ctx));
96
+ const startedGoal = this.runtime.activeGoal;
97
+ onActivated?.(startedGoal);
98
+ if (!legacyQueueBeforeActivation) this.runtime.persistGoal(startedGoal);
99
+ if (this.runtime.activeGoal?.id !== startedGoal.id || !this.runtime.ownsWorkflow(this.runtime.activeGoal)) {
100
+ return;
101
+ }
102
+ this.runtime.updateStatus(ctx, startedGoal);
103
+ const sent = await this.runtime.sendOwnedGoalPrompt(
104
+ ctx,
105
+ startedGoal.id,
106
+ buildGoalPrompt(startedGoal),
107
+ true,
108
+ () => (isRequestCurrent?.() ?? true) && (isActivationCurrent?.(startedGoal) ?? true),
109
+ );
110
+ if (
111
+ sent &&
112
+ legacyQueueBeforeActivation &&
113
+ this.runtime.activeGoal?.id === startedGoal.id &&
114
+ this.runtime.activeGoal.status === "active"
115
+ ) {
116
+ this.runtime.legacyQueueState = undefined;
117
+ this.runtime.persistGoal(startedGoal);
118
+ }
119
+ if (isActivationCurrent && !isActivationCurrent(startedGoal)) return;
120
+ if (!sent) {
121
+ let rolledBackStartedGoal = false;
122
+ if (this.runtime.activeGoal?.id === startedGoal.id) {
123
+ rolledBackStartedGoal = true;
124
+ if (existingGoal) {
125
+ this.runtime.recordGoalUsage(existingGoal, ctx);
126
+ if (existingGoal.status === "active" && existingGoal.waiting) {
127
+ this.runtime.activeGoal = existingGoal;
128
+ this.runtime.clearStaleGoalToolCallBlock();
129
+ this.runtime.persistGoal(existingGoal);
130
+ this.runtime.updateStatus(ctx, existingGoal);
131
+ this.runtime.restoreGoalWaitTimer(ctx);
132
+ } else if (existingGoal.status === "active") {
133
+ this.runtime.activeGoal = existingGoal;
134
+ this.runtime.clearStaleGoalToolCallBlock();
135
+ this.runtime.persistGoal(existingGoal);
136
+ if (this.runtime.activeGoal?.id === existingGoal.id) {
137
+ this.runtime.updateStatus(ctx, existingGoal);
138
+ }
139
+ } else {
140
+ this.runtime.activeGoal = existingGoal;
141
+ if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
142
+ this.runtime.blockStaleGoalToolCalls();
143
+ } else {
144
+ this.runtime.clearStaleGoalToolCallBlock();
145
+ }
146
+ this.runtime.persistGoal(this.runtime.activeGoal);
147
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
148
+ }
149
+ } else if (legacyQueueBeforeActivation) {
150
+ this.runtime.activeGoal = undefined;
151
+ this.runtime.legacyQueueState = legacyQueueBeforeActivation;
152
+ this.runtime.cancelContinuationWork();
153
+ this.runtime.clearGoalRecovery();
154
+ this.runtime.clearBudgetWrapUp();
155
+ this.runtime.clearStaleGoalToolCallBlock();
156
+ ctx.ui.setStatus(STATUS_KEY, undefined);
157
+ } else {
158
+ this.runtime.clearActiveGoal(ctx, "goal activation rolled back", false);
159
+ }
160
+ }
161
+ if (rolledBackStartedGoal) {
162
+ if (acquiredForRequest && !this.runtime.ownsWorkflow(existingGoal)) {
163
+ this.runtime.releaseWorkflow();
164
+ }
165
+ }
166
+ return;
167
+ }
168
+ if (this.runtime.activeGoal?.id !== startedGoal.id || !this.runtime.ownsWorkflow(this.runtime.activeGoal)) {
169
+ return;
170
+ }
171
+ const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
172
+ notifyTerminal(
173
+ ctx.ui,
174
+ `${existingGoal ? "Goal replaced" : "Goal started"}: ${objective}. ${
175
+ startedGoal.tokenBudget === undefined
176
+ ? ""
177
+ : `Token budget: ${formatTokenCount(startedGoal.tokenBudget)} cumulative; the final model call may exceed it. `
178
+ }${
179
+ automaticLimit === null
180
+ ? "Automatic work is Unlimited; tool loops may consume substantial tokens and provider cost. Open /goal to monitor."
181
+ : `Automatic work pauses after ${automaticLimit} responses; open /goal to monitor progress.`
182
+ }`,
183
+ automaticLimit === null ? "warning" : "info",
184
+ );
185
+ }
197
186
 
198
- pauseGoal(ctx: StatusContext) {
199
- if (!this.runtime.activeGoal) {
200
- notifyTerminal(ctx.ui, "No active goal.", "info");
201
- return;
202
- }
203
- if (this.runtime.activeGoal.status !== "active") {
204
- notifyTerminal(
205
- ctx.ui,
206
- `Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`,
207
- "warning",
208
- );
209
- return;
210
- }
211
- const stoppedGoal = this.runtime.stopActiveGoal(ctx, {
212
- kind: "explicit_pause",
213
- expectedGoalId: this.runtime.activeGoal.id,
214
- });
215
- if (stoppedGoal) notifyTerminal(ctx.ui, `Goal paused: ${stoppedGoal.text}`, "info");
216
- }
187
+ pauseGoal(ctx: StatusContext) {
188
+ if (!this.runtime.activeGoal) {
189
+ notifyTerminal(ctx.ui, "No active goal.", "info");
190
+ return;
191
+ }
192
+ if (this.runtime.activeGoal.status !== "active") {
193
+ notifyTerminal(ctx.ui, `Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`, "warning");
194
+ return;
195
+ }
196
+ const stoppedGoal = this.runtime.stopActiveGoal(ctx, {
197
+ kind: "explicit_pause",
198
+ expectedGoalId: this.runtime.activeGoal.id,
199
+ });
200
+ if (stoppedGoal) notifyTerminal(ctx.ui, `Goal paused: ${stoppedGoal.text}`, "info");
201
+ }
217
202
 
218
- async resumeGoal(ctx: StatusContext) {
219
- if (!this.runtime.activeGoal) {
220
- notifyTerminal(ctx.ui, "No active goal.", "info");
221
- return;
222
- }
223
- if (this.runtime.activeGoal.status === "active" && this.runtime.activeGoal.waiting) {
224
- await this.resumeWaitingGoal(ctx);
225
- return;
226
- }
227
- if (!isResumableGoalStatus(this.runtime.activeGoal.status)) {
228
- notifyTerminal(
229
- ctx.ui,
230
- `Goal is ${this.runtime.activeGoal.status}; only paused, blocked, usage-limited, or budget-limited goals can be resumed.`,
231
- "warning",
232
- );
233
- return;
234
- }
235
- if (
236
- this.runtime.activeGoal.tokenBudget !== undefined &&
237
- this.runtime.activeGoal.tokensUsed >= this.runtime.activeGoal.tokenBudget
238
- ) {
239
- notifyTerminal(
240
- ctx.ui,
241
- `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,
242
- "warning",
243
- );
244
- return;
245
- }
246
- if (!this.runtime.acquireWorkflow(ctx.sessionManager)) {
247
- this.reportWorkflowBusy(ctx);
248
- return;
249
- }
250
- try {
251
- this.runtime.assertGoalToolsAvailable();
252
- } catch (error) {
253
- notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
254
- this.runtime.releaseWorkflow();
255
- return;
256
- }
257
- const stoppedGoal = this.runtime.activeGoal;
258
- const stoppedStatus = stoppedGoal.status;
259
- this.runtime.cancelContinuationWork();
260
- this.runtime.clearGoalRecovery();
261
- this.runtime.clearBudgetWrapUp();
262
- this.runtime.clearStaleGoalToolCallBlock();
263
- this.runtime.activeGoal = queueGoalSafetyReset(
264
- transitionGoal(nextGoalInstance(this.runtime.activeGoal), "active"),
265
- );
266
- this.runtime.persistGoal(this.runtime.activeGoal);
267
- if (this.runtime.activeGoal.status !== "active") {
268
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
269
- this.runtime.releaseWorkflow();
270
- notifyTerminal(
271
- ctx.ui,
272
- `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,
273
- "warning",
274
- );
275
- return;
276
- }
277
- if (!this.runtime.ownsWorkflow(this.runtime.activeGoal)) return;
278
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
279
- const resumedGoal = this.runtime.activeGoal;
280
- const sent = await this.runtime.sendOwnedGoalPrompt(
281
- ctx,
282
- resumedGoal.id,
283
- buildResumePrompt(resumedGoal, stoppedStatus),
284
- );
285
- if (!sent) {
286
- if (
287
- this.runtime.activeGoal?.id === resumedGoal.id &&
288
- this.runtime.activeGoal.status === "active"
289
- ) {
290
- this.runtime.activeGoal = stoppedGoal;
291
- this.runtime.persistGoal(this.runtime.activeGoal);
292
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
293
- if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
294
- this.runtime.blockStaleGoalToolCalls();
295
- }
296
- this.runtime.releaseWorkflow();
297
- }
298
- return;
299
- }
300
- if (!this.runtime.ownsWorkflow(resumedGoal)) return;
301
- const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
302
- notifyTerminal(
303
- ctx.ui,
304
- `Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}. ${
305
- automaticLimit === null
306
- ? "Automatic work remains Unlimited; goal progress and cumulative usage are preserved."
307
- : `The automatic-work counter will reset to 0 of ${automaticLimit} when the resumed prompt starts; goal progress and cumulative usage are preserved.`
308
- }`,
309
- automaticLimit === null ? "warning" : "info",
310
- );
311
- }
203
+ async resumeGoal(ctx: StatusContext) {
204
+ if (!this.runtime.activeGoal) {
205
+ notifyTerminal(ctx.ui, "No active goal.", "info");
206
+ return;
207
+ }
208
+ if (this.runtime.activeGoal.status === "active" && this.runtime.activeGoal.waiting) {
209
+ await this.resumeWaitingGoal(ctx);
210
+ return;
211
+ }
212
+ if (!isResumableGoalStatus(this.runtime.activeGoal.status)) {
213
+ notifyTerminal(
214
+ ctx.ui,
215
+ `Goal is ${this.runtime.activeGoal.status}; only paused, blocked, usage-limited, or budget-limited goals can be resumed.`,
216
+ "warning",
217
+ );
218
+ return;
219
+ }
220
+ if (
221
+ this.runtime.activeGoal.tokenBudget !== undefined &&
222
+ this.runtime.activeGoal.tokensUsed >= this.runtime.activeGoal.tokenBudget
223
+ ) {
224
+ notifyTerminal(ctx.ui, `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`, "warning");
225
+ return;
226
+ }
227
+ if (!this.runtime.acquireWorkflow(ctx.sessionManager)) {
228
+ this.reportWorkflowBusy(ctx);
229
+ return;
230
+ }
231
+ try {
232
+ this.runtime.assertGoalToolsAvailable();
233
+ } catch (error) {
234
+ notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
235
+ this.runtime.releaseWorkflow();
236
+ return;
237
+ }
238
+ const stoppedGoal = this.runtime.activeGoal;
239
+ const stoppedStatus = stoppedGoal.status;
240
+ this.runtime.cancelContinuationWork();
241
+ this.runtime.clearGoalRecovery();
242
+ this.runtime.clearBudgetWrapUp();
243
+ this.runtime.clearStaleGoalToolCallBlock();
244
+ this.runtime.activeGoal = queueGoalSafetyReset(transitionGoal(nextGoalInstance(this.runtime.activeGoal), "active"));
245
+ this.runtime.persistGoal(this.runtime.activeGoal);
246
+ if (this.runtime.activeGoal.status !== "active") {
247
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
248
+ this.runtime.releaseWorkflow();
249
+ notifyTerminal(ctx.ui, `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`, "warning");
250
+ return;
251
+ }
252
+ if (!this.runtime.ownsWorkflow(this.runtime.activeGoal)) return;
253
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
254
+ const resumedGoal = this.runtime.activeGoal;
255
+ const sent = await this.runtime.sendOwnedGoalPrompt(
256
+ ctx,
257
+ resumedGoal.id,
258
+ buildResumePrompt(resumedGoal, stoppedStatus),
259
+ );
260
+ if (!sent) {
261
+ if (this.runtime.activeGoal?.id === resumedGoal.id && this.runtime.activeGoal.status === "active") {
262
+ this.runtime.activeGoal = stoppedGoal;
263
+ this.runtime.persistGoal(this.runtime.activeGoal);
264
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
265
+ if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
266
+ this.runtime.blockStaleGoalToolCalls();
267
+ }
268
+ this.runtime.releaseWorkflow();
269
+ }
270
+ return;
271
+ }
272
+ if (!this.runtime.ownsWorkflow(resumedGoal)) return;
273
+ const automaticLimit = this.runtime.settings.continuationLimits.automaticTurns;
274
+ notifyTerminal(
275
+ ctx.ui,
276
+ `Goal resumed from ${stoppedStatusLabel(stoppedStatus)}: ${resumedGoal.text}. ${
277
+ automaticLimit === null
278
+ ? "Automatic work remains Unlimited; goal progress and cumulative usage are preserved."
279
+ : `The automatic-work counter will reset to 0 of ${automaticLimit} when the resumed prompt starts; goal progress and cumulative usage are preserved.`
280
+ }`,
281
+ automaticLimit === null ? "warning" : "info",
282
+ );
283
+ }
312
284
 
313
- private async resumeWaitingGoal(ctx: StatusContext) {
314
- const waitingGoal = this.runtime.activeGoal;
315
- const waiting = waitingGoal?.waiting;
316
- if (waitingGoal?.status !== "active" || !waiting) return;
317
- if (!this.runtime.acquireWorkflow(ctx.sessionManager)) {
318
- this.reportWorkflowBusy(ctx);
319
- return;
320
- }
321
- try {
322
- this.runtime.assertGoalToolsAvailable();
323
- } catch (error) {
324
- notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
325
- return;
326
- }
327
- if (!this.runtime.clearGoalWait(ctx, waitingGoal.id)) return;
328
- const resumedGoal = this.runtime.activeGoal;
329
- if (!resumedGoal || resumedGoal.id !== waitingGoal.id || resumedGoal.status !== "active")
330
- return;
331
- const sent = await this.runtime.sendOwnedGoalPrompt(
332
- ctx,
333
- resumedGoal.id,
334
- buildWaitingResumePrompt(resumedGoal, waiting.reason),
335
- false,
336
- );
337
- if (!sent) {
338
- if (this.runtime.activeGoal?.id === waitingGoal.id) {
339
- this.runtime.enterGoalWait(ctx, waitingGoal.id, waiting);
340
- }
341
- return;
342
- }
343
- if (!this.runtime.ownsWorkflow(resumedGoal)) return;
344
- notifyTerminal(ctx.ui, `Goal resumed from waiting: ${waitingGoal.text}`, "info");
345
- }
285
+ private async resumeWaitingGoal(ctx: StatusContext) {
286
+ const waitingGoal = this.runtime.activeGoal;
287
+ const waiting = waitingGoal?.waiting;
288
+ if (waitingGoal?.status !== "active" || !waiting) return;
289
+ if (!this.runtime.acquireWorkflow(ctx.sessionManager)) {
290
+ this.reportWorkflowBusy(ctx);
291
+ return;
292
+ }
293
+ try {
294
+ this.runtime.assertGoalToolsAvailable();
295
+ } catch (error) {
296
+ notifyTerminal(ctx.ui, `Cannot resume /goal: ${formatError(error)}`, "error");
297
+ return;
298
+ }
299
+ if (!this.runtime.clearGoalWait(ctx, waitingGoal.id)) return;
300
+ const resumedGoal = this.runtime.activeGoal;
301
+ if (!resumedGoal || resumedGoal.id !== waitingGoal.id || resumedGoal.status !== "active") return;
302
+ const sent = await this.runtime.sendOwnedGoalPrompt(
303
+ ctx,
304
+ resumedGoal.id,
305
+ buildWaitingResumePrompt(resumedGoal, waiting.reason),
306
+ false,
307
+ );
308
+ if (!sent) {
309
+ if (this.runtime.activeGoal?.id === waitingGoal.id) {
310
+ this.runtime.enterGoalWait(ctx, waitingGoal.id, waiting);
311
+ }
312
+ return;
313
+ }
314
+ if (!this.runtime.ownsWorkflow(resumedGoal)) return;
315
+ notifyTerminal(ctx.ui, `Goal resumed from waiting: ${waitingGoal.text}`, "info");
316
+ }
346
317
 
347
- clearGoal(ctx: StatusContext) {
348
- if (!this.runtime.activeGoal) {
349
- const hadLegacyQueue = this.runtime.legacyQueueState !== undefined;
350
- this.runtime.legacyQueueState = undefined;
351
- this.runtime.cancelContinuationWork();
352
- this.runtime.clearGoalRecovery();
353
- this.runtime.clearBudgetWrapUp();
354
- this.runtime.clearStaleGoalToolCallBlock();
355
- this.runtime.clearPersistedGoal(ctx.cwd);
356
- ctx.ui.setStatus(STATUS_KEY, undefined);
357
- notifyTerminal(
358
- ctx.ui,
359
- hadLegacyQueue ? "Removed legacy ordered goal queue state." : "No active goal.",
360
- hadLegacyQueue ? "warning" : "info",
361
- );
362
- return;
363
- }
318
+ clearGoal(ctx: StatusContext) {
319
+ if (!this.runtime.activeGoal) {
320
+ const hadLegacyQueue = this.runtime.legacyQueueState !== undefined;
321
+ this.runtime.legacyQueueState = undefined;
322
+ this.runtime.cancelContinuationWork();
323
+ this.runtime.clearGoalRecovery();
324
+ this.runtime.clearBudgetWrapUp();
325
+ this.runtime.clearStaleGoalToolCallBlock();
326
+ this.runtime.clearPersistedGoal(ctx.cwd);
327
+ ctx.ui.setStatus(STATUS_KEY, undefined);
328
+ notifyTerminal(
329
+ ctx.ui,
330
+ hadLegacyQueue ? "Removed legacy ordered goal queue state." : "No active goal.",
331
+ hadLegacyQueue ? "warning" : "info",
332
+ );
333
+ return;
334
+ }
364
335
 
365
- const stoppedGoal = this.runtime.activeGoal.text;
366
- this.runtime.clearActiveGoal(ctx);
367
- notifyTerminal(ctx.ui, `Goal cleared: ${stoppedGoal}`, "warning");
368
- }
336
+ const stoppedGoal = this.runtime.activeGoal.text;
337
+ this.runtime.clearActiveGoal(ctx);
338
+ notifyTerminal(ctx.ui, `Goal cleared: ${stoppedGoal}`, "warning");
339
+ }
369
340
 
370
- async editGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {
371
- const validationError = validateObjective(objective);
372
- if (validationError) {
373
- notifyTerminal(ctx.ui, validationError, "warning");
374
- return;
375
- }
376
- if (!this.runtime.activeGoal) {
377
- notifyTerminal(ctx.ui, "No active goal. Use /goal <objective> to start one.", "warning");
378
- return;
379
- }
341
+ async editGoal(objective: string, tokenBudget: number | undefined, ctx: StatusContext) {
342
+ const validationError = validateObjective(objective);
343
+ if (validationError) {
344
+ notifyTerminal(ctx.ui, validationError, "warning");
345
+ return;
346
+ }
347
+ if (!this.runtime.activeGoal) {
348
+ notifyTerminal(ctx.ui, "No active goal. Use /goal <objective> to start one.", "warning");
349
+ return;
350
+ }
380
351
 
381
- const currentGoal = this.runtime.activeGoal;
382
- const effectiveTokenBudget = tokenBudget ?? currentGoal.tokenBudget;
383
- if (
384
- currentGoal.status === "budget_limited" &&
385
- effectiveTokenBudget !== undefined &&
386
- effectiveTokenBudget <= currentGoal.tokensUsed
387
- ) {
388
- notifyTerminal(
389
- ctx.ui,
390
- `Goal token budget is still reached: ${formatBudget(currentGoal)}. Raise the budget above current usage before editing.`,
391
- "warning",
392
- );
393
- return;
394
- }
395
- const previousStatus = currentGoal.status;
396
- const intendsActive = editedGoalStatus(previousStatus) === "active";
397
- const retainedOwner = this.runtime.ownsWorkflow(currentGoal);
398
- if (intendsActive && !this.runtime.acquireWorkflow(ctx.sessionManager)) {
399
- this.reportWorkflowBusy(ctx);
400
- return;
401
- }
402
- const acquiredForEdit = intendsActive && !retainedOwner;
403
- if (intendsActive) {
404
- try {
405
- this.runtime.assertGoalToolsAvailable();
406
- } catch (error) {
407
- notifyTerminal(ctx.ui, `Cannot reactivate /goal: ${formatError(error)}`, "error");
408
- if (currentGoal.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
409
- else if (acquiredForEdit) this.runtime.releaseWorkflow();
410
- return;
411
- }
412
- }
352
+ const currentGoal = this.runtime.activeGoal;
353
+ const effectiveTokenBudget = tokenBudget ?? currentGoal.tokenBudget;
354
+ if (
355
+ currentGoal.status === "budget_limited" &&
356
+ effectiveTokenBudget !== undefined &&
357
+ effectiveTokenBudget <= currentGoal.tokensUsed
358
+ ) {
359
+ notifyTerminal(
360
+ ctx.ui,
361
+ `Goal token budget is still reached: ${formatBudget(currentGoal)}. Raise the budget above current usage before editing.`,
362
+ "warning",
363
+ );
364
+ return;
365
+ }
366
+ const previousStatus = currentGoal.status;
367
+ const intendsActive = editedGoalStatus(previousStatus) === "active";
368
+ const retainedOwner = this.runtime.ownsWorkflow(currentGoal);
369
+ if (intendsActive && !this.runtime.acquireWorkflow(ctx.sessionManager)) {
370
+ this.reportWorkflowBusy(ctx);
371
+ return;
372
+ }
373
+ const acquiredForEdit = intendsActive && !retainedOwner;
374
+ if (intendsActive) {
375
+ try {
376
+ this.runtime.assertGoalToolsAvailable();
377
+ } catch (error) {
378
+ notifyTerminal(ctx.ui, `Cannot reactivate /goal: ${formatError(error)}`, "error");
379
+ if (currentGoal.status === "active") this.runtime.pauseGoalForUnavailableTools(ctx);
380
+ else if (acquiredForEdit) this.runtime.releaseWorkflow();
381
+ return;
382
+ }
383
+ }
413
384
 
414
- this.runtime.recordGoalUsage(currentGoal, ctx);
415
- const previousGoal = { ...currentGoal };
416
- this.runtime.clearGoalWaitTimer();
417
- this.runtime.cancelContinuationWork();
418
- this.runtime.clearGoalRecovery();
419
- this.runtime.clearBudgetWrapUp();
420
- const rotatedGoal = nextGoalInstance(currentGoal);
421
- const transitionedGoal = transitionGoal(
422
- {
423
- ...rotatedGoal,
424
- text: objective,
425
- tokenBudget: effectiveTokenBudget,
426
- waiting: undefined,
427
- },
428
- editedGoalStatus(previousStatus),
429
- );
430
- const nextGoal =
431
- transitionedGoal.status === "active"
432
- ? queueGoalSafetyReset(transitionedGoal)
433
- : transitionedGoal;
434
- this.runtime.activeGoal = nextGoal;
435
- this.runtime.persistGoal(this.runtime.activeGoal);
436
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
437
- const editedGoal = this.runtime.activeGoal;
438
- if (!editedGoal) return;
439
- if (editedGoal.status === "active") {
440
- if (!this.runtime.ownsWorkflow(editedGoal)) return;
441
- this.runtime.clearStaleGoalToolCallBlock();
442
- const sent = await this.runtime.sendOwnedGoalPrompt(
443
- ctx,
444
- editedGoal.id,
445
- buildObjectiveUpdatedPrompt(editedGoal),
446
- );
447
- if (!sent) {
448
- if (this.runtime.activeGoal?.id === editedGoal.id) {
449
- if (previousStatus === "active" && previousGoal.waiting) {
450
- this.runtime.activeGoal = previousGoal;
451
- this.runtime.clearStaleGoalToolCallBlock();
452
- this.runtime.persistGoal(previousGoal);
453
- this.runtime.updateStatus(ctx, previousGoal);
454
- this.runtime.restoreGoalWaitTimer(ctx);
455
- } else if (previousStatus === "active") {
456
- this.runtime.activeGoal = previousGoal;
457
- this.runtime.clearStaleGoalToolCallBlock();
458
- this.runtime.persistGoal(previousGoal);
459
- if (this.runtime.activeGoal?.id === previousGoal.id) {
460
- this.runtime.updateStatus(ctx, previousGoal);
461
- }
462
- } else {
463
- this.runtime.activeGoal = previousGoal;
464
- if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
465
- this.runtime.blockStaleGoalToolCalls();
466
- } else {
467
- this.runtime.clearStaleGoalToolCallBlock();
468
- }
469
- this.runtime.persistGoal(this.runtime.activeGoal);
470
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
471
- }
472
- if (acquiredForEdit && previousStatus !== "active") {
473
- this.runtime.releaseWorkflow();
474
- }
475
- }
476
- return;
477
- }
478
- if (!this.runtime.ownsWorkflow(editedGoal)) return;
479
- } else if (blocksStaleGoalToolCalls(editedGoal.status)) {
480
- this.runtime.blockStaleGoalToolCalls();
481
- } else {
482
- this.runtime.clearStaleGoalToolCallBlock();
483
- }
484
- if (editedGoal.status !== "active" && (retainedOwner || acquiredForEdit)) {
485
- this.runtime.releaseWorkflow();
486
- }
487
- notifyTerminal(ctx.ui, `Goal updated: ${objective}`, "info");
488
- }
385
+ this.runtime.recordGoalUsage(currentGoal, ctx);
386
+ const previousGoal = { ...currentGoal };
387
+ this.runtime.clearGoalWaitTimer();
388
+ this.runtime.cancelContinuationWork();
389
+ this.runtime.clearGoalRecovery();
390
+ this.runtime.clearBudgetWrapUp();
391
+ const rotatedGoal = nextGoalInstance(currentGoal);
392
+ const transitionedGoal = transitionGoal(
393
+ {
394
+ ...rotatedGoal,
395
+ text: objective,
396
+ tokenBudget: effectiveTokenBudget,
397
+ waiting: undefined,
398
+ },
399
+ editedGoalStatus(previousStatus),
400
+ );
401
+ const nextGoal = transitionedGoal.status === "active" ? queueGoalSafetyReset(transitionedGoal) : transitionedGoal;
402
+ this.runtime.activeGoal = nextGoal;
403
+ this.runtime.persistGoal(this.runtime.activeGoal);
404
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
405
+ const editedGoal = this.runtime.activeGoal;
406
+ if (!editedGoal) return;
407
+ if (editedGoal.status === "active") {
408
+ if (!this.runtime.ownsWorkflow(editedGoal)) return;
409
+ this.runtime.clearStaleGoalToolCallBlock();
410
+ const sent = await this.runtime.sendOwnedGoalPrompt(ctx, editedGoal.id, buildObjectiveUpdatedPrompt(editedGoal));
411
+ if (!sent) {
412
+ if (this.runtime.activeGoal?.id === editedGoal.id) {
413
+ if (previousStatus === "active" && previousGoal.waiting) {
414
+ this.runtime.activeGoal = previousGoal;
415
+ this.runtime.clearStaleGoalToolCallBlock();
416
+ this.runtime.persistGoal(previousGoal);
417
+ this.runtime.updateStatus(ctx, previousGoal);
418
+ this.runtime.restoreGoalWaitTimer(ctx);
419
+ } else if (previousStatus === "active") {
420
+ this.runtime.activeGoal = previousGoal;
421
+ this.runtime.clearStaleGoalToolCallBlock();
422
+ this.runtime.persistGoal(previousGoal);
423
+ if (this.runtime.activeGoal?.id === previousGoal.id) {
424
+ this.runtime.updateStatus(ctx, previousGoal);
425
+ }
426
+ } else {
427
+ this.runtime.activeGoal = previousGoal;
428
+ if (blocksStaleGoalToolCalls(this.runtime.activeGoal.status)) {
429
+ this.runtime.blockStaleGoalToolCalls();
430
+ } else {
431
+ this.runtime.clearStaleGoalToolCallBlock();
432
+ }
433
+ this.runtime.persistGoal(this.runtime.activeGoal);
434
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
435
+ }
436
+ if (acquiredForEdit && previousStatus !== "active") {
437
+ this.runtime.releaseWorkflow();
438
+ }
439
+ }
440
+ return;
441
+ }
442
+ if (!this.runtime.ownsWorkflow(editedGoal)) return;
443
+ } else if (blocksStaleGoalToolCalls(editedGoal.status)) {
444
+ this.runtime.blockStaleGoalToolCalls();
445
+ } else {
446
+ this.runtime.clearStaleGoalToolCallBlock();
447
+ }
448
+ if (editedGoal.status !== "active" && (retainedOwner || acquiredForEdit)) {
449
+ this.runtime.releaseWorkflow();
450
+ }
451
+ notifyTerminal(ctx.ui, `Goal updated: ${objective}`, "info");
452
+ }
489
453
 
490
- private reportWorkflowBusy(ctx: StatusContext) {
491
- const message = "Another workflow is active in this session. End it before starting Goal.";
492
- if (ctx.mode === "print" || ctx.mode === "json") throw new Error(message);
493
- notifyTerminal(ctx.ui, message, "warning");
494
- return { kind: "busy" as const };
495
- }
454
+ private reportWorkflowBusy(ctx: StatusContext) {
455
+ const message = "Another workflow is active in this session. End it before starting Goal.";
456
+ if (ctx.mode === "print" || ctx.mode === "json") throw new Error(message);
457
+ notifyTerminal(ctx.ui, message, "warning");
458
+ return { kind: "busy" as const };
459
+ }
496
460
 
497
- showGoal(ctx: StatusContext) {
498
- if (!this.runtime.activeGoal) {
499
- ctx.ui.setStatus(STATUS_KEY, undefined);
500
- this.reportGoalStatus(ctx, this.emptyGoalMessage());
501
- return;
502
- }
503
- this.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);
504
- this.runtime.persistGoal(this.runtime.activeGoal);
505
- this.runtime.updateStatus(ctx, this.runtime.activeGoal);
506
- this.reportGoalStatus(
507
- ctx,
508
- goalSummary(this.runtime.activeGoal, this.runtime.settings.continuationLimits.automaticTurns),
509
- );
510
- }
461
+ showGoal(ctx: StatusContext) {
462
+ if (!this.runtime.activeGoal) {
463
+ ctx.ui.setStatus(STATUS_KEY, undefined);
464
+ this.reportGoalStatus(ctx, this.emptyGoalMessage());
465
+ return;
466
+ }
467
+ this.runtime.recordGoalUsage(this.runtime.activeGoal, ctx);
468
+ this.runtime.persistGoal(this.runtime.activeGoal);
469
+ this.runtime.updateStatus(ctx, this.runtime.activeGoal);
470
+ this.reportGoalStatus(
471
+ ctx,
472
+ goalSummary(this.runtime.activeGoal, this.runtime.settings.continuationLimits.automaticTurns),
473
+ );
474
+ }
511
475
 
512
- private emptyGoalMessage() {
513
- const legacy = this.runtime.legacyQueueState;
514
- if (!legacy) return "Usage: /goal <objective>\nNo goal is currently set.";
515
- return [
516
- "Ordered goal queue has been removed.",
517
- `Legacy queue state with ${legacy.retainedGoals} retained ${legacy.retainedGoals === 1 ? "goal" : "goals"} will not run automatically.`,
518
- "Use /goal edit to reprioritize an active objective, start /goal <objectives>, or use /goal clear to discard the old queue state.",
519
- 'Example objective: "task b is complete; do task a next, then task c and task d."',
520
- ].join("\n");
521
- }
476
+ private emptyGoalMessage() {
477
+ const legacy = this.runtime.legacyQueueState;
478
+ if (!legacy) return "Usage: /goal <objective>\nNo goal is currently set.";
479
+ return [
480
+ "Ordered goal queue has been removed.",
481
+ `Legacy queue state with ${legacy.retainedGoals} retained ${legacy.retainedGoals === 1 ? "goal" : "goals"} will not run automatically.`,
482
+ "Use /goal edit to reprioritize an active objective, start /goal <objectives>, or use /goal clear to discard the old queue state.",
483
+ 'Example objective: "task b is complete; do task a next, then task c and task d."',
484
+ ].join("\n");
485
+ }
522
486
 
523
- private reportGoalStatus(ctx: StatusContext, message: string) {
524
- if (ctx.mode === "print" || ctx.mode === "json") {
525
- throw new Error(
526
- `/goal status is unavailable in ${ctx.mode} mode because Pi does not expose an extension-command output channel. Use TUI or RPC mode.`,
527
- );
528
- }
529
- notifyTerminal(ctx.ui, message, "info");
530
- }
487
+ private reportGoalStatus(ctx: StatusContext, message: string) {
488
+ if (ctx.mode === "print" || ctx.mode === "json") {
489
+ throw new Error(
490
+ `/goal status is unavailable in ${ctx.mode} mode because Pi does not expose an extension-command output channel. Use TUI or RPC mode.`,
491
+ );
492
+ }
493
+ notifyTerminal(ctx.ui, message, "info");
494
+ }
531
495
  }