pi-subagents 0.88.0 → 0.89.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 +54 -1
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +3 -3
- package/bundle/{chunk-UVDLJXL6.js → chunk-2I6YN6ET.js} +34 -5
- package/bundle/{chunk-6EUQPQY7.js → chunk-443LPCRI.js} +5 -5
- package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
- package/bundle/{chunk-CKLZ5FGU.js → chunk-4ALRHKGE.js} +1 -1
- package/bundle/{chunk-SVIXQDIV.js → chunk-6JD4XCA4.js} +77 -19
- package/bundle/{chunk-RHYVKQQL.js → chunk-7W2IQFP4.js} +4 -4
- package/bundle/{chunk-W6HIYD2Z.js → chunk-A3INCQ6Z.js} +1 -1
- package/bundle/{chunk-4PM6RDE5.js → chunk-AZW4HXNU.js} +54 -36
- package/bundle/{chunk-XAOHLFJO.js → chunk-CHEABMO2.js} +68 -41
- package/bundle/{chunk-CYKNHFXB.js → chunk-EPMRDKQT.js} +1 -1
- package/bundle/{chunk-6PR44R7E.js → chunk-ETDE2VYK.js} +2 -2
- package/bundle/{chunk-4MVDMA5C.js → chunk-GHJ6BH5U.js} +13 -7
- package/bundle/{chunk-IZEKQEY4.js → chunk-HSHLPYCQ.js} +27 -10
- package/bundle/{chunk-3MFYKBKI.js → chunk-HZDLR73C.js} +4 -4
- package/bundle/{chunk-2DIEL4WG.js → chunk-JFACGAJT.js} +2 -2
- package/bundle/{chunk-L4YY2TOE.js → chunk-JRO2CU4D.js} +1 -1
- package/bundle/{chunk-KXW62VBU.js → chunk-KOLLMZ2X.js} +1 -1
- package/bundle/{chunk-47ZN7NKR.js → chunk-NONHDYXE.js} +1 -1
- package/bundle/{chunk-PJSOS2Q4.js → chunk-NQ26PJSQ.js} +96 -96
- package/bundle/{chunk-6OWNDN7R.js → chunk-PPPAEFRA.js} +2 -2
- package/bundle/{chunk-YDZ7BZD5.js → chunk-S77ZKDLS.js} +1 -1
- package/bundle/{chunk-3DT5X2QC.js → chunk-SLLZJ5EC.js} +50 -18
- package/bundle/{chunk-47GJDBIK.js → chunk-TGABNSG5.js} +5 -5
- package/bundle/{chunk-XIA5GSEU.js → chunk-UQT2EQ4U.js} +2 -2
- package/bundle/{chunk-YZPVALSQ.js → chunk-WW6GQBBS.js} +4 -4
- package/bundle/{chunk-4UGWHREQ.js → chunk-X5ZOTDHO.js} +95 -49
- package/bundle/{chunk-CTPAE36Y.js → chunk-YARY7JWU.js} +22 -0
- package/bundle/{chunk-MTPICU4A.js → chunk-YX7R55CR.js} +75 -32
- package/bundle/{chunk-GDR2ILWY.js → chunk-ZSCIHMUI.js} +50 -22
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +2 -2
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +9 -9
- package/bundle/project-panes.js +3 -3
- package/bundle/required-child-extensions.js +1 -1
- package/docs/agents.md +14 -6
- package/docs/configuration.md +2 -0
- package/docs/extension-api.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +8 -4
- package/package.json +1 -1
- package/src/extension/herdr-pi-bridge.js +78 -22
- package/src/extension/index.d.ts +1 -1
- package/src/extension/index.js +43 -20
- package/src/extension/schemas.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +6 -2
- package/src/extension/subagent-launch-tool.js +13 -9
- package/src/extension/subagent-options.js +5 -0
- package/src/intercom/result-intercom.js +3 -2
- package/src/runs/background/notify.d.ts +3 -0
- package/src/runs/background/notify.js +7 -2
- package/src/runs/background/run-status.js +3 -2
- package/src/runs/background/runner-child-launch.js +1 -0
- package/src/runs/background/stale-run-reconciler.js +17 -8
- package/src/runs/background/subagent-runner.js +11 -8
- package/src/runs/foreground/execution.js +8 -7
- package/src/runs/foreground/subagent-executor.js +42 -11
- package/src/runs/shared/child-launch.d.ts +2 -0
- package/src/runs/shared/child-launch.js +7 -4
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +3 -27
- package/src/runs/shared/herdr-connection.d.ts +6 -0
- package/src/runs/shared/herdr-connection.js +11 -1
- package/src/runs/shared/herdr-machine.d.ts +2 -2
- package/src/runs/shared/herdr-machine.js +47 -22
- package/src/runs/shared/herdr-pane-host.d.ts +7 -19
- package/src/runs/shared/herdr-pane-host.js +48 -33
- package/src/runs/shared/herdr-pi-protocol.d.ts +1 -0
- package/src/runs/shared/herdr-pi-protocol.js +3 -2
- package/src/runs/shared/herdr-placed-run.d.ts +2 -12
- package/src/runs/shared/herdr-placed-run.js +10 -8
- package/src/runs/shared/kept-branch-text.d.ts +8 -0
- package/src/runs/shared/kept-branch-text.js +24 -0
- package/src/runs/shared/local-machine-access.d.ts +4 -1
- package/src/runs/shared/local-machine-access.js +6 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +5 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -4
- package/src/runs/shared/mutation-evidence.d.ts +7 -1
- package/src/runs/shared/mutation-evidence.js +18 -2
- package/src/runs/shared/parallel-handoff.js +19 -7
- package/src/runs/shared/placed-run-owner.d.ts +4 -2
- package/src/runs/shared/placed-run-owner.js +15 -7
- package/src/runs/shared/rex-machine.d.ts +7 -3
- package/src/runs/shared/rex-machine.js +12 -9
- package/src/runs/shared/rex-pane-host.js +7 -27
- package/src/runs/shared/single-output.js +2 -2
- package/src/runs/shared/subagent-prompt-runtime.js +33 -0
- package/src/runs/shared/tool-availability.d.ts +4 -0
- package/src/runs/shared/tool-availability.js +7 -0
- package/src/runs/shared/worktree-cleanup-plan.js +2 -2
- package/src/runs/shared/worktree.d.ts +4 -14
- package/src/runs/shared/worktree.js +38 -8
- package/src/shared/compaction-interruption.d.ts +9 -0
- package/src/shared/compaction-interruption.js +47 -0
- package/src/shared/parent-wake.d.ts +3 -2
- package/src/shared/parent-wake.js +14 -3
- package/src/shared/required-child-extensions.d.ts +2 -0
- package/src/shared/required-child-extensions.js +27 -0
- package/src/shared/types.d.ts +26 -2
- package/src/tui/fleet.d.ts +7 -2
- package/src/tui/fleet.js +22 -0
- package/src/workflows/workflow-child-summary.d.ts +2 -1
- package/src/workflows/workflow-child-summary.js +14 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildWorkflowChatProgressRows
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7W2IQFP4.js";
|
|
4
4
|
import {
|
|
5
5
|
aggregateStepStatus,
|
|
6
6
|
contextModeBadge,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
projectAsyncWorkflowRows,
|
|
23
23
|
projectWorkflowChecklist,
|
|
24
24
|
workflowGraphStageNodes
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-6JD4XCA4.js";
|
|
26
26
|
import {
|
|
27
27
|
isStaleExtensionContextError,
|
|
28
28
|
isUnboundExtensionRuntimeError,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
formatWorkflowJsonPreview,
|
|
35
35
|
hostStepReportName,
|
|
36
36
|
hostStepVerdictLabel
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-SLLZJ5EC.js";
|
|
38
38
|
import {
|
|
39
39
|
snapshotExternalRuns
|
|
40
40
|
} from "./chunk-UKG4V45O.js";
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
getSingleResultOutput,
|
|
53
53
|
shortenPath,
|
|
54
54
|
unresolvedChildWatchdogBlockers
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-GHJ6BH5U.js";
|
|
56
56
|
import {
|
|
57
57
|
MAX_WIDGET_JOBS,
|
|
58
58
|
WIDGET_ANIMATION_INTERVAL_MS,
|
|
@@ -11,18 +11,21 @@ import {
|
|
|
11
11
|
startWatchdogDiffBaselineCapture,
|
|
12
12
|
writeUserWatchdogEnabled,
|
|
13
13
|
writeWatchdogModelSettings
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-TGABNSG5.js";
|
|
15
15
|
import {
|
|
16
16
|
resolveGitRepositoryIdentity
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7W2IQFP4.js";
|
|
18
18
|
import {
|
|
19
|
+
formatParallelHandoffLines,
|
|
19
20
|
listAsyncRuns,
|
|
20
21
|
parallelHandoffPath,
|
|
22
|
+
parseKeptBranchLines,
|
|
21
23
|
parseWorkflowChildSummary,
|
|
22
24
|
readAsyncRecoveryDescriptor,
|
|
25
|
+
readKeptBranches,
|
|
23
26
|
readWorkflowLaunchRecord,
|
|
24
27
|
resolveRetainedWorktreeCwd
|
|
25
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-6JD4XCA4.js";
|
|
26
29
|
import {
|
|
27
30
|
ownsRun
|
|
28
31
|
} from "./chunk-HXRB42AF.js";
|
|
@@ -54,21 +57,24 @@ import {
|
|
|
54
57
|
resolveMissionStoreLocation,
|
|
55
58
|
validateMissionId,
|
|
56
59
|
workflowRunParamsFingerprint
|
|
57
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-SLLZJ5EC.js";
|
|
58
61
|
import {
|
|
59
62
|
requestAsyncCommand,
|
|
60
63
|
watchAsyncControlInbox
|
|
61
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-A3INCQ6Z.js";
|
|
62
65
|
import {
|
|
63
66
|
supervisorChannelDir
|
|
64
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-HZDLR73C.js";
|
|
68
|
+
import {
|
|
69
|
+
createRequiredChildExtensionIdentity
|
|
70
|
+
} from "./chunk-YARY7JWU.js";
|
|
65
71
|
import {
|
|
66
72
|
createHerdrClient,
|
|
67
73
|
detectHerdr
|
|
68
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-JFACGAJT.js";
|
|
69
75
|
import {
|
|
70
76
|
getProjectSubagentsDir
|
|
71
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-S77ZKDLS.js";
|
|
72
78
|
import {
|
|
73
79
|
ExternalJobProviderError,
|
|
74
80
|
getExternalJobProvider,
|
|
@@ -78,7 +84,7 @@ import {
|
|
|
78
84
|
} from "./chunk-YYREO77V.js";
|
|
79
85
|
import {
|
|
80
86
|
mergeRuntimeAgents
|
|
81
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-KOLLMZ2X.js";
|
|
82
88
|
import {
|
|
83
89
|
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
84
90
|
EXTERNAL_CLI_ADAPTER_SAFETY,
|
|
@@ -139,7 +145,7 @@ import {
|
|
|
139
145
|
withFileLease,
|
|
140
146
|
writeAtomicJson,
|
|
141
147
|
writePrivateAtomicJson
|
|
142
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-GHJ6BH5U.js";
|
|
143
149
|
import {
|
|
144
150
|
DIRS,
|
|
145
151
|
INTERCOM_DETACH_REQUEST_EVENT,
|
|
@@ -167,6 +173,43 @@ import {
|
|
|
167
173
|
resolveCurrentSubagentCapabilityCeiling
|
|
168
174
|
} from "./chunk-QXASAHIA.js";
|
|
169
175
|
|
|
176
|
+
// src/shared/compaction-interruption.ts
|
|
177
|
+
var stateSymbol = /* @__PURE__ */ Symbol.for("pi-subagents.compaction-interruption.v1");
|
|
178
|
+
var wrappedSymbol = /* @__PURE__ */ Symbol.for("pi-subagents.compaction-interruption.v1.wrapped");
|
|
179
|
+
var globalStore = globalThis;
|
|
180
|
+
var compactions = globalStore[stateSymbol] ??= /* @__PURE__ */ new WeakMap();
|
|
181
|
+
function installCompactionInterruptionCapture(sessionClass) {
|
|
182
|
+
const prototype = sessionClass.prototype;
|
|
183
|
+
const original = prototype.compact;
|
|
184
|
+
if (original[wrappedSymbol]) return;
|
|
185
|
+
const compact = async function(...args) {
|
|
186
|
+
const manager = this.sessionManager;
|
|
187
|
+
const compaction = compactions.get(manager) ?? { calls: 0, interrupted: false, abortPending: false };
|
|
188
|
+
compactions.set(manager, compaction);
|
|
189
|
+
compaction.calls += 1;
|
|
190
|
+
if (this.isStreaming) compaction.interrupted = compaction.abortPending = true;
|
|
191
|
+
try {
|
|
192
|
+
return await original.apply(this, args);
|
|
193
|
+
} finally {
|
|
194
|
+
if (--compaction.calls === 0) compactions.delete(manager);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
compact[wrappedSymbol] = true;
|
|
198
|
+
prototype.compact = compact;
|
|
199
|
+
}
|
|
200
|
+
function compactionInProgress(sessionManager) {
|
|
201
|
+
return compactions.has(sessionManager);
|
|
202
|
+
}
|
|
203
|
+
function compactionInterruptedRun(sessionManager) {
|
|
204
|
+
return compactions.get(sessionManager)?.interrupted === true;
|
|
205
|
+
}
|
|
206
|
+
function takeCompactionAbort(sessionManager) {
|
|
207
|
+
const compaction = compactions.get(sessionManager);
|
|
208
|
+
if (!compaction?.abortPending) return false;
|
|
209
|
+
compaction.abortPending = false;
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
170
213
|
// src/inspectors/herdr/actions.ts
|
|
171
214
|
import * as fs from "node:fs";
|
|
172
215
|
import * as path from "node:path";
|
|
@@ -1223,7 +1266,7 @@ function formatSubagentResultIntercomMessage(input) {
|
|
|
1223
1266
|
}
|
|
1224
1267
|
if (input.asyncId) lines.push(`Async id: ${input.asyncId}`);
|
|
1225
1268
|
if (input.asyncDir) lines.push(`Async dir: ${input.asyncDir}`);
|
|
1226
|
-
if (input.parallelHandoff) lines.push(
|
|
1269
|
+
if (input.parallelHandoff) lines.push(...formatParallelHandoffLines(input.parallelHandoff.path, input.parallelHandoff.keptBranches));
|
|
1227
1270
|
const resumeGuidance = asyncResumeGuidance(input);
|
|
1228
1271
|
if (resumeGuidance) lines.push(resumeGuidance);
|
|
1229
1272
|
if (input.children.some((child) => child.intercomTarget)) {
|
|
@@ -1328,7 +1371,7 @@ function formatSubagentResultReceipt(input) {
|
|
|
1328
1371
|
`Run: ${input.runId}`,
|
|
1329
1372
|
`Children: ${formatStatusCounts(counts)}`
|
|
1330
1373
|
];
|
|
1331
|
-
if (input.payload.parallelHandoff) lines.push(
|
|
1374
|
+
if (input.payload.parallelHandoff) lines.push(...formatParallelHandoffLines(input.payload.parallelHandoff.path, input.payload.parallelHandoff.keptBranches));
|
|
1332
1375
|
const artifacts = input.payload.children.filter((child) => typeof child.artifactPath === "string");
|
|
1333
1376
|
if (artifacts.length > 0) {
|
|
1334
1377
|
lines.push("Artifacts:");
|
|
@@ -5054,6 +5097,7 @@ function createParentWake(pi, now = Date.now) {
|
|
|
5054
5097
|
let ctx;
|
|
5055
5098
|
let session;
|
|
5056
5099
|
let held = false;
|
|
5100
|
+
let deferred = false;
|
|
5057
5101
|
const reservation = () => {
|
|
5058
5102
|
if (!session) return { sessionId: "" };
|
|
5059
5103
|
const current = reservations.get(session.manager);
|
|
@@ -5076,6 +5120,11 @@ function createParentWake(pi, now = Date.now) {
|
|
|
5076
5120
|
pi.sendMessage(message, { triggerTurn: false });
|
|
5077
5121
|
return true;
|
|
5078
5122
|
}
|
|
5123
|
+
if (session && compactionInProgress(session.manager)) {
|
|
5124
|
+
deferred = true;
|
|
5125
|
+
pi.sendMessage(message, { triggerTurn: false });
|
|
5126
|
+
return true;
|
|
5127
|
+
}
|
|
5079
5128
|
if (ctx.isIdle()) reservation().sentAt = now();
|
|
5080
5129
|
pi.sendMessage(message, options);
|
|
5081
5130
|
return false;
|
|
@@ -5084,19 +5133,21 @@ function createParentWake(pi, now = Date.now) {
|
|
|
5084
5133
|
bindSession(context) {
|
|
5085
5134
|
ctx = context;
|
|
5086
5135
|
session = { manager: context.sessionManager, id: context.sessionManager.getSessionId() };
|
|
5087
|
-
held = false;
|
|
5136
|
+
held = deferred = false;
|
|
5088
5137
|
},
|
|
5089
5138
|
agentStarted() {
|
|
5090
5139
|
reservation().sentAt = void 0;
|
|
5091
|
-
held = false;
|
|
5140
|
+
held = deferred = false;
|
|
5092
5141
|
},
|
|
5093
5142
|
userAborted: () => {
|
|
5094
5143
|
held = true;
|
|
5095
5144
|
},
|
|
5096
|
-
releaseHold: () => {
|
|
5097
|
-
held = false;
|
|
5098
|
-
},
|
|
5099
5145
|
isHeld: () => held,
|
|
5146
|
+
takeDeferredWake() {
|
|
5147
|
+
const wasDeferred = deferred;
|
|
5148
|
+
deferred = false;
|
|
5149
|
+
return wasDeferred;
|
|
5150
|
+
},
|
|
5100
5151
|
sessionShutdown(reason) {
|
|
5101
5152
|
if (reason !== "reload") reservation().sentAt = void 0;
|
|
5102
5153
|
}
|
|
@@ -5581,7 +5632,7 @@ function formatSingleCompletion(details) {
|
|
|
5581
5632
|
formatResultPreview(details),
|
|
5582
5633
|
...watchdogLines.length ? ["", ...watchdogLines] : [],
|
|
5583
5634
|
details.handoffPath ? "" : void 0,
|
|
5584
|
-
details.handoffPath ?
|
|
5635
|
+
...details.handoffPath ? formatParallelHandoffLines(details.handoffPath, details.keptBranches) : [],
|
|
5585
5636
|
correlationLines.length && !details.handoffPath ? "" : void 0,
|
|
5586
5637
|
...correlationLines,
|
|
5587
5638
|
sessionLine ? "" : void 0,
|
|
@@ -5643,6 +5694,7 @@ function parseSubagentNotifyContent(content) {
|
|
|
5643
5694
|
const resultEnd = firstMetadataIndex > 0 && body[firstMetadataIndex - 1]?.trim() === "" ? firstMetadataIndex - 1 : firstMetadataIndex;
|
|
5644
5695
|
const resultPreview = body.slice(0, resultEnd).join("\n").trim() || "(no output)";
|
|
5645
5696
|
const handoffPath = handoffIndex >= 0 ? body[handoffIndex].slice("Parallel handoff: ".length).trim() : void 0;
|
|
5697
|
+
const keptBranches = handoffIndex >= 0 ? parseKeptBranchLines(body.slice(handoffIndex + 1)) : [];
|
|
5646
5698
|
const workflowRunId = workflowRunIndex >= 0 ? body[workflowRunIndex].slice("Workflow run: ".length).trim() : void 0;
|
|
5647
5699
|
const childRuns = childRunsIndex >= 0 ? body[childRunsIndex].slice("Child runs: ".length).split(", ").map((part) => {
|
|
5648
5700
|
const trimmed = part.trim();
|
|
@@ -5668,6 +5720,7 @@ function parseSubagentNotifyContent(content) {
|
|
|
5668
5720
|
...workflowReceiptPath2 ? { workflowReceiptPath: workflowReceiptPath2 } : {},
|
|
5669
5721
|
resultPreview,
|
|
5670
5722
|
...handoffPath ? { handoffPath } : {},
|
|
5723
|
+
...keptBranches.length ? { keptBranches } : {},
|
|
5671
5724
|
...workflowRunId ? { workflowRunId } : {},
|
|
5672
5725
|
...resumeNotice ? { resumeNotice } : {},
|
|
5673
5726
|
...childRuns?.length ? { childRuns } : {},
|
|
@@ -5687,7 +5740,7 @@ function formatGroupedCompletion(details) {
|
|
|
5687
5740
|
if (detail.workflowReceiptPath) blocks.push(`Workflow receipt: ${detail.workflowReceiptPath}`);
|
|
5688
5741
|
blocks.push(formatResultPreview(detail));
|
|
5689
5742
|
blocks.push(...formatWatchdogBlockerLines(detail));
|
|
5690
|
-
if (detail.handoffPath) blocks.push(
|
|
5743
|
+
if (detail.handoffPath) blocks.push(...formatParallelHandoffLines(detail.handoffPath, detail.keptBranches));
|
|
5691
5744
|
blocks.push(...formatCorrelationLines(detail));
|
|
5692
5745
|
if (sessionLine) blocks.push(sessionLine);
|
|
5693
5746
|
blocks.push("");
|
|
@@ -5829,6 +5882,7 @@ function buildCompletionDetails(result5) {
|
|
|
5829
5882
|
const taskInfo = runningChildren > 0 ? ` (${status === "completed" ? "dispatch complete; " : ""}${runningChildren} ${runningChildren === 1 ? "child" : "children"} running or uncollected)` : result5.taskIndex !== void 0 && result5.totalTasks !== void 0 ? ` (${result5.taskIndex + 1}/${result5.totalTasks})` : void 0;
|
|
5830
5883
|
const parallelHandoff = result5.parallelHandoff && typeof result5.parallelHandoff === "object" ? result5.parallelHandoff : void 0;
|
|
5831
5884
|
const handoffPath = typeof parallelHandoff?.path === "string" ? parallelHandoff.path : void 0;
|
|
5885
|
+
const keptBranches = readKeptBranches(parallelHandoff?.keptBranches);
|
|
5832
5886
|
const receipt = result5.workflowReceipt;
|
|
5833
5887
|
const receiptPath = receipt && typeof receipt === "object" && !Array.isArray(receipt) ? receipt.path : void 0;
|
|
5834
5888
|
const workflowReceiptPath2 = typeof receiptPath === "string" && receiptPath ? receiptPath : void 0;
|
|
@@ -5927,6 +5981,7 @@ High-importance watchdog concerns:
|
|
|
5927
5981
|
${watchdogConcerns.map((warning) => `- ${warning}`).join("\n")}` : resultPreview,
|
|
5928
5982
|
...typeof result5.durationMs === "number" ? { durationMs: result5.durationMs } : {},
|
|
5929
5983
|
...handoffPath ? { handoffPath } : {},
|
|
5984
|
+
...handoffPath && keptBranches.length ? { keptBranches } : {},
|
|
5930
5985
|
...rawRunId ? { runId: rawRunId } : {},
|
|
5931
5986
|
...workflowRunId ? { workflowRunId } : {},
|
|
5932
5987
|
...resumeNotice ? { resumeNotice } : {},
|
|
@@ -7335,27 +7390,6 @@ function inheritParentProviders(modelRuntime, parentProviders, claimedProviderId
|
|
|
7335
7390
|
var CHILD_PROMPT_RUNTIME_EXTENSION_PATH = "<inline:pi-subagents:prompt-runtime>";
|
|
7336
7391
|
var CHILD_PROMPT_BOUNDARY_EXTENSION_PATH = "<inline:pi-subagents:prompt-boundary>";
|
|
7337
7392
|
var PI_UNICODE_SPACES = new RegExp("[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]", "g");
|
|
7338
|
-
function childExtensionFileIdentity(extensionPath) {
|
|
7339
|
-
if (!path12.isAbsolute(extensionPath)) return void 0;
|
|
7340
|
-
try {
|
|
7341
|
-
const stat = fs13.statSync(extensionPath, { bigint: true });
|
|
7342
|
-
return stat.isFile() ? `${stat.dev}:${stat.ino}` : void 0;
|
|
7343
|
-
} catch {
|
|
7344
|
-
return void 0;
|
|
7345
|
-
}
|
|
7346
|
-
}
|
|
7347
|
-
function createRequiredChildExtensionIdentity(requiredPaths) {
|
|
7348
|
-
const aliases = new Map([...requiredPaths].map((extensionPath) => [extensionPath, childExtensionFileIdentity(extensionPath) ?? extensionPath]));
|
|
7349
|
-
const identities = new Set(aliases.values());
|
|
7350
|
-
return (extensionPath) => {
|
|
7351
|
-
const known = aliases.get(extensionPath);
|
|
7352
|
-
if (known !== void 0) return known;
|
|
7353
|
-
const identity = childExtensionFileIdentity(extensionPath);
|
|
7354
|
-
if (identity === void 0 || !identities.has(identity)) return void 0;
|
|
7355
|
-
aliases.set(extensionPath, identity);
|
|
7356
|
-
return identity;
|
|
7357
|
-
};
|
|
7358
|
-
}
|
|
7359
7393
|
function orderChildPromptHooks(result5) {
|
|
7360
7394
|
const runtime = result5.extensions.filter(({ path: path17 }) => path17 === CHILD_PROMPT_RUNTIME_EXTENSION_PATH);
|
|
7361
7395
|
const boundary = result5.extensions.filter(({ path: path17 }) => path17 === CHILD_PROMPT_BOUNDARY_EXTENSION_PATH);
|
|
@@ -7710,7 +7744,7 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7710
7744
|
await session2.bindExtensions({
|
|
7711
7745
|
mode: "print",
|
|
7712
7746
|
onError: (error2) => {
|
|
7713
|
-
if (binding && isRequiredSource(error2.extensionPath)) requiredStartupErrors.push(`${error2.extensionPath} (${error2.event}): ${error2.error}`);
|
|
7747
|
+
if (binding && error2.event !== "register_mcp_server" && isRequiredSource(error2.extensionPath)) requiredStartupErrors.push(`${error2.extensionPath} (${error2.event}): ${error2.error}`);
|
|
7714
7748
|
launch.onExtensionError?.({ extensionPath: error2.extensionPath, event: error2.event, error: error2.error });
|
|
7715
7749
|
}
|
|
7716
7750
|
});
|
|
@@ -7854,7 +7888,7 @@ function childSessionFactory() {
|
|
|
7854
7888
|
}
|
|
7855
7889
|
function createLazyPlacementFactory(local) {
|
|
7856
7890
|
let placed;
|
|
7857
|
-
const factory = async () => placed ??= (await import("./chunk-
|
|
7891
|
+
const factory = async () => placed ??= (await import("./chunk-NQ26PJSQ.js")).createPlacementAwareChildSessionFactory(local);
|
|
7858
7892
|
return {
|
|
7859
7893
|
async create(launch) {
|
|
7860
7894
|
return launch.machine ? (await factory()).create(launch) : local.create(launch);
|
|
@@ -8084,6 +8118,10 @@ var optionKeys = new Set(SUBAGENT_OPTION_KEYS);
|
|
|
8084
8118
|
var ALIAS_HINTS = { runId: "id (top-level)", maxRuntimeMs: "options.timeoutMs", isolation: "worktree (top-level)" };
|
|
8085
8119
|
var optionsValidator = Compile(SubagentOptionParams);
|
|
8086
8120
|
function flattenSubagentToolOptions(params, disabled) {
|
|
8121
|
+
params = Object.fromEntries(Object.entries(params).filter(([key, value]) => value !== "null" && !(key === "workflow" && value === "false")));
|
|
8122
|
+
if (params.options && typeof params.options === "object" && !Array.isArray(params.options)) {
|
|
8123
|
+
params.options = Object.fromEntries(Object.entries(params.options).filter(([, value]) => value !== "null"));
|
|
8124
|
+
}
|
|
8087
8125
|
const removedTopLevel = removedModelWorkflowFieldError(params);
|
|
8088
8126
|
if (removedTopLevel) throw new Error(removedTopLevel);
|
|
8089
8127
|
const { options, ...topLevel } = params;
|
|
@@ -8249,23 +8287,27 @@ function registerSubagentLaunchTool(pi) {
|
|
|
8249
8287
|
pi.registerTool({
|
|
8250
8288
|
name: SUBAGENT_LAUNCH_TOOL,
|
|
8251
8289
|
label: "Subagent launch",
|
|
8252
|
-
description: "A workflow is about to start this subagent. Blocking this call stops that child from starting.",
|
|
8290
|
+
description: "A workflow is about to start this subagent. Blocking this call stops that child from starting; changing its task changes what the child is told.",
|
|
8253
8291
|
parameters,
|
|
8254
8292
|
exposure: "deferred",
|
|
8255
|
-
|
|
8256
|
-
|
|
8293
|
+
// Pi hands execute the input after every tool_call handler ran, so a handler's change to task arrives here.
|
|
8294
|
+
async execute(_toolCallId, params) {
|
|
8295
|
+
return { content: [{ type: "text", text: "Records approval for a workflow child launch; it starts nothing itself." }], details: { task: params.task } };
|
|
8257
8296
|
}
|
|
8258
8297
|
});
|
|
8259
8298
|
}
|
|
8260
8299
|
async function approveWorkflowChildLaunch(ctx, describe, signal) {
|
|
8261
|
-
if (!("executeTool" in ctx)) return
|
|
8300
|
+
if (!("executeTool" in ctx)) return {};
|
|
8262
8301
|
const toolCtx = ctx;
|
|
8263
|
-
if (!toolCtx.tools.some((tool) => tool.name === SUBAGENT_LAUNCH_TOOL)) return
|
|
8302
|
+
if (!toolCtx.tools.some((tool) => tool.name === SUBAGENT_LAUNCH_TOOL)) return {};
|
|
8264
8303
|
const args = describe();
|
|
8265
8304
|
const outcome = await toolCtx.executeTool(SUBAGENT_LAUNCH_TOOL, args, { signal });
|
|
8266
|
-
if (!outcome.isError)
|
|
8305
|
+
if (!outcome.isError) {
|
|
8306
|
+
const task = outcome.result.details?.task;
|
|
8307
|
+
return { task: typeof task === "string" ? task : void 0 };
|
|
8308
|
+
}
|
|
8267
8309
|
const reason = outcome.result.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n").trim();
|
|
8268
|
-
return `Workflow child '${args.key}' was not started: the ${SUBAGENT_LAUNCH_TOOL} call was refused${reason ? `: ${reason}` : "."}
|
|
8310
|
+
return { refusal: `Workflow child '${args.key}' was not started: the ${SUBAGENT_LAUNCH_TOOL} call was refused${reason ? `: ${reason}` : "."}` };
|
|
8269
8311
|
}
|
|
8270
8312
|
|
|
8271
8313
|
// src/runs/shared/external-job-bridge.ts
|
|
@@ -8692,6 +8734,10 @@ function sameProviderDiagnostics(left, right) {
|
|
|
8692
8734
|
}
|
|
8693
8735
|
|
|
8694
8736
|
export {
|
|
8737
|
+
installCompactionInterruptionCapture,
|
|
8738
|
+
compactionInProgress,
|
|
8739
|
+
compactionInterruptedRun,
|
|
8740
|
+
takeCompactionAbort,
|
|
8695
8741
|
getInspectorPlugins,
|
|
8696
8742
|
registerInspectorEventListener,
|
|
8697
8743
|
effectiveToolTimeoutMs,
|
|
@@ -68,6 +68,27 @@ function assertRequiredChildExtensionsAdmitted(snapshots, launch) {
|
|
|
68
68
|
const route = launch.machine ? `machine '${launch.machine}'` : launch.runnerType !== void 0 && launch.runnerType !== "pi" ? `runner.type='${launch.runnerType}'` : void 0;
|
|
69
69
|
if (route) throw new Error(`Agent '${launch.agent}' cannot run on ${route}: the host requires child extensions (${ids.join(", ")}) for every runner, and only local native Pi children load them.`);
|
|
70
70
|
}
|
|
71
|
+
function childExtensionFileIdentity(extensionPath) {
|
|
72
|
+
if (!path.isAbsolute(extensionPath)) return void 0;
|
|
73
|
+
try {
|
|
74
|
+
const stat = fs.statSync(extensionPath, { bigint: true });
|
|
75
|
+
return stat.isFile() ? `${stat.dev}:${stat.ino}` : void 0;
|
|
76
|
+
} catch {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function createRequiredChildExtensionIdentity(requiredPaths) {
|
|
81
|
+
const aliases = new Map([...requiredPaths].map((extensionPath) => [extensionPath, childExtensionFileIdentity(extensionPath) ?? extensionPath]));
|
|
82
|
+
const identities = new Set(aliases.values());
|
|
83
|
+
return (extensionPath) => {
|
|
84
|
+
const known = aliases.get(extensionPath);
|
|
85
|
+
if (known !== void 0) return known;
|
|
86
|
+
const identity = childExtensionFileIdentity(extensionPath);
|
|
87
|
+
if (identity === void 0 || !identities.has(identity)) return void 0;
|
|
88
|
+
aliases.set(extensionPath, identity);
|
|
89
|
+
return identity;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
71
92
|
function hasMandatoryRequiredChildExtensions(snapshot) {
|
|
72
93
|
return snapshot?.some((entry) => entry.requireForAllRunners) === true;
|
|
73
94
|
}
|
|
@@ -88,6 +109,7 @@ export {
|
|
|
88
109
|
registerRequiredChildExtensions,
|
|
89
110
|
resolveRequiredChildExtensions,
|
|
90
111
|
assertRequiredChildExtensionsAdmitted,
|
|
112
|
+
createRequiredChildExtensionIdentity,
|
|
91
113
|
hasMandatoryRequiredChildExtensions,
|
|
92
114
|
writeRetainedRequiredChildExtensions,
|
|
93
115
|
readRetainedRequiredChildExtensions
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
rewriteSubagentPrompt
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2I6YN6ET.js";
|
|
4
4
|
import {
|
|
5
5
|
package_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4ALRHKGE.js";
|
|
7
7
|
import {
|
|
8
8
|
WATCHDOG_DIFF_TOOL_NAME,
|
|
9
9
|
captureWatchdogDiffBaseline,
|
|
10
10
|
createWatchdogDiffTool
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-TGABNSG5.js";
|
|
12
|
+
import "./chunk-6JD4XCA4.js";
|
|
13
|
+
import "./chunk-EPMRDKQT.js";
|
|
14
14
|
import {
|
|
15
15
|
MODEL_ONLY_TOOL
|
|
16
16
|
} from "./chunk-HXRB42AF.js";
|
|
17
17
|
import "./chunk-W2BZS6UC.js";
|
|
18
18
|
import {
|
|
19
19
|
appendAgentRefinementOverlay
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-UQT2EQ4U.js";
|
|
21
|
+
import "./chunk-SLLZJ5EC.js";
|
|
22
22
|
import "./chunk-NIXWDZZV.js";
|
|
23
|
-
import "./chunk-
|
|
23
|
+
import "./chunk-NONHDYXE.js";
|
|
24
24
|
import "./chunk-7F6RKT6W.js";
|
|
25
25
|
import {
|
|
26
26
|
assertNoToolModifierEntries
|
|
27
|
-
} from "./chunk-
|
|
28
|
-
import "./chunk-
|
|
29
|
-
import "./chunk-
|
|
27
|
+
} from "./chunk-HZDLR73C.js";
|
|
28
|
+
import "./chunk-YARY7JWU.js";
|
|
29
|
+
import "./chunk-S77ZKDLS.js";
|
|
30
30
|
import {
|
|
31
|
+
HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES,
|
|
31
32
|
HERDR_PI_MAX_FRAME_BYTES,
|
|
32
33
|
HERDR_PI_PROTOCOL,
|
|
33
34
|
HERDR_PI_RUNTIME_DIR_ENV,
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
HerdrPiFrameDecoder,
|
|
36
37
|
encodeHerdrPiFrame,
|
|
37
38
|
validateHerdrPiRunId
|
|
38
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-4AL6LDBY.js";
|
|
39
40
|
import "./chunk-XA3DY6UG.js";
|
|
40
41
|
import {
|
|
41
42
|
buildAgentMemoryInjection,
|
|
@@ -43,7 +44,7 @@ import {
|
|
|
43
44
|
discoverAgents,
|
|
44
45
|
resolveExistingReadPaths,
|
|
45
46
|
resolveSkills
|
|
46
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-GHJ6BH5U.js";
|
|
47
48
|
import "./chunk-JEZOSEWG.js";
|
|
48
49
|
import "./chunk-YFCK7H2S.js";
|
|
49
50
|
import "./chunk-QXASAHIA.js";
|
|
@@ -63,6 +64,32 @@ function gitEvidence(cwd) {
|
|
|
63
64
|
const dirty = run(["status", "--porcelain"]);
|
|
64
65
|
return { ...head.status === 0 ? { head: head.stdout.trim() } : {}, ...branch.status === 0 ? { branch: branch.stdout.trim() } : {}, dirty: Boolean(dirty.stdout.trim()) };
|
|
65
66
|
}
|
|
67
|
+
var TOOL_ARGS_FRAME_BUDGET = 64 * 1024;
|
|
68
|
+
function boundedToolArgs(args) {
|
|
69
|
+
if (!args || typeof args !== "object" || Array.isArray(args) || Buffer.byteLength(JSON.stringify(args)) <= TOOL_ARGS_FRAME_BUDGET) return args;
|
|
70
|
+
const shortened = Object.fromEntries(Object.entries(args).flatMap(([key, value]) => typeof value === "string" ? [[key, value.slice(0, 4096)]] : typeof value === "number" || typeof value === "boolean" ? [[key, value]] : []));
|
|
71
|
+
return Buffer.byteLength(JSON.stringify(shortened)) <= TOOL_ARGS_FRAME_BUDGET ? shortened : {};
|
|
72
|
+
}
|
|
73
|
+
var MESSAGE_FRAME_BUDGET = HERDR_PI_MAX_FRAME_BYTES - 64 * 1024;
|
|
74
|
+
var fitsMessageBudget = (value) => Buffer.byteLength(JSON.stringify(value)) <= MESSAGE_FRAME_BUDGET;
|
|
75
|
+
var omittedText = (what, bytes) => `[${what} omitted by the pi-subagents bridge: ${bytes} bytes did not fit in one bridge frame]`;
|
|
76
|
+
function boundedMessage(message) {
|
|
77
|
+
if (fitsMessageBudget(message)) return message;
|
|
78
|
+
const record = message;
|
|
79
|
+
const content = Array.isArray(record.content) ? record.content.map((block) => {
|
|
80
|
+
if (block.type === "image") return { type: "text", text: omittedText(`Image (${String(block.mimeType)})`, Buffer.byteLength(String(block.data))) };
|
|
81
|
+
if (block.type === "text" && typeof block.text === "string" && block.text.length > 65536) return { type: "text", text: `${block.text.slice(0, 65536)}
|
|
82
|
+
${omittedText("The rest of this text", Buffer.byteLength(block.text.slice(65536)))}` };
|
|
83
|
+
if (block.type === "thinking" && typeof block.thinking === "string") return { type: "thinking", thinking: block.thinking.length > 4096 ? `${block.thinking.slice(0, 4096)}
|
|
84
|
+
${omittedText("The rest of this thinking", Buffer.byteLength(block.thinking.slice(4096)))}` : block.thinking };
|
|
85
|
+
if (block.type === "toolCall") return { ...block, arguments: boundedToolArgs(block.arguments) };
|
|
86
|
+
return block;
|
|
87
|
+
}) : record.content;
|
|
88
|
+
const shrunk = { ...record, content, details: void 0 };
|
|
89
|
+
if (fitsMessageBudget(shrunk)) return shrunk;
|
|
90
|
+
const kept = Object.fromEntries(["role", "toolCallId", "toolName", "isError", "api", "provider", "model", "usage", "stopReason", "timestamp"].filter((key) => key in record).map((key) => [key, record[key]]));
|
|
91
|
+
return { ...kept, ...typeof record.errorMessage === "string" ? { errorMessage: record.errorMessage.slice(0, 4096) } : {}, content: [{ type: "text", text: omittedText("This message", Buffer.byteLength(JSON.stringify(message))) }] };
|
|
92
|
+
}
|
|
66
93
|
function resolveRemoteHerdrResources(cwd, resources, remoteDefaultTools = []) {
|
|
67
94
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || resources.skills?.some((name) => !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)) || resources.toolCeiling?.some((name) => !/^[A-Za-z0-9_-]{1,64}$/u.test(name)) || resources.reads !== void 0 && resources.reads !== false && (!Array.isArray(resources.reads) || resources.reads.some((name) => typeof name !== "string"))) throw new Error("Remote logical resource names are invalid.");
|
|
68
95
|
const discovered = discoverAgents(cwd, "both").agents.filter((agent2) => agent2.name === resources.agent || agent2.aliases?.includes(resources.agent));
|
|
@@ -89,18 +116,10 @@ function registerHerdrPiBridge(pi) {
|
|
|
89
116
|
const runId = validateHerdrPiRunId(process.env[HERDR_PI_RUN_ENV]);
|
|
90
117
|
const runDir = process.env[HERDR_PI_RUNTIME_DIR_ENV];
|
|
91
118
|
if (!runDir || !path.isAbsolute(runDir) || fs.lstatSync(runDir).isSymbolicLink()) throw new Error("Herdr bridge runtime directory was not authoritatively provisioned.");
|
|
92
|
-
fs.chmodSync(runDir, 448);
|
|
93
119
|
const socketPath = path.join(runDir, "bridge.sock");
|
|
94
120
|
const manifestPath = path.join(runDir, "manifest.json");
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const stat = fs.lstatSync(candidate);
|
|
98
|
-
if (stat.isSymbolicLink()) throw new Error(`Refusing symlink at '${candidate}'.`);
|
|
99
|
-
fs.rmSync(candidate, { force: true });
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (error.code !== "ENOENT") throw error;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
121
|
+
const claims = globalThis[/* @__PURE__ */ Symbol.for("pi-subagents.herdr-bridge-claims")] ??= /* @__PURE__ */ new Set();
|
|
122
|
+
let claimed = false;
|
|
104
123
|
let client;
|
|
105
124
|
let context;
|
|
106
125
|
let nativeSessionId;
|
|
@@ -115,8 +134,10 @@ function registerHerdrPiBridge(pi) {
|
|
|
115
134
|
let journalBytes = 0;
|
|
116
135
|
const journal = [];
|
|
117
136
|
const send = (frame) => {
|
|
118
|
-
const record = { protocol: HERDR_PI_PROTOCOL, runId, ...frame, cursor:
|
|
137
|
+
const record = { protocol: HERDR_PI_PROTOCOL, runId, ...frame, cursor: evidenceCursor + 1 };
|
|
119
138
|
const size = Buffer.byteLength(JSON.stringify(record));
|
|
139
|
+
if (size >= HERDR_PI_MAX_FRAME_BYTES) throw new Error(`pi-subagents bridge frame '${frame.type}' is ${size} bytes, over the ${HERDR_PI_MAX_FRAME_BYTES}-byte limit.`);
|
|
140
|
+
evidenceCursor++;
|
|
120
141
|
journal.push(record);
|
|
121
142
|
journalBytes += size;
|
|
122
143
|
while (journal.length > 512 || journalBytes > 8 * 1024 * 1024) {
|
|
@@ -126,6 +147,7 @@ function registerHerdrPiBridge(pi) {
|
|
|
126
147
|
if (!client || client.destroyed) return;
|
|
127
148
|
client.write(encodeHerdrPiFrame(record));
|
|
128
149
|
};
|
|
150
|
+
const sendReady = (ctx) => send({ type: "ready", packageVersion: package_default.version, nativeSessionId, sessionFile: ctx.sessionManager?.getSessionFile?.(), cwd: process.cwd(), tools: pi.getActiveTools(), model: ctx.model?.provider && ctx.model.id ? `${ctx.model.provider}/${ctx.model.id}` : void 0, configured, activeRequestId, evidenceCursor, evidenceFloor: journal[0]?.cursor ?? evidenceCursor + 1, initialGit: gitEvidence(process.cwd()) });
|
|
129
151
|
const sessionId = (ctx) => ctx.sessionManager?.getSessionId?.();
|
|
130
152
|
pi.registerTool({
|
|
131
153
|
name: "contact_supervisor",
|
|
@@ -188,23 +210,44 @@ ${answer}` }], details };
|
|
|
188
210
|
${resolvedSystemPrompt}` } : void 0;
|
|
189
211
|
});
|
|
190
212
|
on("session_start", (_event, ctx) => {
|
|
213
|
+
if (claims.has(runDir)) return;
|
|
191
214
|
context = ctx;
|
|
192
215
|
nativeSessionId = sessionId(ctx);
|
|
193
216
|
if (!nativeSessionId) throw new Error("Pane-native Pi bridge requires a persisted native session identity.");
|
|
217
|
+
claims.add(runDir);
|
|
218
|
+
claimed = true;
|
|
219
|
+
fs.chmodSync(runDir, 448);
|
|
220
|
+
for (const candidate of [socketPath, manifestPath]) {
|
|
221
|
+
try {
|
|
222
|
+
const stat = fs.lstatSync(candidate);
|
|
223
|
+
if (stat.isSymbolicLink()) throw new Error(`Refusing symlink at '${candidate}'.`);
|
|
224
|
+
fs.rmSync(candidate, { force: true });
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error.code !== "ENOENT") throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
server.listen(socketPath, () => {
|
|
230
|
+
fs.chmodSync(socketPath, 384);
|
|
231
|
+
});
|
|
194
232
|
fs.writeFileSync(manifestPath, JSON.stringify({ protocol: HERDR_PI_PROTOCOL, packageVersion: package_default.version, runId, socketPath, nativeSessionId, pid: process.pid }), { mode: 384, flag: "wx" });
|
|
195
|
-
|
|
233
|
+
sendReady(ctx);
|
|
196
234
|
});
|
|
197
235
|
on("message_end", (event) => {
|
|
198
|
-
const message = event.message;
|
|
199
|
-
if (message
|
|
236
|
+
const message = boundedMessage(event.message);
|
|
237
|
+
if (message.role === "assistant") finalAssistant = message;
|
|
200
238
|
send({ type: "event", requestId: activeRequestId, event: { ...event, message }, nativeSessionId });
|
|
201
239
|
});
|
|
240
|
+
on("tool_execution_start", (event) => send({ type: "event", requestId: activeRequestId, event: { type: "tool_execution_start", toolCallId: event.toolCallId, toolName: event.toolName, args: boundedToolArgs(event.args) }, nativeSessionId }));
|
|
241
|
+
on("tool_execution_end", (event) => send({ type: "event", requestId: activeRequestId, event: { type: "tool_execution_end", toolCallId: event.toolCallId, toolName: event.toolName, isError: event.isError }, nativeSessionId }));
|
|
202
242
|
on("agent_settled", (_event, ctx) => {
|
|
203
243
|
const requestId = activeRequestId;
|
|
204
244
|
send({ type: "settled", requestId, nativeSessionId, idle: ctx.isIdle(), pending: ctx.hasPendingMessages(), finalAssistant, finalGit: gitEvidence(process.cwd()) });
|
|
205
245
|
if (ctx.isIdle() && !ctx.hasPendingMessages()) activeRequestId = void 0;
|
|
206
246
|
});
|
|
207
247
|
on("session_shutdown", () => {
|
|
248
|
+
if (!claimed) return;
|
|
249
|
+
claimed = false;
|
|
250
|
+
claims.delete(runDir);
|
|
208
251
|
server.close();
|
|
209
252
|
client?.destroy();
|
|
210
253
|
try {
|
|
@@ -243,9 +286,12 @@ ${resolvedSystemPrompt}` } : void 0;
|
|
|
243
286
|
const invalidSkills = resources.skills !== void 0 && (!Array.isArray(resources.skills) || resources.skills.some((name) => typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)));
|
|
244
287
|
const invalidReads = resources.reads !== void 0 && resources.reads !== false && (!Array.isArray(resources.reads) || resources.reads.some((name) => typeof name !== "string"));
|
|
245
288
|
if (typeof resources.agent !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || invalidSkills || invalidReads) throw new Error("Remote logical resource names are invalid.");
|
|
289
|
+
const acceptancePrompt = resources.acceptancePrompt;
|
|
290
|
+
if (acceptancePrompt !== void 0 && (typeof acceptancePrompt !== "string" || Buffer.byteLength(acceptancePrompt) > HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES)) throw new Error("Bridge acceptance instructions are invalid or too large.");
|
|
246
291
|
const resolved = resolveRemoteHerdrResources(process.cwd(), { agent: resources.agent, ...resources.skills ? { skills: resources.skills } : {}, ...resources.toolCeiling ? { toolCeiling: resources.toolCeiling } : {}, ...resources.reads !== void 0 ? { reads: resources.reads } : {} }, context ? pi.getActiveTools() : []);
|
|
247
|
-
resolvedSystemPrompt = resolved.systemPrompt;
|
|
248
292
|
resolvedContextPolicy = resolved;
|
|
293
|
+
resolvedSystemPrompt = acceptancePrompt ? `${resolved.systemPrompt}
|
|
294
|
+
${acceptancePrompt}` : resolved.systemPrompt;
|
|
249
295
|
if (resolved.tools.includes(WATCHDOG_DIFF_TOOL_NAME) && !pi.getAllTools().some((tool) => tool.name === WATCHDOG_DIFF_TOOL_NAME)) pi.registerTool(createWatchdogDiffTool(captureWatchdogDiffBaseline(process.cwd()), { workingTreeAtLaunch: true }));
|
|
250
296
|
pi.setActiveTools(resolved.tools);
|
|
251
297
|
const acknowledged = context ? pi.getActiveTools() : [];
|
|
@@ -275,10 +321,7 @@ ${resolvedSystemPrompt}` } : void 0;
|
|
|
275
321
|
socket.on("close", () => {
|
|
276
322
|
if (client === socket) client = void 0;
|
|
277
323
|
});
|
|
278
|
-
if (context && nativeSessionId)
|
|
279
|
-
});
|
|
280
|
-
server.listen(socketPath, () => {
|
|
281
|
-
fs.chmodSync(socketPath, 384);
|
|
324
|
+
if (context && nativeSessionId) sendReady(context);
|
|
282
325
|
});
|
|
283
326
|
}
|
|
284
327
|
export {
|