@hasna/hooks 0.12.7 → 0.12.8
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/hooks-mcp.js +973 -605
- package/bin/index.js +1244 -891
- package/bin/native-safety-worker.cjs +1 -1
- package/dist/index.js +1165 -797
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-check.d.ts +1 -1
- package/package.json +2 -2
package/bin/hooks-mcp.js
CHANGED
|
@@ -1397,8 +1397,8 @@ function redactValue(value) {
|
|
|
1397
1397
|
return value.map(redactValue);
|
|
1398
1398
|
if (value !== null && typeof value === "object") {
|
|
1399
1399
|
const out = {};
|
|
1400
|
-
for (const [key,
|
|
1401
|
-
out[key] = SECRET_KEY_NAMES.test(key) ? REDACTED : redactValue(
|
|
1400
|
+
for (const [key, child2] of Object.entries(value)) {
|
|
1401
|
+
out[key] = SECRET_KEY_NAMES.test(key) ? REDACTED : redactValue(child2);
|
|
1402
1402
|
}
|
|
1403
1403
|
return out;
|
|
1404
1404
|
}
|
|
@@ -1416,12 +1416,12 @@ function redactEventPayload(text3) {
|
|
|
1416
1416
|
}
|
|
1417
1417
|
function projectEventRowForRead(row) {
|
|
1418
1418
|
const out = { ...row };
|
|
1419
|
-
for (const
|
|
1420
|
-
const value = out[
|
|
1419
|
+
for (const field3 of ["tool_input", "error", "metadata"]) {
|
|
1420
|
+
const value = out[field3];
|
|
1421
1421
|
if (typeof value === "string")
|
|
1422
|
-
out[
|
|
1422
|
+
out[field3] = redactEventPayload(value);
|
|
1423
1423
|
else if (value === null)
|
|
1424
|
-
out[
|
|
1424
|
+
out[field3] = null;
|
|
1425
1425
|
}
|
|
1426
1426
|
return out;
|
|
1427
1427
|
}
|
|
@@ -1453,7 +1453,7 @@ import { spawnSync as spawnSync2 } from "child_process";
|
|
|
1453
1453
|
import { closeSync as closeSync23, fstatSync as fstatSync23, openSync as openSync23, readFileSync as readFileSync22 } from "fs";
|
|
1454
1454
|
import { O_NOFOLLOW as O_NOFOLLOW2, O_NONBLOCK as O_NONBLOCK2, O_RDONLY as O_RDONLY2 } from "constants";
|
|
1455
1455
|
import { hostname as osHostname } from "os";
|
|
1456
|
-
import { isAbsolute as
|
|
1456
|
+
import { isAbsolute as isAbsolute9, join as join22 } from "path";
|
|
1457
1457
|
import { createRequire as createRequire2 } from "module";
|
|
1458
1458
|
function envToken2(name) {
|
|
1459
1459
|
return name.toUpperCase().replace(/-/g, "_");
|
|
@@ -1477,7 +1477,7 @@ function homeDir(env) {
|
|
|
1477
1477
|
}
|
|
1478
1478
|
function absoluteOverride(env, key) {
|
|
1479
1479
|
const value = env[key]?.trim();
|
|
1480
|
-
return value &&
|
|
1480
|
+
return value && isAbsolute9(value) ? value : null;
|
|
1481
1481
|
}
|
|
1482
1482
|
function hasnaHomeDir(env) {
|
|
1483
1483
|
const override = absoluteOverride(env, HASNA_HOME_ENV_KEY);
|
|
@@ -1549,8 +1549,8 @@ function configFileReadsCoherent(before, after) {
|
|
|
1549
1549
|
return before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeMs === after.mtimeMs && before.ctimeMs === after.ctimeMs;
|
|
1550
1550
|
}
|
|
1551
1551
|
function readAppConfigFile(path) {
|
|
1552
|
-
const unsafe = (
|
|
1553
|
-
throw new CredentialFileUnsafeError(path,
|
|
1552
|
+
const unsafe = (reason2) => {
|
|
1553
|
+
throw new CredentialFileUnsafeError(path, reason2);
|
|
1554
1554
|
};
|
|
1555
1555
|
let fd = -1;
|
|
1556
1556
|
try {
|
|
@@ -1739,8 +1739,8 @@ function readKeychainItem(name, env, kind, options) {
|
|
|
1739
1739
|
try {
|
|
1740
1740
|
result = run(["find-generic-password", "-a", account, "-s", service, "-w"]);
|
|
1741
1741
|
} catch (error61) {
|
|
1742
|
-
const
|
|
1743
|
-
throw new CredentialResolutionError(name, `The Keychain lookup for ${source} could not run${
|
|
1742
|
+
const reason2 = keychainFailureHint(error61 instanceof Error ? error61.message : String(error61));
|
|
1743
|
+
throw new CredentialResolutionError(name, `The Keychain lookup for ${source} could not run${reason2}. A Keychain failure is never resolved ` + `around: fix the keychain, or delete the item to fall through to the credential on disk.`, [source]);
|
|
1744
1744
|
}
|
|
1745
1745
|
if (result.status === KEYCHAIN_ITEM_NOT_FOUND_STATUS)
|
|
1746
1746
|
return null;
|
|
@@ -2161,8 +2161,8 @@ var init_transport = __esm(() => {
|
|
|
2161
2161
|
};
|
|
2162
2162
|
CredentialFileUnsafeError = class CredentialFileUnsafeError extends Error {
|
|
2163
2163
|
path;
|
|
2164
|
-
constructor(path,
|
|
2165
|
-
super(`Refusing unsafe credential/config file ${path}: ${
|
|
2164
|
+
constructor(path, reason2) {
|
|
2165
|
+
super(`Refusing unsafe credential/config file ${path}: ${reason2}.`);
|
|
2166
2166
|
this.name = "CredentialFileUnsafeError";
|
|
2167
2167
|
this.path = path;
|
|
2168
2168
|
}
|
|
@@ -2257,8 +2257,8 @@ var init_local_opt_in = __esm(() => {
|
|
|
2257
2257
|
});
|
|
2258
2258
|
|
|
2259
2259
|
// src/lib/hook-env.ts
|
|
2260
|
-
import { dirname as
|
|
2261
|
-
import { existsSync as existsSync14, realpathSync as
|
|
2260
|
+
import { dirname as dirname16, isAbsolute as isAbsolute11 } from "path";
|
|
2261
|
+
import { existsSync as existsSync14, realpathSync as realpathSync12, statSync } from "fs";
|
|
2262
2262
|
import { tmpdir } from "os";
|
|
2263
2263
|
function isDeniedEnvName(name) {
|
|
2264
2264
|
const upper = name.toUpperCase();
|
|
@@ -2277,7 +2277,7 @@ function isBashFunctionEnvName(name) {
|
|
|
2277
2277
|
return name.startsWith("BASH_FUNC_");
|
|
2278
2278
|
}
|
|
2279
2279
|
function isUnsafePathEntry(entry, home) {
|
|
2280
|
-
if (entry === "" || !
|
|
2280
|
+
if (entry === "" || !isAbsolute11(entry))
|
|
2281
2281
|
return true;
|
|
2282
2282
|
if (home && (entry === home || entry.startsWith(home + "/")))
|
|
2283
2283
|
return true;
|
|
@@ -2285,16 +2285,16 @@ function isUnsafePathEntry(entry, home) {
|
|
|
2285
2285
|
return true;
|
|
2286
2286
|
if (entry === "/var/tmp" || entry.startsWith("/var/tmp/"))
|
|
2287
2287
|
return true;
|
|
2288
|
-
const
|
|
2288
|
+
const canonical8 = (path) => {
|
|
2289
2289
|
try {
|
|
2290
|
-
return
|
|
2290
|
+
return realpathSync12(path);
|
|
2291
2291
|
} catch {
|
|
2292
2292
|
return path;
|
|
2293
2293
|
}
|
|
2294
2294
|
};
|
|
2295
|
-
const resolved =
|
|
2295
|
+
const resolved = canonical8(entry);
|
|
2296
2296
|
for (const root of [home, tmpdir(), "/tmp", "/var/tmp"].filter((value) => Boolean(value))) {
|
|
2297
|
-
const blocked =
|
|
2297
|
+
const blocked = canonical8(root);
|
|
2298
2298
|
if (resolved === blocked || resolved.startsWith(blocked + "/"))
|
|
2299
2299
|
return true;
|
|
2300
2300
|
}
|
|
@@ -2308,7 +2308,7 @@ function sanitizeHookPath(pathValue, home) {
|
|
|
2308
2308
|
const baseline = PATH_BASELINE.slice();
|
|
2309
2309
|
if (process.platform === "darwin" && existsSync14("/opt/homebrew/bin"))
|
|
2310
2310
|
baseline.push("/opt/homebrew/bin");
|
|
2311
|
-
const bunDir =
|
|
2311
|
+
const bunDir = dirname16(process.execPath);
|
|
2312
2312
|
const seen = new Set;
|
|
2313
2313
|
const out = [];
|
|
2314
2314
|
for (const dir of baseline) {
|
|
@@ -2433,9 +2433,9 @@ __export(exports_run, {
|
|
|
2433
2433
|
});
|
|
2434
2434
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
2435
2435
|
import { rmSync as rmSync2, writeFileSync as writeFileSync10 } from "fs";
|
|
2436
|
-
import { basename as
|
|
2436
|
+
import { basename as basename8, dirname as dirname21, isAbsolute as isAbsolute15, join as join14 } from "path";
|
|
2437
2437
|
function extensionOf(scriptPath) {
|
|
2438
|
-
const base =
|
|
2438
|
+
const base = basename8(scriptPath);
|
|
2439
2439
|
const dot = base.lastIndexOf(".");
|
|
2440
2440
|
return dot > 0 ? base.slice(dot + 1) : "ts";
|
|
2441
2441
|
}
|
|
@@ -2447,9 +2447,9 @@ function shebangInterpreter(firstLine) {
|
|
|
2447
2447
|
return null;
|
|
2448
2448
|
const parts = rest.split(/\s+/);
|
|
2449
2449
|
if (parts[0] === "env" || parts[0] === "/usr/bin/env") {
|
|
2450
|
-
return parts[1] && parts[1] !== "-S" ?
|
|
2450
|
+
return parts[1] && parts[1] !== "-S" ? basename8(parts[1]) : parts[2] ? basename8(parts[2]) : null;
|
|
2451
2451
|
}
|
|
2452
|
-
return
|
|
2452
|
+
return basename8(parts[0]);
|
|
2453
2453
|
}
|
|
2454
2454
|
function interpreterFor(name, scriptPath, content) {
|
|
2455
2455
|
const ext = extensionOf(scriptPath);
|
|
@@ -2502,7 +2502,7 @@ async function readPipeWithDeadline(stream, deadlineMs) {
|
|
|
2502
2502
|
return chunks.join("");
|
|
2503
2503
|
}
|
|
2504
2504
|
async function executeVerifiedScript(options) {
|
|
2505
|
-
const scriptDir =
|
|
2505
|
+
const scriptDir = dirname21(options.scriptPath);
|
|
2506
2506
|
const interpreter = interpreterFor(options.name, options.scriptPath, options.content);
|
|
2507
2507
|
const tempPath = join14(scriptDir, `.hooks-verified-${randomBytes2(12).toString("hex")}.${interpreter.tempExt}`);
|
|
2508
2508
|
let proc = null;
|
|
@@ -2513,7 +2513,7 @@ async function executeVerifiedScript(options) {
|
|
|
2513
2513
|
}, options.timeout) : null;
|
|
2514
2514
|
try {
|
|
2515
2515
|
writeFileSync10(tempPath, options.content, { flag: "wx", mode: 384 });
|
|
2516
|
-
proc = Bun.spawn([...interpreter.command,
|
|
2516
|
+
proc = Bun.spawn([...interpreter.command, isAbsolute15(tempPath) ? tempPath : `./${tempPath}`, ...options.args ?? []], {
|
|
2517
2517
|
stdin: new Response(options.stdin),
|
|
2518
2518
|
stdout: "pipe",
|
|
2519
2519
|
stderr: "pipe",
|
|
@@ -2713,13 +2713,13 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
2713
2713
|
import { z as z3 } from "zod";
|
|
2714
2714
|
init_registry();
|
|
2715
2715
|
import { existsSync as existsSync15, readFileSync as readFileSync10 } from "fs";
|
|
2716
|
-
import { join as join16, dirname as
|
|
2716
|
+
import { join as join16, dirname as dirname23 } from "path";
|
|
2717
2717
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2718
2718
|
|
|
2719
2719
|
// src/lib/installer.ts
|
|
2720
2720
|
init_registry();
|
|
2721
|
-
import { existsSync as existsSync12, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync4, realpathSync as
|
|
2722
|
-
import { join as join12, dirname as
|
|
2721
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync4, realpathSync as realpathSync9, rmdirSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync7 } from "fs";
|
|
2722
|
+
import { join as join12, dirname as dirname9, basename as basename5, resolve as resolve21 } from "path";
|
|
2723
2723
|
import { homedir as homedir7 } from "os";
|
|
2724
2724
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2725
2725
|
|
|
@@ -3369,12 +3369,12 @@ function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
|
3369
3369
|
}
|
|
3370
3370
|
|
|
3371
3371
|
// src/lib/claude-skills-coordination.ts
|
|
3372
|
-
import { createHash as
|
|
3372
|
+
import { createHash as createHash9 } from "crypto";
|
|
3373
3373
|
import { existsSync as existsSync11, lstatSync as lstatSync8 } from "fs";
|
|
3374
3374
|
import { homedir as homedir6 } from "os";
|
|
3375
|
-
import { join as join11, resolve as
|
|
3375
|
+
import { join as join11, resolve as resolve9 } from "path";
|
|
3376
3376
|
|
|
3377
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
3377
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.53+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
3378
3378
|
import { existsSync as existsSync10 } from "fs";
|
|
3379
3379
|
import { homedir as homedir5 } from "os";
|
|
3380
3380
|
import { join as join10, resolve as resolve4 } from "path";
|
|
@@ -3387,26 +3387,28 @@ import { createHash as createHash32 } from "crypto";
|
|
|
3387
3387
|
import { createHash as createHash22 } from "crypto";
|
|
3388
3388
|
import { closeSync as closeSync5, constants as constants4, fstatSync as fstatSync4, lstatSync as lstatSync32, openSync as openSync5, readSync } from "fs";
|
|
3389
3389
|
import { basename as basename2, dirname as dirname32, isAbsolute as isAbsolute22, resolve as resolve22 } from "path";
|
|
3390
|
-
import { basename as
|
|
3391
|
-
import { createHash as
|
|
3392
|
-
import {
|
|
3393
|
-
import {
|
|
3390
|
+
import { basename as basename4, isAbsolute as isAbsolute4, join as join72, resolve as resolve42, sep as sep22 } from "path";
|
|
3391
|
+
import { createHash as createHash42 } from "crypto";
|
|
3392
|
+
import { basename as basename3, dirname as dirname42, isAbsolute as isAbsolute32, resolve as resolve32 } from "path";
|
|
3393
|
+
import { createHash as createHash25 } from "crypto";
|
|
3394
|
+
import { lstatSync as lstatSync25, readFileSync as readFileSync20, readdirSync as readdirSync10, realpathSync as realpathSync11 } from "fs";
|
|
3395
|
+
import { basename as basename11, dirname as dirname20, isAbsolute as isAbsolute21, join as join32, resolve as resolve20, sep as sep8 } from "path";
|
|
3394
3396
|
import { isDeepStrictEqual as isDeepStrictEqual7 } from "util";
|
|
3395
|
-
import { dirname as
|
|
3397
|
+
import { dirname as dirname52, isAbsolute as isAbsolute5, join as join82, resolve as resolve5 } from "path";
|
|
3396
3398
|
import { lstatSync as lstatSync42, readFileSync as readFileSync62, opendirSync } from "fs";
|
|
3397
|
-
import { createHash as createHash42 } from "crypto";
|
|
3398
|
-
import { lstatSync as lstatSync5, opendirSync as opendirSync2 } from "fs";
|
|
3399
|
-
import { dirname as dirname52, isAbsolute as isAbsolute5, join as join92, resolve as resolve5 } from "path";
|
|
3400
3399
|
import { createHash as createHash52 } from "crypto";
|
|
3401
|
-
import {
|
|
3402
|
-
import { dirname as dirname62, isAbsolute as isAbsolute6, resolve as resolve6 } from "path";
|
|
3400
|
+
import { lstatSync as lstatSync5, opendirSync as opendirSync2 } from "fs";
|
|
3401
|
+
import { dirname as dirname62, isAbsolute as isAbsolute6, join as join92, resolve as resolve6 } from "path";
|
|
3403
3402
|
import { createHash as createHash62 } from "crypto";
|
|
3404
|
-
import { lstatSync as
|
|
3405
|
-
import { dirname as dirname7, isAbsolute as isAbsolute7,
|
|
3403
|
+
import { closeSync as closeSync22, constants as constants22, fstatSync as fstatSync22, lstatSync as lstatSync6, openSync as openSync22, readSync as readSync2 } from "fs";
|
|
3404
|
+
import { dirname as dirname7, isAbsolute as isAbsolute7, resolve as resolve7 } from "path";
|
|
3406
3405
|
import { createHash as createHash7 } from "crypto";
|
|
3407
|
-
import {
|
|
3408
|
-
import {
|
|
3409
|
-
import {
|
|
3406
|
+
import { lstatSync as lstatSync7, readlinkSync } from "fs";
|
|
3407
|
+
import { dirname as dirname8, isAbsolute as isAbsolute8, join as join102, parse as parse2, resolve as resolve8, sep as sep32 } from "path";
|
|
3408
|
+
import { createHash as createHash8 } from "crypto";
|
|
3409
|
+
import { closeSync as closeSync13, constants as constants13, fstatSync as fstatSync13, lstatSync as lstatSync23, openSync as openSync13, opendirSync as opendirSync5, readSync as readSync10 } from "fs";
|
|
3410
|
+
import { basename as basename9, dirname as dirname18, isAbsolute as isAbsolute19, join as join31, resolve as resolve18 } from "path";
|
|
3411
|
+
import { isAbsolute as isAbsolute18, join as join30, resolve as resolve17 } from "path";
|
|
3410
3412
|
import { createRequire } from "module";
|
|
3411
3413
|
|
|
3412
3414
|
// ../contracts/dist/kernel-lock.js
|
|
@@ -3740,47 +3742,47 @@ class KernelLock {
|
|
|
3740
3742
|
}
|
|
3741
3743
|
}
|
|
3742
3744
|
|
|
3743
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
3745
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.53+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
3744
3746
|
import { execFileSync } from "child_process";
|
|
3745
|
-
import { createHash as
|
|
3747
|
+
import { createHash as createHash12 } from "crypto";
|
|
3746
3748
|
import { accessSync, constants as constants6, lstatSync as lstatSync12, readFileSync as readFileSync11, realpathSync as realpathSync32, statSync as statSync7 } from "fs";
|
|
3747
|
-
import { basename as
|
|
3748
|
-
import { basename as
|
|
3749
|
+
import { basename as basename6, delimiter, dirname as dirname11, isAbsolute as isAbsolute10, join as join15, relative as relative4, resolve as resolve10, sep as sep5 } from "path";
|
|
3750
|
+
import { basename as basename7, dirname as dirname12, join as join17, relative as relative5, resolve as resolve11, sep as sep6 } from "path";
|
|
3749
3751
|
import { lstatSync as lstatSync13, readdirSync as readdirSync6, readlinkSync as readlinkSync3, realpathSync as realpathSync6 } from "fs";
|
|
3750
3752
|
import { realpathSync as realpathSync5 } from "fs";
|
|
3751
|
-
import { isAbsolute as
|
|
3752
|
-
import { createHash as
|
|
3753
|
+
import { isAbsolute as isAbsolute12, normalize as normalize2 } from "path";
|
|
3754
|
+
import { createHash as createHash14, randomUUID as randomUUID2 } from "crypto";
|
|
3753
3755
|
import { closeSync as closeSync7, constants as constants7, fstatSync as fstatSync7, fsyncSync as fsyncSync2, lstatSync as lstatSync14, mkdirSync as mkdirSync5, openSync as openSync7, readFileSync as readFileSync12, readSync as readSync5, readlinkSync as readlinkSync4, realpathSync as realpathSync7, renameSync as renameSync22, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
3754
|
-
import { dirname as
|
|
3756
|
+
import { dirname as dirname13, isAbsolute as isAbsolute13, join as join18, resolve as resolve12 } from "path";
|
|
3755
3757
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
3756
|
-
import { createHash as createHash14 } from "crypto";
|
|
3757
|
-
import { isDeepStrictEqual as isDeepStrictEqual3 } from "util";
|
|
3758
3758
|
import { createHash as createHash15 } from "crypto";
|
|
3759
|
+
import { isDeepStrictEqual as isDeepStrictEqual3 } from "util";
|
|
3760
|
+
import { createHash as createHash16 } from "crypto";
|
|
3759
3761
|
import { isDeepStrictEqual as isDeepStrictEqual4 } from "util";
|
|
3760
|
-
import { createHash as
|
|
3762
|
+
import { createHash as createHash20, randomUUID as randomUUID3 } from "crypto";
|
|
3761
3763
|
import { isDeepStrictEqual as isDeepStrictEqual6 } from "util";
|
|
3762
|
-
import { existsSync as existsSync92, lstatSync as
|
|
3763
|
-
import { dirname as
|
|
3764
|
+
import { existsSync as existsSync92, lstatSync as lstatSync20, statSync as statSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync15, readdirSync as readdirSync8, opendirSync as opendirSync3, readlinkSync as readlinkSync7, realpathSync as realpathSync10, renameSync as renameSync3, rmdirSync as rmdirSync2, writeFileSync as writeFileSync6, unlinkSync as unlinkSync4, chmodSync, openSync as openSync11, closeSync as closeSync11, fsyncSync as fsyncSync5, fstatSync as fstatSync11, readSync as readSync8, constants as constants11, linkSync as linkSync2 } from "fs";
|
|
3765
|
+
import { dirname as dirname15, join as join23, resolve as resolve15, relative as relative6, isAbsolute as isAbsolute16, sep as sep7 } from "path";
|
|
3764
3766
|
import { homedir as homedir22 } from "os";
|
|
3765
3767
|
import { closeSync as closeSync8, constants as constants8, fstatSync as fstatSync8, lstatSync as lstatSync15, openSync as openSync8, readSync as readSync6 } from "fs";
|
|
3766
3768
|
import { join as join19 } from "path";
|
|
3767
|
-
import { createHash as
|
|
3769
|
+
import { createHash as createHash17 } from "crypto";
|
|
3768
3770
|
import { lstatSync as lstatSync16, readFileSync as readFileSync13, readdirSync as readdirSync7 } from "fs";
|
|
3769
3771
|
import { join as join20 } from "path";
|
|
3770
3772
|
import { existsSync as existsSync82, lstatSync as lstatSync17, realpathSync as realpathSync8 } from "fs";
|
|
3771
|
-
import { join as join21, resolve as
|
|
3772
|
-
import { closeSync as closeSync9, constants as constants9, fstatSync as fstatSync9, fsyncSync as fsyncSync3, lstatSync as lstatSync18, openSync as openSync9, readSync as readSync7, writeFileSync as writeFileSync5 } from "fs";
|
|
3773
|
-
import { createHash as
|
|
3774
|
-
import { dirname as
|
|
3775
|
-
import { createHash as createHash19 } from "crypto";
|
|
3776
|
-
import { constants as constants11, closeSync as closeSync11, fchmodSync, fstatSync as fstatSync11, fsyncSync as fsyncSync5, linkSync as linkSync3, lstatSync as lstatSync21, mkdirSync as mkdirSync9, openSync as openSync11, opendirSync as opendirSync4, readSync as readSync9, renameSync as renameSync5, rmdirSync as rmdirSync3, rmSync as rmSync3, unlinkSync as unlinkSync5, writeSync as writeSync2 } from "fs";
|
|
3777
|
-
import { dirname as dirname16, isAbsolute as isAbsolute14, join as join29, parse as parse6, resolve as resolve14 } from "path";
|
|
3773
|
+
import { join as join21, resolve as resolve13 } from "path";
|
|
3774
|
+
import { closeSync as closeSync9, constants as constants9, fstatSync as fstatSync9, fsyncSync as fsyncSync3, lstatSync as lstatSync18, openSync as openSync9, readlinkSync as readlinkSync5, readSync as readSync7, writeFileSync as writeFileSync5 } from "fs";
|
|
3775
|
+
import { createHash as createHash18 } from "crypto";
|
|
3776
|
+
import { dirname as dirname14, isAbsolute as isAbsolute14, resolve as resolve14 } from "path";
|
|
3778
3777
|
import { createHash as createHash21 } from "crypto";
|
|
3779
|
-
import { closeSync as
|
|
3780
|
-
import {
|
|
3781
|
-
import { createHash as
|
|
3782
|
-
import {
|
|
3783
|
-
import {
|
|
3778
|
+
import { constants as constants12, closeSync as closeSync12, fchmodSync as fchmodSync2, fstatSync as fstatSync12, fsyncSync as fsyncSync6, linkSync as linkSync3, lstatSync as lstatSync22, mkdirSync as mkdirSync9, openSync as openSync12, opendirSync as opendirSync4, readSync as readSync9, renameSync as renameSync5, rmdirSync as rmdirSync3, rmSync as rmSync3, unlinkSync as unlinkSync5, writeSync as writeSync3 } from "fs";
|
|
3779
|
+
import { dirname as dirname17, isAbsolute as isAbsolute17, join as join29, parse as parse6, resolve as resolve16 } from "path";
|
|
3780
|
+
import { createHash as createHash23 } from "crypto";
|
|
3781
|
+
import { closeSync as closeSync14, constants as constants14, fstatSync as fstatSync14, lstatSync as lstatSync24, openSync as openSync14, readSync as readSync11 } from "fs";
|
|
3782
|
+
import { basename as basename10, dirname as dirname19, isAbsolute as isAbsolute20, resolve as resolve19 } from "path";
|
|
3783
|
+
import { createHash as createHash24 } from "crypto";
|
|
3784
|
+
import { isAbsolute as isAbsolute23 } from "path";
|
|
3785
|
+
import { createHash as createHash29 } from "crypto";
|
|
3784
3786
|
var __defProp2 = Object.defineProperty;
|
|
3785
3787
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3786
3788
|
var __returnValue2 = (v) => v;
|
|
@@ -8888,8 +8890,8 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
8888
8890
|
visit.REMOVE = REMOVE;
|
|
8889
8891
|
visit.itemAtPath = (cst, path) => {
|
|
8890
8892
|
let item = cst;
|
|
8891
|
-
for (const [
|
|
8892
|
-
const tok = item?.[
|
|
8893
|
+
for (const [field2, index] of path) {
|
|
8894
|
+
const tok = item?.[field2];
|
|
8893
8895
|
if (tok && "items" in tok) {
|
|
8894
8896
|
item = tok.items[index];
|
|
8895
8897
|
} else
|
|
@@ -8899,8 +8901,8 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
8899
8901
|
};
|
|
8900
8902
|
visit.parentCollection = (cst, path) => {
|
|
8901
8903
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
8902
|
-
const
|
|
8903
|
-
const coll = parent?.[
|
|
8904
|
+
const field2 = path[path.length - 1][0];
|
|
8905
|
+
const coll = parent?.[field2];
|
|
8904
8906
|
if (coll && "items" in coll)
|
|
8905
8907
|
return coll;
|
|
8906
8908
|
throw new Error("Parent collection not found");
|
|
@@ -8909,11 +8911,11 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
8909
8911
|
let ctrl = visitor(item, path);
|
|
8910
8912
|
if (typeof ctrl === "symbol")
|
|
8911
8913
|
return ctrl;
|
|
8912
|
-
for (const
|
|
8913
|
-
const token = item[
|
|
8914
|
+
for (const field2 of ["key", "value"]) {
|
|
8915
|
+
const token = item[field2];
|
|
8914
8916
|
if (token && "items" in token) {
|
|
8915
8917
|
for (let i = 0;i < token.items.length; ++i) {
|
|
8916
|
-
const ci = _visit(Object.freeze(path.concat([[
|
|
8918
|
+
const ci = _visit(Object.freeze(path.concat([[field2, i]])), token.items[i], visitor);
|
|
8917
8919
|
if (typeof ci === "number")
|
|
8918
8920
|
i = ci - 1;
|
|
8919
8921
|
else if (ci === BREAK)
|
|
@@ -8923,7 +8925,7 @@ var require_cst_visit = __commonJS((exports) => {
|
|
|
8923
8925
|
i -= 1;
|
|
8924
8926
|
}
|
|
8925
8927
|
}
|
|
8926
|
-
if (typeof ctrl === "function" &&
|
|
8928
|
+
if (typeof ctrl === "function" && field2 === "key")
|
|
8927
8929
|
ctrl = ctrl(item, path);
|
|
8928
8930
|
}
|
|
8929
8931
|
}
|
|
@@ -9345,9 +9347,9 @@ var require_lexer = __commonJS((exports) => {
|
|
|
9345
9347
|
}
|
|
9346
9348
|
}
|
|
9347
9349
|
*parseQuotedScalar() {
|
|
9348
|
-
const
|
|
9349
|
-
let end = this.buffer.indexOf(
|
|
9350
|
-
if (
|
|
9350
|
+
const quote22 = this.charAt(0);
|
|
9351
|
+
let end = this.buffer.indexOf(quote22, this.pos + 1);
|
|
9352
|
+
if (quote22 === "'") {
|
|
9351
9353
|
while (end !== -1 && this.buffer[end + 1] === "'")
|
|
9352
9354
|
end = this.buffer.indexOf("'", end + 2);
|
|
9353
9355
|
} else {
|
|
@@ -11288,6 +11290,10 @@ function parse3(text) {
|
|
|
11288
11290
|
need(root.entries.length <= CLAUDE_SETTINGS_WITNESS_LIMITS.rows, "exceeds its settings field limit");
|
|
11289
11291
|
return root;
|
|
11290
11292
|
}
|
|
11293
|
+
function parseNativeJsonObject(text) {
|
|
11294
|
+
need(typeof text === "string" && Buffer.byteLength(text) <= CLAUDE_SETTINGS_WITNESS_LIMITS.bytes, "exceeds its byte limit");
|
|
11295
|
+
return parse3(text);
|
|
11296
|
+
}
|
|
11291
11297
|
var BOOLEAN_PREFERENCES = new Set([
|
|
11292
11298
|
"autoScrollEnabled",
|
|
11293
11299
|
"axScreenReader",
|
|
@@ -11339,6 +11345,8 @@ var BUILTIN_MODEL_SELECTIONS = new Set([
|
|
|
11339
11345
|
"claude-opus-4-6[1m]",
|
|
11340
11346
|
"claude-sonnet-4-6[1m]"
|
|
11341
11347
|
]);
|
|
11348
|
+
var CLAUDE_BUILTIN_THEMES = Object.freeze(["auto", "dark", "light", "dark-daltonized", "light-daltonized", "dark-ansi", "light-ansi"]);
|
|
11349
|
+
var BUILTIN_THEMES = new Set(CLAUDE_BUILTIN_THEMES);
|
|
11342
11350
|
function canonical(value) {
|
|
11343
11351
|
if (value.kind === "object")
|
|
11344
11352
|
return { kind: "object", entries: value.entries.map(([key, child]) => [key, canonical(child)]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0) };
|
|
@@ -11397,7 +11405,9 @@ function inferencePreference(key, child, version) {
|
|
|
11397
11405
|
function settingsDigest(text, version = 1) {
|
|
11398
11406
|
const value = parse3(text);
|
|
11399
11407
|
value.entries = value.entries.filter(([key, child]) => {
|
|
11400
|
-
if (version
|
|
11408
|
+
if (version === 4 && key === "theme" && child.kind === "string" && BUILTIN_THEMES.has(child.value))
|
|
11409
|
+
return false;
|
|
11410
|
+
if (version !== 1 && inferencePreference(key, child, version === 4 ? 3 : version))
|
|
11401
11411
|
return false;
|
|
11402
11412
|
if (key === "model") {
|
|
11403
11413
|
need(child.kind === "string", "contains an invalid model selection");
|
|
@@ -11455,6 +11465,26 @@ function upgradeClaudeSettingsWitness(previous, reviewedSettingsPath) {
|
|
|
11455
11465
|
need(settingsDigest(before, 3) === sha256, "non-preference settings changed; explicit discovery review required");
|
|
11456
11466
|
return { path: previous.path, hashMode: "claude-settings-v3", sha256 };
|
|
11457
11467
|
}
|
|
11468
|
+
function captureClaudeSettingsV4(path, budget = { remaining: 256 * 1024 * 1024 }) {
|
|
11469
|
+
return { path, hashMode: "claude-settings-v4", sha256: settingsDigest(readNativeSettingsWitnessFile(path, budget), 4) };
|
|
11470
|
+
}
|
|
11471
|
+
function hashClaudeSettingsReplacementV4(text, budget) {
|
|
11472
|
+
need(typeof text === "string", "requires settings text");
|
|
11473
|
+
const bytes = Buffer.byteLength(text);
|
|
11474
|
+
need(bytes <= CLAUDE_SETTINGS_WITNESS_LIMITS.bytes && Number.isSafeInteger(budget.remaining) && budget.remaining >= bytes, "exceeds its byte limit");
|
|
11475
|
+
budget.remaining -= bytes;
|
|
11476
|
+
return settingsDigest(text, 4);
|
|
11477
|
+
}
|
|
11478
|
+
function upgradeClaudeSettingsWitnessV4(previous, reviewedSettingsPath) {
|
|
11479
|
+
need(previous && Object.keys(previous).every((key) => ["path", "hashMode", "sha256"].includes(key)) && (previous.hashMode === undefined || previous.hashMode === "bytes" || previous.hashMode === "claude-settings-v1" || previous.hashMode === "claude-settings-v2" || previous.hashMode === "claude-settings-v3") && typeof previous.sha256 === "string" && /^[a-f0-9]{64}$/.test(previous.sha256), "requires an exact prior settings witness");
|
|
11480
|
+
const budget = { remaining: 2 * CLAUDE_SETTINGS_WITNESS_LIMITS.bytes };
|
|
11481
|
+
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget), current2 = readNativeSettingsWitnessFile(previous.path, budget);
|
|
11482
|
+
const beforeDigest = previous.hashMode === undefined || previous.hashMode === "bytes" ? createHash22("sha256").update(before).digest("hex") : settingsDigest(before, previous.hashMode === "claude-settings-v1" ? 1 : previous.hashMode === "claude-settings-v2" ? 2 : 3);
|
|
11483
|
+
need(beforeDigest === previous.sha256, "reviewed preimage does not match the prior witness");
|
|
11484
|
+
const sha256 = settingsDigest(current2, 4);
|
|
11485
|
+
need(settingsDigest(before, 4) === sha256, "non-preference settings changed; explicit discovery review required");
|
|
11486
|
+
return { path: previous.path, hashMode: "claude-settings-v4", sha256 };
|
|
11487
|
+
}
|
|
11458
11488
|
function hashNativeJsonControls(text, excludedMetadata) {
|
|
11459
11489
|
need(Buffer.byteLength(text) <= CLAUDE_SETTINGS_WITNESS_LIMITS.bytes, "exceeds its byte limit");
|
|
11460
11490
|
const value = parse3(text);
|
|
@@ -11513,6 +11543,213 @@ function upgradeSumiSettingsWitness(previous, reviewedSettingsPath) {
|
|
|
11513
11543
|
throw new Error("Sumi non-display settings changed; explicit discovery review required");
|
|
11514
11544
|
return next;
|
|
11515
11545
|
}
|
|
11546
|
+
var MEASURED_CODEX_CAPABILITIES = {
|
|
11547
|
+
"codex-cli 0.153.0": ["hooks"],
|
|
11548
|
+
"codex-cli 0.154.0": ["hooks"],
|
|
11549
|
+
"codex-cli 0.155.0": ["hooks"],
|
|
11550
|
+
"codex-cli 0.155.1": ["hooks"],
|
|
11551
|
+
"codex-cli 0.156.1": ["hooks"],
|
|
11552
|
+
"codex-cli 0.157.0": ["hooks"],
|
|
11553
|
+
"codex-cli 0.157.1": ["hooks"],
|
|
11554
|
+
"codex-cli 0.158.0": ["hooks"],
|
|
11555
|
+
"codex-cli 0.159.0": ["hooks"],
|
|
11556
|
+
"codex-cli 0.159.2": ["hooks", "qualified-skill-catalog"],
|
|
11557
|
+
"codex-cli 0.160.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
11558
|
+
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
11559
|
+
};
|
|
11560
|
+
function supportsCodexNativeCapability(version, capability) {
|
|
11561
|
+
return typeof version === "string" && Object.hasOwn(MEASURED_CODEX_CAPABILITIES, version) && MEASURED_CODEX_CAPABILITIES[version].includes(capability);
|
|
11562
|
+
}
|
|
11563
|
+
var SUPPORTED_CODEX_HOOK_VERSIONS = Object.freeze(Object.keys(MEASURED_CODEX_CAPABILITIES).filter((version) => supportsCodexNativeCapability(version, "hooks")));
|
|
11564
|
+
var CLAUDE_MARKETPLACE_ENTRY_HASH_MODE = "claude-marketplace-entry-v1";
|
|
11565
|
+
var DOMAIN = "hasna.skills.claude-marketplace-entry.v1\x00";
|
|
11566
|
+
var PATH_CHARACTERS = 4096;
|
|
11567
|
+
var NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
11568
|
+
function need2(value, reason) {
|
|
11569
|
+
if (!value)
|
|
11570
|
+
throw new Error(`Claude marketplace entry witness ${reason}`);
|
|
11571
|
+
}
|
|
11572
|
+
var bounded = (key) => key.length > 64 ? `${key.slice(0, 64)}...` : key;
|
|
11573
|
+
var quote3 = (text) => JSON.stringify(text).replace(/[^\x20-\x7e]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
11574
|
+
var child = (path, key) => path + (/^[A-Za-z0-9_$-]{1,64}$/.test(key) ? `.${key}` : `[${JSON.stringify(bounded(key))}]`);
|
|
11575
|
+
function unknownKey(selector, path, key) {
|
|
11576
|
+
throw new Error(path === null ? `${CLAUDE_MARKETPLACE_ENTRY_HASH_MODE}: unknown top-level key ${quote3(bounded(key))} in ${selector.marketplace}` : `${CLAUDE_MARKETPLACE_ENTRY_HASH_MODE}: unknown key ${quote3(child(path, key))} in ${selector.marketplace}`);
|
|
11577
|
+
}
|
|
11578
|
+
function knownKeys(object, allowed, selector, path) {
|
|
11579
|
+
for (const [key] of object.entries)
|
|
11580
|
+
if (!allowed.has(key))
|
|
11581
|
+
unknownKey(selector, path, key);
|
|
11582
|
+
}
|
|
11583
|
+
var reason = (error) => String(error?.message ?? error).replace(/^Claude settings witness /, "");
|
|
11584
|
+
var MARKETPLACE_KEYS = new Set(["$schema", "name", "owner", "plugins", "description", "version", "metadata", "forceRemoveDeletedPlugins", "allowCrossMarketplaceDependenciesOn", "renames"]);
|
|
11585
|
+
var MARKETPLACE_METADATA_KEYS = new Set(["description", "version", "pluginRoot"]);
|
|
11586
|
+
var ENTRY_BOUND_KEYS = new Set([
|
|
11587
|
+
"name",
|
|
11588
|
+
"source",
|
|
11589
|
+
"strict",
|
|
11590
|
+
"defaultEnabled",
|
|
11591
|
+
"dependencies",
|
|
11592
|
+
"relevance",
|
|
11593
|
+
"headers",
|
|
11594
|
+
"headersHelper",
|
|
11595
|
+
"settings",
|
|
11596
|
+
"userConfig",
|
|
11597
|
+
"types",
|
|
11598
|
+
"channels",
|
|
11599
|
+
"skills",
|
|
11600
|
+
"commands",
|
|
11601
|
+
"agents",
|
|
11602
|
+
"hooks",
|
|
11603
|
+
"mcpServers",
|
|
11604
|
+
"lspServers",
|
|
11605
|
+
"outputStyles",
|
|
11606
|
+
"workflows",
|
|
11607
|
+
"experimental",
|
|
11608
|
+
"themes",
|
|
11609
|
+
"monitors"
|
|
11610
|
+
]);
|
|
11611
|
+
var ENTRY_OMITTED_KEYS = new Set(["$schema", "description", "version", "author", "homepage", "repository", "license", "keywords", "category", "tags", "displayName", "metadata"]);
|
|
11612
|
+
var EXPERIMENTAL_KEYS = new Set(["themes", "monitors", "evals"]);
|
|
11613
|
+
var SOURCE_KEYS = Object.freeze({
|
|
11614
|
+
github: ["source", "repo", "ref", "sha"],
|
|
11615
|
+
url: ["source", "url", "ref", "sha", "path"],
|
|
11616
|
+
"git-subdir": ["source", "url", "path", "ref", "sha"],
|
|
11617
|
+
npm: ["source", "package", "version", "registry"],
|
|
11618
|
+
archive: ["source", "url", "sha256"],
|
|
11619
|
+
command: ["source", "command", "timeout", "mode"]
|
|
11620
|
+
});
|
|
11621
|
+
var field = (object, key) => object.entries.find(([name]) => name === key)?.[1];
|
|
11622
|
+
var isString = (value) => value?.kind === "string";
|
|
11623
|
+
var isBoolean = (value) => value?.kind === "literal" && (value.value === "true" || value.value === "false");
|
|
11624
|
+
var stringArray = (value) => value?.kind === "array" && value.items.every(isString);
|
|
11625
|
+
var stringObject = (value) => value?.kind === "object" && value.entries.every(([, item]) => isString(item));
|
|
11626
|
+
function claudeMarketplaceEntrySourceValid(source) {
|
|
11627
|
+
const path = source?.path;
|
|
11628
|
+
return typeof path === "string" && path.length > 0 && path.length <= PATH_CHARACTERS && !/[\x00-\x1f\x7f]/.test(path) && isAbsolute32(path) && resolve32(path) === path && basename3(path) === "marketplace.json" && basename3(dirname42(path)) === ".claude-plugin" && typeof source.marketplace === "string" && NAME.test(source.marketplace) && !source.marketplace.includes("..") && typeof source.plugin === "string" && NAME.test(source.plugin);
|
|
11629
|
+
}
|
|
11630
|
+
function canonical2(value) {
|
|
11631
|
+
if (value.kind === "string")
|
|
11632
|
+
return JSON.stringify(value.value);
|
|
11633
|
+
if (value.kind === "number" || value.kind === "literal")
|
|
11634
|
+
return value.value;
|
|
11635
|
+
if (value.kind === "array")
|
|
11636
|
+
return "[" + value.items.map(canonical2).join(",") + "]";
|
|
11637
|
+
return "{" + [...value.entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => JSON.stringify(key) + ":" + canonical2(item)).join(",") + "}";
|
|
11638
|
+
}
|
|
11639
|
+
function validateMarketplace(root, selector) {
|
|
11640
|
+
knownKeys(root, MARKETPLACE_KEYS, selector, null);
|
|
11641
|
+
const name = field(root, "name");
|
|
11642
|
+
need2(isString(name) && name.value === selector.marketplace, "marketplace name does not match the reviewed binding");
|
|
11643
|
+
for (const key of ["$schema", "description", "version"]) {
|
|
11644
|
+
const value = field(root, key);
|
|
11645
|
+
need2(value === undefined || isString(value), `has an invalid marketplace ${key}`);
|
|
11646
|
+
}
|
|
11647
|
+
const owner = field(root, "owner");
|
|
11648
|
+
need2(owner === undefined || owner.kind === "object", "has an invalid marketplace owner");
|
|
11649
|
+
const metadata = field(root, "metadata");
|
|
11650
|
+
if (metadata !== undefined) {
|
|
11651
|
+
need2(metadata.kind === "object", "has an invalid marketplace metadata object");
|
|
11652
|
+
knownKeys(metadata, MARKETPLACE_METADATA_KEYS, selector, "metadata");
|
|
11653
|
+
for (const [key, value] of metadata.entries)
|
|
11654
|
+
need2(isString(value), `has an invalid marketplace metadata.${key}`);
|
|
11655
|
+
}
|
|
11656
|
+
const remove = field(root, "forceRemoveDeletedPlugins");
|
|
11657
|
+
need2(remove === undefined || isBoolean(remove), "has an invalid forceRemoveDeletedPlugins value");
|
|
11658
|
+
const cross = field(root, "allowCrossMarketplaceDependenciesOn");
|
|
11659
|
+
need2(cross === undefined || stringArray(cross), "has an invalid allowCrossMarketplaceDependenciesOn value");
|
|
11660
|
+
const renames = field(root, "renames");
|
|
11661
|
+
if (renames !== undefined) {
|
|
11662
|
+
need2(renames.kind === "object" && renames.entries.every(([, target]) => isString(target) || target.kind === "literal" && target.value === "null"), "has an invalid renames map");
|
|
11663
|
+
need2(!renames.entries.some(([from]) => from.toLowerCase() === selector.plugin.toLowerCase()), "plugin id is redirected by the marketplace renames map");
|
|
11664
|
+
}
|
|
11665
|
+
}
|
|
11666
|
+
function validateSource(source, selector, path) {
|
|
11667
|
+
if (isString(source)) {
|
|
11668
|
+
need2(source.value.length > 0, "has an empty plugin source");
|
|
11669
|
+
return;
|
|
11670
|
+
}
|
|
11671
|
+
need2(source?.kind === "object", "has an invalid plugin source");
|
|
11672
|
+
const type = field(source, "source");
|
|
11673
|
+
need2(isString(type) && Object.hasOwn(SOURCE_KEYS, type.value), "has an unreviewed plugin source type");
|
|
11674
|
+
knownKeys(source, new Set(SOURCE_KEYS[type.value]), selector, path);
|
|
11675
|
+
}
|
|
11676
|
+
function projectEntry(entry, selector) {
|
|
11677
|
+
const path = `plugins[${selector.plugin}]`;
|
|
11678
|
+
knownKeys(entry, { has: (key) => ENTRY_BOUND_KEYS.has(key) || ENTRY_OMITTED_KEYS.has(key) }, selector, path);
|
|
11679
|
+
const name = field(entry, "name");
|
|
11680
|
+
need2(isString(name) && name.value === selector.plugin, "selected entry name does not match");
|
|
11681
|
+
validateSource(field(entry, "source"), selector, `${path}.source`);
|
|
11682
|
+
for (const key of ["strict", "defaultEnabled"]) {
|
|
11683
|
+
const value = field(entry, key);
|
|
11684
|
+
need2(value === undefined || isBoolean(value), `has an invalid entry ${key}`);
|
|
11685
|
+
}
|
|
11686
|
+
const headersHelper = field(entry, "headersHelper");
|
|
11687
|
+
need2(headersHelper === undefined || isString(headersHelper), "has an invalid entry headersHelper");
|
|
11688
|
+
const experimental = field(entry, "experimental");
|
|
11689
|
+
if (experimental !== undefined) {
|
|
11690
|
+
need2(experimental.kind === "object", "has an invalid entry experimental object");
|
|
11691
|
+
knownKeys(experimental, EXPERIMENTAL_KEYS, selector, `${path}.experimental`);
|
|
11692
|
+
}
|
|
11693
|
+
for (const key of ["$schema", "description", "version", "homepage", "license", "category", "displayName"]) {
|
|
11694
|
+
const value = field(entry, key);
|
|
11695
|
+
need2(value === undefined || isString(value), `has an invalid entry ${key}`);
|
|
11696
|
+
}
|
|
11697
|
+
for (const [key, keys] of [["author", new Set(["name", "email", "url"])], ["repository", new Set(["type", "url", "directory"])]]) {
|
|
11698
|
+
const value = field(entry, key);
|
|
11699
|
+
if (value?.kind === "object")
|
|
11700
|
+
knownKeys(value, keys, selector, `${path}.${key}`);
|
|
11701
|
+
need2(value === undefined || isString(value) || stringObject(value), `has an invalid entry ${key}`);
|
|
11702
|
+
}
|
|
11703
|
+
for (const key of ["keywords", "tags"]) {
|
|
11704
|
+
const value = field(entry, key);
|
|
11705
|
+
need2(value === undefined || stringArray(value), `has an invalid entry ${key}`);
|
|
11706
|
+
}
|
|
11707
|
+
const metadata = field(entry, "metadata");
|
|
11708
|
+
need2(metadata === undefined || metadata.kind === "object", "has an invalid entry metadata object");
|
|
11709
|
+
return { kind: "object", entries: entry.entries.filter(([key]) => ENTRY_BOUND_KEYS.has(key)) };
|
|
11710
|
+
}
|
|
11711
|
+
function hashClaudeMarketplaceEntry(text, selector) {
|
|
11712
|
+
need2(selector && typeof selector.marketplace === "string" && NAME.test(selector.marketplace) && !selector.marketplace.includes("..") && typeof selector.plugin === "string" && NAME.test(selector.plugin), "requires an exact marketplace and plugin name");
|
|
11713
|
+
let root;
|
|
11714
|
+
try {
|
|
11715
|
+
root = parseNativeJsonObject(text);
|
|
11716
|
+
} catch (error) {
|
|
11717
|
+
throw new Error(`Claude marketplace entry witness cannot parse marketplace.json: ${reason(error)}`);
|
|
11718
|
+
}
|
|
11719
|
+
validateMarketplace(root, selector);
|
|
11720
|
+
const plugins = field(root, "plugins");
|
|
11721
|
+
need2(plugins?.kind === "array", "requires a plugins array");
|
|
11722
|
+
const entryName = (item) => {
|
|
11723
|
+
if (item.kind !== "object")
|
|
11724
|
+
return;
|
|
11725
|
+
const name = field(item, "name");
|
|
11726
|
+
return isString(name) ? name.value : undefined;
|
|
11727
|
+
};
|
|
11728
|
+
const exact = plugins.items.filter((item) => entryName(item) === selector.plugin);
|
|
11729
|
+
const folded = plugins.items.filter((item) => entryName(item)?.toLowerCase() === selector.plugin.toLowerCase());
|
|
11730
|
+
need2(exact.length > 0, "selected plugin entry is missing");
|
|
11731
|
+
need2(exact.length === 1 && folded.length === 1, "selected plugin entry is duplicated or ambiguous");
|
|
11732
|
+
const entry = projectEntry(exact[0], selector);
|
|
11733
|
+
const metadata = field(root, "metadata"), pluginRoot = metadata?.kind === "object" ? field(metadata, "pluginRoot") : undefined;
|
|
11734
|
+
const nullValue = { kind: "literal", value: "null" };
|
|
11735
|
+
const marketplace = { kind: "object", entries: [
|
|
11736
|
+
["name", field(root, "name")],
|
|
11737
|
+
["pluginRoot", pluginRoot ?? nullValue],
|
|
11738
|
+
["allowCrossMarketplaceDependenciesOn", field(root, "allowCrossMarketplaceDependenciesOn") ?? nullValue]
|
|
11739
|
+
] };
|
|
11740
|
+
const projection = { kind: "object", entries: [["marketplace", marketplace], ["plugin", entry]] };
|
|
11741
|
+
return createHash42("sha256").update(DOMAIN).update(canonical2(projection)).digest("hex");
|
|
11742
|
+
}
|
|
11743
|
+
function captureClaudeMarketplaceEntry(path, marketplace, plugin, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
11744
|
+
need2(claudeMarketplaceEntrySourceValid({ path, marketplace, plugin }), "requires a normalized absolute .claude-plugin/marketplace.json path and exact names");
|
|
11745
|
+
let text;
|
|
11746
|
+
try {
|
|
11747
|
+
text = readNativeSettingsWitnessFile(path, budget2, "marketplace.json");
|
|
11748
|
+
} catch (error) {
|
|
11749
|
+
throw new Error(`Claude marketplace entry witness cannot read marketplace.json: ${reason(error)}`);
|
|
11750
|
+
}
|
|
11751
|
+
return { path, hashMode: CLAUDE_MARKETPLACE_ENTRY_HASH_MODE, marketplace, plugin, sha256: hashClaudeMarketplaceEntry(text, { marketplace, plugin }) };
|
|
11752
|
+
}
|
|
11516
11753
|
var AGENT_POLICY_LIMITS = Object.freeze({ bytes: 1024 * 1024, agents: 16, discoverySources: 2048, discoveryRawSourceBytes: 64 * 1024 * 1024, discoveryRawTotalBytes: 256 * 1024 * 1024, discoveryPathLinks: 40, discoveryPathSteps: 256, discoveryPathSourceMetadataBytes: 64 * 1024, discoveryPathTotalMetadataBytes: 8 * 1024 * 1024, discoveryRoots: 512, discoveryDirectories: 64, discoveryDirectoryEntries: 20000, discoveryDirectoryBytes: 8 * 1024 * 1024, builtinNames: 2048, rootAliases: 2, fields: 64, pathCharacters: 4096 });
|
|
11517
11754
|
function object(value) {
|
|
11518
11755
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -11566,7 +11803,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11566
11803
|
text(control.pluginId, 1024);
|
|
11567
11804
|
text(control.namespace, 64);
|
|
11568
11805
|
text(control.pluginParent);
|
|
11569
|
-
requireBound(
|
|
11806
|
+
requireBound(isAbsolute4(control.pluginParent) && resolve42(control.pluginParent) === control.pluginParent && /^[a-f0-9]{64}$/.test(control.manifestSha256));
|
|
11570
11807
|
if (control.remotePluginId !== undefined)
|
|
11571
11808
|
requireBound(typeof control.remotePluginId === "string" && /^[A-Za-z0-9_~-]{1,1024}$/.test(control.remotePluginId));
|
|
11572
11809
|
if (control.skillsOnly !== undefined)
|
|
@@ -11578,16 +11815,24 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11578
11815
|
}
|
|
11579
11816
|
if (bridge.codexInactivePlugins !== undefined) {
|
|
11580
11817
|
const controls = array(bridge.codexInactivePlugins, 4096), ids = new Set;
|
|
11581
|
-
requireBound(controls.length === 0 || object(bridge.codexPluginSkillReview) && bridge.codexPluginSkillReview.version
|
|
11818
|
+
requireBound(controls.length === 0 || object(bridge.codexPluginSkillReview) && supportsCodexNativeCapability(bridge.codexPluginSkillReview.version, "installed-plugin-review") && typeof bridge.codexPluginSkillReview.catalogSha256 === "string" && /^[a-f0-9]{64}$/.test(bridge.codexPluginSkillReview.catalogSha256));
|
|
11582
11819
|
for (const control of controls) {
|
|
11583
11820
|
requireBound(object(control) && Object.keys(control).every((key) => ["pluginId", "namespace", "pluginParent", "sourceType", "sourceSha256"].includes(key)));
|
|
11584
11821
|
text(control.pluginId, 1024);
|
|
11585
11822
|
text(control.namespace, 64);
|
|
11586
11823
|
text(control.pluginParent);
|
|
11587
|
-
requireBound(!ids.has(control.pluginId) &&
|
|
11824
|
+
requireBound(!ids.has(control.pluginId) && isAbsolute4(control.pluginParent) && resolve42(control.pluginParent) === control.pluginParent && ["local", "git", "npm"].includes(control.sourceType) && typeof control.sourceSha256 === "string" && /^[a-f0-9]{64}$/.test(control.sourceSha256));
|
|
11588
11825
|
ids.add(control.pluginId);
|
|
11589
11826
|
}
|
|
11590
11827
|
}
|
|
11828
|
+
if (bridge.discoveryExecutables !== undefined)
|
|
11829
|
+
for (const [agent, executable] of Object.entries(record(bridge.discoveryExecutables, AGENT_POLICY_LIMITS.agents))) {
|
|
11830
|
+
requireBound(agent === "gemini" && object(executable) && Object.keys(executable).length === 3 && executable.command === "gemini");
|
|
11831
|
+
for (const path of [executable.path, executable.target]) {
|
|
11832
|
+
text(path);
|
|
11833
|
+
requireBound(!/[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(path) && isAbsolute4(path) && resolve42(path) === path);
|
|
11834
|
+
}
|
|
11835
|
+
}
|
|
11591
11836
|
if (bridge.disabledBuiltins !== undefined)
|
|
11592
11837
|
for (const builtin of array(bridge.disabledBuiltins, AGENT_POLICY_LIMITS.builtinNames)) {
|
|
11593
11838
|
requireBound(object(builtin));
|
|
@@ -11613,11 +11858,11 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11613
11858
|
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && Object.keys(proof).every((key) => ["roots", "parents", "directories"].includes(key)) && roots.length + parents2.length > 0 && new Set(roots).size === roots.length && new Set(parents2).size === parents2.length);
|
|
11614
11859
|
for (const root of roots) {
|
|
11615
11860
|
text(root);
|
|
11616
|
-
requireBound(
|
|
11861
|
+
requireBound(isAbsolute4(root) && resolve42(root) === root);
|
|
11617
11862
|
}
|
|
11618
11863
|
for (const parent of parents2) {
|
|
11619
11864
|
text(parent);
|
|
11620
|
-
requireBound(
|
|
11865
|
+
requireBound(isAbsolute4(parent) && resolve42(parent) === parent);
|
|
11621
11866
|
}
|
|
11622
11867
|
for (const directory of array(proof.directories, AGENT_POLICY_LIMITS.discoveryDirectories)) {
|
|
11623
11868
|
requireBound(object(directory));
|
|
@@ -11630,14 +11875,14 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11630
11875
|
}
|
|
11631
11876
|
if (value.codexInstallationInputs !== undefined) {
|
|
11632
11877
|
const proof = record(value.codexInstallationInputs, 4), inputs = array(proof.plugins, 4096), ids = new Set;
|
|
11633
|
-
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && proof.version
|
|
11878
|
+
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && supportsCodexNativeCapability(proof.version, "installed-plugin-review") && typeof proof.catalogSha256 === "string" && /^[a-f0-9]{64}$/.test(proof.catalogSha256) && inputs.length > 0 && object(bridge.codexPluginSkillReview) && bridge.codexPluginSkillReview.version === proof.version && bridge.codexPluginSkillReview.catalogSha256 === proof.catalogSha256);
|
|
11634
11879
|
for (const input of inputs) {
|
|
11635
11880
|
requireBound(object(input) && Object.keys(input).every((key) => ["pluginId", "namespace", "pluginParent", "sourceRoot", "sourceSha256"].includes(key)));
|
|
11636
11881
|
text(input.pluginId, 1024);
|
|
11637
11882
|
text(input.namespace, 64);
|
|
11638
11883
|
text(input.pluginParent);
|
|
11639
11884
|
text(input.sourceRoot);
|
|
11640
|
-
requireBound(!ids.has(input.pluginId) && [input.pluginParent, input.sourceRoot].every((path) =>
|
|
11885
|
+
requireBound(!ids.has(input.pluginId) && [input.pluginParent, input.sourceRoot].every((path) => isAbsolute4(path) && resolve42(path) === path) && typeof input.sourceSha256 === "string" && /^[a-f0-9]{64}$/.test(input.sourceSha256));
|
|
11641
11886
|
ids.add(input.pluginId);
|
|
11642
11887
|
}
|
|
11643
11888
|
if (proof.directories !== undefined)
|
|
@@ -11654,17 +11899,19 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11654
11899
|
text(source.path);
|
|
11655
11900
|
requireBound(source.sha256 === null || typeof source.sha256 === "string" && /^[a-f0-9]{64}$/.test(source.sha256));
|
|
11656
11901
|
if (source.hashMode !== undefined)
|
|
11657
|
-
requireBound(["bytes", "path-bytes", "claude-plugin-manifest-v1", "claude-plugin-registry", "claude-marketplace-registry", "claude-settings-v1", "claude-settings-v2", "claude-settings-v3", "claude-marketplace-registry-v2", "codex-settings-v1", "codex-settings-v2", "codex-settings-v3", "codex-settings-v4", "sumi-settings-v1"].includes(source.hashMode) && source.format === undefined && source.fields === undefined && (source.hashMode === "bytes" || source.sha256 !== null));
|
|
11902
|
+
requireBound(["bytes", "path-bytes", "claude-plugin-manifest-v1", "claude-plugin-registry", "claude-marketplace-registry", "claude-settings-v1", "claude-settings-v2", "claude-settings-v3", "claude-settings-v4", "claude-marketplace-registry-v2", "codex-settings-v1", "codex-settings-v2", "codex-settings-v3", "codex-settings-v4", "sumi-settings-v1", "claude-marketplace-entry-v1"].includes(source.hashMode) && source.format === undefined && source.fields === undefined && (source.hashMode === "bytes" || source.sha256 !== null));
|
|
11658
11903
|
if (source.hashMode === "claude-plugin-manifest-v1")
|
|
11659
|
-
requireBound(agent === "claude" && value.agent === "claude" && ["automatic", "reviewed"].includes(value.method) && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11904
|
+
requireBound(agent === "claude" && value.agent === "claude" && ["automatic", "reviewed"].includes(value.method) && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute4(source.path) && resolve42(source.path) === source.path && source.path.endsWith(join72(sep22, ".claude-plugin", "plugin.json")) && source.managedPlugins === undefined);
|
|
11660
11905
|
if (source.hashMode === "sumi-settings-v1")
|
|
11661
|
-
requireBound(agent === "sumi" && value.agent === "sumi" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11906
|
+
requireBound(agent === "sumi" && value.agent === "sumi" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute4(source.path) && resolve42(source.path) === source.path && basename4(source.path) === "sumi.json");
|
|
11662
11907
|
if (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4"))
|
|
11663
|
-
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11664
|
-
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || source.hashMode === "claude-settings-v3")
|
|
11665
|
-
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11908
|
+
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute4(source.path) && resolve42(source.path) === source.path && basename4(source.path) === "config.toml");
|
|
11909
|
+
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4"))
|
|
11910
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute4(source.path) && resolve42(source.path) === source.path && basename4(source.path) === "settings.json");
|
|
11666
11911
|
if (source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2")
|
|
11667
|
-
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11912
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute4(source.path) && resolve42(source.path) === source.path && basename4(source.path) === "known_marketplaces.json");
|
|
11913
|
+
if (source.hashMode === "claude-marketplace-entry-v1")
|
|
11914
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && claudeMarketplaceEntrySourceValid(source));
|
|
11668
11915
|
if (source.hashMode === "claude-plugin-registry") {
|
|
11669
11916
|
requireBound(agent === "claude");
|
|
11670
11917
|
const managed = array(source.managedPlugins, 64);
|
|
@@ -11679,8 +11926,8 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11679
11926
|
if (source.format !== undefined)
|
|
11680
11927
|
requireBound(["json", "toml", "yaml"].includes(source.format));
|
|
11681
11928
|
if (source.fields !== undefined)
|
|
11682
|
-
for (const
|
|
11683
|
-
text(
|
|
11929
|
+
for (const field2 of array(source.fields, AGENT_POLICY_LIMITS.fields))
|
|
11930
|
+
text(field2, 256);
|
|
11684
11931
|
}
|
|
11685
11932
|
if (value.directories !== undefined)
|
|
11686
11933
|
for (const directory of array(value.directories, AGENT_POLICY_LIMITS.discoveryDirectories)) {
|
|
@@ -11772,7 +12019,7 @@ function quoted(value) {
|
|
|
11772
12019
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
11773
12020
|
}
|
|
11774
12021
|
function hermesHookDefinitions(supervisor2) {
|
|
11775
|
-
if (!
|
|
12022
|
+
if (!isAbsolute5(supervisor2.runtime) || !isAbsolute5(supervisor2.path))
|
|
11776
12023
|
throw new Error("Expected absolute Hermes supervisor paths");
|
|
11777
12024
|
const entry = (event) => ({ command: `${quoted(supervisor2.runtime)} ${quoted(supervisor2.path)} --event ${event}`, timeout: 15, ...event === "pre_tool_call" ? { fail_closed: true } : {} });
|
|
11778
12025
|
return { pre_llm_call: entry("pre_llm_call"), pre_tool_call: entry("pre_tool_call") };
|
|
@@ -11785,16 +12032,16 @@ function assertHermesEnvironment(home) {
|
|
|
11785
12032
|
throw new Error(`NATIVE_SKILL_DRIFT: Hermes ${variable} requires a dedicated discovery adapter; unset it before using this adapter`);
|
|
11786
12033
|
}
|
|
11787
12034
|
const selected = process.env.HERMES_HOME?.trim();
|
|
11788
|
-
if (selected && (!
|
|
12035
|
+
if (selected && (!isAbsolute5(selected) || resolve5(selected) !== join82(resolve5(home), ".hermes")))
|
|
11789
12036
|
throw new Error("NATIVE_SKILL_DRIFT: custom Hermes homes/profiles require their own reviewed bridge");
|
|
11790
12037
|
if (process.env.HERMES_ENABLE_PROJECT_PLUGINS?.trim() && !["0", "false", "no", "off"].includes(process.env.HERMES_ENABLE_PROJECT_PLUGINS.trim().toLowerCase()))
|
|
11791
12038
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes project plugins require a dedicated discovery review");
|
|
11792
12039
|
}
|
|
11793
12040
|
function read(path) {
|
|
11794
|
-
for (let current2 = path;; current2 =
|
|
12041
|
+
for (let current2 = path;; current2 = dirname52(current2)) {
|
|
11795
12042
|
if (lstatSync42(current2, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
11796
12043
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes protection input");
|
|
11797
|
-
if (
|
|
12044
|
+
if (dirname52(current2) === current2)
|
|
11798
12045
|
break;
|
|
11799
12046
|
}
|
|
11800
12047
|
const stat = lstatSync42(path, { throwIfNoEntry: false });
|
|
@@ -11808,7 +12055,7 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
11808
12055
|
assertHermesEnvironment(home);
|
|
11809
12056
|
if (read(join82(home, ".hermes", HERMES_OPT_OUT)) === null)
|
|
11810
12057
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes bundled skill reseeding is not disabled; run skills hook install");
|
|
11811
|
-
if (!supervisor2 || !
|
|
12058
|
+
if (!supervisor2 || !isAbsolute5(supervisor2.path) || supervisor2.runtime !== process.execPath || read(supervisor2.path) !== renderHermesSupervisor(command, profile))
|
|
11812
12059
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes owned supervisor changed; run skills hook install");
|
|
11813
12060
|
const raw = read(join82(home, ".hermes/shell-hooks-allowlist.json"));
|
|
11814
12061
|
let trust;
|
|
@@ -11834,10 +12081,10 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
11834
12081
|
}
|
|
11835
12082
|
function assertNoHermesLegacyShadow(root) {
|
|
11836
12083
|
let entries = 0;
|
|
11837
|
-
for (let cursor =
|
|
12084
|
+
for (let cursor = resolve5(root);; cursor = dirname52(cursor)) {
|
|
11838
12085
|
if (lstatSync42(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
11839
12086
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes legacy discovery root");
|
|
11840
|
-
if (
|
|
12087
|
+
if (dirname52(cursor) === cursor)
|
|
11841
12088
|
break;
|
|
11842
12089
|
}
|
|
11843
12090
|
function scan(path, depth) {
|
|
@@ -11858,10 +12105,10 @@ function assertNoHermesLegacyShadow(root) {
|
|
|
11858
12105
|
const hasDescriptor = Boolean(lstatSync42(join82(path, "SKILL.md"), { throwIfNoEntry: false }));
|
|
11859
12106
|
const directory = opendirSync(path);
|
|
11860
12107
|
try {
|
|
11861
|
-
for (let
|
|
11862
|
-
if (hasDescriptor && ["references", "templates", "assets", "scripts"].includes(
|
|
12108
|
+
for (let child2 = directory.readSync();child2; child2 = directory.readSync()) {
|
|
12109
|
+
if (hasDescriptor && ["references", "templates", "assets", "scripts"].includes(child2.name))
|
|
11863
12110
|
continue;
|
|
11864
|
-
scan(join82(path,
|
|
12111
|
+
scan(join82(path, child2.name), depth + 1);
|
|
11865
12112
|
}
|
|
11866
12113
|
} finally {
|
|
11867
12114
|
directory.closeSync();
|
|
@@ -11916,15 +12163,15 @@ await new Promise((resolve, reject) => process.stdout.write(JSON.stringify(outpu
|
|
|
11916
12163
|
if (failed) process.exitCode = 2;
|
|
11917
12164
|
`;
|
|
11918
12165
|
}
|
|
11919
|
-
function
|
|
12166
|
+
function need3(value, message) {
|
|
11920
12167
|
if (!value)
|
|
11921
12168
|
throw new Error(message);
|
|
11922
12169
|
}
|
|
11923
12170
|
function safe(path) {
|
|
11924
|
-
|
|
11925
|
-
for (let cursor = path;; cursor =
|
|
11926
|
-
|
|
11927
|
-
if (
|
|
12171
|
+
need3(typeof path === "string" && path.length <= AGENT_POLICY_LIMITS.pathCharacters && isAbsolute6(path) && resolve6(path) === path && !path.includes("\x00"), "Expected a canonical absolute discovery directory path");
|
|
12172
|
+
for (let cursor = path;; cursor = dirname62(cursor)) {
|
|
12173
|
+
need3(!lstatSync5(cursor, { throwIfNoEntry: false })?.isSymbolicLink(), "Refusing symlink native discovery directory");
|
|
12174
|
+
if (dirname62(cursor) === cursor)
|
|
11928
12175
|
break;
|
|
11929
12176
|
}
|
|
11930
12177
|
}
|
|
@@ -11938,45 +12185,45 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
11938
12185
|
const root = lstatSync5(path, { throwIfNoEntry: false });
|
|
11939
12186
|
if (!root)
|
|
11940
12187
|
return { path, sha256: null };
|
|
11941
|
-
|
|
11942
|
-
const hash =
|
|
12188
|
+
need3(root.isDirectory(), "Unsupported native discovery directory input");
|
|
12189
|
+
const hash = createHash52("sha256");
|
|
11943
12190
|
function walk(current2, relative2, before, depth) {
|
|
11944
|
-
|
|
12191
|
+
need3(depth <= 64, "Native discovery directory depth limit exceeded");
|
|
11945
12192
|
const names = [], directory = opendirSync2(current2);
|
|
11946
12193
|
try {
|
|
11947
12194
|
for (let entry = directory.readSync();entry; entry = directory.readSync()) {
|
|
11948
|
-
|
|
12195
|
+
need3(++budget2.entries <= AGENT_POLICY_LIMITS.discoveryDirectoryEntries, "Native discovery directory entry limit exceeded");
|
|
11949
12196
|
names.push(entry.name);
|
|
11950
12197
|
}
|
|
11951
12198
|
} finally {
|
|
11952
12199
|
directory.closeSync();
|
|
11953
12200
|
}
|
|
11954
|
-
|
|
12201
|
+
need3(new Set(names).size === names.length, "Ambiguous native discovery directory names");
|
|
11955
12202
|
for (const name of names.sort()) {
|
|
11956
|
-
const
|
|
11957
|
-
if (omittedRoots.includes(
|
|
12203
|
+
const child2 = join92(current2, name), childRelative = relative2 ? `${relative2}/${name}` : name;
|
|
12204
|
+
if (omittedRoots.includes(child2))
|
|
11958
12205
|
continue;
|
|
11959
|
-
|
|
11960
|
-
const stat = lstatSync5(
|
|
11961
|
-
|
|
12206
|
+
need3(child2.length <= AGENT_POLICY_LIMITS.pathCharacters, "Native discovery directory path limit exceeded");
|
|
12207
|
+
const stat = lstatSync5(child2);
|
|
12208
|
+
need3(stat.isFile() || stat.isDirectory(), "Refusing symlink or special native discovery directory member");
|
|
11962
12209
|
const row = JSON.stringify([childRelative, stat.isDirectory() ? "directory" : "file"]) + `
|
|
11963
12210
|
`;
|
|
11964
12211
|
budget2.bytes += Buffer.byteLength(row);
|
|
11965
|
-
|
|
12212
|
+
need3(budget2.bytes <= AGENT_POLICY_LIMITS.discoveryDirectoryBytes, "Native discovery directory metadata limit exceeded");
|
|
11966
12213
|
hash.update(row);
|
|
11967
12214
|
rows?.push(row);
|
|
11968
|
-
if (stat.isDirectory() && !excludedRoots.includes(
|
|
11969
|
-
walk(
|
|
12215
|
+
if (stat.isDirectory() && !excludedRoots.includes(child2))
|
|
12216
|
+
walk(child2, childRelative, stat, depth + 1);
|
|
11970
12217
|
}
|
|
11971
|
-
|
|
12218
|
+
need3(same(before, lstatSync5(current2, { throwIfNoEntry: false })), "Native discovery directory changed while reading");
|
|
11972
12219
|
}
|
|
11973
12220
|
walk(path, "", root, 0);
|
|
11974
12221
|
safe(path);
|
|
11975
12222
|
return { path, sha256: hash.digest("hex") };
|
|
11976
12223
|
}
|
|
11977
12224
|
function captureDiscoveryDirectoryProjection(paths, omittedRoots) {
|
|
11978
|
-
|
|
11979
|
-
|
|
12225
|
+
need3(Array.isArray(paths) && paths.length <= AGENT_POLICY_LIMITS.discoveryDirectories && new Set(paths).size === paths.length, "Invalid projected discovery directory collection");
|
|
12226
|
+
need3(omittedRoots.length <= AGENT_POLICY_LIMITS.discoveryRoots && new Set(omittedRoots).size === omittedRoots.length, "Invalid inactive discovery roots");
|
|
11980
12227
|
for (const root of omittedRoots)
|
|
11981
12228
|
safe(root);
|
|
11982
12229
|
const budget2 = { entries: 0, bytes: 0 };
|
|
@@ -11986,57 +12233,57 @@ function captureDiscoveryDirectoryProjection(paths, omittedRoots) {
|
|
|
11986
12233
|
});
|
|
11987
12234
|
}
|
|
11988
12235
|
function verifyDiscoveryDirectoryProjection(directories, omittedRoots) {
|
|
11989
|
-
|
|
12236
|
+
need3(directories.length <= AGENT_POLICY_LIMITS.discoveryDirectories, "Invalid projected discovery directory collection");
|
|
11990
12237
|
let count = 0, bytes = 0;
|
|
11991
12238
|
const expected = directories.map((directory) => {
|
|
11992
12239
|
safe(directory.path);
|
|
11993
|
-
|
|
11994
|
-
const hash =
|
|
12240
|
+
need3(Array.isArray(directory.entries), "Missing reviewed directory membership inventory");
|
|
12241
|
+
const hash = createHash52("sha256");
|
|
11995
12242
|
const kept = [];
|
|
11996
12243
|
for (const row of directory.entries) {
|
|
11997
|
-
|
|
12244
|
+
need3(typeof row === "string" && ++count <= AGENT_POLICY_LIMITS.discoveryDirectoryEntries, "Invalid reviewed directory membership rows");
|
|
11998
12245
|
bytes += Buffer.byteLength(row);
|
|
11999
|
-
|
|
12246
|
+
need3(bytes <= AGENT_POLICY_LIMITS.discoveryDirectoryBytes, "Reviewed directory membership byte limit exceeded");
|
|
12000
12247
|
const value = JSON.parse(row);
|
|
12001
|
-
|
|
12248
|
+
need3(Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0] && !isAbsolute6(value[0]) && !value[0].split("/").some((part) => !part || part === "." || part === "..") && ["file", "directory"].includes(value[1]) && row === JSON.stringify(value) + `
|
|
12002
12249
|
`, "Invalid reviewed directory member");
|
|
12003
12250
|
hash.update(row);
|
|
12004
12251
|
const path = join92(directory.path, value[0]);
|
|
12005
12252
|
if (!omittedRoots.some((root) => path === root || path.startsWith(root + "/")))
|
|
12006
12253
|
kept.push(row);
|
|
12007
12254
|
}
|
|
12008
|
-
|
|
12255
|
+
need3(directory.sha256 === null ? directory.entries.length === 0 : hash.digest("hex") === directory.sha256, "Reviewed directory inventory does not match its fingerprint");
|
|
12009
12256
|
const absent = omittedRoots.some((root) => directory.path === root || directory.path.startsWith(root + "/"));
|
|
12010
|
-
return { path: directory.path, sha256: absent || directory.sha256 === null ? null :
|
|
12257
|
+
return { path: directory.path, sha256: absent || directory.sha256 === null ? null : createHash52("sha256").update(kept.join("")).digest("hex") };
|
|
12011
12258
|
});
|
|
12012
12259
|
const current2 = captureDiscoveryDirectoryProjection(directories.map((item) => item.path), omittedRoots);
|
|
12013
|
-
|
|
12260
|
+
need3(current2.every((item, index) => item.sha256 === expected[index].sha256), "Native discovery directory membership changed outside retired Codex roots");
|
|
12014
12261
|
}
|
|
12015
12262
|
function captureDiscoveryDirectories(paths, excludedRoots = []) {
|
|
12016
|
-
|
|
12263
|
+
need3(Array.isArray(paths) && paths.length <= AGENT_POLICY_LIMITS.discoveryDirectories && new Set(paths).size === paths.length, "Invalid native discovery directory collection");
|
|
12017
12264
|
const budget2 = { entries: 0, bytes: 0 };
|
|
12018
12265
|
for (const root of excludedRoots)
|
|
12019
12266
|
safe(root);
|
|
12020
12267
|
return paths.map((path) => capture(path, budget2, excludedRoots));
|
|
12021
12268
|
}
|
|
12022
12269
|
function verifyDiscoveryDirectories(directories, excludedRoots = []) {
|
|
12023
|
-
|
|
12270
|
+
need3(Array.isArray(directories) && directories.length <= AGENT_POLICY_LIMITS.discoveryDirectories, "Invalid native discovery directory collection");
|
|
12024
12271
|
for (const directory of directories)
|
|
12025
|
-
|
|
12272
|
+
need3(directory && typeof directory === "object" && (directory.sha256 === null || typeof directory.sha256 === "string" && /^[a-f0-9]{64}$/.test(directory.sha256)), "Invalid native discovery directory digest");
|
|
12026
12273
|
const current2 = captureDiscoveryDirectories(directories.map((directory) => directory.path), excludedRoots);
|
|
12027
12274
|
for (let i = 0;i < directories.length; i++)
|
|
12028
|
-
|
|
12275
|
+
need3(current2[i].sha256 === directories[i].sha256, `Native discovery directory membership changed; run skills hook install with a fresh discovery review: ${directories[i].path}`);
|
|
12029
12276
|
}
|
|
12030
12277
|
function discoveryByteBudget() {
|
|
12031
12278
|
return { remaining: AGENT_POLICY_LIMITS.discoveryRawTotalBytes };
|
|
12032
12279
|
}
|
|
12033
12280
|
function safe2(path) {
|
|
12034
|
-
if (typeof path !== "string" || !
|
|
12281
|
+
if (typeof path !== "string" || !isAbsolute7(path) || path !== resolve7(path) || path.length > AGENT_POLICY_LIMITS.pathCharacters || path.includes("\x00"))
|
|
12035
12282
|
throw new Error("Expected a canonical absolute raw discovery path");
|
|
12036
|
-
for (let cursor = path;; cursor =
|
|
12283
|
+
for (let cursor = path;; cursor = dirname7(cursor)) {
|
|
12037
12284
|
if (lstatSync6(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
12038
12285
|
throw new Error("Refusing symlink raw discovery input");
|
|
12039
|
-
if (
|
|
12286
|
+
if (dirname7(cursor) === cursor)
|
|
12040
12287
|
break;
|
|
12041
12288
|
}
|
|
12042
12289
|
}
|
|
@@ -12055,7 +12302,7 @@ function hashRawDiscoveryFile(path, budget2, changes) {
|
|
|
12055
12302
|
if (bytes > AGENT_POLICY_LIMITS.discoveryRawSourceBytes)
|
|
12056
12303
|
throw new Error("Raw discovery file byte limit exceeded");
|
|
12057
12304
|
consume(budget2, bytes);
|
|
12058
|
-
return
|
|
12305
|
+
return createHash62("sha256").update(text2).digest("hex");
|
|
12059
12306
|
}
|
|
12060
12307
|
const initial = lstatSync6(path, { throwIfNoEntry: false });
|
|
12061
12308
|
if (!initial)
|
|
@@ -12069,7 +12316,7 @@ function hashRawDiscoveryFile(path, budget2, changes) {
|
|
|
12069
12316
|
const opened = fstatSync22(fd);
|
|
12070
12317
|
if (!opened.isFile() || !same2(initial, opened))
|
|
12071
12318
|
throw new Error("Raw discovery input changed during open");
|
|
12072
|
-
const hash =
|
|
12319
|
+
const hash = createHash62("sha256"), buffer = Buffer.alloc(64 * 1024);
|
|
12073
12320
|
let bytes = 0;
|
|
12074
12321
|
while (true) {
|
|
12075
12322
|
const count = readSync2(fd, buffer, 0, Math.min(buffer.length, AGENT_POLICY_LIMITS.discoveryRawSourceBytes - bytes + 1), null);
|
|
@@ -12100,12 +12347,12 @@ function identity2(stat, mutable = false) {
|
|
|
12100
12347
|
...mutable ? { size: String(stat.size), mtimeNs: String(stat.mtimeNs), ctimeNs: String(stat.ctimeNs) } : {}
|
|
12101
12348
|
};
|
|
12102
12349
|
}
|
|
12103
|
-
function
|
|
12104
|
-
if (typeof path !== "string" || !
|
|
12350
|
+
function canonical3(path) {
|
|
12351
|
+
if (typeof path !== "string" || !isAbsolute8(path) || path !== resolve8(path) || path.length > AGENT_POLICY_LIMITS.pathCharacters || path.includes("\x00") || Buffer.from(path).toString("utf8") !== path)
|
|
12105
12352
|
throw new Error("Expected a canonical absolute discovery path");
|
|
12106
12353
|
}
|
|
12107
12354
|
function trace(path) {
|
|
12108
|
-
|
|
12355
|
+
canonical3(path);
|
|
12109
12356
|
const rows = [], paths = [];
|
|
12110
12357
|
let metadataBytes = 0, steps = 0, links = 0, cursor = parse2(path).root, pending = path.slice(cursor.length).split(sep32);
|
|
12111
12358
|
function record2(path2, row) {
|
|
@@ -12130,7 +12377,7 @@ function trace(path) {
|
|
|
12130
12377
|
if (!component || component === ".")
|
|
12131
12378
|
continue;
|
|
12132
12379
|
if (component === "..") {
|
|
12133
|
-
cursor =
|
|
12380
|
+
cursor = dirname8(cursor);
|
|
12134
12381
|
continue;
|
|
12135
12382
|
}
|
|
12136
12383
|
const candidate = join102(cursor, component);
|
|
@@ -12150,11 +12397,11 @@ function trace(path) {
|
|
|
12150
12397
|
if (!target || target.includes("\x00") || Buffer.byteLength(target) > AGENT_POLICY_LIMITS.pathCharacters || !after.isSymbolicLink() || JSON.stringify(identity2(stat, true)) !== JSON.stringify(identity2(after, true)))
|
|
12151
12398
|
throw new Error("Discovery link changed during read");
|
|
12152
12399
|
record2(candidate, { type: "link", target, ...identity2(stat, true) });
|
|
12153
|
-
if (
|
|
12400
|
+
if (isAbsolute8(target)) {
|
|
12154
12401
|
cursor = parse2(target).root;
|
|
12155
12402
|
root();
|
|
12156
12403
|
}
|
|
12157
|
-
const remainder =
|
|
12404
|
+
const remainder = isAbsolute8(target) ? target.slice(parse2(target).root.length) : target;
|
|
12158
12405
|
pending = [...remainder.split(sep32), ...pending];
|
|
12159
12406
|
if (pending.length + steps > AGENT_POLICY_LIMITS.discoveryPathSteps)
|
|
12160
12407
|
throw new Error("Discovery path step limit exceeded");
|
|
@@ -12197,12 +12444,12 @@ function hashDiscoveryPathFile(path, budget2, changes) {
|
|
|
12197
12444
|
const after = trace(path);
|
|
12198
12445
|
if (JSON.stringify(before.rows) !== JSON.stringify(after.rows) || before.file !== after.file)
|
|
12199
12446
|
throw new Error("Discovery path input changed during read");
|
|
12200
|
-
return
|
|
12447
|
+
return createHash7("sha256").update(JSON.stringify({ version: 1, path, rows: before.rows, content })).digest("hex");
|
|
12201
12448
|
}
|
|
12202
12449
|
var CLAUDE_PLUGIN_MANIFEST_LIMITS = Object.freeze({ bytes: 1024 * 1024, depth: 32, nodes: 65536, stringCharacters: 16384 });
|
|
12203
|
-
function requireValue(value,
|
|
12450
|
+
function requireValue(value, reason2) {
|
|
12204
12451
|
if (!value)
|
|
12205
|
-
throw new Error("Claude plugin manifest " +
|
|
12452
|
+
throw new Error("Claude plugin manifest " + reason2);
|
|
12206
12453
|
}
|
|
12207
12454
|
function parse32(text2) {
|
|
12208
12455
|
requireValue(Buffer.byteLength(text2, "utf8") <= CLAUDE_PLUGIN_MANIFEST_LIMITS.bytes, "exceeds its byte limit");
|
|
@@ -12278,7 +12525,7 @@ function parse32(text2) {
|
|
|
12278
12525
|
requireValue(at === text2.length && root.kind === "object", "requires a JSON object without trailing content");
|
|
12279
12526
|
return root;
|
|
12280
12527
|
}
|
|
12281
|
-
function
|
|
12528
|
+
function canonical4(value) {
|
|
12282
12529
|
if (value.kind === "string")
|
|
12283
12530
|
return JSON.stringify(value.value);
|
|
12284
12531
|
if (value.kind === "number")
|
|
@@ -12286,19 +12533,19 @@ function canonical3(value) {
|
|
|
12286
12533
|
if (value.kind === "literal")
|
|
12287
12534
|
return value.value;
|
|
12288
12535
|
if (value.kind === "array")
|
|
12289
|
-
return "[" + value.items.map(
|
|
12290
|
-
return "{" + value.entries.map(([key, item]) => JSON.stringify(key) + ":" +
|
|
12536
|
+
return "[" + value.items.map(canonical4).join(",") + "]";
|
|
12537
|
+
return "{" + value.entries.map(([key, item]) => JSON.stringify(key) + ":" + canonical4(item)).join(",") + "}";
|
|
12291
12538
|
}
|
|
12292
12539
|
var DESCRIPTIVE_FIELDS = new Set(["description", "version", "author", "homepage", "repository", "license", "keywords"]);
|
|
12293
|
-
function validateText(value,
|
|
12294
|
-
requireValue(value?.kind === "string" && value.value.length <= CLAUDE_PLUGIN_MANIFEST_LIMITS.stringCharacters, "has an invalid " +
|
|
12540
|
+
function validateText(value, field2) {
|
|
12541
|
+
requireValue(value?.kind === "string" && value.value.length <= CLAUDE_PLUGIN_MANIFEST_LIMITS.stringCharacters, "has an invalid " + field2 + " field");
|
|
12295
12542
|
}
|
|
12296
12543
|
function validateDescriptiveFields(manifest) {
|
|
12297
12544
|
const values = new Map(manifest.entries);
|
|
12298
|
-
for (const
|
|
12299
|
-
const value = values.get(
|
|
12545
|
+
for (const field2 of ["description", "version", "homepage", "license"]) {
|
|
12546
|
+
const value = values.get(field2);
|
|
12300
12547
|
if (value !== undefined)
|
|
12301
|
-
validateText(value,
|
|
12548
|
+
validateText(value, field2);
|
|
12302
12549
|
}
|
|
12303
12550
|
const author = values.get("author");
|
|
12304
12551
|
if (author !== undefined) {
|
|
@@ -12323,10 +12570,10 @@ function hashClaudePluginManifest(text2) {
|
|
|
12323
12570
|
const manifest = parse32(text2);
|
|
12324
12571
|
validateDescriptiveFields(manifest);
|
|
12325
12572
|
const discovery = { kind: "object", entries: manifest.entries.filter(([key]) => !DESCRIPTIVE_FIELDS.has(key)) };
|
|
12326
|
-
return
|
|
12573
|
+
return createHash8("sha256").update(canonical4(discovery)).digest("hex");
|
|
12327
12574
|
}
|
|
12328
12575
|
function projectReviewedClaudePluginManifest(text2, reviewedSha256) {
|
|
12329
|
-
if (!/^[a-f0-9]{64}$/.test(reviewedSha256) ||
|
|
12576
|
+
if (!/^[a-f0-9]{64}$/.test(reviewedSha256) || createHash8("sha256").update(text2).digest("hex") !== reviewedSha256) {
|
|
12330
12577
|
throw new Error("Reviewed Claude plugin manifest changed before semantic projection");
|
|
12331
12578
|
}
|
|
12332
12579
|
return hashClaudePluginManifest(text2);
|
|
@@ -12582,8 +12829,8 @@ class BoundedTarReader {
|
|
|
12582
12829
|
}
|
|
12583
12830
|
}
|
|
12584
12831
|
}
|
|
12585
|
-
function tarOctal(
|
|
12586
|
-
const text2 = new TextDecoder().decode(
|
|
12832
|
+
function tarOctal(field2) {
|
|
12833
|
+
const text2 = new TextDecoder().decode(field2);
|
|
12587
12834
|
if (!/^[0-7]+[\0 ]*$/.test(text2))
|
|
12588
12835
|
invalidBundle("Invalid tar octal field");
|
|
12589
12836
|
const value = Number.parseInt(text2, 8);
|
|
@@ -12621,8 +12868,8 @@ function profileDocumentBytes(value) {
|
|
|
12621
12868
|
}
|
|
12622
12869
|
class SkillSelectionError extends Error {
|
|
12623
12870
|
code;
|
|
12624
|
-
constructor(code, message) {
|
|
12625
|
-
super(message);
|
|
12871
|
+
constructor(code, message, options) {
|
|
12872
|
+
super(message, options);
|
|
12626
12873
|
this.code = code;
|
|
12627
12874
|
this.name = "SkillSelectionError";
|
|
12628
12875
|
}
|
|
@@ -12663,7 +12910,7 @@ function validateResolvedProfile(profile, authority) {
|
|
|
12663
12910
|
}
|
|
12664
12911
|
var package_default = {
|
|
12665
12912
|
name: "@hasna/skills",
|
|
12666
|
-
version: "0.10.
|
|
12913
|
+
version: "0.10.53",
|
|
12667
12914
|
description: "Skills library for AI coding agents",
|
|
12668
12915
|
type: "module",
|
|
12669
12916
|
bin: {
|
|
@@ -12877,11 +13124,11 @@ var fail = () => {
|
|
|
12877
13124
|
};
|
|
12878
13125
|
function physicalTarget(path) {
|
|
12879
13126
|
const suffix = [];
|
|
12880
|
-
for (let cursor = path;; cursor =
|
|
13127
|
+
for (let cursor = path;; cursor = dirname11(cursor)) {
|
|
12881
13128
|
try {
|
|
12882
13129
|
return join15(realpathSync32(cursor), ...suffix);
|
|
12883
13130
|
} catch (error) {
|
|
12884
|
-
if (error.code !== "ENOENT" || cursor ===
|
|
13131
|
+
if (error.code !== "ENOENT" || cursor === dirname11(cursor))
|
|
12885
13132
|
throw error;
|
|
12886
13133
|
try {
|
|
12887
13134
|
if (lstatSync12(cursor).isSymbolicLink())
|
|
@@ -12890,14 +13137,14 @@ function physicalTarget(path) {
|
|
|
12890
13137
|
if (statError.code !== "ENOENT")
|
|
12891
13138
|
throw statError;
|
|
12892
13139
|
}
|
|
12893
|
-
suffix.unshift(
|
|
13140
|
+
suffix.unshift(basename6(cursor));
|
|
12894
13141
|
}
|
|
12895
13142
|
}
|
|
12896
13143
|
}
|
|
12897
13144
|
function codexCorpusRootForPath(path) {
|
|
12898
|
-
const target =
|
|
13145
|
+
const target = resolve10(path), physical = physicalTarget(target);
|
|
12899
13146
|
const selected = process.env.CODEX_HOME;
|
|
12900
|
-
const selectedRoots = selected &&
|
|
13147
|
+
const selectedRoots = selected && isAbsolute10(selected) ? [resolve10(selected), physicalTarget(resolve10(selected))] : [];
|
|
12901
13148
|
const classify = (candidate) => {
|
|
12902
13149
|
const checked = (root2) => {
|
|
12903
13150
|
if (candidate === root2 || candidate === join15(root2, `${KEY}.flock-v1`))
|
|
@@ -12906,10 +13153,10 @@ function codexCorpusRootForPath(path) {
|
|
|
12906
13153
|
};
|
|
12907
13154
|
for (const root2 of selectedRoots) {
|
|
12908
13155
|
const distance = relative4(root2, candidate);
|
|
12909
|
-
if (distance === "" || !distance.startsWith(`..${sep5}`) && distance !== ".." && !
|
|
13156
|
+
if (distance === "" || !distance.startsWith(`..${sep5}`) && distance !== ".." && !isAbsolute10(distance))
|
|
12910
13157
|
return checked(root2);
|
|
12911
13158
|
}
|
|
12912
|
-
for (let cursor = candidate;cursor !==
|
|
13159
|
+
for (let cursor = candidate;cursor !== dirname11(cursor); cursor = dirname11(cursor)) {
|
|
12913
13160
|
if (cursor.endsWith(`${sep5}.codex`))
|
|
12914
13161
|
return checked(cursor);
|
|
12915
13162
|
}
|
|
@@ -12935,10 +13182,10 @@ function executable(options) {
|
|
|
12935
13182
|
if (typeof command !== "string" || !command || command.includes("\x00") || options.codexSha256 !== undefined && !/^[a-f0-9]{64}$/.test(options.codexSha256))
|
|
12936
13183
|
return fail();
|
|
12937
13184
|
let found;
|
|
12938
|
-
if (
|
|
13185
|
+
if (isAbsolute10(command))
|
|
12939
13186
|
found = command;
|
|
12940
13187
|
else if (!command.includes(sep5)) {
|
|
12941
|
-
found = (process.env.PATH ?? "").split(delimiter).filter(
|
|
13188
|
+
found = (process.env.PATH ?? "").split(delimiter).filter(isAbsolute10).map((dir) => join15(dir, command)).find((candidate) => {
|
|
12942
13189
|
try {
|
|
12943
13190
|
accessSync(candidate, constants6.X_OK);
|
|
12944
13191
|
return true;
|
|
@@ -12952,7 +13199,7 @@ function executable(options) {
|
|
|
12952
13199
|
const path = realpathSync32(found), initial = statSync7(path, { bigint: true });
|
|
12953
13200
|
if (!initial.isFile() || (initial.mode & 0o022n) !== 0n || (initial.mode & 0o111n) === 0n || initial.uid !== BigInt(process.getuid()) && initial.uid !== 0n)
|
|
12954
13201
|
return fail();
|
|
12955
|
-
const hash2 = () =>
|
|
13202
|
+
const hash2 = () => createHash12("sha256").update(readFileSync11(path)).digest("hex");
|
|
12956
13203
|
const digest = hash2();
|
|
12957
13204
|
if (options.codexSha256 && digest !== options.codexSha256)
|
|
12958
13205
|
return fail();
|
|
@@ -12976,7 +13223,7 @@ function acquireCodexCorpusWrite(roots, options) {
|
|
|
12976
13223
|
}
|
|
12977
13224
|
};
|
|
12978
13225
|
try {
|
|
12979
|
-
if (roots.some((root) => typeof root !== "string" || !
|
|
13226
|
+
if (roots.some((root) => typeof root !== "string" || !isAbsolute10(root) || root.includes("\x00")))
|
|
12980
13227
|
fail();
|
|
12981
13228
|
const inputs = [...new Set(roots)].map((input) => ({ input, root: realpathSync32(input) })).sort((a, b) => a.root.localeCompare(b.root));
|
|
12982
13229
|
for (const { input, root } of inputs) {
|
|
@@ -13089,23 +13336,6 @@ function isCodexLocalStdioMcpServer(name, server) {
|
|
|
13089
13336
|
return false;
|
|
13090
13337
|
}
|
|
13091
13338
|
}
|
|
13092
|
-
var MEASURED_CODEX_CAPABILITIES = {
|
|
13093
|
-
"codex-cli 0.153.0": ["hooks"],
|
|
13094
|
-
"codex-cli 0.154.0": ["hooks"],
|
|
13095
|
-
"codex-cli 0.155.0": ["hooks"],
|
|
13096
|
-
"codex-cli 0.155.1": ["hooks"],
|
|
13097
|
-
"codex-cli 0.156.1": ["hooks"],
|
|
13098
|
-
"codex-cli 0.157.0": ["hooks"],
|
|
13099
|
-
"codex-cli 0.157.1": ["hooks"],
|
|
13100
|
-
"codex-cli 0.158.0": ["hooks"],
|
|
13101
|
-
"codex-cli 0.159.0": ["hooks"],
|
|
13102
|
-
"codex-cli 0.159.2": ["hooks", "qualified-skill-catalog"],
|
|
13103
|
-
"codex-cli 0.160.0": ["hooks", "qualified-skill-catalog"]
|
|
13104
|
-
};
|
|
13105
|
-
function supportsCodexNativeCapability(version, capability) {
|
|
13106
|
-
return typeof version === "string" && Object.hasOwn(MEASURED_CODEX_CAPABILITIES, version) && MEASURED_CODEX_CAPABILITIES[version].includes(capability);
|
|
13107
|
-
}
|
|
13108
|
-
var SUPPORTED_CODEX_HOOK_VERSIONS = Object.freeze(Object.keys(MEASURED_CODEX_CAPABILITIES).filter((version) => supportsCodexNativeCapability(version, "hooks")));
|
|
13109
13339
|
function codexPluginSourceIsConfigControlled(plugin) {
|
|
13110
13340
|
const remoteRealms = ["openai-curated-remote", "created-by-me-remote", "workspace-directory", "workspace-shared-with-me", "workspace-shared-with-me-private", "workspace-shared-with-me-unlisted"];
|
|
13111
13341
|
return Boolean(plugin.sourceType && ["local", "git", "npm"].includes(plugin.sourceType) && plugin.sourceSha256 && /^[a-f0-9]{64}$/.test(plugin.sourceSha256) && !plugin.remotePluginId && !remoteRealms.includes(plugin.id.slice(plugin.id.lastIndexOf("@") + 1)));
|
|
@@ -13119,7 +13349,7 @@ function refuse() {
|
|
|
13119
13349
|
var object4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13120
13350
|
var scalar = (value, max) => typeof value === "string" && value.length > 0 && value.trim() === value && Buffer.byteLength(value, "utf8") <= max && !/[\u0000-\u001f\u007f]/u.test(value);
|
|
13121
13351
|
var remotePluginIdentifier = (value) => typeof value === "string" && /^[A-Za-z0-9_~-]{1,1024}$/.test(value);
|
|
13122
|
-
var absolutePath2 = (value) => scalar(value, MAX_PATH_BYTES) &&
|
|
13352
|
+
var absolutePath2 = (value) => scalar(value, MAX_PATH_BYTES) && isAbsolute12(value);
|
|
13123
13353
|
function canonicalPath(path) {
|
|
13124
13354
|
try {
|
|
13125
13355
|
return realpathSync5(path);
|
|
@@ -13221,7 +13451,7 @@ function mcpControls(path, read2) {
|
|
|
13221
13451
|
function isBundledCleanupHooks(root, namespace, value) {
|
|
13222
13452
|
const object5 = (v) => Boolean(v && typeof v === "object" && !Array.isArray(v));
|
|
13223
13453
|
const exactKeys = (v, keys) => Object.keys(v).length === keys.length && keys.every((key) => Object.hasOwn(v, key));
|
|
13224
|
-
if (
|
|
13454
|
+
if (basename7(dirname12(root)) !== namespace || basename7(dirname12(dirname12(root))) !== "openai-bundled")
|
|
13225
13455
|
return false;
|
|
13226
13456
|
const server = namespace === "unified-computer-use" ? "cua_repl" : ["browser", "chrome", "chrome-dev", "chrome-internal", "computer-use"].includes(namespace) ? "node_repl" : undefined;
|
|
13227
13457
|
if (!server || !object5(value) || !exactKeys(value, ["hooks"]) || !object5(value.hooks))
|
|
@@ -13255,7 +13485,7 @@ function rootControls(root, read2) {
|
|
|
13255
13485
|
}
|
|
13256
13486
|
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || !identifier2(manifest.name))
|
|
13257
13487
|
refuse2();
|
|
13258
|
-
const cacheVersion =
|
|
13488
|
+
const cacheVersion = basename7(root), declaredVersion = manifest.version === undefined ? "" : typeof manifest.version === "string" ? manifest.version.trim() : null;
|
|
13259
13489
|
if (declaredVersion === null || (declaredVersion ? declaredVersion !== cacheVersion : cacheVersion !== CODEX_DEFAULT_AGENT_PLUGIN_VERSION))
|
|
13260
13490
|
refuse2();
|
|
13261
13491
|
if (manifest.hooks !== undefined && !isBundledCleanupHooks(root, manifest.name, manifest.hooks) || manifest.commands !== undefined || manifest.mcpServers !== undefined && manifest.mcpServers !== "./.mcp.json" || manifest.apps !== undefined && manifest.apps !== "./.app.json" || lstatSync13(join17(root, "hooks"), { throwIfNoEntry: false }))
|
|
@@ -13300,7 +13530,7 @@ function documentIdentity(document2, cache, read2) {
|
|
|
13300
13530
|
}
|
|
13301
13531
|
if (!front || typeof front !== "object" || !identifier2(front.name) || typeof front.description !== "string" || !front.description.trim())
|
|
13302
13532
|
refuse2();
|
|
13303
|
-
for (let root =
|
|
13533
|
+
for (let root = dirname12(document2), depth = 0;root.startsWith(cache + sep6) && depth < 12; root = dirname12(root), depth++) {
|
|
13304
13534
|
const path = join17(root, ".codex-plugin", "plugin.json");
|
|
13305
13535
|
if (!lstatSync13(path, { throwIfNoEntry: false }))
|
|
13306
13536
|
continue;
|
|
@@ -13318,9 +13548,9 @@ function documentIdentity(document2, cache, read2) {
|
|
|
13318
13548
|
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || !identifier2(manifest.name))
|
|
13319
13549
|
refuse2();
|
|
13320
13550
|
const declaredVersion = manifest.version === undefined ? "" : typeof manifest.version === "string" ? manifest.version.trim() : null;
|
|
13321
|
-
if (declaredVersion === null || (declaredVersion ? declaredVersion !==
|
|
13551
|
+
if (declaredVersion === null || (declaredVersion ? declaredVersion !== basename7(root) : basename7(root) !== CODEX_DEFAULT_AGENT_PLUGIN_VERSION))
|
|
13322
13552
|
refuse2();
|
|
13323
|
-
return { name: `${manifest.name}:${front.name}`, namespace: manifest.name, pluginParent:
|
|
13553
|
+
return { name: `${manifest.name}:${front.name}`, namespace: manifest.name, pluginParent: dirname12(root), root };
|
|
13324
13554
|
}
|
|
13325
13555
|
refuse2();
|
|
13326
13556
|
}
|
|
@@ -13349,13 +13579,13 @@ function classifyCodexPluginCacheDocument(document2, cache, read2) {
|
|
|
13349
13579
|
function reviewedDisabledCodexPluginParent(cache, parent, controls, rules) {
|
|
13350
13580
|
try {
|
|
13351
13581
|
const parts = relative5(cache, parent).split(sep6), enrolled = controls.filter((control) => control.pluginParent === parent);
|
|
13352
|
-
if (
|
|
13582
|
+
if (resolve11(parent) !== parent || parts.length !== 2 || parts.some((part) => !identifier2(part)) || !enrolled.length || !Array.isArray(rules))
|
|
13353
13583
|
return false;
|
|
13354
|
-
for (let cursor = parent;; cursor =
|
|
13584
|
+
for (let cursor = parent;; cursor = dirname12(cursor)) {
|
|
13355
13585
|
const stat = lstatSync13(cursor, { throwIfNoEntry: false });
|
|
13356
13586
|
if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
|
|
13357
13587
|
return false;
|
|
13358
|
-
if (
|
|
13588
|
+
if (dirname12(cursor) === cursor)
|
|
13359
13589
|
break;
|
|
13360
13590
|
}
|
|
13361
13591
|
return enrolled.every((control) => control.namespace === parts[1] && control.pluginId === `${parts[1]}@${parts[0]}` && remotePluginIdentifier(control.remotePluginId) && control.skillsOnly === true && !control.appSha256 && !control.mcpSha256 && control.name.startsWith(control.namespace + ":") && /^[a-f0-9]{64}$/.test(control.manifestSha256) && rules.some((rule) => typeof rule?.name === "string" && rule.name.trim() === control.name && rule.enabled === false) && !rules.some((rule) => (typeof rule?.name === "string" && rule.name.trim() === control.name || typeof rule?.path === "string" && (rule.path === parent || rule.path.startsWith(parent + sep6))) && rule.enabled !== false));
|
|
@@ -13368,14 +13598,14 @@ function absentDisabledCodexPluginParent(cache, parent, controls, rules) {
|
|
|
13368
13598
|
}
|
|
13369
13599
|
function reviewedRetiredCodexRoot(cache, root, controls, rules, read2, allowAbsent = false) {
|
|
13370
13600
|
try {
|
|
13371
|
-
const parent =
|
|
13372
|
-
if (
|
|
13601
|
+
const parent = dirname12(root), parts = relative5(cache, parent).split(sep6), enrolled = controls.filter((control) => control.pluginParent === parent);
|
|
13602
|
+
if (resolve11(root) !== root || parts.length !== 2 || parts.some((part) => !identifier2(part)) || !basename7(root) || basename7(root) === "latest" || !enrolled.length || !Array.isArray(rules))
|
|
13373
13603
|
return false;
|
|
13374
|
-
for (let cursor = root;; cursor =
|
|
13604
|
+
for (let cursor = root;; cursor = dirname12(cursor)) {
|
|
13375
13605
|
const stat = lstatSync13(cursor, { throwIfNoEntry: false });
|
|
13376
13606
|
if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
|
|
13377
13607
|
return false;
|
|
13378
|
-
if (
|
|
13608
|
+
if (dirname12(cursor) === cursor)
|
|
13379
13609
|
break;
|
|
13380
13610
|
}
|
|
13381
13611
|
if (!enrolled.every((control) => control.namespace === parts[1] && control.pluginId === `${parts[1]}@${parts[0]}` && remotePluginIdentifier(control.remotePluginId) && control.skillsOnly === true && !control.appSha256 && !control.mcpSha256 && control.name.startsWith(control.namespace + ":") && /^[a-f0-9]{64}$/.test(control.manifestSha256) && rules.some((rule) => typeof rule?.name === "string" && rule.name.trim() === control.name && rule.enabled === false) && !rules.some((rule) => (typeof rule?.name === "string" && rule.name.trim() === control.name || typeof rule?.path === "string" && (rule.path === parent || rule.path === root || rule.path.startsWith(root + sep6))) && rule.enabled !== false)))
|
|
@@ -13422,8 +13652,8 @@ function reviewedCodexPluginCapabilitiesUnchanged(cache, controls, read2, rules)
|
|
|
13422
13652
|
for (const name of names) {
|
|
13423
13653
|
let root = join17(parent, name), stat = lstatSync13(root);
|
|
13424
13654
|
if (stat.isSymbolicLink()) {
|
|
13425
|
-
const target =
|
|
13426
|
-
if (name !== "latest" ||
|
|
13655
|
+
const target = resolve11(parent, readlinkSync3(root));
|
|
13656
|
+
if (name !== "latest" || dirname12(target) !== parent || !lstatSync13(target).isDirectory() || realpathSync6(target) !== target)
|
|
13427
13657
|
return false;
|
|
13428
13658
|
root = target;
|
|
13429
13659
|
stat = lstatSync13(root);
|
|
@@ -13443,7 +13673,7 @@ function reviewedCodexPluginCapabilitiesUnchanged(cache, controls, read2, rules)
|
|
|
13443
13673
|
function sourceInputUnchanged(input, cache, read2) {
|
|
13444
13674
|
try {
|
|
13445
13675
|
const parts = relative5(cache, input.pluginParent).split(sep6);
|
|
13446
|
-
if (parts.length !== 2 || parts.some((part) => !identifier2(part)) || parts[1] !== input.namespace || input.pluginId !== `${parts[1]}@${parts[0]}` || !codexPluginSourceIsConfigControlled({ id: input.pluginId, sourceType: "local", sourceSha256: input.sourceSha256 }) || input.sourceSha256 !== hashNativeJsonControls(JSON.stringify({ type: "local", path: input.sourceRoot })) ||
|
|
13676
|
+
if (parts.length !== 2 || parts.some((part) => !identifier2(part)) || parts[1] !== input.namespace || input.pluginId !== `${parts[1]}@${parts[0]}` || !codexPluginSourceIsConfigControlled({ id: input.pluginId, sourceType: "local", sourceSha256: input.sourceSha256 }) || input.sourceSha256 !== hashNativeJsonControls(JSON.stringify({ type: "local", path: input.sourceRoot })) || resolve11(input.sourceRoot) !== input.sourceRoot || !lstatSync13(input.sourceRoot).isDirectory() || realpathSync6(input.sourceRoot) !== input.sourceRoot || input.sourceRoot === cache || input.sourceRoot.startsWith(cache + sep6) || cache.startsWith(input.sourceRoot + sep6))
|
|
13447
13677
|
return false;
|
|
13448
13678
|
const path = join17(input.sourceRoot, ".codex-plugin/plugin.json"), stat = lstatSync13(path);
|
|
13449
13679
|
if (!stat.isFile() || stat.size > 1024 * 1024 || realpathSync6(path) !== path)
|
|
@@ -13514,9 +13744,9 @@ function refuse3(code, detail) {
|
|
|
13514
13744
|
throw new Error(`${code}: ${detail}`);
|
|
13515
13745
|
}
|
|
13516
13746
|
var object5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13517
|
-
function boundedId(value,
|
|
13747
|
+
function boundedId(value, field2) {
|
|
13518
13748
|
if (typeof value !== "string" || !value || value.length > MAX_ENVELOPE_ID_LENGTH || value.trim() !== value || /[\u0000-\u001f\u007f]/.test(value))
|
|
13519
|
-
refuse3("NATIVE_SKILL_POLICY_INVALID", `${
|
|
13749
|
+
refuse3("NATIVE_SKILL_POLICY_INVALID", `${field2} must be a bounded non-empty string`);
|
|
13520
13750
|
return value;
|
|
13521
13751
|
}
|
|
13522
13752
|
function parseCodexNativePolicyTrust(value) {
|
|
@@ -13539,9 +13769,9 @@ function parseCodexNativeHookEnvelope(envelope, bridgeDocument) {
|
|
|
13539
13769
|
if (!object5(value))
|
|
13540
13770
|
refuse3("NATIVE_SKILL_POLICY_INVALID", "native_skill_policy must be an object");
|
|
13541
13771
|
const keys = Object.keys(value);
|
|
13542
|
-
for (const
|
|
13543
|
-
if (!Object.hasOwn(value,
|
|
13544
|
-
refuse3("NATIVE_SKILL_POLICY_INVALID", `native_skill_policy.${
|
|
13772
|
+
for (const field2 of POLICY_FIELDS)
|
|
13773
|
+
if (!Object.hasOwn(value, field2))
|
|
13774
|
+
refuse3("NATIVE_SKILL_POLICY_INVALID", `native_skill_policy.${field2} is missing`);
|
|
13545
13775
|
if (keys.length !== POLICY_FIELDS.length)
|
|
13546
13776
|
refuse3("NATIVE_SKILL_POLICY_INVALID", "native_skill_policy carries unknown fields");
|
|
13547
13777
|
if (value.capability !== CODEX_NATIVE_POLICY_CAPABILITY)
|
|
@@ -13605,19 +13835,19 @@ function readBounded(path, maximum, what) {
|
|
|
13605
13835
|
}
|
|
13606
13836
|
}
|
|
13607
13837
|
function verifyCodexNativeBridgeDocument(path, expectedContent, expectedSha256) {
|
|
13608
|
-
if (!
|
|
13838
|
+
if (!isAbsolute13(path) || resolve12(path) !== path || !path.endsWith("/SKILL.md"))
|
|
13609
13839
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document path is not an exact absolute SKILL.md path");
|
|
13610
|
-
for (let cursor = path;; cursor =
|
|
13840
|
+
for (let cursor = path;; cursor = dirname13(cursor)) {
|
|
13611
13841
|
const stat = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13612
13842
|
if (!stat || stat.isSymbolicLink() || (cursor === path ? !stat.isFile() : !stat.isDirectory()))
|
|
13613
13843
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", `the bridge path has a missing, linked or unexpected component: ${cursor}`);
|
|
13614
|
-
if (
|
|
13844
|
+
if (dirname13(cursor) === cursor)
|
|
13615
13845
|
break;
|
|
13616
13846
|
}
|
|
13617
13847
|
if (realpathSync7.native(path) !== path)
|
|
13618
13848
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document real path differs from its lexical path");
|
|
13619
13849
|
const bytes = readBounded(path, MAX_BRIDGE_DOCUMENT_BYTES, "the bridge document");
|
|
13620
|
-
const sha2562 =
|
|
13850
|
+
const sha2562 = createHash14("sha256").update(bytes).digest("hex");
|
|
13621
13851
|
if (!bytes.equals(Buffer.from(expectedContent, "utf8")) || sha2562 !== expectedSha256)
|
|
13622
13852
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document bytes differ from the managed bridge");
|
|
13623
13853
|
return { path, sha256: sha2562 };
|
|
@@ -13683,13 +13913,13 @@ function assertExecutableWitnessStat(stat, currentUid) {
|
|
|
13683
13913
|
return { dev: String(stat.dev), ino: String(stat.ino), size: String(stat.size), mtimeNs: String(stat.mtimeNs), ctimeNs: String(stat.ctimeNs), uid: String(stat.uid) };
|
|
13684
13914
|
}
|
|
13685
13915
|
function executableWitness(path) {
|
|
13686
|
-
if (!
|
|
13916
|
+
if (!isAbsolute13(path) || resolve12(path) !== path)
|
|
13687
13917
|
refuse3("NATIVE_SKILL_POLICY_PROCESS_UNBOUND", "the consumer executable path is not an exact absolute path");
|
|
13688
|
-
for (let cursor =
|
|
13918
|
+
for (let cursor = dirname13(path);; cursor = dirname13(cursor)) {
|
|
13689
13919
|
const stat2 = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13690
13920
|
if (!stat2 || stat2.isSymbolicLink() || !stat2.isDirectory())
|
|
13691
13921
|
refuse3("NATIVE_SKILL_POLICY_PROCESS_UNBOUND", `the consumer executable path has a missing, linked or unexpected component: ${cursor}`);
|
|
13692
|
-
if (
|
|
13922
|
+
if (dirname13(cursor) === cursor)
|
|
13693
13923
|
break;
|
|
13694
13924
|
}
|
|
13695
13925
|
const stat = lstatSync14(path, { throwIfNoEntry: false, bigint: true });
|
|
@@ -13700,7 +13930,7 @@ function executableWitness(path) {
|
|
|
13700
13930
|
var witnessKey = (path, witness) => JSON.stringify([path, witness.dev, witness.ino, witness.size, witness.mtimeNs, witness.ctimeNs, witness.uid]);
|
|
13701
13931
|
var executableDigestMemory = new Map;
|
|
13702
13932
|
function executableCachePath(dataDir22) {
|
|
13703
|
-
return join18(
|
|
13933
|
+
return join18(resolve12(dataDir22), "agent-hooks", "codex-native-policy-executable-cache.json");
|
|
13704
13934
|
}
|
|
13705
13935
|
var currentUid = () => process.getuid?.() ?? -1;
|
|
13706
13936
|
function readTrustedCacheBytes(path, ownerUid) {
|
|
@@ -13745,16 +13975,16 @@ function readExecutableCache(dataDir22, ownerUid = currentUid()) {
|
|
|
13745
13975
|
if (!object5(value) || value.schema !== CODEX_NATIVE_POLICY_EXECUTABLE_CACHE_SCHEMA || !Array.isArray(value.entries) || value.entries.length > 16)
|
|
13746
13976
|
return [];
|
|
13747
13977
|
const fields = ["path", "sha256", "dev", "ino", "size", "mtimeNs", "ctimeNs", "uid"];
|
|
13748
|
-
return value.entries.filter((entry) => object5(entry) && Object.keys(entry).length === fields.length && fields.every((
|
|
13978
|
+
return value.entries.filter((entry) => object5(entry) && Object.keys(entry).length === fields.length && fields.every((field2) => typeof entry[field2] === "string") && HEX_DIGEST.test(entry.sha256) && isAbsolute13(entry.path) && ["dev", "ino", "size", "mtimeNs", "ctimeNs", "uid"].every((field2) => /^\d{1,30}$/.test(entry[field2])));
|
|
13749
13979
|
} catch {
|
|
13750
13980
|
return [];
|
|
13751
13981
|
}
|
|
13752
13982
|
}
|
|
13753
13983
|
function writeExecutableCache(dataDir22, entries) {
|
|
13754
|
-
const path = executableCachePath(dataDir22), directory =
|
|
13984
|
+
const path = executableCachePath(dataDir22), directory = dirname13(path), temporary = `${path}.skills-${randomUUID2()}`;
|
|
13755
13985
|
let descriptor;
|
|
13756
13986
|
try {
|
|
13757
|
-
const parent = lstatSync14(
|
|
13987
|
+
const parent = lstatSync14(dirname13(directory), { throwIfNoEntry: false });
|
|
13758
13988
|
if (!parent || parent.isSymbolicLink() || !parent.isDirectory())
|
|
13759
13989
|
return;
|
|
13760
13990
|
const existing = lstatSync14(directory, { throwIfNoEntry: false });
|
|
@@ -13822,16 +14052,16 @@ function verifyCodexNativeExecutable(inspector, processId, trust, cache = {}, ex
|
|
|
13822
14052
|
}
|
|
13823
14053
|
function assertOperatorTrustRoot(dataDir22) {
|
|
13824
14054
|
const check = (path, what, required) => {
|
|
13825
|
-
if (!
|
|
14055
|
+
if (!isAbsolute13(path) || resolve12(path) !== path)
|
|
13826
14056
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} path is not an exact absolute path`);
|
|
13827
|
-
for (let cursor =
|
|
14057
|
+
for (let cursor = dirname13(path);; cursor = dirname13(cursor)) {
|
|
13828
14058
|
const stat2 = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13829
14059
|
if (!stat2) {
|
|
13830
14060
|
if (required)
|
|
13831
14061
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} has a missing path component: ${cursor}`);
|
|
13832
14062
|
} else if (stat2.isSymbolicLink() || !stat2.isDirectory())
|
|
13833
14063
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} has a linked or unexpected path component: ${cursor}`);
|
|
13834
|
-
if (
|
|
14064
|
+
if (dirname13(cursor) === cursor)
|
|
13835
14065
|
break;
|
|
13836
14066
|
}
|
|
13837
14067
|
const stat = lstatSync14(path, { throwIfNoEntry: false, bigint: true });
|
|
@@ -13861,9 +14091,9 @@ function assertOperatorTrustRoot(dataDir22) {
|
|
|
13861
14091
|
if ((stat.mode & 0o022n) !== 0n)
|
|
13862
14092
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} is group- or world-writable`);
|
|
13863
14093
|
};
|
|
13864
|
-
checkDirectory(
|
|
13865
|
-
checkDirectory(
|
|
13866
|
-
check(join18(
|
|
14094
|
+
checkDirectory(resolve12(dataDir22), "the Skills data directory", true);
|
|
14095
|
+
checkDirectory(dirname13(executableCachePath(dataDir22)), "the agent-hooks directory", false);
|
|
14096
|
+
check(join18(resolve12(dataDir22), "agent-policy.json"), "the managed policy", true);
|
|
13867
14097
|
check(executableCachePath(dataDir22), "the executable identity cache", false);
|
|
13868
14098
|
}
|
|
13869
14099
|
function runCodexNativePolicyHelper(request) {
|
|
@@ -14034,12 +14264,12 @@ function defaultProcessInspector() {
|
|
|
14034
14264
|
return { platform: process.platform, arch: process.arch, pid: process.pid, parentOf: () => null, startTime: () => null, executablePath: () => null };
|
|
14035
14265
|
}
|
|
14036
14266
|
function codexNativePolicyReceiptPath(dataDir22) {
|
|
14037
|
-
return join18(
|
|
14267
|
+
return join18(resolve12(dataDir22), "agent-hooks", "codex-native-policy-acceptance.json");
|
|
14038
14268
|
}
|
|
14039
14269
|
function recordCodexNativePolicyAcceptance(dataDir22, verification, accepted) {
|
|
14040
|
-
const path = codexNativePolicyReceiptPath(dataDir22), directory =
|
|
14270
|
+
const path = codexNativePolicyReceiptPath(dataDir22), directory = dirname13(path);
|
|
14041
14271
|
const acceptedCache = accepted.map((entry) => ({ path: entry.path, treeSha256: entry.treeSha256 })).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
14042
|
-
if (acceptedCache.some((entry) => !
|
|
14272
|
+
if (acceptedCache.some((entry) => !isAbsolute13(entry.path) || !HEX_DIGEST.test(entry.treeSha256)) || new Set(acceptedCache.map((entry) => entry.path)).size !== acceptedCache.length)
|
|
14043
14273
|
refuse3("NATIVE_SKILL_POLICY_RECEIPT_FAILED", "accepted cache entries must be unique absolute paths with tree digests");
|
|
14044
14274
|
const value = {
|
|
14045
14275
|
schema: CODEX_NATIVE_POLICY_RECEIPT_SCHEMA,
|
|
@@ -14083,10 +14313,10 @@ function recordCodexNativePolicyAcceptance(dataDir22, verification, accepted) {
|
|
|
14083
14313
|
}
|
|
14084
14314
|
return path;
|
|
14085
14315
|
}
|
|
14086
|
-
var sha = (text2) =>
|
|
14316
|
+
var sha = (text2) => createHash15("sha256").update(text2).digest("hex");
|
|
14087
14317
|
var EFFORT = new Set(["none", "minimal", "low", "medium", "high", "xhigh"]);
|
|
14088
14318
|
var VERBOSITY = new Set(["low", "medium", "high"]);
|
|
14089
|
-
function
|
|
14319
|
+
function need4(value) {
|
|
14090
14320
|
if (!value)
|
|
14091
14321
|
throw new Error("Invalid Codex settings witness");
|
|
14092
14322
|
}
|
|
@@ -14101,14 +14331,14 @@ function numericTokens(text2) {
|
|
|
14101
14331
|
continue;
|
|
14102
14332
|
}
|
|
14103
14333
|
if (char === '"' || char === "'") {
|
|
14104
|
-
const
|
|
14334
|
+
const quote22 = char, triple = text2.slice(at, at + 3) === quote22.repeat(3);
|
|
14105
14335
|
at += triple ? 3 : 1;
|
|
14106
14336
|
while (at < text2.length) {
|
|
14107
|
-
if (
|
|
14337
|
+
if (quote22 === '"' && text2[at] === "\\") {
|
|
14108
14338
|
at += 2;
|
|
14109
14339
|
continue;
|
|
14110
14340
|
}
|
|
14111
|
-
if (text2.slice(at, at + (triple ? 3 : 1)) ===
|
|
14341
|
+
if (text2.slice(at, at + (triple ? 3 : 1)) === quote22.repeat(triple ? 3 : 1)) {
|
|
14112
14342
|
at += triple ? 3 : 1;
|
|
14113
14343
|
break;
|
|
14114
14344
|
}
|
|
@@ -14129,8 +14359,8 @@ function numericTokens(text2) {
|
|
|
14129
14359
|
}
|
|
14130
14360
|
return result;
|
|
14131
14361
|
}
|
|
14132
|
-
function
|
|
14133
|
-
|
|
14362
|
+
function canonical5(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
14363
|
+
need4(depth <= 32 && --budget2.remaining >= 0);
|
|
14134
14364
|
if (value === null)
|
|
14135
14365
|
return ["null"];
|
|
14136
14366
|
if (typeof value === "string")
|
|
@@ -14138,20 +14368,20 @@ function canonical4(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
|
14138
14368
|
if (typeof value === "boolean")
|
|
14139
14369
|
return ["boolean", value];
|
|
14140
14370
|
if (typeof value === "number") {
|
|
14141
|
-
|
|
14371
|
+
need4(Number.isFinite(value));
|
|
14142
14372
|
return ["number", String(value)];
|
|
14143
14373
|
}
|
|
14144
14374
|
if (value instanceof Date) {
|
|
14145
|
-
|
|
14375
|
+
need4(Number.isFinite(value.getTime()));
|
|
14146
14376
|
return ["date", value.toISOString()];
|
|
14147
14377
|
}
|
|
14148
14378
|
if (Array.isArray(value))
|
|
14149
|
-
return ["array", value.map((
|
|
14150
|
-
|
|
14151
|
-
return ["object", Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key,
|
|
14379
|
+
return ["array", value.map((child2) => canonical5(child2, depth + 1, budget2))];
|
|
14380
|
+
need4(value && typeof value === "object");
|
|
14381
|
+
return ["object", Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, child2]) => [key, canonical5(child2, depth + 1, budget2)])];
|
|
14152
14382
|
}
|
|
14153
14383
|
function hashCodexSettingsReplacement(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14154
|
-
|
|
14384
|
+
need4(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14155
14385
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14156
14386
|
let config;
|
|
14157
14387
|
try {
|
|
@@ -14159,17 +14389,17 @@ function hashCodexSettingsReplacement(text2, budget2 = { remaining: 256 * 1024 *
|
|
|
14159
14389
|
} catch {
|
|
14160
14390
|
throw new Error("Invalid Codex settings witness");
|
|
14161
14391
|
}
|
|
14162
|
-
|
|
14392
|
+
need4(config && typeof config === "object" && !Array.isArray(config));
|
|
14163
14393
|
if (Object.hasOwn(config, "model")) {
|
|
14164
|
-
|
|
14394
|
+
need4(typeof config.model === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(config.model));
|
|
14165
14395
|
delete config.model;
|
|
14166
14396
|
}
|
|
14167
14397
|
for (const [key, values] of [["model_reasoning_effort", EFFORT], ["model_verbosity", VERBOSITY]])
|
|
14168
14398
|
if (Object.hasOwn(config, key)) {
|
|
14169
|
-
|
|
14399
|
+
need4(typeof config[key] === "string" && values.has(config[key]));
|
|
14170
14400
|
delete config[key];
|
|
14171
14401
|
}
|
|
14172
|
-
return sha(`hasna.skills.codex-settings.v1\x00${JSON.stringify([
|
|
14402
|
+
return sha(`hasna.skills.codex-settings.v1\x00${JSON.stringify([canonical5(config), numericTokens(text2)])}`);
|
|
14173
14403
|
}
|
|
14174
14404
|
function captureCodexSettings(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14175
14405
|
const text2 = readNativeSettingsWitnessFile(path, budget2, "config.toml");
|
|
@@ -14236,13 +14466,13 @@ function projectRegularCodexMcp(config, source) {
|
|
|
14236
14466
|
}
|
|
14237
14467
|
return { config: expected, numericSource };
|
|
14238
14468
|
}
|
|
14239
|
-
var sha2 = (text2) =>
|
|
14469
|
+
var sha2 = (text2) => createHash16("sha256").update(text2).digest("hex");
|
|
14240
14470
|
var EFFORT2 = new Set(["none", "minimal", "low", "medium", "high", "xhigh"]);
|
|
14241
14471
|
var VERBOSITY2 = new Set(["low", "medium", "high"]);
|
|
14242
14472
|
var MODEL = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
14243
14473
|
var CODEX_DISCOVERY_PROJECTION_FIELDS = ["plugins", "marketplaces", "skills"];
|
|
14244
14474
|
var INFERENCE = ["model", "model_reasoning_effort", "model_verbosity"];
|
|
14245
|
-
function
|
|
14475
|
+
function need5(value) {
|
|
14246
14476
|
if (!value)
|
|
14247
14477
|
throw new Error("Invalid Codex settings witness");
|
|
14248
14478
|
}
|
|
@@ -14263,14 +14493,14 @@ function numericTokens2(text2) {
|
|
|
14263
14493
|
continue;
|
|
14264
14494
|
}
|
|
14265
14495
|
if (char === '"' || char === "'") {
|
|
14266
|
-
const
|
|
14496
|
+
const quote22 = char, triple = text2.slice(at, at + 3) === quote22.repeat(3);
|
|
14267
14497
|
at += triple ? 3 : 1;
|
|
14268
14498
|
while (at < text2.length) {
|
|
14269
|
-
if (
|
|
14499
|
+
if (quote22 === '"' && text2[at] === "\\") {
|
|
14270
14500
|
at += 2;
|
|
14271
14501
|
continue;
|
|
14272
14502
|
}
|
|
14273
|
-
if (text2.slice(at, at + (triple ? 3 : 1)) ===
|
|
14503
|
+
if (text2.slice(at, at + (triple ? 3 : 1)) === quote22.repeat(triple ? 3 : 1)) {
|
|
14274
14504
|
at += triple ? 3 : 1;
|
|
14275
14505
|
break;
|
|
14276
14506
|
}
|
|
@@ -14291,8 +14521,8 @@ function numericTokens2(text2) {
|
|
|
14291
14521
|
}
|
|
14292
14522
|
return result.sort();
|
|
14293
14523
|
}
|
|
14294
|
-
function
|
|
14295
|
-
|
|
14524
|
+
function canonical6(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
14525
|
+
need5(depth <= 32 && --budget2.remaining >= 0);
|
|
14296
14526
|
if (value === null)
|
|
14297
14527
|
return ["null"];
|
|
14298
14528
|
if (typeof value === "string")
|
|
@@ -14300,17 +14530,17 @@ function canonical5(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
|
14300
14530
|
if (typeof value === "boolean")
|
|
14301
14531
|
return ["boolean", value];
|
|
14302
14532
|
if (typeof value === "number") {
|
|
14303
|
-
|
|
14533
|
+
need5(Number.isFinite(value));
|
|
14304
14534
|
return ["number", String(value)];
|
|
14305
14535
|
}
|
|
14306
14536
|
if (isDate(value)) {
|
|
14307
|
-
|
|
14537
|
+
need5(Number.isFinite(value.getTime()));
|
|
14308
14538
|
return ["date", value.toISOString()];
|
|
14309
14539
|
}
|
|
14310
14540
|
if (Array.isArray(value))
|
|
14311
|
-
return ["array", value.map((
|
|
14312
|
-
|
|
14313
|
-
return ["object", Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key,
|
|
14541
|
+
return ["array", value.map((child2) => canonical6(child2, depth + 1, budget2))];
|
|
14542
|
+
need5(isRecord3(value));
|
|
14543
|
+
return ["object", Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, child2]) => [key, canonical6(child2, depth + 1, budget2)])];
|
|
14314
14544
|
}
|
|
14315
14545
|
function normalize3(config, version = 2) {
|
|
14316
14546
|
if (isRecord3(config.hooks)) {
|
|
@@ -14352,15 +14582,15 @@ function inference(target, version) {
|
|
|
14352
14582
|
if (Object.hasOwn(target, key)) {
|
|
14353
14583
|
const value = target[key];
|
|
14354
14584
|
if (key === "model")
|
|
14355
|
-
|
|
14585
|
+
need5(typeof value === "string" && MODEL.test(value));
|
|
14356
14586
|
else if (key === "personality")
|
|
14357
|
-
|
|
14587
|
+
need5(typeof value === "string" && ["none", "friendly", "pragmatic"].includes(value));
|
|
14358
14588
|
else if (version >= 3 && key !== "model_verbosity") {
|
|
14359
|
-
|
|
14589
|
+
need5(typeof value === "string" && value.length <= 128 && !/[\x00-\x1f\x7f]/.test(value));
|
|
14360
14590
|
if (key !== "service_tier")
|
|
14361
|
-
|
|
14591
|
+
need5(value.length > 0);
|
|
14362
14592
|
} else
|
|
14363
|
-
|
|
14593
|
+
need5(typeof value === "string" && (key === "model_reasoning_effort" ? EFFORT2.has(value) : VERBOSITY2.has(value)));
|
|
14364
14594
|
delete target[key];
|
|
14365
14595
|
}
|
|
14366
14596
|
}
|
|
@@ -14393,14 +14623,14 @@ function projectModelAvailabilityNux(config, text2) {
|
|
|
14393
14623
|
continue;
|
|
14394
14624
|
}
|
|
14395
14625
|
if (char === '"' || char === "'") {
|
|
14396
|
-
const
|
|
14626
|
+
const quote22 = char;
|
|
14397
14627
|
at++;
|
|
14398
14628
|
while (at < span.length) {
|
|
14399
|
-
if (
|
|
14629
|
+
if (quote22 === '"' && span[at] === "\\") {
|
|
14400
14630
|
at += 2;
|
|
14401
14631
|
continue;
|
|
14402
14632
|
}
|
|
14403
|
-
if (span[at++] ===
|
|
14633
|
+
if (span[at++] === quote22)
|
|
14404
14634
|
break;
|
|
14405
14635
|
}
|
|
14406
14636
|
continue;
|
|
@@ -14480,14 +14710,14 @@ function settingsDigest2(text2, version = 2) {
|
|
|
14480
14710
|
} catch {
|
|
14481
14711
|
throw new Error("Invalid Codex settings witness");
|
|
14482
14712
|
}
|
|
14483
|
-
|
|
14713
|
+
need5(isRecord3(config));
|
|
14484
14714
|
const mcp = version >= 3 ? projectRegularCodexMcp(config, text2) : { config, numericSource: text2 };
|
|
14485
14715
|
const projected = version === 4 ? projectModelAvailabilityNux(mcp.config, mcp.numericSource) : mcp;
|
|
14486
14716
|
normalize3(projected.config, version);
|
|
14487
|
-
return sha2(`hasna.skills.codex-settings.v${version}\x00${JSON.stringify([
|
|
14717
|
+
return sha2(`hasna.skills.codex-settings.v${version}\x00${JSON.stringify([canonical6(projected.config), numericTokens2(projected.numericSource)])}`);
|
|
14488
14718
|
}
|
|
14489
14719
|
function hashCodexSettingsReplacementV2(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14490
|
-
|
|
14720
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14491
14721
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14492
14722
|
return settingsDigest2(text2);
|
|
14493
14723
|
}
|
|
@@ -14499,17 +14729,17 @@ function readCodexSettingsPreimage(path, budget2 = { remaining: 2 * 1024 * 1024
|
|
|
14499
14729
|
return readNativeSettingsWitnessFile(path, budget2, "config.toml");
|
|
14500
14730
|
}
|
|
14501
14731
|
function upgradeCodexSettingsWitness(previous, reviewedSettingsPath) {
|
|
14502
|
-
|
|
14732
|
+
need5(previous && Object.keys(previous).every((key) => ["path", "hashMode", "sha256"].includes(key)) && (previous.hashMode === undefined || previous.hashMode === "bytes" || previous.hashMode === "codex-settings-v1") && /^[a-f0-9]{64}$/.test(previous.sha256));
|
|
14503
14733
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14504
14734
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14505
|
-
|
|
14735
|
+
need5((previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before)) === previous.sha256);
|
|
14506
14736
|
const sha2562 = settingsDigest2(current2);
|
|
14507
14737
|
if (settingsDigest2(before) !== sha2562)
|
|
14508
14738
|
throw new Error("Codex non-preference settings changed; explicit discovery review required");
|
|
14509
14739
|
return { path: previous.path, hashMode: "codex-settings-v2", sha256: sha2562 };
|
|
14510
14740
|
}
|
|
14511
14741
|
function hashCodexSettingsReplacementV3(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14512
|
-
|
|
14742
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14513
14743
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14514
14744
|
return settingsDigest2(text2, 3);
|
|
14515
14745
|
}
|
|
@@ -14517,18 +14747,18 @@ function captureCodexSettingsV3(path, budget2 = { remaining: 256 * 1024 * 1024 }
|
|
|
14517
14747
|
return { path, hashMode: "codex-settings-v3", sha256: settingsDigest2(readNativeSettingsWitnessFile(path, budget2, "config.toml"), 3) };
|
|
14518
14748
|
}
|
|
14519
14749
|
function upgradeCodexSettingsWitnessV3(previous, reviewedSettingsPath) {
|
|
14520
|
-
|
|
14750
|
+
need5(previous && Object.keys(previous).every((key) => ["path", "hashMode", "sha256"].includes(key)) && (previous.hashMode === undefined || ["bytes", "codex-settings-v1", "codex-settings-v2"].includes(previous.hashMode)) && /^[a-f0-9]{64}$/.test(previous.sha256));
|
|
14521
14751
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14522
14752
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14523
14753
|
const original = previous.hashMode === "codex-settings-v2" ? settingsDigest2(before) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
14524
|
-
|
|
14754
|
+
need5(original === previous.sha256);
|
|
14525
14755
|
const sha2562 = settingsDigest2(current2, 3);
|
|
14526
14756
|
if (settingsDigest2(before, 3) !== sha2562)
|
|
14527
14757
|
throw new Error("Codex settings outside the reviewed V3 contract changed; explicit discovery review required");
|
|
14528
14758
|
return { path: previous.path, hashMode: "codex-settings-v3", sha256: sha2562 };
|
|
14529
14759
|
}
|
|
14530
14760
|
function hashCodexSettingsReplacementV4(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14531
|
-
|
|
14761
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14532
14762
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14533
14763
|
return settingsDigest2(text2, 4);
|
|
14534
14764
|
}
|
|
@@ -14536,18 +14766,18 @@ function captureCodexSettingsV4(path, budget2 = { remaining: 256 * 1024 * 1024 }
|
|
|
14536
14766
|
return { path, hashMode: "codex-settings-v4", sha256: settingsDigest2(readNativeSettingsWitnessFile(path, budget2, "config.toml"), 4) };
|
|
14537
14767
|
}
|
|
14538
14768
|
function upgradeCodexSettingsWitnessV4(previous, reviewedSettingsPath) {
|
|
14539
|
-
|
|
14769
|
+
need5(previous && Object.keys(previous).every((key) => ["path", "hashMode", "sha256"].includes(key)) && (previous.hashMode === undefined || ["bytes", "codex-settings-v1", "codex-settings-v2", "codex-settings-v3"].includes(previous.hashMode)) && /^[a-f0-9]{64}$/.test(previous.sha256));
|
|
14540
14770
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14541
14771
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14542
14772
|
const original = previous.hashMode === "codex-settings-v3" ? settingsDigest2(before, 3) : previous.hashMode === "codex-settings-v2" ? settingsDigest2(before, 2) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
14543
|
-
|
|
14773
|
+
need5(original === previous.sha256);
|
|
14544
14774
|
const sha2562 = settingsDigest2(current2, 4);
|
|
14545
14775
|
if (settingsDigest2(before, 4) !== sha2562)
|
|
14546
14776
|
throw new Error("Codex settings outside the reviewed V4 contract changed; explicit discovery review required");
|
|
14547
14777
|
return { path: previous.path, hashMode: "codex-settings-v4", sha256: sha2562 };
|
|
14548
14778
|
}
|
|
14549
|
-
function refusal(
|
|
14550
|
-
return new SkillSelectionError("INVALID_AGENT_POLICY", `The Skills agent loading policy ${
|
|
14779
|
+
function refusal(reason2 = "is unreadable") {
|
|
14780
|
+
return new SkillSelectionError("INVALID_AGENT_POLICY", `The Skills agent loading policy ${reason2}; refusing legacy fallback.`);
|
|
14551
14781
|
}
|
|
14552
14782
|
function parseManagedSkillPolicy(text2) {
|
|
14553
14783
|
if (Buffer.byteLength(text2) > AGENT_POLICY_LIMITS.bytes)
|
|
@@ -14632,7 +14862,7 @@ Use the Skills CLI as the skill authority for this station.
|
|
|
14632
14862
|
|
|
14633
14863
|
This bridge contains no skill payloads. Do not copy skill content into agent-native skill directories or load other native skill copies. If a Skills command refuses authority, selection, integrity, or native drift, report that refusal and use its repair guidance; do not substitute bundled or stale local content. Explicit local draft authoring remains available.
|
|
14634
14864
|
`;
|
|
14635
|
-
var CLI_BRIDGE_DIGEST =
|
|
14865
|
+
var CLI_BRIDGE_DIGEST = createHash17("sha256").update(markdown).digest("hex");
|
|
14636
14866
|
var CLI_BRIDGE_FILES = Object.freeze({
|
|
14637
14867
|
"SKILL.md": markdown,
|
|
14638
14868
|
".hasna-skills.json": `${JSON.stringify({ managedBy: "@hasna/skills", kind: "cli-bridge", version: CLI_BRIDGE_VERSION, protocol: "selection-v1", contentSha256: CLI_BRIDGE_DIGEST }, null, 2)}
|
|
@@ -14659,22 +14889,22 @@ function sumiConfigDirectory(home, env = process.env) {
|
|
|
14659
14889
|
if (env[key] !== undefined)
|
|
14660
14890
|
throw new Error(`Sumi ${key} requires a dedicated discovery adapter; unset it before Skills integration`);
|
|
14661
14891
|
const selected = (key) => env[key]?.trim() ? env[key] : undefined;
|
|
14662
|
-
const expand = (value) =>
|
|
14892
|
+
const expand = (value) => resolve13(value === "~" ? home : value.startsWith("~/") ? join21(home, value.slice(2)) : value);
|
|
14663
14893
|
const explicit = selected("SUMI_CONFIG_DIR");
|
|
14664
14894
|
const xdg = selected("XDG_CONFIG_HOME");
|
|
14665
14895
|
const custom = selected("SUMI_HOME");
|
|
14666
|
-
const
|
|
14896
|
+
const canonical7 = explicit ? expand(explicit) : xdg ? join21(expand(xdg), "sumi") : join21(custom ? expand(custom) : join21(home, ".hasna-internal/sumi"), "config");
|
|
14667
14897
|
if (explicit || xdg || custom)
|
|
14668
|
-
return
|
|
14898
|
+
return canonical7;
|
|
14669
14899
|
const legacy = join21(home, ".config/sumi");
|
|
14670
|
-
const a = lstatSync17(
|
|
14671
|
-
if (a && b && realpathSync8(
|
|
14900
|
+
const a = lstatSync17(canonical7, { throwIfNoEntry: false }), b = lstatSync17(legacy, { throwIfNoEntry: false });
|
|
14901
|
+
if (a && b && realpathSync8(canonical7) !== realpathSync8(legacy))
|
|
14672
14902
|
throw new Error("Sumi config roots conflict; complete native home adoption before Skills integration");
|
|
14673
|
-
const path = a ?
|
|
14903
|
+
const path = a ? canonical7 : b ? legacy : canonical7;
|
|
14674
14904
|
if (!existsSync82(path))
|
|
14675
14905
|
return path;
|
|
14676
14906
|
const physical = realpathSync8(path);
|
|
14677
|
-
if ((a?.isSymbolicLink() || b?.isSymbolicLink()) && ![
|
|
14907
|
+
if ((a?.isSymbolicLink() || b?.isSymbolicLink()) && ![canonical7, legacy].includes(physical))
|
|
14678
14908
|
throw new Error("Sumi config alias must resolve to its canonical or legacy root");
|
|
14679
14909
|
return physical;
|
|
14680
14910
|
}
|
|
@@ -14772,17 +15002,20 @@ var SUMI_SKILL_PERMISSIONS = [
|
|
|
14772
15002
|
{ action: "skill", resource: "*", effect: "deny" },
|
|
14773
15003
|
{ action: "skill", resource: "skills-cli", effect: "allow" }
|
|
14774
15004
|
];
|
|
14775
|
-
function
|
|
15005
|
+
function need6(value, code) {
|
|
14776
15006
|
if (!value)
|
|
14777
15007
|
throw new Error(`CODEX_HOOK_TRUST_${code}`);
|
|
14778
15008
|
}
|
|
14779
15009
|
var sameStat = (a, b) => ["dev", "ino", "uid", "nlink", "mode", "size", "mtimeNs", "ctimeNs"].every((key) => a[key] === b[key]);
|
|
15010
|
+
function trustedAncestorOwner(uid) {
|
|
15011
|
+
return BigInt(uid) === 0n || BigInt(uid) === BigInt(process.getuid());
|
|
15012
|
+
}
|
|
14780
15013
|
function safeParents(file) {
|
|
14781
|
-
for (let p =
|
|
15014
|
+
for (let p = dirname14(file);; p = dirname14(p)) {
|
|
14782
15015
|
const s = lstatSync18(p);
|
|
14783
|
-
|
|
14784
|
-
|
|
14785
|
-
if (
|
|
15016
|
+
need6(s.isDirectory() && !s.isSymbolicLink() && trustedAncestorOwner(s.uid), "UNSAFE_PARENT");
|
|
15017
|
+
need6((s.mode & 18) === 0 || s.uid === 0 && (s.mode & 512) !== 0, "UNSAFE_PARENT");
|
|
15018
|
+
if (dirname14(p) === p)
|
|
14786
15019
|
break;
|
|
14787
15020
|
}
|
|
14788
15021
|
}
|
|
@@ -14790,12 +15023,12 @@ function snapshot(file, privateFile = false, options = {}) {
|
|
|
14790
15023
|
const readOnlyPackage = options.readOnlyPackage === true && !privateFile;
|
|
14791
15024
|
safeParents(file);
|
|
14792
15025
|
const initial = lstatSync18(file, { bigint: true });
|
|
14793
|
-
|
|
14794
|
-
|
|
15026
|
+
need6(initial.isFile() && initial.uid === BigInt(process.getuid()) && (initial.nlink === 1n || readOnlyPackage && initial.nlink > 1n) && (initial.mode & 0o022n) === 0n && (!privateFile || (initial.mode & 0o777n) === 0o600n), "UNSAFE_FILE");
|
|
15027
|
+
need6(initial.size <= 8n * 1024n * 1024n, "FILE_BOUND");
|
|
14795
15028
|
const fd = openSync9(file, constants9.O_RDONLY | constants9.O_NOFOLLOW | constants9.O_NONBLOCK);
|
|
14796
15029
|
try {
|
|
14797
15030
|
const before = fstatSync9(fd, { bigint: true });
|
|
14798
|
-
|
|
15031
|
+
need6(sameStat(initial, before), "INPUT_CHANGED");
|
|
14799
15032
|
const bytes = Buffer.alloc(Number(before.size) + 1);
|
|
14800
15033
|
let length = 0;
|
|
14801
15034
|
while (length < bytes.length) {
|
|
@@ -14804,18 +15037,57 @@ function snapshot(file, privateFile = false, options = {}) {
|
|
|
14804
15037
|
break;
|
|
14805
15038
|
length += n2;
|
|
14806
15039
|
}
|
|
14807
|
-
|
|
15040
|
+
need6(length === Number(before.size) && sameStat(before, fstatSync9(fd, { bigint: true })) && sameStat(before, lstatSync18(file, { bigint: true })), "INPUT_CHANGED");
|
|
14808
15041
|
const content = bytes.subarray(0, length), text2 = new TextDecoder("utf-8", { fatal: true }).decode(content);
|
|
14809
|
-
return { file, privateFile, readOnlyPackage, text: text2, bytes: content, stat: before, sha256:
|
|
15042
|
+
return { file, privateFile, readOnlyPackage, text: text2, bytes: content, stat: before, sha256: createHash18("sha256").update(content).digest("hex") };
|
|
14810
15043
|
} finally {
|
|
14811
15044
|
closeSync9(fd);
|
|
14812
15045
|
}
|
|
14813
15046
|
}
|
|
14814
15047
|
function unchanged2(before) {
|
|
14815
15048
|
const after = snapshot(before.file, before.privateFile, before.readOnlyPackage ? { readOnlyPackage: true } : {});
|
|
14816
|
-
|
|
14817
|
-
}
|
|
14818
|
-
var
|
|
15049
|
+
need6(sameStat(before.stat, after.stat) && after.sha256 === before.sha256, "INPUT_CHANGED");
|
|
15050
|
+
}
|
|
15051
|
+
var PINNED_LAUNCHER_BUN_FLAGS = ["--config=/dev/null", "--no-env-file", "--no-macros", "--no-install"];
|
|
15052
|
+
var PINNED_LAUNCHER_ENV_NAMES = [
|
|
15053
|
+
"HOME",
|
|
15054
|
+
"PATH",
|
|
15055
|
+
"TMPDIR",
|
|
15056
|
+
"TERM",
|
|
15057
|
+
"TERM_PROGRAM",
|
|
15058
|
+
"TERM_PROGRAM_VERSION",
|
|
15059
|
+
"COLORTERM",
|
|
15060
|
+
"LANG",
|
|
15061
|
+
"USER",
|
|
15062
|
+
"LOGNAME",
|
|
15063
|
+
"SHELL",
|
|
15064
|
+
"TZ",
|
|
15065
|
+
"NO_COLOR",
|
|
15066
|
+
"FORCE_COLOR",
|
|
15067
|
+
"CI",
|
|
15068
|
+
"COLUMNS",
|
|
15069
|
+
"LINES",
|
|
15070
|
+
"EDITOR",
|
|
15071
|
+
"VISUAL",
|
|
15072
|
+
"PAGER",
|
|
15073
|
+
"SSH_AUTH_SOCK",
|
|
15074
|
+
"DATABASE_URL",
|
|
15075
|
+
"TERMINAL_CWD",
|
|
15076
|
+
"CODEX_HOME",
|
|
15077
|
+
"HERMES_HOME",
|
|
15078
|
+
"HERMES_ENABLE_PROJECT_PLUGINS",
|
|
15079
|
+
"HOST",
|
|
15080
|
+
"PORT",
|
|
15081
|
+
"NODE_ENV",
|
|
15082
|
+
"AGENT_ID",
|
|
15083
|
+
"ECS_CONTAINER_METADATA_URI_V4"
|
|
15084
|
+
];
|
|
15085
|
+
var PINNED_LAUNCHER_ENV_PREFIXES = ["HASNA", "SKILLS", "SKILL", "MCP", "XDG", "LC", "AWS"];
|
|
15086
|
+
var ENV_PREFIX = new RegExp(`^(${PINNED_LAUNCHER_ENV_PREFIXES.join("|")})_`);
|
|
15087
|
+
var ENV_EXACT = new Set(PINNED_LAUNCHER_ENV_NAMES);
|
|
15088
|
+
var COMMAND_LINE = new RegExp(`^set -- '([^']+)' ${PINNED_LAUNCHER_BUN_FLAGS.join(" ")} '--cwd=([^']+)' '([^']+)' "\\$@"$`, "m");
|
|
15089
|
+
var PINNED_LAUNCHER_MAX_BYTES = 16 * 1024;
|
|
15090
|
+
var sha3 = (data) => createHash20("sha256").update(data).digest("hex");
|
|
14819
15091
|
var ROOTS = NATIVE_SKILL_ROOTS;
|
|
14820
15092
|
function hasTrustedDarwinAcl(fd, allowDenyOnly = false) {
|
|
14821
15093
|
try {
|
|
@@ -14865,12 +15137,13 @@ function isSystemRootAlias(path) {
|
|
|
14865
15137
|
return false;
|
|
14866
15138
|
const target = `/private${path}`, link = `private${path}`;
|
|
14867
15139
|
const identity5 = (stat) => `${stat.dev}:${stat.ino}:${stat.ctimeNs}:${stat.uid}:${stat.mode}`;
|
|
15140
|
+
const directoryIdentity = (stat) => `${stat.dev}:${stat.ino}:${stat.uid}:${stat.mode}`;
|
|
14868
15141
|
try {
|
|
14869
|
-
const before =
|
|
14870
|
-
if (!before.isSymbolicLink() || before.uid !== 0n ||
|
|
15142
|
+
const before = lstatSync20(path, { bigint: true });
|
|
15143
|
+
if (!before.isSymbolicLink() || before.uid !== 0n || readlinkSync7(path) !== link)
|
|
14871
15144
|
return false;
|
|
14872
15145
|
const directories = ["/", "/private", target].map((directory) => {
|
|
14873
|
-
const stat =
|
|
15146
|
+
const stat = lstatSync20(directory, { bigint: true });
|
|
14874
15147
|
if (!stat.isDirectory() || stat.uid !== 0n)
|
|
14875
15148
|
throw new Error("Untrusted system alias directory");
|
|
14876
15149
|
if (directory !== "/private/tmp") {
|
|
@@ -14878,34 +15151,34 @@ function isSystemRootAlias(path) {
|
|
|
14878
15151
|
throw new Error("Writable system alias directory");
|
|
14879
15152
|
} else if ((stat.mode & 0o1000n) === 0n)
|
|
14880
15153
|
throw new Error("Unprotected system temporary directory");
|
|
14881
|
-
const fd =
|
|
15154
|
+
const fd = openSync11(directory, constants11.O_RDONLY | constants11.O_DIRECTORY | constants11.O_NOFOLLOW);
|
|
14882
15155
|
try {
|
|
14883
|
-
if (
|
|
15156
|
+
if (directoryIdentity(fstatSync11(fd, { bigint: true })) !== directoryIdentity(stat) || !hasTrustedDarwinAcl(fd) || directoryIdentity(fstatSync11(fd, { bigint: true })) !== directoryIdentity(stat))
|
|
14884
15157
|
throw new Error("Unverified system alias directory ACL");
|
|
14885
15158
|
} finally {
|
|
14886
|
-
|
|
15159
|
+
closeSync11(fd);
|
|
14887
15160
|
}
|
|
14888
|
-
return { directory, identity:
|
|
15161
|
+
return { directory, identity: directoryIdentity(stat) };
|
|
14889
15162
|
});
|
|
14890
|
-
return
|
|
15163
|
+
return realpathSync10(path) === target && readlinkSync7(path) === link && identity5(lstatSync20(path, { bigint: true })) === identity5(before) && directories.every((item) => directoryIdentity(lstatSync20(item.directory, { bigint: true })) === item.identity);
|
|
14891
15164
|
} catch {
|
|
14892
15165
|
return false;
|
|
14893
15166
|
}
|
|
14894
15167
|
}
|
|
14895
15168
|
function canonicalSystemPath(path) {
|
|
14896
|
-
const absolute =
|
|
14897
|
-
if (process.platform !== "darwin" || !["/var", "/tmp", "/etc"].includes(root) || !
|
|
15169
|
+
const absolute = resolve15(path), root = `/${absolute.split(sep7)[1]}`;
|
|
15170
|
+
if (process.platform !== "darwin" || !["/var", "/tmp", "/etc"].includes(root) || !lstatSync20(root, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
14898
15171
|
return absolute;
|
|
14899
15172
|
if (!isSystemRootAlias(root))
|
|
14900
15173
|
throw new Error(`Refusing symlink path: ${root}`);
|
|
14901
15174
|
return `/private${absolute}`;
|
|
14902
15175
|
}
|
|
14903
15176
|
function assertSafePath(path) {
|
|
14904
|
-
let cursor =
|
|
15177
|
+
let cursor = resolve15(path);
|
|
14905
15178
|
while (true) {
|
|
14906
|
-
if (
|
|
15179
|
+
if (lstatSync20(cursor, { throwIfNoEntry: false })?.isSymbolicLink() && !isSystemRootAlias(cursor))
|
|
14907
15180
|
throw new Error(`Refusing symlink path: ${cursor}`);
|
|
14908
|
-
const parent =
|
|
15181
|
+
const parent = dirname15(cursor);
|
|
14909
15182
|
if (parent === cursor)
|
|
14910
15183
|
return;
|
|
14911
15184
|
cursor = parent;
|
|
@@ -14913,17 +15186,17 @@ function assertSafePath(path) {
|
|
|
14913
15186
|
}
|
|
14914
15187
|
function readRootAlias(home, agent) {
|
|
14915
15188
|
assertSafePath(home);
|
|
14916
|
-
const realHome =
|
|
14917
|
-
const stat =
|
|
15189
|
+
const realHome = realpathSync10(home), alias = join23(realHome, `.${agent}`);
|
|
15190
|
+
const stat = lstatSync20(alias, { throwIfNoEntry: false, bigint: true });
|
|
14918
15191
|
if (!stat?.isSymbolicLink())
|
|
14919
15192
|
throw new Error(`Agent root alias changed after planning: ${alias}`);
|
|
14920
|
-
const link =
|
|
15193
|
+
const link = readlinkSync7(alias), targetPath = resolve15(dirname15(alias), link);
|
|
14921
15194
|
assertSafePath(targetPath);
|
|
14922
|
-
const targetStat =
|
|
15195
|
+
const targetStat = lstatSync20(targetPath, { throwIfNoEntry: false });
|
|
14923
15196
|
if (!targetStat?.isDirectory())
|
|
14924
15197
|
throw new Error(`Agent root alias must target an existing directory: ${alias}`);
|
|
14925
|
-
const target =
|
|
14926
|
-
if (!inside || inside === ".." || inside.startsWith(`..${sep7}`) ||
|
|
15198
|
+
const target = realpathSync10(targetPath), inside = relative6(realHome, target);
|
|
15199
|
+
if (!inside || inside === ".." || inside.startsWith(`..${sep7}`) || isAbsolute16(inside))
|
|
14927
15200
|
throw new Error(`Agent root alias target must be inside the real home: ${alias}`);
|
|
14928
15201
|
return { agent, home: realHome, alias, target, link, aliasIdentity: `${stat.dev}:${stat.ino}:${stat.ctimeNs}`, targetIdentity: `${targetStat.dev}:${targetStat.ino}` };
|
|
14929
15202
|
}
|
|
@@ -14932,7 +15205,7 @@ function rootAliases(home, allowed = false) {
|
|
|
14932
15205
|
return [];
|
|
14933
15206
|
const result = [];
|
|
14934
15207
|
for (const agent of ["claude", "codex"])
|
|
14935
|
-
if (
|
|
15208
|
+
if (lstatSync20(join23(home, `.${agent}`), { throwIfNoEntry: false })?.isSymbolicLink())
|
|
14936
15209
|
result.push(readRootAlias(home, agent));
|
|
14937
15210
|
if (result.some((item, index) => result.slice(index + 1).some((other) => item.target === other.target || item.target.startsWith(other.target + sep7) || other.target.startsWith(item.target + sep7))))
|
|
14938
15211
|
throw new Error("Agent root alias targets must not overlap");
|
|
@@ -14949,17 +15222,17 @@ function disabledCodexSkillPaths(config, aliases) {
|
|
|
14949
15222
|
const rows = skills.config;
|
|
14950
15223
|
if (!Array.isArray(rows))
|
|
14951
15224
|
return [];
|
|
14952
|
-
if (rows.some((entry) => !entry || typeof entry !== "object" || Array.isArray(entry) || typeof entry.enabled !== "boolean" || entry.path !== undefined === (entry.name !== undefined) || entry.path !== undefined && (typeof entry.path !== "string" || !
|
|
15225
|
+
if (rows.some((entry) => !entry || typeof entry !== "object" || Array.isArray(entry) || typeof entry.enabled !== "boolean" || entry.path !== undefined === (entry.name !== undefined) || entry.path !== undefined && (typeof entry.path !== "string" || !isAbsolute16(entry.path)) || entry.name !== undefined && (typeof entry.name !== "string" || !entry.name.trim())))
|
|
14953
15226
|
return [];
|
|
14954
15227
|
if (rows.some((entry) => entry.name !== undefined && entry.enabled !== false))
|
|
14955
15228
|
return [];
|
|
14956
15229
|
const settings = new Map;
|
|
14957
15230
|
for (const entry of rows) {
|
|
14958
|
-
if (typeof entry.path !== "string" || !
|
|
15231
|
+
if (typeof entry.path !== "string" || !isAbsolute16(entry.path))
|
|
14959
15232
|
continue;
|
|
14960
15233
|
let document2;
|
|
14961
15234
|
try {
|
|
14962
|
-
document2 =
|
|
15235
|
+
document2 = realpathSync10(canonicalAgentPath(entry.path, aliases));
|
|
14963
15236
|
} catch {
|
|
14964
15237
|
continue;
|
|
14965
15238
|
}
|
|
@@ -14967,7 +15240,7 @@ function disabledCodexSkillPaths(config, aliases) {
|
|
|
14967
15240
|
continue;
|
|
14968
15241
|
settings.set(document2, [...settings.get(document2) ?? [], entry.enabled === false]);
|
|
14969
15242
|
}
|
|
14970
|
-
return [...settings].filter(([, values]) => values.length === 1 && values[0] === true).map(([document2]) =>
|
|
15243
|
+
return [...settings].filter(([, values]) => values.length === 1 && values[0] === true).map(([document2]) => dirname15(document2));
|
|
14971
15244
|
}
|
|
14972
15245
|
function recheckRootAliases(aliases) {
|
|
14973
15246
|
for (const binding of aliases) {
|
|
@@ -14980,16 +15253,16 @@ function recheckRootAliases(aliases) {
|
|
|
14980
15253
|
}
|
|
14981
15254
|
function nativeSourceDigest(path) {
|
|
14982
15255
|
assertSafePath(path);
|
|
14983
|
-
return
|
|
15256
|
+
return lstatSync20(path, { throwIfNoEntry: false }) ? sha3(readNativeBytes(path, 1024 * 1024)) : null;
|
|
14984
15257
|
}
|
|
14985
15258
|
function readNativeBytes(path, maximum = 64 * 1024 * 1024) {
|
|
14986
15259
|
assertSafePath(path);
|
|
14987
|
-
const before =
|
|
15260
|
+
const before = lstatSync20(path);
|
|
14988
15261
|
if (!before.isFile() || before.size > maximum)
|
|
14989
15262
|
throw new Error("Unsupported or oversized native skill file");
|
|
14990
|
-
const descriptor =
|
|
15263
|
+
const descriptor = openSync11(path, constants11.O_RDONLY | constants11.O_NOFOLLOW | constants11.O_NONBLOCK);
|
|
14991
15264
|
try {
|
|
14992
|
-
const opened =
|
|
15265
|
+
const opened = fstatSync11(descriptor);
|
|
14993
15266
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino || opened.size !== before.size)
|
|
14994
15267
|
throw new Error("Native skill file changed while reading");
|
|
14995
15268
|
const bytes = Buffer.allocUnsafe(before.size + 1);
|
|
@@ -15000,19 +15273,19 @@ function readNativeBytes(path, maximum = 64 * 1024 * 1024) {
|
|
|
15000
15273
|
break;
|
|
15001
15274
|
length += count;
|
|
15002
15275
|
}
|
|
15003
|
-
const after =
|
|
15276
|
+
const after = fstatSync11(descriptor), current2 = lstatSync20(path);
|
|
15004
15277
|
if (current2.dev !== opened.dev || current2.ino !== opened.ino || current2.size !== after.size || current2.mtimeMs !== after.mtimeMs || current2.ctimeMs !== after.ctimeMs || length !== before.size || after.size !== before.size || after.mtimeMs !== opened.mtimeMs || after.ctimeMs !== opened.ctimeMs)
|
|
15005
15278
|
throw new Error("Native skill file changed while reading");
|
|
15006
15279
|
return bytes.subarray(0, length);
|
|
15007
15280
|
} finally {
|
|
15008
|
-
|
|
15281
|
+
closeSync11(descriptor);
|
|
15009
15282
|
}
|
|
15010
15283
|
}
|
|
15011
15284
|
function treeHash(root) {
|
|
15012
|
-
const hash2 =
|
|
15285
|
+
const hash2 = createHash20("sha256");
|
|
15013
15286
|
let bytes = 0, files = 0;
|
|
15014
15287
|
function visit2(path) {
|
|
15015
|
-
const stat =
|
|
15288
|
+
const stat = lstatSync20(path);
|
|
15016
15289
|
if (stat.isSymbolicLink())
|
|
15017
15290
|
throw new Error(`Refusing symlink in skill: ${path}`);
|
|
15018
15291
|
const rel = relative6(root, path);
|
|
@@ -15042,7 +15315,7 @@ function projectAncestorDirectories(projects) {
|
|
|
15042
15315
|
if (depth >= 100)
|
|
15043
15316
|
throw new Error("NATIVE_SKILL_DRIFT: project ancestor discovery limit exceeded");
|
|
15044
15317
|
directories.add(path);
|
|
15045
|
-
const parent =
|
|
15318
|
+
const parent = dirname15(path);
|
|
15046
15319
|
if (parent === path)
|
|
15047
15320
|
break;
|
|
15048
15321
|
path = parent;
|
|
@@ -15051,7 +15324,7 @@ function projectAncestorDirectories(projects) {
|
|
|
15051
15324
|
return [...directories];
|
|
15052
15325
|
}
|
|
15053
15326
|
function isCodexSkillDiscoveryInput(path) {
|
|
15054
|
-
for (let cursor = canonicalSystemPath(path);cursor !==
|
|
15327
|
+
for (let cursor = canonicalSystemPath(path);cursor !== dirname15(cursor); cursor = dirname15(cursor)) {
|
|
15055
15328
|
if (ROOTS.some(([agent, root]) => agent === "codex" && cursor.endsWith(join23(sep7, root))))
|
|
15056
15329
|
return true;
|
|
15057
15330
|
}
|
|
@@ -15059,9 +15332,9 @@ function isCodexSkillDiscoveryInput(path) {
|
|
|
15059
15332
|
}
|
|
15060
15333
|
function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
15061
15334
|
home = canonicalSystemPath(home);
|
|
15062
|
-
if (options.reviewedCacheAlias !== undefined && (!options.includeVendor || !
|
|
15335
|
+
if (options.reviewedCacheAlias !== undefined && (!options.includeVendor || !isAbsolute16(options.reviewedCacheAlias) || resolve15(options.reviewedCacheAlias) !== options.reviewedCacheAlias))
|
|
15063
15336
|
throw new Error("A reviewed cache alias requires vendor inventory and an exact absolute path");
|
|
15064
|
-
if (options.disabledVendorPaths?.some((path) => !
|
|
15337
|
+
if (options.disabledVendorPaths?.some((path) => !isAbsolute16(path) || resolve15(path) !== path))
|
|
15065
15338
|
throw new Error("Disabled vendor paths must be exact absolute paths");
|
|
15066
15339
|
const reviewedCacheAlias = options.reviewedCacheAlias === undefined ? undefined : canonicalSystemPath(options.reviewedCacheAlias);
|
|
15067
15340
|
const disabledVendorPaths = new Set((options.disabledVendorPaths ?? []).map(canonicalSystemPath));
|
|
@@ -15080,7 +15353,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15080
15353
|
roots.push(["sumi", canonicalAgentPath(join23(project, directory, name), aliases)]);
|
|
15081
15354
|
}
|
|
15082
15355
|
const installationInputs = options.codexInstallationInputRoots ?? [];
|
|
15083
|
-
if (installationInputs.some((input) =>
|
|
15356
|
+
if (installationInputs.some((input) => resolve15(input) !== input || realpathSync10(input) !== input || roots.some(([agent, path]) => agent === "codex" && (path === input || path.startsWith(input + sep7) || input.startsWith(path + sep7)))))
|
|
15084
15357
|
throw new Error("Native installation input overlaps an unconditional skill-loading root");
|
|
15085
15358
|
const entries = [], seen = new Set;
|
|
15086
15359
|
const cacheScans = new Map, maxAliasProofEntries = 1e4;
|
|
@@ -15094,13 +15367,13 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15094
15367
|
}
|
|
15095
15368
|
let reviewedCacheAliasFound = false;
|
|
15096
15369
|
function verifiedSiblingCacheAlias(agent, path, parent) {
|
|
15097
|
-
const link =
|
|
15098
|
-
if (
|
|
15370
|
+
const link = readlinkSync7(path), lexicalTarget = resolve15(parent, link);
|
|
15371
|
+
if (isAbsolute16(link) ? link !== lexicalTarget : dirname15(link) !== ".")
|
|
15099
15372
|
return false;
|
|
15100
15373
|
const target = canonicalSystemPath(lexicalTarget);
|
|
15101
|
-
if (
|
|
15374
|
+
if (dirname15(target) !== parent)
|
|
15102
15375
|
return false;
|
|
15103
|
-
if (!
|
|
15376
|
+
if (!lstatSync20(target, { throwIfNoEntry: false })?.isDirectory())
|
|
15104
15377
|
return false;
|
|
15105
15378
|
const scan = cacheScans.get(target);
|
|
15106
15379
|
if (!scan?.complete || scan.entries > maxAliasProofEntries)
|
|
@@ -15125,7 +15398,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15125
15398
|
return scan;
|
|
15126
15399
|
if (!existsSync92(path))
|
|
15127
15400
|
return scan;
|
|
15128
|
-
const stat =
|
|
15401
|
+
const stat = lstatSync20(path);
|
|
15129
15402
|
if (stat.isFile()) {
|
|
15130
15403
|
if (agent === "sumi" && depth === 1 && path.endsWith(".md"))
|
|
15131
15404
|
throw new Error("NATIVE_SKILL_DRIFT: flat Sumi skill documents require a dedicated migration adapter");
|
|
@@ -15142,22 +15415,22 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15142
15415
|
const marker = join23(path, ".hasna-skills.json");
|
|
15143
15416
|
if (existsSync92(marker)) {
|
|
15144
15417
|
try {
|
|
15145
|
-
managed = JSON.parse(
|
|
15418
|
+
managed = JSON.parse(readFileSync15(marker, "utf8")).managedBy === "@hasna/skills";
|
|
15146
15419
|
} catch {}
|
|
15147
15420
|
}
|
|
15148
15421
|
const bridge = (!vendor || agent === "sumi") && isOwnedCliBridge(path, bridgePaths);
|
|
15149
15422
|
const rootAlias = aliases.find((item) => path === item.target || path.startsWith(item.target + sep7));
|
|
15150
|
-
entries.push({ agent, path, hash: treeHash(path), managed, vendor, ...agent === "codex" || isCodexSkillDiscoveryInput(path) ? { codexHome: process.env.CODEX_HOME ?? join23(home, ".codex") } : {}, ...agent === "codex" && path.startsWith(canonicalAgentPath(join23(home, ".codex", "skills", ".system"), aliases) + sep7) ? { system: true } : {}, ...bridge ? { bridge: true, bridgeHome:
|
|
15423
|
+
entries.push({ agent, path, hash: treeHash(path), managed, vendor, ...agent === "codex" || isCodexSkillDiscoveryInput(path) ? { codexHome: process.env.CODEX_HOME ?? join23(home, ".codex") } : {}, ...agent === "codex" && path.startsWith(canonicalAgentPath(join23(home, ".codex", "skills", ".system"), aliases) + sep7) ? { system: true } : {}, ...bridge ? { bridge: true, bridgeHome: resolve15(home) } : {}, ...rootAlias ? { rootAlias } : {} });
|
|
15151
15424
|
return scan;
|
|
15152
15425
|
}
|
|
15153
15426
|
if (depth > (agent === "sumi" ? 32 : vendor ? 32 : 3))
|
|
15154
15427
|
return { ...scan, complete: false };
|
|
15155
15428
|
const children = [], directory = opendirSync3(path);
|
|
15156
15429
|
try {
|
|
15157
|
-
let
|
|
15158
|
-
while ((
|
|
15159
|
-
admit(join23(path,
|
|
15160
|
-
children.push(
|
|
15430
|
+
let child2;
|
|
15431
|
+
while ((child2 = directory.readSync()) !== null) {
|
|
15432
|
+
admit(join23(path, child2.name));
|
|
15433
|
+
children.push(child2);
|
|
15161
15434
|
}
|
|
15162
15435
|
} finally {
|
|
15163
15436
|
directory.closeSync();
|
|
@@ -15173,15 +15446,15 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15173
15446
|
const isVendor = vendor || name === ".system";
|
|
15174
15447
|
if (isVendor && !options.includeVendor)
|
|
15175
15448
|
continue;
|
|
15176
|
-
const
|
|
15177
|
-
if (isVendor &&
|
|
15178
|
-
const target = statSync9(
|
|
15179
|
-
if (target?.isFile() || pluginCache && target?.isDirectory() && verifiedSiblingCacheAlias(agent,
|
|
15449
|
+
const child2 = join23(path, name);
|
|
15450
|
+
if (isVendor && lstatSync20(child2, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
15451
|
+
const target = statSync9(child2, { throwIfNoEntry: false });
|
|
15452
|
+
if (target?.isFile() || pluginCache && target?.isDirectory() && verifiedSiblingCacheAlias(agent, child2, path)) {
|
|
15180
15453
|
scan.entries++;
|
|
15181
15454
|
continue;
|
|
15182
15455
|
}
|
|
15183
15456
|
}
|
|
15184
|
-
const childScan = visit2(agent,
|
|
15457
|
+
const childScan = visit2(agent, child2, isVendor, depth + 1, pluginCache, true, configuredRoot);
|
|
15185
15458
|
scan.complete &&= childScan.complete;
|
|
15186
15459
|
scan.hasSkills ||= childScan.hasSkills;
|
|
15187
15460
|
scan.entries += childScan.entries;
|
|
@@ -15217,7 +15490,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15217
15490
|
}
|
|
15218
15491
|
function readOptional(path) {
|
|
15219
15492
|
assertSafePath(path);
|
|
15220
|
-
return existsSync92(path) ?
|
|
15493
|
+
return existsSync92(path) ? readFileSync15(path, "utf8") : null;
|
|
15221
15494
|
}
|
|
15222
15495
|
function jsonObject(text2, path) {
|
|
15223
15496
|
if (text2 === null)
|
|
@@ -15315,29 +15588,28 @@ function configureHooks(config, agent, command, profileId, nativeReady) {
|
|
|
15315
15588
|
}
|
|
15316
15589
|
}
|
|
15317
15590
|
function claudeSettingsConsumers(home, path, discoveries, aliases) {
|
|
15318
|
-
const
|
|
15591
|
+
const canonical7 = (value) => canonicalAgentPath(value, aliases);
|
|
15319
15592
|
const containsSettings = (root) => {
|
|
15320
|
-
const distance = relative6(
|
|
15321
|
-
return distance === "" || distance !== ".." && !distance.startsWith(`..${sep7}`) && !
|
|
15593
|
+
const distance = relative6(canonical7(root), path);
|
|
15594
|
+
return distance === "" || distance !== ".." && !distance.startsWith(`..${sep7}`) && !isAbsolute16(distance);
|
|
15322
15595
|
};
|
|
15323
|
-
return discoveries.filter((binding) => binding.agent === "claude" || binding.agent === "opencode" ||
|
|
15596
|
+
return discoveries.filter((binding) => binding.agent === "claude" || binding.agent === "opencode" || canonical7(join23(home, AGENT_ADAPTERS[binding.agent].config)) === path || binding.sources.some((source) => canonical7(source.path) === path) || binding.roots.some(containsSettings) || binding.directories?.some((directory) => containsSettings(directory.path))).map((binding) => binding.agent);
|
|
15324
15597
|
}
|
|
15325
|
-
function verifyCoordinatedDiscovery(binding, home, aliases) {
|
|
15598
|
+
function verifyCoordinatedDiscovery(binding, home, aliases, executable2) {
|
|
15326
15599
|
try {
|
|
15327
15600
|
if (binding.method !== "automatic" && binding.method !== "reviewed")
|
|
15328
15601
|
throw new Error("Invalid managed discovery method");
|
|
15329
15602
|
verifyAgentDiscovery(binding);
|
|
15330
|
-
if (binding.method === "automatic")
|
|
15331
|
-
|
|
15332
|
-
if (JSON.stringify(current2) !== JSON.stringify(binding))
|
|
15333
|
-
throw new Error("Configured native discovery roots changed during Claude update");
|
|
15334
|
-
}
|
|
15603
|
+
if (binding.method === "automatic")
|
|
15604
|
+
verifyAutomaticDiscoveryClosure(binding, { home, canonical: (path) => canonicalAgentPath(path, aliases), change: "Configured native discovery roots changed during Claude update", executable: executable2 });
|
|
15335
15605
|
} catch (error) {
|
|
15606
|
+
if (isDiscoveryRootUnresolved(error))
|
|
15607
|
+
throw error;
|
|
15336
15608
|
throw new Error(`NATIVE_SKILL_DRIFT: ${error.message}`);
|
|
15337
15609
|
}
|
|
15338
15610
|
}
|
|
15339
15611
|
function planClaudeHookEventsUpdate(options) {
|
|
15340
|
-
const home =
|
|
15612
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15341
15613
|
const policyPath = join23(dataDir22, "agent-policy.json");
|
|
15342
15614
|
assertSafePath(policyPath);
|
|
15343
15615
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
@@ -15351,7 +15623,7 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15351
15623
|
recheckRootAliases(aliases);
|
|
15352
15624
|
const path = canonicalAgentPath(join23(home, ".claude", "settings.json"), aliases);
|
|
15353
15625
|
assertSafePath(path);
|
|
15354
|
-
const before =
|
|
15626
|
+
const before = lstatSync20(path, { throwIfNoEntry: false }) ? new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readNativeBytes(path, 1024 * 1024)) : null;
|
|
15355
15627
|
if ((before === null ? "absent" : sha3(before)) !== options.expectedSettingsSha256)
|
|
15356
15628
|
throw new Error("Claude settings preimage changed");
|
|
15357
15629
|
assertClaudeHookEventsReplacement(before, options.replacement, options.events);
|
|
@@ -15363,8 +15635,9 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15363
15635
|
});
|
|
15364
15636
|
if (discoveries.length !== agents.length || !agents.includes("claude"))
|
|
15365
15637
|
throw new Error("Missing managed Claude discovery coverage");
|
|
15638
|
+
const discoveryExecutables = bridge.discoveryExecutables;
|
|
15366
15639
|
for (const binding of discoveries)
|
|
15367
|
-
verifyCoordinatedDiscovery(binding, home, aliases);
|
|
15640
|
+
verifyCoordinatedDiscovery(binding, home, aliases, discoveryExecutables?.[binding.agent]);
|
|
15368
15641
|
const consumers = claudeSettingsConsumers(home, path, discoveries, aliases);
|
|
15369
15642
|
for (const agent of consumers)
|
|
15370
15643
|
assertManagedAgentBridge(agent, { home, dataDir: dataDir22, projectDir: home });
|
|
@@ -15399,13 +15672,14 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15399
15672
|
observedPolicy: { path: policyPath, before: snapshot2.text },
|
|
15400
15673
|
discoveryBefore: discoveries,
|
|
15401
15674
|
discoveryAfter,
|
|
15675
|
+
...discoveryExecutables ? { discoveryExecutables } : {},
|
|
15402
15676
|
rootAliases: aliases,
|
|
15403
15677
|
managedAgentChecks: { home, agents: consumers }
|
|
15404
15678
|
};
|
|
15405
15679
|
}
|
|
15406
15680
|
function atomicWrite2(path, content) {
|
|
15407
15681
|
assertSafePath(path);
|
|
15408
|
-
mkdirSync6(
|
|
15682
|
+
mkdirSync6(dirname15(path), { recursive: true, mode: 448 });
|
|
15409
15683
|
const temporary = `${path}.skills-${randomUUID3()}`;
|
|
15410
15684
|
try {
|
|
15411
15685
|
writeFileSync6(temporary, content, { mode: 384, flag: "wx" });
|
|
@@ -15418,7 +15692,9 @@ function atomicWrite2(path, content) {
|
|
|
15418
15692
|
function planAgentSettingsWitnessUpgrade(options) {
|
|
15419
15693
|
if (options.targetCodexVersion !== undefined && (options.agent !== "codex" || ![2, 3, 4].includes(options.targetCodexVersion)))
|
|
15420
15694
|
throw new Error("Invalid Codex witness target version");
|
|
15421
|
-
|
|
15695
|
+
if (options.targetClaudeVersion !== undefined && (options.agent !== "claude" || ![3, 4].includes(options.targetClaudeVersion)))
|
|
15696
|
+
throw new Error("Invalid Claude witness target version");
|
|
15697
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15422
15698
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
15423
15699
|
if (!snapshot2 || sha3(snapshot2.text) !== options.expectedPolicySha256)
|
|
15424
15700
|
throw new Error("Managed policy preimage changed");
|
|
@@ -15465,7 +15741,7 @@ function planAgentSettingsWitnessUpgrade(options) {
|
|
|
15465
15741
|
replaced.push(source);
|
|
15466
15742
|
}
|
|
15467
15743
|
}
|
|
15468
|
-
const next = options.agent === "sumi" ? upgradeSumiSettingsWitness(previous, options.reviewedPreimage) : options.agent === "claude" ? upgradeClaudeSettingsWitness(previous, options.reviewedPreimage) : options.targetCodexVersion === 4 ? upgradeCodexSettingsWitnessV4(previous, options.reviewedPreimage) : options.targetCodexVersion === 3 ? upgradeCodexSettingsWitnessV3(previous, options.reviewedPreimage) : upgradeCodexSettingsWitness(previous, options.reviewedPreimage);
|
|
15744
|
+
const next = options.agent === "sumi" ? upgradeSumiSettingsWitness(previous, options.reviewedPreimage) : options.agent === "claude" ? options.targetClaudeVersion === 4 ? upgradeClaudeSettingsWitnessV4(previous, options.reviewedPreimage) : upgradeClaudeSettingsWitness(previous, options.reviewedPreimage) : options.targetCodexVersion === 4 ? upgradeCodexSettingsWitnessV4(previous, options.reviewedPreimage) : options.targetCodexVersion === 3 ? upgradeCodexSettingsWitnessV3(previous, options.reviewedPreimage) : upgradeCodexSettingsWitness(previous, options.reviewedPreimage);
|
|
15469
15745
|
const rebound = [];
|
|
15470
15746
|
for (const source of binding.sources) {
|
|
15471
15747
|
if (!replaced.includes(source)) {
|
|
@@ -15478,7 +15754,7 @@ function planAgentSettingsWitnessUpgrade(options) {
|
|
|
15478
15754
|
const replacement = { ...binding, sources: rebound };
|
|
15479
15755
|
verifyAgentDiscovery(replacement);
|
|
15480
15756
|
const after = serializeManagedSkillPolicy({ ...policy, bridge: { ...policy.bridge, discovery: { ...policy.bridge.discovery, [options.agent]: replacement } } });
|
|
15481
|
-
return { dataDir: dataDir22, profileId: policy.profileId, changes: [{ path: join23(dataDir22, "agent-policy.json"), before: snapshot2.text, after }], nativeSkills: [], observedPolicy: { path: join23(dataDir22, "agent-policy.json"), before: snapshot2.text }, observedSettings: { path: configPath, before: settings }, discoveryBefore: [replacement], discoveryAfter: [replacement], rootAliases: aliases, managedAgentChecks: { home, agents: [options.agent] }, settingsWitnessUpgrade: { agent: options.agent, path: configPath, fromHashMode: previous.hashMode ?? "bytes", fromSha256: previous.sha256, toHashMode: next.hashMode, toSha256: next.sha256, reviewedPreimage: options.reviewedPreimage, currentSettingsSha256: options.expectedSettingsSha256, replacedWitnesses: replaced.map((source) => ({ hashMode: source.hashMode ?? "bytes", sha256: source.sha256 })) } };
|
|
15757
|
+
return { dataDir: dataDir22, profileId: policy.profileId, changes: [{ path: join23(dataDir22, "agent-policy.json"), before: snapshot2.text, after }], nativeSkills: [], observedPolicy: { path: join23(dataDir22, "agent-policy.json"), before: snapshot2.text }, observedSettings: { path: configPath, before: settings }, discoveryBefore: [replacement], discoveryAfter: [replacement], ...policy.bridge.discoveryExecutables ? { discoveryExecutables: policy.bridge.discoveryExecutables } : {}, rootAliases: aliases, managedAgentChecks: { home, agents: [options.agent] }, settingsWitnessUpgrade: { agent: options.agent, path: configPath, fromHashMode: previous.hashMode ?? "bytes", fromSha256: previous.sha256, toHashMode: next.hashMode, toSha256: next.sha256, reviewedPreimage: options.reviewedPreimage, currentSettingsSha256: options.expectedSettingsSha256, replacedWitnesses: replaced.map((source) => ({ hashMode: source.hashMode ?? "bytes", sha256: source.sha256 })) } };
|
|
15482
15758
|
}
|
|
15483
15759
|
function applyAgentIntegration(plan, options = {}) {
|
|
15484
15760
|
const roots = plan.changes.flatMap((change) => {
|
|
@@ -15496,10 +15772,10 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15496
15772
|
throw new Error("Native settings changed after witness planning");
|
|
15497
15773
|
const policyPath = join23(plan.dataDir, "agent-policy.json");
|
|
15498
15774
|
assertSafePath(policyPath);
|
|
15499
|
-
const currentText = (path) =>
|
|
15775
|
+
const currentText = (path) => resolve15(path) === resolve15(policyPath) ? readManagedSkillPolicySnapshot(plan.dataDir)?.text ?? null : readOptional(path);
|
|
15500
15776
|
readManagedSkillPolicySnapshot(plan.dataDir);
|
|
15501
15777
|
for (const change of plan.changes)
|
|
15502
|
-
if (
|
|
15778
|
+
if (resolve15(change.path) === resolve15(policyPath))
|
|
15503
15779
|
parseManagedSkillPolicy(change.after);
|
|
15504
15780
|
const aliases = plan.rootAliases ?? [];
|
|
15505
15781
|
assertCurrent();
|
|
@@ -15511,7 +15787,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15511
15787
|
const upgrade = plan.settingsWitnessUpgrade;
|
|
15512
15788
|
if (!plan.managedAgentChecks || !plan.observedPolicy?.before)
|
|
15513
15789
|
throw new Error("Invalid settings witness upgrade plan");
|
|
15514
|
-
const verified = planAgentSettingsWitnessUpgrade({ agent: upgrade.agent, ...upgrade.agent === "codex" ? { targetCodexVersion: upgrade.toHashMode === "codex-settings-v4" ? 4 : upgrade.toHashMode === "codex-settings-v3" ? 3 : 2 } : {}, reviewedPreimage: upgrade.reviewedPreimage, home: plan.managedAgentChecks.home, dataDir: plan.dataDir, expectedPolicySha256: sha3(plan.observedPolicy.before), expectedSettingsSha256: upgrade.currentSettingsSha256 });
|
|
15790
|
+
const verified = planAgentSettingsWitnessUpgrade({ agent: upgrade.agent, ...upgrade.agent === "codex" ? { targetCodexVersion: upgrade.toHashMode === "codex-settings-v4" ? 4 : upgrade.toHashMode === "codex-settings-v3" ? 3 : 2 } : {}, ...upgrade.agent === "claude" && upgrade.toHashMode === "claude-settings-v4" ? { targetClaudeVersion: 4 } : {}, reviewedPreimage: upgrade.reviewedPreimage, home: plan.managedAgentChecks.home, dataDir: plan.dataDir, expectedPolicySha256: sha3(plan.observedPolicy.before), expectedSettingsSha256: upgrade.currentSettingsSha256 });
|
|
15515
15791
|
if (JSON.stringify(verified.changes) !== JSON.stringify(plan.changes) || JSON.stringify(verified.settingsWitnessUpgrade) !== JSON.stringify(upgrade))
|
|
15516
15792
|
throw new Error("Settings witness upgrade plan changed");
|
|
15517
15793
|
provenDiscovery = verified.discoveryBefore[0];
|
|
@@ -15520,7 +15796,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15520
15796
|
assertManagedAgentBridgeWithDiscovery(agent, { home: plan.managedAgentChecks.home, dataDir: plan.dataDir, projectDir: plan.managedAgentChecks.home }, provenDiscovery?.agent === agent ? provenDiscovery : undefined);
|
|
15521
15797
|
for (const binding of plan.discoveryBefore ?? []) {
|
|
15522
15798
|
if (plan.managedAgentChecks)
|
|
15523
|
-
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases);
|
|
15799
|
+
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases, plan.discoveryExecutables?.[binding.agent]);
|
|
15524
15800
|
else
|
|
15525
15801
|
verifyAgentDiscovery(binding);
|
|
15526
15802
|
}
|
|
@@ -15542,7 +15818,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15542
15818
|
if (change.before !== null) {
|
|
15543
15819
|
const backup = join23(backupRoot, `${index}-${sha3(change.path).slice(0, 12)}.backup`);
|
|
15544
15820
|
writeFileSync6(backup, change.before, { mode: 384, flag: "wx" });
|
|
15545
|
-
if (
|
|
15821
|
+
if (readFileSync15(backup, "utf8") !== change.before)
|
|
15546
15822
|
throw new Error("Native configuration preservation readback failed");
|
|
15547
15823
|
backups.push(backup);
|
|
15548
15824
|
}
|
|
@@ -15552,7 +15828,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15552
15828
|
recheckRootAliases(aliases);
|
|
15553
15829
|
if (currentText(change.path) !== change.before)
|
|
15554
15830
|
throw new Error(`Configuration changed after planning: ${change.path}`);
|
|
15555
|
-
for (let directory =
|
|
15831
|
+
for (let directory = dirname15(change.path);!existsSync92(directory); directory = dirname15(directory))
|
|
15556
15832
|
createdDirectories.add(directory);
|
|
15557
15833
|
const after = change.after;
|
|
15558
15834
|
atomicWrite2(change.path, after);
|
|
@@ -15567,7 +15843,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15567
15843
|
throw new Error("Native settings changed during witness application");
|
|
15568
15844
|
for (const binding of plan.discoveryAfter ?? []) {
|
|
15569
15845
|
if (plan.managedAgentChecks)
|
|
15570
|
-
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases);
|
|
15846
|
+
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases, plan.discoveryExecutables?.[binding.agent]);
|
|
15571
15847
|
else
|
|
15572
15848
|
verifyAgentDiscovery(binding);
|
|
15573
15849
|
}
|
|
@@ -15609,12 +15885,12 @@ function isInertCodexPluginCacheCopy(entry, cache, allowedHostPaths, read2) {
|
|
|
15609
15885
|
return false;
|
|
15610
15886
|
const document2 = join23(entry.path, "SKILL.md");
|
|
15611
15887
|
const inside = relative6(cache, entry.path);
|
|
15612
|
-
if (!inside ||
|
|
15888
|
+
if (!inside || isAbsolute16(inside) || inside.split(sep7).some((segment) => segment === ".."))
|
|
15613
15889
|
return false;
|
|
15614
15890
|
assertSafePath(entry.path);
|
|
15615
|
-
if (!
|
|
15891
|
+
if (!lstatSync20(cache).isDirectory() || !lstatSync20(entry.path).isDirectory() || !lstatSync20(document2).isFile())
|
|
15616
15892
|
return false;
|
|
15617
|
-
if (
|
|
15893
|
+
if (realpathSync10.native(cache) !== cache || realpathSync10.native(entry.path) !== entry.path || realpathSync10.native(document2) !== document2)
|
|
15618
15894
|
return false;
|
|
15619
15895
|
if (!classifyCodexPluginCacheDocument(document2, cache, read2))
|
|
15620
15896
|
return false;
|
|
@@ -15629,7 +15905,7 @@ function assertManagedAgentBridge(agent, options = {}) {
|
|
|
15629
15905
|
assertManagedAgentBridgeWithDiscovery(agent, options);
|
|
15630
15906
|
}
|
|
15631
15907
|
function assertManagedAgentBridgeWithDiscovery(agent, options = {}, provenDiscovery) {
|
|
15632
|
-
const home =
|
|
15908
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15633
15909
|
assertSafePath(join23(dataDir22, "agent-policy.json"));
|
|
15634
15910
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
15635
15911
|
if (!snapshot2)
|
|
@@ -15727,12 +16003,11 @@ function assertManagedAgentBridgeWithDiscovery(agent, options = {}, provenDiscov
|
|
|
15727
16003
|
verifyAgentDiscovery(agent === "codex" ? { ...discovery, codexDisabledPluginSkills: binding.codexPluginSkills ?? [] } : discovery, options.codexDiscoveryRecovery);
|
|
15728
16004
|
if (agent === "sumi" && discovery.method === "reviewed")
|
|
15729
16005
|
resolveAgentDiscovery({ home, agent, retainedReview: discovery, canonical: (path) => canonicalAgentPath(path, aliases) });
|
|
15730
|
-
if (discovery.method === "automatic")
|
|
15731
|
-
|
|
15732
|
-
if (JSON.stringify(current2) !== JSON.stringify(discovery))
|
|
15733
|
-
throw new Error("Configured native discovery roots changed");
|
|
15734
|
-
}
|
|
16006
|
+
if (discovery.method === "automatic")
|
|
16007
|
+
verifyAutomaticDiscoveryClosure(discovery, { home, canonical: (path) => canonicalAgentPath(path, aliases), change: "Configured native discovery roots changed", executable: binding.discoveryExecutables?.[agent] });
|
|
15735
16008
|
} catch (error) {
|
|
16009
|
+
if (isDiscoveryRootUnresolved(error))
|
|
16010
|
+
throw error;
|
|
15736
16011
|
throw new Error(`NATIVE_SKILL_DRIFT: ${error.message}`);
|
|
15737
16012
|
}
|
|
15738
16013
|
let installationInputRoots = [];
|
|
@@ -15779,7 +16054,7 @@ function pluginNeed(value, message) {
|
|
|
15779
16054
|
if (!value)
|
|
15780
16055
|
pluginRefusal(message);
|
|
15781
16056
|
}
|
|
15782
|
-
var pluginHash = (bytes) =>
|
|
16057
|
+
var pluginHash = (bytes) => createHash21("sha256").update(bytes).digest("hex");
|
|
15783
16058
|
function pluginObject(value) {
|
|
15784
16059
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
15785
16060
|
}
|
|
@@ -15850,21 +16125,21 @@ function pluginFileWitnesses(entries) {
|
|
|
15850
16125
|
return { path: item.path, mode: item.mode, size: item.bytes.byteLength, sha256: pluginHash(item.bytes) };
|
|
15851
16126
|
});
|
|
15852
16127
|
}
|
|
15853
|
-
var READ_FLAGS =
|
|
15854
|
-
var WRITE_FLAGS =
|
|
16128
|
+
var READ_FLAGS = constants12.O_RDONLY | constants12.O_NOFOLLOW | constants12.O_NONBLOCK;
|
|
16129
|
+
var WRITE_FLAGS = constants12.O_WRONLY | constants12.O_CREAT | constants12.O_EXCL | constants12.O_NOFOLLOW | constants12.O_NONBLOCK;
|
|
15855
16130
|
var uid = () => typeof process.getuid === "function" ? BigInt(process.getuid()) : undefined;
|
|
15856
16131
|
var missing = (error) => Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
15857
16132
|
function stat(path) {
|
|
15858
16133
|
try {
|
|
15859
|
-
return
|
|
16134
|
+
return lstatSync22(path, { bigint: true });
|
|
15860
16135
|
} catch (error) {
|
|
15861
16136
|
if (missing(error))
|
|
15862
16137
|
return null;
|
|
15863
16138
|
return pluginRefusal("Cannot inspect plugin filesystem entry");
|
|
15864
16139
|
}
|
|
15865
16140
|
}
|
|
15866
|
-
function
|
|
15867
|
-
pluginNeed(typeof path === "string" && path.length <= 8192 &&
|
|
16141
|
+
function canonical7(path) {
|
|
16142
|
+
pluginNeed(typeof path === "string" && path.length <= 8192 && isAbsolute17(path) && resolve16(path) === path && !/[\x00-\x1f\x7f]/.test(path), "Plugin storage paths must be canonical absolute paths");
|
|
15868
16143
|
}
|
|
15869
16144
|
function owner(stats, system = false) {
|
|
15870
16145
|
const current2 = uid();
|
|
@@ -15874,8 +16149,8 @@ function same3(left, right, identityOnly = false) {
|
|
|
15874
16149
|
pluginNeed(right && left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.uid === right.uid && left.gid === right.gid && (identityOnly || left.size === right.size && left.nlink === right.nlink && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs), "Plugin filesystem entry changed during access");
|
|
15875
16150
|
}
|
|
15876
16151
|
function ancestors(path, create = false) {
|
|
15877
|
-
|
|
15878
|
-
const result = [], parent =
|
|
16152
|
+
canonical7(path);
|
|
16153
|
+
const result = [], parent = dirname17(path), filesystemRoot = parse6(parent).root;
|
|
15879
16154
|
let current2 = filesystemRoot;
|
|
15880
16155
|
for (const segment of ["", ...parent.slice(filesystemRoot.length).split("/").filter(Boolean)]) {
|
|
15881
16156
|
if (segment)
|
|
@@ -15925,8 +16200,8 @@ function readBytes(path, maximum, kind) {
|
|
|
15925
16200
|
fileShape(before, maximum, kind);
|
|
15926
16201
|
let fd;
|
|
15927
16202
|
try {
|
|
15928
|
-
fd =
|
|
15929
|
-
const opened =
|
|
16203
|
+
fd = openSync12(path, READ_FLAGS);
|
|
16204
|
+
const opened = fstatSync12(fd, { bigint: true });
|
|
15930
16205
|
same3(before, opened);
|
|
15931
16206
|
fileShape(opened, maximum, kind);
|
|
15932
16207
|
const bytes = new Uint8Array(Number(opened.size));
|
|
@@ -15937,7 +16212,7 @@ function readBytes(path, maximum, kind) {
|
|
|
15937
16212
|
offset += count;
|
|
15938
16213
|
}
|
|
15939
16214
|
pluginNeed(readSync9(fd, new Uint8Array(1), 0, 1, null) === 0, "Plugin file grew while being read");
|
|
15940
|
-
same3(opened,
|
|
16215
|
+
same3(opened, fstatSync12(fd, { bigint: true }));
|
|
15941
16216
|
same3(opened, stat(path));
|
|
15942
16217
|
verifyAncestors(chain);
|
|
15943
16218
|
return bytes;
|
|
@@ -15947,7 +16222,7 @@ function readBytes(path, maximum, kind) {
|
|
|
15947
16222
|
return pluginRefusal("Cannot safely read plugin file");
|
|
15948
16223
|
} finally {
|
|
15949
16224
|
if (fd !== undefined)
|
|
15950
|
-
|
|
16225
|
+
closeSync12(fd);
|
|
15951
16226
|
}
|
|
15952
16227
|
}
|
|
15953
16228
|
function exactPaths(entries) {
|
|
@@ -16076,7 +16351,7 @@ function validatePluginTarget(value) {
|
|
|
16076
16351
|
for (const registration of value.registrations) {
|
|
16077
16352
|
pluginKeys(registration, ["scope", "projectPath"]);
|
|
16078
16353
|
pluginNeed(registration.scope === "user" || registration.scope === "project", "Unsupported plugin registration scope");
|
|
16079
|
-
pluginNeed(registration.scope === "user" ? registration.projectPath === null : typeof registration.projectPath === "string" &&
|
|
16354
|
+
pluginNeed(registration.scope === "user" ? registration.projectPath === null : typeof registration.projectPath === "string" && isAbsolute18(registration.projectPath) && resolve17(registration.projectPath) === registration.projectPath, "Plugin scope requires its exact project path");
|
|
16080
16355
|
const key = JSON.stringify([registration.scope, registration.projectPath]);
|
|
16081
16356
|
pluginNeed(!scopes.has(key), "Duplicate plugin registration scope");
|
|
16082
16357
|
scopes.add(key);
|
|
@@ -16084,7 +16359,7 @@ function validatePluginTarget(value) {
|
|
|
16084
16359
|
for (const key of ["native", "resolver"]) {
|
|
16085
16360
|
pluginKeys(value[key], key === "native" ? ["version", "executable", "digest"] : ["executable", "digest"]);
|
|
16086
16361
|
pluginText(value[key].executable);
|
|
16087
|
-
pluginNeed(
|
|
16362
|
+
pluginNeed(isAbsolute18(value[key].executable) && resolve17(value[key].executable) === value[key].executable, "Plugin executable must have a canonical absolute path");
|
|
16088
16363
|
pluginDigest(value[key].digest);
|
|
16089
16364
|
}
|
|
16090
16365
|
pluginNeed(["2.1.274", "2.1.276"].includes(value.native.version), "Plugin admission requires a certified Claude command-source runtime (2.1.274 or 2.1.276)");
|
|
@@ -16222,10 +16497,10 @@ function validatePlan(value) {
|
|
|
16222
16497
|
pluginNeed(observedEvidenceDigest(plan.observation) === plan.evidenceDigest, "Plugin receipt observed evidence changed");
|
|
16223
16498
|
pluginNeed(identityDigest(plan) === plan.planDigest, "Plugin receipt immutable identity changed");
|
|
16224
16499
|
}
|
|
16225
|
-
var
|
|
16500
|
+
var quote22 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
16226
16501
|
var resolverGuard = 'exec 9<"$1"; actual=$(/usr/bin/sha256sum /proc/self/fd/9); actual=${actual%% *}; [ "sha256:$actual" = "$2" ]; exec /proc/self/fd/9 integration plugin resolve --binding "$3"';
|
|
16227
16502
|
function pluginResolverCommand(binding) {
|
|
16228
|
-
return `${
|
|
16503
|
+
return `${quote22("/bin/sh")} -eu -c ${quote22(resolverGuard)} plugin-resolver ${quote22(binding.target.resolver.executable)} ${quote22(binding.target.resolver.digest)} ${quote22(bindingId(binding))}`;
|
|
16229
16504
|
}
|
|
16230
16505
|
function pluginBindingPath(storeRoot, id) {
|
|
16231
16506
|
pluginNeed(/^[a-f0-9]{64}$/.test(id), "Invalid plugin binding identifier");
|
|
@@ -16267,25 +16542,25 @@ function validateManagedPluginWitnesses(value) {
|
|
|
16267
16542
|
pluginNeed(typeof item.bindingId === "string" && /^[a-f0-9]{64}$/.test(item.bindingId) && !seen.has(item.bindingId), "Invalid or duplicate managed plugin witness");
|
|
16268
16543
|
seen.add(item.bindingId);
|
|
16269
16544
|
pluginText(item.storeRoot);
|
|
16270
|
-
pluginNeed(
|
|
16545
|
+
pluginNeed(isAbsolute19(item.storeRoot) && resolve18(item.storeRoot) === item.storeRoot, "Invalid plugin receipt store path");
|
|
16271
16546
|
}
|
|
16272
16547
|
}
|
|
16273
16548
|
function safe3(path) {
|
|
16274
16549
|
pluginText(path);
|
|
16275
|
-
pluginNeed(
|
|
16276
|
-
for (let at = path;; at =
|
|
16277
|
-
pluginNeed(!
|
|
16278
|
-
if (at ===
|
|
16550
|
+
pluginNeed(isAbsolute19(path) && resolve18(path) === path, "Invalid plugin registry path");
|
|
16551
|
+
for (let at = path;; at = dirname18(at)) {
|
|
16552
|
+
pluginNeed(!lstatSync23(at, { throwIfNoEntry: false })?.isSymbolicLink(), "Plugin registry path traverses a symlink");
|
|
16553
|
+
if (at === dirname18(at))
|
|
16279
16554
|
break;
|
|
16280
16555
|
}
|
|
16281
16556
|
}
|
|
16282
16557
|
function readRegistry(path) {
|
|
16283
16558
|
safe3(path);
|
|
16284
|
-
const initial =
|
|
16559
|
+
const initial = lstatSync23(path);
|
|
16285
16560
|
pluginNeed(initial.isFile() && initial.size <= 1024 * 1024, "Plugin registry is not a bounded regular file");
|
|
16286
|
-
const fd =
|
|
16561
|
+
const fd = openSync13(path, constants13.O_RDONLY | constants13.O_NOFOLLOW | constants13.O_NONBLOCK);
|
|
16287
16562
|
try {
|
|
16288
|
-
const opened =
|
|
16563
|
+
const opened = fstatSync13(fd);
|
|
16289
16564
|
pluginNeed(opened.isFile() && opened.ino === initial.ino && opened.dev === initial.dev, "Plugin registry changed during open");
|
|
16290
16565
|
const bytes = Buffer.alloc(1024 * 1024 + 1);
|
|
16291
16566
|
let length = 0;
|
|
@@ -16295,7 +16570,7 @@ function readRegistry(path) {
|
|
|
16295
16570
|
break;
|
|
16296
16571
|
length += count;
|
|
16297
16572
|
}
|
|
16298
|
-
const after =
|
|
16573
|
+
const after = fstatSync13(fd), current2 = lstatSync23(path);
|
|
16299
16574
|
safe3(path);
|
|
16300
16575
|
pluginNeed(length <= 1024 * 1024 && length === opened.size && after.size === opened.size && after.mtimeMs === opened.mtimeMs && after.ctimeMs === opened.ctimeMs && current2.dev === opened.dev && current2.ino === opened.ino && current2.mtimeMs === opened.mtimeMs && current2.ctimeMs === opened.ctimeMs, "Plugin registry changed during read");
|
|
16301
16576
|
let value;
|
|
@@ -16307,7 +16582,7 @@ function readRegistry(path) {
|
|
|
16307
16582
|
pluginNeed(pluginObject(value) && value.version === 2 && pluginObject(value.plugins), "Unsupported native plugin registry schema");
|
|
16308
16583
|
return { value, rawDigest: pluginHash(bytes.subarray(0, length)) };
|
|
16309
16584
|
} finally {
|
|
16310
|
-
|
|
16585
|
+
closeSync13(fd);
|
|
16311
16586
|
}
|
|
16312
16587
|
}
|
|
16313
16588
|
function nativeVersionMatches(version, receipt) {
|
|
@@ -16325,7 +16600,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16325
16600
|
seen.add(target.pluginId);
|
|
16326
16601
|
const rows = plugins[target.pluginId];
|
|
16327
16602
|
pluginNeed(Array.isArray(rows) && rows.length === target.registrations.length, "Managed plugin registration membership changed");
|
|
16328
|
-
const [name, market] = target.pluginId.split("@"), cacheRoot = join31(
|
|
16603
|
+
const [name, market] = target.pluginId.split("@"), cacheRoot = join31(dirname18(path), "cache", market, name);
|
|
16329
16604
|
const scopes = new Set, approvals = new Map, currentFiles = new Map;
|
|
16330
16605
|
plugins[target.pluginId] = rows.map((row) => {
|
|
16331
16606
|
pluginNeed(pluginObject(row), "Invalid managed plugin registration");
|
|
@@ -16341,7 +16616,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16341
16616
|
pluginNeed(/^(?:[A-Za-z0-9][A-Za-z0-9._+-]*-)?[a-f0-9]{12}$/.test(row.version) && row.installPath === join31(cacheRoot, row.version), "Managed plugin cache path or version is outside its registration");
|
|
16342
16617
|
const approval = (producer) => {
|
|
16343
16618
|
pluginText(producer);
|
|
16344
|
-
const digest = `sha256:${
|
|
16619
|
+
const digest = `sha256:${basename9(producer)}`;
|
|
16345
16620
|
const receipt2 = readPluginAdmissionReceipt(witness.storeRoot, witness.bindingId, digest);
|
|
16346
16621
|
pluginNeed(receipt2.materializedPath === producer, "Managed producer path is not an approved immutable projection");
|
|
16347
16622
|
if (!verified.has(producer)) {
|
|
@@ -16368,7 +16643,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16368
16643
|
return Object.fromEntries(Object.entries(row).filter(([key]) => !["version", "installPath", "sourceProducerPath", "previousProducerPaths", "lastUpdated"].includes(key)));
|
|
16369
16644
|
});
|
|
16370
16645
|
safe3(cacheRoot);
|
|
16371
|
-
const before =
|
|
16646
|
+
const before = lstatSync23(cacheRoot);
|
|
16372
16647
|
pluginNeed(before.isDirectory(), "Invalid managed plugin cache root");
|
|
16373
16648
|
const directory = opendirSync5(cacheRoot), names = [];
|
|
16374
16649
|
try {
|
|
@@ -16391,7 +16666,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16391
16666
|
}
|
|
16392
16667
|
for (const row of rows)
|
|
16393
16668
|
pluginNeed(names.includes(row.version), "Managed native plugin installation is missing");
|
|
16394
|
-
const after =
|
|
16669
|
+
const after = lstatSync23(cacheRoot);
|
|
16395
16670
|
safe3(cacheRoot);
|
|
16396
16671
|
pluginNeed(before.dev === after.dev && before.ino === after.ino && before.mtimeMs === after.mtimeMs && before.ctimeMs === after.ctimeMs, "Managed cache version membership changed during verification");
|
|
16397
16672
|
}
|
|
@@ -16399,35 +16674,35 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16399
16674
|
return pluginHash(JSON.stringify(snapshot2.value));
|
|
16400
16675
|
}
|
|
16401
16676
|
var CLAUDE_MARKETPLACE_REGISTRY_LIMITS = Object.freeze({ bytes: 1024 * 1024, rows: 1024, depth: 32, nodes: 65536, stringCharacters: 16384, pathCharacters: 4096 });
|
|
16402
|
-
function
|
|
16677
|
+
function need7(value, reason2) {
|
|
16403
16678
|
if (!value)
|
|
16404
|
-
throw new Error(`Claude marketplace registry ${
|
|
16679
|
+
throw new Error(`Claude marketplace registry ${reason2}`);
|
|
16405
16680
|
}
|
|
16406
16681
|
function absolutePath3(value) {
|
|
16407
|
-
|
|
16682
|
+
need7(typeof value === "string" && value.length > 0 && value.length <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.pathCharacters && !/[\x00-\x1f\x7f]/.test(value) && isAbsolute20(value) && resolve19(value) === value, "requires a normalized absolute path");
|
|
16408
16683
|
}
|
|
16409
16684
|
var sameFile2 = (a, b) => a.dev === b.dev && a.ino === b.ino && a.mode === b.mode && a.uid === b.uid && a.gid === b.gid && a.nlink === b.nlink && a.size === b.size && a.mtimeNs === b.mtimeNs && a.ctimeNs === b.ctimeNs;
|
|
16410
16685
|
function parents2(path) {
|
|
16411
16686
|
const result = [];
|
|
16412
|
-
for (let at =
|
|
16413
|
-
const stat2 =
|
|
16414
|
-
|
|
16687
|
+
for (let at = dirname19(path);; at = dirname19(at)) {
|
|
16688
|
+
const stat2 = lstatSync24(at, { bigint: true });
|
|
16689
|
+
need7(stat2.isDirectory() && !stat2.isSymbolicLink(), "path traverses a symlink or non-directory");
|
|
16415
16690
|
result.push([at, stat2]);
|
|
16416
|
-
if (at ===
|
|
16691
|
+
if (at === dirname19(at))
|
|
16417
16692
|
return result;
|
|
16418
16693
|
}
|
|
16419
16694
|
}
|
|
16420
16695
|
function readRegistry2(path, budget2) {
|
|
16421
16696
|
absolutePath3(path);
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
const ancestors2 = parents2(path), initial =
|
|
16425
|
-
|
|
16426
|
-
|
|
16427
|
-
const fd =
|
|
16697
|
+
need7(basename10(path) === "known_marketplaces.json", "requires known_marketplaces.json");
|
|
16698
|
+
need7(Number.isSafeInteger(budget2.remaining) && budget2.remaining >= 0, "has an invalid byte budget");
|
|
16699
|
+
const ancestors2 = parents2(path), initial = lstatSync24(path, { bigint: true });
|
|
16700
|
+
need7(initial.isFile() && !initial.isSymbolicLink() && initial.size <= BigInt(CLAUDE_MARKETPLACE_REGISTRY_LIMITS.bytes), "is not a bounded regular file");
|
|
16701
|
+
need7(initial.size <= BigInt(budget2.remaining), "exceeds its aggregate byte limit");
|
|
16702
|
+
const fd = openSync14(path, constants14.O_RDONLY | constants14.O_NOFOLLOW | constants14.O_NONBLOCK);
|
|
16428
16703
|
try {
|
|
16429
|
-
const opened =
|
|
16430
|
-
|
|
16704
|
+
const opened = fstatSync14(fd, { bigint: true });
|
|
16705
|
+
need7(opened.isFile() && sameFile2(initial, opened), "changed during open");
|
|
16431
16706
|
const bytes = Buffer.alloc(Number(opened.size) + 1);
|
|
16432
16707
|
let length = 0;
|
|
16433
16708
|
while (length < bytes.length) {
|
|
@@ -16436,11 +16711,11 @@ function readRegistry2(path, budget2) {
|
|
|
16436
16711
|
break;
|
|
16437
16712
|
length += count;
|
|
16438
16713
|
}
|
|
16439
|
-
const after =
|
|
16440
|
-
|
|
16714
|
+
const after = fstatSync14(fd, { bigint: true }), current2 = lstatSync24(path, { bigint: true });
|
|
16715
|
+
need7(current2.isFile() && sameFile2(opened, after) && sameFile2(after, current2) && BigInt(length) === opened.size, "changed during read");
|
|
16441
16716
|
for (const [ancestor, before] of ancestors2) {
|
|
16442
|
-
const now =
|
|
16443
|
-
|
|
16717
|
+
const now = lstatSync24(ancestor, { bigint: true });
|
|
16718
|
+
need7(now.isDirectory() && before.dev === now.dev && before.ino === now.ino && before.mode === now.mode, "parent changed during read");
|
|
16444
16719
|
}
|
|
16445
16720
|
budget2.remaining -= length;
|
|
16446
16721
|
try {
|
|
@@ -16449,7 +16724,7 @@ function readRegistry2(path, budget2) {
|
|
|
16449
16724
|
throw new Error("Claude marketplace registry is not strict UTF-8");
|
|
16450
16725
|
}
|
|
16451
16726
|
} finally {
|
|
16452
|
-
|
|
16727
|
+
closeSync14(fd);
|
|
16453
16728
|
}
|
|
16454
16729
|
}
|
|
16455
16730
|
function parse7(text2) {
|
|
@@ -16460,7 +16735,7 @@ function parse7(text2) {
|
|
|
16460
16735
|
at++;
|
|
16461
16736
|
};
|
|
16462
16737
|
function string() {
|
|
16463
|
-
|
|
16738
|
+
need7(text2[at] === '"', "contains invalid JSON");
|
|
16464
16739
|
const start = at++;
|
|
16465
16740
|
while (at < text2.length) {
|
|
16466
16741
|
const character = text2[at++];
|
|
@@ -16471,7 +16746,7 @@ function parse7(text2) {
|
|
|
16471
16746
|
} catch {
|
|
16472
16747
|
throw new Error("Claude marketplace registry contains invalid JSON string");
|
|
16473
16748
|
}
|
|
16474
|
-
|
|
16749
|
+
need7(value2.length <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.stringCharacters, "exceeds its string limit");
|
|
16475
16750
|
return value2;
|
|
16476
16751
|
}
|
|
16477
16752
|
if (character === "\\")
|
|
@@ -16480,7 +16755,7 @@ function parse7(text2) {
|
|
|
16480
16755
|
throw new Error("Claude marketplace registry contains an unterminated JSON string");
|
|
16481
16756
|
}
|
|
16482
16757
|
function value(depth) {
|
|
16483
|
-
|
|
16758
|
+
need7(depth <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.depth && ++nodes <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.nodes, "exceeds its nesting or node limit");
|
|
16484
16759
|
space();
|
|
16485
16760
|
const character = text2[at];
|
|
16486
16761
|
if (character === '"')
|
|
@@ -16494,17 +16769,17 @@ function parse7(text2) {
|
|
|
16494
16769
|
if (object6) {
|
|
16495
16770
|
space();
|
|
16496
16771
|
const key = string();
|
|
16497
|
-
|
|
16772
|
+
need7(!keys.has(key), "contains a duplicate JSON key");
|
|
16498
16773
|
keys.add(key);
|
|
16499
16774
|
space();
|
|
16500
|
-
|
|
16775
|
+
need7(text2[at++] === ":", "contains invalid JSON");
|
|
16501
16776
|
entries.push([key, value(depth + 1)]);
|
|
16502
16777
|
} else
|
|
16503
16778
|
items.push(value(depth + 1));
|
|
16504
16779
|
space();
|
|
16505
16780
|
if (text2[at] === end)
|
|
16506
16781
|
break;
|
|
16507
|
-
|
|
16782
|
+
need7(text2[at++] === ",", "contains invalid JSON");
|
|
16508
16783
|
}
|
|
16509
16784
|
at++;
|
|
16510
16785
|
return object6 ? { kind: "object", entries } : { kind: "array", items };
|
|
@@ -16516,73 +16791,73 @@ function parse7(text2) {
|
|
|
16516
16791
|
}
|
|
16517
16792
|
numberPattern.lastIndex = at;
|
|
16518
16793
|
const number = numberPattern.exec(text2);
|
|
16519
|
-
|
|
16794
|
+
need7(number, "contains invalid JSON");
|
|
16520
16795
|
at += number[0].length;
|
|
16521
16796
|
return { kind: "number", value: number[0] };
|
|
16522
16797
|
}
|
|
16523
16798
|
const root2 = value(0);
|
|
16524
16799
|
space();
|
|
16525
|
-
|
|
16526
|
-
|
|
16800
|
+
need7(at === text2.length && root2.kind === "object", "requires a JSON object without trailing content");
|
|
16801
|
+
need7(root2.entries.length <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.rows, "exceeds its marketplace row limit");
|
|
16527
16802
|
return root2;
|
|
16528
16803
|
}
|
|
16529
16804
|
function exactKeys(value, keys) {
|
|
16530
16805
|
return value?.kind === "object" && value.entries.length === keys.length && value.entries.every(([key]) => keys.includes(key));
|
|
16531
16806
|
}
|
|
16532
|
-
var
|
|
16807
|
+
var field2 = (object6, key) => object6.entries.find(([name]) => name === key)?.[1];
|
|
16533
16808
|
function textField(value) {
|
|
16534
|
-
|
|
16809
|
+
need7(value?.kind === "string" && value.value.length > 0 && !/[\x00-\x1f\x7f]/.test(value.value), "contains an invalid recognized field");
|
|
16535
16810
|
return value.value;
|
|
16536
16811
|
}
|
|
16537
16812
|
function normalizeRow(row, version = 1) {
|
|
16538
16813
|
if (!exactKeys(row, ["source", "installLocation", "lastUpdated"])) {
|
|
16539
16814
|
if (version !== 2 || !exactKeys(row, ["source", "installLocation", "lastUpdated", "autoUpdate"]))
|
|
16540
16815
|
return;
|
|
16541
|
-
const autoUpdate =
|
|
16542
|
-
|
|
16816
|
+
const autoUpdate = field2(row, "autoUpdate");
|
|
16817
|
+
need7(autoUpdate?.kind === "literal" && (autoUpdate.value === "true" || autoUpdate.value === "false"), "contains an invalid automatic-update preference");
|
|
16543
16818
|
}
|
|
16544
|
-
const source =
|
|
16819
|
+
const source = field2(row, "source");
|
|
16545
16820
|
if (source?.kind !== "object")
|
|
16546
16821
|
return;
|
|
16547
|
-
const type =
|
|
16822
|
+
const type = field2(source, "source");
|
|
16548
16823
|
if (type?.kind !== "string" || !["github", "directory"].includes(type.value))
|
|
16549
16824
|
return;
|
|
16550
16825
|
const location = type.value === "github" ? "repo" : "path";
|
|
16551
16826
|
if (!exactKeys(source, ["source", location]))
|
|
16552
16827
|
return;
|
|
16553
|
-
const sourceLocation = textField(
|
|
16828
|
+
const sourceLocation = textField(field2(source, location));
|
|
16554
16829
|
if (type.value === "directory")
|
|
16555
16830
|
absolutePath3(sourceLocation);
|
|
16556
|
-
absolutePath3(textField(
|
|
16557
|
-
const updated = textField(
|
|
16558
|
-
|
|
16831
|
+
absolutePath3(textField(field2(row, "installLocation")));
|
|
16832
|
+
const updated = textField(field2(row, "lastUpdated"));
|
|
16833
|
+
need7(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(updated), "contains an invalid recognized update timestamp");
|
|
16559
16834
|
const millis = Date.parse(updated);
|
|
16560
|
-
|
|
16835
|
+
need7(Number.isFinite(millis) && new Date(millis).toISOString() === updated, "contains an invalid recognized update timestamp");
|
|
16561
16836
|
row.entries = row.entries.map(([key, value]) => [key, key === "lastUpdated" ? { kind: "validated-update-time" } : value]);
|
|
16562
16837
|
}
|
|
16563
16838
|
function captureClaudeMarketplaceRegistry(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
16564
16839
|
const value = parse7(readRegistry2(path, budget2));
|
|
16565
16840
|
for (const [, row] of value.entries)
|
|
16566
16841
|
normalizeRow(row);
|
|
16567
|
-
const
|
|
16568
|
-
return { path, hashMode: "claude-marketplace-registry", sha256:
|
|
16842
|
+
const sha2563 = createHash23("sha256").update("hasna.skills.claude-marketplace-registry.v1\x00").update(JSON.stringify(value)).digest("hex");
|
|
16843
|
+
return { path, hashMode: "claude-marketplace-registry", sha256: sha2563 };
|
|
16569
16844
|
}
|
|
16570
16845
|
function captureClaudeMarketplaceRegistryV2(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
16571
16846
|
const value = parse7(readRegistry2(path, budget2));
|
|
16572
16847
|
for (const [, row] of value.entries)
|
|
16573
16848
|
normalizeRow(row, 2);
|
|
16574
|
-
const
|
|
16575
|
-
return { path, hashMode: "claude-marketplace-registry-v2", sha256:
|
|
16849
|
+
const sha2563 = createHash23("sha256").update("hasna.skills.claude-marketplace-registry.v2\x00").update(JSON.stringify(value)).digest("hex");
|
|
16850
|
+
return { path, hashMode: "claude-marketplace-registry-v2", sha256: sha2563 };
|
|
16576
16851
|
}
|
|
16577
16852
|
var events = { UserPromptSubmit: ["userPromptSubmit", "user_prompt_submit"], SessionStart: ["sessionStart", "session_start"], SubagentStart: ["subagentStart", "subagent_start"] };
|
|
16578
16853
|
var matchedEvents = { ...events, PreToolUse: ["preToolUse", "pre_tool_use"] };
|
|
16579
16854
|
var proofs = new WeakMap;
|
|
16580
|
-
var sha4 = (text2) =>
|
|
16855
|
+
var sha4 = (text2) => createHash24("sha256").update(text2).digest("hex");
|
|
16581
16856
|
var fields = [...CODEX_DISCOVERY_PROJECTION_FIELDS];
|
|
16582
16857
|
var proofs2 = new WeakMap;
|
|
16583
16858
|
function assertCodexHookDiscoveryRecovery(binding, witness) {
|
|
16584
16859
|
const proof = proofs2.get(witness);
|
|
16585
|
-
|
|
16860
|
+
need6(!!proof && binding.agent === "codex" && witness.discoverySha256 === sha4(JSON.stringify(binding)), "RECONCILE_DISCOVERY_RECOVERY_CHANGED");
|
|
16586
16861
|
unchanged2(proof.before);
|
|
16587
16862
|
unchanged2(proof.current);
|
|
16588
16863
|
proof.recheckAdditions();
|
|
@@ -16591,10 +16866,41 @@ function verifiesCodexHookDiscoverySource(binding, source, currentDigest, witnes
|
|
|
16591
16866
|
if (!witness || source.path !== witness.configPath || source.hashMode !== "bytes")
|
|
16592
16867
|
return false;
|
|
16593
16868
|
assertCodexHookDiscoveryRecovery(binding, witness);
|
|
16594
|
-
|
|
16869
|
+
need6(source.sha256 === witness.beforeSha256 && currentDigest === witness.currentSha256, "RECONCILE_DISCOVERY_RECOVERY_CHANGED");
|
|
16595
16870
|
return true;
|
|
16596
16871
|
}
|
|
16597
|
-
var
|
|
16872
|
+
var DISCOVERY_RUNTIME_COMMANDS = Object.freeze({ gemini: "gemini" });
|
|
16873
|
+
var DISCOVERY_ROOT_UNRESOLVED = "DISCOVERY_ROOT_UNRESOLVED";
|
|
16874
|
+
function discoveryRootUnresolved(agent, command, detail) {
|
|
16875
|
+
return new Error(`${DISCOVERY_ROOT_UNRESOLVED}: ${agent} discovery cannot resolve its "${command}" executable: ${detail}. The reviewed discovery is unchanged; this is an environment gap, not drift.`);
|
|
16876
|
+
}
|
|
16877
|
+
function isDiscoveryRootUnresolved(error) {
|
|
16878
|
+
return error instanceof Error && error.message.startsWith(`${DISCOVERY_ROOT_UNRESOLVED}: `);
|
|
16879
|
+
}
|
|
16880
|
+
var quotedPath = (path) => JSON.stringify(path).replace(/[^\x20-\x7e]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
16881
|
+
var realpathOrNull = (path) => {
|
|
16882
|
+
try {
|
|
16883
|
+
return realpathSync11(path);
|
|
16884
|
+
} catch {
|
|
16885
|
+
return null;
|
|
16886
|
+
}
|
|
16887
|
+
};
|
|
16888
|
+
function discoveryExecutable(agent) {
|
|
16889
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[agent];
|
|
16890
|
+
const found = command ? Bun.which(command) : null;
|
|
16891
|
+
if (!command || !found)
|
|
16892
|
+
return null;
|
|
16893
|
+
const path = resolve20(found), target = realpathOrNull(path);
|
|
16894
|
+
return target === null ? null : { command, path, target };
|
|
16895
|
+
}
|
|
16896
|
+
function recordedDiscoveryExecutable(agent, recorded) {
|
|
16897
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[agent];
|
|
16898
|
+
if (!command || recorded.command !== command)
|
|
16899
|
+
throw new Error(`Recorded ${agent} discovery executable names another command`);
|
|
16900
|
+
const target = realpathOrNull(recorded.path);
|
|
16901
|
+
return target === null ? null : { command, path: recorded.path, target };
|
|
16902
|
+
}
|
|
16903
|
+
var digest = (text2) => createHash25("sha256").update(text2).digest("hex");
|
|
16598
16904
|
function parseConfig(text2, path, toml = false) {
|
|
16599
16905
|
try {
|
|
16600
16906
|
const value = toml ? Bun.TOML.parse(text2) : JSON.parse(text2);
|
|
@@ -16606,12 +16912,12 @@ function parseConfig(text2, path, toml = false) {
|
|
|
16606
16912
|
}
|
|
16607
16913
|
}
|
|
16608
16914
|
function safe4(path) {
|
|
16609
|
-
if (!
|
|
16915
|
+
if (!isAbsolute21(path) || path.includes("\x00"))
|
|
16610
16916
|
throw new Error("Expected an absolute native discovery path");
|
|
16611
|
-
for (let cursor = path;; cursor =
|
|
16612
|
-
if (
|
|
16917
|
+
for (let cursor = path;; cursor = dirname20(cursor)) {
|
|
16918
|
+
if (lstatSync25(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
16613
16919
|
throw new Error(`Refusing symlink native discovery input: ${cursor}`);
|
|
16614
|
-
if (
|
|
16920
|
+
if (dirname20(cursor) === cursor)
|
|
16615
16921
|
break;
|
|
16616
16922
|
}
|
|
16617
16923
|
}
|
|
@@ -16619,18 +16925,18 @@ function read2(path, changes) {
|
|
|
16619
16925
|
safe4(path);
|
|
16620
16926
|
if (changes?.has(path))
|
|
16621
16927
|
return changes.get(path);
|
|
16622
|
-
const stat2 =
|
|
16928
|
+
const stat2 = lstatSync25(path, { throwIfNoEntry: false });
|
|
16623
16929
|
if (!stat2)
|
|
16624
16930
|
return null;
|
|
16625
16931
|
if (!stat2.isFile() || stat2.size > 16 * 1024 * 1024)
|
|
16626
16932
|
throw new Error(`Unsupported or oversized native discovery input: ${path}`);
|
|
16627
|
-
return
|
|
16933
|
+
return readFileSync20(path, "utf8");
|
|
16628
16934
|
}
|
|
16629
16935
|
function projectNativeDiscoveryFields(text2, format, fields2, path) {
|
|
16630
16936
|
const object6 = format === "yaml" ? parseHermesConfig(text2) : parseConfig(text2, path, format === "toml");
|
|
16631
16937
|
if (!object6 || typeof object6 !== "object" || Array.isArray(object6))
|
|
16632
16938
|
throw new Error("Expected native discovery configuration object");
|
|
16633
|
-
return digest(JSON.stringify(Object.fromEntries(fields2.map((
|
|
16939
|
+
return digest(JSON.stringify(Object.fromEntries(fields2.map((field3) => [field3, object6[field3] ?? null]))));
|
|
16634
16940
|
}
|
|
16635
16941
|
function isSupersededSettingsProjection(agent, configPath, source) {
|
|
16636
16942
|
if (agent === "sumi")
|
|
@@ -16659,21 +16965,29 @@ function projected(source, changes, budget2 = discoveryByteBudget()) {
|
|
|
16659
16965
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16660
16966
|
return changes?.has(source.path) ? (source.hashMode === "codex-settings-v4" ? hashCodexSettingsReplacementV4 : source.hashMode === "codex-settings-v3" ? hashCodexSettingsReplacementV3 : source.hashMode === "codex-settings-v2" ? hashCodexSettingsReplacementV2 : hashCodexSettingsReplacement)(changes.get(source.path), budget2) : current2;
|
|
16661
16967
|
}
|
|
16662
|
-
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || source.hashMode === "claude-settings-v3") {
|
|
16968
|
+
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4")) {
|
|
16663
16969
|
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || typeof source.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(source.sha256))
|
|
16664
16970
|
throw new Error("Claude settings witnesses require exact typed metadata");
|
|
16665
|
-
const current2 = (source.hashMode === "claude-settings-v3" ? captureClaudeSettingsV3 : source.hashMode === "claude-settings-v2" ? captureClaudeSettingsV2 : captureClaudeSettings)(source.path, budget2).sha256;
|
|
16971
|
+
const current2 = (source.hashMode === "claude-settings-v4" ? captureClaudeSettingsV4 : source.hashMode === "claude-settings-v3" ? captureClaudeSettingsV3 : source.hashMode === "claude-settings-v2" ? captureClaudeSettingsV2 : captureClaudeSettings)(source.path, budget2).sha256;
|
|
16666
16972
|
if (current2 !== source.sha256)
|
|
16667
16973
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16668
|
-
return changes?.has(source.path) ? (source.hashMode === "claude-settings-v3" ? hashClaudeSettingsReplacementV3 : source.hashMode === "claude-settings-v2" ? hashClaudeSettingsReplacementV2 : hashClaudeSettingsReplacement)(changes.get(source.path), budget2) : current2;
|
|
16974
|
+
return changes?.has(source.path) ? (source.hashMode === "claude-settings-v4" ? hashClaudeSettingsReplacementV4 : source.hashMode === "claude-settings-v3" ? hashClaudeSettingsReplacementV3 : source.hashMode === "claude-settings-v2" ? hashClaudeSettingsReplacementV2 : hashClaudeSettingsReplacement)(changes.get(source.path), budget2) : current2;
|
|
16669
16975
|
}
|
|
16670
16976
|
if (source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2") {
|
|
16671
16977
|
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || typeof source.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(source.sha256) || changes?.has(source.path))
|
|
16672
16978
|
throw new Error("Claude marketplace witnesses require an exact reviewed registry without synthetic changes");
|
|
16673
|
-
const
|
|
16674
|
-
if (
|
|
16979
|
+
const sha2563 = (source.hashMode === "claude-marketplace-registry-v2" ? captureClaudeMarketplaceRegistryV2 : captureClaudeMarketplaceRegistry)(source.path, budget2).sha256;
|
|
16980
|
+
if (sha2563 !== source.sha256)
|
|
16675
16981
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16676
|
-
return
|
|
16982
|
+
return sha2563;
|
|
16983
|
+
}
|
|
16984
|
+
if (source.hashMode === "claude-marketplace-entry-v1") {
|
|
16985
|
+
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || typeof source.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(source.sha256) || changes?.has(source.path) || !claudeMarketplaceEntrySourceValid(source))
|
|
16986
|
+
throw new Error("Claude marketplace entry witnesses require an exact reviewed entry without synthetic changes");
|
|
16987
|
+
const sha2563 = captureClaudeMarketplaceEntry(source.path, source.marketplace, source.plugin, budget2).sha256;
|
|
16988
|
+
if (sha2563 !== source.sha256)
|
|
16989
|
+
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16990
|
+
return sha2563;
|
|
16677
16991
|
}
|
|
16678
16992
|
if (source.hashMode === "claude-plugin-registry") {
|
|
16679
16993
|
if (source.format !== undefined || source.fields !== undefined || !source.managedPlugins || changes?.has(source.path))
|
|
@@ -16710,9 +17024,9 @@ function absentCodexSkillRoots(binding) {
|
|
|
16710
17024
|
return [];
|
|
16711
17025
|
if (binding.agent !== "codex" || !Array.isArray(controls) || controls.length > 4096)
|
|
16712
17026
|
throw new Error("Invalid disabled Codex discovery proof");
|
|
16713
|
-
if (binding.method !== "reviewed" || controls.every((control) =>
|
|
17027
|
+
if (binding.method !== "reviewed" || controls.every((control) => lstatSync25(control.pluginParent, { throwIfNoEntry: false })))
|
|
16714
17028
|
return [];
|
|
16715
|
-
const cache =
|
|
17029
|
+
const cache = dirname20(dirname20(controls[0].pluginParent)), config = join32(dirname20(dirname20(cache)), "config.toml");
|
|
16716
17030
|
const source = binding.sources.find((source2) => source2.path === config && source2.sha256 !== null && source2.format === undefined && source2.fields === undefined);
|
|
16717
17031
|
if (!source || projected(source) !== source.sha256)
|
|
16718
17032
|
throw new Error("Missing current disabled Codex configuration witness");
|
|
@@ -16720,7 +17034,7 @@ function absentCodexSkillRoots(binding) {
|
|
|
16720
17034
|
return [...new Set(controls.map((control) => control.pluginParent))].filter((parent) => !codexDirectHookSelects(cache, parent) && absentDisabledCodexPluginParent(cache, parent, controls, rules));
|
|
16721
17035
|
}
|
|
16722
17036
|
function codexDirectHookSelects(cache, root2) {
|
|
16723
|
-
const codex =
|
|
17037
|
+
const codex = dirname20(dirname20(cache)), config = Bun.TOML.parse(read2(join32(codex, "config.toml")) ?? "");
|
|
16724
17038
|
const hooks = read2(join32(codex, "hooks.json"));
|
|
16725
17039
|
if (hooks !== null)
|
|
16726
17040
|
hashNativeJsonControls(hooks);
|
|
@@ -16733,7 +17047,7 @@ function retiredCodexRoots(binding) {
|
|
|
16733
17047
|
const controls = binding.codexDisabledPluginSkills;
|
|
16734
17048
|
if (binding.agent !== "codex" || binding.method !== "reviewed" || !Array.isArray(controls) || !controls.length || !Array.isArray(proof.roots) || proof.roots.length > AGENT_POLICY_LIMITS.discoveryRoots || new Set(proof.roots).size !== proof.roots.length || !Array.isArray(proof.directories) || proof.parents !== undefined && (!Array.isArray(proof.parents) || proof.parents.length > AGENT_POLICY_LIMITS.discoveryRoots || new Set(proof.parents).size !== proof.parents.length) || !proof.roots.length && !proof.parents?.length)
|
|
16735
17049
|
throw new Error("Invalid retired Codex materialization proof");
|
|
16736
|
-
const cache =
|
|
17050
|
+
const cache = dirname20(dirname20(controls[0].pluginParent)), config = join32(dirname20(dirname20(cache)), "config.toml");
|
|
16737
17051
|
const source = binding.sources.find((source2) => source2.path === config && source2.sha256 !== null && source2.format === undefined && source2.fields === undefined);
|
|
16738
17052
|
if (!source || projected(source) !== source.sha256)
|
|
16739
17053
|
throw new Error("Missing current retired Codex configuration witness");
|
|
@@ -16762,9 +17076,9 @@ function absentRetiredClaudeRoots(binding) {
|
|
|
16762
17076
|
continue;
|
|
16763
17077
|
const root2 = join32(cache, ...parts.slice(0, 3));
|
|
16764
17078
|
safe4(root2);
|
|
16765
|
-
if (
|
|
17079
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16766
17080
|
continue;
|
|
16767
|
-
const claude =
|
|
17081
|
+
const claude = dirname20(dirname20(cache)), settings = join32(claude, "settings.json"), registry = join32(claude, "plugins/installed_plugins.json");
|
|
16768
17082
|
const full = (path) => binding.sources.find((item) => item.path === path && item.sha256 !== null && item.format === undefined && item.fields === undefined);
|
|
16769
17083
|
const configSource = full(settings), registrySource = full(registry);
|
|
16770
17084
|
if (!configSource || !registrySource || projected(configSource) !== configSource.sha256 || projected(registrySource) !== registrySource.sha256)
|
|
@@ -16777,17 +17091,41 @@ function absentRetiredClaudeRoots(binding) {
|
|
|
16777
17091
|
continue;
|
|
16778
17092
|
if (JSON.stringify(config.hooks ?? {}).includes(root2))
|
|
16779
17093
|
continue;
|
|
17094
|
+
const registrationScope = (row) => {
|
|
17095
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
17096
|
+
return null;
|
|
17097
|
+
const value = row;
|
|
17098
|
+
if (typeof value.installPath !== "string" || /[\x00-\x1f\x7f]/.test(value.installPath) || !isAbsolute21(value.installPath) || resolve20(value.installPath) !== value.installPath || value.installPath.length > AGENT_POLICY_LIMITS.pathCharacters)
|
|
17099
|
+
return null;
|
|
17100
|
+
if (value.scope === "user")
|
|
17101
|
+
return value.projectPath === undefined || value.projectPath === null ? "user\x00" : null;
|
|
17102
|
+
if (value.scope === "project")
|
|
17103
|
+
return typeof value.projectPath === "string" && !/[\x00-\x1f\x7f]/.test(value.projectPath) && value.projectPath.length <= AGENT_POLICY_LIMITS.pathCharacters && isAbsolute21(value.projectPath) && resolve20(value.projectPath) === value.projectPath ? `project\x00${value.projectPath}` : null;
|
|
17104
|
+
return null;
|
|
17105
|
+
};
|
|
17106
|
+
if (Object.values(installed.plugins).some((value) => !Array.isArray(value) || value.some((row) => !row || typeof row.installPath !== "string" || row.installPath === root2 || row.installPath.startsWith(root2 + sep8) || root2.startsWith(row.installPath + sep8))))
|
|
17107
|
+
continue;
|
|
16780
17108
|
const rows = installed.plugins[id];
|
|
16781
|
-
if (!Array.isArray(rows) || rows.length
|
|
17109
|
+
if (!Array.isArray(rows) || rows.length < 1)
|
|
17110
|
+
continue;
|
|
17111
|
+
const targetScopes = new Set;
|
|
17112
|
+
let targetValid = true;
|
|
17113
|
+
for (const row of rows) {
|
|
17114
|
+
const scope = registrationScope(row), value = row;
|
|
17115
|
+
if (scope === null || targetScopes.has(scope) || value?.installPath !== rows[0]?.installPath || value?.version !== rows[0]?.version) {
|
|
17116
|
+
targetValid = false;
|
|
17117
|
+
break;
|
|
17118
|
+
}
|
|
17119
|
+
targetScopes.add(scope);
|
|
17120
|
+
}
|
|
17121
|
+
if (!targetValid || !targetScopes.has("user\x00"))
|
|
16782
17122
|
continue;
|
|
16783
|
-
const active = rows[0]
|
|
16784
|
-
if (rows[0]
|
|
17123
|
+
const active = rows[0]?.installPath;
|
|
17124
|
+
if (typeof active !== "string" || rows[0]?.version !== basename11(active) || dirname20(active) !== dirname20(root2) || active === root2 || !lstatSync25(active, { throwIfNoEntry: false })?.isDirectory() || realpathSync11(active) !== active)
|
|
16785
17125
|
continue;
|
|
16786
17126
|
const activeManifest = full(join32(active, ".claude-plugin/plugin.json"));
|
|
16787
17127
|
if (!activeManifest || projected(activeManifest) !== activeManifest.sha256)
|
|
16788
17128
|
continue;
|
|
16789
|
-
if (Object.values(installed.plugins).some((value) => !Array.isArray(value) || value.some((row) => !row || typeof row.installPath !== "string" || row.installPath === root2 || row.installPath.startsWith(root2 + sep8) || root2.startsWith(row.installPath + sep8))))
|
|
16790
|
-
continue;
|
|
16791
17129
|
result.add(root2);
|
|
16792
17130
|
}
|
|
16793
17131
|
return [...result];
|
|
@@ -16812,7 +17150,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16812
17150
|
const projection = binding.codexRetiredMaterializations.directories;
|
|
16813
17151
|
if (projection.length !== ordinary.length || projection.some((item, index) => item.path !== ordinary[index]?.path))
|
|
16814
17152
|
throw new Error("Missing retired Codex directory projection");
|
|
16815
|
-
const omitted = [...retiredRoots, ...(binding.codexRetiredMaterializations.parents ?? []).filter((parent) => !
|
|
17153
|
+
const omitted = [...retiredRoots, ...(binding.codexRetiredMaterializations.parents ?? []).filter((parent) => !lstatSync25(parent, { throwIfNoEntry: false }))];
|
|
16816
17154
|
if (projection.every((item) => Array.isArray(item.entries)))
|
|
16817
17155
|
verifyDiscoveryDirectoryProjection(projection, omitted);
|
|
16818
17156
|
else {
|
|
@@ -16826,13 +17164,13 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16826
17164
|
verifyDiscoveryDirectories(ordinary);
|
|
16827
17165
|
verifyDiscoveryDirectories(projected2, installationRoots);
|
|
16828
17166
|
}
|
|
16829
|
-
const absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredRoots.filter((root2) => !
|
|
17167
|
+
const absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredRoots.filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
16830
17168
|
const budget2 = discoveryByteBudget();
|
|
16831
17169
|
for (const source of binding.sources) {
|
|
16832
17170
|
assertMarketplaceBinding(binding, source);
|
|
16833
17171
|
if (source.hashMode === "claude-plugin-registry" && binding.agent !== "claude")
|
|
16834
17172
|
throw new Error("Managed Claude registry witnesses cannot apply to another agent");
|
|
16835
|
-
if (source.format !== undefined && (!["json", "toml", "yaml"].includes(source.format) || !Array.isArray(source.fields) || !source.fields.length || source.fields.length > 64 || source.fields.some((
|
|
17173
|
+
if (source.format !== undefined && (!["json", "toml", "yaml"].includes(source.format) || !Array.isArray(source.fields) || !source.fields.length || source.fields.length > 64 || source.fields.some((field3) => typeof field3 !== "string" || !field3)))
|
|
16836
17174
|
throw new Error("Invalid native discovery projection");
|
|
16837
17175
|
if (source.sha256 !== null && !/^[a-f0-9]{64}$/.test(source.sha256))
|
|
16838
17176
|
throw new Error("Invalid native discovery digest");
|
|
@@ -16852,7 +17190,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16852
17190
|
safe4(root2);
|
|
16853
17191
|
for (const root2 of absentRoots) {
|
|
16854
17192
|
safe4(root2);
|
|
16855
|
-
if (
|
|
17193
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16856
17194
|
throw new Error("Retired native materialization changed during discovery verification");
|
|
16857
17195
|
}
|
|
16858
17196
|
}
|
|
@@ -16860,15 +17198,15 @@ function codexInstallationRoots(binding) {
|
|
|
16860
17198
|
const proof = binding.codexInstallationInputs;
|
|
16861
17199
|
if (proof === undefined)
|
|
16862
17200
|
return [];
|
|
16863
|
-
if (binding.agent !== "codex" || binding.method !== "reviewed" || proof.version
|
|
17201
|
+
if (binding.agent !== "codex" || binding.method !== "reviewed" || !supportsCodexNativeCapability(proof.version, "installed-plugin-review") || !/^[a-f0-9]{64}$/.test(proof.catalogSha256) || !Array.isArray(proof.plugins) || !proof.plugins.length)
|
|
16864
17202
|
throw new Error("Invalid native installation input proof");
|
|
16865
|
-
const cache =
|
|
16866
|
-
const config = join32(
|
|
17203
|
+
const cache = dirname20(dirname20(proof.plugins[0].pluginParent));
|
|
17204
|
+
const config = join32(dirname20(dirname20(cache)), "config.toml"), home = dirname20(dirname20(dirname20(cache)));
|
|
16867
17205
|
const configSource = binding.sources.find((source) => source.path === config && source.sha256 !== null && (!source.format || source.format === "toml" && source.fields?.includes("plugins")));
|
|
16868
17206
|
const nativeRoots = NATIVE_SKILL_ROOTS.filter(([agent]) => agent === "codex").map(([, path]) => join32(home, path));
|
|
16869
|
-
if (!configSource || proof.plugins.some((input) => nativeRoots.some((root2) => root2 === input.sourceRoot || root2.startsWith(input.sourceRoot + sep8) || input.sourceRoot.startsWith(root2 + sep8)) || binding.sources.some((source) =>
|
|
17207
|
+
if (!configSource || proof.plugins.some((input) => nativeRoots.some((root2) => root2 === input.sourceRoot || root2.startsWith(input.sourceRoot + sep8) || input.sourceRoot.startsWith(root2 + sep8)) || binding.sources.some((source) => basename11(source.path) === "config.toml" && (source.path === input.sourceRoot || source.path.startsWith(input.sourceRoot + sep8)))))
|
|
16870
17208
|
throw new Error("Native installation input overlaps configuration or loading roots");
|
|
16871
|
-
if (proof.plugins.some((input) =>
|
|
17209
|
+
if (proof.plugins.some((input) => dirname20(dirname20(input.pluginParent)) !== cache || !binding.sources.some((source) => source.path === join32(input.sourceRoot, ".codex-plugin/plugin.json") && source.sha256 !== null && source.format === undefined && source.fields === undefined)))
|
|
16872
17210
|
throw new Error("Missing native installation input source witness");
|
|
16873
17211
|
return reviewedCodexPluginSourceRoots(cache, proof.plugins, (path) => {
|
|
16874
17212
|
const text2 = read2(path);
|
|
@@ -16878,40 +17216,42 @@ function codexInstallationRoots(binding) {
|
|
|
16878
17216
|
});
|
|
16879
17217
|
}
|
|
16880
17218
|
function assertMarketplaceBinding(binding, source) {
|
|
16881
|
-
if (source.hashMode === "claude-plugin-manifest-v1" && (binding.agent !== "claude" ||
|
|
17219
|
+
if (source.hashMode === "claude-plugin-manifest-v1" && (binding.agent !== "claude" || basename11(source.path) !== "plugin.json" || !source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json"))))
|
|
16882
17220
|
throw new Error("Claude plugin manifest witnesses require Claude plugin discovery");
|
|
16883
|
-
if (source.hashMode === "sumi-settings-v1" && (binding.agent !== "sumi" || binding.method !== "reviewed" ||
|
|
17221
|
+
if (source.hashMode === "sumi-settings-v1" && (binding.agent !== "sumi" || binding.method !== "reviewed" || basename11(source.path) !== "sumi.json"))
|
|
16884
17222
|
throw new Error("Sumi settings witnesses require explicit reviewed Sumi configuration");
|
|
16885
|
-
if ((source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")) && (binding.agent !== "codex" || binding.method !== "reviewed" ||
|
|
17223
|
+
if ((source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")) && (binding.agent !== "codex" || binding.method !== "reviewed" || basename11(source.path) !== "config.toml"))
|
|
16886
17224
|
throw new Error("Codex settings witnesses require explicit reviewed Codex configuration");
|
|
16887
|
-
if ((source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || source.hashMode === "claude-settings-v3") && (binding.agent !== "claude" || binding.method !== "reviewed" ||
|
|
17225
|
+
if ((source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4")) && (binding.agent !== "claude" || binding.method !== "reviewed" || basename11(source.path) !== "settings.json"))
|
|
16888
17226
|
throw new Error("Claude settings witnesses require explicit reviewed Claude configuration");
|
|
16889
17227
|
if ((source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2") && (binding.agent !== "claude" || binding.method !== "reviewed"))
|
|
16890
17228
|
throw new Error("Claude marketplace witnesses require explicit reviewed Claude discovery");
|
|
17229
|
+
if (source.hashMode === "claude-marketplace-entry-v1" && (binding.agent !== "claude" || binding.method !== "reviewed" || !claudeMarketplaceEntrySourceValid(source)))
|
|
17230
|
+
throw new Error("Claude marketplace entry witnesses require explicit reviewed Claude discovery of one named entry");
|
|
16891
17231
|
}
|
|
16892
17232
|
function rebindAgentDiscovery(binding, changes) {
|
|
16893
17233
|
const budget2 = discoveryByteBudget();
|
|
16894
|
-
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !
|
|
17234
|
+
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
16895
17235
|
const rebound = { ...binding, sources: binding.sources.map((source) => {
|
|
16896
17236
|
assertMarketplaceBinding(binding, source);
|
|
16897
17237
|
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && source.format === undefined && source.fields === undefined && source.managedPlugins === undefined && [undefined, "bytes"].includes(source.hashMode)))
|
|
16898
17238
|
return source;
|
|
16899
|
-
const
|
|
16900
|
-
if (!changes.has(source.path) &&
|
|
17239
|
+
const sha2563 = projected(source, changes, budget2);
|
|
17240
|
+
if (!changes.has(source.path) && sha2563 !== source.sha256)
|
|
16901
17241
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16902
|
-
return { ...source, sha256:
|
|
17242
|
+
return { ...source, sha256: sha2563 };
|
|
16903
17243
|
}) };
|
|
16904
17244
|
for (const root2 of absentRoots) {
|
|
16905
17245
|
safe4(root2);
|
|
16906
|
-
if (
|
|
17246
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16907
17247
|
throw new Error("Retired native materialization changed during discovery rebinding");
|
|
16908
17248
|
}
|
|
16909
17249
|
return rebound;
|
|
16910
17250
|
}
|
|
16911
|
-
function assertProjectDiscovery(agent, directories, home,
|
|
16912
|
-
const homeConfigPath =
|
|
17251
|
+
function assertProjectDiscovery(agent, directories, home, canonical8 = resolve20, reviewed) {
|
|
17252
|
+
const homeConfigPath = canonical8(agentDiscoveryConfigPath(home, agent));
|
|
16913
17253
|
for (const directory of directories) {
|
|
16914
|
-
const isHome =
|
|
17254
|
+
const isHome = resolve20(directory) === resolve20(home);
|
|
16915
17255
|
if (agent === "hermes") {
|
|
16916
17256
|
assertHermesEnvironment(home);
|
|
16917
17257
|
continue;
|
|
@@ -16920,7 +17260,7 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16920
17260
|
continue;
|
|
16921
17261
|
const paths = agent === "claude" ? [...isHome ? [] : [".claude/settings.json"], ".claude/settings.local.json"] : agent === "codex" ? [".codex/config.toml"] : agent === "gemini" ? [".gemini/settings.json"] : agent === "opencode" ? ["opencode.json", "opencode.jsonc", ".opencode/opencode.json", ".opencode/opencode.jsonc"] : agent === "sumi" ? ["sumi.json", "sumi.jsonc", ".sumi/sumi.json", ".sumi/sumi.jsonc"] : [".cursor/hooks.json"];
|
|
16922
17262
|
for (const suffix of paths) {
|
|
16923
|
-
const path =
|
|
17263
|
+
const path = canonical8(join32(directory, suffix)), raw = read2(path);
|
|
16924
17264
|
if (raw === null)
|
|
16925
17265
|
continue;
|
|
16926
17266
|
const isRootAliasedHomeConfig = agent === "claude" && suffix === ".claude/settings.json" || agent === "codex" && suffix === ".codex/config.toml";
|
|
@@ -16936,7 +17276,7 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16936
17276
|
const managed = reviewed.sources.flatMap((source) => source.hashMode === "claude-plugin-registry" ? source.managedPlugins ?? [] : []);
|
|
16937
17277
|
if (exact && projected(exact) === exact.sha256 && managed.length) {
|
|
16938
17278
|
const bindings = managed.map((item) => readPluginBinding(item.storeRoot, item.bindingId));
|
|
16939
|
-
admittedPlugins = Object.entries(config.enabledPlugins).every(([id, enabled]) => typeof enabled === "boolean" && bindings.some((binding) => binding.target.pluginId === id && binding.target.registrations.some((scope) => scope.scope === "project" && scope.projectPath ===
|
|
17279
|
+
admittedPlugins = Object.entries(config.enabledPlugins).every(([id, enabled]) => typeof enabled === "boolean" && bindings.some((binding) => binding.target.pluginId === id && binding.target.registrations.some((scope) => scope.scope === "project" && scope.projectPath === canonical8(directory))));
|
|
16940
17280
|
}
|
|
16941
17281
|
}
|
|
16942
17282
|
if (keys.some((key) => config[key] !== undefined && !(key === "enabledPlugins" && admittedPlugins)) || config.disableAllHooks === true || config.disableBundledSkills === false || config.hooksConfig?.enabled === false || config.permission?.skill !== undefined || config.permissions?.deny?.some((rule) => typeof rule === "string" && /^Skill(?:\(|$)/.test(rule)))
|
|
@@ -16944,15 +17284,15 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16944
17284
|
}
|
|
16945
17285
|
if (agent === "sumi")
|
|
16946
17286
|
for (const name of ["plugin", "plugins"]) {
|
|
16947
|
-
const path =
|
|
17287
|
+
const path = canonical8(join32(directory, ".sumi", name));
|
|
16948
17288
|
safe4(path);
|
|
16949
|
-
if (
|
|
17289
|
+
if (lstatSync25(path, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(path).length)
|
|
16950
17290
|
throw new Error(`NATIVE_SKILL_DRIFT: project Sumi plugins require a dedicated discovery review: ${path}`);
|
|
16951
17291
|
}
|
|
16952
17292
|
if (agent === "claude") {
|
|
16953
|
-
const commands =
|
|
17293
|
+
const commands = canonical8(join32(directory, ".claude/commands"));
|
|
16954
17294
|
safe4(commands);
|
|
16955
|
-
if (
|
|
17295
|
+
if (lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length)
|
|
16956
17296
|
throw new Error("NATIVE_SKILL_DRIFT: legacy project command discovery requires a dedicated format adapter");
|
|
16957
17297
|
}
|
|
16958
17298
|
}
|
|
@@ -16962,11 +17302,37 @@ function agentDiscoveryConfigPath(home, agent) {
|
|
|
16962
17302
|
return sumiConfigPath(home);
|
|
16963
17303
|
return join32(home, agent === "hermes" ? ".hermes/config.yaml" : agent === "opencode" ? ".config/opencode/opencode.json" : `.${agent}/${agent === "codex" ? "config.toml" : agent === "cursor" ? "hooks.json" : "settings.json"}`);
|
|
16964
17304
|
}
|
|
17305
|
+
function verifyAutomaticDiscoveryClosure(binding, options) {
|
|
17306
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[binding.agent], recorded = options.executable;
|
|
17307
|
+
const onPath = discoveryExecutable(binding.agent);
|
|
17308
|
+
let runtime, gap;
|
|
17309
|
+
if (recorded) {
|
|
17310
|
+
runtime = recordedDiscoveryExecutable(binding.agent, recorded);
|
|
17311
|
+
if (runtime && runtime.target !== recorded.target)
|
|
17312
|
+
throw new Error(`${options.change}: the recorded ${binding.agent} executable now resolves to ${quotedPath(runtime.target)}, not the reviewed ${quotedPath(recorded.target)}`);
|
|
17313
|
+
if (onPath && onPath.target !== recorded.target)
|
|
17314
|
+
throw new Error(`${options.change}: the "${command}" on this process's PATH resolves to ${quotedPath(onPath.target)}, not the reviewed ${quotedPath(recorded.target)}`);
|
|
17315
|
+
if (!runtime)
|
|
17316
|
+
gap = `the recorded executable ${quotedPath(recorded.path)} no longer resolves. Restore it, or review the change with skills hook install`;
|
|
17317
|
+
} else {
|
|
17318
|
+
runtime = onPath;
|
|
17319
|
+
if (!runtime)
|
|
17320
|
+
gap = "it is not on this process's PATH, and the reviewed policy has no recorded executable path. Run with the PATH used for the review, or run skills hook install there to record it";
|
|
17321
|
+
}
|
|
17322
|
+
const current2 = resolveAgentDiscovery({ home: options.home, agent: binding.agent, canonical: options.canonical, executable: runtime });
|
|
17323
|
+
if (JSON.stringify(current2) === JSON.stringify(binding))
|
|
17324
|
+
return;
|
|
17325
|
+
const reviewedWithRuntime = (binding.builtinNames?.length ?? 0) > 0 || binding.sources.some((source) => basename11(source.path) === "package.json");
|
|
17326
|
+
const otherwiseCurrent = current2.method === binding.method && JSON.stringify(current2.roots) === JSON.stringify(binding.roots) && JSON.stringify(current2.directories) === JSON.stringify(binding.directories) && current2.sources.every((source) => binding.sources.some((saved) => isDeepStrictEqual7(saved, source)));
|
|
17327
|
+
if (command && gap && runtime === null && reviewedWithRuntime && otherwiseCurrent)
|
|
17328
|
+
throw discoveryRootUnresolved(binding.agent, command, gap);
|
|
17329
|
+
throw new Error(options.change);
|
|
17330
|
+
}
|
|
16965
17331
|
function resolveAgentDiscovery(options) {
|
|
16966
|
-
const
|
|
17332
|
+
const canonical8 = options.canonical ?? resolve20, home = resolve20(options.home), agent = options.agent;
|
|
16967
17333
|
const sources = [], roots = new Set, builtinNames = [];
|
|
16968
17334
|
const witness = (path, format, fields2, hashMode) => {
|
|
16969
|
-
const source = { path:
|
|
17335
|
+
const source = { path: canonical8(path), sha256: null, ...format ? { format, fields: fields2 } : {}, ...hashMode ? { hashMode } : {} };
|
|
16970
17336
|
source.sha256 = projected(source);
|
|
16971
17337
|
sources.push(source);
|
|
16972
17338
|
return read2(source.path);
|
|
@@ -16988,13 +17354,13 @@ function resolveAgentDiscovery(options) {
|
|
|
16988
17354
|
unresolved("JSONC configuration requires a supported format adapter");
|
|
16989
17355
|
for (const root2 of [directory, join32(home, ".claude"), join32(home, ".agents")])
|
|
16990
17356
|
for (const name of ["skill", "skills"])
|
|
16991
|
-
roots.add(
|
|
17357
|
+
roots.add(canonical8(join32(root2, name)));
|
|
16992
17358
|
if (config.skills !== undefined && (!Array.isArray(config.skills) || config.skills.some((path) => typeof path !== "string")))
|
|
16993
17359
|
unresolved("skills must be a string array");
|
|
16994
17360
|
for (const value of config.skills ?? []) {
|
|
16995
|
-
if (typeof value !== "string" || /[\0$]/.test(value) || !value || !(
|
|
17361
|
+
if (typeof value !== "string" || /[\0$]/.test(value) || !value || !(isAbsolute21(value) || value.startsWith("~/")))
|
|
16996
17362
|
unresolved("remote or relative skill sources need a dedicated discovery adapter");
|
|
16997
|
-
roots.add(
|
|
17363
|
+
roots.add(canonical8(value.startsWith("~/") ? join32(home, value.slice(2)) : value));
|
|
16998
17364
|
}
|
|
16999
17365
|
for (const key of ["plugin", "plugins"])
|
|
17000
17366
|
if (config[key] !== undefined && !Array.isArray(config[key]))
|
|
@@ -17002,19 +17368,19 @@ function resolveAgentDiscovery(options) {
|
|
|
17002
17368
|
const plugins = [join32(directory, "plugin"), join32(directory, "plugins")];
|
|
17003
17369
|
for (const path of plugins) {
|
|
17004
17370
|
safe4(path);
|
|
17005
|
-
if (
|
|
17371
|
+
if (lstatSync25(path, { throwIfNoEntry: false })?.isDirectory())
|
|
17006
17372
|
for (const name of readdirSync10(path).sort()) {
|
|
17007
17373
|
if (name === "skills-cli.js" && path === plugins[1])
|
|
17008
17374
|
continue;
|
|
17009
17375
|
const target = join32(path, name);
|
|
17010
|
-
if (!
|
|
17376
|
+
if (!lstatSync25(target).isFile())
|
|
17011
17377
|
unresolved("local plugin packages need a dedicated discovery adapter");
|
|
17012
17378
|
witness(target);
|
|
17013
17379
|
}
|
|
17014
17380
|
}
|
|
17015
17381
|
for (const root2 of roots) {
|
|
17016
17382
|
safe4(root2);
|
|
17017
|
-
if (
|
|
17383
|
+
if (lstatSync25(root2, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(root2).some((name) => name.endsWith(".md")))
|
|
17018
17384
|
unresolved("flat markdown skills require a dedicated native migration adapter");
|
|
17019
17385
|
}
|
|
17020
17386
|
}
|
|
@@ -17033,30 +17399,30 @@ function resolveAgentDiscovery(options) {
|
|
|
17033
17399
|
continue;
|
|
17034
17400
|
if (normalized.startsWith("~") && normalized !== "~" && !normalized.startsWith("~/"))
|
|
17035
17401
|
unresolved("user-specific tilde expansion requires a separate discovery adapter");
|
|
17036
|
-
const path = normalized === "~" ? home : normalized.startsWith("~/") ? join32(home, normalized.slice(2)) :
|
|
17402
|
+
const path = normalized === "~" ? home : normalized.startsWith("~/") ? join32(home, normalized.slice(2)) : resolve20(home, ".hermes", normalized);
|
|
17037
17403
|
safe4(path);
|
|
17038
17404
|
roots.add(path);
|
|
17039
17405
|
}
|
|
17040
17406
|
}
|
|
17041
17407
|
if (agent === "gemini") {
|
|
17042
|
-
const executable2 =
|
|
17408
|
+
const executable2 = options.executable === undefined ? discoveryExecutable(agent) : options.executable;
|
|
17043
17409
|
if (executable2) {
|
|
17044
17410
|
let packageRoot;
|
|
17045
|
-
for (let directory =
|
|
17411
|
+
for (let directory = dirname20(executable2.target), depth = 0;depth < 8; directory = dirname20(directory), depth++) {
|
|
17046
17412
|
const path = join32(directory, "package.json"), raw = read2(path);
|
|
17047
17413
|
if (raw !== null && parseConfig(raw, path).name === "@google/gemini-cli") {
|
|
17048
17414
|
packageRoot = directory;
|
|
17049
17415
|
witness(path);
|
|
17050
17416
|
break;
|
|
17051
17417
|
}
|
|
17052
|
-
if (
|
|
17418
|
+
if (dirname20(directory) === directory)
|
|
17053
17419
|
break;
|
|
17054
17420
|
}
|
|
17055
17421
|
if (!packageRoot)
|
|
17056
17422
|
unresolved("installed Gemini package layout is not recognized");
|
|
17057
17423
|
const builtinRoot = join32(packageRoot, "bundle/builtin");
|
|
17058
17424
|
safe4(builtinRoot);
|
|
17059
|
-
if (!
|
|
17425
|
+
if (!lstatSync25(builtinRoot, { throwIfNoEntry: false })?.isDirectory())
|
|
17060
17426
|
unresolved("installed Gemini builtin root is missing");
|
|
17061
17427
|
for (const name of readdirSync10(builtinRoot).sort()) {
|
|
17062
17428
|
const text2 = witness(join32(builtinRoot, name, "SKILL.md"));
|
|
@@ -17072,11 +17438,11 @@ function resolveAgentDiscovery(options) {
|
|
|
17072
17438
|
if (retained.agent !== agent || retained.method !== "reviewed")
|
|
17073
17439
|
unresolved("invalid retained review");
|
|
17074
17440
|
verifyAgentDiscovery(retained);
|
|
17075
|
-
if (!retained.sources.some((source) => source.path ===
|
|
17441
|
+
if (!retained.sources.some((source) => source.path === canonical8(configPath) && source.format === undefined && source.fields === undefined))
|
|
17076
17442
|
unresolved("retained review is missing the full agent configuration source");
|
|
17077
|
-
if (retained.sources.some((source) => (source.hashMode === "sumi-settings-v1" || source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")))) && source.path !==
|
|
17443
|
+
if (retained.sources.some((source) => (source.hashMode === "sumi-settings-v1" || source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4" || (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")))) && source.path !== canonical8(configPath)))
|
|
17078
17444
|
unresolved("retained settings witness names another configuration source");
|
|
17079
|
-
const covered = supersedesSettingsProjection(agent, retained.sources,
|
|
17445
|
+
const covered = supersedesSettingsProjection(agent, retained.sources, canonical8(configPath)) ? sources.filter((source) => !isSupersededSettingsProjection(agent, canonical8(configPath), source)) : sources;
|
|
17080
17446
|
if (covered.some((source) => !retained.sources.some((saved) => isDeepStrictEqual7(saved, source))) || [...roots].some((root2) => !retained.roots.includes(root2)) || agent === "gemini" && JSON.stringify(retained.builtinNames) !== JSON.stringify(builtinNames))
|
|
17081
17447
|
unresolved("retained review is missing current runtime discovery coverage");
|
|
17082
17448
|
return retained;
|
|
@@ -17088,16 +17454,16 @@ function resolveAgentDiscovery(options) {
|
|
|
17088
17454
|
if (review.sources.some((source) => source.format !== undefined || source.fields !== undefined))
|
|
17089
17455
|
throw new Error("Explicit discovery reviews require full source-file hashes");
|
|
17090
17456
|
verifyAgentDiscovery(supplied);
|
|
17091
|
-
if (review.sources.some((source) => (source.hashMode === "sumi-settings-v1" || source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")))) && source.path !==
|
|
17457
|
+
if (review.sources.some((source) => (source.hashMode === "sumi-settings-v1" || source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4" || (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4")))) && source.path !== canonical8(configPath)))
|
|
17092
17458
|
throw new Error("Semantic settings witnesses must name the configured agent configuration source");
|
|
17093
|
-
if (!review.sources.some((source) => source.path ===
|
|
17459
|
+
if (!review.sources.some((source) => source.path === canonical8(configPath)))
|
|
17094
17460
|
throw new Error("Discovery review must include the agent configuration source");
|
|
17095
|
-
const reviewedSources = supersedesSettingsProjection(agent, review.sources,
|
|
17461
|
+
const reviewedSources = supersedesSettingsProjection(agent, review.sources, canonical8(configPath)) ? sources.filter((source) => !isSupersededSettingsProjection(agent, canonical8(configPath), source)) : sources;
|
|
17096
17462
|
const reviewedSourcesWithManifestProjection = review.sources.map((source) => {
|
|
17097
|
-
if (agent !== "claude" || source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || source.hashMode !== undefined && source.hashMode !== "bytes" ||
|
|
17463
|
+
if (agent !== "claude" || source.sha256 === null || source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || source.hashMode !== undefined && source.hashMode !== "bytes" || basename11(source.path) !== "plugin.json" || !source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json")))
|
|
17098
17464
|
return source;
|
|
17099
|
-
const pluginRoot =
|
|
17100
|
-
const hookStat =
|
|
17465
|
+
const pluginRoot = dirname20(dirname20(source.path)), hooksPath = join32(pluginRoot, "hooks/hooks.json");
|
|
17466
|
+
const hookStat = lstatSync25(hooksPath, { throwIfNoEntry: false });
|
|
17101
17467
|
const text2 = read2(source.path);
|
|
17102
17468
|
if (text2 === null)
|
|
17103
17469
|
throw new Error("Reviewed Claude plugin manifest is missing");
|
|
@@ -17111,13 +17477,13 @@ function resolveAgentDiscovery(options) {
|
|
|
17111
17477
|
if (manifest.hooks !== undefined) {
|
|
17112
17478
|
if (typeof manifest.hooks !== "string")
|
|
17113
17479
|
throw new Error("Reviewed Claude plugin manifest has an unsupported hooks target");
|
|
17114
|
-
const declaredHookPath =
|
|
17480
|
+
const declaredHookPath = resolve20(pluginRoot, manifest.hooks);
|
|
17115
17481
|
if (!declaredHookPath.startsWith(pluginRoot + sep8))
|
|
17116
17482
|
throw new Error("Reviewed Claude plugin hooks target escapes its root");
|
|
17117
17483
|
reviewedHookPaths.add(declaredHookPath);
|
|
17118
17484
|
}
|
|
17119
17485
|
for (const hooksFile of reviewedHookPaths)
|
|
17120
|
-
if (!review.sources.some((hook) => hook.path ===
|
|
17486
|
+
if (!review.sources.some((hook) => hook.path === canonical8(hooksFile) && hook.sha256 !== null && hook.format === undefined && hook.fields === undefined && hook.managedPlugins === undefined && (hook.hashMode === undefined || hook.hashMode === "bytes")))
|
|
17121
17487
|
throw new Error("Reviewed Claude plugin manifest requires separately reviewed exact hook file sources");
|
|
17122
17488
|
return { path: source.path, sha256: manifestSha256, hashMode: "claude-plugin-manifest-v1" };
|
|
17123
17489
|
});
|
|
@@ -17126,7 +17492,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17126
17492
|
return { ...supplied, roots: [...new Set([...roots, ...supplied.roots])].sort(), sources: unique, ...agent === "gemini" ? { builtinNames } : {} };
|
|
17127
17493
|
}
|
|
17128
17494
|
function plugin(root2) {
|
|
17129
|
-
root2 =
|
|
17495
|
+
root2 = canonical8(root2);
|
|
17130
17496
|
safe4(root2);
|
|
17131
17497
|
const manifestPath = join32(root2, agent === "claude" ? ".claude-plugin/plugin.json" : ".codex-plugin/plugin.json");
|
|
17132
17498
|
const raw = witness(manifestPath, undefined, undefined, agent === "claude" ? "claude-plugin-manifest-v1" : undefined);
|
|
@@ -17138,7 +17504,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17138
17504
|
unresolved("plugin hooks require a separate no-skill-injection review");
|
|
17139
17505
|
const commands = join32(root2, "commands");
|
|
17140
17506
|
safe4(commands);
|
|
17141
|
-
if (agent === "claude" && (manifest.commands !== undefined ||
|
|
17507
|
+
if (agent === "claude" && (manifest.commands !== undefined || lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length))
|
|
17142
17508
|
unresolved("legacy command discovery requires retirement or a dedicated format adapter");
|
|
17143
17509
|
const rootSkill = witness(join32(root2, "SKILL.md"));
|
|
17144
17510
|
if (rootSkill !== null)
|
|
@@ -17149,18 +17515,18 @@ function resolveAgentDiscovery(options) {
|
|
|
17149
17515
|
if (agent === "claude")
|
|
17150
17516
|
roots.add(join32(root2, "skills"));
|
|
17151
17517
|
for (const value of declared) {
|
|
17152
|
-
const path =
|
|
17518
|
+
const path = resolve20(root2, value);
|
|
17153
17519
|
if (path !== root2 && !path.startsWith(root2 + sep8))
|
|
17154
17520
|
unresolved("plugin skill path escapes its root");
|
|
17155
|
-
roots.add(path.endsWith(`${sep8}SKILL.md`) ?
|
|
17521
|
+
roots.add(path.endsWith(`${sep8}SKILL.md`) ? dirname20(path) : path);
|
|
17156
17522
|
}
|
|
17157
17523
|
}
|
|
17158
17524
|
if (agent === "claude") {
|
|
17159
17525
|
const registrations = witness(join32(home, ".claude/plugins/installed_plugins.json"));
|
|
17160
17526
|
const installed = registrations === null ? {} : parseConfig(registrations, join32(home, ".claude/plugins/installed_plugins.json")).plugins;
|
|
17161
|
-
const commands =
|
|
17527
|
+
const commands = canonical8(join32(home, ".claude/commands"));
|
|
17162
17528
|
safe4(commands);
|
|
17163
|
-
if (
|
|
17529
|
+
if (lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length)
|
|
17164
17530
|
unresolved("legacy home command discovery requires a dedicated format adapter");
|
|
17165
17531
|
for (const [id, enabled] of Object.entries(config.enabledPlugins ?? {})) {
|
|
17166
17532
|
if (enabled === false)
|
|
@@ -17180,7 +17546,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17180
17546
|
unresolved("unsupported plugin enablement");
|
|
17181
17547
|
const split = id.lastIndexOf("@"), name = id.slice(0, split), marketplace = id.slice(split + 1);
|
|
17182
17548
|
const market = config.marketplaces?.[marketplace] ?? (marketplace === "personal" ? { source_type: "local", source: home } : undefined);
|
|
17183
|
-
if (split < 1 || market?.source_type !== "local" || typeof market.source !== "string" || !
|
|
17549
|
+
if (split < 1 || market?.source_type !== "local" || typeof market.source !== "string" || !isAbsolute21(market.source))
|
|
17184
17550
|
unresolved("enabled plugin marketplace is not an explicit local source");
|
|
17185
17551
|
const catalogText = witness(join32(market.source, ".agents/plugins/marketplace.json"));
|
|
17186
17552
|
if (catalogText === null)
|
|
@@ -17188,7 +17554,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17188
17554
|
const catalog = parseConfig(catalogText, join32(market.source, ".agents/plugins/marketplace.json")), matches = Array.isArray(catalog.plugins) ? catalog.plugins.filter((item) => item.name === name) : [];
|
|
17189
17555
|
if (matches.length !== 1 || matches[0]?.source?.source !== "local" || typeof matches[0]?.source?.path !== "string")
|
|
17190
17556
|
unresolved("plugin catalog source is missing or ambiguous");
|
|
17191
|
-
plugin(
|
|
17557
|
+
plugin(resolve20(market.source, matches[0].source.path));
|
|
17192
17558
|
}
|
|
17193
17559
|
} else if (agent === "opencode") {
|
|
17194
17560
|
if (witness(join32(home, ".config/opencode/opencode.jsonc")) !== null || witness(join32(home, ".config/opencode/config.json")) !== null)
|
|
@@ -17196,21 +17562,21 @@ function resolveAgentDiscovery(options) {
|
|
|
17196
17562
|
if ((config.plugin?.length ?? 0) > 0 || config.skills?.urls?.length)
|
|
17197
17563
|
unresolved("external plugin or remote skill source");
|
|
17198
17564
|
for (const path of config.skills?.paths ?? []) {
|
|
17199
|
-
if (typeof path !== "string" || !
|
|
17565
|
+
if (typeof path !== "string" || !isAbsolute21(path))
|
|
17200
17566
|
unresolved("relative or malformed added skill root");
|
|
17201
17567
|
roots.add(path);
|
|
17202
17568
|
}
|
|
17203
17569
|
const localPlugins = join32(home, ".config/opencode/plugins");
|
|
17204
17570
|
safe4(localPlugins);
|
|
17205
|
-
if (
|
|
17571
|
+
if (lstatSync25(localPlugins, { throwIfNoEntry: false }) && readdirSync10(localPlugins).some((name) => name !== "skills-cli.js"))
|
|
17206
17572
|
unresolved("additional local plugin hooks require review");
|
|
17207
17573
|
} else if (agent === "sumi") {
|
|
17208
|
-
if ((config.plugin?.length ?? 0) > 0 || (config.plugins?.length ?? 0) > 0 || sources.some((source) => source.path !==
|
|
17574
|
+
if ((config.plugin?.length ?? 0) > 0 || (config.plugins?.length ?? 0) > 0 || sources.some((source) => source.path !== canonical8(configPath) && source.path !== canonical8(join32(sumiConfigDirectory(home), "sumi.jsonc")) && source.sha256 !== null))
|
|
17209
17575
|
unresolved("external or foreign local plugins require review");
|
|
17210
17576
|
} else if (agent === "hermes") {
|
|
17211
17577
|
for (const directory of [join32(home, ".hermes/plugins"), join32(home, ".hermes/hermes-agent")]) {
|
|
17212
17578
|
safe4(directory);
|
|
17213
|
-
if (
|
|
17579
|
+
if (lstatSync25(directory, { throwIfNoEntry: false }))
|
|
17214
17580
|
unresolved("installed runtime/plugin discovery requires reviewed source bindings");
|
|
17215
17581
|
}
|
|
17216
17582
|
if (Bun.which("hermes") || Object.keys(config.plugins ?? {}).length)
|
|
@@ -17220,11 +17586,11 @@ function resolveAgentDiscovery(options) {
|
|
|
17220
17586
|
unresolved("custom extension or skill paths");
|
|
17221
17587
|
const directory = join32(home, ".gemini/extensions");
|
|
17222
17588
|
safe4(directory);
|
|
17223
|
-
if (
|
|
17589
|
+
if (lstatSync25(directory, { throwIfNoEntry: false }))
|
|
17224
17590
|
for (const name of readdirSync10(directory)) {
|
|
17225
17591
|
const root2 = join32(directory, name);
|
|
17226
17592
|
safe4(root2);
|
|
17227
|
-
if (!
|
|
17593
|
+
if (!lstatSync25(root2)?.isDirectory())
|
|
17228
17594
|
continue;
|
|
17229
17595
|
const raw = witness(join32(root2, "gemini-extension.json"));
|
|
17230
17596
|
if (raw === null)
|
|
@@ -17235,7 +17601,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17235
17601
|
roots.add(join32(root2, "skills"));
|
|
17236
17602
|
}
|
|
17237
17603
|
}
|
|
17238
|
-
return { agent, roots: [...roots].sort(), sources, method: "automatic", ...agent === "gemini" ? { builtinNames } : {}, ...agent === "hermes" ? { directories: captureDiscoveryDirectories([join32(home, ".hermes/plugins"), join32(home, ".hermes/hermes-agent")].map((path) =>
|
|
17604
|
+
return { agent, roots: [...roots].sort(), sources, method: "automatic", ...agent === "gemini" ? { builtinNames } : {}, ...agent === "hermes" ? { directories: captureDiscoveryDirectories([join32(home, ".hermes/plugins"), join32(home, ".hermes/hermes-agent")].map((path) => canonical8(path))) } : {} };
|
|
17239
17605
|
}
|
|
17240
17606
|
var NATIVE_DISCOVERY_ROOTS = NATIVE_SKILL_ROOTS.map(([, path]) => path.split("/"));
|
|
17241
17607
|
var OFFICIAL_SKILL_NAMES = new Set(SKILLS.map((skill) => skill.name));
|
|
@@ -20686,14 +21052,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
20686
21052
|
const shape = zod.def.shape;
|
|
20687
21053
|
const propValues = {};
|
|
20688
21054
|
for (const key in shape) {
|
|
20689
|
-
const
|
|
20690
|
-
if (
|
|
21055
|
+
const field3 = shape[key]._zod;
|
|
21056
|
+
if (field3.values) {
|
|
20691
21057
|
if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
|
|
20692
21058
|
assignProp(propValues, key, new Set);
|
|
20693
21059
|
}
|
|
20694
|
-
for (const v of
|
|
21060
|
+
for (const v of field3.values)
|
|
20695
21061
|
propValues[key].add(v);
|
|
20696
|
-
if (
|
|
21062
|
+
if (field3.optin !== undefined)
|
|
20697
21063
|
propValues[key].add(undefined);
|
|
20698
21064
|
}
|
|
20699
21065
|
}
|
|
@@ -22106,8 +22472,8 @@ function isRecursive(inst, stack) {
|
|
|
22106
22472
|
return true;
|
|
22107
22473
|
stack.add(inst);
|
|
22108
22474
|
let result = false;
|
|
22109
|
-
const check = (
|
|
22110
|
-
if (!result &&
|
|
22475
|
+
const check = (child2) => {
|
|
22476
|
+
if (!result && child2?._zod && isRecursive(child2, stack))
|
|
22111
22477
|
result = true;
|
|
22112
22478
|
};
|
|
22113
22479
|
const def = inst._zod.def;
|
|
@@ -32815,11 +33181,11 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
32815
33181
|
}
|
|
32816
33182
|
const allKeys = new Set(Object.keys(shape));
|
|
32817
33183
|
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
32818
|
-
const
|
|
33184
|
+
const field3 = def.shape[key];
|
|
32819
33185
|
if (ctx.io === "input") {
|
|
32820
|
-
return inputOptin(
|
|
33186
|
+
return inputOptin(field3) === undefined;
|
|
32821
33187
|
} else {
|
|
32822
|
-
return
|
|
33188
|
+
return field3._zod.optout === undefined;
|
|
32823
33189
|
}
|
|
32824
33190
|
}));
|
|
32825
33191
|
if (requiredKeys.size > 0) {
|
|
@@ -36213,7 +36579,7 @@ var hash3 = (v) => typeof v === "string" && /^[a-f0-9]{64}$/.test(v);
|
|
|
36213
36579
|
var record9 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
36214
36580
|
var exact = (v, keys) => record9(v) && Object.keys(v).sort().join(",") === keys.sort().join(",");
|
|
36215
36581
|
var date5 = (v) => typeof v === "string" && /^\d{4}-\d\d-\d\dT[0-9:.]+(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.test(v) && Number.isFinite(Date.parse(v));
|
|
36216
|
-
var publicationSha256 = (bytes) =>
|
|
36582
|
+
var publicationSha256 = (bytes) => createHash29("sha256").update(bytes).digest("hex");
|
|
36217
36583
|
function checkedPublicationDeclaration(value) {
|
|
36218
36584
|
if (!exact(value, ["idempotencyKey", "version", "expectedCurrentVersionId", "manifestText", "archiveSha256", "archiveByteSize"]) || !publicationUuid(value.idempotencyKey) || !(value.expectedCurrentVersionId === null || publicationUuid(value.expectedCurrentVersionId)) || typeof value.version !== "string" || !value.version || value.version.length > 128 || /[\p{Cc}\p{Cs}]/u.test(value.version) || typeof value.manifestText !== "string" || Buffer.byteLength(value.manifestText) > 16384 || !hash3(value.archiveSha256) || !Number.isSafeInteger(value.archiveByteSize) || Number(value.archiveByteSize) < 1 || Number(value.archiveByteSize) > PRIVATE_PUBLICATION_MAX_BYTES)
|
|
36219
36585
|
return bad();
|
|
@@ -36458,12 +36824,12 @@ class RemotePrivatePublicationsClient {
|
|
|
36458
36824
|
previous = view;
|
|
36459
36825
|
if (!["queued", "verifying"].includes(view.state) || Date.now() >= until)
|
|
36460
36826
|
return view;
|
|
36461
|
-
await new Promise((
|
|
36827
|
+
await new Promise((resolve23) => {
|
|
36462
36828
|
const timer = setTimeout(done, Math.min(1000, until - Date.now()));
|
|
36463
36829
|
function done() {
|
|
36464
36830
|
clearTimeout(timer);
|
|
36465
36831
|
options.signal?.removeEventListener("abort", done);
|
|
36466
|
-
|
|
36832
|
+
resolve23();
|
|
36467
36833
|
}
|
|
36468
36834
|
options.signal?.addEventListener("abort", done, { once: true });
|
|
36469
36835
|
});
|
|
@@ -36499,7 +36865,7 @@ var stateSchema = exports_external.object({
|
|
|
36499
36865
|
var uuid13 = exports_external.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/);
|
|
36500
36866
|
var context = { userId: uuid13.optional(), membershipId: uuid13.optional() };
|
|
36501
36867
|
var page2 = { limit: exports_external.number().int().min(1).max(100).optional(), cursor: exports_external.string().min(1).max(2048).optional() };
|
|
36502
|
-
var directory = exports_external.string().max(4096).refine(
|
|
36868
|
+
var directory = exports_external.string().max(4096).refine(isAbsolute23, "Use an absolute recovery directory");
|
|
36503
36869
|
var email4 = exports_external.string().trim().toLowerCase().email().max(254);
|
|
36504
36870
|
var code = exports_external.string().regex(/^\d{6}$/);
|
|
36505
36871
|
var recurringSurfaceSchemas = {
|
|
@@ -37628,6 +37994,8 @@ var STATION_SNAPSHOT_PRODUCER = { name: "@hasna/skills", version: package_defaul
|
|
|
37628
37994
|
var STATION_HYDRATION_PRODUCER = { name: "@hasna/skills", version: package_default.version };
|
|
37629
37995
|
var MANIFEST_HASH_KEY_SEP = String.fromCharCode(0);
|
|
37630
37996
|
var SESSION_RECONCILIATION_PLAN_TTL_MS = 5 * 60 * 1000;
|
|
37997
|
+
var SESSION_RENEWAL_REFUSAL_TTL_MS = 5 * 60 * 1000;
|
|
37998
|
+
var SESSION_RENEWAL_REFUSAL_MAX_BYTES = 4 * 1024;
|
|
37631
37999
|
|
|
37632
38000
|
// src/lib/claude-skills-coordination.ts
|
|
37633
38001
|
class ClaudeSettingsRefusal extends Error {
|
|
@@ -37667,7 +38035,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
37667
38035
|
function skillsPolicyLocations(dataDir3) {
|
|
37668
38036
|
const state = (path) => existsSync11(path) ? "present" : "absent";
|
|
37669
38037
|
if (dataDir3 !== undefined)
|
|
37670
|
-
return [`${join11(
|
|
38038
|
+
return [`${join11(resolve9(dataDir3), "agent-policy.json")} (explicit data directory, absent)`];
|
|
37671
38039
|
const env = process.env, home = env.HOME || env.USERPROFILE || homedir6() || "/tmp", searched = [];
|
|
37672
38040
|
let selected = false;
|
|
37673
38041
|
for (const key of ["HASNA_SKILLS_DIR", "HASNA_SKILLS_HOME", "SKILLS_HOME"]) {
|
|
@@ -37678,7 +38046,7 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
37678
38046
|
searched.push(`$${key} (unset)`);
|
|
37679
38047
|
else {
|
|
37680
38048
|
selected = true;
|
|
37681
|
-
searched.push(`$${key} -> ${join11(
|
|
38049
|
+
searched.push(`$${key} -> ${join11(resolve9(value), "agent-policy.json")} (selected, absent)`);
|
|
37682
38050
|
}
|
|
37683
38051
|
}
|
|
37684
38052
|
const override = env.HASNA_DATA_HOME;
|
|
@@ -37704,7 +38072,7 @@ function planCoordinatedClaudeSettings(before, replacement, options) {
|
|
|
37704
38072
|
const plan = planClaudeHookEventsUpdate({
|
|
37705
38073
|
...options,
|
|
37706
38074
|
events: selected,
|
|
37707
|
-
expectedSettingsSha256: before === null ? "absent" :
|
|
38075
|
+
expectedSettingsSha256: before === null ? "absent" : createHash9("sha256").update(before).digest("hex"),
|
|
37708
38076
|
replacement
|
|
37709
38077
|
});
|
|
37710
38078
|
if (!plan) {
|
|
@@ -37724,7 +38092,7 @@ function coordinateClaudeSettings(before, replacement, options, beforeWrite) {
|
|
|
37724
38092
|
}
|
|
37725
38093
|
|
|
37726
38094
|
// src/lib/installer.ts
|
|
37727
|
-
var __dirname2 =
|
|
38095
|
+
var __dirname2 = dirname9(fileURLToPath3(import.meta.url));
|
|
37728
38096
|
var HOOKS_DIR = existsSync12(join12(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join12(__dirname2, "..", "..", "hooks") : join12(__dirname2, "..", "hooks");
|
|
37729
38097
|
function normalizeHookName(name) {
|
|
37730
38098
|
return name.startsWith("hook-") ? name : `hook-${name}`;
|
|
@@ -37795,9 +38163,9 @@ function getTargetSettingsDir(target) {
|
|
|
37795
38163
|
}
|
|
37796
38164
|
function getGlobalSettingsPathOverride(target) {
|
|
37797
38165
|
if (target === "codex")
|
|
37798
|
-
return process.env.HASNA_HOOKS_CODEX_SETTINGS_PATH ?? (process.env.CODEX_HOME ?
|
|
38166
|
+
return process.env.HASNA_HOOKS_CODEX_SETTINGS_PATH ?? (process.env.CODEX_HOME ? resolve21(process.env.CODEX_HOME, "hooks.json") : undefined);
|
|
37799
38167
|
if (target === "claude")
|
|
37800
|
-
return process.env.HASNA_HOOKS_CLAUDE_SETTINGS_PATH ?? (process.env.CLAUDE_CONFIG_DIR ?
|
|
38168
|
+
return process.env.HASNA_HOOKS_CLAUDE_SETTINGS_PATH ?? (process.env.CLAUDE_CONFIG_DIR ? resolve21(process.env.CLAUDE_CONFIG_DIR, "settings.json") : undefined);
|
|
37801
38169
|
if (target === "gemini")
|
|
37802
38170
|
return process.env.HASNA_HOOKS_GEMINI_SETTINGS_PATH;
|
|
37803
38171
|
return;
|
|
@@ -37835,29 +38203,29 @@ function readSettings(scope = "global", target = "claude") {
|
|
|
37835
38203
|
const path = getSettingsPath(scope, target);
|
|
37836
38204
|
if (target === "codex")
|
|
37837
38205
|
return readCodexSettings(path);
|
|
37838
|
-
let
|
|
38206
|
+
let reason2 = "cannot be read";
|
|
37839
38207
|
try {
|
|
37840
38208
|
if (existsSync12(path)) {
|
|
37841
38209
|
const text3 = readFileSync8(path, "utf-8");
|
|
37842
|
-
|
|
38210
|
+
reason2 = "is not valid JSON";
|
|
37843
38211
|
const value = JSON.parse(text3);
|
|
37844
|
-
|
|
38212
|
+
reason2 = "does not hold a JSON object";
|
|
37845
38213
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
37846
|
-
throw new TypeError(
|
|
38214
|
+
throw new TypeError(reason2);
|
|
37847
38215
|
settingsPreimages.set(value, { path, text: text3 });
|
|
37848
38216
|
return value;
|
|
37849
38217
|
}
|
|
37850
38218
|
} catch (error61) {
|
|
37851
38219
|
const code2 = error61?.code;
|
|
37852
|
-
if (
|
|
37853
|
-
|
|
38220
|
+
if (reason2 === "cannot be read" && typeof code2 === "string")
|
|
38221
|
+
reason2 += ` (${code2})`;
|
|
37854
38222
|
console.warn("[hooks] Cannot read hook settings; repair the selected file before installation.");
|
|
37855
38223
|
}
|
|
37856
38224
|
const empty = {};
|
|
37857
38225
|
if (!existsSync12(path))
|
|
37858
38226
|
settingsPreimages.set(empty, { path, text: null });
|
|
37859
38227
|
else
|
|
37860
|
-
unreadableSettings.set(empty, { path, reason });
|
|
38228
|
+
unreadableSettings.set(empty, { path, reason: reason2 });
|
|
37861
38229
|
return empty;
|
|
37862
38230
|
}
|
|
37863
38231
|
function unreadableSettingsRefusal(settings, path) {
|
|
@@ -37865,13 +38233,13 @@ function unreadableSettingsRefusal(settings, path) {
|
|
|
37865
38233
|
if (captured?.path === path && captured.text !== null || !existsSync12(path))
|
|
37866
38234
|
return;
|
|
37867
38235
|
const failed = unreadableSettings.get(settings);
|
|
37868
|
-
const
|
|
37869
|
-
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${
|
|
38236
|
+
const reason2 = captured?.path === path ? "was created after Hooks read the settings" : failed?.path === path ? failed.reason : "was not read as a settings object";
|
|
38237
|
+
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${reason2}, so Hooks wrote nothing. Repair the file or move it aside, then retry.`);
|
|
37870
38238
|
}
|
|
37871
38239
|
function settingsIdentity(path) {
|
|
37872
38240
|
if (existsSync12(path))
|
|
37873
|
-
return
|
|
37874
|
-
return existsSync12(
|
|
38241
|
+
return realpathSync9(path);
|
|
38242
|
+
return existsSync12(dirname9(path)) ? join12(realpathSync9(dirname9(path)), basename5(path)) : resolve21(path);
|
|
37875
38243
|
}
|
|
37876
38244
|
function coordinatesWithSkills(path, target) {
|
|
37877
38245
|
return target === "claude" && settingsIdentity(path) === settingsIdentity(join12(homedir7(), ".claude/settings.json"));
|
|
@@ -37906,7 +38274,7 @@ function writeSettings(settings, scope = "global", target = "claude", expectedSe
|
|
|
37906
38274
|
if (expectedSettingsSha256 !== undefined)
|
|
37907
38275
|
return writeHookSettingsPreimage(path, settings, captured.text, beforeWrite);
|
|
37908
38276
|
beforeWrite?.();
|
|
37909
|
-
const dir =
|
|
38277
|
+
const dir = dirname9(path);
|
|
37910
38278
|
if (!existsSync12(dir)) {
|
|
37911
38279
|
mkdirSync7(dir, { recursive: true });
|
|
37912
38280
|
}
|
|
@@ -38013,7 +38381,7 @@ function readCodewithConfig(scope, configPath) {
|
|
|
38013
38381
|
}
|
|
38014
38382
|
function appendCodewithFragment(fragment, scope, configPath) {
|
|
38015
38383
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
38016
|
-
const dir =
|
|
38384
|
+
const dir = dirname9(path);
|
|
38017
38385
|
if (!existsSync12(dir))
|
|
38018
38386
|
mkdirSync7(dir, { recursive: true });
|
|
38019
38387
|
const existing = existsSync12(path) ? readFileSync8(path, "utf-8") : "";
|
|
@@ -38459,11 +38827,11 @@ init_transport();
|
|
|
38459
38827
|
init_config();
|
|
38460
38828
|
init_local_opt_in();
|
|
38461
38829
|
var localNoticePrinted = false;
|
|
38462
|
-
function announceLocal(notice,
|
|
38830
|
+
function announceLocal(notice, reason2) {
|
|
38463
38831
|
if (localNoticePrinted)
|
|
38464
38832
|
return;
|
|
38465
38833
|
localNoticePrinted = true;
|
|
38466
|
-
const line = `hooks: LOCAL mode \u2014 ${
|
|
38834
|
+
const line = `hooks: LOCAL mode \u2014 ${reason2}; using the bundled registry and the local store at ` + `${getHooksDataDir()}, not a remote registry. Set HASNA_HOOKS_API_KEY (or the Keychain item ` + `hasna.credentials.hooks.api-key / ~/.hasna/hooks/config/credentials) to go remote.`;
|
|
38467
38835
|
if (notice)
|
|
38468
38836
|
notice(line);
|
|
38469
38837
|
else if (typeof process !== "undefined")
|
|
@@ -38970,7 +39338,7 @@ function coerceForSqlite(value) {
|
|
|
38970
39338
|
return String(value);
|
|
38971
39339
|
}
|
|
38972
39340
|
// src/mcp/server.ts
|
|
38973
|
-
var __dirname3 =
|
|
39341
|
+
var __dirname3 = dirname23(fileURLToPath4(import.meta.url));
|
|
38974
39342
|
var pkg = { name: "@hasna/hooks", version: "0.0.0" };
|
|
38975
39343
|
try {
|
|
38976
39344
|
for (const rel of ["../../package.json", "../package.json", "../../../package.json"]) {
|