@fractaal/pi-goal-x 0.19.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ # pi-goal-x
2
+
3
+ `pi-goal-x` is a long-running goal extension for [pi](https://github.com/earendil-works/pi-coding-agent). It gives the agent a durable objective, a visible lifecycle, and schema-gated tools for drafting, executing, pausing, resuming, and completing work.
4
+
5
+ The extension is designed around one rule: **the user owns intent; the agent executes only after the goal is explicit and confirmed**.
6
+
7
+ ## Features
8
+
9
+ - **Two goal styles** — Regular goals for open-ended research and implementation. Sisyphus goals for patient ordered execution, one step at a time.
10
+ - **Simple goal creation** — Use `/goals` to discuss and confirm a draft. Use `/goals-set` to skip discussion and start immediately.
11
+ - **Full lifecycle** — Pause blocked goals, resume when unblocked, abort obsolete work, complete when done. Auto-continue keeps the agent working across turns until completion, interruption, or the empty-turn guard.
12
+ - **Session-scoped goals** — Each Pi session keeps its own open goals under `.pi/goals/sessions/<session-id>/`. Switch that session's focus with `/goal-focus`.
13
+ - **Above-editor status widget** — See the current goal, status, file path, and progress at a glance while the agent works.
14
+ - **Structured task lists with subtasks** — Break goals into trackable tasks. Agents can mark individual tasks or subtasks complete without stopping the turn. Subtask IDs are validated for uniqueness and depth.
15
+ - **Verification contracts** — Attach plain-text requirements to a goal or task (e.g. "Run npm test, zero failures"). The agent must provide matching evidence before `complete_goal` or `complete_task` will succeed.
16
+ - **Independent completion auditor** — When a goal is marked complete, a separate pi agent inspects the workspace, verifies every success criterion, and approves or rejects before the goal is archived. You can press Escape during an audit to abort it. Configure the auditor model via `/goal-settings`.
17
+ - **Schema-gated tools** — Agents see only the tools relevant to the current lifecycle phase: drafting, active, paused, or tweaking. Lifecycle tools like `pause_goal`, `complete_task`, and `abort_goal` appear and disappear automatically.
18
+ - **Immutable objective** — The agent cannot silently change your goal. Objective updates require a `/goal-tweak` drafting flow with explicit user confirmation.
19
+ - **Built-in questionnaire tools** — During drafting, agents can ask structured questions through `goal_question` and `goal_questionnaire` without depending on external packages.
20
+ - **Disk-backed state** — Active and archived goals persist under the current session's `.pi/goals/sessions/<session-id>/` directory. Legacy cwd-scoped `.pi/goals/active_goal_*.md` files remain readable and are migrated when an old session resumes.
21
+ - **Configurable settings** — Tune the auditor model, disable the task system or contracts, and set subtask depth through `/goal-settings` or `.pi/pi-goal-x-settings.json`.
22
+
23
+ > **Fork of [@capyup/pi-goal](https://github.com/capyup/pi-goal)** — pi-goal-x preserves all upstream features and adds: verification contracts (per-goal and per-task), unified goal+task acceptance in a single confirmation dialog, recursive task lists with subtasks, an immutable objective enforced by tools, deferred archival with cleaner lifecycle hooks, an improved completion auditor with configurable model and progress widget, drafting UX refinements, and lifecycle reliability fixes.
24
+
25
+ ## Install
26
+
27
+ From npm:
28
+
29
+ ```bash
30
+ pi install npm:pi-goal-x
31
+ ```
32
+
33
+ From a local checkout:
34
+
35
+ ```bash
36
+ pi install .
37
+ ```
38
+
39
+ Try once without installing:
40
+
41
+ ```bash
42
+ pi -e .
43
+ ```
44
+
45
+ ## Quick start
46
+
47
+ ### Regular goal
48
+
49
+ ```text
50
+ /goals add structured logging to the auth module
51
+ ```
52
+
53
+ Flow:
54
+
55
+ 1. The agent clarifies, researches, or grills only when the goal contract needs it.
56
+ 2. The agent calls `propose_goal_draft` with a concrete objective once the contract is clear.
57
+ 3. pi shows a full plain-text confirmation report.
58
+ 4. If confirmed, the full finalized goal is printed into the conversation and written under `.pi/goals/sessions/<session-id>/`.
59
+ 5. The new goal becomes this session's focus. Existing open goals in the same session remain selectable later with `/goal-focus`.
60
+ 6. The agent works only on the focused goal until it calls `complete_goal`, pauses, aborts, produces an empty/non-progress turn, or the user interrupts.
61
+
62
+ ### Sisyphus goal
63
+
64
+ ```text
65
+ /sisyphus Refactor the auth flow: 1) extract token validation. 2) wire it into login. 3) update tests.
66
+ ```
67
+
68
+ Sisyphus mode is for patient ordered execution. It uses the same lifecycle and tools as a regular goal; the difference is the prompt style and completion standard: preserve the user's order, do not rush, do not invent preflight/reconnaissance steps, and stop to ask when blocked.
69
+
70
+ If the objective is already final and should start immediately, use:
71
+
72
+ ```text
73
+ /goals-set add structured logging to the auth module
74
+ /sisyphus-set Refactor auth flow exactly as ordered: 1) extract token validation. 2) wire it into login. 3) update tests.
75
+ ```
76
+
77
+ ## User commands
78
+
79
+ ```text
80
+ /goals <topic> Discuss/research/grill a regular goal, then confirm a draft
81
+ /sisyphus <topic> Discuss/grill a Sisyphus-style goal, then confirm a draft
82
+ /goals-set <objective> Immediately create and start a regular goal
83
+ /sisyphus-set <objective> Immediately create and start a Sisyphus-style goal
84
+ /goal-status Show focused goal state
85
+ /goal-list List open goals for this Pi session
86
+ /goal-focus Choose this session's focused goal
87
+ /goal-tweak <change> Draft a revision to the focused active/paused goal
88
+ /goal-pause Pause the focused active goal
89
+ /goal-resume Resume a paused goal
90
+ /goal-settings Configure pi-goal settings, including auditor model settings
91
+ /goal-abort Abort/archive the focused goal or cancel drafting
92
+ /goal-clear Archive the focused goal or cancel drafting
93
+ ```
94
+
95
+ Pressing `Esc` or aborting an active run pauses the goal so it does not remain falsely active.
96
+
97
+ ## Multiple open goals and focus
98
+
99
+ `pi-goal` separates durable goals from session focus:
100
+
101
+ - **Goal pool**: every open goal for the current Pi session is an `active_goal_*.md` file under `.pi/goals/sessions/<session-id>/`. Legacy cwd-scoped `.pi/goals/active_goal_*.md` files are read only for compatibility/migration.
102
+ - **Focused goal**: the current pi session has one focused goal id stored in a `pi-goal-focus` custom session entry.
103
+ - **No focus in markdown**: goal files describe the goal itself; they do not record which session is focused on them.
104
+ - **Branch-local focus**: because focus is reconstructed from the current session branch, `/tree` navigation can restore a different focus for a different branch.
105
+ - **One continuation chain**: auto-continue only schedules work for the focused goal in the current session.
106
+
107
+ Creating a goal with `/goals`, `/sisyphus`, `/goals-set`, or `/sisyphus-set` no longer clears other open goals in the same session. It creates a new session-scoped active goal file and focuses it. Use `/goal-list` to inspect this session's open goals and `/goal-focus` to switch the session focus. If the latest focus entry explicitly clears focus, or points at a missing/stale goal, a remaining single open goal is not auto-focused; single-open auto-focus only happens when no focus entry exists at all. If multiple open goals exist and the session has no valid focus, `/goal-resume`, `/goal-clear`, `/goal-abort`, `/goal-pause`, and `/goal-tweak` ask the user to choose a goal instead of acting on all of them.
108
+
109
+ ## Agent tools
110
+
111
+ The extension exposes tools only when they make sense for the current lifecycle phase.
112
+
113
+ | Tool | Visible when | Purpose |
114
+ |---|---|---|
115
+ | `goal_question` | drafting / tweak drafting | Ask one focused user question |
116
+ | `goal_questionnaire` | drafting / tweak drafting | Ask multiple structured questions |
117
+ | `get_goal` | always | Read the focused goal state; mentions other open goals when present |
118
+ | `propose_goal_draft` | drafting only (goal creation) | Submit a concrete draft for user confirmation |
119
+ | `propose_goal_tweak` | tweak drafting only | Submit a revision to an existing goal (shows Confirm / Continue Chatting dialog) |
120
+ | `complete_goal` | focused active or paused goal | Mark the focused goal complete — supply a `verificationSummary` covering all contract items. When the auditor is disabled, supply `confirmBypassAuditor: true` after user confirmation to bypass the audit |
121
+ | `pause_goal` | focused active goal | Pause the focused goal because of a real blocker |
122
+ | `abort_goal` | focused active or paused goal | Abort/archive an obsolete, impossible, unsafe, or user-cancelled focused goal |
123
+ | `propose_task_list` | active or paused goal | Propose a structured task list for user confirmation (stops the turn) |
124
+ | `complete_task` | active or paused goal | Mark a task complete with optional `verificationSummary`. If the task has a `verificationContract`, the summary is required (does not stop turn) |
125
+ | `skip_task` | active or paused goal | Mark a task skipped with a required reason (does not stop turn) |
126
+ | `propose_goal_tweak` | tweak drafting only | Submit a revision to the focused goal (shows Confirm / Continue Chatting dialog) |
127
+ | `step_complete` | hidden / legacy | Compatibility no-op; Sisyphus no longer requires a step counter |
128
+ | `create_goal` | hidden | Direct calls are rejected; normal creation goes through `propose_goal_draft` |
129
+
130
+ ## Drafting behavior
131
+
132
+ `/goals` and `/sisyphus` start a lightweight intent discussion, not a heavy runtime sub-state. The agent clarifies, researches, and grills only when needed, may proceed directly for fully specified requests, and then calls `propose_goal_draft` to show the user a Confirm / Continue Chatting dialog. `goal_question` and `goal_questionnaire` are available when structured input helps, but plain conversation is acceptable.
133
+
134
+ `/goals-set` and `/sisyphus-set` skip the discussion and confirmation dialog. They directly create and focus an active goal from the supplied objective so execution can begin immediately.
135
+
136
+ The agent may do minimal read-only reconnaissance when it directly improves the goal contract, but should not begin substantive implementation before confirmation. The strict runtime starts after the user confirms the draft and an active goal is created.
137
+
138
+ When a draft is proposed, the confirmation UI shows a full plain-text report with draft details, the original topic, and the proposed goal. If the confirmation UI throws in interactive mode, creation fails closed and confirmation remains active; it never auto-creates a goal. When a draft is confirmed, the tool result includes the full final objective, not a one-line summary, and normal work tools (`write`, `read`, `bash`, `edit`) are available for execution. This makes the confirmed contract visible in the conversation as well as on disk.
139
+
140
+ While goal confirmation or tweak drafting is active, old goal execution is suspended: active-goal prompts, accounting, and auto-continue checkpoints do not run for the previously focused goal.
141
+
142
+ ## Completion behavior
143
+
144
+ Completion is also explicit and is checked by an independent pi auditor agent. The executor calls `complete_goal` with its completion claim:
145
+
146
+ ```json
147
+ {
148
+ "status": "complete",
149
+ "completionSummary": "What was completed and what evidence proves it."
150
+ }
151
+ ```
152
+
153
+ Before archiving the goal, `complete_goal` starts a separate pi agent in an isolated in-memory session. The auditor receives the objective, the executor's completion claim, and current goal metadata, then can inspect the workspace with read-only-oriented tools (`read`, `grep`, `find`, `ls`, and `bash`). It must end its report with exactly one marker:
154
+
155
+ - `<approved/>` archives the goal as complete.
156
+ - `<disapproved/>`, no marker, an error, or an abort rejects completion and leaves the goal open.
157
+
158
+ The auditor is semantic, not a paperwork checklist: it should reject scaffold-only, alpha, generated-template, proxy-metric, build-only, or weakly verified completions when the real user outcome is not satisfied.
159
+
160
+ By default the auditor uses the current/default pi model. Configure it via `.pi/pi-goal-x-settings.json`, or interactively with `/goal-settings` (see [Configuration](#configuration)).
161
+
162
+ The completion result prints a full report into the conversation:
163
+
164
+ - `Goal complete.`
165
+ - optional completion summary / evidence supplied by the executor
166
+ - the auditor's approval report
167
+ - full current goal details, including objective, status, usage, mode, and file path
168
+
169
+ Sisyphus goals use the same completion tool as regular goals. The stricter part is the prompt/criteria standard: the agent should only call completion after the whole ordered objective is actually satisfied and likely to survive independent auditing. A paused goal can also be completed directly when the agent already has enough evidence that every requirement is satisfied; it does not need a resume just to call `complete_goal`.
170
+
171
+ ## Schema gates
172
+
173
+ The shipped gates are intentionally small and mechanical.
174
+
175
+ | Gate | Prevents |
176
+ |---|---|
177
+ | Focus consistency | `/goals` accidentally becoming Sisyphus, or `/sisyphus` becoming regular mode |
178
+ | Confirm-before-commit | The agent silently creating or replacing a discussion-based goal |
179
+ | Direct set intent | `/goals-set` and `/sisyphus-set` are explicit user shortcuts that bypass draft confirmation |
180
+ | Completion auditor gate | Archiving completion unless an independent pi auditor agent returns `<approved/>` |
181
+ | Abort gate | Aborting missing, stale, completed, or reasonless goals |
182
+ | Direct-create rejection | Hidden `create_goal` calls creating goals without the confirmation flow |
183
+ | Post-stop block | Continuing to call tools after `pause_goal`, `abort_goal`, `complete_goal`, or `propose_goal_tweak` stops the turn |
184
+ | Empty-turn guard | Pure chat loops that would keep auto-continuing without meaningful goal work |
185
+ | Abort pause | Active goals staying active after user abort / Ctrl-C |
186
+ | Disk reconciliation | External pause/archive/delete/status changes being ignored or overwritten by stale memory |
187
+ | Post-compaction reminder | Losing the active objective after session compaction |
188
+
189
+ ## Files
190
+
191
+ ```text
192
+ .pi/goals/sessions/<session-id>/active_goal_<timestamp>_<id>.md
193
+ .pi/goals/sessions/<session-id>/archived/goal_<timestamp>_<id>.md
194
+ .pi/goals/sessions/<session-id>/goal_events.jsonl
195
+ ```
196
+
197
+ Multiple `active_goal_*.md` files may exist simultaneously within a session directory. This is the session-level open goal pool. The selected/focused goal is intentionally not stored in these files; focus lives in session custom state.
198
+
199
+ Each file contains:
200
+
201
+ 1. extension-owned JSON metadata;
202
+ 2. a user-editable `# Goal Prompt` section;
203
+ 3. progress/status information.
204
+
205
+ Before commands, tools, and lifecycle hooks act on a focused goal, the runtime reconciles the focused record against the active goal file on disk. External archive/delete/status changes therefore win over stale in-memory state and cannot resurrect deleted active files. Prompt-body edits are still picked up from the `# Goal Prompt` section; focus is never stored in goal markdown.
206
+
207
+ Goal paths are constrained to `.pi/goals/sessions/<session-id>/` and its `archived/` child for current writes. Legacy `.pi/goals/` and `.pi/goals/archived/` paths remain readable for migration. Absolute paths, traversal, NUL bytes, symlinks, and unsafe metadata paths are rejected.
208
+
209
+ ## Configuration
210
+
211
+ All settings live in a single file: **`.pi/pi-goal-x-settings.json`**
212
+
213
+ Configured interactively via `/goal-settings`, or edited directly:
214
+
215
+ ```json
216
+ {
217
+ "disableTasks": false,
218
+ "disableContracts": false,
219
+ "subtaskDepth": 1,
220
+ "provider": "fireworks",
221
+ "model": "accounts/fireworks/models/deepseek-v4-flash",
222
+ "thinkingLevel": "high",
223
+ "disabled": false
224
+ }
225
+ ```
226
+
227
+ | Field | Default | Purpose |
228
+ |---|---:|---|
229
+ | `disableTasks` | `false` | Suppress task list features entirely when `true` |
230
+ | `disableContracts` | `false` | Suppress verification contract enforcement when `true` |
231
+ | `subtaskDepth` | `1` | Maximum nesting depth for subtasks |
232
+ | `provider` | system default | Provider name for the auditor agent |
233
+ | `model` | system default | Model name for the auditor agent |
234
+ | `thinkingLevel` | system default | Thinking level: `off`, `minimal`, `low`, `medium`, `high`, `xhigh` |
235
+ | `disabled` | `false` | When `true`, skip the completion audit entirely |
236
+
237
+ **Env var overrides:**
238
+ - `PI_GOAL_DISABLE_TASKS=1` — disable task features (takes precedence over file)
239
+ - `PI_GOAL_DISABLE_CONTRACTS=1` — disable contract enforcement (takes precedence over file)
240
+ - `PI_GOAL_SETTINGS_FILE=custom-path.json` — alternative settings file path (relative to cwd or absolute)
241
+
242
+ ## Environment variables
243
+
244
+ | Variable | Default | Purpose |
245
+ |---|---:|---|
246
+ | `PI_GOAL_AUTO_CONFIRM` | unset | When `1`, auto-confirms drafts in headless/test contexts |
247
+ | `PI_GOAL_DISABLE_TASKS` | — | When `1`, disable task features (overrides settings file) |
248
+ | `PI_GOAL_DISABLE_CONTRACTS` | — | When `1`, disable contract enforcement (overrides settings file) |
249
+ | `PI_GOAL_SETTINGS_FILE` | `.pi/pi-goal-x-settings.json` | Alternative settings file path (relative to cwd or absolute) |
250
+
251
+ ## Development
252
+
253
+ ```bash
254
+ npm install
255
+ npm test
256
+ npm run check
257
+ npm pack --dry-run
258
+ ```
259
+
260
+ The fast unit suite uses Node's built-in test runner and covers core parsing, drafting gates, lifecycle policy, abort policy, questionnaire formatting, centralized tool names, Sisyphus prompt-style behavior, completion reporting, and display helpers.
261
+
262
+ The experiment harness under `experiments/` runs full pi sessions against real model calls and mechanical rubrics.
263
+
264
+ ```bash
265
+ cd experiments
266
+ bash harness/run.sh C1-vague-goal-set --count 3 --grade --no-smoke
267
+ ```
268
+
269
+ ## Package contents
270
+
271
+ The npm package ships only the runtime extension, docs, and package metadata. The extension is split into small modules:
272
+
273
+ ```text
274
+ extensions/goal.ts orchestration, commands, tools, events, timers
275
+ extensions/goal-record.ts goal record types, normalization, creation helpers
276
+ extensions/goal-pool.ts open-goal pool, focus resolution, list/selector text helpers
277
+ extensions/goal-core.ts display helpers
278
+ extensions/goal-draft.ts lightweight confirmation prompt, proposal validation, drafting tool gate
279
+ extensions/goal-policy.ts lifecycle, pause/resume/complete, and Sisyphus policy
280
+ extensions/goal-auditor.ts independent pi auditor agent for completion approval, config, and progress tracking
281
+ extensions/goal-ledger.ts event append, read, validation, sanitization, and reconstruction
282
+ extensions/goal-questionnaire.ts built-in question UI and question tool registration
283
+ extensions/goal-tool-names.ts centralized published tool names and allowlists
284
+ extensions/prompts/goal-prompts.ts active, continuation, tweak, and stale prompts
285
+ extensions/storage/goal-files.ts goal file paths, serialization, parsing, archive IO
286
+ extensions/widgets/goal-widget.ts above-editor goal beacon component
287
+ extensions/widgets/goal-notifications.ts widget-style notification text
288
+ ```
289
+
290
+ ## Design principles
291
+
292
+ - **User owns intent**: only the user starts, replaces, resumes, clears, or confirms goals; the agent may only pause, complete, or abort through schema-gated lifecycle tools with evidence/reason.
293
+ - **One commit path**: normal goal creation goes through drafting and confirmation.
294
+ - **Schema beats prompt walls**: recurring failure modes are handled by validators and tool-call interceptors.
295
+ - **Visible contracts**: confirmed goals and completion reports are printed fully into the conversation.
296
+ - **Lifecycle-shaped tool surface**: the agent sees only tools appropriate to the current phase.
297
+ - **Disk-backed continuity**: goal state survives context churn and can be audited from `.pi/goals/sessions/<session-id>/`.
298
+ - **Human-owned focus**: the agent may work on the focused goal, but only user commands/UI selection switch focus.
299
+
300
+ ## Upstream
301
+
302
+ This repository is a downstream fork of [@capyup/pi-goal](https://github.com/capyup/pi-goal). To sync with upstream changes:
303
+
304
+ ```bash
305
+ git fetch upstream
306
+ git merge upstream/main
307
+ # resolve conflicts, test, commit
308
+ ```
309
+
310
+ The `upstream` remote should point to `https://github.com/capyup/pi-goal.git`.
311
+
312
+ ## Release policy
313
+
314
+ This repository can be validated locally with tests and packaging checks. Publishing a new npm version, pushing tags, and running `pi update` are explicit release steps and are not part of ordinary implementation goals unless requested.
315
+
316
+ ## License
317
+
318
+ MIT