@xzzpig/pi-subagents 0.24.1 → 0.25.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 +28 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-ZWXU5SPQ.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-6BJUEES3.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-SLNMBXLL.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-LMGQAJ3O.js → chunk-KCJFGKVK.js} +350 -123
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-Y6H2G6KX.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-TGLFTQWJ.js → chunk-YWXILP5N.js} +5 -4
- 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 +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/node_modules/@xzzpig/pi-components/CHANGELOG.md +12 -0
- package/node_modules/@xzzpig/pi-components/README.md +94 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.d.ts +186 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.js +693 -0
- package/node_modules/@xzzpig/pi-components/package.json +5 -1
- package/package.json +4 -4
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- 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.d.ts +0 -3
- package/src/runs/foreground/execution.js +56 -24
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- 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/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- 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 +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -12,6 +12,55 @@ export declare function validateCodeOwnedProfileRunner(agent: {
|
|
|
12
12
|
adapter?: string;
|
|
13
13
|
};
|
|
14
14
|
}): string | undefined;
|
|
15
|
+
export declare const EXTERNAL_CLI_ADAPTER_SAFETY: {
|
|
16
|
+
readonly "codex-exec": {
|
|
17
|
+
readonly sandbox: "read-only";
|
|
18
|
+
readonly approvalPolicy: "never";
|
|
19
|
+
readonly ephemeral: true;
|
|
20
|
+
};
|
|
21
|
+
readonly "codex-exec-writer": {
|
|
22
|
+
readonly access: "workspace-write";
|
|
23
|
+
readonly sandbox: "workspace-write";
|
|
24
|
+
readonly approvalPolicy: "never";
|
|
25
|
+
readonly ephemeral: true;
|
|
26
|
+
};
|
|
27
|
+
readonly "claude-code": {
|
|
28
|
+
readonly access: "read-only";
|
|
29
|
+
readonly authentication: "existing-cli-required";
|
|
30
|
+
readonly permissionMode: "plan";
|
|
31
|
+
readonly tools: "none";
|
|
32
|
+
readonly mcp: "empty-strict";
|
|
33
|
+
readonly settingSources: "user";
|
|
34
|
+
readonly userSettingsTrust: "required";
|
|
35
|
+
readonly sessionPersistence: false;
|
|
36
|
+
};
|
|
37
|
+
readonly "claude-code-writer": {
|
|
38
|
+
readonly access: "workspace-write";
|
|
39
|
+
readonly authentication: "existing-cli-required";
|
|
40
|
+
readonly permissionMode: "acceptEdits";
|
|
41
|
+
readonly tools: "Read,Write,Edit,Glob,Grep";
|
|
42
|
+
readonly mcp: "empty-strict";
|
|
43
|
+
readonly settingSources: "user";
|
|
44
|
+
readonly userSettingsTrust: "required";
|
|
45
|
+
readonly sessionPersistence: false;
|
|
46
|
+
};
|
|
47
|
+
readonly "cursor-agent": {
|
|
48
|
+
readonly access: "read-only";
|
|
49
|
+
readonly authentication: "cursor-api-key-or-existing-login";
|
|
50
|
+
readonly mode: "ask";
|
|
51
|
+
readonly sandbox: "enabled";
|
|
52
|
+
readonly workspaceTrust: "existing-required";
|
|
53
|
+
readonly sessionReuse: false;
|
|
54
|
+
};
|
|
55
|
+
readonly "cursor-agent-writer": {
|
|
56
|
+
readonly access: "workspace-write";
|
|
57
|
+
readonly authentication: "cursor-api-key-or-existing-login";
|
|
58
|
+
readonly mode: "print";
|
|
59
|
+
readonly sandbox: "enabled";
|
|
60
|
+
readonly workspaceTrust: "existing-required";
|
|
61
|
+
readonly sessionReuse: false;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
15
64
|
export declare function parseExternalCliCapabilityNarrowing(value: unknown, label: string): ExternalCliCapabilityNarrowing | undefined;
|
|
16
65
|
export declare function resolveExternalCliRunnerStatus(input: {
|
|
17
66
|
adapter?: CodeOwnedExternalCliAdapterId;
|
|
@@ -40,6 +40,16 @@ export function validateCodeOwnedProfileRunner(agent) {
|
|
|
40
40
|
}
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
|
+
// What each adapter's own argv asks the CLI for. It is a profile, not a measurement:
|
|
44
|
+
// a runner command that wraps the CLI can grant something else.
|
|
45
|
+
export const EXTERNAL_CLI_ADAPTER_SAFETY = {
|
|
46
|
+
"codex-exec": { sandbox: "read-only", approvalPolicy: "never", ephemeral: true },
|
|
47
|
+
"codex-exec-writer": { access: "workspace-write", sandbox: "workspace-write", approvalPolicy: "never", ephemeral: true },
|
|
48
|
+
"claude-code": { access: "read-only", authentication: "existing-cli-required", permissionMode: "plan", tools: "none", mcp: "empty-strict", settingSources: "user", userSettingsTrust: "required", sessionPersistence: false },
|
|
49
|
+
"claude-code-writer": { access: "workspace-write", authentication: "existing-cli-required", permissionMode: "acceptEdits", tools: "Read,Write,Edit,Glob,Grep", mcp: "empty-strict", settingSources: "user", userSettingsTrust: "required", sessionPersistence: false },
|
|
50
|
+
"cursor-agent": { access: "read-only", authentication: "cursor-api-key-or-existing-login", mode: "ask", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false },
|
|
51
|
+
"cursor-agent-writer": { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false },
|
|
52
|
+
};
|
|
43
53
|
export function parseExternalCliCapabilityNarrowing(value, label) {
|
|
44
54
|
if (value === undefined)
|
|
45
55
|
return undefined;
|
|
@@ -56,13 +66,8 @@ export function parseExternalCliCapabilityNarrowing(value, label) {
|
|
|
56
66
|
return input;
|
|
57
67
|
}
|
|
58
68
|
export function resolveExternalCliRunnerStatus(input) {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const claudeCode = input.adapter === "claude-code";
|
|
62
|
-
const claudeCodeWriter = input.adapter === "claude-code-writer";
|
|
63
|
-
const cursorAgent = input.adapter === "cursor-agent";
|
|
64
|
-
const cursorAgentWriter = input.adapter === "cursor-agent-writer";
|
|
65
|
-
const cursor = cursorAgent || cursorAgentWriter;
|
|
69
|
+
const cursor = input.adapter === "cursor-agent" || input.adapter === "cursor-agent-writer";
|
|
70
|
+
const profileSafety = input.adapter ? EXTERNAL_CLI_ADAPTER_SAFETY[input.adapter] : undefined;
|
|
66
71
|
const unsupported = cursor ? PROMPT_FILE_UNSUPPORTED : UNSUPPORTED;
|
|
67
72
|
return {
|
|
68
73
|
type: "external-cli",
|
|
@@ -70,12 +75,11 @@ export function resolveExternalCliRunnerStatus(input) {
|
|
|
70
75
|
args: input.args ?? [],
|
|
71
76
|
promptDelivery: cursor ? "prompt-file" : input.promptDelivery ?? "stdin",
|
|
72
77
|
adapter: { id: input.adapter ?? "external-cli", version: 1, executionMode: cursor ? "one-shot-prompt-file" : "one-shot-stdin" },
|
|
73
|
-
...(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...(cursorAgentWriter ? { safety: { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false } } : {}),
|
|
78
|
+
...(profileSafety ? {
|
|
79
|
+
safety: { ...profileSafety },
|
|
80
|
+
// A Herdr saved machine launches the remote adapter binary, never runner.command.
|
|
81
|
+
safetySource: { measured: false, ...(input.machine ? {} : { command: input.command }) },
|
|
82
|
+
} : {}),
|
|
79
83
|
...(input.machine ? { machine: input.machine } : {}),
|
|
80
84
|
capabilities: {
|
|
81
85
|
stop: true,
|
|
@@ -131,6 +135,7 @@ export function externalCliReceiptMetadata(input) {
|
|
|
131
135
|
capabilities: { ...runner.capabilities },
|
|
132
136
|
...(machine ? { machine: { ...machine, ...(machine.remoteGit ? { remoteGit: { ...machine.remoteGit } } : {}) } } : {}),
|
|
133
137
|
...(runner.safety ? { safety: { ...runner.safety } } : {}),
|
|
138
|
+
...(runner.safetySource ? { safetySource: { ...runner.safetySource } } : {}),
|
|
134
139
|
...(input.externalProcess ? {
|
|
135
140
|
outputArtifacts: {
|
|
136
141
|
stdoutPath: input.externalProcess.stdoutPath,
|
|
@@ -15,7 +15,9 @@ const MAX_PARSER_LINE_BYTES = 256 * 1024;
|
|
|
15
15
|
const MAX_PARSER_STREAM_BYTES = 32 * 1024 * 1024;
|
|
16
16
|
const MAX_PARSER_OUTPUT_BYTES = 1024 * 1024;
|
|
17
17
|
const MAX_OVERSIZED_LINE_PREFIX_BYTES = 512;
|
|
18
|
-
|
|
18
|
+
// A skipped line keeps only its prefix in memory, and the stream limit still bounds the run.
|
|
19
|
+
// Claude Code puts a read image's base64 in its tool-result line twice.
|
|
20
|
+
const MAX_SKIPPABLE_LINE_BYTES = 8 * 1024 * 1024;
|
|
19
21
|
const PARSER_PROGRESS_INTERVAL_MS = 100;
|
|
20
22
|
export function buildExternalCliPrompt(systemInstructions, task) {
|
|
21
23
|
return `<System instructions>\n${systemInstructions.trim()}\n\n<Task>\n${task}`;
|
|
@@ -196,6 +198,22 @@ export function runExternalCli(input) {
|
|
|
196
198
|
let processTree;
|
|
197
199
|
let processPid;
|
|
198
200
|
let termination;
|
|
201
|
+
// A throwing onProcess fails the run only after the process is stopped and temp paths are removed.
|
|
202
|
+
let callbackFailed = false;
|
|
203
|
+
let callbackError;
|
|
204
|
+
const notifyProcess = (status) => {
|
|
205
|
+
try {
|
|
206
|
+
input.onProcess?.(status);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (callbackFailed)
|
|
210
|
+
return;
|
|
211
|
+
callbackFailed = true;
|
|
212
|
+
callbackError = error;
|
|
213
|
+
if (!settled && processTree && processPid !== undefined)
|
|
214
|
+
termination ??= terminateExternalProcessTree(processPid, processTree);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
199
217
|
const flushProgress = () => {
|
|
200
218
|
if (!latestProgress)
|
|
201
219
|
return;
|
|
@@ -217,7 +235,7 @@ export function runExternalCli(input) {
|
|
|
217
235
|
progressTimer.unref?.();
|
|
218
236
|
};
|
|
219
237
|
const terminate = (reason) => {
|
|
220
|
-
if (settled || timedOut || stopped || parserError)
|
|
238
|
+
if (settled || timedOut || stopped || parserError || callbackFailed)
|
|
221
239
|
return;
|
|
222
240
|
timedOut = reason === "timeout";
|
|
223
241
|
stopped = reason === "stop";
|
|
@@ -323,7 +341,7 @@ export function runExternalCli(input) {
|
|
|
323
341
|
stderrPath,
|
|
324
342
|
...(input.finalOutputPath ? { finalOutputPath: input.finalOutputPath } : {}),
|
|
325
343
|
};
|
|
326
|
-
|
|
344
|
+
notifyProcess(initialProcess);
|
|
327
345
|
child.stdout.on("data", (chunk) => {
|
|
328
346
|
parseChunk(chunk);
|
|
329
347
|
writeBoundedLog(child.stdout, stdoutStream, chunk, stdoutLog, limits.stdoutLogBytes);
|
|
@@ -380,7 +398,7 @@ export function runExternalCli(input) {
|
|
|
380
398
|
...(stdoutLog.total > stdoutLog.bytes ? { stdoutTruncated: true } : {}),
|
|
381
399
|
...(stderrLog.total > stderrLog.bytes ? { stderrTruncated: true } : {}),
|
|
382
400
|
};
|
|
383
|
-
|
|
401
|
+
notifyProcess(externalProcess);
|
|
384
402
|
const stderr = stderrTail.text().trim();
|
|
385
403
|
const parserFailure = parserError?.message ?? (parserTerminal?.state === "failed" ? parserTerminal.error ?? "External CLI parser reported terminal failure." : undefined);
|
|
386
404
|
const treeFailure = process.platform !== "win32" && treeProof?.state === "unknown"
|
|
@@ -415,11 +433,13 @@ export function runExternalCli(input) {
|
|
|
415
433
|
reject(cleanupError);
|
|
416
434
|
return;
|
|
417
435
|
}
|
|
418
|
-
if (
|
|
436
|
+
if (callbackFailed)
|
|
437
|
+
reject(callbackError);
|
|
438
|
+
else if (streamFailure?.status === "rejected")
|
|
419
439
|
reject(streamFailure.reason);
|
|
420
440
|
else
|
|
421
441
|
resolve(result);
|
|
422
|
-
})();
|
|
442
|
+
})().catch(reject);
|
|
423
443
|
});
|
|
424
444
|
});
|
|
425
445
|
}
|
|
@@ -238,7 +238,8 @@ function openSshSockets(machine, options) {
|
|
|
238
238
|
if (!path.posix.isAbsolute(remotePath))
|
|
239
239
|
throw new Error("Remote socket path must be absolute.");
|
|
240
240
|
const local = path.join(dir, `${name}.sock`);
|
|
241
|
-
|
|
241
|
+
// Some sshd policies drop sessions that run no command (`ssh -N`). The remote command reads the open stdin pipe, so it ends on EOF when the connection closes; a non-tty `sleep` would outlive the forwarder.
|
|
242
|
+
const child = spawn(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), "-o", "StreamLocalBindUnlink=yes", "-L", `${local}:${remotePath}`, machine.target, remoteShellCommand("exec cat >/dev/null")], { env: hardenedSshEnv(options.env), stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
|
|
242
243
|
children.add(child);
|
|
243
244
|
const stop = async () => { await terminateChild(child); children.delete(child); try {
|
|
244
245
|
fs.rmSync(local, { force: true });
|
|
@@ -2,7 +2,7 @@ import type { HerdrMachineReference, PlacementMachineReference } from "../../sha
|
|
|
2
2
|
import { type HerdrForwardedConnection, type HerdrRpcClient } from "./herdr-connection.ts";
|
|
3
3
|
import type { HerdrRunIdentity } from "./herdr-placed-run.ts";
|
|
4
4
|
import { PlacedRunOwner, type PlacedBridgeManifest } from "./placed-run-owner.ts";
|
|
5
|
-
import { type PlacementAgentKind, type PlacementBridgeIdentity, type PlacementEvidenceProof, type PlacementOwnedPane, type PlacementReconnectCheck, type PlacementRunState, type PlacementStartOptions } from "./placement-host.ts";
|
|
5
|
+
import { type PlacementAgentKind, type PlacementBridgeIdentity, type PlacementEvidenceProof, type PlacementOwnedPane, type PlacementPromptOptions, type PlacementReconnectCheck, type PlacementRunState, type PlacementStartOptions } from "./placement-host.ts";
|
|
6
6
|
export interface HerdrPaneCandidate {
|
|
7
7
|
endpoint: {
|
|
8
8
|
session: string | null;
|
|
@@ -43,7 +43,7 @@ export declare const herdrPaneHost: {
|
|
|
43
43
|
owned: PlacementOwnedPane;
|
|
44
44
|
terminalId: string;
|
|
45
45
|
}>;
|
|
46
|
-
prompt(connection: HerdrForwardedConnection, identity: HerdrRunIdentity, text: string): Promise<void>;
|
|
46
|
+
prompt(connection: HerdrForwardedConnection, identity: HerdrRunIdentity, text: string, options?: PlacementPromptOptions): Promise<void>;
|
|
47
47
|
subscribe(connection: HerdrForwardedConnection, paneId: string, listener: (event: unknown) => void, onDisconnect: (error: Error) => void): Promise<() => void>;
|
|
48
48
|
paneEvent(event: unknown, fallback: PlacementRunState): {
|
|
49
49
|
terminalId: unknown;
|
|
@@ -104,7 +104,23 @@ export const herdrPaneHost = {
|
|
|
104
104
|
connect(machine) { return connectHerdrMachine(asHerdrMachine(machine)); },
|
|
105
105
|
sessionOf(connection) { return connection.endpoint.session; },
|
|
106
106
|
async launch(connection, machine, runId, runtimeDir, request, onPane, options) { const owned = await provisionHerdrOwnedPane(connection, asHerdrMachine(machine), runId, runtimeDir, request.environment); await onPane(owned); const { terminalId } = await startHerdrAgent(connection, owned, request.kind, request.name, request.args, options); return { owned, terminalId }; },
|
|
107
|
-
async prompt(connection, identity, text
|
|
107
|
+
async prompt(connection, identity, text, options = {}) {
|
|
108
|
+
// Herdr registers a started agent's name asynchronously, so a prompt right after start can be refused; a refused prompt was not delivered.
|
|
109
|
+
const clock = options.clock ?? { now: () => Date.now(), wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }, deadline = clock.now() + (options.timeoutMs ?? 5_000), pollMs = options.pollMs ?? 100;
|
|
110
|
+
for (;;) {
|
|
111
|
+
try {
|
|
112
|
+
await connection.client.call("agent.prompt", { target: identity.agentName, text });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (!(error instanceof Error) || !error.message.includes("is not an active named agent") || clock.now() >= deadline)
|
|
117
|
+
throw error;
|
|
118
|
+
await clock.wait(Math.min(pollMs, deadline - clock.now()));
|
|
119
|
+
if (options.stopped?.())
|
|
120
|
+
throw new Error("Remote Pi prompt was not sent because the run was stopped.", { cause: error });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
108
124
|
subscribe(connection, paneId, listener, onDisconnect) { return connection.client.subscribe(herdrStatusSubscriptions(paneId), listener, onDisconnect); },
|
|
109
125
|
paneEvent(event, fallback) { const data = event && typeof event === "object" ? event.data : undefined; return data ? { terminalId: data.terminal_id, paneId: data.pane_id, state: herdrRunState(data.agent_status, fallback) } : undefined; },
|
|
110
126
|
async panes(connection) { return { endpoint: connection.endpoint, agents: snapshotAgents(parseHerdrSessionSnapshot(await connection.client.call("session.snapshot"))) }; },
|
|
@@ -7,6 +7,7 @@ import { herdrPaneHost, HerdrPlacedRunOwner } from "./herdr-pane-host.js";
|
|
|
7
7
|
import { encodeHerdrPiFrame, HERDR_PI_MODE_ENV, HERDR_PI_PROTOCOL, HERDR_PI_RUN_ENV, HERDR_PI_RUNTIME_DIR_ENV, HerdrPiFrameDecoder, validateHerdrPiRunId } from "./herdr-pi-protocol.js";
|
|
8
8
|
import { discoverPlacedBridgeManifest } from "./placed-run-owner.js";
|
|
9
9
|
import { RexPlacedRunOwner } from "./rex-pane-host.js";
|
|
10
|
+
import { ensureSupervisorChannelDir } from "../../intercom/native-supervisor-channel.js";
|
|
10
11
|
import { isRexLocalMachine } from "./rex-machine.js";
|
|
11
12
|
import { PLACED_RESTORE_UNSUPPORTED } from "./herdr-machine.js";
|
|
12
13
|
import { hasUnsupportedPlacedProcessEnv } from "./fork-placed-env.js";
|
|
@@ -137,21 +138,35 @@ export class HerdrPiSession {
|
|
|
137
138
|
#reconnectFactory;
|
|
138
139
|
#reconnectFailure;
|
|
139
140
|
#replyTimer;
|
|
141
|
+
#repliesInFlight = new Set();
|
|
140
142
|
supervisorDir;
|
|
141
143
|
runtime;
|
|
142
144
|
owner;
|
|
143
145
|
constructor(owner, bridgeForward, bridge, requestedTools, model, runtime, initialGit) { this.owner = owner; this.bridgeForward = bridgeForward; this.bridge = bridge; this.requestedTools = requestedTools; this.model = model; this.runtime = runtime; this.supervisorDir = runtime.supervisorChannelDir; this.#initialGit = initialGit; bridge.adopt((frame) => this.#frame(frame)); if (this.supervisorDir) {
|
|
144
|
-
this.#replyTimer = setInterval(() =>
|
|
145
|
-
const file = path.join(replies, name);
|
|
146
|
-
try {
|
|
147
|
-
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
148
|
-
if (typeof value.message === "string" && typeof value.requestId === "string")
|
|
149
|
-
void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : undefined).then(() => fs.rmSync(file, { force: true }));
|
|
150
|
-
}
|
|
151
|
-
catch { }
|
|
152
|
-
} }, 50);
|
|
146
|
+
this.#replyTimer = setInterval(() => this.#deliverSupervisorReplies(this.supervisorDir), 50);
|
|
153
147
|
this.#replyTimer.unref?.();
|
|
154
148
|
} }
|
|
149
|
+
// Runs on a timer, where a throw or an unhandled rejection exits Pi. A reply that can't be read or delivered stays
|
|
150
|
+
// on disk for the next tick, once its earlier delivery has settled; a lost transport reaches the session through the
|
|
151
|
+
// bridge failure.
|
|
152
|
+
#deliverSupervisorReplies(supervisorDir) { const replies = path.join(supervisorDir, "replies"); let names; try {
|
|
153
|
+
names = fs.existsSync(replies) ? fs.readdirSync(replies) : [];
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return;
|
|
157
|
+
} for (const name of names) {
|
|
158
|
+
const file = path.join(replies, name);
|
|
159
|
+
if (this.#repliesInFlight.has(file))
|
|
160
|
+
continue;
|
|
161
|
+
try {
|
|
162
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
163
|
+
if (typeof value.message === "string" && typeof value.requestId === "string") {
|
|
164
|
+
this.#repliesInFlight.add(file);
|
|
165
|
+
void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : undefined).then(() => fs.rmSync(file, { force: true })).catch(() => { }).finally(() => this.#repliesInFlight.delete(file));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch { }
|
|
169
|
+
} }
|
|
155
170
|
get host() { return this.owner.host; }
|
|
156
171
|
get identity() { return this.owner.identity; }
|
|
157
172
|
set identity(value) { this.owner.identity = value; }
|
|
@@ -219,23 +234,34 @@ export class HerdrPiSession {
|
|
|
219
234
|
for (const listener of this.#listeners)
|
|
220
235
|
listener({ type: "agent_settled" });
|
|
221
236
|
} }
|
|
222
|
-
#relaySupervisor(frame) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
#relaySupervisor(frame) {
|
|
238
|
+
if (!this.supervisorDir || typeof frame.requestId !== "string")
|
|
239
|
+
return;
|
|
240
|
+
const reason = frame.reason;
|
|
241
|
+
if (reason !== "need_decision" && reason !== "interview_request" && reason !== "progress_update")
|
|
242
|
+
return;
|
|
243
|
+
const createdAt = Date.now();
|
|
244
|
+
const file = path.join(this.supervisorDir, "requests", `${path.basename(frame.requestId)}.json`);
|
|
245
|
+
const request = { type: "subagent.supervisor.request", id: frame.requestId, createdAt, ...(reason !== "progress_update" ? { expiresAt: createdAt + 10 * 60_000 } : {}), reason, message: typeof frame.message === "string" ? frame.message : "", ...(frame.interview && typeof frame.interview === "object" ? { interview: frame.interview } : {}), expectsReply: reason !== "progress_update", runId: this.runtime.runId ?? this.identity.runId, agent: this.runtime.agent ?? "remote", childIndex: this.runtime.childIndex ?? 0, orchestratorSessionId: this.runtime.orchestratorSessionId };
|
|
246
|
+
// The parent's stale-channel cleanup removes an idle channel's empty directories after a minute.
|
|
247
|
+
ensureSupervisorChannelDir(this.supervisorDir);
|
|
248
|
+
try {
|
|
249
|
+
fs.writeFileSync(file, JSON.stringify(request), { mode: 0o600, flag: "wx" });
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (error.code !== "EEXIST")
|
|
253
|
+
throw error;
|
|
254
|
+
const existing = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
255
|
+
if (existing.id !== frame.requestId || existing.reason !== reason)
|
|
256
|
+
throw new Error("Supervisor relay identity changed during replay.");
|
|
257
|
+
}
|
|
258
|
+
if (reason === "progress_update")
|
|
259
|
+
this.bridge.supervisorDelivered(frame.requestId);
|
|
226
260
|
}
|
|
227
|
-
catch (error) {
|
|
228
|
-
if (error.code !== "EEXIST")
|
|
229
|
-
throw error;
|
|
230
|
-
const existing = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
231
|
-
if (existing.id !== frame.requestId || existing.reason !== reason)
|
|
232
|
-
throw new Error("Supervisor relay identity changed during replay.");
|
|
233
|
-
} if (reason === "progress_update")
|
|
234
|
-
this.bridge.supervisorDelivered(frame.requestId); }
|
|
235
261
|
async #operation(operation, text, supervisorId, supervisorError) { const requestId = `${++this.#sequence}_${randomBytes(5).toString("hex")}`; let completion = Promise.resolve(); if (operation === "prompt")
|
|
236
262
|
completion = new Promise((resolve, reject) => this.#operations.set(requestId, { resolve, reject, accepted: false, settled: false })); try {
|
|
237
263
|
await Promise.race([this.bridge.prepare(requestId, operation, text, supervisorId, supervisorError), this.bridge.failure]);
|
|
238
|
-
await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}
|
|
264
|
+
await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}`, operation === "abort" ? {} : { stopped: () => this.#aborted || this.#disposed });
|
|
239
265
|
await completion;
|
|
240
266
|
}
|
|
241
267
|
catch (error) {
|
|
@@ -374,7 +400,8 @@ async function startPlacedPiSession(launch, owner, policy) {
|
|
|
374
400
|
}
|
|
375
401
|
function createPlacedPiSession(launch) { return launch.machine?.provider === "rex" ? createRexPiSession(launch) : createHerdrPiSession(launch); }
|
|
376
402
|
export function createPlacementAwareChildSessionFactory(local, createRemote = createPlacedPiSession) {
|
|
377
|
-
const remote = new
|
|
403
|
+
const remote = new Map();
|
|
378
404
|
return { async create(launch) { if (!launch.machine)
|
|
379
|
-
return local.create(launch); serializeHerdrPiLaunch(launch); const child = await createRemote(launch); remote.
|
|
405
|
+
return local.create(launch); serializeHerdrPiLaunch(launch); const child = await createRemote(launch); remote.set(child, launch.parentSessionFile); return child; }, async dispose() { await Promise.allSettled([...remote.keys()].map((child) => child.dispose())); remote.clear(); await local.dispose(); }, async disposeForParent(parentSessionFile) { const matching = [...remote].filter(([, parent]) => parent === parentSessionFile).map(([child]) => child); await Promise.allSettled(matching.map((child) => child.dispose())); for (const child of matching)
|
|
406
|
+
remote.delete(child); await local.disposeForParent(parentSessionFile); } };
|
|
380
407
|
}
|
|
@@ -8,7 +8,6 @@ export declare const WORKFLOW_LANE_OUTPUT_PATHS_MAX = 10;
|
|
|
8
8
|
export declare const WORKTREE_STATUS_PATH_MAX_BYTES = 4096;
|
|
9
9
|
export declare const WORKTREE_STATUS_BRANCH_MAX_BYTES = 256;
|
|
10
10
|
export declare const WORKTREE_STATUS_NAMING_LABEL_MAX_BYTES = 256;
|
|
11
|
-
/** Normalize and validate launch-declared lane metadata. */
|
|
12
11
|
export declare function normalizeWorkflowLaneMetadata(value: unknown, label?: string): WorkflowLaneMetadata | undefined;
|
|
13
12
|
export declare function assertWorkflowLaneKey(lane: WorkflowLaneMetadata | undefined, workflowKey: string | undefined, label?: string): void;
|
|
14
13
|
export interface WorktreeStatusReference {
|
|
@@ -43,7 +43,6 @@ function boundedStringArray(value, label, maxItems, maxBytes) {
|
|
|
43
43
|
return boundedNonEmptyString(entry, `${label}[${index}]`, maxBytes);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
/** Normalize and validate launch-declared lane metadata. */
|
|
47
46
|
export function normalizeWorkflowLaneMetadata(value, label = "lane") {
|
|
48
47
|
if (value === undefined)
|
|
49
48
|
return undefined;
|
|
@@ -22,11 +22,14 @@ export interface McpServerDefinition {
|
|
|
22
22
|
/** Per-server override of the global `settings.toolPrefix`, matching the adapter. */
|
|
23
23
|
toolPrefix?: McpToolPrefix;
|
|
24
24
|
protocolVersion?: string;
|
|
25
|
-
|
|
25
|
+
/** Validated so adapter configs load; `mcp:` selectors do not read it. */
|
|
26
|
+
directTools?: boolean | string[] | "search";
|
|
26
27
|
httpTransport?: string;
|
|
27
28
|
pluginDataDir?: string;
|
|
28
29
|
literalEnv?: boolean;
|
|
29
30
|
inheritEnv?: boolean;
|
|
31
|
+
/** Only literal true disables a server, matching pi-mcp-adapter. */
|
|
32
|
+
disabled?: boolean;
|
|
30
33
|
}
|
|
31
34
|
export declare function isMcpServerDefinition(value: unknown): value is McpServerDefinition;
|
|
32
35
|
export declare function loadPackageMcpServers(cwd: string): Record<string, McpServerDefinition>;
|
|
@@ -33,7 +33,7 @@ export function isMcpServerDefinition(value) {
|
|
|
33
33
|
return false;
|
|
34
34
|
if (value.auth !== undefined && value.auth !== "oauth" && value.auth !== "bearer" && value.auth !== false)
|
|
35
35
|
return false;
|
|
36
|
-
return value.directTools === undefined || typeof value.directTools === "boolean" || isStringArray(value.directTools);
|
|
36
|
+
return value.directTools === undefined || typeof value.directTools === "boolean" || value.directTools === "search" || isStringArray(value.directTools);
|
|
37
37
|
}
|
|
38
38
|
function isRecord(value) {
|
|
39
39
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -17,7 +17,6 @@ export interface McpConfig {
|
|
|
17
17
|
imports?: ImportKind[];
|
|
18
18
|
settings?: {
|
|
19
19
|
toolPrefix?: McpToolPrefix;
|
|
20
|
-
directTools?: boolean;
|
|
21
20
|
agentPluginPaths?: unknown;
|
|
22
21
|
};
|
|
23
22
|
}
|
|
@@ -74,7 +73,6 @@ export interface McpDirectToolResolution {
|
|
|
74
73
|
builtin?: true;
|
|
75
74
|
}
|
|
76
75
|
export declare function resolveMcpDirectToolResolution(mcpDirectTools: string[] | undefined, cwd?: string, runtimeSnapshotHost?: McpRuntimeSnapshotHost, configOverride?: McpConfig): McpDirectToolResolution;
|
|
77
|
-
export declare function resolveMcpDirectToolSelections(mcpDirectTools: string[] | undefined, cwd?: string, runtimeSnapshotHost?: McpRuntimeSnapshotHost): ResolvedMcpDirectToolSelection[];
|
|
78
76
|
export declare function formatUnresolvedBuiltinMcpSelectors(agentName: string | undefined, selectors: readonly string[]): string;
|
|
79
77
|
/**
|
|
80
78
|
* Selected servers that only an extension registered, which a child without ambient extensions
|
|
@@ -82,5 +80,4 @@ export declare function formatUnresolvedBuiltinMcpSelectors(agentName: string |
|
|
|
82
80
|
* the project file is read only when the project is trusted.
|
|
83
81
|
*/
|
|
84
82
|
export declare function extensionOnlyMcpServers(selections: readonly ResolvedMcpDirectToolSelection[], host: McpRuntimeSnapshotHost, cwd: string, projectTrusted: boolean): string[];
|
|
85
|
-
export declare function resolveMcpDirectToolNames(mcpDirectTools: string[] | undefined, cwd?: string): string[];
|
|
86
83
|
export declare function computeMcpServerHash(definition: ServerEntry): string;
|
|
@@ -38,21 +38,26 @@ export function resolveMcpDirectToolResolution(mcpDirectTools, cwd = process.cwd
|
|
|
38
38
|
const resolvedConfig = Object.keys(runtimeServers).length > 0
|
|
39
39
|
? mergeConfigs(config, { mcpServers: runtimeServers })
|
|
40
40
|
: config;
|
|
41
|
-
|
|
41
|
+
const enabledSelectors = selectors.filter((selector) => resolvedConfig.mcpServers[selector.split("/", 1)[0]]?.disabled !== true);
|
|
42
|
+
validateSelectedServerDefinitions(resolvedConfig, enabledSelectors);
|
|
42
43
|
const runtime = Object.keys(runtimeServers).length > 0
|
|
43
44
|
? { mcpConfig: resolvedConfig, runtimeServerNames: Object.keys(runtimeServers) }
|
|
44
45
|
: {};
|
|
46
|
+
if (enabledSelectors.length === 0)
|
|
47
|
+
return { selections: [], unresolvedSelectors: [], ...runtime };
|
|
45
48
|
const cache = loadMetadataCache();
|
|
46
49
|
if (!cache)
|
|
47
|
-
return { selections: [], unresolvedSelectors:
|
|
50
|
+
return { selections: [], unresolvedSelectors: enabledSelectors, ...runtime };
|
|
48
51
|
const validMetadata = {};
|
|
49
52
|
for (const [serverName, definition] of Object.entries(resolvedConfig.mcpServers)) {
|
|
53
|
+
if (definition.disabled === true)
|
|
54
|
+
continue;
|
|
50
55
|
const serverCache = cache.servers[serverName];
|
|
51
56
|
if (isServerCacheValid(serverCache, definition))
|
|
52
57
|
validMetadata[serverName] = serverCache;
|
|
53
58
|
}
|
|
54
59
|
const grant = planMcpDirectToolGrant({
|
|
55
|
-
selectors,
|
|
60
|
+
selectors: enabledSelectors,
|
|
56
61
|
servers: resolvedConfig.mcpServers,
|
|
57
62
|
metadata: validMetadata,
|
|
58
63
|
toolPrefix: resolvedConfig.settings?.toolPrefix,
|
|
@@ -63,9 +68,6 @@ export function resolveMcpDirectToolResolution(mcpDirectTools, cwd = process.cwd
|
|
|
63
68
|
...runtime,
|
|
64
69
|
};
|
|
65
70
|
}
|
|
66
|
-
export function resolveMcpDirectToolSelections(mcpDirectTools, cwd = process.cwd(), runtimeSnapshotHost) {
|
|
67
|
-
return resolveMcpDirectToolResolution(mcpDirectTools, cwd, runtimeSnapshotHost).selections;
|
|
68
|
-
}
|
|
69
71
|
/**
|
|
70
72
|
* pi-mcp-adapter keeps priority whenever it is loaded. 2.x registers /mcp, so Pi does not load its
|
|
71
73
|
* built-in MCP. 3.x always registers /mcp-adapter and leaves /mcp to the built-in MCP.
|
|
@@ -292,10 +294,8 @@ function parseSettings(value) {
|
|
|
292
294
|
if (!isRecord(value))
|
|
293
295
|
return undefined;
|
|
294
296
|
const toolPrefix = value.toolPrefix === "server" || value.toolPrefix === "short" || value.toolPrefix === "none" || value.toolPrefix === "mcp" ? value.toolPrefix : undefined;
|
|
295
|
-
const directTools = typeof value.directTools === "boolean" ? value.directTools : undefined;
|
|
296
297
|
const settings = {
|
|
297
298
|
...(toolPrefix ? { toolPrefix } : {}),
|
|
298
|
-
...(directTools !== undefined ? { directTools } : {}),
|
|
299
299
|
...(value.agentPluginPaths !== undefined ? { agentPluginPaths: value.agentPluginPaths } : {}),
|
|
300
300
|
};
|
|
301
301
|
return Object.keys(settings).length ? settings : undefined;
|
|
@@ -303,11 +303,22 @@ function parseSettings(value) {
|
|
|
303
303
|
function mergeConfigs(base, next) {
|
|
304
304
|
const imports = [...(base.imports ?? []), ...(next.imports ?? [])];
|
|
305
305
|
return {
|
|
306
|
-
mcpServers:
|
|
306
|
+
mcpServers: mergeServerDefinitions(base.mcpServers, next.mcpServers),
|
|
307
307
|
imports: imports.length ? [...new Set(imports)] : undefined,
|
|
308
308
|
settings: next.settings ? { ...base.settings, ...next.settings } : base.settings,
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
|
+
function mergeServerDefinitions(base, next) {
|
|
312
|
+
const servers = { ...base };
|
|
313
|
+
for (const [name, definition] of Object.entries(next)) {
|
|
314
|
+
const previous = base[name];
|
|
315
|
+
if (previous && Object.keys(definition).every((key) => key === "disabled"))
|
|
316
|
+
servers[name] = { ...previous, ...definition };
|
|
317
|
+
else
|
|
318
|
+
servers[name] = previous?.disabled === undefined ? definition : { disabled: previous.disabled, ...definition };
|
|
319
|
+
}
|
|
320
|
+
return servers;
|
|
321
|
+
}
|
|
311
322
|
function expandImports(config, cwd) {
|
|
312
323
|
if (!config.imports?.length)
|
|
313
324
|
return config;
|
|
@@ -331,7 +342,7 @@ function expandImports(config, cwd) {
|
|
|
331
342
|
return {
|
|
332
343
|
imports: config.imports,
|
|
333
344
|
settings: config.settings,
|
|
334
|
-
mcpServers:
|
|
345
|
+
mcpServers: mergeServerDefinitions(importedServers, config.mcpServers),
|
|
335
346
|
};
|
|
336
347
|
}
|
|
337
348
|
function resolveImportPath(importKind, cwd) {
|
|
@@ -351,9 +362,6 @@ function extractServers(config, kind) {
|
|
|
351
362
|
: obj.mcpServers;
|
|
352
363
|
return parseServerEntries(servers);
|
|
353
364
|
}
|
|
354
|
-
export function resolveMcpDirectToolNames(mcpDirectTools, cwd = process.cwd()) {
|
|
355
|
-
return resolveMcpDirectToolSelections(mcpDirectTools, cwd).map((selection) => selection.name);
|
|
356
|
-
}
|
|
357
365
|
function validateSelectedServerDefinitions(config, selectors) {
|
|
358
366
|
const { servers, tools } = parseMcpDirectToolSelectors(selectors);
|
|
359
367
|
for (const serverName of new Set([...servers, ...tools.keys()])) {
|
|
@@ -414,7 +422,8 @@ function interpolateEnvRecord(values) {
|
|
|
414
422
|
}
|
|
415
423
|
function interpolateEnvVars(value) {
|
|
416
424
|
return value
|
|
417
|
-
|
|
425
|
+
// `${NAME:-default}` uses the default only when NAME is unset, as pi-mcp-adapter and Claude Code do.
|
|
426
|
+
.replace(/\$\{(\w+)(?::-([^}]*))?\}/g, (_, name, fallback) => process.env[name] ?? fallback ?? "")
|
|
418
427
|
.replace(/\$env:(\w+)/g, (_, name) => process.env[name] ?? "")
|
|
419
428
|
.replace(/\{env:(\w+)\}/g, (_, name) => process.env[name] ?? "");
|
|
420
429
|
}
|
|
@@ -425,9 +434,9 @@ function interpolateSecretExpression(value) {
|
|
|
425
434
|
}
|
|
426
435
|
function getMissingEnvVars(value) {
|
|
427
436
|
const missing = new Set();
|
|
428
|
-
for (const match of value.matchAll(/\$\{(\w+)
|
|
429
|
-
const name = match[1] ?? match[
|
|
430
|
-
if (name && process.env[name] === undefined)
|
|
437
|
+
for (const match of value.matchAll(/\$\{(\w+)(:-[^}]*)?\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
|
|
438
|
+
const name = match[1] ?? match[3] ?? match[4];
|
|
439
|
+
if (name && match[2] === undefined && process.env[name] === undefined)
|
|
431
440
|
missing.add(name);
|
|
432
441
|
}
|
|
433
442
|
return [...missing];
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
const BUILTIN_TOOL_NAMES = new Set(["read", "bash", "edit", "write", "grep", "find", "ls", "mcp"]);
|
|
2
2
|
export function normalizeMcpDirectToolSelectors(selectors) {
|
|
3
|
-
return [...new Set((selectors ?? []).map(
|
|
3
|
+
return [...new Set((selectors ?? []).map(trimTrailingSlashes).filter(Boolean))];
|
|
4
|
+
}
|
|
5
|
+
/** A `/+$/` replace rescans the selector from every index when the string ends in anything else. */
|
|
6
|
+
function trimTrailingSlashes(selector) {
|
|
7
|
+
let end = selector.length;
|
|
8
|
+
while (end > 0 && selector[end - 1] === "/")
|
|
9
|
+
end -= 1;
|
|
10
|
+
return selector.slice(0, end);
|
|
4
11
|
}
|
|
5
12
|
export function parseMcpDirectToolSelectors(selectors) {
|
|
6
13
|
const servers = new Set();
|