orkestrator 2.36.4-beta → 2.36.5-beta
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/dist/client.js +11962 -10260
- package/dist/main.js +5058 -2903
- package/package.json +3 -3
- package/resources/acp-bridge/dist/index.js +884 -48
- package/resources/claude-bridge/dist/index.js +1177 -183
- package/resources/codex-bridge/dist/index.js +999 -161
- package/resources/cursor-bridge/dist/index.js +876 -40
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +890 -52
- package/resources/pi-bridge/runtime/install.json +1 -1
|
@@ -643,6 +643,8 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
643
643
|
},
|
|
644
644
|
"essential.write-failed": "Writing the essential log failed. Its entries are counted, and a marker reports them at the next write that works.",
|
|
645
645
|
"policy.changed": "The logging settings changed: saving, retention and levels, with no content.",
|
|
646
|
+
"policy.detail-expired": "Raised log detail reached its expiry, so the backend set its raised levels back to info. Saving is unchanged.",
|
|
647
|
+
"policy.expiry-failed": "Checking or applying the log detail expiry failed; the next check, a minute later, tries again.",
|
|
646
648
|
"policy.bridge-predates-route": "A running bridge has no logging settings route; it applies them at its next start.",
|
|
647
649
|
"policy.push-failed": "A running bridge did not take the logging settings after retries; its next start resends them.",
|
|
648
650
|
"prune.failed": "Removing expired log files failed; the next sweep retries.",
|
|
@@ -650,6 +652,23 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
650
652
|
"unknown-area": "Code outside the type checker asked for an area that is not listed.",
|
|
651
653
|
...THROTTLE_LOG_EVENTS
|
|
652
654
|
}
|
|
655
|
+
},
|
|
656
|
+
"renderer-errors": {
|
|
657
|
+
description: "Renderer failures a desktop window reported from its error ring: class, boundary, surface, count and fingerprint, never a message or stack.",
|
|
658
|
+
events: {
|
|
659
|
+
"error.recorded": {
|
|
660
|
+
description: "A renderer reported `count` new occurrences of one failure since its last report.",
|
|
661
|
+
essential: true,
|
|
662
|
+
fields: {
|
|
663
|
+
errorClass: "label",
|
|
664
|
+
boundary: "label",
|
|
665
|
+
route: "label",
|
|
666
|
+
fingerprint: "label",
|
|
667
|
+
count: "number"
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
"report.rate-limited": "Renderer error entries arrived faster than the backend records them, so `dropped` were counted and not written."
|
|
671
|
+
}
|
|
653
672
|
}
|
|
654
673
|
});
|
|
655
674
|
|
|
@@ -707,6 +726,8 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
707
726
|
"usage-limit.notice-failed": "A usage-limit stop's outcome could not be read for its notice.",
|
|
708
727
|
"usage-limit.resend-failed": "Resending after a usage limit failed. An unknown send stays in the journal.",
|
|
709
728
|
"title.strategy-failed": "A session title strategy failed, so the next is tried. Content-free: the error can quote the prompt.",
|
|
729
|
+
"steer.qualification-failed": "A bridge's steer qualification failed or answered non-OK, so steering is not offered. Agent and status code or error class only.",
|
|
730
|
+
"steer.capability-cleared": "A projection cleared `actions.steer` because its bridge did not qualify. Identifiers and turn status only.",
|
|
710
731
|
...THROTTLE_LOG_EVENTS
|
|
711
732
|
}
|
|
712
733
|
},
|
|
@@ -807,6 +828,9 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
807
828
|
essential: true,
|
|
808
829
|
fields: { origin: "label", ...ESSENTIAL_ERROR_FIELDS }
|
|
809
830
|
},
|
|
831
|
+
"child.reaped": "A macOS child whose exit Bun lost was reaped after its command settled, so it no longer waits as a zombie.",
|
|
832
|
+
"child.reap-abandoned": "A child whose exit Bun lost was left unreaped: `reason` says whether it was never seen as a zombie (`not-a-zombie`), too many were pending (`capacity`), or `waitpid` failed.",
|
|
833
|
+
"child.reap-unavailable": "waitpid could not be loaded, so children whose exit Bun lost stay zombies until this process exits.",
|
|
810
834
|
...THROTTLE_LOG_EVENTS
|
|
811
835
|
}
|
|
812
836
|
}
|
|
@@ -1213,6 +1237,13 @@ var COORDINATOR_LOG_AREAS = defineLogAreas({
|
|
|
1213
1237
|
"store.workflows-cleared": "The workflow store was full, so a batch of its oldest finished records was removed.",
|
|
1214
1238
|
"store.workflows-in-use": "The workflow store was full and every record was still in use, so new work was refused.",
|
|
1215
1239
|
"remote-worker.settle-failed": "A remote worker could not be settled.",
|
|
1240
|
+
"node-release.failed": "Work on a node that was forgotten or handed over could not be closed; the sweep's registry check retries.",
|
|
1241
|
+
"node-release.reconcile-failed": "The sweep could not check records against the node registry; the next sweep retries.",
|
|
1242
|
+
"node-release.unregistered": "Records named a node the registry no longer holds, so their work was closed here.",
|
|
1243
|
+
"node-release.notice-failed": "The notice for work closed on a released node could not be sent; it stays owed and the sweep retries.",
|
|
1244
|
+
"node-release.no-coordinator": "Work closed on a released node belonged to a coordinator that no longer exists, so nobody was told.",
|
|
1245
|
+
"node-offline.notice-failed": "The notice that a node has been unreachable for a day could not be sent; the next failed read retries.",
|
|
1246
|
+
"node-offline.check-failed": "Whether a long-unreachable node's coordinators were told could not be checked; the next read retries.",
|
|
1216
1247
|
"checkout.merge-followed": "After an environment's PR merged, the project checkout was fast-forwarded, or `outcome` says why not.",
|
|
1217
1248
|
"checkout.merge-follow-failed": "Fast-forwarding the project checkout failed, after an environment's PR merged or before mail woke the main coordinator.",
|
|
1218
1249
|
"checkout.mail-follow": "Before mail woke the main coordinator, the project checkout was fast-forwarded (`fast-forwarded-fetched` when the fetch was slow or failed and the upstream commit already fetched was merged), or `outcome` says why not (`timed-out`, `failed`).",
|
|
@@ -1309,6 +1340,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1309
1340
|
events: {
|
|
1310
1341
|
"portable-inputs.relay-missing": "Docker is rootless and the image predates the staged-input relay, so the container cannot read them until rebuilt.",
|
|
1311
1342
|
"git-mirror.mount-unavailable": "A new container gets no project Git mirror, so its clone goes to the remote.",
|
|
1343
|
+
"git-mirror.mount-withheld": "A new restricted container gets no project Git mirror because its firewall would not let it reach the project's remote, so it cannot read what the remote serves through the mirror either.",
|
|
1312
1344
|
"git-mirror.refreshed": "A project's Git mirror was built or updated.",
|
|
1313
1345
|
"git-mirror.seeded": "A project's Git mirror was built from its host checkout and only what the remote added to it.",
|
|
1314
1346
|
"git-mirror.seed-skipped": "A project's host checkout could not seed its Git mirror, so the build downloads everything.",
|
|
@@ -1485,6 +1517,7 @@ var NODES_LOG_AREAS = defineLogAreas({
|
|
|
1485
1517
|
"verification.record-failed": "A node verification could not be recorded.",
|
|
1486
1518
|
"profile.record-failed": "A node profile could not be recorded.",
|
|
1487
1519
|
"detach.unconfirmed": "A forgotten node has not confirmed the detach yet.",
|
|
1520
|
+
"grant.revocation-listener-failed": "A connection could not be told its client grant was removed; the grant is still gone.",
|
|
1488
1521
|
"handover.recovery-pending": "Command handover recovery is still pending.",
|
|
1489
1522
|
"ticket-sync.work-record-failed": "A remote build started but its ticket work location could not be saved.",
|
|
1490
1523
|
"ticket-sync.failed": "A Kanban sync with a node failed; it is retried.",
|
|
@@ -1537,7 +1570,9 @@ var HOST_LOG_AREAS = defineLogAreas({
|
|
|
1537
1570
|
"tool.missing": "A host tool was not found.",
|
|
1538
1571
|
"maintenance.listener-failed": "A host maintenance listener threw; the others still run.",
|
|
1539
1572
|
"suspend.reconcile-failed": "Reconciling due work after a host suspension failed.",
|
|
1540
|
-
"load.sample-failed": "Sampling machine load failed; the next sample retries."
|
|
1573
|
+
"load.sample-failed": "Sampling machine load failed; the next sample retries.",
|
|
1574
|
+
"usage.source-stalled": "A usage source (scope: disk or gpu-sysfs) did not answer in time; its figure is missing from the sample until it does.",
|
|
1575
|
+
...THROTTLE_LOG_EVENTS
|
|
1541
1576
|
}
|
|
1542
1577
|
}
|
|
1543
1578
|
});
|
|
@@ -2860,6 +2895,7 @@ function effectiveLogLevel(detail, area) {
|
|
|
2860
2895
|
return detail.level;
|
|
2861
2896
|
}
|
|
2862
2897
|
}
|
|
2898
|
+
var LOG_DETAIL_EXPIRY_MS = 24 * 60 * 60 * 1000;
|
|
2863
2899
|
function logDetailEnablesBridgeDiagnostics(detail) {
|
|
2864
2900
|
return LEVEL_DETAIL[effectiveLogLevel(detail, BRIDGE_DIAGNOSTICS_LOG_AREA)] >= LEVEL_DETAIL.debug;
|
|
2865
2901
|
}
|
|
@@ -8109,10 +8145,13 @@ import { isAbsolute, join as join3 } from "node:path";
|
|
|
8109
8145
|
|
|
8110
8146
|
// ../protocol/src/coordinator.ts
|
|
8111
8147
|
var COORDINATOR_COMMAND_SANDBOX_ENV = "ORKESTRATOR_COORDINATOR_COMMAND_SANDBOX";
|
|
8148
|
+
var COORDINATOR_PROTECTED_DATA_DIR_ENV = "ORKESTRATOR_COORDINATOR_PROTECTED_DATA_DIR";
|
|
8112
8149
|
function coordinatorCommandSandboxFromEnv(env) {
|
|
8113
8150
|
return env[COORDINATOR_COMMAND_SANDBOX_ENV] === "unavailable" ? "unavailable" : "required";
|
|
8114
8151
|
}
|
|
8115
8152
|
var COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV = "ORKESTRATOR_COORDINATOR_CLAUDE_USER_SKILLS_DIR";
|
|
8153
|
+
var COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL = "Let the coordinator use environments it did not create";
|
|
8154
|
+
var COORDINATOR_ENVIRONMENT_ORIGIN_REFUSAL = `Not done: this coordinator did not create that environment, so it may not send it work. Do not retry. Use an environment this coordinator launched, or start a new one. If the user wants this coordinator to work in environments it did not create, tell them to turn on "${COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL}" in this project's settings, under Coordinator.`;
|
|
8116
8155
|
var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
8117
8156
|
"ack_message",
|
|
8118
8157
|
"add_ticket_comment",
|
|
@@ -8841,6 +8880,126 @@ function claudeMcpToolPrefix(name) {
|
|
|
8841
8880
|
return `mcp__${normalized}__`;
|
|
8842
8881
|
}
|
|
8843
8882
|
|
|
8883
|
+
// ../../bridges/claude-bridge/src/services/read-only-path-boundary.ts
|
|
8884
|
+
import { realpathSync } from "node:fs";
|
|
8885
|
+
import { homedir as homedir2 } from "node:os";
|
|
8886
|
+
import { dirname, isAbsolute as isAbsolute2, join as join5, parse, resolve as resolve2, sep } from "node:path";
|
|
8887
|
+
function canonical(path) {
|
|
8888
|
+
let existing = path;
|
|
8889
|
+
const tail = [];
|
|
8890
|
+
for (;; ) {
|
|
8891
|
+
try {
|
|
8892
|
+
return join5(realpathSync.native(existing), ...tail.reverse());
|
|
8893
|
+
} catch {
|
|
8894
|
+
const parent = dirname(existing);
|
|
8895
|
+
if (parent === existing)
|
|
8896
|
+
return path;
|
|
8897
|
+
tail.push(existing.slice(parent.length).replace(/^[/\\]+/, ""));
|
|
8898
|
+
existing = parent;
|
|
8899
|
+
}
|
|
8900
|
+
}
|
|
8901
|
+
}
|
|
8902
|
+
function namedAndCanonical(paths) {
|
|
8903
|
+
const named = paths.flatMap((path) => path?.trim() && isAbsolute2(path) ? [path] : []);
|
|
8904
|
+
return [...new Set(named.flatMap((path) => [resolve2(path), canonical(path)]))];
|
|
8905
|
+
}
|
|
8906
|
+
function claudeReadOnlyWorkspacePaths(cwd) {
|
|
8907
|
+
return [...new Set([cwd, canonical(cwd)])];
|
|
8908
|
+
}
|
|
8909
|
+
function coordinatorReadBoundary(workspaces, env = process.env) {
|
|
8910
|
+
const dataDir = env[COORDINATOR_PROTECTED_DATA_DIR_ENV]?.trim();
|
|
8911
|
+
if (!dataDir || !isAbsolute2(dataDir))
|
|
8912
|
+
return null;
|
|
8913
|
+
const deny = namedAndCanonical([dataDir]);
|
|
8914
|
+
return {
|
|
8915
|
+
deny,
|
|
8916
|
+
allow: namedAndCanonical([
|
|
8917
|
+
env.CLAUDE_CONFIG_DIR,
|
|
8918
|
+
env.ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT,
|
|
8919
|
+
env[COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV],
|
|
8920
|
+
join5(dataDir, "toolchains"),
|
|
8921
|
+
...workspaces
|
|
8922
|
+
]).filter((path) => !deny.includes(path) && deny.some((root) => isWithin(root, path)))
|
|
8923
|
+
};
|
|
8924
|
+
}
|
|
8925
|
+
function isWithin(root, path) {
|
|
8926
|
+
if (path === root)
|
|
8927
|
+
return true;
|
|
8928
|
+
const prefix = root === parse(root).root ? root : `${root}${sep}`;
|
|
8929
|
+
return path.startsWith(prefix);
|
|
8930
|
+
}
|
|
8931
|
+
function deniedForm(boundary, path) {
|
|
8932
|
+
return boundary.deny.some((root) => isWithin(root, path)) && !boundary.allow.some((root) => isWithin(root, path));
|
|
8933
|
+
}
|
|
8934
|
+
function expandedHome(path) {
|
|
8935
|
+
if (path === "~")
|
|
8936
|
+
return homedir2();
|
|
8937
|
+
return path.startsWith("~/") ? `${homedir2()}${sep}${path.slice(2)}` : path;
|
|
8938
|
+
}
|
|
8939
|
+
function readBoundaryRefuses(boundary, path, cwd, options = {}) {
|
|
8940
|
+
const expanded = expandedHome(path);
|
|
8941
|
+
const raw = isAbsolute2(expanded) ? expanded : `${cwd}${sep}${expanded}`;
|
|
8942
|
+
const lexical = resolve2(raw);
|
|
8943
|
+
const real = canonical(raw);
|
|
8944
|
+
if (deniedForm(boundary, lexical) || deniedForm(boundary, real))
|
|
8945
|
+
return true;
|
|
8946
|
+
return options.traversal === true && boundary.deny.some((root) => isWithin(lexical, root) || isWithin(real, root));
|
|
8947
|
+
}
|
|
8948
|
+
function globRoot(pattern) {
|
|
8949
|
+
if (!pattern.startsWith("/") && !pattern.startsWith("~") && !pattern.startsWith("..")) {
|
|
8950
|
+
return;
|
|
8951
|
+
}
|
|
8952
|
+
const wildcard = pattern.search(/[*?[{]/);
|
|
8953
|
+
return wildcard < 0 ? pattern : pattern.slice(0, wildcard);
|
|
8954
|
+
}
|
|
8955
|
+
function readToolRefused(boundary, tool, input, cwd) {
|
|
8956
|
+
const text = (key) => {
|
|
8957
|
+
const value = input[key];
|
|
8958
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
8959
|
+
};
|
|
8960
|
+
if (tool === "Read") {
|
|
8961
|
+
const path = text("file_path");
|
|
8962
|
+
return path !== undefined && readBoundaryRefuses(boundary, path, cwd);
|
|
8963
|
+
}
|
|
8964
|
+
if (tool !== "Grep" && tool !== "Glob")
|
|
8965
|
+
return false;
|
|
8966
|
+
const roots = [text("path") ?? cwd];
|
|
8967
|
+
const pattern = tool === "Glob" ? text("pattern") : undefined;
|
|
8968
|
+
const root = pattern ? globRoot(pattern) : undefined;
|
|
8969
|
+
if (root)
|
|
8970
|
+
roots.push(root);
|
|
8971
|
+
return roots.some((path) => readBoundaryRefuses(boundary, path, cwd, { traversal: true }));
|
|
8972
|
+
}
|
|
8973
|
+
function shellCommandRefused(boundary, command, cwd, options) {
|
|
8974
|
+
const [program, ...tokens] = command.trim().split(/\s+/);
|
|
8975
|
+
if (options.traversal) {
|
|
8976
|
+
const indirectOption = program === "sort" || program === "wc" ? "--files0-from" : program === "file" ? "--files-from" : ["cksum", "md5sum", "sha1sum", "sha256sum"].includes(program ?? "") ? "--check" : undefined;
|
|
8977
|
+
if (indirectOption && tokens.some((token) => {
|
|
8978
|
+
const option = token.split("=", 1)[0];
|
|
8979
|
+
return option.startsWith("--") && indirectOption.startsWith(option) || program === "file" && /^-[^-]*f/.test(token) || indirectOption === "--check" && /^-[^-]*c/.test(token);
|
|
8980
|
+
}))
|
|
8981
|
+
return true;
|
|
8982
|
+
if (program === "grep" && tokens.some((token) => /^-[^-]*[RS]/.test(token) || token.startsWith("--") && "--dereference-recursive".startsWith(token)) || program === "diff" && tokens.some((token) => /^-[^-]*r/.test(token) || token.startsWith("--") && "--recursive".startsWith(token)) || (program === "rg" || program === "ag" || program === "find" || program === "fd" || program === "du" || program === "ls") && tokens.some((token) => token === "--follow" || token === "--dereference" || /^-[^-]*L/.test(token)))
|
|
8983
|
+
return true;
|
|
8984
|
+
const searches = program === "rg" || program === "ag" || program === "find" || program === "fd" || program === "du" || program === "ls" || program === "tree" || program === "grep";
|
|
8985
|
+
if (searches && readBoundaryRefuses(boundary, cwd, cwd, options))
|
|
8986
|
+
return true;
|
|
8987
|
+
}
|
|
8988
|
+
return tokens.some((token) => {
|
|
8989
|
+
const attached = [];
|
|
8990
|
+
if (token.startsWith("--")) {
|
|
8991
|
+
const equals = token.indexOf("=");
|
|
8992
|
+
if (equals >= 0)
|
|
8993
|
+
attached.push(token.slice(equals + 1));
|
|
8994
|
+
} else if (token.startsWith("-")) {
|
|
8995
|
+
for (let index = 1;index < token.length && /[a-zA-Z0-9]/.test(token[index]); index++) {
|
|
8996
|
+
attached.push(token.slice(index + 1));
|
|
8997
|
+
}
|
|
8998
|
+
}
|
|
8999
|
+
return [token, ...attached].some((candidate) => candidate && readBoundaryRefuses(boundary, candidate, cwd, options));
|
|
9000
|
+
});
|
|
9001
|
+
}
|
|
9002
|
+
|
|
8844
9003
|
// ../../bridges/claude-bridge/src/services/read-only-policy.ts
|
|
8845
9004
|
var CAPABILITY_TOOLS = new Map([
|
|
8846
9005
|
["file.write", ["Write", "NotebookEdit", "EnterWorktree", "ExitWorktree"]],
|
|
@@ -9124,7 +9283,10 @@ function claudeReadOnlySandbox(policy, options = {}) {
|
|
|
9124
9283
|
autoAllowBashIfSandboxed: true,
|
|
9125
9284
|
allowUnsandboxedCommands: false,
|
|
9126
9285
|
excludedCommands: [],
|
|
9127
|
-
filesystem: {
|
|
9286
|
+
filesystem: {
|
|
9287
|
+
denyWrite: [...new Set(options.workspaces ?? [])],
|
|
9288
|
+
...options.readBoundary ? { denyRead: options.readBoundary.deny, allowRead: options.readBoundary.allow } : {}
|
|
9289
|
+
},
|
|
9128
9290
|
network: {
|
|
9129
9291
|
allowLocalBinding: policy.networkAccess === "full",
|
|
9130
9292
|
strictAllowlist: true,
|
|
@@ -9151,7 +9313,8 @@ var REFUSALS = {
|
|
|
9151
9313
|
tool: (tool) => `Coordinator is read-only, so ${tool} is not available. Delegate file changes to a worker environment.`,
|
|
9152
9314
|
waiting: (tool) => `Coordinator turns do not wait, so ${tool} is not available. Delegated work reports back by waking this conversation with a message when it finishes; end your turn instead.`,
|
|
9153
9315
|
mcp: (tool) => `Coordinator sessions may only use Orkestrator's own tools, so ${tool} is not available.`,
|
|
9154
|
-
unsandboxed: "Coordinator commands may not run outside the sandbox."
|
|
9316
|
+
unsandboxed: "Coordinator commands may not run outside the sandbox.",
|
|
9317
|
+
dataDirectory: "Coordinators cannot read Orkestrator's data directory, which holds credentials with wider authority than this conversation. This conversation's own tool results, memory and attachments stay readable."
|
|
9155
9318
|
},
|
|
9156
9319
|
"read-only": {
|
|
9157
9320
|
composition: "Shell commands in this session cannot use quotes, escapes, globs, pipes, redirection, substitution or command chaining, because the command that runs would not be the one checked.",
|
|
@@ -9166,7 +9329,8 @@ var REFUSALS = {
|
|
|
9166
9329
|
tool: (tool) => `This session is read-only, so ${tool} is not available.`,
|
|
9167
9330
|
waiting: (tool) => `This session's turns do not wait, so ${tool} is not available. End your turn instead.`,
|
|
9168
9331
|
mcp: (tool) => `This session may only use Orkestrator's own tools and the MCP servers granted to it, so ${tool} is not available.`,
|
|
9169
|
-
unsandboxed: "Commands in this session may not run outside the sandbox."
|
|
9332
|
+
unsandboxed: "Commands in this session may not run outside the sandbox.",
|
|
9333
|
+
dataDirectory: "This session cannot read Orkestrator's data directory, which holds credentials with wider authority than this session. Its own tool results, memory and attachments stay readable."
|
|
9170
9334
|
}
|
|
9171
9335
|
};
|
|
9172
9336
|
function isReadOnlyShellCommand(command, options = {}) {
|
|
@@ -9279,6 +9443,7 @@ function createCoordinatorReadOnlyHook(policy, researchMcpServerNames = coordina
|
|
|
9279
9443
|
...researchMcpServerNames.map(claudeMcpToolPrefix),
|
|
9280
9444
|
...(nativeAgentUserMcpGrant(policy) ?? []).map(claudeMcpToolPrefix)
|
|
9281
9445
|
];
|
|
9446
|
+
const readBoundary = (cwd) => options.readBoundary !== undefined ? options.readBoundary : process.env[COORDINATOR_PROTECTED_DATA_DIR_ENV] ? coordinatorReadBoundary(claudeReadOnlyWorkspacePaths(cwd)) : null;
|
|
9282
9447
|
return async (input) => {
|
|
9283
9448
|
if (input.hook_event_name !== "PreToolUse")
|
|
9284
9449
|
return {};
|
|
@@ -9307,6 +9472,20 @@ function createCoordinatorReadOnlyHook(policy, researchMcpServerNames = coordina
|
|
|
9307
9472
|
const verdict = isReadOnlyShellCommand(command, options);
|
|
9308
9473
|
if (!verdict.allowed)
|
|
9309
9474
|
return deny(verdict.reason);
|
|
9475
|
+
const boundary = readBoundary(input.cwd);
|
|
9476
|
+
if (boundary && shellCommandRefused(boundary, command, input.cwd, {
|
|
9477
|
+
traversal: options.commandSandbox === "unavailable"
|
|
9478
|
+
})) {
|
|
9479
|
+
return deny(refusals.dataDirectory);
|
|
9480
|
+
}
|
|
9481
|
+
return {};
|
|
9482
|
+
}
|
|
9483
|
+
if (toolName === "Read" || toolName === "Grep" || toolName === "Glob") {
|
|
9484
|
+
const boundary = readBoundary(input.cwd);
|
|
9485
|
+
const toolInput = input.tool_input ?? {};
|
|
9486
|
+
if (boundary && readToolRefused(boundary, toolName, toolInput, input.cwd)) {
|
|
9487
|
+
return deny(refusals.dataDirectory);
|
|
9488
|
+
}
|
|
9310
9489
|
}
|
|
9311
9490
|
return {};
|
|
9312
9491
|
};
|
|
@@ -9445,12 +9624,12 @@ function effectiveClaudeChrome(policy, options) {
|
|
|
9445
9624
|
}
|
|
9446
9625
|
|
|
9447
9626
|
// ../../bridges/claude-bridge/src/services/claude-execution-sandbox.ts
|
|
9448
|
-
import { realpathSync } from "node:fs";
|
|
9627
|
+
import { realpathSync as realpathSync2 } from "node:fs";
|
|
9449
9628
|
|
|
9450
9629
|
// ../protocol/src/node/claude-linux-sandbox.ts
|
|
9451
9630
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
9452
9631
|
import { accessSync, constants, existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
9453
|
-
import { delimiter, join as
|
|
9632
|
+
import { delimiter, join as join6 } from "node:path";
|
|
9454
9633
|
var CLAUDE_LINUX_SANDBOX_PROGRAMS = Object.freeze(["bwrap", "socat"]);
|
|
9455
9634
|
var APPARMOR_BWRAP_PROFILE = "/etc/apparmor.d/bwrap-userns-restrict";
|
|
9456
9635
|
var CLAUDE_LINUX_SANDBOX_PROBE_TIMEOUT_MS = 5000;
|
|
@@ -9484,7 +9663,7 @@ function executableOnPath(name, path = process.env.PATH) {
|
|
|
9484
9663
|
if (!directory)
|
|
9485
9664
|
continue;
|
|
9486
9665
|
try {
|
|
9487
|
-
accessSync(
|
|
9666
|
+
accessSync(join6(directory, name), constants.X_OK);
|
|
9488
9667
|
return true;
|
|
9489
9668
|
} catch {}
|
|
9490
9669
|
}
|
|
@@ -9577,7 +9756,7 @@ function claudeLinuxSandboxStatus(now = Date.now()) {
|
|
|
9577
9756
|
function claudeReadOnlyWorkspaces(cwd) {
|
|
9578
9757
|
let resolved;
|
|
9579
9758
|
try {
|
|
9580
|
-
resolved =
|
|
9759
|
+
resolved = realpathSync2(cwd);
|
|
9581
9760
|
} catch {
|
|
9582
9761
|
resolved = undefined;
|
|
9583
9762
|
}
|
|
@@ -9604,9 +9783,11 @@ function claudeReadOnlyCommandSandbox(options = {}) {
|
|
|
9604
9783
|
}
|
|
9605
9784
|
function claudeExecutionSandbox(policy, asksForApproval, readOnly = {}) {
|
|
9606
9785
|
if (policy && isCoordinatorReadOnlyPolicy(policy)) {
|
|
9786
|
+
const workspaces = claudeReadOnlyWorkspaces(readOnly.cwd ?? claudeWorkspaceCwd());
|
|
9607
9787
|
return claudeReadOnlySandbox(policy, {
|
|
9608
|
-
workspaces
|
|
9609
|
-
commandSandbox: readOnly.commandSandbox ?? claudeReadOnlyCommandSandbox().commandSandbox
|
|
9788
|
+
workspaces,
|
|
9789
|
+
commandSandbox: readOnly.commandSandbox ?? claudeReadOnlyCommandSandbox().commandSandbox,
|
|
9790
|
+
readBoundary: readOnly.readBoundary ?? coordinatorReadBoundary(workspaces)
|
|
9610
9791
|
});
|
|
9611
9792
|
}
|
|
9612
9793
|
if (policy?.sandbox !== "provider")
|
|
@@ -12067,11 +12248,24 @@ var SYSTEM_SUBTYPE_DISPOSITIONS = {
|
|
|
12067
12248
|
files_persisted: "notice",
|
|
12068
12249
|
elicitation_complete: "notice"
|
|
12069
12250
|
};
|
|
12251
|
+
var INTERNAL_SYSTEM_SUBTYPE_DISPOSITIONS = {
|
|
12252
|
+
session_title_changed: "ignored",
|
|
12253
|
+
vcs_state_changed: "ignored",
|
|
12254
|
+
per_turn_effort_changed: "ignored",
|
|
12255
|
+
permission_check_status: "ignored",
|
|
12256
|
+
peer_message_hold: "ignored",
|
|
12257
|
+
instruction_size_warning: "notice"
|
|
12258
|
+
};
|
|
12070
12259
|
function systemSubtypeDisposition(subtype) {
|
|
12071
|
-
if (typeof subtype !== "string"
|
|
12260
|
+
if (typeof subtype !== "string")
|
|
12072
12261
|
return;
|
|
12262
|
+
if (Object.hasOwn(SYSTEM_SUBTYPE_DISPOSITIONS, subtype)) {
|
|
12263
|
+
return SYSTEM_SUBTYPE_DISPOSITIONS[subtype];
|
|
12264
|
+
}
|
|
12265
|
+
if (Object.hasOwn(INTERNAL_SYSTEM_SUBTYPE_DISPOSITIONS, subtype)) {
|
|
12266
|
+
return INTERNAL_SYSTEM_SUBTYPE_DISPOSITIONS[subtype];
|
|
12073
12267
|
}
|
|
12074
|
-
return
|
|
12268
|
+
return;
|
|
12075
12269
|
}
|
|
12076
12270
|
function sessionHealth(session) {
|
|
12077
12271
|
session.health ??= new RuntimeHealthRecorder;
|
|
@@ -12433,11 +12627,11 @@ function noMessages() {
|
|
|
12433
12627
|
// ../../bridges/claude-bridge/src/services/session-manager-persistence.ts
|
|
12434
12628
|
import { constants as constants2 } from "node:fs";
|
|
12435
12629
|
import { lstat as lstat2, open as open2, realpath as realpath2 } from "node:fs/promises";
|
|
12436
|
-
import { isAbsolute as
|
|
12630
|
+
import { isAbsolute as isAbsolute4, join as join11, relative, resolve as resolve4, sep as sep2 } from "node:path";
|
|
12437
12631
|
|
|
12438
12632
|
// ../protocol/src/node/command-change-journal.ts
|
|
12439
12633
|
import { appendFile, mkdir as mkdir3, readFile as readFile5, rename as rename3, rm as rm3, stat as stat4, writeFile as writeFile3 } from "node:fs/promises";
|
|
12440
|
-
import { dirname } from "node:path";
|
|
12634
|
+
import { dirname as dirname2 } from "node:path";
|
|
12441
12635
|
var MAX_JOURNAL_ENTRIES = 1000;
|
|
12442
12636
|
var MAX_JOURNAL_FILES_PER_ENTRY = 20;
|
|
12443
12637
|
var MAX_JOURNAL_PATH_LENGTH = 1024;
|
|
@@ -12510,7 +12704,7 @@ class CommandChangeJournal {
|
|
|
12510
12704
|
const line = `${JSON.stringify({ id, change: bounded })}
|
|
12511
12705
|
`;
|
|
12512
12706
|
this.writes = this.writes.then(async () => {
|
|
12513
|
-
await mkdir3(
|
|
12707
|
+
await mkdir3(dirname2(this.path), { recursive: true, mode: 448 });
|
|
12514
12708
|
if (!this.sizeChecked) {
|
|
12515
12709
|
this.sizeChecked = true;
|
|
12516
12710
|
const existing = await stat4(this.path).catch(() => {
|
|
@@ -12585,12 +12779,823 @@ async function readJournal(path, maxEntries) {
|
|
|
12585
12779
|
}
|
|
12586
12780
|
|
|
12587
12781
|
// ../protocol/src/node/workspace-change-probe.ts
|
|
12588
|
-
import {
|
|
12589
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
12782
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
12590
12783
|
import { rmSync } from "node:fs";
|
|
12591
12784
|
import { copyFile, lstat, mkdtemp as mkdtemp2, rm as rm4 } from "node:fs/promises";
|
|
12592
12785
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
12593
|
-
import { delimiter as delimiter2, isAbsolute as
|
|
12786
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute3, join as join7, resolve as resolve3 } from "node:path";
|
|
12787
|
+
|
|
12788
|
+
// ../protocol/src/node/command-capture.ts
|
|
12789
|
+
import { spawn } from "node:child_process";
|
|
12790
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
12791
|
+
import { constants as fsConstants } from "node:fs";
|
|
12792
|
+
import * as captureFs from "node:fs";
|
|
12793
|
+
import os from "node:os";
|
|
12794
|
+
import path3 from "node:path";
|
|
12795
|
+
import { inspect } from "node:util";
|
|
12796
|
+
|
|
12797
|
+
// ../protocol/src/node/command-failure-reason.ts
|
|
12798
|
+
var MAX_MATCHED_CHARS = 16 * 1024;
|
|
12799
|
+
var SIGNAL_PATTERN = /^SIG[A-Z0-9]{1,16}$/;
|
|
12800
|
+
var TOOL_RULES = {
|
|
12801
|
+
git: [
|
|
12802
|
+
["branch-exists", /a branch named .* already exists/i],
|
|
12803
|
+
["ref-conflict", /exists; cannot create|cannot lock ref .* is at .* but expected/i],
|
|
12804
|
+
["lock-held", /could not lock config file [^\n]*: File exists/i],
|
|
12805
|
+
["lock-held", /(?:unable to create '[^\n]*\.lock'|cannot lock ref)[^\n]*: File exists/i],
|
|
12806
|
+
["lock-held", /another git process/i],
|
|
12807
|
+
["worktree-conflict", /already (?:checked out|used by worktree)|used by worktree at/i],
|
|
12808
|
+
["invalid-ref", /not a valid (?:branch name|object name)|bad (?:revision|object)/i],
|
|
12809
|
+
["invalid-ref", /unknown revision|ambiguous argument|invalid reference/i],
|
|
12810
|
+
["branch-not-found", /no branch named|refname .* not found|branch '.*' not found/i],
|
|
12811
|
+
["branch-not-found", /did not match any file\(s\) known to git/i],
|
|
12812
|
+
["dubious-ownership", /detected dubious ownership/i],
|
|
12813
|
+
["no-remote", /does not appear to be a git repository|no such remote/i],
|
|
12814
|
+
["no-remote", /repository (?:.* )?not found/i],
|
|
12815
|
+
["not-a-repository", /not a git repository/i],
|
|
12816
|
+
["remote-ref-missing", /could(?:n't| not) find remote ref|not our ref/i],
|
|
12817
|
+
["merge-conflict", /\bCONFLICT \(|merge conflict|could not apply|unmerged files/i],
|
|
12818
|
+
["dirty-worktree", /local changes .* would be overwritten|commit your changes or stash/i],
|
|
12819
|
+
["nothing-to-commit", /nothing to commit|no changes added to commit/i],
|
|
12820
|
+
["push-rejected", /\[(?:remote )?rejected\]|non-fast-forward/i],
|
|
12821
|
+
["identity-unknown", /please tell me who you are|unable to auto-detect email/i],
|
|
12822
|
+
[
|
|
12823
|
+
"worktree-has-changes",
|
|
12824
|
+
/^fatal: [^\n]*['"] contains modified or untracked files(?:, use --force to delete it)?\.?\s*$/im
|
|
12825
|
+
],
|
|
12826
|
+
["not-a-worktree", /^fatal: [^\n]*['"] is not a working tree\.?\s*$/im],
|
|
12827
|
+
["branch-not-merged", /^(?:error|fatal): [^\n]*['"] is not fully merged\.?\s*$/im]
|
|
12828
|
+
],
|
|
12829
|
+
gh: [
|
|
12830
|
+
["pull-request-exists", /a pull request for branch .* already exists/i],
|
|
12831
|
+
["no-pull-request", /no (?:pull requests? (?:found|match)|open pull requests?\b)/i],
|
|
12832
|
+
["rate-limited", /rate limit|http 429/i],
|
|
12833
|
+
["forbidden", /http 403|resource not accessible/i],
|
|
12834
|
+
["resource-not-found", /http 404|could not resolve to a/i],
|
|
12835
|
+
["server-error", /http 5\d\d/i]
|
|
12836
|
+
],
|
|
12837
|
+
docker: [
|
|
12838
|
+
["daemon-unavailable", /cannot connect to the docker daemon|error during connect/i],
|
|
12839
|
+
[
|
|
12840
|
+
"daemon-unavailable",
|
|
12841
|
+
/is the docker daemon running|docker desktop is (?:not running|unable)/i
|
|
12842
|
+
],
|
|
12843
|
+
["container-not-found", /no such container/i],
|
|
12844
|
+
["container-not-running", /container .* is (?:not running|paused|restarting)/i],
|
|
12845
|
+
["container-name-conflict", /name .* is already in use/i],
|
|
12846
|
+
["image-not-found", /no such image|pull access denied|manifest .* not found/i],
|
|
12847
|
+
["image-not-found", /manifest unknown|repository does not exist/i],
|
|
12848
|
+
["removal-in-progress", /removal of container .* is already in progress/i],
|
|
12849
|
+
[
|
|
12850
|
+
"image-in-use",
|
|
12851
|
+
/image is (?:being used|referenced)|unable to (?:remove|delete) .*must be forced/i
|
|
12852
|
+
],
|
|
12853
|
+
["volume-in-use", /volume is in use/i],
|
|
12854
|
+
["volume-not-found", /no such volume/i],
|
|
12855
|
+
["network-in-use", /has active endpoints/i],
|
|
12856
|
+
["network-not-found", /network .* not found/i]
|
|
12857
|
+
],
|
|
12858
|
+
tmux: [
|
|
12859
|
+
["session-exists", /duplicate session/i],
|
|
12860
|
+
[
|
|
12861
|
+
"server-not-running",
|
|
12862
|
+
/no server running|failed to connect to server|no sessions|server exited|lost server/i
|
|
12863
|
+
],
|
|
12864
|
+
[
|
|
12865
|
+
"server-not-running",
|
|
12866
|
+
/error connecting to \/[^\n]* \((?:No such file or directory|Connection refused)\)/i
|
|
12867
|
+
],
|
|
12868
|
+
["session-not-found", /can't find (?:session|window|pane)|session not found/i]
|
|
12869
|
+
]
|
|
12870
|
+
};
|
|
12871
|
+
var ALL_TOOLS = Object.keys(TOOL_RULES);
|
|
12872
|
+
var SHARED_RULES = [
|
|
12873
|
+
["disk-full", /no space left|enospc|disk quota exceeded/i],
|
|
12874
|
+
["auth-failed", /authentication (?:failed|required)|could not read (?:username|password)/i],
|
|
12875
|
+
["auth-failed", /terminal prompts disabled|invalid username or password|bad credentials/i],
|
|
12876
|
+
["auth-failed", /permission denied \(|permission to \S+ denied|host key verification failed/i],
|
|
12877
|
+
["auth-failed", /gh auth login|not logged in|unauthorized|http 401|returned error: 40[13]/i],
|
|
12878
|
+
["network-failed", /could not resolve host|connection (?:timed out|refused|reset)/i],
|
|
12879
|
+
["network-failed", /network is unreachable|no route to host|temporary failure in name/i],
|
|
12880
|
+
["network-failed", /early eof|failed to connect|remote end hung up/i],
|
|
12881
|
+
["network-failed", /unable to access ['"]?https?:\/\//i],
|
|
12882
|
+
["network-failed", /tls handshake|i\/o timeout/i],
|
|
12883
|
+
[
|
|
12884
|
+
"network-failed",
|
|
12885
|
+
/error connecting to (?:https?:\/\/)?[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::\d+)?(?:[\s/:]|$)/i
|
|
12886
|
+
],
|
|
12887
|
+
["port-in-use", /port is already allocated|address already in use/i],
|
|
12888
|
+
["permission-denied", /permission denied|operation not permitted|read-only file system/i],
|
|
12889
|
+
["command-not-found", /command not found/i],
|
|
12890
|
+
["path-not-found", /no such file or directory/i],
|
|
12891
|
+
["invalid-usage", /^usage: |unknown (?:option|flag|command|shorthand flag)|invalid option/im]
|
|
12892
|
+
];
|
|
12893
|
+
var TOOL_EXIT_CODES = {
|
|
12894
|
+
git: { 129: "invalid-usage" },
|
|
12895
|
+
gh: { 2: "aborted", 4: "auth-failed" },
|
|
12896
|
+
docker: { 125: "daemon-error" },
|
|
12897
|
+
tmux: {}
|
|
12898
|
+
};
|
|
12899
|
+
var SHARED_EXIT_CODES = {
|
|
12900
|
+
124: "timed-out",
|
|
12901
|
+
126: "not-executable",
|
|
12902
|
+
127: "command-not-found",
|
|
12903
|
+
137: "killed",
|
|
12904
|
+
143: "killed"
|
|
12905
|
+
};
|
|
12906
|
+
function read2(target, key) {
|
|
12907
|
+
return target[key];
|
|
12908
|
+
}
|
|
12909
|
+
function boundedForMatching(text) {
|
|
12910
|
+
if (text.length <= MAX_MATCHED_CHARS)
|
|
12911
|
+
return text;
|
|
12912
|
+
const half = MAX_MATCHED_CHARS / 2;
|
|
12913
|
+
return `${text.slice(0, half)}
|
|
12914
|
+
${text.slice(-half)}`;
|
|
12915
|
+
}
|
|
12916
|
+
function failureText(error) {
|
|
12917
|
+
const stderr = read2(error, "stderr");
|
|
12918
|
+
if (Buffer.isBuffer(stderr) && stderr.length > 0) {
|
|
12919
|
+
return boundedForMatching(stderr.subarray(-MAX_MATCHED_CHARS).toString());
|
|
12920
|
+
}
|
|
12921
|
+
if (typeof stderr === "string" && stderr.length > 0)
|
|
12922
|
+
return boundedForMatching(stderr);
|
|
12923
|
+
const message = read2(error, "message");
|
|
12924
|
+
if (typeof message !== "string")
|
|
12925
|
+
return "";
|
|
12926
|
+
return message.startsWith("Command failed") ? "" : boundedForMatching(message);
|
|
12927
|
+
}
|
|
12928
|
+
function isRawSpawnEnoent(error) {
|
|
12929
|
+
const syscall = read2(error, "syscall");
|
|
12930
|
+
return read2(error, "code") === "ENOENT" && typeof syscall === "string" && /^(?:spawn(?:Sync)?(?:\s|$)|posix_spawnp?$)/.test(syscall);
|
|
12931
|
+
}
|
|
12932
|
+
function classifiedReason(error, exitCode, signal, options) {
|
|
12933
|
+
if (read2(error, "aborted") === true)
|
|
12934
|
+
return "aborted";
|
|
12935
|
+
if (read2(error, "outputLimitExceeded") === true)
|
|
12936
|
+
return "output-too-large";
|
|
12937
|
+
if (read2(error, "timedOut") === true)
|
|
12938
|
+
return "timed-out";
|
|
12939
|
+
if (read2(error, "executableMissing") === true || isRawSpawnEnoent(error)) {
|
|
12940
|
+
return "executable-missing";
|
|
12941
|
+
}
|
|
12942
|
+
const named = exitCode === null ? undefined : options.exitCodes?.[exitCode];
|
|
12943
|
+
if (named)
|
|
12944
|
+
return named;
|
|
12945
|
+
if (signal)
|
|
12946
|
+
return "killed";
|
|
12947
|
+
const text = failureText(error);
|
|
12948
|
+
for (const tool of options.tools ?? ALL_TOOLS) {
|
|
12949
|
+
for (const [reason, pattern] of TOOL_RULES[tool]) {
|
|
12950
|
+
if (pattern.test(text))
|
|
12951
|
+
return reason;
|
|
12952
|
+
}
|
|
12953
|
+
}
|
|
12954
|
+
for (const [reason, pattern] of SHARED_RULES) {
|
|
12955
|
+
if (pattern.test(text))
|
|
12956
|
+
return reason;
|
|
12957
|
+
}
|
|
12958
|
+
if (exitCode !== null) {
|
|
12959
|
+
for (const tool of options.tools ?? []) {
|
|
12960
|
+
const reason = TOOL_EXIT_CODES[tool][exitCode];
|
|
12961
|
+
if (reason)
|
|
12962
|
+
return reason;
|
|
12963
|
+
}
|
|
12964
|
+
const reason = SHARED_EXIT_CODES[exitCode];
|
|
12965
|
+
if (reason)
|
|
12966
|
+
return reason;
|
|
12967
|
+
}
|
|
12968
|
+
return "unclassified";
|
|
12969
|
+
}
|
|
12970
|
+
function numericExitCode(error) {
|
|
12971
|
+
for (const key of ["exitCode", "code"]) {
|
|
12972
|
+
const value = read2(error, key);
|
|
12973
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
12974
|
+
return value;
|
|
12975
|
+
}
|
|
12976
|
+
return null;
|
|
12977
|
+
}
|
|
12978
|
+
function classifyCommandFailure(error, options = {}) {
|
|
12979
|
+
if (typeof error !== "object" || error === null) {
|
|
12980
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
12981
|
+
}
|
|
12982
|
+
try {
|
|
12983
|
+
const exitCode = numericExitCode(error);
|
|
12984
|
+
const rawSignal = read2(error, "signal");
|
|
12985
|
+
const signal = typeof rawSignal === "string" && SIGNAL_PATTERN.test(rawSignal) ? rawSignal : null;
|
|
12986
|
+
return { reason: classifiedReason(error, exitCode, signal, options), exitCode, signal };
|
|
12987
|
+
} catch {
|
|
12988
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
12989
|
+
}
|
|
12990
|
+
}
|
|
12991
|
+
|
|
12992
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
12993
|
+
import { createRequire } from "node:module";
|
|
12994
|
+
|
|
12995
|
+
// ../protocol/src/node/shell-process-state.ts
|
|
12996
|
+
import { readdirSync, readFileSync as readFileSync3 } from "node:fs";
|
|
12997
|
+
import { constants as osConstants } from "node:os";
|
|
12998
|
+
var PROCESS_INSPECTION_OPTIONS = {
|
|
12999
|
+
timeout: 100,
|
|
13000
|
+
killSignal: "SIGKILL",
|
|
13001
|
+
maxBuffer: 1024 * 1024
|
|
13002
|
+
};
|
|
13003
|
+
function bunRuntime() {
|
|
13004
|
+
return globalThis.Bun;
|
|
13005
|
+
}
|
|
13006
|
+
function decodeWaitStatus(status) {
|
|
13007
|
+
const signalNumber = status & 127;
|
|
13008
|
+
if (signalNumber === 0)
|
|
13009
|
+
return { code: status >> 8 & 255, signal: null };
|
|
13010
|
+
const name = Object.entries(osConstants.signals).find(([, value]) => value === signalNumber)?.[0];
|
|
13011
|
+
return { code: null, signal: name ?? "SIGKILL" };
|
|
13012
|
+
}
|
|
13013
|
+
function readZombieExit(pid) {
|
|
13014
|
+
try {
|
|
13015
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "stat=,xstat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
13016
|
+
if (!result?.success)
|
|
13017
|
+
return;
|
|
13018
|
+
const { stdout } = result;
|
|
13019
|
+
const match = /^Z\S*\s+([0-9a-f]+)\s*$/i.exec(stdout.toString().trim());
|
|
13020
|
+
return match ? decodeWaitStatus(Number.parseInt(match[1], 16)) : undefined;
|
|
13021
|
+
} catch {
|
|
13022
|
+
return;
|
|
13023
|
+
}
|
|
13024
|
+
}
|
|
13025
|
+
var EXIT_WATCH_MS = 1000;
|
|
13026
|
+
var EXIT_WATCH_MAX_MS = 16000;
|
|
13027
|
+
function watchForLostExit(pid, onExit) {
|
|
13028
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
13029
|
+
return () => {
|
|
13030
|
+
return;
|
|
13031
|
+
};
|
|
13032
|
+
let timer;
|
|
13033
|
+
const watch = (delayMs) => {
|
|
13034
|
+
timer = setTimeout(() => {
|
|
13035
|
+
const exit = readZombieExit(pid);
|
|
13036
|
+
if (exit)
|
|
13037
|
+
onExit(exit);
|
|
13038
|
+
else
|
|
13039
|
+
watch(Math.min(delayMs * 2, EXIT_WATCH_MAX_MS));
|
|
13040
|
+
}, delayMs);
|
|
13041
|
+
};
|
|
13042
|
+
watch(EXIT_WATCH_MS);
|
|
13043
|
+
return () => clearTimeout(timer);
|
|
13044
|
+
}
|
|
13045
|
+
function isLiveMember(state, groupId, pgid) {
|
|
13046
|
+
return Number(groupId) === pgid && state !== undefined && !/^[ZX]/.test(state);
|
|
13047
|
+
}
|
|
13048
|
+
function linuxGroupHasLiveMember(pgid) {
|
|
13049
|
+
for (const entry of readdirSync("/proc")) {
|
|
13050
|
+
if (!/^\d+$/.test(entry))
|
|
13051
|
+
continue;
|
|
13052
|
+
let stat;
|
|
13053
|
+
try {
|
|
13054
|
+
stat = readFileSync3(`/proc/${entry}/stat`, "latin1");
|
|
13055
|
+
} catch {
|
|
13056
|
+
continue;
|
|
13057
|
+
}
|
|
13058
|
+
const [state, , groupId] = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
13059
|
+
if (isLiveMember(state, groupId, pgid))
|
|
13060
|
+
return true;
|
|
13061
|
+
}
|
|
13062
|
+
return false;
|
|
13063
|
+
}
|
|
13064
|
+
function psGroupHasLiveMember(pgid) {
|
|
13065
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-A", "-o", "pgid=,stat="], PROCESS_INSPECTION_OPTIONS);
|
|
13066
|
+
if (!result?.success)
|
|
13067
|
+
return true;
|
|
13068
|
+
return result.stdout.toString().split(`
|
|
13069
|
+
`).some((line) => {
|
|
13070
|
+
const [groupId, state] = line.trim().split(/\s+/);
|
|
13071
|
+
return isLiveMember(state, groupId, pgid);
|
|
13072
|
+
});
|
|
13073
|
+
}
|
|
13074
|
+
function groupHasLiveMember(pgid) {
|
|
13075
|
+
try {
|
|
13076
|
+
return process.platform === "linux" ? linuxGroupHasLiveMember(pgid) : psGroupHasLiveMember(pgid);
|
|
13077
|
+
} catch {
|
|
13078
|
+
return true;
|
|
13079
|
+
}
|
|
13080
|
+
}
|
|
13081
|
+
|
|
13082
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
13083
|
+
var log7 = createLogger("process");
|
|
13084
|
+
var REAP_GRACE_MS = 2000;
|
|
13085
|
+
var REAP_MAX_CHECK_MS = 30000;
|
|
13086
|
+
var REAP_MAX_CHECKS = 12;
|
|
13087
|
+
var REAP_MAX_PENDING = 256;
|
|
13088
|
+
function createLostExitReaper(options) {
|
|
13089
|
+
const { system } = options;
|
|
13090
|
+
const graceMs = options.graceMs ?? REAP_GRACE_MS;
|
|
13091
|
+
const maxCheckMs = options.maxCheckMs ?? REAP_MAX_CHECK_MS;
|
|
13092
|
+
const maxChecks = options.maxChecks ?? REAP_MAX_CHECKS;
|
|
13093
|
+
const maxPending = options.maxPending ?? REAP_MAX_PENDING;
|
|
13094
|
+
const pending = new Map;
|
|
13095
|
+
let reaped = 0;
|
|
13096
|
+
let abandoned = 0;
|
|
13097
|
+
const abandon = (pid, reason) => {
|
|
13098
|
+
abandoned += 1;
|
|
13099
|
+
log7.warn("child.reap-abandoned", { pid, reason });
|
|
13100
|
+
};
|
|
13101
|
+
const check = (pid, reported, startedAt) => {
|
|
13102
|
+
if (reported())
|
|
13103
|
+
return false;
|
|
13104
|
+
const found = system.inspect(pid);
|
|
13105
|
+
if (found === undefined)
|
|
13106
|
+
return true;
|
|
13107
|
+
if (found === "gone" || found.ppid !== system.selfPid)
|
|
13108
|
+
return false;
|
|
13109
|
+
if (!found.state.startsWith("Z"))
|
|
13110
|
+
return true;
|
|
13111
|
+
const result = system.waitNoHang(pid);
|
|
13112
|
+
if (result === pid) {
|
|
13113
|
+
reaped += 1;
|
|
13114
|
+
log7.info("child.reaped", { pid, waitedMs: Date.now() - startedAt });
|
|
13115
|
+
return false;
|
|
13116
|
+
}
|
|
13117
|
+
if (result === 0)
|
|
13118
|
+
return true;
|
|
13119
|
+
abandon(pid, "waitpid-failed");
|
|
13120
|
+
return false;
|
|
13121
|
+
};
|
|
13122
|
+
const schedule = (pid, reported, startedAt, delayMs, checks) => {
|
|
13123
|
+
const timer = setTimeout(() => {
|
|
13124
|
+
pending.delete(pid);
|
|
13125
|
+
let again;
|
|
13126
|
+
try {
|
|
13127
|
+
again = check(pid, reported, startedAt);
|
|
13128
|
+
} catch {
|
|
13129
|
+
again = true;
|
|
13130
|
+
}
|
|
13131
|
+
if (!again)
|
|
13132
|
+
return;
|
|
13133
|
+
if (checks + 1 >= maxChecks) {
|
|
13134
|
+
abandon(pid, "not-a-zombie");
|
|
13135
|
+
return;
|
|
13136
|
+
}
|
|
13137
|
+
schedule(pid, reported, startedAt, Math.min(delayMs * 2, maxCheckMs), checks + 1);
|
|
13138
|
+
}, delayMs);
|
|
13139
|
+
timer.unref?.();
|
|
13140
|
+
pending.set(pid, timer);
|
|
13141
|
+
};
|
|
13142
|
+
return {
|
|
13143
|
+
reap(pid, reported) {
|
|
13144
|
+
if (!Number.isSafeInteger(pid) || pid <= 1 || pid === system.selfPid)
|
|
13145
|
+
return;
|
|
13146
|
+
if (pending.has(pid) || reported())
|
|
13147
|
+
return;
|
|
13148
|
+
if (pending.size >= maxPending) {
|
|
13149
|
+
abandon(pid, "capacity");
|
|
13150
|
+
return;
|
|
13151
|
+
}
|
|
13152
|
+
schedule(pid, reported, Date.now(), graceMs, 0);
|
|
13153
|
+
},
|
|
13154
|
+
stats: () => ({ pending: pending.size, reaped, abandoned }),
|
|
13155
|
+
stop() {
|
|
13156
|
+
for (const timer of pending.values())
|
|
13157
|
+
clearTimeout(timer);
|
|
13158
|
+
pending.clear();
|
|
13159
|
+
}
|
|
13160
|
+
};
|
|
13161
|
+
}
|
|
13162
|
+
var WNOHANG = 1;
|
|
13163
|
+
function loadDarwinWaitpid(loadFfi = () => createRequire(import.meta.url)("bun:ffi")) {
|
|
13164
|
+
try {
|
|
13165
|
+
const { dlopen, FFIType } = loadFfi();
|
|
13166
|
+
const libSystem = dlopen("/usr/lib/libSystem.B.dylib", {
|
|
13167
|
+
waitpid: { args: [FFIType.i32, FFIType.ptr, FFIType.i32], returns: FFIType.i32 }
|
|
13168
|
+
});
|
|
13169
|
+
const status = new Int32Array(1);
|
|
13170
|
+
return (pid) => libSystem.symbols.waitpid(pid, status, WNOHANG);
|
|
13171
|
+
} catch {
|
|
13172
|
+
return;
|
|
13173
|
+
}
|
|
13174
|
+
}
|
|
13175
|
+
function darwinReaperSystem(loadFfi) {
|
|
13176
|
+
const waitNoHang = loadDarwinWaitpid(loadFfi);
|
|
13177
|
+
if (!waitNoHang)
|
|
13178
|
+
return;
|
|
13179
|
+
return {
|
|
13180
|
+
selfPid: process.pid,
|
|
13181
|
+
inspect(pid) {
|
|
13182
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "ppid=,stat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
13183
|
+
if (!result)
|
|
13184
|
+
return;
|
|
13185
|
+
const output = result.stdout.toString().trim();
|
|
13186
|
+
if (!result.success)
|
|
13187
|
+
return result.exitCode === 1 && output === "" ? "gone" : undefined;
|
|
13188
|
+
const match = /^(\d+)\s+(\S+)$/.exec(output);
|
|
13189
|
+
return match ? { ppid: Number(match[1]), state: match[2] } : undefined;
|
|
13190
|
+
},
|
|
13191
|
+
waitNoHang
|
|
13192
|
+
};
|
|
13193
|
+
}
|
|
13194
|
+
var defaultReaper;
|
|
13195
|
+
function createDarwinLostExitReaper(loadFfi) {
|
|
13196
|
+
const system = darwinReaperSystem(loadFfi);
|
|
13197
|
+
if (!system)
|
|
13198
|
+
log7.warn("child.reap-unavailable");
|
|
13199
|
+
return system ? createLostExitReaper({ system }) : null;
|
|
13200
|
+
}
|
|
13201
|
+
function sharedReaper() {
|
|
13202
|
+
if (defaultReaper === undefined) {
|
|
13203
|
+
defaultReaper = createDarwinLostExitReaper();
|
|
13204
|
+
}
|
|
13205
|
+
return defaultReaper ?? undefined;
|
|
13206
|
+
}
|
|
13207
|
+
function reapAfterLostExit(pid, reported) {
|
|
13208
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
13209
|
+
return;
|
|
13210
|
+
sharedReaper()?.reap(pid, reported);
|
|
13211
|
+
}
|
|
13212
|
+
|
|
13213
|
+
// ../protocol/src/node/command-capture.ts
|
|
13214
|
+
class CommandFailedError extends Error {
|
|
13215
|
+
stdout;
|
|
13216
|
+
stdoutBytes;
|
|
13217
|
+
stderr;
|
|
13218
|
+
timedOut;
|
|
13219
|
+
outputCloseTimedOut;
|
|
13220
|
+
executableMissing;
|
|
13221
|
+
aborted;
|
|
13222
|
+
outputLimitExceeded;
|
|
13223
|
+
exitCode;
|
|
13224
|
+
signal;
|
|
13225
|
+
constructor(message, details = {}) {
|
|
13226
|
+
super(message);
|
|
13227
|
+
this.name = "CommandFailedError";
|
|
13228
|
+
this.stdout = details.stdout ?? "";
|
|
13229
|
+
this.stdoutBytes = details.stdoutBytes ?? Buffer.alloc(0);
|
|
13230
|
+
this.stderr = details.stderr ?? "";
|
|
13231
|
+
this.timedOut = details.timedOut ?? false;
|
|
13232
|
+
this.outputCloseTimedOut = details.outputCloseTimedOut ?? false;
|
|
13233
|
+
this.executableMissing = details.executableMissing ?? false;
|
|
13234
|
+
this.aborted = details.aborted ?? false;
|
|
13235
|
+
this.outputLimitExceeded = details.outputLimitExceeded ?? false;
|
|
13236
|
+
this.exitCode = details.exitCode ?? null;
|
|
13237
|
+
this.signal = details.signal ?? null;
|
|
13238
|
+
}
|
|
13239
|
+
toJSON() {
|
|
13240
|
+
return { ...formatLogError(this), ...classifyCommandFailure(this) };
|
|
13241
|
+
}
|
|
13242
|
+
[inspect.custom]() {
|
|
13243
|
+
const { name, reason, exitCode, signal, stack } = this.toJSON();
|
|
13244
|
+
const frames = stack?.length ? ` | ${stack.join(" | ")}` : "";
|
|
13245
|
+
return `${name} reason=${reason} exitCode=${exitCode} signal=${signal} outputOmitted=true${frames}`;
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
function redactCommandValues(value, redactValues) {
|
|
13249
|
+
const secrets = Array.from(new Set((redactValues ?? []).filter((secret) => typeof secret === "string" && secret.length > 0))).sort((left, right) => right.length - left.length);
|
|
13250
|
+
return secrets.reduce((redacted, secret) => redacted.split(secret).join("[REDACTED]"), value);
|
|
13251
|
+
}
|
|
13252
|
+
var COMMAND_ABORTED_MESSAGE = "Command aborted";
|
|
13253
|
+
var OUTPUT_LIMIT_MESSAGE = "maxBuffer length exceeded";
|
|
13254
|
+
function commandFailureOutcome(error) {
|
|
13255
|
+
const details = error ?? {};
|
|
13256
|
+
const message = typeof details.message === "string" ? details.message : "";
|
|
13257
|
+
return {
|
|
13258
|
+
timedOut: details.killed === true,
|
|
13259
|
+
executableMissing: details.code === "ENOENT",
|
|
13260
|
+
aborted: message === COMMAND_ABORTED_MESSAGE,
|
|
13261
|
+
outputLimitExceeded: details.outputLimitExceeded === true,
|
|
13262
|
+
exitCode: typeof details.code === "number" ? details.code : null,
|
|
13263
|
+
signal: details.signal ?? null
|
|
13264
|
+
};
|
|
13265
|
+
}
|
|
13266
|
+
var commandInvocations = new Map;
|
|
13267
|
+
var commandCaptureMetrics;
|
|
13268
|
+
var commandObservers = new Map;
|
|
13269
|
+
function nonInteractiveGitEnv(env) {
|
|
13270
|
+
const merged = { ...env ?? process.env };
|
|
13271
|
+
merged.GIT_TERMINAL_PROMPT ??= "0";
|
|
13272
|
+
if (process.platform !== "win32") {
|
|
13273
|
+
merged.SSH_ASKPASS ??= "/usr/bin/false";
|
|
13274
|
+
merged.SSH_ASKPASS_REQUIRE ??= "force";
|
|
13275
|
+
}
|
|
13276
|
+
return merged;
|
|
13277
|
+
}
|
|
13278
|
+
var MAX_COMMAND_OUTPUT_BYTES = 50 * 1024 * 1024;
|
|
13279
|
+
var COMMAND_KILL_GRACE_MS = 100;
|
|
13280
|
+
var COMMAND_OUTPUT_CHECK_MS = 100;
|
|
13281
|
+
var COMMAND_GROUP_POLL_MS = 5;
|
|
13282
|
+
var COMMAND_GROUP_POLL_MAX_MS = 200;
|
|
13283
|
+
function openCaptureFile() {
|
|
13284
|
+
const filePath = path3.join(os.tmpdir(), `orkestrator-capture-${randomUUID2()}`);
|
|
13285
|
+
const fd = captureFs.openSync(filePath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_RDWR | fsConstants.O_APPEND, 384);
|
|
13286
|
+
try {
|
|
13287
|
+
captureFs.unlinkSync(filePath);
|
|
13288
|
+
return fd;
|
|
13289
|
+
} catch (error) {
|
|
13290
|
+
captureFs.closeSync(fd);
|
|
13291
|
+
throw error;
|
|
13292
|
+
}
|
|
13293
|
+
}
|
|
13294
|
+
function readCaptureFile(fd, limit) {
|
|
13295
|
+
const size = Math.min(captureFs.fstatSync(fd).size, limit);
|
|
13296
|
+
const buffer = Buffer.allocUnsafe(size);
|
|
13297
|
+
let offset = 0;
|
|
13298
|
+
while (offset < size) {
|
|
13299
|
+
const bytesRead = captureFs.readSync(fd, buffer, offset, size - offset, offset);
|
|
13300
|
+
if (bytesRead === 0)
|
|
13301
|
+
break;
|
|
13302
|
+
offset += bytesRead;
|
|
13303
|
+
}
|
|
13304
|
+
return buffer.subarray(0, offset);
|
|
13305
|
+
}
|
|
13306
|
+
function spawnCaptured(command, args, options, stdoutFd, stderrFd) {
|
|
13307
|
+
const payload = options.stdin?.length ? Buffer.from(options.stdin) : undefined;
|
|
13308
|
+
const env = command === "git" ? nonInteractiveGitEnv(options.env) : options.env ?? process.env;
|
|
13309
|
+
const detached = process.platform !== "win32";
|
|
13310
|
+
const bun = bunRuntime();
|
|
13311
|
+
if (bun) {
|
|
13312
|
+
const child = bun.spawn([command, ...args], {
|
|
13313
|
+
cwd: options.cwd,
|
|
13314
|
+
env,
|
|
13315
|
+
detached,
|
|
13316
|
+
windowsHide: true,
|
|
13317
|
+
stdin: payload ?? "pipe",
|
|
13318
|
+
stdout: stdoutFd,
|
|
13319
|
+
stderr: stderrFd
|
|
13320
|
+
});
|
|
13321
|
+
if (!payload)
|
|
13322
|
+
closeStdin(child.stdin);
|
|
13323
|
+
const current = () => ({ code: child.exitCode, signal: child.signalCode });
|
|
13324
|
+
return {
|
|
13325
|
+
pid: child.pid,
|
|
13326
|
+
exited: child.exited.then(current),
|
|
13327
|
+
current,
|
|
13328
|
+
kill: (signal) => child.kill(signal)
|
|
13329
|
+
};
|
|
13330
|
+
}
|
|
13331
|
+
const child = spawn(command, args, {
|
|
13332
|
+
cwd: options.cwd,
|
|
13333
|
+
env,
|
|
13334
|
+
detached,
|
|
13335
|
+
windowsHide: true,
|
|
13336
|
+
stdio: [payload ? "pipe" : "ignore", stdoutFd, stderrFd]
|
|
13337
|
+
});
|
|
13338
|
+
if (payload) {
|
|
13339
|
+
child.stdin?.on("error", () => {
|
|
13340
|
+
return;
|
|
13341
|
+
});
|
|
13342
|
+
child.stdin?.end(payload);
|
|
13343
|
+
}
|
|
13344
|
+
return {
|
|
13345
|
+
pid: child.pid,
|
|
13346
|
+
exited: new Promise((resolve, reject) => {
|
|
13347
|
+
child.once("exit", (code, signal) => resolve({ code, signal }));
|
|
13348
|
+
child.once("error", reject);
|
|
13349
|
+
}),
|
|
13350
|
+
current: () => ({ code: child.exitCode, signal: child.signalCode }),
|
|
13351
|
+
kill: (signal) => {
|
|
13352
|
+
child.kill(signal);
|
|
13353
|
+
}
|
|
13354
|
+
};
|
|
13355
|
+
}
|
|
13356
|
+
function closeStdin(stdin) {
|
|
13357
|
+
try {
|
|
13358
|
+
Promise.resolve(stdin.end()).catch(() => {
|
|
13359
|
+
return;
|
|
13360
|
+
});
|
|
13361
|
+
} catch {}
|
|
13362
|
+
}
|
|
13363
|
+
function exitReported(child) {
|
|
13364
|
+
const { code, signal } = child.current();
|
|
13365
|
+
return code !== null || signal !== null;
|
|
13366
|
+
}
|
|
13367
|
+
function signalCommand(child, signal) {
|
|
13368
|
+
if (child.pid === undefined)
|
|
13369
|
+
return;
|
|
13370
|
+
try {
|
|
13371
|
+
if (process.platform !== "win32") {
|
|
13372
|
+
process.kill(-child.pid, signal);
|
|
13373
|
+
} else {
|
|
13374
|
+
child.kill(signal);
|
|
13375
|
+
}
|
|
13376
|
+
} catch {}
|
|
13377
|
+
}
|
|
13378
|
+
function commandGroupAlive(child) {
|
|
13379
|
+
if (process.platform === "win32" || child.pid === undefined)
|
|
13380
|
+
return false;
|
|
13381
|
+
try {
|
|
13382
|
+
process.kill(-child.pid, 0);
|
|
13383
|
+
} catch (error) {
|
|
13384
|
+
if (error.code === "ESRCH")
|
|
13385
|
+
return false;
|
|
13386
|
+
}
|
|
13387
|
+
return groupHasLiveMember(child.pid);
|
|
13388
|
+
}
|
|
13389
|
+
function executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit) {
|
|
13390
|
+
return new Promise((resolve, reject) => {
|
|
13391
|
+
if (options.signal?.aborted) {
|
|
13392
|
+
reject(Object.assign(new Error(COMMAND_ABORTED_MESSAGE), { killed: true }));
|
|
13393
|
+
return;
|
|
13394
|
+
}
|
|
13395
|
+
const captureFds = [];
|
|
13396
|
+
const releaseCaptureFds = () => {
|
|
13397
|
+
for (const fd of captureFds.splice(0)) {
|
|
13398
|
+
try {
|
|
13399
|
+
captureFs.closeSync(fd);
|
|
13400
|
+
} catch {}
|
|
13401
|
+
}
|
|
13402
|
+
};
|
|
13403
|
+
try {
|
|
13404
|
+
captureFds.push(openCaptureFile());
|
|
13405
|
+
captureFds.push(openCaptureFile());
|
|
13406
|
+
} catch (error) {
|
|
13407
|
+
releaseCaptureFds();
|
|
13408
|
+
const code = error.code ?? "unknown";
|
|
13409
|
+
reject(new Error(`Could not open a command output file in the temporary directory: ${code}`));
|
|
13410
|
+
return;
|
|
13411
|
+
}
|
|
13412
|
+
const [stdoutFd, stderrFd] = captureFds;
|
|
13413
|
+
let child;
|
|
13414
|
+
try {
|
|
13415
|
+
child = spawnCaptured(command, args, options, stdoutFd, stderrFd);
|
|
13416
|
+
} catch (error) {
|
|
13417
|
+
releaseCaptureFds();
|
|
13418
|
+
reject(error);
|
|
13419
|
+
return;
|
|
13420
|
+
}
|
|
13421
|
+
let settled = false;
|
|
13422
|
+
let timedOut = false;
|
|
13423
|
+
let timeoutTimer;
|
|
13424
|
+
let groupTimer;
|
|
13425
|
+
let limitTimer;
|
|
13426
|
+
let stopExitWatch = () => {};
|
|
13427
|
+
let commandExit;
|
|
13428
|
+
const finishCapture = () => {
|
|
13429
|
+
settled = true;
|
|
13430
|
+
clearTimeout(timeoutTimer);
|
|
13431
|
+
clearTimeout(groupTimer);
|
|
13432
|
+
clearInterval(limitTimer);
|
|
13433
|
+
stopExitWatch();
|
|
13434
|
+
options.signal?.removeEventListener("abort", abort);
|
|
13435
|
+
if (!exitReported(child))
|
|
13436
|
+
reapAfterLostExit(child.pid, () => exitReported(child));
|
|
13437
|
+
try {
|
|
13438
|
+
return {
|
|
13439
|
+
stdout: readCaptureFile(stdoutFd, outputLimit),
|
|
13440
|
+
stderr: readCaptureFile(stderrFd, stderrLimit)
|
|
13441
|
+
};
|
|
13442
|
+
} catch (error) {
|
|
13443
|
+
reject(error);
|
|
13444
|
+
return;
|
|
13445
|
+
} finally {
|
|
13446
|
+
releaseCaptureFds();
|
|
13447
|
+
}
|
|
13448
|
+
};
|
|
13449
|
+
const fail = (error) => {
|
|
13450
|
+
if (settled)
|
|
13451
|
+
return;
|
|
13452
|
+
const output = finishCapture();
|
|
13453
|
+
if (output)
|
|
13454
|
+
reject(Object.assign(error, { ...output, killed: timedOut }));
|
|
13455
|
+
};
|
|
13456
|
+
const abort = () => {
|
|
13457
|
+
timedOut = true;
|
|
13458
|
+
signalCommand(child, "SIGKILL");
|
|
13459
|
+
fail(new Error(COMMAND_ABORTED_MESSAGE));
|
|
13460
|
+
};
|
|
13461
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
13462
|
+
const checkOutputLimit = () => {
|
|
13463
|
+
const stream = captureFs.fstatSync(stdoutFd).size > outputLimit ? "stdout" : captureFs.fstatSync(stderrFd).size > stderrLimit ? "stderr" : undefined;
|
|
13464
|
+
if (stream === undefined)
|
|
13465
|
+
return false;
|
|
13466
|
+
signalCommand(child, "SIGKILL");
|
|
13467
|
+
fail(Object.assign(new Error(`${stream} ${OUTPUT_LIMIT_MESSAGE}`), {
|
|
13468
|
+
outputLimitExceeded: true
|
|
13469
|
+
}));
|
|
13470
|
+
return true;
|
|
13471
|
+
};
|
|
13472
|
+
const failIfOverLimit = () => {
|
|
13473
|
+
try {
|
|
13474
|
+
return checkOutputLimit();
|
|
13475
|
+
} catch (error) {
|
|
13476
|
+
signalCommand(child, "SIGKILL");
|
|
13477
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
13478
|
+
return true;
|
|
13479
|
+
}
|
|
13480
|
+
};
|
|
13481
|
+
limitTimer = setInterval(() => {
|
|
13482
|
+
if (!settled && !timedOut)
|
|
13483
|
+
failIfOverLimit();
|
|
13484
|
+
}, COMMAND_OUTPUT_CHECK_MS);
|
|
13485
|
+
const settleOnExit = () => {
|
|
13486
|
+
if (settled || timedOut || failIfOverLimit())
|
|
13487
|
+
return;
|
|
13488
|
+
if (commandExit?.code !== 0 || commandExit.signal !== null) {
|
|
13489
|
+
fail(Object.assign(new Error(`Command failed: ${[command, ...args].join(" ")}`), {
|
|
13490
|
+
code: commandExit?.code,
|
|
13491
|
+
signal: commandExit?.signal
|
|
13492
|
+
}));
|
|
13493
|
+
return;
|
|
13494
|
+
}
|
|
13495
|
+
const output = finishCapture();
|
|
13496
|
+
if (output)
|
|
13497
|
+
resolve(output);
|
|
13498
|
+
};
|
|
13499
|
+
const awaitGroupExit = (delayMs) => {
|
|
13500
|
+
if (settled || timedOut)
|
|
13501
|
+
return;
|
|
13502
|
+
if (commandGroupAlive(child)) {
|
|
13503
|
+
groupTimer = setTimeout(awaitGroupExit, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
|
|
13504
|
+
return;
|
|
13505
|
+
}
|
|
13506
|
+
settleOnExit();
|
|
13507
|
+
};
|
|
13508
|
+
const onCommandExit = (exit) => {
|
|
13509
|
+
if (commandExit)
|
|
13510
|
+
return;
|
|
13511
|
+
commandExit = exit;
|
|
13512
|
+
stopExitWatch();
|
|
13513
|
+
if (options.waitForDescendants)
|
|
13514
|
+
awaitGroupExit(COMMAND_GROUP_POLL_MS);
|
|
13515
|
+
else
|
|
13516
|
+
settleOnExit();
|
|
13517
|
+
};
|
|
13518
|
+
child.exited.then(onCommandExit, (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
13519
|
+
stopExitWatch = watchForLostExit(child.pid, (exit) => {
|
|
13520
|
+
if (!settled && !timedOut)
|
|
13521
|
+
onCommandExit(exit);
|
|
13522
|
+
});
|
|
13523
|
+
if (timeoutMs > 0) {
|
|
13524
|
+
timeoutTimer = setTimeout(() => {
|
|
13525
|
+
timedOut = true;
|
|
13526
|
+
signalCommand(child, "SIGTERM");
|
|
13527
|
+
timeoutTimer = setTimeout(() => {
|
|
13528
|
+
signalCommand(child, "SIGKILL");
|
|
13529
|
+
fail(Object.assign(new Error(`Command timed out after ${timeoutMs} ms`), {
|
|
13530
|
+
code: child.current().code,
|
|
13531
|
+
signal: child.current().signal
|
|
13532
|
+
}));
|
|
13533
|
+
}, COMMAND_KILL_GRACE_MS);
|
|
13534
|
+
}, timeoutMs);
|
|
13535
|
+
}
|
|
13536
|
+
});
|
|
13537
|
+
}
|
|
13538
|
+
async function runCommandBytes(command, args = [], options = {}) {
|
|
13539
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
13540
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2147483647) {
|
|
13541
|
+
throw new RangeError("timeoutMs must be an integer between 0 and 2147483647");
|
|
13542
|
+
}
|
|
13543
|
+
const outputLimit = options.maxOutputBytes ?? MAX_COMMAND_OUTPUT_BYTES;
|
|
13544
|
+
if (!Number.isSafeInteger(outputLimit) || outputLimit <= 0) {
|
|
13545
|
+
throw new RangeError("maxOutputBytes must be a positive integer");
|
|
13546
|
+
}
|
|
13547
|
+
const stderrLimit = options.maxStderrBytes ?? outputLimit;
|
|
13548
|
+
if (!Number.isSafeInteger(stderrLimit) || stderrLimit <= 0) {
|
|
13549
|
+
throw new RangeError("maxStderrBytes must be a positive integer");
|
|
13550
|
+
}
|
|
13551
|
+
if (commandInvocations.size < 64 || commandInvocations.has(command)) {
|
|
13552
|
+
commandInvocations.set(command, (commandInvocations.get(command) ?? 0) + 1);
|
|
13553
|
+
}
|
|
13554
|
+
for (const observer of commandObservers.get(command) ?? [])
|
|
13555
|
+
observer(args);
|
|
13556
|
+
commandCaptureMetrics?.started(command, args);
|
|
13557
|
+
try {
|
|
13558
|
+
const { stdout, stderr } = await executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit);
|
|
13559
|
+
commandCaptureMetrics?.capturedBytes(stdout.length);
|
|
13560
|
+
return {
|
|
13561
|
+
stdout: Buffer.isBuffer(stdout) ? stdout : Buffer.from(stdout),
|
|
13562
|
+
stderr: Buffer.isBuffer(stderr) ? stderr : Buffer.from(stderr)
|
|
13563
|
+
};
|
|
13564
|
+
} catch (error) {
|
|
13565
|
+
const outcome = commandFailureOutcome(error);
|
|
13566
|
+
const redacting = options.redactValues?.some((value) => typeof value === "string" && value.length > 0);
|
|
13567
|
+
if (error && typeof error === "object" && "stdout" in error && "stderr" in error) {
|
|
13568
|
+
const withOutput = error;
|
|
13569
|
+
const stderr = withOutput.stderr?.toString() ?? "";
|
|
13570
|
+
const stdout = withOutput.stdout?.toString() ?? "";
|
|
13571
|
+
const message = (stderr || stdout || withOutput.message || "Command failed").trim();
|
|
13572
|
+
throw new CommandFailedError(redactCommandValues(message, options.redactValues), {
|
|
13573
|
+
...outcome,
|
|
13574
|
+
stdout: redactCommandValues(stdout, options.redactValues),
|
|
13575
|
+
stderr: redactCommandValues(stderr, options.redactValues),
|
|
13576
|
+
...!redacting && Buffer.isBuffer(withOutput.stdout) ? { stdoutBytes: withOutput.stdout } : {}
|
|
13577
|
+
});
|
|
13578
|
+
}
|
|
13579
|
+
if (redacting) {
|
|
13580
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
13581
|
+
throw new CommandFailedError(redactCommandValues(message || "Command failed", options.redactValues), outcome);
|
|
13582
|
+
}
|
|
13583
|
+
if (outcome.timedOut || outcome.executableMissing) {
|
|
13584
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
13585
|
+
throw new CommandFailedError(message || "Command failed", outcome);
|
|
13586
|
+
}
|
|
13587
|
+
throw error;
|
|
13588
|
+
}
|
|
13589
|
+
}
|
|
13590
|
+
async function runCommand(command, args = [], options = {}) {
|
|
13591
|
+
const { stdout, stderr } = await runCommandBytes(command, args, options);
|
|
13592
|
+
return {
|
|
13593
|
+
stdout: redactCommandValues(stdout.toString(), options.redactValues),
|
|
13594
|
+
stderr: redactCommandValues(stderr.toString(), options.redactValues)
|
|
13595
|
+
};
|
|
13596
|
+
}
|
|
13597
|
+
|
|
13598
|
+
// ../protocol/src/node/workspace-change-probe.ts
|
|
12594
13599
|
var DEFAULT_MAX_UNTRACKED_FILE_BYTES = 2 * 1024 * 1024;
|
|
12595
13600
|
var DEFAULT_MAX_UNTRACKED_FILES = 5000;
|
|
12596
13601
|
var DEFAULT_SLOW_SNAPSHOT_MS = 500;
|
|
@@ -12608,27 +13613,16 @@ process.once("exit", () => {
|
|
|
12608
13613
|
} catch {}
|
|
12609
13614
|
}
|
|
12610
13615
|
});
|
|
12611
|
-
var runGit = (args, options) =>
|
|
12612
|
-
const
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
|
|
12617
|
-
|
|
12618
|
-
let stdout = "";
|
|
12619
|
-
let stdoutBytes = 0;
|
|
12620
|
-
child.stdout.setEncoding("utf8");
|
|
12621
|
-
child.stdout.on("data", (chunk) => {
|
|
12622
|
-
stdoutBytes += chunk.length;
|
|
12623
|
-
if (stdoutBytes <= GIT_MAX_BUFFER)
|
|
12624
|
-
stdout += chunk;
|
|
13616
|
+
var runGit = async (args, options) => {
|
|
13617
|
+
const { stdout } = await runCommand("git", args, {
|
|
13618
|
+
cwd: options.cwd,
|
|
13619
|
+
env: { ...process.env, ...options.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
13620
|
+
timeoutMs: GIT_TIMEOUT_MS,
|
|
13621
|
+
maxOutputBytes: GIT_MAX_BUFFER,
|
|
13622
|
+
...options.stdin === undefined ? {} : { stdin: options.stdin }
|
|
12625
13623
|
});
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
child.on("close", (code) => code === 0 ? resolvePromise({ stdout }) : reject(new Error(`git exited with ${code}`)));
|
|
12629
|
-
child.stdin.on("error", () => {});
|
|
12630
|
-
child.stdin.end(options.stdin);
|
|
12631
|
-
});
|
|
13624
|
+
return { stdout };
|
|
13625
|
+
};
|
|
12632
13626
|
|
|
12633
13627
|
class WorkspaceChangeProbe {
|
|
12634
13628
|
git;
|
|
@@ -12872,8 +13866,8 @@ class WorkspaceChangeProbe {
|
|
|
12872
13866
|
return;
|
|
12873
13867
|
return {
|
|
12874
13868
|
root,
|
|
12875
|
-
indexPath:
|
|
12876
|
-
objectsPath:
|
|
13869
|
+
indexPath: isAbsolute3(index) ? index : resolve3(cwd, index),
|
|
13870
|
+
objectsPath: isAbsolute3(objects) ? objects : resolve3(cwd, objects)
|
|
12877
13871
|
};
|
|
12878
13872
|
}).catch(() => {
|
|
12879
13873
|
return;
|
|
@@ -12916,8 +13910,8 @@ class WorkspaceChangeProbe {
|
|
|
12916
13910
|
return;
|
|
12917
13911
|
const { root, indexPath } = repo.location;
|
|
12918
13912
|
const started = this.now();
|
|
12919
|
-
const tempIndex =
|
|
12920
|
-
const objectDirectory = await mkdtemp2(
|
|
13913
|
+
const tempIndex = join7(this.tempDir, `orkestrator-probe-${randomUUID3()}.index`);
|
|
13914
|
+
const objectDirectory = await mkdtemp2(join7(this.tempDir, "orkestrator-probe-objects-"));
|
|
12921
13915
|
temporaryObjectDirectories.add(objectDirectory);
|
|
12922
13916
|
let retained = false;
|
|
12923
13917
|
try {
|
|
@@ -12934,7 +13928,7 @@ class WorkspaceChangeProbe {
|
|
|
12934
13928
|
const included = [];
|
|
12935
13929
|
const skipped = new Map;
|
|
12936
13930
|
for (const path of untracked) {
|
|
12937
|
-
const stats = await lstat(
|
|
13931
|
+
const stats = await lstat(join7(root, path)).catch(() => {
|
|
12938
13932
|
return;
|
|
12939
13933
|
});
|
|
12940
13934
|
if (!stats)
|
|
@@ -13080,20 +14074,20 @@ function parseNumstatZ(output) {
|
|
|
13080
14074
|
}
|
|
13081
14075
|
|
|
13082
14076
|
// ../../bridges/claude-bridge/src/services/command-changes.ts
|
|
13083
|
-
import { join as
|
|
14077
|
+
import { join as join10 } from "node:path";
|
|
13084
14078
|
|
|
13085
14079
|
// ../../bridges/claude-bridge/src/services/change-evidence.ts
|
|
13086
14080
|
import { createHash as createHash8 } from "node:crypto";
|
|
13087
14081
|
import {
|
|
13088
|
-
closeSync,
|
|
14082
|
+
closeSync as closeSync2,
|
|
13089
14083
|
existsSync as existsSync2,
|
|
13090
14084
|
mkdirSync,
|
|
13091
|
-
openSync,
|
|
13092
|
-
readFileSync as
|
|
14085
|
+
openSync as openSync2,
|
|
14086
|
+
readFileSync as readFileSync5,
|
|
13093
14087
|
rmSync as rmSync2,
|
|
13094
14088
|
writeSync
|
|
13095
14089
|
} from "node:fs";
|
|
13096
|
-
import { join as
|
|
14090
|
+
import { join as join9 } from "node:path";
|
|
13097
14091
|
|
|
13098
14092
|
// ../protocol/src/field-validation.ts
|
|
13099
14093
|
function isPlainRecord(value) {
|
|
@@ -13496,10 +14490,10 @@ function workspaceObservationReportIssues(value) {
|
|
|
13496
14490
|
}
|
|
13497
14491
|
|
|
13498
14492
|
// ../protocol/src/node/change-tracking/evidence-spool.ts
|
|
13499
|
-
import { createHash as createHash7, randomUUID as
|
|
13500
|
-
import { readdirSync, readFileSync as
|
|
14493
|
+
import { createHash as createHash7, randomUUID as randomUUID4 } from "node:crypto";
|
|
14494
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync4 } from "node:fs";
|
|
13501
14495
|
import { appendFile as appendFile2, mkdir as mkdir4, rename as rename4, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
|
|
13502
|
-
import { join as
|
|
14496
|
+
import { join as join8 } from "node:path";
|
|
13503
14497
|
var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
|
|
13504
14498
|
maxEntries: 2048,
|
|
13505
14499
|
maxEntryBytes: 256 * 1024,
|
|
@@ -13542,7 +14536,7 @@ class ChangeEvidenceSpool {
|
|
|
13542
14536
|
restoring = false;
|
|
13543
14537
|
constructor(options = {}) {
|
|
13544
14538
|
this.limits = { ...DEFAULT_EVIDENCE_SPOOL_LIMITS, ...options.limits };
|
|
13545
|
-
this.runtimeEpoch = options.runtimeEpoch ??
|
|
14539
|
+
this.runtimeEpoch = options.runtimeEpoch ?? randomUUID4();
|
|
13546
14540
|
this.directory = options.directory;
|
|
13547
14541
|
if (this.directory) {
|
|
13548
14542
|
this.restoring = true;
|
|
@@ -13645,7 +14639,7 @@ class ChangeEvidenceSpool {
|
|
|
13645
14639
|
return;
|
|
13646
14640
|
if (this.entries.length >= this.limits.maxEntries - 1)
|
|
13647
14641
|
return;
|
|
13648
|
-
const gapId =
|
|
14642
|
+
const gapId = randomUUID4();
|
|
13649
14643
|
const coverage = this.droppedUnknown ? {
|
|
13650
14644
|
kind: "unknown-range",
|
|
13651
14645
|
bindingId: this.gapBindingId || "unknown",
|
|
@@ -13762,7 +14756,7 @@ class ChangeEvidenceSpool {
|
|
|
13762
14756
|
const lines = this.pendingLines.splice(0).join("");
|
|
13763
14757
|
this.enqueueIo(async () => {
|
|
13764
14758
|
await mkdir4(directory, { recursive: true, mode: 448 });
|
|
13765
|
-
await appendFile2(
|
|
14759
|
+
await appendFile2(join8(directory, ENTRIES_FILE), lines, { mode: 384 });
|
|
13766
14760
|
});
|
|
13767
14761
|
}
|
|
13768
14762
|
persistBody(id, bytes) {
|
|
@@ -13770,9 +14764,9 @@ class ChangeEvidenceSpool {
|
|
|
13770
14764
|
if (!directory || this.restoring)
|
|
13771
14765
|
return;
|
|
13772
14766
|
this.enqueueIo(async () => {
|
|
13773
|
-
const bodies =
|
|
14767
|
+
const bodies = join8(directory, BODY_DIRECTORY);
|
|
13774
14768
|
await mkdir4(bodies, { recursive: true, mode: 448 });
|
|
13775
|
-
await writeFile4(
|
|
14769
|
+
await writeFile4(join8(bodies, bodyFileName(id)), bytes, { mode: 384, flag: "wx" }).catch((error) => {
|
|
13776
14770
|
if (error.code !== "EEXIST")
|
|
13777
14771
|
throw error;
|
|
13778
14772
|
});
|
|
@@ -13782,7 +14776,7 @@ class ChangeEvidenceSpool {
|
|
|
13782
14776
|
const directory = this.directory;
|
|
13783
14777
|
if (!directory)
|
|
13784
14778
|
return;
|
|
13785
|
-
this.enqueueIo(() => rm5(
|
|
14779
|
+
this.enqueueIo(() => rm5(join8(directory, BODY_DIRECTORY, bodyFileName(id)), { force: true }));
|
|
13786
14780
|
}
|
|
13787
14781
|
compactPersisted() {
|
|
13788
14782
|
const directory = this.directory;
|
|
@@ -13793,7 +14787,7 @@ class ChangeEvidenceSpool {
|
|
|
13793
14787
|
`);
|
|
13794
14788
|
this.enqueueIo(async () => {
|
|
13795
14789
|
await mkdir4(directory, { recursive: true, mode: 448 });
|
|
13796
|
-
const file =
|
|
14790
|
+
const file = join8(directory, ENTRIES_FILE);
|
|
13797
14791
|
const temp = `${file}.${process.pid}.tmp`;
|
|
13798
14792
|
await writeFile4(temp, body ? `${body}
|
|
13799
14793
|
` : "", { mode: 384 });
|
|
@@ -13805,10 +14799,10 @@ class ChangeEvidenceSpool {
|
|
|
13805
14799
|
await this.io;
|
|
13806
14800
|
}
|
|
13807
14801
|
restore(directory) {
|
|
13808
|
-
const bodyDirectory =
|
|
14802
|
+
const bodyDirectory = join8(directory, BODY_DIRECTORY);
|
|
13809
14803
|
try {
|
|
13810
|
-
for (const name of
|
|
13811
|
-
const bytes = new Uint8Array(
|
|
14804
|
+
for (const name of readdirSync2(bodyDirectory)) {
|
|
14805
|
+
const bytes = new Uint8Array(readFileSync4(join8(bodyDirectory, name)));
|
|
13812
14806
|
const id = evidenceBodyId(bytes);
|
|
13813
14807
|
if (bodyFileName(id) !== name)
|
|
13814
14808
|
continue;
|
|
@@ -13820,7 +14814,7 @@ class ChangeEvidenceSpool {
|
|
|
13820
14814
|
} catch {}
|
|
13821
14815
|
let text = "";
|
|
13822
14816
|
try {
|
|
13823
|
-
text =
|
|
14817
|
+
text = readFileSync4(join8(directory, ENTRIES_FILE), "utf8");
|
|
13824
14818
|
} catch {
|
|
13825
14819
|
return;
|
|
13826
14820
|
}
|
|
@@ -14201,14 +15195,14 @@ function record(value) {
|
|
|
14201
15195
|
function text(value) {
|
|
14202
15196
|
return typeof value === "string" ? value : undefined;
|
|
14203
15197
|
}
|
|
14204
|
-
function
|
|
15198
|
+
function path4(value) {
|
|
14205
15199
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
14206
15200
|
}
|
|
14207
15201
|
function claudeProposalEvidence(toolName, input) {
|
|
14208
15202
|
const fields = record(input);
|
|
14209
15203
|
switch (toolName) {
|
|
14210
15204
|
case "Edit": {
|
|
14211
|
-
const filePath =
|
|
15205
|
+
const filePath = path4(fields.file_path);
|
|
14212
15206
|
if (!filePath)
|
|
14213
15207
|
return [];
|
|
14214
15208
|
return [
|
|
@@ -14226,7 +15220,7 @@ function claudeProposalEvidence(toolName, input) {
|
|
|
14226
15220
|
];
|
|
14227
15221
|
}
|
|
14228
15222
|
case "MultiEdit": {
|
|
14229
|
-
const filePath =
|
|
15223
|
+
const filePath = path4(fields.file_path);
|
|
14230
15224
|
if (!filePath || !Array.isArray(fields.edits))
|
|
14231
15225
|
return [];
|
|
14232
15226
|
return fields.edits.map((edit, index) => {
|
|
@@ -14245,7 +15239,7 @@ function claudeProposalEvidence(toolName, input) {
|
|
|
14245
15239
|
});
|
|
14246
15240
|
}
|
|
14247
15241
|
case "Write": {
|
|
14248
|
-
const filePath =
|
|
15242
|
+
const filePath = path4(fields.file_path);
|
|
14249
15243
|
if (!filePath)
|
|
14250
15244
|
return [];
|
|
14251
15245
|
return [
|
|
@@ -14263,7 +15257,7 @@ function claudeProposalEvidence(toolName, input) {
|
|
|
14263
15257
|
];
|
|
14264
15258
|
}
|
|
14265
15259
|
case "NotebookEdit": {
|
|
14266
|
-
const filePath =
|
|
15260
|
+
const filePath = path4(fields.notebook_path);
|
|
14267
15261
|
if (!filePath)
|
|
14268
15262
|
return [];
|
|
14269
15263
|
const deleting = fields.edit_mode === "delete";
|
|
@@ -14332,20 +15326,20 @@ function createChangeEvidence(options) {
|
|
|
14332
15326
|
};
|
|
14333
15327
|
}
|
|
14334
15328
|
function claimSpoolDirectory(root = claudeChangeEvidenceDir(), scope = process.env.CWD || process.cwd()) {
|
|
14335
|
-
const directory =
|
|
14336
|
-
const owner =
|
|
15329
|
+
const directory = join9(root, createHash8("sha256").update(scope).digest("hex").slice(0, 32));
|
|
15330
|
+
const owner = join9(directory, "owner.pid");
|
|
14337
15331
|
try {
|
|
14338
15332
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
14339
15333
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
14340
15334
|
try {
|
|
14341
|
-
const fd =
|
|
15335
|
+
const fd = openSync2(owner, "wx", 384);
|
|
14342
15336
|
writeSync(fd, ownerFileContents());
|
|
14343
|
-
|
|
15337
|
+
closeSync2(fd);
|
|
14344
15338
|
return directory;
|
|
14345
15339
|
} catch (error) {
|
|
14346
15340
|
if (error.code !== "EEXIST")
|
|
14347
15341
|
return;
|
|
14348
|
-
const holder = parseOwnerFile(
|
|
15342
|
+
const holder = parseOwnerFile(readFileSync5(owner, "utf8"));
|
|
14349
15343
|
if (holder) {
|
|
14350
15344
|
const state = recordedOwnerState(holder, { slowPath: true });
|
|
14351
15345
|
if (state === "current")
|
|
@@ -14531,7 +15525,7 @@ function commandChangeJournal(sdkSessionId) {
|
|
|
14531
15525
|
if (journal) {
|
|
14532
15526
|
journals.delete(sdkSessionId);
|
|
14533
15527
|
} else {
|
|
14534
|
-
journal = new CommandChangeJournal(
|
|
15528
|
+
journal = new CommandChangeJournal(join10(claudeCommandChangesDir(), `${sdkSessionId}.jsonl`));
|
|
14535
15529
|
}
|
|
14536
15530
|
journals.set(sdkSessionId, journal);
|
|
14537
15531
|
while (journals.size > MAX_CACHED_JOURNALS) {
|
|
@@ -15298,17 +16292,17 @@ class ClaudeAttachmentError extends Error {
|
|
|
15298
16292
|
var BRIDGE_ATTACHMENT_ROOT_ENV = "ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT";
|
|
15299
16293
|
function configuredAttachmentRoot(env = process.env) {
|
|
15300
16294
|
const value = env[BRIDGE_ATTACHMENT_ROOT_ENV]?.trim();
|
|
15301
|
-
return value &&
|
|
16295
|
+
return value && isAbsolute4(value) ? resolve4(value) : undefined;
|
|
15302
16296
|
}
|
|
15303
16297
|
function attachmentContainmentRoot(filePath, cwd, extraRoot = configuredAttachmentRoot()) {
|
|
15304
|
-
if (extraRoot &&
|
|
16298
|
+
if (extraRoot && isAbsolute4(filePath) && isPathWithin2(extraRoot, resolve4(filePath))) {
|
|
15305
16299
|
return extraRoot;
|
|
15306
16300
|
}
|
|
15307
|
-
return
|
|
16301
|
+
return resolve4(cwd);
|
|
15308
16302
|
}
|
|
15309
16303
|
function isPathWithin2(rootPath, targetPath) {
|
|
15310
16304
|
const childPath = relative(rootPath, targetPath);
|
|
15311
|
-
return childPath === "" || childPath !== ".." && !childPath.startsWith(`..${
|
|
16305
|
+
return childPath === "" || childPath !== ".." && !childPath.startsWith(`..${sep2}`) && !isAbsolute4(childPath);
|
|
15312
16306
|
}
|
|
15313
16307
|
function attachmentErrorForFsFailure(error) {
|
|
15314
16308
|
const code = error?.code;
|
|
@@ -15323,8 +16317,8 @@ function attachmentErrorForFsFailure(error) {
|
|
|
15323
16317
|
async function assertNoSymlinkComponents(lexicalRoot, targetPath) {
|
|
15324
16318
|
const childPath = relative(lexicalRoot, targetPath);
|
|
15325
16319
|
let currentPath = lexicalRoot;
|
|
15326
|
-
for (const segment of childPath.split(
|
|
15327
|
-
currentPath =
|
|
16320
|
+
for (const segment of childPath.split(sep2).filter(Boolean)) {
|
|
16321
|
+
currentPath = join11(currentPath, segment);
|
|
15328
16322
|
const stats = await lstat2(currentPath).catch((error) => {
|
|
15329
16323
|
throw attachmentErrorForFsFailure(error);
|
|
15330
16324
|
});
|
|
@@ -15352,7 +16346,7 @@ async function assertOpenedWorkspaceFile(targetPath, canonicalRoot, openedStats)
|
|
|
15352
16346
|
}
|
|
15353
16347
|
async function readWorkspaceImageAttachment(filePath, cwd, afterSymlinkValidation, afterCanonicalValidation, afterInitialValidation) {
|
|
15354
16348
|
const lexicalRoot = attachmentContainmentRoot(filePath, cwd);
|
|
15355
|
-
const targetPath =
|
|
16349
|
+
const targetPath = isAbsolute4(filePath) ? resolve4(filePath) : resolve4(lexicalRoot, filePath);
|
|
15356
16350
|
if (!isPathWithin2(lexicalRoot, targetPath)) {
|
|
15357
16351
|
throw new ClaudeAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace.");
|
|
15358
16352
|
}
|
|
@@ -16382,7 +17376,7 @@ function reconcileClaudeUsage(terminal, streamed) {
|
|
|
16382
17376
|
}
|
|
16383
17377
|
|
|
16384
17378
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-turn-lifecycle.ts
|
|
16385
|
-
var
|
|
17379
|
+
var log8 = createLogger("bridge.claude");
|
|
16386
17380
|
function diagnosticErrorClass(error) {
|
|
16387
17381
|
try {
|
|
16388
17382
|
if (!(error instanceof Error))
|
|
@@ -16451,7 +17445,7 @@ async function reconcilePlanModeFromStatus(turn, reported) {
|
|
|
16451
17445
|
try {
|
|
16452
17446
|
await applySessionPlanMode(session, false);
|
|
16453
17447
|
} catch (error) {
|
|
16454
|
-
|
|
17448
|
+
log8.warn("plan-mode.record-failed", { sessionId, errorClass: diagnosticErrorClass(error) });
|
|
16455
17449
|
}
|
|
16456
17450
|
}
|
|
16457
17451
|
function setCompletionBlockedByBackgroundTasks(turn, blocked) {
|
|
@@ -16696,7 +17690,7 @@ function createTurnState(session, sessionId, init) {
|
|
|
16696
17690
|
}
|
|
16697
17691
|
|
|
16698
17692
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-admission.ts
|
|
16699
|
-
var
|
|
17693
|
+
var log9 = createLogger("bridge.claude");
|
|
16700
17694
|
var STREAM_EVENT_COALESCE_MS = 100;
|
|
16701
17695
|
function admitPrompt(sessionId, options) {
|
|
16702
17696
|
const session = sessions.get(sessionId);
|
|
@@ -16831,7 +17825,7 @@ async function readTranscriptForPrompt(session) {
|
|
|
16831
17825
|
try {
|
|
16832
17826
|
return await readPersistedSessionMessagesOnce(session);
|
|
16833
17827
|
} catch (error) {
|
|
16834
|
-
|
|
17828
|
+
log9.warn("transcript.hydrate-failed", { error: formatLogError(error, { stack: false }) });
|
|
16835
17829
|
return TRANSCRIPT_READ_FAILED;
|
|
16836
17830
|
}
|
|
16837
17831
|
}
|
|
@@ -16918,7 +17912,7 @@ import { query as query2 } from "@anthropic-ai/claude-agent-sdk";
|
|
|
16918
17912
|
|
|
16919
17913
|
// ../../bridges/claude-bridge/src/services/mcp-config.ts
|
|
16920
17914
|
import { createHash as createHash9 } from "node:crypto";
|
|
16921
|
-
import { join as
|
|
17915
|
+
import { join as join12 } from "node:path";
|
|
16922
17916
|
|
|
16923
17917
|
// ../protocol/src/agent-mail.ts
|
|
16924
17918
|
var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
|
|
@@ -16986,7 +17980,7 @@ var ORKESTRATOR_ARTIFACT_MCP_SERVER_NAME = "orkestrator-artifacts";
|
|
|
16986
17980
|
var ORKESTRATOR_ARTIFACT_MCP_PATH = "/artifact-mcp";
|
|
16987
17981
|
|
|
16988
17982
|
// ../../bridges/claude-bridge/src/services/mcp-config.ts
|
|
16989
|
-
var
|
|
17983
|
+
var log10 = createLogger("bridge.claude");
|
|
16990
17984
|
var AGENT_MCP_SERVER_NAME = "orkestrator";
|
|
16991
17985
|
var AGENT_MCP_URL_ENV = "ORKESTRATOR_AGENT_MCP_URL";
|
|
16992
17986
|
var AGENT_MCP_TOKEN_ENV = "ORKESTRATOR_AGENT_MCP_TOKEN";
|
|
@@ -17033,7 +18027,7 @@ async function loadGlobalMcpServers() {
|
|
|
17033
18027
|
return servers ?? {};
|
|
17034
18028
|
}
|
|
17035
18029
|
async function loadProjectMcpServers(cwd) {
|
|
17036
|
-
const servers = await readJsonSliceCached(
|
|
18030
|
+
const servers = await readJsonSliceCached(join12(cwd, ".mcp.json"), "mcpServers", (config) => config?.mcpServers);
|
|
17037
18031
|
return servers ?? {};
|
|
17038
18032
|
}
|
|
17039
18033
|
async function loadProjectOverridesFromGlobal2(cwd) {
|
|
@@ -17071,7 +18065,7 @@ function toSdkServers(configs) {
|
|
|
17071
18065
|
if (sdkConfig) {
|
|
17072
18066
|
servers[name] = sdkConfig;
|
|
17073
18067
|
} else {
|
|
17074
|
-
|
|
18068
|
+
log10.warn("mcp.config-ignored");
|
|
17075
18069
|
}
|
|
17076
18070
|
}
|
|
17077
18071
|
return servers;
|
|
@@ -17153,7 +18147,7 @@ async function loadScopedMcpServers(cwd, scope) {
|
|
|
17153
18147
|
const [global2, projectGlobal, projectLocal] = await Promise.all([
|
|
17154
18148
|
readJsonSliceCachedWithDigest(path, "mcpServers", (config) => config?.mcpServers),
|
|
17155
18149
|
scope === "all" ? readJsonSliceCachedWithDigest(path, `projects:${cwd}:mcpServers`, (config) => config?.projects?.[cwd]?.mcpServers) : null,
|
|
17156
|
-
scope === "all" ? readJsonSliceCachedWithDigest(
|
|
18150
|
+
scope === "all" ? readJsonSliceCachedWithDigest(join12(cwd, ".mcp.json"), "mcpServers", (config) => config?.mcpServers) : null
|
|
17157
18151
|
]);
|
|
17158
18152
|
const configs = {
|
|
17159
18153
|
...global2.value,
|
|
@@ -17234,11 +18228,11 @@ async function getMcpRuntimeConfig(cwd, env = process.env, connection, sources =
|
|
|
17234
18228
|
}
|
|
17235
18229
|
|
|
17236
18230
|
// ../../bridges/claude-bridge/src/services/session-manager-commands.ts
|
|
17237
|
-
import { randomUUID as
|
|
18231
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
17238
18232
|
|
|
17239
18233
|
// ../../bridges/claude-bridge/src/services/claude-model-catalog.ts
|
|
17240
|
-
import { homedir as
|
|
17241
|
-
import { join as
|
|
18234
|
+
import { homedir as homedir3 } from "node:os";
|
|
18235
|
+
import { join as join13 } from "node:path";
|
|
17242
18236
|
import { stat as stat5 } from "node:fs/promises";
|
|
17243
18237
|
|
|
17244
18238
|
// ../../bridges/claude-bridge/src/services/live-claude-control.ts
|
|
@@ -17436,7 +18430,7 @@ function claudeReadiness() {
|
|
|
17436
18430
|
}
|
|
17437
18431
|
|
|
17438
18432
|
// ../../bridges/claude-bridge/src/services/claude-model-catalog.ts
|
|
17439
|
-
var
|
|
18433
|
+
var log11 = createLogger("bridge.claude");
|
|
17440
18434
|
var CLAUDE_MODEL_CACHE_TTL_MS = 60 * 60000;
|
|
17441
18435
|
var CLAUDE_MODEL_PROBE_TIMEOUT_MS = 25000;
|
|
17442
18436
|
var remembered;
|
|
@@ -17464,15 +18458,15 @@ function catalogModels(models) {
|
|
|
17464
18458
|
}));
|
|
17465
18459
|
}
|
|
17466
18460
|
async function claudeCliIdentity() {
|
|
17467
|
-
const configDir = process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
18461
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR?.trim() || join13(homedir3(), ".claude");
|
|
17468
18462
|
const executable = process.env.CLAUDE_CLI_PATH?.trim();
|
|
17469
18463
|
const resolved = executable ? Bun.which(executable, { PATH: process.env.PATH }) || executable : undefined;
|
|
17470
18464
|
const cwd = process.env.CWD || process.cwd();
|
|
17471
18465
|
const paths = [
|
|
17472
18466
|
resolved,
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
18467
|
+
join13(configDir, "settings.json"),
|
|
18468
|
+
join13(cwd, ".claude/settings.json"),
|
|
18469
|
+
join13(cwd, ".claude/settings.local.json")
|
|
17476
18470
|
];
|
|
17477
18471
|
const files = await Promise.all(paths.map(async (path) => {
|
|
17478
18472
|
const file = path ? await stat5(path).catch(() => {
|
|
@@ -17577,7 +18571,7 @@ async function probeModels(at) {
|
|
|
17577
18571
|
await rememberModels(models, account, at);
|
|
17578
18572
|
return { source: "sdk", models: catalogModels(models) };
|
|
17579
18573
|
} catch (error) {
|
|
17580
|
-
|
|
18574
|
+
log11.warn("models.fetch-failed", { error: formatLogError(error) });
|
|
17581
18575
|
return fallbackCatalog();
|
|
17582
18576
|
} finally {
|
|
17583
18577
|
clearTimeout(timer);
|
|
@@ -17919,7 +18913,7 @@ function idleSteerPromptReply(prompt, agentLabel) {
|
|
|
17919
18913
|
|
|
17920
18914
|
// ../../bridges/claude-bridge/src/services/claude-terminal-commands.ts
|
|
17921
18915
|
import { mkdir as mkdir5, readFile as readFile6, rename as rename5, writeFile as writeFile5 } from "node:fs/promises";
|
|
17922
|
-
import { join as
|
|
18916
|
+
import { join as join14 } from "node:path";
|
|
17923
18917
|
var FILE_NAME = "terminal-slash-commands.json";
|
|
17924
18918
|
var MAX_VERSIONS = 4;
|
|
17925
18919
|
var MAX_NAMES = 512;
|
|
@@ -17930,7 +18924,7 @@ var dirty = false;
|
|
|
17930
18924
|
var entries = [];
|
|
17931
18925
|
var writes = Promise.resolve();
|
|
17932
18926
|
function filePath() {
|
|
17933
|
-
return
|
|
18927
|
+
return join14(claudeOrkestratorDir(), FILE_NAME);
|
|
17934
18928
|
}
|
|
17935
18929
|
function validVersion(value) {
|
|
17936
18930
|
return typeof value === "string" && value.length > 0 && value.length <= MAX_VERSION_LENGTH;
|
|
@@ -18483,7 +19477,7 @@ async function gracefulInterruptClaudeSession(sessionId) {
|
|
|
18483
19477
|
}
|
|
18484
19478
|
|
|
18485
19479
|
// ../../bridges/claude-bridge/src/services/session-manager-commands.ts
|
|
18486
|
-
var CATALOGUE_GENERATION =
|
|
19480
|
+
var CATALOGUE_GENERATION = randomUUID5();
|
|
18487
19481
|
var COMMAND_PROBE_TIMEOUT_MS = 30000;
|
|
18488
19482
|
var MAX_LOCAL_COMMAND_OUTPUT_BYTES = 64 * 1024;
|
|
18489
19483
|
var MAX_MESSAGE_BYTES = 512;
|
|
@@ -19377,7 +20371,7 @@ function claudeArtifactServerTools(servers) {
|
|
|
19377
20371
|
|
|
19378
20372
|
// ../protocol/src/node/repository-instructions.ts
|
|
19379
20373
|
import { open as open3, realpath as realpath3 } from "node:fs/promises";
|
|
19380
|
-
import { join as
|
|
20374
|
+
import { join as join15, relative as relative2, isAbsolute as isAbsolute5 } from "node:path";
|
|
19381
20375
|
|
|
19382
20376
|
// ../protocol/src/rich-content-policy.ts
|
|
19383
20377
|
var KIB = 1024;
|
|
@@ -19576,11 +20570,11 @@ function repositoryInstructionsBlock(path, content, truncated) {
|
|
|
19576
20570
|
// ../protocol/src/node/repository-instructions.ts
|
|
19577
20571
|
var MAX_REPOSITORY_INSTRUCTIONS_BYTES = 256 * 1024;
|
|
19578
20572
|
async function readRepositoryInstructions(cwd, maxBytes = MAX_REPOSITORY_INSTRUCTIONS_BYTES) {
|
|
19579
|
-
const path =
|
|
20573
|
+
const path = join15(cwd, REPOSITORY_INSTRUCTIONS_FILE);
|
|
19580
20574
|
try {
|
|
19581
20575
|
const [root, target] = await Promise.all([realpath3(cwd), realpath3(path)]);
|
|
19582
20576
|
const inside = relative2(root, target);
|
|
19583
|
-
if (!inside || inside.startsWith("..") ||
|
|
20577
|
+
if (!inside || inside.startsWith("..") || isAbsolute5(inside))
|
|
19584
20578
|
return;
|
|
19585
20579
|
const handle = await open3(target, "r");
|
|
19586
20580
|
try {
|
|
@@ -19877,14 +20871,14 @@ function isValidMcpFormContent(schema, content) {
|
|
|
19877
20871
|
}
|
|
19878
20872
|
|
|
19879
20873
|
// ../../bridges/claude-bridge/src/services/session-manager-interactions.ts
|
|
19880
|
-
var
|
|
20874
|
+
var log12 = createLogger("bridge.claude");
|
|
19881
20875
|
function answerQuestion(requestId, answers) {
|
|
19882
20876
|
const question = pendingQuestions.get(requestId);
|
|
19883
20877
|
if (!question) {
|
|
19884
20878
|
debugLog("[session-manager] Question not found for requestId:", requestId);
|
|
19885
20879
|
return false;
|
|
19886
20880
|
}
|
|
19887
|
-
|
|
20881
|
+
log12.info("question.answering", { requestId, answerCount: Object.keys(answers).length });
|
|
19888
20882
|
const resolver = questionResolvers.get(requestId);
|
|
19889
20883
|
if (resolver) {
|
|
19890
20884
|
debugLog("[session-manager] Resolving promise for question:", requestId);
|
|
@@ -19936,7 +20930,7 @@ function respondToPlanApproval(requestId, approved, feedback) {
|
|
|
19936
20930
|
debugLog("[session-manager] Refusing incomplete plan approval", { requestId });
|
|
19937
20931
|
return false;
|
|
19938
20932
|
}
|
|
19939
|
-
|
|
20933
|
+
log12.info("plan-approval.responding", {
|
|
19940
20934
|
requestId,
|
|
19941
20935
|
approved,
|
|
19942
20936
|
hasFeedback: typeof feedback === "string" && feedback.length > 0
|
|
@@ -21185,7 +22179,7 @@ function classifyUsageLimitError(text) {
|
|
|
21185
22179
|
var USAGE_LIMIT_ERROR_CODE = "usage-limit";
|
|
21186
22180
|
|
|
21187
22181
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-handlers/result.ts
|
|
21188
|
-
var
|
|
22182
|
+
var log13 = createLogger("bridge.claude");
|
|
21189
22183
|
function claudeStartupFailureMessage(reason) {
|
|
21190
22184
|
switch (reason) {
|
|
21191
22185
|
case "org_pin_api_key_conflict":
|
|
@@ -21358,7 +22352,7 @@ async function handleResultMessage(turn, message) {
|
|
|
21358
22352
|
debugLog("[session-manager] Query stopped by the user", { sessionId });
|
|
21359
22353
|
finishTurnInputIfSettled(turn);
|
|
21360
22354
|
} else {
|
|
21361
|
-
|
|
22355
|
+
log13.error("query.failed", { subtype: resultMsg.subtype, sessionId, isError: resultIsError });
|
|
21362
22356
|
const startupFailure = resultMsg.startup_failure_reason ? claudeStartupFailureMessage(resultMsg.startup_failure_reason) : undefined;
|
|
21363
22357
|
const usageLimit = resultMsg.subtype === "success" && classifyUsageLimitError(resultMsg.result) ? resultMsg.result.trim().slice(0, MAX_USAGE_LIMIT_ERROR_CHARS) : undefined;
|
|
21364
22358
|
const resultError = startupFailure || resultMsg.errors?.filter(Boolean).join(`
|
|
@@ -21788,7 +22782,7 @@ async function handleSystemMessage(turn, message) {
|
|
|
21788
22782
|
}
|
|
21789
22783
|
|
|
21790
22784
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-handlers/user.ts
|
|
21791
|
-
var
|
|
22785
|
+
var log14 = createLogger("bridge.claude");
|
|
21792
22786
|
function handleUserMessage(turn, message) {
|
|
21793
22787
|
const { session, sessionId, stream } = turn;
|
|
21794
22788
|
const { toolTracker, taskRegistry, activeTaskIds } = stream;
|
|
@@ -21838,7 +22832,7 @@ function handleUserMessage(turn, message) {
|
|
|
21838
22832
|
if (turn.planApprovedThisTurn) {
|
|
21839
22833
|
for (const tool of toolTracker.getTools()) {
|
|
21840
22834
|
if (tool.toolName === "ExitPlanMode" && tool.toolState === "failure" && tool.toolUseId) {
|
|
21841
|
-
|
|
22835
|
+
log14.warn("plan-exit.failure-overridden", { sessionId, toolUseId: tool.toolUseId });
|
|
21842
22836
|
toolTracker.updateToolResult(tool.toolUseId, {
|
|
21843
22837
|
state: "success",
|
|
21844
22838
|
output: "Plan approved by the user. Proceeding with implementation.",
|
|
@@ -21910,7 +22904,7 @@ async function handleTurnMessage(turn, message) {
|
|
|
21910
22904
|
}
|
|
21911
22905
|
|
|
21912
22906
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-can-use-tool.ts
|
|
21913
|
-
var
|
|
22907
|
+
var log15 = createLogger("bridge.claude");
|
|
21914
22908
|
function boundedPlan(content) {
|
|
21915
22909
|
if (typeof content !== "string" || content.trim().length === 0)
|
|
21916
22910
|
return {};
|
|
@@ -21969,7 +22963,7 @@ async function askUserQuestion(turn, input, permissionContext) {
|
|
|
21969
22963
|
});
|
|
21970
22964
|
try {
|
|
21971
22965
|
const answers = await Promise.race([answerPromise, timeoutPromise]);
|
|
21972
|
-
|
|
22966
|
+
log15.info("question.answers-received", { questionId, answerCount: Object.keys(answers).length });
|
|
21973
22967
|
return {
|
|
21974
22968
|
behavior: "allow",
|
|
21975
22969
|
updatedInput: {
|
|
@@ -21978,7 +22972,7 @@ async function askUserQuestion(turn, input, permissionContext) {
|
|
|
21978
22972
|
}
|
|
21979
22973
|
};
|
|
21980
22974
|
} catch (error) {
|
|
21981
|
-
|
|
22975
|
+
log15.warn("question.wait-failed", { error: formatLogError(error) });
|
|
21982
22976
|
const message = error instanceof Error ? error.message : "Question was cancelled";
|
|
21983
22977
|
if (pendingQuestions.has(questionId)) {
|
|
21984
22978
|
eventEmitter.emit({
|
|
@@ -22059,7 +23053,7 @@ async function requestPlanApproval(turn, input, permissionContext) {
|
|
|
22059
23053
|
});
|
|
22060
23054
|
try {
|
|
22061
23055
|
const response = await Promise.race([approvalPromise, timeoutPromise]);
|
|
22062
|
-
|
|
23056
|
+
log15.info("plan-approval.result", {
|
|
22063
23057
|
approvalId,
|
|
22064
23058
|
approved: response.approved,
|
|
22065
23059
|
hasFeedback: typeof response.feedback === "string" && response.feedback.length > 0
|
|
@@ -22108,7 +23102,7 @@ Please revise the plan based on this feedback.` : `I've reviewed the plan and I
|
|
|
22108
23102
|
};
|
|
22109
23103
|
}
|
|
22110
23104
|
} catch (error) {
|
|
22111
|
-
|
|
23105
|
+
log15.warn("plan-approval.wait-failed", { error: formatLogError(error) });
|
|
22112
23106
|
const errorMessage = error instanceof Error ? error.message : "Plan approval was cancelled";
|
|
22113
23107
|
if (pendingPlanApprovals.has(approvalId)) {
|
|
22114
23108
|
eventEmitter.emit({
|
|
@@ -22198,7 +23192,7 @@ function createClaudeRuntimeTurn(turn) {
|
|
|
22198
23192
|
}
|
|
22199
23193
|
|
|
22200
23194
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-launch.ts
|
|
22201
|
-
var
|
|
23195
|
+
var log16 = createLogger("bridge.claude");
|
|
22202
23196
|
async function consumeClaudeRuntime(runtime, frames, markEnded) {
|
|
22203
23197
|
let failure;
|
|
22204
23198
|
try {
|
|
@@ -22275,7 +23269,7 @@ function releaseOrphanedForeground(runtime, error) {
|
|
|
22275
23269
|
eventEmitter.emit({ type: "session.idle", sessionId, data: { success: true } });
|
|
22276
23270
|
return;
|
|
22277
23271
|
}
|
|
22278
|
-
|
|
23272
|
+
log16.error("runtime.ended-under-resumed-turn", { sessionId });
|
|
22279
23273
|
session.status = "error";
|
|
22280
23274
|
session.error = error instanceof Error ? error.message : String(error);
|
|
22281
23275
|
session.errorCode = undefined;
|
|
@@ -22440,7 +23434,7 @@ async function runTurnOnRuntime(turn, plan, testHooks) {
|
|
|
22440
23434
|
}
|
|
22441
23435
|
|
|
22442
23436
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-settle.ts
|
|
22443
|
-
var
|
|
23437
|
+
var log17 = createLogger("bridge.claude");
|
|
22444
23438
|
function settleTurnEnd(turn) {
|
|
22445
23439
|
const { session, sessionId, options, structuredRequestId, abortController, stream, diagnostics } = turn;
|
|
22446
23440
|
diagnostics?.streamSettled("resolved");
|
|
@@ -22562,7 +23556,7 @@ function settleFailedTurn(turn, error) {
|
|
|
22562
23556
|
recordInterruptedStructuredOutputIfCurrent(turn);
|
|
22563
23557
|
return;
|
|
22564
23558
|
}
|
|
22565
|
-
|
|
23559
|
+
log17.error("prompt.failed", { errorClass: diagnosticErrorClass(error) });
|
|
22566
23560
|
if (session.abortController === abortController) {
|
|
22567
23561
|
const killedBy = killedClaudeProcessSignal(error);
|
|
22568
23562
|
const failure = killedBy ? claudeProcessKilledMessage(killedBy) : error instanceof Error ? error.message : String(error);
|
|
@@ -22672,7 +23666,7 @@ function finalizeTurn(turn) {
|
|
|
22672
23666
|
}
|
|
22673
23667
|
|
|
22674
23668
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt.ts
|
|
22675
|
-
var
|
|
23669
|
+
var log18 = createLogger("bridge.claude");
|
|
22676
23670
|
function turnWriterLiveness(turn) {
|
|
22677
23671
|
const tasks = Object.values(turn.session.backgroundTasks ?? {});
|
|
22678
23672
|
if (tasks.some((task) => LIVE_BACKGROUND_TASK_STATUSES.has(task.status)))
|
|
@@ -22715,7 +23709,7 @@ async function sendPrompt(sessionId, prompt, options, testHooks) {
|
|
|
22715
23709
|
try {
|
|
22716
23710
|
await sendPrompt(sessionId, followUp.prompt, followUp.options);
|
|
22717
23711
|
} catch (repromptError) {
|
|
22718
|
-
|
|
23712
|
+
log18.error(followUp.failureEvent, { error: formatLogError(repromptError) });
|
|
22719
23713
|
return Promise.reject(repromptError);
|
|
22720
23714
|
}
|
|
22721
23715
|
} catch (error) {
|
|
@@ -22727,7 +23721,7 @@ async function sendPrompt(sessionId, prompt, options, testHooks) {
|
|
|
22727
23721
|
}
|
|
22728
23722
|
}
|
|
22729
23723
|
// ../../bridges/claude-bridge/src/services/session-manager-close.ts
|
|
22730
|
-
var
|
|
23724
|
+
var log19 = createLogger("bridge.claude");
|
|
22731
23725
|
var CLOSE_CONFIRMATION_BUDGET_MS = 1e4;
|
|
22732
23726
|
|
|
22733
23727
|
class SessionCloseNotConfirmedError extends Error {
|
|
@@ -22790,7 +23784,7 @@ async function closeQueryControls(controls, deadline) {
|
|
|
22790
23784
|
if (await settlesBy(Promise.resolve(control.close()), deadline))
|
|
22791
23785
|
return;
|
|
22792
23786
|
} catch (error) {
|
|
22793
|
-
|
|
23787
|
+
log19.error("query.close-failed", {
|
|
22794
23788
|
errorClass: error instanceof Error ? error.name : typeof error
|
|
22795
23789
|
});
|
|
22796
23790
|
}
|
|
@@ -22810,18 +23804,18 @@ async function settlesBy(work, deadline) {
|
|
|
22810
23804
|
}
|
|
22811
23805
|
}
|
|
22812
23806
|
// ../../bridges/claude-bridge/src/routes/config.ts
|
|
22813
|
-
var
|
|
23807
|
+
var log20 = createLogger("bridge.claude");
|
|
22814
23808
|
var config2 = new Hono2;
|
|
22815
23809
|
config2.get("/models", async (c) => {
|
|
22816
23810
|
if (c.req.query("forceRefresh") === "true")
|
|
22817
23811
|
invalidateClaudeModelCatalog();
|
|
22818
23812
|
const startedAt = Date.now();
|
|
22819
|
-
|
|
23813
|
+
log20.debug("models.requested");
|
|
22820
23814
|
const [{ models, source }, versions] = await Promise.all([
|
|
22821
23815
|
getAvailableModelCatalog(),
|
|
22822
23816
|
getClaudeRuntimeVersions()
|
|
22823
23817
|
]);
|
|
22824
|
-
|
|
23818
|
+
log20.debug("models.responded", { count: models.length, durationMs: Date.now() - startedAt });
|
|
22825
23819
|
const response = {
|
|
22826
23820
|
models,
|
|
22827
23821
|
source,
|
|
@@ -22898,7 +23892,7 @@ function humanPromptObservation(messages, tasks) {
|
|
|
22898
23892
|
}
|
|
22899
23893
|
|
|
22900
23894
|
// ../../bridges/claude-bridge/src/routes/session.ts
|
|
22901
|
-
import { randomUUID as
|
|
23895
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
22902
23896
|
|
|
22903
23897
|
// ../../node_modules/.bun/hono@4.13.13/node_modules/hono/dist/middleware/body-limit/index.js
|
|
22904
23898
|
var ERROR_MESSAGE = "Payload Too Large";
|
|
@@ -23814,7 +24808,7 @@ function bridgeTranscriptPageRouteBody(source, query) {
|
|
|
23814
24808
|
}
|
|
23815
24809
|
|
|
23816
24810
|
// ../../bridges/claude-bridge/src/routes/session-transcript.ts
|
|
23817
|
-
var
|
|
24811
|
+
var log21 = createLogger("bridge.claude");
|
|
23818
24812
|
function claudeTranscriptSource(id, generation) {
|
|
23819
24813
|
const sessionData = peekSession(id);
|
|
23820
24814
|
if (!sessionData)
|
|
@@ -23867,7 +24861,7 @@ function registerSessionTranscriptRoutes(app, generation, materialize) {
|
|
|
23867
24861
|
const response = c.json(bridgeTranscriptRouteBody(read.source, query3(c)));
|
|
23868
24862
|
if (read.needsHydration) {
|
|
23869
24863
|
hydratePersistedSessionMessages(id).catch((error) => {
|
|
23870
|
-
|
|
24864
|
+
log21.warn("transcript.background-hydrate-failed", {
|
|
23871
24865
|
error: formatLogError(error, { stack: false })
|
|
23872
24866
|
});
|
|
23873
24867
|
});
|
|
@@ -23879,9 +24873,9 @@ function registerSessionTranscriptRoutes(app, generation, materialize) {
|
|
|
23879
24873
|
}
|
|
23880
24874
|
|
|
23881
24875
|
// ../../bridges/claude-bridge/src/routes/session.ts
|
|
23882
|
-
var
|
|
24876
|
+
var log22 = createLogger("bridge.claude");
|
|
23883
24877
|
var session = new Hono2;
|
|
23884
|
-
var TRANSCRIPT_GENERATION =
|
|
24878
|
+
var TRANSCRIPT_GENERATION = randomUUID6();
|
|
23885
24879
|
var MAX_QUESTION_ANSWER_REQUEST_BYTES = AGENT_INTERACTION_LIMITS.maxSerializedPayloadBytes + 1024;
|
|
23886
24880
|
var MAX_CLAUDE_TRANSCRIPT_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
23887
24881
|
function boundClaudeTranscriptResponse(messages, tailMessages) {
|
|
@@ -23959,7 +24953,7 @@ session.post("/create", async (c) => {
|
|
|
23959
24953
|
const clientSessionKey = body.clientSessionKey;
|
|
23960
24954
|
const policy = effectiveExecutionPolicy(isNativeAgentExecutionPolicy(body.policy) ? body.policy : undefined);
|
|
23961
24955
|
const newSession = policy ? await createOrRecoverSession(title, clientSessionKey, policy) : await createOrRecoverSession(title, clientSessionKey);
|
|
23962
|
-
|
|
24956
|
+
log22.info("session.created", { sessionId: newSession.id });
|
|
23963
24957
|
const response = {
|
|
23964
24958
|
sessionId: newSession.id,
|
|
23965
24959
|
title: newSession.title
|
|
@@ -23967,10 +24961,10 @@ session.post("/create", async (c) => {
|
|
|
23967
24961
|
return c.json(response, 201);
|
|
23968
24962
|
} catch (error) {
|
|
23969
24963
|
if (error instanceof PolicyWideningRefusedError) {
|
|
23970
|
-
|
|
24964
|
+
log22.warn("session.policy-widening-refused", { widened: error.widened.join(",") });
|
|
23971
24965
|
return c.json(error.refusal(), 403);
|
|
23972
24966
|
}
|
|
23973
|
-
|
|
24967
|
+
log22.error("session.create-failed", { error: formatLogError(error) });
|
|
23974
24968
|
return c.json({ error: error instanceof Error ? error.message : "Failed to create session" }, 500);
|
|
23975
24969
|
}
|
|
23976
24970
|
});
|
|
@@ -23978,7 +24972,7 @@ session.get("/list", async (c) => {
|
|
|
23978
24972
|
try {
|
|
23979
24973
|
await reconcilePersistedSessions();
|
|
23980
24974
|
} catch (error) {
|
|
23981
|
-
|
|
24975
|
+
log22.warn("sessions.reconcile-failed", { error: formatLogError(error) });
|
|
23982
24976
|
}
|
|
23983
24977
|
const sessions = listSessions();
|
|
23984
24978
|
const response = {
|
|
@@ -23997,7 +24991,7 @@ async function resolveSession(id, failureMessage) {
|
|
|
23997
24991
|
try {
|
|
23998
24992
|
return { ok: true, session: getSession(id) ?? await ensurePersistedSession(id) };
|
|
23999
24993
|
} catch (error) {
|
|
24000
|
-
|
|
24994
|
+
log22.error("session.resolve-failed", { action: failureMessage, error: formatLogError(error) });
|
|
24001
24995
|
return {
|
|
24002
24996
|
ok: false,
|
|
24003
24997
|
body: { error: errorMessage(error, failureMessage) },
|
|
@@ -24018,7 +25012,7 @@ session.get("/:id", async (c) => {
|
|
|
24018
25012
|
try {
|
|
24019
25013
|
await hydratePersistedSessionMessages(id);
|
|
24020
25014
|
} catch (error) {
|
|
24021
|
-
|
|
25015
|
+
log22.error("session.task-state-hydrate-failed", { error: formatLogError(error) });
|
|
24022
25016
|
return c.json({ error: errorMessage(error, "Failed to hydrate session task state") }, sessionErrorStatus(error));
|
|
24023
25017
|
}
|
|
24024
25018
|
}
|
|
@@ -24070,7 +25064,7 @@ session.get("/:id/usage", async (c) => {
|
|
|
24070
25064
|
const contextUsage = await refreshClaudeContextUsage(resolved.session);
|
|
24071
25065
|
return c.json({ contextUsage });
|
|
24072
25066
|
} catch (error) {
|
|
24073
|
-
|
|
25067
|
+
log22.warn("context-usage.read-failed", { error: formatLogError(error, { stack: false }) });
|
|
24074
25068
|
return c.json({ error: "Context usage is temporarily unavailable" }, 503);
|
|
24075
25069
|
}
|
|
24076
25070
|
});
|
|
@@ -24120,7 +25114,7 @@ session.post("/:id/config", async (c) => {
|
|
|
24120
25114
|
const refusePolicyWidening = () => {
|
|
24121
25115
|
const widened = nextPolicy ? executionPolicyWidenings(sessionData.executionPolicy, nextPolicy) : [];
|
|
24122
25116
|
if (widened.length > 0) {
|
|
24123
|
-
|
|
25117
|
+
log22.warn("session.policy-widening-refused", {
|
|
24124
25118
|
sessionId: sessionData.id,
|
|
24125
25119
|
widened: widened.join(",")
|
|
24126
25120
|
});
|
|
@@ -24161,7 +25155,7 @@ session.get("/:id/commands", async (c) => {
|
|
|
24161
25155
|
try {
|
|
24162
25156
|
return c.json(await readClaudeCommandCatalogue(c.req.param("id")));
|
|
24163
25157
|
} catch (error) {
|
|
24164
|
-
|
|
25158
|
+
log22.warn("commands.read-failed", { error: formatLogError(error, { stack: false }) });
|
|
24165
25159
|
return c.json({ error: errorMessage(error, "Claude command discovery failed") }, 503);
|
|
24166
25160
|
}
|
|
24167
25161
|
});
|
|
@@ -24406,7 +25400,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
24406
25400
|
rejectStarted?.(sessionOperationError("conflict", "Prompt stopped before launch"));
|
|
24407
25401
|
}, (error) => {
|
|
24408
25402
|
rejectStarted?.(error);
|
|
24409
|
-
|
|
25403
|
+
log22.error("prompt.processing-failed", { error: formatLogError(error) });
|
|
24410
25404
|
});
|
|
24411
25405
|
return { started, completion };
|
|
24412
25406
|
});
|
|
@@ -24420,7 +25414,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
24420
25414
|
duplicate: true
|
|
24421
25415
|
});
|
|
24422
25416
|
}
|
|
24423
|
-
|
|
25417
|
+
log22.debug("prompt.accepted", { sessionId: id });
|
|
24424
25418
|
return c.json({
|
|
24425
25419
|
status: "processing",
|
|
24426
25420
|
requestId,
|
|
@@ -24433,7 +25427,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
24433
25427
|
if (sessionData.rewindInProgress === true) {
|
|
24434
25428
|
return c.json({ error: "Session is restoring files from a checkpoint" }, 409);
|
|
24435
25429
|
}
|
|
24436
|
-
|
|
25430
|
+
log22.info("prompt.received", {
|
|
24437
25431
|
sessionId: id,
|
|
24438
25432
|
promptLength: prompt.length,
|
|
24439
25433
|
model,
|
|
@@ -24461,16 +25455,16 @@ session.post("/:id/prompt", async (c) => {
|
|
|
24461
25455
|
...workflowResultTurn ? { workflowResultTurn } : {},
|
|
24462
25456
|
...providerPrompt !== undefined ? { providerPrompt } : {}
|
|
24463
25457
|
}).catch((error) => {
|
|
24464
|
-
|
|
25458
|
+
log22.error("prompt.processing-failed", { error: formatLogError(error) });
|
|
24465
25459
|
});
|
|
24466
|
-
|
|
25460
|
+
log22.debug("prompt.accepted", { sessionId: id });
|
|
24467
25461
|
return c.json({
|
|
24468
25462
|
status: "processing",
|
|
24469
25463
|
requestId,
|
|
24470
25464
|
turnStartedAt: sessionData.turnStartedAt
|
|
24471
25465
|
}, 202);
|
|
24472
25466
|
} catch (error) {
|
|
24473
|
-
|
|
25467
|
+
log22.error("prompt.send-failed", { error: formatLogError(error) });
|
|
24474
25468
|
return c.json({ error: errorMessage(error, "Failed to send prompt") }, sessionErrorStatus(error));
|
|
24475
25469
|
}
|
|
24476
25470
|
});
|
|
@@ -24514,7 +25508,7 @@ session.delete("/:id", async (c) => {
|
|
|
24514
25508
|
}
|
|
24515
25509
|
return c.json({ error: "Session not found" }, 404);
|
|
24516
25510
|
} catch (error) {
|
|
24517
|
-
|
|
25511
|
+
log22.error("session.delete-failed", { error: formatLogError(error) });
|
|
24518
25512
|
return c.json({ error: errorMessage(error, "Failed to delete session") }, sessionErrorStatus(error));
|
|
24519
25513
|
}
|
|
24520
25514
|
});
|
|
@@ -24529,7 +25523,7 @@ session.post("/:id/rename", async (c) => {
|
|
|
24529
25523
|
const renamed = await renameSessionDurably(id, title);
|
|
24530
25524
|
return renamed ? c.json({ status: "renamed", title }) : c.json({ error: "Session not found" }, 404);
|
|
24531
25525
|
} catch (error) {
|
|
24532
|
-
|
|
25526
|
+
log22.error("session.rename-failed", { error: formatLogError(error) });
|
|
24533
25527
|
return c.json({ error: errorMessage(error, "Failed to rename session") }, sessionErrorStatus(error));
|
|
24534
25528
|
}
|
|
24535
25529
|
});
|
|
@@ -24558,7 +25552,7 @@ session.post("/:id/fork", async (c) => {
|
|
|
24558
25552
|
title: forked.title
|
|
24559
25553
|
}, 201);
|
|
24560
25554
|
} catch (error) {
|
|
24561
|
-
|
|
25555
|
+
log22.error("session.fork-failed", { error: formatLogError(error) });
|
|
24562
25556
|
return c.json({ error: errorMessage(error, "Failed to fork session") }, sessionErrorStatus(error));
|
|
24563
25557
|
}
|
|
24564
25558
|
});
|
|
@@ -24590,7 +25584,7 @@ session.post("/:id/compact", compactBodyLimit, async (c) => {
|
|
|
24590
25584
|
}
|
|
24591
25585
|
const { instructions } = parsed;
|
|
24592
25586
|
sendPrompt(id, instructions ? `/compact ${instructions}` : "/compact").catch((error) => {
|
|
24593
|
-
|
|
25587
|
+
log22.error("session.compact-failed", { error: formatLogError(error) });
|
|
24594
25588
|
});
|
|
24595
25589
|
return c.json(instructions ? { status: "processing", instructions: "applied" } : { status: "processing" }, 202);
|
|
24596
25590
|
});
|
|
@@ -24608,7 +25602,7 @@ session.post("/:id/rewind", async (c) => {
|
|
|
24608
25602
|
const result = await rewindSessionFiles(id, messageId, dryRun);
|
|
24609
25603
|
return c.json({ status: dryRun ? "previewed" : "rewound", result });
|
|
24610
25604
|
} catch (error) {
|
|
24611
|
-
|
|
25605
|
+
log22.error("session.rewind-failed", { error: formatLogError(error) });
|
|
24612
25606
|
return c.json({ error: errorMessage(error, "Failed to rewind session files") }, sessionErrorStatus(error));
|
|
24613
25607
|
}
|
|
24614
25608
|
});
|
|
@@ -24619,7 +25613,7 @@ session.post("/:id/tasks/:taskId/stop", async (c) => {
|
|
|
24619
25613
|
return c.json({ status: "stopped" });
|
|
24620
25614
|
return c.json({ error: stopped.message }, stopped.reason === "no_control_channel" ? 409 : 404);
|
|
24621
25615
|
} catch (error) {
|
|
24622
|
-
|
|
25616
|
+
log22.error("task.stop-route-failed", { error: formatLogError(error) });
|
|
24623
25617
|
return c.json({ error: errorMessage(error, "Failed to stop background task") }, sessionErrorStatus(error));
|
|
24624
25618
|
}
|
|
24625
25619
|
});
|
|
@@ -24690,7 +25684,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
24690
25684
|
const pendingQuestions = getPendingQuestions(sessionId);
|
|
24691
25685
|
const pendingQuestion = pendingQuestions.find((q) => q.id === questionId);
|
|
24692
25686
|
if (!pendingQuestion) {
|
|
24693
|
-
|
|
25687
|
+
log22.info("question.stale", { questionId });
|
|
24694
25688
|
return c.json(stalePrompt("Question is no longer pending"), STALE_PROMPT_STATUS);
|
|
24695
25689
|
}
|
|
24696
25690
|
if (!isBoundedClaudeQuestionAnswers(answersArray, pendingQuestion.questions.length)) {
|
|
@@ -24701,7 +25695,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
24701
25695
|
const questionAnswers = answersArray[index] || [];
|
|
24702
25696
|
answersRecord[q.question] = serializeClaudeQuestionAnswer(questionAnswers, q.multiSelect === true);
|
|
24703
25697
|
});
|
|
24704
|
-
|
|
25698
|
+
log22.debug("question.answers-prepared", {
|
|
24705
25699
|
questionId,
|
|
24706
25700
|
questionCount: pendingQuestion.questions.length,
|
|
24707
25701
|
answerCount: answersArray.reduce((count, answers) => count + answers.length, 0)
|
|
@@ -24713,7 +25707,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
24713
25707
|
return c.json(stalePrompt("Question is no longer pending"), STALE_PROMPT_STATUS);
|
|
24714
25708
|
}
|
|
24715
25709
|
} catch (error) {
|
|
24716
|
-
|
|
25710
|
+
log22.error("question.answer-failed", { error: formatLogError(error) });
|
|
24717
25711
|
return c.json({ error: error instanceof Error ? error.message : "Failed to answer question" }, 500);
|
|
24718
25712
|
}
|
|
24719
25713
|
});
|
|
@@ -24753,7 +25747,7 @@ session.post("/:id/plan-approvals/:approvalId/respond", planApprovalBodyLimit, a
|
|
|
24753
25747
|
if (approved && (typeof pendingApproval.plan !== "string" || pendingApproval.plan.trim().length === 0 || pendingApproval.planTruncated === true)) {
|
|
24754
25748
|
return c.json({ error: "A complete plan is required before approval", status: "rejected" }, 409);
|
|
24755
25749
|
}
|
|
24756
|
-
|
|
25750
|
+
log22.info("plan-approval.response-received", {
|
|
24757
25751
|
sessionId,
|
|
24758
25752
|
approvalId,
|
|
24759
25753
|
approved,
|
|
@@ -24766,7 +25760,7 @@ session.post("/:id/plan-approvals/:approvalId/respond", planApprovalBodyLimit, a
|
|
|
24766
25760
|
return c.json(stalePrompt("Plan approval is no longer pending"), STALE_PROMPT_STATUS);
|
|
24767
25761
|
}
|
|
24768
25762
|
} catch (error) {
|
|
24769
|
-
|
|
25763
|
+
log22.error("plan-approval.response-failed", { error: formatLogError(error) });
|
|
24770
25764
|
return c.json({ error: error instanceof Error ? error.message : "Failed to respond to plan approval" }, 500);
|
|
24771
25765
|
}
|
|
24772
25766
|
});
|
|
@@ -25165,7 +26159,7 @@ class EventRing {
|
|
|
25165
26159
|
}
|
|
25166
26160
|
|
|
25167
26161
|
// ../../bridges/claude-bridge/src/routes/events.ts
|
|
25168
|
-
var
|
|
26162
|
+
var log23 = createLogger("bridge.claude");
|
|
25169
26163
|
var serializedEvents = new WeakMap;
|
|
25170
26164
|
function serializeEvent(event) {
|
|
25171
26165
|
let serialized = serializedEvents.get(event);
|
|
@@ -25371,10 +26365,10 @@ function createEventsRouter(limits = {}) {
|
|
|
25371
26365
|
events.get("/subscribe", (c) => {
|
|
25372
26366
|
const origin = c.req.header("origin");
|
|
25373
26367
|
const userAgent = c.req.header("user-agent");
|
|
25374
|
-
|
|
26368
|
+
log23.debug("sse.subscribe-requested", { origin, userAgent });
|
|
25375
26369
|
return streamSSE(c, async (stream) => {
|
|
25376
26370
|
const connectedAt = new Date().toISOString();
|
|
25377
|
-
|
|
26371
|
+
log23.debug("sse.opened", { connectedAt });
|
|
25378
26372
|
let isOpen = true;
|
|
25379
26373
|
let resolveConnectionClosed;
|
|
25380
26374
|
const connectionClosed = new Promise((resolve) => {
|
|
@@ -25385,7 +26379,7 @@ function createEventsRouter(limits = {}) {
|
|
|
25385
26379
|
resolveRequestAborted = resolve;
|
|
25386
26380
|
});
|
|
25387
26381
|
const onRequestAbort = () => {
|
|
25388
|
-
|
|
26382
|
+
log23.debug("sse.aborted");
|
|
25389
26383
|
isOpen = false;
|
|
25390
26384
|
resolveRequestAborted();
|
|
25391
26385
|
};
|
|
@@ -25399,7 +26393,7 @@ function createEventsRouter(limits = {}) {
|
|
|
25399
26393
|
if (!isOpen)
|
|
25400
26394
|
return;
|
|
25401
26395
|
isOpen = false;
|
|
25402
|
-
|
|
26396
|
+
log23.info("sse.closed", { reason });
|
|
25403
26397
|
resolveConnectionClosed();
|
|
25404
26398
|
};
|
|
25405
26399
|
const writeFrame = createBoundedSseWriter(async (frame) => {
|
|
@@ -25450,7 +26444,7 @@ function createEventsRouter(limits = {}) {
|
|
|
25450
26444
|
}
|
|
25451
26445
|
writeFrame(frame).catch((error) => {
|
|
25452
26446
|
if (!c.req.raw.signal.aborted) {
|
|
25453
|
-
|
|
26447
|
+
log23.warn("sse.write-failed", { error: formatLogError(error) });
|
|
25454
26448
|
closeConnection("write failed");
|
|
25455
26449
|
}
|
|
25456
26450
|
});
|
|
@@ -25512,7 +26506,7 @@ function createEventsRouter(limits = {}) {
|
|
|
25512
26506
|
data: JSON.stringify({ timestamp: new Date().toISOString() })
|
|
25513
26507
|
}).catch((error) => {
|
|
25514
26508
|
if (!c.req.raw.signal.aborted) {
|
|
25515
|
-
|
|
26509
|
+
log23.warn("sse.keepalive-failed", { error: formatLogError(error, { stack: false }) });
|
|
25516
26510
|
closeConnection("keepalive failed");
|
|
25517
26511
|
}
|
|
25518
26512
|
});
|
|
@@ -25520,10 +26514,10 @@ function createEventsRouter(limits = {}) {
|
|
|
25520
26514
|
await Promise.race([connectionClosed, requestAborted]);
|
|
25521
26515
|
} catch (error) {
|
|
25522
26516
|
if (!c.req.raw.signal.aborted) {
|
|
25523
|
-
|
|
26517
|
+
log23.warn("sse.handshake-failed", { error: formatLogError(error) });
|
|
25524
26518
|
}
|
|
25525
26519
|
} finally {
|
|
25526
|
-
|
|
26520
|
+
log23.debug("sse.cleanup");
|
|
25527
26521
|
isOpen = false;
|
|
25528
26522
|
c.req.raw.signal.removeEventListener("abort", onRequestAbort);
|
|
25529
26523
|
if (keepaliveInterval)
|
|
@@ -25539,7 +26533,7 @@ var events = createEventsRouter();
|
|
|
25539
26533
|
var events_default = events;
|
|
25540
26534
|
|
|
25541
26535
|
// ../../bridges/claude-bridge/src/routes/mcp.ts
|
|
25542
|
-
var
|
|
26536
|
+
var log24 = createLogger("bridge.claude");
|
|
25543
26537
|
var mcp = new Hono2;
|
|
25544
26538
|
mcp.get("/servers", async (c) => {
|
|
25545
26539
|
try {
|
|
@@ -25550,14 +26544,14 @@ mcp.get("/servers", async (c) => {
|
|
|
25550
26544
|
cwd
|
|
25551
26545
|
});
|
|
25552
26546
|
} catch (error) {
|
|
25553
|
-
|
|
26547
|
+
log24.error("mcp.read-failed", { error: formatLogError(error) });
|
|
25554
26548
|
return c.json({ error: error instanceof Error ? error.message : "Failed to get MCP servers" }, 500);
|
|
25555
26549
|
}
|
|
25556
26550
|
});
|
|
25557
26551
|
var mcp_default = mcp;
|
|
25558
26552
|
|
|
25559
26553
|
// ../../bridges/claude-bridge/src/routes/plugins.ts
|
|
25560
|
-
var
|
|
26554
|
+
var log25 = createLogger("bridge.claude");
|
|
25561
26555
|
var plugins = new Hono2;
|
|
25562
26556
|
plugins.get("/", async (c) => {
|
|
25563
26557
|
try {
|
|
@@ -25568,7 +26562,7 @@ plugins.get("/", async (c) => {
|
|
|
25568
26562
|
cwd
|
|
25569
26563
|
});
|
|
25570
26564
|
} catch (error) {
|
|
25571
|
-
|
|
26565
|
+
log25.error("plugins.read-failed", { error: formatLogError(error) });
|
|
25572
26566
|
return c.json({ error: error instanceof Error ? error.message : "Failed to get plugins" }, 500);
|
|
25573
26567
|
}
|
|
25574
26568
|
});
|
|
@@ -25761,9 +26755,9 @@ function installFatalRejectionGuard(options) {
|
|
|
25761
26755
|
}
|
|
25762
26756
|
|
|
25763
26757
|
// ../protocol/src/node/process-failure-log.ts
|
|
25764
|
-
var
|
|
26758
|
+
var log26 = createLogger("process");
|
|
25765
26759
|
function logUnhandledRejection(reason) {
|
|
25766
|
-
|
|
26760
|
+
log26.throttled("error", "rejection.unhandled", {
|
|
25767
26761
|
error: reason,
|
|
25768
26762
|
fields: () => ({ error: formatLogError(reason, { message: false }) })
|
|
25769
26763
|
});
|
|
@@ -27255,11 +28249,11 @@ var serve = (options, listeningListener) => {
|
|
|
27255
28249
|
|
|
27256
28250
|
// ../protocol/src/node/bridge-credential.ts
|
|
27257
28251
|
import { createHash as createHash13, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
|
|
27258
|
-
import { createRequire } from "node:module";
|
|
28252
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
27259
28253
|
var BRIDGE_TOKEN_PREFIX = "okb_";
|
|
27260
28254
|
var PR_SET_DUMPABLE = 4;
|
|
27261
28255
|
var VERIFIER_PATTERN = /^[0-9a-f]{64}$/;
|
|
27262
|
-
var
|
|
28256
|
+
var log27 = createLogger("bridge.lifecycle");
|
|
27263
28257
|
function mintBridgeToken() {
|
|
27264
28258
|
return `${BRIDGE_TOKEN_PREFIX}${randomBytes2(32).toString("base64url")}`;
|
|
27265
28259
|
}
|
|
@@ -27283,7 +28277,7 @@ function credentialFromVerifier(verifier, plainToken) {
|
|
|
27283
28277
|
function bridgeCredentialFromToken(token) {
|
|
27284
28278
|
return credentialFromVerifier(bridgeTokenVerifier(token), token);
|
|
27285
28279
|
}
|
|
27286
|
-
function markProcessNonDumpable(loadFfi = () =>
|
|
28280
|
+
function markProcessNonDumpable(loadFfi = () => createRequire2(import.meta.url)("bun:ffi")) {
|
|
27287
28281
|
if (process.platform !== "linux" || !process.versions.bun)
|
|
27288
28282
|
return false;
|
|
27289
28283
|
try {
|
|
@@ -27300,9 +28294,9 @@ function markProcessNonDumpable(loadFfi = () => createRequire(import.meta.url)("
|
|
|
27300
28294
|
} finally {
|
|
27301
28295
|
libc.close();
|
|
27302
28296
|
}
|
|
27303
|
-
|
|
28297
|
+
log27.warn("credential.not-hardened", { reason: "prctl-refused" });
|
|
27304
28298
|
} catch {
|
|
27305
|
-
|
|
28299
|
+
log27.warn("credential.not-hardened", { reason: "ffi-unavailable" });
|
|
27306
28300
|
}
|
|
27307
28301
|
return false;
|
|
27308
28302
|
}
|
|
@@ -27321,11 +28315,11 @@ function loadBridgeCredential(tokenEnv, options = {}) {
|
|
|
27321
28315
|
}
|
|
27322
28316
|
|
|
27323
28317
|
// ../../bridges/claude-bridge/src/index.ts
|
|
27324
|
-
var
|
|
28318
|
+
var log28 = createLogger("bridge.claude");
|
|
27325
28319
|
configureBridgeLogger();
|
|
27326
28320
|
var app = new Hono2;
|
|
27327
28321
|
app.onError((error, c) => {
|
|
27328
|
-
|
|
28322
|
+
log28.error("http.request-failed", {
|
|
27329
28323
|
method: c.req.method,
|
|
27330
28324
|
path: c.req.path,
|
|
27331
28325
|
error: formatLogError(error)
|
|
@@ -27448,7 +28442,7 @@ if (parentPid !== null) {
|
|
|
27448
28442
|
startParentWatchdog({
|
|
27449
28443
|
parentPid,
|
|
27450
28444
|
onParentExit: () => {
|
|
27451
|
-
|
|
28445
|
+
log28.warn("parent.gone", { parentPid });
|
|
27452
28446
|
process.exit(0);
|
|
27453
28447
|
}
|
|
27454
28448
|
});
|
|
@@ -27459,13 +28453,13 @@ function startBridgeServer(env = process.env, start = serve) {
|
|
|
27459
28453
|
}
|
|
27460
28454
|
const port = parseInt(env.PORT || "4097", 10);
|
|
27461
28455
|
const hostname = env.HOSTNAME || "0.0.0.0";
|
|
27462
|
-
|
|
28456
|
+
log28.debug("server.starting", { hostname, port });
|
|
27463
28457
|
const server = start({
|
|
27464
28458
|
fetch: app.fetch,
|
|
27465
28459
|
port,
|
|
27466
28460
|
hostname
|
|
27467
28461
|
});
|
|
27468
|
-
|
|
28462
|
+
log28.info("server.listening", { hostname, port });
|
|
27469
28463
|
return server;
|
|
27470
28464
|
}
|
|
27471
28465
|
var __testing = {
|