orkestrator 2.37.5-beta → 2.37.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/artifact-runtime/preview-worker.js +70 -0
- package/dist/artifact-runtime/worker-context/preview-worker.mjs +70 -0
- package/dist/client.js +22 -5
- package/dist/main.js +3759 -2254
- package/package.json +3 -3
- package/resources/acp-bridge/dist/index.js +21 -4
- package/resources/claude-bridge/dist/index.js +1475 -1320
- package/resources/codex-bridge/dist/index.js +24 -5
- package/resources/cursor-bridge/dist/index.js +21 -4
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +26 -5
- package/resources/pi-bridge/runtime/install.json +1 -1
|
@@ -263,6 +263,7 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
|
|
|
263
263
|
"question.answers-received": "A parked question received its answers.",
|
|
264
264
|
"question.stale": "An answer arrived for a question no longer pending; the route answered stale.",
|
|
265
265
|
"question.wait-failed": "A parked question ended without an answer: cancelled, timed out or closed.",
|
|
266
|
+
"read-only-connection.bedrock-withheld": "A read-only turn did not take the user settings' Bedrock connection: it names no bearer token or static key pair, so the CLI would resolve AWS profiles, whose credential_process runs outside the read-only boundary.",
|
|
266
267
|
"runtime.ended-under-resumed-turn": "The Claude runtime ended while a resumed root turn was still open.",
|
|
267
268
|
"server.listening": "The HTTP server is listening.",
|
|
268
269
|
"server.starting": "The HTTP server is about to bind.",
|
|
@@ -892,6 +893,7 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
892
893
|
description: "The OpenCode 2.x provider: its event monitor, steering, routing, host and container servers.",
|
|
893
894
|
events: {
|
|
894
895
|
"events.dropped": "The 2.x event stream ended or failed, so reads go to the server until it reconnects. Error class only.",
|
|
896
|
+
"monitor.silent": "The 2.x event stream sent a heartbeat and then went quiet, so it is replaced. `silenceMs` only.",
|
|
895
897
|
"steer.unconfirmed": "A 2.x steer got no definite answer, so its delivery is reconciled from history. Error class only.",
|
|
896
898
|
"provider.dispose-failed": "Disposing the 2.x provider of a replaced server failed. Error class only.",
|
|
897
899
|
"transcript.unknown-row": "A 2.x history row of a kind the transcript does not know was dropped (a newer server). Its kind name only, once per kind.",
|
|
@@ -957,7 +959,7 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
957
959
|
description: "This process's event loop. A stall of 10 seconds or more is written at error, so no level hides it.",
|
|
958
960
|
events: {
|
|
959
961
|
stalled: {
|
|
960
|
-
description: "A timer fired late, so every request in that window waited. In the backend the line also names what ran: `storageMs` and the `storage*` fields describe the slow SQLite calls in the window (`operation.slow` in `storage`), `commandsInFlight` and `commands` the commands running, `blockingCommand` one whose synchronous part overlapped it, and `jobsInWindow` and `jobs` the recurring jobs that ran around it. `cpuMs` is the CPU time the process used in the window: near `lagMs` its own thread was busy, far below it the thread waited.",
|
|
962
|
+
description: "A timer fired late, so every request in that window waited. In the backend the line also names what ran: `storageMs` and the `storage*` fields describe the slow SQLite calls in the window (`operation.slow` in `storage`), `storageCalls` and `storageCallMs` every SQLite call that ended in it, slow or not (`storageMainCallMs` and `storageLedgerCallMs` per database), `commandsInFlight` and `commands` the commands running, `blockingCommand` one whose synchronous part overlapped it, and `jobsInWindow` and `jobs` the recurring jobs that ran around it. `cpuMs` is the CPU time the process used in the window: near `lagMs` its own thread was busy, far below it the thread waited.",
|
|
961
963
|
essential: true,
|
|
962
964
|
minLevel: "error",
|
|
963
965
|
fields: {
|
|
@@ -970,6 +972,10 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
970
972
|
storageTable: "label",
|
|
971
973
|
storageLongestMs: "number",
|
|
972
974
|
storageBusy: "boolean",
|
|
975
|
+
storageCalls: "number",
|
|
976
|
+
storageCallMs: "number",
|
|
977
|
+
storageMainCallMs: "number",
|
|
978
|
+
storageLedgerCallMs: "number",
|
|
973
979
|
commandsInFlight: "number",
|
|
974
980
|
blockingCommandMs: "number",
|
|
975
981
|
jobsInWindow: "number"
|
|
@@ -1274,7 +1280,6 @@ var STORAGE_LOG_AREAS = defineLogAreas({
|
|
|
1274
1280
|
"native-session-owners.backfill-failed": "Native-session rows could not be given their environment as owner at open; an environment delete then parses those rows instead, and the next open retries.",
|
|
1275
1281
|
"lease.timed-out": "A waiter gave up on a lease; `lease` and `family` name it, `holderAgeMs` is the time since its holder's last heartbeat (null when the holder had just gone), `waitedMs` how long the waiter waited.",
|
|
1276
1282
|
"lease.heartbeat-failed": "A held lease's heartbeat failed, which shortens the lease; the next one retries.",
|
|
1277
|
-
"scrub.vacuum-failed": "Deleted-content page reclamation failed; the checkpoint is attempted independently.",
|
|
1278
1283
|
"scrub.checkpoint-failed": "Deleted content could not be scrubbed from the WAL yet because the truncating checkpoint failed or a reader held an older snapshot; it is retried without waiting until it succeeds.",
|
|
1279
1284
|
"upkeep.vacuum-failed": "Periodic page reclamation failed; the next upkeep pass retries.",
|
|
1280
1285
|
"upkeep.finished": "One periodic upkeep pass ended: `optimizeMs` is how long refreshing planner statistics held the event loop, `released` and `left` the free pages returned and still free, `releaseMs` the release child's run and `stop` why it ended (`done`, `budget`, `busy`, `no-progress`, `slow-step`, `not-incremental`, `no-free-pages`, `failed`).",
|
|
@@ -1462,7 +1467,17 @@ var REVIEW_LOG_AREAS = defineLogAreas({
|
|
|
1462
1467
|
"fix-outcome.read-failed": "Reading an interactive fix's outcome failed; it stays pending.",
|
|
1463
1468
|
"fix-usage.read-failed": "Reading an Address Findings session's token usage failed.",
|
|
1464
1469
|
"result.consume-deferred": "Consuming a workflow result failed; it stays staged and is retried.",
|
|
1465
|
-
"failure-triage.failed": "Classifying a review package's failing tests failed; the package is sealed without the triage and says so."
|
|
1470
|
+
"failure-triage.failed": "Classifying a review package's failing tests failed; the package is sealed without the triage and says so.",
|
|
1471
|
+
"consolidation.budget-exceeded": {
|
|
1472
|
+
description: "A panel's reports did not fit one consolidation turn even after optional prose was removed, so consolidation failed before dispatch. Counts only.",
|
|
1473
|
+
essential: true,
|
|
1474
|
+
fields: {
|
|
1475
|
+
reviewers: "number",
|
|
1476
|
+
sourceFindings: "number",
|
|
1477
|
+
compactBytes: "number",
|
|
1478
|
+
maxBytes: "number"
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1466
1481
|
}
|
|
1467
1482
|
},
|
|
1468
1483
|
"pull-request": {
|
|
@@ -1558,6 +1573,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1558
1573
|
"opencode.listener-replaced": "The process on a container's OpenCode port (`provider`: `opencode` or `opencode2`) is not the server the backend launched and recorded, so its password was withheld and the next start replaces it. `stage` is `request` when the re-check after a refused connection or an unexpected answer found it; that connection then sends nothing more.",
|
|
1559
1574
|
"opencode.project-config-too-large": "A checkout's opencode.json or opencode.jsonc was larger than the limit, so a launched OpenCode server does not read it. File name only.",
|
|
1560
1575
|
"opencode.project-config-filtered": "Values were left out of a checkout's OpenCode configuration before a launched server reads it: counts of plugin keys, `{env:}` and `{file:}` references and dropped instructions (including separate instructionGlob and instructionUrl counts), and the names of files that were not a JSONC object. Never values.",
|
|
1576
|
+
"daemon.rootless-live-restore": "The Docker daemon is rootless and has live-restore on, which a rootless restart cannot honour: the new daemon reports every container exited while the old containers' processes keep running with no network, so turn live-restore off in its daemon.json. Written once per backend.",
|
|
1561
1577
|
"log-driver.unbounded": "The Docker daemon offers neither the local nor the json-file log driver, so new containers keep its default driver, whose log may be uncapped. Written once per backend.",
|
|
1562
1578
|
"lifecycle-event.reconcile-failed": "Reconciling an environment after a container start or stop event failed; the next status read retries.",
|
|
1563
1579
|
"login-keeper.pass-failed": "A Claude login keeper pass failed; the next interval retries.",
|
|
@@ -1571,7 +1587,8 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1571
1587
|
"recovery.clear-terminals-failed": "Terminal sessions could not be cleared after a recovery restore.",
|
|
1572
1588
|
"github-ranges.seed-not-copied": "The GitHub ranges seed could not be copied into a container, so its firewall fetches them.",
|
|
1573
1589
|
"availability.probe-failed": "Docker is not available; written when the diagnostic changes. Fixed-shape metadata only: messages can hold daemon endpoints.",
|
|
1574
|
-
"start.port-collision-retrying": "An automatic host port collided on start, so it is retried
|
|
1590
|
+
"start.port-collision-retrying": "An automatic host port collided on start, so it is retried (up to three times): with fresh ports, or, when `backendChosen`, on the same backend-chosen port after a pause.",
|
|
1591
|
+
"host-ports.owned-list-failed": "Docker could not list the host ports the backend chose for this owner's other containers, so a new rootless container's ports were chosen avoiding only this process's recent choices.",
|
|
1575
1592
|
"writer-lease.lost": {
|
|
1576
1593
|
description: "This backend lost the registry writer lease, for the fixed `reason` given. Schedules stop and container changes are refused until it restarts.",
|
|
1577
1594
|
essential: true,
|
|
@@ -8760,20 +8777,177 @@ function withReadOnlyGitConfig(turnPolicy, environment) {
|
|
|
8760
8777
|
return next;
|
|
8761
8778
|
}
|
|
8762
8779
|
|
|
8763
|
-
// ../../bridges/claude-bridge/src/services/
|
|
8764
|
-
import { createHash as createHash4
|
|
8765
|
-
import {
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8780
|
+
// ../../bridges/claude-bridge/src/services/json-file-cache.ts
|
|
8781
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
8782
|
+
import { readFile as readFile3, stat as stat2 } from "node:fs/promises";
|
|
8783
|
+
var SEPARATOR = "\x00";
|
|
8784
|
+
var slices = new Map;
|
|
8785
|
+
var readCohorts = new Map;
|
|
8786
|
+
var parseCounts = new Map;
|
|
8787
|
+
var beforeStatForTesting = null;
|
|
8788
|
+
function fingerprintOf(stats) {
|
|
8789
|
+
return `${stats.dev}:${stats.ino}:${stats.size}:${stats.mtimeMs}`;
|
|
8790
|
+
}
|
|
8791
|
+
function forgetFile(filePath) {
|
|
8792
|
+
const prefix = `${filePath}${SEPARATOR}`;
|
|
8793
|
+
for (const key of slices.keys()) {
|
|
8794
|
+
if (key.startsWith(prefix))
|
|
8795
|
+
slices.delete(key);
|
|
8796
|
+
}
|
|
8797
|
+
}
|
|
8798
|
+
function joinReadCohort(filePath) {
|
|
8799
|
+
const existing = readCohorts.get(filePath);
|
|
8800
|
+
if (existing) {
|
|
8801
|
+
existing.readers += 1;
|
|
8802
|
+
return existing;
|
|
8803
|
+
}
|
|
8804
|
+
const cohort = { readers: 1, parses: new Map };
|
|
8805
|
+
readCohorts.set(filePath, cohort);
|
|
8806
|
+
return cohort;
|
|
8807
|
+
}
|
|
8808
|
+
function leaveReadCohort(filePath, cohort) {
|
|
8809
|
+
cohort.readers -= 1;
|
|
8810
|
+
if (cohort.readers === 0 && readCohorts.get(filePath) === cohort) {
|
|
8811
|
+
readCohorts.delete(filePath);
|
|
8812
|
+
}
|
|
8813
|
+
}
|
|
8814
|
+
function parseOnce(filePath, fingerprint, cohort) {
|
|
8815
|
+
const existing = cohort.parses.get(fingerprint);
|
|
8816
|
+
if (existing)
|
|
8817
|
+
return existing;
|
|
8818
|
+
const parse = (async () => {
|
|
8819
|
+
parseCounts.set(filePath, (parseCounts.get(filePath) ?? 0) + 1);
|
|
8820
|
+
let bytes;
|
|
8821
|
+
try {
|
|
8822
|
+
bytes = await readFile3(filePath);
|
|
8823
|
+
} catch {
|
|
8824
|
+
return { parsed: null, digest: null };
|
|
8825
|
+
}
|
|
8826
|
+
const digest = createHash4("sha256").update(bytes).digest("base64url");
|
|
8827
|
+
try {
|
|
8828
|
+
return { parsed: JSON.parse(bytes.toString("utf-8")), digest };
|
|
8829
|
+
} catch {
|
|
8830
|
+
return { parsed: null, digest };
|
|
8831
|
+
}
|
|
8832
|
+
})();
|
|
8833
|
+
cohort.parses.set(fingerprint, parse);
|
|
8834
|
+
return parse;
|
|
8835
|
+
}
|
|
8836
|
+
async function readJsonSliceCached(filePath, sliceKey, select) {
|
|
8837
|
+
return (await readJsonSliceCachedWithDigest(filePath, sliceKey, select)).value;
|
|
8838
|
+
}
|
|
8839
|
+
async function readJsonSliceCachedWithDigest(filePath, sliceKey, select) {
|
|
8840
|
+
const cohort = joinReadCohort(filePath);
|
|
8841
|
+
try {
|
|
8842
|
+
await beforeStatForTesting?.(filePath);
|
|
8843
|
+
let fingerprint;
|
|
8844
|
+
try {
|
|
8845
|
+
fingerprint = fingerprintOf(await stat2(filePath));
|
|
8846
|
+
} catch {
|
|
8847
|
+
forgetFile(filePath);
|
|
8848
|
+
return { value: null, digest: null };
|
|
8849
|
+
}
|
|
8850
|
+
const key = `${filePath}${SEPARATOR}${sliceKey}`;
|
|
8851
|
+
const cached = slices.get(key);
|
|
8852
|
+
if (cached && cached.fingerprint === fingerprint) {
|
|
8853
|
+
return { value: cached.value, digest: cached.digest };
|
|
8854
|
+
}
|
|
8855
|
+
const { parsed, digest } = await parseOnce(filePath, fingerprint, cohort);
|
|
8856
|
+
let value = null;
|
|
8857
|
+
if (parsed !== null && parsed !== undefined) {
|
|
8858
|
+
try {
|
|
8859
|
+
value = select(parsed) ?? null;
|
|
8860
|
+
} catch {
|
|
8861
|
+
value = null;
|
|
8862
|
+
}
|
|
8863
|
+
}
|
|
8864
|
+
slices.set(key, { fingerprint, value, digest });
|
|
8865
|
+
return { value, digest };
|
|
8866
|
+
} finally {
|
|
8867
|
+
leaveReadCohort(filePath, cohort);
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8870
|
+
|
|
8871
|
+
// ../protocol/src/coordinator-web-research.ts
|
|
8872
|
+
var COORDINATOR_WEB_RESEARCH_MODES = ["off", "search", "search-and-mcp"];
|
|
8873
|
+
var DEFAULT_COORDINATOR_RESEARCH_MCP_SERVERS = Object.freeze([{ name: "context7", url: "https://mcp.context7.com/mcp" }]);
|
|
8874
|
+
var MAX_COORDINATOR_RESEARCH_MCP_SERVERS = 8;
|
|
8875
|
+
var COORDINATOR_WEB_RESEARCH_ENV = "ORKESTRATOR_COORDINATOR_WEB_RESEARCH";
|
|
8876
|
+
var COORDINATOR_RESEARCH_MCP_ENV = "ORKESTRATOR_COORDINATOR_RESEARCH_MCP";
|
|
8877
|
+
var RESERVED_SERVER_NAME = /^orkestrator/;
|
|
8878
|
+
var SERVER_NAME = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
8879
|
+
function isCoordinatorWebResearch(value) {
|
|
8880
|
+
return typeof value === "string" && COORDINATOR_WEB_RESEARCH_MODES.includes(value);
|
|
8881
|
+
}
|
|
8882
|
+
function coordinatorResearchMcpServerProblem(server) {
|
|
8883
|
+
if (!SERVER_NAME.test(server.name)) {
|
|
8884
|
+
return "Use 1 to 32 lowercase letters, digits or hyphens for the name.";
|
|
8885
|
+
}
|
|
8886
|
+
if (RESERVED_SERVER_NAME.test(server.name))
|
|
8887
|
+
return "Names starting with orkestrator are reserved.";
|
|
8888
|
+
let url;
|
|
8889
|
+
try {
|
|
8890
|
+
url = new URL(server.url);
|
|
8891
|
+
} catch {
|
|
8892
|
+
return "The URL is not valid.";
|
|
8893
|
+
}
|
|
8894
|
+
if (url.protocol !== "https:")
|
|
8895
|
+
return "Only https:// research servers are allowed.";
|
|
8896
|
+
if (url.username || url.password)
|
|
8897
|
+
return "Credentials in the URL are not allowed.";
|
|
8898
|
+
return;
|
|
8899
|
+
}
|
|
8900
|
+
function normalizeCoordinatorResearchMcpServers(value) {
|
|
8901
|
+
if (value === undefined)
|
|
8902
|
+
return DEFAULT_COORDINATOR_RESEARCH_MCP_SERVERS.map((s) => ({ ...s }));
|
|
8903
|
+
if (!Array.isArray(value))
|
|
8904
|
+
return [];
|
|
8905
|
+
const servers = [];
|
|
8906
|
+
const names = new Set;
|
|
8907
|
+
for (const entry of value) {
|
|
8908
|
+
if (servers.length >= MAX_COORDINATOR_RESEARCH_MCP_SERVERS)
|
|
8909
|
+
break;
|
|
8910
|
+
if (!entry || typeof entry !== "object")
|
|
8911
|
+
continue;
|
|
8912
|
+
const { name, url } = entry;
|
|
8913
|
+
if (typeof name !== "string" || typeof url !== "string")
|
|
8914
|
+
continue;
|
|
8915
|
+
const server = { name: name.trim(), url: url.trim() };
|
|
8916
|
+
if (coordinatorResearchMcpServerProblem(server) || names.has(server.name))
|
|
8917
|
+
continue;
|
|
8918
|
+
names.add(server.name);
|
|
8919
|
+
servers.push(server);
|
|
8920
|
+
}
|
|
8921
|
+
return servers;
|
|
8922
|
+
}
|
|
8923
|
+
function coordinatorWebResearchFromEnv(env) {
|
|
8924
|
+
const value = env[COORDINATOR_WEB_RESEARCH_ENV];
|
|
8925
|
+
return isCoordinatorWebResearch(value) ? value : "off";
|
|
8926
|
+
}
|
|
8927
|
+
function coordinatorResearchMcpServersFromEnv(env) {
|
|
8928
|
+
if (coordinatorWebResearchFromEnv(env) !== "search-and-mcp")
|
|
8929
|
+
return [];
|
|
8930
|
+
const raw = env[COORDINATOR_RESEARCH_MCP_ENV];
|
|
8931
|
+
if (!raw)
|
|
8932
|
+
return [];
|
|
8933
|
+
try {
|
|
8934
|
+
return normalizeCoordinatorResearchMcpServers(JSON.parse(raw));
|
|
8935
|
+
} catch {
|
|
8936
|
+
return [];
|
|
8937
|
+
}
|
|
8938
|
+
}
|
|
8939
|
+
var COORDINATOR_DENIED = Object.freeze([
|
|
8940
|
+
"file.write",
|
|
8941
|
+
"file.patch",
|
|
8942
|
+
"shell.mutate",
|
|
8943
|
+
"network"
|
|
8944
|
+
]);
|
|
8945
|
+
function coordinatorCapabilityPolicy(mode) {
|
|
8946
|
+
return {
|
|
8947
|
+
deny: [...COORDINATOR_DENIED],
|
|
8948
|
+
...mode === "off" ? {} : { allow: ["web.search"] }
|
|
8949
|
+
};
|
|
8950
|
+
}
|
|
8777
8951
|
// ../protocol/src/coordinator.ts
|
|
8778
8952
|
var COORDINATOR_COMMAND_SANDBOX_ENV = "ORKESTRATOR_COORDINATOR_COMMAND_SANDBOX";
|
|
8779
8953
|
var COORDINATOR_PROTECTED_DATA_DIR_ENV = "ORKESTRATOR_COORDINATOR_PROTECTED_DATA_DIR";
|
|
@@ -8874,1285 +9048,1256 @@ var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
|
8874
9048
|
]);
|
|
8875
9049
|
var COORDINATOR_PROJECT_HOME_MESSAGE_WINDOW_MS = 3 * 60 * 60000;
|
|
8876
9050
|
|
|
8877
|
-
// ../../bridges/claude-bridge/src/services/
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
"
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
"disable-model-invocation",
|
|
8885
|
-
"user-invocable",
|
|
8886
|
-
"version"
|
|
8887
|
-
]);
|
|
8888
|
-
var MIRROR_FORMAT = 1;
|
|
8889
|
-
var MAX_SKILLS_PER_SOURCE = 256;
|
|
8890
|
-
var MAX_SKILL_FILE_BYTES = 1024 * 1024;
|
|
8891
|
-
var MAX_ENTRIES_PER_SKILL = 256;
|
|
8892
|
-
var KEPT_OLD_MIRRORS = 4;
|
|
8893
|
-
var SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
8894
|
-
var FRONTMATTER = /^?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
8895
|
-
function coordinatorSkillSources(cwd, env = process.env) {
|
|
8896
|
-
const userDir = env[COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV]?.trim();
|
|
8897
|
-
return [
|
|
8898
|
-
...userDir && isAbsolute(userDir) ? [{ plugin: "user-skills", dir: userDir }] : [],
|
|
8899
|
-
{ plugin: "project-skills", dir: join3(cwd, ".claude", "skills") }
|
|
8900
|
-
];
|
|
9051
|
+
// ../../bridges/claude-bridge/src/services/mcp-tool-prefix.ts
|
|
9052
|
+
function claudeMcpToolPrefix(name) {
|
|
9053
|
+
let normalized = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
9054
|
+
if (name.startsWith("claude.ai ")) {
|
|
9055
|
+
normalized = normalized.replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
9056
|
+
}
|
|
9057
|
+
return `mcp__${normalized}__`;
|
|
8901
9058
|
}
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
9059
|
+
|
|
9060
|
+
// ../../bridges/claude-bridge/src/services/read-only-path-boundary.ts
|
|
9061
|
+
import { join as join4 } from "node:path";
|
|
9062
|
+
|
|
9063
|
+
// ../protocol/src/node/coordinator-read-boundary.ts
|
|
9064
|
+
import { realpathSync } from "node:fs";
|
|
9065
|
+
import { homedir as homedir2 } from "node:os";
|
|
9066
|
+
import { dirname as dirname2, isAbsolute, join as join3, parse, resolve as resolve2, sep } from "node:path";
|
|
9067
|
+
function canonicalPath(path) {
|
|
9068
|
+
let existing = path;
|
|
9069
|
+
const tail = [];
|
|
9070
|
+
for (;; ) {
|
|
8906
9071
|
try {
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
plugin: source.plugin,
|
|
8915
|
-
error: error instanceof Error ? error.message : String(error)
|
|
8916
|
-
});
|
|
9072
|
+
return join3(realpathSync.native(existing), ...tail.reverse());
|
|
9073
|
+
} catch {
|
|
9074
|
+
const parent = dirname2(existing);
|
|
9075
|
+
if (parent === existing)
|
|
9076
|
+
return path;
|
|
9077
|
+
tail.push(existing.slice(parent.length).replace(/^[/\\]+/, ""));
|
|
9078
|
+
existing = parent;
|
|
8917
9079
|
}
|
|
8918
9080
|
}
|
|
8919
|
-
return { plugins, skills };
|
|
8920
9081
|
}
|
|
8921
|
-
|
|
8922
|
-
const
|
|
8923
|
-
|
|
8924
|
-
});
|
|
8925
|
-
if (!dir)
|
|
8926
|
-
return;
|
|
8927
|
-
const skills = await readSkills(dir);
|
|
8928
|
-
if (skills.length === 0)
|
|
8929
|
-
return;
|
|
8930
|
-
const digest = createHash4("sha256").update(JSON.stringify([MIRROR_FORMAT, source.plugin, dir, skills])).digest("hex").slice(0, 24);
|
|
8931
|
-
const path = join3(root, `${source.plugin}-${digest}`);
|
|
8932
|
-
if (!await isMirror(path))
|
|
8933
|
-
await writeMirror(root, path, source.plugin, skills);
|
|
8934
|
-
await pruneOldMirrors(root, source.plugin, path);
|
|
8935
|
-
return { path, names: skills.map((skill) => skill.name) };
|
|
9082
|
+
function namedAndCanonicalPaths(paths) {
|
|
9083
|
+
const named = paths.flatMap((path) => path?.trim() && isAbsolute(path) ? [path] : []);
|
|
9084
|
+
return [...new Set(named.flatMap((path) => [resolve2(path), canonicalPath(path)]))];
|
|
8936
9085
|
}
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
const
|
|
8941
|
-
|
|
8942
|
-
if (skills.length >= MAX_SKILLS_PER_SOURCE)
|
|
8943
|
-
break;
|
|
8944
|
-
const skillDir = await realpath(join3(dir, entry)).catch(() => {
|
|
8945
|
-
return;
|
|
8946
|
-
});
|
|
8947
|
-
if (!skillDir || !(await stat2(skillDir).catch(() => {
|
|
8948
|
-
return;
|
|
8949
|
-
}))?.isDirectory())
|
|
8950
|
-
continue;
|
|
8951
|
-
const skill = await readSkill(skillDir, entry);
|
|
8952
|
-
if (!skill || names.has(skill.name))
|
|
8953
|
-
continue;
|
|
8954
|
-
names.add(skill.name);
|
|
8955
|
-
skills.push(skill);
|
|
8956
|
-
}
|
|
8957
|
-
return skills;
|
|
8958
|
-
}
|
|
8959
|
-
async function readSkill(skillDir, dirName) {
|
|
8960
|
-
const entries = await readdir2(skillDir);
|
|
8961
|
-
const skillFile = entries.find((entry) => entry === "SKILL.md");
|
|
8962
|
-
if (!skillFile)
|
|
8963
|
-
return;
|
|
8964
|
-
const file = join3(skillDir, skillFile);
|
|
8965
|
-
const info = await stat2(file).catch(() => {
|
|
8966
|
-
return;
|
|
8967
|
-
});
|
|
8968
|
-
if (!info?.isFile() || info.size > MAX_SKILL_FILE_BYTES)
|
|
8969
|
-
return;
|
|
8970
|
-
const sanitized = sanitizeSkillFile(await readFile3(file, "utf8"), dirName);
|
|
8971
|
-
if (!sanitized) {
|
|
8972
|
-
debugLog("[coordinator-skills] Skipping skill with unreadable frontmatter", { dirName });
|
|
8973
|
-
return;
|
|
8974
|
-
}
|
|
8975
|
-
const links = entries.filter((entry) => entry.toLowerCase() !== "skill.md").sort().slice(0, MAX_ENTRIES_PER_SKILL).map((entry) => [entry, join3(skillDir, entry)]);
|
|
8976
|
-
return { name: sanitized.name, text: sanitized.text, links };
|
|
8977
|
-
}
|
|
8978
|
-
function yamlParser() {
|
|
8979
|
-
const parse = globalThis.Bun?.YAML?.parse;
|
|
8980
|
-
return typeof parse === "function" ? parse : null;
|
|
8981
|
-
}
|
|
8982
|
-
function sanitizeSkillFile(text, dirName, parse = yamlParser()) {
|
|
8983
|
-
const match = FRONTMATTER.exec(text);
|
|
8984
|
-
let fields = {};
|
|
8985
|
-
if (match) {
|
|
8986
|
-
if (!parse)
|
|
8987
|
-
return;
|
|
8988
|
-
let parsed;
|
|
8989
|
-
try {
|
|
8990
|
-
parsed = parse(match[1]);
|
|
8991
|
-
} catch {
|
|
8992
|
-
return;
|
|
8993
|
-
}
|
|
8994
|
-
if (parsed !== null && parsed !== undefined) {
|
|
8995
|
-
if (typeof parsed !== "object" || Array.isArray(parsed))
|
|
8996
|
-
return;
|
|
8997
|
-
fields = parsed;
|
|
8998
|
-
}
|
|
8999
|
-
}
|
|
9000
|
-
const declared = typeof fields.name === "string" ? fields.name.trim() : "";
|
|
9001
|
-
const name = SKILL_NAME.test(declared) ? declared : dirName;
|
|
9002
|
-
if (!SKILL_NAME.test(name))
|
|
9003
|
-
return;
|
|
9004
|
-
const lines = [`name: ${JSON.stringify(name)}`];
|
|
9005
|
-
for (const key of KEPT_FRONTMATTER_KEYS) {
|
|
9006
|
-
if (key === "name" || !Object.hasOwn(fields, key))
|
|
9007
|
-
continue;
|
|
9008
|
-
const value = frontmatterValue(fields[key]);
|
|
9009
|
-
if (value !== undefined)
|
|
9010
|
-
lines.push(`${key}: ${value}`);
|
|
9011
|
-
}
|
|
9012
|
-
const body = match ? text.slice(match[0].length) : text.replace(/^/, "");
|
|
9013
|
-
return { name, text: `---
|
|
9014
|
-
${lines.join(`
|
|
9015
|
-
`)}
|
|
9016
|
-
---
|
|
9017
|
-
${body}` };
|
|
9086
|
+
function isWithin(root, path) {
|
|
9087
|
+
if (path === root)
|
|
9088
|
+
return true;
|
|
9089
|
+
const prefix = root === parse(root).root ? root : `${root}${sep}`;
|
|
9090
|
+
return path.startsWith(prefix);
|
|
9018
9091
|
}
|
|
9019
|
-
function
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9092
|
+
function protectedDataDirBoundary(dataDir, allowances) {
|
|
9093
|
+
const trimmed = dataDir?.trim();
|
|
9094
|
+
if (!trimmed || !isAbsolute(trimmed))
|
|
9095
|
+
return null;
|
|
9096
|
+
const deny = namedAndCanonicalPaths([trimmed]);
|
|
9097
|
+
return {
|
|
9098
|
+
deny,
|
|
9099
|
+
allow: namedAndCanonicalPaths(allowances).filter((path) => !deny.includes(path) && deny.some((root) => isWithin(root, path)))
|
|
9100
|
+
};
|
|
9027
9101
|
}
|
|
9028
|
-
|
|
9029
|
-
return (
|
|
9030
|
-
return;
|
|
9031
|
-
}))?.isFile() ? true : false;
|
|
9102
|
+
function deniedForm(boundary, path) {
|
|
9103
|
+
return boundary.deny.some((root) => isWithin(root, path)) && !boundary.allow.some((root) => isWithin(root, path));
|
|
9032
9104
|
}
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
await mkdir2(join3(staging, ".claude-plugin"), { recursive: true });
|
|
9038
|
-
await writeFile2(join3(staging, ".claude-plugin", "plugin.json"), JSON.stringify({
|
|
9039
|
-
name: plugin,
|
|
9040
|
-
description: plugin === "user-skills" ? "The user's own Claude skills, mirrored by Orkestrator without hooks or tool grants." : "This project's .claude/skills, mirrored by Orkestrator without hooks or tool grants."
|
|
9041
|
-
}));
|
|
9042
|
-
for (const skill of skills) {
|
|
9043
|
-
const skillDir = join3(staging, "skills", skill.name);
|
|
9044
|
-
await mkdir2(skillDir, { recursive: true });
|
|
9045
|
-
await writeFile2(join3(skillDir, "SKILL.md"), skill.text);
|
|
9046
|
-
for (const [name, target] of skill.links)
|
|
9047
|
-
await symlink(target, join3(skillDir, name));
|
|
9048
|
-
}
|
|
9049
|
-
try {
|
|
9050
|
-
await rename2(staging, path);
|
|
9051
|
-
} catch (error) {
|
|
9052
|
-
if (!await isMirror(path))
|
|
9053
|
-
throw error;
|
|
9054
|
-
}
|
|
9055
|
-
} finally {
|
|
9056
|
-
await rm2(staging, { recursive: true, force: true });
|
|
9057
|
-
}
|
|
9105
|
+
function expandedHome(path) {
|
|
9106
|
+
if (path === "~")
|
|
9107
|
+
return homedir2();
|
|
9108
|
+
return path.startsWith("~/") ? `${homedir2()}${sep}${path.slice(2)}` : path;
|
|
9058
9109
|
}
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
old.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
9068
|
-
for (const { path } of old.slice(KEPT_OLD_MIRRORS)) {
|
|
9069
|
-
await rm2(path, { recursive: true, force: true });
|
|
9070
|
-
}
|
|
9071
|
-
} catch {}
|
|
9110
|
+
function readBoundaryRefuses(boundary, path, cwd, options = {}) {
|
|
9111
|
+
const expanded = expandedHome(path);
|
|
9112
|
+
const raw = isAbsolute(expanded) ? expanded : `${cwd}${sep}${expanded}`;
|
|
9113
|
+
const lexical = resolve2(raw);
|
|
9114
|
+
const real = canonicalPath(raw);
|
|
9115
|
+
if (deniedForm(boundary, lexical) || deniedForm(boundary, real))
|
|
9116
|
+
return true;
|
|
9117
|
+
return options.traversal === true && boundary.deny.some((root) => isWithin(lexical, root) || isWithin(real, root));
|
|
9072
9118
|
}
|
|
9073
9119
|
|
|
9074
|
-
// ../../bridges/claude-bridge/src/services/
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
// ../protocol/src/node/claude-plugin-set.ts
|
|
9079
|
-
import path2 from "node:path";
|
|
9080
|
-
var CLAUDE_PLUGINS_MARKER = "/.claude/plugins/";
|
|
9081
|
-
function isRecord(value) {
|
|
9082
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9120
|
+
// ../../bridges/claude-bridge/src/services/read-only-path-boundary.ts
|
|
9121
|
+
function claudeReadOnlyWorkspacePaths(cwd) {
|
|
9122
|
+
return [...new Set([cwd, canonicalPath(cwd)])];
|
|
9083
9123
|
}
|
|
9084
|
-
function
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9124
|
+
function coordinatorReadBoundary(workspaces, env = process.env) {
|
|
9125
|
+
const dataDir = env[COORDINATOR_PROTECTED_DATA_DIR_ENV]?.trim();
|
|
9126
|
+
return protectedDataDirBoundary(dataDir, [
|
|
9127
|
+
env.CLAUDE_CONFIG_DIR,
|
|
9128
|
+
env.ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT,
|
|
9129
|
+
env[COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV],
|
|
9130
|
+
dataDir ? join4(dataDir, "toolchains") : undefined,
|
|
9131
|
+
...workspaces
|
|
9132
|
+
]);
|
|
9133
|
+
}
|
|
9134
|
+
function globRoot(pattern) {
|
|
9135
|
+
if (!pattern.startsWith("/") && !pattern.startsWith("~") && !pattern.startsWith("..")) {
|
|
9136
|
+
return;
|
|
9092
9137
|
}
|
|
9093
|
-
|
|
9138
|
+
const wildcard = pattern.search(/[*?[{]/);
|
|
9139
|
+
return wildcard < 0 ? pattern : pattern.slice(0, wildcard);
|
|
9094
9140
|
}
|
|
9095
|
-
function
|
|
9096
|
-
const
|
|
9097
|
-
|
|
9141
|
+
function readToolRefused(boundary, tool, input, cwd) {
|
|
9142
|
+
const text = (key) => {
|
|
9143
|
+
const value = input[key];
|
|
9144
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
9145
|
+
};
|
|
9146
|
+
if (tool === "Read") {
|
|
9147
|
+
const path = text("file_path");
|
|
9148
|
+
return path !== undefined && readBoundaryRefuses(boundary, path, cwd);
|
|
9149
|
+
}
|
|
9150
|
+
if (tool !== "Grep" && tool !== "Glob")
|
|
9151
|
+
return false;
|
|
9152
|
+
const roots = [text("path") ?? cwd];
|
|
9153
|
+
const pattern = tool === "Glob" ? text("pattern") : undefined;
|
|
9154
|
+
const root = pattern ? globRoot(pattern) : undefined;
|
|
9155
|
+
if (root)
|
|
9156
|
+
roots.push(root);
|
|
9157
|
+
return roots.some((path) => readBoundaryRefuses(boundary, path, cwd, { traversal: true }));
|
|
9098
9158
|
}
|
|
9099
|
-
function
|
|
9100
|
-
const
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9159
|
+
function shellCommandRefused(boundary, command, cwd, options) {
|
|
9160
|
+
const [program, ...tokens] = command.trim().split(/\s+/);
|
|
9161
|
+
if (options.traversal) {
|
|
9162
|
+
const indirectOption = program === "sort" || program === "wc" ? "--files0-from" : program === "file" ? "--files-from" : ["cksum", "md5sum", "sha1sum", "sha256sum"].includes(program ?? "") ? "--check" : undefined;
|
|
9163
|
+
if (indirectOption && tokens.some((token) => {
|
|
9164
|
+
const option = token.split("=", 1)[0];
|
|
9165
|
+
return option.startsWith("--") && indirectOption.startsWith(option) || program === "file" && /^-[^-]*f/.test(token) || indirectOption === "--check" && /^-[^-]*c/.test(token);
|
|
9166
|
+
}))
|
|
9167
|
+
return true;
|
|
9168
|
+
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)))
|
|
9169
|
+
return true;
|
|
9170
|
+
const searches = program === "rg" || program === "ag" || program === "find" || program === "fd" || program === "du" || program === "ls" || program === "tree" || program === "grep";
|
|
9171
|
+
if (searches && readBoundaryRefuses(boundary, cwd, cwd, options))
|
|
9172
|
+
return true;
|
|
9173
|
+
}
|
|
9174
|
+
return tokens.some((token) => {
|
|
9175
|
+
const attached = [];
|
|
9176
|
+
if (token.startsWith("--")) {
|
|
9177
|
+
const equals = token.indexOf("=");
|
|
9178
|
+
if (equals >= 0)
|
|
9179
|
+
attached.push(token.slice(equals + 1));
|
|
9180
|
+
} else if (token.startsWith("-")) {
|
|
9181
|
+
for (let index = 1;index < token.length && /[a-zA-Z0-9]/.test(token[index]); index++) {
|
|
9182
|
+
attached.push(token.slice(index + 1));
|
|
9123
9183
|
}
|
|
9124
|
-
plugins.push({ type: "local", path: resolvedPath, installedId });
|
|
9125
9184
|
}
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
}
|
|
9129
|
-
function resolveClaudePluginPath(pluginPath, cwd, home) {
|
|
9130
|
-
if (pluginPath.startsWith("~"))
|
|
9131
|
-
return path2.join(home, pluginPath.slice(1));
|
|
9132
|
-
if (pluginPath.startsWith("/"))
|
|
9133
|
-
return pluginPath;
|
|
9134
|
-
return path2.join(cwd, pluginPath);
|
|
9135
|
-
}
|
|
9136
|
-
function mergeClaudePluginLayers(layers, options) {
|
|
9137
|
-
const ordered = [
|
|
9138
|
-
claudePluginConfigList(layers.global),
|
|
9139
|
-
layers.cliInstalled,
|
|
9140
|
-
...options.includeProjectSources ? [claudePluginConfigList(layers.projectGlobal), claudePluginConfigList(layers.projectLocal)] : []
|
|
9141
|
-
];
|
|
9142
|
-
const seen = new Set;
|
|
9143
|
-
const paths = [];
|
|
9144
|
-
for (const layer of ordered) {
|
|
9145
|
-
for (const plugin of layer) {
|
|
9146
|
-
const resolved = resolveClaudePluginPath(plugin.path, options.cwd, options.home);
|
|
9147
|
-
if (seen.has(resolved))
|
|
9148
|
-
continue;
|
|
9149
|
-
seen.add(resolved);
|
|
9150
|
-
paths.push(resolved);
|
|
9151
|
-
}
|
|
9152
|
-
}
|
|
9153
|
-
return paths;
|
|
9154
|
-
}
|
|
9155
|
-
var INVALID_PLUGIN_NAME = new RegExp("[@:\\s/\\\\\\u0000-\\u001f\\u007f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]");
|
|
9156
|
-
var CLAUDE_PLUGIN_SETTING_SOURCES = ["local", "project", "user"];
|
|
9157
|
-
function claudeInstalledPluginIdEnablement(id, settings, loadedSources) {
|
|
9158
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9159
|
-
for (const source of ["local", "project", "user"]) {
|
|
9160
|
-
if (!loadedSources.includes(source))
|
|
9161
|
-
continue;
|
|
9162
|
-
const document = settings[source];
|
|
9163
|
-
const enabledPlugins = isRecord(document) ? document.enabledPlugins : undefined;
|
|
9164
|
-
if (!isRecord(enabledPlugins) || !Object.hasOwn(enabledPlugins, id))
|
|
9165
|
-
continue;
|
|
9166
|
-
return { enabled: enabledPlugins[id] === true, decidedBy: { source, key: id } };
|
|
9167
|
-
}
|
|
9168
|
-
return { enabled: false };
|
|
9169
|
-
}
|
|
9170
|
-
function enabledInstalledPlugins(plugins, settings, loadedSources) {
|
|
9171
|
-
return plugins.filter((plugin) => plugin.installedId === undefined || claudeInstalledPluginIdEnablement(plugin.installedId, settings, loadedSources).enabled);
|
|
9172
|
-
}
|
|
9173
|
-
function claudePluginSettingSources(settingSources) {
|
|
9174
|
-
return CLAUDE_PLUGIN_SETTING_SOURCES.filter((source) => settingSources.includes(source));
|
|
9185
|
+
return [token, ...attached].some((candidate) => candidate && readBoundaryRefuses(boundary, candidate, cwd, options));
|
|
9186
|
+
});
|
|
9175
9187
|
}
|
|
9176
9188
|
|
|
9177
|
-
// ../../bridges/claude-bridge/src/services/
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
}
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
}
|
|
9297
|
-
}
|
|
9298
|
-
return plugins;
|
|
9299
|
-
} catch {
|
|
9300
|
-
return [];
|
|
9301
|
-
}
|
|
9302
|
-
}
|
|
9303
|
-
async function loadGlobalPlugins() {
|
|
9304
|
-
const plugins = await readJsonSliceCached(claudeJsonPath(), "plugins", (config) => claudePluginConfigList(config?.plugins));
|
|
9305
|
-
return plugins ?? [];
|
|
9306
|
-
}
|
|
9307
|
-
async function loadProjectPlugins(cwd) {
|
|
9308
|
-
const plugins = await readJsonSliceCached(join4(cwd, ".claude", "plugins.json"), "plugins", (config) => claudePluginConfigList(config?.plugins));
|
|
9309
|
-
return plugins ?? [];
|
|
9310
|
-
}
|
|
9311
|
-
async function loadCliInstalledPlugins() {
|
|
9312
|
-
const pluginsDir = claudePluginsDir();
|
|
9313
|
-
const installedPluginsPath = join4(pluginsDir, "installed_plugins.json");
|
|
9314
|
-
const plugins = await readJsonSliceCached(installedPluginsPath, "plugins", (config) => config?.plugins);
|
|
9315
|
-
if (!plugins) {
|
|
9316
|
-
return scanCliPluginsDirectory(pluginsDir);
|
|
9317
|
-
}
|
|
9318
|
-
return remapInstalledPlugins2(pluginsDir, { plugins });
|
|
9319
|
-
}
|
|
9320
|
-
function pluginSettingsPath(source, cwd) {
|
|
9321
|
-
switch (source) {
|
|
9322
|
-
case "user":
|
|
9323
|
-
return claudeUserSettingsPath();
|
|
9324
|
-
case "project":
|
|
9325
|
-
return join4(cwd, ".claude", "settings.json");
|
|
9326
|
-
case "local":
|
|
9327
|
-
return join4(cwd, ".claude", "settings.local.json");
|
|
9328
|
-
}
|
|
9329
|
-
}
|
|
9330
|
-
async function loadPluginSettings(cwd, sources) {
|
|
9331
|
-
const entries = await Promise.all(sources.map(async (source) => {
|
|
9332
|
-
const enabledPlugins = await readJsonSliceCached(pluginSettingsPath(source, cwd), "enabledPlugins", (config) => config?.enabledPlugins ?? null);
|
|
9333
|
-
return [source, enabledPlugins === null ? undefined : { enabledPlugins }];
|
|
9334
|
-
}));
|
|
9335
|
-
return Object.fromEntries(entries);
|
|
9336
|
-
}
|
|
9337
|
-
function remapInstalledPlugins2(pluginsDir, installedPlugins) {
|
|
9338
|
-
return remapInstalledPlugins(pluginsDir, installedPlugins, (installPath) => log4.warn("plugin.unsafe-path", { path: installPath }));
|
|
9339
|
-
}
|
|
9340
|
-
async function loadProjectOverridesFromGlobal(cwd) {
|
|
9341
|
-
const plugins = await readJsonSliceCached(claudeJsonPath(), `projects:${cwd}:plugins`, (config) => claudePluginConfigList(config?.projects?.[cwd]?.plugins));
|
|
9342
|
-
return plugins ?? [];
|
|
9343
|
-
}
|
|
9344
|
-
async function readPluginManifest(pluginPath) {
|
|
9345
|
-
const manifestPath = join4(pluginPath, ".claude-plugin", "plugin.json");
|
|
9346
|
-
const manifest = await readJsonSliceCached(manifestPath, "manifest", (config) => config ? { name: config.name, description: config.description } : null);
|
|
9347
|
-
if (!manifest) {
|
|
9348
|
-
return null;
|
|
9349
|
-
}
|
|
9350
|
-
const name = manifest.name || pluginPath.split("/").pop() || "unknown";
|
|
9351
|
-
return {
|
|
9352
|
-
name,
|
|
9353
|
-
description: manifest.description
|
|
9354
|
-
};
|
|
9355
|
-
}
|
|
9356
|
-
function resolvePath(pluginPath, cwd) {
|
|
9357
|
-
return resolveClaudePluginPath(pluginPath, cwd, claudeHome());
|
|
9358
|
-
}
|
|
9359
|
-
function defaultSettingSources(includeProjectSources) {
|
|
9360
|
-
return includeProjectSources ? ["user", "project"] : ["user"];
|
|
9361
|
-
}
|
|
9362
|
-
async function getMergedPlugins(cwd, includeProjectSources = true, settingSources = defaultSettingSources(includeProjectSources)) {
|
|
9363
|
-
const sources = claudePluginSettingSources(settingSources);
|
|
9364
|
-
const [global2, cliInstalled, projectGlobal, projectLocal, settings] = await Promise.all([
|
|
9365
|
-
loadGlobalPlugins(),
|
|
9366
|
-
loadCliInstalledPlugins(),
|
|
9367
|
-
includeProjectSources ? loadProjectOverridesFromGlobal(cwd) : [],
|
|
9368
|
-
includeProjectSources ? loadProjectPlugins(cwd) : [],
|
|
9369
|
-
loadPluginSettings(cwd, sources)
|
|
9370
|
-
]);
|
|
9371
|
-
return mergeClaudePluginLayers({
|
|
9372
|
-
global: global2,
|
|
9373
|
-
cliInstalled: enabledInstalledPlugins(cliInstalled, settings, sources),
|
|
9374
|
-
projectGlobal,
|
|
9375
|
-
projectLocal
|
|
9376
|
-
}, { cwd, home: claudeHome(), includeProjectSources }).map((path) => ({ type: "local", path }));
|
|
9377
|
-
}
|
|
9378
|
-
async function getPluginsForSdk(cwd, includeProjectSources = true, settingSources = defaultSettingSources(includeProjectSources)) {
|
|
9379
|
-
const configs = await getMergedPlugins(cwd, includeProjectSources, settingSources);
|
|
9380
|
-
const validPlugins = [];
|
|
9381
|
-
for (const config of configs) {
|
|
9382
|
-
if (await pathExists(config.path)) {
|
|
9383
|
-
validPlugins.push({
|
|
9384
|
-
type: "local",
|
|
9385
|
-
path: config.path
|
|
9386
|
-
});
|
|
9387
|
-
} else {
|
|
9388
|
-
const pluginName = config.path.split("/").pop() || "unknown";
|
|
9389
|
-
log4.warn("plugin.path-missing", { pluginName, path: config.path });
|
|
9390
|
-
}
|
|
9391
|
-
}
|
|
9392
|
-
return validPlugins;
|
|
9393
|
-
}
|
|
9394
|
-
async function getPluginInfo(cwd) {
|
|
9395
|
-
const [global2, cliInstalled, projectGlobal, projectLocal] = await Promise.all([
|
|
9396
|
-
loadGlobalPlugins(),
|
|
9397
|
-
loadCliInstalledPlugins(),
|
|
9398
|
-
loadProjectOverridesFromGlobal(cwd),
|
|
9399
|
-
loadProjectPlugins(cwd)
|
|
9400
|
-
]);
|
|
9401
|
-
const globalPaths = new Set(global2.map((p) => resolvePath(p.path, cwd)));
|
|
9402
|
-
const cliPaths = new Set(cliInstalled.map((p) => resolvePath(p.path, cwd)));
|
|
9403
|
-
const projectGlobalPaths = new Set(projectGlobal.map((p) => resolvePath(p.path, cwd)));
|
|
9404
|
-
const projectLocalPaths = new Set(projectLocal.map((p) => resolvePath(p.path, cwd)));
|
|
9405
|
-
const merged = await getMergedPlugins(cwd);
|
|
9406
|
-
const result = [];
|
|
9407
|
-
for (const config of merged) {
|
|
9408
|
-
const manifest = await readPluginManifest(config.path);
|
|
9409
|
-
const exists = await pathExists(config.path);
|
|
9410
|
-
let source = "global";
|
|
9411
|
-
if (projectLocalPaths.has(config.path) || projectGlobalPaths.has(config.path)) {
|
|
9412
|
-
source = "project";
|
|
9413
|
-
} else if (cliPaths.has(config.path)) {
|
|
9414
|
-
source = "cli";
|
|
9415
|
-
} else if (globalPaths.has(config.path)) {
|
|
9416
|
-
source = "global";
|
|
9189
|
+
// ../../bridges/claude-bridge/src/services/read-only-policy.ts
|
|
9190
|
+
var CAPABILITY_TOOLS = new Map([
|
|
9191
|
+
["file.write", ["Write", "NotebookEdit", "EnterWorktree", "ExitWorktree"]],
|
|
9192
|
+
["file.patch", ["Edit", "MultiEdit", "ApplyPatch"]],
|
|
9193
|
+
["shell", ["Bash", "BashOutput", "KillShell", "PowerShell"]],
|
|
9194
|
+
["shell.mutate", ["PowerShell"]],
|
|
9195
|
+
["network", ["WebFetch", "WebSearch", "RemoteTrigger"]],
|
|
9196
|
+
["web.search", ["WebSearch"]],
|
|
9197
|
+
["subagents", ["Task", "Agent"]],
|
|
9198
|
+
["git.commit", ["Bash(git commit)", "Bash(git commit *)"]],
|
|
9199
|
+
["git.push", ["Bash(git push)", "Bash(git push *)"]],
|
|
9200
|
+
["github.write", ["Bash(gh)", "Bash(gh *)"]]
|
|
9201
|
+
]);
|
|
9202
|
+
var READ_ONLY_TOOLS = Object.freeze([
|
|
9203
|
+
"Read",
|
|
9204
|
+
"Glob",
|
|
9205
|
+
"Grep",
|
|
9206
|
+
"Bash",
|
|
9207
|
+
"Task",
|
|
9208
|
+
"Agent",
|
|
9209
|
+
"TodoWrite",
|
|
9210
|
+
"AskUserQuestion"
|
|
9211
|
+
]);
|
|
9212
|
+
var WAITING_TOOLS = new Set([
|
|
9213
|
+
"Monitor",
|
|
9214
|
+
"ScheduleWakeup",
|
|
9215
|
+
"CronCreate",
|
|
9216
|
+
"CronList",
|
|
9217
|
+
"CronDelete",
|
|
9218
|
+
"SendMessage"
|
|
9219
|
+
]);
|
|
9220
|
+
var READ_ONLY_COMMANDS = Object.freeze(new Set([
|
|
9221
|
+
"awk",
|
|
9222
|
+
"basename",
|
|
9223
|
+
"cat",
|
|
9224
|
+
"cksum",
|
|
9225
|
+
"column",
|
|
9226
|
+
"comm",
|
|
9227
|
+
"cut",
|
|
9228
|
+
"date",
|
|
9229
|
+
"diff",
|
|
9230
|
+
"dirname",
|
|
9231
|
+
"du",
|
|
9232
|
+
"echo",
|
|
9233
|
+
"file",
|
|
9234
|
+
"find",
|
|
9235
|
+
"fd",
|
|
9236
|
+
"grep",
|
|
9237
|
+
"head",
|
|
9238
|
+
"hostname",
|
|
9239
|
+
"jq",
|
|
9240
|
+
"ls",
|
|
9241
|
+
"md5sum",
|
|
9242
|
+
"nl",
|
|
9243
|
+
"od",
|
|
9244
|
+
"printf",
|
|
9245
|
+
"pwd",
|
|
9246
|
+
"readlink",
|
|
9247
|
+
"realpath",
|
|
9248
|
+
"rg",
|
|
9249
|
+
"sha1sum",
|
|
9250
|
+
"sha256sum",
|
|
9251
|
+
"sort",
|
|
9252
|
+
"stat",
|
|
9253
|
+
"tail",
|
|
9254
|
+
"tr",
|
|
9255
|
+
"true",
|
|
9256
|
+
"uniq",
|
|
9257
|
+
"wc",
|
|
9258
|
+
"which",
|
|
9259
|
+
"whoami",
|
|
9260
|
+
"xxd",
|
|
9261
|
+
"yq"
|
|
9262
|
+
]));
|
|
9263
|
+
var MUTATING_ARGUMENTS = new Map([
|
|
9264
|
+
["date", new Set(["-s", "--set"])],
|
|
9265
|
+
["fd", new Set(["-x", "-X", "--exec", "--exec-batch"])],
|
|
9266
|
+
["file", new Set(["-C", "--compile"])],
|
|
9267
|
+
[
|
|
9268
|
+
"find",
|
|
9269
|
+
new Set([
|
|
9270
|
+
"-delete",
|
|
9271
|
+
"-exec",
|
|
9272
|
+
"-execdir",
|
|
9273
|
+
"-fls",
|
|
9274
|
+
"-fprint",
|
|
9275
|
+
"-fprint0",
|
|
9276
|
+
"-fprintf",
|
|
9277
|
+
"-ok",
|
|
9278
|
+
"-okdir"
|
|
9279
|
+
])
|
|
9280
|
+
],
|
|
9281
|
+
["hostname", new Set(["-F", "--file", "-b", "--boot"])],
|
|
9282
|
+
["rg", new Set(["--hostname-bin", "--pre"])],
|
|
9283
|
+
["sort", new Set(["-o", "--output", "-T", "--temporary-directory", "--compress-program"])],
|
|
9284
|
+
["yq", new Set(["-i", "--in-place", "--inplace", "-s", "--split-exp"])]
|
|
9285
|
+
]);
|
|
9286
|
+
var POSITIONAL_LIMITS = new Map([
|
|
9287
|
+
["hostname", { max: 0, valueOptions: new Set }],
|
|
9288
|
+
["uniq", { max: 1, valueOptions: new Set(["-f", "-s", "-w"]) }],
|
|
9289
|
+
[
|
|
9290
|
+
"xxd",
|
|
9291
|
+
{
|
|
9292
|
+
max: 1,
|
|
9293
|
+
stopAtFirstOperand: true,
|
|
9294
|
+
valueOptions: new Set([
|
|
9295
|
+
"-c",
|
|
9296
|
+
"-cols",
|
|
9297
|
+
"-g",
|
|
9298
|
+
"-groupsize",
|
|
9299
|
+
"-l",
|
|
9300
|
+
"-len",
|
|
9301
|
+
"-n",
|
|
9302
|
+
"-name",
|
|
9303
|
+
"-o",
|
|
9304
|
+
"-offset",
|
|
9305
|
+
"-s",
|
|
9306
|
+
"-seek"
|
|
9307
|
+
])
|
|
9417
9308
|
}
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9309
|
+
]
|
|
9310
|
+
]);
|
|
9311
|
+
var OPTION_ALLOWLISTS = new Map([
|
|
9312
|
+
["awk", new Set(["-F", "-v", "--field-separator", "--assign"])]
|
|
9313
|
+
]);
|
|
9314
|
+
var GIT_GLOBAL_OPTIONS = new Set([
|
|
9315
|
+
"-P",
|
|
9316
|
+
"--literal-pathspecs",
|
|
9317
|
+
"--no-optional-locks",
|
|
9318
|
+
"--no-pager"
|
|
9319
|
+
]);
|
|
9320
|
+
var GIT_MUTATING_ARGUMENTS = new Set([
|
|
9321
|
+
"--config-env",
|
|
9322
|
+
"--exec-path",
|
|
9323
|
+
"--ext-diff",
|
|
9324
|
+
"--filters",
|
|
9325
|
+
"--output",
|
|
9326
|
+
"--textconv"
|
|
9327
|
+
]);
|
|
9328
|
+
var GIT_SUBCOMMAND_MUTATING_ARGUMENTS = new Map([
|
|
9329
|
+
["grep", new Set(["-O", "--open-files-in-pager"])]
|
|
9330
|
+
]);
|
|
9331
|
+
var READ_ONLY_GIT_SUBCOMMANDS = Object.freeze(new Set([
|
|
9332
|
+
"blame",
|
|
9333
|
+
"cat-file",
|
|
9334
|
+
"describe",
|
|
9335
|
+
"diff",
|
|
9336
|
+
"grep",
|
|
9337
|
+
"log",
|
|
9338
|
+
"ls-files",
|
|
9339
|
+
"ls-tree",
|
|
9340
|
+
"merge-base",
|
|
9341
|
+
"name-rev",
|
|
9342
|
+
"rev-list",
|
|
9343
|
+
"rev-parse",
|
|
9344
|
+
"shortlog",
|
|
9345
|
+
"show",
|
|
9346
|
+
"show-ref",
|
|
9347
|
+
"status",
|
|
9348
|
+
"whatchanged"
|
|
9349
|
+
]));
|
|
9350
|
+
var GIT_REF_WRITE_FLAGS = Object.freeze(new Set([
|
|
9351
|
+
"-C",
|
|
9352
|
+
"-D",
|
|
9353
|
+
"-M",
|
|
9354
|
+
"-c",
|
|
9355
|
+
"-d",
|
|
9356
|
+
"-f",
|
|
9357
|
+
"-m",
|
|
9358
|
+
"-u",
|
|
9359
|
+
"--copy",
|
|
9360
|
+
"--delete",
|
|
9361
|
+
"--edit-description",
|
|
9362
|
+
"--force",
|
|
9363
|
+
"--move",
|
|
9364
|
+
"--set-upstream-to",
|
|
9365
|
+
"--unset-upstream"
|
|
9366
|
+
]));
|
|
9367
|
+
var GIT_REF_LIST_FLAGS = Object.freeze(new Set([
|
|
9368
|
+
"-l",
|
|
9369
|
+
"--list",
|
|
9370
|
+
"--contains",
|
|
9371
|
+
"--no-contains",
|
|
9372
|
+
"--merged",
|
|
9373
|
+
"--no-merged",
|
|
9374
|
+
"--points-at",
|
|
9375
|
+
"--show-current"
|
|
9376
|
+
]));
|
|
9377
|
+
var GIT_CONFIG_READ_FLAGS = Object.freeze(new Set(["-l", "--get", "--get-all", "--get-regexp", "--get-urlmatch", "--list"]));
|
|
9378
|
+
var GIT_CONFIG_WRITE_FLAGS = Object.freeze(new Set([
|
|
9379
|
+
"-e",
|
|
9380
|
+
"--add",
|
|
9381
|
+
"--edit",
|
|
9382
|
+
"--remove-section",
|
|
9383
|
+
"--rename-section",
|
|
9384
|
+
"--replace-all",
|
|
9385
|
+
"--set",
|
|
9386
|
+
"--set-all",
|
|
9387
|
+
"--unset",
|
|
9388
|
+
"--unset-all"
|
|
9389
|
+
]));
|
|
9390
|
+
var GIT_CONFIG_READ_SUBCOMMANDS = Object.freeze(new Set(["get", "list"]));
|
|
9391
|
+
var GIT_CONFIG_WRITE_SUBCOMMANDS = Object.freeze(new Set(["edit", "remove-section", "rename-section", "set", "unset"]));
|
|
9392
|
+
var GIT_REMOTE_READ_SUBCOMMANDS = Object.freeze(new Set(["get-url"]));
|
|
9393
|
+
function hasFlag(args, flags) {
|
|
9394
|
+
const letters = [...flags].flatMap((flag) => /^-[A-Za-z0-9]$/.test(flag) ? [flag[1]] : []);
|
|
9395
|
+
return args.some((arg) => flags.has(arg) || flags.has(arg.split("=", 1)[0] ?? arg) || arg.startsWith("--") && [...flags].some((flag) => flag.startsWith("--") && flag.startsWith(arg.split("=", 1)[0])) || /^-[^-]/.test(arg) && letters.some((letter) => arg.slice(1).includes(letter)));
|
|
9480
9396
|
}
|
|
9481
|
-
function
|
|
9482
|
-
|
|
9483
|
-
|
|
9397
|
+
function listsRefsOnly(args) {
|
|
9398
|
+
if (hasFlag(args, GIT_REF_WRITE_FLAGS))
|
|
9399
|
+
return false;
|
|
9400
|
+
const positionals = args.filter((arg) => !arg.startsWith("-"));
|
|
9401
|
+
return positionals.length === 0 || hasFlag(args, GIT_REF_LIST_FLAGS);
|
|
9484
9402
|
}
|
|
9485
|
-
function
|
|
9486
|
-
if (
|
|
9487
|
-
return
|
|
9488
|
-
const
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9403
|
+
function readsConfigOnly(args) {
|
|
9404
|
+
if (hasFlag(args, GIT_CONFIG_WRITE_FLAGS))
|
|
9405
|
+
return false;
|
|
9406
|
+
const positionals = args.filter((arg) => !arg.startsWith("-"));
|
|
9407
|
+
const first = positionals[0];
|
|
9408
|
+
if (first && GIT_CONFIG_WRITE_SUBCOMMANDS.has(first))
|
|
9409
|
+
return false;
|
|
9410
|
+
if (hasFlag(args, GIT_CONFIG_READ_FLAGS))
|
|
9411
|
+
return true;
|
|
9412
|
+
if (first && GIT_CONFIG_READ_SUBCOMMANDS.has(first))
|
|
9413
|
+
return true;
|
|
9414
|
+
return positionals.length <= 1;
|
|
9496
9415
|
}
|
|
9497
|
-
var
|
|
9498
|
-
"
|
|
9499
|
-
"
|
|
9500
|
-
|
|
9501
|
-
|
|
9416
|
+
var CONDITIONAL_GIT_SUBCOMMANDS = new Map([
|
|
9417
|
+
["branch", listsRefsOnly],
|
|
9418
|
+
["config", readsConfigOnly],
|
|
9419
|
+
[
|
|
9420
|
+
"remote",
|
|
9421
|
+
(args) => {
|
|
9422
|
+
const first = args.find((arg) => !arg.startsWith("-"));
|
|
9423
|
+
return first === undefined || GIT_REMOTE_READ_SUBCOMMANDS.has(first);
|
|
9424
|
+
}
|
|
9425
|
+
],
|
|
9426
|
+
["tag", listsRefsOnly]
|
|
9502
9427
|
]);
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
}
|
|
9509
|
-
|
|
9510
|
-
// ../../bridges/claude-bridge/src/services/mcp-tool-prefix.ts
|
|
9511
|
-
function claudeMcpToolPrefix(name) {
|
|
9512
|
-
let normalized = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
9513
|
-
if (name.startsWith("claude.ai ")) {
|
|
9514
|
-
normalized = normalized.replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
9515
|
-
}
|
|
9516
|
-
return `mcp__${normalized}__`;
|
|
9428
|
+
var NETWORK_COMMANDS = new Set(["curl", "gh", "wget"]);
|
|
9429
|
+
var NETWORK_GIT_SUBCOMMANDS = new Set(["fetch", "ls-remote", "pull"]);
|
|
9430
|
+
var COMPOSITION_PATTERN = /[;&|><`$(){}\n\r'"\\*?[\]]|\bsudo\b|\bexec\b/;
|
|
9431
|
+
function isCoordinatorReadOnlyPolicy(policy) {
|
|
9432
|
+
return policy?.id === "coordinator-read-only";
|
|
9517
9433
|
}
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
|
|
9525
|
-
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join5, parse, resolve as resolve2, sep } from "node:path";
|
|
9526
|
-
function canonicalPath(path) {
|
|
9527
|
-
let existing = path;
|
|
9528
|
-
const tail = [];
|
|
9529
|
-
for (;; ) {
|
|
9530
|
-
try {
|
|
9531
|
-
return join5(realpathSync.native(existing), ...tail.reverse());
|
|
9532
|
-
} catch {
|
|
9533
|
-
const parent = dirname2(existing);
|
|
9534
|
-
if (parent === existing)
|
|
9535
|
-
return path;
|
|
9536
|
-
tail.push(existing.slice(parent.length).replace(/^[/\\]+/, ""));
|
|
9537
|
-
existing = parent;
|
|
9434
|
+
function claudeDeniedTools(policy) {
|
|
9435
|
+
const tools = new Set;
|
|
9436
|
+
for (const capability of nativeAgentDeniedCapabilities(policy)) {
|
|
9437
|
+
const server = nativeAgentMcpServer(capability);
|
|
9438
|
+
if (server) {
|
|
9439
|
+
tools.add(`${claudeMcpToolPrefix(server)}*`);
|
|
9440
|
+
continue;
|
|
9538
9441
|
}
|
|
9442
|
+
for (const tool of CAPABILITY_TOOLS.get(capability) ?? [])
|
|
9443
|
+
tools.add(tool);
|
|
9539
9444
|
}
|
|
9445
|
+
if (!nativeAgentPolicyDeniesWebSearch(policy))
|
|
9446
|
+
tools.delete("WebSearch");
|
|
9447
|
+
return [...tools];
|
|
9540
9448
|
}
|
|
9541
|
-
function
|
|
9542
|
-
const
|
|
9543
|
-
|
|
9449
|
+
function claudeDisallowedTools(policy) {
|
|
9450
|
+
const denied = claudeDeniedTools(policy);
|
|
9451
|
+
if (denied.length === 0)
|
|
9452
|
+
return policy?.toolPolicy?.deny;
|
|
9453
|
+
return [...new Set([...policy?.toolPolicy?.deny ?? [], ...denied])];
|
|
9544
9454
|
}
|
|
9545
|
-
function
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9455
|
+
function claudeReadOnlyAllowedTools(options) {
|
|
9456
|
+
return [
|
|
9457
|
+
...READ_ONLY_TOOLS,
|
|
9458
|
+
...(options.skillNames ?? []).map((name) => `Skill(${name})`),
|
|
9459
|
+
...options.policy && !nativeAgentPolicyDeniesWebSearch(options.policy) ? ["WebSearch"] : [],
|
|
9460
|
+
...(options.agentMcpServerNames ?? []).map((name) => `${claudeMcpToolPrefix(name)}*`),
|
|
9461
|
+
...(options.researchMcpServerNames ?? []).map((name) => `${claudeMcpToolPrefix(name)}*`),
|
|
9462
|
+
...(options.grantedMcpServerNames ?? []).map((name) => `${claudeMcpToolPrefix(name)}*`)
|
|
9463
|
+
];
|
|
9550
9464
|
}
|
|
9551
|
-
function
|
|
9552
|
-
const trimmed = dataDir?.trim();
|
|
9553
|
-
if (!trimmed || !isAbsolute2(trimmed))
|
|
9554
|
-
return null;
|
|
9555
|
-
const deny = namedAndCanonicalPaths([trimmed]);
|
|
9465
|
+
function claudeReadOnlySandbox(policy, options = {}) {
|
|
9556
9466
|
return {
|
|
9557
|
-
|
|
9558
|
-
|
|
9467
|
+
enabled: options.commandSandbox !== "unavailable",
|
|
9468
|
+
failIfUnavailable: options.commandSandbox !== "unavailable",
|
|
9469
|
+
autoAllowBashIfSandboxed: true,
|
|
9470
|
+
allowUnsandboxedCommands: false,
|
|
9471
|
+
excludedCommands: [],
|
|
9472
|
+
filesystem: {
|
|
9473
|
+
denyWrite: [...new Set(options.workspaces ?? [])],
|
|
9474
|
+
...options.readBoundary ? { denyRead: options.readBoundary.deny, allowRead: options.readBoundary.allow } : {}
|
|
9475
|
+
},
|
|
9476
|
+
network: {
|
|
9477
|
+
allowLocalBinding: policy.networkAccess === "full",
|
|
9478
|
+
strictAllowlist: true,
|
|
9479
|
+
allowedDomains: []
|
|
9480
|
+
}
|
|
9559
9481
|
};
|
|
9560
9482
|
}
|
|
9561
|
-
function
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
if (path === "~")
|
|
9566
|
-
return homedir2();
|
|
9567
|
-
return path.startsWith("~/") ? `${homedir2()}${sep}${path.slice(2)}` : path;
|
|
9568
|
-
}
|
|
9569
|
-
function readBoundaryRefuses(boundary, path, cwd, options = {}) {
|
|
9570
|
-
const expanded = expandedHome(path);
|
|
9571
|
-
const raw = isAbsolute2(expanded) ? expanded : `${cwd}${sep}${expanded}`;
|
|
9572
|
-
const lexical = resolve2(raw);
|
|
9573
|
-
const real = canonicalPath(raw);
|
|
9574
|
-
if (deniedForm(boundary, lexical) || deniedForm(boundary, real))
|
|
9575
|
-
return true;
|
|
9576
|
-
return options.traversal === true && boundary.deny.some((root) => isWithin(lexical, root) || isWithin(real, root));
|
|
9483
|
+
function readOnlyRefusalRole(sessionPolicy, readOnlyTurn, env = process.env) {
|
|
9484
|
+
if (processExecutionPolicyIsCoordinator(env))
|
|
9485
|
+
return "coordinator";
|
|
9486
|
+
return !readOnlyTurn && isCoordinatorReadOnlyPolicy(sessionPolicy) ? "coordinator" : "read-only";
|
|
9577
9487
|
}
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9488
|
+
var REFUSALS = {
|
|
9489
|
+
coordinator: {
|
|
9490
|
+
composition: "Coordinator shells cannot use quotes, escapes, globs, pipes, redirection, substitution or command chaining, because the command that runs would not be the one checked.",
|
|
9491
|
+
byPath: (program) => `Coordinator shells run reading programs by name only, so \`${program}\` is not available here. Use the program name, or delegate it to a worker environment.`,
|
|
9492
|
+
gitSandbox: "Coordinator Git commands require the command sandbox because Git configuration can run helpers. Use reading tools or delegate to a worker environment.",
|
|
9493
|
+
unavailable: (described) => `Coordinator is read-only, so \`${described}\` is not available here. Delegate it to a worker environment.`,
|
|
9494
|
+
gitArgument: (described) => `Coordinator is read-only, so \`${described}\` cannot be used with an argument that writes a file or runs another program. Delegate it to a worker environment.`,
|
|
9495
|
+
gitGlobalOption: (option) => `Coordinator Git commands run against this checkout only, so the Git option \`${option}\` is not available before the subcommand. Delegate it to a worker environment.`,
|
|
9496
|
+
argument: (program) => `Coordinator is read-only, so \`${program}\` cannot be used with an argument that writes or runs another program. Delegate it to a worker environment.`,
|
|
9497
|
+
program: (program) => `Coordinator is read-only, so \`${program}\` is not available here. Delegate commands that change the checkout to a worker environment.`,
|
|
9498
|
+
network: (described) => `Coordinator commands have no network access, so \`${described}\` is not available here. Delegate it to a worker environment.`,
|
|
9499
|
+
tool: (tool) => `Coordinator is read-only, so ${tool} is not available. Delegate file changes to a worker environment.`,
|
|
9500
|
+
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.`,
|
|
9501
|
+
mcp: (tool) => `Coordinator sessions may only use Orkestrator's own tools, so ${tool} is not available.`,
|
|
9502
|
+
unsandboxed: "Coordinator commands may not run outside the sandbox.",
|
|
9503
|
+
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."
|
|
9504
|
+
},
|
|
9505
|
+
"read-only": {
|
|
9506
|
+
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.",
|
|
9507
|
+
byPath: (program) => `This session runs reading programs by name only, so \`${program}\` is not available here. Use the program name.`,
|
|
9508
|
+
gitSandbox: "Git commands in this session require the command sandbox because Git configuration can run helpers. Use reading tools instead.",
|
|
9509
|
+
unavailable: (described) => `This session is read-only, so \`${described}\` is not available here.`,
|
|
9510
|
+
gitArgument: (described) => `This session is read-only, so \`${described}\` cannot be used with an argument that writes a file or runs another program.`,
|
|
9511
|
+
gitGlobalOption: (option) => `Git commands in this session run against this checkout only, so the Git option \`${option}\` is not available before the subcommand.`,
|
|
9512
|
+
argument: (program) => `This session is read-only, so \`${program}\` cannot be used with an argument that writes or runs another program.`,
|
|
9513
|
+
program: (program) => `This session is read-only, so \`${program}\` is not available here. It may read the checkout but not change it.`,
|
|
9514
|
+
network: (described) => `Commands in this session have no network access, so \`${described}\` is not available here.`,
|
|
9515
|
+
tool: (tool) => `This session is read-only, so ${tool} is not available.`,
|
|
9516
|
+
waiting: (tool) => `This session's turns do not wait, so ${tool} is not available. End your turn instead.`,
|
|
9517
|
+
mcp: (tool) => `This session may only use Orkestrator's own tools and the MCP servers granted to it, so ${tool} is not available.`,
|
|
9518
|
+
unsandboxed: "Commands in this session may not run outside the sandbox.",
|
|
9519
|
+
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."
|
|
9520
|
+
}
|
|
9521
|
+
};
|
|
9522
|
+
function isReadOnlyShellCommand(command, options = {}) {
|
|
9523
|
+
const refusals = REFUSALS[options.role ?? "coordinator"];
|
|
9524
|
+
const trimmed = command.trim();
|
|
9525
|
+
if (!trimmed)
|
|
9526
|
+
return { allowed: true };
|
|
9527
|
+
if (COMPOSITION_PATTERN.test(trimmed) || /(?:^|\s)~/.test(trimmed)) {
|
|
9528
|
+
return { allowed: false, reason: refusals.composition };
|
|
9529
|
+
}
|
|
9530
|
+
const tokens = trimmed.split(/\s+/).filter(Boolean);
|
|
9531
|
+
const first = tokens[0] ?? "";
|
|
9532
|
+
if (!first)
|
|
9533
|
+
return { allowed: true };
|
|
9534
|
+
if (first.includes("/") || first.includes("\\")) {
|
|
9535
|
+
return { allowed: false, reason: refusals.byPath(first) };
|
|
9536
|
+
}
|
|
9537
|
+
const program = first;
|
|
9538
|
+
if (NETWORK_COMMANDS.has(program))
|
|
9539
|
+
return { allowed: false, reason: refusals.network(program) };
|
|
9540
|
+
if (program === "git") {
|
|
9541
|
+
if (options.commandSandbox !== "required") {
|
|
9542
|
+
return { allowed: false, reason: refusals.gitSandbox };
|
|
9543
|
+
}
|
|
9544
|
+
const subcommandIndex = tokens.findIndex((token, index) => index > 0 && !token.startsWith("-"));
|
|
9545
|
+
const subcommand = subcommandIndex > 0 ? tokens[subcommandIndex] : undefined;
|
|
9546
|
+
const args = subcommandIndex > 0 ? tokens.slice(subcommandIndex + 1) : [];
|
|
9547
|
+
const globalOptions = tokens.slice(1, subcommandIndex > 0 ? subcommandIndex : undefined);
|
|
9548
|
+
const unlisted = globalOptions.find((option) => !GIT_GLOBAL_OPTIONS.has(option));
|
|
9549
|
+
if (unlisted)
|
|
9550
|
+
return { allowed: false, reason: refusals.gitGlobalOption(unlisted) };
|
|
9551
|
+
if (subcommand && (NETWORK_GIT_SUBCOMMANDS.has(subcommand) || subcommand === "remote" && args.some((arg) => arg === "show"))) {
|
|
9552
|
+
return { allowed: false, reason: refusals.network(`git ${subcommand}`) };
|
|
9553
|
+
}
|
|
9554
|
+
const permitted = subcommand !== undefined && (READ_ONLY_GIT_SUBCOMMANDS.has(subcommand) || (CONDITIONAL_GIT_SUBCOMMANDS.get(subcommand)?.(args) ?? false));
|
|
9555
|
+
const described = ["git", subcommand].filter(Boolean).join(" ");
|
|
9556
|
+
if (!permitted) {
|
|
9557
|
+
return { allowed: false, reason: refusals.unavailable(described) };
|
|
9558
|
+
}
|
|
9559
|
+
if (hasFlag(tokens.slice(1), GIT_MUTATING_ARGUMENTS) || hasFlag(args, GIT_SUBCOMMAND_MUTATING_ARGUMENTS.get(subcommand) ?? new Set)) {
|
|
9560
|
+
return { allowed: false, reason: refusals.gitArgument(described) };
|
|
9561
|
+
}
|
|
9562
|
+
return { allowed: true };
|
|
9563
|
+
}
|
|
9564
|
+
if (READ_ONLY_COMMANDS.has(program)) {
|
|
9565
|
+
const args = tokens.slice(1);
|
|
9566
|
+
const mutating = MUTATING_ARGUMENTS.get(program);
|
|
9567
|
+
const allowedOptions = OPTION_ALLOWLISTS.get(program);
|
|
9568
|
+
const limit = POSITIONAL_LIMITS.get(program);
|
|
9569
|
+
if (mutating && hasFlag(args, mutating) || allowedOptions && !optionsAllowed(args, allowedOptions) || limit && positionalCount(args, limit.valueOptions, limit.stopAtFirstOperand) > limit.max) {
|
|
9570
|
+
return { allowed: false, reason: refusals.argument(program) };
|
|
9571
|
+
}
|
|
9572
|
+
return { allowed: true };
|
|
9573
|
+
}
|
|
9574
|
+
return { allowed: false, reason: refusals.program(program) };
|
|
9582
9575
|
}
|
|
9583
|
-
function
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9576
|
+
function optionsAllowed(args, allowed) {
|
|
9577
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
9578
|
+
const arg = args[index];
|
|
9579
|
+
if (arg === "--")
|
|
9580
|
+
return true;
|
|
9581
|
+
if (!arg.startsWith("-") || arg === "-")
|
|
9582
|
+
continue;
|
|
9583
|
+
if (allowed.has(arg)) {
|
|
9584
|
+
index += 1;
|
|
9585
|
+
continue;
|
|
9586
|
+
}
|
|
9587
|
+
const long = arg.startsWith("--") ? arg.split("=", 1)[0] : undefined;
|
|
9588
|
+
const attached = long ?? arg.slice(0, 2);
|
|
9589
|
+
if (!allowed.has(attached))
|
|
9590
|
+
return false;
|
|
9591
|
+
}
|
|
9592
|
+
return true;
|
|
9592
9593
|
}
|
|
9593
|
-
function
|
|
9594
|
-
|
|
9595
|
-
|
|
9594
|
+
function positionalCount(args, valueOptions, stopAtFirstOperand = false) {
|
|
9595
|
+
let count = 0;
|
|
9596
|
+
let optionsEnded = false;
|
|
9597
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
9598
|
+
const arg = args[index];
|
|
9599
|
+
if (!optionsEnded && arg === "--") {
|
|
9600
|
+
optionsEnded = true;
|
|
9601
|
+
continue;
|
|
9602
|
+
}
|
|
9603
|
+
if (!optionsEnded && arg.startsWith("-") && arg !== "-") {
|
|
9604
|
+
if (valueOptions.has(arg))
|
|
9605
|
+
index += 1;
|
|
9606
|
+
continue;
|
|
9607
|
+
}
|
|
9608
|
+
count += 1;
|
|
9609
|
+
if (stopAtFirstOperand)
|
|
9610
|
+
optionsEnded = true;
|
|
9596
9611
|
}
|
|
9597
|
-
|
|
9598
|
-
return wildcard < 0 ? pattern : pattern.slice(0, wildcard);
|
|
9612
|
+
return count;
|
|
9599
9613
|
}
|
|
9600
|
-
function
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9614
|
+
function deny(reason) {
|
|
9615
|
+
return {
|
|
9616
|
+
hookSpecificOutput: {
|
|
9617
|
+
hookEventName: "PreToolUse",
|
|
9618
|
+
permissionDecision: "deny",
|
|
9619
|
+
permissionDecisionReason: reason
|
|
9620
|
+
}
|
|
9604
9621
|
};
|
|
9605
|
-
if (tool === "Read") {
|
|
9606
|
-
const path = text("file_path");
|
|
9607
|
-
return path !== undefined && readBoundaryRefuses(boundary, path, cwd);
|
|
9608
|
-
}
|
|
9609
|
-
if (tool !== "Grep" && tool !== "Glob")
|
|
9610
|
-
return false;
|
|
9611
|
-
const roots = [text("path") ?? cwd];
|
|
9612
|
-
const pattern = tool === "Glob" ? text("pattern") : undefined;
|
|
9613
|
-
const root = pattern ? globRoot(pattern) : undefined;
|
|
9614
|
-
if (root)
|
|
9615
|
-
roots.push(root);
|
|
9616
|
-
return roots.some((path) => readBoundaryRefuses(boundary, path, cwd, { traversal: true }));
|
|
9617
9622
|
}
|
|
9618
|
-
function
|
|
9619
|
-
const
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
if (
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9623
|
+
function createCoordinatorReadOnlyHook(policy, researchMcpServerNames = coordinatorResearchMcpServersFromEnv(process.env).map((server) => server.name), options = {}) {
|
|
9624
|
+
const refusals = REFUSALS[options.role ?? "coordinator"];
|
|
9625
|
+
const deniedTools = new Set(claudeDeniedTools(policy));
|
|
9626
|
+
const deniedMcpPrefixes = [...deniedTools].filter((tool) => tool.startsWith("mcp__") && tool.endsWith("__*")).map((tool) => tool.slice(0, -1));
|
|
9627
|
+
const allowedMcpPrefixes = [
|
|
9628
|
+
claudeMcpToolPrefix("orkestrator"),
|
|
9629
|
+
...researchMcpServerNames.map(claudeMcpToolPrefix),
|
|
9630
|
+
...(nativeAgentUserMcpGrant(policy) ?? []).map(claudeMcpToolPrefix)
|
|
9631
|
+
];
|
|
9632
|
+
const readBoundary = (cwd) => options.readBoundary !== undefined ? options.readBoundary : process.env[COORDINATOR_PROTECTED_DATA_DIR_ENV] ? coordinatorReadBoundary(claudeReadOnlyWorkspacePaths(cwd)) : null;
|
|
9633
|
+
return async (input) => {
|
|
9634
|
+
if (input.hook_event_name !== "PreToolUse")
|
|
9635
|
+
return {};
|
|
9636
|
+
const toolName = input.tool_name;
|
|
9637
|
+
if (deniedTools.has(toolName)) {
|
|
9638
|
+
return deny(refusals.tool(toolName));
|
|
9639
|
+
}
|
|
9640
|
+
if (WAITING_TOOLS.has(toolName)) {
|
|
9641
|
+
return deny(refusals.waiting(toolName));
|
|
9642
|
+
}
|
|
9643
|
+
if (deniedMcpPrefixes.some((prefix) => toolName.startsWith(prefix))) {
|
|
9644
|
+
return deny(`This session's policy denies the MCP server behind ${toolName}.`);
|
|
9645
|
+
}
|
|
9646
|
+
if (toolName.startsWith("mcp__")) {
|
|
9647
|
+
if (!allowedMcpPrefixes.some((prefix) => toolName.startsWith(prefix))) {
|
|
9648
|
+
return deny(refusals.mcp(toolName));
|
|
9642
9649
|
}
|
|
9650
|
+
return {};
|
|
9643
9651
|
}
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
]);
|
|
9661
|
-
var READ_ONLY_TOOLS = Object.freeze([
|
|
9662
|
-
"Read",
|
|
9663
|
-
"Glob",
|
|
9664
|
-
"Grep",
|
|
9665
|
-
"Bash",
|
|
9666
|
-
"Task",
|
|
9667
|
-
"Agent",
|
|
9668
|
-
"TodoWrite",
|
|
9669
|
-
"AskUserQuestion"
|
|
9670
|
-
]);
|
|
9671
|
-
var WAITING_TOOLS = new Set([
|
|
9672
|
-
"Monitor",
|
|
9673
|
-
"ScheduleWakeup",
|
|
9674
|
-
"CronCreate",
|
|
9675
|
-
"CronList",
|
|
9676
|
-
"CronDelete",
|
|
9677
|
-
"SendMessage"
|
|
9678
|
-
]);
|
|
9679
|
-
var READ_ONLY_COMMANDS = Object.freeze(new Set([
|
|
9680
|
-
"awk",
|
|
9681
|
-
"basename",
|
|
9682
|
-
"cat",
|
|
9683
|
-
"cksum",
|
|
9684
|
-
"column",
|
|
9685
|
-
"comm",
|
|
9686
|
-
"cut",
|
|
9687
|
-
"date",
|
|
9688
|
-
"diff",
|
|
9689
|
-
"dirname",
|
|
9690
|
-
"du",
|
|
9691
|
-
"echo",
|
|
9692
|
-
"file",
|
|
9693
|
-
"find",
|
|
9694
|
-
"fd",
|
|
9695
|
-
"grep",
|
|
9696
|
-
"head",
|
|
9697
|
-
"hostname",
|
|
9698
|
-
"jq",
|
|
9699
|
-
"ls",
|
|
9700
|
-
"md5sum",
|
|
9701
|
-
"nl",
|
|
9702
|
-
"od",
|
|
9703
|
-
"printf",
|
|
9704
|
-
"pwd",
|
|
9705
|
-
"readlink",
|
|
9706
|
-
"realpath",
|
|
9707
|
-
"rg",
|
|
9708
|
-
"sha1sum",
|
|
9709
|
-
"sha256sum",
|
|
9710
|
-
"sort",
|
|
9711
|
-
"stat",
|
|
9712
|
-
"tail",
|
|
9713
|
-
"tr",
|
|
9714
|
-
"true",
|
|
9715
|
-
"uniq",
|
|
9716
|
-
"wc",
|
|
9717
|
-
"which",
|
|
9718
|
-
"whoami",
|
|
9719
|
-
"xxd",
|
|
9720
|
-
"yq"
|
|
9721
|
-
]));
|
|
9722
|
-
var MUTATING_ARGUMENTS = new Map([
|
|
9723
|
-
["date", new Set(["-s", "--set"])],
|
|
9724
|
-
["fd", new Set(["-x", "-X", "--exec", "--exec-batch"])],
|
|
9725
|
-
["file", new Set(["-C", "--compile"])],
|
|
9726
|
-
[
|
|
9727
|
-
"find",
|
|
9728
|
-
new Set([
|
|
9729
|
-
"-delete",
|
|
9730
|
-
"-exec",
|
|
9731
|
-
"-execdir",
|
|
9732
|
-
"-fls",
|
|
9733
|
-
"-fprint",
|
|
9734
|
-
"-fprint0",
|
|
9735
|
-
"-fprintf",
|
|
9736
|
-
"-ok",
|
|
9737
|
-
"-okdir"
|
|
9738
|
-
])
|
|
9739
|
-
],
|
|
9740
|
-
["hostname", new Set(["-F", "--file", "-b", "--boot"])],
|
|
9741
|
-
["rg", new Set(["--hostname-bin", "--pre"])],
|
|
9742
|
-
["sort", new Set(["-o", "--output", "-T", "--temporary-directory", "--compress-program"])],
|
|
9743
|
-
["yq", new Set(["-i", "--in-place", "--inplace", "-s", "--split-exp"])]
|
|
9744
|
-
]);
|
|
9745
|
-
var POSITIONAL_LIMITS = new Map([
|
|
9746
|
-
["hostname", { max: 0, valueOptions: new Set }],
|
|
9747
|
-
["uniq", { max: 1, valueOptions: new Set(["-f", "-s", "-w"]) }],
|
|
9748
|
-
[
|
|
9749
|
-
"xxd",
|
|
9750
|
-
{
|
|
9751
|
-
max: 1,
|
|
9752
|
-
stopAtFirstOperand: true,
|
|
9753
|
-
valueOptions: new Set([
|
|
9754
|
-
"-c",
|
|
9755
|
-
"-cols",
|
|
9756
|
-
"-g",
|
|
9757
|
-
"-groupsize",
|
|
9758
|
-
"-l",
|
|
9759
|
-
"-len",
|
|
9760
|
-
"-n",
|
|
9761
|
-
"-name",
|
|
9762
|
-
"-o",
|
|
9763
|
-
"-offset",
|
|
9764
|
-
"-s",
|
|
9765
|
-
"-seek"
|
|
9766
|
-
])
|
|
9652
|
+
if (toolName === "Bash") {
|
|
9653
|
+
const toolInput = input.tool_input;
|
|
9654
|
+
if (toolInput?.dangerouslyDisableSandbox === true) {
|
|
9655
|
+
return deny(refusals.unsandboxed);
|
|
9656
|
+
}
|
|
9657
|
+
const command = typeof toolInput?.command === "string" ? toolInput.command : "";
|
|
9658
|
+
const verdict = isReadOnlyShellCommand(command, options);
|
|
9659
|
+
if (!verdict.allowed)
|
|
9660
|
+
return deny(verdict.reason);
|
|
9661
|
+
const boundary = readBoundary(input.cwd);
|
|
9662
|
+
if (boundary && shellCommandRefused(boundary, command, input.cwd, {
|
|
9663
|
+
traversal: options.commandSandbox === "unavailable"
|
|
9664
|
+
})) {
|
|
9665
|
+
return deny(refusals.dataDirectory);
|
|
9666
|
+
}
|
|
9667
|
+
return {};
|
|
9767
9668
|
}
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9775
|
-
|
|
9776
|
-
|
|
9777
|
-
"--no-pager"
|
|
9778
|
-
]);
|
|
9779
|
-
var GIT_MUTATING_ARGUMENTS = new Set([
|
|
9780
|
-
"--config-env",
|
|
9781
|
-
"--exec-path",
|
|
9782
|
-
"--ext-diff",
|
|
9783
|
-
"--filters",
|
|
9784
|
-
"--output",
|
|
9785
|
-
"--textconv"
|
|
9786
|
-
]);
|
|
9787
|
-
var GIT_SUBCOMMAND_MUTATING_ARGUMENTS = new Map([
|
|
9788
|
-
["grep", new Set(["-O", "--open-files-in-pager"])]
|
|
9789
|
-
]);
|
|
9790
|
-
var READ_ONLY_GIT_SUBCOMMANDS = Object.freeze(new Set([
|
|
9791
|
-
"blame",
|
|
9792
|
-
"cat-file",
|
|
9793
|
-
"describe",
|
|
9794
|
-
"diff",
|
|
9795
|
-
"grep",
|
|
9796
|
-
"log",
|
|
9797
|
-
"ls-files",
|
|
9798
|
-
"ls-tree",
|
|
9799
|
-
"merge-base",
|
|
9800
|
-
"name-rev",
|
|
9801
|
-
"rev-list",
|
|
9802
|
-
"rev-parse",
|
|
9803
|
-
"shortlog",
|
|
9804
|
-
"show",
|
|
9805
|
-
"show-ref",
|
|
9806
|
-
"status",
|
|
9807
|
-
"whatchanged"
|
|
9808
|
-
]));
|
|
9809
|
-
var GIT_REF_WRITE_FLAGS = Object.freeze(new Set([
|
|
9810
|
-
"-C",
|
|
9811
|
-
"-D",
|
|
9812
|
-
"-M",
|
|
9813
|
-
"-c",
|
|
9814
|
-
"-d",
|
|
9815
|
-
"-f",
|
|
9816
|
-
"-m",
|
|
9817
|
-
"-u",
|
|
9818
|
-
"--copy",
|
|
9819
|
-
"--delete",
|
|
9820
|
-
"--edit-description",
|
|
9821
|
-
"--force",
|
|
9822
|
-
"--move",
|
|
9823
|
-
"--set-upstream-to",
|
|
9824
|
-
"--unset-upstream"
|
|
9825
|
-
]));
|
|
9826
|
-
var GIT_REF_LIST_FLAGS = Object.freeze(new Set([
|
|
9827
|
-
"-l",
|
|
9828
|
-
"--list",
|
|
9829
|
-
"--contains",
|
|
9830
|
-
"--no-contains",
|
|
9831
|
-
"--merged",
|
|
9832
|
-
"--no-merged",
|
|
9833
|
-
"--points-at",
|
|
9834
|
-
"--show-current"
|
|
9835
|
-
]));
|
|
9836
|
-
var GIT_CONFIG_READ_FLAGS = Object.freeze(new Set(["-l", "--get", "--get-all", "--get-regexp", "--get-urlmatch", "--list"]));
|
|
9837
|
-
var GIT_CONFIG_WRITE_FLAGS = Object.freeze(new Set([
|
|
9838
|
-
"-e",
|
|
9839
|
-
"--add",
|
|
9840
|
-
"--edit",
|
|
9841
|
-
"--remove-section",
|
|
9842
|
-
"--rename-section",
|
|
9843
|
-
"--replace-all",
|
|
9844
|
-
"--set",
|
|
9845
|
-
"--set-all",
|
|
9846
|
-
"--unset",
|
|
9847
|
-
"--unset-all"
|
|
9848
|
-
]));
|
|
9849
|
-
var GIT_CONFIG_READ_SUBCOMMANDS = Object.freeze(new Set(["get", "list"]));
|
|
9850
|
-
var GIT_CONFIG_WRITE_SUBCOMMANDS = Object.freeze(new Set(["edit", "remove-section", "rename-section", "set", "unset"]));
|
|
9851
|
-
var GIT_REMOTE_READ_SUBCOMMANDS = Object.freeze(new Set(["get-url"]));
|
|
9852
|
-
function hasFlag(args, flags) {
|
|
9853
|
-
const letters = [...flags].flatMap((flag) => /^-[A-Za-z0-9]$/.test(flag) ? [flag[1]] : []);
|
|
9854
|
-
return args.some((arg) => flags.has(arg) || flags.has(arg.split("=", 1)[0] ?? arg) || arg.startsWith("--") && [...flags].some((flag) => flag.startsWith("--") && flag.startsWith(arg.split("=", 1)[0])) || /^-[^-]/.test(arg) && letters.some((letter) => arg.slice(1).includes(letter)));
|
|
9669
|
+
if (toolName === "Read" || toolName === "Grep" || toolName === "Glob") {
|
|
9670
|
+
const boundary = readBoundary(input.cwd);
|
|
9671
|
+
const toolInput = input.tool_input ?? {};
|
|
9672
|
+
if (boundary && readToolRefused(boundary, toolName, toolInput, input.cwd)) {
|
|
9673
|
+
return deny(refusals.dataDirectory);
|
|
9674
|
+
}
|
|
9675
|
+
}
|
|
9676
|
+
return {};
|
|
9677
|
+
};
|
|
9855
9678
|
}
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
const positionals = args.filter((arg) => !arg.startsWith("-"));
|
|
9860
|
-
return positionals.length === 0 || hasFlag(args, GIT_REF_LIST_FLAGS);
|
|
9679
|
+
var BRIDGE_EXECUTION_POLICY_ENV = "ORKESTRATOR_BRIDGE_EXECUTION_POLICY";
|
|
9680
|
+
function processExecutionPolicyIsCoordinator(env = process.env) {
|
|
9681
|
+
return env[BRIDGE_EXECUTION_POLICY_ENV] === "coordinator-read-only";
|
|
9861
9682
|
}
|
|
9862
|
-
function
|
|
9863
|
-
|
|
9683
|
+
function coordinatorProcessPolicy(env = process.env) {
|
|
9684
|
+
return {
|
|
9685
|
+
id: "coordinator-read-only",
|
|
9686
|
+
sandbox: "provider",
|
|
9687
|
+
approvals: "deny",
|
|
9688
|
+
projectResources: false,
|
|
9689
|
+
capabilityPolicy: coordinatorCapabilityPolicy(coordinatorWebResearchFromEnv(env)),
|
|
9690
|
+
networkAccess: "restricted"
|
|
9691
|
+
};
|
|
9692
|
+
}
|
|
9693
|
+
function effectiveExecutionPolicy(requested, env = process.env) {
|
|
9694
|
+
if (!processExecutionPolicyIsCoordinator(env))
|
|
9695
|
+
return requested;
|
|
9696
|
+
return coordinatorProcessPolicy();
|
|
9697
|
+
}
|
|
9698
|
+
|
|
9699
|
+
// ../../bridges/claude-bridge/src/services/read-only-connection-env.ts
|
|
9700
|
+
var log4 = createLogger("bridge.claude");
|
|
9701
|
+
var READ_ONLY_CONNECTION_ENV_NAMES = new Set([
|
|
9702
|
+
"ANTHROPIC_API_KEY",
|
|
9703
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
9704
|
+
"ANTHROPIC_BASE_URL",
|
|
9705
|
+
"ANTHROPIC_CUSTOM_HEADERS",
|
|
9706
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
9707
|
+
"ANTHROPIC_MODEL",
|
|
9708
|
+
"ANTHROPIC_SMALL_FAST_MODEL",
|
|
9709
|
+
"ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION",
|
|
9710
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
9711
|
+
"CLAUDE_CODE_SKIP_BEDROCK_AUTH",
|
|
9712
|
+
"ANTHROPIC_BEDROCK_BASE_URL",
|
|
9713
|
+
"AWS_REGION",
|
|
9714
|
+
"AWS_DEFAULT_REGION",
|
|
9715
|
+
"AWS_ACCESS_KEY_ID",
|
|
9716
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
9717
|
+
"AWS_SESSION_TOKEN",
|
|
9718
|
+
"AWS_BEARER_TOKEN_BEDROCK",
|
|
9719
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
9720
|
+
"CLAUDE_CODE_SKIP_VERTEX_AUTH",
|
|
9721
|
+
"ANTHROPIC_VERTEX_PROJECT_ID",
|
|
9722
|
+
"ANTHROPIC_VERTEX_BASE_URL",
|
|
9723
|
+
"CLOUD_ML_REGION",
|
|
9724
|
+
"GOOGLE_CLOUD_PROJECT",
|
|
9725
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
9726
|
+
"CLAUDE_CODE_USE_FOUNDRY",
|
|
9727
|
+
"CLAUDE_CODE_SKIP_FOUNDRY_AUTH",
|
|
9728
|
+
"ANTHROPIC_FOUNDRY_API_KEY",
|
|
9729
|
+
"ANTHROPIC_FOUNDRY_BASE_URL",
|
|
9730
|
+
"ANTHROPIC_FOUNDRY_RESOURCE",
|
|
9731
|
+
"HTTPS_PROXY",
|
|
9732
|
+
"https_proxy",
|
|
9733
|
+
"HTTP_PROXY",
|
|
9734
|
+
"http_proxy",
|
|
9735
|
+
"NO_PROXY",
|
|
9736
|
+
"no_proxy",
|
|
9737
|
+
"NODE_EXTRA_CA_CERTS",
|
|
9738
|
+
"CLAUDE_CODE_CLIENT_CERT",
|
|
9739
|
+
"CLAUDE_CODE_CLIENT_KEY",
|
|
9740
|
+
"CLAUDE_CODE_CLIENT_KEY_PASSPHRASE"
|
|
9741
|
+
]);
|
|
9742
|
+
var READ_ONLY_CONNECTION_ENV_PATTERNS = [
|
|
9743
|
+
/^ANTHROPIC_DEFAULT_[A-Z0-9]+_MODEL$/,
|
|
9744
|
+
/^VERTEX_REGION_CLAUDE_[A-Z0-9_]+$/
|
|
9745
|
+
];
|
|
9746
|
+
var MAX_CONNECTION_ENV_ENTRIES = 64;
|
|
9747
|
+
var MAX_CONNECTION_ENV_VALUE_BYTES = 16 * 1024;
|
|
9748
|
+
function isReadOnlyConnectionEnvName(name) {
|
|
9749
|
+
return READ_ONLY_CONNECTION_ENV_NAMES.has(name) || READ_ONLY_CONNECTION_ENV_PATTERNS.some((pattern) => pattern.test(name));
|
|
9750
|
+
}
|
|
9751
|
+
function selectReadOnlyConnectionEnv(settings) {
|
|
9752
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings))
|
|
9753
|
+
return {};
|
|
9754
|
+
const env = settings.env;
|
|
9755
|
+
if (!env || typeof env !== "object" || Array.isArray(env))
|
|
9756
|
+
return {};
|
|
9757
|
+
const selected = {};
|
|
9758
|
+
let count = 0;
|
|
9759
|
+
for (const [name, raw] of Object.entries(env)) {
|
|
9760
|
+
if (!isReadOnlyConnectionEnvName(name))
|
|
9761
|
+
continue;
|
|
9762
|
+
const value = typeof raw === "string" ? raw : typeof raw === "number" || typeof raw === "boolean" ? String(raw) : undefined;
|
|
9763
|
+
if (value === undefined || value.includes("\x00"))
|
|
9764
|
+
continue;
|
|
9765
|
+
if (Buffer.byteLength(value, "utf8") > MAX_CONNECTION_ENV_VALUE_BYTES)
|
|
9766
|
+
continue;
|
|
9767
|
+
if (++count > MAX_CONNECTION_ENV_ENTRIES)
|
|
9768
|
+
break;
|
|
9769
|
+
selected[name] = value;
|
|
9770
|
+
}
|
|
9771
|
+
return selected;
|
|
9772
|
+
}
|
|
9773
|
+
async function readUserSettingsConnectionEnv(settingsPath = claudeUserSettingsPath()) {
|
|
9774
|
+
const selected = await readJsonSliceCached(settingsPath, "read-only-connection-env", selectReadOnlyConnectionEnv);
|
|
9775
|
+
return selected ?? {};
|
|
9776
|
+
}
|
|
9777
|
+
var BEDROCK_AUTH_ENV_NAMES = [
|
|
9778
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
9779
|
+
"CLAUDE_CODE_SKIP_BEDROCK_AUTH",
|
|
9780
|
+
"AWS_BEARER_TOKEN_BEDROCK",
|
|
9781
|
+
"AWS_ACCESS_KEY_ID",
|
|
9782
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
9783
|
+
"AWS_SESSION_TOKEN"
|
|
9784
|
+
];
|
|
9785
|
+
var FALSE_FLAG_VALUES = new Set(["", "0", "false", "no", "off"]);
|
|
9786
|
+
var TRUE_FLAG_VALUES = new Set(["1", "true", "yes", "on"]);
|
|
9787
|
+
function flagMayBeOn(value) {
|
|
9788
|
+
return value !== undefined && !FALSE_FLAG_VALUES.has(value.trim().toLowerCase());
|
|
9789
|
+
}
|
|
9790
|
+
function flagIsOn(value) {
|
|
9791
|
+
return value !== undefined && TRUE_FLAG_VALUES.has(value.trim().toLowerCase());
|
|
9792
|
+
}
|
|
9793
|
+
function bedrockResolvesAwsProfiles(environment) {
|
|
9794
|
+
if (!flagMayBeOn(environment.CLAUDE_CODE_USE_BEDROCK))
|
|
9864
9795
|
return false;
|
|
9865
|
-
|
|
9866
|
-
const first = positionals[0];
|
|
9867
|
-
if (first && GIT_CONFIG_WRITE_SUBCOMMANDS.has(first))
|
|
9796
|
+
if (flagIsOn(environment.CLAUDE_CODE_SKIP_BEDROCK_AUTH))
|
|
9868
9797
|
return false;
|
|
9869
|
-
if (
|
|
9870
|
-
return
|
|
9871
|
-
|
|
9872
|
-
return true;
|
|
9873
|
-
return positionals.length <= 1;
|
|
9798
|
+
if (environment.AWS_BEARER_TOKEN_BEDROCK?.trim())
|
|
9799
|
+
return false;
|
|
9800
|
+
return !(environment.AWS_ACCESS_KEY_ID?.trim() && environment.AWS_SECRET_ACCESS_KEY?.trim());
|
|
9874
9801
|
}
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9802
|
+
function readOnlyConnectionOverlay(environment, connection) {
|
|
9803
|
+
if (!bedrockResolvesAwsProfiles({ ...environment, ...connection }) || bedrockResolvesAwsProfiles(environment)) {
|
|
9804
|
+
return { overlay: connection, withheldBedrock: false };
|
|
9805
|
+
}
|
|
9806
|
+
const overlay = { ...connection };
|
|
9807
|
+
for (const name of BEDROCK_AUTH_ENV_NAMES)
|
|
9808
|
+
delete overlay[name];
|
|
9809
|
+
return { overlay, withheldBedrock: true };
|
|
9810
|
+
}
|
|
9811
|
+
async function withReadOnlyConnectionEnv(turnPolicy, environment, readConnectionEnv = () => readUserSettingsConnectionEnv()) {
|
|
9812
|
+
if (!isCoordinatorReadOnlyPolicy(turnPolicy))
|
|
9813
|
+
return environment;
|
|
9814
|
+
const connection = await readConnectionEnv();
|
|
9815
|
+
if (Object.keys(connection).length === 0)
|
|
9816
|
+
return environment;
|
|
9817
|
+
const { overlay, withheldBedrock } = readOnlyConnectionOverlay(environment, connection);
|
|
9818
|
+
if (withheldBedrock) {
|
|
9819
|
+
log4.warn("read-only-connection.bedrock-withheld");
|
|
9820
|
+
}
|
|
9821
|
+
if (Object.keys(overlay).length === 0)
|
|
9822
|
+
return environment;
|
|
9823
|
+
return { ...environment, ...overlay };
|
|
9824
|
+
}
|
|
9825
|
+
function connectionEnvFingerprint(environment) {
|
|
9826
|
+
return Object.entries(environment).filter((entry) => typeof entry[1] === "string" && isReadOnlyConnectionEnvName(entry[0])).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
|
|
9827
|
+
}
|
|
9828
|
+
|
|
9829
|
+
// ../../bridges/claude-bridge/src/services/coordinator-skills.ts
|
|
9830
|
+
import { createHash as createHash5, randomBytes } from "node:crypto";
|
|
9831
|
+
import {
|
|
9832
|
+
mkdir as mkdir2,
|
|
9833
|
+
readdir as readdir2,
|
|
9834
|
+
readFile as readFile4,
|
|
9835
|
+
realpath,
|
|
9836
|
+
rename as rename2,
|
|
9837
|
+
rm as rm2,
|
|
9838
|
+
stat as stat3,
|
|
9839
|
+
symlink,
|
|
9840
|
+
writeFile as writeFile2
|
|
9841
|
+
} from "node:fs/promises";
|
|
9842
|
+
import { isAbsolute as isAbsolute2, join as join5 } from "node:path";
|
|
9843
|
+
var KEPT_FRONTMATTER_KEYS = Object.freeze([
|
|
9844
|
+
"name",
|
|
9845
|
+
"description",
|
|
9846
|
+
"when_to_use",
|
|
9847
|
+
"argument-hint",
|
|
9848
|
+
"arguments",
|
|
9849
|
+
"disable-model-invocation",
|
|
9850
|
+
"user-invocable",
|
|
9851
|
+
"version"
|
|
9886
9852
|
]);
|
|
9887
|
-
var
|
|
9888
|
-
var
|
|
9889
|
-
var
|
|
9890
|
-
|
|
9891
|
-
|
|
9853
|
+
var MIRROR_FORMAT = 1;
|
|
9854
|
+
var MAX_SKILLS_PER_SOURCE = 256;
|
|
9855
|
+
var MAX_SKILL_FILE_BYTES = 1024 * 1024;
|
|
9856
|
+
var MAX_ENTRIES_PER_SKILL = 256;
|
|
9857
|
+
var KEPT_OLD_MIRRORS = 4;
|
|
9858
|
+
var SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
9859
|
+
var FRONTMATTER = /^?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
9860
|
+
function coordinatorSkillSources(cwd, env = process.env) {
|
|
9861
|
+
const userDir = env[COORDINATOR_CLAUDE_USER_SKILLS_DIR_ENV]?.trim();
|
|
9862
|
+
return [
|
|
9863
|
+
...userDir && isAbsolute2(userDir) ? [{ plugin: "user-skills", dir: userDir }] : [],
|
|
9864
|
+
{ plugin: "project-skills", dir: join5(cwd, ".claude", "skills") }
|
|
9865
|
+
];
|
|
9892
9866
|
}
|
|
9893
|
-
function
|
|
9894
|
-
const
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9867
|
+
async function coordinatorSkillPlugins(sources, root = claudeCoordinatorSkillPluginsDir()) {
|
|
9868
|
+
const plugins = [];
|
|
9869
|
+
const skills = [];
|
|
9870
|
+
for (const source of sources) {
|
|
9871
|
+
try {
|
|
9872
|
+
const mirror = await mirrorSkillSource(source, root);
|
|
9873
|
+
if (!mirror)
|
|
9874
|
+
continue;
|
|
9875
|
+
plugins.push({ type: "local", path: mirror.path });
|
|
9876
|
+
skills.push(...mirror.names.map((name) => `${source.plugin}:${name}`));
|
|
9877
|
+
} catch (error) {
|
|
9878
|
+
debugLog("[coordinator-skills] Skipping skills source", {
|
|
9879
|
+
plugin: source.plugin,
|
|
9880
|
+
error: error instanceof Error ? error.message : String(error)
|
|
9881
|
+
});
|
|
9882
|
+
}
|
|
9883
|
+
}
|
|
9884
|
+
return { plugins, skills };
|
|
9885
|
+
}
|
|
9886
|
+
async function mirrorSkillSource(source, root) {
|
|
9887
|
+
const dir = await realpath(source.dir).catch(() => {
|
|
9888
|
+
return;
|
|
9889
|
+
});
|
|
9890
|
+
if (!dir)
|
|
9891
|
+
return;
|
|
9892
|
+
const skills = await readSkills(dir);
|
|
9893
|
+
if (skills.length === 0)
|
|
9894
|
+
return;
|
|
9895
|
+
const digest = createHash5("sha256").update(JSON.stringify([MIRROR_FORMAT, source.plugin, dir, skills])).digest("hex").slice(0, 24);
|
|
9896
|
+
const path = join5(root, `${source.plugin}-${digest}`);
|
|
9897
|
+
if (!await isMirror(path))
|
|
9898
|
+
await writeMirror(root, path, source.plugin, skills);
|
|
9899
|
+
await pruneOldMirrors(root, source.plugin, path);
|
|
9900
|
+
return { path, names: skills.map((skill) => skill.name) };
|
|
9901
|
+
}
|
|
9902
|
+
async function readSkills(dir) {
|
|
9903
|
+
const entries = (await readdir2(dir)).filter((name) => !name.startsWith(".")).sort();
|
|
9904
|
+
const skills = [];
|
|
9905
|
+
const names = new Set;
|
|
9906
|
+
for (const entry of entries) {
|
|
9907
|
+
if (skills.length >= MAX_SKILLS_PER_SOURCE)
|
|
9908
|
+
break;
|
|
9909
|
+
const skillDir = await realpath(join5(dir, entry)).catch(() => {
|
|
9910
|
+
return;
|
|
9911
|
+
});
|
|
9912
|
+
if (!skillDir || !(await stat3(skillDir).catch(() => {
|
|
9913
|
+
return;
|
|
9914
|
+
}))?.isDirectory())
|
|
9915
|
+
continue;
|
|
9916
|
+
const skill = await readSkill(skillDir, entry);
|
|
9917
|
+
if (!skill || names.has(skill.name))
|
|
9899
9918
|
continue;
|
|
9919
|
+
names.add(skill.name);
|
|
9920
|
+
skills.push(skill);
|
|
9921
|
+
}
|
|
9922
|
+
return skills;
|
|
9923
|
+
}
|
|
9924
|
+
async function readSkill(skillDir, dirName) {
|
|
9925
|
+
const entries = await readdir2(skillDir);
|
|
9926
|
+
const skillFile = entries.find((entry) => entry === "SKILL.md");
|
|
9927
|
+
if (!skillFile)
|
|
9928
|
+
return;
|
|
9929
|
+
const file = join5(skillDir, skillFile);
|
|
9930
|
+
const info = await stat3(file).catch(() => {
|
|
9931
|
+
return;
|
|
9932
|
+
});
|
|
9933
|
+
if (!info?.isFile() || info.size > MAX_SKILL_FILE_BYTES)
|
|
9934
|
+
return;
|
|
9935
|
+
const sanitized = sanitizeSkillFile(await readFile4(file, "utf8"), dirName);
|
|
9936
|
+
if (!sanitized) {
|
|
9937
|
+
debugLog("[coordinator-skills] Skipping skill with unreadable frontmatter", { dirName });
|
|
9938
|
+
return;
|
|
9939
|
+
}
|
|
9940
|
+
const links = entries.filter((entry) => entry.toLowerCase() !== "skill.md").sort().slice(0, MAX_ENTRIES_PER_SKILL).map((entry) => [entry, join5(skillDir, entry)]);
|
|
9941
|
+
return { name: sanitized.name, text: sanitized.text, links };
|
|
9942
|
+
}
|
|
9943
|
+
function yamlParser() {
|
|
9944
|
+
const parse = globalThis.Bun?.YAML?.parse;
|
|
9945
|
+
return typeof parse === "function" ? parse : null;
|
|
9946
|
+
}
|
|
9947
|
+
function sanitizeSkillFile(text, dirName, parse = yamlParser()) {
|
|
9948
|
+
const match = FRONTMATTER.exec(text);
|
|
9949
|
+
let fields = {};
|
|
9950
|
+
if (match) {
|
|
9951
|
+
if (!parse)
|
|
9952
|
+
return;
|
|
9953
|
+
let parsed;
|
|
9954
|
+
try {
|
|
9955
|
+
parsed = parse(match[1]);
|
|
9956
|
+
} catch {
|
|
9957
|
+
return;
|
|
9958
|
+
}
|
|
9959
|
+
if (parsed !== null && parsed !== undefined) {
|
|
9960
|
+
if (typeof parsed !== "object" || Array.isArray(parsed))
|
|
9961
|
+
return;
|
|
9962
|
+
fields = parsed;
|
|
9900
9963
|
}
|
|
9901
|
-
for (const tool of CAPABILITY_TOOLS.get(capability) ?? [])
|
|
9902
|
-
tools.add(tool);
|
|
9903
9964
|
}
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9965
|
+
const declared = typeof fields.name === "string" ? fields.name.trim() : "";
|
|
9966
|
+
const name = SKILL_NAME.test(declared) ? declared : dirName;
|
|
9967
|
+
if (!SKILL_NAME.test(name))
|
|
9968
|
+
return;
|
|
9969
|
+
const lines = [`name: ${JSON.stringify(name)}`];
|
|
9970
|
+
for (const key of KEPT_FRONTMATTER_KEYS) {
|
|
9971
|
+
if (key === "name" || !Object.hasOwn(fields, key))
|
|
9972
|
+
continue;
|
|
9973
|
+
const value = frontmatterValue(fields[key]);
|
|
9974
|
+
if (value !== undefined)
|
|
9975
|
+
lines.push(`${key}: ${value}`);
|
|
9976
|
+
}
|
|
9977
|
+
const body = match ? text.slice(match[0].length) : text.replace(/^/, "");
|
|
9978
|
+
return { name, text: `---
|
|
9979
|
+
${lines.join(`
|
|
9980
|
+
`)}
|
|
9981
|
+
---
|
|
9982
|
+
${body}` };
|
|
9983
|
+
}
|
|
9984
|
+
function frontmatterValue(value) {
|
|
9985
|
+
if (typeof value === "string" || typeof value === "boolean")
|
|
9986
|
+
return JSON.stringify(value);
|
|
9987
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
9988
|
+
return JSON.stringify(String(value));
|
|
9989
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string"))
|
|
9990
|
+
return JSON.stringify(value);
|
|
9991
|
+
return;
|
|
9992
|
+
}
|
|
9993
|
+
async function isMirror(path) {
|
|
9994
|
+
return (await stat3(join5(path, ".claude-plugin", "plugin.json")).catch(() => {
|
|
9995
|
+
return;
|
|
9996
|
+
}))?.isFile() ? true : false;
|
|
9997
|
+
}
|
|
9998
|
+
async function writeMirror(root, path, plugin, skills) {
|
|
9999
|
+
await mkdir2(root, { recursive: true, mode: 448 });
|
|
10000
|
+
const staging = join5(root, `.staging-${randomBytes(8).toString("hex")}`);
|
|
10001
|
+
try {
|
|
10002
|
+
await mkdir2(join5(staging, ".claude-plugin"), { recursive: true });
|
|
10003
|
+
await writeFile2(join5(staging, ".claude-plugin", "plugin.json"), JSON.stringify({
|
|
10004
|
+
name: plugin,
|
|
10005
|
+
description: plugin === "user-skills" ? "The user's own Claude skills, mirrored by Orkestrator without hooks or tool grants." : "This project's .claude/skills, mirrored by Orkestrator without hooks or tool grants."
|
|
10006
|
+
}));
|
|
10007
|
+
for (const skill of skills) {
|
|
10008
|
+
const skillDir = join5(staging, "skills", skill.name);
|
|
10009
|
+
await mkdir2(skillDir, { recursive: true });
|
|
10010
|
+
await writeFile2(join5(skillDir, "SKILL.md"), skill.text);
|
|
10011
|
+
for (const [name, target] of skill.links)
|
|
10012
|
+
await symlink(target, join5(skillDir, name));
|
|
10013
|
+
}
|
|
10014
|
+
try {
|
|
10015
|
+
await rename2(staging, path);
|
|
10016
|
+
} catch (error) {
|
|
10017
|
+
if (!await isMirror(path))
|
|
10018
|
+
throw error;
|
|
10019
|
+
}
|
|
10020
|
+
} finally {
|
|
10021
|
+
await rm2(staging, { recursive: true, force: true });
|
|
10022
|
+
}
|
|
9907
10023
|
}
|
|
9908
|
-
function
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
10024
|
+
async function pruneOldMirrors(root, plugin, current) {
|
|
10025
|
+
try {
|
|
10026
|
+
const old = await Promise.all((await readdir2(root)).filter((name) => name.startsWith(`${plugin}-`) && join5(root, name) !== current).map(async (name) => ({
|
|
10027
|
+
path: join5(root, name),
|
|
10028
|
+
mtimeMs: (await stat3(join5(root, name)).catch(() => {
|
|
10029
|
+
return;
|
|
10030
|
+
}))?.mtimeMs ?? 0
|
|
10031
|
+
})));
|
|
10032
|
+
old.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
10033
|
+
for (const { path } of old.slice(KEPT_OLD_MIRRORS)) {
|
|
10034
|
+
await rm2(path, { recursive: true, force: true });
|
|
10035
|
+
}
|
|
10036
|
+
} catch {}
|
|
9913
10037
|
}
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
10038
|
+
|
|
10039
|
+
// ../../bridges/claude-bridge/src/services/plugin-config.ts
|
|
10040
|
+
import { readdir as readdir3, access } from "node:fs/promises";
|
|
10041
|
+
import { join as join6 } from "node:path";
|
|
10042
|
+
|
|
10043
|
+
// ../protocol/src/node/claude-plugin-set.ts
|
|
10044
|
+
import path2 from "node:path";
|
|
10045
|
+
var CLAUDE_PLUGINS_MARKER = "/.claude/plugins/";
|
|
10046
|
+
function isRecord(value) {
|
|
10047
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9923
10048
|
}
|
|
9924
|
-
function
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
filesystem: {
|
|
9932
|
-
denyWrite: [...new Set(options.workspaces ?? [])],
|
|
9933
|
-
...options.readBoundary ? { denyRead: options.readBoundary.deny, allowRead: options.readBoundary.allow } : {}
|
|
9934
|
-
},
|
|
9935
|
-
network: {
|
|
9936
|
-
allowLocalBinding: policy.networkAccess === "full",
|
|
9937
|
-
strictAllowlist: true,
|
|
9938
|
-
allowedDomains: []
|
|
10049
|
+
function claudePluginConfigList(value) {
|
|
10050
|
+
if (!Array.isArray(value))
|
|
10051
|
+
return [];
|
|
10052
|
+
const plugins = [];
|
|
10053
|
+
for (const item of value) {
|
|
10054
|
+
if (isRecord(item) && typeof item.path === "string" && item.path) {
|
|
10055
|
+
plugins.push({ type: "local", path: item.path });
|
|
9939
10056
|
}
|
|
9940
|
-
}
|
|
10057
|
+
}
|
|
10058
|
+
return plugins;
|
|
9941
10059
|
}
|
|
9942
|
-
function
|
|
9943
|
-
|
|
9944
|
-
|
|
9945
|
-
return !readOnlyTurn && isCoordinatorReadOnlyPolicy(sessionPolicy) ? "coordinator" : "read-only";
|
|
10060
|
+
function isPathWithin(parentDir, candidatePath) {
|
|
10061
|
+
const relativePath = path2.relative(parentDir, candidatePath);
|
|
10062
|
+
return relativePath === "" || !relativePath.startsWith("..") && !path2.isAbsolute(relativePath);
|
|
9946
10063
|
}
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
network: (described) => `Commands in this session have no network access, so \`${described}\` is not available here.`,
|
|
9974
|
-
tool: (tool) => `This session is read-only, so ${tool} is not available.`,
|
|
9975
|
-
waiting: (tool) => `This session's turns do not wait, so ${tool} is not available. End your turn instead.`,
|
|
9976
|
-
mcp: (tool) => `This session may only use Orkestrator's own tools and the MCP servers granted to it, so ${tool} is not available.`,
|
|
9977
|
-
unsandboxed: "Commands in this session may not run outside the sandbox.",
|
|
9978
|
-
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."
|
|
9979
|
-
}
|
|
9980
|
-
};
|
|
9981
|
-
function isReadOnlyShellCommand(command, options = {}) {
|
|
9982
|
-
const refusals = REFUSALS[options.role ?? "coordinator"];
|
|
9983
|
-
const trimmed = command.trim();
|
|
9984
|
-
if (!trimmed)
|
|
9985
|
-
return { allowed: true };
|
|
9986
|
-
if (COMPOSITION_PATTERN.test(trimmed) || /(?:^|\s)~/.test(trimmed)) {
|
|
9987
|
-
return { allowed: false, reason: refusals.composition };
|
|
9988
|
-
}
|
|
9989
|
-
const tokens = trimmed.split(/\s+/).filter(Boolean);
|
|
9990
|
-
const first = tokens[0] ?? "";
|
|
9991
|
-
if (!first)
|
|
9992
|
-
return { allowed: true };
|
|
9993
|
-
if (first.includes("/") || first.includes("\\")) {
|
|
9994
|
-
return { allowed: false, reason: refusals.byPath(first) };
|
|
9995
|
-
}
|
|
9996
|
-
const program = first;
|
|
9997
|
-
if (NETWORK_COMMANDS.has(program))
|
|
9998
|
-
return { allowed: false, reason: refusals.network(program) };
|
|
9999
|
-
if (program === "git") {
|
|
10000
|
-
if (options.commandSandbox !== "required") {
|
|
10001
|
-
return { allowed: false, reason: refusals.gitSandbox };
|
|
10002
|
-
}
|
|
10003
|
-
const subcommandIndex = tokens.findIndex((token, index) => index > 0 && !token.startsWith("-"));
|
|
10004
|
-
const subcommand = subcommandIndex > 0 ? tokens[subcommandIndex] : undefined;
|
|
10005
|
-
const args = subcommandIndex > 0 ? tokens.slice(subcommandIndex + 1) : [];
|
|
10006
|
-
const globalOptions = tokens.slice(1, subcommandIndex > 0 ? subcommandIndex : undefined);
|
|
10007
|
-
const unlisted = globalOptions.find((option) => !GIT_GLOBAL_OPTIONS.has(option));
|
|
10008
|
-
if (unlisted)
|
|
10009
|
-
return { allowed: false, reason: refusals.gitGlobalOption(unlisted) };
|
|
10010
|
-
if (subcommand && (NETWORK_GIT_SUBCOMMANDS.has(subcommand) || subcommand === "remote" && args.some((arg) => arg === "show"))) {
|
|
10011
|
-
return { allowed: false, reason: refusals.network(`git ${subcommand}`) };
|
|
10012
|
-
}
|
|
10013
|
-
const permitted = subcommand !== undefined && (READ_ONLY_GIT_SUBCOMMANDS.has(subcommand) || (CONDITIONAL_GIT_SUBCOMMANDS.get(subcommand)?.(args) ?? false));
|
|
10014
|
-
const described = ["git", subcommand].filter(Boolean).join(" ");
|
|
10015
|
-
if (!permitted) {
|
|
10016
|
-
return { allowed: false, reason: refusals.unavailable(described) };
|
|
10017
|
-
}
|
|
10018
|
-
if (hasFlag(tokens.slice(1), GIT_MUTATING_ARGUMENTS) || hasFlag(args, GIT_SUBCOMMAND_MUTATING_ARGUMENTS.get(subcommand) ?? new Set)) {
|
|
10019
|
-
return { allowed: false, reason: refusals.gitArgument(described) };
|
|
10064
|
+
function remapInstalledPlugins(pluginsDir, installedPlugins, onUnsafe) {
|
|
10065
|
+
const plugins = [];
|
|
10066
|
+
const pluginsRoot = path2.resolve(pluginsDir);
|
|
10067
|
+
if (!isRecord(installedPlugins.plugins))
|
|
10068
|
+
return plugins;
|
|
10069
|
+
for (const [installedId, entries] of Object.entries(installedPlugins.plugins)) {
|
|
10070
|
+
if (!Array.isArray(entries))
|
|
10071
|
+
continue;
|
|
10072
|
+
for (const entry of entries) {
|
|
10073
|
+
if (!isRecord(entry) || typeof entry.installPath !== "string")
|
|
10074
|
+
continue;
|
|
10075
|
+
const installPath = entry.installPath;
|
|
10076
|
+
const markerIdx = installPath.indexOf(CLAUDE_PLUGINS_MARKER);
|
|
10077
|
+
let resolvedPath;
|
|
10078
|
+
if (markerIdx !== -1) {
|
|
10079
|
+
const relativePath = installPath.substring(markerIdx + CLAUDE_PLUGINS_MARKER.length);
|
|
10080
|
+
const remappedPath = path2.resolve(pluginsDir, relativePath);
|
|
10081
|
+
if (!isPathWithin(pluginsRoot, remappedPath)) {
|
|
10082
|
+
onUnsafe?.(installPath);
|
|
10083
|
+
continue;
|
|
10084
|
+
}
|
|
10085
|
+
resolvedPath = remappedPath;
|
|
10086
|
+
} else {
|
|
10087
|
+
resolvedPath = installPath;
|
|
10088
|
+
}
|
|
10089
|
+
plugins.push({ type: "local", path: resolvedPath, installedId });
|
|
10020
10090
|
}
|
|
10021
|
-
return { allowed: true };
|
|
10022
10091
|
}
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10092
|
+
return plugins;
|
|
10093
|
+
}
|
|
10094
|
+
function resolveClaudePluginPath(pluginPath, cwd, home) {
|
|
10095
|
+
if (pluginPath.startsWith("~"))
|
|
10096
|
+
return path2.join(home, pluginPath.slice(1));
|
|
10097
|
+
if (pluginPath.startsWith("/"))
|
|
10098
|
+
return pluginPath;
|
|
10099
|
+
return path2.join(cwd, pluginPath);
|
|
10100
|
+
}
|
|
10101
|
+
function mergeClaudePluginLayers(layers, options) {
|
|
10102
|
+
const ordered = [
|
|
10103
|
+
claudePluginConfigList(layers.global),
|
|
10104
|
+
layers.cliInstalled,
|
|
10105
|
+
...options.includeProjectSources ? [claudePluginConfigList(layers.projectGlobal), claudePluginConfigList(layers.projectLocal)] : []
|
|
10106
|
+
];
|
|
10107
|
+
const seen = new Set;
|
|
10108
|
+
const paths = [];
|
|
10109
|
+
for (const layer of ordered) {
|
|
10110
|
+
for (const plugin of layer) {
|
|
10111
|
+
const resolved = resolveClaudePluginPath(plugin.path, options.cwd, options.home);
|
|
10112
|
+
if (seen.has(resolved))
|
|
10113
|
+
continue;
|
|
10114
|
+
seen.add(resolved);
|
|
10115
|
+
paths.push(resolved);
|
|
10030
10116
|
}
|
|
10031
|
-
return { allowed: true };
|
|
10032
10117
|
}
|
|
10033
|
-
return
|
|
10118
|
+
return paths;
|
|
10034
10119
|
}
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
if (!
|
|
10120
|
+
var INVALID_PLUGIN_NAME = new RegExp("[@:\\s/\\\\\\u0000-\\u001f\\u007f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]");
|
|
10121
|
+
var CLAUDE_PLUGIN_SETTING_SOURCES = ["local", "project", "user"];
|
|
10122
|
+
function claudeInstalledPluginIdEnablement(id, settings, loadedSources) {
|
|
10123
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10124
|
+
for (const source of ["local", "project", "user"]) {
|
|
10125
|
+
if (!loadedSources.includes(source))
|
|
10041
10126
|
continue;
|
|
10042
|
-
|
|
10043
|
-
|
|
10127
|
+
const document = settings[source];
|
|
10128
|
+
const enabledPlugins = isRecord(document) ? document.enabledPlugins : undefined;
|
|
10129
|
+
if (!isRecord(enabledPlugins) || !Object.hasOwn(enabledPlugins, id))
|
|
10044
10130
|
continue;
|
|
10131
|
+
return { enabled: enabledPlugins[id] === true, decidedBy: { source, key: id } };
|
|
10132
|
+
}
|
|
10133
|
+
return { enabled: false };
|
|
10134
|
+
}
|
|
10135
|
+
function enabledInstalledPlugins(plugins, settings, loadedSources) {
|
|
10136
|
+
return plugins.filter((plugin) => plugin.installedId === undefined || claudeInstalledPluginIdEnablement(plugin.installedId, settings, loadedSources).enabled);
|
|
10137
|
+
}
|
|
10138
|
+
function claudePluginSettingSources(settingSources) {
|
|
10139
|
+
return CLAUDE_PLUGIN_SETTING_SOURCES.filter((source) => settingSources.includes(source));
|
|
10140
|
+
}
|
|
10141
|
+
|
|
10142
|
+
// ../../bridges/claude-bridge/src/services/plugin-config.ts
|
|
10143
|
+
var log5 = createLogger("bridge.claude");
|
|
10144
|
+
async function pathExists(path) {
|
|
10145
|
+
try {
|
|
10146
|
+
await access(path);
|
|
10147
|
+
return true;
|
|
10148
|
+
} catch {
|
|
10149
|
+
return false;
|
|
10150
|
+
}
|
|
10151
|
+
}
|
|
10152
|
+
async function scanCliPluginsDirectory(pluginsDir) {
|
|
10153
|
+
if (!await pathExists(pluginsDir)) {
|
|
10154
|
+
return [];
|
|
10155
|
+
}
|
|
10156
|
+
try {
|
|
10157
|
+
const entries = await readdir3(pluginsDir, { withFileTypes: true });
|
|
10158
|
+
const plugins = [];
|
|
10159
|
+
for (const entry of entries) {
|
|
10160
|
+
if (!entry.isDirectory()) {
|
|
10161
|
+
continue;
|
|
10162
|
+
}
|
|
10163
|
+
const pluginPath = join6(pluginsDir, entry.name);
|
|
10164
|
+
const manifestPath = join6(pluginPath, ".claude-plugin", "plugin.json");
|
|
10165
|
+
if (await pathExists(manifestPath)) {
|
|
10166
|
+
plugins.push({
|
|
10167
|
+
type: "local",
|
|
10168
|
+
path: pluginPath
|
|
10169
|
+
});
|
|
10170
|
+
}
|
|
10045
10171
|
}
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
return false;
|
|
10172
|
+
return plugins;
|
|
10173
|
+
} catch {
|
|
10174
|
+
return [];
|
|
10050
10175
|
}
|
|
10051
|
-
return true;
|
|
10052
10176
|
}
|
|
10053
|
-
function
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
count += 1;
|
|
10068
|
-
if (stopAtFirstOperand)
|
|
10069
|
-
optionsEnded = true;
|
|
10177
|
+
async function loadGlobalPlugins() {
|
|
10178
|
+
const plugins = await readJsonSliceCached(claudeJsonPath(), "plugins", (config) => claudePluginConfigList(config?.plugins));
|
|
10179
|
+
return plugins ?? [];
|
|
10180
|
+
}
|
|
10181
|
+
async function loadProjectPlugins(cwd) {
|
|
10182
|
+
const plugins = await readJsonSliceCached(join6(cwd, ".claude", "plugins.json"), "plugins", (config) => claudePluginConfigList(config?.plugins));
|
|
10183
|
+
return plugins ?? [];
|
|
10184
|
+
}
|
|
10185
|
+
async function loadCliInstalledPlugins() {
|
|
10186
|
+
const pluginsDir = claudePluginsDir();
|
|
10187
|
+
const installedPluginsPath = join6(pluginsDir, "installed_plugins.json");
|
|
10188
|
+
const plugins = await readJsonSliceCached(installedPluginsPath, "plugins", (config) => config?.plugins);
|
|
10189
|
+
if (!plugins) {
|
|
10190
|
+
return scanCliPluginsDirectory(pluginsDir);
|
|
10070
10191
|
}
|
|
10071
|
-
return
|
|
10192
|
+
return remapInstalledPlugins2(pluginsDir, { plugins });
|
|
10072
10193
|
}
|
|
10073
|
-
function
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10194
|
+
function pluginSettingsPath(source, cwd) {
|
|
10195
|
+
switch (source) {
|
|
10196
|
+
case "user":
|
|
10197
|
+
return claudeUserSettingsPath();
|
|
10198
|
+
case "project":
|
|
10199
|
+
return join6(cwd, ".claude", "settings.json");
|
|
10200
|
+
case "local":
|
|
10201
|
+
return join6(cwd, ".claude", "settings.local.json");
|
|
10202
|
+
}
|
|
10081
10203
|
}
|
|
10082
|
-
function
|
|
10083
|
-
const
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
...researchMcpServerNames.map(claudeMcpToolPrefix),
|
|
10089
|
-
...(nativeAgentUserMcpGrant(policy) ?? []).map(claudeMcpToolPrefix)
|
|
10090
|
-
];
|
|
10091
|
-
const readBoundary = (cwd) => options.readBoundary !== undefined ? options.readBoundary : process.env[COORDINATOR_PROTECTED_DATA_DIR_ENV] ? coordinatorReadBoundary(claudeReadOnlyWorkspacePaths(cwd)) : null;
|
|
10092
|
-
return async (input) => {
|
|
10093
|
-
if (input.hook_event_name !== "PreToolUse")
|
|
10094
|
-
return {};
|
|
10095
|
-
const toolName = input.tool_name;
|
|
10096
|
-
if (deniedTools.has(toolName)) {
|
|
10097
|
-
return deny(refusals.tool(toolName));
|
|
10098
|
-
}
|
|
10099
|
-
if (WAITING_TOOLS.has(toolName)) {
|
|
10100
|
-
return deny(refusals.waiting(toolName));
|
|
10101
|
-
}
|
|
10102
|
-
if (deniedMcpPrefixes.some((prefix) => toolName.startsWith(prefix))) {
|
|
10103
|
-
return deny(`This session's policy denies the MCP server behind ${toolName}.`);
|
|
10104
|
-
}
|
|
10105
|
-
if (toolName.startsWith("mcp__")) {
|
|
10106
|
-
if (!allowedMcpPrefixes.some((prefix) => toolName.startsWith(prefix))) {
|
|
10107
|
-
return deny(refusals.mcp(toolName));
|
|
10108
|
-
}
|
|
10109
|
-
return {};
|
|
10110
|
-
}
|
|
10111
|
-
if (toolName === "Bash") {
|
|
10112
|
-
const toolInput = input.tool_input;
|
|
10113
|
-
if (toolInput?.dangerouslyDisableSandbox === true) {
|
|
10114
|
-
return deny(refusals.unsandboxed);
|
|
10115
|
-
}
|
|
10116
|
-
const command = typeof toolInput?.command === "string" ? toolInput.command : "";
|
|
10117
|
-
const verdict = isReadOnlyShellCommand(command, options);
|
|
10118
|
-
if (!verdict.allowed)
|
|
10119
|
-
return deny(verdict.reason);
|
|
10120
|
-
const boundary = readBoundary(input.cwd);
|
|
10121
|
-
if (boundary && shellCommandRefused(boundary, command, input.cwd, {
|
|
10122
|
-
traversal: options.commandSandbox === "unavailable"
|
|
10123
|
-
})) {
|
|
10124
|
-
return deny(refusals.dataDirectory);
|
|
10125
|
-
}
|
|
10126
|
-
return {};
|
|
10127
|
-
}
|
|
10128
|
-
if (toolName === "Read" || toolName === "Grep" || toolName === "Glob") {
|
|
10129
|
-
const boundary = readBoundary(input.cwd);
|
|
10130
|
-
const toolInput = input.tool_input ?? {};
|
|
10131
|
-
if (boundary && readToolRefused(boundary, toolName, toolInput, input.cwd)) {
|
|
10132
|
-
return deny(refusals.dataDirectory);
|
|
10133
|
-
}
|
|
10134
|
-
}
|
|
10135
|
-
return {};
|
|
10136
|
-
};
|
|
10204
|
+
async function loadPluginSettings(cwd, sources) {
|
|
10205
|
+
const entries = await Promise.all(sources.map(async (source) => {
|
|
10206
|
+
const enabledPlugins = await readJsonSliceCached(pluginSettingsPath(source, cwd), "enabledPlugins", (config) => config?.enabledPlugins ?? null);
|
|
10207
|
+
return [source, enabledPlugins === null ? undefined : { enabledPlugins }];
|
|
10208
|
+
}));
|
|
10209
|
+
return Object.fromEntries(entries);
|
|
10137
10210
|
}
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
return env[BRIDGE_EXECUTION_POLICY_ENV] === "coordinator-read-only";
|
|
10211
|
+
function remapInstalledPlugins2(pluginsDir, installedPlugins) {
|
|
10212
|
+
return remapInstalledPlugins(pluginsDir, installedPlugins, (installPath) => log5.warn("plugin.unsafe-path", { path: installPath }));
|
|
10141
10213
|
}
|
|
10142
|
-
function
|
|
10214
|
+
async function loadProjectOverridesFromGlobal(cwd) {
|
|
10215
|
+
const plugins = await readJsonSliceCached(claudeJsonPath(), `projects:${cwd}:plugins`, (config) => claudePluginConfigList(config?.projects?.[cwd]?.plugins));
|
|
10216
|
+
return plugins ?? [];
|
|
10217
|
+
}
|
|
10218
|
+
async function readPluginManifest(pluginPath) {
|
|
10219
|
+
const manifestPath = join6(pluginPath, ".claude-plugin", "plugin.json");
|
|
10220
|
+
const manifest = await readJsonSliceCached(manifestPath, "manifest", (config) => config ? { name: config.name, description: config.description } : null);
|
|
10221
|
+
if (!manifest) {
|
|
10222
|
+
return null;
|
|
10223
|
+
}
|
|
10224
|
+
const name = manifest.name || pluginPath.split("/").pop() || "unknown";
|
|
10143
10225
|
return {
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
approvals: "deny",
|
|
10147
|
-
projectResources: false,
|
|
10148
|
-
capabilityPolicy: coordinatorCapabilityPolicy(coordinatorWebResearchFromEnv(env)),
|
|
10149
|
-
networkAccess: "restricted"
|
|
10226
|
+
name,
|
|
10227
|
+
description: manifest.description
|
|
10150
10228
|
};
|
|
10151
10229
|
}
|
|
10152
|
-
function
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10230
|
+
function resolvePath(pluginPath, cwd) {
|
|
10231
|
+
return resolveClaudePluginPath(pluginPath, cwd, claudeHome());
|
|
10232
|
+
}
|
|
10233
|
+
function defaultSettingSources(includeProjectSources) {
|
|
10234
|
+
return includeProjectSources ? ["user", "project"] : ["user"];
|
|
10235
|
+
}
|
|
10236
|
+
async function getMergedPlugins(cwd, includeProjectSources = true, settingSources = defaultSettingSources(includeProjectSources)) {
|
|
10237
|
+
const sources = claudePluginSettingSources(settingSources);
|
|
10238
|
+
const [global2, cliInstalled, projectGlobal, projectLocal, settings] = await Promise.all([
|
|
10239
|
+
loadGlobalPlugins(),
|
|
10240
|
+
loadCliInstalledPlugins(),
|
|
10241
|
+
includeProjectSources ? loadProjectOverridesFromGlobal(cwd) : [],
|
|
10242
|
+
includeProjectSources ? loadProjectPlugins(cwd) : [],
|
|
10243
|
+
loadPluginSettings(cwd, sources)
|
|
10244
|
+
]);
|
|
10245
|
+
return mergeClaudePluginLayers({
|
|
10246
|
+
global: global2,
|
|
10247
|
+
cliInstalled: enabledInstalledPlugins(cliInstalled, settings, sources),
|
|
10248
|
+
projectGlobal,
|
|
10249
|
+
projectLocal
|
|
10250
|
+
}, { cwd, home: claudeHome(), includeProjectSources }).map((path) => ({ type: "local", path }));
|
|
10251
|
+
}
|
|
10252
|
+
async function getPluginsForSdk(cwd, includeProjectSources = true, settingSources = defaultSettingSources(includeProjectSources)) {
|
|
10253
|
+
const configs = await getMergedPlugins(cwd, includeProjectSources, settingSources);
|
|
10254
|
+
const validPlugins = [];
|
|
10255
|
+
for (const config of configs) {
|
|
10256
|
+
if (await pathExists(config.path)) {
|
|
10257
|
+
validPlugins.push({
|
|
10258
|
+
type: "local",
|
|
10259
|
+
path: config.path
|
|
10260
|
+
});
|
|
10261
|
+
} else {
|
|
10262
|
+
const pluginName = config.path.split("/").pop() || "unknown";
|
|
10263
|
+
log5.warn("plugin.path-missing", { pluginName, path: config.path });
|
|
10264
|
+
}
|
|
10265
|
+
}
|
|
10266
|
+
return validPlugins;
|
|
10267
|
+
}
|
|
10268
|
+
async function getPluginInfo(cwd) {
|
|
10269
|
+
const [global2, cliInstalled, projectGlobal, projectLocal] = await Promise.all([
|
|
10270
|
+
loadGlobalPlugins(),
|
|
10271
|
+
loadCliInstalledPlugins(),
|
|
10272
|
+
loadProjectOverridesFromGlobal(cwd),
|
|
10273
|
+
loadProjectPlugins(cwd)
|
|
10274
|
+
]);
|
|
10275
|
+
const globalPaths = new Set(global2.map((p) => resolvePath(p.path, cwd)));
|
|
10276
|
+
const cliPaths = new Set(cliInstalled.map((p) => resolvePath(p.path, cwd)));
|
|
10277
|
+
const projectGlobalPaths = new Set(projectGlobal.map((p) => resolvePath(p.path, cwd)));
|
|
10278
|
+
const projectLocalPaths = new Set(projectLocal.map((p) => resolvePath(p.path, cwd)));
|
|
10279
|
+
const merged = await getMergedPlugins(cwd);
|
|
10280
|
+
const result = [];
|
|
10281
|
+
for (const config of merged) {
|
|
10282
|
+
const manifest = await readPluginManifest(config.path);
|
|
10283
|
+
const exists = await pathExists(config.path);
|
|
10284
|
+
let source = "global";
|
|
10285
|
+
if (projectLocalPaths.has(config.path) || projectGlobalPaths.has(config.path)) {
|
|
10286
|
+
source = "project";
|
|
10287
|
+
} else if (cliPaths.has(config.path)) {
|
|
10288
|
+
source = "cli";
|
|
10289
|
+
} else if (globalPaths.has(config.path)) {
|
|
10290
|
+
source = "global";
|
|
10291
|
+
}
|
|
10292
|
+
result.push({
|
|
10293
|
+
name: manifest?.name || config.path.split("/").pop() || "unknown",
|
|
10294
|
+
path: config.path,
|
|
10295
|
+
description: manifest?.description,
|
|
10296
|
+
source,
|
|
10297
|
+
enabled: exists
|
|
10298
|
+
});
|
|
10299
|
+
}
|
|
10300
|
+
return result;
|
|
10156
10301
|
}
|
|
10157
10302
|
|
|
10158
10303
|
// ../../bridges/claude-bridge/src/services/claude-query-config.ts
|
|
@@ -10185,14 +10330,23 @@ function readOnlyTurnPolicy(sessionPolicy) {
|
|
|
10185
10330
|
}
|
|
10186
10331
|
}, "claude");
|
|
10187
10332
|
}
|
|
10188
|
-
|
|
10333
|
+
var CLAUDE_LINUX_SANDBOX_LOOPBACK_NOTE = "On Linux, Claude's command sandbox gives each command its own network namespace: commands reach other hosts through the sandbox's proxy, but cannot connect directly to services on this machine's loopback (localhost), such as a dev server or local database.";
|
|
10334
|
+
function claudeReportedPolicy(session, platform = process.platform) {
|
|
10189
10335
|
if (session.status === "running" && session.commandDiscoveryInputs?.readOnly === true) {
|
|
10190
10336
|
const turnPolicy = claudeTurnPolicy(session.executionPolicy, true);
|
|
10191
10337
|
if (turnPolicy) {
|
|
10192
10338
|
return readOnlyTurnReportedPolicy(turnPolicy, session.readOnlyCommandSandboxOff === undefined ? {} : { commandSandboxOff: session.readOnlyCommandSandboxOff });
|
|
10193
10339
|
}
|
|
10194
10340
|
}
|
|
10195
|
-
return session.executionPolicy;
|
|
10341
|
+
return session.executionPolicy && withLinuxLoopbackNote(session.executionPolicy, platform);
|
|
10342
|
+
}
|
|
10343
|
+
function withLinuxLoopbackNote(policy, platform) {
|
|
10344
|
+
if (platform !== "linux" || policy.sandbox !== "provider" || policy.networkAccess !== "full") {
|
|
10345
|
+
return policy;
|
|
10346
|
+
}
|
|
10347
|
+
if (policy.note?.includes(CLAUDE_LINUX_SANDBOX_LOOPBACK_NOTE))
|
|
10348
|
+
return policy;
|
|
10349
|
+
return appendNativeAgentPolicyNote(policy, CLAUDE_LINUX_SANDBOX_LOOPBACK_NOTE);
|
|
10196
10350
|
}
|
|
10197
10351
|
function claudePolicyPermissionMode(policy) {
|
|
10198
10352
|
return isRestrictivePolicy(policy) ? "default" : "bypassPermissions";
|
|
@@ -10465,7 +10619,7 @@ function claudeSandboxRefusal(policy, options = {}) {
|
|
|
10465
10619
|
}
|
|
10466
10620
|
|
|
10467
10621
|
// ../../bridges/claude-bridge/src/services/session-manager-background-tasks.ts
|
|
10468
|
-
var
|
|
10622
|
+
var log6 = createLogger("bridge.claude");
|
|
10469
10623
|
var PROVISIONAL_BACKGROUND_TASK_PREFIX = "pending-bash:";
|
|
10470
10624
|
var MAX_BACKGROUND_TASK_CANDIDATES = 128;
|
|
10471
10625
|
function provisionalBackgroundTaskId(toolUseId) {
|
|
@@ -10500,7 +10654,7 @@ function registerBackgroundTaskCandidate(runtime, toolUseId) {
|
|
|
10500
10654
|
return;
|
|
10501
10655
|
const { candidates } = runtime.tasks;
|
|
10502
10656
|
if (!candidates.has(toolUseId) && candidates.size >= MAX_BACKGROUND_TASK_CANDIDATES) {
|
|
10503
|
-
|
|
10657
|
+
log6.warn("task.candidate-bound-reached", {
|
|
10504
10658
|
sessionId: runtime.session.id,
|
|
10505
10659
|
bound: MAX_BACKGROUND_TASK_CANDIDATES
|
|
10506
10660
|
});
|
|
@@ -10614,7 +10768,7 @@ async function persistShellTaskFields(session, toolUseId, fields) {
|
|
|
10614
10768
|
]
|
|
10615
10769
|
});
|
|
10616
10770
|
} catch {
|
|
10617
|
-
|
|
10771
|
+
log6.warn("task.details-persist-failed");
|
|
10618
10772
|
}
|
|
10619
10773
|
}
|
|
10620
10774
|
function cacheShellTaskFields(session, toolUseId, fields) {
|
|
@@ -10736,7 +10890,7 @@ function parkSettlingBackgroundTask(owner, task) {
|
|
|
10736
10890
|
return;
|
|
10737
10891
|
const { settling } = owner.tasks;
|
|
10738
10892
|
if (!settling.has(task.id) && settling.size >= MAX_SETTLING_BACKGROUND_TASKS) {
|
|
10739
|
-
|
|
10893
|
+
log6.warn("task.settling-bound-reached", {
|
|
10740
10894
|
sessionId: owner.session.id,
|
|
10741
10895
|
bound: MAX_SETTLING_BACKGROUND_TASKS
|
|
10742
10896
|
});
|
|
@@ -10811,7 +10965,7 @@ async function stopBackgroundTask(sessionId, taskId) {
|
|
|
10811
10965
|
if (latest && !LIVE_BACKGROUND_TASK_STATUSES.has(latest.status)) {
|
|
10812
10966
|
return { ok: true };
|
|
10813
10967
|
}
|
|
10814
|
-
|
|
10968
|
+
log6.warn("task.stop-failed", { error: formatLogError(error, { stack: false }) });
|
|
10815
10969
|
if (settleBackgroundTask(session, taskId, "killed", "The Claude control channel for this task is no longer available")) {
|
|
10816
10970
|
emitBackgroundTaskSnapshot(session);
|
|
10817
10971
|
}
|
|
@@ -12438,7 +12592,7 @@ function restoredTurnInterruption(preferences) {
|
|
|
12438
12592
|
}
|
|
12439
12593
|
|
|
12440
12594
|
// ../../bridges/claude-bridge/src/services/session-manager-lifecycle.ts
|
|
12441
|
-
var
|
|
12595
|
+
var log7 = createLogger("bridge.claude");
|
|
12442
12596
|
async function getSessionActivity(sessionId) {
|
|
12443
12597
|
const session = sessions.get(sessionId);
|
|
12444
12598
|
if (session) {
|
|
@@ -12618,7 +12772,7 @@ async function claimPromptDispatch(sessionId, requestId, startDispatch, testHook
|
|
|
12618
12772
|
try {
|
|
12619
12773
|
await updateSessionPreferences(sdkSessionId, journalUpdate([...retainedRequestIds].slice(-MAX_DISPATCHED_REQUEST_IDS)));
|
|
12620
12774
|
} catch (rollbackError) {
|
|
12621
|
-
|
|
12775
|
+
log7.error("dispatch.rollback-failed", {
|
|
12622
12776
|
error: formatLogError(rollbackError, { stack: false })
|
|
12623
12777
|
});
|
|
12624
12778
|
}
|
|
@@ -12872,7 +13026,8 @@ function claudeLaunchResourceProfile(plugins, environment) {
|
|
|
12872
13026
|
credentials: digest([
|
|
12873
13027
|
environment.GH_TOKEN ?? null,
|
|
12874
13028
|
environment.GITHUB_TOKEN ?? null,
|
|
12875
|
-
environment.GITHUB_PERSONAL_ACCESS_TOKEN ?? null
|
|
13029
|
+
environment.GITHUB_PERSONAL_ACCESS_TOKEN ?? null,
|
|
13030
|
+
connectionEnvFingerprint(environment)
|
|
12876
13031
|
])
|
|
12877
13032
|
};
|
|
12878
13033
|
}
|
|
@@ -12912,7 +13067,7 @@ async function assertClaudeRuntimeAccepts(session, options, resources, readOnlyC
|
|
|
12912
13067
|
const policy = claudeTurnPolicy(session.executionPolicy, options?.readOnly);
|
|
12913
13068
|
const [{ plugins }, environment] = await Promise.all([
|
|
12914
13069
|
resolveClaudeTurnPlugins(request.cwd, policy, claudeTurnSettingSources(session, options)),
|
|
12915
|
-
runtimeEnvironmentForSessionQuery(policy)
|
|
13070
|
+
runtimeEnvironmentForSessionQuery(policy).then((environment) => withReadOnlyConnectionEnv(policy, environment))
|
|
12916
13071
|
]);
|
|
12917
13072
|
resources = claudeLaunchResourceProfile(plugins, environment);
|
|
12918
13073
|
}
|
|
@@ -13566,7 +13721,7 @@ function groupHasLiveMember(pgid) {
|
|
|
13566
13721
|
}
|
|
13567
13722
|
|
|
13568
13723
|
// ../protocol/src/node/lost-exit-reaper.ts
|
|
13569
|
-
var
|
|
13724
|
+
var log8 = createLogger("process");
|
|
13570
13725
|
var REAP_GRACE_MS = 2000;
|
|
13571
13726
|
var REAP_MAX_CHECK_MS = 30000;
|
|
13572
13727
|
var REAP_MAX_CHECKS = 12;
|
|
@@ -13582,7 +13737,7 @@ function createLostExitReaper(options) {
|
|
|
13582
13737
|
let abandoned = 0;
|
|
13583
13738
|
const abandon = (pid, reason) => {
|
|
13584
13739
|
abandoned += 1;
|
|
13585
|
-
|
|
13740
|
+
log8.warn("child.reap-abandoned", { pid, reason });
|
|
13586
13741
|
};
|
|
13587
13742
|
const check = (pid, reported, startedAt) => {
|
|
13588
13743
|
if (reported())
|
|
@@ -13597,7 +13752,7 @@ function createLostExitReaper(options) {
|
|
|
13597
13752
|
const result = system.waitNoHang(pid);
|
|
13598
13753
|
if (result === pid) {
|
|
13599
13754
|
reaped += 1;
|
|
13600
|
-
|
|
13755
|
+
log8.info("child.reaped", { pid, waitedMs: Date.now() - startedAt });
|
|
13601
13756
|
return false;
|
|
13602
13757
|
}
|
|
13603
13758
|
if (result === 0)
|
|
@@ -13681,7 +13836,7 @@ var defaultReaper;
|
|
|
13681
13836
|
function createDarwinLostExitReaper(loadFfi) {
|
|
13682
13837
|
const system = darwinReaperSystem(loadFfi);
|
|
13683
13838
|
if (!system)
|
|
13684
|
-
|
|
13839
|
+
log8.warn("child.reap-unavailable");
|
|
13685
13840
|
return system ? createLostExitReaper({ system }) : null;
|
|
13686
13841
|
}
|
|
13687
13842
|
function sharedReaper() {
|
|
@@ -17892,7 +18047,7 @@ function reconcileClaudeUsage(terminal, streamed) {
|
|
|
17892
18047
|
}
|
|
17893
18048
|
|
|
17894
18049
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-turn-lifecycle.ts
|
|
17895
|
-
var
|
|
18050
|
+
var log9 = createLogger("bridge.claude");
|
|
17896
18051
|
function diagnosticErrorClass(error) {
|
|
17897
18052
|
try {
|
|
17898
18053
|
if (!(error instanceof Error))
|
|
@@ -17982,7 +18137,7 @@ async function reconcilePlanModeFromStatus(turn, reported) {
|
|
|
17982
18137
|
try {
|
|
17983
18138
|
await applySessionPlanMode(session, false);
|
|
17984
18139
|
} catch (error) {
|
|
17985
|
-
|
|
18140
|
+
log9.warn("plan-mode.record-failed", { sessionId, errorClass: diagnosticErrorClass(error) });
|
|
17986
18141
|
}
|
|
17987
18142
|
}
|
|
17988
18143
|
function setCompletionBlockedByBackgroundTasks(turn, blocked) {
|
|
@@ -18227,7 +18382,7 @@ function createTurnState(session, sessionId, init) {
|
|
|
18227
18382
|
}
|
|
18228
18383
|
|
|
18229
18384
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-admission.ts
|
|
18230
|
-
var
|
|
18385
|
+
var log10 = createLogger("bridge.claude");
|
|
18231
18386
|
var STREAM_EVENT_COALESCE_MS = 100;
|
|
18232
18387
|
function admitPrompt(sessionId, options) {
|
|
18233
18388
|
const session = sessions.get(sessionId);
|
|
@@ -18362,7 +18517,7 @@ async function readTranscriptForPrompt(session) {
|
|
|
18362
18517
|
try {
|
|
18363
18518
|
return await readPersistedSessionMessagesOnce(session);
|
|
18364
18519
|
} catch (error) {
|
|
18365
|
-
|
|
18520
|
+
log10.warn("transcript.hydrate-failed", { error: formatLogError(error, { stack: false }) });
|
|
18366
18521
|
return TRANSCRIPT_READ_FAILED;
|
|
18367
18522
|
}
|
|
18368
18523
|
}
|
|
@@ -18466,7 +18621,7 @@ var ORKESTRATOR_ARTIFACT_MCP_SERVER_NAME = "orkestrator-artifacts";
|
|
|
18466
18621
|
var ORKESTRATOR_ARTIFACT_MCP_PATH = "/artifact-mcp";
|
|
18467
18622
|
|
|
18468
18623
|
// ../../bridges/claude-bridge/src/services/mcp-config.ts
|
|
18469
|
-
var
|
|
18624
|
+
var log11 = createLogger("bridge.claude");
|
|
18470
18625
|
var AGENT_MCP_SERVER_NAME = "orkestrator";
|
|
18471
18626
|
var AGENT_MCP_URL_ENV = "ORKESTRATOR_AGENT_MCP_URL";
|
|
18472
18627
|
var AGENT_MCP_TOKEN_ENV = "ORKESTRATOR_AGENT_MCP_TOKEN";
|
|
@@ -18551,7 +18706,7 @@ function toSdkServers(configs) {
|
|
|
18551
18706
|
if (sdkConfig) {
|
|
18552
18707
|
servers[name] = sdkConfig;
|
|
18553
18708
|
} else {
|
|
18554
|
-
|
|
18709
|
+
log11.warn("mcp.config-ignored");
|
|
18555
18710
|
}
|
|
18556
18711
|
}
|
|
18557
18712
|
return servers;
|
|
@@ -18938,7 +19093,7 @@ function claudeReadiness() {
|
|
|
18938
19093
|
}
|
|
18939
19094
|
|
|
18940
19095
|
// ../../bridges/claude-bridge/src/services/claude-model-catalog.ts
|
|
18941
|
-
var
|
|
19096
|
+
var log12 = createLogger("bridge.claude");
|
|
18942
19097
|
var CLAUDE_MODEL_CACHE_TTL_MS = 60 * 60000;
|
|
18943
19098
|
var CLAUDE_MODEL_PROBE_TIMEOUT_MS = 25000;
|
|
18944
19099
|
var remembered;
|
|
@@ -19073,7 +19228,7 @@ async function probeModels(at) {
|
|
|
19073
19228
|
await rememberModels(models, account, at);
|
|
19074
19229
|
return { source: "sdk", models: catalogModels(models) };
|
|
19075
19230
|
} catch (error) {
|
|
19076
|
-
|
|
19231
|
+
log12.warn("models.fetch-failed", { error: formatLogError(error) });
|
|
19077
19232
|
return fallbackCatalog();
|
|
19078
19233
|
} finally {
|
|
19079
19234
|
if (q?.return) {
|
|
@@ -21330,14 +21485,14 @@ function isValidMcpFormContent(schema, content) {
|
|
|
21330
21485
|
}
|
|
21331
21486
|
|
|
21332
21487
|
// ../../bridges/claude-bridge/src/services/session-manager-interactions.ts
|
|
21333
|
-
var
|
|
21488
|
+
var log13 = createLogger("bridge.claude");
|
|
21334
21489
|
function answerQuestion(requestId, answers) {
|
|
21335
21490
|
const question = pendingQuestions.get(requestId);
|
|
21336
21491
|
if (!question) {
|
|
21337
21492
|
debugLog("[session-manager] Question not found for requestId:", requestId);
|
|
21338
21493
|
return false;
|
|
21339
21494
|
}
|
|
21340
|
-
|
|
21495
|
+
log13.info("question.answering", { requestId, answerCount: Object.keys(answers).length });
|
|
21341
21496
|
const resolver = questionResolvers.get(requestId);
|
|
21342
21497
|
if (resolver) {
|
|
21343
21498
|
debugLog("[session-manager] Resolving promise for question:", requestId);
|
|
@@ -21389,7 +21544,7 @@ function respondToPlanApproval(requestId, approved, feedback) {
|
|
|
21389
21544
|
debugLog("[session-manager] Refusing incomplete plan approval", { requestId });
|
|
21390
21545
|
return false;
|
|
21391
21546
|
}
|
|
21392
|
-
|
|
21547
|
+
log13.info("plan-approval.responding", {
|
|
21393
21548
|
requestId,
|
|
21394
21549
|
approved,
|
|
21395
21550
|
hasFeedback: typeof feedback === "string" && feedback.length > 0
|
|
@@ -21746,7 +21901,7 @@ async function requestClaudeToolApproval(sessionId, toolName, input, permissionC
|
|
|
21746
21901
|
}
|
|
21747
21902
|
|
|
21748
21903
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-hooks.ts
|
|
21749
|
-
var
|
|
21904
|
+
var log14 = createLogger("bridge.claude");
|
|
21750
21905
|
async function recordPreCompact(turn, hookInput) {
|
|
21751
21906
|
const { session } = turn;
|
|
21752
21907
|
if (hookInput.hook_event_name !== "PreCompact" || session.latestTurnGeneration !== turn.turnGeneration) {
|
|
@@ -21860,7 +22015,7 @@ function recordingHookDenials(hook, conversationId) {
|
|
|
21860
22015
|
} catch (error) {
|
|
21861
22016
|
if (input.hook_event_name !== "PreToolUse")
|
|
21862
22017
|
throw error;
|
|
21863
|
-
|
|
22018
|
+
log14.warn("hook.boundary-failed-closed", { tool: input.tool_name });
|
|
21864
22019
|
output = {
|
|
21865
22020
|
hookSpecificOutput: {
|
|
21866
22021
|
hookEventName: "PreToolUse",
|
|
@@ -21984,7 +22139,7 @@ async function resolveQueryPlan(turn, sdkTextPrompt, testHooks) {
|
|
|
21984
22139
|
const envPath = process.env.PATH;
|
|
21985
22140
|
debugLog("[session-manager] SDK env PATH", { path: envPath });
|
|
21986
22141
|
const sdkPrompt = await buildSdkPrompt(sdkTextPrompt, options?.attachments, cwd, testHooks?.afterAttachmentSymlinkValidation, testHooks?.afterAttachmentCanonicalValidation, testHooks?.afterAttachmentInitialValidation);
|
|
21987
|
-
const queryEnvironment = withReadOnlyGitConfig(policy, withUnattendedOverloadRetry(session.executionPolicy, await runtimeEnvironmentForSessionQuery(policy)));
|
|
22142
|
+
const queryEnvironment = withReadOnlyGitConfig(policy, withUnattendedOverloadRetry(session.executionPolicy, await withReadOnlyConnectionEnv(policy, await runtimeEnvironmentForSessionQuery(policy))));
|
|
21988
22143
|
const liveSettings = claudeLiveSettings({
|
|
21989
22144
|
model: options?.model,
|
|
21990
22145
|
permissionMode,
|
|
@@ -22635,7 +22790,7 @@ var LEAF_MESSAGE_HANDLERS = {
|
|
|
22635
22790
|
};
|
|
22636
22791
|
|
|
22637
22792
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-handlers/result.ts
|
|
22638
|
-
var
|
|
22793
|
+
var log15 = createLogger("bridge.claude");
|
|
22639
22794
|
function claudeStartupFailureMessage(reason) {
|
|
22640
22795
|
switch (reason) {
|
|
22641
22796
|
case "org_pin_api_key_conflict":
|
|
@@ -22843,9 +22998,9 @@ async function handleResultMessage(turn, message) {
|
|
|
22843
22998
|
const startupFailure = resultMsg.startup_failure_reason ? withStartupFailureDetail(claudeStartupFailureMessage(resultMsg.startup_failure_reason), resultMsg.errors) : undefined;
|
|
22844
22999
|
const usageLimit = resultMsg.subtype === "success" && classifyUsageLimitError(resultMsg.result) ? resultMsg.result.trim().slice(0, MAX_USAGE_LIMIT_ERROR_CHARS) : undefined;
|
|
22845
23000
|
if (!startupFailure && (usageLimit || turn.rateLimitRejected)) {
|
|
22846
|
-
|
|
23001
|
+
log15.warn("query.usage-limited", { subtype: resultMsg.subtype, sessionId });
|
|
22847
23002
|
} else {
|
|
22848
|
-
|
|
23003
|
+
log15.error("query.failed", { subtype: resultMsg.subtype, sessionId, isError: resultIsError });
|
|
22849
23004
|
}
|
|
22850
23005
|
const resultError = startupFailure || resultMsg.errors?.filter(Boolean).join(`
|
|
22851
23006
|
`) || usageLimit || (resultMsg.subtype === "success" ? "Claude ended the turn on an API error." : `Claude query failed: ${resultMsg.subtype}`);
|
|
@@ -23279,7 +23434,7 @@ async function handleSystemMessage(turn, message) {
|
|
|
23279
23434
|
}
|
|
23280
23435
|
|
|
23281
23436
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-handlers/user.ts
|
|
23282
|
-
var
|
|
23437
|
+
var log16 = createLogger("bridge.claude");
|
|
23283
23438
|
function handleUserMessage(turn, message) {
|
|
23284
23439
|
const { session, sessionId, stream } = turn;
|
|
23285
23440
|
const { toolTracker, taskRegistry, activeTaskIds } = stream;
|
|
@@ -23329,7 +23484,7 @@ function handleUserMessage(turn, message) {
|
|
|
23329
23484
|
if (turn.planApprovedThisTurn) {
|
|
23330
23485
|
for (const tool of toolTracker.getTools()) {
|
|
23331
23486
|
if (tool.toolName === "ExitPlanMode" && tool.toolState === "failure" && tool.toolUseId) {
|
|
23332
|
-
|
|
23487
|
+
log16.warn("plan-exit.failure-overridden", { sessionId, toolUseId: tool.toolUseId });
|
|
23333
23488
|
toolTracker.updateToolResult(tool.toolUseId, {
|
|
23334
23489
|
state: "success",
|
|
23335
23490
|
output: "Plan approved by the user. Proceeding with implementation.",
|
|
@@ -23441,7 +23596,7 @@ async function readClaudeMcpToolHints(control, serverName, toolName, timeoutMs =
|
|
|
23441
23596
|
}
|
|
23442
23597
|
|
|
23443
23598
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-can-use-tool.ts
|
|
23444
|
-
var
|
|
23599
|
+
var log17 = createLogger("bridge.claude");
|
|
23445
23600
|
function boundedPlan(content) {
|
|
23446
23601
|
if (typeof content !== "string" || content.trim().length === 0)
|
|
23447
23602
|
return {};
|
|
@@ -23500,7 +23655,7 @@ async function askUserQuestion(turn, input, permissionContext) {
|
|
|
23500
23655
|
});
|
|
23501
23656
|
try {
|
|
23502
23657
|
const answers = await Promise.race([answerPromise, timeoutPromise]);
|
|
23503
|
-
|
|
23658
|
+
log17.info("question.answers-received", { questionId, answerCount: Object.keys(answers).length });
|
|
23504
23659
|
return {
|
|
23505
23660
|
behavior: "allow",
|
|
23506
23661
|
updatedInput: {
|
|
@@ -23509,7 +23664,7 @@ async function askUserQuestion(turn, input, permissionContext) {
|
|
|
23509
23664
|
}
|
|
23510
23665
|
};
|
|
23511
23666
|
} catch (error) {
|
|
23512
|
-
|
|
23667
|
+
log17.warn("question.wait-failed", { error: formatLogError(error) });
|
|
23513
23668
|
const message = error instanceof Error ? error.message : "Question was cancelled";
|
|
23514
23669
|
if (pendingQuestions.has(questionId)) {
|
|
23515
23670
|
eventEmitter.emit({
|
|
@@ -23590,7 +23745,7 @@ async function requestPlanApproval(turn, input, permissionContext) {
|
|
|
23590
23745
|
});
|
|
23591
23746
|
try {
|
|
23592
23747
|
const response = await Promise.race([approvalPromise, timeoutPromise]);
|
|
23593
|
-
|
|
23748
|
+
log17.info("plan-approval.result", {
|
|
23594
23749
|
approvalId,
|
|
23595
23750
|
approved: response.approved,
|
|
23596
23751
|
hasFeedback: typeof response.feedback === "string" && response.feedback.length > 0
|
|
@@ -23639,7 +23794,7 @@ Please revise the plan based on this feedback.` : `I've reviewed the plan and I
|
|
|
23639
23794
|
};
|
|
23640
23795
|
}
|
|
23641
23796
|
} catch (error) {
|
|
23642
|
-
|
|
23797
|
+
log17.warn("plan-approval.wait-failed", { error: formatLogError(error) });
|
|
23643
23798
|
const errorMessage = error instanceof Error ? error.message : "Plan approval was cancelled";
|
|
23644
23799
|
if (pendingPlanApprovals.has(approvalId)) {
|
|
23645
23800
|
eventEmitter.emit({
|
|
@@ -23730,7 +23885,7 @@ function createClaudeRuntimeTurn(turn) {
|
|
|
23730
23885
|
}
|
|
23731
23886
|
|
|
23732
23887
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-launch.ts
|
|
23733
|
-
var
|
|
23888
|
+
var log18 = createLogger("bridge.claude");
|
|
23734
23889
|
async function consumeClaudeRuntime(runtime, frames, markEnded) {
|
|
23735
23890
|
let failure;
|
|
23736
23891
|
try {
|
|
@@ -23807,7 +23962,7 @@ function releaseOrphanedForeground(runtime, error) {
|
|
|
23807
23962
|
eventEmitter.emit({ type: "session.idle", sessionId, data: { success: true } });
|
|
23808
23963
|
return;
|
|
23809
23964
|
}
|
|
23810
|
-
|
|
23965
|
+
log18.error("runtime.ended-under-resumed-turn", { sessionId });
|
|
23811
23966
|
session.status = "error";
|
|
23812
23967
|
session.error = error instanceof Error ? error.message : String(error);
|
|
23813
23968
|
session.errorCode = undefined;
|
|
@@ -23972,7 +24127,7 @@ async function runTurnOnRuntime(turn, plan, testHooks) {
|
|
|
23972
24127
|
}
|
|
23973
24128
|
|
|
23974
24129
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-settle.ts
|
|
23975
|
-
var
|
|
24130
|
+
var log19 = createLogger("bridge.claude");
|
|
23976
24131
|
function settleTurnEnd(turn) {
|
|
23977
24132
|
const { session, sessionId, options, structuredRequestId, abortController, stream, diagnostics } = turn;
|
|
23978
24133
|
diagnostics?.streamSettled("resolved");
|
|
@@ -24097,10 +24252,10 @@ function settleFailedTurn(turn, error) {
|
|
|
24097
24252
|
const killedBy = killedClaudeProcessSignal(error);
|
|
24098
24253
|
const usageLimited = !killedBy && (turn.rateLimitRejected || isUsageLimitError(error));
|
|
24099
24254
|
if (usageLimited) {
|
|
24100
|
-
|
|
24255
|
+
log19.warn("prompt.usage-limited", { errorClass: diagnosticErrorClass(error) });
|
|
24101
24256
|
markUsageLimitError(error);
|
|
24102
24257
|
} else {
|
|
24103
|
-
|
|
24258
|
+
log19.error("prompt.failed", { errorClass: diagnosticErrorClass(error) });
|
|
24104
24259
|
}
|
|
24105
24260
|
if (session.abortController === abortController) {
|
|
24106
24261
|
const failure = killedBy ? claudeProcessKilledMessage(killedBy) : error instanceof Error ? error.message : String(error);
|
|
@@ -24210,7 +24365,7 @@ function finalizeTurn(turn) {
|
|
|
24210
24365
|
}
|
|
24211
24366
|
|
|
24212
24367
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt.ts
|
|
24213
|
-
var
|
|
24368
|
+
var log20 = createLogger("bridge.claude");
|
|
24214
24369
|
function turnWriterLiveness(turn) {
|
|
24215
24370
|
const tasks = Object.values(turn.session.backgroundTasks ?? {});
|
|
24216
24371
|
if (tasks.some((task) => LIVE_BACKGROUND_TASK_STATUSES.has(task.status)))
|
|
@@ -24253,7 +24408,7 @@ async function sendPrompt(sessionId, prompt, options, testHooks) {
|
|
|
24253
24408
|
try {
|
|
24254
24409
|
await sendPrompt(sessionId, followUp.prompt, followUp.options);
|
|
24255
24410
|
} catch (repromptError) {
|
|
24256
|
-
|
|
24411
|
+
log20.error(followUp.failureEvent, { error: formatLogError(repromptError) });
|
|
24257
24412
|
return Promise.reject(repromptError);
|
|
24258
24413
|
}
|
|
24259
24414
|
} catch (error) {
|
|
@@ -24265,7 +24420,7 @@ async function sendPrompt(sessionId, prompt, options, testHooks) {
|
|
|
24265
24420
|
}
|
|
24266
24421
|
}
|
|
24267
24422
|
// ../../bridges/claude-bridge/src/services/session-manager-close.ts
|
|
24268
|
-
var
|
|
24423
|
+
var log21 = createLogger("bridge.claude");
|
|
24269
24424
|
var CLOSE_CONFIRMATION_BUDGET_MS = 1e4;
|
|
24270
24425
|
|
|
24271
24426
|
class SessionCloseNotConfirmedError extends Error {
|
|
@@ -24328,7 +24483,7 @@ async function closeQueryControls(controls, deadline) {
|
|
|
24328
24483
|
if (await settlesBy(Promise.resolve(control.close()), deadline))
|
|
24329
24484
|
return;
|
|
24330
24485
|
} catch (error) {
|
|
24331
|
-
|
|
24486
|
+
log21.error("query.close-failed", {
|
|
24332
24487
|
errorClass: error instanceof Error ? error.name : typeof error
|
|
24333
24488
|
});
|
|
24334
24489
|
}
|
|
@@ -24340,18 +24495,18 @@ async function settlesBy(work, deadline) {
|
|
|
24340
24495
|
return (await boundedWait(work, Math.max(0, deadline - Date.now()))).settled;
|
|
24341
24496
|
}
|
|
24342
24497
|
// ../../bridges/claude-bridge/src/routes/config.ts
|
|
24343
|
-
var
|
|
24498
|
+
var log22 = createLogger("bridge.claude");
|
|
24344
24499
|
var config2 = new Hono2;
|
|
24345
24500
|
config2.get("/models", async (c) => {
|
|
24346
24501
|
if (c.req.query("forceRefresh") === "true")
|
|
24347
24502
|
invalidateClaudeModelCatalog();
|
|
24348
24503
|
const startedAt = Date.now();
|
|
24349
|
-
|
|
24504
|
+
log22.debug("models.requested");
|
|
24350
24505
|
const [{ models, source }, versions] = await Promise.all([
|
|
24351
24506
|
getAvailableModelCatalog(),
|
|
24352
24507
|
getClaudeRuntimeVersions()
|
|
24353
24508
|
]);
|
|
24354
|
-
|
|
24509
|
+
log22.debug("models.responded", { count: models.length, durationMs: Date.now() - startedAt });
|
|
24355
24510
|
const response = {
|
|
24356
24511
|
models,
|
|
24357
24512
|
source,
|
|
@@ -25375,7 +25530,7 @@ function bridgeTranscriptPageRouteBody(source, query) {
|
|
|
25375
25530
|
}
|
|
25376
25531
|
|
|
25377
25532
|
// ../../bridges/claude-bridge/src/routes/session-transcript.ts
|
|
25378
|
-
var
|
|
25533
|
+
var log23 = createLogger("bridge.claude");
|
|
25379
25534
|
function claudeTranscriptSource(id, generation) {
|
|
25380
25535
|
const sessionData = peekSession(id);
|
|
25381
25536
|
if (!sessionData)
|
|
@@ -25428,7 +25583,7 @@ function registerSessionTranscriptRoutes(app, generation, materialize) {
|
|
|
25428
25583
|
const response = c.json(bridgeTranscriptRouteBody(read.source, query3(c)));
|
|
25429
25584
|
if (read.needsHydration) {
|
|
25430
25585
|
hydratePersistedSessionMessages(id).catch((error) => {
|
|
25431
|
-
|
|
25586
|
+
log23.warn("transcript.background-hydrate-failed", {
|
|
25432
25587
|
error: formatLogError(error, { stack: false })
|
|
25433
25588
|
});
|
|
25434
25589
|
});
|
|
@@ -25440,7 +25595,7 @@ function registerSessionTranscriptRoutes(app, generation, materialize) {
|
|
|
25440
25595
|
}
|
|
25441
25596
|
|
|
25442
25597
|
// ../../bridges/claude-bridge/src/routes/session.ts
|
|
25443
|
-
var
|
|
25598
|
+
var log24 = createLogger("bridge.claude");
|
|
25444
25599
|
var session = new Hono2;
|
|
25445
25600
|
var TRANSCRIPT_GENERATION = randomUUID6();
|
|
25446
25601
|
var MAX_QUESTION_ANSWER_REQUEST_BYTES = AGENT_INTERACTION_LIMITS.maxSerializedPayloadBytes + 1024;
|
|
@@ -25497,10 +25652,10 @@ function isUsageLimitedRejection(error) {
|
|
|
25497
25652
|
}
|
|
25498
25653
|
function logPromptProcessingFailure(error) {
|
|
25499
25654
|
if (isUsageLimitedRejection(error)) {
|
|
25500
|
-
|
|
25655
|
+
log24.debug("prompt.processing-usage-limited");
|
|
25501
25656
|
return;
|
|
25502
25657
|
}
|
|
25503
|
-
|
|
25658
|
+
log24.error("prompt.processing-failed", { error: formatLogError(error) });
|
|
25504
25659
|
}
|
|
25505
25660
|
var STALE_PROMPT_STATUS = 409;
|
|
25506
25661
|
function stalePrompt(message) {
|
|
@@ -25536,7 +25691,7 @@ session.post("/create", async (c) => {
|
|
|
25536
25691
|
const clientSessionKey = body.clientSessionKey;
|
|
25537
25692
|
const policy = effectiveExecutionPolicy(isNativeAgentExecutionPolicy(body.policy) ? body.policy : undefined);
|
|
25538
25693
|
const newSession = policy ? await createOrRecoverSession(title, clientSessionKey, policy) : await createOrRecoverSession(title, clientSessionKey);
|
|
25539
|
-
|
|
25694
|
+
log24.info("session.created", { sessionId: newSession.id });
|
|
25540
25695
|
const response = {
|
|
25541
25696
|
sessionId: newSession.id,
|
|
25542
25697
|
title: newSession.title
|
|
@@ -25544,10 +25699,10 @@ session.post("/create", async (c) => {
|
|
|
25544
25699
|
return c.json(response, 201);
|
|
25545
25700
|
} catch (error) {
|
|
25546
25701
|
if (error instanceof PolicyWideningRefusedError) {
|
|
25547
|
-
|
|
25702
|
+
log24.warn("session.policy-widening-refused", { widened: error.widened.join(",") });
|
|
25548
25703
|
return c.json(error.refusal(), 403);
|
|
25549
25704
|
}
|
|
25550
|
-
|
|
25705
|
+
log24.error("session.create-failed", { error: formatLogError(error) });
|
|
25551
25706
|
return c.json({ error: error instanceof Error ? error.message : "Failed to create session" }, 500);
|
|
25552
25707
|
}
|
|
25553
25708
|
});
|
|
@@ -25555,7 +25710,7 @@ session.get("/list", async (c) => {
|
|
|
25555
25710
|
try {
|
|
25556
25711
|
await reconcilePersistedSessions();
|
|
25557
25712
|
} catch (error) {
|
|
25558
|
-
|
|
25713
|
+
log24.warn("sessions.reconcile-failed", { error: formatLogError(error) });
|
|
25559
25714
|
}
|
|
25560
25715
|
const sessions = listSessions();
|
|
25561
25716
|
const response = {
|
|
@@ -25574,7 +25729,7 @@ async function resolveSession(id, failureMessage) {
|
|
|
25574
25729
|
try {
|
|
25575
25730
|
return { ok: true, session: getSession(id) ?? await ensurePersistedSession(id) };
|
|
25576
25731
|
} catch (error) {
|
|
25577
|
-
|
|
25732
|
+
log24.error("session.resolve-failed", { action: failureMessage, error: formatLogError(error) });
|
|
25578
25733
|
return {
|
|
25579
25734
|
ok: false,
|
|
25580
25735
|
body: { error: errorMessage(error, failureMessage) },
|
|
@@ -25595,7 +25750,7 @@ session.get("/:id", async (c) => {
|
|
|
25595
25750
|
try {
|
|
25596
25751
|
await hydratePersistedSessionMessages(id);
|
|
25597
25752
|
} catch (error) {
|
|
25598
|
-
|
|
25753
|
+
log24.error("session.task-state-hydrate-failed", { error: formatLogError(error) });
|
|
25599
25754
|
return c.json({ error: errorMessage(error, "Failed to hydrate session task state") }, sessionErrorStatus(error));
|
|
25600
25755
|
}
|
|
25601
25756
|
}
|
|
@@ -25647,7 +25802,7 @@ session.get("/:id/usage", async (c) => {
|
|
|
25647
25802
|
const contextUsage = await refreshClaudeContextUsage(resolved.session);
|
|
25648
25803
|
return c.json({ contextUsage });
|
|
25649
25804
|
} catch (error) {
|
|
25650
|
-
|
|
25805
|
+
log24.warn("context-usage.read-failed", { error: formatLogError(error, { stack: false }) });
|
|
25651
25806
|
return c.json({ error: "Context usage is temporarily unavailable" }, 503);
|
|
25652
25807
|
}
|
|
25653
25808
|
});
|
|
@@ -25668,7 +25823,7 @@ session.post("/:id/config", async (c) => {
|
|
|
25668
25823
|
const refusePolicyWidening = () => {
|
|
25669
25824
|
const widened = nextPolicy ? executionPolicyWidenings(sessionData.executionPolicy, nextPolicy) : [];
|
|
25670
25825
|
if (widened.length > 0) {
|
|
25671
|
-
|
|
25826
|
+
log24.warn("session.policy-widening-refused", {
|
|
25672
25827
|
sessionId: sessionData.id,
|
|
25673
25828
|
widened: widened.join(",")
|
|
25674
25829
|
});
|
|
@@ -25709,7 +25864,7 @@ session.get("/:id/commands", async (c) => {
|
|
|
25709
25864
|
try {
|
|
25710
25865
|
return c.json(await readClaudeCommandCatalogue(c.req.param("id")));
|
|
25711
25866
|
} catch (error) {
|
|
25712
|
-
|
|
25867
|
+
log24.warn("commands.read-failed", { error: formatLogError(error, { stack: false }) });
|
|
25713
25868
|
return c.json({ error: errorMessage(error, "Claude command discovery failed") }, 503);
|
|
25714
25869
|
}
|
|
25715
25870
|
});
|
|
@@ -25957,7 +26112,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
25957
26112
|
duplicate: true
|
|
25958
26113
|
});
|
|
25959
26114
|
}
|
|
25960
|
-
|
|
26115
|
+
log24.debug("prompt.accepted", { sessionId: id });
|
|
25961
26116
|
return c.json({
|
|
25962
26117
|
status: "processing",
|
|
25963
26118
|
requestId,
|
|
@@ -25970,7 +26125,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
25970
26125
|
if (sessionData.rewindInProgress === true) {
|
|
25971
26126
|
return c.json({ error: "Session is restoring files from a checkpoint" }, 409);
|
|
25972
26127
|
}
|
|
25973
|
-
|
|
26128
|
+
log24.info("prompt.received", {
|
|
25974
26129
|
sessionId: id,
|
|
25975
26130
|
promptLength: prompt.length,
|
|
25976
26131
|
model,
|
|
@@ -26000,14 +26155,14 @@ session.post("/:id/prompt", async (c) => {
|
|
|
26000
26155
|
}).catch((error) => {
|
|
26001
26156
|
logPromptProcessingFailure(error);
|
|
26002
26157
|
});
|
|
26003
|
-
|
|
26158
|
+
log24.debug("prompt.accepted", { sessionId: id });
|
|
26004
26159
|
return c.json({
|
|
26005
26160
|
status: "processing",
|
|
26006
26161
|
requestId,
|
|
26007
26162
|
turnStartedAt: sessionData.turnStartedAt
|
|
26008
26163
|
}, 202);
|
|
26009
26164
|
} catch (error) {
|
|
26010
|
-
|
|
26165
|
+
log24.error("prompt.send-failed", { error: formatLogError(error) });
|
|
26011
26166
|
return c.json({ error: errorMessage(error, "Failed to send prompt") }, sessionErrorStatus(error));
|
|
26012
26167
|
}
|
|
26013
26168
|
});
|
|
@@ -26068,7 +26223,7 @@ session.post("/:id/fork", async (c) => {
|
|
|
26068
26223
|
title: forked.title
|
|
26069
26224
|
}, 201);
|
|
26070
26225
|
} catch (error) {
|
|
26071
|
-
|
|
26226
|
+
log24.error("session.fork-failed", { error: formatLogError(error) });
|
|
26072
26227
|
return c.json({ error: errorMessage(error, "Failed to fork session") }, sessionErrorStatus(error));
|
|
26073
26228
|
}
|
|
26074
26229
|
});
|
|
@@ -26100,7 +26255,7 @@ session.post("/:id/compact", compactBodyLimit, async (c) => {
|
|
|
26100
26255
|
}
|
|
26101
26256
|
const { instructions } = parsed;
|
|
26102
26257
|
sendPrompt(id, instructions ? `/compact ${instructions}` : "/compact").catch((error) => {
|
|
26103
|
-
|
|
26258
|
+
log24.error("session.compact-failed", { error: formatLogError(error) });
|
|
26104
26259
|
});
|
|
26105
26260
|
return c.json(instructions ? { status: "processing", instructions: "applied" } : { status: "processing" }, 202);
|
|
26106
26261
|
});
|
|
@@ -26118,7 +26273,7 @@ session.post("/:id/rewind", async (c) => {
|
|
|
26118
26273
|
const result = await rewindSessionFiles(id, messageId, dryRun);
|
|
26119
26274
|
return c.json({ status: dryRun ? "previewed" : "rewound", result });
|
|
26120
26275
|
} catch (error) {
|
|
26121
|
-
|
|
26276
|
+
log24.error("session.rewind-failed", { error: formatLogError(error) });
|
|
26122
26277
|
return c.json({ error: errorMessage(error, "Failed to rewind session files") }, sessionErrorStatus(error));
|
|
26123
26278
|
}
|
|
26124
26279
|
});
|
|
@@ -26129,7 +26284,7 @@ session.post("/:id/tasks/:taskId/stop", async (c) => {
|
|
|
26129
26284
|
return c.json({ status: "stopped" });
|
|
26130
26285
|
return c.json({ error: stopped.message }, stopped.reason === "no_control_channel" ? 409 : 404);
|
|
26131
26286
|
} catch (error) {
|
|
26132
|
-
|
|
26287
|
+
log24.error("task.stop-route-failed", { error: formatLogError(error) });
|
|
26133
26288
|
return c.json({ error: errorMessage(error, "Failed to stop background task") }, sessionErrorStatus(error));
|
|
26134
26289
|
}
|
|
26135
26290
|
});
|
|
@@ -26200,7 +26355,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
26200
26355
|
const pendingQuestions = getPendingQuestions(sessionId);
|
|
26201
26356
|
const pendingQuestion = pendingQuestions.find((q) => q.id === questionId);
|
|
26202
26357
|
if (!pendingQuestion) {
|
|
26203
|
-
|
|
26358
|
+
log24.info("question.stale", { questionId });
|
|
26204
26359
|
return c.json(stalePrompt("Question is no longer pending"), STALE_PROMPT_STATUS);
|
|
26205
26360
|
}
|
|
26206
26361
|
if (!isBoundedClaudeQuestionAnswers(answersArray, pendingQuestion.questions.length)) {
|
|
@@ -26211,7 +26366,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
26211
26366
|
const questionAnswers = answersArray[index] || [];
|
|
26212
26367
|
answersRecord[q.question] = serializeClaudeQuestionAnswer(questionAnswers, q.multiSelect === true);
|
|
26213
26368
|
});
|
|
26214
|
-
|
|
26369
|
+
log24.debug("question.answers-prepared", {
|
|
26215
26370
|
questionId,
|
|
26216
26371
|
questionCount: pendingQuestion.questions.length,
|
|
26217
26372
|
answerCount: answersArray.reduce((count, answers) => count + answers.length, 0)
|
|
@@ -26223,7 +26378,7 @@ session.post("/:id/questions/:questionId/answer", questionAnswerBodyLimit, async
|
|
|
26223
26378
|
return c.json(stalePrompt("Question is no longer pending"), STALE_PROMPT_STATUS);
|
|
26224
26379
|
}
|
|
26225
26380
|
} catch (error) {
|
|
26226
|
-
|
|
26381
|
+
log24.error("question.answer-failed", { error: formatLogError(error) });
|
|
26227
26382
|
return c.json({ error: error instanceof Error ? error.message : "Failed to answer question" }, 500);
|
|
26228
26383
|
}
|
|
26229
26384
|
});
|
|
@@ -26263,7 +26418,7 @@ session.post("/:id/plan-approvals/:approvalId/respond", planApprovalBodyLimit, a
|
|
|
26263
26418
|
if (approved && (typeof pendingApproval.plan !== "string" || pendingApproval.plan.trim().length === 0 || pendingApproval.planTruncated === true)) {
|
|
26264
26419
|
return c.json({ error: "A complete plan is required before approval", status: "rejected" }, 409);
|
|
26265
26420
|
}
|
|
26266
|
-
|
|
26421
|
+
log24.info("plan-approval.response-received", {
|
|
26267
26422
|
sessionId,
|
|
26268
26423
|
approvalId,
|
|
26269
26424
|
approved,
|
|
@@ -26276,7 +26431,7 @@ session.post("/:id/plan-approvals/:approvalId/respond", planApprovalBodyLimit, a
|
|
|
26276
26431
|
return c.json(stalePrompt("Plan approval is no longer pending"), STALE_PROMPT_STATUS);
|
|
26277
26432
|
}
|
|
26278
26433
|
} catch (error) {
|
|
26279
|
-
|
|
26434
|
+
log24.error("plan-approval.response-failed", { error: formatLogError(error) });
|
|
26280
26435
|
return c.json({ error: error instanceof Error ? error.message : "Failed to respond to plan approval" }, 500);
|
|
26281
26436
|
}
|
|
26282
26437
|
});
|
|
@@ -26675,7 +26830,7 @@ class EventRing {
|
|
|
26675
26830
|
}
|
|
26676
26831
|
|
|
26677
26832
|
// ../../bridges/claude-bridge/src/routes/events.ts
|
|
26678
|
-
var
|
|
26833
|
+
var log25 = createLogger("bridge.claude");
|
|
26679
26834
|
var serializedEvents = new WeakMap;
|
|
26680
26835
|
function serializeEvent(event) {
|
|
26681
26836
|
let serialized = serializedEvents.get(event);
|
|
@@ -26926,14 +27081,14 @@ function createEventsRouter(limits = {}) {
|
|
|
26926
27081
|
events.get("/subscribe", (c) => {
|
|
26927
27082
|
const origin = c.req.header("origin");
|
|
26928
27083
|
const userAgent = c.req.header("user-agent");
|
|
26929
|
-
|
|
27084
|
+
log25.debug("sse.subscribe-requested", { origin, userAgent });
|
|
26930
27085
|
return streamSSE(c, async (stream) => {
|
|
26931
27086
|
const connectedAt = new Date().toISOString();
|
|
26932
|
-
|
|
27087
|
+
log25.debug("sse.opened", { connectedAt });
|
|
26933
27088
|
let isOpen = true;
|
|
26934
27089
|
const closure = createSseConnectionClosure();
|
|
26935
27090
|
const onRequestAbort = () => {
|
|
26936
|
-
|
|
27091
|
+
log25.debug("sse.aborted");
|
|
26937
27092
|
isOpen = false;
|
|
26938
27093
|
closure.close();
|
|
26939
27094
|
};
|
|
@@ -26947,7 +27102,7 @@ function createEventsRouter(limits = {}) {
|
|
|
26947
27102
|
if (!isOpen)
|
|
26948
27103
|
return;
|
|
26949
27104
|
isOpen = false;
|
|
26950
|
-
|
|
27105
|
+
log25.info("sse.closed", { reason });
|
|
26951
27106
|
closure.close();
|
|
26952
27107
|
};
|
|
26953
27108
|
const writeFrame = createBoundedSseWriter(async (frame) => {
|
|
@@ -26998,7 +27153,7 @@ function createEventsRouter(limits = {}) {
|
|
|
26998
27153
|
}
|
|
26999
27154
|
writeFrame(frame).catch((error) => {
|
|
27000
27155
|
if (!c.req.raw.signal.aborted) {
|
|
27001
|
-
|
|
27156
|
+
log25.warn("sse.write-failed", { error: formatLogError(error) });
|
|
27002
27157
|
closeConnection("write failed");
|
|
27003
27158
|
}
|
|
27004
27159
|
});
|
|
@@ -27060,7 +27215,7 @@ function createEventsRouter(limits = {}) {
|
|
|
27060
27215
|
data: JSON.stringify({ timestamp: new Date().toISOString() })
|
|
27061
27216
|
}).catch((error) => {
|
|
27062
27217
|
if (!c.req.raw.signal.aborted) {
|
|
27063
|
-
|
|
27218
|
+
log25.warn("sse.keepalive-failed", { error: formatLogError(error, { stack: false }) });
|
|
27064
27219
|
closeConnection("keepalive failed");
|
|
27065
27220
|
}
|
|
27066
27221
|
});
|
|
@@ -27068,10 +27223,10 @@ function createEventsRouter(limits = {}) {
|
|
|
27068
27223
|
await closure.closed;
|
|
27069
27224
|
} catch (error) {
|
|
27070
27225
|
if (!c.req.raw.signal.aborted) {
|
|
27071
|
-
|
|
27226
|
+
log25.warn("sse.handshake-failed", { error: formatLogError(error) });
|
|
27072
27227
|
}
|
|
27073
27228
|
} finally {
|
|
27074
|
-
|
|
27229
|
+
log25.debug("sse.cleanup");
|
|
27075
27230
|
isOpen = false;
|
|
27076
27231
|
c.req.raw.signal.removeEventListener("abort", onRequestAbort);
|
|
27077
27232
|
if (keepaliveInterval)
|
|
@@ -27087,7 +27242,7 @@ var events = createEventsRouter();
|
|
|
27087
27242
|
var events_default = events;
|
|
27088
27243
|
|
|
27089
27244
|
// ../../bridges/claude-bridge/src/routes/mcp.ts
|
|
27090
|
-
var
|
|
27245
|
+
var log26 = createLogger("bridge.claude");
|
|
27091
27246
|
var mcp = new Hono2;
|
|
27092
27247
|
mcp.get("/servers", async (c) => {
|
|
27093
27248
|
try {
|
|
@@ -27098,14 +27253,14 @@ mcp.get("/servers", async (c) => {
|
|
|
27098
27253
|
cwd
|
|
27099
27254
|
});
|
|
27100
27255
|
} catch (error) {
|
|
27101
|
-
|
|
27256
|
+
log26.error("mcp.read-failed", { error: formatLogError(error) });
|
|
27102
27257
|
return c.json({ error: error instanceof Error ? error.message : "Failed to get MCP servers" }, 500);
|
|
27103
27258
|
}
|
|
27104
27259
|
});
|
|
27105
27260
|
var mcp_default = mcp;
|
|
27106
27261
|
|
|
27107
27262
|
// ../../bridges/claude-bridge/src/routes/plugins.ts
|
|
27108
|
-
var
|
|
27263
|
+
var log27 = createLogger("bridge.claude");
|
|
27109
27264
|
var plugins = new Hono2;
|
|
27110
27265
|
plugins.get("/", async (c) => {
|
|
27111
27266
|
try {
|
|
@@ -27116,7 +27271,7 @@ plugins.get("/", async (c) => {
|
|
|
27116
27271
|
cwd
|
|
27117
27272
|
});
|
|
27118
27273
|
} catch (error) {
|
|
27119
|
-
|
|
27274
|
+
log27.error("plugins.read-failed", { error: formatLogError(error) });
|
|
27120
27275
|
return c.json({ error: error instanceof Error ? error.message : "Failed to get plugins" }, 500);
|
|
27121
27276
|
}
|
|
27122
27277
|
});
|
|
@@ -27309,9 +27464,9 @@ function installFatalRejectionGuard(options) {
|
|
|
27309
27464
|
}
|
|
27310
27465
|
|
|
27311
27466
|
// ../protocol/src/node/process-failure-log.ts
|
|
27312
|
-
var
|
|
27467
|
+
var log28 = createLogger("process");
|
|
27313
27468
|
function logUnhandledRejection(reason) {
|
|
27314
|
-
|
|
27469
|
+
log28.throttled("error", "rejection.unhandled", {
|
|
27315
27470
|
error: reason,
|
|
27316
27471
|
fields: () => ({ error: formatLogError(reason, { message: false }) })
|
|
27317
27472
|
});
|
|
@@ -28990,7 +29145,7 @@ async function admitFetchBridgeRequest(authority, original, maxBodyBytes = BRIDG
|
|
|
28990
29145
|
var BRIDGE_TOKEN_PREFIX = "okb_";
|
|
28991
29146
|
var PR_SET_DUMPABLE = 4;
|
|
28992
29147
|
var VERIFIER_PATTERN = /^[0-9a-f]{64}$/;
|
|
28993
|
-
var
|
|
29148
|
+
var log29 = createLogger("bridge.lifecycle");
|
|
28994
29149
|
function mintBridgeToken() {
|
|
28995
29150
|
return `${BRIDGE_TOKEN_PREFIX}${randomBytes3(32).toString("base64url")}`;
|
|
28996
29151
|
}
|
|
@@ -29033,9 +29188,9 @@ function markProcessNonDumpable(loadFfi = () => createRequire2(import.meta.url)(
|
|
|
29033
29188
|
} finally {
|
|
29034
29189
|
libc.close();
|
|
29035
29190
|
}
|
|
29036
|
-
|
|
29191
|
+
log29.warn("credential.not-hardened", { reason: "prctl-refused" });
|
|
29037
29192
|
} catch {
|
|
29038
|
-
|
|
29193
|
+
log29.warn("credential.not-hardened", { reason: "ffi-unavailable" });
|
|
29039
29194
|
}
|
|
29040
29195
|
return false;
|
|
29041
29196
|
}
|
|
@@ -29055,11 +29210,11 @@ function loadBridgeCredential(tokenEnv, options = {}) {
|
|
|
29055
29210
|
}
|
|
29056
29211
|
|
|
29057
29212
|
// ../../bridges/claude-bridge/src/index.ts
|
|
29058
|
-
var
|
|
29213
|
+
var log30 = createLogger("bridge.claude");
|
|
29059
29214
|
configureBridgeLogger();
|
|
29060
29215
|
var app = new Hono2;
|
|
29061
29216
|
app.onError((error, c) => {
|
|
29062
|
-
|
|
29217
|
+
log30.error("http.request-failed", {
|
|
29063
29218
|
method: c.req.method,
|
|
29064
29219
|
path: c.req.path,
|
|
29065
29220
|
error: formatLogError(error)
|
|
@@ -29170,7 +29325,7 @@ if (parentPid !== null) {
|
|
|
29170
29325
|
startParentWatchdog({
|
|
29171
29326
|
parentPid,
|
|
29172
29327
|
onParentExit: () => {
|
|
29173
|
-
|
|
29328
|
+
log30.warn("parent.gone", { parentPid });
|
|
29174
29329
|
process.exit(0);
|
|
29175
29330
|
}
|
|
29176
29331
|
});
|
|
@@ -29181,13 +29336,13 @@ function startBridgeServer(env = process.env, start = serve) {
|
|
|
29181
29336
|
}
|
|
29182
29337
|
const port = parseInt(env.PORT || "4097", 10);
|
|
29183
29338
|
const hostname = env.HOSTNAME || "0.0.0.0";
|
|
29184
|
-
|
|
29339
|
+
log30.debug("server.starting", { hostname, port });
|
|
29185
29340
|
const server = start({
|
|
29186
29341
|
fetch: app.fetch,
|
|
29187
29342
|
port,
|
|
29188
29343
|
hostname
|
|
29189
29344
|
});
|
|
29190
|
-
|
|
29345
|
+
log30.info("server.listening", { hostname, port });
|
|
29191
29346
|
return server;
|
|
29192
29347
|
}
|
|
29193
29348
|
var __testing = {
|