@narumitw/pi-goal 0.51.0 → 0.52.1
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 +28 -45
- package/package.json +8 -9
- package/src/command-registration.ts +15 -38
- package/src/command.ts +25 -70
- package/src/commands.ts +51 -383
- package/src/goal.ts +1 -1
- package/src/lifecycle.ts +25 -138
- package/src/menu.ts +15 -242
- package/src/persistence.ts +72 -108
- package/src/runtime.ts +22 -64
- package/src/settings-ui.ts +3 -125
- package/src/settings.ts +13 -29
- package/src/tools.ts +0 -65
- package/src/queue.ts +0 -126
package/README.md
CHANGED
|
@@ -2,35 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-goal) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
`@narumitw/pi-goal` is a native [Pi coding agent](https://pi.dev) extension that adds session-scoped `/goal` commands, a `goal_complete({ goal_id, summary })` completion tool, a strict `goal_blocked({ goal_id, reason, evidence, repeated_turns })` impasse tool, and a `goal_wait({ goal_id, reason, resume_after_ms? })` tool for external-event waits.
|
|
5
|
+
`@narumitw/pi-goal` is a native [Pi coding agent](https://pi.dev) extension that adds session-scoped `/goal` commands, a `goal_complete({ goal_id, summary })` completion tool, a strict `goal_blocked({ goal_id, reason, evidence, repeated_turns })` impasse tool, and a `goal_wait({ goal_id, reason, resume_after_ms? })` tool for external-event waits.
|
|
6
6
|
|
|
7
|
-
Goal mode uses Codex-like persistence instructions and sends guarded continuation messages from Pi's fully settled idle boundary until the agent completes the goal, explicitly waits for an external event, the user pauses or clears it, a safety circuit breaker trips, a true blocker or provider usage limit stops it, or an optional token budget is reached.
|
|
7
|
+
Goal mode uses Codex-like persistence instructions and sends guarded continuation messages from Pi's fully settled idle boundary until the agent completes the goal, explicitly waits for an external event, the user pauses or clears it, a safety circuit breaker trips, a true blocker or provider usage limit stops it, or an optional token budget is reached.
|
|
8
8
|
|
|
9
9
|
## ✨ Features
|
|
10
10
|
|
|
11
11
|
- Adds `/goal <goal_to_complete>` to start goal mode, with confirmation before replacing an existing goal.
|
|
12
12
|
- Bare `/goal` opens a standard current-state manager in the TUI, with guided start, pause,
|
|
13
|
-
resume, edit,
|
|
13
|
+
resume, edit, settings, status, help, and destructive-action confirmation; RPC mode retains
|
|
14
14
|
observable status notifications.
|
|
15
15
|
- Keeps direct goal management available through `/goal` subcommands: `status`, `pause`, `resume`, `clear`, and `edit`.
|
|
16
|
-
- Exposes only one top-level command: `/goal
|
|
17
|
-
- Optionally adds ordered-goal operations through `/goal add`, `prioritize`, `drop-last`, and `skip`, while accepting `push`, `unshift`, `pop`, and `shift` as hidden compatibility aliases.
|
|
16
|
+
- Exposes only one top-level command: `/goal`.
|
|
18
17
|
- Pauses automatic work after 25 Goal-owned model responses by default, preserves progress, and provides a guided review-and-continue flow; custom finite limits and confirmed Unlimited mode remain available.
|
|
19
18
|
- Pauses after three consecutive empty or normalized-identical tool-free automatic runs, while distinct short output and tool activity reset the repeat detector.
|
|
20
19
|
- Supports optional token budgets such as `/goal --tokens 100k <goal>`, using provider-reported total-token accounting with a cache-inclusive compatibility fallback.
|
|
21
20
|
- Tracks distinct `active`, `paused`, `blocked`, `usage_limited`, `budget_limited`, and `complete` states.
|
|
22
|
-
- Stores goal state in the current Pi session, following Codex's thread-owned goal model instead of using a global per-directory goal.
|
|
21
|
+
- Stores goal state in the current Pi session, following Codex's thread-owned goal model instead of using a global per-directory goal.
|
|
23
22
|
- Registers a `goal_complete({ goal_id, summary })` tool for explicit completion, requiring the current goal id and rejecting missing/stale ids plus plainly contradictory summaries such as “not complete” or “tests still fail”.
|
|
24
23
|
- Registers `goal_blocked({ goal_id, reason, evidence, repeated_turns })` for true impasses only; it requires the current goal id, concrete evidence, and the same blocker recurring for at least three consecutive goal turns.
|
|
25
|
-
- Registers `goal_wait({ goal_id, reason, resume_after_ms? })` for an active Goal that has arranged an external wake message; waiting suppresses automatic continuation while preserving the objective, accounting,
|
|
24
|
+
- Registers `goal_wait({ goal_id, reason, resume_after_ms? })` for an active Goal that has arranged an external wake message; waiting suppresses automatic continuation while preserving the objective, accounting, and managed-run ownership.
|
|
26
25
|
- Starts all three Goal tools inactive by default, reveals them for the first accepted `/goal` activation or an unfinished-goal restore, and keeps them desired for the rest of that extension runtime without overriding a restrictive restore policy. Optional `"always"` visibility keeps them active from session startup.
|
|
27
|
-
- Records continuation
|
|
26
|
+
- Records continuation intent, then triggers exactly one next turn only after Pi reports the agent fully settled, idle, and free of pending messages; an explicit wait remains quiet until non-Goal work or its optional deadline wakes it, and missing terminal tools still pause before another model turn.
|
|
28
27
|
- Lets retry, compaction, steering, follow-up, and other queued work settle before automatic goal continuation.
|
|
29
28
|
- Separates user interruption (`paused`), true impasse or terminal non-usage error (`blocked`), provider/account quota exhaustion (`usage_limited`), and user token budget exhaustion (`budget_limited`).
|
|
30
29
|
- Detects budget exhaustion after completed tool activity when assistant usage is persisted, then injects at most one non-user-authored wrap-up instruction and blocks further substantive tools.
|
|
31
30
|
- Keeps retryable provider interruptions and Pi compaction retries active without enqueueing duplicate goal continuations while Pi retries, then marks a matching unresolved error `blocked` only when `agent_settled` proves no retry, compaction, or follow-up remains.
|
|
32
31
|
- Preserves active goals across manual, threshold, and overflow compaction.
|
|
33
|
-
- Guards auto-follow-ups and Goal-owned kickoff deliveries so duplicate, replaced, stopped, cleared, completed, budget-limited, or stale
|
|
32
|
+
- Guards auto-follow-ups and Goal-owned kickoff deliveries so duplicate, replaced, stopped, cleared, completed, budget-limited, or stale prompts cannot continue or overwrite a newer goal.
|
|
34
33
|
- Rotates the completion guard id when a goal is resumed or edited so delayed old turns cannot complete the newer goal instance.
|
|
35
34
|
- Blocks stale tool calls after in-flight work pauses, blocks, or reaches a usage limit, until fresh non-goal user work, successful reactivation/replacement, or clear.
|
|
36
35
|
- Applies one evidence-based completion audit across kickoff, resume, edit, system, continuation, and budget-wrap-up prompts.
|
|
@@ -64,9 +63,6 @@ built-in defaults without creating the file:
|
|
|
64
63
|
```json
|
|
65
64
|
{
|
|
66
65
|
"toolVisibility": "after-first-goal",
|
|
67
|
-
"experimental": {
|
|
68
|
-
"goals": false
|
|
69
|
-
},
|
|
70
66
|
"rpc": {
|
|
71
67
|
"enabled": false
|
|
72
68
|
},
|
|
@@ -78,13 +74,12 @@ built-in defaults without creating the file:
|
|
|
78
74
|
```
|
|
79
75
|
|
|
80
76
|
Use `/goal` → **Settings…** in the TUI to create or update the file interactively, or create
|
|
81
|
-
and edit it directly. The standard Settings screen keeps all
|
|
77
|
+
and edit it directly. The standard Settings screen keeps all four controls on one level in task
|
|
82
78
|
order; the two safety limits open standard choice screens:
|
|
83
79
|
|
|
84
80
|
- **Automatic-work limit** shows the exact response limit or **Unlimited**. Choose **Set response limit…** to edit the current finite value (or the built-in default of 25 when switching from Unlimited), or choose **Unlimited…**. Unlimited requires confirmation that tool loops may continue consuming tokens and provider cost without a response-count cap.
|
|
85
81
|
- **No-progress guard** shows **_N_ runs** or **Off**. Choose the default threshold, **Off**, or **Set threshold…** and enter a safe whole number greater than zero.
|
|
86
82
|
- **Goal tools** controls whether all Goal tools are always visible or appear after the first goal.
|
|
87
|
-
- **Ordered goal queue** controls the experimental ordered-goal workflows.
|
|
88
83
|
- **Managed run RPC** controls whether trusted installed extensions may start and cancel managed Goal runs. It defaults to **Off** and is a cooperation setting, not an extension security sandbox.
|
|
89
84
|
|
|
90
85
|
Custom number inputs reject zero, negative numbers, decimals, text, and unsafe integers without saving; use the explicit **Unlimited** or **Off** choice instead. Interactive changes are serialized, written atomically, preserve unknown fields, and apply to the current runtime. A successful change updates the visible state immediately. A failed save restores the prior value and reports the settings path so it can be retried. Tool-visibility changes that would alter the active tool schema are rejected while Pi is busy; retry after Pi settles. Escape returns to the previous screen without reverting changes that were already saved.
|
|
@@ -94,7 +89,7 @@ Custom number inputs reject zero, negative numbers, decimals, text, and unsafe i
|
|
|
94
89
|
- `"always"` — pi-goal does not proactively hide `goal_complete`, `goal_blocked`, or `goal_wait`, keeping the Goal tool schema stable from session startup.
|
|
95
90
|
- `"after-first-goal"` (default) — hides all three Goal tools at fresh runtime startup, reveals them for the first accepted Goal activation, and treats an unfinished-goal restore as unlocked for the remainder of that extension runtime. On restore, pi-goal uses the active tools already established by earlier lifecycle handlers; it does not re-add missing terminal tools over a restrictive policy. Failed kickoff, replacement, resume, or reactivating-edit delivery restores the exact pre-activation tool set, including Goal tools exposed by another extension. If revealing the tools would widen an already-running turn, wait for Pi to become idle and retry `/goal`.
|
|
96
91
|
|
|
97
|
-
`experimental.goals`
|
|
92
|
+
`experimental.goals` is a removed legacy setting. If it remains `true`, pi-goal accepts the settings file, ignores the old queue feature, and shows an affected-user warning that recommends `/goal edit` when an active objective exists or `/goal <objectives>` when no active goal exists. Later settings saves preserve unknown legacy fields instead of deleting them.
|
|
98
93
|
|
|
99
94
|
`rpc.enabled` accepts a boolean and defaults to `false`. When disabled, a valid managed-run start receives `RPC_DISABLED`; manual and restored Goals remain unchanged. A Settings-menu change applies immediately after its atomic save. 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. Reload, replacement, and shutdown clear that in-memory ownership.
|
|
100
95
|
|
|
@@ -122,12 +117,6 @@ Tool visibility is a baseline, not ownership of Pi's global active-tool list. Pl
|
|
|
122
117
|
/goal pause
|
|
123
118
|
/goal resume
|
|
124
119
|
/goal clear
|
|
125
|
-
|
|
126
|
-
# With experimental.goals enabled:
|
|
127
|
-
/goal add --tokens 20k run the integration tests
|
|
128
|
-
/goal prioritize fix the urgent production regression
|
|
129
|
-
/goal drop-last
|
|
130
|
-
/goal skip
|
|
131
120
|
```
|
|
132
121
|
|
|
133
122
|
- In the TUI, `/goal` opens a standard state-aware manager. Its first action follows the current
|
|
@@ -135,33 +124,29 @@ Tool visibility is a baseline, not ownership of Pi's global active-tool list. Pl
|
|
|
135
124
|
stopped states, or increase an exhausted token budget. Active and paused views show **Automatic
|
|
136
125
|
work: _used_ of _limit_ responses** with the remaining count, or explicitly show **Unlimited**.
|
|
137
126
|
A hard-cap pause opens **Review and continue…**, which states that objective, cumulative usage,
|
|
138
|
-
active time
|
|
127
|
+
and active time are preserved and previews that Continue resets the counter to zero and
|
|
139
128
|
allows up to one more configured epoch. **Change automatic-work limit…** opens that setting while
|
|
140
129
|
leaving the goal paused; Back and Escape make no change. **Start with token budget…** first offers
|
|
141
130
|
`25k`, a suggested `100k`, `300k`, and **Set a custom budget…**, then collects the objective with
|
|
142
131
|
the selected budget still visible. Custom input accepts examples such as `300000`, `300k`, `2.5k`,
|
|
143
|
-
and `1.5m`; invalid input retains its draft for correction. Status, Settings, Help,
|
|
144
|
-
|
|
132
|
+
and `1.5m`; invalid input retains its draft for correction. Status, Settings, Help,
|
|
133
|
+
invalid-settings guidance, Clear, and Close remain shallow, labeled routes. Arrow keys
|
|
145
134
|
navigate, Enter selects or submits, Escape goes Back, and Ctrl+C closes the full flow.
|
|
146
135
|
- In RPC mode, bare `/goal` and `/goal status` report the current summary through an observable notification without opening terminal UI. Pi exposes no extension-command output channel in print or JSON mode, so those routes reject with an explicit unsupported-mode error instead of misreporting stderr as status output.
|
|
147
|
-
- Menu-driven Replace
|
|
136
|
+
- Menu-driven Replace and Clear actions preview the exact affected goal and require confirmation. Existing direct routes remain immediate for compatibility and automation.
|
|
148
137
|
- `/goal <goal_to_complete>` starts goal mode. If another unfinished goal exists, Pi asks for confirmation before replacing it with a new active goal and resetting its usage counters. Failed kickoff delivery clears a new goal or restores the prior goal; a previously active goal is restored as paused.
|
|
149
138
|
- `/goal --tokens 100k <goal_to_complete>` starts or replaces goal mode with a token budget. `k` and `m` suffixes are accepted, for example `100k` or `1.5m`.
|
|
150
139
|
- `/goal edit <goal_to_complete>` updates the existing goal objective without resetting usage counters. A successful active edit rotates the stale-turn guard and starts a fresh safety epoch. Paused, blocked, and usage-limited goals stay stopped and retain their safety state until resume. A budget-limited goal reactivates only when `edit --tokens` raises its budget above current usage. Failed prompt delivery restores the exact previous safety counters/cause; it restores a budget-limited goal or restores and pauses a previously active goal.
|
|
151
140
|
- `/goal pause` stops prompt injection and auto-continuation, aborts the current turn, and keeps the goal for later resume. Only active goals can be paused.
|
|
152
|
-
- `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it, rotates the stale-turn guard id, resets the automatic-response/repeat safety epoch when the queued resume prompt starts, clears a safety-pause cause, and reports the new finite epoch or explicit Unlimited state. Objective, cumulative usage, elapsed time
|
|
153
|
-
- `/goal clear` clears the current goal
|
|
154
|
-
|
|
155
|
-
With `experimental.goals: true`:
|
|
141
|
+
- `/goal resume` resumes a paused, blocked, usage-limited, or budget-limited goal when its token budget allows it, rotates the stale-turn guard id, resets the automatic-response/repeat safety epoch when the queued resume prompt starts, clears a safety-pause cause, and reports the new finite epoch or explicit Unlimited state. Objective, cumulative usage, and elapsed time are preserved. If prompt delivery fails, the original stopped state, guard id, counters, fingerprint, and cause are restored.
|
|
142
|
+
- `/goal clear` clears the current goal, status, pending continuation, inert legacy queue state, and legacy persisted state for the current working directory without aborting unrelated in-flight work.
|
|
156
143
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
- `/goal skip` removes the active head and starts the next eligible item only from an idle settled boundary. A stopped next item remains stopped.
|
|
161
|
-
- `push`, `unshift`, `pop`, and `shift` are accepted as aliases for `add`, `prioritize`, `drop-last`, and `skip`, respectively. Autocomplete shows only the intent-oriented names.
|
|
162
|
-
- `/goal <goal>` still starts or replaces the whole queue; `edit`, `pause`, and `resume` operate on the active head.
|
|
144
|
+
The experimental ordered-goal queue has been removed.
|
|
145
|
+
Use `/goal edit <objective>` to reprioritize the active objective instead.
|
|
146
|
+
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.`
|
|
163
147
|
|
|
164
|
-
|
|
148
|
+
Former queue command words such as `add`, `prioritize`, `drop-last`, `skip`, `push`, `unshift`, `pop`, and `shift` are ordinary objective text for unaffected users.
|
|
149
|
+
If a session still has legacy queue settings or persisted queue state, those words show a migration warning instead of replacing the active Goal.
|
|
165
150
|
|
|
166
151
|
Goal objectives are limited to 4,000 characters. Put longer instructions in a file and reference the file path from `/goal`.
|
|
167
152
|
|
|
@@ -169,9 +154,9 @@ Goal objectives are limited to 4,000 characters. Put longer instructions in a fi
|
|
|
169
154
|
|
|
170
155
|
Goal state is stored as Pi session state, similar to Codex's thread-owned goals. `/reload` and reopening the same Pi session can restore that session's unfinished goal. An active restored goal already at or above its finite automatic-work limit pauses before another provider request and reports that progress is saved; use `/goal` to review and continue. A restored waiting Goal remains quiet, excludes offline and waiting wall time from active elapsed time, and restores only its absolute optional deadline timer. With `"after-first-goal"`, an unfinished restore marks the tools unlocked in the new extension runtime, but it does not widen an active-tool set already restricted by an earlier lifecycle handler; an active goal instead restores as paused when either terminal tool is missing. If no unfinished goal remains, a fresh runtime starts locked again. Active elapsed time is checkpointed before shutdown and restarted after reload only when the Goal is not waiting, so offline and stopped wall-clock time is excluded. Automatic-response counts, repeat fingerprints, and safety-pause causes persist across reload and compaction. A direct non-`/goal` user/RPC input resets the safety epoch only while the goal is active and reclassifies the in-flight run as manual; extension input and messages sent while stopped do not reset it. Starting a new Pi session in the same working directory does not inherit the old goal.
|
|
171
156
|
|
|
172
|
-
|
|
157
|
+
The legacy `{ goal }` shape remains valid, and missing safety fields normalize to zero/defaults. Sessions created by the former standalone `pi-goals` experiment can still restore exactly one ordinary unfinished goal when no canonical `goal-state` entry exists.
|
|
173
158
|
|
|
174
|
-
If a session still contains multiple goals or a pending queue transition
|
|
159
|
+
If a session still contains old queue metadata, multiple legacy goals, a queued head, or a pending queue transition, pi-goal treats that state as inert legacy data. It does not inject Goal prompts, advance the queue, or run any retained item automatically. Affected users receive a warning that recommends starting one merged objective with `/goal <objectives>`, or using `/goal clear` to discard the old queue state.
|
|
175
160
|
|
|
176
161
|
Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed by working directory. This version no longer reads that global file, and `/goal clear` removes any legacy entry for the current working directory.
|
|
177
162
|
|
|
@@ -189,7 +174,6 @@ Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed
|
|
|
189
174
|
- `usage · automatic 12/25` — the provider or account usage limit stopped work.
|
|
190
175
|
- `budget 100k/100k · automatic 12/25` — the user-configured token budget was reached; auto-continuation stops.
|
|
191
176
|
- `complete` — shown briefly after `goal_complete` succeeds.
|
|
192
|
-
- `queue off` — retained ordered goals are frozen because `experimental.goals` is disabled.
|
|
193
177
|
|
|
194
178
|
## 💰 Token budgets and elapsed time
|
|
195
179
|
|
|
@@ -239,11 +223,11 @@ An accepted call keeps the canonical Goal status active, checkpoints active elap
|
|
|
239
223
|
|
|
240
224
|
Interactive input, RPC input, another extension's `sendUserMessage()` input, and supported non-Goal custom follow-ups clear the wait before their turn runs. pi-goal-owned kickoff, resume, edit, continuation, stale, or cancelled prompts do not count as external wake-ups. Pi does not expose the sending extension's identity, so any non-Goal extension message is treated as a wake signal.
|
|
241
225
|
|
|
242
|
-
After a waking turn ends, ordinary continuation rules apply again. The agent can complete or block the Goal, continue working, or call `goal_wait` again after arranging the next wake source. `/goal resume` also clears waiting and sends one manual resume prompt without resetting cumulative usage or the safety epoch. `/goal pause`, clear, edit, replace, completion, blocking, terminal limits, tool loss,
|
|
226
|
+
After a waking turn ends, ordinary continuation rules apply again. The agent can complete or block the Goal, continue working, or call `goal_wait` again after arranging the next wake source. `/goal resume` also clears waiting and sends one manual resume prompt without resetting cumulative usage or the safety epoch. `/goal pause`, clear, edit, replace, completion, blocking, terminal limits, tool loss, session replacement, and shutdown cancel the in-memory deadline owner.
|
|
243
227
|
|
|
244
228
|
A future deadline is restored from its absolute timestamp after reload. Reload never restarts, extends, or newly clamps an already-persisted absolute deadline, including a short deadline written by an older version. An already-due deadline waits for Pi's settled, idle, no-pending-message boundary and then requests exactly one continuation through the normal dispatcher. If that delivery throws, pi-goal restores the wait, retries once after one second, and leaves the Goal visibly waiting after a second failure instead of retry-looping. A deadline never sends a prompt directly from a stale timer.
|
|
245
229
|
|
|
246
|
-
Waiting time is excluded from **Active elapsed**, while tokens, iteration, automatic-response count, no-progress state,
|
|
230
|
+
Waiting time is excluded from **Active elapsed**, while tokens, iteration, automatic-response count, no-progress state, managed-run ownership remain preserved. The managed-run protocol continues reporting `active` because waiting is non-terminal. Editing or replacing a waiting Goal clears the previous wait so the updated objective performs a fresh external-state check.
|
|
247
231
|
|
|
248
232
|
## 🚧 Blocked goals
|
|
249
233
|
|
|
@@ -253,7 +237,7 @@ Do not use `goal_blocked` merely because work is difficult, incomplete, uncertai
|
|
|
253
237
|
|
|
254
238
|
## 🛑 Interruption and queued-input behavior
|
|
255
239
|
|
|
256
|
-
A user pause or aborted turn produces `paused`; a terminal provider/account quota error produces `usage_limited`; another non-retryable agent error produces `blocked`. Each stopped transition cancels pending continuation intent or delivery, aborts stale work when applicable, and blocks stale tool calls until the next non-goal user prompt, successful reactivation/replacement, or `/goal clear`. On `/goal clear`, the extension clears goal state, continuation markers, and any stale tool-call block without aborting an unrelated in-flight turn. Retryable provider interruptions and overflow compaction retries stay `active` while Pi retries; no extra continuation is queued, and automatic ownership remains charged through retry `agent_start` events. If matching recovery still exists at `agent_settled`, retries are exhausted and the goal becomes `blocked` before any
|
|
240
|
+
A user pause or aborted turn produces `paused`; a terminal provider/account quota error produces `usage_limited`; another non-retryable agent error produces `blocked`. Each stopped transition cancels pending continuation intent or delivery, aborts stale work when applicable, and blocks stale tool calls until the next non-goal user prompt, successful reactivation/replacement, or `/goal clear`. On `/goal clear`, the extension clears goal state, continuation markers, and any stale tool-call block without aborting an unrelated in-flight turn. Retryable provider interruptions and overflow compaction retries stay `active` while Pi retries; no extra continuation is queued, and automatic ownership remains charged through retry `agent_start` events. If matching recovery still exists at `agent_settled`, retries are exhausted and the goal becomes `blocked` before any continuation dispatches. Stale recovery cannot block a replacement goal. User and extension work that starts before settlement supersedes the older continuation intent, and pending messages always take priority.
|
|
257
241
|
|
|
258
242
|
## 🤝 Managed run RPC
|
|
259
243
|
|
|
@@ -292,7 +276,7 @@ A successful start produces canonical state on `pi-goal:event:${runId}`:
|
|
|
292
276
|
|
|
293
277
|
Subsequent state events use `active`, `complete`, `blocked`, `paused`, `usage_limited`, `budget_limited`, or `cleared`. `complete` is the only successful terminal outcome. A matching completion may include `summary`; other terminal outcomes may include `reason`. Events come only from canonical Goal persistence and only for the matching managed run. Manual and restored Goals are not adopted or broadcast, unchanged persistence does not duplicate a status, and each run emits at most one terminal event.
|
|
294
278
|
|
|
295
|
-
Terminal events are dispatched after the underlying Goal transition settles, so a listener can start the next managed run directly after `complete` without re-entering completion cleanup. Other terminal statuses leave a stopped Goal that must be resolved or cleared first. If a manual edit, replacement,
|
|
279
|
+
Terminal events are dispatched after the underlying Goal transition settles, so a listener can start the next managed run directly after `complete` without re-entering completion cleanup. Other terminal statuses leave a stopped Goal that must be resolved or cleared first. If a manual edit, replacement, or edit transition rotates the Goal id, the prior managed run ends as `cleared` with a superseded reason; the replacement remains outside that run.
|
|
296
280
|
|
|
297
281
|
To cancel before or after activation, emit the same `runId`:
|
|
298
282
|
|
|
@@ -341,7 +325,7 @@ packages/pi-goal/
|
|
|
341
325
|
│ ├── index.ts # Pi package entrypoint
|
|
342
326
|
│ ├── goal.ts # Order-explicit extension composition root
|
|
343
327
|
│ ├── command-registration.ts # Lightweight slash-command adapter with lazy manager/settings UI
|
|
344
|
-
│ ├── commands.ts # Per-factory user-command
|
|
328
|
+
│ ├── commands.ts # Per-factory user-command controller
|
|
345
329
|
│ ├── tools.ts # Goal completion and blocker tool adapters
|
|
346
330
|
│ ├── lifecycle.ts # Pi session, agent, tool, and compaction event adapter
|
|
347
331
|
│ ├── runtime.ts # Per-factory Goal state, transitions, prompts, and budgets
|
|
@@ -351,7 +335,6 @@ packages/pi-goal/
|
|
|
351
335
|
│ ├── errors.ts # Pi-aligned provider error and retry classification
|
|
352
336
|
│ ├── markers.ts # Bounded Goal prompt marker parsing and formatting
|
|
353
337
|
│ ├── run-protocol.ts # Default-off managed-run protocol and session ownership
|
|
354
|
-
│ ├── queue.ts # Pure ordered-goal transitions
|
|
355
338
|
│ └── *.ts # Package-local parsing, settings, prompts, accounting, and persistence
|
|
356
339
|
├── README.md
|
|
357
340
|
├── LICENSE
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-goal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pi extension for autonomous /goal completion
|
|
3
|
+
"version": "0.52.1",
|
|
4
|
+
"description": "Pi extension for autonomous single-objective /goal completion.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"pi-extension",
|
|
11
11
|
"pi",
|
|
12
12
|
"goal",
|
|
13
|
-
"queue",
|
|
14
13
|
"automation"
|
|
15
14
|
],
|
|
16
15
|
"files": [
|
|
@@ -39,15 +38,15 @@
|
|
|
39
38
|
"typebox": "*"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@biomejs/biome": "2.5.
|
|
43
|
-
"@earendil-works/pi-ai": "0.84.
|
|
44
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
45
|
-
"@earendil-works/pi-tui": "0.84.
|
|
46
|
-
"typebox": "1.3.
|
|
41
|
+
"@biomejs/biome": "2.5.8",
|
|
42
|
+
"@earendil-works/pi-ai": "0.84.2",
|
|
43
|
+
"@earendil-works/pi-coding-agent": "0.84.2",
|
|
44
|
+
"@earendil-works/pi-tui": "0.84.2",
|
|
45
|
+
"typebox": "1.3.14",
|
|
47
46
|
"typescript": "7.0.2"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
49
|
+
"@narumitw/pi-tui-kit": "^0.56.0"
|
|
51
50
|
},
|
|
52
51
|
"repository": {
|
|
53
52
|
"type": "git",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { completeGoalArguments, parseCommand } from "./command.js";
|
|
2
|
+
import { completeGoalArguments, isRemovedQueueCommand, parseCommand } from "./command.js";
|
|
3
3
|
import type { GoalCommandController } from "./commands.js";
|
|
4
4
|
import { notifyTerminal, safeTerminalText } from "./errors.js";
|
|
5
5
|
import type { GoalRuntime } from "./runtime.js";
|
|
@@ -28,14 +28,13 @@ export function registerGoalCommand(
|
|
|
28
28
|
|
|
29
29
|
pi.registerCommand("goal", {
|
|
30
30
|
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
31
|
-
getArgumentCompletions: (prefix) =>
|
|
32
|
-
completeGoalArguments(prefix, {
|
|
33
|
-
experimentalGoals: runtime.settings.experimental.goals,
|
|
34
|
-
}),
|
|
31
|
+
getArgumentCompletions: (prefix) => completeGoalArguments(prefix),
|
|
35
32
|
handler: async (args, ctx) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
if (runtime.hasLegacyQueueInterface() && isRemovedQueueCommand(args)) {
|
|
34
|
+
reportRemovedQueueCommand(ctx, runtime);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = parseCommand(args);
|
|
39
38
|
if (typeof result === "string") {
|
|
40
39
|
reportCommandError(result, ctx);
|
|
41
40
|
return;
|
|
@@ -65,28 +64,10 @@ export function registerGoalCommand(
|
|
|
65
64
|
await showGoalSettings(runtime, menuCtx, {
|
|
66
65
|
settingsPath: options.settingsPath,
|
|
67
66
|
initialScreen: target,
|
|
68
|
-
onQueueUnfrozen: async (settingsCtx) => {
|
|
69
|
-
await commands.resumeQueueAfterUnfreeze(settingsCtx);
|
|
70
|
-
},
|
|
71
67
|
});
|
|
72
68
|
});
|
|
73
69
|
return;
|
|
74
70
|
}
|
|
75
|
-
if (runtime.queueFrozen) {
|
|
76
|
-
if (result.kind === "show") commands.showGoal(ctx);
|
|
77
|
-
else if (result.kind === "clear") commands.clearGoal(ctx);
|
|
78
|
-
else commands.notifyFrozenQueue(ctx);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (runtime.pendingQueueAction && result.kind !== "show" && result.kind !== "clear") {
|
|
82
|
-
notifyTerminal(
|
|
83
|
-
ctx.ui,
|
|
84
|
-
"A queued goal change is waiting for Pi to settle. Retry after it finishes.",
|
|
85
|
-
"warning",
|
|
86
|
-
);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
71
|
switch (result.kind) {
|
|
91
72
|
case "show":
|
|
92
73
|
commands.showGoal(ctx);
|
|
@@ -103,18 +84,6 @@ export function registerGoalCommand(
|
|
|
103
84
|
case "edit":
|
|
104
85
|
await commands.editGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
105
86
|
return;
|
|
106
|
-
case "add":
|
|
107
|
-
await commands.addGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
108
|
-
return;
|
|
109
|
-
case "prioritize":
|
|
110
|
-
await commands.prioritizeGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
111
|
-
return;
|
|
112
|
-
case "drop-last":
|
|
113
|
-
commands.dropLastGoal(ctx);
|
|
114
|
-
return;
|
|
115
|
-
case "skip":
|
|
116
|
-
await commands.skipGoal(ctx);
|
|
117
|
-
return;
|
|
118
87
|
case "start":
|
|
119
88
|
await commands.startGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
120
89
|
return;
|
|
@@ -129,6 +98,14 @@ function reportCommandError(message: string, ctx: ExtensionCommandContext) {
|
|
|
129
98
|
notifyTerminal(ctx.ui, safeMessage, "warning");
|
|
130
99
|
}
|
|
131
100
|
|
|
101
|
+
function reportRemovedQueueCommand(ctx: ExtensionCommandContext, runtime: GoalRuntime) {
|
|
102
|
+
const message = runtime.activeGoal
|
|
103
|
+
? "Ordered goal queue has been removed. Use /goal edit to reprioritize the active objective instead."
|
|
104
|
+
: "Ordered goal queue has been removed. Start /goal <objectives> to continue with one merged objective, or use /goal clear to discard the old queue state.";
|
|
105
|
+
if (ctx.mode === "print" || ctx.mode === "json") throw new Error(message);
|
|
106
|
+
notifyTerminal(ctx.ui, message, "warning");
|
|
107
|
+
}
|
|
108
|
+
|
|
132
109
|
function captureMenuOwnership(runtime: GoalRuntime): () => boolean {
|
|
133
110
|
const generation = runtime.menuGeneration;
|
|
134
111
|
const controller = runtime.menuController;
|
package/src/command.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
const MAX_OBJECTIVE_LENGTH = 4_000;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const REMOVED_QUEUE_COMMANDS = new Set([
|
|
4
|
+
"add",
|
|
5
|
+
"prioritize",
|
|
6
|
+
"drop-last",
|
|
7
|
+
"skip",
|
|
8
|
+
"push",
|
|
9
|
+
"unshift",
|
|
10
|
+
"pop",
|
|
11
|
+
"shift",
|
|
12
|
+
]);
|
|
6
13
|
|
|
7
14
|
export interface CommandResult {
|
|
8
|
-
kind:
|
|
9
|
-
| "start"
|
|
10
|
-
| "pause"
|
|
11
|
-
| "resume"
|
|
12
|
-
| "clear"
|
|
13
|
-
| "show"
|
|
14
|
-
| "edit"
|
|
15
|
-
| "add"
|
|
16
|
-
| "prioritize"
|
|
17
|
-
| "drop-last"
|
|
18
|
-
| "skip";
|
|
15
|
+
kind: "start" | "pause" | "resume" | "clear" | "show" | "edit";
|
|
19
16
|
objective?: string;
|
|
20
17
|
tokenBudget?: number;
|
|
21
18
|
}
|
|
@@ -39,63 +36,32 @@ const GOAL_ARGUMENT_COMPLETIONS: readonly GoalArgumentCompletion[] = [
|
|
|
39
36
|
{ value: "status", label: "status", description: "Show the current goal" },
|
|
40
37
|
TOKEN_BUDGET_COMPLETION,
|
|
41
38
|
];
|
|
42
|
-
const QUEUE_ARGUMENT_COMPLETIONS: readonly GoalArgumentCompletion[] = [
|
|
43
|
-
{ value: "add", label: "add", description: "Add a goal to the end of the queue" },
|
|
44
|
-
{
|
|
45
|
-
value: "prioritize",
|
|
46
|
-
label: "prioritize",
|
|
47
|
-
description: "Prioritize a new goal at the front of the queue",
|
|
48
|
-
},
|
|
49
|
-
{ value: "drop-last", label: "drop-last", description: "Remove the last goal" },
|
|
50
|
-
{ value: "skip", label: "skip", description: "Skip the current goal" },
|
|
51
|
-
];
|
|
52
39
|
|
|
53
|
-
export function completeGoalArguments(
|
|
54
|
-
argumentPrefix: string,
|
|
55
|
-
features: GoalCommandFeatures = {},
|
|
56
|
-
): GoalArgumentCompletion[] | null {
|
|
40
|
+
export function completeGoalArguments(argumentPrefix: string): GoalArgumentCompletion[] | null {
|
|
57
41
|
const prefix = argumentPrefix.trimStart();
|
|
58
|
-
|
|
59
|
-
? [
|
|
60
|
-
...GOAL_ARGUMENT_COMPLETIONS.slice(0, -1),
|
|
61
|
-
...QUEUE_ARGUMENT_COMPLETIONS,
|
|
62
|
-
TOKEN_BUDGET_COMPLETION,
|
|
63
|
-
]
|
|
64
|
-
: [...GOAL_ARGUMENT_COMPLETIONS];
|
|
65
|
-
if (prefix === "") return completions;
|
|
42
|
+
if (prefix === "") return [...GOAL_ARGUMENT_COMPLETIONS];
|
|
66
43
|
|
|
67
|
-
const objectiveOption =
|
|
68
|
-
? /^(edit|add|prioritize)\s+(\S*)$/.exec(prefix)
|
|
69
|
-
: /^edit\s+(\S*)$/.exec(prefix);
|
|
44
|
+
const objectiveOption = /^edit\s+(\S*)$/.exec(prefix);
|
|
70
45
|
if (objectiveOption) {
|
|
71
|
-
const
|
|
72
|
-
const optionPrefix = features.experimentalGoals
|
|
73
|
-
? (objectiveOption[2] ?? "")
|
|
74
|
-
: (objectiveOption[1] ?? "");
|
|
46
|
+
const optionPrefix = objectiveOption[1] ?? "";
|
|
75
47
|
return optionPrefix === "" || "--tokens".startsWith(optionPrefix)
|
|
76
48
|
? [
|
|
77
49
|
{
|
|
78
|
-
value:
|
|
50
|
+
value: "edit --tokens ",
|
|
79
51
|
label: "--tokens",
|
|
80
|
-
description:
|
|
81
|
-
command === "edit"
|
|
82
|
-
? "Set a token budget before the updated goal"
|
|
83
|
-
: "Set a token budget before the queued goal",
|
|
52
|
+
description: "Set a token budget before the updated goal",
|
|
84
53
|
},
|
|
85
54
|
]
|
|
86
55
|
: null;
|
|
87
56
|
}
|
|
88
57
|
if (/\s/.test(prefix)) return null;
|
|
89
|
-
const matches =
|
|
58
|
+
const matches = GOAL_ARGUMENT_COMPLETIONS.filter(
|
|
90
59
|
(item) => item.value.startsWith(prefix) || item.label.startsWith(prefix),
|
|
91
60
|
);
|
|
92
61
|
return matches.length > 0 ? matches : null;
|
|
93
62
|
}
|
|
94
63
|
|
|
95
|
-
export function parseCommand(
|
|
96
|
-
args: string,
|
|
97
|
-
features: GoalCommandFeatures = {},
|
|
98
|
-
): CommandResult | string {
|
|
64
|
+
export function parseCommand(args: string): CommandResult | string {
|
|
99
65
|
const tokens = tokenize(args.trim());
|
|
100
66
|
if (tokens.length === 0) return { kind: "show" };
|
|
101
67
|
const [first, ...rest] = tokens;
|
|
@@ -106,26 +72,15 @@ export function parseCommand(
|
|
|
106
72
|
if (first === "status") return rest.length === 0 ? { kind: "show" } : "Usage: /goal status";
|
|
107
73
|
if (first === "edit") return parseObjective("edit", rest);
|
|
108
74
|
|
|
109
|
-
if (features.experimentalGoals) {
|
|
110
|
-
if (first === "drop-last" || first === "pop") {
|
|
111
|
-
return rest.length === 0 ? { kind: "drop-last" } : "Usage: /goal drop-last";
|
|
112
|
-
}
|
|
113
|
-
if (first === "skip" || first === "shift") {
|
|
114
|
-
return rest.length === 0 ? { kind: "skip" } : "Usage: /goal skip";
|
|
115
|
-
}
|
|
116
|
-
if (first === "add" || first === "push") return parseObjective("add", rest);
|
|
117
|
-
if (first === "prioritize" || first === "unshift") {
|
|
118
|
-
return parseObjective("prioritize", rest);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
75
|
return parseObjective("start", tokens);
|
|
123
76
|
}
|
|
124
77
|
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
78
|
+
export function isRemovedQueueCommand(args: string) {
|
|
79
|
+
const [first] = tokenize(args.trim());
|
|
80
|
+
return first !== undefined && REMOVED_QUEUE_COMMANDS.has(first);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseObjective(kind: "start" | "edit", tokens: string[]): CommandResult | string {
|
|
129
84
|
let tokenBudget: number | undefined;
|
|
130
85
|
const objectiveTokens = [...tokens];
|
|
131
86
|
if (objectiveTokens[0] === "--tokens") {
|