pi-subagents 0.85.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-O7CPL6H4.js → chunk-2D2DQGC2.js} +9 -9
- package/bundle/{chunk-KZ34KQQH.js → chunk-2NY5PCKQ.js} +11 -5
- package/bundle/{chunk-PVIVCDG2.js → chunk-3CVOAS77.js} +2 -2
- package/bundle/{chunk-N7B2KD74.js → chunk-6O7YH2QV.js} +1 -1
- package/bundle/{chunk-IQIWF2VX.js → chunk-AIL46SZU.js} +8 -6
- package/bundle/{chunk-H2NLFTC5.js → chunk-BFF6YDK6.js} +1 -1
- package/bundle/{chunk-UX4SCV5N.js → chunk-C3KWLXDH.js} +159 -98
- package/bundle/{chunk-GCSLVFCX.js → chunk-C5QWQSSM.js} +1 -1
- package/bundle/{chunk-3UZ5FVVJ.js → chunk-DGTZKYIE.js} +39 -34
- package/bundle/{chunk-KDMFBYFM.js → chunk-ESWW6XSX.js} +1 -1
- package/bundle/{chunk-WOVMHDES.js → chunk-EYGBK6CE.js} +194 -94
- package/bundle/{chunk-CS4O36CZ.js → chunk-HDICKROY.js} +5 -5
- package/bundle/{chunk-DV2NCNPR.js → chunk-JLDQ6YUR.js} +12 -12
- package/bundle/{chunk-RQAUNAWG.js → chunk-LFKMM3UH.js} +2 -2
- package/bundle/{chunk-L2ENOFVZ.js → chunk-LZKVUWIY.js} +66 -26
- package/bundle/{chunk-RV5OGHLO.js → chunk-M2VBGET6.js} +2 -2
- package/bundle/{chunk-HFTBF7SG.js → chunk-OOE3R7IQ.js} +1 -1
- package/bundle/{chunk-JNXT3MPI.js → chunk-OTLDAYEQ.js} +5 -5
- package/bundle/{chunk-JWYG26RE.js → chunk-OZCPYJEY.js} +80 -37
- package/bundle/{chunk-LGMILZNE.js → chunk-PGU4TZV3.js} +79 -32
- package/bundle/{chunk-KEY3UQMQ.js → chunk-SIAQXPJ4.js} +6 -8
- package/bundle/{chunk-QO75KJBT.js → chunk-USRX7QXD.js} +2 -2
- package/bundle/{chunk-7MAE3DJV.js → chunk-VFUFOZBU.js} +1 -1
- package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
- package/bundle/{chunk-T5V5BRCL.js → chunk-W52LJANO.js} +1 -1
- package/bundle/{chunk-PHZP3KHB.js → chunk-XSDYTXHF.js} +18 -11
- package/bundle/{chunk-LTPH2DXH.js → chunk-XV7RTWTS.js} +3 -3
- package/bundle/{chunk-JO67XSKD.js → chunk-YEXKJJVS.js} +12 -7
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +9 -3
- package/docs/configuration.md +14 -6
- package/docs/extension-api.md +2 -0
- package/docs/models.md +6 -2
- package/docs/tool-reference.md +3 -0
- package/package.json +1 -1
- package/skills/pi-subagents/SKILL.md +7 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.js +10 -6
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.js +37 -12
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/index.js +4 -2
- package/src/extension/schemas.d.ts +2 -0
- package/src/extension/schemas.js +1 -0
- package/src/extension/tool-activation.js +10 -1
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +8 -8
- package/src/runs/background/async-execution.d.ts +2 -1
- package/src/runs/background/async-execution.js +4 -2
- package/src/runs/background/run-status.js +5 -4
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/subagent-runner.js +6 -6
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +1 -0
- package/src/runs/foreground/subagent-executor.js +51 -8
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-session.d.ts +5 -4
- package/src/runs/shared/child-session.js +43 -33
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/herdr-placed-run.js +3 -2
- package/src/runs/shared/mcp-config-sources.d.ts +2 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -6
- package/src/runs/shared/model-resolution.d.ts +19 -4
- package/src/runs/shared/model-resolution.js +50 -51
- package/src/runs/shared/structured-output.js +10 -3
- package/src/shared/artifacts.js +25 -13
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/types.d.ts +71 -48
- package/src/tui/render.js +83 -22
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/review.js +2 -2
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +103 -39
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +1 -1
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +3 -1
package/bundle/preflight.js
CHANGED
|
@@ -2,22 +2,22 @@ import {
|
|
|
2
2
|
buildEffectiveSystemPrompt,
|
|
3
3
|
canPreferForkFromSnapshot,
|
|
4
4
|
resolveSubagentLaunchContext
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-LFKMM3UH.js";
|
|
6
|
+
import "./chunk-USRX7QXD.js";
|
|
7
7
|
import {
|
|
8
8
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-M2VBGET6.js";
|
|
10
10
|
import {
|
|
11
11
|
nestedResultsPath,
|
|
12
12
|
processTerminalCandidatePath,
|
|
13
13
|
processTerminalPath,
|
|
14
14
|
resultFilePath
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PGU4TZV3.js";
|
|
16
16
|
import {
|
|
17
17
|
applyIntercomBridgeToAgent,
|
|
18
18
|
resolveIntercomBridge,
|
|
19
19
|
validateIntercomBridgeConfig
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-ESWW6XSX.js";
|
|
21
21
|
import {
|
|
22
22
|
AGENT_DEFINITION_PROJECTION_VERSION,
|
|
23
23
|
resolveLaunchBinding,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
applyThinkingSuffix,
|
|
28
28
|
resolvePiLaunchToolPlan
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-SIAQXPJ4.js";
|
|
30
30
|
import {
|
|
31
31
|
assertRequiredChildExtensionsAdmitted,
|
|
32
32
|
resolveRequiredChildExtensions
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
import {
|
|
35
35
|
getArtifactPaths,
|
|
36
36
|
getArtifactsDir
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-XSDYTXHF.js";
|
|
38
38
|
import {
|
|
39
39
|
assertClaudeCodeModelScope,
|
|
40
40
|
assertThinkingWithinCeiling,
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
resolveSkillsWithFallback,
|
|
62
62
|
resolveStepBehavior,
|
|
63
63
|
unknownAgentDiagnosticContext
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-C3KWLXDH.js";
|
|
65
65
|
import {
|
|
66
66
|
DIRS,
|
|
67
67
|
SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
@@ -246,7 +246,8 @@ async function resolveSubagentLaunchContract(input) {
|
|
|
246
246
|
const modelOrigin = resolveModelOrigin({ explicitModel: input.model, agentModel: agent.model, parentModel: input.parentModel });
|
|
247
247
|
const primaryModel = externalRunner ? void 0 : resolveEffectiveSubagentModel(input.model, agent.model, input.parentModel, availableModels, preferredProvider, {
|
|
248
248
|
scope: modelScopes,
|
|
249
|
-
source: modelOrigin === "explicit" ? "explicit" : "inherited"
|
|
249
|
+
source: modelOrigin === "explicit" ? "explicit" : "inherited",
|
|
250
|
+
knownProviders: input.knownProviders
|
|
250
251
|
});
|
|
251
252
|
const effectiveThinkingConfig = input.thinking !== void 0 ? input.thinking : agent.thinking;
|
|
252
253
|
const thinkingCeiling = externalRunner ? void 0 : intersectThinkingCeilings(
|
|
@@ -257,7 +258,8 @@ async function resolveSubagentLaunchContract(input) {
|
|
|
257
258
|
const model = externalRunner ? void 0 : applyThinkingSuffix(resolveModelSelection(primaryModel, availableModels, preferredProvider, {
|
|
258
259
|
scope: modelScopes,
|
|
259
260
|
primaryModelFromParent: modelOrigin === "inherited" || inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
260
|
-
origin: modelOrigin
|
|
261
|
+
origin: modelOrigin,
|
|
262
|
+
knownProviders: input.knownProviders
|
|
261
263
|
}).model, effectiveThinkingConfig, input.thinking !== void 0);
|
|
262
264
|
if (!externalRunner) {
|
|
263
265
|
try {
|
package/bundle/project-panes.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
openProjectPane,
|
|
9
9
|
projectPaneBindingPath,
|
|
10
10
|
readProjectPaneBinding
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3CVOAS77.js";
|
|
12
12
|
import "./chunk-7J4ZXMY7.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-XSDYTXHF.js";
|
|
14
|
+
import "./chunk-C3KWLXDH.js";
|
|
15
15
|
import "./chunk-JEZOSEWG.js";
|
|
16
16
|
import "./chunk-YFCK7H2S.js";
|
|
17
17
|
import "./chunk-QXASAHIA.js";
|
package/docs/agents.md
CHANGED
|
@@ -194,6 +194,12 @@ node --experimental-strip-types --import ./test/support/register-loader.mjs \
|
|
|
194
194
|
|
|
195
195
|
The read-only smoke must report `writeCanaryExists: false`. The writer smoke must report `writeCanaryMatches: true`. Both reports record `workspaceTrust: "operator-managed-saved"`, confirm that the external prompt root was added, and include startup duration and terminal proof without raw protocol output, prompts, or credentials. A trust-required error remains terminal; the harness does not retry with a trust, force, or yolo flag.
|
|
196
196
|
|
|
197
|
+
#### Safety record and wrapper commands
|
|
198
|
+
|
|
199
|
+
Each code-owned adapter run records a `safety` block in its runner status, in `subagent({ action: "status" })`, and in its workflow receipt entry. The block is the adapter's profile: the access its own argv asks the CLI for. Nothing in it is measured from the launched process, and status labels it `Safety (adapter profile, not measured)`.
|
|
200
|
+
|
|
201
|
+
The record carries `safetySource: { "measured": false, "command": "..." }` beside it. `command` is the launch command as configured; a run on a Herdr saved machine records none, because the remote pane runs the adapter's own binary. When `runner.command` is a wrapper script that changes argv before it starts the CLI, the wrapper can grant more or less than the profile shows, so read the wrapper to know the real grant. Receipts written before `safetySource` existed are read as profile values.
|
|
202
|
+
|
|
197
203
|
#### Native oracle compared with external advisors
|
|
198
204
|
|
|
199
205
|
Native `oracle` runs inside Pi and can use its configured read tools. The Claude profiles send the assembled prompt to the local Claude Code CLI through stdin. An external-job agent sends the assembled prompt to its registered provider. Provider options and a prompt digest are persisted in Pi run state. The prompt text is delivered through the local host bridge to the provider and is not stored in the public result payload. Do not place secrets in advisory prompts unless the target provider is approved to receive them.
|
|
@@ -398,11 +404,11 @@ Use these fields when an agent should see more:
|
|
|
398
404
|
|-------|--------|
|
|
399
405
|
| `systemPromptMode: append` | Append the agent prompt to Pi's normal base prompt. |
|
|
400
406
|
| `inheritProjectContext: true` | Keep inherited repository instructions from files like `AGENTS.md` and `CLAUDE.md`. |
|
|
401
|
-
| `inheritGlobalContext: true` | Also keep the operator's global context file from the Pi config agent directory (such as `~/.pi/agent/AGENTS.md`). Defaults to `false
|
|
407
|
+
| `inheritGlobalContext: true` | Also keep the operator's global context file from the Pi config agent directory (such as `~/.pi/agent/AGENTS.md`). Defaults to `false`, or to `subagents.defaultInheritGlobalContext` when that is set. |
|
|
402
408
|
| `inheritSkills: true` | Let the child see Pi's discovered skills catalog. |
|
|
403
409
|
| `defaultContext: fork` | Prefer forked session context when a launch omits `context`; if the parent has no persisted session file or current leaf yet, the implicit default falls back to `fresh` without a failed first attempt. Explicit `context: "fork"` remains strict, and explicit `context: "fresh"` still wins. |
|
|
404
410
|
|
|
405
|
-
Builtin agents opt into repository instruction inheritance by default so they follow repo-specific rules out of the box, but global context remains excluded unless `inheritGlobalContext: true` is set. This changes the behavior of existing agents that previously received global context as part of `inheritProjectContext: true`. `delegate` also uses append mode because its job is orchestration inside the parent workflow.
|
|
411
|
+
Builtin agents opt into repository instruction inheritance by default so they follow repo-specific rules out of the box, but global context remains excluded unless `inheritGlobalContext: true` is set, per agent or for every agent with `subagents.defaultInheritGlobalContext: true` (see [models.md](models.md#global-context-default)). This changes the behavior of existing agents that previously received global context as part of `inheritProjectContext: true`. `delegate` also uses append mode because its job is orchestration inside the parent workflow.
|
|
406
412
|
|
|
407
413
|
These fields and `systemPromptMode` shape a fresh child's system prompt. A forked child (`context: "fork"`) sends its parent's whole system prompt instead, project context, global context, and skills included, and gets its agent prompt in its task message (see [fork context details](tool-reference.md#fork-context-details)).
|
|
408
414
|
|
|
@@ -472,7 +478,7 @@ Field notes:
|
|
|
472
478
|
| `thinking` | Appended as a `:level` suffix at runtime unless a suffix is already present. On the two Claude Code adapters it becomes `--effort`, and a suffix on `model` wins over it. |
|
|
473
479
|
| `systemPromptMode` | `replace` by default; `append` keeps Pi's base prompt. |
|
|
474
480
|
| `inheritProjectContext` | Keeps or strips inherited repository instruction blocks. |
|
|
475
|
-
| `inheritGlobalContext` | Keeps or strips the operator's global context file from the Pi config agent directory (e.g. `~/.pi/agent/AGENTS.md`). It has an effect only when `inheritProjectContext` is `true`; otherwise all context files are already disabled.
|
|
481
|
+
| `inheritGlobalContext` | Keeps or strips the operator's global context file from the Pi config agent directory (e.g. `~/.pi/agent/AGENTS.md`). It has an effect only when `inheritProjectContext` is `true`; otherwise all context files are already disabled. |
|
|
476
482
|
| `inheritSkills` | Keeps or strips Pi's discovered skills catalog. For in-process children this includes skills that loaded extensions add; herdr-placed children rely on Pi's `--no-skills`. |
|
|
477
483
|
| `defaultContext` | Optional `fresh` or `fork` launch-context preference. An implicit `fork` falls back to `fresh` when the parent has no persisted session file or current leaf; an explicit launch `context: "fork"` remains strict. |
|
|
478
484
|
| `skills` | Selects specific skills for the child, regardless of `inheritSkills`. |
|
package/docs/configuration.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`pi-subagents` reads optional JSON config from `~/.pi/agent/extensions/subagent/config.json`. This page lists every key, plus the environment variables and the settings-file keys that affect config resolution.
|
|
4
4
|
|
|
5
|
-
Settings-level keys (`subagents.defaultModel`, `defaultProvider`, `defaultThinking`, `defaultExtensions`, `defaultSubagentOnlyExtensions`, `agentOverrides`, `machines`, `agentScanDirs`, `agentExcludeDirs`, `modelScope`, `disableThinking`, `disableBuiltins`, watchdog settings) live in Pi settings files, not this config file. `modelScope.agents.<name>` adds per-agent restrictions, `allow: ["inherit"]` permits the current parent model, and `allow: ["scoped"]` permits the parent session's scoped models (the parent model when the session is unscoped). See [models.md](models.md), [agents.md](agents.md), and [watchdog.md](watchdog.md).
|
|
5
|
+
Settings-level keys (`subagents.defaultModel`, `defaultProvider`, `defaultThinking`, `defaultExtensions`, `defaultSubagentOnlyExtensions`, `defaultInheritGlobalContext`, `agentOverrides`, `machines`, `agentScanDirs`, `agentExcludeDirs`, `modelScope`, `disableThinking`, `disableBuiltins`, watchdog settings) live in Pi settings files, not this config file. `modelScope.agents.<name>` adds per-agent restrictions, `allow: ["inherit"]` permits the current parent model, and `allow: ["scoped"]` permits the parent session's scoped models (the parent model when the session is unscoped). See [models.md](models.md), [agents.md](agents.md), and [watchdog.md](watchdog.md).
|
|
6
6
|
|
|
7
7
|
## Project root resolution (settings)
|
|
8
8
|
|
|
@@ -86,6 +86,14 @@ The recorded native `subagent` selection is restored on resume, reload, and tree
|
|
|
86
86
|
|
|
87
87
|
Some providers fix the tool list for a whole prompt, for example bridges that hand Pi's tools to another agent SDK. There `subagent` appears only on the next user prompt, not the next model request. Start Pi with `--exclude-tools subagents_enable` to keep `subagent` active from the start.
|
|
88
88
|
|
|
89
|
+
### First installation into an existing recorded session
|
|
90
|
+
|
|
91
|
+
If intact tool-selection history never declared this extension, `"auto"` keeps both `subagents_enable` and `subagent` absent. Installing the extension and running `/reload` alone does not add them.
|
|
92
|
+
|
|
93
|
+
To enable delegation in that session, merge `"toolActivation": "dynamic"` into the existing `~/.pi/agent/extensions/subagent/config.json` object; do not replace the file with the one-key example below. Restart Pi and resume the session, then ask the model to call the `subagents_enable({})` tool. This is a model tool, not a slash command.
|
|
94
|
+
|
|
95
|
+
Alternatively, merge `"toolActivation": "eager"` into the same config, restart Pi to remove the loader, then run `/reload` in the resumed session (see `"eager"` below).
|
|
96
|
+
|
|
89
97
|
## `toolActivation`
|
|
90
98
|
|
|
91
99
|
```json
|
|
@@ -96,9 +104,9 @@ Controls how a new parent session offers the `subagent` tool. The default is `"a
|
|
|
96
104
|
|
|
97
105
|
- `"auto"`: a new session starts with the `subagents_enable` loader only when its model can take a new tool mid-conversation. Otherwise it starts with `subagent` active and no loader, because calling the loader on such a model makes Pi resend the conversation in a form the provider may not have cached. A model qualifies when its Pi `compat` settings set `supportsMidConvoSystemMessages: true` and, for its API, `supportsMidConvoToolChanges: true` (`anthropic-messages`), `supportsMidConvoToolAdditions: true` (`openai-completions`), or `supportsAdditionalTools: true` or `supportsToolSearch: true` (`openai-responses`, `openai-codex-responses`, `azure-openai-responses`). Other APIs, missing settings, and no model do not qualify.
|
|
98
106
|
- `"dynamic"`: every new session starts with the loader, whatever the model. This was the behavior before `toolActivation` existed.
|
|
99
|
-
- `"eager"`: the loader is not registered,
|
|
107
|
+
- `"eager"`: the loader is not registered, and the extension does not change the tool selection. A new session or `/reload` makes `subagent` active; a resumed session whose recorded tools lack `subagent` stays without it until `/reload`. See the recovery steps above.
|
|
100
108
|
|
|
101
|
-
The choice is made at session start or tree navigation, and only for a session with no messages. If a compaction that kept no tool checkpoint dropped the record of this choice, the session is decided again as a new session would be; tool selections recorded after that compaction (for `bg_wait` or another extension's tools) are not evidence that the choice survived.
|
|
109
|
+
The choice is made at session start or tree navigation, and only for a session with no messages. If a compaction that kept no tool checkpoint dropped the record of this choice, the session is decided again as a new session would be; tool selections recorded after that compaction (for `bg_wait` or another extension's tools) are not evidence that the choice survived. Under `"auto"`, resumed sessions keep the tools they recorded. `"dynamic"` also adds the loader to recorded sessions that did not have it. Switching models mid-session does not change the selection. `"auto"` avoids only the loader's cache miss; other tool-list or provider changes can still miss the cache. An active `subagent` sends its full schema on every request. An invalid value is a config error, not a fallback to the default. Restart Pi after changing it.
|
|
102
110
|
|
|
103
111
|
## `toolDescriptionMode`
|
|
104
112
|
|
|
@@ -108,7 +116,7 @@ The choice is made at session start or tree navigation, and only for a session w
|
|
|
108
116
|
|
|
109
117
|
Controls the parent-facing `subagent` tool description registered at startup. The default registers the short execution/safety description, which states the delegation authorization rule, plus a one-line `promptSnippet`. Explicit `"compact"` uses the same description without the snippet; `"full"` adds workflow and management detail, also without the snippet. All modes retain the same flat parameter schema. Extended examples and recipes are available on demand through `action:"guide"` and the bundled pi-subagents skill; full mode is not an exhaustive manual. Count the default snippet as well as the tool definition when comparing prompt footprints.
|
|
110
118
|
|
|
111
|
-
`custom` reads `subagent-tool-description.md` from the project config directory, then from `~/.pi/agent/subagent-tool-description.md`. Missing, empty, unreadable, or oversized custom files fall back to the full description. Custom templates may use `{{fullDescription}}`, `{{compactDescription}}`, `{{safetyGuidance}}`, `{{agentDir}}`, and `{{projectConfigDir}}`; the safety guidance is always present so custom prose cannot remove the runtime guardrails. Restart Pi after changing the mode or custom file. The change applies to new sessions; a resumed session keeps the tool definition and prompt text it already declared, so its prompt cache stays valid. To apply it to resumed sessions too, set [`pinToolDeclarations`](#pintooldeclarations) to `false`.
|
|
119
|
+
`custom` reads `subagent-tool-description.md` from the project config directory, then from `~/.pi/agent/subagent-tool-description.md`. Missing, empty, unreadable, or oversized custom files fall back to the full description. Custom templates may use `{{fullDescription}}`, `{{compactDescription}}`, `{{safetyGuidance}}`, `{{agentDir}}`, and `{{projectConfigDir}}`; the two description placeholders leave out features turned off with [`disabledFeatures`](#disabledfeatures), and the safety guidance is always present so custom prose cannot remove the runtime guardrails. Restart Pi after changing the mode or custom file. The change applies to new sessions; a resumed session keeps the tool definition and prompt text it already declared, so its prompt cache stays valid. To apply it to resumed sessions too, set [`pinToolDeclarations`](#pintooldeclarations) to `false`.
|
|
112
120
|
|
|
113
121
|
## `pinToolDeclarations`
|
|
114
122
|
|
|
@@ -124,7 +132,7 @@ Pi records each tool definition and prompt section a session declares, and decla
|
|
|
124
132
|
{ "disabledFeatures": ["watchdog", "panes", "preflight", "lane-metadata", "gates"] }
|
|
125
133
|
```
|
|
126
134
|
|
|
127
|
-
Removes feature groups you do not use from the `subagent` tool. Each listed feature loses its top-level parameters from the model-facing schema and its `options` keys are rejected, and any request that still uses one of its parameters or actions fails with an error naming this setting. The check covers the parent tool, fanout-child tools, RPC, slash commands, prompt templates, scheduled launches, delegated launches, and workflow `runs.run`/`runs.all`/`runs.lanes` children, which are rejected before they launch. The built-in tool descriptions, the unknown-action list, the fanout-child tool description, and RPC `ping` no longer mention disabled features. Every `{ action: "guide" }` response starts with a notice: a topic lists what is disabled, and a section points to the `tool-reference` topic for that list. With `workflow-scripts` disabled, the notice also says to use the top-level `tasks` or `chain` fields instead. Custom tool descriptions
|
|
135
|
+
Removes feature groups you do not use from the `subagent` tool. Each listed feature loses its top-level parameters from the model-facing schema and its `options` keys are rejected, and any request that still uses one of its parameters or actions fails with an error naming this setting. The check covers the parent tool, fanout-child tools, RPC, slash commands, prompt templates, scheduled launches, delegated launches, and workflow `runs.run`/`runs.all`/`runs.lanes` children, which are rejected before they launch. The built-in tool descriptions, the unknown-action list, the fanout-child tool description, and RPC `ping` no longer mention disabled features. Every `{ action: "guide" }` response starts with a notice: a topic lists what is disabled, and a section points to the `tool-reference` topic for that list. With `workflow-scripts` disabled, the notice also says to use the top-level `tasks` or `chain` fields instead. Custom tool descriptions keep their own text; only their `{{compactDescription}}` and `{{fullDescription}}` placeholders leave out disabled features. Nothing is disabled by default, and the default schema and description are unchanged. An unknown or duplicate feature name fails config loading rather than silently re-enabling every feature.
|
|
128
136
|
|
|
129
137
|
| Feature | Parameters removed | Actions rejected |
|
|
130
138
|
|---|---|---|
|
|
@@ -724,7 +732,7 @@ Controls where subagent artifact files (inputs, outputs, transcripts, metadata)
|
|
|
724
732
|
|
|
725
733
|
This preference also controls the default workflow artifact directory used by scripted chaining. `"project"` uses `<cwd>/.pi/subagents/chain-runs/`; the directory keeps its legacy name for compatibility. The default `"session"` and `"temp"` use the user-scoped temp workflow artifact directory.
|
|
726
734
|
|
|
727
|
-
The `"session"` option uses the same directory that `cleanupAllArtifactDirs` already scans for age-based cleanup, so artifacts are still cleaned up automatically. Temporary workflow artifact directories are cleaned up separately after 24 hours.
|
|
735
|
+
The `"session"` option uses the same directory that `cleanupAllArtifactDirs` already scans for age-based cleanup, so artifacts are still cleaned up automatically: files older than `artifactConfig.cleanupDays` (default 7, `0` turns cleanup off) are removed, including those in nested folders such as workflow `outputs/`. `handoffs/` and `worktree-diffs/` are kept, because they record worktrees that can be kept longer than that. Temporary workflow artifact directories are cleaned up separately after 24 hours.
|
|
728
736
|
|
|
729
737
|
When a project-scoped launch runs from an npm package directory, pi-subagents warns if package settings can include `.pi/subagents/` in the published package. Add `.pi/subagents/` to `.npmignore` (or `.gitignore` when no `.npmignore` exists), use a `files` allowlist that does not include `.pi/subagents/`, or select `"session"` or `"temp"`.
|
|
730
738
|
|
package/docs/extension-api.md
CHANGED
|
@@ -275,6 +275,8 @@ const result = await resolveSubagentLaunchContract({
|
|
|
275
275
|
cwd: ctx.cwd,
|
|
276
276
|
sessionRoot: "/tmp/my-extension-preflight-session-root",
|
|
277
277
|
availableModels: ctx.modelRegistry.getAvailable(),
|
|
278
|
+
// Every provider Pi knows, so `anthropic/...` never resolves to another provider's copy.
|
|
279
|
+
knownProviders: () => ctx.modelRegistry.getAll().map((model) => model.provider),
|
|
278
280
|
});
|
|
279
281
|
|
|
280
282
|
if (!result.ok) {
|
package/docs/models.md
CHANGED
|
@@ -164,6 +164,10 @@ Set `subagents.defaultSubagentOnlyExtensions` to give agents without a `subagent
|
|
|
164
164
|
|
|
165
165
|
The two defaults resolve independently, with an explicitly present project value winning over the user value. If both are set, `defaultExtensions` still disables ambient discovery and the child-only paths are loaded alongside its allowlist. Both reject non-arrays, non-string or blank entries with an error naming the setting and source file. Extension paths execute trusted code, so use project defaults only for trusted repositories and extensions.
|
|
166
166
|
|
|
167
|
+
## Global context default
|
|
168
|
+
|
|
169
|
+
Set `subagents.defaultInheritGlobalContext: true` to give every builtin, package, user and project agent your global context file (such as `~/.pi/agent/AGENTS.md`). An agent that declares `inheritGlobalContext` in its frontmatter keeps its own value, and `agentOverrides.<name>.inheritGlobalContext` still wins over both, so `false` in either place opts that agent out. A project value wins over the user value. The setting only matters for agents with `inheritProjectContext: true` (every builtin agent has it); without project context a child gets no context files at all. Runtime-registered agents keep their extension's value. A non-boolean value is rejected with an error naming the settings file.
|
|
170
|
+
|
|
167
171
|
## Inspecting the live mapping
|
|
168
172
|
|
|
169
173
|
To see what `pi-subagents` has actually loaded right now:
|
|
@@ -184,9 +188,9 @@ You do not have to spell a model exactly. Model ids are matched fuzzily against
|
|
|
184
188
|
- Case differences: `Claude-Sonnet-4` vs `claude-sonnet-4`
|
|
185
189
|
- Optional trailing date stamps: `claude-haiku-4-5-20251001` or `claude-haiku-4-5-2025-10-01` vs `claude-haiku-4-5`
|
|
186
190
|
|
|
187
|
-
Exact `provider/id` matches still win, and a qualified provider query never silently switches providers — it only matches within the named provider. Ambiguous bare ids that exist under multiple providers still require a provider prefix or the current session's provider to disambiguate.
|
|
191
|
+
Exact `provider/id` matches still win, and a qualified provider query never silently switches providers — it only matches within the named provider. This holds for providers you are not signed in to: without Anthropic credentials, `anthropic/claude-opus-4-8` fails with an error that names the OpenRouter copy (`openrouter/anthropic/claude-opus-4.8`) instead of running it. Ambiguous bare ids that exist under multiple providers still require a provider prefix or the current session's provider to disambiguate.
|
|
188
192
|
|
|
189
|
-
Registry ids that themselves contain `/` (Hugging Face `owner/name`) resolve the same way as Pi's main agent: `thinkingmachines/Inkling` becomes `huggingface/thinkingmachines/Inkling` when that id is unique or offered by the current session provider. A first path segment that
|
|
193
|
+
Registry ids that themselves contain `/` (Hugging Face `owner/name`) resolve the same way as Pi's main agent: `thinkingmachines/Inkling` becomes `huggingface/thinkingmachines/Inkling` when that id is unique or offered by the current session provider. A first path segment that names any provider Pi knows, signed in or not, still means `provider/id`.
|
|
190
194
|
|
|
191
195
|
## Model scope enforcement
|
|
192
196
|
|
package/docs/tool-reference.md
CHANGED
|
@@ -392,6 +392,7 @@ Commands remain owned by the child session. Normal completion with unfinished co
|
|
|
392
392
|
- `/subagents-stop` without an id opens a selector with confirmation when a TUI is available. Use `↑`/`↓` or `j`/`k` to move through the selector. When two or more current-session async runs are active, the first row is "stop all", which stops each of them after one confirmation and leaves scheduled runs alone.
|
|
393
393
|
- In non-TUI contexts the slash command prints exact `subagent({ action: "stop", id })` and `/subagents-stop <id>` commands.
|
|
394
394
|
- Pass a child id to stop one child of a multi-child async run or workflow while the rest continue: `/subagents-stop <run-id> <child-id>` (equivalent to `subagent({ action: "stop", id, childId })`). Child ids come from status output, the async status snapshot, or `/subagents-inspect-rpc` replies. Only pending or running children are stoppable; the request is rejected for anything else instead of widening to a run-level stop.
|
|
395
|
+
- `subagent({ action: "stop", id, options: { drain: true } })` stops a live async workflow in this session without killing running children: children that have not started are stopped, the script cannot start new children or `runs.host` commands, and children already running finish and keep their results. The workflow then ends as stopped and is never resumed. It cannot be combined with `childId`; a full `stop` still works during a drain.
|
|
395
396
|
- Inactive schedules can appear in the selector, but they are labeled as schedules and route through `schedule.pause`, not `stop`.
|
|
396
397
|
|
|
397
398
|
### steer
|
|
@@ -539,6 +540,8 @@ async: true
|
|
|
539
540
|
|
|
540
541
|
Supported: status artifacts, stdout/stderr logs, timeout, and stop. Full stdout and stderr are written to log files, while the in-memory final stdout response and stderr error are limited to their last 64 KiB.
|
|
541
542
|
|
|
543
|
+
A code-owned adapter (`adapter: claude-code-writer` and the others in [agents.md](agents.md#claude-code-profiles)) records a `safety` block and a `safetySource: { measured: false, command }` beside it. The block is the adapter's profile, not a measurement, so a wrapper `command` that changes the CLI's argv can grant something else; see [Safety record and wrapper commands](agents.md#safety-record-and-wrapper-commands).
|
|
544
|
+
|
|
542
545
|
Intentionally unsupported: native Pi child options such as model override, structured output, acceptance/agent contract, tool budgets, fast mode, fork context, skills, or native Pi tools unless the runner explicitly implements them. Foreground/clarify, steer/resume/interrupt-as-pause, and nested subagents are also unsupported.
|
|
543
546
|
|
|
544
547
|
## Session sharing
|
package/package.json
CHANGED
|
@@ -68,9 +68,11 @@ return reviews.map((review) => review.output);
|
|
|
68
68
|
and plain helpers. Nested async functions, arrows, and methods are rejected.
|
|
69
69
|
- Every `runs.run` / `runs.all` item needs a stable `key`. Add a short
|
|
70
70
|
verb + behavior `label` unless the user gave one.
|
|
71
|
-
- Bind files with `output: "plans/x.md"`
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
- Bind files with `output: "plans/x.md"` and return `outputReference` or
|
|
72
|
+
`artifactPaths`; a filename in task text does not route output. Relative
|
|
73
|
+
paths land in run artifacts. Never send reports to the repo root. When the
|
|
74
|
+
task ends, delete scratch briefs, scripts and reports you wrote anywhere
|
|
75
|
+
else; keep final deliverables.
|
|
74
76
|
- `runs.lanes([{ key, stages: [...] }])` runs a predeclared plan: first stages
|
|
75
77
|
together, later stages in order per lane.
|
|
76
78
|
|
|
@@ -113,7 +115,8 @@ number.
|
|
|
113
115
|
- As a conservative orchestration policy, do not pass a hard `toolBudget` or tight `usageBudget` to mutation-capable workers. The default tool budget blocks read/search tools rather than mutation tools. If interrupted after a tool call starts, checkpoint after the current tool returns with changed files, build/test state, and commit or PR state.
|
|
114
116
|
- Route workers and scouts to a fast capable tier, serious reviews to a strong
|
|
115
117
|
tier, and top reasoning only to bounded read-only critique. Exact model names
|
|
116
|
-
belong in user or project settings, not here.
|
|
118
|
+
belong in user or project settings, not here. When neither the user nor
|
|
119
|
+
settings name a model, omit `model` so the child inherits the parent's.
|
|
117
120
|
- `subagent`, `subagents_enable`, `subagent_supervisor`, `contact_supervisor`, and `structured_output` are model-only: call them as ordinary model tool calls. Codemode scripts cannot reach them through `tools.*`, `ALL_TOOLS`, or `searchTools`.
|
|
118
121
|
- Receipts, CI, and review bots are evidence, not authority. Backlog, release,
|
|
119
122
|
and merge policy belong to the user's or project's own skill.
|
|
@@ -96,3 +96,4 @@ top-reasoning model is only a bounded read-only critic after ordinary evidence
|
|
|
96
96
|
falls short, never an autonomous root. Map tiers to real models in user or
|
|
97
97
|
project settings or a profile (guide `models/setting-defaults-and-overrides`,
|
|
98
98
|
`models/profiles-and-provider-model-catalogs`). Explicit user policy wins.
|
|
99
|
+
Never pick a model from memory.
|
|
@@ -7,7 +7,7 @@ import { discoverAvailableSkills, resolveSkills } from "./skills.js";
|
|
|
7
7
|
import { buildProactiveSkillSubagentRecommendationLines, } from "./proactive-skills.js";
|
|
8
8
|
import { parseFrontmatter, parseUnquotedList } from "./frontmatter.js";
|
|
9
9
|
import { resolveEffectiveThinking, THINKING_LEVELS, toModelInfo } from "../shared/model-info.js";
|
|
10
|
-
import { isUnavailableSubagentModel, resolveSubagentModelOverride } from "../runs/shared/model-resolution.js";
|
|
10
|
+
import { isUnavailableSubagentModel, knownModelProviders, resolveSubagentModelOverride } from "../runs/shared/model-resolution.js";
|
|
11
11
|
import { validateToolBudgetConfig } from "../runs/shared/tool-budget.js";
|
|
12
12
|
import { formatReviewGateLabel, validateAcceptanceInput } from "../runs/shared/acceptance.js";
|
|
13
13
|
import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, resolveExternalCliRunnerStatus, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.js";
|
|
@@ -195,6 +195,8 @@ export function editableAgentConfig(agent) {
|
|
|
195
195
|
delete next.model;
|
|
196
196
|
if (!hasDeclaredField("thinking"))
|
|
197
197
|
delete next.thinking;
|
|
198
|
+
if (!hasDeclaredField("inheritGlobalContext"))
|
|
199
|
+
next.inheritGlobalContext = false;
|
|
198
200
|
return next;
|
|
199
201
|
};
|
|
200
202
|
const { override: _override, description: _description, output: _output, outputMode: _outputMode, defaultReads: _defaultReads, model: _model, fast: _fast, thinking: _thinking, systemPromptMode: _systemPromptMode, inheritProjectContext: _inheritProjectContext, inheritGlobalContext: _inheritGlobalContext, inheritSkills: _inheritSkills, defaultContext: _defaultContext, acceptanceRole: _acceptanceRole, disabled: _disabled, systemPrompt: _systemPrompt, skills: _skills, skillPath: _skillPath, tools: _tools, excludeTools: _excludeTools, mcpDirectTools: _mcpDirectTools, allowNestedSubagents: _allowNestedSubagents, allowedAgents: _allowedAgents, subagentOnlyExtensions: _subagentOnlyExtensions, mutationTools: _mutationTools, toolBudget: _toolBudget, ...editable } = withoutExtensions;
|
|
@@ -215,7 +217,7 @@ export function editableAgentConfig(agent) {
|
|
|
215
217
|
...(base.thinking !== undefined && hasDeclaredField("thinking") ? { thinking: base.thinking } : {}),
|
|
216
218
|
systemPromptMode: base.systemPromptMode,
|
|
217
219
|
inheritProjectContext: base.inheritProjectContext,
|
|
218
|
-
inheritGlobalContext: base.inheritGlobalContext,
|
|
220
|
+
inheritGlobalContext: hasDeclaredField("inheritGlobalContext") && base.inheritGlobalContext,
|
|
219
221
|
inheritSkills: base.inheritSkills,
|
|
220
222
|
...(base.defaultContext !== undefined ? { defaultContext: base.defaultContext } : {}),
|
|
221
223
|
...(base.acceptanceRole !== undefined ? { acceptanceRole: base.acceptanceRole } : {}),
|
|
@@ -1042,8 +1044,9 @@ export function handleList(params, ctx) {
|
|
|
1042
1044
|
const capabilityMode = params.capabilities === true;
|
|
1043
1045
|
const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : undefined;
|
|
1044
1046
|
const availableModels = capabilityMode ? ctx.modelRegistry.getAvailable().map(toModelInfo) : [];
|
|
1047
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
1045
1048
|
const unavailableModels = new Set([...agents, ...restrictedAgents].filter((agent) => (agent.runner?.type ?? "pi") === "pi"
|
|
1046
|
-
&& isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? ctx.model?.provider)));
|
|
1049
|
+
&& isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? ctx.model?.provider, knownProviders)));
|
|
1047
1050
|
const formatLine = capabilityMode
|
|
1048
1051
|
? (agent, names) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability, unavailableModels)
|
|
1049
1052
|
: formatAgentListLine;
|
|
@@ -1094,6 +1097,7 @@ function handleModels(params, ctx) {
|
|
|
1094
1097
|
const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner, ctx.model?.provider)
|
|
1095
1098
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
1096
1099
|
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
1100
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
1097
1101
|
const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined;
|
|
1098
1102
|
const preferredProvider = ctx.model?.provider;
|
|
1099
1103
|
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
@@ -1127,9 +1131,9 @@ function handleModels(params, ctx) {
|
|
|
1127
1131
|
? [{ agent, name: requestedAgent }]
|
|
1128
1132
|
: [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
|
|
1129
1133
|
for (const { agent, name } of modelEntries) {
|
|
1130
|
-
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
|
|
1134
|
+
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider, { knownProviders });
|
|
1131
1135
|
const shownModel = resolvedModel === undefined ? "(unresolved)"
|
|
1132
|
-
: (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
1136
|
+
: (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider, knownProviders) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
1133
1137
|
const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking)
|
|
1134
1138
|
?? (agent.thinking === false ? "off" : undefined);
|
|
1135
1139
|
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
|
|
@@ -1270,7 +1274,7 @@ export function handleCreate(params, ctx) {
|
|
|
1270
1274
|
const sw = skillsWarning(ctx.cwd, agent);
|
|
1271
1275
|
if (sw)
|
|
1272
1276
|
warnings.push(sw);
|
|
1273
|
-
fs.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
|
|
1277
|
+
fs.writeFileSync(targetPath, serializeAgent(agent, { explicitInheritGlobalContext: hasKey(cfg, "inheritGlobalContext") }), "utf-8");
|
|
1274
1278
|
ctx.onAgentsChanged?.();
|
|
1275
1279
|
return result([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
|
|
1276
1280
|
}
|
|
@@ -2,6 +2,8 @@ import type { AgentConfig } from "./agents.ts";
|
|
|
2
2
|
export declare const KNOWN_FIELDS: Set<string>;
|
|
3
3
|
interface SerializeAgentOptions {
|
|
4
4
|
preserveFrontmatterFields?: ReadonlySet<string>;
|
|
5
|
+
/** The caller set inheritGlobalContext on create; write it even when false, because an absent field takes settings defaults. */
|
|
6
|
+
explicitInheritGlobalContext?: boolean;
|
|
5
7
|
}
|
|
6
8
|
export declare function serializeAgent(config: AgentConfig, options?: SerializeAgentOptions): string;
|
|
7
9
|
export {};
|
|
@@ -97,7 +97,7 @@ export function serializeAgent(config, options = {}) {
|
|
|
97
97
|
lines.push(`systemPromptMode: ${config.systemPromptMode}`);
|
|
98
98
|
if (!preservingExistingFrontmatter || preserve("inheritProjectContext"))
|
|
99
99
|
lines.push(`inheritProjectContext: ${config.inheritProjectContext ? "true" : "false"}`);
|
|
100
|
-
if (config.inheritGlobalContext || preserve("inheritGlobalContext"))
|
|
100
|
+
if (config.inheritGlobalContext || preserve("inheritGlobalContext") || options.explicitInheritGlobalContext)
|
|
101
101
|
lines.push(`inheritGlobalContext: ${config.inheritGlobalContext ? "true" : "false"}`);
|
|
102
102
|
if (!preservingExistingFrontmatter || preserve("inheritSkills"))
|
|
103
103
|
lines.push(`inheritSkills: ${config.inheritSkills ? "true" : "false"}`);
|
package/src/agents/agents.js
CHANGED
|
@@ -953,21 +953,24 @@ function readSubagentSettings(filePath) {
|
|
|
953
953
|
const subagentsObject = subagents;
|
|
954
954
|
let disableBuiltins;
|
|
955
955
|
if ("disableBuiltins" in subagentsObject) {
|
|
956
|
-
if (typeof subagentsObject.disableBuiltins === "boolean")
|
|
956
|
+
if (typeof subagentsObject.disableBuiltins === "boolean")
|
|
957
957
|
disableBuiltins = subagentsObject.disableBuiltins;
|
|
958
|
-
|
|
959
|
-
else {
|
|
958
|
+
else
|
|
960
959
|
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
|
|
961
|
-
}
|
|
962
960
|
}
|
|
963
961
|
let disableThinking;
|
|
964
962
|
if ("disableThinking" in subagentsObject) {
|
|
965
|
-
if (typeof subagentsObject.disableThinking === "boolean")
|
|
963
|
+
if (typeof subagentsObject.disableThinking === "boolean")
|
|
966
964
|
disableThinking = subagentsObject.disableThinking;
|
|
967
|
-
|
|
968
|
-
else {
|
|
965
|
+
else
|
|
969
966
|
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableThinking'; expected a boolean.`);
|
|
970
|
-
|
|
967
|
+
}
|
|
968
|
+
let defaultInheritGlobalContext;
|
|
969
|
+
if ("defaultInheritGlobalContext" in subagentsObject) {
|
|
970
|
+
if (typeof subagentsObject.defaultInheritGlobalContext === "boolean")
|
|
971
|
+
defaultInheritGlobalContext = subagentsObject.defaultInheritGlobalContext;
|
|
972
|
+
else
|
|
973
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultInheritGlobalContext'; expected a boolean.`);
|
|
971
974
|
}
|
|
972
975
|
let defaultModel;
|
|
973
976
|
if ("defaultModel" in subagentsObject) {
|
|
@@ -1051,6 +1054,7 @@ function readSubagentSettings(filePath) {
|
|
|
1051
1054
|
...(maxThinking !== undefined ? { maxThinking } : {}),
|
|
1052
1055
|
...(defaultExtensions !== undefined ? { defaultExtensions } : {}),
|
|
1053
1056
|
...(defaultSubagentOnlyExtensions !== undefined ? { defaultSubagentOnlyExtensions } : {}),
|
|
1057
|
+
...(defaultInheritGlobalContext !== undefined ? { defaultInheritGlobalContext } : {}),
|
|
1054
1058
|
...(agentScanDirs !== undefined ? { agentScanDirs } : {}),
|
|
1055
1059
|
...(agentExcludeDirs !== undefined ? { agentExcludeDirs } : {}),
|
|
1056
1060
|
...(disableBuiltins !== undefined ? { disableBuiltins } : {}),
|
|
@@ -1189,8 +1193,27 @@ function applySubagentDefaultSubagentOnlyExtensions(agents, defaultSubagentOnlyE
|
|
|
1189
1193
|
return next;
|
|
1190
1194
|
});
|
|
1191
1195
|
}
|
|
1192
|
-
function
|
|
1193
|
-
|
|
1196
|
+
function resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, projectSettingsPath) {
|
|
1197
|
+
if (projectSettingsPath && projectSettings.defaultInheritGlobalContext !== undefined)
|
|
1198
|
+
return projectSettings.defaultInheritGlobalContext;
|
|
1199
|
+
return userSettings.defaultInheritGlobalContext;
|
|
1200
|
+
}
|
|
1201
|
+
// The parsed field is a plain boolean, so only the frontmatter key tells an explicit `false` from an unset field.
|
|
1202
|
+
function applySubagentDefaultInheritGlobalContext(agents, defaultInheritGlobalContext) {
|
|
1203
|
+
if (!defaultInheritGlobalContext)
|
|
1204
|
+
return agents;
|
|
1205
|
+
return agents.map((agent) => {
|
|
1206
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1207
|
+
if (agent.inheritGlobalContext || frontmatterFields?.has("inheritGlobalContext"))
|
|
1208
|
+
return agent;
|
|
1209
|
+
const next = { ...agent, inheritGlobalContext: true };
|
|
1210
|
+
if (frontmatterFields)
|
|
1211
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1212
|
+
return next;
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
function applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext) {
|
|
1216
|
+
return applySubagentDefaultInheritGlobalContext(applySubagentDefaultSubagentOnlyExtensions(applySubagentDefaultExtensions(applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking), defaultExtensions), defaultSubagentOnlyExtensions), defaultInheritGlobalContext);
|
|
1194
1217
|
}
|
|
1195
1218
|
function applyToolsOverride(target, toolsOverride) {
|
|
1196
1219
|
if (toolsOverride === "inherit") {
|
|
@@ -2550,7 +2573,8 @@ function configuredAgentsForScope(sources, scope, settingsScope = scope) {
|
|
|
2550
2573
|
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2551
2574
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2552
2575
|
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2553
|
-
const
|
|
2576
|
+
const defaultInheritGlobalContext = resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2577
|
+
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext);
|
|
2554
2578
|
const builtin = applyBuiltinOverrides(applyDefaults(sources.builtinLoaded.agents), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2555
2579
|
const user = applyCustomAgentOverrides(applyDefaults(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.agents)), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2556
2580
|
const projectMap = new Map();
|
|
@@ -2706,12 +2730,13 @@ function discoverAgentsUncached(cwd, scope, preferredModelProvider, options = {}
|
|
|
2706
2730
|
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2707
2731
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
2708
2732
|
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
2733
|
+
const defaultInheritGlobalContext = resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, projectSettingsPath);
|
|
2709
2734
|
const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
|
|
2710
2735
|
const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd, { includeUser: scope !== "project", includeProject: scope !== "user", globalNpmRoot: options.globalNpmRoot });
|
|
2711
2736
|
const isExcluded = agentExclusions(agentExclusionRoots(userSettingsPath, projectSettingsPath));
|
|
2712
2737
|
const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
|
|
2713
2738
|
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
2714
|
-
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
|
|
2739
|
+
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext);
|
|
2715
2740
|
const builtinAgents = applyBuiltinOverrides(applyDefaults(builtinLoaded.agents), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
2716
2741
|
const userScanDirs = settingsAgentScanDirs(userSettings.agentScanDirs ?? [], isExcluded);
|
|
2717
2742
|
const projectScanDirs = settingsAgentScanDirs(projectSettings.agentScanDirs ?? [], isExcluded);
|
package/src/api/preflight.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AgentConfig, type AgentScope, type AgentSource } from "../agents/agents.ts";
|
|
2
|
-
import { type AvailableModelInfo, type ParentModel } from "../runs/shared/model-resolution.ts";
|
|
2
|
+
import { type AvailableModelInfo, type KnownProviders, type ParentModel } from "../runs/shared/model-resolution.ts";
|
|
3
3
|
import { type ThinkingLevel } from "../shared/thinking-ceiling.ts";
|
|
4
4
|
import { type ArtifactDirPreference, type ArtifactPaths, type IntercomBridgeConfig, type IntercomBridgeMode, type JsonSchemaObject, type OutputMode } from "../shared/types.ts";
|
|
5
5
|
import { type ResolvedSubagentCapabilityCeiling, type SubagentCapabilityAudit } from "../runs/shared/capability-ceiling.ts";
|
|
@@ -36,6 +36,8 @@ export interface SubagentLaunchContractInput {
|
|
|
36
36
|
fullId?: string;
|
|
37
37
|
reasoning?: boolean;
|
|
38
38
|
}>;
|
|
39
|
+
/** Every provider in Pi's full catalog (`ctx.modelRegistry.getAll()`), signed in or not, so a `provider/id` never resolves under another provider. */
|
|
40
|
+
knownProviders?: KnownProviders;
|
|
39
41
|
preferredProvider?: string;
|
|
40
42
|
skill?: string | string[] | boolean;
|
|
41
43
|
output?: string | boolean;
|
package/src/api/preflight.js
CHANGED
|
@@ -225,6 +225,7 @@ export async function resolveSubagentLaunchContract(input) {
|
|
|
225
225
|
: resolveEffectiveSubagentModel(input.model, agent.model, input.parentModel, availableModels, preferredProvider, {
|
|
226
226
|
scope: modelScopes,
|
|
227
227
|
source: modelOrigin === "explicit" ? "explicit" : "inherited",
|
|
228
|
+
knownProviders: input.knownProviders,
|
|
228
229
|
});
|
|
229
230
|
const effectiveThinkingConfig = input.thinking !== undefined ? input.thinking : agent.thinking;
|
|
230
231
|
const thinkingCeiling = externalRunner ? undefined : intersectThinkingCeilings(discovered.maxThinking, input.thinkingCeiling, input.inheritedThinkingCeiling);
|
|
@@ -232,6 +233,7 @@ export async function resolveSubagentLaunchContract(input) {
|
|
|
232
233
|
scope: modelScopes,
|
|
233
234
|
primaryModelFromParent: modelOrigin === "inherited" || inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
234
235
|
origin: modelOrigin,
|
|
236
|
+
knownProviders: input.knownProviders,
|
|
235
237
|
}).model, effectiveThinkingConfig, input.thinking !== undefined);
|
|
236
238
|
if (!externalRunner) {
|
|
237
239
|
try {
|
package/src/extension/index.js
CHANGED
|
@@ -57,7 +57,7 @@ import registerSubagentNotify from "../runs/background/notify.js";
|
|
|
57
57
|
import { createParentWake } from "../shared/parent-wake.js";
|
|
58
58
|
import { handleSubagentSteeringNotice } from "./steering-notices.js";
|
|
59
59
|
import { SUBAGENT_CHILD_ENV, SUBAGENT_PARENT_SESSION_ENV } from "../runs/shared/child-runtime-config.js";
|
|
60
|
-
import {
|
|
60
|
+
import { disposeChildSessionsForParent } from "../runs/shared/child-session.js";
|
|
61
61
|
import { resolveCurrentSubagentCapabilityCeiling } from "../runs/shared/capability-ceiling.js";
|
|
62
62
|
import { loadConfig, resolveAsyncByDefault, resolveScheduledStoreRoot } from "./config.js";
|
|
63
63
|
import { buildSubagentToolDescription, buildSubagentToolPromptMetadata } from "./tool-description.js";
|
|
@@ -1196,13 +1196,15 @@ export default function registerSubagentExtension(pi) {
|
|
|
1196
1196
|
supervisorChannel.activateTransport();
|
|
1197
1197
|
});
|
|
1198
1198
|
pi.on("session_shutdown", async (event) => {
|
|
1199
|
+
// Captured first: runtimeEntry.cleanup() below clears state.parentSessionFile.
|
|
1200
|
+
const parentSessionFile = state.parentSessionFile ?? undefined;
|
|
1199
1201
|
sessionSwitchGuard.sessionShutdown(event);
|
|
1200
1202
|
cancelCompactionResume();
|
|
1201
1203
|
completionNotifier.sessionShutdown(event?.reason);
|
|
1202
1204
|
parentWake.sessionShutdown(event?.reason);
|
|
1203
1205
|
runtimeEntry.cleanup(event?.reason);
|
|
1204
1206
|
try {
|
|
1205
|
-
await
|
|
1207
|
+
await disposeChildSessionsForParent(parentSessionFile);
|
|
1206
1208
|
}
|
|
1207
1209
|
catch (error) {
|
|
1208
1210
|
console.error("Failed to dispose in-process child sessions:", error);
|
|
@@ -19,6 +19,7 @@ export declare const SubagentFlatParams: Type.TObject<{
|
|
|
19
19
|
supersession: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
20
20
|
index: Type.TOptional<Type.TInteger>;
|
|
21
21
|
childId: Type.TOptional<Type.TString>;
|
|
22
|
+
drain: Type.TOptional<Type.TBoolean>;
|
|
22
23
|
toolCallId: Type.TOptional<Type.TString>;
|
|
23
24
|
view: Type.TOptional<Type.TString>;
|
|
24
25
|
lines: Type.TOptional<Type.TInteger>;
|
|
@@ -150,6 +151,7 @@ export declare const SubagentOptionParams: Type.TObject<{
|
|
|
150
151
|
supersession: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
151
152
|
index: Type.TOptional<Type.TInteger>;
|
|
152
153
|
childId: Type.TOptional<Type.TString>;
|
|
154
|
+
drain: Type.TOptional<Type.TBoolean>;
|
|
153
155
|
toolCallId: Type.TOptional<Type.TString>;
|
|
154
156
|
view: Type.TOptional<Type.TString>;
|
|
155
157
|
lines: Type.TOptional<Type.TInteger>;
|
package/src/extension/schemas.js
CHANGED
|
@@ -159,6 +159,7 @@ const SubagentParamProperties = {
|
|
|
159
159
|
supersession: Type.Optional(Type.Unsafe({ type: "object", additionalProperties: true, description: "lane.recordSupersession evidence; read guide tool-reference." })),
|
|
160
160
|
index: Type.Optional(Type.Integer({ minimum: 0, description: "Zero-based child/transcript index." })),
|
|
161
161
|
childId: Type.Optional(Type.String({ minLength: 1, maxLength: 256, description: "Child-scoped stop identity." })),
|
|
162
|
+
drain: Type.Optional(Type.Boolean({ description: "stop: a live async workflow starts no new children; started ones finish." })),
|
|
162
163
|
toolCallId: Type.Optional(Type.String({ description: "Command tool-call id." })),
|
|
163
164
|
view: Type.Optional(Type.String({
|
|
164
165
|
enum: ["fleet", "transcript"],
|
|
@@ -56,7 +56,16 @@ function applyRecordedSelection(pi, ctx, mode, replyOwed) {
|
|
|
56
56
|
if (!available.some((tool) => tool.name === LOADER_NAME))
|
|
57
57
|
return true;
|
|
58
58
|
// SAFETY: The running Pi session manager exposes buildSessionContext, but its read-only extension type omits it.
|
|
59
|
-
|
|
59
|
+
let messages = ctx.sessionManager.buildSessionContext().messages;
|
|
60
|
+
// A compaction checkpoint (the system message before the summary) folds the branch's earlier system messages into
|
|
61
|
+
// one declaration, which hides an extension unload before the compaction. Replay those messages instead, as Pi
|
|
62
|
+
// restores the session's tools from them.
|
|
63
|
+
if (messages[0]?.role === "system" && messages[1]?.role === "compactionSummary") {
|
|
64
|
+
const branch = ctx.sessionManager.getBranch();
|
|
65
|
+
const history = branch.slice(0, branch.findLastIndex((entry) => entry.type === "compaction"))
|
|
66
|
+
.flatMap((entry) => entry.type === "message" && entry.message.role === "system" ? [entry.message] : []);
|
|
67
|
+
messages = [...history, ...messages.slice(1)];
|
|
68
|
+
}
|
|
60
69
|
// A compaction without a checkpoint leaves its summary first, with no system message before it: the
|
|
61
70
|
// declarations from before it are lost, even when no tool selection was recorded after it.
|
|
62
71
|
const lost = messages.find((message) => message.role === "system" || message.role === "compactionSummary")?.role === "compactionSummary";
|