pi-subagents 0.80.0 → 0.82.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 +66 -0
- package/bundle/agents.js +18 -0
- package/bundle/background-work.js +16 -0
- package/bundle/capability-ceiling.js +22 -0
- package/bundle/child-tool-plan.js +11 -0
- package/bundle/chunk-43SCHIMD.js +57 -0
- package/bundle/chunk-4QFZZV3O.js +57 -0
- package/bundle/chunk-4SDU2BZX.js +1190 -0
- package/bundle/chunk-52UBALJL.js +753 -0
- package/bundle/chunk-5LFLVSTM.js +260 -0
- package/bundle/chunk-5TYMSZX3.js +235 -0
- package/bundle/chunk-62OCY2S4.js +14 -0
- package/bundle/chunk-7F6RKT6W.js +132 -0
- package/bundle/chunk-7IVSUMQQ.js +1337 -0
- package/bundle/chunk-7J4ZXMY7.js +18 -0
- package/bundle/chunk-7PCKZHR5.js +1234 -0
- package/bundle/chunk-7YMXOYEU.js +1373 -0
- package/bundle/chunk-B5EKXDHE.js +16870 -0
- package/bundle/chunk-CIZQXJ5Q.js +8619 -0
- package/bundle/chunk-CTPAE36Y.js +94 -0
- package/bundle/chunk-D4EHT5SJ.js +14 -0
- package/bundle/chunk-GC4DSPMH.js +946 -0
- package/bundle/chunk-GJECHSAR.js +179 -0
- package/bundle/chunk-M2CTFYT3.js +4164 -0
- package/bundle/chunk-MHZ4G23A.js +1296 -0
- package/bundle/chunk-N2BN7BF5.js +159 -0
- package/bundle/chunk-NF7IEKBH.js +490 -0
- package/bundle/chunk-NGGAFDL6.js +742 -0
- package/bundle/chunk-NIXWDZZV.js +9 -0
- package/bundle/chunk-NRQ75MGH.js +8327 -0
- package/bundle/chunk-OYF6AFDY.js +458 -0
- package/bundle/chunk-PLCCBLPY.js +526 -0
- package/bundle/chunk-RMQFMMAT.js +416 -0
- package/bundle/chunk-SIJ4S3EN.js +276 -0
- package/bundle/chunk-UKG4V45O.js +228 -0
- package/bundle/chunk-VH5OAWVG.js +4096 -0
- package/bundle/chunk-W2SZ22EM.js +5462 -0
- package/bundle/chunk-WVD4UEL4.js +9367 -0
- package/bundle/chunk-XSWOTIA3.js +175 -0
- package/bundle/chunk-YFCK7H2S.js +129 -0
- package/bundle/chunk-YKEWIB4M.js +380 -0
- package/bundle/chunk-YYREO77V.js +137 -0
- package/bundle/chunk-Z7KVHQHL.js +173 -0
- package/bundle/chunk-ZLINIYTP.js +8613 -0
- package/bundle/chunk-ZQGSDHL6.js +128 -0
- package/bundle/control-channel.js +11 -0
- package/bundle/delegation.js +14 -0
- package/bundle/external-job-provider.js +20 -0
- package/bundle/external-runs.js +21 -0
- package/bundle/index.js +30 -0
- package/bundle/inspectors.js +8 -0
- package/bundle/intercom-bridge.js +11 -0
- package/bundle/preflight.js +425 -0
- package/bundle/project-panes.js +28 -0
- package/bundle/required-child-extensions.js +6 -0
- package/bundle/shared-types.js +8 -0
- package/bundle/workflow-resources.js +7 -0
- package/docs/agents.md +31 -0
- package/docs/configuration.md +9 -1
- package/docs/extension-api.md +27 -0
- package/docs/observability.md +6 -2
- package/docs/tool-reference.md +3 -1
- package/docs/workflows.md +16 -0
- package/package.json +19 -19
- package/skills/pi-subagents/references/execution-controls.md +5 -4
- package/src/agents/agent-management.js +3 -3
- package/src/agents/agent-memory.js +3 -1
- package/src/agents/agents.js +6 -6
- package/src/agents/frontmatter.d.ts +4 -0
- package/src/agents/frontmatter.js +24 -3
- package/src/agents/skills.js +2 -1
- package/src/api/delegation.d.ts +20 -0
- package/src/extension/config.js +3 -0
- package/src/extension/herdr-pi-bridge.js +17 -10
- package/src/extension/index.js +109 -9
- package/src/extension/schemas.js +3 -3
- package/src/intercom/native-supervisor-channel.js +20 -0
- package/src/missions/lifecycle.js +7 -1
- package/src/runs/background/active-async-capacity.d.ts +1 -0
- package/src/runs/background/active-async-capacity.js +9 -3
- package/src/runs/background/async-execution.js +20 -10
- package/src/runs/background/async-job-tracker.d.ts +6 -1
- package/src/runs/background/async-job-tracker.js +9 -4
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +21 -2
- package/src/runs/background/await-async-run.js +3 -7
- package/src/runs/background/boot-id.d.ts +12 -0
- package/src/runs/background/boot-id.js +47 -0
- package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
- package/src/runs/background/interrupted-elsewhere.js +68 -0
- package/src/runs/background/notify.d.ts +2 -0
- package/src/runs/background/notify.js +13 -0
- package/src/runs/background/result-delivery-ownership.d.ts +6 -0
- package/src/runs/background/result-delivery-ownership.js +19 -1
- package/src/runs/background/result-watcher.d.ts +3 -1
- package/src/runs/background/result-watcher.js +24 -8
- package/src/runs/background/run-child-session.d.ts +1 -6
- package/src/runs/background/run-child-session.js +19 -1
- package/src/runs/background/run-status.js +2 -1
- package/src/runs/background/stale-run-reconciler.d.ts +25 -0
- package/src/runs/background/stale-run-reconciler.js +54 -13
- package/src/runs/background/subagent-runner-bootstrap.js +3 -0
- package/src/runs/background/subagent-runner.d.ts +4 -0
- package/src/runs/background/subagent-runner.js +13 -5
- package/src/runs/background/subagent-wait.d.ts +1 -1
- package/src/runs/background/subagent-wait.js +6 -1
- package/src/runs/background/terminal-run-index.d.ts +1 -0
- package/src/runs/background/terminal-run-index.js +4 -2
- package/src/runs/foreground/async-stop-action.js +3 -1
- package/src/runs/foreground/execution.js +45 -5
- package/src/runs/foreground/foreground-history.d.ts +16 -2
- package/src/runs/foreground/foreground-history.js +133 -31
- package/src/runs/foreground/subagent-executor.d.ts +11 -0
- package/src/runs/foreground/subagent-executor.js +277 -74
- package/src/runs/shared/child-launch.d.ts +2 -2
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +51 -8
- package/src/runs/shared/child-tool-plan.d.ts +7 -0
- package/src/runs/shared/child-tool-plan.js +21 -6
- package/src/runs/shared/herdr-connection.d.ts +17 -8
- package/src/runs/shared/herdr-connection.js +19 -7
- package/src/runs/shared/herdr-external-adapters.d.ts +3 -2
- package/src/runs/shared/herdr-external-adapters.js +1 -1
- package/src/runs/shared/herdr-machine.d.ts +12 -2
- package/src/runs/shared/herdr-machine.js +55 -9
- package/src/runs/shared/herdr-pane-host.d.ts +88 -0
- package/src/runs/shared/herdr-pane-host.js +155 -0
- package/src/runs/shared/herdr-placed-run.d.ts +27 -150
- package/src/runs/shared/herdr-placed-run.js +48 -395
- package/src/runs/shared/local-machine-access.d.ts +5 -0
- package/src/runs/shared/local-machine-access.js +28 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +0 -1
- package/src/runs/shared/orca-progress-tabs.js +1 -24
- package/src/runs/shared/parallel-utils.d.ts +1 -1
- package/src/runs/shared/placed-run-owner.d.ts +49 -0
- package/src/runs/shared/placed-run-owner.js +93 -0
- package/src/runs/shared/placement-host.d.ts +99 -0
- package/src/runs/shared/placement-host.js +157 -0
- package/src/runs/shared/rex-machine.d.ts +25 -0
- package/src/runs/shared/rex-machine.js +83 -0
- package/src/runs/shared/rex-pane-host.d.ts +62 -0
- package/src/runs/shared/rex-pane-host.js +327 -0
- package/src/runs/shared/structured-output.d.ts +1 -0
- package/src/runs/shared/structured-output.js +1 -0
- package/src/shared/accessible-dir.js +4 -1
- package/src/shared/completion-owner.d.ts +5 -0
- package/src/shared/completion-owner.js +5 -0
- package/src/shared/provider-diagnostics.d.ts +9 -0
- package/src/shared/provider-diagnostics.js +75 -0
- package/src/shared/session-identity.d.ts +2 -0
- package/src/shared/session-identity.js +26 -0
- package/src/shared/types.d.ts +48 -6
- package/src/slash/delegation-adapters.d.ts +3 -1
- package/src/slash/delegation-adapters.js +7 -0
- package/src/slash/prompt-template-bridge.js +3 -1
- package/src/slash/subagents-admin.d.ts +1 -0
- package/src/slash/subagents-admin.js +1 -1
- package/src/tui/fleet-layout.d.ts +20 -0
- package/src/tui/fleet-layout.js +17 -0
- package/src/tui/fleet-viewport.d.ts +12 -0
- package/src/tui/fleet-viewport.js +35 -0
- package/src/tui/fleet.d.ts +6 -6
- package/src/tui/fleet.js +93 -66
- package/src/tui/render.d.ts +6 -0
- package/src/tui/render.js +3 -3
- package/src/tui/subagent-messages.js +1 -0
- package/src/workflows/scripted-workflow.d.ts +1 -1
- package/src/workflows/structured-workflow-scripts.d.ts +1 -0
- package/src/workflows/structured-workflow-scripts.js +5 -4
- package/src/workflows/workflow-auto-resume.d.ts +32 -0
- package/src/workflows/workflow-auto-resume.js +102 -0
- package/src/workflows/workflow-launch-record.d.ts +27 -0
- package/src/workflows/workflow-launch-record.js +48 -0
- package/src/workflows/workflow-resources.js +2 -2
- package/src/workflows/workflow-resume-claim.d.ts +82 -0
- package/src/workflows/workflow-resume-claim.js +210 -0
- package/src/workflows/workflow-resume.d.ts +56 -0
- package/src/workflows/workflow-resume.js +106 -0
- package/src/workflows/workflow-reuse.d.ts +15 -9
- package/src/workflows/workflow-reuse.js +77 -14
- package/src/workflows/workflow-revival.d.ts +2 -0
- package/src/workflows/workflow-revival.js +2 -1
- package/src/workflows/workflow-stop-cause.d.ts +6 -0
- package/src/workflows/workflow-stop-cause.js +8 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// src/shared/types.ts
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
var SUBAGENT_LIFECYCLE_ARTIFACT_VERSION = 3;
|
|
5
|
+
var INTERCOM_DETACH_REQUEST_EVENT = "pi-intercom:detach-request";
|
|
6
|
+
var INTERCOM_DETACH_RESPONSE_EVENT = "pi-intercom:detach-response";
|
|
7
|
+
var INTERCOM_SESSION_IDENTITY_EVENT = "intercom:session-identity";
|
|
8
|
+
var SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started";
|
|
9
|
+
var RUNNER_LAUNCHER_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
10
|
+
var RUNNER_LAUNCHER_NAME_RULE = "must start with a letter or digit and use only letters, digits, '.', '_' or '-' (at most 128 characters)";
|
|
11
|
+
var SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete";
|
|
12
|
+
var SUBAGENT_PROCESS_TERMINAL_EVENT = "subagent:process-terminal";
|
|
13
|
+
var SUBAGENT_FOREGROUND_COMPLETE_EVENT = "subagent:foreground-complete";
|
|
14
|
+
var SUBAGENT_CONTROL_EVENT = "subagent:control-event";
|
|
15
|
+
var SUBAGENT_CONTROL_INTERCOM_EVENT = "subagent:control-intercom";
|
|
16
|
+
var SUBAGENT_STEERING_NOTICE_EVENT = "subagent:steering-notice";
|
|
17
|
+
var SUBAGENT_CHILD_STATUS_EVENT = "subagent:child-status";
|
|
18
|
+
var SUBAGENT_RESULT_INTERCOM_EVENT = "subagent:result-intercom";
|
|
19
|
+
var SUBAGENT_RESULT_INTERCOM_DELIVERY_EVENT = "subagent:result-intercom-delivery";
|
|
20
|
+
var FLEET_KEYBINDING_ACTIONS = [
|
|
21
|
+
"close",
|
|
22
|
+
"scrollUp",
|
|
23
|
+
"scrollDown",
|
|
24
|
+
"selectUp",
|
|
25
|
+
"selectDown",
|
|
26
|
+
"selectFirst",
|
|
27
|
+
"selectLast",
|
|
28
|
+
"pageUp",
|
|
29
|
+
"pageDown",
|
|
30
|
+
"refresh",
|
|
31
|
+
"steer",
|
|
32
|
+
"inspect",
|
|
33
|
+
"stop",
|
|
34
|
+
"toggleTools"
|
|
35
|
+
];
|
|
36
|
+
var DEFAULT_MAX_OUTPUT = {
|
|
37
|
+
bytes: 200 * 1024,
|
|
38
|
+
lines: 5e3
|
|
39
|
+
};
|
|
40
|
+
var DEFAULT_ARTIFACT_CONFIG = {
|
|
41
|
+
enabled: true,
|
|
42
|
+
dir: "session",
|
|
43
|
+
includeInput: true,
|
|
44
|
+
includeOutput: true,
|
|
45
|
+
includeJsonl: false,
|
|
46
|
+
includeTranscript: true,
|
|
47
|
+
includeMetadata: true,
|
|
48
|
+
cleanupDays: 7
|
|
49
|
+
};
|
|
50
|
+
function sanitizeTempScopeSegment(value) {
|
|
51
|
+
const sanitized = value.trim().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
52
|
+
return sanitized || "unknown";
|
|
53
|
+
}
|
|
54
|
+
function resolveTempScopeId(options) {
|
|
55
|
+
const env = options?.env ?? process.env;
|
|
56
|
+
const getuid = options && Object.hasOwn(options, "getuid") ? options.getuid : process.getuid?.bind(process);
|
|
57
|
+
if (typeof getuid === "function") {
|
|
58
|
+
return `uid-${getuid()}`;
|
|
59
|
+
}
|
|
60
|
+
for (const key of ["USERNAME", "USER", "LOGNAME"]) {
|
|
61
|
+
const value = env[key];
|
|
62
|
+
if (value) return `user-${sanitizeTempScopeSegment(value)}`;
|
|
63
|
+
}
|
|
64
|
+
const userInfo2 = options && Object.hasOwn(options, "userInfo") ? options.userInfo : os.userInfo;
|
|
65
|
+
try {
|
|
66
|
+
const username = userInfo2?.().username;
|
|
67
|
+
if (username) return `user-${sanitizeTempScopeSegment(username)}`;
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
const homedir2 = env.USERPROFILE ?? env.HOME;
|
|
71
|
+
if (homedir2) return `home-${sanitizeTempScopeSegment(homedir2)}`;
|
|
72
|
+
const resolveHomedir = options && Object.hasOwn(options, "homedir") ? options.homedir : os.homedir;
|
|
73
|
+
try {
|
|
74
|
+
const fallbackHomedir = resolveHomedir?.();
|
|
75
|
+
if (fallbackHomedir) return `home-${sanitizeTempScopeSegment(fallbackHomedir)}`;
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
return "shared";
|
|
79
|
+
}
|
|
80
|
+
var configuredTempRoot = process.env.PI_SUBAGENTS_TEMP_ROOT?.trim();
|
|
81
|
+
var TEMP_ROOT_DIR = configuredTempRoot ? path.resolve(configuredTempRoot) : path.join(os.tmpdir(), `pi-subagents-${resolveTempScopeId()}`);
|
|
82
|
+
var RESULTS_DIR = path.join(TEMP_ROOT_DIR, "async-subagent-results");
|
|
83
|
+
var ASYNC_DIR = path.join(TEMP_ROOT_DIR, "async-subagent-runs");
|
|
84
|
+
var CHAIN_RUNS_DIR = path.join(TEMP_ROOT_DIR, "chain-runs");
|
|
85
|
+
var TEMP_ARTIFACTS_DIR = path.join(TEMP_ROOT_DIR, "artifacts");
|
|
86
|
+
var DIRS = {
|
|
87
|
+
results: RESULTS_DIR,
|
|
88
|
+
async: ASYNC_DIR,
|
|
89
|
+
chain: CHAIN_RUNS_DIR,
|
|
90
|
+
artifacts: TEMP_ARTIFACTS_DIR
|
|
91
|
+
};
|
|
92
|
+
var WIDGET_KEY = "subagent-async";
|
|
93
|
+
var SLASH_RESULT_TYPE = "subagent-slash-result";
|
|
94
|
+
var SLASH_TEXT_RESULT_TYPE = "subagent-slash-text-result";
|
|
95
|
+
var SLASH_TEXT_VIEW_ONLY_DETAILS = { viewOnly: true };
|
|
96
|
+
var SLASH_SUBAGENT_REQUEST_EVENT = "subagent:slash:request";
|
|
97
|
+
var SLASH_SUBAGENT_STARTED_EVENT = "subagent:slash:started";
|
|
98
|
+
var SLASH_SUBAGENT_RESPONSE_EVENT = "subagent:slash:response";
|
|
99
|
+
var SLASH_SUBAGENT_UPDATE_EVENT = "subagent:slash:update";
|
|
100
|
+
var SLASH_SUBAGENT_CANCEL_EVENT = "subagent:slash:cancel";
|
|
101
|
+
var POLL_INTERVAL_MS = 250;
|
|
102
|
+
var WIDGET_ANIMATION_INTERVAL_MS = 1e3;
|
|
103
|
+
var MAX_WIDGET_JOBS = 4;
|
|
104
|
+
var DEFAULT_SUBAGENT_MAX_DEPTH = 2;
|
|
105
|
+
var SUBAGENT_ACTIONS = ["list", "get", "models", "children.list", "guide", "validate", "create", "update", "delete", "eject", "disable", "enable", "reset", "mission.create", "mission.list", "mission.show", "mission.update", "mission.resolve-decision", "mission.attach-run", "mission.close", "worktree.discard", "worktree.cleanup", "lane.status", "lane.recordMerge", "lane.recordSupersession", "refine", "refine.show", "refine.rollback", "inspector.open", "inspector.command", "inspector.status", "inspector.close", "project.open", "project.status", "project.close", "status", "debug.run", "grant-spawn-budget", "interrupt", "resume", "steer", "stop", "command.status", "command.yield", "command.cancel", "dismiss", "doctor", "watchdog.status", "watchdog.check", "watchdog.configure", "watchdog.recommend-model", "schedule.create", "schedule.list", "schedule.show", "schedule.history", "schedule.pause", "schedule.resume", "schedule.run", "schedule.run-due", "schedule.delete"];
|
|
106
|
+
var DEFAULT_FORK_PREAMBLE = "You are a delegated subagent running from a fork of the parent session. Treat the inherited conversation as reference-only context, not a live thread to continue. Do not continue or answer prior messages as if they are waiting for a reply. Your sole job is to execute the task below and return a focused result for that task using your tools.";
|
|
107
|
+
function getAsyncConfigPath(suffix) {
|
|
108
|
+
return path.join(TEMP_ROOT_DIR, `async-cfg-${suffix}.json`);
|
|
109
|
+
}
|
|
110
|
+
function wrapForkTask(task, preamble) {
|
|
111
|
+
if (preamble === false) return task;
|
|
112
|
+
const effectivePreamble = preamble ?? DEFAULT_FORK_PREAMBLE;
|
|
113
|
+
const wrappedPrefix = `${effectivePreamble}
|
|
114
|
+
|
|
115
|
+
Task:
|
|
116
|
+
`;
|
|
117
|
+
if (task.startsWith(wrappedPrefix)) return task;
|
|
118
|
+
return `${wrappedPrefix}${task}`;
|
|
119
|
+
}
|
|
120
|
+
function normalizeNonNegativeInteger(value) {
|
|
121
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
122
|
+
if (!Number.isInteger(parsed) || parsed < 0) return void 0;
|
|
123
|
+
return parsed;
|
|
124
|
+
}
|
|
125
|
+
function normalizeMaxSubagentDepth(value) {
|
|
126
|
+
return normalizeNonNegativeInteger(value);
|
|
127
|
+
}
|
|
128
|
+
var SUBAGENT_MAX_DEPTH_ENV = "PI_SUBAGENT_MAX_DEPTH";
|
|
129
|
+
function resolveCurrentMaxSubagentDepth(configMaxDepth, runtime) {
|
|
130
|
+
return normalizeMaxSubagentDepth(runtime ? runtime.maxDepth : process.env[SUBAGENT_MAX_DEPTH_ENV]) ?? normalizeMaxSubagentDepth(configMaxDepth) ?? DEFAULT_SUBAGENT_MAX_DEPTH;
|
|
131
|
+
}
|
|
132
|
+
function resolveChildMaxSubagentDepth(parentMaxDepth, agentMaxDepth) {
|
|
133
|
+
const normalizedParent = normalizeMaxSubagentDepth(parentMaxDepth) ?? DEFAULT_SUBAGENT_MAX_DEPTH;
|
|
134
|
+
const normalizedAgent = normalizeMaxSubagentDepth(agentMaxDepth);
|
|
135
|
+
return normalizedAgent === void 0 ? normalizedParent : Math.min(normalizedParent, normalizedAgent);
|
|
136
|
+
}
|
|
137
|
+
function resolveCurrentSubagentDepth(runtime) {
|
|
138
|
+
const depth = runtime ? runtime.depth : 0;
|
|
139
|
+
return Number.isFinite(depth) ? depth : 0;
|
|
140
|
+
}
|
|
141
|
+
function checkSubagentDepth(configMaxDepth, runtime) {
|
|
142
|
+
const depth = resolveCurrentSubagentDepth(runtime);
|
|
143
|
+
const maxDepth = resolveCurrentMaxSubagentDepth(configMaxDepth, runtime);
|
|
144
|
+
const blocked = depth >= maxDepth;
|
|
145
|
+
return { blocked, depth, maxDepth };
|
|
146
|
+
}
|
|
147
|
+
function resolveChildDepth(maxDepth, runtime) {
|
|
148
|
+
return {
|
|
149
|
+
depth: resolveCurrentSubagentDepth(runtime) + 1,
|
|
150
|
+
maxDepth: normalizeMaxSubagentDepth(maxDepth) ?? resolveCurrentMaxSubagentDepth(void 0, runtime)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function normalizeMaxSubagentSpawnsPerSession(value) {
|
|
154
|
+
return normalizeNonNegativeInteger(value);
|
|
155
|
+
}
|
|
156
|
+
function resolveMaxSubagentSpawnsPerSession(configMaxSpawns) {
|
|
157
|
+
const envMaxSpawns = normalizeMaxSubagentSpawnsPerSession(process.env.PI_SUBAGENT_MAX_SPAWNS_PER_SESSION);
|
|
158
|
+
if (envMaxSpawns !== void 0) return envMaxSpawns === 0 ? void 0 : envMaxSpawns;
|
|
159
|
+
const configuredMaxSpawns = normalizeMaxSubagentSpawnsPerSession(configMaxSpawns);
|
|
160
|
+
return configuredMaxSpawns === 0 ? void 0 : configuredMaxSpawns;
|
|
161
|
+
}
|
|
162
|
+
var DEFAULT_MAX_SUBAGENT_SPAWNS_PER_RUN = 64;
|
|
163
|
+
function normalizeMaxSubagentSpawnsPerRun(value) {
|
|
164
|
+
const normalized = normalizeNonNegativeInteger(value);
|
|
165
|
+
return normalized !== void 0 && normalized > 0 ? normalized : void 0;
|
|
166
|
+
}
|
|
167
|
+
function resolveMaxSubagentSpawnsPerRun(configMaxSpawns) {
|
|
168
|
+
return normalizeMaxSubagentSpawnsPerRun(process.env.PI_SUBAGENT_MAX_SPAWNS_PER_RUN) ?? normalizeMaxSubagentSpawnsPerRun(configMaxSpawns) ?? DEFAULT_MAX_SUBAGENT_SPAWNS_PER_RUN;
|
|
169
|
+
}
|
|
170
|
+
function formatBytes(bytes) {
|
|
171
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
172
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
173
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
174
|
+
}
|
|
175
|
+
function truncateOutput(output, config, artifactPath) {
|
|
176
|
+
const lines = output.split("\n");
|
|
177
|
+
const bytes = Buffer.byteLength(output, "utf-8");
|
|
178
|
+
if (bytes <= config.bytes && lines.length <= config.lines) {
|
|
179
|
+
return { text: output, truncated: false };
|
|
180
|
+
}
|
|
181
|
+
let truncatedLines = lines;
|
|
182
|
+
if (lines.length > config.lines) {
|
|
183
|
+
truncatedLines = lines.slice(0, config.lines);
|
|
184
|
+
}
|
|
185
|
+
let result = truncatedLines.join("\n");
|
|
186
|
+
if (Buffer.byteLength(result, "utf-8") > config.bytes) {
|
|
187
|
+
let low = 0;
|
|
188
|
+
let high = result.length;
|
|
189
|
+
while (low < high) {
|
|
190
|
+
const mid = Math.floor((low + high + 1) / 2);
|
|
191
|
+
if (Buffer.byteLength(result.slice(0, mid), "utf-8") <= config.bytes) {
|
|
192
|
+
low = mid;
|
|
193
|
+
} else {
|
|
194
|
+
high = mid - 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
result = result.slice(0, low);
|
|
198
|
+
}
|
|
199
|
+
const keptLines = result.split("\n").length;
|
|
200
|
+
const marker = `[TRUNCATED: showing first ${keptLines} of ${lines.length} lines, ${formatBytes(Buffer.byteLength(result))} of ${formatBytes(bytes)}${artifactPath ? ` - full output at ${artifactPath}` : ""}]
|
|
201
|
+
`;
|
|
202
|
+
return {
|
|
203
|
+
text: marker + result,
|
|
204
|
+
truncated: true,
|
|
205
|
+
originalBytes: bytes,
|
|
206
|
+
originalLines: lines.length,
|
|
207
|
+
artifactPath
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
213
|
+
INTERCOM_DETACH_REQUEST_EVENT,
|
|
214
|
+
INTERCOM_DETACH_RESPONSE_EVENT,
|
|
215
|
+
INTERCOM_SESSION_IDENTITY_EVENT,
|
|
216
|
+
SUBAGENT_ASYNC_STARTED_EVENT,
|
|
217
|
+
RUNNER_LAUNCHER_NAME_PATTERN,
|
|
218
|
+
RUNNER_LAUNCHER_NAME_RULE,
|
|
219
|
+
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
220
|
+
SUBAGENT_PROCESS_TERMINAL_EVENT,
|
|
221
|
+
SUBAGENT_FOREGROUND_COMPLETE_EVENT,
|
|
222
|
+
SUBAGENT_CONTROL_EVENT,
|
|
223
|
+
SUBAGENT_CONTROL_INTERCOM_EVENT,
|
|
224
|
+
SUBAGENT_STEERING_NOTICE_EVENT,
|
|
225
|
+
SUBAGENT_CHILD_STATUS_EVENT,
|
|
226
|
+
SUBAGENT_RESULT_INTERCOM_EVENT,
|
|
227
|
+
SUBAGENT_RESULT_INTERCOM_DELIVERY_EVENT,
|
|
228
|
+
FLEET_KEYBINDING_ACTIONS,
|
|
229
|
+
DEFAULT_MAX_OUTPUT,
|
|
230
|
+
DEFAULT_ARTIFACT_CONFIG,
|
|
231
|
+
TEMP_ROOT_DIR,
|
|
232
|
+
ASYNC_DIR,
|
|
233
|
+
CHAIN_RUNS_DIR,
|
|
234
|
+
TEMP_ARTIFACTS_DIR,
|
|
235
|
+
DIRS,
|
|
236
|
+
WIDGET_KEY,
|
|
237
|
+
SLASH_RESULT_TYPE,
|
|
238
|
+
SLASH_TEXT_RESULT_TYPE,
|
|
239
|
+
SLASH_TEXT_VIEW_ONLY_DETAILS,
|
|
240
|
+
SLASH_SUBAGENT_REQUEST_EVENT,
|
|
241
|
+
SLASH_SUBAGENT_STARTED_EVENT,
|
|
242
|
+
SLASH_SUBAGENT_RESPONSE_EVENT,
|
|
243
|
+
SLASH_SUBAGENT_UPDATE_EVENT,
|
|
244
|
+
SLASH_SUBAGENT_CANCEL_EVENT,
|
|
245
|
+
POLL_INTERVAL_MS,
|
|
246
|
+
WIDGET_ANIMATION_INTERVAL_MS,
|
|
247
|
+
MAX_WIDGET_JOBS,
|
|
248
|
+
SUBAGENT_ACTIONS,
|
|
249
|
+
DEFAULT_FORK_PREAMBLE,
|
|
250
|
+
getAsyncConfigPath,
|
|
251
|
+
wrapForkTask,
|
|
252
|
+
resolveCurrentMaxSubagentDepth,
|
|
253
|
+
resolveChildMaxSubagentDepth,
|
|
254
|
+
checkSubagentDepth,
|
|
255
|
+
resolveChildDepth,
|
|
256
|
+
resolveMaxSubagentSpawnsPerSession,
|
|
257
|
+
normalizeMaxSubagentSpawnsPerRun,
|
|
258
|
+
resolveMaxSubagentSpawnsPerRun,
|
|
259
|
+
truncateOutput
|
|
260
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAgentDir
|
|
3
|
+
} from "./chunk-CIZQXJ5Q.js";
|
|
4
|
+
import {
|
|
5
|
+
TEMP_ARTIFACTS_DIR
|
|
6
|
+
} from "./chunk-5LFLVSTM.js";
|
|
7
|
+
|
|
8
|
+
// src/shared/artifacts.ts
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
var CLEANUP_MARKER_FILE = ".last-cleanup";
|
|
12
|
+
var PROJECT_SUBAGENTS_RELATIVE_DIR = ".pi/subagents";
|
|
13
|
+
var PROJECT_ARTIFACT_PATHS = [
|
|
14
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/output.md`,
|
|
15
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_input.md`,
|
|
16
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_output.md`,
|
|
17
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker.jsonl`,
|
|
18
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_transcript.jsonl`,
|
|
19
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_meta.json`,
|
|
20
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/progress/run/progress.md`,
|
|
21
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/outputs/output.md`,
|
|
22
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/outputs/run/output.md`,
|
|
23
|
+
`${PROJECT_SUBAGENTS_RELATIVE_DIR}/chain-runs/run.json`
|
|
24
|
+
];
|
|
25
|
+
function globMatchesPath(pattern, filePath) {
|
|
26
|
+
let expression = "^";
|
|
27
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
28
|
+
const character = pattern[index];
|
|
29
|
+
if (character === void 0) break;
|
|
30
|
+
if (character === "*" && pattern[index + 1] === "*") {
|
|
31
|
+
index += 1;
|
|
32
|
+
if (pattern[index + 1] === "/") {
|
|
33
|
+
index += 1;
|
|
34
|
+
expression += "(?:.*/)?";
|
|
35
|
+
} else {
|
|
36
|
+
expression += ".*";
|
|
37
|
+
}
|
|
38
|
+
} else if (character === "*") {
|
|
39
|
+
expression += "[^/]*";
|
|
40
|
+
} else if (character === "?") {
|
|
41
|
+
expression += "[^/]";
|
|
42
|
+
} else if (character === "[") {
|
|
43
|
+
const end = pattern.indexOf("]", index + 1);
|
|
44
|
+
if (end === -1) expression += "\\[";
|
|
45
|
+
else {
|
|
46
|
+
expression += pattern.slice(index, end + 1);
|
|
47
|
+
index = end;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
expression += character.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return new RegExp(`${expression}$`).test(filePath);
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function normalizePattern(pattern) {
|
|
60
|
+
return pattern.replace(/^\.\//, "").replace(/^\//, "").replace(/\/+$/, "");
|
|
61
|
+
}
|
|
62
|
+
function patternMatchesArtifactPath(pattern, artifactPath) {
|
|
63
|
+
const normalized = normalizePattern(pattern);
|
|
64
|
+
return normalized === PROJECT_SUBAGENTS_RELATIVE_DIR || normalized === "*" || artifactPath.startsWith(`${normalized}/`) || globMatchesPath(normalized, artifactPath);
|
|
65
|
+
}
|
|
66
|
+
function ignoreFileExcludesProjectArtifacts(filePath) {
|
|
67
|
+
if (!fs.existsSync(filePath)) return false;
|
|
68
|
+
try {
|
|
69
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const rawLine of fs.readFileSync(filePath, "utf-8").split(/\r?\n/)) {
|
|
71
|
+
const line = rawLine.trim();
|
|
72
|
+
if (!line || line.startsWith("#")) continue;
|
|
73
|
+
const negated = line.startsWith("!");
|
|
74
|
+
const pattern = negated ? line.slice(1) : line;
|
|
75
|
+
for (const artifactPath of PROJECT_ARTIFACT_PATHS) {
|
|
76
|
+
if (!patternMatchesArtifactPath(pattern, artifactPath)) continue;
|
|
77
|
+
if (negated) excluded.delete(artifactPath);
|
|
78
|
+
else excluded.add(artifactPath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return excluded.size === PROJECT_ARTIFACT_PATHS.length;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function filesIncludeProjectArtifacts(files) {
|
|
87
|
+
if (!Array.isArray(files)) return void 0;
|
|
88
|
+
const included = /* @__PURE__ */ new Set();
|
|
89
|
+
for (const entry of files) {
|
|
90
|
+
if (typeof entry !== "string") continue;
|
|
91
|
+
const negated = entry.startsWith("!");
|
|
92
|
+
const pattern = negated ? entry.slice(1) : entry;
|
|
93
|
+
for (const artifactPath of PROJECT_ARTIFACT_PATHS) {
|
|
94
|
+
if (!patternMatchesArtifactPath(pattern, artifactPath)) continue;
|
|
95
|
+
if (negated) included.delete(artifactPath);
|
|
96
|
+
else included.add(artifactPath);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return included.size > 0;
|
|
100
|
+
}
|
|
101
|
+
function getProjectArtifactPackagingWarning(cwd) {
|
|
102
|
+
const packagePath = path.join(cwd, "package.json");
|
|
103
|
+
if (!fs.existsSync(packagePath)) return void 0;
|
|
104
|
+
let packageJson;
|
|
105
|
+
try {
|
|
106
|
+
const parsed = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
107
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return void 0;
|
|
108
|
+
packageJson = parsed;
|
|
109
|
+
} catch {
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
const filesIncludeArtifacts = filesIncludeProjectArtifacts(packageJson.files);
|
|
113
|
+
if (filesIncludeArtifacts === false) return void 0;
|
|
114
|
+
const npmIgnorePath = path.join(cwd, ".npmignore");
|
|
115
|
+
const ignorePath = fs.existsSync(npmIgnorePath) ? npmIgnorePath : path.join(cwd, ".gitignore");
|
|
116
|
+
if (filesIncludeArtifacts === void 0 && ignoreFileExcludesProjectArtifacts(ignorePath)) return void 0;
|
|
117
|
+
return "Project-scoped subagent artifacts can be included when this package is published. Add '.pi/subagents/' to .npmignore, restrict package.json files, or set artifactDir to 'session' or 'temp'.";
|
|
118
|
+
}
|
|
119
|
+
function getProjectSubagentsDir(cwd) {
|
|
120
|
+
return path.join(cwd, PROJECT_SUBAGENTS_RELATIVE_DIR);
|
|
121
|
+
}
|
|
122
|
+
function getProjectArtifactsDir(cwd) {
|
|
123
|
+
return path.join(getProjectSubagentsDir(cwd), "artifacts");
|
|
124
|
+
}
|
|
125
|
+
function getArtifactsDir(sessionFile, projectCwd, dirPreference = "session") {
|
|
126
|
+
switch (dirPreference) {
|
|
127
|
+
case "session":
|
|
128
|
+
if (sessionFile) {
|
|
129
|
+
const sessionDir = path.dirname(sessionFile);
|
|
130
|
+
return path.join(sessionDir, "subagent-artifacts");
|
|
131
|
+
}
|
|
132
|
+
return TEMP_ARTIFACTS_DIR;
|
|
133
|
+
case "temp":
|
|
134
|
+
return TEMP_ARTIFACTS_DIR;
|
|
135
|
+
case "project":
|
|
136
|
+
if (projectCwd) return getProjectArtifactsDir(projectCwd);
|
|
137
|
+
if (sessionFile) {
|
|
138
|
+
const sessionDir = path.dirname(sessionFile);
|
|
139
|
+
return path.join(sessionDir, "subagent-artifacts");
|
|
140
|
+
}
|
|
141
|
+
return TEMP_ARTIFACTS_DIR;
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unsupported artifactDir ${JSON.stringify(dirPreference)}; expected "project", "session", or "temp".`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function getArtifactPaths(artifactsDir, runId, agent, index) {
|
|
147
|
+
const suffix = index !== void 0 ? `_${index}` : "";
|
|
148
|
+
const safeAgent = agent.replace(/[^\w.-]/g, "_");
|
|
149
|
+
const base = `${runId}_${safeAgent}${suffix}`;
|
|
150
|
+
return {
|
|
151
|
+
inputPath: path.join(artifactsDir, `${base}_input.md`),
|
|
152
|
+
outputPath: path.join(artifactsDir, `${base}_output.md`),
|
|
153
|
+
jsonlPath: path.join(artifactsDir, `${base}.jsonl`),
|
|
154
|
+
transcriptPath: path.join(artifactsDir, `${base}_transcript.jsonl`),
|
|
155
|
+
metadataPath: path.join(artifactsDir, `${base}_meta.json`)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function ensureArtifactsDir(dir) {
|
|
159
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
160
|
+
}
|
|
161
|
+
function writeArtifact(filePath, content) {
|
|
162
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
163
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
164
|
+
}
|
|
165
|
+
function formatOutputArtifactContent(input) {
|
|
166
|
+
if (input.output.trim() || !input.error) return input.output;
|
|
167
|
+
const lines = ["Subagent run failed before producing output.", "", "Error:", input.error];
|
|
168
|
+
if (input.transcriptPath) lines.push("", `Transcript: ${input.transcriptPath}`);
|
|
169
|
+
if (input.metadataPath) lines.push(`Metadata: ${input.metadataPath}`);
|
|
170
|
+
return lines.join("\n");
|
|
171
|
+
}
|
|
172
|
+
function writeMetadata(filePath, metadata) {
|
|
173
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
174
|
+
fs.writeFileSync(filePath, JSON.stringify(metadata, null, 2), "utf-8");
|
|
175
|
+
}
|
|
176
|
+
function appendJsonl(filePath, line) {
|
|
177
|
+
fs.appendFileSync(filePath, `${line}
|
|
178
|
+
`);
|
|
179
|
+
}
|
|
180
|
+
function cleanupOldArtifacts(dir, maxAgeDays) {
|
|
181
|
+
if (maxAgeDays <= 0 || !fs.existsSync(dir)) return;
|
|
182
|
+
const markerPath = path.join(dir, CLEANUP_MARKER_FILE);
|
|
183
|
+
const now = Date.now();
|
|
184
|
+
if (fs.existsSync(markerPath)) {
|
|
185
|
+
const stat = fs.statSync(markerPath);
|
|
186
|
+
if (now - stat.mtimeMs < 24 * 60 * 60 * 1e3) return;
|
|
187
|
+
}
|
|
188
|
+
const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1e3;
|
|
189
|
+
const cutoff = now - maxAgeMs;
|
|
190
|
+
for (const file of fs.readdirSync(dir)) {
|
|
191
|
+
if (file === CLEANUP_MARKER_FILE) continue;
|
|
192
|
+
const filePath = path.join(dir, file);
|
|
193
|
+
try {
|
|
194
|
+
const stat = fs.statSync(filePath);
|
|
195
|
+
if (stat.mtimeMs < cutoff) {
|
|
196
|
+
fs.unlinkSync(filePath);
|
|
197
|
+
}
|
|
198
|
+
} catch {
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
fs.writeFileSync(markerPath, String(now));
|
|
202
|
+
}
|
|
203
|
+
function cleanupAllArtifactDirs(maxAgeDays) {
|
|
204
|
+
cleanupOldArtifacts(TEMP_ARTIFACTS_DIR, maxAgeDays);
|
|
205
|
+
const sessionsBase = path.join(getAgentDir(), "sessions");
|
|
206
|
+
if (!fs.existsSync(sessionsBase)) return;
|
|
207
|
+
let dirs;
|
|
208
|
+
try {
|
|
209
|
+
dirs = fs.readdirSync(sessionsBase);
|
|
210
|
+
} catch {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const dir of dirs) {
|
|
214
|
+
const artifactsDir = path.join(sessionsBase, dir, "subagent-artifacts");
|
|
215
|
+
try {
|
|
216
|
+
cleanupOldArtifacts(artifactsDir, maxAgeDays);
|
|
217
|
+
} catch {
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
PROJECT_SUBAGENTS_RELATIVE_DIR,
|
|
224
|
+
getProjectArtifactPackagingWarning,
|
|
225
|
+
getProjectSubagentsDir,
|
|
226
|
+
getArtifactsDir,
|
|
227
|
+
getArtifactPaths,
|
|
228
|
+
ensureArtifactsDir,
|
|
229
|
+
writeArtifact,
|
|
230
|
+
formatOutputArtifactContent,
|
|
231
|
+
writeMetadata,
|
|
232
|
+
appendJsonl,
|
|
233
|
+
cleanupOldArtifacts,
|
|
234
|
+
cleanupAllArtifactDirs
|
|
235
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/api/inspectors.ts
|
|
2
|
+
var INSPECTOR_REGISTER_EVENT = "pi-subagents:inspector-register:v1";
|
|
3
|
+
function registerInspector(pi, plugin) {
|
|
4
|
+
const request = { version: 1, plugin };
|
|
5
|
+
pi.events.emit(INSPECTOR_REGISTER_EVENT, request);
|
|
6
|
+
if (!request.result) throw new Error("pi-subagents is not installed, not ready, or does not support inspector registration.");
|
|
7
|
+
if (!request.result.ok) throw request.result.error;
|
|
8
|
+
return request.result.registration;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
INSPECTOR_REGISTER_EVENT,
|
|
13
|
+
registerInspector
|
|
14
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/shared/launch-contract.ts
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
var AGENT_DEFINITION_PROJECTION_VERSION = 2;
|
|
5
|
+
var LAUNCH_BINDING_PROJECTION_VERSION = 2;
|
|
6
|
+
function stableJson(value) {
|
|
7
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
8
|
+
if (value && typeof value === "object") {
|
|
9
|
+
return `{${Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => `${JSON.stringify(key)}:${stableJson(entry)}`).join(",")}}`;
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
function stableJsonDigest(value) {
|
|
14
|
+
return createHash("sha256").update(stableJson(value)).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
function fileDigest(filePath) {
|
|
17
|
+
try {
|
|
18
|
+
return createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
|
|
19
|
+
} catch {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function projectAgentDefinition(agent) {
|
|
24
|
+
return {
|
|
25
|
+
version: AGENT_DEFINITION_PROJECTION_VERSION,
|
|
26
|
+
name: agent.name,
|
|
27
|
+
localName: agent.localName,
|
|
28
|
+
packageName: agent.packageName,
|
|
29
|
+
filePath: agent.filePath,
|
|
30
|
+
fileContentDigest: fileDigest(agent.filePath),
|
|
31
|
+
runner: agent.runner,
|
|
32
|
+
systemPrompt: agent.systemPrompt,
|
|
33
|
+
systemPromptMode: agent.systemPromptMode,
|
|
34
|
+
inheritProjectContext: agent.inheritProjectContext,
|
|
35
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
36
|
+
inheritSkills: agent.inheritSkills,
|
|
37
|
+
model: agent.model,
|
|
38
|
+
modelProvider: agent.modelProvider,
|
|
39
|
+
fast: agent.fast,
|
|
40
|
+
thinking: agent.thinking,
|
|
41
|
+
tools: agent.tools,
|
|
42
|
+
excludeTools: agent.excludeTools,
|
|
43
|
+
allowNestedSubagents: agent.allowNestedSubagents,
|
|
44
|
+
allowedAgents: agent.allowedAgents,
|
|
45
|
+
mcpDirectTools: agent.mcpDirectTools,
|
|
46
|
+
extensions: agent.extensions,
|
|
47
|
+
subagentOnlyExtensions: agent.subagentOnlyExtensions,
|
|
48
|
+
mutationTools: agent.mutationTools,
|
|
49
|
+
skills: agent.skills,
|
|
50
|
+
skillPath: agent.skillPath,
|
|
51
|
+
output: agent.output,
|
|
52
|
+
outputSchema: agent.outputSchema,
|
|
53
|
+
defaultReads: agent.defaultReads,
|
|
54
|
+
defaultProgress: agent.defaultProgress,
|
|
55
|
+
defaultContext: agent.defaultContext,
|
|
56
|
+
defaultAsync: agent.defaultAsync,
|
|
57
|
+
defaultTimeoutMs: agent.defaultTimeoutMs,
|
|
58
|
+
defaultAcceptance: agent.defaultAcceptance,
|
|
59
|
+
acceptanceRole: agent.acceptanceRole,
|
|
60
|
+
interactive: agent.interactive,
|
|
61
|
+
maxSubagentDepth: agent.maxSubagentDepth,
|
|
62
|
+
toolBudget: agent.toolBudget,
|
|
63
|
+
memory: agent.memory
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function agentDefinitionDigest(agent) {
|
|
67
|
+
return agent.definitionDigest ?? stableJsonDigest(projectAgentDefinition(agent));
|
|
68
|
+
}
|
|
69
|
+
function projectLaunchBinding(input) {
|
|
70
|
+
return {
|
|
71
|
+
version: LAUNCH_BINDING_PROJECTION_VERSION,
|
|
72
|
+
definitionDigest: input.definitionDigest,
|
|
73
|
+
taskDigest: input.task === void 0 ? void 0 : stableJsonDigest(input.task),
|
|
74
|
+
model: input.model,
|
|
75
|
+
fast: input.fast,
|
|
76
|
+
thinking: input.thinking,
|
|
77
|
+
systemPromptDigest: input.systemPrompt === void 0 || input.systemPrompt === null ? void 0 : stableJsonDigest(input.systemPrompt),
|
|
78
|
+
systemPromptMode: input.systemPromptMode,
|
|
79
|
+
inheritProjectContext: input.inheritProjectContext,
|
|
80
|
+
inheritGlobalContext: input.inheritGlobalContext,
|
|
81
|
+
inheritSkills: input.inheritSkills,
|
|
82
|
+
skills: input.skills,
|
|
83
|
+
tools: input.tools,
|
|
84
|
+
excludeTools: input.excludeTools,
|
|
85
|
+
extensions: input.extensions,
|
|
86
|
+
subagentOnlyExtensions: input.subagentOnlyExtensions,
|
|
87
|
+
mcpDirectTools: input.mcpDirectTools,
|
|
88
|
+
outputPath: input.outputPath,
|
|
89
|
+
outputMode: input.outputMode,
|
|
90
|
+
structuredOutputSchema: input.structuredOutputSchema,
|
|
91
|
+
extensionBindings: input.extensionBindings
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function launchBindingDigest(input) {
|
|
95
|
+
return stableJsonDigest(projectLaunchBinding(input));
|
|
96
|
+
}
|
|
97
|
+
function resolveLaunchBinding(source) {
|
|
98
|
+
const identity = "agent" in source ? {
|
|
99
|
+
definitionDigest: agentDefinitionDigest(source.agent),
|
|
100
|
+
systemPromptMode: source.agent.systemPromptMode,
|
|
101
|
+
inheritProjectContext: source.agent.inheritProjectContext,
|
|
102
|
+
inheritGlobalContext: source.agent.inheritGlobalContext,
|
|
103
|
+
inheritSkills: source.agent.inheritSkills
|
|
104
|
+
} : source;
|
|
105
|
+
return {
|
|
106
|
+
definitionDigest: identity.definitionDigest,
|
|
107
|
+
launchContractDigest: launchBindingDigest({
|
|
108
|
+
...identity,
|
|
109
|
+
task: source.task,
|
|
110
|
+
model: source.model,
|
|
111
|
+
fast: source.fast,
|
|
112
|
+
thinking: source.thinking || void 0,
|
|
113
|
+
systemPrompt: source.systemPrompt,
|
|
114
|
+
skills: source.skills,
|
|
115
|
+
tools: source.toolPlan.effectiveToolAllowlist,
|
|
116
|
+
excludeTools: source.toolPlan.excludeTools.length > 0 ? source.toolPlan.excludeTools : void 0,
|
|
117
|
+
extensions: source.toolPlan.extensionArgs,
|
|
118
|
+
mcpDirectTools: source.toolPlan.effectiveMcpTools,
|
|
119
|
+
outputPath: source.outputPath || void 0,
|
|
120
|
+
outputMode: source.outputMode,
|
|
121
|
+
structuredOutputSchema: source.structuredOutputSchema,
|
|
122
|
+
extensionBindings: source.extensionBindings || void 0
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export {
|
|
128
|
+
AGENT_DEFINITION_PROJECTION_VERSION,
|
|
129
|
+
stableJsonDigest,
|
|
130
|
+
agentDefinitionDigest,
|
|
131
|
+
resolveLaunchBinding
|
|
132
|
+
};
|