@narumitw/pi-goal 0.54.4 → 0.54.5
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/README.md +41 -166
- package/dist/chunks/{chunk-QWIUWKRW.js → chunk-VJ5LR26S.js} +57 -77
- package/dist/chunks/chunk-VJ5LR26S.js.map +7 -0
- package/dist/chunks/{chunk-UQRRW4CY.js → chunk-WQIA35U2.js} +6 -5
- package/dist/chunks/chunk-WQIA35U2.js.map +7 -0
- package/dist/chunks/{menu-WEFDREGC.js → menu-JMGWQZIT.js} +7 -22
- package/dist/chunks/menu-JMGWQZIT.js.map +7 -0
- package/dist/chunks/{settings-ui-MVYTTBHW.js → settings-ui-JG3PFRB5.js} +6 -18
- package/dist/chunks/settings-ui-JG3PFRB5.js.map +7 -0
- package/dist/index.ts +92 -126
- package/dist/index.ts.map +2 -2
- package/docs/managing-goals.md +47 -0
- package/docs/settings.md +91 -0
- package/package.json +55 -55
- package/src/accounting.ts +62 -66
- package/src/command-registration.ts +104 -102
- package/src/command.ts +101 -112
- package/src/commands.ts +465 -501
- package/src/errors.ts +127 -122
- package/src/goal-contract.ts +64 -64
- package/src/goal.ts +25 -25
- package/src/lifecycle.ts +615 -628
- package/src/markers.ts +6 -6
- package/src/menu.ts +565 -591
- package/src/persistence.ts +177 -192
- package/src/prompts.ts +53 -67
- package/src/run-protocol.ts +299 -325
- package/src/runtime.ts +1422 -1495
- package/src/safety.ts +51 -51
- package/src/settings-ui.ts +366 -393
- package/src/settings.ts +134 -147
- package/src/tool-policy.ts +6 -6
- package/src/tools.ts +360 -371
- package/src/wait.ts +47 -51
- package/src/workflow-mutex.ts +68 -68
- package/dist/chunks/chunk-QWIUWKRW.js.map +0 -7
- package/dist/chunks/chunk-UQRRW4CY.js.map +0 -7
- package/dist/chunks/menu-WEFDREGC.js.map +0 -7
- package/dist/chunks/settings-ui-MVYTTBHW.js.map +0 -7
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
Give Pi one session-scoped objective and let it continue after Pi becomes fully idle.
|
|
6
6
|
Goal mode stops when work completes, pauses, waits for an external event, or reaches a safety limit.
|
|
7
|
-
|
|
8
7
|
Explicit completion, blocker, and wait tools give each managed run a clear stopping reason.
|
|
9
8
|
|
|
10
9
|
## ✨ Features
|
|
@@ -54,88 +53,29 @@ Use the manager to review, pause, resume, edit, or clear the current goal.
|
|
|
54
53
|
|
|
55
54
|
## ⚙️ Settings
|
|
56
55
|
|
|
57
|
-
Settings
|
|
58
|
-
|
|
56
|
+
Use `/goal` → **Settings…** in TUI mode, or edit `<getAgentDir()>/pi-goal.json` (normally `~/.pi/agent/pi-goal.json`).
|
|
57
|
+
A missing file uses the defaults without creating it:
|
|
59
58
|
|
|
60
59
|
```json
|
|
61
60
|
{
|
|
62
|
-
"rpc": {
|
|
63
|
-
"enabled": false
|
|
64
|
-
},
|
|
65
61
|
"continuationLimits": {
|
|
66
62
|
"automaticTurns": 25,
|
|
67
63
|
"noProgressTurns": 3
|
|
68
|
-
}
|
|
64
|
+
},
|
|
65
|
+
"rpc": { "enabled": false }
|
|
69
66
|
}
|
|
70
67
|
```
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
The
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
It defaults to **Off** and controls cooperation, not extension permissions.
|
|
83
|
-
|
|
84
|
-
Custom number inputs accept only positive safe integers.
|
|
85
|
-
Choose **Unlimited** or **Off** explicitly instead of entering zero, a negative number, a decimal, or text.
|
|
86
|
-
Interactive changes run in order, publish atomically, preserve unknown fields, and apply to the current runtime.
|
|
87
|
-
A successful save updates the visible state immediately.
|
|
88
|
-
A failed save restores the prior value and reports the settings path so it can be retried.
|
|
89
|
-
Escape returns to the previous screen without reverting changes that were already saved.
|
|
90
|
-
|
|
91
|
-
Pi-goal registers `goal_complete`, `goal_blocked`, and `goal_wait` once and keeps their schemas stable from startup.
|
|
92
|
-
Visible Goal tools do not mean Goal mode is active, and only the latest effective active Goal contract authorizes their use.
|
|
93
|
-
Pi-goal never widens a restrictive active-tool policy; activation rejects when required terminal tools are missing, and an active Goal pauses if they later disappear.
|
|
94
|
-
The retired `toolVisibility` key is ignored and preserved as unknown data when another setting is saved.
|
|
95
|
-
|
|
96
|
-
`experimental.goals` is a removed legacy setting.
|
|
97
|
-
If it remains `true`, pi-goal accepts the settings file and ignores the old queue feature.
|
|
98
|
-
Affected users see a warning that recommends `/goal edit` for an active objective or `/goal <objectives>` when no goal is active.
|
|
99
|
-
Later settings saves preserve unknown legacy fields instead of deleting them.
|
|
100
|
-
|
|
101
|
-
`rpc.enabled` accepts a boolean and defaults to `false`.
|
|
102
|
-
When disabled, a valid managed-run start receives `RPC_DISABLED`; manual and restored Goals remain unchanged.
|
|
103
|
-
A Settings-menu change applies immediately after its atomic save.
|
|
104
|
-
Disabling rejects new starts but lets an already accepted run continue publishing its exact state and accept its exact cancellation until terminal, avoiding stranded work.
|
|
105
|
-
Reload, replacement, and shutdown clear that in-memory ownership.
|
|
106
|
-
|
|
107
|
-
`continuationLimits` controls the automatic-work safety guards:
|
|
108
|
-
|
|
109
|
-
- `automaticTurns` accepts a positive safe integer or `null` and defaults to `25`.
|
|
110
|
-
It counts every completed normal `turn_end` owned by automatically started Goal work, including model responses inside tool loops and matching Pi-owned retries.
|
|
111
|
-
The user-triggered kickoff, resume, edit, and ordinary user runs are not charged.
|
|
112
|
-
At the limit, the goal becomes `paused` with cause `continuation_limit` and pending continuation or recovery is cancelled.
|
|
113
|
-
The current operation is aborted before a 26th normal response starts.
|
|
114
|
-
Pi may invoke a provider adapter once more with an already-aborted signal to produce its synthetic terminal event; that event is not counted and cannot resume Goal work.
|
|
115
|
-
Set this field explicitly to `null` to opt into Unlimited mode; existing explicit `null` values remain compatible.
|
|
116
|
-
- `noProgressTurns` is a positive safe integer and defaults to `3`.
|
|
117
|
-
At the end of an automatic run, pi-goal compares visible assistant text after Unicode normalization, lowercase conversion, control-character removal, and whitespace collapse.
|
|
118
|
-
Thinking and tool blocks are excluded; empty and punctuation-only output are equivalent.
|
|
119
|
-
Consecutive empty or identical tool-free outputs increment the repeat count.
|
|
120
|
-
Different non-empty output starts a new run at one, and any attempted tool call resets it.
|
|
121
|
-
Set this field to `null` to disable only this heuristic.
|
|
122
|
-
|
|
123
|
-
Settings are reread at Pi startup, session replacement, and `/reload`.
|
|
124
|
-
Direct file edits are not watched, while Goal-menu changes apply immediately.
|
|
125
|
-
A missing file remains absent and uses the built-in defaults.
|
|
126
|
-
The first successful settings change creates the file atomically; later saves preserve unknown fields.
|
|
127
|
-
|
|
128
|
-
Omitted fields use the defaults above.
|
|
129
|
-
Invalid or malformed existing settings are never overwritten; they produce a warning and fall back to all defaults.
|
|
130
|
-
In the TUI, Goal Settings becomes a read-only summary that identifies the invalid file and tells you to fix it and run `/reload`.
|
|
131
|
-
|
|
132
|
-
Plan mode or another restrictive policy may hide Goal tools.
|
|
133
|
-
Pi-goal does not override that policy during restore or later turns.
|
|
134
|
-
Activation fails when required terminal tools are unavailable, and an active goal pauses without automatic continuation if they disappear.
|
|
135
|
-
A restrictive allowlist created before `goal_wait` existed can still run ordinary Goals with `goal_complete` and `goal_blocked`.
|
|
136
|
-
The model cannot enter external waiting until that allowlist also includes `goal_wait`.
|
|
137
|
-
The pause aborts a Goal-owned kickoff, resume, active edit, or automatic-continuation prompt.
|
|
138
|
-
It does not cancel or stale-block unrelated user or extension turns, including startup follow-ups after a restrictive restore.
|
|
69
|
+
The automatic-work limit counts model responses in Goal-owned automatic work, including tool loops.
|
|
70
|
+
The no-progress guard pauses repeated tool-free output.
|
|
71
|
+
Choose **Unlimited** or **Off** explicitly to disable the corresponding guard; Unlimited requires confirmation and can continue consuming tokens and provider cost.
|
|
72
|
+
Neither these guards nor an optional token budget is a dollar-cost cap.
|
|
73
|
+
|
|
74
|
+
Menu saves apply immediately, run in order, preserve unknown fields, and publish atomically.
|
|
75
|
+
Manual edits apply at session start or `/reload`.
|
|
76
|
+
Invalid settings remain untouched, use defaults, and make the TUI Settings screen read-only until repaired and reloaded.
|
|
77
|
+
|
|
78
|
+
Read the [settings reference](./docs/settings.md) for exact counting rules, accepted values, managed-run RPC behavior, tool-policy restrictions, and legacy-setting recovery.
|
|
139
79
|
|
|
140
80
|
## 🔒 Security and privacy
|
|
141
81
|
|
|
@@ -178,61 +118,24 @@ Guaranteed coexistence with Plan mode requires `@narumitw/pi-plan-mode` `0.52.0`
|
|
|
178
118
|
|
|
179
119
|
## 💬 Commands
|
|
180
120
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
Custom input accepts examples such as `300000`, `300k`, `2.5k`, and `1.5m`; invalid input retains its draft for correction.
|
|
200
|
-
Status, Settings, Help, invalid-settings guidance, Clear, and Close remain shallow, labeled routes.
|
|
201
|
-
Arrow keys navigate, Enter selects or submits, Escape goes Back, and Ctrl+C closes the full flow.
|
|
202
|
-
- In RPC mode, bare `/goal` and `/goal status` report the current summary through an observable notification without opening terminal UI.
|
|
203
|
-
Pi exposes no extension-command output channel in print or JSON mode.
|
|
204
|
-
Those routes return an explicit unsupported-mode error instead of treating stderr as status output.
|
|
205
|
-
- Menu-driven Replace and Clear actions preview the exact affected goal and require confirmation.
|
|
206
|
-
Existing direct routes remain immediate for compatibility and automation.
|
|
207
|
-
- `/goal <goal_to_complete>` starts goal mode.
|
|
208
|
-
If another unfinished goal exists, Pi asks for confirmation before replacing it with a new active goal and resetting its usage counters.
|
|
209
|
-
Failed kickoff delivery clears a new goal or restores the exact prior Goal and tool-policy snapshot; a previously active or waiting Goal keeps its existing workflow ownership.
|
|
210
|
-
- `/goal --tokens 100k <goal_to_complete>` starts or replaces goal mode with a token budget.
|
|
211
|
-
`k` and `m` suffixes are accepted, for example `100k` or `1.5m`.
|
|
212
|
-
- `/goal edit <goal_to_complete>` updates the existing goal objective without resetting usage counters.
|
|
213
|
-
A successful active edit rotates the stale-turn guard and starts a fresh safety epoch.
|
|
214
|
-
Paused, blocked, and usage-limited goals stay stopped and retain their safety state until resume.
|
|
215
|
-
A budget-limited goal reactivates only when `edit --tokens` raises its budget above current usage.
|
|
216
|
-
Failed prompt delivery restores the exact previous Goal, guard id, safety counters, cause, tool-policy snapshot, and active ownership when applicable.
|
|
217
|
-
- `/goal pause` stops prompt injection and auto-continuation, aborts the current turn, and keeps the goal for later resume.
|
|
218
|
-
Only active goals can be paused.
|
|
219
|
-
- `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it.
|
|
220
|
-
When the queued resume prompt starts, pi-goal rotates the stale-turn guard id, resets the automatic-response and repeat safety epoch, and clears a safety-pause cause.
|
|
221
|
-
The command reports the new finite epoch or explicit Unlimited state.
|
|
222
|
-
Objective, cumulative usage, and elapsed time are preserved.
|
|
223
|
-
If prompt delivery fails, the original stopped state, guard id, counters, fingerprint, and cause are restored.
|
|
224
|
-
- `/goal clear` clears the current goal, status, pending continuation, inert legacy queue state, and legacy persisted state for the current working directory.
|
|
225
|
-
It does not abort unrelated in-flight work.
|
|
226
|
-
|
|
227
|
-
The experimental ordered-goal queue has been removed.
|
|
228
|
-
Use `/goal edit <objective>` to reprioritize the active objective instead.
|
|
229
|
-
For example, if `task b` is complete and `task c` is in progress, edit the objective to say: `task b is complete; do task a next; after task a, continue task c, then task d; do not redo task b unless verification shows it is incomplete.`
|
|
230
|
-
|
|
231
|
-
Former queue command words such as `add`, `prioritize`, `drop-last`, `skip`, `push`, `unshift`, `pop`, and `shift` are ordinary objective text for unaffected users.
|
|
232
|
-
If a session still has legacy queue settings or persisted queue state, those words show a migration warning instead of replacing the active Goal.
|
|
233
|
-
|
|
234
|
-
Goal objectives are limited to 4,000 characters.
|
|
235
|
-
Put longer instructions in a file and reference the file path from `/goal`.
|
|
121
|
+
| Command | Purpose |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `/goal` | Manage the current goal in TUI; report its summary in RPC. |
|
|
124
|
+
| `/goal status` | Report the current goal and progress. |
|
|
125
|
+
| `/goal [--tokens <budget>] <objective>` | Start automatic work, confirming replacement of an unfinished goal. |
|
|
126
|
+
| `/goal edit [--tokens <budget>] <objective>` | Update the objective or budget without resetting cumulative usage. |
|
|
127
|
+
| `/goal pause` | Pause an active goal and abort its current turn, preserving progress. |
|
|
128
|
+
| `/goal resume` | Resume an eligible stopped goal or wake an active waiting goal. |
|
|
129
|
+
| `/goal clear` (alias: `stop`) | Immediately clear the goal and pending continuation, not unrelated in-flight work. |
|
|
130
|
+
|
|
131
|
+
All routes support TUI and RPC; bare `/goal` and `status` reject print and JSON modes, while direct mutation routes remain available.
|
|
132
|
+
Objectives are limited to 4,000 characters; reference a file for longer instructions.
|
|
133
|
+
`--tokens` must precede the objective and accepts positive amounts such as `100k` or `1.5m`.
|
|
134
|
+
`status`, `pause`, `resume`, and `clear`/`stop` reject trailing arguments; other text starts an objective.
|
|
135
|
+
|
|
136
|
+
Starting, editing an active goal, or resuming can trigger paid model work; [token budgets](#-token-budgets-and-elapsed-time) are not dollar-cost caps.
|
|
137
|
+
Direct Clear is immediate, while menu Clear requires confirmation.
|
|
138
|
+
See [Managing goals](./docs/managing-goals.md) for safety-epoch resets, failed-delivery recovery, budget-limited edits, and migration from removed queue commands.
|
|
236
139
|
|
|
237
140
|
## 🛠️ Tools
|
|
238
141
|
|
|
@@ -528,46 +431,18 @@ No compatibility aliases are registered.
|
|
|
528
431
|
|
|
529
432
|
## 🗂️ Package layout
|
|
530
433
|
|
|
531
|
-
```
|
|
434
|
+
```text
|
|
532
435
|
packages/pi-goal/
|
|
533
|
-
├──
|
|
534
|
-
├──
|
|
535
|
-
│ └──
|
|
536
|
-
├──
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
│ ├── commands.ts # Per-factory user-command controller
|
|
541
|
-
│ ├── tools.ts # Goal completion and blocker tool adapters
|
|
542
|
-
│ ├── lifecycle.ts # Pi session, agent, tool, and compaction event adapter
|
|
543
|
-
│ ├── goal-contract.ts # Deterministic post-compaction model contract
|
|
544
|
-
│ ├── runtime.ts # Per-factory Goal state, transitions, prompts, and budgets
|
|
545
|
-
│ ├── tool-policy.ts # Goal tool names and read-only availability checks
|
|
546
|
-
│ ├── safety.ts # Output normalization and no-progress fingerprint state
|
|
547
|
-
│ ├── wait.ts # External-wait validation and session timer ownership
|
|
548
|
-
│ ├── errors.ts # Pi-aligned provider error and retry classification
|
|
549
|
-
│ ├── markers.ts # Bounded Goal prompt marker parsing and formatting
|
|
550
|
-
│ ├── run-protocol.ts # Default-off managed-run protocol and session ownership
|
|
551
|
-
│ └── *.ts # Package-local parsing, settings, prompts, accounting, and persistence
|
|
552
|
-
├── test/
|
|
553
|
-
├── README.md
|
|
554
|
-
├── LICENSE
|
|
555
|
-
├── tsconfig.json
|
|
556
|
-
└── package.json
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
`index.ts` is the Pi entrypoint and forwards to `goal.ts`; the other source modules are internal.
|
|
560
|
-
The package exposes its Pi extension through `package.json`:
|
|
561
|
-
|
|
562
|
-
```json
|
|
563
|
-
{
|
|
564
|
-
"pi": {
|
|
565
|
-
"extensions": ["./dist/index.ts"]
|
|
566
|
-
}
|
|
567
|
-
}
|
|
436
|
+
├── src/ # State, safety, waiting, settings, and protocol modules
|
|
437
|
+
│ ├── index.ts # Thin Pi entrypoint
|
|
438
|
+
│ └── goal.ts # Goal lifecycle, commands, and tools
|
|
439
|
+
├── dist/ # Generated Jiti runtime
|
|
440
|
+
├── scripts/build-runtime.mjs # Runtime builder
|
|
441
|
+
├── docs/ # Published reference documentation
|
|
442
|
+
└── test/ # Behavior and lifecycle coverage
|
|
568
443
|
```
|
|
569
444
|
|
|
570
|
-
The generated runtime is built from
|
|
445
|
+
The generated runtime is built from `src/index.ts` and does not import back into `src`.
|
|
571
446
|
|
|
572
447
|
## 🔎 Keywords
|
|
573
448
|
|
|
@@ -7,26 +7,18 @@ import {
|
|
|
7
7
|
formatError,
|
|
8
8
|
formatTokenCount,
|
|
9
9
|
isNonNegativeFiniteNumber,
|
|
10
|
+
isStaleContextError,
|
|
10
11
|
nonNegativeFiniteNumber,
|
|
11
12
|
normalizeTokenBudget,
|
|
12
13
|
notifyTerminal,
|
|
13
14
|
safeGoalMenuText,
|
|
14
15
|
truncateNotification,
|
|
15
16
|
updateGoalUsage
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-WQIA35U2.js";
|
|
17
18
|
|
|
18
19
|
// src/command.ts
|
|
19
20
|
var MAX_OBJECTIVE_LENGTH = 4e3;
|
|
20
|
-
var REMOVED_QUEUE_COMMANDS = /* @__PURE__ */ new Set([
|
|
21
|
-
"add",
|
|
22
|
-
"prioritize",
|
|
23
|
-
"drop-last",
|
|
24
|
-
"skip",
|
|
25
|
-
"push",
|
|
26
|
-
"unshift",
|
|
27
|
-
"pop",
|
|
28
|
-
"shift"
|
|
29
|
-
]);
|
|
21
|
+
var REMOVED_QUEUE_COMMANDS = /* @__PURE__ */ new Set(["add", "prioritize", "drop-last", "skip", "push", "unshift", "pop", "shift"]);
|
|
30
22
|
var TOKEN_BUDGET_COMPLETION = {
|
|
31
23
|
value: "--tokens ",
|
|
32
24
|
label: "--tokens",
|
|
@@ -66,8 +58,7 @@ function parseCommand(args) {
|
|
|
66
58
|
const [first, ...rest] = tokens;
|
|
67
59
|
if (first === "pause") return rest.length === 0 ? { kind: "pause" } : "Usage: /goal pause";
|
|
68
60
|
if (first === "resume") return rest.length === 0 ? { kind: "resume" } : "Usage: /goal resume";
|
|
69
|
-
if (first === "clear" || first === "stop")
|
|
70
|
-
return rest.length === 0 ? { kind: "clear" } : "Usage: /goal clear";
|
|
61
|
+
if (first === "clear" || first === "stop") return rest.length === 0 ? { kind: "clear" } : "Usage: /goal clear";
|
|
71
62
|
if (first === "status") return rest.length === 0 ? { kind: "show" } : "Usage: /goal status";
|
|
72
63
|
if (first === "edit") return parseObjective("edit", rest);
|
|
73
64
|
return parseObjective("start", tokens);
|
|
@@ -429,34 +420,31 @@ function loadGoalStateFromSession(ctx) {
|
|
|
429
420
|
const entries = ctx.sessionManager?.getBranch?.() ?? ctx.sessionManager?.getEntries?.() ?? [];
|
|
430
421
|
const canonicalEntry = entries.filter((entry) => entry.type === "custom" && entry.customType === GOAL_STATE_ENTRY_TYPE).pop();
|
|
431
422
|
if (canonicalEntry) return loadCanonicalGoalState(canonicalEntry.data);
|
|
432
|
-
const legacyEntry = entries.filter(
|
|
433
|
-
|
|
434
|
-
).pop();
|
|
435
|
-
return legacyEntry ? loadLegacyGoalsState(legacyEntry.data) : emptyGoalState("none");
|
|
423
|
+
const legacyEntry = entries.filter((entry) => entry.type === "custom" && entry.customType === LEGACY_GOALS_STATE_ENTRY_TYPE).pop();
|
|
424
|
+
return legacyEntry ? loadLegacyGoalsState(legacyEntry.data) : emptyGoalState();
|
|
436
425
|
}
|
|
437
426
|
function loadCanonicalGoalState(data) {
|
|
438
|
-
if (!isRecord2(data)) return emptyGoalState(
|
|
427
|
+
if (!isRecord2(data)) return emptyGoalState();
|
|
439
428
|
const rawGoal = data.goal;
|
|
440
|
-
if (rawGoal !== null && !
|
|
429
|
+
if (rawGoal !== null && !isStoredGoal(rawGoal)) return emptyGoalState();
|
|
441
430
|
const rawQueue = Object.hasOwn(data, "queue") ? data.queue : void 0;
|
|
442
431
|
if (rawQueue !== void 0 && (!Array.isArray(rawQueue) || !rawQueue.every(isQueueGoal))) {
|
|
443
|
-
return emptyGoalState(
|
|
432
|
+
return emptyGoalState();
|
|
444
433
|
}
|
|
445
434
|
const pendingAction = Object.hasOwn(data, "pendingAction") ? normalizeCanonicalPendingAction(data.pendingAction) : void 0;
|
|
446
|
-
if (Object.hasOwn(data, "pendingAction") && !pendingAction) return emptyGoalState(
|
|
435
|
+
if (Object.hasOwn(data, "pendingAction") && !pendingAction) return emptyGoalState();
|
|
447
436
|
const hasQueueFields = rawQueue !== void 0 || pendingAction !== void 0;
|
|
448
|
-
if (hasQueueFields ||
|
|
449
|
-
return legacyQueueState(
|
|
450
|
-
reason: "canonical-queue",
|
|
437
|
+
if (hasQueueFields || isStoredGoal(rawGoal) && rawGoal.status === "queued") {
|
|
438
|
+
return legacyQueueState({
|
|
451
439
|
retainedGoals: countCanonicalLegacyGoals(rawGoal, rawQueue, pendingAction)
|
|
452
440
|
});
|
|
453
441
|
}
|
|
454
|
-
let goal = rawGoal === null ? void 0 : normalizeLoadedGoal(rawGoal);
|
|
442
|
+
let goal = rawGoal === null || !isCanonicalGoal(rawGoal) ? void 0 : normalizeLoadedGoal(rawGoal);
|
|
455
443
|
if (goal?.status === "complete") goal = void 0;
|
|
456
|
-
return { goal, legacyQueueState: void 0
|
|
444
|
+
return { goal, legacyQueueState: void 0 };
|
|
457
445
|
}
|
|
458
446
|
function countCanonicalLegacyGoals(goal, queue, pendingAction) {
|
|
459
|
-
let count =
|
|
447
|
+
let count = isStoredGoal(goal) && goal.status !== "complete" ? 1 : 0;
|
|
460
448
|
count += (queue ?? []).filter((queuedGoal) => queuedGoal.status !== "complete").length;
|
|
461
449
|
if (pendingAction?.kind === "prioritize") count += 1;
|
|
462
450
|
return count;
|
|
@@ -470,27 +458,26 @@ function normalizeCanonicalPendingAction(value) {
|
|
|
470
458
|
return void 0;
|
|
471
459
|
}
|
|
472
460
|
function loadLegacyGoalsState(data) {
|
|
473
|
-
if (!isRecord2(data)) return emptyGoalState(
|
|
461
|
+
if (!isRecord2(data)) return emptyGoalState();
|
|
474
462
|
let rawGoals;
|
|
475
463
|
if (Array.isArray(data.goals)) {
|
|
476
|
-
if (!data.goals.every(
|
|
464
|
+
if (!data.goals.every(isStoredGoal)) return emptyGoalState();
|
|
477
465
|
rawGoals = data.goals.filter((goal) => goal.status !== "complete");
|
|
478
|
-
} else if (
|
|
466
|
+
} else if (isStoredGoal(data.goal) && data.goal.status !== "complete") {
|
|
479
467
|
rawGoals = [data.goal];
|
|
480
468
|
} else {
|
|
481
469
|
rawGoals = [];
|
|
482
470
|
}
|
|
483
471
|
const pendingAction = normalizeLegacyPendingPrioritize(data.pendingUnshift);
|
|
484
|
-
|
|
472
|
+
const onlyGoal = rawGoals.length === 1 ? rawGoals[0] : void 0;
|
|
473
|
+
if (onlyGoal && isCanonicalGoal(onlyGoal) && pendingAction === void 0) {
|
|
485
474
|
return {
|
|
486
|
-
goal: normalizeLoadedGoal(
|
|
487
|
-
legacyQueueState: void 0
|
|
488
|
-
source: "legacy-goals"
|
|
475
|
+
goal: normalizeLoadedGoal(onlyGoal),
|
|
476
|
+
legacyQueueState: void 0
|
|
489
477
|
};
|
|
490
478
|
}
|
|
491
|
-
if (rawGoals.length === 0 && pendingAction === void 0) return emptyGoalState(
|
|
492
|
-
return legacyQueueState(
|
|
493
|
-
reason: "legacy-goals",
|
|
479
|
+
if (rawGoals.length === 0 && pendingAction === void 0) return emptyGoalState();
|
|
480
|
+
return legacyQueueState({
|
|
494
481
|
retainedGoals: rawGoals.length + (pendingAction ? 1 : 0)
|
|
495
482
|
});
|
|
496
483
|
}
|
|
@@ -548,36 +535,31 @@ function readState() {
|
|
|
548
535
|
return {};
|
|
549
536
|
}
|
|
550
537
|
}
|
|
551
|
-
function
|
|
538
|
+
function isStoredGoal(value) {
|
|
552
539
|
if (!isRecord2(value)) return false;
|
|
553
|
-
return typeof value.id === "string" && Boolean(value.id) && value.id === value.id.trim() && validObjective(value.text) && [
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
"budget_limited",
|
|
560
|
-
"complete"
|
|
561
|
-
].includes(String(value.status)) && typeof value.startedAt === "number" && typeof value.updatedAt === "number" && typeof value.iteration === "number" && typeof value.tokensUsed === "number" && typeof value.timeUsedSeconds === "number" && typeof value.baselineTokens === "number" && (value.activeStartedAt === void 0 || typeof value.activeStartedAt === "number") && (value.safetyResetPending === void 0 || typeof value.safetyResetPending === "boolean");
|
|
540
|
+
return typeof value.id === "string" && Boolean(value.id) && value.id === value.id.trim() && validObjective(value.text) && ["active", "queued", "paused", "blocked", "usage_limited", "budget_limited", "complete"].includes(
|
|
541
|
+
String(value.status)
|
|
542
|
+
) && typeof value.startedAt === "number" && typeof value.updatedAt === "number" && typeof value.iteration === "number" && typeof value.tokensUsed === "number" && typeof value.timeUsedSeconds === "number" && typeof value.baselineTokens === "number" && (value.activeStartedAt === void 0 || typeof value.activeStartedAt === "number") && (value.safetyResetPending === void 0 || typeof value.safetyResetPending === "boolean");
|
|
543
|
+
}
|
|
544
|
+
function isCanonicalGoal(goal) {
|
|
545
|
+
return goal.status !== "queued";
|
|
562
546
|
}
|
|
563
547
|
function isQueueGoal(value) {
|
|
564
|
-
return
|
|
548
|
+
return isStoredGoal(value) && value.status !== "complete";
|
|
565
549
|
}
|
|
566
550
|
function isRecord2(value) {
|
|
567
551
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
568
552
|
}
|
|
569
|
-
function emptyGoalState(
|
|
553
|
+
function emptyGoalState() {
|
|
570
554
|
return {
|
|
571
555
|
goal: void 0,
|
|
572
|
-
legacyQueueState: void 0
|
|
573
|
-
source
|
|
556
|
+
legacyQueueState: void 0
|
|
574
557
|
};
|
|
575
558
|
}
|
|
576
|
-
function legacyQueueState(
|
|
559
|
+
function legacyQueueState(legacyQueue) {
|
|
577
560
|
return {
|
|
578
561
|
goal: void 0,
|
|
579
|
-
legacyQueueState: legacyQueue
|
|
580
|
-
source
|
|
562
|
+
legacyQueueState: legacyQueue
|
|
581
563
|
};
|
|
582
564
|
}
|
|
583
565
|
|
|
@@ -719,7 +701,7 @@ var STATUS_KEY = "goal";
|
|
|
719
701
|
var GOAL_STATE_ENTRY_TYPE2 = "goal-state";
|
|
720
702
|
var MAX_GOAL_ID_LENGTH = 128;
|
|
721
703
|
function isTerminalGoalStatus(status) {
|
|
722
|
-
return status !== "active"
|
|
704
|
+
return status !== "active";
|
|
723
705
|
}
|
|
724
706
|
function buildGoalStateSnapshot(goal, summary, reason) {
|
|
725
707
|
const snapshot = { goalId: goal.id, status: goal.status };
|
|
@@ -926,7 +908,7 @@ var GoalRuntime = class {
|
|
|
926
908
|
if (this.activeGoal?.id === intent.goalId && this.activeGoal.status === "active") {
|
|
927
909
|
this.continuationIntent = intent;
|
|
928
910
|
}
|
|
929
|
-
|
|
911
|
+
notifyWhenSessionAlive(ctx, `Goal prompt failed: ${formatError(error)}`, "error");
|
|
930
912
|
return false;
|
|
931
913
|
}
|
|
932
914
|
}
|
|
@@ -1011,7 +993,7 @@ var GoalRuntime = class {
|
|
|
1011
993
|
try {
|
|
1012
994
|
this.dispatchDueGoalWait(ctx);
|
|
1013
995
|
} catch (error) {
|
|
1014
|
-
|
|
996
|
+
notifyWhenSessionAlive(ctx, `Goal wait deadline failed: ${formatError(error)}`, "error");
|
|
1015
997
|
}
|
|
1016
998
|
});
|
|
1017
999
|
}
|
|
@@ -1042,10 +1024,7 @@ var GoalRuntime = class {
|
|
|
1042
1024
|
}
|
|
1043
1025
|
updateStatus(ctx, goal) {
|
|
1044
1026
|
this.clearCompletionStatusTimer();
|
|
1045
|
-
ctx.ui.setStatus(
|
|
1046
|
-
STATUS_KEY,
|
|
1047
|
-
formatStatus(goal, this.settings.continuationLimits.automaticTurns)
|
|
1048
|
-
);
|
|
1027
|
+
ctx.ui.setStatus(STATUS_KEY, formatStatus(goal, this.settings.continuationLimits.automaticTurns));
|
|
1049
1028
|
}
|
|
1050
1029
|
stopActiveGoal(ctx, request) {
|
|
1051
1030
|
const currentGoal = this.activeGoal;
|
|
@@ -1196,7 +1175,7 @@ var GoalRuntime = class {
|
|
|
1196
1175
|
return true;
|
|
1197
1176
|
} catch (error) {
|
|
1198
1177
|
this.budgetWrapUp.delivered = false;
|
|
1199
|
-
|
|
1178
|
+
notifyWhenSessionAlive(ctx, `Goal budget wrap-up failed: ${formatError(error)}`, "error");
|
|
1200
1179
|
return false;
|
|
1201
1180
|
}
|
|
1202
1181
|
}
|
|
@@ -1499,9 +1478,7 @@ var GoalRuntime = class {
|
|
|
1499
1478
|
);
|
|
1500
1479
|
if (exactIndex >= 0) return this.pendingNonGoalInputs.splice(exactIndex, 1)[0];
|
|
1501
1480
|
if (!allowDeliveryFallback) return void 0;
|
|
1502
|
-
const fallbackSteerIndex = this.pendingNonGoalInputs.findIndex(
|
|
1503
|
-
(pending) => pending.behavior === "steer"
|
|
1504
|
-
);
|
|
1481
|
+
const fallbackSteerIndex = this.pendingNonGoalInputs.findIndex((pending) => pending.behavior === "steer");
|
|
1505
1482
|
const fallbackIndex = fallbackSteerIndex >= 0 ? fallbackSteerIndex : this.pendingNonGoalInputs.findIndex((pending) => pending.behavior === "followUp");
|
|
1506
1483
|
if (fallbackIndex < 0) return void 0;
|
|
1507
1484
|
return this.pendingNonGoalInputs.splice(fallbackIndex, 1)[0];
|
|
@@ -1540,9 +1517,7 @@ var GoalRuntime = class {
|
|
|
1540
1517
|
this.clearTerminalDetails();
|
|
1541
1518
|
}
|
|
1542
1519
|
this.pi.appendEntry(GOAL_STATE_ENTRY_TYPE2, serializeGoalState(goal));
|
|
1543
|
-
this.publishGoalState(
|
|
1544
|
-
buildGoalStateSnapshot(goal, this.terminalDetails?.summary, this.terminalDetails?.reason)
|
|
1545
|
-
);
|
|
1520
|
+
this.publishGoalState(buildGoalStateSnapshot(goal, this.terminalDetails?.summary, this.terminalDetails?.reason));
|
|
1546
1521
|
}
|
|
1547
1522
|
clearPersistedGoal(cwd, clearedGoal, reason = "goal cleared") {
|
|
1548
1523
|
this.pi.appendEntry(GOAL_STATE_ENTRY_TYPE2, serializeGoalState(void 0));
|
|
@@ -1740,7 +1715,6 @@ function formatStatus(goal, automaticTurnLimit = DEFAULT_GOAL_SETTINGS.continuat
|
|
|
1740
1715
|
if (!goal) return void 0;
|
|
1741
1716
|
if (goal.status === "complete") return "complete";
|
|
1742
1717
|
const automatic = automaticTurnLimit === null ? "automatic Unlimited" : `automatic ${goal.automaticModelTurns}/${automaticTurnLimit}`;
|
|
1743
|
-
if (goal.status === "queued") return `queued \xB7 ${automatic}`;
|
|
1744
1718
|
if (goal.waiting) {
|
|
1745
1719
|
return `waiting ${safeGoalMenuText(goal.waiting.reason)} \xB7 ${automatic}`;
|
|
1746
1720
|
}
|
|
@@ -1833,23 +1807,29 @@ async function sendPrompt(pi, ctx, prompt, isCurrent) {
|
|
|
1833
1807
|
return true;
|
|
1834
1808
|
} catch (error) {
|
|
1835
1809
|
if (!isCurrent || isCurrent()) {
|
|
1836
|
-
|
|
1810
|
+
notifyWhenSessionAlive(ctx, `Goal prompt failed: ${formatError(error)}`, "error");
|
|
1837
1811
|
}
|
|
1838
1812
|
return false;
|
|
1839
1813
|
}
|
|
1840
1814
|
}
|
|
1841
|
-
function
|
|
1842
|
-
|
|
1815
|
+
function notifyWhenSessionAlive(ctx, message, level) {
|
|
1816
|
+
try {
|
|
1817
|
+
notifyTerminal(ctx.ui, message, level);
|
|
1818
|
+
} catch (error) {
|
|
1819
|
+
if (!isStaleContextError(error)) throw error;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
function goalCommandHint(goal) {
|
|
1843
1823
|
if (goal.waiting) {
|
|
1844
|
-
return
|
|
1824
|
+
return "/goal resume, /goal edit <objective>, /goal pause, /goal clear";
|
|
1845
1825
|
}
|
|
1846
1826
|
if (goal.status === "active") {
|
|
1847
|
-
return
|
|
1827
|
+
return "/goal edit <objective>, /goal pause, /goal clear";
|
|
1848
1828
|
}
|
|
1849
1829
|
if (isResumableGoalStatus(goal.status)) {
|
|
1850
|
-
return
|
|
1830
|
+
return "/goal edit <objective>, /goal resume, /goal clear";
|
|
1851
1831
|
}
|
|
1852
|
-
return
|
|
1832
|
+
return "/goal edit <objective>, /goal clear";
|
|
1853
1833
|
}
|
|
1854
1834
|
function continuationMarker(goal) {
|
|
1855
1835
|
return `${goal.id}:${goal.iteration}:${randomUUID()}`;
|
|
@@ -1900,4 +1880,4 @@ export {
|
|
|
1900
1880
|
isContradictoryCompletionSummary,
|
|
1901
1881
|
goalIdRejectionReason
|
|
1902
1882
|
};
|
|
1903
|
-
//# sourceMappingURL=chunk-
|
|
1883
|
+
//# sourceMappingURL=chunk-VJ5LR26S.js.map
|