@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
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOCAL_HARNESS_POLICY_VERSION,
|
|
3
|
+
LOCAL_ISOLATION_POLICY_VERSION
|
|
4
|
+
} from "./chunk-VFRLMHOC.js";
|
|
5
|
+
import {
|
|
6
|
+
createLocalStateMutationLock,
|
|
7
|
+
logger
|
|
8
|
+
} from "./chunk-C47PTIDS.js";
|
|
9
|
+
import {
|
|
10
|
+
capabilityFingerprint,
|
|
11
|
+
capabilityMatches,
|
|
12
|
+
mintCapabilityToken,
|
|
13
|
+
persistCapabilityState
|
|
14
|
+
} from "./chunk-HJTKF2X6.js";
|
|
15
|
+
|
|
16
|
+
// server/utils/harness/local/grants.ts
|
|
17
|
+
import { randomUUID } from "crypto";
|
|
18
|
+
import { mkdir, readFile, rename, writeFile, chmod } from "fs/promises";
|
|
19
|
+
import { homedir } from "os";
|
|
20
|
+
import { join, sep } from "path";
|
|
21
|
+
import { realpath, stat } from "fs/promises";
|
|
22
|
+
var LOCAL_HARNESS_GRANT_HEADER = "x-mcpjam-local-harness-grant";
|
|
23
|
+
function localHarnessStateRoot() {
|
|
24
|
+
return join(homedir(), ".mcpjam", "harness-local");
|
|
25
|
+
}
|
|
26
|
+
function grantsFilePath() {
|
|
27
|
+
return join(localHarnessStateRoot(), "grants.json");
|
|
28
|
+
}
|
|
29
|
+
function machineFilePath() {
|
|
30
|
+
return join(localHarnessStateRoot(), "machine.json");
|
|
31
|
+
}
|
|
32
|
+
function emptyState() {
|
|
33
|
+
return { version: 1, workspaces: [], harnessGrants: [] };
|
|
34
|
+
}
|
|
35
|
+
var GRANT_TTL_MS = 12 * 60 * 60 * 1e3;
|
|
36
|
+
var withGrantLock = createLocalStateMutationLock({
|
|
37
|
+
rootDir: localHarnessStateRoot,
|
|
38
|
+
lockFileName: "grants.lock",
|
|
39
|
+
resourceLabel: "grant store"
|
|
40
|
+
});
|
|
41
|
+
function hashGrantBinding(binding) {
|
|
42
|
+
return capabilityFingerprint(
|
|
43
|
+
JSON.stringify([
|
|
44
|
+
binding.scope ?? "attended",
|
|
45
|
+
binding.userId,
|
|
46
|
+
binding.machineId,
|
|
47
|
+
binding.projectId,
|
|
48
|
+
binding.workspaceGrantId,
|
|
49
|
+
binding.harnessId,
|
|
50
|
+
binding.targetKind,
|
|
51
|
+
binding.backend ?? null,
|
|
52
|
+
binding.runtimeId,
|
|
53
|
+
binding.permissionProfile,
|
|
54
|
+
binding.policyVersion,
|
|
55
|
+
// Only isolated bindings carry one, and only they hash it. A native
|
|
56
|
+
// binding has no isolation policy to be bound to, so folding a constant
|
|
57
|
+
// `null` into its hash would change every native hash for a value that
|
|
58
|
+
// means nothing there — invalidating consents that the local policy
|
|
59
|
+
// never touched. A native binding that carries one anyway is refused
|
|
60
|
+
// outright by `verifyLocalHarnessGrant`, not admitted by the hash.
|
|
61
|
+
...binding.targetKind === "local-isolated" ? [binding.isolationPolicyVersion ?? null] : []
|
|
62
|
+
])
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
var GrantStateUnreadableError = class extends Error {
|
|
66
|
+
};
|
|
67
|
+
function isValidDate(value) {
|
|
68
|
+
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
69
|
+
}
|
|
70
|
+
function isWorkspaceGrant(value) {
|
|
71
|
+
if (!value || typeof value !== "object") return false;
|
|
72
|
+
const workspace = value;
|
|
73
|
+
return typeof workspace.workspaceGrantId === "string" && workspace.workspaceGrantId.length > 0 && typeof workspace.canonicalPath === "string" && workspace.canonicalPath.length > 0 && isValidDate(workspace.createdAt);
|
|
74
|
+
}
|
|
75
|
+
function isHarnessGrantBinding(value) {
|
|
76
|
+
if (!value || typeof value !== "object") return false;
|
|
77
|
+
const binding = value;
|
|
78
|
+
const isolatedBackend = binding.backend === "linux-bwrap" || binding.backend === "darwin-seatbelt" || binding.backend === "oci-v1" || binding.backend === "vm-v1";
|
|
79
|
+
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);
|
|
80
|
+
}
|
|
81
|
+
function isPersistedHarnessGrant(value) {
|
|
82
|
+
if (!value || typeof value !== "object") return false;
|
|
83
|
+
const grant = value;
|
|
84
|
+
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);
|
|
85
|
+
}
|
|
86
|
+
async function readState() {
|
|
87
|
+
let raw;
|
|
88
|
+
try {
|
|
89
|
+
raw = await readFile(grantsFilePath(), "utf8");
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error.code === "ENOENT") return emptyState();
|
|
92
|
+
throw new GrantStateUnreadableError(
|
|
93
|
+
`the local harness grant store could not be read: ${error instanceof Error ? error.message : String(error)}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
let parsed;
|
|
97
|
+
try {
|
|
98
|
+
parsed = JSON.parse(raw);
|
|
99
|
+
} catch {
|
|
100
|
+
throw new GrantStateUnreadableError(
|
|
101
|
+
"the local harness grant store is corrupt; refusing to treat it as empty or overwrite it"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (!parsed || typeof parsed !== "object") {
|
|
105
|
+
throw new GrantStateUnreadableError(
|
|
106
|
+
"the local harness grant store is not an object"
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const record = parsed;
|
|
110
|
+
if (record.version !== 1 || !Array.isArray(record.workspaces) || !Array.isArray(record.harnessGrants) || !record.workspaces.every(isWorkspaceGrant) || !record.harnessGrants.every(isPersistedHarnessGrant)) {
|
|
111
|
+
throw new GrantStateUnreadableError(
|
|
112
|
+
"the local harness grant store has an unrecognized or malformed shape"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
version: 1,
|
|
117
|
+
workspaces: [...record.workspaces],
|
|
118
|
+
harnessGrants: [...record.harnessGrants]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async function writeState(state) {
|
|
122
|
+
const dir = localHarnessStateRoot();
|
|
123
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
124
|
+
await chmod(dir, 448).catch(() => {
|
|
125
|
+
});
|
|
126
|
+
await persistCapabilityState(grantsFilePath(), state);
|
|
127
|
+
}
|
|
128
|
+
async function getLocalMachineId() {
|
|
129
|
+
const readExisting = async () => {
|
|
130
|
+
let raw;
|
|
131
|
+
try {
|
|
132
|
+
raw = await readFile(machineFilePath(), "utf8");
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error.code === "ENOENT") return null;
|
|
135
|
+
throw new GrantStateUnreadableError(
|
|
136
|
+
`the local harness machine identity could not be read: ${error instanceof Error ? error.message : String(error)}`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
let parsed;
|
|
140
|
+
try {
|
|
141
|
+
parsed = JSON.parse(raw);
|
|
142
|
+
} catch {
|
|
143
|
+
throw new GrantStateUnreadableError(
|
|
144
|
+
"the local harness machine identity is corrupt; refusing to replace it"
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (!parsed || typeof parsed !== "object") {
|
|
148
|
+
throw new GrantStateUnreadableError(
|
|
149
|
+
"the local harness machine identity has an unrecognized shape"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const machineId = parsed.machineId;
|
|
153
|
+
if (typeof machineId !== "string" || machineId.length < 8) {
|
|
154
|
+
throw new GrantStateUnreadableError(
|
|
155
|
+
"the local harness machine identity has an invalid id"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return machineId;
|
|
159
|
+
};
|
|
160
|
+
const existing = await readExisting();
|
|
161
|
+
if (existing !== null) return existing;
|
|
162
|
+
return withGrantLock(async () => {
|
|
163
|
+
const raced = await readExisting();
|
|
164
|
+
if (raced !== null) return raced;
|
|
165
|
+
const machineId = `mach_${randomUUID()}`;
|
|
166
|
+
const dir = localHarnessStateRoot();
|
|
167
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
168
|
+
const file = machineFilePath();
|
|
169
|
+
const tmp = `${file}.tmp`;
|
|
170
|
+
await writeFile(tmp, JSON.stringify({ machineId }), { mode: 384 });
|
|
171
|
+
await rename(tmp, file);
|
|
172
|
+
return machineId;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function isFilesystemRoot(canonicalPath) {
|
|
176
|
+
return canonicalPath === sep || canonicalPath === "/" || // A drive root: `C:`, `C:\`, `C:/`.
|
|
177
|
+
/^[A-Za-z]:[\\/]?$/.test(canonicalPath) || // A UNC share root: `\\server\share` and its trailing-separator form, and
|
|
178
|
+
// a bare `\\server`. Scoping a session to a whole network share is the
|
|
179
|
+
// same mistake as scoping it to a whole volume, and the earlier rule
|
|
180
|
+
// covered only the volume. Anything BELOW the share
|
|
181
|
+
// (`\\server\share\project`) stays acceptable.
|
|
182
|
+
//
|
|
183
|
+
// Matched on the BACKSLASH form only. Accepting `//` here as well read a
|
|
184
|
+
// POSIX path with a doubled leading slash — `//tmp/project`, which POSIX
|
|
185
|
+
// expressly permits an implementation to keep — as a share root, and
|
|
186
|
+
// refused an ordinary directory. Windows has no such ambiguity to trade
|
|
187
|
+
// against: `realpath` and `path.resolve` both answer `\\server\share`
|
|
188
|
+
// there, so the canonical path this predicate is given is always the
|
|
189
|
+
// backslash form.
|
|
190
|
+
/^\\{2}[^\\/]+([\\/][^\\/]+)?[\\/]?$/.test(canonicalPath);
|
|
191
|
+
}
|
|
192
|
+
async function validateWorkspaceCandidate(rawPath) {
|
|
193
|
+
let canonicalPath;
|
|
194
|
+
try {
|
|
195
|
+
canonicalPath = await realpath(rawPath);
|
|
196
|
+
const info = await stat(canonicalPath);
|
|
197
|
+
if (!info.isDirectory()) {
|
|
198
|
+
return { ok: false, message: "the selection is not a directory" };
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
return {
|
|
202
|
+
ok: false,
|
|
203
|
+
message: `the selected workspace could not be resolved: ${error instanceof Error ? error.message : String(error)}`
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const home = await realpath(homedir()).catch(() => homedir());
|
|
207
|
+
const appRoot = join(home, ".mcpjam");
|
|
208
|
+
const workspaces = join(appRoot, "harness-workspaces");
|
|
209
|
+
if (canonicalPath === home || isFilesystemRoot(canonicalPath) || (canonicalPath === appRoot || canonicalPath.startsWith(appRoot + sep)) && !canonicalPath.startsWith(workspaces + sep)) {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
message: "pick a project directory rather than your home directory or the filesystem root \u2014 the workspace is what the session is scoped to."
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return { ok: true, canonicalPath };
|
|
216
|
+
}
|
|
217
|
+
function registerWorkspaceGrant(rawPath) {
|
|
218
|
+
return withGrantLock(async () => {
|
|
219
|
+
const candidate = await validateWorkspaceCandidate(rawPath);
|
|
220
|
+
if (!candidate.ok) {
|
|
221
|
+
return { ok: false, message: candidate.message };
|
|
222
|
+
}
|
|
223
|
+
const canonicalPath = candidate.canonicalPath;
|
|
224
|
+
const state = await readState();
|
|
225
|
+
const existing = state.workspaces.find(
|
|
226
|
+
(w) => w.canonicalPath === canonicalPath
|
|
227
|
+
);
|
|
228
|
+
if (existing) return { ok: true, grant: existing };
|
|
229
|
+
const grant = {
|
|
230
|
+
workspaceGrantId: `ws_${randomUUID()}`,
|
|
231
|
+
canonicalPath,
|
|
232
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
233
|
+
};
|
|
234
|
+
state.workspaces.push(grant);
|
|
235
|
+
await writeState(state);
|
|
236
|
+
logger.info("[local-harness] workspace grant registered");
|
|
237
|
+
return { ok: true, grant };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async function resolveWorkspaceGrant(workspaceGrantId) {
|
|
241
|
+
let state;
|
|
242
|
+
try {
|
|
243
|
+
state = await readState();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
message: error instanceof Error ? error.message : "the local harness grant store could not be read"
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const grant = state.workspaces.find(
|
|
251
|
+
(w) => w.workspaceGrantId === workspaceGrantId
|
|
252
|
+
);
|
|
253
|
+
if (!grant) {
|
|
254
|
+
return { ok: false, message: "unknown workspace grant" };
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const canonical = await realpath(grant.canonicalPath);
|
|
258
|
+
if (canonical !== grant.canonicalPath) {
|
|
259
|
+
return {
|
|
260
|
+
ok: false,
|
|
261
|
+
message: "the granted workspace now resolves somewhere else; re-select it before running locally"
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const info = await stat(canonical);
|
|
265
|
+
if (!info.isDirectory()) {
|
|
266
|
+
return {
|
|
267
|
+
ok: false,
|
|
268
|
+
message: "the granted workspace is no longer a directory"
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const candidate = await validateWorkspaceCandidate(canonical);
|
|
272
|
+
if (!candidate.ok) return candidate;
|
|
273
|
+
return { ok: true, canonicalPath: canonical };
|
|
274
|
+
} catch {
|
|
275
|
+
return {
|
|
276
|
+
ok: false,
|
|
277
|
+
message: "the granted workspace is no longer reachable"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function grantLocalHarnessConsent(binding, opts) {
|
|
282
|
+
return withGrantLock(async () => {
|
|
283
|
+
const now = opts?.now ?? Date.now();
|
|
284
|
+
const ttlMs = Math.min(opts?.ttlMs ?? GRANT_TTL_MS, GRANT_TTL_MS);
|
|
285
|
+
const token = mintCapabilityToken();
|
|
286
|
+
const grant = {
|
|
287
|
+
grantId: `grant_${randomUUID()}`,
|
|
288
|
+
tokenHash: capabilityFingerprint(token),
|
|
289
|
+
bindingHash: hashGrantBinding(binding),
|
|
290
|
+
binding,
|
|
291
|
+
grantedAt: new Date(now).toISOString(),
|
|
292
|
+
expiresAt: new Date(now + ttlMs).toISOString()
|
|
293
|
+
};
|
|
294
|
+
const state = await readState();
|
|
295
|
+
state.harnessGrants = state.harnessGrants.filter(
|
|
296
|
+
(g) => Date.parse(g.expiresAt) > now
|
|
297
|
+
);
|
|
298
|
+
state.harnessGrants.push(grant);
|
|
299
|
+
await writeState(state);
|
|
300
|
+
logger.info("[local-harness] consent granted", {
|
|
301
|
+
harnessId: binding.harnessId,
|
|
302
|
+
targetKind: binding.targetKind,
|
|
303
|
+
permissionProfile: binding.permissionProfile,
|
|
304
|
+
policyVersion: binding.policyVersion
|
|
305
|
+
});
|
|
306
|
+
return { grantId: grant.grantId, token, expiresAt: grant.expiresAt };
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async function verifyLocalHarnessGrant(token, binding, opts) {
|
|
310
|
+
if (!token || token.length < 16 || token.length > 256) {
|
|
311
|
+
return {
|
|
312
|
+
ok: false,
|
|
313
|
+
reason: "invalid",
|
|
314
|
+
message: "no local harness grant was presented"
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (binding.policyVersion !== LOCAL_HARNESS_POLICY_VERSION) {
|
|
318
|
+
return {
|
|
319
|
+
ok: false,
|
|
320
|
+
reason: "binding-mismatch",
|
|
321
|
+
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.`
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (binding.targetKind === "local-isolated") {
|
|
325
|
+
if (binding.isolationPolicyVersion !== LOCAL_ISOLATION_POLICY_VERSION) {
|
|
326
|
+
return {
|
|
327
|
+
ok: false,
|
|
328
|
+
reason: "binding-mismatch",
|
|
329
|
+
message: `this grant was minted under isolation policy ${binding.isolationPolicyVersion ?? "(none)"}; the current isolation policy is ${LOCAL_ISOLATION_POLICY_VERSION}.`
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
} else if (binding.isolationPolicyVersion !== void 0) {
|
|
333
|
+
return {
|
|
334
|
+
ok: false,
|
|
335
|
+
reason: "binding-mismatch",
|
|
336
|
+
message: "a native grant must not carry an isolation policy version"
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const bindingHash = hashGrantBinding(binding);
|
|
340
|
+
let state;
|
|
341
|
+
try {
|
|
342
|
+
state = await readState();
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return {
|
|
345
|
+
ok: false,
|
|
346
|
+
reason: "invalid",
|
|
347
|
+
message: error instanceof Error ? error.message : "the local harness grant store could not be read"
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const now = opts?.now ?? Date.now();
|
|
351
|
+
for (const grant of state.harnessGrants) {
|
|
352
|
+
if (!capabilityMatches(token, grant.tokenHash)) continue;
|
|
353
|
+
if (grant.bindingHash !== bindingHash) {
|
|
354
|
+
return {
|
|
355
|
+
ok: false,
|
|
356
|
+
reason: "binding-mismatch",
|
|
357
|
+
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."
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (Date.parse(grant.expiresAt) <= now) {
|
|
361
|
+
return {
|
|
362
|
+
ok: false,
|
|
363
|
+
reason: "expired",
|
|
364
|
+
message: "the local harness grant expired; consent is attended and short-lived"
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
return { ok: true, grantId: grant.grantId };
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
ok: false,
|
|
371
|
+
reason: "absent",
|
|
372
|
+
message: "no local harness grant matches the presented capability"
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function revokeLocalHarnessGrants(selector) {
|
|
376
|
+
return withGrantLock(async () => {
|
|
377
|
+
const state = await readState();
|
|
378
|
+
const before = state.harnessGrants.length;
|
|
379
|
+
if (!selector) {
|
|
380
|
+
state.harnessGrants = [];
|
|
381
|
+
} else if (selector.userId) {
|
|
382
|
+
state.harnessGrants = state.harnessGrants.filter((g) => g.binding.userId !== selector.userId || selector.projectId !== void 0 && g.binding.projectId !== selector.projectId);
|
|
383
|
+
} else if (selector.grantId) {
|
|
384
|
+
state.harnessGrants = state.harnessGrants.filter(
|
|
385
|
+
(g) => g.grantId !== selector.grantId
|
|
386
|
+
);
|
|
387
|
+
} else if (selector.binding) {
|
|
388
|
+
const hash = hashGrantBinding(selector.binding);
|
|
389
|
+
state.harnessGrants = state.harnessGrants.filter(
|
|
390
|
+
(g) => g.bindingHash !== hash
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
const removed = before - state.harnessGrants.length;
|
|
394
|
+
if (removed > 0) {
|
|
395
|
+
await writeState(state);
|
|
396
|
+
logger.info("[local-harness] consent revoked", { removed });
|
|
397
|
+
}
|
|
398
|
+
return removed;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function pruneExpiredHarnessGrants(now = Date.now()) {
|
|
402
|
+
return withGrantLock(async () => {
|
|
403
|
+
const state = await readState();
|
|
404
|
+
const before = state.harnessGrants.length;
|
|
405
|
+
state.harnessGrants = state.harnessGrants.filter(
|
|
406
|
+
(g) => Date.parse(g.expiresAt) > now
|
|
407
|
+
);
|
|
408
|
+
const removed = before - state.harnessGrants.length;
|
|
409
|
+
if (removed > 0) await writeState(state);
|
|
410
|
+
return removed;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function forgetWorkspaceGrant(workspaceGrantId) {
|
|
414
|
+
return withGrantLock(async () => {
|
|
415
|
+
const state = await readState();
|
|
416
|
+
state.workspaces = state.workspaces.filter((w) => w.workspaceGrantId !== workspaceGrantId);
|
|
417
|
+
state.harnessGrants = state.harnessGrants.filter((g) => g.binding.workspaceGrantId !== workspaceGrantId);
|
|
418
|
+
await writeState(state);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export {
|
|
423
|
+
LOCAL_HARNESS_GRANT_HEADER,
|
|
424
|
+
localHarnessStateRoot,
|
|
425
|
+
hashGrantBinding,
|
|
426
|
+
GrantStateUnreadableError,
|
|
427
|
+
getLocalMachineId,
|
|
428
|
+
isFilesystemRoot,
|
|
429
|
+
validateWorkspaceCandidate,
|
|
430
|
+
registerWorkspaceGrant,
|
|
431
|
+
resolveWorkspaceGrant,
|
|
432
|
+
grantLocalHarnessConsent,
|
|
433
|
+
verifyLocalHarnessGrant,
|
|
434
|
+
revokeLocalHarnessGrants,
|
|
435
|
+
pruneExpiredHarnessGrants,
|
|
436
|
+
forgetWorkspaceGrant
|
|
437
|
+
};
|
|
438
|
+
//# sourceMappingURL=chunk-XSQ2GC45.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withRuntimeLifecycleLock
|
|
3
|
+
} from "./chunk-7M3XVZCQ.js";
|
|
4
|
+
|
|
5
|
+
// server/utils/harness/local/runtime-health.ts
|
|
6
|
+
import { randomUUID } from "crypto";
|
|
7
|
+
import { readFile, rename, writeFile } from "fs/promises";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
var HEALTH_FILE = ".mcpjam-pack-health.json";
|
|
10
|
+
var LAUNCH_FAILURE_THRESHOLD = 3;
|
|
11
|
+
var LAUNCH_FAILURE_WINDOW_MS = 30 * 60 * 1e3;
|
|
12
|
+
function newHealthRecord(fields) {
|
|
13
|
+
return { schema: 1, launchFailures: [], ...fields };
|
|
14
|
+
}
|
|
15
|
+
async function readRuntimeHealth(versionRoot) {
|
|
16
|
+
try {
|
|
17
|
+
const record = JSON.parse(await readFile(join(versionRoot, HEALTH_FILE), "utf8"));
|
|
18
|
+
if (record?.schema !== 1 || !Array.isArray(record.launchFailures)) return null;
|
|
19
|
+
return record;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isUnhealthy(record, treeDigest) {
|
|
25
|
+
return record !== null && record.treeDigest === treeDigest && record.unhealthy !== void 0;
|
|
26
|
+
}
|
|
27
|
+
async function writeRuntimeHealth(dir, record) {
|
|
28
|
+
const file = join(dir, HEALTH_FILE);
|
|
29
|
+
const tmp = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
30
|
+
await writeFile(tmp, `${JSON.stringify(record, null, 2)}
|
|
31
|
+
`, { mode: 384 });
|
|
32
|
+
await rename(tmp, file);
|
|
33
|
+
}
|
|
34
|
+
function foldLaunch(record, outcome, now) {
|
|
35
|
+
if (outcome.ok) {
|
|
36
|
+
const firstUsable = record.firstUsableAt === void 0;
|
|
37
|
+
const { unhealthy: _cleared, ...rest } = record;
|
|
38
|
+
return {
|
|
39
|
+
record: { ...rest, launchFailures: [], ...firstUsable ? { firstUsableAt: now } : {} },
|
|
40
|
+
becameUnhealthy: false,
|
|
41
|
+
firstUsable
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const failures = [...record.launchFailures, now].filter((at) => now - at <= LAUNCH_FAILURE_WINDOW_MS);
|
|
45
|
+
const becameUnhealthy = record.unhealthy === void 0 && failures.length >= LAUNCH_FAILURE_THRESHOLD;
|
|
46
|
+
return {
|
|
47
|
+
record: {
|
|
48
|
+
...record,
|
|
49
|
+
launchFailures: failures,
|
|
50
|
+
...becameUnhealthy ? { unhealthy: { at: now, reason: outcome.reason } } : {}
|
|
51
|
+
},
|
|
52
|
+
becameUnhealthy,
|
|
53
|
+
firstUsable: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async function recordRuntimeLaunch(args) {
|
|
57
|
+
return withRuntimeLifecycleLock(args.key, async () => {
|
|
58
|
+
const existing = await readRuntimeHealth(args.versionRoot);
|
|
59
|
+
const base = existing !== null && existing.treeDigest === args.key.treeDigest ? existing : newHealthRecord({ packVersion: args.key.packVersion, treeDigest: args.key.treeDigest });
|
|
60
|
+
const folded = foldLaunch(base, args.outcome, args.now ?? Date.now());
|
|
61
|
+
await writeRuntimeHealth(args.versionRoot, folded.record);
|
|
62
|
+
return folded;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async function noteFailedReprobe(args) {
|
|
66
|
+
await withRuntimeLifecycleLock(args.key, async () => {
|
|
67
|
+
const existing = await readRuntimeHealth(args.versionRoot);
|
|
68
|
+
if (existing === null || !isUnhealthy(existing, args.key.treeDigest)) return;
|
|
69
|
+
await writeRuntimeHealth(args.versionRoot, {
|
|
70
|
+
...existing,
|
|
71
|
+
unhealthy: { ...existing.unhealthy, at: args.now ?? Date.now() }
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
HEALTH_FILE,
|
|
78
|
+
LAUNCH_FAILURE_THRESHOLD,
|
|
79
|
+
LAUNCH_FAILURE_WINDOW_MS,
|
|
80
|
+
newHealthRecord,
|
|
81
|
+
readRuntimeHealth,
|
|
82
|
+
isUnhealthy,
|
|
83
|
+
writeRuntimeHealth,
|
|
84
|
+
foldLaunch,
|
|
85
|
+
recordRuntimeLaunch,
|
|
86
|
+
noteFailedReprobe
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=chunk-YQ2BTE46.js.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createBrowserConsentLifetime,
|
|
3
3
|
invalidateBrowserConsentLifetimes
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-RWFTW2EW.js";
|
|
5
|
+
import "./chunk-7ZIR7SX7.js";
|
|
6
|
+
import "./chunk-HJTKF2X6.js";
|
|
6
7
|
import "./chunk-PZ5AY32C.js";
|
|
7
8
|
export {
|
|
8
9
|
createBrowserConsentLifetime,
|
|
9
10
|
invalidateBrowserConsentLifetimes
|
|
10
11
|
};
|
|
11
|
-
//# sourceMappingURL=consent-lifetime-
|
|
12
|
+
//# sourceMappingURL=consent-lifetime-OXQM37RV.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GrantStateUnreadableError,
|
|
3
|
+
LOCAL_HARNESS_GRANT_HEADER,
|
|
4
|
+
forgetWorkspaceGrant,
|
|
5
|
+
getLocalMachineId,
|
|
6
|
+
grantLocalHarnessConsent,
|
|
7
|
+
hashGrantBinding,
|
|
8
|
+
isFilesystemRoot,
|
|
9
|
+
localHarnessStateRoot,
|
|
10
|
+
pruneExpiredHarnessGrants,
|
|
11
|
+
registerWorkspaceGrant,
|
|
12
|
+
resolveWorkspaceGrant,
|
|
13
|
+
revokeLocalHarnessGrants,
|
|
14
|
+
validateWorkspaceCandidate,
|
|
15
|
+
verifyLocalHarnessGrant
|
|
16
|
+
} from "./chunk-XSQ2GC45.js";
|
|
17
|
+
import "./chunk-VFRLMHOC.js";
|
|
18
|
+
import "./chunk-C47PTIDS.js";
|
|
19
|
+
import "./chunk-HJTKF2X6.js";
|
|
20
|
+
import "./chunk-PZ5AY32C.js";
|
|
21
|
+
export {
|
|
22
|
+
GrantStateUnreadableError,
|
|
23
|
+
LOCAL_HARNESS_GRANT_HEADER,
|
|
24
|
+
forgetWorkspaceGrant,
|
|
25
|
+
getLocalMachineId,
|
|
26
|
+
grantLocalHarnessConsent,
|
|
27
|
+
hashGrantBinding,
|
|
28
|
+
isFilesystemRoot,
|
|
29
|
+
localHarnessStateRoot,
|
|
30
|
+
pruneExpiredHarnessGrants,
|
|
31
|
+
registerWorkspaceGrant,
|
|
32
|
+
resolveWorkspaceGrant,
|
|
33
|
+
revokeLocalHarnessGrants,
|
|
34
|
+
validateWorkspaceCandidate,
|
|
35
|
+
verifyLocalHarnessGrant
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=grants-UVE62NGN.js.map
|