@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.
- package/README.md +245 -118
- package/dist/chunks/chunk-ODVXYZXS.ts +1782 -0
- package/dist/chunks/chunk-ODVXYZXS.ts.map +7 -0
- package/dist/chunks/chunk-UA7LMS63.ts +348 -0
- package/dist/chunks/chunk-UA7LMS63.ts.map +7 -0
- package/dist/chunks/menu-YILEIJE6.ts +565 -0
- package/dist/chunks/menu-YILEIJE6.ts.map +7 -0
- package/dist/chunks/settings-ui-HMSJEEZN.ts +418 -0
- package/dist/chunks/settings-ui-HMSJEEZN.ts.map +7 -0
- package/dist/index.ts +1585 -0
- package/dist/index.ts.map +7 -0
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,39 +1,22 @@
|
|
|
1
|
-
# 🎯 pi-goal —
|
|
1
|
+
# 🎯 pi-goal — Keep Pi Working Toward a Goal
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-goal) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Give Pi a session-scoped objective and let it continue from each fully settled idle boundary until the work completes, pauses, waits, or reaches a safety limit.
|
|
6
6
|
|
|
7
|
-
Goal mode
|
|
7
|
+
Goal mode adds explicit completion, blocker, and external-wait tools so managed execution stops for a clear reason instead of looping blindly.
|
|
8
8
|
|
|
9
9
|
## ✨ Features
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
- Tracks distinct `active`, `paused`, `blocked`, `usage_limited`, `budget_limited`, and `complete` states.
|
|
21
|
-
- Stores goal state in the current Pi session, following Codex's thread-owned goal model instead of using a global per-directory goal.
|
|
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”.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
27
|
-
- Lets retry, compaction, steering, follow-up, and other queued work settle before automatic goal continuation.
|
|
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`).
|
|
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.
|
|
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.
|
|
31
|
-
- Preserves active goals across manual, threshold, and overflow compaction.
|
|
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.
|
|
33
|
-
- Rotates the completion guard id when a goal is resumed or edited so delayed old turns cannot complete the newer goal instance.
|
|
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.
|
|
35
|
-
- Applies one evidence-based completion audit across kickoff, resume, edit, system, continuation, and budget-wrap-up prompts.
|
|
36
|
-
- Optionally exposes a default-off, run-scoped `pi.events` protocol for trusted sibling extensions to start, observe, and cancel one Goal lifecycle without emulating `/goal` input.
|
|
11
|
+
- Starts or manages a session goal through one `/goal` command and direct status, pause, resume, edit, or clear routes.
|
|
12
|
+
- Continues exactly once from Pi's settled idle boundary after queued work, retries, and compaction have finished.
|
|
13
|
+
- Uses explicit `goal_complete`, `goal_blocked`, and `goal_wait` tools with stale-goal guards and evidence requirements.
|
|
14
|
+
- Tracks active, paused, blocked, usage-limited, budget-limited, waiting, and complete outcomes separately.
|
|
15
|
+
- Pauses after a configurable response limit or repeated no-progress runs and offers a guided review before continuing.
|
|
16
|
+
- Supports optional token budgets and a single guarded wrap-up when the budget is exhausted.
|
|
17
|
+
- Persists the goal in the current session across reload, resume, compatible forks, and compaction.
|
|
18
|
+
- Rejects stale continuations and tool calls after replacement, pause, completion, limits, or other terminal state changes.
|
|
19
|
+
- Optionally exposes a default-off run protocol for trusted sibling extensions to start, observe, and cancel one Goal lifecycle.
|
|
37
20
|
|
|
38
21
|
## 📦 Install
|
|
39
22
|
|
|
@@ -49,16 +32,24 @@ Try without installing permanently:
|
|
|
49
32
|
pi -e npm:@narumitw/pi-goal
|
|
50
33
|
```
|
|
51
34
|
|
|
52
|
-
|
|
35
|
+
Build and try this package locally from the repository root:
|
|
53
36
|
|
|
54
37
|
```bash
|
|
38
|
+
npm --workspace @narumitw/pi-goal run build
|
|
55
39
|
pi -e ./packages/pi-goal
|
|
56
40
|
```
|
|
57
41
|
|
|
58
|
-
|
|
42
|
+
The package declares `dist/index.ts`, so an unbuilt local checkout must run the build before Pi loads the package directory.
|
|
59
43
|
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
## 🚀 Quick start
|
|
45
|
+
|
|
46
|
+
Run `/goal <objective>` to start working toward an objective, or run `/goal` to open the state-aware manager.
|
|
47
|
+
Use the manager to review status, pause, resume, edit, or clear the current goal.
|
|
48
|
+
|
|
49
|
+
## ⚙️ Settings
|
|
50
|
+
|
|
51
|
+
Settings are optional.
|
|
52
|
+
When `~/.pi/agent/pi-goal.json` is absent, pi-goal uses these built-in defaults without creating the file:
|
|
62
53
|
|
|
63
54
|
```json
|
|
64
55
|
{
|
|
@@ -73,40 +64,74 @@ built-in defaults without creating the file:
|
|
|
73
64
|
}
|
|
74
65
|
```
|
|
75
66
|
|
|
76
|
-
Use `/goal` → **Settings…** in the TUI to create or update the file interactively, or create
|
|
77
|
-
|
|
78
|
-
order; the two safety limits open standard choice screens:
|
|
67
|
+
Use `/goal` → **Settings…** in the TUI to create or update the file interactively, or create and edit it directly.
|
|
68
|
+
The standard Settings screen keeps all four controls on one level in task order; the two safety limits open standard choice screens:
|
|
79
69
|
|
|
80
|
-
- **Automatic-work limit** shows the exact response limit or **Unlimited**.
|
|
81
|
-
|
|
70
|
+
- **Automatic-work limit** shows the exact response limit or **Unlimited**.
|
|
71
|
+
Choose **Set response limit…** to edit the current finite value (or the built-in default of 25 when switching from Unlimited), or choose **Unlimited…**.
|
|
72
|
+
Unlimited requires confirmation that tool loops may continue consuming tokens and provider cost without a response-count cap.
|
|
73
|
+
- **No-progress guard** shows **_N_ runs** or **Off**.
|
|
74
|
+
Choose the default threshold, **Off**, or **Set threshold…** and enter a safe whole number greater than zero.
|
|
82
75
|
- **Goal tools** controls whether all Goal tools are always visible or appear after the first goal.
|
|
83
|
-
- **Managed run RPC** controls whether trusted installed extensions may start and cancel managed Goal runs.
|
|
76
|
+
- **Managed run RPC** controls whether trusted installed extensions may start and cancel managed Goal runs.
|
|
77
|
+
It defaults to **Off** and is a cooperation setting, not an extension security sandbox.
|
|
84
78
|
|
|
85
|
-
Custom number inputs reject zero, negative numbers, decimals, text, and unsafe integers without saving; use the explicit **Unlimited** or **Off** choice instead.
|
|
79
|
+
Custom number inputs reject zero, negative numbers, decimals, text, and unsafe integers without saving; use the explicit **Unlimited** or **Off** choice instead.
|
|
80
|
+
Interactive changes are serialized, written atomically, preserve unknown fields, and apply to the current runtime.
|
|
81
|
+
A successful change updates the visible state immediately.
|
|
82
|
+
A failed save restores the prior value and reports the settings path so it can be retried.
|
|
83
|
+
Tool-visibility changes that would alter the active tool schema are rejected while Pi is busy; retry after Pi settles.
|
|
84
|
+
Escape returns to the previous screen without reverting changes that were already saved.
|
|
86
85
|
|
|
87
86
|
`toolVisibility` accepts:
|
|
88
87
|
|
|
89
88
|
- `"always"` — pi-goal does not proactively hide `goal_complete`, `goal_blocked`, or `goal_wait`, keeping the Goal tool schema stable from session startup.
|
|
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.
|
|
89
|
+
- `"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.
|
|
90
|
+
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.
|
|
91
|
+
Failed kickoff, replacement, resume, or reactivating-edit delivery restores the exact pre-activation tool set, including Goal tools exposed by another extension.
|
|
92
|
+
If revealing the tools would widen an already-running turn, wait for Pi to become idle and retry `/goal`.
|
|
91
93
|
|
|
92
|
-
`experimental.goals` is a removed legacy setting.
|
|
94
|
+
`experimental.goals` is a removed legacy setting.
|
|
95
|
+
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.
|
|
96
|
+
Later settings saves preserve unknown legacy fields instead of deleting them.
|
|
93
97
|
|
|
94
|
-
`rpc.enabled` accepts a boolean and defaults to `false`.
|
|
98
|
+
`rpc.enabled` accepts a boolean and defaults to `false`.
|
|
99
|
+
When disabled, a valid managed-run start receives `RPC_DISABLED`; manual and restored Goals remain unchanged.
|
|
100
|
+
A Settings-menu change applies immediately after its atomic save.
|
|
101
|
+
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.
|
|
102
|
+
Reload, replacement, and shutdown clear that in-memory ownership.
|
|
95
103
|
|
|
96
104
|
`continuationLimits` controls the runaway guards:
|
|
97
105
|
|
|
98
|
-
- `automaticTurns` accepts a positive safe integer or `null` and defaults to `25`.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
- `automaticTurns` accepts a positive safe integer or `null` and defaults to `25`.
|
|
107
|
+
It counts every completed normal `turn_end` owned by automatically started Goal work, including model responses inside tool loops and matching Pi-owned retries.
|
|
108
|
+
The user-triggered kickoff, resume, edit, and ordinary user runs are not charged.
|
|
109
|
+
At the limit, the goal becomes `paused` with cause `continuation_limit`, pending continuation/recovery is cancelled, and the current operation is aborted before a 26th normal response starts.
|
|
110
|
+
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.
|
|
111
|
+
Set this field explicitly to `null` to opt into Unlimited mode; existing explicit `null` values remain compatible.
|
|
112
|
+
- `noProgressTurns` is a positive safe integer and defaults to `3`.
|
|
113
|
+
At the end of an automatic run, pi-goal compares visible assistant text after Unicode normalization, lowercasing, control-character removal, and whitespace collapse.
|
|
114
|
+
Thinking and tool blocks are excluded; empty and punctuation-only output are equivalent.
|
|
115
|
+
Consecutive empty or identical tool-free outputs increment the repeat count.
|
|
116
|
+
Different non-empty output starts a new run at one, and any attempted tool call resets it.
|
|
117
|
+
Set this field to `null` to disable only this heuristic.
|
|
118
|
+
|
|
119
|
+
Settings are reread at Pi startup, session replacement, and `/reload`; direct external file edits are not watched live, while changes made through the Goal menu apply immediately.
|
|
120
|
+
A missing file remains absent and uses the built-in defaults.
|
|
121
|
+
The first successful settings change creates the file atomically; later saves preserve unknown fields.
|
|
122
|
+
|
|
123
|
+
Omitted fields use the defaults above.
|
|
124
|
+
Invalid or malformed existing settings are never overwritten; they produce a warning and fall back to all defaults.
|
|
125
|
+
In the TUI, Goal Settings becomes a read-only summary that identifies the invalid file and directs the user to fix it and run `/reload`.
|
|
126
|
+
Reload Pi after changing the file.
|
|
127
|
+
If a live runtime reloads settings, switching `toolVisibility` to `"always"` restores only the exact tools that pi-goal previously hid, while switching to `"after-first-goal"` locks a runtime that has no unfinished goal.
|
|
128
|
+
|
|
129
|
+
Tool visibility is a baseline, not ownership of Pi's global active-tool list.
|
|
130
|
+
Plan mode or another restrictive policy may temporarily hide the tools. pi-goal does not fight that policy on restore or on every turn: activation is rejected if the required terminal tools cannot be made available, and an already-active goal is paused without automatic continuation if they disappear.
|
|
131
|
+
A restrictive allowlist created before `goal_wait` existed can still run ordinary Goals with `goal_complete` and `goal_blocked`, but the model cannot enter external waiting until that allowlist also includes `goal_wait`.
|
|
132
|
+
The pause aborts a Goal-owned kickoff, resume, active-edit, or automatic-continuation prompt, but it does not cancel or stale-block an unrelated user or extension turn, including startup follow-ups after a restrictive restore.
|
|
133
|
+
|
|
134
|
+
## 💬 Commands
|
|
110
135
|
|
|
111
136
|
```text
|
|
112
137
|
/goal
|
|
@@ -119,26 +144,34 @@ Tool visibility is a baseline, not ownership of Pi's global active-tool list. Pl
|
|
|
119
144
|
/goal clear
|
|
120
145
|
```
|
|
121
146
|
|
|
122
|
-
- In the TUI, `/goal` opens a standard state-aware manager.
|
|
123
|
-
state: start when empty, pause when active, review a reached automatic-work limit, resume for other
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
- `/goal --tokens 100k <goal_to_complete>` starts or replaces goal mode with a token budget.
|
|
139
|
-
|
|
140
|
-
- `/goal
|
|
141
|
-
|
|
147
|
+
- In the TUI, `/goal` opens a standard state-aware manager.
|
|
148
|
+
Its first action follows the current state: start when empty, pause when active, review a reached automatic-work limit, resume for other stopped states, or increase an exhausted token budget.
|
|
149
|
+
Active and paused views show **Automatic work: _used_ of _limit_ responses** with the remaining count, or explicitly show **Unlimited**.
|
|
150
|
+
A hard-cap pause opens **Review and continue…**, which states that objective, cumulative usage, and active time are preserved and previews that Continue resets the counter to zero and allows up to one more configured epoch.
|
|
151
|
+
**Change automatic-work limit…** opens that setting while leaving the goal paused; Back and Escape make no change.
|
|
152
|
+
**Start with token budget…** first offers `25k`, a suggested `100k`, `300k`, and **Set a custom budget…**, then collects the objective with the selected budget still visible.
|
|
153
|
+
Custom input accepts examples such as `300000`, `300k`, `2.5k`, and `1.5m`; invalid input retains its draft for correction.
|
|
154
|
+
Status, Settings, Help, invalid-settings guidance, Clear, and Close remain shallow, labeled routes.
|
|
155
|
+
Arrow keys navigate, Enter selects or submits, Escape goes Back, and Ctrl+C closes the full flow.
|
|
156
|
+
- In RPC mode, bare `/goal` and `/goal status` report the current summary through an observable notification without opening terminal UI.
|
|
157
|
+
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.
|
|
158
|
+
- Menu-driven Replace and Clear actions preview the exact affected goal and require confirmation.
|
|
159
|
+
Existing direct routes remain immediate for compatibility and automation.
|
|
160
|
+
- `/goal <goal_to_complete>` starts goal mode.
|
|
161
|
+
If another unfinished goal exists, Pi asks for confirmation before replacing it with a new active goal and resetting its usage counters.
|
|
162
|
+
Failed kickoff delivery clears a new goal or restores the prior goal; a previously active goal is restored as paused.
|
|
163
|
+
- `/goal --tokens 100k <goal_to_complete>` starts or replaces goal mode with a token budget.
|
|
164
|
+
`k` and `m` suffixes are accepted, for example `100k` or `1.5m`.
|
|
165
|
+
- `/goal edit <goal_to_complete>` updates the existing goal objective without resetting usage counters.
|
|
166
|
+
A successful active edit rotates the stale-turn guard and starts a fresh safety epoch.
|
|
167
|
+
Paused, blocked, and usage-limited goals stay stopped and retain their safety state until resume.
|
|
168
|
+
A budget-limited goal reactivates only when `edit --tokens` raises its budget above current usage.
|
|
169
|
+
Failed prompt delivery restores the exact previous safety counters/cause; it restores a budget-limited goal or restores and pauses a previously active goal.
|
|
170
|
+
- `/goal pause` stops prompt injection and auto-continuation, aborts the current turn, and keeps the goal for later resume.
|
|
171
|
+
Only active goals can be paused.
|
|
172
|
+
- `/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.
|
|
173
|
+
Objective, cumulative usage, and elapsed time are preserved.
|
|
174
|
+
If prompt delivery fails, the original stopped state, guard id, counters, fingerprint, and cause are restored.
|
|
142
175
|
- `/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.
|
|
143
176
|
|
|
144
177
|
The experimental ordered-goal queue has been removed.
|
|
@@ -148,21 +181,42 @@ For example, if `task b` is complete and `task c` is in progress, edit the objec
|
|
|
148
181
|
Former queue command words such as `add`, `prioritize`, `drop-last`, `skip`, `push`, `unshift`, `pop`, and `shift` are ordinary objective text for unaffected users.
|
|
149
182
|
If a session still has legacy queue settings or persisted queue state, those words show a migration warning instead of replacing the active Goal.
|
|
150
183
|
|
|
151
|
-
Goal objectives are limited to 4,000 characters.
|
|
184
|
+
Goal objectives are limited to 4,000 characters.
|
|
185
|
+
Put longer instructions in a file and reference the file path from `/goal`.
|
|
186
|
+
|
|
187
|
+
## 🛠️ Tools
|
|
188
|
+
|
|
189
|
+
- `goal_complete` records completion only for the exact active goal id and requires an evidence-based summary.
|
|
190
|
+
- `goal_blocked` records a true repeated impasse with the exact goal id, reason, evidence, and repeated-turn count.
|
|
191
|
+
- `goal_wait` pauses automatic continuation after the agent arranges an external wake source, with an optional bounded resume deadline.
|
|
152
192
|
|
|
153
193
|
## 🔁 Session and reload behavior
|
|
154
194
|
|
|
155
|
-
Goal state is stored as Pi session state, similar to Codex's thread-owned goals.
|
|
195
|
+
Goal state is stored as Pi session state, similar to Codex's thread-owned goals.
|
|
196
|
+
`/reload` and reopening the same Pi session can restore that session's unfinished goal.
|
|
197
|
+
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.
|
|
198
|
+
A restored waiting Goal remains quiet, excludes offline and waiting wall time from active elapsed time, and restores only its absolute optional deadline timer.
|
|
199
|
+
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.
|
|
200
|
+
If no unfinished goal remains, a fresh runtime starts locked again.
|
|
201
|
+
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.
|
|
202
|
+
Automatic-response counts, repeat fingerprints, and safety-pause causes persist across reload and compaction.
|
|
203
|
+
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.
|
|
204
|
+
Starting a new Pi session in the same working directory does not inherit the old goal.
|
|
156
205
|
|
|
157
|
-
The legacy `{ goal }` shape remains valid, and missing safety fields normalize to zero/defaults.
|
|
206
|
+
The legacy `{ goal }` shape remains valid, and missing safety fields normalize to zero/defaults.
|
|
207
|
+
Sessions created by the former standalone `pi-goals` experiment can still restore exactly one ordinary unfinished goal when no canonical `goal-state` entry exists.
|
|
158
208
|
|
|
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.
|
|
209
|
+
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.
|
|
210
|
+
It does not inject Goal prompts, advance the queue, or run any retained item automatically.
|
|
211
|
+
Affected users receive a warning that recommends starting one merged objective with `/goal <objectives>`, or using `/goal clear` to discard the old queue state.
|
|
160
212
|
|
|
161
|
-
Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed by working directory.
|
|
213
|
+
Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed by working directory.
|
|
214
|
+
This version no longer reads that global file, and `/goal clear` removes any legacy entry for the current working directory.
|
|
162
215
|
|
|
163
216
|
## 📊 Statusline states
|
|
164
217
|
|
|
165
|
-
`pi-goal` writes compact plain status strings for statusline extensions.
|
|
218
|
+
`pi-goal` writes compact plain status strings for statusline extensions.
|
|
219
|
+
`@narumitw/pi-statusline` adds the default `🎯` icon unless configured otherwise:
|
|
166
220
|
|
|
167
221
|
- `active 3m · automatic 12/25` — an active goal without a token budget; elapsed time counts only periods when its status is active and not waiting.
|
|
168
222
|
- `waiting review monitor · automatic 12/25` — an active Goal is quiet until non-Goal work or its optional deadline wakes it; the displayed reason is sanitized and bounded.
|
|
@@ -177,33 +231,54 @@ Older versions wrote unfinished goals to `~/.pi/agent/pi-goal-state.json` keyed
|
|
|
177
231
|
|
|
178
232
|
## 💰 Token budgets and elapsed time
|
|
179
233
|
|
|
180
|
-
The TUI budget chooser describes token budgets as cumulative Goal usage, warns that the final model
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
above current usage, previews the new total plus automatic-work epoch, and resumes only after
|
|
186
|
-
confirmation. If the goal or its usage changes while that dialog is open, no change is applied.
|
|
234
|
+
The TUI budget chooser describes token budgets as cumulative Goal usage, warns that the final model call may exceed the chosen value, and keeps the independent automatic-work response limit visible.
|
|
235
|
+
It is not a dollar-cost cap.
|
|
236
|
+
Choosing a preset or entering a custom value remains provisional until the objective is submitted; cancelling the chooser, custom input, or objective editor creates no Goal.
|
|
237
|
+
**Increase budget and resume…** shows the exact current budget and usage, requires a new total above current usage, previews the new total plus automatic-work epoch, and resumes only after confirmation.
|
|
238
|
+
If the goal or its usage changes while that dialog is open, no change is applied.
|
|
187
239
|
|
|
188
|
-
For each persisted assistant message, `pi-goal` uses finite, non-negative `usage.totalTokens` when available.
|
|
240
|
+
For each persisted assistant message, `pi-goal` uses finite, non-negative `usage.totalTokens` when available.
|
|
241
|
+
For compatibility with older or partial records, it otherwise sums finite, non-negative `input + output + cacheRead + cacheWrite`.
|
|
242
|
+
It does not add `reasoning` because reasoning is already part of output, or `cacheWrite1h` because that is a subset of cache writes.
|
|
243
|
+
Goal usage is the current branch's cumulative assistant total minus the baseline captured when the goal started, clamped at zero after branch rewinds.
|
|
189
244
|
|
|
190
|
-
Provider usage becomes authoritative only when an assistant message finishes, so a budget can overshoot by one model call.
|
|
245
|
+
Provider usage becomes authoritative only when an assistant message finishes, so a budget can overshoot by one model call.
|
|
246
|
+
When completed tool activity first exposes exhaustion, the goal transitions once to `budget_limited`, cancels continuation, and queues one bounded custom wrap-up instruction before the next model call.
|
|
247
|
+
The instruction permits only a concise progress/results/blockers summary; a substantive tool attempt is blocked and aborts the remaining wrap-up.
|
|
248
|
+
A rejected `goal_complete` also terminates the wrap-up, while accepted completion still requires existing evidence that proves every requirement—budget exhaustion itself never means completion.
|
|
249
|
+
If exhaustion is first visible at `agent_end` and no turn remains, the extension stops without creating another model turn.
|
|
191
250
|
|
|
192
|
-
The default 25-response automatic-work limit is a response-count boundary, not a fixed cost ceiling: context size, cache pricing, output length, and provider rates vary, and the final capped response is still retained.
|
|
251
|
+
The default 25-response automatic-work limit is a response-count boundary, not a fixed cost ceiling: context size, cache pricing, output length, and provider rates vary, and the final capped response is still retained.
|
|
252
|
+
Pi derives displayed cost estimates from provider-reported token usage and local model pricing; pi-goal does not query a billing balance or enforce a dollar cap.
|
|
253
|
+
For tighter token control, choose a smaller `automaticTurns` value and/or use `/goal --tokens`; choosing Unlimited removes only the response-count boundary.
|
|
193
254
|
|
|
194
|
-
Elapsed time is accumulated only while status is `active`.
|
|
255
|
+
Elapsed time is accumulated only while status is `active`.
|
|
256
|
+
Pause, blocked, usage-limited, budget-limited, shutdown, and offline periods do not increase it.
|
|
257
|
+
Legacy session entries are migrated by preserving their accumulated seconds and starting a fresh active clock when loaded.
|
|
195
258
|
|
|
196
259
|
## ✅ How completion works
|
|
197
260
|
|
|
198
|
-
While a goal is active, `pi-goal` injects persistence rules, a `<goal_id>` stale-turn guard, and exposes `goal_complete`.
|
|
261
|
+
While a goal is active, `pi-goal` injects persistence rules, a `<goal_id>` stale-turn guard, and exposes `goal_complete`.
|
|
262
|
+
Kickoff, resume, edited-objective, system, and automatic-continuation prompts all place a trust boundary before the escaped objective, identifying it as user-provided task data; they preserve its full scope across turns and require the agent to derive concrete requirements from the objective and referenced artifacts.
|
|
263
|
+
They treat the current worktree, command output, tests, runtime behavior, PR state, rendered artifacts, and external state as authoritative; previous conversation and plans are context rather than proof.
|
|
199
264
|
|
|
200
|
-
Before completion, the shared audit tells the agent to treat completion as unproven, inspect requirement-by-requirement evidence for every named artifact, command, test, gate, invariant, and deliverable, and match each check's scope to the requirement it supports.
|
|
265
|
+
Before completion, the shared audit tells the agent to treat completion as unproven, inspect requirement-by-requirement evidence for every named artifact, command, test, gate, invariant, and deliverable, and match each check's scope to the requirement it supports.
|
|
266
|
+
Weak, indirect, missing, or merely consistent evidence means work must continue.
|
|
267
|
+
This prompt wording is a behavioral guardrail, not proof by itself: `pi-goal` can enforce the current goal id and reject empty or plainly contradictory summaries, but it cannot independently prove that external work is complete.
|
|
201
268
|
|
|
202
|
-
To finish, the agent must call `goal_complete` with the exact current `goal_id` and a `summary` of completion evidence.
|
|
269
|
+
To finish, the agent must call `goal_complete` with the exact current `goal_id` and a `summary` of completion evidence.
|
|
270
|
+
Missing or stale `goal_id` values are rejected before summary validation.
|
|
271
|
+
Paused, blocked, and usage-limited goals cannot be completed until resumed; a budget-limited goal permits completion only during its bounded in-flight wrap-up.
|
|
272
|
+
The summary is completion evidence, not the stale-turn safety token.
|
|
203
273
|
|
|
204
|
-
If a turn ends before completion, `pi-goal` records usage and creates one continuation intent unless a circuit breaker pauses it first.
|
|
274
|
+
If a turn ends before completion, `pi-goal` records usage and creates one continuation intent unless a circuit breaker pauses it first.
|
|
275
|
+
It dispatches that continuation only from Pi's `agent_settled` lifecycle after retries, automatic compaction, steering, and follow-up work have drained, `ctx.isIdle()` is true, and no messages are pending.
|
|
276
|
+
Repeated settled events cannot dispatch the same intent twice.
|
|
277
|
+
Goal-owned kickoff, resume, active-edit, and automatic-continuation deliveries are bound to the goal instance that created them; a delayed prompt from a replaced goal is aborted without rolling back, injecting, or stopping the newer goal.
|
|
278
|
+
Plain assistant text never marks a goal complete—even an exact-reply objective pauses safely when the model repeatedly omits `goal_complete`.
|
|
205
279
|
|
|
206
|
-
Manual compaction does not emit `agent_settled`, so its completion hook uses the same single-flight dispatcher as a narrow idle-only fallback.
|
|
280
|
+
Manual compaction does not emit `agent_settled`, so its completion hook uses the same single-flight dispatcher as a narrow idle-only fallback.
|
|
281
|
+
Pi extensions cannot reserve an idle turn atomically like Codex core; another extension can still win the race after the idle check, and its newer turn supersedes the old continuation intent.
|
|
207
282
|
|
|
208
283
|
## ⏳ External waiting
|
|
209
284
|
|
|
@@ -217,31 +292,59 @@ goal_wait({
|
|
|
217
292
|
})
|
|
218
293
|
```
|
|
219
294
|
|
|
220
|
-
`goal_id` must match the current active Goal, `reason` must contain 1–1,000 characters, and the optional `resume_after_ms` must be a whole number from 1 through 2,147,483,647.
|
|
295
|
+
`goal_id` must match the current active Goal, `reason` must contain 1–1,000 characters, and the optional `resume_after_ms` must be a whole number from 1 through 2,147,483,647.
|
|
296
|
+
The deadline is a safety wake-up rather than a polling interval.
|
|
297
|
+
Requests below 10,000 milliseconds are accepted for compatibility but clamped to an effective 10,000-millisecond deadline; the tool result reports both the requested and effective values.
|
|
298
|
+
Prefer deadlines measured in minutes instead of repeated short wakes.
|
|
299
|
+
Omitting `resume_after_ms` intentionally permits an indefinite quiet wait.
|
|
221
300
|
|
|
222
|
-
An accepted call keeps the canonical Goal status active, checkpoints active elapsed time, cancels pending continuation work, persists the reason and absolute optional deadline, and terminates the normal single-tool run.
|
|
301
|
+
An accepted call keeps the canonical Goal status active, checkpoints active elapsed time, cancels pending continuation work, persists the reason and absolute optional deadline, and terminates the normal single-tool run.
|
|
302
|
+
Call `goal_wait` alone because Pi only guarantees early termination when every finalized result in a parallel tool batch terminates.
|
|
223
303
|
|
|
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.
|
|
304
|
+
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.
|
|
305
|
+
Pi does not expose the sending extension's identity, so any non-Goal extension message is treated as a wake signal.
|
|
225
306
|
|
|
226
|
-
After a waking turn ends, ordinary continuation rules apply again.
|
|
307
|
+
After a waking turn ends, ordinary continuation rules apply again.
|
|
308
|
+
The agent can complete or block the Goal, continue working, or call `goal_wait` again after arranging the next wake source.
|
|
309
|
+
`/goal resume` also clears waiting and sends one manual resume prompt without resetting cumulative usage or the safety epoch.
|
|
310
|
+
`/goal pause`, clear, edit, replace, completion, blocking, terminal limits, tool loss, session replacement, and shutdown cancel the in-memory deadline owner.
|
|
227
311
|
|
|
228
|
-
A future deadline is restored from its absolute timestamp after reload.
|
|
312
|
+
A future deadline is restored from its absolute timestamp after reload.
|
|
313
|
+
Reload never restarts, extends, or newly clamps an already-persisted absolute deadline, including a short deadline written by an older version.
|
|
314
|
+
An already-due deadline waits for Pi's settled, idle, no-pending-message boundary and then requests exactly one continuation through the normal dispatcher.
|
|
315
|
+
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.
|
|
316
|
+
A deadline never sends a prompt directly from a stale timer.
|
|
229
317
|
|
|
230
|
-
Waiting time is excluded from **Active elapsed**, while tokens, iteration, automatic-response count, no-progress state, managed-run ownership remain preserved.
|
|
318
|
+
Waiting time is excluded from **Active elapsed**, while tokens, iteration, automatic-response count, no-progress state, managed-run ownership remain preserved.
|
|
319
|
+
The managed-run protocol continues reporting `active` because waiting is non-terminal.
|
|
320
|
+
Editing or replacing a waiting Goal clears the previous wait so the updated objective performs a fresh external-state check.
|
|
231
321
|
|
|
232
322
|
## 🚧 Blocked goals
|
|
233
323
|
|
|
234
|
-
`goal_blocked` is intentionally narrower than completion or ordinary clarification.
|
|
324
|
+
`goal_blocked` is intentionally narrower than completion or ordinary clarification.
|
|
325
|
+
Every goal-mode prompt repeats the blocked audit: the model must provide the exact current `goal_id`, a specific reason describing the user or external action required (up to 1,000 characters), concrete evidence from the failed resolution attempts (up to 4,000 characters), and `repeated_turns` showing the same blocker recurred for at least three consecutive goal turns.
|
|
326
|
+
A resumed goal starts a fresh blocker audit.
|
|
327
|
+
Empty or oversized reasons/evidence, stale ids, non-whole turn counts, stopped goals, and fewer than three turns are rejected.
|
|
328
|
+
Accepted blocker reports set `blocked`, stop automatic continuation, and terminate the tool batch when Pi can do so safely.
|
|
235
329
|
|
|
236
|
-
Do not use `goal_blocked` merely because work is difficult, incomplete, uncertain, awaiting normal clarification, or affected by a recoverable tool/provider failure.
|
|
330
|
+
Do not use `goal_blocked` merely because work is difficult, incomplete, uncertain, awaiting normal clarification, or affected by a recoverable tool/provider failure.
|
|
331
|
+
The user can resolve the external condition and run `/goal resume` to rotate the goal id and continue.
|
|
237
332
|
|
|
238
333
|
## 🛑 Interruption and queued-input behavior
|
|
239
334
|
|
|
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`.
|
|
335
|
+
A user pause or aborted turn produces `paused`; a terminal provider/account quota error produces `usage_limited`; another non-retryable agent error produces `blocked`.
|
|
336
|
+
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`.
|
|
337
|
+
On `/goal clear`, the extension clears goal state, continuation markers, and any stale tool-call block without aborting an unrelated in-flight turn.
|
|
338
|
+
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.
|
|
339
|
+
If matching recovery still exists at `agent_settled`, retries are exhausted and the goal becomes `blocked` before any continuation dispatches.
|
|
340
|
+
Stale recovery cannot block a replacement goal.
|
|
341
|
+
User and extension work that starts before settlement supersedes the older continuation intent, and pending messages always take priority.
|
|
241
342
|
|
|
242
343
|
## 🤝 Managed run RPC
|
|
243
344
|
|
|
244
|
-
With `rpc.enabled: true`, pi-goal exposes a session-local, dependency-free protocol over Pi's shared `pi.events` bus.
|
|
345
|
+
With `rpc.enabled: true`, pi-goal exposes a session-local, dependency-free protocol over Pi's shared `pi.events` bus.
|
|
346
|
+
It is intended for trusted sibling extensions that need to start, observe, and cancel one Goal lifecycle without driving the `/goal` command.
|
|
347
|
+
Installed Pi extensions remain fully privileged: this setting controls only whether pi-goal cooperates with these channels and is not authentication or sandboxing.
|
|
245
348
|
|
|
246
349
|
The public channels are:
|
|
247
350
|
|
|
@@ -251,7 +354,8 @@ pi-goal:cancel
|
|
|
251
354
|
pi-goal:event:${runId}
|
|
252
355
|
```
|
|
253
356
|
|
|
254
|
-
The protocol intentionally has no separate version field or versioned channel namespace.
|
|
357
|
+
The protocol intentionally has no separate version field or versioned channel namespace.
|
|
358
|
+
Before starting, the caller must generate a session-unique `runId`, subscribe to its event channel, and then emit:
|
|
255
359
|
|
|
256
360
|
```ts
|
|
257
361
|
pi.events.emit("pi-goal:start", {
|
|
@@ -261,7 +365,9 @@ pi.events.emit("pi-goal:start", {
|
|
|
261
365
|
});
|
|
262
366
|
```
|
|
263
367
|
|
|
264
|
-
`runId` must match `^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$`; UUIDs are recommended.
|
|
368
|
+
`runId` must match `^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$`; UUIDs are recommended.
|
|
369
|
+
It is a correlation identifier, not a secret or authenticated caller identity.
|
|
370
|
+
The objective uses the same 4,000-character validation as `/goal`, and `tokenBudget` is an absolute positive integer rather than a `k`/`m` string.
|
|
265
371
|
|
|
266
372
|
A successful start produces canonical state on `pi-goal:event:${runId}`:
|
|
267
373
|
|
|
@@ -274,9 +380,15 @@ A successful start produces canonical state on `pi-goal:event:${runId}`:
|
|
|
274
380
|
}
|
|
275
381
|
```
|
|
276
382
|
|
|
277
|
-
Subsequent state events use `active`, `complete`, `blocked`, `paused`, `usage_limited`, `budget_limited`, or `cleared`.
|
|
383
|
+
Subsequent state events use `active`, `complete`, `blocked`, `paused`, `usage_limited`, `budget_limited`, or `cleared`.
|
|
384
|
+
`complete` is the only successful terminal outcome.
|
|
385
|
+
A matching completion may include `summary`; other terminal outcomes may include `reason`.
|
|
386
|
+
Events come only from canonical Goal persistence and only for the matching managed run.
|
|
387
|
+
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.
|
|
278
388
|
|
|
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.
|
|
389
|
+
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.
|
|
390
|
+
Other terminal statuses leave a stopped Goal that must be resolved or cleared first.
|
|
391
|
+
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.
|
|
280
392
|
|
|
281
393
|
To cancel before or after activation, emit the same `runId`:
|
|
282
394
|
|
|
@@ -287,7 +399,10 @@ pi.events.emit("pi-goal:cancel", {
|
|
|
287
399
|
});
|
|
288
400
|
```
|
|
289
401
|
|
|
290
|
-
Cancellation uses the normal Goal pause transition.
|
|
402
|
+
Cancellation uses the normal Goal pause transition.
|
|
403
|
+
It cannot affect a manual, restored, stale, or different run.
|
|
404
|
+
The resulting `paused` state is the cancellation result; there is no separate reply envelope.
|
|
405
|
+
A caller must not reopen a terminal `runId`, and a later manual `/goal resume` is outside that completed managed run.
|
|
291
406
|
|
|
292
407
|
Rejected operations emit a structured error on the same run event channel:
|
|
293
408
|
|
|
@@ -303,11 +418,16 @@ Rejected operations emit a structured error on the same run event channel:
|
|
|
303
418
|
}
|
|
304
419
|
```
|
|
305
420
|
|
|
306
|
-
Stable codes are `RPC_DISABLED`, `INVALID_REQUEST`, `NO_ACTIVE_SESSION`, `RUN_ID_IN_USE`, `RUN_NOT_FOUND`, `GOAL_ALREADY_EXISTS`, `ACTIVATION_FAILED`, and `SUPERSEDED`.
|
|
421
|
+
Stable codes are `RPC_DISABLED`, `INVALID_REQUEST`, `NO_ACTIVE_SESSION`, `RUN_ID_IN_USE`, `RUN_NOT_FOUND`, `GOAL_ALREADY_EXISTS`, `ACTIVATION_FAILED`, and `SUPERSEDED`.
|
|
422
|
+
Consumers branch on `code`; `message` is diagnostic.
|
|
423
|
+
An unsafe or missing `runId` is ignored because there is no safe response channel.
|
|
307
424
|
|
|
308
|
-
Start never prompts for replacement: any pre-existing Goal is rejected.
|
|
425
|
+
Start never prompts for replacement: any pre-existing Goal is rejected.
|
|
426
|
+
The protocol binds only after current settings and restored Goal state load, and unbinds before session shutdown.
|
|
427
|
+
A caller must not assume that `emit()` waits for Goal completion; it should wait for a terminal run event and participate in its own session-shutdown cleanup.
|
|
309
428
|
|
|
310
|
-
This breaking contract replaces and removes `pi-goal:rpc:start`, `pi-goal:rpc:pause`, request-scoped start replies, and the global `pi-goal:state` broadcast.
|
|
429
|
+
This breaking contract replaces and removes `pi-goal:rpc:start`, `pi-goal:rpc:pause`, request-scoped start replies, and the global `pi-goal:state` broadcast.
|
|
430
|
+
No compatibility aliases are registered.
|
|
311
431
|
|
|
312
432
|
## 🧠 Use cases
|
|
313
433
|
|
|
@@ -321,6 +441,9 @@ This breaking contract replaces and removes `pi-goal:rpc:start`, `pi-goal:rpc:pa
|
|
|
321
441
|
|
|
322
442
|
```txt
|
|
323
443
|
packages/pi-goal/
|
|
444
|
+
├── dist/ # Generated TypeScript runtime loaded by Jiti
|
|
445
|
+
├── scripts/
|
|
446
|
+
│ └── build-runtime.mjs # Deterministic runtime builder and boundary validator
|
|
324
447
|
├── src/
|
|
325
448
|
│ ├── index.ts # Pi package entrypoint
|
|
326
449
|
│ ├── goal.ts # Order-explicit extension composition root
|
|
@@ -342,20 +465,24 @@ packages/pi-goal/
|
|
|
342
465
|
└── package.json
|
|
343
466
|
```
|
|
344
467
|
|
|
345
|
-
`index.ts` is the Pi entrypoint and forwards to `goal.ts`; the other source modules are internal.
|
|
468
|
+
`index.ts` is the Pi entrypoint and forwards to `goal.ts`; the other source modules are internal.
|
|
469
|
+
The package exposes its Pi extension through `package.json`:
|
|
346
470
|
|
|
347
471
|
```json
|
|
348
472
|
{
|
|
349
473
|
"pi": {
|
|
350
|
-
"extensions": ["./
|
|
474
|
+
"extensions": ["./dist/index.ts"]
|
|
351
475
|
}
|
|
352
476
|
}
|
|
353
477
|
```
|
|
354
478
|
|
|
479
|
+
The generated runtime is built from the authoritative `src/index.ts` graph and does not import back into `src`.
|
|
480
|
+
|
|
355
481
|
## 🔎 Keywords
|
|
356
482
|
|
|
357
483
|
Pi extension, Pi coding agent, goal mode, autonomous coding agent, AI agent workflow, task completion, agent loop, verification, TypeScript Pi package.
|
|
358
484
|
|
|
359
485
|
## 📄 License
|
|
360
486
|
|
|
361
|
-
MIT.
|
|
487
|
+
MIT.
|
|
488
|
+
See [`LICENSE`](./LICENSE).
|