@xzzpig/pi-subagents 0.24.2 → 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 +22 -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-XWWUDWUW.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-4UH4WS4G.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-CYY5UMJU.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-224WMDIV.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-BQ2OAB4Q.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-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
- 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/package.json +2 -2
- 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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/shared/session-succession.ts
|
|
2
|
+
var SUCCESSION_KEY = /* @__PURE__ */ Symbol.for("pi-subagents.session-succession");
|
|
3
|
+
var MAX_INHERITED_SESSIONS = 8;
|
|
4
|
+
var MAX_RECORDED_SESSIONS = 64;
|
|
5
|
+
var KEPT_WORK_KEY = /* @__PURE__ */ Symbol.for("pi-subagents.sessions-keeping-work");
|
|
6
|
+
function successions() {
|
|
7
|
+
const runtime = globalThis;
|
|
8
|
+
runtime[SUCCESSION_KEY] ??= /* @__PURE__ */ new Map();
|
|
9
|
+
return runtime[SUCCESSION_KEY];
|
|
10
|
+
}
|
|
11
|
+
function keptWork() {
|
|
12
|
+
const runtime = globalThis;
|
|
13
|
+
runtime[KEPT_WORK_KEY] ??= /* @__PURE__ */ new Set();
|
|
14
|
+
return runtime[KEPT_WORK_KEY];
|
|
15
|
+
}
|
|
16
|
+
function keepSessionWork(sessionId) {
|
|
17
|
+
keptWork().delete(sessionId);
|
|
18
|
+
keptWork().add(sessionId);
|
|
19
|
+
while (keptWork().size > MAX_RECORDED_SESSIONS) keptWork().delete(keptWork().values().next().value);
|
|
20
|
+
}
|
|
21
|
+
function releaseSessionWork(sessionId) {
|
|
22
|
+
keptWork().delete(sessionId);
|
|
23
|
+
}
|
|
24
|
+
function recordSessionReplacement(sessionId, previousSessionId) {
|
|
25
|
+
const inherited = keptWork().has(previousSessionId) ? [] : [previousSessionId, ...successions().get(previousSessionId) ?? []];
|
|
26
|
+
const own = keptWork().has(sessionId) ? successions().get(sessionId) ?? [] : [];
|
|
27
|
+
const chain = [.../* @__PURE__ */ new Set([...inherited, ...own])].filter((id) => id !== sessionId);
|
|
28
|
+
successions().delete(sessionId);
|
|
29
|
+
successions().set(sessionId, chain.slice(0, MAX_INHERITED_SESSIONS));
|
|
30
|
+
while (successions().size > MAX_RECORDED_SESSIONS) successions().delete(successions().keys().next().value);
|
|
31
|
+
}
|
|
32
|
+
function recordSessionStart(sessionId, startup) {
|
|
33
|
+
if (startup) {
|
|
34
|
+
successions().delete(sessionId);
|
|
35
|
+
keptWork().delete(sessionId);
|
|
36
|
+
}
|
|
37
|
+
for (const [id, chain] of successions()) {
|
|
38
|
+
if (chain.includes(sessionId)) successions().set(id, chain.filter((inherited) => inherited !== sessionId));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function inheritedSessionIds(sessionId) {
|
|
42
|
+
return successions().get(sessionId) ?? [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/shared/extension-context.ts
|
|
46
|
+
var MODEL_ONLY_TOOL = { exposure: "model-only" };
|
|
47
|
+
function isStaleExtensionContextError(error) {
|
|
48
|
+
return error instanceof Error && /extension ctx is stale|extension context no longer active|stale after session replacement or reload/i.test(error.message);
|
|
49
|
+
}
|
|
50
|
+
function canRenderComponents(ctx) {
|
|
51
|
+
return ctx.mode === "tui" || process.env.PI_SUBAGENTS_COMPONENT_UI === "1";
|
|
52
|
+
}
|
|
53
|
+
function isUnboundExtensionRuntimeError(error) {
|
|
54
|
+
return error instanceof Error && /extension runtime not initialized/i.test(error.message);
|
|
55
|
+
}
|
|
56
|
+
function withCachedUiContext(ctx, onStale, run) {
|
|
57
|
+
if (!ctx) return void 0;
|
|
58
|
+
try {
|
|
59
|
+
if (!ctx.hasUI) return void 0;
|
|
60
|
+
return run(ctx);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (!isStaleExtensionContextError(error)) throw error;
|
|
63
|
+
onStale();
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/shared/session-warnings.ts
|
|
69
|
+
var reportedWarnings = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
function reportSessionWarning(state, message, key = message) {
|
|
71
|
+
let reported = reportedWarnings.get(state);
|
|
72
|
+
if (!reported) reportedWarnings.set(state, reported = /* @__PURE__ */ new Set());
|
|
73
|
+
if (reported.has(key)) return;
|
|
74
|
+
reported.add(key);
|
|
75
|
+
const text = `[pi-subagents] ${message}`;
|
|
76
|
+
const cached = state.lastUiContext;
|
|
77
|
+
const notified = withCachedUiContext(cached, () => {
|
|
78
|
+
if (state.lastUiContext === cached) state.lastUiContext = null;
|
|
79
|
+
}, (ctx) => {
|
|
80
|
+
ctx.ui.notify(text, "warning");
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
if (!notified) console.warn(text);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/runs/shared/run-ownership.ts
|
|
87
|
+
function ownerSessionIds(sessionId) {
|
|
88
|
+
return /* @__PURE__ */ new Set([sessionId, ...inheritedSessionIds(sessionId)]);
|
|
89
|
+
}
|
|
90
|
+
function ownsRun(currentSessionId, runSessionId) {
|
|
91
|
+
return currentSessionId ? ownerSessionIds(currentSessionId).has(runSessionId) : false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
keepSessionWork,
|
|
96
|
+
releaseSessionWork,
|
|
97
|
+
recordSessionReplacement,
|
|
98
|
+
recordSessionStart,
|
|
99
|
+
inheritedSessionIds,
|
|
100
|
+
ownerSessionIds,
|
|
101
|
+
ownsRun,
|
|
102
|
+
MODEL_ONLY_TOOL,
|
|
103
|
+
isStaleExtensionContextError,
|
|
104
|
+
canRenderComponents,
|
|
105
|
+
isUnboundExtensionRuntimeError,
|
|
106
|
+
withCachedUiContext,
|
|
107
|
+
reportSessionWarning
|
|
108
|
+
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getProjectConfigDir,
|
|
10
10
|
validatePermissionProfileName,
|
|
11
11
|
validateSandboxProfileName
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XAC2XNAP.js";
|
|
13
13
|
import {
|
|
14
14
|
TEMP_ROOT_DIR
|
|
15
15
|
} from "./chunk-UQDHXMUG.js";
|
|
@@ -58,7 +58,7 @@ function isMcpServerDefinition(value) {
|
|
|
58
58
|
}
|
|
59
59
|
if (value.requestHeadersCommand !== void 0 && !isRequestHeadersCommand(value.requestHeadersCommand)) return false;
|
|
60
60
|
if (value.auth !== void 0 && value.auth !== "oauth" && value.auth !== "bearer" && value.auth !== false) return false;
|
|
61
|
-
return value.directTools === void 0 || typeof value.directTools === "boolean" || isStringArray(value.directTools);
|
|
61
|
+
return value.directTools === void 0 || typeof value.directTools === "boolean" || value.directTools === "search" || isStringArray(value.directTools);
|
|
62
62
|
}
|
|
63
63
|
function isRecord(value) {
|
|
64
64
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -355,7 +355,12 @@ function readJson(filePath) {
|
|
|
355
355
|
// src/runs/shared/mcp-direct-tool-grant.ts
|
|
356
356
|
var BUILTIN_TOOL_NAMES = /* @__PURE__ */ new Set(["read", "bash", "edit", "write", "grep", "find", "ls", "mcp"]);
|
|
357
357
|
function normalizeMcpDirectToolSelectors(selectors) {
|
|
358
|
-
return [...new Set((selectors ?? []).map(
|
|
358
|
+
return [...new Set((selectors ?? []).map(trimTrailingSlashes).filter(Boolean))];
|
|
359
|
+
}
|
|
360
|
+
function trimTrailingSlashes(selector) {
|
|
361
|
+
let end = selector.length;
|
|
362
|
+
while (end > 0 && selector[end - 1] === "/") end -= 1;
|
|
363
|
+
return selector.slice(0, end);
|
|
359
364
|
}
|
|
360
365
|
function parseMcpDirectToolSelectors(selectors) {
|
|
361
366
|
const servers = /* @__PURE__ */ new Set();
|
|
@@ -506,17 +511,20 @@ function resolveMcpDirectToolResolution(mcpDirectTools, cwd = process.cwd(), run
|
|
|
506
511
|
const runtimeSelectionServers = /* @__PURE__ */ new Set([...selectedServers, ...selectedTools.keys()]);
|
|
507
512
|
const runtimeServers = resolveRuntimeMcpServers(config, runtimeSelectionServers, runtimeSnapshotHost);
|
|
508
513
|
const resolvedConfig = Object.keys(runtimeServers).length > 0 ? mergeConfigs(config, { mcpServers: runtimeServers }) : config;
|
|
509
|
-
|
|
514
|
+
const enabledSelectors = selectors.filter((selector) => resolvedConfig.mcpServers[selector.split("/", 1)[0]]?.disabled !== true);
|
|
515
|
+
validateSelectedServerDefinitions(resolvedConfig, enabledSelectors);
|
|
510
516
|
const runtime = Object.keys(runtimeServers).length > 0 ? { mcpConfig: resolvedConfig, runtimeServerNames: Object.keys(runtimeServers) } : {};
|
|
517
|
+
if (enabledSelectors.length === 0) return { selections: [], unresolvedSelectors: [], ...runtime };
|
|
511
518
|
const cache = loadMetadataCache();
|
|
512
|
-
if (!cache) return { selections: [], unresolvedSelectors:
|
|
519
|
+
if (!cache) return { selections: [], unresolvedSelectors: enabledSelectors, ...runtime };
|
|
513
520
|
const validMetadata = {};
|
|
514
521
|
for (const [serverName, definition] of Object.entries(resolvedConfig.mcpServers)) {
|
|
522
|
+
if (definition.disabled === true) continue;
|
|
515
523
|
const serverCache = cache.servers[serverName];
|
|
516
524
|
if (isServerCacheValid(serverCache, definition)) validMetadata[serverName] = serverCache;
|
|
517
525
|
}
|
|
518
526
|
const grant = planMcpDirectToolGrant({
|
|
519
|
-
selectors,
|
|
527
|
+
selectors: enabledSelectors,
|
|
520
528
|
servers: resolvedConfig.mcpServers,
|
|
521
529
|
metadata: validMetadata,
|
|
522
530
|
toolPrefix: resolvedConfig.settings?.toolPrefix
|
|
@@ -702,10 +710,8 @@ function parseServerEntries(value) {
|
|
|
702
710
|
function parseSettings(value) {
|
|
703
711
|
if (!isRecord2(value)) return void 0;
|
|
704
712
|
const toolPrefix = value.toolPrefix === "server" || value.toolPrefix === "short" || value.toolPrefix === "none" || value.toolPrefix === "mcp" ? value.toolPrefix : void 0;
|
|
705
|
-
const directTools = typeof value.directTools === "boolean" ? value.directTools : void 0;
|
|
706
713
|
const settings = {
|
|
707
714
|
...toolPrefix ? { toolPrefix } : {},
|
|
708
|
-
...directTools !== void 0 ? { directTools } : {},
|
|
709
715
|
...value.agentPluginPaths !== void 0 ? { agentPluginPaths: value.agentPluginPaths } : {}
|
|
710
716
|
};
|
|
711
717
|
return Object.keys(settings).length ? settings : void 0;
|
|
@@ -713,11 +719,20 @@ function parseSettings(value) {
|
|
|
713
719
|
function mergeConfigs(base, next) {
|
|
714
720
|
const imports = [...base.imports ?? [], ...next.imports ?? []];
|
|
715
721
|
return {
|
|
716
|
-
mcpServers:
|
|
722
|
+
mcpServers: mergeServerDefinitions(base.mcpServers, next.mcpServers),
|
|
717
723
|
imports: imports.length ? [...new Set(imports)] : void 0,
|
|
718
724
|
settings: next.settings ? { ...base.settings, ...next.settings } : base.settings
|
|
719
725
|
};
|
|
720
726
|
}
|
|
727
|
+
function mergeServerDefinitions(base, next) {
|
|
728
|
+
const servers = { ...base };
|
|
729
|
+
for (const [name, definition] of Object.entries(next)) {
|
|
730
|
+
const previous = base[name];
|
|
731
|
+
if (previous && Object.keys(definition).every((key) => key === "disabled")) servers[name] = { ...previous, ...definition };
|
|
732
|
+
else servers[name] = previous?.disabled === void 0 ? definition : { disabled: previous.disabled, ...definition };
|
|
733
|
+
}
|
|
734
|
+
return servers;
|
|
735
|
+
}
|
|
721
736
|
function expandImports(config, cwd) {
|
|
722
737
|
if (!config.imports?.length) return config;
|
|
723
738
|
const importedServers = {};
|
|
@@ -737,7 +752,7 @@ function expandImports(config, cwd) {
|
|
|
737
752
|
return {
|
|
738
753
|
imports: config.imports,
|
|
739
754
|
settings: config.settings,
|
|
740
|
-
mcpServers:
|
|
755
|
+
mcpServers: mergeServerDefinitions(importedServers, config.mcpServers)
|
|
741
756
|
};
|
|
742
757
|
}
|
|
743
758
|
function resolveImportPath(importKind, cwd) {
|
|
@@ -804,7 +819,7 @@ function interpolateEnvRecord(values) {
|
|
|
804
819
|
return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, interpolateSecretExpression(value)]));
|
|
805
820
|
}
|
|
806
821
|
function interpolateEnvVars(value) {
|
|
807
|
-
return value.replace(/\$\{(\w+)
|
|
822
|
+
return value.replace(/\$\{(\w+)(?::-([^}]*))?\}/g, (_, name, fallback) => process.env[name] ?? fallback ?? "").replace(/\$env:(\w+)/g, (_, name) => process.env[name] ?? "").replace(/\{env:(\w+)\}/g, (_, name) => process.env[name] ?? "");
|
|
808
823
|
}
|
|
809
824
|
function interpolateSecretExpression(value) {
|
|
810
825
|
if (value.startsWith("!!")) return interpolateEnvVars(value.slice(1));
|
|
@@ -812,9 +827,9 @@ function interpolateSecretExpression(value) {
|
|
|
812
827
|
}
|
|
813
828
|
function getMissingEnvVars(value) {
|
|
814
829
|
const missing = /* @__PURE__ */ new Set();
|
|
815
|
-
for (const match of value.matchAll(/\$\{(\w+)
|
|
816
|
-
const name = match[1] ?? match[
|
|
817
|
-
if (name && process.env[name] === void 0) missing.add(name);
|
|
830
|
+
for (const match of value.matchAll(/\$\{(\w+)(:-[^}]*)?\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
|
|
831
|
+
const name = match[1] ?? match[3] ?? match[4];
|
|
832
|
+
if (name && match[2] === void 0 && process.env[name] === void 0) missing.add(name);
|
|
818
833
|
}
|
|
819
834
|
return [...missing];
|
|
820
835
|
}
|