@mcpjam/inspector 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/runtime-profile.mjs +774 -0
- package/bin/start.js +117 -24
- package/dist/client/assets/{OAuthDesktopReturnNotice-D5tJNqny.js → OAuthDesktopReturnNotice-D7d-faB1.js} +2 -2
- package/dist/client/assets/{app-bootstrap-baadQQNk.js → app-bootstrap-BtDjj9nz.js} +350 -350
- package/dist/client/assets/{button-DHPqnOj6.js → button-B99pZFz_.js} +2 -2
- package/dist/client/assets/{chunk-D32TOXHM-BPB6AqSK.js → chunk-D32TOXHM-Bcyg0ZVj.js} +5 -5
- package/dist/client/assets/{dead-clicks-autocapture-Cbczl2El.js → dead-clicks-autocapture-CnUHv5CB.js} +2 -2
- package/dist/client/assets/{error-reporting-CORfsjyM.js → error-reporting-BohBwcQQ.js} +4 -4
- package/dist/client/assets/{error-reporting-B4hGM_ob.js → error-reporting-p6G1ojum.js} +1 -1
- package/dist/client/assets/{exception-autocapture-CMOUrnel.js → exception-autocapture-Q-isBTHp.js} +2 -2
- package/dist/client/assets/{failed-request-tracker-DoQRXuIy.js → failed-request-tracker-BBJW8izb.js} +2 -2
- package/dist/client/assets/{highlighted-body-KQOG7T2V-_ljE4u1k.js → highlighted-body-KQOG7T2V-zsXWRnSM.js} +2 -2
- package/dist/client/assets/{index-BBr8TZVx.js → index-C9oFRqoK.js} +3 -3
- package/dist/client/assets/{jszip.min-C-vIQbxH.js → jszip.min-C86zG41a.js} +2 -2
- package/dist/client/assets/{mermaid-MCJ5UELQ-DTJaEEBm.js → mermaid-MCJ5UELQ-DAW4LYwz.js} +1 -1
- package/dist/client/assets/{posthog-recorder-Dby9Z8HR.js → posthog-recorder-trUd0BXy.js} +2 -2
- package/dist/client/assets/{preload-helper-Dvt1a6xa.js → preload-helper-Buauuydw.js} +2 -2
- package/dist/client/assets/{react-CD7Pk4KS.js → react-CZb-kDOs.js} +2 -2
- package/dist/client/assets/{rolldown-runtime-mzU9SaVm.js → rolldown-runtime-Bkua2_Tb.js} +1 -1
- package/dist/client/assets/{surveys-DYqpu8xl.js → surveys-BISK_WOT.js} +2 -2
- package/dist/client/assets/{trace-timeline-PnE1ouRj.js → trace-timeline-CRewsP1E.js} +2 -2
- package/dist/client/assets/{trace-timeline-WXINST5z.js → trace-timeline-D-DWE-sO.js} +1 -1
- package/dist/client/assets/{web-vitals-BLq6M5vx.js → web-vitals-DqmZ9w02.js} +2 -2
- package/dist/client/index.html +7 -7
- package/dist/server/authorization-MA42CNYT.js +22 -0
- package/dist/server/chunk-7M3XVZCQ.js +381 -0
- package/dist/server/{chunk-MBS3EZ3U.js → chunk-7ZIR7SX7.js} +5 -44
- package/dist/server/chunk-C47PTIDS.js +487 -0
- package/dist/server/chunk-DHRTCKJA.js +3979 -0
- package/dist/server/chunk-HJTKF2X6.js +45 -0
- package/dist/server/{chunk-2FVSBJQF.js → chunk-KNO4KZJF.js} +224 -758
- package/dist/server/{chunk-QHYREDE3.js → chunk-RWFTW2EW.js} +7 -5
- package/dist/server/chunk-SDWJSPSI.js +252 -0
- package/dist/server/chunk-VFRLMHOC.js +33 -0
- package/dist/server/chunk-XSQ2GC45.js +438 -0
- package/dist/server/chunk-YQ2BTE46.js +88 -0
- package/dist/server/{consent-lifetime-TYLDY64H.js → consent-lifetime-OXQM37RV.js} +4 -3
- package/dist/server/grants-UVE62NGN.js +37 -0
- package/dist/server/harness-install-cli.js +239 -4
- package/dist/server/index.js +9044 -9216
- package/dist/server/local-turn-XSUGEKTL.js +19 -0
- package/dist/server/runtime-health-TCF3ZEKS.js +28 -0
- package/dist/server/runtime-lifecycle-YQ3KWDLJ.js +53 -0
- package/package.json +26 -23
- package/dist/server/chunk-I7ZVTBZP.js +0 -3100
- package/dist/server/local-turn-VQDSTY6T.js +0 -12
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CODEX_LOCAL_ADAPTER_IDENTITY,
|
|
3
3
|
LOCAL_HARNESS_MANIFEST,
|
|
4
|
-
|
|
5
|
-
LOCAL_ISOLATION_POLICY_VERSION,
|
|
6
|
-
SUPPORTED_LOCAL_HARNESS_IDS,
|
|
7
|
-
createLocalStateMutationLock,
|
|
8
|
-
currentLocalPlatform,
|
|
4
|
+
isSelectablePack,
|
|
9
5
|
listGroupMembers,
|
|
10
|
-
localPackTarget,
|
|
11
|
-
logger,
|
|
12
6
|
manifestWithExpectedBundleDigest,
|
|
7
|
+
noteRuntimeLaunch,
|
|
13
8
|
probeProcess,
|
|
14
9
|
probeProcessGroup,
|
|
15
10
|
readProcessBirthIdentity,
|
|
16
11
|
readProcessGroupId,
|
|
17
12
|
readRuntimeInstallStatus,
|
|
18
|
-
reserveRuntimeUse,
|
|
19
13
|
resolveLocalCompatibility,
|
|
20
14
|
resolveManagedBundle,
|
|
21
15
|
resolveSystemInstall,
|
|
@@ -24,639 +18,38 @@ import {
|
|
|
24
18
|
supportsOwnershipProof,
|
|
25
19
|
terminateOwnedProcess,
|
|
26
20
|
terminateOwnedProcessGroup
|
|
27
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-DHRTCKJA.js";
|
|
22
|
+
import {
|
|
23
|
+
reserveRuntimeUse
|
|
24
|
+
} from "./chunk-7M3XVZCQ.js";
|
|
25
|
+
import {
|
|
26
|
+
endLocalHarnessSession,
|
|
27
|
+
forgetLocalHarnessSession,
|
|
28
|
+
forgetLocalHarnessSessionRecord,
|
|
29
|
+
getLocalHarnessSession,
|
|
30
|
+
readLocalHarnessAuthorization,
|
|
31
|
+
registerLocalHarnessSession
|
|
32
|
+
} from "./chunk-SDWJSPSI.js";
|
|
33
|
+
import {
|
|
34
|
+
getLocalMachineId,
|
|
35
|
+
localHarnessStateRoot,
|
|
36
|
+
resolveWorkspaceGrant,
|
|
37
|
+
verifyLocalHarnessGrant
|
|
38
|
+
} from "./chunk-XSQ2GC45.js";
|
|
39
|
+
import {
|
|
40
|
+
LOCAL_HARNESS_POLICY_VERSION,
|
|
41
|
+
SUPPORTED_LOCAL_HARNESS_IDS,
|
|
42
|
+
currentLocalPlatform,
|
|
43
|
+
localPackTarget
|
|
44
|
+
} from "./chunk-VFRLMHOC.js";
|
|
45
|
+
import {
|
|
46
|
+
createLocalStateMutationLock,
|
|
47
|
+
logger
|
|
48
|
+
} from "./chunk-C47PTIDS.js";
|
|
28
49
|
import {
|
|
29
50
|
HOSTED_MODE,
|
|
30
|
-
LOCAL_HARNESS_ENABLED
|
|
31
|
-
|
|
32
|
-
capabilityMatches,
|
|
33
|
-
mintCapabilityToken,
|
|
34
|
-
persistCapabilityState
|
|
35
|
-
} from "./chunk-MBS3EZ3U.js";
|
|
36
|
-
|
|
37
|
-
// server/utils/harness/local/grants.ts
|
|
38
|
-
import { randomUUID } from "crypto";
|
|
39
|
-
import { mkdir, readFile, rename, writeFile, chmod } from "fs/promises";
|
|
40
|
-
import { homedir } from "os";
|
|
41
|
-
import { join, sep } from "path";
|
|
42
|
-
import { realpath, stat } from "fs/promises";
|
|
43
|
-
var LOCAL_HARNESS_GRANT_HEADER = "x-mcpjam-local-harness-grant";
|
|
44
|
-
function localHarnessStateRoot() {
|
|
45
|
-
return join(homedir(), ".mcpjam", "harness-local");
|
|
46
|
-
}
|
|
47
|
-
function grantsFilePath() {
|
|
48
|
-
return join(localHarnessStateRoot(), "grants.json");
|
|
49
|
-
}
|
|
50
|
-
function machineFilePath() {
|
|
51
|
-
return join(localHarnessStateRoot(), "machine.json");
|
|
52
|
-
}
|
|
53
|
-
function emptyState() {
|
|
54
|
-
return { version: 1, workspaces: [], harnessGrants: [] };
|
|
55
|
-
}
|
|
56
|
-
var GRANT_TTL_MS = 12 * 60 * 60 * 1e3;
|
|
57
|
-
var withGrantLock = createLocalStateMutationLock({
|
|
58
|
-
rootDir: localHarnessStateRoot,
|
|
59
|
-
lockFileName: "grants.lock",
|
|
60
|
-
resourceLabel: "grant store"
|
|
61
|
-
});
|
|
62
|
-
function hashGrantBinding(binding) {
|
|
63
|
-
return capabilityFingerprint(
|
|
64
|
-
JSON.stringify([
|
|
65
|
-
binding.scope ?? "attended",
|
|
66
|
-
binding.userId,
|
|
67
|
-
binding.machineId,
|
|
68
|
-
binding.projectId,
|
|
69
|
-
binding.workspaceGrantId,
|
|
70
|
-
binding.harnessId,
|
|
71
|
-
binding.targetKind,
|
|
72
|
-
binding.backend ?? null,
|
|
73
|
-
binding.runtimeId,
|
|
74
|
-
binding.permissionProfile,
|
|
75
|
-
binding.policyVersion,
|
|
76
|
-
// Only isolated bindings carry one, and only they hash it. A native
|
|
77
|
-
// binding has no isolation policy to be bound to, so folding a constant
|
|
78
|
-
// `null` into its hash would change every native hash for a value that
|
|
79
|
-
// means nothing there — invalidating consents that the local policy
|
|
80
|
-
// never touched. A native binding that carries one anyway is refused
|
|
81
|
-
// outright by `verifyLocalHarnessGrant`, not admitted by the hash.
|
|
82
|
-
...binding.targetKind === "local-isolated" ? [binding.isolationPolicyVersion ?? null] : []
|
|
83
|
-
])
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
var GrantStateUnreadableError = class extends Error {
|
|
87
|
-
};
|
|
88
|
-
function isValidDate(value) {
|
|
89
|
-
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
90
|
-
}
|
|
91
|
-
function isWorkspaceGrant(value) {
|
|
92
|
-
if (!value || typeof value !== "object") return false;
|
|
93
|
-
const workspace = value;
|
|
94
|
-
return typeof workspace.workspaceGrantId === "string" && workspace.workspaceGrantId.length > 0 && typeof workspace.canonicalPath === "string" && workspace.canonicalPath.length > 0 && isValidDate(workspace.createdAt);
|
|
95
|
-
}
|
|
96
|
-
function isHarnessGrantBinding(value) {
|
|
97
|
-
if (!value || typeof value !== "object") return false;
|
|
98
|
-
const binding = value;
|
|
99
|
-
const isolatedBackend = binding.backend === "linux-bwrap" || binding.backend === "darwin-seatbelt" || binding.backend === "oci-v1" || binding.backend === "vm-v1";
|
|
100
|
-
return typeof binding.userId === "string" && binding.userId.length > 0 && typeof binding.machineId === "string" && binding.machineId.length > 0 && (binding.scope === void 0 || binding.scope === "attended" || binding.scope === "unattended") && typeof binding.projectId === "string" && binding.projectId.length > 0 && typeof binding.workspaceGrantId === "string" && binding.workspaceGrantId.length > 0 && (binding.harnessId === "claude-code" || binding.harnessId === "codex") && (binding.targetKind === "local-native" || binding.targetKind === "local-isolated") && typeof binding.runtimeId === "string" && binding.runtimeId.length > 0 && (binding.permissionProfile === "read-only" || binding.permissionProfile === "workspace-edits" || binding.permissionProfile === "unrestricted") && typeof binding.policyVersion === "string" && binding.policyVersion.length > 0 && (binding.targetKind === "local-native" ? binding.backend === void 0 && binding.isolationPolicyVersion === void 0 : isolatedBackend && typeof binding.isolationPolicyVersion === "string" && binding.isolationPolicyVersion.length > 0);
|
|
101
|
-
}
|
|
102
|
-
function isPersistedHarnessGrant(value) {
|
|
103
|
-
if (!value || typeof value !== "object") return false;
|
|
104
|
-
const grant = value;
|
|
105
|
-
return typeof grant.grantId === "string" && grant.grantId.length > 0 && typeof grant.tokenHash === "string" && /^[0-9a-f]{64}$/.test(grant.tokenHash) && typeof grant.bindingHash === "string" && /^[0-9a-f]{64}$/.test(grant.bindingHash) && isHarnessGrantBinding(grant.binding) && isValidDate(grant.grantedAt) && isValidDate(grant.expiresAt);
|
|
106
|
-
}
|
|
107
|
-
async function readState() {
|
|
108
|
-
let raw;
|
|
109
|
-
try {
|
|
110
|
-
raw = await readFile(grantsFilePath(), "utf8");
|
|
111
|
-
} catch (error) {
|
|
112
|
-
if (error.code === "ENOENT") return emptyState();
|
|
113
|
-
throw new GrantStateUnreadableError(
|
|
114
|
-
`the local harness grant store could not be read: ${error instanceof Error ? error.message : String(error)}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
let parsed;
|
|
118
|
-
try {
|
|
119
|
-
parsed = JSON.parse(raw);
|
|
120
|
-
} catch {
|
|
121
|
-
throw new GrantStateUnreadableError(
|
|
122
|
-
"the local harness grant store is corrupt; refusing to treat it as empty or overwrite it"
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
if (!parsed || typeof parsed !== "object") {
|
|
126
|
-
throw new GrantStateUnreadableError(
|
|
127
|
-
"the local harness grant store is not an object"
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
const record = parsed;
|
|
131
|
-
if (record.version !== 1 || !Array.isArray(record.workspaces) || !Array.isArray(record.harnessGrants) || !record.workspaces.every(isWorkspaceGrant) || !record.harnessGrants.every(isPersistedHarnessGrant)) {
|
|
132
|
-
throw new GrantStateUnreadableError(
|
|
133
|
-
"the local harness grant store has an unrecognized or malformed shape"
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
version: 1,
|
|
138
|
-
workspaces: [...record.workspaces],
|
|
139
|
-
harnessGrants: [...record.harnessGrants]
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
async function writeState(state) {
|
|
143
|
-
const dir = localHarnessStateRoot();
|
|
144
|
-
await mkdir(dir, { recursive: true, mode: 448 });
|
|
145
|
-
await chmod(dir, 448).catch(() => {
|
|
146
|
-
});
|
|
147
|
-
await persistCapabilityState(grantsFilePath(), state);
|
|
148
|
-
}
|
|
149
|
-
async function getLocalMachineId() {
|
|
150
|
-
const readExisting = async () => {
|
|
151
|
-
let raw;
|
|
152
|
-
try {
|
|
153
|
-
raw = await readFile(machineFilePath(), "utf8");
|
|
154
|
-
} catch (error) {
|
|
155
|
-
if (error.code === "ENOENT") return null;
|
|
156
|
-
throw new GrantStateUnreadableError(
|
|
157
|
-
`the local harness machine identity could not be read: ${error instanceof Error ? error.message : String(error)}`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
let parsed;
|
|
161
|
-
try {
|
|
162
|
-
parsed = JSON.parse(raw);
|
|
163
|
-
} catch {
|
|
164
|
-
throw new GrantStateUnreadableError(
|
|
165
|
-
"the local harness machine identity is corrupt; refusing to replace it"
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
if (!parsed || typeof parsed !== "object") {
|
|
169
|
-
throw new GrantStateUnreadableError(
|
|
170
|
-
"the local harness machine identity has an unrecognized shape"
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
const machineId = parsed.machineId;
|
|
174
|
-
if (typeof machineId !== "string" || machineId.length < 8) {
|
|
175
|
-
throw new GrantStateUnreadableError(
|
|
176
|
-
"the local harness machine identity has an invalid id"
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
return machineId;
|
|
180
|
-
};
|
|
181
|
-
const existing = await readExisting();
|
|
182
|
-
if (existing !== null) return existing;
|
|
183
|
-
return withGrantLock(async () => {
|
|
184
|
-
const raced = await readExisting();
|
|
185
|
-
if (raced !== null) return raced;
|
|
186
|
-
const machineId = `mach_${randomUUID()}`;
|
|
187
|
-
const dir = localHarnessStateRoot();
|
|
188
|
-
await mkdir(dir, { recursive: true, mode: 448 });
|
|
189
|
-
const file2 = machineFilePath();
|
|
190
|
-
const tmp = `${file2}.tmp`;
|
|
191
|
-
await writeFile(tmp, JSON.stringify({ machineId }), { mode: 384 });
|
|
192
|
-
await rename(tmp, file2);
|
|
193
|
-
return machineId;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function isFilesystemRoot(canonicalPath) {
|
|
197
|
-
return canonicalPath === sep || canonicalPath === "/" || // A drive root: `C:`, `C:\`, `C:/`.
|
|
198
|
-
/^[A-Za-z]:[\\/]?$/.test(canonicalPath) || // A UNC share root: `\\server\share` and its trailing-separator form, and
|
|
199
|
-
// a bare `\\server`. Scoping a session to a whole network share is the
|
|
200
|
-
// same mistake as scoping it to a whole volume, and the earlier rule
|
|
201
|
-
// covered only the volume. Anything BELOW the share
|
|
202
|
-
// (`\\server\share\project`) stays acceptable.
|
|
203
|
-
//
|
|
204
|
-
// Matched on the BACKSLASH form only. Accepting `//` here as well read a
|
|
205
|
-
// POSIX path with a doubled leading slash — `//tmp/project`, which POSIX
|
|
206
|
-
// expressly permits an implementation to keep — as a share root, and
|
|
207
|
-
// refused an ordinary directory. Windows has no such ambiguity to trade
|
|
208
|
-
// against: `realpath` and `path.resolve` both answer `\\server\share`
|
|
209
|
-
// there, so the canonical path this predicate is given is always the
|
|
210
|
-
// backslash form.
|
|
211
|
-
/^\\{2}[^\\/]+([\\/][^\\/]+)?[\\/]?$/.test(canonicalPath);
|
|
212
|
-
}
|
|
213
|
-
async function validateWorkspaceCandidate(rawPath) {
|
|
214
|
-
let canonicalPath;
|
|
215
|
-
try {
|
|
216
|
-
canonicalPath = await realpath(rawPath);
|
|
217
|
-
const info = await stat(canonicalPath);
|
|
218
|
-
if (!info.isDirectory()) {
|
|
219
|
-
return { ok: false, message: "the selection is not a directory" };
|
|
220
|
-
}
|
|
221
|
-
} catch (error) {
|
|
222
|
-
return {
|
|
223
|
-
ok: false,
|
|
224
|
-
message: `the selected workspace could not be resolved: ${error instanceof Error ? error.message : String(error)}`
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
const home = await realpath(homedir()).catch(() => homedir());
|
|
228
|
-
const appRoot = join(home, ".mcpjam");
|
|
229
|
-
const workspaces = join(appRoot, "harness-workspaces");
|
|
230
|
-
if (canonicalPath === home || isFilesystemRoot(canonicalPath) || (canonicalPath === appRoot || canonicalPath.startsWith(appRoot + sep)) && !canonicalPath.startsWith(workspaces + sep)) {
|
|
231
|
-
return {
|
|
232
|
-
ok: false,
|
|
233
|
-
message: "pick a project directory rather than your home directory or the filesystem root \u2014 the workspace is what the session is scoped to."
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
return { ok: true, canonicalPath };
|
|
237
|
-
}
|
|
238
|
-
function registerWorkspaceGrant(rawPath) {
|
|
239
|
-
return withGrantLock(async () => {
|
|
240
|
-
const candidate = await validateWorkspaceCandidate(rawPath);
|
|
241
|
-
if (!candidate.ok) {
|
|
242
|
-
return { ok: false, message: candidate.message };
|
|
243
|
-
}
|
|
244
|
-
const canonicalPath = candidate.canonicalPath;
|
|
245
|
-
const state = await readState();
|
|
246
|
-
const existing = state.workspaces.find(
|
|
247
|
-
(w) => w.canonicalPath === canonicalPath
|
|
248
|
-
);
|
|
249
|
-
if (existing) return { ok: true, grant: existing };
|
|
250
|
-
const grant = {
|
|
251
|
-
workspaceGrantId: `ws_${randomUUID()}`,
|
|
252
|
-
canonicalPath,
|
|
253
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
254
|
-
};
|
|
255
|
-
state.workspaces.push(grant);
|
|
256
|
-
await writeState(state);
|
|
257
|
-
logger.info("[local-harness] workspace grant registered");
|
|
258
|
-
return { ok: true, grant };
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
async function resolveWorkspaceGrant(workspaceGrantId) {
|
|
262
|
-
let state;
|
|
263
|
-
try {
|
|
264
|
-
state = await readState();
|
|
265
|
-
} catch (error) {
|
|
266
|
-
return {
|
|
267
|
-
ok: false,
|
|
268
|
-
message: error instanceof Error ? error.message : "the local harness grant store could not be read"
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
const grant = state.workspaces.find(
|
|
272
|
-
(w) => w.workspaceGrantId === workspaceGrantId
|
|
273
|
-
);
|
|
274
|
-
if (!grant) {
|
|
275
|
-
return { ok: false, message: "unknown workspace grant" };
|
|
276
|
-
}
|
|
277
|
-
try {
|
|
278
|
-
const canonical = await realpath(grant.canonicalPath);
|
|
279
|
-
if (canonical !== grant.canonicalPath) {
|
|
280
|
-
return {
|
|
281
|
-
ok: false,
|
|
282
|
-
message: "the granted workspace now resolves somewhere else; re-select it before running locally"
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
const info = await stat(canonical);
|
|
286
|
-
if (!info.isDirectory()) {
|
|
287
|
-
return {
|
|
288
|
-
ok: false,
|
|
289
|
-
message: "the granted workspace is no longer a directory"
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
const candidate = await validateWorkspaceCandidate(canonical);
|
|
293
|
-
if (!candidate.ok) return candidate;
|
|
294
|
-
return { ok: true, canonicalPath: canonical };
|
|
295
|
-
} catch {
|
|
296
|
-
return {
|
|
297
|
-
ok: false,
|
|
298
|
-
message: "the granted workspace is no longer reachable"
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function grantLocalHarnessConsent(binding, opts) {
|
|
303
|
-
return withGrantLock(async () => {
|
|
304
|
-
const now = opts?.now ?? Date.now();
|
|
305
|
-
const ttlMs = Math.min(opts?.ttlMs ?? GRANT_TTL_MS, GRANT_TTL_MS);
|
|
306
|
-
const token = mintCapabilityToken();
|
|
307
|
-
const grant = {
|
|
308
|
-
grantId: `grant_${randomUUID()}`,
|
|
309
|
-
tokenHash: capabilityFingerprint(token),
|
|
310
|
-
bindingHash: hashGrantBinding(binding),
|
|
311
|
-
binding,
|
|
312
|
-
grantedAt: new Date(now).toISOString(),
|
|
313
|
-
expiresAt: new Date(now + ttlMs).toISOString()
|
|
314
|
-
};
|
|
315
|
-
const state = await readState();
|
|
316
|
-
state.harnessGrants = state.harnessGrants.filter(
|
|
317
|
-
(g) => Date.parse(g.expiresAt) > now
|
|
318
|
-
);
|
|
319
|
-
state.harnessGrants.push(grant);
|
|
320
|
-
await writeState(state);
|
|
321
|
-
logger.info("[local-harness] consent granted", {
|
|
322
|
-
harnessId: binding.harnessId,
|
|
323
|
-
targetKind: binding.targetKind,
|
|
324
|
-
permissionProfile: binding.permissionProfile,
|
|
325
|
-
policyVersion: binding.policyVersion
|
|
326
|
-
});
|
|
327
|
-
return { grantId: grant.grantId, token, expiresAt: grant.expiresAt };
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
async function verifyLocalHarnessGrant(token, binding, opts) {
|
|
331
|
-
if (!token || token.length < 16 || token.length > 256) {
|
|
332
|
-
return {
|
|
333
|
-
ok: false,
|
|
334
|
-
reason: "invalid",
|
|
335
|
-
message: "no local harness grant was presented"
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
if (binding.policyVersion !== LOCAL_HARNESS_POLICY_VERSION) {
|
|
339
|
-
return {
|
|
340
|
-
ok: false,
|
|
341
|
-
reason: "binding-mismatch",
|
|
342
|
-
message: `this grant was minted under policy ${binding.policyVersion}; the current policy is ${LOCAL_HARNESS_POLICY_VERSION}. The terms changed, so consent is asked again.`
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
if (binding.targetKind === "local-isolated") {
|
|
346
|
-
if (binding.isolationPolicyVersion !== LOCAL_ISOLATION_POLICY_VERSION) {
|
|
347
|
-
return {
|
|
348
|
-
ok: false,
|
|
349
|
-
reason: "binding-mismatch",
|
|
350
|
-
message: `this grant was minted under isolation policy ${binding.isolationPolicyVersion ?? "(none)"}; the current isolation policy is ${LOCAL_ISOLATION_POLICY_VERSION}.`
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
} else if (binding.isolationPolicyVersion !== void 0) {
|
|
354
|
-
return {
|
|
355
|
-
ok: false,
|
|
356
|
-
reason: "binding-mismatch",
|
|
357
|
-
message: "a native grant must not carry an isolation policy version"
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
const bindingHash = hashGrantBinding(binding);
|
|
361
|
-
let state;
|
|
362
|
-
try {
|
|
363
|
-
state = await readState();
|
|
364
|
-
} catch (error) {
|
|
365
|
-
return {
|
|
366
|
-
ok: false,
|
|
367
|
-
reason: "invalid",
|
|
368
|
-
message: error instanceof Error ? error.message : "the local harness grant store could not be read"
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
const now = opts?.now ?? Date.now();
|
|
372
|
-
for (const grant of state.harnessGrants) {
|
|
373
|
-
if (!capabilityMatches(token, grant.tokenHash)) continue;
|
|
374
|
-
if (grant.bindingHash !== bindingHash) {
|
|
375
|
-
return {
|
|
376
|
-
ok: false,
|
|
377
|
-
reason: "binding-mismatch",
|
|
378
|
-
message: "the presented grant was issued for different terms (workspace, harness, runtime, target mode, permission profile, or policy version). Local execution never runs under terms the user did not see."
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
if (Date.parse(grant.expiresAt) <= now) {
|
|
382
|
-
return {
|
|
383
|
-
ok: false,
|
|
384
|
-
reason: "expired",
|
|
385
|
-
message: "the local harness grant expired; consent is attended and short-lived"
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
return { ok: true, grantId: grant.grantId };
|
|
389
|
-
}
|
|
390
|
-
return {
|
|
391
|
-
ok: false,
|
|
392
|
-
reason: "absent",
|
|
393
|
-
message: "no local harness grant matches the presented capability"
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function revokeLocalHarnessGrants(selector) {
|
|
397
|
-
return withGrantLock(async () => {
|
|
398
|
-
const state = await readState();
|
|
399
|
-
const before = state.harnessGrants.length;
|
|
400
|
-
if (!selector) {
|
|
401
|
-
state.harnessGrants = [];
|
|
402
|
-
} else if (selector.userId) {
|
|
403
|
-
state.harnessGrants = state.harnessGrants.filter((g) => g.binding.userId !== selector.userId || selector.projectId !== void 0 && g.binding.projectId !== selector.projectId);
|
|
404
|
-
} else if (selector.grantId) {
|
|
405
|
-
state.harnessGrants = state.harnessGrants.filter(
|
|
406
|
-
(g) => g.grantId !== selector.grantId
|
|
407
|
-
);
|
|
408
|
-
} else if (selector.binding) {
|
|
409
|
-
const hash = hashGrantBinding(selector.binding);
|
|
410
|
-
state.harnessGrants = state.harnessGrants.filter(
|
|
411
|
-
(g) => g.bindingHash !== hash
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
const removed = before - state.harnessGrants.length;
|
|
415
|
-
if (removed > 0) {
|
|
416
|
-
await writeState(state);
|
|
417
|
-
logger.info("[local-harness] consent revoked", { removed });
|
|
418
|
-
}
|
|
419
|
-
return removed;
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
function pruneExpiredHarnessGrants(now = Date.now()) {
|
|
423
|
-
return withGrantLock(async () => {
|
|
424
|
-
const state = await readState();
|
|
425
|
-
const before = state.harnessGrants.length;
|
|
426
|
-
state.harnessGrants = state.harnessGrants.filter(
|
|
427
|
-
(g) => Date.parse(g.expiresAt) > now
|
|
428
|
-
);
|
|
429
|
-
const removed = before - state.harnessGrants.length;
|
|
430
|
-
if (removed > 0) await writeState(state);
|
|
431
|
-
return removed;
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
function forgetWorkspaceGrant(workspaceGrantId) {
|
|
435
|
-
return withGrantLock(async () => {
|
|
436
|
-
const state = await readState();
|
|
437
|
-
state.workspaces = state.workspaces.filter((w) => w.workspaceGrantId !== workspaceGrantId);
|
|
438
|
-
state.harnessGrants = state.harnessGrants.filter((g) => g.binding.workspaceGrantId !== workspaceGrantId);
|
|
439
|
-
await writeState(state);
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// server/utils/harness/local/session-registry.ts
|
|
444
|
-
var sessions = /* @__PURE__ */ new Map();
|
|
445
|
-
var unstopped = /* @__PURE__ */ new Set();
|
|
446
|
-
function registerLocalHarnessSession(record) {
|
|
447
|
-
sessions.set(record.sessionId, record);
|
|
448
|
-
}
|
|
449
|
-
function getLocalHarnessSession(sessionId) {
|
|
450
|
-
return sessions.get(sessionId);
|
|
451
|
-
}
|
|
452
|
-
function forgetLocalHarnessSession(sessionId) {
|
|
453
|
-
sessions.delete(sessionId);
|
|
454
|
-
}
|
|
455
|
-
function forgetLocalHarnessSessionRecord(record) {
|
|
456
|
-
unstopped.delete(record);
|
|
457
|
-
if (sessions.get(record.sessionId) !== record) return false;
|
|
458
|
-
sessions.delete(record.sessionId);
|
|
459
|
-
return true;
|
|
460
|
-
}
|
|
461
|
-
function claimRecord(record) {
|
|
462
|
-
const claimed = sessions.get(record.sessionId) === record || unstopped.has(record);
|
|
463
|
-
if (!claimed) return false;
|
|
464
|
-
if (sessions.get(record.sessionId) === record) {
|
|
465
|
-
sessions.delete(record.sessionId);
|
|
466
|
-
}
|
|
467
|
-
unstopped.delete(record);
|
|
468
|
-
return true;
|
|
469
|
-
}
|
|
470
|
-
async function endLocalHarnessSession(sessionId) {
|
|
471
|
-
const record = sessions.get(sessionId);
|
|
472
|
-
if (record === void 0) return { stopped: true, errors: [] };
|
|
473
|
-
if (!claimRecord(record)) return { stopped: true, errors: [] };
|
|
474
|
-
return endRecord(record);
|
|
475
|
-
}
|
|
476
|
-
async function endRecord(record) {
|
|
477
|
-
const sessionId = record.sessionId;
|
|
478
|
-
const errors = [];
|
|
479
|
-
try {
|
|
480
|
-
record.onEnded?.();
|
|
481
|
-
} catch (error) {
|
|
482
|
-
errors.push(`end hook: ${messageOf(error)}`);
|
|
483
|
-
}
|
|
484
|
-
try {
|
|
485
|
-
record.gateway?.revoke();
|
|
486
|
-
} catch (error) {
|
|
487
|
-
errors.push(`gateway revoke: ${messageOf(error)}`);
|
|
488
|
-
}
|
|
489
|
-
try {
|
|
490
|
-
await record.gateway?.close();
|
|
491
|
-
} catch (error) {
|
|
492
|
-
errors.push(`gateway close: ${messageOf(error)}`);
|
|
493
|
-
}
|
|
494
|
-
try {
|
|
495
|
-
await record.revokeLease?.();
|
|
496
|
-
} catch (error) {
|
|
497
|
-
errors.push(`lease revoke: ${messageOf(error)}`);
|
|
498
|
-
}
|
|
499
|
-
let stopped = true;
|
|
500
|
-
try {
|
|
501
|
-
const outcome = await record.stop();
|
|
502
|
-
if (outcome?.stopped !== true) {
|
|
503
|
-
stopped = false;
|
|
504
|
-
errors.push(
|
|
505
|
-
`stop: ${outcome?.escaped ?? "some"} process(es) escaped the session`
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
} catch (error) {
|
|
509
|
-
stopped = false;
|
|
510
|
-
errors.push(`stop: ${messageOf(error)}`);
|
|
511
|
-
}
|
|
512
|
-
if (stopped) {
|
|
513
|
-
unstopped.delete(record);
|
|
514
|
-
try {
|
|
515
|
-
await record.releaseRuntime?.();
|
|
516
|
-
} catch (error) {
|
|
517
|
-
errors.push(`runtime release: ${messageOf(error)}`);
|
|
518
|
-
}
|
|
519
|
-
} else {
|
|
520
|
-
unstopped.add(record);
|
|
521
|
-
if (!sessions.has(sessionId)) sessions.set(sessionId, record);
|
|
522
|
-
}
|
|
523
|
-
if (errors.length > 0) {
|
|
524
|
-
logger.warn("[local-harness] session teardown had failures", {
|
|
525
|
-
sessionId,
|
|
526
|
-
errors
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
return { stopped, errors };
|
|
530
|
-
}
|
|
531
|
-
async function stopAllLocalHarnessSessions() {
|
|
532
|
-
const candidates = [.../* @__PURE__ */ new Set([...sessions.values(), ...unstopped])];
|
|
533
|
-
const mine = candidates.filter(claimRecord);
|
|
534
|
-
const results = await Promise.all(
|
|
535
|
-
mine.map(
|
|
536
|
-
(record) => endRecord(record).catch(() => ({
|
|
537
|
-
stopped: false,
|
|
538
|
-
errors: ["unexpected"]
|
|
539
|
-
}))
|
|
540
|
-
)
|
|
541
|
-
);
|
|
542
|
-
const failed = results.filter((result) => !result.stopped).length;
|
|
543
|
-
return { ok: failed === 0, stopped: results.length - failed, failed };
|
|
544
|
-
}
|
|
545
|
-
function messageOf(error) {
|
|
546
|
-
return error instanceof Error ? error.message : String(error);
|
|
547
|
-
}
|
|
548
|
-
async function stopLocalHarnessWorkspace(workspaceGrantId) {
|
|
549
|
-
const records = new Set([...sessions.values(), ...unstopped].filter((record) => record.workspaceGrantId === workspaceGrantId));
|
|
550
|
-
let stopped = true;
|
|
551
|
-
for (const record of records) {
|
|
552
|
-
if (claimRecord(record)) stopped = (await endRecord(record)).stopped && stopped;
|
|
553
|
-
else stopped = false;
|
|
554
|
-
}
|
|
555
|
-
return stopped;
|
|
556
|
-
}
|
|
557
|
-
async function stopLocalHarnessProject(userId, projectId) {
|
|
558
|
-
const records = new Set([...sessions.values(), ...unstopped].filter((record) => record.userId === userId && (projectId === void 0 || record.projectId === projectId)));
|
|
559
|
-
await Promise.all([...records].filter(claimRecord).map(endRecord));
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// server/utils/harness/local/authorization.ts
|
|
563
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
564
|
-
import { join as join2 } from "path";
|
|
565
|
-
import { z } from "zod";
|
|
566
|
-
var harnessIdSchema = z.enum(["claude-code", "codex"]);
|
|
567
|
-
var authorization = z.object({
|
|
568
|
-
userId: z.string().min(1),
|
|
569
|
-
machineId: z.string().min(1),
|
|
570
|
-
projectId: z.string().min(1),
|
|
571
|
-
harnessId: harnessIdSchema,
|
|
572
|
-
autoApproveAcknowledgedAt: z.string().datetime().optional(),
|
|
573
|
-
workspaceGrantId: z.string().min(1),
|
|
574
|
-
policyVersion: z.string().min(1),
|
|
575
|
-
authorizedAt: z.string().datetime(),
|
|
576
|
-
unattended: z.literal(true)
|
|
577
|
-
});
|
|
578
|
-
var legacyAuthorization = authorization.extend({ harnessId: harnessIdSchema.optional() });
|
|
579
|
-
var schema = z.object({
|
|
580
|
-
version: z.literal(1),
|
|
581
|
-
authorizations: z.array(legacyAuthorization),
|
|
582
|
-
harnessAuthorizations: z.array(authorization).optional()
|
|
583
|
-
});
|
|
584
|
-
var file = () => join2(localHarnessStateRoot(), "authorizations.json");
|
|
585
|
-
var lock = createLocalStateMutationLock({ rootDir: localHarnessStateRoot, lockFileName: "authorizations.lock", resourceLabel: "authorization" });
|
|
586
|
-
async function read() {
|
|
587
|
-
try {
|
|
588
|
-
const stored = schema.parse(JSON.parse(await readFile2(file(), "utf8")));
|
|
589
|
-
return {
|
|
590
|
-
authorizations: [
|
|
591
|
-
...stored.authorizations.map((a) => ({ ...a, harnessId: a.harnessId ?? "claude-code" })),
|
|
592
|
-
...stored.harnessAuthorizations ?? []
|
|
593
|
-
]
|
|
594
|
-
};
|
|
595
|
-
} catch (error) {
|
|
596
|
-
if (error.code === "ENOENT") return { authorizations: [] };
|
|
597
|
-
throw new Error("Local authorization could not be read. Restore the authorization store or authorize this client again.", { cause: error });
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
async function write(state) {
|
|
601
|
-
await persistCapabilityState(file(), {
|
|
602
|
-
version: 1,
|
|
603
|
-
authorizations: state.authorizations.filter((a) => a.harnessId === "claude-code").map(({ harnessId: _harnessId, ...legacy }) => legacy),
|
|
604
|
-
harnessAuthorizations: state.authorizations.filter((a) => a.harnessId !== "claude-code")
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
async function readLocalHarnessAuthorization(userId, machineId, projectId, harnessId = "claude-code") {
|
|
608
|
-
return (await read()).authorizations.find((a) => a.userId === userId && a.machineId === machineId && a.projectId === projectId && a.harnessId === harnessId && a.policyVersion === LOCAL_HARNESS_POLICY_VERSION) ?? null;
|
|
609
|
-
}
|
|
610
|
-
async function authorizeLocalHarness(args) {
|
|
611
|
-
return lock(async () => {
|
|
612
|
-
const state = await read();
|
|
613
|
-
const harnessId = args.harnessId ?? "claude-code";
|
|
614
|
-
const existing = state.authorizations.find((a) => a.userId === args.userId && a.machineId === args.machineId && a.projectId === args.projectId && a.harnessId === harnessId && a.policyVersion === LOCAL_HARNESS_POLICY_VERSION);
|
|
615
|
-
const record = { ...existing?.autoApproveAcknowledgedAt ? { autoApproveAcknowledgedAt: existing.autoApproveAcknowledgedAt } : {}, ...args, harnessId, policyVersion: LOCAL_HARNESS_POLICY_VERSION, authorizedAt: (/* @__PURE__ */ new Date()).toISOString(), unattended: true };
|
|
616
|
-
state.authorizations = state.authorizations.filter((a) => !(a.userId === args.userId && a.machineId === args.machineId && a.projectId === args.projectId && a.harnessId === harnessId));
|
|
617
|
-
state.authorizations.push(record);
|
|
618
|
-
await write(state);
|
|
619
|
-
return record;
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
async function revokeLocalHarnessAuthorization(userId, projectId) {
|
|
623
|
-
await lock(async () => {
|
|
624
|
-
const state = await read();
|
|
625
|
-
const revoked = state.authorizations.filter((a) => a.userId === userId && (projectId === void 0 || a.projectId === projectId));
|
|
626
|
-
state.authorizations = state.authorizations.filter((a) => !revoked.includes(a));
|
|
627
|
-
await write(state);
|
|
628
|
-
await revokeLocalHarnessGrants({ userId, projectId });
|
|
629
|
-
await stopLocalHarnessProject(userId, projectId);
|
|
630
|
-
await Promise.all(
|
|
631
|
-
revoked.map((a) => stopLocalHarnessWorkspace(a.workspaceGrantId))
|
|
632
|
-
);
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
async function updateAuthorizedWorkspace(args) {
|
|
636
|
-
await lock(async () => {
|
|
637
|
-
const state = await read();
|
|
638
|
-
const harnessId = args.harnessId ?? "claude-code";
|
|
639
|
-
const record = state.authorizations.find((a) => a.userId === args.userId && a.machineId === args.machineId && a.projectId === args.projectId && a.harnessId === harnessId && a.policyVersion === LOCAL_HARNESS_POLICY_VERSION);
|
|
640
|
-
if (!record) return;
|
|
641
|
-
record.workspaceGrantId = args.workspaceGrantId;
|
|
642
|
-
await write(state);
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
async function acknowledgeLocalHarnessAutoApprove(args) {
|
|
646
|
-
return lock(async () => {
|
|
647
|
-
const state = await read();
|
|
648
|
-
const record = state.authorizations.find(
|
|
649
|
-
(a) => a.userId === args.userId && a.machineId === args.machineId && a.projectId === args.projectId && a.harnessId === args.harnessId && a.policyVersion === LOCAL_HARNESS_POLICY_VERSION
|
|
650
|
-
);
|
|
651
|
-
if (!record)
|
|
652
|
-
throw new Error(
|
|
653
|
-
"Set up this local harness before allowing commands without asking"
|
|
654
|
-
);
|
|
655
|
-
record.autoApproveAcknowledgedAt ??= (/* @__PURE__ */ new Date()).toISOString();
|
|
656
|
-
await write(state);
|
|
657
|
-
return record;
|
|
658
|
-
});
|
|
659
|
-
}
|
|
51
|
+
LOCAL_HARNESS_ENABLED
|
|
52
|
+
} from "./chunk-7ZIR7SX7.js";
|
|
660
53
|
|
|
661
54
|
// shared/harness-model-support-evidence.json
|
|
662
55
|
var harness_model_support_evidence_default = {
|
|
@@ -931,7 +324,8 @@ async function startHarnessModelBroker(args) {
|
|
|
931
324
|
return {
|
|
932
325
|
ok: false,
|
|
933
326
|
status: response.ok ? 502 : response.status,
|
|
934
|
-
error: typeof payload?.error === "string" ? payload.error : `Harness model-broker failed (${response.status})
|
|
327
|
+
error: typeof payload?.error === "string" ? payload.error : `Harness model-broker failed (${response.status})`,
|
|
328
|
+
...!response.ok && typeof payload?.code === "string" ? { code: payload.code } : {}
|
|
935
329
|
};
|
|
936
330
|
}
|
|
937
331
|
return {
|
|
@@ -1339,16 +733,28 @@ async function resolveLocalHarnessAvailability(query) {
|
|
|
1339
733
|
if (!workspace.ok) {
|
|
1340
734
|
return unavailable("workspace-grant-invalid", workspace.message);
|
|
1341
735
|
}
|
|
736
|
+
const packTarget = localPackTarget(platform);
|
|
737
|
+
if (query.runtimeDigest !== void 0 && query.manifests === void 0 && compatibility.manifest.runtime.source === "managed-bundle" && packTarget !== null) {
|
|
738
|
+
const selectable = await isSelectablePack(compatibility.manifest.harnessId, packTarget, query.runtimeDigest);
|
|
739
|
+
if (!selectable.ok) return unavailable("runtime-unavailable", selectable.message);
|
|
740
|
+
}
|
|
1342
741
|
const runtimeResolution = compatibility.manifest.runtime.source === "managed-bundle" ? await resolveManagedBundle({
|
|
1343
742
|
// Through `manifestWithExpectedBundleDigest`, so this path verifies
|
|
1344
743
|
// against the digest the INSTALLER accepted rather than a second
|
|
1345
744
|
// reading of the same table. They differ only under the documented
|
|
1346
745
|
// development override — and there they differed fatally: a locally
|
|
1347
746
|
// built pack installed and then could never run.
|
|
1348
|
-
|
|
747
|
+
//
|
|
748
|
+
// EXCEPT for a caller that supplied its own manifests (the
|
|
749
|
+
// conformance runners): their manifest names the pack under test,
|
|
750
|
+
// and replacing its digest with the pinned one made a pack built
|
|
751
|
+
// from changed inputs — exactly what a pack-input change or a new
|
|
752
|
+
// pack's pre-pin conformance has to run — unrunnable.
|
|
753
|
+
manifest: query.manifests !== void 0 ? compatibility.manifest : manifestWithExpectedBundleDigest(
|
|
1349
754
|
compatibility.manifest,
|
|
1350
755
|
compatibility.manifest.harnessId,
|
|
1351
|
-
|
|
756
|
+
packTarget,
|
|
757
|
+
query.runtimeDigest
|
|
1352
758
|
),
|
|
1353
759
|
runtimeRoot: query.runtimeRoot,
|
|
1354
760
|
platform: currentLocalPlatform(platform)
|
|
@@ -1425,14 +831,14 @@ function resolveNodeLauncher(opts) {
|
|
|
1425
831
|
// server/utils/harness/local/model-gateway.ts
|
|
1426
832
|
import { randomBytes, timingSafeEqual } from "crypto";
|
|
1427
833
|
import { execFile as execFile2 } from "child_process";
|
|
1428
|
-
import { readdir as readdir2, readFile as
|
|
834
|
+
import { readdir as readdir2, readFile as readFile3, readlink as readlink2 } from "fs/promises";
|
|
1429
835
|
import {
|
|
1430
836
|
createServer as createServer2
|
|
1431
837
|
} from "http";
|
|
1432
838
|
|
|
1433
839
|
// server/utils/harness/local/bridge-endpoint.ts
|
|
1434
840
|
import { execFile } from "child_process";
|
|
1435
|
-
import { readdir, readFile
|
|
841
|
+
import { readdir, readFile, readlink } from "fs/promises";
|
|
1436
842
|
import { createConnection, createServer } from "net";
|
|
1437
843
|
import { networkInterfaces } from "os";
|
|
1438
844
|
var LOOPBACK_HOST_V4 = "127.0.0.1";
|
|
@@ -1627,7 +1033,7 @@ async function readLinuxListenAddresses(pid) {
|
|
|
1627
1033
|
for (const table of ["/proc/net/tcp", "/proc/net/tcp6"]) {
|
|
1628
1034
|
let raw;
|
|
1629
1035
|
try {
|
|
1630
|
-
raw = await
|
|
1036
|
+
raw = await readFile(table, "utf8");
|
|
1631
1037
|
} catch {
|
|
1632
1038
|
continue;
|
|
1633
1039
|
}
|
|
@@ -1683,8 +1089,8 @@ function isLoopbackBoundAddress(address) {
|
|
|
1683
1089
|
}
|
|
1684
1090
|
async function assertBridgeBindingIsLoopback(args) {
|
|
1685
1091
|
const platform = args.platform ?? process.platform;
|
|
1686
|
-
const
|
|
1687
|
-
const addresses = await
|
|
1092
|
+
const read = args.read ?? readProcessListenAddresses;
|
|
1093
|
+
const addresses = await read(args.pid, platform);
|
|
1688
1094
|
if (addresses === null) return;
|
|
1689
1095
|
const offBox = addresses.filter(
|
|
1690
1096
|
(address) => !isLoopbackBoundAddress(address)
|
|
@@ -1698,8 +1104,8 @@ async function assertBridgeBindingIsLoopback(args) {
|
|
|
1698
1104
|
|
|
1699
1105
|
// server/utils/harness/local/instance-key.ts
|
|
1700
1106
|
import { createHash, generateKeyPairSync, sign as edSign } from "crypto";
|
|
1701
|
-
import { chmod
|
|
1702
|
-
import { join
|
|
1107
|
+
import { chmod, mkdir, readFile as readFile2, stat, writeFile } from "fs/promises";
|
|
1108
|
+
import { join } from "path";
|
|
1703
1109
|
var POP_SCHEME_PREFIX = "mcpjam-pop-v1";
|
|
1704
1110
|
var KEY_FILE = "instance-key.json";
|
|
1705
1111
|
var KeystoreUnavailableError = class extends Error {
|
|
@@ -1709,7 +1115,7 @@ var cached = null;
|
|
|
1709
1115
|
var cachedKeyId = null;
|
|
1710
1116
|
var loading = null;
|
|
1711
1117
|
function keyFilePath() {
|
|
1712
|
-
return
|
|
1118
|
+
return join(localHarnessStateRoot(), KEY_FILE);
|
|
1713
1119
|
}
|
|
1714
1120
|
function toBase64Url(bytes) {
|
|
1715
1121
|
return bytes.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
@@ -1723,7 +1129,7 @@ async function loadLocalInstanceKey() {
|
|
|
1723
1129
|
let stored = null;
|
|
1724
1130
|
let fileExists = true;
|
|
1725
1131
|
try {
|
|
1726
|
-
stored = JSON.parse(await
|
|
1132
|
+
stored = JSON.parse(await readFile2(path, "utf8"));
|
|
1727
1133
|
} catch (error) {
|
|
1728
1134
|
fileExists = error?.code !== "ENOENT";
|
|
1729
1135
|
stored = null;
|
|
@@ -1762,12 +1168,12 @@ async function loadLocalInstanceKey() {
|
|
|
1762
1168
|
next.protection = "os-keystore";
|
|
1763
1169
|
next.privateKey = keystore.encrypt(privateKeyPem);
|
|
1764
1170
|
}
|
|
1765
|
-
await
|
|
1171
|
+
await mkdir(localHarnessStateRoot(), { recursive: true, mode: 448 });
|
|
1766
1172
|
const serialized = `${JSON.stringify(next, null, 2)}
|
|
1767
1173
|
`;
|
|
1768
1174
|
if (!fileExists) {
|
|
1769
1175
|
try {
|
|
1770
|
-
await
|
|
1176
|
+
await writeFile(path, serialized, { mode: 384, flag: "wx" });
|
|
1771
1177
|
} catch (error) {
|
|
1772
1178
|
if (error?.code !== "EEXIST") throw error;
|
|
1773
1179
|
const adopted = await adoptExistingKey(path, machineId);
|
|
@@ -1775,10 +1181,10 @@ async function loadLocalInstanceKey() {
|
|
|
1775
1181
|
cached = adopted;
|
|
1776
1182
|
return adopted;
|
|
1777
1183
|
}
|
|
1778
|
-
await
|
|
1184
|
+
await writeFile(path, serialized, { mode: 384 });
|
|
1779
1185
|
}
|
|
1780
1186
|
} else {
|
|
1781
|
-
await
|
|
1187
|
+
await writeFile(path, serialized, { mode: 384 });
|
|
1782
1188
|
}
|
|
1783
1189
|
await repairKeyFileMode(path, true);
|
|
1784
1190
|
const loaded = {
|
|
@@ -1797,7 +1203,7 @@ async function loadLocalInstanceKey() {
|
|
|
1797
1203
|
}
|
|
1798
1204
|
async function adoptExistingKey(path, machineId) {
|
|
1799
1205
|
try {
|
|
1800
|
-
const stored = JSON.parse(await
|
|
1206
|
+
const stored = JSON.parse(await readFile2(path, "utf8"));
|
|
1801
1207
|
return {
|
|
1802
1208
|
machineId,
|
|
1803
1209
|
publicKey: stored.publicKey,
|
|
@@ -1810,9 +1216,9 @@ async function adoptExistingKey(path, machineId) {
|
|
|
1810
1216
|
async function repairKeyFileMode(path, quiet = false) {
|
|
1811
1217
|
if (process.platform === "win32") return;
|
|
1812
1218
|
try {
|
|
1813
|
-
const mode = (await
|
|
1219
|
+
const mode = (await stat(path)).mode & 511;
|
|
1814
1220
|
if ((mode & 63) === 0) return;
|
|
1815
|
-
await
|
|
1221
|
+
await chmod(path, 384);
|
|
1816
1222
|
if (!quiet) {
|
|
1817
1223
|
logger.warn("[local-harness] instance key file was not owner-only", {
|
|
1818
1224
|
// The mode, never the path: the path is a home directory.
|
|
@@ -1974,7 +1380,7 @@ async function startLocalModelGateway(options) {
|
|
|
1974
1380
|
refuse(res, 404, "endpoint not allowed");
|
|
1975
1381
|
return;
|
|
1976
1382
|
}
|
|
1977
|
-
if (!
|
|
1383
|
+
if (!capabilityMatches(req, capabilityBytes)) {
|
|
1978
1384
|
refuse(res, 401, "capability rejected");
|
|
1979
1385
|
return;
|
|
1980
1386
|
}
|
|
@@ -2155,7 +1561,7 @@ function isAllowedPath(method, path) {
|
|
|
2155
1561
|
(entry) => entry.method === method && (bare === entry.prefix || bare.startsWith(`${entry.prefix}/`))
|
|
2156
1562
|
);
|
|
2157
1563
|
}
|
|
2158
|
-
function
|
|
1564
|
+
function capabilityMatches(req, expected) {
|
|
2159
1565
|
const header = req.headers["x-api-key"] ?? req.headers.authorization;
|
|
2160
1566
|
const presented = typeof header === "string" ? header.replace(/^Bearer\s+/i, "") : Array.isArray(header) ? "" : "";
|
|
2161
1567
|
const presentedBytes = Buffer.from(presented, "utf8");
|
|
@@ -2234,7 +1640,7 @@ async function findLocalSocketInode(port) {
|
|
|
2234
1640
|
for (const table of ["/proc/net/tcp", "/proc/net/tcp6"]) {
|
|
2235
1641
|
let raw;
|
|
2236
1642
|
try {
|
|
2237
|
-
raw = await
|
|
1643
|
+
raw = await readFile3(table, "utf8");
|
|
2238
1644
|
} catch {
|
|
2239
1645
|
continue;
|
|
2240
1646
|
}
|
|
@@ -2430,31 +1836,31 @@ function refusal(reason, message) {
|
|
|
2430
1836
|
}
|
|
2431
1837
|
|
|
2432
1838
|
// server/utils/harness/local/supervised-provider.ts
|
|
2433
|
-
import { randomUUID
|
|
1839
|
+
import { randomUUID } from "crypto";
|
|
2434
1840
|
import {
|
|
2435
1841
|
lstat as lstat2,
|
|
2436
|
-
mkdir as
|
|
1842
|
+
mkdir as mkdir2,
|
|
2437
1843
|
open,
|
|
2438
1844
|
readlink as readlink4,
|
|
2439
|
-
realpath as
|
|
2440
|
-
rename
|
|
1845
|
+
realpath as realpath2,
|
|
1846
|
+
rename,
|
|
2441
1847
|
rm,
|
|
2442
|
-
stat as
|
|
1848
|
+
stat as stat2,
|
|
2443
1849
|
symlink
|
|
2444
1850
|
} from "fs/promises";
|
|
2445
1851
|
import {
|
|
2446
1852
|
basename,
|
|
2447
1853
|
dirname as dirname2,
|
|
2448
1854
|
isAbsolute as isAbsolute3,
|
|
2449
|
-
join as
|
|
1855
|
+
join as join2,
|
|
2450
1856
|
posix as posix4,
|
|
2451
1857
|
resolve as resolve2,
|
|
2452
|
-
sep as
|
|
1858
|
+
sep as sep3
|
|
2453
1859
|
} from "path";
|
|
2454
1860
|
|
|
2455
1861
|
// server/utils/harness/local/confine.ts
|
|
2456
|
-
import { lstat, readlink as readlink3, realpath
|
|
2457
|
-
import { dirname, isAbsolute as isAbsolute2, normalize, resolve, sep
|
|
1862
|
+
import { lstat, readlink as readlink3, realpath } from "fs/promises";
|
|
1863
|
+
import { dirname, isAbsolute as isAbsolute2, normalize, resolve, sep } from "path";
|
|
2458
1864
|
var MAX_PATH_LENGTH = 4096;
|
|
2459
1865
|
var PathConfinementError = class extends Error {
|
|
2460
1866
|
constructor(message, requestedPath) {
|
|
@@ -2464,20 +1870,20 @@ var PathConfinementError = class extends Error {
|
|
|
2464
1870
|
}
|
|
2465
1871
|
};
|
|
2466
1872
|
function isUnder(candidate, root) {
|
|
2467
|
-
return candidate === root || candidate.startsWith(root +
|
|
1873
|
+
return candidate === root || candidate.startsWith(root + sep);
|
|
2468
1874
|
}
|
|
2469
1875
|
async function resolveExistingAncestor(path) {
|
|
2470
1876
|
const tail = [];
|
|
2471
1877
|
let current = path;
|
|
2472
1878
|
for (; ; ) {
|
|
2473
1879
|
try {
|
|
2474
|
-
return { base: await
|
|
1880
|
+
return { base: await realpath(current), tail };
|
|
2475
1881
|
} catch {
|
|
2476
1882
|
const parent = dirname(current);
|
|
2477
1883
|
if (parent === current) {
|
|
2478
1884
|
return { base: current, tail };
|
|
2479
1885
|
}
|
|
2480
|
-
const cut = parent.endsWith(
|
|
1886
|
+
const cut = parent.endsWith(sep) ? parent.length : parent.length + 1;
|
|
2481
1887
|
tail.unshift(current.slice(cut));
|
|
2482
1888
|
current = parent;
|
|
2483
1889
|
}
|
|
@@ -2503,7 +1909,7 @@ async function resolveDanglingLinks(base, tail, requested) {
|
|
|
2503
1909
|
return resolve(next, ...tail.slice(index + 1));
|
|
2504
1910
|
}
|
|
2505
1911
|
if (!isLink) {
|
|
2506
|
-
next = await
|
|
1912
|
+
next = await realpath(next).catch(() => next);
|
|
2507
1913
|
break;
|
|
2508
1914
|
}
|
|
2509
1915
|
if ((hops += 1) > MAX_LINK_HOPS) {
|
|
@@ -2585,7 +1991,7 @@ function fromAdapterPath(adapterPath, platform = process.platform) {
|
|
|
2585
1991
|
}
|
|
2586
1992
|
|
|
2587
1993
|
// server/utils/harness/local/command-translation.ts
|
|
2588
|
-
import { normalize as normalize2, posix as posix2, sep as
|
|
1994
|
+
import { normalize as normalize2, posix as posix2, sep as sep2 } from "path";
|
|
2589
1995
|
|
|
2590
1996
|
// server/utils/harness/local/argv-policy.ts
|
|
2591
1997
|
var MAX_ARG_LENGTH = 4096;
|
|
@@ -2792,9 +2198,9 @@ function remapBootstrapPath(path, ctx) {
|
|
|
2792
2198
|
);
|
|
2793
2199
|
}
|
|
2794
2200
|
const rest = normalizedPath.slice(root.length).replace(/^\//, "");
|
|
2795
|
-
const mapped = rest ? `${ctx.managedBundleRoot}${
|
|
2201
|
+
const mapped = rest ? `${ctx.managedBundleRoot}${sep2}${rest.split("/").join(sep2)}` : ctx.managedBundleRoot;
|
|
2796
2202
|
const normalized = normalize2(mapped);
|
|
2797
|
-
if (normalized !== ctx.managedBundleRoot && !normalized.startsWith(ctx.managedBundleRoot +
|
|
2203
|
+
if (normalized !== ctx.managedBundleRoot && !normalized.startsWith(ctx.managedBundleRoot + sep2)) {
|
|
2798
2204
|
throw new CommandTranslationError(
|
|
2799
2205
|
`bootstrap path ${JSON.stringify(path)} escapes the managed bundle root`,
|
|
2800
2206
|
path
|
|
@@ -2817,10 +2223,17 @@ function classifyBootstrapPath(path, ctx) {
|
|
|
2817
2223
|
if (BOOTSTRAP_MARKER.test(relative)) {
|
|
2818
2224
|
return {
|
|
2819
2225
|
kind: "session-overlay",
|
|
2820
|
-
overlayPath: `${ctx.bootstrapOverlayDir}${
|
|
2226
|
+
overlayPath: `${ctx.bootstrapOverlayDir}${sep2}${relative}`
|
|
2821
2227
|
};
|
|
2822
2228
|
}
|
|
2823
2229
|
if (ctx.adapterBootstrapFiles.includes(relative)) {
|
|
2230
|
+
if (ctx.layerRoot !== void 0 && ctx.layerFiles?.includes(relative) === true && !relative.includes("/")) {
|
|
2231
|
+
return {
|
|
2232
|
+
kind: "bundle-asset",
|
|
2233
|
+
bundlePath: `${ctx.layerRoot}${sep2}${relative}`,
|
|
2234
|
+
relativePath: relative
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2824
2237
|
return {
|
|
2825
2238
|
kind: "bundle-asset",
|
|
2826
2239
|
bundlePath: remapBootstrapPath(normalized, ctx),
|
|
@@ -2944,7 +2357,10 @@ async function matchBridgeLaunch(command, ctx) {
|
|
|
2944
2357
|
);
|
|
2945
2358
|
}
|
|
2946
2359
|
const args = [
|
|
2947
|
-
ctx.bridgeLauncherPath ?? remapBootstrapPath(expectedBridge, ctx)
|
|
2360
|
+
ctx.bridgeLauncherPath ?? (ctx.layerRoot !== void 0 ? `${ctx.layerRoot}${sep2}bridge.mjs` : remapBootstrapPath(expectedBridge, ctx)),
|
|
2361
|
+
// The launcher's own argument, never the bridge's: only where a launcher
|
|
2362
|
+
// is in front, and only the verified pack.
|
|
2363
|
+
...ctx.bridgeLauncherPath !== void 0 && ctx.launcherVendorRoot !== void 0 ? ["--mcpjam-vendor-root", ctx.launcherVendorRoot] : []
|
|
2948
2364
|
];
|
|
2949
2365
|
for (let i = 0; i < flags.length; i += 1) {
|
|
2950
2366
|
const flag = tokens[1 + i * 2];
|
|
@@ -2963,7 +2379,16 @@ async function matchBridgeLaunch(command, ctx) {
|
|
|
2963
2379
|
command
|
|
2964
2380
|
);
|
|
2965
2381
|
}
|
|
2966
|
-
|
|
2382
|
+
if (ctx.layerRoot !== void 0) {
|
|
2383
|
+
args.push(
|
|
2384
|
+
"--vendor-dir",
|
|
2385
|
+
remapBootstrapPath(value, ctx),
|
|
2386
|
+
"--layer-dir",
|
|
2387
|
+
ctx.layerRoot
|
|
2388
|
+
);
|
|
2389
|
+
} else {
|
|
2390
|
+
args.push(flag, remapBootstrapPath(value, ctx));
|
|
2391
|
+
}
|
|
2967
2392
|
continue;
|
|
2968
2393
|
}
|
|
2969
2394
|
if (ctx.harnessId === "codex" && (flag === "--bridge-state-dir" || flag === "--session-data-dir")) {
|
|
@@ -3154,6 +2579,12 @@ function buildLocalHarnessEnv(opts) {
|
|
|
3154
2579
|
} catch {
|
|
3155
2580
|
}
|
|
3156
2581
|
}
|
|
2582
|
+
for (const root of opts.extraDeniedRoots ?? []) {
|
|
2583
|
+
if (!path.isAbsolute(root)) {
|
|
2584
|
+
throw new LocalHarnessEnvError("a denied runtime root must be an absolute path");
|
|
2585
|
+
}
|
|
2586
|
+
if (!deniedRoots.includes(root)) deniedRoots.push(root);
|
|
2587
|
+
}
|
|
3157
2588
|
env.MCPJAM_LOCAL_DENIED_ROOTS = JSON.stringify(deniedRoots);
|
|
3158
2589
|
env.TMPDIR = path.join(opts.syntheticHome, "tmp");
|
|
3159
2590
|
env.CLAUDE_CODE_TMPDIR = env.TMPDIR;
|
|
@@ -3417,14 +2848,14 @@ async function writeBytesAtomically(path, bytes, abortSignal) {
|
|
|
3417
2848
|
const abortError = () => abortSignal?.reason instanceof Error ? abortSignal.reason : new Error("aborted");
|
|
3418
2849
|
if (abortSignal?.aborted) throw abortError();
|
|
3419
2850
|
const parent = dirname2(path);
|
|
3420
|
-
await
|
|
2851
|
+
await mkdir2(parent, { recursive: true, mode: 448 });
|
|
3421
2852
|
let mode = 384;
|
|
3422
2853
|
try {
|
|
3423
|
-
mode = (await
|
|
2854
|
+
mode = (await stat2(path)).mode & 511;
|
|
3424
2855
|
} catch (error) {
|
|
3425
2856
|
if (error.code !== "ENOENT") throw error;
|
|
3426
2857
|
}
|
|
3427
|
-
const temp =
|
|
2858
|
+
const temp = join2(parent, `.${basename(path)}.${randomUUID()}.tmp`);
|
|
3428
2859
|
const handle = await open(temp, "wx", mode);
|
|
3429
2860
|
let closed = false;
|
|
3430
2861
|
try {
|
|
@@ -3436,7 +2867,7 @@ async function writeBytesAtomically(path, bytes, abortSignal) {
|
|
|
3436
2867
|
if (abortSignal?.aborted) throw abortError();
|
|
3437
2868
|
await handle.close();
|
|
3438
2869
|
closed = true;
|
|
3439
|
-
await
|
|
2870
|
+
await rename(temp, path);
|
|
3440
2871
|
} catch (error) {
|
|
3441
2872
|
if (!closed) await handle.close().catch(() => {
|
|
3442
2873
|
});
|
|
@@ -3450,7 +2881,7 @@ async function resolveGitBashPath(platform) {
|
|
|
3450
2881
|
const configured = process.env.CLAUDE_CODE_GIT_BASH_PATH;
|
|
3451
2882
|
const candidates = [
|
|
3452
2883
|
...configured && isAbsolute3(configured) ? [configured] : [],
|
|
3453
|
-
|
|
2884
|
+
join2(
|
|
3454
2885
|
process.env.ProgramFiles ?? "C:\\Program Files",
|
|
3455
2886
|
"Git",
|
|
3456
2887
|
"bin",
|
|
@@ -3459,7 +2890,7 @@ async function resolveGitBashPath(platform) {
|
|
|
3459
2890
|
];
|
|
3460
2891
|
for (const candidate of candidates) {
|
|
3461
2892
|
try {
|
|
3462
|
-
if ((await
|
|
2893
|
+
if ((await stat2(candidate)).isFile()) return candidate;
|
|
3463
2894
|
} catch {
|
|
3464
2895
|
}
|
|
3465
2896
|
}
|
|
@@ -3517,9 +2948,9 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3517
2948
|
);
|
|
3518
2949
|
}
|
|
3519
2950
|
};
|
|
3520
|
-
const syntheticHome =
|
|
3521
|
-
const bootstrapOverlay =
|
|
3522
|
-
const workRoot =
|
|
2951
|
+
const syntheticHome = join2(opts.sessionStateDir, "home");
|
|
2952
|
+
const bootstrapOverlay = join2(opts.sessionStateDir, "bootstrap");
|
|
2953
|
+
const workRoot = join2(opts.sessionStateDir, "work");
|
|
3523
2954
|
const WORKSPACE_LINK_NAME = "project";
|
|
3524
2955
|
const platform = opts.platform ?? process.platform;
|
|
3525
2956
|
const adapterWorkRoot = toAdapterPath(workRoot, platform);
|
|
@@ -3533,18 +2964,18 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3533
2964
|
};
|
|
3534
2965
|
const buildSession = async (sessionId, abortSignal) => {
|
|
3535
2966
|
for (const dir of syntheticHomeDirectories(syntheticHome, platform)) {
|
|
3536
|
-
await
|
|
2967
|
+
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
3537
2968
|
}
|
|
3538
|
-
await
|
|
3539
|
-
await
|
|
3540
|
-
const workspaceLink =
|
|
2969
|
+
await mkdir2(bootstrapOverlay, { recursive: true, mode: 448 });
|
|
2970
|
+
await mkdir2(workRoot, { recursive: true, mode: 448 });
|
|
2971
|
+
const workspaceLink = join2(workRoot, WORKSPACE_LINK_NAME);
|
|
3541
2972
|
try {
|
|
3542
2973
|
const existing = await lstat2(workspaceLink);
|
|
3543
2974
|
if (!existing.isSymbolicLink()) {
|
|
3544
2975
|
throw new Error(`${workspaceLink} exists and is not the workspace link`);
|
|
3545
2976
|
}
|
|
3546
2977
|
const current = await readlink4(workspaceLink);
|
|
3547
|
-
const resolved = await
|
|
2978
|
+
const resolved = await realpath2(workspaceLink).catch(
|
|
3548
2979
|
(error) => {
|
|
3549
2980
|
if (error.code === "ENOENT") return null;
|
|
3550
2981
|
throw error;
|
|
@@ -3562,17 +2993,34 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3562
2993
|
if (error.code !== "ENOENT") throw error;
|
|
3563
2994
|
await linkWorkspace(workspaceLink);
|
|
3564
2995
|
}
|
|
3565
|
-
const roots = [await
|
|
2996
|
+
const roots = [await realpath2(opts.sessionStateDir), opts.workspacePath];
|
|
3566
2997
|
const confine = (path) => confinePath(fromAdapterPath(path, platform), { roots });
|
|
3567
2998
|
const confineToSessionState = (path) => confinePath(fromAdapterPath(path, platform), { roots: [roots[0]] });
|
|
3568
2999
|
const gitBashPath = opts.harnessId === "claude-code" ? await resolveGitBashPath(platform) : void 0;
|
|
3000
|
+
for (const runtimeDir of [
|
|
3001
|
+
opts.runtime.rootPath,
|
|
3002
|
+
...opts.runtime.layer !== void 0 ? [opts.runtime.layer.root] : []
|
|
3003
|
+
]) {
|
|
3004
|
+
for (const writable of roots) {
|
|
3005
|
+
if (runtimeDir === writable || runtimeDir.startsWith(writable + sep3)) {
|
|
3006
|
+
throw new Error(
|
|
3007
|
+
`the local runtime at ${runtimeDir} is inside a directory this session may write, so it cannot be protected from the agent it launches. Pick a workspace that does not contain the Inspector's runtime directory.`
|
|
3008
|
+
);
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3569
3012
|
const env = {
|
|
3570
3013
|
...buildLocalHarnessEnv({
|
|
3571
3014
|
syntheticHome,
|
|
3572
3015
|
sessionRoot: opts.workspacePath,
|
|
3573
3016
|
platform,
|
|
3574
3017
|
...opts.scopedEnv ? { scoped: opts.scopedEnv } : {},
|
|
3575
|
-
...gitBashPath !== void 0 ? { gitBashPath } : {}
|
|
3018
|
+
...gitBashPath !== void 0 ? { gitBashPath } : {},
|
|
3019
|
+
// Named in the agent's own deny rules, alongside sibling sessions.
|
|
3020
|
+
extraDeniedRoots: [
|
|
3021
|
+
...opts.runtime.layer !== void 0 ? [opts.runtime.layer.root] : [],
|
|
3022
|
+
opts.runtime.rootPath
|
|
3023
|
+
]
|
|
3576
3024
|
}),
|
|
3577
3025
|
...opts.launcher.requiredEnv
|
|
3578
3026
|
};
|
|
@@ -3586,11 +3034,18 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3586
3034
|
opts.manifest.adapterBootstrapDir
|
|
3587
3035
|
),
|
|
3588
3036
|
managedBundleRoot: opts.runtime.rootPath,
|
|
3037
|
+
...opts.runtime.layer !== void 0 ? {
|
|
3038
|
+
layerRoot: opts.runtime.layer.root,
|
|
3039
|
+
layerFiles: opts.runtime.layer.files,
|
|
3040
|
+
// The layer's launcher resolves a vendor SDK import into the
|
|
3041
|
+
// verified pack and nowhere else.
|
|
3042
|
+
launcherVendorRoot: opts.runtime.rootPath
|
|
3043
|
+
} : {},
|
|
3589
3044
|
adapterBootstrapFiles: opts.manifest.adapterBootstrapFiles,
|
|
3590
3045
|
bootstrapOverlayDir: bootstrapOverlay,
|
|
3591
3046
|
nodeExecutable: opts.launcher.executable,
|
|
3592
|
-
// Launch the
|
|
3593
|
-
// `bridge.mjs
|
|
3047
|
+
// Launch the loopback/resolution wrapper (the Inspector layer's, or a
|
|
3048
|
+
// legacy pack's) rather than `bridge.mjs` directly.
|
|
3594
3049
|
bridgeLauncherPath: opts.runtime.launcherPath,
|
|
3595
3050
|
// The framework's default working directory (and the bridge's cwd), in
|
|
3596
3051
|
// the shape the adapter composes with. `confine` turns it native.
|
|
@@ -3669,7 +3124,7 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3669
3124
|
// were confined to the synthetic home by the translator; no shell is
|
|
3670
3125
|
// involved at any point.
|
|
3671
3126
|
case "rename": {
|
|
3672
|
-
await
|
|
3127
|
+
await rename(translated.from, translated.to);
|
|
3673
3128
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
3674
3129
|
}
|
|
3675
3130
|
case "remove": {
|
|
@@ -3680,7 +3135,7 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3680
3135
|
}
|
|
3681
3136
|
case "probe-absent": {
|
|
3682
3137
|
try {
|
|
3683
|
-
await
|
|
3138
|
+
await stat2(translated.path);
|
|
3684
3139
|
return { exitCode: 1, stdout: "", stderr: "" };
|
|
3685
3140
|
} catch (error) {
|
|
3686
3141
|
if (error.code === "ENOENT") {
|
|
@@ -3696,7 +3151,7 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3696
3151
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
3697
3152
|
case "mkdir": {
|
|
3698
3153
|
for (const path of translated.paths) {
|
|
3699
|
-
await
|
|
3154
|
+
await mkdir2(path, { recursive: true, mode: 448 });
|
|
3700
3155
|
}
|
|
3701
3156
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
3702
3157
|
}
|
|
@@ -3845,11 +3300,14 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3845
3300
|
if (isBridge) bridgeClaimed = false;
|
|
3846
3301
|
};
|
|
3847
3302
|
let handle;
|
|
3303
|
+
const aborted = () => (signal ?? abortSignal)?.aborted === true;
|
|
3304
|
+
let spawning = false;
|
|
3848
3305
|
try {
|
|
3849
3306
|
await assertRuntimeUnchanged();
|
|
3850
3307
|
if (isBridge) {
|
|
3851
3308
|
await assertBridgePortUnclaimed({ port: opts.bridgePort });
|
|
3852
3309
|
}
|
|
3310
|
+
spawning = true;
|
|
3853
3311
|
handle = await opts.supervisor.spawnSupervised({
|
|
3854
3312
|
sessionId,
|
|
3855
3313
|
executable: translated.executable,
|
|
@@ -3868,9 +3326,13 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3868
3326
|
});
|
|
3869
3327
|
} catch (error) {
|
|
3870
3328
|
releaseBridgeClaim();
|
|
3329
|
+
if (isBridge && spawning && !aborted()) {
|
|
3330
|
+
opts.onBridgeFailed?.({ phase: "spawn", message: error instanceof Error ? error.message : String(error) });
|
|
3331
|
+
}
|
|
3871
3332
|
throw error;
|
|
3872
3333
|
}
|
|
3873
3334
|
if (isBridge) {
|
|
3335
|
+
let bridgeReady = false;
|
|
3874
3336
|
try {
|
|
3875
3337
|
await assertBridgeLoopbackOnly({
|
|
3876
3338
|
port: opts.bridgePort,
|
|
@@ -3883,6 +3345,7 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3883
3345
|
// after our bridge died is somebody else's.
|
|
3884
3346
|
isBridgeAlive: async () => opts.supervisor.liveProcessCount(sessionId) > 0
|
|
3885
3347
|
});
|
|
3348
|
+
bridgeReady = true;
|
|
3886
3349
|
if (opts.onBridgeStarted) {
|
|
3887
3350
|
await opts.onBridgeStarted({
|
|
3888
3351
|
pid: handle.pid,
|
|
@@ -3901,6 +3364,12 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3901
3364
|
).catch(() => "no diagnosis could be read");
|
|
3902
3365
|
error.message = `${error.message} (bridge: ${said})`;
|
|
3903
3366
|
}
|
|
3367
|
+
if (!bridgeReady && !aborted()) {
|
|
3368
|
+
opts.onBridgeFailed?.({
|
|
3369
|
+
phase: "readiness",
|
|
3370
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3904
3373
|
throw error;
|
|
3905
3374
|
}
|
|
3906
3375
|
}
|
|
@@ -3984,7 +3453,7 @@ function createSupervisedLocalHarnessProvider(opts) {
|
|
|
3984
3453
|
async function removeSessionStateDir(dir) {
|
|
3985
3454
|
const root = resolve2(`${localHarnessStateRoot()}-sessions`);
|
|
3986
3455
|
const target = resolve2(dir);
|
|
3987
|
-
if (target === root || !target.startsWith(root +
|
|
3456
|
+
if (target === root || !target.startsWith(root + sep3)) {
|
|
3988
3457
|
logger.warn("[local-harness] refusing to remove state outside the root", {
|
|
3989
3458
|
dir
|
|
3990
3459
|
});
|
|
@@ -4000,27 +3469,27 @@ function sessionStateDirFor(stateRoot, sessionId) {
|
|
|
4000
3469
|
)} is not a single safe path segment`
|
|
4001
3470
|
);
|
|
4002
3471
|
}
|
|
4003
|
-
return
|
|
3472
|
+
return join2(`${stateRoot}-sessions`, sessionId);
|
|
4004
3473
|
}
|
|
4005
3474
|
|
|
4006
3475
|
// server/utils/harness/local/supervisor.ts
|
|
4007
3476
|
import { spawn } from "child_process";
|
|
4008
|
-
import { mkdir as
|
|
3477
|
+
import { mkdir as mkdir4, chmod as chmod3 } from "fs/promises";
|
|
4009
3478
|
import { isAbsolute as isAbsolute4 } from "path";
|
|
4010
3479
|
|
|
4011
3480
|
// server/utils/harness/local/process-registry.ts
|
|
4012
|
-
import { randomUUID as
|
|
3481
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
4013
3482
|
import {
|
|
4014
|
-
mkdir as
|
|
4015
|
-
readFile as
|
|
4016
|
-
rename as
|
|
4017
|
-
writeFile as
|
|
4018
|
-
chmod as
|
|
3483
|
+
mkdir as mkdir3,
|
|
3484
|
+
readFile as readFile4,
|
|
3485
|
+
rename as rename2,
|
|
3486
|
+
writeFile as writeFile2,
|
|
3487
|
+
chmod as chmod2,
|
|
4019
3488
|
rm as rm2
|
|
4020
3489
|
} from "fs/promises";
|
|
4021
|
-
import { join as
|
|
3490
|
+
import { join as join3, resolve as resolve3, sep as sep4 } from "path";
|
|
4022
3491
|
function registryPath() {
|
|
4023
|
-
return
|
|
3492
|
+
return join3(localHarnessStateRoot(), "processes.json");
|
|
4024
3493
|
}
|
|
4025
3494
|
var withRegistryLock = createLocalStateMutationLock({
|
|
4026
3495
|
rootDir: localHarnessStateRoot,
|
|
@@ -4032,7 +3501,7 @@ var RegistryUnreadableError = class extends Error {
|
|
|
4032
3501
|
async function readRegistry() {
|
|
4033
3502
|
let raw;
|
|
4034
3503
|
try {
|
|
4035
|
-
raw = await
|
|
3504
|
+
raw = await readFile4(registryPath(), "utf8");
|
|
4036
3505
|
} catch (error) {
|
|
4037
3506
|
if (error.code === "ENOENT") {
|
|
4038
3507
|
return { version: 1, records: [] };
|
|
@@ -4064,16 +3533,16 @@ async function readRegistry() {
|
|
|
4064
3533
|
}
|
|
4065
3534
|
async function writeRegistry(registry) {
|
|
4066
3535
|
const dir = localHarnessStateRoot();
|
|
4067
|
-
await
|
|
4068
|
-
await
|
|
3536
|
+
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
3537
|
+
await chmod2(dir, 448).catch(() => {
|
|
4069
3538
|
});
|
|
4070
|
-
const
|
|
4071
|
-
const tmp = `${
|
|
4072
|
-
await
|
|
4073
|
-
await
|
|
3539
|
+
const file = registryPath();
|
|
3540
|
+
const tmp = `${file}.tmp`;
|
|
3541
|
+
await writeFile2(tmp, JSON.stringify(registry), { mode: 384 });
|
|
3542
|
+
await rename2(tmp, file);
|
|
4074
3543
|
}
|
|
4075
3544
|
function mintSupervisorNonce() {
|
|
4076
|
-
return `sup_${
|
|
3545
|
+
return `sup_${randomUUID2()}`;
|
|
4077
3546
|
}
|
|
4078
3547
|
function recordProcess(record) {
|
|
4079
3548
|
return withRegistryLock(async () => {
|
|
@@ -4124,7 +3593,7 @@ function janitorOutcomeForUnsettled(outcome) {
|
|
|
4124
3593
|
async function removeSessionState(dir) {
|
|
4125
3594
|
const root = resolve3(`${localHarnessStateRoot()}-sessions`);
|
|
4126
3595
|
const target = resolve3(dir);
|
|
4127
|
-
if (target === root || !target.startsWith(root +
|
|
3596
|
+
if (target === root || !target.startsWith(root + sep4)) {
|
|
4128
3597
|
logger.warn("[local-harness] refusing to clean state outside the root", {
|
|
4129
3598
|
dir
|
|
4130
3599
|
});
|
|
@@ -4356,8 +3825,8 @@ var LocalHarnessSupervisor = class {
|
|
|
4356
3825
|
}
|
|
4357
3826
|
/** Create a directory inside the session's own state, owner-only. */
|
|
4358
3827
|
async ensureDirectory(path) {
|
|
4359
|
-
await
|
|
4360
|
-
await
|
|
3828
|
+
await mkdir4(path, { recursive: true, mode: 448 });
|
|
3829
|
+
await chmod3(path, 448).catch(() => {
|
|
4361
3830
|
});
|
|
4362
3831
|
}
|
|
4363
3832
|
/**
|
|
@@ -4814,8 +4283,8 @@ var LocalHarnessSupervisor = class {
|
|
|
4814
4283
|
};
|
|
4815
4284
|
|
|
4816
4285
|
// server/utils/harness/local/local-turn.ts
|
|
4817
|
-
import { join as
|
|
4818
|
-
import { mkdir as
|
|
4286
|
+
import { join as join4 } from "path";
|
|
4287
|
+
import { mkdir as mkdir5, stat as stat3 } from "fs/promises";
|
|
4819
4288
|
import { createRequire } from "module";
|
|
4820
4289
|
var sharedSupervisor = null;
|
|
4821
4290
|
function localHarnessSupervisor() {
|
|
@@ -4866,18 +4335,21 @@ async function prepareLocalHarnessTurn(args) {
|
|
|
4866
4335
|
await invalidateParkedLocalSession(args.sessionId, "superseded");
|
|
4867
4336
|
}
|
|
4868
4337
|
if (args.scope !== "unattended" && args.requireToolApproval === false) {
|
|
4869
|
-
const
|
|
4870
|
-
if (!
|
|
4338
|
+
const authorization = await readLocalHarnessAuthorization(args.target.actingUserId, args.target.machineId, args.projectId, harnessId);
|
|
4339
|
+
if (!authorization?.autoApproveAcknowledgedAt) {
|
|
4871
4340
|
return { ok: false, status: "auto-approve-consent-required", message: "Allow commands without asking before turning Tool Approval off on this computer." };
|
|
4872
4341
|
}
|
|
4873
4342
|
}
|
|
4874
4343
|
const verifyStartedAt = Date.now();
|
|
4875
|
-
const runtimeStatus = await readRuntimeInstallStatus({
|
|
4344
|
+
const runtimeStatus = await readRuntimeInstallStatus({
|
|
4345
|
+
harnessId,
|
|
4346
|
+
preferRuntimeId: args.target.runtimeId
|
|
4347
|
+
});
|
|
4876
4348
|
if (runtimeStatus.state !== "ready") {
|
|
4877
4349
|
return {
|
|
4878
4350
|
ok: false,
|
|
4879
4351
|
status: "runtime-unavailable",
|
|
4880
|
-
message: runtimeStatus.state === "absent" ? `The local ${displayName} runtime is not installed on this machine yet.` : `The local ${displayName} runtime is not usable (${runtimeStatus.state}).`
|
|
4352
|
+
message: runtimeStatus.state === "absent" ? `The local ${displayName} runtime is not installed on this machine yet.` : runtimeStatus.state === "revoked" ? runtimeStatus.message : `The local ${displayName} runtime is not usable (${runtimeStatus.state}).`
|
|
4881
4353
|
};
|
|
4882
4354
|
}
|
|
4883
4355
|
const target = localPackTarget();
|
|
@@ -4958,6 +4430,7 @@ async function prepareWithReservedRuntime(outer) {
|
|
|
4958
4430
|
projectId: args.projectId,
|
|
4959
4431
|
grantToken: args.target.grantToken,
|
|
4960
4432
|
runtimeRoot: runtimeStatus.runtimeRoot,
|
|
4433
|
+
runtimeDigest: runtimeStatus.digest,
|
|
4961
4434
|
installedAdapterVersion: args.installedAdapterVersion ?? await readInstalledAdapterVersion(harnessId)
|
|
4962
4435
|
});
|
|
4963
4436
|
if (!availability.available) {
|
|
@@ -5007,13 +4480,13 @@ async function prepareWithReservedRuntime(outer) {
|
|
|
5007
4480
|
let gateway = null;
|
|
5008
4481
|
let currentRunId = broker.runId;
|
|
5009
4482
|
try {
|
|
5010
|
-
const sessionStateExists = await
|
|
4483
|
+
const sessionStateExists = await stat3(sessionStateDir).then((entry) => entry.isDirectory()).catch((error) => {
|
|
5011
4484
|
if (error.code === "ENOENT") return false;
|
|
5012
4485
|
throw error;
|
|
5013
4486
|
});
|
|
5014
|
-
await
|
|
5015
|
-
const hooksPath =
|
|
5016
|
-
if (args.scope === "unattended") await
|
|
4487
|
+
await mkdir5(sessionStateDir, { recursive: true, mode: 448 });
|
|
4488
|
+
const hooksPath = join4(sessionStateDir, "empty-git-hooks");
|
|
4489
|
+
if (args.scope === "unattended") await mkdir5(hooksPath, { recursive: true, mode: 448 });
|
|
5017
4490
|
const gatewayStartedAt = Date.now();
|
|
5018
4491
|
try {
|
|
5019
4492
|
gateway = await startLocalModelGateway({
|
|
@@ -5050,11 +4523,17 @@ async function prepareWithReservedRuntime(outer) {
|
|
|
5050
4523
|
workspacePath: plan.workspacePath,
|
|
5051
4524
|
workspaceGrantId: plan.target.workspaceGrantId,
|
|
5052
4525
|
sessionStateDir,
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
}
|
|
4526
|
+
onBridgeStarted: async () => {
|
|
4527
|
+
void noteRuntimeLaunch({ harnessId, status: runtimeStatus, outcome: { ok: true } });
|
|
4528
|
+
if (Object.keys(args.scopedEnv ?? {}).length) args.onSecretEnvDelivered?.();
|
|
4529
|
+
},
|
|
4530
|
+
onBridgeFailed: ({ phase, message }) => {
|
|
4531
|
+
void noteRuntimeLaunch({
|
|
4532
|
+
harnessId,
|
|
4533
|
+
status: runtimeStatus,
|
|
4534
|
+
outcome: { ok: false, reason: `${phase}: ${message.slice(0, 300)}` }
|
|
4535
|
+
});
|
|
4536
|
+
},
|
|
5058
4537
|
targetKind: "local-native",
|
|
5059
4538
|
bridgePort,
|
|
5060
4539
|
scopedEnv: {
|
|
@@ -5122,7 +4601,7 @@ async function prepareWithReservedRuntime(outer) {
|
|
|
5122
4601
|
auth: localChildAuth(harnessId, started),
|
|
5123
4602
|
sandboxWorkDir: "project",
|
|
5124
4603
|
skillsBaseDir: toAdapterPath(
|
|
5125
|
-
|
|
4604
|
+
join4(sessionStateDir, "home", ...LOCAL_SKILLS_SUBDIR[harnessId])
|
|
5126
4605
|
),
|
|
5127
4606
|
sessionStateExists,
|
|
5128
4607
|
permissionMode,
|
|
@@ -5188,7 +4667,10 @@ async function adoptParkedLocalTurn(args, harnessId) {
|
|
|
5188
4667
|
return { ok: false, status, message };
|
|
5189
4668
|
};
|
|
5190
4669
|
const verifyStartedAt = Date.now();
|
|
5191
|
-
const runtimeStatus = await readRuntimeInstallStatus({
|
|
4670
|
+
const runtimeStatus = await readRuntimeInstallStatus({
|
|
4671
|
+
harnessId,
|
|
4672
|
+
preferRuntimeId: args.target.runtimeId
|
|
4673
|
+
});
|
|
5192
4674
|
if (runtimeStatus.state !== "ready") {
|
|
5193
4675
|
return fail(
|
|
5194
4676
|
"authorization-revoked",
|
|
@@ -5212,6 +4694,7 @@ async function adoptParkedLocalTurn(args, harnessId) {
|
|
|
5212
4694
|
projectId: args.projectId,
|
|
5213
4695
|
grantToken: args.target.grantToken,
|
|
5214
4696
|
runtimeRoot: runtimeStatus.runtimeRoot,
|
|
4697
|
+
runtimeDigest: runtimeStatus.digest,
|
|
5215
4698
|
installedAdapterVersion: args.installedAdapterVersion ?? await readInstalledAdapterVersion(harnessId)
|
|
5216
4699
|
});
|
|
5217
4700
|
if (!availability.available) {
|
|
@@ -5342,24 +4825,7 @@ function onceAsync(fn) {
|
|
|
5342
4825
|
}
|
|
5343
4826
|
|
|
5344
4827
|
export {
|
|
5345
|
-
LOCAL_HARNESS_GRANT_HEADER,
|
|
5346
|
-
localHarnessStateRoot,
|
|
5347
|
-
getLocalMachineId,
|
|
5348
|
-
validateWorkspaceCandidate,
|
|
5349
|
-
registerWorkspaceGrant,
|
|
5350
|
-
resolveWorkspaceGrant,
|
|
5351
|
-
grantLocalHarnessConsent,
|
|
5352
|
-
revokeLocalHarnessGrants,
|
|
5353
|
-
pruneExpiredHarnessGrants,
|
|
5354
|
-
forgetWorkspaceGrant,
|
|
5355
4828
|
listProcessRecords,
|
|
5356
|
-
stopAllLocalHarnessSessions,
|
|
5357
|
-
stopLocalHarnessWorkspace,
|
|
5358
|
-
readLocalHarnessAuthorization,
|
|
5359
|
-
authorizeLocalHarness,
|
|
5360
|
-
revokeLocalHarnessAuthorization,
|
|
5361
|
-
updateAuthorizedWorkspace,
|
|
5362
|
-
acknowledgeLocalHarnessAutoApprove,
|
|
5363
4829
|
harnessPinnedVersion,
|
|
5364
4830
|
harnessModelSupport,
|
|
5365
4831
|
startHarnessModelBroker,
|
|
@@ -5378,4 +4844,4 @@ export {
|
|
|
5378
4844
|
localHarnessSupervisor,
|
|
5379
4845
|
prepareLocalHarnessTurn
|
|
5380
4846
|
};
|
|
5381
|
-
//# sourceMappingURL=chunk-
|
|
4847
|
+
//# sourceMappingURL=chunk-KNO4KZJF.js.map
|