@herbertgao/pi-extensions 2026.11.1 → 2026.11.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/CHANGELOG.md +19 -0
- package/README.md +14 -14
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +109 -16
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/write-execution.ts +5 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +54 -42
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +2 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +9 -8
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +70 -9
- package/node_modules/@herbertgao/pi-subagents/src/agent-record-entry.ts +183 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +156 -13
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +52 -8
- package/node_modules/@herbertgao/pi-subagents/src/default-agents.ts +3 -4
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +158 -56
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/status-note.ts +3 -1
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +167 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/viewer-keys.ts +8 -4
- package/node_modules/@herbertgao/pi-subagents/src/workflow/host.ts +88 -6
- package/node_modules/@herbertgao/pi-subagents/src/workflow/progress.ts +3 -2
- package/node_modules/@narumitw/pi-btw/CHANGELOG.md +259 -0
- package/node_modules/@narumitw/pi-btw/package.json +6 -5
- package/node_modules/@narumitw/pi-caffeinate/CHANGELOG.md +70 -0
- package/node_modules/@narumitw/pi-caffeinate/package.json +5 -4
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +21 -0
- package/node_modules/pi-commandcode-provider/README.md +18 -6
- package/node_modules/pi-commandcode-provider/index.ts +11 -5
- package/node_modules/pi-commandcode-provider/package.json +1 -1
- package/node_modules/pi-commandcode-provider/src/api-key.ts +26 -10
- package/node_modules/pi-commandcode-provider/src/auth-server.ts +33 -24
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +2 -2
- package/node_modules/pi-commandcode-provider/src/converters.ts +3 -61
- package/node_modules/pi-commandcode-provider/src/core.ts +29 -4
- package/node_modules/pi-commandcode-provider/src/cost.ts +32 -12
- package/node_modules/pi-commandcode-provider/src/oauth.ts +40 -6
- package/node_modules/pi-commandcode-provider/src/pricing.ts +5 -3
- package/node_modules/pi-commandcode-provider/src/runtime.ts +14 -7
- package/node_modules/pi-commandcode-provider/src/transport.ts +6 -3
- package/node_modules/pi-provider-qoder/README.md +40 -0
- package/node_modules/pi-provider-qoder/dist/index.js +64 -0
- package/node_modules/pi-provider-qoder/package.json +4 -3
- package/node_modules/pi-typesafe/README.md +3 -3
- package/node_modules/pi-typesafe/dist/auth.d.ts +21 -4
- package/node_modules/pi-typesafe/dist/auth.js +32 -7
- package/node_modules/pi-typesafe/dist/backends.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/backends.js +9 -0
- package/node_modules/pi-typesafe/dist/client.js +7 -12
- package/node_modules/pi-typesafe/dist/errors.d.ts +3 -2
- package/node_modules/pi-typesafe/dist/errors.js +12 -10
- package/node_modules/pi-typesafe/dist/extension.js +14 -10
- package/node_modules/pi-typesafe/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +22 -0
- package/node_modules/pi-web-access/README.md +31 -12
- package/node_modules/pi-web-access/curator-page.ts +5 -1
- package/node_modules/pi-web-access/curator-server.ts +2 -0
- package/node_modules/pi-web-access/dist/index.js +673 -308
- package/node_modules/pi-web-access/dist/mcp-cli.js +666 -309
- package/node_modules/pi-web-access/gemini-search.ts +12 -4
- package/node_modules/pi-web-access/github-api.ts +1 -1
- package/node_modules/pi-web-access/github-extract.ts +3 -2
- package/node_modules/pi-web-access/index.ts +7 -3
- package/node_modules/pi-web-access/mcp-tool-definitions.ts +1 -1
- package/node_modules/pi-web-access/outcrawl.ts +204 -0
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/pi-web-access/sofya.ts +201 -0
- package/node_modules/pi-web-access/utils.ts +16 -6
- package/node_modules/pi-web-access/web-tool-core.ts +4 -0
- package/package.json +11 -11
|
@@ -14,7 +14,7 @@ https://github.com/user-attachments/assets/8685261b-9338-4fea-8dfe-1c590d5df543
|
|
|
14
14
|
- **Parallel background agents** — spawn multiple agents that run concurrently with automatic queuing (configurable concurrency limit, default 10) and completion notifications that reach the parent at its next boundary, several at once when they finish together
|
|
15
15
|
- **Live widget UI** — persistent above-editor widget with animated spinners, live tool activity, token counts, and colored status icons. Configurable via `/agents → Settings → Widget`: `all` (every agent), `background` (default — hides foreground runs, which already render inline as the `Agent` tool result), or `off`
|
|
16
16
|
- **FleetView** — Claude Code-style navigable list of `main` + every running subagent rendered below the editor (earliest-launched first). Press `↓` (or `←`) at an empty prompt to jump in, `↑`/`↓` to move the selection, `Enter` to open the selected agent's live, auto-updating conversation, `Esc` to return. Finished agents linger briefly before dropping out, and a viewer stays open through completion so you can read the final output. Toggle via `/agents → Settings → Fleet view`
|
|
17
|
-
- **Conversation viewer** — select any agent in `/agents` to open a live-scrolling overlay of its full conversation (auto-follows new content, scroll up to pause). In pi's fullscreen mode it is a borderless, full-terminal observer with mouse support. Steer a running agent inline by pressing `Enter` to open a composer, typing, then `Enter` to send (`Esc` or an empty submit returns) — the message appears as a user message and redirects the agent after its current tool. Press `b` on a running foreground `Agent` call to hand that run to the background (see [Sending a foreground agent to the background](#sending-a-foreground-agent-to-the-background)). Stop a still-running agent by pressing `x` (then `x` again to confirm) — steer and stop both work for background agents too. Assistant text renders as Markdown; `m` cycles that between off, assistant-only and everything (see [Viewer markdown](#persistent-settings))
|
|
17
|
+
- **Conversation viewer** — select any agent in `/agents` to open a live-scrolling overlay of its full conversation (auto-follows new content, scroll up to pause). In pi's fullscreen mode it is a borderless, full-terminal observer with mouse support. Steer a running agent inline by pressing `Enter` to open a composer, typing, then `Enter` to send (`Esc` or an empty submit returns) — the message appears as a user message and redirects the agent after its current tool. Press `b` on a running foreground `Agent` call to hand that run to the background (see [Sending a foreground agent to the background](#sending-a-foreground-agent-to-the-background)). Stop a still-running agent by pressing `x` (then `x` again to confirm) — steer and stop both work for background agents too. Tool calls render the way they do in pi's own transcript, through the renderers registered in the agent's session: a bash call shows its command and output, `read` its line numbers, `edit` its diff, an extension tool its own renderer, and a tool without one falls back to its arguments plus a bounded output preview. `ctrl+o` (or whatever `app.tools.expand` is bound to) unfolds elided tool output. Assistant text renders as Markdown; `m` cycles that between off, assistant-only and everything (see [Viewer markdown](#persistent-settings))
|
|
18
18
|
- **Custom agent types** — define agents in `.pi/agents/<name>.md` or `.agents/agents/<name>.md` (project) or globally, with YAML frontmatter: custom system prompts, model selection, thinking levels, tool restrictions, and Claude Code-compatible colored name badges
|
|
19
19
|
- **Package-shipped agents** — a pi package can declare its own subagents (and workflow scripts) with `"pi": { "subagents": { "agents": ["./agents"] } }` in its `package.json`, so `pi install` is the whole setup: no copying files into `.pi/agents/` on every machine or container start. Only packages pi has actually installed are read (never `node_modules`), package definitions rank below every agent you wrote, and `/agents` shows them read-only with Eject and Disable. Narrow or switch it off with `packageAgents` / `packageWorkflows`. **[Full guide](https://github.com/HerbertGao/pi-extensions/blob/master/packages/pi-subagents/docs/packages.md)**
|
|
20
20
|
- **Nested subagents** — opt-in, default-off delegation: a custom agent that sets `allowed_subagents` gets its own ownership-scoped `Agent`, `get_subagent_result`, and `steer_subagent` tools, depth-capped from the main session (default 2). It can control only its own children, they are stopped when it finishes, and their transcripts and token spend roll up to it. The allowlist is a privilege boundary — a child runs with its own tools, so pick it as carefully as `tools:` itself
|
|
@@ -214,12 +214,12 @@ It is a literal clone — the session's own entries and the same system prompt,
|
|
|
214
214
|
| Mode | `@plan sketch the migration`, with no Plan agent running |
|
|
215
215
|
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
216
216
|
| `model` (default) | a clone of this conversation takes the turn off-screen and calls `Agent`, so the agent starts with a prompt **written from the conversation**. Nothing reaches the chat but a `Prompting @plan…` toast — the wording marks the wait for that turn, where `direct`'s `Started @plan` means it is already running |
|
|
217
|
-
| `direct` | the agent starts here, immediately, with your message verbatim as its prompt. No model call at all, so no latency before it begins
|
|
217
|
+
| `direct` | the agent starts here, immediately, with your message verbatim as its prompt (after this conversation, if its file sets `inherit_context`). No model call at all, so no latency before it begins |
|
|
218
218
|
| `off` | `@` means only "attach a file" again |
|
|
219
219
|
|
|
220
|
-
Either way the started agent honours its own frontmatter — `model:`, `thinking:`, `max_turns:` all apply, since neither path passes them and the agent's config wins. Mentioning something as the very first thing in a session works: there is simply no history to carry, and the clone still runs on your model and system prompt. If it cannot deliver at all — a model can always answer in prose instead of calling the tool — the agent is started directly with your text and the toast says so, rather than leaving you with nothing running.
|
|
220
|
+
Either way the started agent honours its own frontmatter — `model:`, `thinking:`, `max_turns:` all apply, since neither path passes them and the agent's config wins, and `inherit_context: true` hands it this conversation even in `direct` mode. Mentioning something as the very first thing in a session works: there is simply no history to carry, and the clone still runs on your model and system prompt. If it cannot deliver at all — a model can always answer in prose instead of calling the tool — the agent is started directly with your text and the toast says so, rather than leaving you with nothing running.
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
Mentions are TUI-only. In `pi -p '@plan the migration'`, pi itself reads the leading `@plan` as a file to attach and exits with `File not found` before any extension sees the prompt. For a headless run, ask for the agent in plain words so the model calls the `Agent` tool, or use [`--subagents-workflow-file`](#cli-flags).
|
|
223
223
|
|
|
224
224
|
Two things to weigh against `direct`: the clone re-sends the whole conversation, and the agent does not start until that turn finishes.
|
|
225
225
|
|
|
@@ -269,15 +269,15 @@ Group completions render each agent as a separate block. The LLM receives struct
|
|
|
269
269
|
|
|
270
270
|
## Default Agent Types
|
|
271
271
|
|
|
272
|
-
| Type | Tools | Model
|
|
273
|
-
| ----------------- | -------------------------- |
|
|
274
|
-
| `general-purpose` | all 7 | inherit
|
|
275
|
-
| `Explore` | read, bash, grep, find, ls |
|
|
276
|
-
| `Plan` | read, bash, grep, find, ls | inherit
|
|
272
|
+
| Type | Tools | Model | Prompt Mode | Description |
|
|
273
|
+
| ----------------- | -------------------------- | ------- | ---------------------- | ------------------------------------------------------------------------------------- |
|
|
274
|
+
| `general-purpose` | all 7 | inherit | `append` (parent twin) | Inherits the parent's full system prompt — same rules, CLAUDE.md, project conventions |
|
|
275
|
+
| `Explore` | read, bash, grep, find, ls | inherit | `replace` (standalone) | Fast codebase exploration (read-only) |
|
|
276
|
+
| `Plan` | read, bash, grep, find, ls | inherit | `replace` (standalone) | Software architect for implementation planning (read-only) |
|
|
277
277
|
|
|
278
278
|
The `general-purpose` agent is a **parent twin** — it receives the parent's system prompt plus a sub-agent context bridge, so it follows the same rules the parent does. The parent's skill list, cwd and extension sections are left out: the subagent's own session adds them for itself, so its skills follow its `skills` setting. Explore and Plan use standalone prompts tailored to their read-only roles.
|
|
279
279
|
|
|
280
|
-
Default agents can be **ejected** (`/agents` → select agent → Eject) to export them as `.md` files for customization, **overridden** by creating a `.md` file with the same name (e.g. `.pi/agents/general-purpose.md`), or **disabled** per-project with `enabled: false` frontmatter.
|
|
280
|
+
Default agents can be **ejected** (`/agents` → select agent → Eject) to export them as `.md` files for customization, **overridden** by creating a `.md` file with the same name (e.g. `.pi/agents/general-purpose.md`), or **disabled** per-project with `enabled: false` frontmatter. To run Explore on a cheaper model, eject it and add `model:` (e.g. `model: anthropic/claude-haiku-4-5`); a pinned model resolves through any provider with a key, not just the session's.
|
|
281
281
|
|
|
282
282
|
## Custom Agents
|
|
283
283
|
|
|
@@ -334,12 +334,12 @@ All fields are optional — sensible defaults for everything.
|
|
|
334
334
|
| `name` | filename | **The agent's type** — what `subagent_type` and `@handle` address. Claude Code's rule: the filename doesn't have to match, so `blubb.md` with `name: code-review` dispatches as `code-review`. Omit it and the filename is used. Any value works except one containing `:`, which Claude Code reserves for plugin-scoped identifiers — such a file is skipped with a warning. Two files may declare the same name; the later load wins, as a filename clash always did |
|
|
335
335
|
| `display_name` | the type | Label shown in the UI (widget, agent list, badges) — cosmetic only, and independent of `name`. Claude Code has no equivalent; a file that sets only `name` badges as its type, unchanged |
|
|
336
336
|
| `color` | — | Background color for the agent name badge in the Agent tool header, widget, FleetView, and conversation viewer. Supports Claude Code's `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, `cyan` (the values its own default theme uses); quoted six-digit hex such as `"#8B5CF6"`; and Agency Agents aliases (`amber`, `teal`, `indigo`, `gold`, `neon-green`, `neon-cyan`, `metallic-blue`, `violet`, `rose`, `lime`, `gray`/`grey`, `fuchsia`, `slate`, `navy`). Badge text is black or white, whichever clears 4.5:1 against the rendered background — Claude Code uses one inverse color for every badge. Invalid values render no badge and preserve each surface's existing theme foreground |
|
|
337
|
-
| `tools` | all 7 | Which tools the agent can call. Built-in names (`read, grep, …`), `*` / `all` (all built-ins), `none`,
|
|
337
|
+
| `tools` | all 7 | Which tools the agent can call. Built-in names (`read, grep, …`, or Claude Code's `Read, Glob, …`), `*` / `all` (all built-ins), `none`, `ext:<extension>` / `ext:<extension>/<tool>` selectors for extension tools, and bare `mcp__<server>__<tool>` entries for MCP tools. See [Tool & extension scoping](#tool--extension-scoping) below |
|
|
338
338
|
| `extensions` | `true` | Which extensions to load for the agent. `true` (all defaults), `false` (none), or an explicit list: `[mcp, "/abs/path.ts", "*"]`. See [Tool & extension scoping](#tool--extension-scoping) below |
|
|
339
339
|
| `exclude_extensions` | — | Extension denylist applied after `extensions:` — exclude wins. Plain names only (case-insensitive), no paths or `*`. Useful with `extensions: true` to drop one extension (e.g. `pi-notify`) |
|
|
340
340
|
| `skills` | `true` | `true` inherits the parent's skills; `false` inherits none. A comma-separated list preloads **only** those skills into the system prompt and does not inherit the rest (see [Skill Preloading](#skill-preloading) for discovery locations) |
|
|
341
341
|
| `memory` | — | Persistent agent memory scope: `project`, `local`, or `user`. Auto-detects read-only agents |
|
|
342
|
-
| `disallowed_tools` | — | Comma-separated tools to deny even if extensions provide them
|
|
342
|
+
| `disallowed_tools` | — | Comma-separated tools to deny even if extensions provide them. Claude Code's `disallowedTools` key and tool names (`Write`, `Glob`) work too |
|
|
343
343
|
| `isolation` | — | Set to `worktree` to run in an isolated git worktree, or `off` to refuse one even when the caller passes `isolation: "worktree"` (frontmatter is authoritative). Workflow scripts are the exception: as in Claude Code, only their `agent()` option decides. `none`, `no`, and `false` are accepted spellings of `off` |
|
|
344
344
|
| `model` | inherit parent | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`). Resolved tolerantly (`.`/`-` and a trailing date stamp are interchangeable) and falls back to the same model under another provider if the named one doesn't have it |
|
|
345
345
|
| `thinking` | inherit | off, minimal, low, medium, high, xhigh, max — actual availability depends on your pi version and model; pi clamps unsupported levels down |
|
|
@@ -358,7 +358,7 @@ Frontmatter is authoritative. If an agent file sets `model`, `thinking`, `max_tu
|
|
|
358
358
|
|
|
359
359
|
- `isolated` holds on every spawn path, including `@handle` mentions, workflows and [cross-extension RPC](https://github.com/HerbertGao/pi-extensions/blob/master/packages/pi-subagents/docs/rpc.md).
|
|
360
360
|
- `isolation` holds on every path except workflows: as in Claude Code, only the script's `agent()` option decides there.
|
|
361
|
-
- `inherit_context`
|
|
361
|
+
- `inherit_context` holds wherever you start the agent from this session: `Agent` tool and nested spawns, and `@handle` mentions in either mode. Spawns another caller starts are its caller's to decide, as in Claude Code, where only a fork inherits the conversation: workflow children and scheduled runs never inherit, and an RPC caller opts in with `inheritContext`.
|
|
362
362
|
|
|
363
363
|
**Forgiving `model:` resolution.** A `model:` pin is matched against pi's model registry tolerantly, so cosmetic id variations don't silently drop the agent back to the parent's model: `.` and `-` are treated as equivalent in version numbers (`claude-haiku-4.5` ≡ `claude-haiku-4-5`), a trailing `-YYYYMMDD` date stamp is optional (`anthropic/claude-haiku-4-5-20251001` matches an undated registry id and vice-versa), and a `provider/modelId` whose named provider doesn't carry that model retries the bare id against every provider. Precedence is **exact → fuzzy under the named provider → same model under any provider → unavailable**, so an exact match always wins and dated snapshots aren't conflated. If nothing resolves, the pin can't run and the agent inherits the parent model — `/agents → Agent types` flags this case as `(unavailable, fallback: inherit)` and shows the resolved target `(→ provider/id)` when resolution lands on a different provider or version than configured. (This is distinct from [Model Scope](#model-scope) enforcement, which matches the `enabledModels` allowlist by _exact_ entry.)
|
|
364
364
|
|
|
@@ -395,6 +395,8 @@ tools: read, grep, find # narrow to listed built-ins; extensions still load
|
|
|
395
395
|
tools: "*" # all 7 built-ins (alias: `all`)
|
|
396
396
|
tools: none # zero built-ins (alias: `""`)
|
|
397
397
|
tools: "*, ext:mcp/search" # built-ins plus one extension tool
|
|
398
|
+
tools: Read, Grep, Glob # Claude Code names: read, grep, find
|
|
399
|
+
tools: "read, mcp__radius__*" # read plus the radius MCP server's tools
|
|
398
400
|
|
|
399
401
|
extensions: false # no extensions load
|
|
400
402
|
extensions: [mcp] # only mcp loads
|
|
@@ -416,24 +418,27 @@ A few rules the examples don't make obvious:
|
|
|
416
418
|
- `extensions:` is the sole loading authority. `ext:foo` in `tools:` narrows what surfaces; it can't load `foo` on its own. Mismatches fire `extension-error:…` warnings.
|
|
417
419
|
- Any `ext:` entry flips extension tools to an explicit allowlist — unnamed extensions still load (handlers fire) but expose no tools. So `tools: "*, ext:mcp/search"` exposes only `search` from `mcp`, nothing from any other extension.
|
|
418
420
|
- Extension names match case-insensitively (`[Mcp]` = `[mcp]`); tool names in `ext:foo/bar` stay case-sensitive.
|
|
421
|
+
- Claude Code agent files work as written. Built-in names match case-insensitively (`Read` = `read`), `Glob` means `find` and `MultiEdit` means `edit`; Claude Code tools pi lacks (`WebFetch`, `Task`) fire a `tools-error:…` warning. `disallowedTools` is read as `disallowed_tools`.
|
|
422
|
+
- Bare `mcp__<server>__<tool>` entries (exact, or `*` patterns like `mcp__radius__*`; a server-level `mcp__radius` means the whole server, as in Claude Code) narrow MCP tools as pi's `--tools` does: only matching MCP tools stay, from whichever extension serves them, and every other extension tool follows the rules above. The `codemode` and `tool_search` bridges that reach MCP tools stay in scope automatically, even under an `ext:` allowlist. With `extensions: false` or `isolated: true` nothing can serve them, and a `tools-error:…` warning says so.
|
|
419
423
|
- pi's built-in extensions (`builtin:mcp`, `builtin:codemode`, `builtin:tool-search`) load in subagents as they do in the main session, so with `extensions: true` **every subagent starts its own set of `mcp.json` servers**, which stay up until the subagent's session is disposed (on quit, or ~10 minutes after it finishes). Address them by the full `builtin:` name — bare `[mcp]` matches a third-party extension named `mcp`, not the built-in — and narrow their tools with `ext:builtin:mcp/<tool>`. MCP tools are reached through codemode (or `tool_search` for `deferred` servers), so an `ext:` allowlist must name that bridge too, as pi's `--tools read,codemode,'mcp__*'` does: `tools: "read, ext:builtin:codemode, ext:builtin:mcp/mcp__radius__search"`. Opt out per agent with `exclude_extensions: builtin:mcp`, or everywhere with `-builtin:mcp` in pi's `extensions` setting; starting pi with `--no-mcp` keeps MCP out of subagents too, and `--no-extensions` keeps all three built-ins out. MCP tools stay undeclared until codemode or `tool_search` reaches them, as in the main session, and a codemode script can only call tools inside the agent's scope. Out-of-scope tools are blocked but can still appear in codemode's `searchTools()` and `tool_search` results.
|
|
420
424
|
- Subagents inherit the parent session's **project trust**: in a project you did not trust, a subagent loads none of its `.pi` extensions or settings and never starts the servers in its `.pi/mcp.json`. A subagent spawned into another directory (RPC `cwd`) treats that directory as untrusted.
|
|
421
425
|
- Extensions that register tools **lazily** work too. MCP-backed extensions typically can't enumerate their tools until their servers connect, so they register from `session_start` or `before_agent_start` rather than at load. Subagent scoping is re-derived as tools appear, so these surface normally — including under `ext:` selectors, which keep narrowing correctly no matter when a tool shows up.
|
|
422
426
|
- Extensions bound into a subagent see **both ends** of that session's lifecycle: `session_start` when the agent starts, `session_shutdown` (reason `quit`) when its session is disposed — on quit, and when its record is evicted ~10 minutes after it finishes. Release per-session resources there; anything left armed outlives the session it belongs to. Handlers are given three seconds on quit, after which teardown proceeds regardless.
|
|
423
427
|
- An installed **package** extension matches by its package short name (`@scope/pi-subagents` → `[pi-subagents]`), in addition to its path-derived name (a package whose entry is `src/index.ts` also answers to `[src]`). Prefer the package name — the path-derived one is incidental.
|
|
424
428
|
- Plain `tools:` typos fail loudly: `tools: reed, grep` fires `tools-error:…` instead of silently producing an under-tooled agent.
|
|
429
|
+
- An agent whose `tools:` resolve to nothing is refused, as in Claude Code: an entry is unknown (or an `ext:` names an extension that did not load), no built-in survives `disallowed_tools`, and no extension could add a tool. That is mostly `extensions: false` or `isolated: true` with only unknown names (`tools: WebFetch`). With extensions loading the agent still starts, since their tools register after spawn.
|
|
425
430
|
- `exclude_extensions:` wins over `extensions:` and over `ext:` selectors — an excluded extension never loads and a `tools: ext:` entry can't pull it back. Plain names only (no paths, no `*`); a name matching nothing fires an `extension-error:…` warning.
|
|
426
431
|
- `exclude_extensions:` is **not a sandbox**: excluded extensions' factory code still executes once during loading. Exclusion suppresses their tools and their bound lifecycle hooks (`pi.on` handlers like `session_start` only fire for extensions bound to the session), but not other load-time side effects — a factory that subscribes directly to the shared `pi.events` bus stays live. Don't rely on it to contain an untrusted extension.
|
|
427
432
|
- Array and string forms are equivalent: `[a, b]` == `"a, b"`.
|
|
428
433
|
|
|
429
434
|
**How an agent's scope is advertised.** The Agent tool description lists every available agent with a `(Tools: …)` suffix, and that suffix is what the orchestrator reads when deciding where to route work. It describes **built-in scope only** — extension tools are resolved when the agent runs (extensions may register lazily, see above), so they can't be enumerated when the description is built:
|
|
430
435
|
|
|
431
|
-
| `tools:`
|
|
432
|
-
|
|
|
433
|
-
| omitted, `*`, or `all`
|
|
434
|
-
| a list of built-ins
|
|
435
|
-
| `none` with `isolated: true` or `extensions: false`
|
|
436
|
-
| `none`, or only `ext:` entries, with extensions loading | `no built-ins, extension tools only` |
|
|
436
|
+
| `tools:` | suffix |
|
|
437
|
+
| ----------------------------------------------------------------- | ------------------------------------ |
|
|
438
|
+
| omitted, `*`, or `all` | `*` |
|
|
439
|
+
| a list of built-ins | that list, e.g. `read, grep` |
|
|
440
|
+
| `none` with `isolated: true` or `extensions: false` | `none` |
|
|
441
|
+
| `none`, or only `ext:` / `mcp__` entries, with extensions loading | `no built-ins, extension tools only` |
|
|
437
442
|
|
|
438
443
|
The last two rows are separate because zero built-ins is not zero tools: `tools: none` alongside `extensions:` still surfaces every extension tool, so calling it `none` would understate what the agent can do. Note `*` doesn't enumerate extension tools either — an agent with `tools: "*, ext:mcp/search"` advertises `*`.
|
|
439
444
|
|
|
@@ -477,20 +482,20 @@ Four rules define the feature:
|
|
|
477
482
|
|
|
478
483
|
Launch a sub-agent.
|
|
479
484
|
|
|
480
|
-
| Parameter | Type | Required | Description
|
|
481
|
-
| ------------------- | ----------------------- | -------- |
|
|
482
|
-
| `prompt` | string | yes | The task for the agent
|
|
483
|
-
| `description` | string | yes | Short 3-5 word summary (shown in UI)
|
|
484
|
-
| `name` | string | no | Memorable name for this agent (`auth-audit`), addressable as `@name` and accepted by `steer_subagent`/`get_subagent_result`. Additive — the type-derived handle is still assigned
|
|
485
|
-
| `subagent_type` | string | yes | Agent type (built-in or custom)
|
|
486
|
-
| `model` | string | no | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`). Resolved tolerantly (`.`/`-` and a trailing date stamp interchangeable) with provider fallback
|
|
487
|
-
| `thinking` | string | no | Thinking level: off, minimal, low, medium, high, xhigh, max (availability depends on pi version and model)
|
|
488
|
-
| `max_turns` | number | no | Max agentic turns. Omit for unlimited (default)
|
|
489
|
-
| `run_in_background` | boolean | no | Defaults to `true`; `false` blocks and returns the result inline, until [`ctrl+b`](#sending-a-foreground-agent-to-the-background) hands it to the background
|
|
490
|
-
| `resume` | string | no | Agent ID to resume a previous session. The resumed run gets a fresh `max_turns` budget
|
|
491
|
-
| `isolated` | boolean | no | No extension/MCP tools
|
|
492
|
-
| `isolation` | `"off"` \| `"worktree"` | no | `worktree` runs in an isolated git worktree; `off` (the default) does not. Absent from the schema entirely when `worktreeIsolation: false`
|
|
493
|
-
| `inherit_context` | boolean | no | Fork parent conversation into agent
|
|
485
|
+
| Parameter | Type | Required | Description |
|
|
486
|
+
| ------------------- | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
487
|
+
| `prompt` | string | yes | The task for the agent |
|
|
488
|
+
| `description` | string | yes | Short 3-5 word summary (shown in UI) |
|
|
489
|
+
| `name` | string | no | Memorable name for this agent (`auth-audit`), addressable as `@name` and accepted by `steer_subagent`/`get_subagent_result`. Additive — the type-derived handle is still assigned |
|
|
490
|
+
| `subagent_type` | string | yes | Agent type (built-in or custom) |
|
|
491
|
+
| `model` | string | no | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`). Resolved tolerantly (`.`/`-` and a trailing date stamp interchangeable) with provider fallback |
|
|
492
|
+
| `thinking` | string | no | Thinking level: off, minimal, low, medium, high, xhigh, max (availability depends on pi version and model) |
|
|
493
|
+
| `max_turns` | number | no | Max agentic turns. Omit for unlimited (default) |
|
|
494
|
+
| `run_in_background` | boolean | no | Defaults to `true`; `false` blocks and returns the result inline, until [`ctrl+b`](#sending-a-foreground-agent-to-the-background) hands it to the background |
|
|
495
|
+
| `resume` | string | no | Agent ID to resume a previous session. The resumed run gets a fresh `max_turns` budget. Works after the agent's record is evicted (about ten minutes after it finishes) or lost to a reload: the agent is reopened from its saved session under the same id, running under its type's current definition and never in a new worktree. Refused, with the reason, when the session was never saved, its file is gone, or it ran in a worktree that held changes (the worktree was removed when the agent finished, and its changes are on the branch named in the result) |
|
|
496
|
+
| `isolated` | boolean | no | No extension/MCP tools |
|
|
497
|
+
| `isolation` | `"off"` \| `"worktree"` | no | `worktree` runs in an isolated git worktree; `off` (the default) does not. Absent from the schema entirely when `worktreeIsolation: false` |
|
|
498
|
+
| `inherit_context` | boolean | no | Fork parent conversation into agent |
|
|
494
499
|
|
|
495
500
|
### `SubagentWorkflow`
|
|
496
501
|
|
|
@@ -544,14 +549,16 @@ Concurrency is capped at `max(1, min(16, cpus - 2))` — the run's own limit, in
|
|
|
544
549
|
|
|
545
550
|
Check status and retrieve results from a background agent.
|
|
546
551
|
|
|
547
|
-
| Parameter | Type | Required | Description
|
|
548
|
-
| ---------- | ------- | -------- |
|
|
549
|
-
| `agent_id` | string | yes | Agent ID
|
|
550
|
-
| `wait` | boolean | no | Wait for completion
|
|
551
|
-
| `verbose` | boolean | no | Include full conversation log
|
|
552
|
+
| Parameter | Type | Required | Description |
|
|
553
|
+
| ---------- | ------- | -------- | --------------------------------------------------------------------------------------------- |
|
|
554
|
+
| `agent_id` | string | yes | Agent ID or handle — its `name` if one was given, otherwise its type (`explore`, `explore-2`) |
|
|
555
|
+
| `wait` | boolean | no | Wait for completion |
|
|
556
|
+
| `verbose` | boolean | no | Include full conversation log |
|
|
552
557
|
|
|
553
558
|
Cancelling a `wait: true` call (for example, with `Esc`) stops only the wait. The background agent keeps running, and its completion notification still arrives normally.
|
|
554
559
|
|
|
560
|
+
A finished agent's result stays retrievable after its in-memory record is cleaned up (about ten minutes after it finishes) or lost to a reload: the final record is saved in the session as a `subagents:record` entry, and `get_subagent_result` answers from it by id or by handle, without the stats or the conversation (`verbose`).
|
|
561
|
+
|
|
555
562
|
### `steer_subagent`
|
|
556
563
|
|
|
557
564
|
Send a steering message to a running agent. The message interrupts after the current tool execution.
|
|
@@ -718,7 +725,7 @@ Runtime tuning values set via `/agents` → Settings (max concurrency, max foreg
|
|
|
718
725
|
|
|
719
726
|
**Background by default** (`backgroundByDefault`, default `true`): what an `Agent` call that doesn't say means. On — following Claude Code — the agent runs detached, the call returns its ID immediately, and a completion notification carries a preview of the result (`get_subagent_result` for the full text). Set `false` to restore the previous behaviour, where an unqualified spawn blocked the turn and returned its output inline. An explicit `run_in_background` on the call, or in an agent file's frontmatter, overrides this in both directions; the setting only decides what "unspecified" means. **Top-level only** — a nested spawn (an agent spawning its own) always defaults to foreground, because a detached child is stopped when its parent settles and has no notification path of its own. Toggle via `/agents → Settings → Background by default`; applied live.
|
|
720
727
|
|
|
721
|
-
**Remember agents** (`rememberAgents`, default `true`): whether subagents persist their pi session, which is what lets [`@handle`](#agent-mentions) reopen an agent's conversation after its in-memory record has been evicted. Two visible consequences of the default: top-level subagents write a session file, and they nest under the session that spawned them in pi's `/resume`. Agents spawned by another agent are excluded — they get no handle, so nothing could reopen their transcript. A custom agent's `persist_session` frontmatter overrides this per agent, in both directions. Toggle via `/agents → Settings → Remember agents`; with it off, handles expire with their record (roughly ten minutes past completion) and `@explore` then starts a fresh agent rather than resuming — the behaviour before this setting existed.
|
|
728
|
+
**Remember agents** (`rememberAgents`, default `true`): whether subagents persist their pi session, which is what lets [`@handle`](#agent-mentions), `Agent({ resume })` and a workflow's `resume` reopen an agent's conversation after its in-memory record has been evicted. Two visible consequences of the default: top-level subagents write a session file, and they nest under the session that spawned them in pi's `/resume`. Agents spawned by another agent are excluded — they get no handle, so nothing could reopen their transcript. A custom agent's `persist_session` frontmatter overrides this per agent, in both directions. Toggle via `/agents → Settings → Remember agents`; with it off, handles expire with their record (roughly ten minutes past completion) and `@explore` then starts a fresh agent rather than resuming — the behaviour before this setting existed — and a later `resume` is refused because nothing was saved. When pi's `/fork` or `/clone` copies a session, resuming one of its agents from the copy forks that agent's session too, so the two parents never write into one file. That agent's `.output` transcript in the copy starts at the resume.
|
|
722
729
|
|
|
723
730
|
**Output transcript** (`outputTranscript`, default `true`): the project/global default for writing each subagent's `.output` transcript. Toggle via `/agents → Settings → Output transcript`, or set `false` in `subagents.json` to make transcripts opt-in project-wide — useful when run transcripts shouldn't sit on disk for backup or DLP tooling to pick up. A custom agent's `output_transcript` frontmatter overrides this per agent. Applied live at spawn time. Governs only the transcript, not `persist_session`, worktree commits, or memory files.
|
|
724
731
|
|
|
@@ -761,10 +768,12 @@ Toggle via `/agents → Settings → Show model`; applied live.
|
|
|
761
768
|
|
|
762
769
|
```text
|
|
763
770
|
off every line literal, as before this setting existed
|
|
764
|
-
assistant assistant text rendered;
|
|
765
|
-
all
|
|
771
|
+
assistant assistant text rendered; any result the viewer prints itself stays verbatim (default)
|
|
772
|
+
all those results rendered too
|
|
766
773
|
```
|
|
767
774
|
|
|
775
|
+
Tool calls are outside this setting: a call and its result are drawn by the tool's own renderer (see [the conversation viewer](#ui)), which knows the shape of what it produced — a diff, line-numbered source, a shell transcript — better than a generic Markdown pass would. So `m` changes assistant text and the plain result block the viewer still prints for a result whose call is not in the transcript (a compacted prefix, a reopened session).
|
|
776
|
+
|
|
768
777
|
Scoped rather than all-or-nothing because the two kinds of content have different contracts. Assistant text _is_ Markdown — the model writes it that way, and the viewer was the only surface showing its source. A tool result is whatever bytes the tool produced, and a Markdown pass over one rewrites things that occur constantly in real output: `# section` in a shell script loses its `#`, a `---` line is swallowed as a setext heading, indented output is re-fenced, and `| a | b |` is redrawn as a box-drawing table. Each of those reads as the _tool_ having misbehaved, which is why `all` is opt-in.
|
|
769
778
|
|
|
770
779
|
Two rewrites are suppressed outright rather than left to the mode, because they change _data_ rather than layout: ordered-list markers keep their source numbering (`3) 7) 9)` stays, instead of being renumbered `3. 4. 5.`) and backslash escapes are not normalised.
|
|
@@ -978,6 +987,8 @@ The agent gets a full, isolated copy of the repository. The worktree is normally
|
|
|
978
987
|
- **Agent committed its own work:** the branch is created at the agent's HEAD, preserving its commits (uncommitted leftovers are committed on top first)
|
|
979
988
|
- **Preservation failed:** the run reports an error and keeps the worktree. Its path is included in the result so the changes can be recovered manually
|
|
980
989
|
|
|
990
|
+
A resumed agent never gets a worktree, as in Claude Code: a fresh copy of HEAD would not hold its earlier edits. This covers `Agent({ resume })` and `@handle` once the record is evicted, and a workflow's `resume`. If its worktree held changes, the resume is refused with "its worktree no longer exists"; the work is on its branch. If the worktree held none, the agent continues in the main checkout without isolation.
|
|
991
|
+
|
|
981
992
|
The agent's system prompt names the worktree as an isolated copy and tells it to work only there, even if other instructions name the main checkout — otherwise an inherited parent prompt or a task prompt mentioning the project path walks it straight back out of the copy. This is a directive, not a sandbox: an agent with shell access can still `cd` out, so don't rely on `isolation` alone to protect the main checkout.
|
|
982
993
|
|
|
983
994
|
The automatic preservation commit uses `--no-verify` and `--no-gpg-sign`, so local pre-commit hooks and interactive signing configuration can't block it. The commit is local-only and never pushed; pre-push and server-side hooks still apply. Other Git failures keep the worktree intact and report its recovery path instead of deleting the only copy.
|
|
@@ -1070,6 +1081,7 @@ src/
|
|
|
1070
1081
|
completion-outbox.ts # Deliver completion notifications at the parent's next boundary, coalesced
|
|
1071
1082
|
group-join.ts # `group` join mode: one notification per turn's batch, with timeout
|
|
1072
1083
|
status-note.ts # Honest status note + salvaged partial output for non-normal outcomes
|
|
1084
|
+
agent-record-entry.ts # The `subagents:record` session entry a finished agent leaves; get_subagent_result's fallback, and what resume reopens an evicted agent from
|
|
1073
1085
|
usage.ts # Token usage shapes, accumulators, session-stats readers
|
|
1074
1086
|
|
|
1075
1087
|
# Invocation surface
|
|
@@ -1107,7 +1119,7 @@ src/
|
|
|
1107
1119
|
agent-widget.ts # Persistent widget: spinners, activity, status icons, theming
|
|
1108
1120
|
fleet-list.ts # FleetView: navigable agent list below the editor
|
|
1109
1121
|
conversation-viewer.ts # Live conversation overlay for viewing agent sessions
|
|
1110
|
-
viewer-keys.ts # Viewer scroll keys resolved through user keybindings
|
|
1122
|
+
viewer-keys.ts # Viewer scroll and expand keys, resolved through user keybindings
|
|
1111
1123
|
agent-mention.ts # `@` roster (running, resumable, and startable agents) + popup rows
|
|
1112
1124
|
schedule-menu.ts # /agents → Scheduled jobs submenu
|
|
1113
1125
|
select-item.ts # Collision-safe ctx.ui.select wrapper (numbered rows)
|
|
@@ -130,7 +130,7 @@ Fire-and-forget is the intended use: the reply carries nothing to act on, and th
|
|
|
130
130
|
|
|
131
131
|
Consumption is not terminal. An `@handle` steer un-consumes the record (the mention handler, `src/index.ts`) because the agent's reply to that message still needs relaying. A background resume (`AgentManager.resume`) does too, because the record is starting a new run, and so does handing a foreground agent to the background (`AgentManager.sendToBackground`), because its result now has to reach the parent as a notification.
|
|
132
132
|
|
|
133
|
-
One related thing that lives nowhere else: on every top-level settle, pi-subagents writes a session entry — not an event — via `pi.appendEntry("subagents:record", …)` (the manager's completion callback, `src/index.ts`), carrying `id`, `type`, `description`, `status`, `result`, `error`, `startedAt` and `completedAt
|
|
133
|
+
One related thing that lives nowhere else: on every top-level settle, pi-subagents writes a session entry — not an event — via `pi.appendEntry("subagents:record", …)` (the manager's completion callback, `src/index.ts`, and the Agent tool's foreground `resume` branch, which settles inline without that callback; the shape is `AgentRecordEntryData` in `src/agent-record-entry.ts`), carrying `id`, `type`, `description`, `status`, `result`, `error`, `startedAt` and `completedAt`, plus `sessionFile`, `handle` and `alias` when the agent has them, and `worktreeLost: true` when its work lived in a worktree that has since been removed. `get_subagent_result` answers from it once the live record is gone, by id or by the entry's handle or alias. `Agent({ resume })` reopens the agent's session from its id, and the entry also serves cross-extension history reconstruction. It is append-only history, not something to react to.
|
|
134
134
|
|
|
135
135
|
## Steering a running agent
|
|
136
136
|
|
|
@@ -279,6 +279,8 @@ Any other key is rejected **by name** at the call. Note that this checks option
|
|
|
279
279
|
|
|
280
280
|
Combination rules: `resume` cannot be combined with `agentType`, `model`, `effort`, `isolation`, `gate` or `schema` — a resumed child keeps the agent type, model and tree it was started with, and its session predates the `StructuredOutput` tool.
|
|
281
281
|
|
|
282
|
+
A child stays resumable for the whole run. The manager evicts a finished child's record about ten minutes after it settles, and a review or a merge queue easily takes longer; `resume` then reopens the child's saved session under the same id, still owned by the run. That reopen runs under the agent type's current definition, so the model and tree the script chose for the first run are not carried over. It fails, resolving to `null` with the reason on that agent's row in the card and the inspector, when the child's session was never saved (`rememberAgents` off, or `persist_session: false`), its file is gone, or it ran with `isolation: "worktree"` and left changes: that worktree was removed when the child finished, with its changes on a branch, and continuing the work anywhere else would split it. A child whose worktree held no changes reopens in the run's directory, as in Claude Code.
|
|
283
|
+
|
|
282
284
|
### `pipeline()` and `parallel()`
|
|
283
285
|
|
|
284
286
|
```js
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herbertgao/pi-subagents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1-local.1",
|
|
4
4
|
"description": "Claude Code-style autonomous subagents and workflow orchestration for Pi, with HerbertGao-maintained UI extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
},
|
|
70
70
|
"x-upstream": {
|
|
71
71
|
"package": "@tintinweb/pi-subagents",
|
|
72
|
-
"version": "0.
|
|
73
|
-
"reviewedVersion": "0.
|
|
72
|
+
"version": "0.23.1",
|
|
73
|
+
"reviewedVersion": "0.23.1",
|
|
74
74
|
"repository": "https://github.com/tintinweb/pi-subagents",
|
|
75
|
-
"commit": "
|
|
75
|
+
"commit": "9bb6c822bae9f4fe8d33384b715a5e2e96d5df10",
|
|
76
76
|
"trackVersion": true
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -263,13 +263,13 @@ ${input.systemPrompt}
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
|
-
* Rebuild the `tools:` CSV from the
|
|
266
|
+
* Rebuild the `tools:` CSV from the parts the loader split it into.
|
|
267
267
|
*
|
|
268
|
-
* `extSelectors`
|
|
269
|
-
* `tools: read, ext:mcp/github` into `["read"]` and
|
|
270
|
-
* writing only the first half hands the ejected copy a
|
|
271
|
-
* the file it came from. That was invisible while Eject
|
|
272
|
-
* built-in defaults, which carry no selectors; a package agent can.
|
|
268
|
+
* `extSelectors` and `mcpToolPatterns` have to come back with the built-ins:
|
|
269
|
+
* `parseToolsField` splits `tools: read, ext:mcp/github` into `["read"]` and
|
|
270
|
+
* `["ext:mcp/github"]`, so writing only the first half hands the ejected copy a
|
|
271
|
+
* *narrower* toolset than the file it came from. That was invisible while Eject
|
|
272
|
+
* only ever ran on built-in defaults, which carry no selectors; a package agent can.
|
|
273
273
|
*
|
|
274
274
|
* Zero built-ins with selectors present is not `none` — `none` means no tools at
|
|
275
275
|
* all, while `ext:` entries alone mean "extension tools only", which the loader
|
|
@@ -278,8 +278,9 @@ ${input.systemPrompt}
|
|
|
278
278
|
function formatToolsField(
|
|
279
279
|
tools: string[] | undefined,
|
|
280
280
|
extSelectors?: string[],
|
|
281
|
+
mcpToolPatterns?: string[],
|
|
281
282
|
): string {
|
|
282
|
-
const selectors = extSelectors ?? []
|
|
283
|
+
const selectors = [...(extSelectors ?? []), ...(mcpToolPatterns ?? [])]
|
|
283
284
|
if (tools === undefined)
|
|
284
285
|
return selectors.length > 0 ? ["*", ...selectors].join(", ") : "all"
|
|
285
286
|
if (tools.length === 0)
|
|
@@ -297,7 +298,7 @@ export function serializeAgentFile(cfg: AgentConfig): string {
|
|
|
297
298
|
// `all` for both would hand a deliberately tool-less agent the whole toolbox
|
|
298
299
|
// the first time it is ejected.
|
|
299
300
|
fmFields.push(
|
|
300
|
-
`tools: ${formatToolsField(cfg.builtinToolNames, cfg.extSelectors)}`,
|
|
301
|
+
`tools: ${formatToolsField(cfg.builtinToolNames, cfg.extSelectors, cfg.mcpToolPatterns)}`,
|
|
301
302
|
)
|
|
302
303
|
if (cfg.model) fmFields.push(`model: ${cfg.model}`)
|
|
303
304
|
if (cfg.thinking) fmFields.push(`thinking: ${cfg.thinking}`)
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
ExtensionAPI,
|
|
24
24
|
ExtensionContext,
|
|
25
25
|
} from "@earendil-works/pi-coding-agent"
|
|
26
|
+
import { worktreeLost } from "./agent-record-entry.js"
|
|
26
27
|
import { resumeAgent, runAgent, type ToolActivity } from "./agent-runner.js"
|
|
27
28
|
import { getAgentConfig } from "./agent-types.js"
|
|
28
29
|
import { assignHandle, handleBase } from "./mention.js"
|
|
@@ -232,8 +233,13 @@ interface SpawnOptions {
|
|
|
232
233
|
* Internal capability, like `resumeSessionFile`: a forged handle would
|
|
233
234
|
* duplicate a live agent's name and make `resolveMention` ambiguous, so
|
|
234
235
|
* `spawnTopLevel` strips it from anything a caller sends.
|
|
236
|
+
*
|
|
237
|
+
* `id` keeps the evicted agent's id too, so the id the model already holds
|
|
238
|
+
* names the reopened conversation (`Agent({ resume })`, a workflow's
|
|
239
|
+
* `resume`). A name is taken back only while nothing else holds it — see
|
|
240
|
+
* `reclaimable`.
|
|
235
241
|
*/
|
|
236
|
-
reclaim?: { handle
|
|
242
|
+
reclaim?: { id?: string; handle?: string; alias?: string }
|
|
237
243
|
model?: Model<any>
|
|
238
244
|
maxTurns?: number
|
|
239
245
|
isolated?: boolean
|
|
@@ -575,7 +581,18 @@ export class AgentManager {
|
|
|
575
581
|
// can fix and retry; the RPC layer converts throws into error envelopes.
|
|
576
582
|
assertValidSpawnCwd(options.cwd)
|
|
577
583
|
|
|
578
|
-
|
|
584
|
+
// A reclaimed id must not be live: the record would replace the one in the
|
|
585
|
+
// map, orphaning its run beyond the reach of stop and `abortAll()`.
|
|
586
|
+
// Callers reopen only what they found evicted; this keeps that true.
|
|
587
|
+
if (
|
|
588
|
+
options.reclaim?.id !== undefined &&
|
|
589
|
+
this.agents.has(options.reclaim.id)
|
|
590
|
+
) {
|
|
591
|
+
throw new Error(
|
|
592
|
+
`Agent ${options.reclaim.id} is still in memory, so it cannot be reopened from its saved session.`,
|
|
593
|
+
)
|
|
594
|
+
}
|
|
595
|
+
const id = options.reclaim?.id ?? randomUUID().slice(0, 17)
|
|
579
596
|
const abortController = new AbortController()
|
|
580
597
|
const record: AgentRecord = {
|
|
581
598
|
id,
|
|
@@ -585,15 +602,18 @@ export class AgentManager {
|
|
|
585
602
|
// not consume a name a top-level sibling could otherwise take.
|
|
586
603
|
handle: !isTopLevelAgent(options)
|
|
587
604
|
? undefined
|
|
588
|
-
: // A reclaimed handle is
|
|
589
|
-
// spawn is reopening, and re-deriving it would
|
|
590
|
-
|
|
605
|
+
: // A reclaimed handle is taken back as-is while it is free: it belongs to
|
|
606
|
+
// the conversation this spawn is reopening, and re-deriving it would
|
|
607
|
+
// lose the numbering.
|
|
608
|
+
(this.reclaimable(options.reclaim?.handle, options.reclaim?.id) ??
|
|
591
609
|
assignHandle(handleBase(type), this.takenHandles())),
|
|
592
610
|
description: options.description,
|
|
593
611
|
// Reclaimed here, or filled in below from `name` — in which case it must
|
|
594
612
|
// see the handle this record just took, since both come out of the same
|
|
595
613
|
// namespace.
|
|
596
|
-
alias: isTopLevelAgent(options)
|
|
614
|
+
alias: isTopLevelAgent(options)
|
|
615
|
+
? this.reclaimable(options.reclaim?.alias, options.reclaim?.id)
|
|
616
|
+
: undefined,
|
|
597
617
|
// Overwritten below when the spawn is actually queued; a foreground spawn
|
|
598
618
|
// that queues flips to "queued" there rather than being guessed at here,
|
|
599
619
|
// since the pool decision needs the finished record.
|
|
@@ -619,6 +639,12 @@ export class AgentManager {
|
|
|
619
639
|
workflowId: options.workflowId,
|
|
620
640
|
maxSubagentDepth: options.maxSubagentDepth,
|
|
621
641
|
rootSessionId: options.rootSessionId,
|
|
642
|
+
// A reopen continues this file until its session says otherwise (a fork
|
|
643
|
+
// gets its own, set at session creation). Seeded so a run that fails
|
|
644
|
+
// before it has a session still names the conversation in its saved
|
|
645
|
+
// record and tombstone: without it, the next resume would be refused as
|
|
646
|
+
// never saved.
|
|
647
|
+
sessionFile: options.resumeSessionFile,
|
|
622
648
|
}
|
|
623
649
|
this.agents.set(id, record)
|
|
624
650
|
// After the insert, so `takenHandles()` already counts this record's own
|
|
@@ -830,10 +856,15 @@ export class AgentManager {
|
|
|
830
856
|
// mentions pass none, and RPC forwards only its caller's value. Workflow
|
|
831
857
|
// children are the exception, as in Claude Code, whose workflow agent()
|
|
832
858
|
// reads only the script's option and ignores the definition's.
|
|
859
|
+
// A reopen never gets a worktree, as in Claude Code: a fresh copy of HEAD
|
|
860
|
+
// would not hold the earlier run's edits, and a reopen whose old worktree
|
|
861
|
+
// held any is refused before it gets here (`reopenTarget`).
|
|
833
862
|
const isolation =
|
|
834
|
-
options.
|
|
835
|
-
?
|
|
836
|
-
:
|
|
863
|
+
options.resumeSessionFile !== undefined
|
|
864
|
+
? undefined
|
|
865
|
+
: options.workflowId !== undefined
|
|
866
|
+
? options.isolation
|
|
867
|
+
: (getAgentConfig(type)?.isolation ?? options.isolation)
|
|
837
868
|
let worktreeCwd: string | undefined
|
|
838
869
|
if (isolation === "worktree" && isWorktreeIsolationEnabled()) {
|
|
839
870
|
const wt = await createWorktree(pi, baseCwd, id)
|
|
@@ -1626,6 +1657,35 @@ export class AgentManager {
|
|
|
1626
1657
|
return taken
|
|
1627
1658
|
}
|
|
1628
1659
|
|
|
1660
|
+
/**
|
|
1661
|
+
* `name`, if a reopened agent can take it back. Within one activation that is
|
|
1662
|
+
* always so — tombstoned names are never allocated (`takenHandles`) — but a
|
|
1663
|
+
* resume after a reload reopens from the session's saved record, with no
|
|
1664
|
+
* tombstone holding the name, so a fresh agent may have taken it since. A
|
|
1665
|
+
* name held by a live record, or by another agent's tombstone, stays with
|
|
1666
|
+
* its holder and the reopened agent gets a fresh one.
|
|
1667
|
+
*
|
|
1668
|
+
* `id` is the agent being reopened, when it keeps its own: its tombstone is
|
|
1669
|
+
* the one holding the name, legitimately. The `@handle` path keeps no id and
|
|
1670
|
+
* reopens exactly the tombstone that holds the name, so it skips that check.
|
|
1671
|
+
*/
|
|
1672
|
+
private reclaimable(
|
|
1673
|
+
name: string | undefined,
|
|
1674
|
+
id: string | undefined,
|
|
1675
|
+
): string | undefined {
|
|
1676
|
+
if (name === undefined) return undefined
|
|
1677
|
+
for (const record of this.agents.values()) {
|
|
1678
|
+
if (record.handle === name || record.alias === name) return undefined
|
|
1679
|
+
}
|
|
1680
|
+
if (id !== undefined) {
|
|
1681
|
+
for (const entry of this.tombstones.values()) {
|
|
1682
|
+
if (entry.id !== id && (entry.handle === name || entry.alias === name))
|
|
1683
|
+
return undefined
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return name
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1629
1689
|
/**
|
|
1630
1690
|
* Resolve an `@name` from the prompt. Matches a top-level agent's handle
|
|
1631
1691
|
* case-insensitively, preferring one that can still be steered and otherwise
|
|
@@ -1744,6 +1804,7 @@ export class AgentManager {
|
|
|
1744
1804
|
description: record.description,
|
|
1745
1805
|
sessionFile: record.sessionFile,
|
|
1746
1806
|
completedAt: record.completedAt ?? Date.now(),
|
|
1807
|
+
worktreeLost: worktreeLost(record) || undefined,
|
|
1747
1808
|
})
|
|
1748
1809
|
// Bound the memory a long session can accumulate. Oldest first, since the
|
|
1749
1810
|
// agent someone still wants to reach is the one they used most recently.
|