specpi 0.13.0 → 0.15.0
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/CHANGELOG.md +19 -0
- package/NPM_RELEASE.md +2 -0
- package/README.md +11 -5
- package/SECURITY_MODEL.md +30 -0
- package/THIRD_PARTY.md +6 -0
- package/docs/delegation/README.md +40 -4
- package/docs/delegation/protocol.md +13 -0
- package/extensions/command-guard/index.ts +4 -1
- package/extensions/delegation/core.mjs +13 -2
- package/extensions/delegation/extension.mjs +64 -7
- package/extensions/delegation/managed-files.mjs +1 -0
- package/extensions/delegation/native.mjs +8 -2
- package/extensions/delegation/presentation.mjs +2 -1
- package/extensions/delegation/protocol.mjs +13 -2
- package/extensions/delegation/provider.mjs +3 -2
- package/extensions/delegation/settings.mjs +140 -0
- package/extensions/spec.ts +9 -0
- package/extensions/tool-wishlist/index.ts +7 -1
- package/extensions/tool-wishlist/verification.mjs +1 -0
- package/extensions/workflow-controls/index.ts +2 -2
- package/package.json +1 -1
- package/scripts/check-package.mjs +36 -20
- package/scripts/check-syntax.mjs +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.0 - 2026-09-05
|
|
4
|
+
|
|
5
|
+
- Add **SpecPi Chat 0.3.1**, a separately packaged VS Code sidebar with streamed Pi replies, safe Markdown, expanded thinking and collapsed tool output by default, model/thinking controls, exact approvals, and a compact composer. It reuses the user's Pi configuration without managing credentials or installing the harness.
|
|
6
|
+
- Add searchable extension-owned history, rename and reversible archive, and independent live conversations. Switching chats or folders preserves background work, approvals, drafts, attachments, usage, and view position. Stop/Disconnect target the selected conversation; parallel chats share workspace files rather than isolated worktrees.
|
|
7
|
+
- Add validated file/image attachment, screenshot paste/drop, bounded inline images, workspace code links and image previews, explicit queued-image recovery, visible transcript search/copy/export, usage/cost reporting, and native Git diff review. Branching and earlier-prompt editing preserve the source conversation and never undo code files or automatically send restored drafts.
|
|
8
|
+
- Start Command Guard in Guard mode in RPC without an unreadable startup selector; retain explicit `/guard` choices after readiness. Route task handoffs, challenge reports, and wishlist reports through RPC-capable dialogs, and disclose terminal-only display controls.
|
|
9
|
+
- Wait for legacy Pi startup fallbacks without approving early dialogs. Reset interrupted-run state on reconnect and never restore accepted prompts after a later refresh failure.
|
|
10
|
+
- Show installed Codex Usage and pi-usage (including Anthropic) reports in Chat's compact, expandable Limits row, separate from conversation tokens/cost. Reuse bounded Pi status events without provider queries, credential/cache reads, or changes to the default package list.
|
|
11
|
+
- Scope Chat's Pi-state filename restrictions to Pi/Chat storage so ordinary authentication, session, and history source files remain usable; retain global credential/key protection and canonical-path checks.
|
|
12
|
+
- Fix composer `/model` selection, read-only usage during active work, and stale Stop cleanup errors after reconnect. Align README and Pages installation examples with the separately versioned Chat artifact.
|
|
13
|
+
- Add dependency-free local VSIX packaging, isolated real-Pi and native VS Code tests, rendered Chat checks in CI, and editor-extension syntax/source-inventory coverage. No npm/Marketplace publication or automatic editor installation is included.
|
|
14
|
+
|
|
15
|
+
## 0.14.0 - 2026-09-05
|
|
16
|
+
|
|
17
|
+
- Raise delegation's default job timeout from 2 to 10 minutes, including the provider adapter. Add `/delegate timeout <minutes>` (1–60) and `reset` with an atomic, backed-up preference across restarts. Batch timeouts scale with the job window; call quotas, original follow-up deadlines and settling ownership remain unchanged. Restart Pi after updating the delegation runtime.
|
|
18
|
+
- Support platform aliases in the selected Pi agent-directory path while rejecting links inside preference state. Bound encoded backups separately so every accepted settings file can be saved repeatedly.
|
|
19
|
+
- Keep `.mts` declarations on LF checkouts and validate Pages permissions with either LF or CRLF input so release checks remain portable on Windows.
|
|
20
|
+
- Run timeout persistence fixtures across release platforms, isolate the package help probe, and verify that settings survive failed updates and every managed delegation file is removed on uninstall.
|
|
21
|
+
|
|
3
22
|
## 0.13.0 - 2026-09-05
|
|
4
23
|
|
|
5
24
|
- Add bounded, best-effort sanitized browser exceptions, console errors, failed requests, and HTTP error diagnostics with explicit cursor/loss/clear semantics and ephemeral retention.
|
package/NPM_RELEASE.md
CHANGED
|
@@ -22,6 +22,8 @@ Verify the registry bytes and metadata immediately, then configure trusted publi
|
|
|
22
22
|
|
|
23
23
|
1. Select a version that has never appeared on npm. npm versions are immutable.
|
|
24
24
|
2. Update `package.json`, `CHANGELOG.md`, `README.md`, `site/index.html`, `site/wiki/index.html`, `site/single-agent/index.html`, and the delegation guide to the same version. Keep historical changelog entries intact and remove stale unreleased-status wording.
|
|
25
|
+
If Chat changes are included, increment its independent version in `vscode/package.json` and `vscode/CHANGELOG.md`, and align the VSIX filenames and feature descriptions in the root README, extension README, and Pages guides. Build it with `npm --prefix vscode run package`, run `npm --prefix vscode run test:render` and the isolated `npm --prefix vscode run test:vsix`, and inspect the VSIX allowlist. The editor extension is not part of the npm tarball; creating this local artifact does not publish it or authorize a Marketplace release.
|
|
26
|
+
|
|
25
27
|
3. For a stable release, add a dated changelog heading. Use a prerelease version when the package should not receive the `latest` dist-tag.
|
|
26
28
|
4. Install the pinned development tools without lifecycle scripts or peers:
|
|
27
29
|
|
package/README.md
CHANGED
|
@@ -24,7 +24,13 @@ SpecPi adds task contracts, workflow controls, and a local improvement loop to P
|
|
|
24
24
|
|
|
25
25
|
Collection is disabled until explicitly enabled. Reports are sanitized, bounded, deduplicated by task, and never uploaded. Later evidence can reopen an item for review, but never restarts implementation automatically.
|
|
26
26
|
|
|
27
|
-
Version `0.
|
|
27
|
+
Version `0.15.0` adds the separately packaged SpecPi Chat sidebar and RPC-compatible Guard startup and report dialogs. The terminal harness, optional read-only delegation, browser checks, and human-selected improvement workflow remain available. See the [release notes](CHANGELOG.md) for the change list.
|
|
28
|
+
|
|
29
|
+
## SpecPi Chat for VS Code
|
|
30
|
+
|
|
31
|
+
The `vscode/` source contains **SpecPi Chat 0.3.1**, a separately packaged native sidebar with streamed replies, tool results, file and image attachments, model/thinking controls, Pi approvals, and searchable workspace conversation history. Rename or archive chats, switch between independent live conversations, branch or edit an earlier prompt, search and export visible messages, inspect usage, and review changes through VS Code's native diff tools. Switching chats preserves background work, approvals, drafts, and attachments. Connected conversations share workspace files; use separate worktrees for isolated writers. Opening the sidebar does not start Pi.
|
|
32
|
+
|
|
33
|
+
From a repository checkout, build a local VSIX with `npm --prefix vscode run package`, then install `.specpi-test/vscode/specpi-chat-0.3.1.vsix` through **Extensions: Install from VSIX…**. See the [extension guide](https://github.com/TannerMidd/SpecPi/blob/main/vscode/README.md) for prerequisites, image/provider limits, commands, privacy, and testing. Pi owns provider authentication and tool execution. Stop and Disconnect affect the selected conversation only; branching does not undo code changes. The extension is separate from the SpecPi npm package and has not been published to a marketplace.
|
|
28
34
|
|
|
29
35
|
## Optional delegation
|
|
30
36
|
|
|
@@ -55,14 +61,14 @@ specpi doctor
|
|
|
55
61
|
Pin the reusable CLI when installing a reviewed release, or inspect its plan without retaining a global CLI installation:
|
|
56
62
|
|
|
57
63
|
```bash
|
|
58
|
-
npm install --global specpi@0.
|
|
59
|
-
npx --package specpi@0.
|
|
64
|
+
npm install --global specpi@0.15.0
|
|
65
|
+
npx --package specpi@0.15.0 specpi plan
|
|
60
66
|
```
|
|
61
67
|
|
|
62
68
|
For a source-audited installation, clone the exact release:
|
|
63
69
|
|
|
64
70
|
```bash
|
|
65
|
-
git clone --branch v0.
|
|
71
|
+
git clone --branch v0.15.0 --depth 1 https://github.com/TannerMidd/SpecPi.git
|
|
66
72
|
cd SpecPi
|
|
67
73
|
./specpi plan
|
|
68
74
|
./specpi install
|
|
@@ -167,7 +173,7 @@ Use `/task clear` before recording an unrelated task. Within a session, repeated
|
|
|
167
173
|
|
|
168
174
|
Use `/experiment start` when an independent review or trial justifies a separate worktree. Open the reported path in another Pi session. SpecPi does not launch an agent, copy dirty base changes, commit, merge, or touch remotes.
|
|
169
175
|
|
|
170
|
-
SpecPi
|
|
176
|
+
SpecPi's default workflow uses one writer per working directory. Its experimental delegation adds bounded read-only Pi sessions. SpecPi Chat also supports independent conversations that you start explicitly; connected chats can continue concurrently in the same workspace. They share workspace files rather than receiving separate worktrees. A parent determines what context a delegated child receives and verifies what returns, so either handoff can omit a material constraint. Parallel writers also introduce conflicting assumptions and increase review work.
|
|
171
177
|
|
|
172
178
|
## Improvement loop
|
|
173
179
|
|
package/SECURITY_MODEL.md
CHANGED
|
@@ -30,6 +30,10 @@ Incremental stream checks count recognized delta bytes and bound event structure
|
|
|
30
30
|
|
|
31
31
|
The same controller and bounded idempotency journal remain in memory for the Pi process lifetime, including `/reload`, session switches and off/on. Successful spending and final-disposition receipts are retained (at most 20 under the fixed ceilings); cancellation and nonfinal assessments have a separate 128-entry oldest-first cache. Failures reserve no keys. Cache churn cannot evict spending receipts, reset quotas or disable cancellation. Limits are two active workers, four batches and 32 SDK invocations per process; two jobs and 8 invocations per batch; four invocations per logical job including follow-up. Invalidation does not reset these counters or release settling work. Completed reports retain their source bindings after the deadline, but child sessions are released at the deadline and later follow-up is rejected. These numeric limits are engineering choices, not empirical optima.
|
|
32
32
|
|
|
33
|
+
Logical jobs default to 10 minutes and batches to 20 minutes. Human `/delegate timeout <minutes>` persists a whole-minute value from 1–60 while delegation is off; the batch window is twice the job window. Queue and follow-up time count from admission. SDK request timeouts and adapter abort timers use the remaining job window, with a 60-minute ceiling. Changes revoke old policy bindings, never extend old jobs or reset quotas/settling slots, and are absent from the model-facing schema. The effective time policy is included in Guard fingerprints and packet digests. Longer windows also allow longer in-memory input/child retention; they do not add calls, retries or billing guarantees.
|
|
34
|
+
|
|
35
|
+
Only the numeric timeout preference is persisted under `<agent-dir>/specpi/delegation/settings.json`; its previous content and SHA-256 are backed up in `settings.json.bak`. The human-selected agent directory is canonicalized once, including platform aliases; owned SpecPi subdirectories and preference files still reject links. Reads reject malformed/nonregular settings and are bounded to 4 KiB; the encoded backup has a separate 32 KiB bound. Saves use exclusive staging and atomic promotion. Invalid settings block activation. This store does not read Pi authentication, settings or sessions. The process loads it once; manual or other-process edits require restart, and concurrent saves are last-writer-wins. As with snapshots, this is a trusted-local-filesystem contract, not protection against hostile filesystem races. User-owned preferences survive uninstall. Requested file/directory modes are 0600/0700; Windows relies on profile ACLs.
|
|
36
|
+
|
|
33
37
|
Shared snapshot text is destroyed once no job can continue; failed attempts retain original expiry cleanup. Packet/job-input references are dropped after owned workers settle. Metadata and digests remain for completed receipt freshness. Starting the next accepted batch retires previous reports; invalidation retires old generations after settlement. Retired batch objects are pruned, leaving only bounded state summaries and idempotency/usage counters. Replay cannot restore their reports, inputs, sessions or allowances. JavaScript strings, provider buffers and values already returned to Pi cannot be securely erased.
|
|
34
38
|
|
|
35
39
|
Selected context reaches the configured provider; normal parent tool results may be retained by Pi. Child sessions use memory only, with no child session database, raw metrics journal, credential copy, automatic resume or policy learning, or secure memory-erasure guarantee. See the [implemented protocol](docs/delegation/protocol.md) for states and receipts. SDK integration and synthetic-provider fixtures concern the runtime contract; their existence does not establish full parent inference parity or measured outcome gains.
|
|
@@ -152,6 +156,32 @@ The GitHub Pages workflow publishes the checked-in `site/` directory. Its deploy
|
|
|
152
156
|
|
|
153
157
|
Repository checks, smoke tests, checksums, closed capability validators, and browser comparisons provide evidence for documented behavior. They reduce regression risk but do not prove the absence of vulnerabilities or establish cryptographic provenance for dependencies and releases.
|
|
154
158
|
|
|
159
|
+
## SpecPi Chat editor integration
|
|
160
|
+
|
|
161
|
+
The optional `vscode/` extension is distributed separately from the SpecPi npm installation. It runs in the VS Code workspace extension host and requires a trusted filesystem workspace before launching Pi or collecting file context. Only application-level settings choose executable paths; the launcher resolves native executables or known adjacent Pi JavaScript entry points and never executes a shell command string. Pi runs in the explicitly selected workspace with its normal installed extensions and provider configuration. VS Code trust does not replace Pi project trust, and the extension does not pass a flag to bypass Pi's trust decisions or Command Guard.
|
|
162
|
+
|
|
163
|
+
The sidebar uses Pi's documented JSONL RPC protocol. Pi owns provider authentication and tool execution; the extension does not read, copy, or manage authentication files. RPC model metadata is projected to display fields. Approvals and selection/input/editor requests are displayed as text and require an exact response for the requesting conversation's active request. Switching the displayed conversation preserves outstanding requests; background requests appear as needing input and never receive automatic approval. Stop, disconnect, runtime session transitions, and expiry cancel the affected conversation's requests. Expired or wrong-conversation responses cannot authorize later requests. In RPC, Command Guard starts in Guard mode without an initial selection dialog because Pi cannot read dialog responses until its startup handlers return; explicit `/guard` commands remain available after startup. Unsupported terminal-only components are disclosed rather than treated as functional editor controls.
|
|
164
|
+
|
|
165
|
+
Chat allows up to 90 seconds for an initial read-only RPC readiness probe before sending normal requests. This accommodates the 30-second startup fallback in older installed Guard versions without extending later request deadlines. Dialogs arriving before readiness receive cancellation only, never an approval or mode selection; the sidebar explains the limitation and retains a notice after connection. An extension with an unbounded startup dialog can still prevent readiness. Chat times out with recovery guidance instead of bypassing that extension or changing the user's installed harness.
|
|
166
|
+
|
|
167
|
+
The webview loads only packaged scripts/styles under a strict content security policy, forbids network resources, and renders model/tool/file text without interpreting embedded HTML. Images use validated data URLs under `img-src data:`; remote image URLs are never fetched by the webview. HTTP(S) links, including external image links, require a human click and pass through VS Code's external-link API. Clicked code references use a separate host action: paths are parsed, checked against the selected workspace, canonicalized, and restricted to regular non-sensitive files before VS Code opens the file and reveals a clamped line/range. Clicked workspace Markdown image references use the same path boundary and the image validator before a preview is returned. Arbitrary command and URI handlers are not executed. Raw paths preserve literal percent signs; Markdown link destinations and explicit local file URLs are decoded once before filesystem validation.
|
|
168
|
+
|
|
169
|
+
Text/code context requires an explicit file/selection action, is size-bounded, rejects binary and known sensitive paths, and checks canonical workspace containment. Workspace file suggestions enumerate a bounded set of names; choosing a suggestion invokes the same attachment validation before reading contents. Dropped workspace URIs are validated independently of their browser representation. Native image selection, clipboard images, and dropped image files are explicit attachment actions and may supply images from outside the selected workspace; filesystem image sources still require ordinary files and pass sensitive-path checks. Pi-state names such as `auth`, `trust`, `sessions`, `missions`, and `history` are reserved inside `.pi`, Chat-owned storage, and the configured Pi agent directory (including its canonical target), not arbitrary source directories. Global credential/key patterns remain blocked, including `auth.json`. Relative `PI_CODING_AGENT_DIR` overrides retain conservative name blocking because they resolve in the child workspace; use an absolute path or `~/…` to obtain directory-scoped filtering. These filename checks and format validators are not content-based secret detectors. Manually typed messages, ordinary files, and images may contain sensitive content, and the extension does not promise image metadata removal. Prompts and attachments are sent to the provider selected in Pi when the user sends them.
|
|
170
|
+
|
|
171
|
+
Image content is checked for supported PNG, JPEG, GIF, or WebP structure, declared MIME agreement, dimensions, and bounded base64 size. Each image is limited to 5 MiB, 16,384 pixels per side, and 40 million pixels. A prompt permits eight mixed attachments and 20 MiB of image bytes. The display retains at most 32 images / 20 MiB and reports omitted content; this is separate from Pi's persisted history. RPC records and buffered writes have independent 64 MiB caps. Recognized oversized history responses with a matching pending request are drained without accumulating the remaining bytes, then rejected without terminating Pi. The sidebar reports omitted history and remains usable; other oversized protocol records terminate the connection. A large historical transcript can exceed the RPC cap even when its original prompts were individually valid. Media caches remain in memory, are referenced by opaque identifiers while streaming, and are released as content is no longer retained. No remote image fetch, image processing service, or new image dependency is introduced. Pi/provider image limits and behavior remain upstream contracts.
|
|
172
|
+
|
|
173
|
+
Connection teardown resets transient run bookkeeping without discarding displayed partial text. An accepted prompt is never restored because a later status refresh failed, and the Refresh status action performs read-only RPC queries instead of replaying work. RPC request IDs correlate replies; they do not make retries idempotent. A lost connection before acknowledgement leaves the prompt outcome uncertain.
|
|
174
|
+
|
|
175
|
+
Image prompts require a model advertising image input. Rejection retains the unsent draft and attachments. Image-bearing slash commands are rejected because Pi extension commands can acknowledge execution without consuming image arguments. Stop clears queued work before aborting. Pi's queue-clear response contains text only, so Chat retains bounded in-memory image snapshots for its accepted queued submissions and restores them only after an exact, unambiguous match and an explicit user action. It does not attach discarded or unmatched images to a later prompt, automatically resend recovered work, or treat a missing acknowledgement as proof of failure.
|
|
176
|
+
|
|
177
|
+
Pi persists chats, including sent image blocks, in a workspace-specific directory under the extension's VS Code storage. A bounded atomic catalog stores only identifiers, titles, timestamps, archive flags, and paths of conversations created there. It never scans or opens terminal Pi history or writes transcripts to VS Code settings, logs, telemetry, or persistent webview state. Each conversation's live projection, draft, and attachment snapshots stay in memory with per-conversation bounds. Resume is limited to catalogued regular files inside the owned session directory. Renaming and reversible archiving change catalog metadata without opening transcripts; archiving neither deletes files nor stops a live process. Uninstalling the extension does not promise secure deletion of VS Code storage. POSIX permissions are requested where supported; Windows relies on the profile's ACLs. As elsewhere in SpecPi, local filesystem races, a compromised extension host, an untrusted Pi executable, or same-user tampering are outside the isolation guarantee.
|
|
178
|
+
|
|
179
|
+
Conversation edits select entries from the active Pi tree, revalidate the selection before mutation, and fork before the chosen user prompt. Exact original text and validated image blocks are captured before forking because Pi's fork response returns text only. The original conversation is retained, restored drafts require another send action, and conversation forks/clones do not restore or checkpoint workspace files. Actions are scoped to the active workspace, connection, and session revision. Export opens an unsaved Markdown document and Copy Conversation writes the visible Markdown to the OS clipboard only on explicit request. Both omit image bytes and represent images as placeholders; they do not reconstruct truncated or hidden history. Usage displays report Pi measurements, preserving unavailable values rather than inventing totals. The separate provider Limits row projects bounded strings from the known Codex Usage and pi-usage status keys, strips terminal/control sequences, and inserts text only. It does not parse numeric quotas, combine budgets with conversation cost, read provider credentials or usage-cache files, or add provider requests. Reports stay with their live connection and are cleared on disconnect, exit, and reconnect; refreshing and cache age remain upstream plugin responsibilities. Opening the details has no RPC or provider side effect. Existing `/usage` notifications and exact confirmation dialogs continue through the normal UI protocol; no automatic reset consumption or terminal-footer emulation is added.
|
|
180
|
+
|
|
181
|
+
Native change review reads VS Code's Git API, validates selected workspace paths, and opens the corresponding working-tree or staged view through the built-in diff/editor actions. It does not execute a shell command, stage, commit, discard, or restore files. Git integration availability and the filesystem race boundary still apply. The sidebar coordinator keeps independent Pi connections for explicitly opened conversations. Switching conversations or folders only changes the selected view. Stop and Disconnect target the selected process; extension-host shutdown stops all owned processes. User-initiated parallel conversations share their workspace files and are not isolated worktrees. Branching uses Pi's pre-runtime `--fork` to copy into a new owned session before extensions can write, then performs any active-branch or prompt selection there; the original process and session remain unchanged.
|
|
182
|
+
|
|
183
|
+
The extension introduces no network server, telemetry, runtime package dependency, or automatic model request when a view opens. Pi itself may contact its configured services when connected. Tests use synthetic homes, agent directories, providers, workspaces and profiles, plus an installed VS Code extension host; they do not access the user's live Pi credentials or conversations. Live provider availability and billing are outside the offline test evidence.
|
|
184
|
+
|
|
155
185
|
## Supply-chain assumptions
|
|
156
186
|
|
|
157
187
|
SpecPi pins reviewed executable package versions and the browser dependency graph. These controls improve repeatability and make version changes reviewable. They do not prove that a registry, publisher account, package artifact, downloaded browser, GitHub Action tag, or invoking host is uncompromised. Releases are not described as reproducible or cryptographically signed unless a future release adds and documents those mechanisms.
|
package/THIRD_PARTY.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Third-party components
|
|
2
2
|
|
|
3
|
+
SpecPi Chat is a separate VS Code extension built with the public VS Code Webview View API and Pi `0.84.4`'s documented RPC protocol. VS Code and the installed Pi runtime retain their upstream licenses; neither is bundled in the VSIX. The extension and its ZIP/VSIX packager use Node built-ins and first-party source only, with no added runtime or development dependency. Its tests reuse the repository's pinned Playwright and Pi packages. Provider authentication, requests, billing, and normal Pi background behavior remain owned by the configured Pi runtime.
|
|
4
|
+
|
|
5
|
+
Chat's provider Limits row recognizes the public RPC `setStatus` presentation contracts of `@llblab/pi-codex-usage` **0.9.3** (`aa-codex-usage`) and `@sreetej510/pi-usage` **0.9.9** (`provider-usage`). Public source was checked at commits `1a97ee5560c5d7dd3b99ce34e2dcfe456592f8a0` and `9dee3b590f736c723011e3bc3717b3f0d6e8072b`, respectively. Tests reproduce their status/notification contracts through synthetic local Pi RPC, not live accounts or upstream provider requests. Text retains each plugin's quota semantics rather than converting or aggregating measurements. Neither plugin is bundled in the VSIX; this compatibility change does not install pi-usage or change SpecPi's existing package pins. Plugins retain ownership of authentication, caching, refresh/backoff, and explicit reset-consumption confirmation.
|
|
6
|
+
|
|
7
|
+
Chat uses Pi's image content blocks, conversation tree/fork/clone operations, and session statistics, plus the installed VS Code Git extension's public API for diff review. Version 0.3.0 retains a separate Pi process for each connected conversation and uses Pi's `--fork <session>` CLI option to copy branch history before runtime extensions initialize; the original live session remains untouched. Image container validation and base64 framing are first-party code; display uses VS Code's embedded browser image decoders. No image codec, provider SDK, export package, or remote image service is added. Local acceptance of PNG, JPEG, GIF, or WebP does not establish that every configured provider accepts the same formats or animation behavior. RPC records and buffered writes are capped at 64 MiB; image prompts and rendered media have separate, smaller limits documented in the extension guide.
|
|
8
|
+
|
|
3
9
|
Delegation loads `clampThinkingLevel` from the Pi SDK when exported there, otherwise
|
|
4
10
|
from the public `@earendil-works/pi-ai/compat` subpath declared in Pi's
|
|
5
11
|
[package exports](https://github.com/earendil-works/pi/blob/main/packages/ai/package.json).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bounded delegation
|
|
2
2
|
|
|
3
|
-
Status: experimental in SpecPi 0.
|
|
3
|
+
Status: experimental in SpecPi 0.15.0. Disabled by default.
|
|
4
4
|
The package remains `specpi`; no separate npm package or background service is required.
|
|
5
5
|
|
|
6
6
|
SpecPi keeps one agent responsible for changes and acceptance. This extension adds
|
|
@@ -94,8 +94,8 @@ structured tool responses and do not mount terminal widgets. The UI uses Pi's pu
|
|
|
94
94
|
[widget and tool-rendering APIs](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/extensions.md).
|
|
95
95
|
|
|
96
96
|
`on` grants the displayed experimental calls/time envelope. There is no model-call
|
|
97
|
-
permission toggle in the model-facing tool. `limits` is read-only;
|
|
98
|
-
|
|
97
|
+
permission toggle in the model-facing tool. `limits` is read-only; prompts cannot
|
|
98
|
+
change timeouts or raise other ceilings. Turning delegation off, changing guard policy, switching
|
|
99
99
|
sessions or models, navigating branches, and changing task/scope bindings revoke the
|
|
100
100
|
current generation. Off/on, `/reload` and session switches do not reset the Pi process's
|
|
101
101
|
counters or free requests that are still settling. The same in-memory controller remains
|
|
@@ -123,6 +123,42 @@ the error identifies that state. `/delegate status` reports the observed Guard s
|
|
|
123
123
|
Worker tool restrictions and resource limits are enforced independently of Guard. A worker result
|
|
124
124
|
cannot authorize a write, a commit, a deployment, or an improvement.
|
|
125
125
|
|
|
126
|
+
## Configure the timeout
|
|
127
|
+
|
|
128
|
+
The default is **10 minutes per logical job** (previously 2 minutes). In Pi:
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
/delegate off
|
|
132
|
+
/delegate timeout 15
|
|
133
|
+
/delegate on
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`/delegate timeout` shows the current value; `/delegate timeout reset` saves the
|
|
137
|
+
10-minute default. Tab completion suggests common values. Use whole minutes from
|
|
138
|
+
**1 to 60**; there is no unlimited setting. The batch deadline is twice the job
|
|
139
|
+
timeout (20 minutes by default), so it does not truncate the configured job window.
|
|
140
|
+
Both deadlines start at batch admission and include queue and follow-up time; a
|
|
141
|
+
follow-up never gets a fresh timeout. Provider requests use the remaining job window,
|
|
142
|
+
not a separate two-minute cap. Provider-side limits may still end requests sooner.
|
|
143
|
+
|
|
144
|
+
Changes require delegation to be off, including when model setup is pending or paused.
|
|
145
|
+
They apply to this process and future Pi starts; they cannot extend old jobs, reset
|
|
146
|
+
call quotas or free requests still settling. `/delegate on`, `status`, `limits` and
|
|
147
|
+
Strict Guard policy summaries display the effective timeout. Only the human command
|
|
148
|
+
can configure it; the model-facing tool has no timeout-setting operation.
|
|
149
|
+
|
|
150
|
+
The preference is stored in `<agent-dir>/specpi/delegation/settings.json`, where
|
|
151
|
+
`<agent-dir>` is `PI_CODING_AGENT_DIR` or `~/.pi/agent`. It contains only
|
|
152
|
+
`{"schema":1,"timeoutMinutes":15}`. Saves atomically replace this file and keep the
|
|
153
|
+
previous contents plus their SHA-256 in `settings.json.bak`. No Pi settings,
|
|
154
|
+
authentication, sessions or history are read or changed by this preference store.
|
|
155
|
+
The human-selected agent directory is resolved once, supporting platform path aliases.
|
|
156
|
+
Preference files and SpecPi subdirectories must not be links. Malformed, oversized or
|
|
157
|
+
unreadable settings block activation rather than silently using another timeout. Repair them manually
|
|
158
|
+
and restart Pi. Manual edits and changes from another Pi process take effect on
|
|
159
|
+
restart; `/reload` preserves the current process policy and counters. The preference
|
|
160
|
+
survives uninstall as user-owned configuration.
|
|
161
|
+
|
|
126
162
|
## Admit a specific purpose
|
|
127
163
|
|
|
128
164
|
| Mode | Required structure | Context and tools |
|
|
@@ -165,7 +201,7 @@ and counters. [Protocol and executable examples](protocol.md) define the exact f
|
|
|
165
201
|
| Batches / jobs | 4 batches per Pi process; one unresolved batch; 2 jobs per batch |
|
|
166
202
|
| SDK model invocations | 32 per Pi process, 8 per batch; 4 per logical job including follow-up |
|
|
167
203
|
| Follow-ups / retries | 1 changed-input follow-up per job; provider and session retries disabled |
|
|
168
|
-
| Time |
|
|
204
|
+
| Time | 10 minutes per job by default (human configurable 1–60); batch twice that; queue/follow-up included |
|
|
169
205
|
| Packet / child context | 256 KiB, checked before dispatch |
|
|
170
206
|
| Selected sources | 200 files and 8 MiB per batch |
|
|
171
207
|
| Tools | 12 calls and 64 KiB total returned JSON per logical job |
|
|
@@ -36,6 +36,19 @@ data are rejected. The host creates identities and receipts; workers cannot supp
|
|
|
36
36
|
The protocol identifier `bounded-pi-sessions-v1` and inference contract
|
|
37
37
|
`pi-agent-session-v1` describe the host implementation, not model-selected options.
|
|
38
38
|
|
|
39
|
+
## Human timeout preference
|
|
40
|
+
|
|
41
|
+
Logical jobs default to 10 minutes; batches default to 20 minutes. Human
|
|
42
|
+
`/delegate timeout <minutes>` saves a whole-minute value from 1 to 60 while delegation
|
|
43
|
+
is off; `timeout reset` saves 10. The batch window is twice the job window.
|
|
44
|
+
Deadlines start at admission and include queue and the single follow-up. Provider
|
|
45
|
+
request timeouts and the adapter abort timer honor the remaining job window, capped
|
|
46
|
+
at 60 minutes. Settings changes invalidate old policy bindings without resetting
|
|
47
|
+
quotas or settling slots. No tool operation or packet field can change the timeout.
|
|
48
|
+
See the [configuration guide](README.md#configure-the-timeout) for persistence and
|
|
49
|
+
recovery. Status limits, packet digests and Guard fingerprints bind the effective
|
|
50
|
+
policy rather than assuming the shipped default.
|
|
51
|
+
|
|
39
52
|
## Submit a batch
|
|
40
53
|
|
|
41
54
|
After the human runs `/delegate on`, the parent calls the `delegate` tool:
|
|
@@ -229,7 +229,10 @@ export default function registerCommandGuard(
|
|
|
229
229
|
const startupGeneration = state.generation;
|
|
230
230
|
try {
|
|
231
231
|
subscribeGuardState();
|
|
232
|
-
|
|
232
|
+
// Pi RPC binds session_start before it starts reading UI responses.
|
|
233
|
+
// Begin guarded without a startup dialog; /guard remains available
|
|
234
|
+
// for explicit changes once the RPC client is connected.
|
|
235
|
+
const choice = ctx.hasUI && ctx.mode !== "rpc" ? await startupChoice(ctx, startupTimeoutMs) : undefined;
|
|
233
236
|
if (state.generation !== startupGeneration) {
|
|
234
237
|
return;
|
|
235
238
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { createSnapshot } from "./snapshot.mjs";
|
|
3
|
-
import { LIMITS, digest, validateOperation } from "./protocol.mjs";
|
|
3
|
+
import { LIMITS, digest, timeoutLimits, validateOperation } from "./protocol.mjs";
|
|
4
4
|
import { runWorker } from "./worker.mjs";
|
|
5
5
|
import { DelegationError, publicErrorMessage } from "./errors.mjs";
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ export function createDelegationController({
|
|
|
17
17
|
worker = runWorker,
|
|
18
18
|
getGuard = () => "absent",
|
|
19
19
|
}) {
|
|
20
|
-
|
|
20
|
+
let policy = Object.freeze(
|
|
21
21
|
Object.fromEntries(
|
|
22
22
|
Object.entries(LIMITS).map(([key, maximum]) => {
|
|
23
23
|
const value = limits[key] ?? maximum;
|
|
@@ -707,6 +707,17 @@ export function createDelegationController({
|
|
|
707
707
|
status,
|
|
708
708
|
presentation,
|
|
709
709
|
invalidate,
|
|
710
|
+
// Human command only; never exposed through execute() or the model schema.
|
|
711
|
+
setTimeoutMinutes(minutes) {
|
|
712
|
+
const times = timeoutLimits(minutes);
|
|
713
|
+
if (enabled) {
|
|
714
|
+
throw new DelegationError("Turn delegation off before changing its timeout: /delegate off");
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
invalidate("timeout policy changed");
|
|
718
|
+
policy = Object.freeze({ ...policy, ...times });
|
|
719
|
+
changed();
|
|
720
|
+
},
|
|
710
721
|
enable() {
|
|
711
722
|
const host = getHost();
|
|
712
723
|
const guard = getGuard();
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { DelegationError, publicErrorMessage } from "./errors.mjs";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { createDelegationController } from "./core.mjs";
|
|
4
|
+
import { DEFAULT_TIMEOUT_MINUTES, timeoutLimits } from "./protocol.mjs";
|
|
4
5
|
import { createLivePanel, createToolRenderers, readableLimits, readableStatus } from "./presentation.mjs";
|
|
5
6
|
|
|
7
|
+
const USAGE = "Usage: /delegate [on|off|status|limits|timeout [<minutes>|reset]|cancel <batchId>]";
|
|
8
|
+
|
|
6
9
|
const integer = { type: "integer", minimum: 0 };
|
|
7
10
|
const string = { type: "string" };
|
|
8
11
|
const strings = { type: "array", items: string };
|
|
@@ -92,7 +95,7 @@ export const DELEGATE_SCHEMA = {
|
|
|
92
95
|
/** The native entry supplies a preflighted Pi child-session host for the active context. */
|
|
93
96
|
export function createDelegationExtension(
|
|
94
97
|
getHost,
|
|
95
|
-
{ root = process.cwd(), controllerOptions = {}, prepareContext = () => {}, presentation } = {},
|
|
98
|
+
{ root = process.cwd(), controllerOptions = {}, prepareContext = () => {}, presentation, timeoutStore } = {},
|
|
96
99
|
) {
|
|
97
100
|
let currentPi;
|
|
98
101
|
let currentContext;
|
|
@@ -130,6 +133,14 @@ export function createDelegationExtension(
|
|
|
130
133
|
getGuard,
|
|
131
134
|
onChange: updatePresentation,
|
|
132
135
|
});
|
|
136
|
+
let timeoutLoaded = !timeoutStore;
|
|
137
|
+
const loadTimeout = () => {
|
|
138
|
+
if (!timeoutLoaded) {
|
|
139
|
+
controller.setTimeoutMinutes(timeoutStore.load());
|
|
140
|
+
timeoutLoaded = true;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
133
144
|
const panel = presentation ? createLivePanel(() => controller.presentation(), presentation) : undefined;
|
|
134
145
|
|
|
135
146
|
const status = () => ({
|
|
@@ -335,6 +346,7 @@ export function createDelegationExtension(
|
|
|
335
346
|
panel?.bind(ctx);
|
|
336
347
|
invalidate("session started or resources reloaded");
|
|
337
348
|
try {
|
|
349
|
+
loadTimeout();
|
|
338
350
|
prepareContext(ctx, true);
|
|
339
351
|
} catch (error) {
|
|
340
352
|
pauseReason = publicErrorMessage(error);
|
|
@@ -368,9 +380,22 @@ export function createDelegationExtension(
|
|
|
368
380
|
}
|
|
369
381
|
});
|
|
370
382
|
pi.registerCommand("delegate", {
|
|
371
|
-
description: "Enable
|
|
383
|
+
description: "Enable read-only delegation, inspect limits, or save timeout <minutes> (1–60; reset: 10)",
|
|
372
384
|
getArgumentCompletions: (prefix) =>
|
|
373
|
-
[
|
|
385
|
+
[
|
|
386
|
+
"on",
|
|
387
|
+
"off",
|
|
388
|
+
"status",
|
|
389
|
+
"limits",
|
|
390
|
+
"timeout",
|
|
391
|
+
"timeout 5",
|
|
392
|
+
"timeout 10",
|
|
393
|
+
"timeout 15",
|
|
394
|
+
"timeout 30",
|
|
395
|
+
"timeout 60",
|
|
396
|
+
"timeout reset",
|
|
397
|
+
"cancel",
|
|
398
|
+
]
|
|
374
399
|
.filter((value) => value.startsWith(prefix.trim()))
|
|
375
400
|
.map((value) => ({ value, label: value })),
|
|
376
401
|
handler: async (args, ctx) => {
|
|
@@ -383,8 +408,8 @@ export function createDelegationExtension(
|
|
|
383
408
|
currentContext = ctx;
|
|
384
409
|
const [action = "status", id, extra] = args.trim().split(/\s+/u).filter(Boolean);
|
|
385
410
|
try {
|
|
386
|
-
if (extra || (id &&
|
|
387
|
-
throw new DelegationError(
|
|
411
|
+
if (extra || (id && !["cancel", "timeout"].includes(action))) {
|
|
412
|
+
throw new DelegationError(USAGE);
|
|
388
413
|
}
|
|
389
414
|
|
|
390
415
|
if (action === "on") {
|
|
@@ -392,6 +417,7 @@ export function createDelegationExtension(
|
|
|
392
417
|
throw new DelegationError("Delegation activation requires a human interactive command");
|
|
393
418
|
}
|
|
394
419
|
|
|
420
|
+
loadTimeout();
|
|
395
421
|
requested = true;
|
|
396
422
|
requestedGuard = getGuard();
|
|
397
423
|
await refreshSelection(ctx);
|
|
@@ -408,7 +434,38 @@ export function createDelegationExtension(
|
|
|
408
434
|
|
|
409
435
|
syncActiveTool(true);
|
|
410
436
|
ctx.ui.notify(
|
|
411
|
-
`Delegation enabled: Pi child sessions for review and scout, ${state.model.provider}/${state.model.id}, thinking ${state.model.thinkingLevel ?? "Pi configured"}. At most 2 workers, 4 batches and 32 SDK inference calls per Pi process;
|
|
437
|
+
`Delegation enabled: Pi child sessions for review and scout, ${state.model.provider}/${state.model.id}, thinking ${state.model.thinkingLevel ?? "Pi configured"}. At most 2 workers, 4 batches and 32 SDK inference calls per Pi process; ${state.limits.jobMs / 60_000} minutes per job, ${state.limits.batchMs / 60_000} minutes per batch. Configure with /delegate timeout <minutes> while off (saved across restarts). Workers see only supplied text and selected snapshots. Pi owns configured authentication; temporary parent provider/auth overrides and parent hooks are not inherited. No shell, edits, recursion, automatic retries or compaction. /delegate off cancels workers; SDK requests still settling retain their slots. These limits do not guarantee remote termination or a billing cap.`,
|
|
438
|
+
"info",
|
|
439
|
+
);
|
|
440
|
+
} else if (action === "timeout") {
|
|
441
|
+
if (id) {
|
|
442
|
+
if (!ctx.hasUI) {
|
|
443
|
+
throw new DelegationError("Timeout changes require a human interactive command");
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (requested || pending || controller.status().enabled) {
|
|
447
|
+
throw new DelegationError(
|
|
448
|
+
"Turn delegation off before changing its timeout: /delegate off",
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const minutes =
|
|
453
|
+
id === "reset" ? DEFAULT_TIMEOUT_MINUTES : /^\d+$/u.test(id) ? Number(id) : NaN;
|
|
454
|
+
timeoutLimits(minutes);
|
|
455
|
+
if (!timeoutStore) {
|
|
456
|
+
throw new DelegationError("Persistent delegation settings are unavailable");
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
timeoutStore.save(minutes);
|
|
460
|
+
controller.setTimeoutMinutes(minutes);
|
|
461
|
+
timeoutLoaded = true;
|
|
462
|
+
} else {
|
|
463
|
+
loadTimeout();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const limits = controller.status().limits;
|
|
467
|
+
ctx.ui.notify(
|
|
468
|
+
`Delegation timeout: ${limits.jobMs / 60_000} minutes per job; ${limits.batchMs / 60_000} minutes per batch, including queue and follow-up time. ${id ? "Saved for this process and future Pi starts. " : ""}Use /delegate timeout <minutes> (1–60) or /delegate timeout reset (10). Changes require /delegate off; call budgets do not reset.`,
|
|
412
469
|
"info",
|
|
413
470
|
);
|
|
414
471
|
} else if (action === "off") {
|
|
@@ -428,7 +485,7 @@ export function createDelegationExtension(
|
|
|
428
485
|
const state = status();
|
|
429
486
|
ctx.ui.notify(action === "limits" ? readableLimits(state) : readableStatus(state), "info");
|
|
430
487
|
} else {
|
|
431
|
-
throw new DelegationError(
|
|
488
|
+
throw new DelegationError(USAGE);
|
|
432
489
|
}
|
|
433
490
|
} catch (error) {
|
|
434
491
|
ctx.ui.notify(publicErrorMessage(error), "error");
|
|
@@ -4,9 +4,10 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
import { createDelegationExtension } from "./extension.mjs";
|
|
5
5
|
import { createNativePiHost, getPiSessionCompatibilityError } from "./provider.mjs";
|
|
6
6
|
import { DelegationError } from "./errors.mjs";
|
|
7
|
+
import { createTimeoutStore } from "./settings.mjs";
|
|
7
8
|
|
|
8
9
|
const stateKey = Symbol.for("specpi.delegation.native.v1");
|
|
9
|
-
const revision =
|
|
10
|
+
const revision = 8;
|
|
10
11
|
|
|
11
12
|
export async function withPiCompatibility(sdk, loadCompatibility) {
|
|
12
13
|
if (typeof sdk.clampThinkingLevel === "function") {
|
|
@@ -121,7 +122,12 @@ function createState(root, sdk, presentation) {
|
|
|
121
122
|
}
|
|
122
123
|
};
|
|
123
124
|
|
|
124
|
-
const extensionFactory = createDelegationExtension(() => host, {
|
|
125
|
+
const extensionFactory = createDelegationExtension(() => host, {
|
|
126
|
+
root,
|
|
127
|
+
prepareContext,
|
|
128
|
+
presentation,
|
|
129
|
+
timeoutStore: createTimeoutStore(),
|
|
130
|
+
});
|
|
125
131
|
const factory = (pi) => {
|
|
126
132
|
getThinkingLevel = () => pi.getThinkingLevel();
|
|
127
133
|
extensionFactory(pi);
|
|
@@ -145,6 +145,7 @@ export function readableStatus(state) {
|
|
|
145
145
|
`Delegation ${mode} · ${state.active}/${state.limits.concurrency} workers active`,
|
|
146
146
|
`Process budget: ${state.sessionCalls}/${state.limits.sessionCalls} model calls · ${state.sessionBatches}/${state.limits.sessionBatches} batches used`,
|
|
147
147
|
`Command Guard: ${plain(state.guard)}`,
|
|
148
|
+
`Timeout: ${state.limits.jobMs / 60_000} minutes per job · ${state.limits.batchMs / 60_000} minutes per batch (/delegate timeout)`,
|
|
148
149
|
];
|
|
149
150
|
if (state.model) {
|
|
150
151
|
lines.push(
|
|
@@ -176,7 +177,7 @@ export function readableLimits(state) {
|
|
|
176
177
|
return ` ${label}: ${value}${unit}`;
|
|
177
178
|
});
|
|
178
179
|
|
|
179
|
-
return `${readableStatus(state)}\
|
|
180
|
+
return `${readableStatus(state)}\nEffective limits:\n${limits.join("\n")}\nBudgets do not reset on off/on or reload. Cancellation is best effort; no billing cap.`;
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
export function createToolRenderers({ truncateToWidth, wrapTextWithAnsi }) {
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { DelegationError } from "./errors.mjs";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
|
|
4
|
+
export const DEFAULT_TIMEOUT_MINUTES = 10;
|
|
5
|
+
export const MAX_TIMEOUT_MINUTES = 60;
|
|
6
|
+
export const MAX_JOB_MS = MAX_TIMEOUT_MINUTES * 60_000;
|
|
7
|
+
|
|
8
|
+
export function timeoutLimits(minutes) {
|
|
9
|
+
if (!Number.isSafeInteger(minutes) || minutes < 1 || minutes > MAX_TIMEOUT_MINUTES) {
|
|
10
|
+
throw new DelegationError(`Delegation timeout must be a whole number from 1 to ${MAX_TIMEOUT_MINUTES} minutes`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return { jobMs: minutes * 60_000, batchMs: minutes * 120_000 };
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
export const LIMITS = Object.freeze({
|
|
5
17
|
concurrency: 2,
|
|
6
18
|
sessionBatches: 4,
|
|
@@ -8,8 +20,7 @@ export const LIMITS = Object.freeze({
|
|
|
8
20
|
batchJobs: 2,
|
|
9
21
|
batchCalls: 8,
|
|
10
22
|
jobCalls: 4,
|
|
11
|
-
|
|
12
|
-
batchMs: 300_000,
|
|
23
|
+
...timeoutLimits(DEFAULT_TIMEOUT_MINUTES),
|
|
13
24
|
contextBytes: 256 * 1024,
|
|
14
25
|
retainedResponseBytes: 256 * 1024,
|
|
15
26
|
toolBytes: 64 * 1024,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DelegationError } from "./errors.mjs";
|
|
2
|
+
import { MAX_JOB_MS } from "./protocol.mjs";
|
|
2
3
|
|
|
3
4
|
const MAX_CONTEXT_BYTES = 256 * 1024;
|
|
4
5
|
const MAX_OUTPUT_TOKENS = 8192;
|
|
@@ -513,7 +514,7 @@ export function createNativePiHost(ctx, { id, isCurrent, sdk, thinkingLevel } =
|
|
|
513
514
|
),
|
|
514
515
|
maxTokens: Math.min(MAX_OUTPUT_TOKENS, childModel.maxTokens, run.controls.limits.outputTokens),
|
|
515
516
|
maxRetries: 0,
|
|
516
|
-
timeoutMs: Math.max(1, Math.min(
|
|
517
|
+
timeoutMs: Math.max(1, Math.min(MAX_JOB_MS, run.controls.deadline - Date.now())),
|
|
517
518
|
onPayload: async (payload, providerModel) => {
|
|
518
519
|
assertRun();
|
|
519
520
|
const result = (await options.onPayload?.(payload, providerModel)) ?? payload;
|
|
@@ -637,7 +638,7 @@ export function createNativePiHost(ctx, { id, isCurrent, sdk, thinkingLevel } =
|
|
|
637
638
|
active = run;
|
|
638
639
|
const cancel = () => fail(new DelegationError("Delegation session was cancelled or expired"));
|
|
639
640
|
controls.signal.addEventListener("abort", cancel, { once: true });
|
|
640
|
-
const timer = setTimeout(cancel, Math.max(1, Math.min(
|
|
641
|
+
const timer = setTimeout(cancel, Math.max(1, Math.min(MAX_JOB_MS, controls.deadline - Date.now())));
|
|
641
642
|
timer.unref?.();
|
|
642
643
|
try {
|
|
643
644
|
assertRun();
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
+
import { DEFAULT_TIMEOUT_MINUTES, timeoutLimits } from "./protocol.mjs";
|
|
6
|
+
import { DelegationError } from "./errors.mjs";
|
|
7
|
+
|
|
8
|
+
const MAX_SETTINGS_BYTES = 4096;
|
|
9
|
+
const MAX_BACKUP_BYTES = 32 * 1024;
|
|
10
|
+
|
|
11
|
+
function regularFile(file, maxBytes = MAX_SETTINGS_BYTES) {
|
|
12
|
+
const stat = fs.lstatSync(file, { throwIfNoEntry: false });
|
|
13
|
+
if (stat && (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > maxBytes)) {
|
|
14
|
+
throw new Error("Unsupported settings file");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return stat;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function directory(dir, create = false) {
|
|
21
|
+
const parent = path.dirname(dir);
|
|
22
|
+
if (parent !== dir) {
|
|
23
|
+
directory(parent, create);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let stat = fs.lstatSync(dir, { throwIfNoEntry: false });
|
|
27
|
+
if (!stat && create) {
|
|
28
|
+
fs.mkdirSync(dir, { mode: 0o700 });
|
|
29
|
+
stat = fs.lstatSync(dir);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (stat && (!stat.isDirectory() || stat.isSymbolicLink())) {
|
|
33
|
+
throw new Error("Unsupported settings directory");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Resolve the human-selected agent root, including platform aliases, once.
|
|
38
|
+
// Missing descendants stay non-mutating on load and are checked before creation.
|
|
39
|
+
function canonicalAgentDirectory(dir) {
|
|
40
|
+
if (fs.lstatSync(dir, { throwIfNoEntry: false })) {
|
|
41
|
+
const resolved = fs.realpathSync.native(dir);
|
|
42
|
+
if (!fs.statSync(resolved).isDirectory()) {
|
|
43
|
+
throw new Error("Unsupported agent directory");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return resolved;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const parent = path.dirname(dir);
|
|
50
|
+
if (parent === dir) {
|
|
51
|
+
throw new Error("Agent directory root is unavailable");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return path.join(canonicalAgentDirectory(parent), path.basename(dir));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function atomicWrite(file, content, maxBytes = MAX_SETTINGS_BYTES) {
|
|
58
|
+
regularFile(file, maxBytes);
|
|
59
|
+
if (Buffer.byteLength(content, "utf8") > maxBytes) {
|
|
60
|
+
throw new Error("Settings write exceeds its bound");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
64
|
+
try {
|
|
65
|
+
fs.writeFileSync(temporary, content, { flag: "wx", mode: 0o600 });
|
|
66
|
+
fs.renameSync(temporary, file);
|
|
67
|
+
} finally {
|
|
68
|
+
fs.rmSync(temporary, { force: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Own preference only; never reads Pi settings, credentials or session state. */
|
|
73
|
+
export function createTimeoutStore(
|
|
74
|
+
agentDir = process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent"),
|
|
75
|
+
) {
|
|
76
|
+
const requestedAgentDir = path.resolve(agentDir);
|
|
77
|
+
let resolvedAgentDir;
|
|
78
|
+
const location = () => {
|
|
79
|
+
resolvedAgentDir ??= canonicalAgentDirectory(requestedAgentDir);
|
|
80
|
+
const dir = path.join(resolvedAgentDir, "specpi", "delegation");
|
|
81
|
+
|
|
82
|
+
return { dir, file: path.join(dir, "settings.json") };
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const read = () => {
|
|
86
|
+
const { dir, file } = location();
|
|
87
|
+
directory(dir);
|
|
88
|
+
if (!regularFile(file)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const content = fs.readFileSync(file, "utf8");
|
|
93
|
+
const settings = JSON.parse(content);
|
|
94
|
+
if (
|
|
95
|
+
!settings ||
|
|
96
|
+
settings.schema !== 1 ||
|
|
97
|
+
Object.keys(settings).length !== 2 ||
|
|
98
|
+
!Object.hasOwn(settings, "timeoutMinutes")
|
|
99
|
+
) {
|
|
100
|
+
throw new Error("Invalid settings schema");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
timeoutLimits(settings.timeoutMinutes);
|
|
104
|
+
|
|
105
|
+
return { content, minutes: settings.timeoutMinutes };
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
load() {
|
|
110
|
+
try {
|
|
111
|
+
return read()?.minutes ?? DEFAULT_TIMEOUT_MINUTES;
|
|
112
|
+
} catch {
|
|
113
|
+
throw new DelegationError(
|
|
114
|
+
"Cannot read delegation settings. Check <agent-dir>/specpi/delegation/settings.json (schema 1, timeoutMinutes: integer 1–60) and its permissions; restart Pi after repairing it.",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
save(minutes) {
|
|
119
|
+
timeoutLimits(minutes);
|
|
120
|
+
try {
|
|
121
|
+
const previous = read();
|
|
122
|
+
const { dir, file } = location();
|
|
123
|
+
directory(dir, true);
|
|
124
|
+
if (previous) {
|
|
125
|
+
atomicWrite(
|
|
126
|
+
`${file}.bak`,
|
|
127
|
+
`${JSON.stringify({ sha256: createHash("sha256").update(previous.content).digest("hex"), content: previous.content })}\n`,
|
|
128
|
+
MAX_BACKUP_BYTES,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
atomicWrite(file, `${JSON.stringify({ schema: 1, timeoutMinutes: minutes })}\n`);
|
|
133
|
+
} catch {
|
|
134
|
+
throw new DelegationError(
|
|
135
|
+
"Cannot save delegation settings. Check <agent-dir>/specpi/delegation/settings.json and its permissions; the active timeout is unchanged.",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
package/extensions/spec.ts
CHANGED
|
@@ -634,6 +634,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
634
634
|
return matches.length > 0 ? matches.map((value) => ({ value, label: value })) : null;
|
|
635
635
|
},
|
|
636
636
|
handler: async (args, ctx) => {
|
|
637
|
+
if (ctx.mode === "rpc") {
|
|
638
|
+
ctx.ui.notify(
|
|
639
|
+
"/spec controls the interactive terminal interface. SpecPi Chat manages its own response and tool display.",
|
|
640
|
+
"info",
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
|
|
637
646
|
lastContext = ctx;
|
|
638
647
|
const action = args.trim().toLowerCase();
|
|
639
648
|
if (!action) {
|
|
@@ -685,7 +685,13 @@ export default function toolWishlist(pi: ExtensionAPI) {
|
|
|
685
685
|
reportPath,
|
|
686
686
|
truncated: display.truncated,
|
|
687
687
|
});
|
|
688
|
-
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (
|
|
691
|
+
(ctx.mode === "rpc" || !supportsReportEntries) &&
|
|
692
|
+
(ctx.mode === "rpc" || ctx.mode === "tui" || ctx.mode === undefined) &&
|
|
693
|
+
typeof ctx.ui.editor === "function"
|
|
694
|
+
) {
|
|
689
695
|
await ctx.ui.editor(
|
|
690
696
|
"SpecPi Wishlist (view only; changes are ignored)",
|
|
691
697
|
`${content}\n\n---\nReport: ${displayPath}`,
|
|
@@ -1113,7 +1113,7 @@ export default function workflowControls(pi: ExtensionAPI) {
|
|
|
1113
1113
|
createdAt: new Date().toISOString(),
|
|
1114
1114
|
};
|
|
1115
1115
|
pi.appendEntry(TASK_HANDOFF_ENTRY, data);
|
|
1116
|
-
if (!supportsEntryRenderer && typeof ctx.ui.editor === "function") {
|
|
1116
|
+
if ((ctx.mode === "rpc" || !supportsEntryRenderer) && typeof ctx.ui.editor === "function") {
|
|
1117
1117
|
await ctx.ui.editor("Task handoff (view only)", markdown);
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
@@ -1738,7 +1738,7 @@ export default function workflowControls(pi: ExtensionAPI) {
|
|
|
1738
1738
|
|
|
1739
1739
|
if (!latestChallenge) {
|
|
1740
1740
|
ctx.ui.notify("No completed challenge exists on this session branch.", "info");
|
|
1741
|
-
} else if (supportsEntryRenderer) {
|
|
1741
|
+
} else if (supportsEntryRenderer && ctx.mode !== "rpc") {
|
|
1742
1742
|
pi.appendEntry(CHALLENGE_ENTRY, { ...latestChallenge, kind: "display" });
|
|
1743
1743
|
} else if (typeof ctx.ui.editor === "function") {
|
|
1744
1744
|
await ctx.ui.editor("Completion challenge (view only)", latestChallenge.markdown ?? "Unavailable");
|
package/package.json
CHANGED
|
@@ -367,6 +367,28 @@ function assertInstalledLifecycle(packageRoot, binPath, temporaryRoot, baseEnv)
|
|
|
367
367
|
runCli(["install", ...lifecycleFlags]);
|
|
368
368
|
runCli(["doctor"], { timeout: 300_000 });
|
|
369
369
|
|
|
370
|
+
const privateEvidence = new Map([
|
|
371
|
+
[path.join(agentDir, "specpi", "delegation", "settings.json"), '{"schema":1,"timeoutMinutes":15}\n'],
|
|
372
|
+
[
|
|
373
|
+
path.join(agentDir, "specpi", "delegation", "settings.json.bak"),
|
|
374
|
+
`${JSON.stringify({
|
|
375
|
+
content: '{"schema":1,"timeoutMinutes":10}\n',
|
|
376
|
+
sha256: createHash("sha256").update('{"schema":1,"timeoutMinutes":10}\n').digest("hex"),
|
|
377
|
+
})}\n`,
|
|
378
|
+
],
|
|
379
|
+
[path.join(agentDir, "specpi", "wishlist", "observations.jsonl"), '{"private":true}\n'],
|
|
380
|
+
[
|
|
381
|
+
path.join(agentDir, "specpi", "wishlist", "decisions.jsonl"),
|
|
382
|
+
'{"action":"retire","journal":{"schema":1,"evidence":["private proof"],"gates":["npm run check"],"version":"0.10.0"}}\n',
|
|
383
|
+
],
|
|
384
|
+
[path.join(agentDir, "specpi", "experiments", "registry.json"), '{"private":true}\n'],
|
|
385
|
+
[path.join(agentDir, "specpi", "experiments", "patches", "package-smoke.patch"), "private patch\n"],
|
|
386
|
+
]);
|
|
387
|
+
for (const [file, content] of privateEvidence) {
|
|
388
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
389
|
+
fs.writeFileSync(file, content, { mode: 0o600 });
|
|
390
|
+
}
|
|
391
|
+
|
|
370
392
|
const guardDirectory = path.join(agentDir, "extensions", "command-guard");
|
|
371
393
|
const driftedGuardPath = path.join(guardDirectory, "index.ts");
|
|
372
394
|
fs.appendFileSync(driftedGuardPath, "\n// package-check rollback drift\n");
|
|
@@ -386,20 +408,6 @@ function assertInstalledLifecycle(packageRoot, binPath, temporaryRoot, baseEnv)
|
|
|
386
408
|
"failed update did not restore the complete managed tree",
|
|
387
409
|
);
|
|
388
410
|
|
|
389
|
-
const privateEvidence = new Map([
|
|
390
|
-
[path.join(agentDir, "specpi", "wishlist", "observations.jsonl"), '{"private":true}\n'],
|
|
391
|
-
[
|
|
392
|
-
path.join(agentDir, "specpi", "wishlist", "decisions.jsonl"),
|
|
393
|
-
'{"action":"retire","journal":{"schema":1,"evidence":["private proof"],"gates":["npm run check"],"version":"0.10.0"}}\n',
|
|
394
|
-
],
|
|
395
|
-
[path.join(agentDir, "specpi", "experiments", "registry.json"), '{"private":true}\n'],
|
|
396
|
-
[path.join(agentDir, "specpi", "experiments", "patches", "package-smoke.patch"), "private patch\n"],
|
|
397
|
-
]);
|
|
398
|
-
for (const [file, content] of privateEvidence) {
|
|
399
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
400
|
-
fs.writeFileSync(file, content, { mode: 0o600 });
|
|
401
|
-
}
|
|
402
|
-
|
|
403
411
|
runCli(["update", ...lifecycleFlags, "--force"]);
|
|
404
412
|
runCli(["doctor"], { timeout: 300_000 });
|
|
405
413
|
runCli(["uninstall", "--yes"]);
|
|
@@ -409,11 +417,14 @@ function assertInstalledLifecycle(packageRoot, binPath, temporaryRoot, baseEnv)
|
|
|
409
417
|
false,
|
|
410
418
|
"uninstall left a managed extension behind",
|
|
411
419
|
);
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
420
|
+
for (const file of DELEGATION_MANAGED_FILES) {
|
|
421
|
+
assert.equal(
|
|
422
|
+
fs.existsSync(path.join(agentDir, "extensions", "delegation", file)),
|
|
423
|
+
false,
|
|
424
|
+
`uninstall left a managed delegation file: ${file}`,
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
417
428
|
for (const [file, expected] of privateEvidence) {
|
|
418
429
|
assert.equal(fs.existsSync(file), true, `uninstall removed private SpecPi evidence: ${file}`);
|
|
419
430
|
assert.equal(fs.readFileSync(file, "utf8"), expected, `uninstall changed private SpecPi evidence: ${file}`);
|
|
@@ -460,7 +471,12 @@ try {
|
|
|
460
471
|
assert.ok(fs.existsSync(tarball), "the reported npm tarball does not exist");
|
|
461
472
|
assertArtifactMatchesManifest(tarball, packResult);
|
|
462
473
|
|
|
463
|
-
const installEnv = {
|
|
474
|
+
const installEnv = {
|
|
475
|
+
...process.env,
|
|
476
|
+
PI_CODING_AGENT_DIR: path.join(temporaryRoot, "install-agent"),
|
|
477
|
+
npm_config_audit: "false",
|
|
478
|
+
npm_config_fund: "false",
|
|
479
|
+
};
|
|
464
480
|
runNpm(
|
|
465
481
|
[
|
|
466
482
|
"install",
|
package/scripts/check-syntax.mjs
CHANGED
|
@@ -26,6 +26,11 @@ export function syntaxFiles(root) {
|
|
|
26
26
|
visit(path.join(root, directory));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// The separately distributed editor extension is absent from the npm artifact.
|
|
30
|
+
if (fs.existsSync(path.join(root, "vscode"))) {
|
|
31
|
+
visit(path.join(root, "vscode"));
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
return files.sort();
|
|
30
35
|
}
|
|
31
36
|
|