orkestrator 2.36.5-beta → 2.36.6-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 +72 -20
- package/dist/main.js +64254 -62158
- package/package.json +3 -3
- package/resources/acp-bridge/dist/index.js +365 -78
- package/resources/claude-bridge/dist/index.js +411 -96
- package/resources/codex-bridge/dist/index.js +541 -148
- package/resources/cursor-bridge/dist/index.js +344 -61
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +885 -350
- package/resources/pi-bridge/runtime/install.json +1 -1
|
@@ -1,3 +1,75 @@
|
|
|
1
|
+
// ../protocol/src/node/bridge-launch-environment.ts
|
|
2
|
+
import { closeSync, fstatSync, openSync, readSync, rmSync, constants } from "node:fs";
|
|
3
|
+
var BRIDGE_LAUNCH_ENVIRONMENT_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_ENVIRONMENT";
|
|
4
|
+
var BRIDGE_LAUNCH_KEYS_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_KEYS";
|
|
5
|
+
var BRIDGE_LAUNCH_WORKDIR_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_WORKDIR";
|
|
6
|
+
var MAX_SNAPSHOT_BYTES = 1024 * 1024;
|
|
7
|
+
var MAX_SNAPSHOT_ENTRIES = 4096;
|
|
8
|
+
var NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_%.-]*$/;
|
|
9
|
+
var LAUNCH_ONLY = /(?:_BRIDGE_TOKEN|_TOKEN_SHA256|_AUTHORITY_KEY)$|^ORKESTRATOR_BRIDGE_(?:LAUNCH_|EXECUTION_POLICY$)|^ORKESTRATOR_COORDINATOR_/;
|
|
10
|
+
var NOT_APPLIED = new Set(["PWD", "OLDPWD", "SHLVL", "_", "NODE_PATH"]);
|
|
11
|
+
function readSnapshot(file) {
|
|
12
|
+
let fd;
|
|
13
|
+
try {
|
|
14
|
+
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const stat = fstatSync(fd);
|
|
20
|
+
if (!stat.isFile() || stat.size > MAX_SNAPSHOT_BYTES)
|
|
21
|
+
return null;
|
|
22
|
+
const buffer = Buffer.alloc(stat.size);
|
|
23
|
+
let offset = 0;
|
|
24
|
+
while (offset < buffer.length) {
|
|
25
|
+
const read = readSync(fd, buffer, offset, buffer.length - offset, offset);
|
|
26
|
+
if (read === 0)
|
|
27
|
+
break;
|
|
28
|
+
offset += read;
|
|
29
|
+
}
|
|
30
|
+
return buffer.subarray(0, offset);
|
|
31
|
+
} finally {
|
|
32
|
+
closeSync(fd);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function applyBridgeLaunchEnvironment(env = process.env, chdir = (directory) => process.chdir(directory)) {
|
|
36
|
+
const file = env[BRIDGE_LAUNCH_ENVIRONMENT_ENV];
|
|
37
|
+
if (!file)
|
|
38
|
+
return null;
|
|
39
|
+
const trusted = new Set((env[BRIDGE_LAUNCH_KEYS_ENV] ?? "").split(",").map((name) => name.trim()).filter(Boolean));
|
|
40
|
+
const workdir = env[BRIDGE_LAUNCH_WORKDIR_ENV];
|
|
41
|
+
delete env[BRIDGE_LAUNCH_ENVIRONMENT_ENV];
|
|
42
|
+
delete env[BRIDGE_LAUNCH_KEYS_ENV];
|
|
43
|
+
delete env[BRIDGE_LAUNCH_WORKDIR_ENV];
|
|
44
|
+
const result = { applied: 0, refused: 0 };
|
|
45
|
+
const snapshot = readSnapshot(file);
|
|
46
|
+
rmSync(file, { force: true });
|
|
47
|
+
if (snapshot) {
|
|
48
|
+
const entries = snapshot.toString("utf8").split("\x00").slice(0, MAX_SNAPSHOT_ENTRIES);
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
const separator = entry.indexOf("=");
|
|
51
|
+
if (separator <= 0)
|
|
52
|
+
continue;
|
|
53
|
+
const name = entry.slice(0, separator);
|
|
54
|
+
if (!NAME_PATTERN.test(name) || NOT_APPLIED.has(name))
|
|
55
|
+
continue;
|
|
56
|
+
if (trusted.has(name) || LAUNCH_ONLY.test(name)) {
|
|
57
|
+
result.refused += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
env[name] = entry.slice(separator + 1);
|
|
61
|
+
result.applied += 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (workdir) {
|
|
65
|
+
try {
|
|
66
|
+
chdir(workdir);
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
applyBridgeLaunchEnvironment();
|
|
72
|
+
|
|
1
73
|
// ../protocol/src/log-vocabulary/define.ts
|
|
2
74
|
var ESSENTIAL_ERROR_FIELDS = {
|
|
3
75
|
"error.name": "label",
|
|
@@ -416,6 +488,7 @@ var DESKTOP_LOG_AREAS = defineLogAreas({
|
|
|
416
488
|
events: {
|
|
417
489
|
"attention-failed": "A dialog could not ask for the user's attention.",
|
|
418
490
|
closed: "A native dialog closed.",
|
|
491
|
+
"hidden-cancelled": "A hidden profile cancelled a dialog without opening native UI.",
|
|
419
492
|
"open-failed": "A dialog could not open; it was answered as cancelled.",
|
|
420
493
|
opening: "A native dialog is opening.",
|
|
421
494
|
"preview-beforeunload-ignored": "A browser preview's beforeunload handler was ignored.",
|
|
@@ -501,6 +574,7 @@ var ENVIRONMENT_LOG_AREAS = defineLogAreas({
|
|
|
501
574
|
"orphan-session.reaped": "A native session no tab references was torn down.",
|
|
502
575
|
"handoff-sweep.failed": "Sweeping transferred transcripts no tab references failed.",
|
|
503
576
|
"delete.terminals-survived": "Terminal process trees outlived termination, so the deletion stops.",
|
|
577
|
+
"delete.step-deadline": "A deletion step that runs child processes passed its deadline; they are stopped and the deletion fails once they have.",
|
|
504
578
|
"delete.artifacts-left": "Graph run artifact directories were not removed.",
|
|
505
579
|
"delete.worktrees-kept": "Graph runs kept branch worktrees.",
|
|
506
580
|
"delete.step-failed": "One best-effort part of deleting an environment failed; `step` says which, and the rest goes on.",
|
|
@@ -535,6 +609,7 @@ var GATEWAY_LOG_AREAS = defineLogAreas({
|
|
|
535
609
|
"host.refused": "A request named a host this gateway does not answer to. Logged once per name, up to a limit.",
|
|
536
610
|
"port.fallback": "The preferred port was taken, so a nearby one is used.",
|
|
537
611
|
"port.fallback-distant": "The preferred port and those nearby were taken, so another is used.",
|
|
612
|
+
"request-auth.fallback": "A desktop request-auth hook failed closed. Phase only; no request or error content.",
|
|
538
613
|
"request.failed": "A gateway request failed. Throttled: repeats are counted, not written.",
|
|
539
614
|
"websocket.upgrade-failed": "A WebSocket upgrade failed.",
|
|
540
615
|
"events.client-dropped": "An event-stream client buffered too much and was dropped; it reconnects and refetches.",
|
|
@@ -593,6 +668,11 @@ var LOCAL_SERVER_LOG_AREAS = defineLogAreas({
|
|
|
593
668
|
requested: "boolean"
|
|
594
669
|
}
|
|
595
670
|
},
|
|
671
|
+
"bridge.orphans-reaped": {
|
|
672
|
+
description: "Processes a bridge left in its process group after exiting on its own (its agent CLI, mid-turn) were stopped. `warn` when they left; `error` when one survived SIGKILL.",
|
|
673
|
+
essential: true,
|
|
674
|
+
fields: { key: "label", pid: "number", result: "label" }
|
|
675
|
+
},
|
|
596
676
|
"reaper.tmux-list-failed": "Orphaned claude-tmux sessions could not be listed.",
|
|
597
677
|
"reaper.tmux-kill-failed": "An orphaned tmux session could not be killed.",
|
|
598
678
|
"reaper.tmux-reaped": "Orphaned claude-tmux sessions of a deleted environment were killed.",
|
|
@@ -1426,7 +1506,11 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1426
1506
|
"network.list-failed": "Docker networks could not be listed.",
|
|
1427
1507
|
"network.inspect-failed": "A Docker network could not be inspected.",
|
|
1428
1508
|
"stale-containers.removing": "Stale probe containers are being removed.",
|
|
1429
|
-
"stale-networks.removing": "Stale probe networks are being removed."
|
|
1509
|
+
"stale-networks.removing": "Stale probe networks are being removed.",
|
|
1510
|
+
"peers.refused": "The agent tools server closed connections from addresses outside loopback and this backend's Docker networks (at most one entry a minute, with a count).",
|
|
1511
|
+
"peers.subnets-loaded": "The Docker subnets the agent tools server admits were reloaded.",
|
|
1512
|
+
"port.loopback-taken": "The agent tools server gave up a port because another process holds it on 127.0.0.1, where host agents call; it moves to a free port.",
|
|
1513
|
+
"peers.subnets-load-failed": "The Docker subnets the agent tools server admits could not be read; cached permissions are cleared and only loopback is admitted until a successful retry."
|
|
1430
1514
|
}
|
|
1431
1515
|
}
|
|
1432
1516
|
});
|
|
@@ -2149,7 +2233,7 @@ var MAX_FRAME_CHARS = 240;
|
|
|
2149
2233
|
var MAX_RAW_FRAME_CHARS = 1024;
|
|
2150
2234
|
var MAX_CAUSE_DEPTH = 2;
|
|
2151
2235
|
var TRUNCATED_MARKER = "...[truncated]";
|
|
2152
|
-
var
|
|
2236
|
+
var NAME_PATTERN2 = /^[A-Za-z_$][\w$.-]{0,63}$/;
|
|
2153
2237
|
var CODE_PATTERN = /^[\w.:-]{1,64}$/;
|
|
2154
2238
|
var SYSCALL_PATTERN = /^[\w./ -]{1,128}$/;
|
|
2155
2239
|
var COMMAND_OUTPUT_FIELDS = ["stdout", "stderr", "cmd", "spawnargs"];
|
|
@@ -2227,7 +2311,7 @@ function describe(error, includeStack, includeMessage, depth) {
|
|
|
2227
2311
|
if (!(error instanceof Error) && typeof rawMessage !== "string") {
|
|
2228
2312
|
return { name: "NonError", message: "[object]" };
|
|
2229
2313
|
}
|
|
2230
|
-
const name = matching(read(error, "name"),
|
|
2314
|
+
const name = matching(read(error, "name"), NAME_PATTERN2) ?? "Error";
|
|
2231
2315
|
const message = typeof rawMessage === "string" ? rawMessage : undefined;
|
|
2232
2316
|
const commandFailure = isCommandFailure(error, name, message);
|
|
2233
2317
|
const stackHoldsMessage = message !== undefined && String(read(error, "stack") ?? "").includes(message);
|
|
@@ -2282,7 +2366,7 @@ function logErrorKind(error) {
|
|
|
2282
2366
|
const safeCode = finite(code) ?? matching(code, CODE_PATTERN);
|
|
2283
2367
|
if (safeCode !== undefined)
|
|
2284
2368
|
return String(safeCode);
|
|
2285
|
-
return matching(read(error, "name"),
|
|
2369
|
+
return matching(read(error, "name"), NAME_PATTERN2) ?? "Error";
|
|
2286
2370
|
}
|
|
2287
2371
|
|
|
2288
2372
|
// ../protocol/src/log-essential-labels.ts
|
|
@@ -8881,10 +8965,13 @@ function claudeMcpToolPrefix(name) {
|
|
|
8881
8965
|
}
|
|
8882
8966
|
|
|
8883
8967
|
// ../../bridges/claude-bridge/src/services/read-only-path-boundary.ts
|
|
8968
|
+
import { join as join6 } from "node:path";
|
|
8969
|
+
|
|
8970
|
+
// ../protocol/src/node/coordinator-read-boundary.ts
|
|
8884
8971
|
import { realpathSync } from "node:fs";
|
|
8885
8972
|
import { homedir as homedir2 } from "node:os";
|
|
8886
8973
|
import { dirname, isAbsolute as isAbsolute2, join as join5, parse, resolve as resolve2, sep } from "node:path";
|
|
8887
|
-
function
|
|
8974
|
+
function canonicalPath(path) {
|
|
8888
8975
|
let existing = path;
|
|
8889
8976
|
const tail = [];
|
|
8890
8977
|
for (;; ) {
|
|
@@ -8899,28 +8986,9 @@ function canonical(path) {
|
|
|
8899
8986
|
}
|
|
8900
8987
|
}
|
|
8901
8988
|
}
|
|
8902
|
-
function
|
|
8989
|
+
function namedAndCanonicalPaths(paths) {
|
|
8903
8990
|
const named = paths.flatMap((path) => path?.trim() && isAbsolute2(path) ? [path] : []);
|
|
8904
|
-
return [...new Set(named.flatMap((path) => [resolve2(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
|
-
};
|
|
8991
|
+
return [...new Set(named.flatMap((path) => [resolve2(path), canonicalPath(path)]))];
|
|
8924
8992
|
}
|
|
8925
8993
|
function isWithin(root, path) {
|
|
8926
8994
|
if (path === root)
|
|
@@ -8928,6 +8996,16 @@ function isWithin(root, path) {
|
|
|
8928
8996
|
const prefix = root === parse(root).root ? root : `${root}${sep}`;
|
|
8929
8997
|
return path.startsWith(prefix);
|
|
8930
8998
|
}
|
|
8999
|
+
function protectedDataDirBoundary(dataDir, allowances) {
|
|
9000
|
+
const trimmed = dataDir?.trim();
|
|
9001
|
+
if (!trimmed || !isAbsolute2(trimmed))
|
|
9002
|
+
return null;
|
|
9003
|
+
const deny = namedAndCanonicalPaths([trimmed]);
|
|
9004
|
+
return {
|
|
9005
|
+
deny,
|
|
9006
|
+
allow: namedAndCanonicalPaths(allowances).filter((path) => !deny.includes(path) && deny.some((root) => isWithin(root, path)))
|
|
9007
|
+
};
|
|
9008
|
+
}
|
|
8931
9009
|
function deniedForm(boundary, path) {
|
|
8932
9010
|
return boundary.deny.some((root) => isWithin(root, path)) && !boundary.allow.some((root) => isWithin(root, path));
|
|
8933
9011
|
}
|
|
@@ -8940,11 +9018,26 @@ function readBoundaryRefuses(boundary, path, cwd, options = {}) {
|
|
|
8940
9018
|
const expanded = expandedHome(path);
|
|
8941
9019
|
const raw = isAbsolute2(expanded) ? expanded : `${cwd}${sep}${expanded}`;
|
|
8942
9020
|
const lexical = resolve2(raw);
|
|
8943
|
-
const real =
|
|
9021
|
+
const real = canonicalPath(raw);
|
|
8944
9022
|
if (deniedForm(boundary, lexical) || deniedForm(boundary, real))
|
|
8945
9023
|
return true;
|
|
8946
9024
|
return options.traversal === true && boundary.deny.some((root) => isWithin(lexical, root) || isWithin(real, root));
|
|
8947
9025
|
}
|
|
9026
|
+
|
|
9027
|
+
// ../../bridges/claude-bridge/src/services/read-only-path-boundary.ts
|
|
9028
|
+
function claudeReadOnlyWorkspacePaths(cwd) {
|
|
9029
|
+
return [...new Set([cwd, canonicalPath(cwd)])];
|
|
9030
|
+
}
|
|
9031
|
+
function coordinatorReadBoundary(workspaces, env = process.env) {
|
|
9032
|
+
const dataDir = env[COORDINATOR_PROTECTED_DATA_DIR_ENV]?.trim();
|
|
9033
|
+
return protectedDataDirBoundary(dataDir, [
|
|
9034
|
+
env.CLAUDE_CONFIG_DIR,
|
|
9035
|
+
env.ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT,
|
|
9036
|
+
env[COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV],
|
|
9037
|
+
dataDir ? join6(dataDir, "toolchains") : undefined,
|
|
9038
|
+
...workspaces
|
|
9039
|
+
]);
|
|
9040
|
+
}
|
|
8948
9041
|
function globRoot(pattern) {
|
|
8949
9042
|
if (!pattern.startsWith("/") && !pattern.startsWith("~") && !pattern.startsWith("..")) {
|
|
8950
9043
|
return;
|
|
@@ -9628,8 +9721,8 @@ import { realpathSync as realpathSync2 } from "node:fs";
|
|
|
9628
9721
|
|
|
9629
9722
|
// ../protocol/src/node/claude-linux-sandbox.ts
|
|
9630
9723
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
9631
|
-
import { accessSync, constants, existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
9632
|
-
import { delimiter, join as
|
|
9724
|
+
import { accessSync, constants as constants2, existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
9725
|
+
import { delimiter, join as join7 } from "node:path";
|
|
9633
9726
|
var CLAUDE_LINUX_SANDBOX_PROGRAMS = Object.freeze(["bwrap", "socat"]);
|
|
9634
9727
|
var APPARMOR_BWRAP_PROFILE = "/etc/apparmor.d/bwrap-userns-restrict";
|
|
9635
9728
|
var CLAUDE_LINUX_SANDBOX_PROBE_TIMEOUT_MS = 5000;
|
|
@@ -9663,7 +9756,7 @@ function executableOnPath(name, path = process.env.PATH) {
|
|
|
9663
9756
|
if (!directory)
|
|
9664
9757
|
continue;
|
|
9665
9758
|
try {
|
|
9666
|
-
accessSync(
|
|
9759
|
+
accessSync(join7(directory, name), constants2.X_OK);
|
|
9667
9760
|
return true;
|
|
9668
9761
|
} catch {}
|
|
9669
9762
|
}
|
|
@@ -12625,9 +12718,9 @@ function noMessages() {
|
|
|
12625
12718
|
}
|
|
12626
12719
|
|
|
12627
12720
|
// ../../bridges/claude-bridge/src/services/session-manager-persistence.ts
|
|
12628
|
-
import { constants as
|
|
12721
|
+
import { constants as constants3 } from "node:fs";
|
|
12629
12722
|
import { lstat as lstat2, open as open2, realpath as realpath2 } from "node:fs/promises";
|
|
12630
|
-
import { isAbsolute as isAbsolute4, join as
|
|
12723
|
+
import { isAbsolute as isAbsolute4, join as join12, relative, resolve as resolve4, sep as sep2 } from "node:path";
|
|
12631
12724
|
|
|
12632
12725
|
// ../protocol/src/node/command-change-journal.ts
|
|
12633
12726
|
import { appendFile, mkdir as mkdir3, readFile as readFile5, rename as rename3, rm as rm3, stat as stat4, writeFile as writeFile3 } from "node:fs/promises";
|
|
@@ -12780,10 +12873,10 @@ async function readJournal(path, maxEntries) {
|
|
|
12780
12873
|
|
|
12781
12874
|
// ../protocol/src/node/workspace-change-probe.ts
|
|
12782
12875
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
12783
|
-
import { rmSync } from "node:fs";
|
|
12876
|
+
import { rmSync as rmSync2 } from "node:fs";
|
|
12784
12877
|
import { copyFile, lstat, mkdtemp as mkdtemp2, rm as rm4 } from "node:fs/promises";
|
|
12785
12878
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
12786
|
-
import { delimiter as delimiter2, isAbsolute as isAbsolute3, join as
|
|
12879
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute3, join as join8, resolve as resolve3 } from "node:path";
|
|
12787
12880
|
|
|
12788
12881
|
// ../protocol/src/node/command-capture.ts
|
|
12789
12882
|
import { spawn } from "node:child_process";
|
|
@@ -12993,6 +13086,7 @@ function classifyCommandFailure(error, options = {}) {
|
|
|
12993
13086
|
import { createRequire } from "node:module";
|
|
12994
13087
|
|
|
12995
13088
|
// ../protocol/src/node/shell-process-state.ts
|
|
13089
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
12996
13090
|
import { readdirSync, readFileSync as readFileSync3 } from "node:fs";
|
|
12997
13091
|
import { constants as osConstants } from "node:os";
|
|
12998
13092
|
var PROCESS_INSPECTION_OPTIONS = {
|
|
@@ -13062,8 +13156,11 @@ function linuxGroupHasLiveMember(pgid) {
|
|
|
13062
13156
|
return false;
|
|
13063
13157
|
}
|
|
13064
13158
|
function psGroupHasLiveMember(pgid) {
|
|
13065
|
-
const
|
|
13066
|
-
|
|
13159
|
+
const argv = ["-A", "-o", "pgid=,stat="];
|
|
13160
|
+
const bun = bunRuntime();
|
|
13161
|
+
const result = bun ? bun.spawnSync(["/bin/ps", ...argv], PROCESS_INSPECTION_OPTIONS) : spawnSync3("/bin/ps", argv, PROCESS_INSPECTION_OPTIONS);
|
|
13162
|
+
const succeeded = "success" in result ? result.success : result.status === 0 && !result.error;
|
|
13163
|
+
if (!succeeded)
|
|
13067
13164
|
return true;
|
|
13068
13165
|
return result.stdout.toString().split(`
|
|
13069
13166
|
`).some((line) => {
|
|
@@ -13425,6 +13522,7 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
|
|
|
13425
13522
|
let limitTimer;
|
|
13426
13523
|
let stopExitWatch = () => {};
|
|
13427
13524
|
let commandExit;
|
|
13525
|
+
let pendingFailure;
|
|
13428
13526
|
const finishCapture = () => {
|
|
13429
13527
|
settled = true;
|
|
13430
13528
|
clearTimeout(timeoutTimer);
|
|
@@ -13446,13 +13544,33 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
|
|
|
13446
13544
|
releaseCaptureFds();
|
|
13447
13545
|
}
|
|
13448
13546
|
};
|
|
13449
|
-
const
|
|
13450
|
-
if (settled)
|
|
13451
|
-
return;
|
|
13547
|
+
const rejectFailure = (error) => {
|
|
13452
13548
|
const output = finishCapture();
|
|
13453
13549
|
if (output)
|
|
13454
13550
|
reject(Object.assign(error, { ...output, killed: timedOut }));
|
|
13455
13551
|
};
|
|
13552
|
+
const awaitTermination = (delayMs) => {
|
|
13553
|
+
clearTimeout(groupTimer);
|
|
13554
|
+
if (settled)
|
|
13555
|
+
return;
|
|
13556
|
+
if ((commandExit || exitReported(child)) && !commandGroupAlive(child)) {
|
|
13557
|
+
rejectFailure(pendingFailure);
|
|
13558
|
+
return;
|
|
13559
|
+
}
|
|
13560
|
+
groupTimer = setTimeout(awaitTermination, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
|
|
13561
|
+
};
|
|
13562
|
+
const fail = (error) => {
|
|
13563
|
+
if (settled || pendingFailure)
|
|
13564
|
+
return;
|
|
13565
|
+
if (options.waitForTermination && child.pid !== undefined) {
|
|
13566
|
+
pendingFailure = error;
|
|
13567
|
+
signalCommand(child, "SIGKILL");
|
|
13568
|
+
clearTimeout(timeoutTimer);
|
|
13569
|
+
clearInterval(limitTimer);
|
|
13570
|
+
awaitTermination(COMMAND_GROUP_POLL_MS);
|
|
13571
|
+
} else
|
|
13572
|
+
rejectFailure(error);
|
|
13573
|
+
};
|
|
13456
13574
|
const abort = () => {
|
|
13457
13575
|
timedOut = true;
|
|
13458
13576
|
signalCommand(child, "SIGKILL");
|
|
@@ -13479,11 +13597,11 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
|
|
|
13479
13597
|
}
|
|
13480
13598
|
};
|
|
13481
13599
|
limitTimer = setInterval(() => {
|
|
13482
|
-
if (!settled && !timedOut)
|
|
13600
|
+
if (!settled && !timedOut && !pendingFailure)
|
|
13483
13601
|
failIfOverLimit();
|
|
13484
13602
|
}, COMMAND_OUTPUT_CHECK_MS);
|
|
13485
13603
|
const settleOnExit = () => {
|
|
13486
|
-
if (settled || timedOut || failIfOverLimit())
|
|
13604
|
+
if (settled || timedOut || pendingFailure || failIfOverLimit())
|
|
13487
13605
|
return;
|
|
13488
13606
|
if (commandExit?.code !== 0 || commandExit.signal !== null) {
|
|
13489
13607
|
fail(Object.assign(new Error(`Command failed: ${[command, ...args].join(" ")}`), {
|
|
@@ -13497,7 +13615,7 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
|
|
|
13497
13615
|
resolve(output);
|
|
13498
13616
|
};
|
|
13499
13617
|
const awaitGroupExit = (delayMs) => {
|
|
13500
|
-
if (settled || timedOut)
|
|
13618
|
+
if (settled || timedOut || pendingFailure)
|
|
13501
13619
|
return;
|
|
13502
13620
|
if (commandGroupAlive(child)) {
|
|
13503
13621
|
groupTimer = setTimeout(awaitGroupExit, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
|
|
@@ -13510,14 +13628,16 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
|
|
|
13510
13628
|
return;
|
|
13511
13629
|
commandExit = exit;
|
|
13512
13630
|
stopExitWatch();
|
|
13513
|
-
if (
|
|
13631
|
+
if (pendingFailure)
|
|
13632
|
+
awaitTermination(COMMAND_GROUP_POLL_MS);
|
|
13633
|
+
else if (options.waitForDescendants)
|
|
13514
13634
|
awaitGroupExit(COMMAND_GROUP_POLL_MS);
|
|
13515
13635
|
else
|
|
13516
13636
|
settleOnExit();
|
|
13517
13637
|
};
|
|
13518
13638
|
child.exited.then(onCommandExit, (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
13519
13639
|
stopExitWatch = watchForLostExit(child.pid, (exit) => {
|
|
13520
|
-
if (!settled
|
|
13640
|
+
if (!settled)
|
|
13521
13641
|
onCommandExit(exit);
|
|
13522
13642
|
});
|
|
13523
13643
|
if (timeoutMs > 0) {
|
|
@@ -13609,7 +13729,7 @@ var temporaryObjectDirectories = new Set;
|
|
|
13609
13729
|
process.once("exit", () => {
|
|
13610
13730
|
for (const directory of temporaryObjectDirectories) {
|
|
13611
13731
|
try {
|
|
13612
|
-
|
|
13732
|
+
rmSync2(directory, { recursive: true, force: true });
|
|
13613
13733
|
} catch {}
|
|
13614
13734
|
}
|
|
13615
13735
|
});
|
|
@@ -13910,8 +14030,8 @@ class WorkspaceChangeProbe {
|
|
|
13910
14030
|
return;
|
|
13911
14031
|
const { root, indexPath } = repo.location;
|
|
13912
14032
|
const started = this.now();
|
|
13913
|
-
const tempIndex =
|
|
13914
|
-
const objectDirectory = await mkdtemp2(
|
|
14033
|
+
const tempIndex = join8(this.tempDir, `orkestrator-probe-${randomUUID3()}.index`);
|
|
14034
|
+
const objectDirectory = await mkdtemp2(join8(this.tempDir, "orkestrator-probe-objects-"));
|
|
13915
14035
|
temporaryObjectDirectories.add(objectDirectory);
|
|
13916
14036
|
let retained = false;
|
|
13917
14037
|
try {
|
|
@@ -13928,7 +14048,7 @@ class WorkspaceChangeProbe {
|
|
|
13928
14048
|
const included = [];
|
|
13929
14049
|
const skipped = new Map;
|
|
13930
14050
|
for (const path of untracked) {
|
|
13931
|
-
const stats = await lstat(
|
|
14051
|
+
const stats = await lstat(join8(root, path)).catch(() => {
|
|
13932
14052
|
return;
|
|
13933
14053
|
});
|
|
13934
14054
|
if (!stats)
|
|
@@ -14074,20 +14194,20 @@ function parseNumstatZ(output) {
|
|
|
14074
14194
|
}
|
|
14075
14195
|
|
|
14076
14196
|
// ../../bridges/claude-bridge/src/services/command-changes.ts
|
|
14077
|
-
import { join as
|
|
14197
|
+
import { join as join11 } from "node:path";
|
|
14078
14198
|
|
|
14079
14199
|
// ../../bridges/claude-bridge/src/services/change-evidence.ts
|
|
14080
14200
|
import { createHash as createHash8 } from "node:crypto";
|
|
14081
14201
|
import {
|
|
14082
|
-
closeSync as
|
|
14202
|
+
closeSync as closeSync3,
|
|
14083
14203
|
existsSync as existsSync2,
|
|
14084
14204
|
mkdirSync,
|
|
14085
|
-
openSync as
|
|
14205
|
+
openSync as openSync3,
|
|
14086
14206
|
readFileSync as readFileSync5,
|
|
14087
|
-
rmSync as
|
|
14207
|
+
rmSync as rmSync3,
|
|
14088
14208
|
writeSync
|
|
14089
14209
|
} from "node:fs";
|
|
14090
|
-
import { join as
|
|
14210
|
+
import { join as join10 } from "node:path";
|
|
14091
14211
|
|
|
14092
14212
|
// ../protocol/src/field-validation.ts
|
|
14093
14213
|
function isPlainRecord(value) {
|
|
@@ -14493,7 +14613,7 @@ function workspaceObservationReportIssues(value) {
|
|
|
14493
14613
|
import { createHash as createHash7, randomUUID as randomUUID4 } from "node:crypto";
|
|
14494
14614
|
import { readdirSync as readdirSync2, readFileSync as readFileSync4 } from "node:fs";
|
|
14495
14615
|
import { appendFile as appendFile2, mkdir as mkdir4, rename as rename4, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
|
|
14496
|
-
import { join as
|
|
14616
|
+
import { join as join9 } from "node:path";
|
|
14497
14617
|
var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
|
|
14498
14618
|
maxEntries: 2048,
|
|
14499
14619
|
maxEntryBytes: 256 * 1024,
|
|
@@ -14756,7 +14876,7 @@ class ChangeEvidenceSpool {
|
|
|
14756
14876
|
const lines = this.pendingLines.splice(0).join("");
|
|
14757
14877
|
this.enqueueIo(async () => {
|
|
14758
14878
|
await mkdir4(directory, { recursive: true, mode: 448 });
|
|
14759
|
-
await appendFile2(
|
|
14879
|
+
await appendFile2(join9(directory, ENTRIES_FILE), lines, { mode: 384 });
|
|
14760
14880
|
});
|
|
14761
14881
|
}
|
|
14762
14882
|
persistBody(id, bytes) {
|
|
@@ -14764,9 +14884,9 @@ class ChangeEvidenceSpool {
|
|
|
14764
14884
|
if (!directory || this.restoring)
|
|
14765
14885
|
return;
|
|
14766
14886
|
this.enqueueIo(async () => {
|
|
14767
|
-
const bodies =
|
|
14887
|
+
const bodies = join9(directory, BODY_DIRECTORY);
|
|
14768
14888
|
await mkdir4(bodies, { recursive: true, mode: 448 });
|
|
14769
|
-
await writeFile4(
|
|
14889
|
+
await writeFile4(join9(bodies, bodyFileName(id)), bytes, { mode: 384, flag: "wx" }).catch((error) => {
|
|
14770
14890
|
if (error.code !== "EEXIST")
|
|
14771
14891
|
throw error;
|
|
14772
14892
|
});
|
|
@@ -14776,7 +14896,7 @@ class ChangeEvidenceSpool {
|
|
|
14776
14896
|
const directory = this.directory;
|
|
14777
14897
|
if (!directory)
|
|
14778
14898
|
return;
|
|
14779
|
-
this.enqueueIo(() => rm5(
|
|
14899
|
+
this.enqueueIo(() => rm5(join9(directory, BODY_DIRECTORY, bodyFileName(id)), { force: true }));
|
|
14780
14900
|
}
|
|
14781
14901
|
compactPersisted() {
|
|
14782
14902
|
const directory = this.directory;
|
|
@@ -14787,7 +14907,7 @@ class ChangeEvidenceSpool {
|
|
|
14787
14907
|
`);
|
|
14788
14908
|
this.enqueueIo(async () => {
|
|
14789
14909
|
await mkdir4(directory, { recursive: true, mode: 448 });
|
|
14790
|
-
const file =
|
|
14910
|
+
const file = join9(directory, ENTRIES_FILE);
|
|
14791
14911
|
const temp = `${file}.${process.pid}.tmp`;
|
|
14792
14912
|
await writeFile4(temp, body ? `${body}
|
|
14793
14913
|
` : "", { mode: 384 });
|
|
@@ -14799,10 +14919,10 @@ class ChangeEvidenceSpool {
|
|
|
14799
14919
|
await this.io;
|
|
14800
14920
|
}
|
|
14801
14921
|
restore(directory) {
|
|
14802
|
-
const bodyDirectory =
|
|
14922
|
+
const bodyDirectory = join9(directory, BODY_DIRECTORY);
|
|
14803
14923
|
try {
|
|
14804
14924
|
for (const name of readdirSync2(bodyDirectory)) {
|
|
14805
|
-
const bytes = new Uint8Array(readFileSync4(
|
|
14925
|
+
const bytes = new Uint8Array(readFileSync4(join9(bodyDirectory, name)));
|
|
14806
14926
|
const id = evidenceBodyId(bytes);
|
|
14807
14927
|
if (bodyFileName(id) !== name)
|
|
14808
14928
|
continue;
|
|
@@ -14814,7 +14934,7 @@ class ChangeEvidenceSpool {
|
|
|
14814
14934
|
} catch {}
|
|
14815
14935
|
let text = "";
|
|
14816
14936
|
try {
|
|
14817
|
-
text = readFileSync4(
|
|
14937
|
+
text = readFileSync4(join9(directory, ENTRIES_FILE), "utf8");
|
|
14818
14938
|
} catch {
|
|
14819
14939
|
return;
|
|
14820
14940
|
}
|
|
@@ -15326,15 +15446,15 @@ function createChangeEvidence(options) {
|
|
|
15326
15446
|
};
|
|
15327
15447
|
}
|
|
15328
15448
|
function claimSpoolDirectory(root = claudeChangeEvidenceDir(), scope = process.env.CWD || process.cwd()) {
|
|
15329
|
-
const directory =
|
|
15330
|
-
const owner =
|
|
15449
|
+
const directory = join10(root, createHash8("sha256").update(scope).digest("hex").slice(0, 32));
|
|
15450
|
+
const owner = join10(directory, "owner.pid");
|
|
15331
15451
|
try {
|
|
15332
15452
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
15333
15453
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
15334
15454
|
try {
|
|
15335
|
-
const fd =
|
|
15455
|
+
const fd = openSync3(owner, "wx", 384);
|
|
15336
15456
|
writeSync(fd, ownerFileContents());
|
|
15337
|
-
|
|
15457
|
+
closeSync3(fd);
|
|
15338
15458
|
return directory;
|
|
15339
15459
|
} catch (error) {
|
|
15340
15460
|
if (error.code !== "EEXIST")
|
|
@@ -15347,7 +15467,7 @@ function claimSpoolDirectory(root = claudeChangeEvidenceDir(), scope = process.e
|
|
|
15347
15467
|
if (state !== "dead")
|
|
15348
15468
|
return;
|
|
15349
15469
|
}
|
|
15350
|
-
|
|
15470
|
+
rmSync3(owner, { force: true });
|
|
15351
15471
|
}
|
|
15352
15472
|
}
|
|
15353
15473
|
} catch {}
|
|
@@ -15525,7 +15645,7 @@ function commandChangeJournal(sdkSessionId) {
|
|
|
15525
15645
|
if (journal) {
|
|
15526
15646
|
journals.delete(sdkSessionId);
|
|
15527
15647
|
} else {
|
|
15528
|
-
journal = new CommandChangeJournal(
|
|
15648
|
+
journal = new CommandChangeJournal(join11(claudeCommandChangesDir(), `${sdkSessionId}.jsonl`));
|
|
15529
15649
|
}
|
|
15530
15650
|
journals.set(sdkSessionId, journal);
|
|
15531
15651
|
while (journals.size > MAX_CACHED_JOURNALS) {
|
|
@@ -16318,7 +16438,7 @@ async function assertNoSymlinkComponents(lexicalRoot, targetPath) {
|
|
|
16318
16438
|
const childPath = relative(lexicalRoot, targetPath);
|
|
16319
16439
|
let currentPath = lexicalRoot;
|
|
16320
16440
|
for (const segment of childPath.split(sep2).filter(Boolean)) {
|
|
16321
|
-
currentPath =
|
|
16441
|
+
currentPath = join12(currentPath, segment);
|
|
16322
16442
|
const stats = await lstat2(currentPath).catch((error) => {
|
|
16323
16443
|
throw attachmentErrorForFsFailure(error);
|
|
16324
16444
|
});
|
|
@@ -16362,8 +16482,8 @@ async function readWorkspaceImageAttachment(filePath, cwd, afterSymlinkValidatio
|
|
|
16362
16482
|
throw new ClaudeAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace.");
|
|
16363
16483
|
}
|
|
16364
16484
|
await afterCanonicalValidation?.(targetPath);
|
|
16365
|
-
const noFollow =
|
|
16366
|
-
const handle = await open2(targetPath,
|
|
16485
|
+
const noFollow = constants3.O_NOFOLLOW ?? 0;
|
|
16486
|
+
const handle = await open2(targetPath, constants3.O_RDONLY | noFollow).catch((error) => {
|
|
16367
16487
|
throw attachmentErrorForFsFailure(error);
|
|
16368
16488
|
});
|
|
16369
16489
|
try {
|
|
@@ -17912,7 +18032,7 @@ import { query as query2 } from "@anthropic-ai/claude-agent-sdk";
|
|
|
17912
18032
|
|
|
17913
18033
|
// ../../bridges/claude-bridge/src/services/mcp-config.ts
|
|
17914
18034
|
import { createHash as createHash9 } from "node:crypto";
|
|
17915
|
-
import { join as
|
|
18035
|
+
import { join as join13 } from "node:path";
|
|
17916
18036
|
|
|
17917
18037
|
// ../protocol/src/agent-mail.ts
|
|
17918
18038
|
var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
|
|
@@ -18027,7 +18147,7 @@ async function loadGlobalMcpServers() {
|
|
|
18027
18147
|
return servers ?? {};
|
|
18028
18148
|
}
|
|
18029
18149
|
async function loadProjectMcpServers(cwd) {
|
|
18030
|
-
const servers = await readJsonSliceCached(
|
|
18150
|
+
const servers = await readJsonSliceCached(join13(cwd, ".mcp.json"), "mcpServers", (config) => config?.mcpServers);
|
|
18031
18151
|
return servers ?? {};
|
|
18032
18152
|
}
|
|
18033
18153
|
async function loadProjectOverridesFromGlobal2(cwd) {
|
|
@@ -18147,7 +18267,7 @@ async function loadScopedMcpServers(cwd, scope) {
|
|
|
18147
18267
|
const [global2, projectGlobal, projectLocal] = await Promise.all([
|
|
18148
18268
|
readJsonSliceCachedWithDigest(path, "mcpServers", (config) => config?.mcpServers),
|
|
18149
18269
|
scope === "all" ? readJsonSliceCachedWithDigest(path, `projects:${cwd}:mcpServers`, (config) => config?.projects?.[cwd]?.mcpServers) : null,
|
|
18150
|
-
scope === "all" ? readJsonSliceCachedWithDigest(
|
|
18270
|
+
scope === "all" ? readJsonSliceCachedWithDigest(join13(cwd, ".mcp.json"), "mcpServers", (config) => config?.mcpServers) : null
|
|
18151
18271
|
]);
|
|
18152
18272
|
const configs = {
|
|
18153
18273
|
...global2.value,
|
|
@@ -18232,7 +18352,7 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
18232
18352
|
|
|
18233
18353
|
// ../../bridges/claude-bridge/src/services/claude-model-catalog.ts
|
|
18234
18354
|
import { homedir as homedir3 } from "node:os";
|
|
18235
|
-
import { join as
|
|
18355
|
+
import { join as join14 } from "node:path";
|
|
18236
18356
|
import { stat as stat5 } from "node:fs/promises";
|
|
18237
18357
|
|
|
18238
18358
|
// ../../bridges/claude-bridge/src/services/live-claude-control.ts
|
|
@@ -18458,15 +18578,15 @@ function catalogModels(models) {
|
|
|
18458
18578
|
}));
|
|
18459
18579
|
}
|
|
18460
18580
|
async function claudeCliIdentity() {
|
|
18461
|
-
const configDir = process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
18581
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR?.trim() || join14(homedir3(), ".claude");
|
|
18462
18582
|
const executable = process.env.CLAUDE_CLI_PATH?.trim();
|
|
18463
18583
|
const resolved = executable ? Bun.which(executable, { PATH: process.env.PATH }) || executable : undefined;
|
|
18464
18584
|
const cwd = process.env.CWD || process.cwd();
|
|
18465
18585
|
const paths = [
|
|
18466
18586
|
resolved,
|
|
18467
|
-
|
|
18468
|
-
|
|
18469
|
-
|
|
18587
|
+
join14(configDir, "settings.json"),
|
|
18588
|
+
join14(cwd, ".claude/settings.json"),
|
|
18589
|
+
join14(cwd, ".claude/settings.local.json")
|
|
18470
18590
|
];
|
|
18471
18591
|
const files = await Promise.all(paths.map(async (path) => {
|
|
18472
18592
|
const file = path ? await stat5(path).catch(() => {
|
|
@@ -18913,7 +19033,7 @@ function idleSteerPromptReply(prompt, agentLabel) {
|
|
|
18913
19033
|
|
|
18914
19034
|
// ../../bridges/claude-bridge/src/services/claude-terminal-commands.ts
|
|
18915
19035
|
import { mkdir as mkdir5, readFile as readFile6, rename as rename5, writeFile as writeFile5 } from "node:fs/promises";
|
|
18916
|
-
import { join as
|
|
19036
|
+
import { join as join15 } from "node:path";
|
|
18917
19037
|
var FILE_NAME = "terminal-slash-commands.json";
|
|
18918
19038
|
var MAX_VERSIONS = 4;
|
|
18919
19039
|
var MAX_NAMES = 512;
|
|
@@ -18924,7 +19044,7 @@ var dirty = false;
|
|
|
18924
19044
|
var entries = [];
|
|
18925
19045
|
var writes = Promise.resolve();
|
|
18926
19046
|
function filePath() {
|
|
18927
|
-
return
|
|
19047
|
+
return join15(claudeOrkestratorDir(), FILE_NAME);
|
|
18928
19048
|
}
|
|
18929
19049
|
function validVersion(value) {
|
|
18930
19050
|
return typeof value === "string" && value.length > 0 && value.length <= MAX_VERSION_LENGTH;
|
|
@@ -20371,7 +20491,7 @@ function claudeArtifactServerTools(servers) {
|
|
|
20371
20491
|
|
|
20372
20492
|
// ../protocol/src/node/repository-instructions.ts
|
|
20373
20493
|
import { open as open3, realpath as realpath3 } from "node:fs/promises";
|
|
20374
|
-
import { join as
|
|
20494
|
+
import { join as join16, relative as relative2, isAbsolute as isAbsolute5 } from "node:path";
|
|
20375
20495
|
|
|
20376
20496
|
// ../protocol/src/rich-content-policy.ts
|
|
20377
20497
|
var KIB = 1024;
|
|
@@ -20570,7 +20690,7 @@ function repositoryInstructionsBlock(path, content, truncated) {
|
|
|
20570
20690
|
// ../protocol/src/node/repository-instructions.ts
|
|
20571
20691
|
var MAX_REPOSITORY_INSTRUCTIONS_BYTES = 256 * 1024;
|
|
20572
20692
|
async function readRepositoryInstructions(cwd, maxBytes = MAX_REPOSITORY_INSTRUCTIONS_BYTES) {
|
|
20573
|
-
const path =
|
|
20693
|
+
const path = join16(cwd, REPOSITORY_INSTRUCTIONS_FILE);
|
|
20574
20694
|
try {
|
|
20575
20695
|
const [root, target] = await Promise.all([realpath3(cwd), realpath3(path)]);
|
|
20576
20696
|
const inside = relative2(root, target);
|
|
@@ -23990,10 +24110,13 @@ function sessionRuntimeHealthBody(session) {
|
|
|
23990
24110
|
mcpConfigReporting: MCP_CONFIG_REPORTING_VERSION,
|
|
23991
24111
|
...session?.mcpConfigRevision ? { mcpConfig: structuredClone(session.mcpConfigRevision) } : {}
|
|
23992
24112
|
};
|
|
23993
|
-
if (!session
|
|
24113
|
+
if (!session)
|
|
23994
24114
|
return { ...emptyRuntimeHealth(), ...mcpConfig };
|
|
24115
|
+
const state = openClaudeRuntime(session) ? "attached" : "detached";
|
|
24116
|
+
if (!session.health)
|
|
24117
|
+
return { ...emptyRuntimeHealth(), summary: { state }, ...mcpConfig };
|
|
23995
24118
|
const { drift, notices } = session.health.snapshot();
|
|
23996
|
-
return { summary: drift ? { drift } : {}, notices, ...mcpConfig };
|
|
24119
|
+
return { summary: { state, ...drift ? { drift } : {} }, notices, ...mcpConfig };
|
|
23997
24120
|
}
|
|
23998
24121
|
|
|
23999
24122
|
// ../protocol/src/node/transcript-window.ts
|
|
@@ -26768,7 +26891,7 @@ var X_ALREADY_SENT = "x-hono-already-sent";
|
|
|
26768
26891
|
|
|
26769
26892
|
// ../../node_modules/.bun/@hono+node-server@2.1.5+c539cad7f494f5c9/node_modules/@hono/node-server/dist/index.mjs
|
|
26770
26893
|
import { STATUS_CODES, ServerResponse, createServer } from "node:http";
|
|
26771
|
-
import { Http2ServerRequest, constants as
|
|
26894
|
+
import { Http2ServerRequest, constants as constants4 } from "node:http2";
|
|
26772
26895
|
import { Readable } from "node:stream";
|
|
26773
26896
|
|
|
26774
26897
|
// ../../node_modules/.bun/hono@4.13.13/node_modules/hono/dist/helper/websocket/index.js
|
|
@@ -27687,7 +27810,7 @@ var drainIncoming = (incoming) => {
|
|
|
27687
27810
|
incomingWithDrainState[incomingDraining] = true;
|
|
27688
27811
|
if (incoming instanceof Http2ServerRequest) {
|
|
27689
27812
|
try {
|
|
27690
|
-
incoming.stream?.close?.(
|
|
27813
|
+
incoming.stream?.close?.(constants4.NGHTTP2_NO_ERROR);
|
|
27691
27814
|
} catch {}
|
|
27692
27815
|
return;
|
|
27693
27816
|
}
|
|
@@ -28248,34 +28371,219 @@ var serve = (options, listeningListener) => {
|
|
|
28248
28371
|
};
|
|
28249
28372
|
|
|
28250
28373
|
// ../protocol/src/node/bridge-credential.ts
|
|
28251
|
-
import { createHash as
|
|
28374
|
+
import { createHash as createHash14, randomBytes as randomBytes3, timingSafeEqual } from "node:crypto";
|
|
28252
28375
|
import { createRequire as createRequire2 } from "node:module";
|
|
28376
|
+
|
|
28377
|
+
// ../protocol/src/node/bridge-authority.ts
|
|
28378
|
+
import {
|
|
28379
|
+
createHash as createHash13,
|
|
28380
|
+
createPrivateKey,
|
|
28381
|
+
createPublicKey,
|
|
28382
|
+
generateKeyPairSync,
|
|
28383
|
+
randomBytes as randomBytes2,
|
|
28384
|
+
sign,
|
|
28385
|
+
verify
|
|
28386
|
+
} from "node:crypto";
|
|
28387
|
+
var BRIDGE_AUTHORITY_HEADER = "x-orkestrator-authority";
|
|
28388
|
+
var BRIDGE_AUTHORITY_REFUSED_CODE = "authority-signature-required";
|
|
28389
|
+
var BRIDGE_AUTHORITY_WINDOW_MS = 5 * 60000;
|
|
28390
|
+
var BRIDGE_AUTHORITY_MAX_NONCES = 8192;
|
|
28391
|
+
var BRIDGE_AUTHORITY_MAX_BODY_BYTES = 64 * 1024 * 1024;
|
|
28392
|
+
var SCHEME = "orkestrator-bridge-authority-v1";
|
|
28393
|
+
var KEY_PATTERN = /^[A-Za-z0-9_-]{40,200}$/;
|
|
28394
|
+
var HEADER_PATTERN = /^v1 t=(\d{1,16}) n=([A-Za-z0-9_-]{22}) s=([A-Za-z0-9_-]{86})$/;
|
|
28395
|
+
var READ_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
28396
|
+
var UNSIGNED_ROUTES = [
|
|
28397
|
+
/^\/session\/[^/]+\/close$/,
|
|
28398
|
+
/^\/sessions\/activity$/,
|
|
28399
|
+
/^\/debug\/log-policy$/
|
|
28400
|
+
];
|
|
28401
|
+
function bridgeAuthorityKeyEnv(tokenEnv) {
|
|
28402
|
+
return `${tokenEnv}_AUTHORITY_KEY`;
|
|
28403
|
+
}
|
|
28404
|
+
function isBridgeAuthorityKey(value) {
|
|
28405
|
+
return typeof value === "string" && KEY_PATTERN.test(value);
|
|
28406
|
+
}
|
|
28407
|
+
function publicKeyFrom(encoded) {
|
|
28408
|
+
if (!isBridgeAuthorityKey(encoded))
|
|
28409
|
+
return null;
|
|
28410
|
+
try {
|
|
28411
|
+
const key = createPublicKey({
|
|
28412
|
+
key: Buffer.from(encoded, "base64url"),
|
|
28413
|
+
format: "der",
|
|
28414
|
+
type: "spki"
|
|
28415
|
+
});
|
|
28416
|
+
return key.asymmetricKeyType === "ed25519" ? key : null;
|
|
28417
|
+
} catch {
|
|
28418
|
+
return null;
|
|
28419
|
+
}
|
|
28420
|
+
}
|
|
28421
|
+
function bridgeAuthorityTarget(url) {
|
|
28422
|
+
const parsed = new URL(url, "http://bridge.invalid");
|
|
28423
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
28424
|
+
}
|
|
28425
|
+
function bridgeRequestNeedsAuthority(method, target) {
|
|
28426
|
+
if (READ_METHODS.has(method.toUpperCase()))
|
|
28427
|
+
return false;
|
|
28428
|
+
const pathname = bridgeAuthorityTarget(target).split("?", 1)[0];
|
|
28429
|
+
return !UNSIGNED_ROUTES.some((pattern) => pattern.test(pathname));
|
|
28430
|
+
}
|
|
28431
|
+
function bodyDigest(body) {
|
|
28432
|
+
return createHash13("sha256").update(body ?? "").digest("hex");
|
|
28433
|
+
}
|
|
28434
|
+
function signedMessage(method, target, issuedAt, nonce, digest) {
|
|
28435
|
+
return Buffer.from([SCHEME, method.toUpperCase(), target, String(issuedAt), nonce, digest].join(`
|
|
28436
|
+
`));
|
|
28437
|
+
}
|
|
28438
|
+
var UNENFORCED = {
|
|
28439
|
+
enforced: false,
|
|
28440
|
+
requires: () => false,
|
|
28441
|
+
check: () => ({ ok: true })
|
|
28442
|
+
};
|
|
28443
|
+
function bridgeAuthorityFromPublicKey(publicKey, options = {}) {
|
|
28444
|
+
if (publicKey === undefined)
|
|
28445
|
+
return UNENFORCED;
|
|
28446
|
+
const key = publicKeyFrom(publicKey);
|
|
28447
|
+
const now = options.now ?? Date.now;
|
|
28448
|
+
const maxNonces = options.maxNonces ?? BRIDGE_AUTHORITY_MAX_NONCES;
|
|
28449
|
+
const seen = new Map;
|
|
28450
|
+
let floor = -Infinity;
|
|
28451
|
+
const remember = (nonce, issuedAt, current) => {
|
|
28452
|
+
for (const [oldNonce, oldIssuedAt] of seen) {
|
|
28453
|
+
if (seen.size < maxNonces && oldIssuedAt >= current - BRIDGE_AUTHORITY_WINDOW_MS)
|
|
28454
|
+
break;
|
|
28455
|
+
seen.delete(oldNonce);
|
|
28456
|
+
floor = Math.max(floor, oldIssuedAt);
|
|
28457
|
+
}
|
|
28458
|
+
seen.set(nonce, issuedAt);
|
|
28459
|
+
};
|
|
28460
|
+
return {
|
|
28461
|
+
enforced: true,
|
|
28462
|
+
requires: bridgeRequestNeedsAuthority,
|
|
28463
|
+
check(request) {
|
|
28464
|
+
if (!request.header)
|
|
28465
|
+
return { ok: false, reason: "missing" };
|
|
28466
|
+
const match = HEADER_PATTERN.exec(request.header.trim());
|
|
28467
|
+
if (!match)
|
|
28468
|
+
return { ok: false, reason: "malformed" };
|
|
28469
|
+
const issuedAt = Number(match[1]);
|
|
28470
|
+
const nonce = match[2];
|
|
28471
|
+
const current = now();
|
|
28472
|
+
if (Math.abs(current - issuedAt) > BRIDGE_AUTHORITY_WINDOW_MS || issuedAt <= floor) {
|
|
28473
|
+
return { ok: false, reason: "stale" };
|
|
28474
|
+
}
|
|
28475
|
+
if (!key)
|
|
28476
|
+
return { ok: false, reason: "invalid" };
|
|
28477
|
+
const valid = verify(null, signedMessage(request.method, bridgeAuthorityTarget(request.url), issuedAt, nonce, bodyDigest(request.body)), key, Buffer.from(match[3], "base64url"));
|
|
28478
|
+
if (!valid)
|
|
28479
|
+
return { ok: false, reason: "invalid" };
|
|
28480
|
+
if (seen.has(nonce))
|
|
28481
|
+
return { ok: false, reason: "replayed" };
|
|
28482
|
+
remember(nonce, issuedAt, current);
|
|
28483
|
+
return { ok: true };
|
|
28484
|
+
}
|
|
28485
|
+
};
|
|
28486
|
+
}
|
|
28487
|
+
function loadBridgeAuthority(tokenEnv, options = {}) {
|
|
28488
|
+
const env = options.env ?? process.env;
|
|
28489
|
+
const name = bridgeAuthorityKeyEnv(tokenEnv);
|
|
28490
|
+
const value = env[name]?.trim();
|
|
28491
|
+
delete env[name];
|
|
28492
|
+
return bridgeAuthorityFromPublicKey(value || undefined, { now: options.now });
|
|
28493
|
+
}
|
|
28494
|
+
function refusal(reason) {
|
|
28495
|
+
return {
|
|
28496
|
+
status: 403,
|
|
28497
|
+
body: {
|
|
28498
|
+
error: "This request changes an agent's authority and needs the backend's signature",
|
|
28499
|
+
code: BRIDGE_AUTHORITY_REFUSED_CODE,
|
|
28500
|
+
reason
|
|
28501
|
+
}
|
|
28502
|
+
};
|
|
28503
|
+
}
|
|
28504
|
+
var TOO_LARGE = {
|
|
28505
|
+
status: 413,
|
|
28506
|
+
body: { error: "Request body is too large" }
|
|
28507
|
+
};
|
|
28508
|
+
var admittedBodies = new WeakMap;
|
|
28509
|
+
async function readBounded(request, maxBodyBytes) {
|
|
28510
|
+
const declared = Number(request.headers.get("content-length") ?? NaN);
|
|
28511
|
+
if (Number.isFinite(declared) && declared > maxBodyBytes)
|
|
28512
|
+
return null;
|
|
28513
|
+
if (!request.body)
|
|
28514
|
+
return new Uint8Array;
|
|
28515
|
+
const reader = request.body.getReader();
|
|
28516
|
+
const chunks = [];
|
|
28517
|
+
let total = 0;
|
|
28518
|
+
for (;; ) {
|
|
28519
|
+
const { done, value } = await reader.read();
|
|
28520
|
+
if (done)
|
|
28521
|
+
break;
|
|
28522
|
+
total += value.byteLength;
|
|
28523
|
+
if (total > maxBodyBytes) {
|
|
28524
|
+
await reader.cancel().catch(() => {
|
|
28525
|
+
return;
|
|
28526
|
+
});
|
|
28527
|
+
return null;
|
|
28528
|
+
}
|
|
28529
|
+
chunks.push(value);
|
|
28530
|
+
}
|
|
28531
|
+
return Buffer.concat(chunks);
|
|
28532
|
+
}
|
|
28533
|
+
async function admitFetchBridgeRequest(authority, original, maxBodyBytes = BRIDGE_AUTHORITY_MAX_BODY_BYTES) {
|
|
28534
|
+
if (!authority.requires(original.method, original.url))
|
|
28535
|
+
return {};
|
|
28536
|
+
const header = original.headers.get(BRIDGE_AUTHORITY_HEADER);
|
|
28537
|
+
if (!header)
|
|
28538
|
+
return { refusal: refusal("missing") };
|
|
28539
|
+
const body = await readBounded(original, maxBodyBytes);
|
|
28540
|
+
if (!body)
|
|
28541
|
+
return { refusal: TOO_LARGE };
|
|
28542
|
+
const result = authority.check({ method: original.method, url: original.url, header, body });
|
|
28543
|
+
if (!result.ok)
|
|
28544
|
+
return { refusal: refusal(result.reason) };
|
|
28545
|
+
const headers = new Headers(original.headers);
|
|
28546
|
+
headers.set("content-length", String(body.byteLength));
|
|
28547
|
+
headers.delete("transfer-encoding");
|
|
28548
|
+
return {
|
|
28549
|
+
request: new Request(original.url, {
|
|
28550
|
+
method: original.method,
|
|
28551
|
+
headers,
|
|
28552
|
+
body: body.byteLength > 0 ? new Uint8Array(body) : undefined,
|
|
28553
|
+
signal: original.signal
|
|
28554
|
+
})
|
|
28555
|
+
};
|
|
28556
|
+
}
|
|
28557
|
+
|
|
28558
|
+
// ../protocol/src/node/bridge-credential.ts
|
|
28253
28559
|
var BRIDGE_TOKEN_PREFIX = "okb_";
|
|
28254
28560
|
var PR_SET_DUMPABLE = 4;
|
|
28255
28561
|
var VERIFIER_PATTERN = /^[0-9a-f]{64}$/;
|
|
28256
28562
|
var log27 = createLogger("bridge.lifecycle");
|
|
28257
28563
|
function mintBridgeToken() {
|
|
28258
|
-
return `${BRIDGE_TOKEN_PREFIX}${
|
|
28564
|
+
return `${BRIDGE_TOKEN_PREFIX}${randomBytes3(32).toString("base64url")}`;
|
|
28259
28565
|
}
|
|
28260
28566
|
function bridgeTokenVerifier(token) {
|
|
28261
|
-
return
|
|
28567
|
+
return createHash14("sha256").update(token).digest("hex");
|
|
28262
28568
|
}
|
|
28263
28569
|
function bridgeTokenVerifierEnv(tokenEnv) {
|
|
28264
28570
|
return `${tokenEnv}_SHA256`;
|
|
28265
28571
|
}
|
|
28266
|
-
function credentialFromVerifier(verifier, plainToken) {
|
|
28572
|
+
function credentialFromVerifier(verifier, plainToken, authority = UNENFORCED_AUTHORITY) {
|
|
28267
28573
|
const expected = Buffer.from(verifier, "hex");
|
|
28268
28574
|
return {
|
|
28269
28575
|
plainToken,
|
|
28576
|
+
authority,
|
|
28270
28577
|
matches(candidate) {
|
|
28271
28578
|
if (!candidate)
|
|
28272
28579
|
return false;
|
|
28273
|
-
return timingSafeEqual(expected,
|
|
28580
|
+
return timingSafeEqual(expected, createHash14("sha256").update(candidate).digest());
|
|
28274
28581
|
}
|
|
28275
28582
|
};
|
|
28276
28583
|
}
|
|
28277
|
-
|
|
28278
|
-
|
|
28584
|
+
var UNENFORCED_AUTHORITY = loadBridgeAuthority("", { env: {} });
|
|
28585
|
+
function bridgeCredentialFromToken(token, authority = UNENFORCED_AUTHORITY) {
|
|
28586
|
+
return credentialFromVerifier(bridgeTokenVerifier(token), token, authority);
|
|
28279
28587
|
}
|
|
28280
28588
|
function markProcessNonDumpable(loadFfi = () => createRequire2(import.meta.url)("bun:ffi")) {
|
|
28281
28589
|
if (process.platform !== "linux" || !process.versions.bun)
|
|
@@ -28307,11 +28615,12 @@ function loadBridgeCredential(tokenEnv, options = {}) {
|
|
|
28307
28615
|
const token = env[tokenEnv]?.trim();
|
|
28308
28616
|
delete env[verifierEnv];
|
|
28309
28617
|
delete env[tokenEnv];
|
|
28618
|
+
const authority = loadBridgeAuthority(tokenEnv, { env });
|
|
28310
28619
|
if (verifier) {
|
|
28311
28620
|
(options.harden ?? markProcessNonDumpable)();
|
|
28312
|
-
return VERIFIER_PATTERN.test(verifier) ? credentialFromVerifier(verifier, undefined) : bridgeCredentialFromToken(mintBridgeToken());
|
|
28621
|
+
return VERIFIER_PATTERN.test(verifier) ? credentialFromVerifier(verifier, undefined, authority) : bridgeCredentialFromToken(mintBridgeToken(), authority);
|
|
28313
28622
|
}
|
|
28314
|
-
return bridgeCredentialFromToken(token || mintBridgeToken());
|
|
28623
|
+
return bridgeCredentialFromToken(token || mintBridgeToken(), authority);
|
|
28315
28624
|
}
|
|
28316
28625
|
|
|
28317
28626
|
// ../../bridges/claude-bridge/src/index.ts
|
|
@@ -28386,6 +28695,12 @@ app.use("*", async (c, next) => {
|
|
|
28386
28695
|
if (!tokenMatches(dedicatedHeaderToken) && !tokenMatches(headerToken) && !tokenMatches(eventToken)) {
|
|
28387
28696
|
return c.json({ error: "Unauthorized" }, 401);
|
|
28388
28697
|
}
|
|
28698
|
+
const admission = await admitFetchBridgeRequest(bridgeCredential.authority, c.req.raw);
|
|
28699
|
+
if ("refusal" in admission) {
|
|
28700
|
+
return c.json(admission.refusal.body, admission.refusal.status);
|
|
28701
|
+
}
|
|
28702
|
+
if (admission.request)
|
|
28703
|
+
c.req.raw = admission.request;
|
|
28389
28704
|
}
|
|
28390
28705
|
await next();
|
|
28391
28706
|
});
|