pi-subagent-manager 0.7.0 → 0.9.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/README.md +54 -294
- package/agents/architect.md +1 -1
- package/agents/coder.md +1 -1
- package/agents/researcher.md +1 -1
- package/docs/custom-agents.md +84 -0
- package/docs/default-agents.md +2 -2
- package/docs/development.md +72 -0
- package/docs/importing-agents.md +41 -0
- package/docs/research-model-roles-writing.md +2 -2
- package/docs/research-researcher-workflow.md +4 -2
- package/docs/settings.md +107 -0
- package/docs/threads.md +73 -0
- package/docs/tools-and-ui.md +96 -0
- package/package.json +1 -1
- package/src/index.ts +60 -5
- package/src/orch/inherited-tools.ts +84 -0
- package/src/orch/manager.ts +96 -0
- package/src/orch/runtime.ts +52 -3
- package/src/orch/transcript.ts +186 -0
- package/src/types.ts +30 -0
- package/src/ui/agent-navigation-editor.ts +198 -0
- package/src/ui/dialog.ts +14 -13
- package/src/ui/live-agent-view.ts +361 -0
- package/src/ui/status-ui.ts +279 -46
- package/src/ui/ui.ts +13 -7
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Importing agents
|
|
2
|
+
|
|
3
|
+
Already have agents for another pi subagent package? Import them.
|
|
4
|
+
|
|
5
|
+
## How
|
|
6
|
+
|
|
7
|
+
- **First run:** in an interactive TUI session, you're offered an import once. (Not in `off` or `orchestration` mode.)
|
|
8
|
+
- **Any time:** `/agents import`.
|
|
9
|
+
|
|
10
|
+
The checkbox picker starts with nothing selected.
|
|
11
|
+
|
|
12
|
+
| Key | Action |
|
|
13
|
+
| ------ | --------------------- |
|
|
14
|
+
| ↑↓ | Navigate |
|
|
15
|
+
| Space | Toggle row |
|
|
16
|
+
| Ctrl+A | Toggle all |
|
|
17
|
+
| Enter | Submit (empty = skip) |
|
|
18
|
+
| Esc | Cancel |
|
|
19
|
+
|
|
20
|
+
## What happens
|
|
21
|
+
|
|
22
|
+
Your **current main model** does the conversion, in your current conversation. There's no converter code and no separate agent.
|
|
23
|
+
|
|
24
|
+
- It receives only the selected file paths, relevant source settings paths, the target schema, your scoped models and tools, and migration instructions.
|
|
25
|
+
- It must explain and get your approval for anything lossy: unsupported features, dropped security restrictions, unavailable models, name collisions.
|
|
26
|
+
- Originals are never modified.
|
|
27
|
+
- New definitions load after the turn, or with `/agents reload`.
|
|
28
|
+
|
|
29
|
+
Requires `opportunistic` mode (it uses the main thread's file tools). TUI only — RPC/print/JSON sessions never prompt.
|
|
30
|
+
|
|
31
|
+
## Where it looks
|
|
32
|
+
|
|
33
|
+
Supported sources: [`@tintinweb/pi-subagents` 0.19.0](https://github.com/tintinweb/pi-subagents/blob/e955e29c51b7a6cce37e1108cd2d6c57a77e151c/src/custom-agents.ts) and [npm `pi-subagents` 0.74.0](https://github.com/nicobailon/pi-subagents/blob/b6bda32f03b7f549623bc404c9be14dca298ddc4/src/agents/agents.ts).
|
|
34
|
+
|
|
35
|
+
- **User:** `<pi-agent-dir>/agents`; recursive `~/.agents` (npm).
|
|
36
|
+
- **Project (trusted only):** `.pi/agents`, `.agents/agents` (tintinweb), recursive `.agents` (npm), including npm's nearest configured ancestor.
|
|
37
|
+
- **Extra:** npm's `PI_SUBAGENT_EXTRA_AGENT_DIRS` and `settings.json` → `subagents.agentScanDirs` / `agentExcludeDirs`.
|
|
38
|
+
|
|
39
|
+
Skipped: `skills`/`.skills` trees, any `SKILL.md`, symlinks, `.chain.md` workflows, installed-package builtins. npm's git-root anchoring isn't reproduced.
|
|
40
|
+
|
|
41
|
+
The offer is remembered in `<pi-agent-dir>/subagent-manager/.import-offered`.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Requested cutoff: **2026-10-03**; freshest dated Arena snapshot discovered: **2026-10-02**. The confirmed five defaults are **architect (absorbs research), reviewer (GPT-only), coder, tasker, writer**. Recommend keeping writing separate from evidence gathering. All names below are advisory `modelSuggestions`, not runtime pins or configuration edits.
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**Historical tool disclosure (research session, before parent-tool bridging):** the parent confirmed Exa MCP search/fetch tools were accessible through its codemode. That child session did **not** expose codemode or those MCP tools and did not inherit parent tools. This research used `web_search` with `provider: "exa"` for Exa-based discovery and `fetch_content` for selected pages, not Exa MCP fetch. Context7 and code-search tools are unavailable here. Read the requested web-research skill. Only this document was written; no source/config edits or git operations were performed.
|
|
8
8
|
|
|
9
9
|
## Advisory modelSuggestions: confirmed five roles
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@ This table records exploratory candidates from the writing/research sweep, not t
|
|
|
22
22
|
|
|
23
23
|
### Research-tool contract for architect
|
|
24
24
|
|
|
25
|
-
The
|
|
25
|
+
The default architect allowlist does not grant MCP retrieval tools. With parent-tool bridging, a custom allowlist or broader Tool Filtering mode can expose registered non-hidden parent tools, with deferred/codemode discovery through child-local codemode. External tools reuse main-session resources/context, not isolated extension instances. When authorized retrieval is unavailable, architect must consume a **supplied research packet** or use **authorized shell retrieval**, including an Exa CLI/API only if it is actually installed/configured and authorized. Do not hardcode unavailable Exa MCP tool names into child instructions, promise nonexistent tool access, or embed credentials. If retrieval is unavailable, explicitly state that limitation and ask for parent-supplied sources. Parent-side codemode Exa access can produce the packet: URLs, dates, fetched passages, contradictions, and unresolved questions. Model ability and retrieval availability are separate decisions.
|
|
26
26
|
|
|
27
27
|
### Five versus six responsibilities
|
|
28
28
|
|
|
@@ -12,14 +12,16 @@ Use a reasoning-capable, tool-reliable model with good code reading, multi-hop r
|
|
|
12
12
|
|
|
13
13
|
## Runtime capability gate — implementation evidence
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Historical evidence at inspected revision `af8424dc621fa38f61058e2e0afa19ab449d084b` (before parent-tool bridging):
|
|
16
16
|
|
|
17
17
|
- [`src/runtime.ts:299-303`](../src/runtime.ts) selects from built-ins and `options.tools`; [`src/index.ts:230`](../src/index.ts) supplies only subagent-manager tools through `toolsFor`.
|
|
18
18
|
- [`src/runtime.ts:311-319`](../src/runtime.ts) sets `noExtensions`, `noSkills`, `noPromptTemplates`, `noContextFiles`, and `noThemes` to true. The parent’s Context7/Exa/Parallel/Perplexity MCP or web extensions are **not inherited**.
|
|
19
19
|
- [`src/runtime.ts:339-343`](../src/runtime.ts) blocks unallowed tool calls; [`src/runtime.ts:350-362`](../src/runtime.ts) passes only selected tools to the SDK session.
|
|
20
20
|
- [`src/config.ts:257-269`](../src/config.ts) validates exact tool names and throws for unavailable names. Adding imagined MCP names to the frontmatter will not enable them and can break spawning.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Current parent-tool bridging includes registered non-hidden main-session tools in the child inventory, subject to exact-name Tool Filtering policies. Permitted MCP/web tools can therefore be selected by a custom allowlist or broader mode; deferred/codemode tools use child-local codemode discovery. External execution reuses main-session resources/context rather than loading fresh extensions or MCP connections, and the parent's policy still applies to bridged callable tools. Skills and project context files are not automatically loaded.
|
|
23
|
+
|
|
24
|
+
The shipped prompt must still not assume MCP tools, `web_enable`, or provider-discovery tools are available under its default local-tool allowlist. Use actually available authorized retrieval, configured shell routes, or a parent-supplied packet containing URLs, dates, versions and fetched passages. If none can answer the assignment, pause with the missing capability instead of pretending model memory is live evidence.
|
|
23
25
|
|
|
24
26
|
The local `web-research` skill recommends complementary search angles, discovery followed by full-page reading, Context7 for library questions, and explicit dates and uncertainty. The local `github` skill prefers `gh` and warns that API writes bypass the local checkout. Those are useful workflow ideas, but their statements that servers/credentials are installed are session-specific and must **not** be copied as assumptions into a portable bundled definition. Neither skill is automatically loaded into this child.
|
|
25
27
|
|
package/docs/settings.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Settings
|
|
2
|
+
|
|
3
|
+
Open with `/agents` (or `/agents settings`). Save with **Ctrl+S**. Changes apply immediately and never cancel running work.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
| Scope | Path |
|
|
8
|
+
| ------- | ------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| Global | `<pi-agent-dir>/subagent-manager/settings.json` (normally `~/.pi/agent/subagent-manager/settings.json`) |
|
|
10
|
+
| Project | `<cwd>/.pi/agent/subagent-manager/settings.json` — trusted projects only; overrides global |
|
|
11
|
+
|
|
12
|
+
All keys are optional. Defaults:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"subagentMode": "opportunistic",
|
|
17
|
+
"modelSelection": "pick-first-scoped",
|
|
18
|
+
"toolFiltering": "allowed",
|
|
19
|
+
"maxLevels": 3,
|
|
20
|
+
"maxConcurrent": 16,
|
|
21
|
+
"maxThreads": 64
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Unknown keys, bad values and symlinked paths produce warnings. An invalid file is ignored as a whole; the previous layer (or defaults) stays in effect.
|
|
26
|
+
|
|
27
|
+
Other packages' settings (e.g. `.pi/subagents.json`) are never read here.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Subagent Mode (`subagentMode`)
|
|
32
|
+
|
|
33
|
+
How much the main model is encouraged to delegate.
|
|
34
|
+
|
|
35
|
+
| Option | What it does | Use when |
|
|
36
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
37
|
+
| `off` | Hides subagent tools; injects no guidance. Widget, notifications and import offer are hidden. `/agents` still works. | You want plain pi for a while, without uninstalling. |
|
|
38
|
+
| `opportunistic` (default) | Tools on. Main model delegates only parallelizable or very large tasks; otherwise works directly. | Everyday use. |
|
|
39
|
+
| `orchestration` | Tools on. `/root` delegates **all** execution and only coordinates and synthesizes. | Big multi-part tasks where you want the main context kept clean. |
|
|
40
|
+
|
|
41
|
+
- Orchestration is a prompt policy, not a tool restriction. Workers don't inherit the root-only rule.
|
|
42
|
+
- Agent import needs `opportunistic` (it uses the main thread's file tools).
|
|
43
|
+
|
|
44
|
+
## Model Picking (`modelSelection`)
|
|
45
|
+
|
|
46
|
+
Which model an agent gets when its session starts.
|
|
47
|
+
|
|
48
|
+
| Option | What it does | Use when |
|
|
49
|
+
| ------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
|
50
|
+
| `pick-first-available` — **Pick First (available)** | First entry in the type's `models` with configured credentials. | You trust your per-agent lists and want them honored regardless of `/scoped-models`. |
|
|
51
|
+
| `pick-first-scoped` — **Pick First (scoped)** (default) | Same, but the model must also be in the main session's `/scoped-models`. | You use `/scoped-models` as an allowlist (cost, compliance) and want agents to respect it. |
|
|
52
|
+
| `use-current` — **Use Current** | Ignores `models`; uses the main session's current model. | One model for everything, or quick testing. |
|
|
53
|
+
|
|
54
|
+
- Types with no `models` inherit the parent's model in both Pick First modes.
|
|
55
|
+
- Your list's order decides, not the scoped list's order.
|
|
56
|
+
- No match → spawn fails clearly. An empty `/scoped-models` matches nothing.
|
|
57
|
+
- `use-current` always uses the **main** session's model, even for nested or reopened agents. Thinking levels stay per-agent.
|
|
58
|
+
- `modelSuggestions` never affects this.
|
|
59
|
+
- Switching modes doesn't change already-open sessions.
|
|
60
|
+
- Legacy `scopedModelFiltering: true` → `pick-first-scoped`; `false` → `pick-first-available`.
|
|
61
|
+
|
|
62
|
+
## Tool Filtering (`toolFiltering`)
|
|
63
|
+
|
|
64
|
+
How the type's `tools.allow` / `tools.block` lists are applied.
|
|
65
|
+
|
|
66
|
+
| Option | What it does | Use when |
|
|
67
|
+
| -------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------ |
|
|
68
|
+
| `allowed` — **Allowed (except blocked)** (default) | Only `allow` tools, minus `block`. Empty/missing `allow` = no tools. | Least privilege. Recommended. |
|
|
69
|
+
| `all-except-blocked` — **All except blocked** | Ignores `allow`; everything except `block`. | Your definitions only list what to forbid. |
|
|
70
|
+
| `all` — **All** | Ignores both lists. | Trusted local experiments. |
|
|
71
|
+
|
|
72
|
+
- "All" includes child-local built-in and manager tools plus the main session's registered non-hidden tools. Exact-name allow/block lists apply to this inventory.
|
|
73
|
+
- Inherited tools retain exposure and active status. Deferred/codemode tools are discoverable through child-local codemode when permitted; direct tools remain model-facing when active.
|
|
74
|
+
- Built-in tools, manager controls, codemode and tool search remain child-local. External calls reuse main-session resources/context rather than loading fresh extensions or MCP connections. Bridged callable tools remain subject to the main session's tool policy; session-mutating external tools are not necessarily isolated to the child. Skills and project context files are not automatically loaded.
|
|
75
|
+
- Other custom **model-only** tools fail closed: the SDK cannot bridge them while preserving root permission/result hooks. Run those in the main session.
|
|
76
|
+
- UI/command-driven resumes after reopening the main session need a main-session `agent_*` tool call to establish the execution bridge; use `agent_steer` rather than the thread dialog.
|
|
77
|
+
- Applies to newly started sessions (including retained ones reopened after reload). Already-open sessions keep their selected tools, and the main session's tool set is unchanged.
|
|
78
|
+
- Non-default modes can expose `agent_spawn` to types that weren't meant to delegate.
|
|
79
|
+
|
|
80
|
+
## Max Levels (`maxLevels`)
|
|
81
|
+
|
|
82
|
+
Maximum tree depth, counting the main conversation as level 1. Integer 1–32. Default `3` = children and grandchildren.
|
|
83
|
+
|
|
84
|
+
| Value | Effect | Use when |
|
|
85
|
+
| ------------- | ------------------------ | ---------------------------------------------------- |
|
|
86
|
+
| `1` | No new subagents | Block spawning while still resuming existing threads |
|
|
87
|
+
| `2` | Children only | Flat fan-out; simplest to follow |
|
|
88
|
+
| `3` (default) | Children + grandchildren | An `architect` coordinating workers |
|
|
89
|
+
| `4+` | Deeper trees | Large hierarchical teams |
|
|
90
|
+
|
|
91
|
+
Independent roots like `/k` count as level 2, so they can't bypass the limit. Lowering it still lets you resume existing deeper threads.
|
|
92
|
+
|
|
93
|
+
## Max Concurrent (`maxConcurrent`)
|
|
94
|
+
|
|
95
|
+
Threads starting or running at once, across the whole tree. Parents waiting on children count. Default `16`.
|
|
96
|
+
|
|
97
|
+
Lower it for rate limits or cost. Raise it for wide fan-out. When full, spawns **fail** — they don't queue.
|
|
98
|
+
|
|
99
|
+
## Max Threads (`maxThreads`)
|
|
100
|
+
|
|
101
|
+
Total retained threads (any state) per main session. Default `64`.
|
|
102
|
+
|
|
103
|
+
Lower it to keep the tree tidy. Raise it for long sessions with many agents. When full, spawns fail.
|
|
104
|
+
|
|
105
|
+
## Scope
|
|
106
|
+
|
|
107
|
+
The dialog's scope field picks where to save: **global** or **trusted project**.
|
package/docs/threads.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Threads and lifecycle
|
|
2
|
+
|
|
3
|
+
## Paths
|
|
4
|
+
|
|
5
|
+
`/root` is the main pi conversation. Every subagent gets a path under a root.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
/root
|
|
9
|
+
/root/coding-researcher
|
|
10
|
+
/root/change-file-names
|
|
11
|
+
/root/change-file-names/review
|
|
12
|
+
/k # independent root: no /root history
|
|
13
|
+
/k/l # inherits /k, never /root/...
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Relative names resolve under the calling agent.
|
|
17
|
+
- A nested parent must already exist.
|
|
18
|
+
- `/root` can address every tree. Children can spawn immediate children and address only their descendants.
|
|
19
|
+
- Dot segments, URL escapes and ambiguous slash spellings are rejected.
|
|
20
|
+
- Name paths after the **task** (`fix-auth`), not the type.
|
|
21
|
+
|
|
22
|
+
## Context
|
|
23
|
+
|
|
24
|
+
A child starts from a snapshot of its **lexical parent** (the path one level up).
|
|
25
|
+
|
|
26
|
+
- **Included:** conversation messages, custom messages, shell output.
|
|
27
|
+
- **Excluded:** the parent's system prompt, unmatched tool calls/results.
|
|
28
|
+
- **Frozen:** later parent turns don't change the child's context.
|
|
29
|
+
- **Model/thinking:** inherited from the parent unless the type sets them.
|
|
30
|
+
- **Independent roots** (`/k`) use the main session's model defaults but **none of its history**.
|
|
31
|
+
|
|
32
|
+
## States
|
|
33
|
+
|
|
34
|
+
| Child action | State | Parent receives |
|
|
35
|
+
| ---------------------- | ----------- | ---------------------------- |
|
|
36
|
+
| Returns a final answer | `completed` | The final answer only |
|
|
37
|
+
| Calls `agent_pause` | `paused` | Status and reason, no answer |
|
|
38
|
+
| Is stopped | `stopped` | — |
|
|
39
|
+
| Errors | `failed` | The error |
|
|
40
|
+
|
|
41
|
+
Every state keeps the session. Any of them can be resumed with `agent_steer`.
|
|
42
|
+
|
|
43
|
+
- `agent_update` reports progress without ending the task.
|
|
44
|
+
- Pause takes effect at the turn boundary. Call it alone, not alongside other tools.
|
|
45
|
+
- `agent_stop` cancels a thread and its working descendants. Resume a stopped ancestor before its descendants.
|
|
46
|
+
- Wait timeouts don't kill children.
|
|
47
|
+
- Progress and completion notices don't force a parent turn; the parent sees them on its next turn.
|
|
48
|
+
|
|
49
|
+
## Persistence
|
|
50
|
+
|
|
51
|
+
**Transcripts.** Each child is a normal pi JSONL session in the main session directory (normally `<pi-agent-dir>/sessions/<encoded-cwd>/`), named like `worker /root/task`, with a `parentSession` link.
|
|
52
|
+
|
|
53
|
+
- In `pi --resume` / `/resume` with **Threaded** sorting and empty search, children nest under parents.
|
|
54
|
+
- Recent/Fuzzy sorting and search show flat rows. Named-only filtering can hide an unnamed parent.
|
|
55
|
+
|
|
56
|
+
**Registry.** The parent saves its thread tree, pending steering and progress mailboxes in its own session.
|
|
57
|
+
|
|
58
|
+
- `/reload` or reopening the parent restores retained threads.
|
|
59
|
+
- Interrupted work comes back **paused**, never auto-restarted.
|
|
60
|
+
- Older transcripts under `<pi-agent-dir>/subagents/<parent-session-id>/` still reopen through the registry.
|
|
61
|
+
|
|
62
|
+
**Resuming.**
|
|
63
|
+
|
|
64
|
+
- Resume the **main session** to keep the managed tree and tool policies.
|
|
65
|
+
- Opening a child directly gives a normal, unmanaged session. Don't do this while the parent is running it.
|
|
66
|
+
- `pi --continue` may pick a recently active child. Use `pi --resume` to choose the main session.
|
|
67
|
+
|
|
68
|
+
**Branching.**
|
|
69
|
+
|
|
70
|
+
- A forked main session gets a fresh registry, so two parents never write the same child transcript.
|
|
71
|
+
- Tree navigation in the parent restores that branch's registry and each child's transcript leaf.
|
|
72
|
+
- Resuming from an older checkpoint branches the child file; newer branches stay intact.
|
|
73
|
+
- In-memory main sessions don't survive process exit.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Tools and UI
|
|
2
|
+
|
|
3
|
+
## Model-facing tools
|
|
4
|
+
|
|
5
|
+
| Tool | Purpose |
|
|
6
|
+
| -------------- | ---------------------------------------------------- |
|
|
7
|
+
| `agent_types` | List types and what they're for |
|
|
8
|
+
| `agent_spawn` | Start `{path, type, task, wait?}`. Waits by default. |
|
|
9
|
+
| `agent_wait` | Wait for settlement; optional `timeoutMs` |
|
|
10
|
+
| `agent_steer` | Send `{path, message}`; queues input or resumes |
|
|
11
|
+
| `agent_status` | Inspect one path or list visible threads |
|
|
12
|
+
| `agent_update` | Child: report progress |
|
|
13
|
+
| `agent_pause` | Child: pause without an answer |
|
|
14
|
+
| `agent_stop` | Cancel a descendant and its subtree |
|
|
15
|
+
| `agent_output` | Page through long final answers by character offset |
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"path": "controller-security-research",
|
|
20
|
+
"type": "architect",
|
|
21
|
+
"task": "Investigate controller security and plan the change",
|
|
22
|
+
"wait": false
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then `agent_wait` or `agent_status` on `/root/controller-security-research`.
|
|
27
|
+
|
|
28
|
+
## Parallel and nested work
|
|
29
|
+
|
|
30
|
+
- Launch **all independent siblings with `wait: false`, then wait**. Spawning one foreground child and waiting before the next is sequential.
|
|
31
|
+
- Nesting works the same way: `/root` launches `team-a` and `team-b`; each launches its own workers.
|
|
32
|
+
- Only `architect` delegates among bundled types. A custom coordinator needs `agent_spawn` and `agent_wait` in `tools.allow`.
|
|
33
|
+
- Limits are shared across the tree — see [settings](settings.md#max-levels-maxlevels).
|
|
34
|
+
|
|
35
|
+
## Commands
|
|
36
|
+
|
|
37
|
+
| Command | Does |
|
|
38
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
39
|
+
| `/agents`, `/agents settings` | [Settings](settings.md) dialog. **Agent definitions** jumps to the type editor. |
|
|
40
|
+
| `/agents types` | Type browser and editor — see [custom agents](custom-agents.md#editing-in-the-tui) |
|
|
41
|
+
| `/agents tree [path]` | Live full tree; optional path preselects. `/agents status` is an alias. |
|
|
42
|
+
| `/agents import` | [Import picker](importing-agents.md) |
|
|
43
|
+
| `/agents reload` | Reload definitions and settings; show diagnostics |
|
|
44
|
+
|
|
45
|
+
### `/agents tree` keys
|
|
46
|
+
|
|
47
|
+
| Key | Action |
|
|
48
|
+
| ----------- | ----------------- |
|
|
49
|
+
| ↑↓ | Select |
|
|
50
|
+
| ←→ | Collapse / expand |
|
|
51
|
+
| PgUp / PgDn | Scroll |
|
|
52
|
+
| Enter | Watch thread; Main returns to the editor |
|
|
53
|
+
| i | Existing actions: steer, stop, output, transcript |
|
|
54
|
+
| Esc | Watcher → saved tree → Main |
|
|
55
|
+
| Ctrl+Q | Return directly to Main |
|
|
56
|
+
|
|
57
|
+
Refreshes every second and keeps your selection, collapse state and scroll position.
|
|
58
|
+
|
|
59
|
+
### Live agent navigation (read-only)
|
|
60
|
+
|
|
61
|
+
The fullscreen watcher shows steer and agent messages in full, including the in-progress assistant reply. Tool calls, results, and other metadata show their name/status and only the first three wrapped lines of each arguments/output preview, followed by `...` when more is hidden. Use **i → Transcript** from the tree for retained tool details. Thinking is initially hidden (**t** toggles it). It never sends a prompt, switches sessions, or changes model/tool/resource ownership. Inherited context is initially collapsed (**c** toggles it). Unsupported/custom content and images use safe text placeholders rather than native rich rendering. Legacy sessions without reliable inherited-prefix metadata show their whole transcript.
|
|
62
|
+
|
|
63
|
+
- **Up/Down, PageUp/PageDown, Home** scroll and pause following.
|
|
64
|
+
- **End** or **l** resumes following the live tail. Scroll/follow state is remembered per agent.
|
|
65
|
+
- **r** retries an unavailable observation without starting a turn. Starting threads are watchable; stopped/completed threads remain readable.
|
|
66
|
+
- Frames are sanitized, viewport-bounded and coalesced during bursts. Exit, root replacement and shutdown release observers/timers. Streaming deltas never enter persisted thread events.
|
|
67
|
+
|
|
68
|
+
#### Experimental exhausted-Down entry
|
|
69
|
+
|
|
70
|
+
Set `PI_SUBAGENT_NAVIGATION_EDITOR=1` before starting Pi to open the tree when focused physical **Down** has exhausted native history/cursor movement at the end of the draft. Native editing runs first; autocomplete, jumps, paste, configured shortcuts, duplicate history entries and changed drafts do not count as exhausted boundaries. Navigating preserves the main draft/cursor and does not require the root to be idle.
|
|
71
|
+
|
|
72
|
+
The editor adapter is **opt-in** pending the full real-terminal acceptance matrix. Unset the variable or use `PI_SUBAGENT_NAVIGATION_EDITOR=0` to leave the editor slot untouched; command entry still works. Pi has one custom-editor slot: installation is skipped if another factory owns it or an existing draft is nonempty, since the host cannot transfer cursor/undo/expanded-paste state. Load order can still let a later editor replace ours. Initial startup uses Pi's history hydration; replacement installations seed history once. Session-tree rebuilds keep the existing editor instance.
|
|
73
|
+
|
|
74
|
+
While navigation is open, the host fullscreen search shortcut is temporarily disabled through public keybindings to avoid stacking a second host overlay. The prior binding owner is restored only if no other extension replaced it. **Known host limitation:** if an unrelated extension stacks another overlay above navigation, Pi's custom-UI completion can close the newer overlay instead. Avoid concurrent extension-owned overlays; a host identity-targeted completion API is needed to remove this limitation. No private host access or unsupported overlay-lifecycle workaround is used.
|
|
75
|
+
|
|
76
|
+
Run `python3 scripts/live-agent-navigation-smoke.py` after `npm install` for credential-free, offline POSIX PTY checks in regular/fullscreen mode (entry, root return, draft restoration, resize and host-search suppression). No model prompts are submitted. Broader manual acceptance (concurrent live turns, autocomplete/paste/undo interactions, remapped shortcuts and rich custom content) is still required before making the editor gesture default.
|
|
77
|
+
|
|
78
|
+
## Agents widget
|
|
79
|
+
|
|
80
|
+
A compact tree above the input editor, at most twelve lines including two help lines.
|
|
81
|
+
|
|
82
|
+
- Each row: colored type pill, path, state, task, active time, input `↑` / output `↓` tokens.
|
|
83
|
+
- A second, indented line shows latest activity.
|
|
84
|
+
- Active branches are shown first; overflow is counted, not listed.
|
|
85
|
+
- Time freezes while paused and resumes on continue.
|
|
86
|
+
- The footer always shows tree navigation and the default interrupt keys, including when agents overflow.
|
|
87
|
+
|
|
88
|
+
### Interrupts and stopping agents
|
|
89
|
+
|
|
90
|
+
With the main input focused (default keybindings):
|
|
91
|
+
|
|
92
|
+
- **Esc** aborts the main turn (including a pending `agent_wait` or foreground spawn wait), **not the subagents**. Already-started subagents keep running.
|
|
93
|
+
- **Ctrl+C** clears the input; it does not stop the main turn or subagents.
|
|
94
|
+
- **Ctrl+C twice quickly** (within 500 ms) exits Pi. Session shutdown cooperatively stops all agents, retaining their sessions.
|
|
95
|
+
|
|
96
|
+
Inside the tree/watcher, **Esc** returns to the previous view without stopping an agent. To stop one subtree without exiting Pi, open **`/agents tree`**, select an agent, press **i**, and choose **Stop**. This stops that agent and its working descendants; other branches continue. Cancellation is cooperative, not a guarantee of killing external processes.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,8 +7,10 @@ import { IMPORT_REQUEST_PREFIX, markImportOffered, offerAgentImport } from "./pr
|
|
|
7
7
|
import { ThreadManager } from "./orch/manager.ts";
|
|
8
8
|
import { loadManagerSettings } from "./prefs/settings.ts";
|
|
9
9
|
import { configureAgents } from "./ui/settings-ui.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { AgentNavigationController, showAgentStatus } from "./ui/status-ui.ts";
|
|
11
|
+
import { AgentNavigationEditor } from "./ui/agent-navigation-editor.ts";
|
|
11
12
|
import { createDriverFactory } from "./orch/runtime.ts";
|
|
13
|
+
import { createInheritedToolSource } from "./orch/inherited-tools.ts";
|
|
12
14
|
import { subagentPrompt } from "./orch/prompt.ts";
|
|
13
15
|
import { agentTools } from "./orch/tools.ts";
|
|
14
16
|
import { editAgentTypes, updateWidget } from "./ui/ui.ts";
|
|
@@ -24,6 +26,7 @@ type RootNotification = {
|
|
|
24
26
|
|
|
25
27
|
export default function piSubagent(pi: ExtensionAPI): void {
|
|
26
28
|
let context: ExtensionContext | undefined;
|
|
29
|
+
const inheritedTools = createInheritedToolSource(pi);
|
|
27
30
|
let store = new ConfigStore({
|
|
28
31
|
cwd: process.cwd(),
|
|
29
32
|
agentDir: getAgentDir(),
|
|
@@ -45,6 +48,49 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
45
48
|
return loaded.diagnostics;
|
|
46
49
|
};
|
|
47
50
|
let generation = 0;
|
|
51
|
+
let navigation = new AgentNavigationController();
|
|
52
|
+
let navigationEditor: AgentNavigationEditor | undefined;
|
|
53
|
+
let navigationEditorFactory: Parameters<ExtensionContext["ui"]["setEditorComponent"]>[0];
|
|
54
|
+
let navigationGeneration = 0;
|
|
55
|
+
const closeNavigation = (disposeEditor = false) => {
|
|
56
|
+
navigationGeneration++;
|
|
57
|
+
navigation.close();
|
|
58
|
+
if (disposeEditor) {
|
|
59
|
+
navigationEditor?.dispose();
|
|
60
|
+
navigationEditor = undefined;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const installNavigationEditor = (ctx: ExtensionContext, seedHistory: boolean) => {
|
|
64
|
+
// Pi has one custom-editor slot: integrations owning it can opt out explicitly.
|
|
65
|
+
if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setEditorComponent ||
|
|
66
|
+
process.env.PI_SUBAGENT_NAVIGATION_EDITOR !== "1") return;
|
|
67
|
+
const existingFactory = ctx.ui.getEditorComponent?.();
|
|
68
|
+
if (existingFactory && existingFactory !== navigationEditorFactory) return;
|
|
69
|
+
// The host only transfers raw text, not cursor/undo/expanded-paste state.
|
|
70
|
+
if (ctx.ui.getEditorText?.()) return;
|
|
71
|
+
const history = buildSessionContext(ctx.sessionManager.getBranch()).messages.flatMap((message) => {
|
|
72
|
+
if (message.role !== "user") return [];
|
|
73
|
+
const content = message.content;
|
|
74
|
+
return [typeof content === "string" ? content : content
|
|
75
|
+
.filter((block) => block.type === "text").map((block) => block.text).join("")];
|
|
76
|
+
});
|
|
77
|
+
navigationEditorFactory = (tui, theme, keys) => {
|
|
78
|
+
const editor = new AgentNavigationEditor(tui, theme, keys, {
|
|
79
|
+
// Initial startup hydrates after session_start; replacement editors do not.
|
|
80
|
+
initialHistory: seedHistory ? history : undefined,
|
|
81
|
+
generation: () => navigationGeneration,
|
|
82
|
+
canOpen: () => manager !== undefined && context?.mode === "tui" &&
|
|
83
|
+
limits.subagentMode !== "off" && !navigation.isOpen,
|
|
84
|
+
openTree: () => manager && context
|
|
85
|
+
? navigation.open(context, manager.scope("/root")) : undefined,
|
|
86
|
+
onError: (error) => context?.ui.notify(
|
|
87
|
+
error instanceof Error ? error.message : String(error), "error"),
|
|
88
|
+
});
|
|
89
|
+
navigationEditor = editor;
|
|
90
|
+
return editor;
|
|
91
|
+
};
|
|
92
|
+
ctx.ui.setEditorComponent(navigationEditorFactory);
|
|
93
|
+
};
|
|
48
94
|
let persistenceSignature = "";
|
|
49
95
|
let migrationRequested = false;
|
|
50
96
|
let importInProgress = false;
|
|
@@ -181,8 +227,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
181
227
|
...tool,
|
|
182
228
|
// Hidden tools are neither model-visible nor discoverable/callable via codemode.
|
|
183
229
|
exposure: enabled ? "direct" : "hidden",
|
|
230
|
+
prepareLoadout: inheritedTools.captureLoadout,
|
|
184
231
|
execute: (...args) => {
|
|
185
232
|
if (limits.subagentMode === "off") throw new Error("Subagent Mode is off");
|
|
233
|
+
inheritedTools.captureContext(args[4]);
|
|
186
234
|
return tool.execute(...args);
|
|
187
235
|
},
|
|
188
236
|
});
|
|
@@ -209,10 +257,13 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
209
257
|
};
|
|
210
258
|
});
|
|
211
259
|
|
|
212
|
-
const attachSession = async (ctx: ExtensionContext) => {
|
|
260
|
+
const attachSession = async (ctx: ExtensionContext, installEditor = false, seedHistory = true) => {
|
|
213
261
|
const token = ++generation;
|
|
262
|
+
closeNavigation(installEditor);
|
|
263
|
+
navigation = new AgentNavigationController();
|
|
214
264
|
// session_start already belongs to the replacement session: never append the old registry here.
|
|
215
265
|
if (manager) await manager.shutdown();
|
|
266
|
+
inheritedTools.reset();
|
|
216
267
|
context = ctx;
|
|
217
268
|
store = new ConfigStore({
|
|
218
269
|
cwd: ctx.cwd,
|
|
@@ -228,6 +279,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
228
279
|
requireContext,
|
|
229
280
|
() => limits.modelSelection,
|
|
230
281
|
() => limits.toolFiltering,
|
|
282
|
+
() => inheritedTools.snapshot(),
|
|
231
283
|
),
|
|
232
284
|
rootSnapshot: () => buildSessionContext(requireContext().sessionManager.getBranch()).messages,
|
|
233
285
|
getType: (name) => store.get(name),
|
|
@@ -240,6 +292,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
240
292
|
},
|
|
241
293
|
});
|
|
242
294
|
manager = instance;
|
|
295
|
+
if (installEditor) installNavigationEditor(ctx, seedHistory);
|
|
243
296
|
const entries = ctx.sessionManager.getBranch();
|
|
244
297
|
const entry = [...entries]
|
|
245
298
|
.reverse()
|
|
@@ -268,12 +321,13 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
268
321
|
if (limits.subagentMode !== "off" && diagnostics.length)
|
|
269
322
|
ctx.ui.notify(diagnostics.join("\n"), "warning");
|
|
270
323
|
};
|
|
271
|
-
pi.on("session_start", async (
|
|
272
|
-
await attachSession(ctx);
|
|
324
|
+
pi.on("session_start", async (event, ctx) => {
|
|
325
|
+
await attachSession(ctx, true, event.reason !== "startup");
|
|
273
326
|
if (limits.subagentMode !== "off") await importAgents(ctx, true);
|
|
274
327
|
});
|
|
275
328
|
pi.on("session_tree", async (_event, ctx) => attachSession(ctx));
|
|
276
329
|
const stopWorkingThreads = async () => {
|
|
330
|
+
closeNavigation();
|
|
277
331
|
if (!manager) return;
|
|
278
332
|
for (const thread of manager.list()) {
|
|
279
333
|
const state = manager.get(thread.path).state;
|
|
@@ -286,6 +340,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
286
340
|
pi.on("session_before_fork", stopWorkingThreads);
|
|
287
341
|
pi.on("session_shutdown", async () => {
|
|
288
342
|
generation++;
|
|
343
|
+
closeNavigation(true);
|
|
289
344
|
await manager?.shutdown();
|
|
290
345
|
persist();
|
|
291
346
|
if (context?.hasUI) context.ui.setWidget("pi-subagent", undefined);
|
|
@@ -351,7 +406,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
351
406
|
} else if (command === "status") {
|
|
352
407
|
await showAgentStatus(ctx, requireManager().scope("/root"));
|
|
353
408
|
} else if (command === "tree") {
|
|
354
|
-
await
|
|
409
|
+
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined);
|
|
355
410
|
} else
|
|
356
411
|
ctx.ui.notify(
|
|
357
412
|
"Usage: /agents [tree [path] | status | settings | types | import | reload]",
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionToolContext,
|
|
4
|
+
ToolDefinition,
|
|
5
|
+
ToolLoadout,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
|
|
8
|
+
/** A snapshot of the root's reachable tools, without loading its extensions again. */
|
|
9
|
+
export interface InheritedToolSource {
|
|
10
|
+
tools: ToolDefinition[];
|
|
11
|
+
activeNames: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Capture the public loadout API and a root execution bridge. Keep the bridge alive for
|
|
16
|
+
* detached children, but always pass their signal rather than the spawning call's signal.
|
|
17
|
+
* Built-ins and manager controls are replaced with child-local implementations by runtime.
|
|
18
|
+
*/
|
|
19
|
+
export function createInheritedToolSource(pi: ExtensionAPI) {
|
|
20
|
+
let loadout: ToolLoadout | undefined;
|
|
21
|
+
let context: ExtensionToolContext | undefined;
|
|
22
|
+
return {
|
|
23
|
+
captureLoadout(next: ToolLoadout) {
|
|
24
|
+
loadout = next;
|
|
25
|
+
return undefined;
|
|
26
|
+
},
|
|
27
|
+
captureContext(next: ExtensionToolContext) {
|
|
28
|
+
context = next;
|
|
29
|
+
},
|
|
30
|
+
reset() {
|
|
31
|
+
// session_start is emitted after the replacement loadout is prepared; do not
|
|
32
|
+
// discard that fresh snapshot (or an unchanged loadout on /tree).
|
|
33
|
+
context = undefined;
|
|
34
|
+
},
|
|
35
|
+
snapshot(): InheritedToolSource {
|
|
36
|
+
if (!loadout) return { tools: [], activeNames: [] };
|
|
37
|
+
const rootContext = context;
|
|
38
|
+
const callable = new Set(loadout.callable.map((tool) => tool.name));
|
|
39
|
+
const active = new Set(loadout.declared.map((tool) => tool.name));
|
|
40
|
+
const info = new Map(pi.getAllTools().map((tool) => [tool.name, tool]));
|
|
41
|
+
const tools: ToolDefinition[] = [];
|
|
42
|
+
for (const tool of loadout.registered) {
|
|
43
|
+
const exposure = loadout.getExposure(tool.name);
|
|
44
|
+
// Inactive direct tools and hidden tools are not available in the root either.
|
|
45
|
+
if (!callable.has(tool.name) && !active.has(tool.name)) continue;
|
|
46
|
+
if (exposure === "hidden") continue;
|
|
47
|
+
const metadata = info.get(tool.name);
|
|
48
|
+
tools.push({
|
|
49
|
+
...tool,
|
|
50
|
+
// The root execution pipeline applies argument preparation. Running it in
|
|
51
|
+
// the child too would corrupt non-idempotent preparation shims.
|
|
52
|
+
prepareArguments: undefined,
|
|
53
|
+
label: tool.label,
|
|
54
|
+
exposure,
|
|
55
|
+
namespace: loadout.getNamespace(tool.name),
|
|
56
|
+
annotations: metadata?.annotations,
|
|
57
|
+
promptGuidelines: metadata?.promptGuidelines,
|
|
58
|
+
defaultActive: active.has(tool.name),
|
|
59
|
+
async execute(_id, args, signal, onUpdate) {
|
|
60
|
+
if (!callable.has(tool.name)) {
|
|
61
|
+
// The SDK rejects nested model-only execution. Calling its captured
|
|
62
|
+
// wrapper directly would bypass root permission/result hooks. Known
|
|
63
|
+
// SDK orchestrators are instead recreated locally by runtime.
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Cannot safely inherit model-only tool ${tool.name}: the SDK does not ` +
|
|
66
|
+
"provide a hook-preserving execution bridge. Run it in the main session.",
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const bridge = rootContext ?? context;
|
|
70
|
+
if (!bridge) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Inherited tool execution needs a main-session agent_* tool call first. " +
|
|
73
|
+
"Use agent_steer to resume this child instead of the thread dialog.",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const outcome = await bridge.executeTool(tool.name, args, { signal, onUpdate });
|
|
77
|
+
return { ...outcome.result, isError: outcome.isError };
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return { tools, activeNames: [...active] };
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|