@narumitw/pi-goal 0.52.1 → 0.52.3

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.
@@ -0,0 +1,565 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ goalSummary,
5
+ parseTokenBudget
6
+ } from "./chunk-ODVXYZXS.js";
7
+ import {
8
+ formatDuration,
9
+ formatTokenCount,
10
+ notifyTerminal,
11
+ safeGoalMenuText
12
+ } from "./chunk-UA7LMS63.js";
13
+
14
+ // src/menu.ts
15
+ var GOAL_MENU_ACTIONS = {
16
+ start: "Start a goal\u2026",
17
+ startBudget: "Start with token budget\u2026",
18
+ pause: "Pause goal",
19
+ resume: "Resume goal",
20
+ reviewSafety: "Review and continue\u2026",
21
+ increaseBudget: "Increase budget and resume\u2026",
22
+ edit: "Edit goal\u2026",
23
+ replace: "Replace goal\u2026",
24
+ status: "View full status",
25
+ settings: "Settings\u2026",
26
+ help: "Help",
27
+ clear: "Clear goal\u2026",
28
+ close: "Close"
29
+ };
30
+ function buildGoalMenuState(runtime) {
31
+ const goal = runtime.activeGoal;
32
+ const pausedByAutomaticLimit = goal?.status === "paused" && goal.safetyPauseCause === "continuation_limit";
33
+ const waitingReason = goal?.waiting ? safeGoalMenuText(goal.waiting.reason) : void 0;
34
+ const state = pausedByAutomaticLimit ? "Paused \u2014 automatic-work limit reached" : waitingReason ? `Waiting \u2014 ${waitingReason}` : displayStatus(goal?.status);
35
+ const automaticTurnLimit = runtime.settings.continuationLimits.automaticTurns;
36
+ const used = goal?.automaticModelTurns ?? 0;
37
+ const automaticResponses = automaticTurnLimit === null ? `Automatic work: ${used} responses \xB7 Unlimited` : `Automatic work: ${used} of ${automaticTurnLimit} responses${used < automaticTurnLimit ? ` \xB7 ${automaticTurnLimit - used} remaining` : ""}`;
38
+ const title = goal ? [
39
+ `Goal \xB7 ${state}`,
40
+ safeGoalMenuText(goal.text),
41
+ `Usage: ${goal.tokenBudget === void 0 ? formatDuration(goal.timeUsedSeconds) : `${formatTokenCount2(goal.tokensUsed)}/${formatTokenCount2(goal.tokenBudget)}`}`,
42
+ automaticResponses,
43
+ ...pausedByAutomaticLimit ? ["Progress is saved. Review the safety limit before continuing."] : []
44
+ ].join("\n") : [
45
+ `Goal \xB7 ${state}`,
46
+ "No goal is currently set",
47
+ automaticTurnLimit === null ? "Automatic work is configured as Unlimited." : `Automatic work is configured to pause after ${automaticTurnLimit} responses.`
48
+ ].join("\n");
49
+ const actions = [];
50
+ if (!goal || goal.status === "complete") {
51
+ actions.push(GOAL_MENU_ACTIONS.start, GOAL_MENU_ACTIONS.startBudget);
52
+ } else if (goal.waiting) {
53
+ actions.push(GOAL_MENU_ACTIONS.resume);
54
+ } else if (goal.status === "active") {
55
+ actions.push(GOAL_MENU_ACTIONS.pause);
56
+ } else if (goal.status === "budget_limited") {
57
+ actions.push(GOAL_MENU_ACTIONS.increaseBudget);
58
+ } else if (pausedByAutomaticLimit) {
59
+ actions.push(GOAL_MENU_ACTIONS.reviewSafety);
60
+ } else {
61
+ actions.push(GOAL_MENU_ACTIONS.resume);
62
+ }
63
+ if (goal && goal.status !== "complete") {
64
+ actions.push(GOAL_MENU_ACTIONS.edit, GOAL_MENU_ACTIONS.replace);
65
+ }
66
+ if (goal) actions.push(GOAL_MENU_ACTIONS.status);
67
+ actions.push(GOAL_MENU_ACTIONS.settings, GOAL_MENU_ACTIONS.help);
68
+ if (goal) actions.push(GOAL_MENU_ACTIONS.clear);
69
+ actions.push(GOAL_MENU_ACTIONS.close);
70
+ return { title, actions };
71
+ }
72
+ async function showGoalManager(runtime, commands, ctx, showSettings) {
73
+ if (ctx.mode !== "tui") {
74
+ commands.showGoal(ctx);
75
+ return;
76
+ }
77
+ const owner = runtime;
78
+ const generation = owner.menuGeneration;
79
+ const ownerSignal = owner.menuController?.signal;
80
+ const isMenuCurrent = () => owner.menuController === void 0 || generation === owner.menuGeneration && !owner.menuController.signal.aborted;
81
+ const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
82
+ if (!isMenuCurrent()) return;
83
+ let displayedGoal;
84
+ let displayedBudgetGoal;
85
+ let displayedBudgetValue;
86
+ let displayedBudgetUsage;
87
+ let displayedBudgetStatus;
88
+ const menu = defineMenu({
89
+ start: "main",
90
+ screens: {
91
+ main: () => {
92
+ refreshGoalMenuState(runtime, ctx);
93
+ const state = buildGoalMenuState(runtime);
94
+ displayedGoal = runtime.activeGoal;
95
+ return {
96
+ kind: "actions",
97
+ title: "Goal",
98
+ lines: state.title.split("\n").slice(1),
99
+ items: state.actions.map(goalMainMenuItem),
100
+ hint: "close"
101
+ };
102
+ },
103
+ "start-budget": () => {
104
+ return {
105
+ kind: "actions",
106
+ title: "Choose token budget",
107
+ lines: tokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),
108
+ items: [
109
+ {
110
+ id: "25k",
111
+ label: "25k \u2014 Lower token ceiling",
112
+ description: "Set the cumulative token limit to 25k.",
113
+ action: "start-with-budget"
114
+ },
115
+ {
116
+ id: "100k",
117
+ label: "100k \u2014 Suggested",
118
+ description: "Set the cumulative token limit to 100k.",
119
+ action: "start-with-budget"
120
+ },
121
+ {
122
+ id: "300k",
123
+ label: "300k \u2014 Higher token ceiling",
124
+ description: "Set the cumulative token limit to 300k.",
125
+ action: "start-with-budget"
126
+ },
127
+ {
128
+ id: "custom",
129
+ label: "Set a custom budget\u2026",
130
+ description: "Enter an exact cumulative token limit.",
131
+ to: "start-custom-budget"
132
+ },
133
+ { id: "back", label: "Back", action: "back" }
134
+ ],
135
+ hint: "back"
136
+ };
137
+ },
138
+ "start-custom-budget": () => ({
139
+ kind: "input",
140
+ title: "Custom token budget",
141
+ lines: customTokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),
142
+ placeholder: "100k",
143
+ action: "start-with-custom-budget",
144
+ hint: "back"
145
+ }),
146
+ "increase-budget": () => {
147
+ const goal = runtime.activeGoal;
148
+ displayedBudgetGoal = goal;
149
+ displayedBudgetValue = goal?.tokenBudget;
150
+ displayedBudgetUsage = goal?.tokensUsed;
151
+ displayedBudgetStatus = goal?.status;
152
+ if (goal && goal.tokensUsed >= Number.MAX_SAFE_INTEGER) {
153
+ return {
154
+ kind: "detail",
155
+ title: "Increase token budget unavailable",
156
+ lines: [
157
+ `Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,
158
+ "No larger safe whole-number token budget is available. Progress remains saved; choose Back and clear or replace the goal when ready."
159
+ ],
160
+ hint: "back"
161
+ };
162
+ }
163
+ return {
164
+ kind: "input",
165
+ title: "Increase token budget",
166
+ lines: goal ? increaseTokenBudgetGuidance(goal, runtime.settings.continuationLimits.automaticTurns) : ["The budget-limited goal is no longer available. Return to the Goal menu."],
167
+ placeholder: goal ? suggestedIncreasedBudget(goal) : "300k",
168
+ action: "submit-increase-budget",
169
+ hint: "back"
170
+ };
171
+ },
172
+ safety: () => {
173
+ const goal = runtime.activeGoal;
174
+ displayedGoal = goal;
175
+ const limit = runtime.settings.continuationLimits.automaticTurns;
176
+ const used = goal?.automaticModelTurns ?? 0;
177
+ return {
178
+ kind: "actions",
179
+ title: "Automatic work paused",
180
+ lines: goal ? [
181
+ automaticPauseSummary(used, limit),
182
+ `${safeGoalMenuText(goal.text)} is preserved.`,
183
+ `${formatInteger(goal.tokensUsed)} cumulative tokens and ${formatDuration(goal.timeUsedSeconds)} active time are preserved.`,
184
+ "The objective and usage are preserved.",
185
+ limit === null ? "Continuing resets the counter to 0 and resumes with Unlimited automatic work." : `Continuing resets the counter to 0 and allows up to ${limit} more automatic model responses.`
186
+ ] : ["The paused goal is no longer available. Return to the Goal menu."],
187
+ items: goal ? [
188
+ {
189
+ id: "continue",
190
+ label: limit === null ? "Continue \u2014 Unlimited" : `Continue \u2014 up to ${limit} more responses`,
191
+ action: "safety-resume"
192
+ },
193
+ {
194
+ id: "settings",
195
+ label: "Change automatic-work limit\u2026",
196
+ action: "safety-settings"
197
+ },
198
+ { id: "back", label: "Back", action: "back" }
199
+ ] : [{ id: "back", label: "Back", action: "back" }],
200
+ hint: "back"
201
+ };
202
+ },
203
+ status: () => ({
204
+ kind: "detail",
205
+ title: "Goal status",
206
+ lines: runtime.activeGoal ? goalSummary(
207
+ runtime.activeGoal,
208
+ runtime.settings.continuationLimits.automaticTurns
209
+ ).split("\n") : ["No goal is currently set."],
210
+ hint: "back"
211
+ }),
212
+ help: () => ({
213
+ kind: "detail",
214
+ title: "Goal help",
215
+ lines: goalHelp().split("\n").slice(1),
216
+ hint: "back"
217
+ })
218
+ },
219
+ actions: {
220
+ start: async () => {
221
+ await startFromMenu(commands, ctx);
222
+ return { kind: "close" };
223
+ },
224
+ "start-with-budget": async ({ itemId, signal }) => {
225
+ const budget = parseTokenBudget(itemId);
226
+ if (budget === void 0) return { kind: "rejected" };
227
+ return startBudgetedGoal(
228
+ commands,
229
+ ctx,
230
+ budget,
231
+ runtime.settings.continuationLimits.automaticTurns,
232
+ signal,
233
+ isMenuCurrent,
234
+ "stay"
235
+ );
236
+ },
237
+ "start-with-custom-budget": async ({ value, signal }) => {
238
+ const budget = parseTokenBudget(value ?? "");
239
+ if (budget === void 0) {
240
+ notifyTerminal(
241
+ ctx.ui,
242
+ "Enter a positive token amount, for example 25k, 300k, or 1.5m.",
243
+ "warning"
244
+ );
245
+ return { kind: "rejected" };
246
+ }
247
+ return startBudgetedGoal(
248
+ commands,
249
+ ctx,
250
+ budget,
251
+ runtime.settings.continuationLimits.automaticTurns,
252
+ signal,
253
+ isMenuCurrent,
254
+ "back"
255
+ );
256
+ },
257
+ "submit-increase-budget": async ({ value, signal }) => {
258
+ const goal = displayedBudgetGoal;
259
+ const budget = parseTokenBudget(value ?? "");
260
+ if (budget === void 0) {
261
+ notifyTerminal(
262
+ ctx.ui,
263
+ "Enter a positive token amount, for example 300k, 1.5m, or 300000.",
264
+ "warning"
265
+ );
266
+ return { kind: "rejected" };
267
+ }
268
+ if (!goal || !requireCurrentBudgetPreview(
269
+ runtime,
270
+ goal,
271
+ displayedBudgetValue,
272
+ displayedBudgetUsage,
273
+ displayedBudgetStatus,
274
+ ctx
275
+ )) {
276
+ return { kind: "close" };
277
+ }
278
+ if (budget <= goal.tokensUsed) {
279
+ notifyTerminal(
280
+ ctx.ui,
281
+ `Enter a new cumulative total greater than current usage (${formatTokenCount(goal.tokensUsed)}).`,
282
+ "warning"
283
+ );
284
+ return { kind: "rejected" };
285
+ }
286
+ const confirmed = await ctx.ui.confirm(
287
+ "Increase goal budget?",
288
+ increaseBudgetPreview(goal, budget, runtime.settings.continuationLimits.automaticTurns)
289
+ );
290
+ if (signal.aborted || !isMenuCurrent()) return { kind: "close" };
291
+ if (!confirmed) return { kind: "rejected" };
292
+ if (!requireCurrentBudgetPreview(
293
+ runtime,
294
+ goal,
295
+ displayedBudgetValue,
296
+ displayedBudgetUsage,
297
+ displayedBudgetStatus,
298
+ ctx
299
+ )) {
300
+ return { kind: "close" };
301
+ }
302
+ await commands.editGoal(goal.text, budget, ctx);
303
+ return { kind: "close" };
304
+ },
305
+ pause: async () => {
306
+ if (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {
307
+ return { kind: "stay" };
308
+ }
309
+ commands.pauseGoal(ctx);
310
+ return { kind: "close" };
311
+ },
312
+ resume: async () => {
313
+ if (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {
314
+ return { kind: "stay" };
315
+ }
316
+ await commands.resumeGoal(ctx);
317
+ return { kind: "close" };
318
+ },
319
+ "safety-resume": async () => {
320
+ if (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {
321
+ return { kind: "stay" };
322
+ }
323
+ await commands.resumeGoal(ctx);
324
+ return { kind: "close" };
325
+ },
326
+ "safety-settings": async () => {
327
+ if (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {
328
+ return { kind: "stay" };
329
+ }
330
+ const expectedGoal = displayedGoal;
331
+ await showSettings(ctx, "automatic");
332
+ if (!isMenuCurrent()) return { kind: "close" };
333
+ if (!requireCurrentMenuGoal(runtime, expectedGoal, ctx)) return { kind: "stay" };
334
+ return { kind: "stay" };
335
+ },
336
+ edit: async () => {
337
+ if (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {
338
+ return { kind: "stay" };
339
+ }
340
+ await editFromMenu(runtime, commands, ctx);
341
+ return { kind: "close" };
342
+ },
343
+ replace: async () => {
344
+ await startFromMenu(commands, ctx);
345
+ return { kind: "close" };
346
+ },
347
+ settings: async () => {
348
+ await showSettings(ctx);
349
+ return { kind: "stay" };
350
+ },
351
+ clear: async () => {
352
+ const previewedGoal = runtime.activeGoal;
353
+ if (!await confirmClear(runtime, ctx)) return { kind: "stay" };
354
+ if (previewedGoal && !requireCurrentMenuGoal(runtime, previewedGoal, ctx)) {
355
+ return { kind: "stay" };
356
+ }
357
+ commands.clearGoal(ctx);
358
+ return { kind: "close" };
359
+ },
360
+ back: async () => ({ kind: "back" })
361
+ }
362
+ });
363
+ await runMenu(ctx, menu, {
364
+ getState: () => void 0,
365
+ signal: ownerSignal,
366
+ isCurrent: isMenuCurrent
367
+ });
368
+ }
369
+ function goalMainMenuItem(label) {
370
+ if (label === GOAL_MENU_ACTIONS.status) return { id: "status", label, to: "status" };
371
+ if (label === GOAL_MENU_ACTIONS.startBudget) {
372
+ return { id: "start-budget", label, to: "start-budget" };
373
+ }
374
+ if (label === GOAL_MENU_ACTIONS.increaseBudget) {
375
+ return { id: "increase-budget", label, to: "increase-budget" };
376
+ }
377
+ if (label === GOAL_MENU_ACTIONS.reviewSafety) {
378
+ return { id: "review-safety", label, to: "safety" };
379
+ }
380
+ if (label === GOAL_MENU_ACTIONS.help) return { id: "help", label, to: "help" };
381
+ if (label === GOAL_MENU_ACTIONS.close) return { id: "close", label, close: true };
382
+ const actions = /* @__PURE__ */ new Map([
383
+ [GOAL_MENU_ACTIONS.start, "start"],
384
+ [GOAL_MENU_ACTIONS.pause, "pause"],
385
+ [GOAL_MENU_ACTIONS.resume, "resume"],
386
+ [GOAL_MENU_ACTIONS.edit, "edit"],
387
+ [GOAL_MENU_ACTIONS.replace, "replace"],
388
+ [GOAL_MENU_ACTIONS.settings, "settings"],
389
+ [GOAL_MENU_ACTIONS.clear, "clear"]
390
+ ]);
391
+ return { id: actions.get(label) ?? label, label, action: actions.get(label) ?? "settings" };
392
+ }
393
+ function refreshGoalMenuState(runtime, ctx) {
394
+ const goal = runtime.activeGoal;
395
+ if (!goal) return;
396
+ runtime.recordGoalUsage?.(goal, ctx);
397
+ runtime.persistGoal?.(goal);
398
+ runtime.updateStatus?.(ctx, goal);
399
+ }
400
+ async function startFromMenu(commands, ctx) {
401
+ const objective = (await ctx.ui.editor("Goal objective", ""))?.trim();
402
+ if (!objective) return;
403
+ await commands.startGoal(objective, void 0, ctx);
404
+ }
405
+ async function startBudgetedGoal(commands, ctx, budget, automaticLimit, signal, isMenuCurrent, cancelTransition) {
406
+ const objective = (await ctx.ui.editor(
407
+ `Goal objective \xB7 Token budget ${formatTokenCount(budget)} \xB7 ${automaticLimit === null ? "Automatic Unlimited" : `Automatic limit ${automaticLimit}`}`,
408
+ ""
409
+ ))?.trim();
410
+ if (signal.aborted || !isMenuCurrent()) return { kind: "close" };
411
+ if (!objective) return { kind: cancelTransition };
412
+ await commands.startGoal(
413
+ objective,
414
+ budget,
415
+ ctx,
416
+ void 0,
417
+ () => !signal.aborted && isMenuCurrent(),
418
+ () => !signal.aborted && isMenuCurrent()
419
+ );
420
+ return { kind: "close" };
421
+ }
422
+ function tokenBudgetGuidance(automaticLimit) {
423
+ return [
424
+ "Set the maximum cumulative token usage for this goal.",
425
+ "The final model call may exceed the limit; this is not a dollar-cost cap.",
426
+ automaticBudgetGuidance(automaticLimit)
427
+ ];
428
+ }
429
+ function customTokenBudgetGuidance(automaticLimit) {
430
+ return [
431
+ "Enter the maximum cumulative token usage for this goal.",
432
+ "Examples: 25k, 300k, 1.5m, or 300000.",
433
+ "The final model call may exceed this value; this is not a dollar-cost cap.",
434
+ automaticBudgetGuidance(automaticLimit)
435
+ ];
436
+ }
437
+ function automaticBudgetGuidance(automaticLimit) {
438
+ return automaticLimit === null ? "Automatic work has no response-count cap." : `Automatic work will also pause after ${automaticLimit} responses.`;
439
+ }
440
+ function increaseTokenBudgetGuidance(goal, automaticLimit) {
441
+ return [
442
+ `Current budget: ${formatBudgetDecisionValue(goal.tokenBudget ?? 0)}`,
443
+ `Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,
444
+ `Enter a new cumulative total greater than ${formatBudgetDecisionValue(goal.tokensUsed)}.`,
445
+ "Examples: 300k, 1.5m, or 300000.",
446
+ "The final model call may exceed the limit; this is not a dollar-cost cap.",
447
+ automaticBudgetGuidance(automaticLimit)
448
+ ];
449
+ }
450
+ function suggestedIncreasedBudget(goal) {
451
+ const floor = Math.max(goal.tokensUsed, goal.tokenBudget ?? 0);
452
+ for (const suggestion of [25e3, 1e5, 3e5, 5e5, 1e6]) {
453
+ if (suggestion > floor) return formatTokenCount(suggestion);
454
+ }
455
+ return formatTokenCount(
456
+ Math.min(Number.MAX_SAFE_INTEGER, Math.max(Math.floor(floor) + 1, Math.ceil(floor * 2)))
457
+ );
458
+ }
459
+ function formatBudgetDecisionValue(value) {
460
+ const compact = formatTokenCount(value);
461
+ if (value < 1e3 || value % 1e3 === 0) return compact;
462
+ return `${compact} (${formatInteger(value)} tokens)`;
463
+ }
464
+ function increaseBudgetPreview(goal, budget, automaticLimit) {
465
+ return [
466
+ `Goal: ${safeGoalMenuText(goal.text, 4e3)}`,
467
+ `Budget: ${formatTokenCount(goal.tokenBudget ?? 0)} \u2192 ${formatTokenCount(budget)}`,
468
+ `Current usage: ${formatTokenCount(goal.tokensUsed)}`,
469
+ automaticLimit === null ? "Automatic work: Unlimited after resume" : `Automatic work: up to ${automaticLimit} more responses after resume`,
470
+ "The goal will resume immediately."
471
+ ].join("\n");
472
+ }
473
+ async function editFromMenu(runtime, commands, ctx) {
474
+ const goal = runtime.activeGoal;
475
+ if (!goal) return;
476
+ const objective = (await ctx.ui.editor("Edit goal objective", goal.text))?.trim();
477
+ if (!objective || objective === goal.text) return;
478
+ if (!requireCurrentMenuGoal(runtime, goal, ctx)) return;
479
+ if (goal.status === "active") {
480
+ const confirmed = await ctx.ui.confirm(
481
+ "Apply goal edit?",
482
+ `Current goal:
483
+ ${safeGoalMenuText(goal.text, 4e3)}
484
+
485
+ Updated goal:
486
+ ${safeGoalMenuText(objective, 4e3)}
487
+
488
+ Applying this edit starts a new guarded goal instance.`
489
+ );
490
+ if (!confirmed || !requireCurrentMenuGoal(runtime, goal, ctx)) return;
491
+ }
492
+ await commands.editGoal(objective, void 0, ctx);
493
+ }
494
+ async function confirmClear(runtime, ctx) {
495
+ const goal = runtime.activeGoal;
496
+ if (!goal) return false;
497
+ return ctx.ui.confirm(
498
+ "Clear goal?",
499
+ `Remove this goal:
500
+
501
+ ${safeGoalMenuText(goal.text, 4e3)}
502
+
503
+ This cannot be undone.`
504
+ );
505
+ }
506
+ function requireCurrentBudgetPreview(runtime, expectedGoal, expectedBudget, expectedUsage, expectedStatus, ctx) {
507
+ const current = runtime.activeGoal;
508
+ if (current?.id === expectedGoal.id && current.tokenBudget === expectedBudget && current.tokensUsed === expectedUsage && current.status === expectedStatus) {
509
+ return true;
510
+ }
511
+ notifyTerminal(
512
+ ctx.ui,
513
+ "The goal changed or its usage changed while the budget dialog was open. Reopen /goal and try again.",
514
+ "warning"
515
+ );
516
+ return false;
517
+ }
518
+ function requireCurrentMenuGoal(runtime, expected, ctx) {
519
+ if (runtime.activeGoal?.id === expected.id) return true;
520
+ notifyTerminal(
521
+ ctx.ui,
522
+ "The active goal changed while the dialog was open. Reopen /goal and try again.",
523
+ "warning"
524
+ );
525
+ return false;
526
+ }
527
+ function displayStatus(status) {
528
+ if (!status) return "No goal";
529
+ if (status === "usage_limited") return "Usage limited";
530
+ if (status === "budget_limited") return "Budget limited";
531
+ return status[0]?.toUpperCase() + status.slice(1);
532
+ }
533
+ function formatTokenCount2(tokens) {
534
+ return String(tokens);
535
+ }
536
+ function formatInteger(value) {
537
+ return value.toLocaleString("en-US", { maximumFractionDigits: 0 });
538
+ }
539
+ function automaticPauseSummary(used, limit) {
540
+ if (limit === null) {
541
+ return `Goal paused after ${used} responses at its previous safety limit. Current limit: Unlimited.`;
542
+ }
543
+ if (used < limit) {
544
+ return `Goal paused after ${used} responses at its previous safety limit. Current automatic-work limit: ${limit}.`;
545
+ }
546
+ return `Goal reached its ${used}-of-${limit} safety limit.`;
547
+ }
548
+ function goalHelp() {
549
+ return [
550
+ "Goal menu",
551
+ "Use the menu for guided status, edits, settings, and confirmations.",
552
+ "Direct routes remain available for deterministic workflows:",
553
+ "/goal <objective>",
554
+ "/goal status | pause | resume | edit | clear",
555
+ "/goal --tokens 100k <objective>",
556
+ "Escape cancels the current menu or input without changing goal state."
557
+ ].join("\n");
558
+ }
559
+ export {
560
+ GOAL_MENU_ACTIONS,
561
+ buildGoalMenuState,
562
+ safeGoalMenuText,
563
+ showGoalManager
564
+ };
565
+ //# sourceMappingURL=menu-YILEIJE6.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/menu.ts"],
4
+ "sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { ActionMenuItem } from \"@narumitw/pi-tui-kit\";\nimport { formatTokenCount as formatCompactTokenCount, formatDuration } from \"./accounting.js\";\nimport { parseTokenBudget } from \"./command.js\";\nimport type { GoalCommandController } from \"./commands.js\";\nimport { notifyTerminal, safeGoalMenuText } from \"./errors.js\";\n\nexport { safeGoalMenuText } from \"./errors.js\";\n\nimport type { ActiveGoal } from \"./persistence.js\";\nimport { type GoalRuntime, goalSummary } from \"./runtime.js\";\n\nexport const GOAL_MENU_ACTIONS = {\n\tstart: \"Start a goal\u2026\",\n\tstartBudget: \"Start with token budget\u2026\",\n\tpause: \"Pause goal\",\n\tresume: \"Resume goal\",\n\treviewSafety: \"Review and continue\u2026\",\n\tincreaseBudget: \"Increase budget and resume\u2026\",\n\tedit: \"Edit goal\u2026\",\n\treplace: \"Replace goal\u2026\",\n\tstatus: \"View full status\",\n\tsettings: \"Settings\u2026\",\n\thelp: \"Help\",\n\tclear: \"Clear goal\u2026\",\n\tclose: \"Close\",\n} as const;\n\ninterface GoalMenuRuntimeView {\n\tactiveGoal?: ActiveGoal;\n\tsettings: GoalRuntime[\"settings\"];\n\trecordGoalUsage?: GoalRuntime[\"recordGoalUsage\"];\n\tpersistGoal?: GoalRuntime[\"persistGoal\"];\n\tupdateStatus?: GoalRuntime[\"updateStatus\"];\n}\n\nexport interface GoalMenuState {\n\ttitle: string;\n\tactions: string[];\n}\n\ntype ShowSettings = (ctx: ExtensionCommandContext, target?: \"automatic\") => Promise<void>;\ntype GoalMenuScreen =\n\t| \"main\"\n\t| \"start-budget\"\n\t| \"start-custom-budget\"\n\t| \"increase-budget\"\n\t| \"safety\"\n\t| \"status\"\n\t| \"help\";\ntype GoalMenuAction =\n\t| \"start\"\n\t| \"start-with-budget\"\n\t| \"start-with-custom-budget\"\n\t| \"submit-increase-budget\"\n\t| \"pause\"\n\t| \"resume\"\n\t| \"safety-resume\"\n\t| \"safety-settings\"\n\t| \"edit\"\n\t| \"replace\"\n\t| \"settings\"\n\t| \"clear\"\n\t| \"back\";\n\nexport function buildGoalMenuState(runtime: GoalMenuRuntimeView): GoalMenuState {\n\tconst goal = runtime.activeGoal;\n\tconst pausedByAutomaticLimit =\n\t\tgoal?.status === \"paused\" && goal.safetyPauseCause === \"continuation_limit\";\n\tconst waitingReason = goal?.waiting ? safeGoalMenuText(goal.waiting.reason) : undefined;\n\tconst state = pausedByAutomaticLimit\n\t\t? \"Paused \u2014 automatic-work limit reached\"\n\t\t: waitingReason\n\t\t\t? `Waiting \u2014 ${waitingReason}`\n\t\t\t: displayStatus(goal?.status);\n\tconst automaticTurnLimit = runtime.settings.continuationLimits.automaticTurns;\n\tconst used = goal?.automaticModelTurns ?? 0;\n\tconst automaticResponses =\n\t\tautomaticTurnLimit === null\n\t\t\t? `Automatic work: ${used} responses \u00B7 Unlimited`\n\t\t\t: `Automatic work: ${used} of ${automaticTurnLimit} responses${\n\t\t\t\t\tused < automaticTurnLimit ? ` \u00B7 ${automaticTurnLimit - used} remaining` : \"\"\n\t\t\t\t}`;\n\tconst title = goal\n\t\t? [\n\t\t\t\t`Goal \u00B7 ${state}`,\n\t\t\t\tsafeGoalMenuText(goal.text),\n\t\t\t\t`Usage: ${\n\t\t\t\t\tgoal.tokenBudget === undefined\n\t\t\t\t\t\t? formatDuration(goal.timeUsedSeconds)\n\t\t\t\t\t\t: `${formatTokenCount(goal.tokensUsed)}/${formatTokenCount(goal.tokenBudget)}`\n\t\t\t\t}`,\n\t\t\t\tautomaticResponses,\n\t\t\t\t...(pausedByAutomaticLimit\n\t\t\t\t\t? [\"Progress is saved. Review the safety limit before continuing.\"]\n\t\t\t\t\t: []),\n\t\t\t].join(\"\\n\")\n\t\t: [\n\t\t\t\t`Goal \u00B7 ${state}`,\n\t\t\t\t\"No goal is currently set\",\n\t\t\t\tautomaticTurnLimit === null\n\t\t\t\t\t? \"Automatic work is configured as Unlimited.\"\n\t\t\t\t\t: `Automatic work is configured to pause after ${automaticTurnLimit} responses.`,\n\t\t\t].join(\"\\n\");\n\n\tconst actions: string[] = [];\n\tif (!goal || goal.status === \"complete\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.start, GOAL_MENU_ACTIONS.startBudget);\n\t} else if (goal.waiting) {\n\t\tactions.push(GOAL_MENU_ACTIONS.resume);\n\t} else if (goal.status === \"active\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.pause);\n\t} else if (goal.status === \"budget_limited\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.increaseBudget);\n\t} else if (pausedByAutomaticLimit) {\n\t\tactions.push(GOAL_MENU_ACTIONS.reviewSafety);\n\t} else {\n\t\tactions.push(GOAL_MENU_ACTIONS.resume);\n\t}\n\tif (goal && goal.status !== \"complete\") {\n\t\tactions.push(GOAL_MENU_ACTIONS.edit, GOAL_MENU_ACTIONS.replace);\n\t}\n\tif (goal) actions.push(GOAL_MENU_ACTIONS.status);\n\tactions.push(GOAL_MENU_ACTIONS.settings, GOAL_MENU_ACTIONS.help);\n\tif (goal) actions.push(GOAL_MENU_ACTIONS.clear);\n\tactions.push(GOAL_MENU_ACTIONS.close);\n\treturn { title, actions };\n}\n\nexport async function showGoalManager(\n\truntime: GoalMenuRuntimeView,\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n\tshowSettings: ShowSettings,\n): Promise<void> {\n\tif (ctx.mode !== \"tui\") {\n\t\tcommands.showGoal(ctx);\n\t\treturn;\n\t}\n\tconst owner = runtime as GoalRuntime;\n\tconst generation = owner.menuGeneration;\n\tconst ownerSignal = owner.menuController?.signal;\n\tconst isMenuCurrent = () =>\n\t\towner.menuController === undefined ||\n\t\t(generation === owner.menuGeneration && !owner.menuController.signal.aborted);\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isMenuCurrent()) return;\n\tlet displayedGoal: ActiveGoal | undefined;\n\tlet displayedBudgetGoal: ActiveGoal | undefined;\n\tlet displayedBudgetValue: number | undefined;\n\tlet displayedBudgetUsage: number | undefined;\n\tlet displayedBudgetStatus: ActiveGoal[\"status\"] | undefined;\n\tconst menu = defineMenu<undefined, GoalMenuScreen, GoalMenuAction, ExtensionCommandContext>({\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: () => {\n\t\t\t\trefreshGoalMenuState(runtime, ctx);\n\t\t\t\tconst state = buildGoalMenuState(runtime);\n\t\t\t\tdisplayedGoal = runtime.activeGoal;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Goal\",\n\t\t\t\t\tlines: state.title.split(\"\\n\").slice(1),\n\t\t\t\t\titems: state.actions.map(goalMainMenuItem),\n\t\t\t\t\thint: \"close\",\n\t\t\t\t};\n\t\t\t},\n\t\t\t\"start-budget\": () => {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Choose token budget\",\n\t\t\t\t\tlines: tokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\t\titems: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"25k\",\n\t\t\t\t\t\t\tlabel: \"25k \u2014 Lower token ceiling\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 25k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"100k\",\n\t\t\t\t\t\t\tlabel: \"100k \u2014 Suggested\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 100k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"300k\",\n\t\t\t\t\t\t\tlabel: \"300k \u2014 Higher token ceiling\",\n\t\t\t\t\t\t\tdescription: \"Set the cumulative token limit to 300k.\",\n\t\t\t\t\t\t\taction: \"start-with-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"custom\",\n\t\t\t\t\t\t\tlabel: \"Set a custom budget\u2026\",\n\t\t\t\t\t\t\tdescription: \"Enter an exact cumulative token limit.\",\n\t\t\t\t\t\t\tto: \"start-custom-budget\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t\t],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\t\"start-custom-budget\": () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Custom token budget\",\n\t\t\t\tlines: customTokenBudgetGuidance(runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\tplaceholder: \"100k\",\n\t\t\t\taction: \"start-with-custom-budget\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\t\"increase-budget\": () => {\n\t\t\t\tconst goal = runtime.activeGoal;\n\t\t\t\tdisplayedBudgetGoal = goal;\n\t\t\t\tdisplayedBudgetValue = goal?.tokenBudget;\n\t\t\t\tdisplayedBudgetUsage = goal?.tokensUsed;\n\t\t\t\tdisplayedBudgetStatus = goal?.status;\n\t\t\t\tif (goal && goal.tokensUsed >= Number.MAX_SAFE_INTEGER) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"detail\",\n\t\t\t\t\t\ttitle: \"Increase token budget unavailable\",\n\t\t\t\t\t\tlines: [\n\t\t\t\t\t\t\t`Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,\n\t\t\t\t\t\t\t\"No larger safe whole-number token budget is available. Progress remains saved; choose Back and clear or replace the goal when ready.\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\thint: \"back\",\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"input\",\n\t\t\t\t\ttitle: \"Increase token budget\",\n\t\t\t\t\tlines: goal\n\t\t\t\t\t\t? increaseTokenBudgetGuidance(goal, runtime.settings.continuationLimits.automaticTurns)\n\t\t\t\t\t\t: [\"The budget-limited goal is no longer available. Return to the Goal menu.\"],\n\t\t\t\t\tplaceholder: goal ? suggestedIncreasedBudget(goal) : \"300k\",\n\t\t\t\t\taction: \"submit-increase-budget\",\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tsafety: () => {\n\t\t\t\tconst goal = runtime.activeGoal;\n\t\t\t\tdisplayedGoal = goal;\n\t\t\t\tconst limit = runtime.settings.continuationLimits.automaticTurns;\n\t\t\t\tconst used = goal?.automaticModelTurns ?? 0;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Automatic work paused\",\n\t\t\t\t\tlines: goal\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tautomaticPauseSummary(used, limit),\n\t\t\t\t\t\t\t\t`${safeGoalMenuText(goal.text)} is preserved.`,\n\t\t\t\t\t\t\t\t`${formatInteger(goal.tokensUsed)} cumulative tokens and ${formatDuration(goal.timeUsedSeconds)} active time are preserved.`,\n\t\t\t\t\t\t\t\t\"The objective and usage are preserved.\",\n\t\t\t\t\t\t\t\tlimit === null\n\t\t\t\t\t\t\t\t\t? \"Continuing resets the counter to 0 and resumes with Unlimited automatic work.\"\n\t\t\t\t\t\t\t\t\t: `Continuing resets the counter to 0 and allows up to ${limit} more automatic model responses.`,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [\"The paused goal is no longer available. Return to the Goal menu.\"],\n\t\t\t\t\titems: goal\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"continue\",\n\t\t\t\t\t\t\t\t\tlabel:\n\t\t\t\t\t\t\t\t\t\tlimit === null\n\t\t\t\t\t\t\t\t\t\t\t? \"Continue \u2014 Unlimited\"\n\t\t\t\t\t\t\t\t\t\t\t: `Continue \u2014 up to ${limit} more responses`,\n\t\t\t\t\t\t\t\t\taction: \"safety-resume\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"settings\",\n\t\t\t\t\t\t\t\t\tlabel: \"Change automatic-work limit\u2026\",\n\t\t\t\t\t\t\t\t\taction: \"safety-settings\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" as const },\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [{ id: \"back\", label: \"Back\", action: \"back\" as const }],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tstatus: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Goal status\",\n\t\t\t\tlines: runtime.activeGoal\n\t\t\t\t\t? goalSummary(\n\t\t\t\t\t\t\truntime.activeGoal,\n\t\t\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\t\t).split(\"\\n\")\n\t\t\t\t\t: [\"No goal is currently set.\"],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\thelp: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Goal help\",\n\t\t\t\tlines: goalHelp().split(\"\\n\").slice(1),\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tstart: async () => {\n\t\t\t\tawait startFromMenu(commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"start-with-budget\": async ({ itemId, signal }) => {\n\t\t\t\tconst budget = parseTokenBudget(itemId);\n\t\t\t\tif (budget === undefined) return { kind: \"rejected\" };\n\t\t\t\treturn startBudgetedGoal(\n\t\t\t\t\tcommands,\n\t\t\t\t\tctx,\n\t\t\t\t\tbudget,\n\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\tsignal,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t\t\"stay\",\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"start-with-custom-budget\": async ({ value, signal }) => {\n\t\t\t\tconst budget = parseTokenBudget(value ?? \"\");\n\t\t\t\tif (budget === undefined) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t\"Enter a positive token amount, for example 25k, 300k, or 1.5m.\",\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\treturn startBudgetedGoal(\n\t\t\t\t\tcommands,\n\t\t\t\t\tctx,\n\t\t\t\t\tbudget,\n\t\t\t\t\truntime.settings.continuationLimits.automaticTurns,\n\t\t\t\t\tsignal,\n\t\t\t\t\tisMenuCurrent,\n\t\t\t\t\t\"back\",\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"submit-increase-budget\": async ({ value, signal }) => {\n\t\t\t\tconst goal = displayedBudgetGoal;\n\t\t\t\tconst budget = parseTokenBudget(value ?? \"\");\n\t\t\t\tif (budget === undefined) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t\"Enter a positive token amount, for example 300k, 1.5m, or 300000.\",\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t!goal ||\n\t\t\t\t\t!requireCurrentBudgetPreview(\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tdisplayedBudgetValue,\n\t\t\t\t\t\tdisplayedBudgetUsage,\n\t\t\t\t\t\tdisplayedBudgetStatus,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t}\n\t\t\t\tif (budget <= goal.tokensUsed) {\n\t\t\t\t\tnotifyTerminal(\n\t\t\t\t\t\tctx.ui,\n\t\t\t\t\t\t`Enter a new cumulative total greater than current usage (${formatCompactTokenCount(goal.tokensUsed)}).`,\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\"Increase goal budget?\",\n\t\t\t\t\tincreaseBudgetPreview(goal, budget, runtime.settings.continuationLimits.automaticTurns),\n\t\t\t\t);\n\t\t\t\tif (signal.aborted || !isMenuCurrent()) return { kind: \"close\" };\n\t\t\t\tif (!confirmed) return { kind: \"rejected\" };\n\t\t\t\tif (\n\t\t\t\t\t!requireCurrentBudgetPreview(\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tdisplayedBudgetValue,\n\t\t\t\t\t\tdisplayedBudgetUsage,\n\t\t\t\t\t\tdisplayedBudgetStatus,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t}\n\t\t\t\tawait commands.editGoal(goal.text, budget, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tpause: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tcommands.pauseGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tresume: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"safety-resume\": async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait commands.resumeGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"safety-settings\": async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tconst expectedGoal = displayedGoal;\n\t\t\t\tawait showSettings(ctx, \"automatic\");\n\t\t\t\tif (!isMenuCurrent()) return { kind: \"close\" };\n\t\t\t\tif (!requireCurrentMenuGoal(runtime, expectedGoal, ctx)) return { kind: \"stay\" };\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tedit: async () => {\n\t\t\t\tif (!displayedGoal || !requireCurrentMenuGoal(runtime, displayedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait editFromMenu(runtime, commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\treplace: async () => {\n\t\t\t\tawait startFromMenu(commands, ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tsettings: async () => {\n\t\t\t\tawait showSettings(ctx);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tclear: async () => {\n\t\t\t\tconst previewedGoal = runtime.activeGoal;\n\t\t\t\tif (!(await confirmClear(runtime, ctx))) return { kind: \"stay\" };\n\t\t\t\tif (previewedGoal && !requireCurrentMenuGoal(runtime, previewedGoal, ctx)) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tcommands.clearGoal(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tback: async () => ({ kind: \"back\" }),\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: ownerSignal,\n\t\tisCurrent: isMenuCurrent,\n\t});\n}\n\nfunction goalMainMenuItem(label: string): ActionMenuItem<GoalMenuScreen, GoalMenuAction> {\n\tif (label === GOAL_MENU_ACTIONS.status) return { id: \"status\", label, to: \"status\" as const };\n\tif (label === GOAL_MENU_ACTIONS.startBudget) {\n\t\treturn { id: \"start-budget\", label, to: \"start-budget\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.increaseBudget) {\n\t\treturn { id: \"increase-budget\", label, to: \"increase-budget\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.reviewSafety) {\n\t\treturn { id: \"review-safety\", label, to: \"safety\" as const };\n\t}\n\tif (label === GOAL_MENU_ACTIONS.help) return { id: \"help\", label, to: \"help\" as const };\n\tif (label === GOAL_MENU_ACTIONS.close) return { id: \"close\", label, close: true as const };\n\tconst actions = new Map<string, GoalMenuAction>([\n\t\t[GOAL_MENU_ACTIONS.start, \"start\"],\n\t\t[GOAL_MENU_ACTIONS.pause, \"pause\"],\n\t\t[GOAL_MENU_ACTIONS.resume, \"resume\"],\n\t\t[GOAL_MENU_ACTIONS.edit, \"edit\"],\n\t\t[GOAL_MENU_ACTIONS.replace, \"replace\"],\n\t\t[GOAL_MENU_ACTIONS.settings, \"settings\"],\n\t\t[GOAL_MENU_ACTIONS.clear, \"clear\"],\n\t]);\n\treturn { id: actions.get(label) ?? label, label, action: actions.get(label) ?? \"settings\" };\n}\n\nfunction refreshGoalMenuState(runtime: GoalMenuRuntimeView, ctx: ExtensionCommandContext) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return;\n\truntime.recordGoalUsage?.(goal, ctx);\n\truntime.persistGoal?.(goal);\n\truntime.updateStatus?.(ctx, goal);\n}\n\nasync function startFromMenu(commands: GoalCommandController, ctx: ExtensionCommandContext) {\n\tconst objective = (await ctx.ui.editor(\"Goal objective\", \"\"))?.trim();\n\tif (!objective) return;\n\tawait commands.startGoal(objective, undefined, ctx);\n}\n\nasync function startBudgetedGoal(\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n\tbudget: number,\n\tautomaticLimit: number | null,\n\tsignal: AbortSignal,\n\tisMenuCurrent: () => boolean,\n\tcancelTransition: \"stay\" | \"back\",\n) {\n\tconst objective = (\n\t\tawait ctx.ui.editor(\n\t\t\t`Goal objective \u00B7 Token budget ${formatCompactTokenCount(budget)} \u00B7 ${automaticLimit === null ? \"Automatic Unlimited\" : `Automatic limit ${automaticLimit}`}`,\n\t\t\t\"\",\n\t\t)\n\t)?.trim();\n\tif (signal.aborted || !isMenuCurrent()) return { kind: \"close\" as const };\n\tif (!objective) return { kind: cancelTransition } as const;\n\tawait commands.startGoal(\n\t\tobjective,\n\t\tbudget,\n\t\tctx,\n\t\tundefined,\n\t\t() => !signal.aborted && isMenuCurrent(),\n\t\t() => !signal.aborted && isMenuCurrent(),\n\t);\n\treturn { kind: \"close\" as const };\n}\n\nfunction tokenBudgetGuidance(automaticLimit: number | null) {\n\treturn [\n\t\t\"Set the maximum cumulative token usage for this goal.\",\n\t\t\"The final model call may exceed the limit; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction customTokenBudgetGuidance(automaticLimit: number | null) {\n\treturn [\n\t\t\"Enter the maximum cumulative token usage for this goal.\",\n\t\t\"Examples: 25k, 300k, 1.5m, or 300000.\",\n\t\t\"The final model call may exceed this value; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction automaticBudgetGuidance(automaticLimit: number | null) {\n\treturn automaticLimit === null\n\t\t? \"Automatic work has no response-count cap.\"\n\t\t: `Automatic work will also pause after ${automaticLimit} responses.`;\n}\n\nfunction increaseTokenBudgetGuidance(goal: ActiveGoal, automaticLimit: number | null) {\n\treturn [\n\t\t`Current budget: ${formatBudgetDecisionValue(goal.tokenBudget ?? 0)}`,\n\t\t`Current usage: ${formatBudgetDecisionValue(goal.tokensUsed)}`,\n\t\t`Enter a new cumulative total greater than ${formatBudgetDecisionValue(goal.tokensUsed)}.`,\n\t\t\"Examples: 300k, 1.5m, or 300000.\",\n\t\t\"The final model call may exceed the limit; this is not a dollar-cost cap.\",\n\t\tautomaticBudgetGuidance(automaticLimit),\n\t];\n}\n\nfunction suggestedIncreasedBudget(goal: ActiveGoal) {\n\tconst floor = Math.max(goal.tokensUsed, goal.tokenBudget ?? 0);\n\tfor (const suggestion of [25_000, 100_000, 300_000, 500_000, 1_000_000]) {\n\t\tif (suggestion > floor) return formatCompactTokenCount(suggestion);\n\t}\n\treturn formatCompactTokenCount(\n\t\tMath.min(Number.MAX_SAFE_INTEGER, Math.max(Math.floor(floor) + 1, Math.ceil(floor * 2))),\n\t);\n}\n\nfunction formatBudgetDecisionValue(value: number) {\n\tconst compact = formatCompactTokenCount(value);\n\tif (value < 1_000 || value % 1_000 === 0) return compact;\n\treturn `${compact} (${formatInteger(value)} tokens)`;\n}\n\nfunction increaseBudgetPreview(goal: ActiveGoal, budget: number, automaticLimit: number | null) {\n\treturn [\n\t\t`Goal: ${safeGoalMenuText(goal.text, 4_000)}`,\n\t\t`Budget: ${formatCompactTokenCount(goal.tokenBudget ?? 0)} \u2192 ${formatCompactTokenCount(budget)}`,\n\t\t`Current usage: ${formatCompactTokenCount(goal.tokensUsed)}`,\n\t\tautomaticLimit === null\n\t\t\t? \"Automatic work: Unlimited after resume\"\n\t\t\t: `Automatic work: up to ${automaticLimit} more responses after resume`,\n\t\t\"The goal will resume immediately.\",\n\t].join(\"\\n\");\n}\n\nasync function editFromMenu(\n\truntime: GoalMenuRuntimeView,\n\tcommands: GoalCommandController,\n\tctx: ExtensionCommandContext,\n) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return;\n\tconst objective = (await ctx.ui.editor(\"Edit goal objective\", goal.text))?.trim();\n\tif (!objective || objective === goal.text) return;\n\tif (!requireCurrentMenuGoal(runtime, goal, ctx)) return;\n\tif (goal.status === \"active\") {\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Apply goal edit?\",\n\t\t\t`Current goal:\\n${safeGoalMenuText(goal.text, 4_000)}\\n\\nUpdated goal:\\n${safeGoalMenuText(objective, 4_000)}\\n\\nApplying this edit starts a new guarded goal instance.`,\n\t\t);\n\t\tif (!confirmed || !requireCurrentMenuGoal(runtime, goal, ctx)) return;\n\t}\n\tawait commands.editGoal(objective, undefined, ctx);\n}\n\nasync function confirmClear(runtime: GoalMenuRuntimeView, ctx: ExtensionCommandContext) {\n\tconst goal = runtime.activeGoal;\n\tif (!goal) return false;\n\treturn ctx.ui.confirm(\n\t\t\"Clear goal?\",\n\t\t`Remove this goal:\\n\\n${safeGoalMenuText(goal.text, 4_000)}\\n\\nThis cannot be undone.`,\n\t);\n}\n\nfunction requireCurrentBudgetPreview(\n\truntime: GoalMenuRuntimeView,\n\texpectedGoal: ActiveGoal,\n\texpectedBudget: number | undefined,\n\texpectedUsage: number | undefined,\n\texpectedStatus: ActiveGoal[\"status\"] | undefined,\n\tctx: ExtensionCommandContext,\n) {\n\tconst current = runtime.activeGoal;\n\tif (\n\t\tcurrent?.id === expectedGoal.id &&\n\t\tcurrent.tokenBudget === expectedBudget &&\n\t\tcurrent.tokensUsed === expectedUsage &&\n\t\tcurrent.status === expectedStatus\n\t) {\n\t\treturn true;\n\t}\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\t\"The goal changed or its usage changed while the budget dialog was open. Reopen /goal and try again.\",\n\t\t\"warning\",\n\t);\n\treturn false;\n}\n\nfunction requireCurrentMenuGoal(\n\truntime: GoalMenuRuntimeView,\n\texpected: ActiveGoal,\n\tctx: ExtensionCommandContext,\n) {\n\tif (runtime.activeGoal?.id === expected.id) return true;\n\tnotifyTerminal(\n\t\tctx.ui,\n\t\t\"The active goal changed while the dialog was open. Reopen /goal and try again.\",\n\t\t\"warning\",\n\t);\n\treturn false;\n}\n\nfunction displayStatus(status?: ActiveGoal[\"status\"]) {\n\tif (!status) return \"No goal\";\n\tif (status === \"usage_limited\") return \"Usage limited\";\n\tif (status === \"budget_limited\") return \"Budget limited\";\n\treturn status[0]?.toUpperCase() + status.slice(1);\n}\n\nfunction formatTokenCount(tokens: number) {\n\treturn String(tokens);\n}\n\nfunction formatInteger(value: number) {\n\treturn value.toLocaleString(\"en-US\", { maximumFractionDigits: 0 });\n}\n\nfunction automaticPauseSummary(used: number, limit: number | null) {\n\tif (limit === null) {\n\t\treturn `Goal paused after ${used} responses at its previous safety limit. Current limit: Unlimited.`;\n\t}\n\tif (used < limit) {\n\t\treturn `Goal paused after ${used} responses at its previous safety limit. Current automatic-work limit: ${limit}.`;\n\t}\n\treturn `Goal reached its ${used}-of-${limit} safety limit.`;\n}\n\nfunction goalHelp() {\n\treturn [\n\t\t\"Goal menu\",\n\t\t\"Use the menu for guided status, edits, settings, and confirmations.\",\n\t\t\"Direct routes remain available for deterministic workflows:\",\n\t\t\"/goal <objective>\",\n\t\t\"/goal status | pause | resume | edit | clear\",\n\t\t\"/goal --tokens 100k <objective>\",\n\t\t\"Escape cancels the current menu or input without changing goal state.\",\n\t].join(\"\\n\");\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAYO,IAAM,oBAAoB;AAAA,EAChC,OAAO;AAAA,EACP,aAAa;AAAA,EACb,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACR;AAuCO,SAAS,mBAAmB,SAA6C;AAC/E,QAAM,OAAO,QAAQ;AACrB,QAAM,yBACL,MAAM,WAAW,YAAY,KAAK,qBAAqB;AACxD,QAAM,gBAAgB,MAAM,UAAU,iBAAiB,KAAK,QAAQ,MAAM,IAAI;AAC9E,QAAM,QAAQ,yBACX,+CACA,gBACC,kBAAa,aAAa,KAC1B,cAAc,MAAM,MAAM;AAC9B,QAAM,qBAAqB,QAAQ,SAAS,mBAAmB;AAC/D,QAAM,OAAO,MAAM,uBAAuB;AAC1C,QAAM,qBACL,uBAAuB,OACpB,mBAAmB,IAAI,8BACvB,mBAAmB,IAAI,OAAO,kBAAkB,aAChD,OAAO,qBAAqB,SAAM,qBAAqB,IAAI,eAAe,EAC3E;AACH,QAAM,QAAQ,OACX;AAAA,IACA,aAAU,KAAK;AAAA,IACf,iBAAiB,KAAK,IAAI;AAAA,IAC1B,UACC,KAAK,gBAAgB,SAClB,eAAe,KAAK,eAAe,IACnC,GAAGA,kBAAiB,KAAK,UAAU,CAAC,IAAIA,kBAAiB,KAAK,WAAW,CAAC,EAC9E;AAAA,IACA;AAAA,IACA,GAAI,yBACD,CAAC,+DAA+D,IAChE,CAAC;AAAA,EACL,EAAE,KAAK,IAAI,IACV;AAAA,IACA,aAAU,KAAK;AAAA,IACf;AAAA,IACA,uBAAuB,OACpB,+CACA,+CAA+C,kBAAk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