@hasna/hooks 0.12.7 → 0.12.9
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/README.md +14 -1
- package/bin/hooks-mcp.js +982 -608
- package/bin/index.js +1322 -930
- package/bin/native-safety-worker.cjs +1 -1
- package/dist/index.js +1229 -825
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-check.d.ts +7 -3
- package/dist/lib/codex-safety-trust.d.ts +24 -4
- package/dist/lib/installer.d.ts +7 -2
- package/dist/lib/native-safety-registration.d.ts +25 -2
- package/dist/native-safety.d.ts +10 -2
- package/dist/native-safety.js +18 -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.55+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.55+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,214 @@ 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
|
+
"codex-cli 0.161.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
11560
|
+
};
|
|
11561
|
+
function supportsCodexNativeCapability(version, capability) {
|
|
11562
|
+
return typeof version === "string" && Object.hasOwn(MEASURED_CODEX_CAPABILITIES, version) && MEASURED_CODEX_CAPABILITIES[version].includes(capability);
|
|
11563
|
+
}
|
|
11564
|
+
var SUPPORTED_CODEX_HOOK_VERSIONS = Object.freeze(Object.keys(MEASURED_CODEX_CAPABILITIES).filter((version) => supportsCodexNativeCapability(version, "hooks")));
|
|
11565
|
+
var CLAUDE_MARKETPLACE_ENTRY_HASH_MODE = "claude-marketplace-entry-v1";
|
|
11566
|
+
var DOMAIN = "hasna.skills.claude-marketplace-entry.v1\x00";
|
|
11567
|
+
var PATH_CHARACTERS = 4096;
|
|
11568
|
+
var NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
11569
|
+
function need2(value, reason) {
|
|
11570
|
+
if (!value)
|
|
11571
|
+
throw new Error(`Claude marketplace entry witness ${reason}`);
|
|
11572
|
+
}
|
|
11573
|
+
var bounded = (key) => key.length > 64 ? `${key.slice(0, 64)}...` : key;
|
|
11574
|
+
var quote3 = (text) => JSON.stringify(text).replace(/[^\x20-\x7e]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
11575
|
+
var child = (path, key) => path + (/^[A-Za-z0-9_$-]{1,64}$/.test(key) ? `.${key}` : `[${JSON.stringify(bounded(key))}]`);
|
|
11576
|
+
function unknownKey(selector, path, key) {
|
|
11577
|
+
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}`);
|
|
11578
|
+
}
|
|
11579
|
+
function knownKeys(object, allowed, selector, path) {
|
|
11580
|
+
for (const [key] of object.entries)
|
|
11581
|
+
if (!allowed.has(key))
|
|
11582
|
+
unknownKey(selector, path, key);
|
|
11583
|
+
}
|
|
11584
|
+
var reason = (error) => String(error?.message ?? error).replace(/^Claude settings witness /, "");
|
|
11585
|
+
var MARKETPLACE_KEYS = new Set(["$schema", "name", "owner", "plugins", "description", "version", "metadata", "forceRemoveDeletedPlugins", "allowCrossMarketplaceDependenciesOn", "renames"]);
|
|
11586
|
+
var MARKETPLACE_METADATA_KEYS = new Set(["description", "version", "pluginRoot"]);
|
|
11587
|
+
var ENTRY_BOUND_KEYS = new Set([
|
|
11588
|
+
"name",
|
|
11589
|
+
"source",
|
|
11590
|
+
"strict",
|
|
11591
|
+
"defaultEnabled",
|
|
11592
|
+
"dependencies",
|
|
11593
|
+
"relevance",
|
|
11594
|
+
"headers",
|
|
11595
|
+
"headersHelper",
|
|
11596
|
+
"settings",
|
|
11597
|
+
"userConfig",
|
|
11598
|
+
"types",
|
|
11599
|
+
"channels",
|
|
11600
|
+
"skills",
|
|
11601
|
+
"commands",
|
|
11602
|
+
"agents",
|
|
11603
|
+
"hooks",
|
|
11604
|
+
"mcpServers",
|
|
11605
|
+
"lspServers",
|
|
11606
|
+
"outputStyles",
|
|
11607
|
+
"workflows",
|
|
11608
|
+
"experimental",
|
|
11609
|
+
"themes",
|
|
11610
|
+
"monitors"
|
|
11611
|
+
]);
|
|
11612
|
+
var ENTRY_OMITTED_KEYS = new Set(["$schema", "description", "version", "author", "homepage", "repository", "license", "keywords", "category", "tags", "displayName", "metadata"]);
|
|
11613
|
+
var EXPERIMENTAL_KEYS = new Set(["themes", "monitors", "evals"]);
|
|
11614
|
+
var SOURCE_KEYS = Object.freeze({
|
|
11615
|
+
github: ["source", "repo", "ref", "sha"],
|
|
11616
|
+
url: ["source", "url", "ref", "sha", "path"],
|
|
11617
|
+
"git-subdir": ["source", "url", "path", "ref", "sha"],
|
|
11618
|
+
npm: ["source", "package", "version", "registry"],
|
|
11619
|
+
archive: ["source", "url", "sha256"],
|
|
11620
|
+
command: ["source", "command", "timeout", "mode"]
|
|
11621
|
+
});
|
|
11622
|
+
var field = (object, key) => object.entries.find(([name]) => name === key)?.[1];
|
|
11623
|
+
var isString = (value) => value?.kind === "string";
|
|
11624
|
+
var isBoolean = (value) => value?.kind === "literal" && (value.value === "true" || value.value === "false");
|
|
11625
|
+
var stringArray = (value) => value?.kind === "array" && value.items.every(isString);
|
|
11626
|
+
var stringObject = (value) => value?.kind === "object" && value.entries.every(([, item]) => isString(item));
|
|
11627
|
+
function claudeMarketplaceEntrySourceValid(source) {
|
|
11628
|
+
const path = source?.path;
|
|
11629
|
+
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);
|
|
11630
|
+
}
|
|
11631
|
+
function canonical2(value) {
|
|
11632
|
+
if (value.kind === "string")
|
|
11633
|
+
return JSON.stringify(value.value);
|
|
11634
|
+
if (value.kind === "number" || value.kind === "literal")
|
|
11635
|
+
return value.value;
|
|
11636
|
+
if (value.kind === "array")
|
|
11637
|
+
return "[" + value.items.map(canonical2).join(",") + "]";
|
|
11638
|
+
return "{" + [...value.entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => JSON.stringify(key) + ":" + canonical2(item)).join(",") + "}";
|
|
11639
|
+
}
|
|
11640
|
+
function validateMarketplace(root, selector) {
|
|
11641
|
+
knownKeys(root, MARKETPLACE_KEYS, selector, null);
|
|
11642
|
+
const name = field(root, "name");
|
|
11643
|
+
need2(isString(name) && name.value === selector.marketplace, "marketplace name does not match the reviewed binding");
|
|
11644
|
+
for (const key of ["$schema", "description", "version"]) {
|
|
11645
|
+
const value = field(root, key);
|
|
11646
|
+
need2(value === undefined || isString(value), `has an invalid marketplace ${key}`);
|
|
11647
|
+
}
|
|
11648
|
+
const owner = field(root, "owner");
|
|
11649
|
+
need2(owner === undefined || owner.kind === "object", "has an invalid marketplace owner");
|
|
11650
|
+
const metadata = field(root, "metadata");
|
|
11651
|
+
if (metadata !== undefined) {
|
|
11652
|
+
need2(metadata.kind === "object", "has an invalid marketplace metadata object");
|
|
11653
|
+
knownKeys(metadata, MARKETPLACE_METADATA_KEYS, selector, "metadata");
|
|
11654
|
+
for (const [key, value] of metadata.entries)
|
|
11655
|
+
need2(isString(value), `has an invalid marketplace metadata.${key}`);
|
|
11656
|
+
}
|
|
11657
|
+
const remove = field(root, "forceRemoveDeletedPlugins");
|
|
11658
|
+
need2(remove === undefined || isBoolean(remove), "has an invalid forceRemoveDeletedPlugins value");
|
|
11659
|
+
const cross = field(root, "allowCrossMarketplaceDependenciesOn");
|
|
11660
|
+
need2(cross === undefined || stringArray(cross), "has an invalid allowCrossMarketplaceDependenciesOn value");
|
|
11661
|
+
const renames = field(root, "renames");
|
|
11662
|
+
if (renames !== undefined) {
|
|
11663
|
+
need2(renames.kind === "object" && renames.entries.every(([, target]) => isString(target) || target.kind === "literal" && target.value === "null"), "has an invalid renames map");
|
|
11664
|
+
need2(!renames.entries.some(([from]) => from.toLowerCase() === selector.plugin.toLowerCase()), "plugin id is redirected by the marketplace renames map");
|
|
11665
|
+
}
|
|
11666
|
+
}
|
|
11667
|
+
function validateSource(source, selector, path) {
|
|
11668
|
+
if (isString(source)) {
|
|
11669
|
+
need2(source.value.length > 0, "has an empty plugin source");
|
|
11670
|
+
return;
|
|
11671
|
+
}
|
|
11672
|
+
need2(source?.kind === "object", "has an invalid plugin source");
|
|
11673
|
+
const type = field(source, "source");
|
|
11674
|
+
need2(isString(type) && Object.hasOwn(SOURCE_KEYS, type.value), "has an unreviewed plugin source type");
|
|
11675
|
+
knownKeys(source, new Set(SOURCE_KEYS[type.value]), selector, path);
|
|
11676
|
+
}
|
|
11677
|
+
function projectEntry(entry, selector) {
|
|
11678
|
+
const path = `plugins[${selector.plugin}]`;
|
|
11679
|
+
knownKeys(entry, { has: (key) => ENTRY_BOUND_KEYS.has(key) || ENTRY_OMITTED_KEYS.has(key) }, selector, path);
|
|
11680
|
+
const name = field(entry, "name");
|
|
11681
|
+
need2(isString(name) && name.value === selector.plugin, "selected entry name does not match");
|
|
11682
|
+
validateSource(field(entry, "source"), selector, `${path}.source`);
|
|
11683
|
+
for (const key of ["strict", "defaultEnabled"]) {
|
|
11684
|
+
const value = field(entry, key);
|
|
11685
|
+
need2(value === undefined || isBoolean(value), `has an invalid entry ${key}`);
|
|
11686
|
+
}
|
|
11687
|
+
const headersHelper = field(entry, "headersHelper");
|
|
11688
|
+
need2(headersHelper === undefined || isString(headersHelper), "has an invalid entry headersHelper");
|
|
11689
|
+
const experimental = field(entry, "experimental");
|
|
11690
|
+
if (experimental !== undefined) {
|
|
11691
|
+
need2(experimental.kind === "object", "has an invalid entry experimental object");
|
|
11692
|
+
knownKeys(experimental, EXPERIMENTAL_KEYS, selector, `${path}.experimental`);
|
|
11693
|
+
}
|
|
11694
|
+
for (const key of ["$schema", "description", "version", "homepage", "license", "category", "displayName"]) {
|
|
11695
|
+
const value = field(entry, key);
|
|
11696
|
+
need2(value === undefined || isString(value), `has an invalid entry ${key}`);
|
|
11697
|
+
}
|
|
11698
|
+
for (const [key, keys] of [["author", new Set(["name", "email", "url"])], ["repository", new Set(["type", "url", "directory"])]]) {
|
|
11699
|
+
const value = field(entry, key);
|
|
11700
|
+
if (value?.kind === "object")
|
|
11701
|
+
knownKeys(value, keys, selector, `${path}.${key}`);
|
|
11702
|
+
need2(value === undefined || isString(value) || stringObject(value), `has an invalid entry ${key}`);
|
|
11703
|
+
}
|
|
11704
|
+
for (const key of ["keywords", "tags"]) {
|
|
11705
|
+
const value = field(entry, key);
|
|
11706
|
+
need2(value === undefined || stringArray(value), `has an invalid entry ${key}`);
|
|
11707
|
+
}
|
|
11708
|
+
const metadata = field(entry, "metadata");
|
|
11709
|
+
need2(metadata === undefined || metadata.kind === "object", "has an invalid entry metadata object");
|
|
11710
|
+
return { kind: "object", entries: entry.entries.filter(([key]) => ENTRY_BOUND_KEYS.has(key)) };
|
|
11711
|
+
}
|
|
11712
|
+
function hashClaudeMarketplaceEntry(text, selector) {
|
|
11713
|
+
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");
|
|
11714
|
+
let root;
|
|
11715
|
+
try {
|
|
11716
|
+
root = parseNativeJsonObject(text);
|
|
11717
|
+
} catch (error) {
|
|
11718
|
+
throw new Error(`Claude marketplace entry witness cannot parse marketplace.json: ${reason(error)}`);
|
|
11719
|
+
}
|
|
11720
|
+
validateMarketplace(root, selector);
|
|
11721
|
+
const plugins = field(root, "plugins");
|
|
11722
|
+
need2(plugins?.kind === "array", "requires a plugins array");
|
|
11723
|
+
const entryName = (item) => {
|
|
11724
|
+
if (item.kind !== "object")
|
|
11725
|
+
return;
|
|
11726
|
+
const name = field(item, "name");
|
|
11727
|
+
return isString(name) ? name.value : undefined;
|
|
11728
|
+
};
|
|
11729
|
+
const exact = plugins.items.filter((item) => entryName(item) === selector.plugin);
|
|
11730
|
+
const folded = plugins.items.filter((item) => entryName(item)?.toLowerCase() === selector.plugin.toLowerCase());
|
|
11731
|
+
need2(exact.length > 0, "selected plugin entry is missing");
|
|
11732
|
+
need2(exact.length === 1 && folded.length === 1, "selected plugin entry is duplicated or ambiguous");
|
|
11733
|
+
const entry = projectEntry(exact[0], selector);
|
|
11734
|
+
const metadata = field(root, "metadata"), pluginRoot = metadata?.kind === "object" ? field(metadata, "pluginRoot") : undefined;
|
|
11735
|
+
const nullValue = { kind: "literal", value: "null" };
|
|
11736
|
+
const marketplace = { kind: "object", entries: [
|
|
11737
|
+
["name", field(root, "name")],
|
|
11738
|
+
["pluginRoot", pluginRoot ?? nullValue],
|
|
11739
|
+
["allowCrossMarketplaceDependenciesOn", field(root, "allowCrossMarketplaceDependenciesOn") ?? nullValue]
|
|
11740
|
+
] };
|
|
11741
|
+
const projection = { kind: "object", entries: [["marketplace", marketplace], ["plugin", entry]] };
|
|
11742
|
+
return createHash42("sha256").update(DOMAIN).update(canonical2(projection)).digest("hex");
|
|
11743
|
+
}
|
|
11744
|
+
function captureClaudeMarketplaceEntry(path, marketplace, plugin, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
11745
|
+
need2(claudeMarketplaceEntrySourceValid({ path, marketplace, plugin }), "requires a normalized absolute .claude-plugin/marketplace.json path and exact names");
|
|
11746
|
+
let text;
|
|
11747
|
+
try {
|
|
11748
|
+
text = readNativeSettingsWitnessFile(path, budget2, "marketplace.json");
|
|
11749
|
+
} catch (error) {
|
|
11750
|
+
throw new Error(`Claude marketplace entry witness cannot read marketplace.json: ${reason(error)}`);
|
|
11751
|
+
}
|
|
11752
|
+
return { path, hashMode: CLAUDE_MARKETPLACE_ENTRY_HASH_MODE, marketplace, plugin, sha256: hashClaudeMarketplaceEntry(text, { marketplace, plugin }) };
|
|
11753
|
+
}
|
|
11516
11754
|
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
11755
|
function object(value) {
|
|
11518
11756
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -11566,7 +11804,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11566
11804
|
text(control.pluginId, 1024);
|
|
11567
11805
|
text(control.namespace, 64);
|
|
11568
11806
|
text(control.pluginParent);
|
|
11569
|
-
requireBound(
|
|
11807
|
+
requireBound(isAbsolute4(control.pluginParent) && resolve42(control.pluginParent) === control.pluginParent && /^[a-f0-9]{64}$/.test(control.manifestSha256));
|
|
11570
11808
|
if (control.remotePluginId !== undefined)
|
|
11571
11809
|
requireBound(typeof control.remotePluginId === "string" && /^[A-Za-z0-9_~-]{1,1024}$/.test(control.remotePluginId));
|
|
11572
11810
|
if (control.skillsOnly !== undefined)
|
|
@@ -11578,16 +11816,24 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11578
11816
|
}
|
|
11579
11817
|
if (bridge.codexInactivePlugins !== undefined) {
|
|
11580
11818
|
const controls = array(bridge.codexInactivePlugins, 4096), ids = new Set;
|
|
11581
|
-
requireBound(controls.length === 0 || object(bridge.codexPluginSkillReview) && bridge.codexPluginSkillReview.version
|
|
11819
|
+
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
11820
|
for (const control of controls) {
|
|
11583
11821
|
requireBound(object(control) && Object.keys(control).every((key) => ["pluginId", "namespace", "pluginParent", "sourceType", "sourceSha256"].includes(key)));
|
|
11584
11822
|
text(control.pluginId, 1024);
|
|
11585
11823
|
text(control.namespace, 64);
|
|
11586
11824
|
text(control.pluginParent);
|
|
11587
|
-
requireBound(!ids.has(control.pluginId) &&
|
|
11825
|
+
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
11826
|
ids.add(control.pluginId);
|
|
11589
11827
|
}
|
|
11590
11828
|
}
|
|
11829
|
+
if (bridge.discoveryExecutables !== undefined)
|
|
11830
|
+
for (const [agent, executable] of Object.entries(record(bridge.discoveryExecutables, AGENT_POLICY_LIMITS.agents))) {
|
|
11831
|
+
requireBound(agent === "gemini" && object(executable) && Object.keys(executable).length === 3 && executable.command === "gemini");
|
|
11832
|
+
for (const path of [executable.path, executable.target]) {
|
|
11833
|
+
text(path);
|
|
11834
|
+
requireBound(!/[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(path) && isAbsolute4(path) && resolve42(path) === path);
|
|
11835
|
+
}
|
|
11836
|
+
}
|
|
11591
11837
|
if (bridge.disabledBuiltins !== undefined)
|
|
11592
11838
|
for (const builtin of array(bridge.disabledBuiltins, AGENT_POLICY_LIMITS.builtinNames)) {
|
|
11593
11839
|
requireBound(object(builtin));
|
|
@@ -11613,11 +11859,11 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11613
11859
|
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
11860
|
for (const root of roots) {
|
|
11615
11861
|
text(root);
|
|
11616
|
-
requireBound(
|
|
11862
|
+
requireBound(isAbsolute4(root) && resolve42(root) === root);
|
|
11617
11863
|
}
|
|
11618
11864
|
for (const parent of parents2) {
|
|
11619
11865
|
text(parent);
|
|
11620
|
-
requireBound(
|
|
11866
|
+
requireBound(isAbsolute4(parent) && resolve42(parent) === parent);
|
|
11621
11867
|
}
|
|
11622
11868
|
for (const directory of array(proof.directories, AGENT_POLICY_LIMITS.discoveryDirectories)) {
|
|
11623
11869
|
requireBound(object(directory));
|
|
@@ -11630,14 +11876,14 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11630
11876
|
}
|
|
11631
11877
|
if (value.codexInstallationInputs !== undefined) {
|
|
11632
11878
|
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
|
|
11879
|
+
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
11880
|
for (const input of inputs) {
|
|
11635
11881
|
requireBound(object(input) && Object.keys(input).every((key) => ["pluginId", "namespace", "pluginParent", "sourceRoot", "sourceSha256"].includes(key)));
|
|
11636
11882
|
text(input.pluginId, 1024);
|
|
11637
11883
|
text(input.namespace, 64);
|
|
11638
11884
|
text(input.pluginParent);
|
|
11639
11885
|
text(input.sourceRoot);
|
|
11640
|
-
requireBound(!ids.has(input.pluginId) && [input.pluginParent, input.sourceRoot].every((path) =>
|
|
11886
|
+
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
11887
|
ids.add(input.pluginId);
|
|
11642
11888
|
}
|
|
11643
11889
|
if (proof.directories !== undefined)
|
|
@@ -11654,17 +11900,19 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11654
11900
|
text(source.path);
|
|
11655
11901
|
requireBound(source.sha256 === null || typeof source.sha256 === "string" && /^[a-f0-9]{64}$/.test(source.sha256));
|
|
11656
11902
|
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));
|
|
11903
|
+
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
11904
|
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) &&
|
|
11905
|
+
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
11906
|
if (source.hashMode === "sumi-settings-v1")
|
|
11661
|
-
requireBound(agent === "sumi" && value.agent === "sumi" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) &&
|
|
11907
|
+
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
11908
|
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) &&
|
|
11909
|
+
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");
|
|
11910
|
+
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4"))
|
|
11911
|
+
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
11912
|
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) &&
|
|
11913
|
+
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");
|
|
11914
|
+
if (source.hashMode === "claude-marketplace-entry-v1")
|
|
11915
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && claudeMarketplaceEntrySourceValid(source));
|
|
11668
11916
|
if (source.hashMode === "claude-plugin-registry") {
|
|
11669
11917
|
requireBound(agent === "claude");
|
|
11670
11918
|
const managed = array(source.managedPlugins, 64);
|
|
@@ -11679,8 +11927,8 @@ function assertAgentPolicyCollections(policy) {
|
|
|
11679
11927
|
if (source.format !== undefined)
|
|
11680
11928
|
requireBound(["json", "toml", "yaml"].includes(source.format));
|
|
11681
11929
|
if (source.fields !== undefined)
|
|
11682
|
-
for (const
|
|
11683
|
-
text(
|
|
11930
|
+
for (const field2 of array(source.fields, AGENT_POLICY_LIMITS.fields))
|
|
11931
|
+
text(field2, 256);
|
|
11684
11932
|
}
|
|
11685
11933
|
if (value.directories !== undefined)
|
|
11686
11934
|
for (const directory of array(value.directories, AGENT_POLICY_LIMITS.discoveryDirectories)) {
|
|
@@ -11772,7 +12020,7 @@ function quoted(value) {
|
|
|
11772
12020
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
11773
12021
|
}
|
|
11774
12022
|
function hermesHookDefinitions(supervisor2) {
|
|
11775
|
-
if (!
|
|
12023
|
+
if (!isAbsolute5(supervisor2.runtime) || !isAbsolute5(supervisor2.path))
|
|
11776
12024
|
throw new Error("Expected absolute Hermes supervisor paths");
|
|
11777
12025
|
const entry = (event) => ({ command: `${quoted(supervisor2.runtime)} ${quoted(supervisor2.path)} --event ${event}`, timeout: 15, ...event === "pre_tool_call" ? { fail_closed: true } : {} });
|
|
11778
12026
|
return { pre_llm_call: entry("pre_llm_call"), pre_tool_call: entry("pre_tool_call") };
|
|
@@ -11785,16 +12033,16 @@ function assertHermesEnvironment(home) {
|
|
|
11785
12033
|
throw new Error(`NATIVE_SKILL_DRIFT: Hermes ${variable} requires a dedicated discovery adapter; unset it before using this adapter`);
|
|
11786
12034
|
}
|
|
11787
12035
|
const selected = process.env.HERMES_HOME?.trim();
|
|
11788
|
-
if (selected && (!
|
|
12036
|
+
if (selected && (!isAbsolute5(selected) || resolve5(selected) !== join82(resolve5(home), ".hermes")))
|
|
11789
12037
|
throw new Error("NATIVE_SKILL_DRIFT: custom Hermes homes/profiles require their own reviewed bridge");
|
|
11790
12038
|
if (process.env.HERMES_ENABLE_PROJECT_PLUGINS?.trim() && !["0", "false", "no", "off"].includes(process.env.HERMES_ENABLE_PROJECT_PLUGINS.trim().toLowerCase()))
|
|
11791
12039
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes project plugins require a dedicated discovery review");
|
|
11792
12040
|
}
|
|
11793
12041
|
function read(path) {
|
|
11794
|
-
for (let current2 = path;; current2 =
|
|
12042
|
+
for (let current2 = path;; current2 = dirname52(current2)) {
|
|
11795
12043
|
if (lstatSync42(current2, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
11796
12044
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes protection input");
|
|
11797
|
-
if (
|
|
12045
|
+
if (dirname52(current2) === current2)
|
|
11798
12046
|
break;
|
|
11799
12047
|
}
|
|
11800
12048
|
const stat = lstatSync42(path, { throwIfNoEntry: false });
|
|
@@ -11808,7 +12056,7 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
11808
12056
|
assertHermesEnvironment(home);
|
|
11809
12057
|
if (read(join82(home, ".hermes", HERMES_OPT_OUT)) === null)
|
|
11810
12058
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes bundled skill reseeding is not disabled; run skills hook install");
|
|
11811
|
-
if (!supervisor2 || !
|
|
12059
|
+
if (!supervisor2 || !isAbsolute5(supervisor2.path) || supervisor2.runtime !== process.execPath || read(supervisor2.path) !== renderHermesSupervisor(command, profile))
|
|
11812
12060
|
throw new Error("NATIVE_SKILL_DRIFT: Hermes owned supervisor changed; run skills hook install");
|
|
11813
12061
|
const raw = read(join82(home, ".hermes/shell-hooks-allowlist.json"));
|
|
11814
12062
|
let trust;
|
|
@@ -11834,10 +12082,10 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
11834
12082
|
}
|
|
11835
12083
|
function assertNoHermesLegacyShadow(root) {
|
|
11836
12084
|
let entries = 0;
|
|
11837
|
-
for (let cursor =
|
|
12085
|
+
for (let cursor = resolve5(root);; cursor = dirname52(cursor)) {
|
|
11838
12086
|
if (lstatSync42(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
11839
12087
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes legacy discovery root");
|
|
11840
|
-
if (
|
|
12088
|
+
if (dirname52(cursor) === cursor)
|
|
11841
12089
|
break;
|
|
11842
12090
|
}
|
|
11843
12091
|
function scan(path, depth) {
|
|
@@ -11858,10 +12106,10 @@ function assertNoHermesLegacyShadow(root) {
|
|
|
11858
12106
|
const hasDescriptor = Boolean(lstatSync42(join82(path, "SKILL.md"), { throwIfNoEntry: false }));
|
|
11859
12107
|
const directory = opendirSync(path);
|
|
11860
12108
|
try {
|
|
11861
|
-
for (let
|
|
11862
|
-
if (hasDescriptor && ["references", "templates", "assets", "scripts"].includes(
|
|
12109
|
+
for (let child2 = directory.readSync();child2; child2 = directory.readSync()) {
|
|
12110
|
+
if (hasDescriptor && ["references", "templates", "assets", "scripts"].includes(child2.name))
|
|
11863
12111
|
continue;
|
|
11864
|
-
scan(join82(path,
|
|
12112
|
+
scan(join82(path, child2.name), depth + 1);
|
|
11865
12113
|
}
|
|
11866
12114
|
} finally {
|
|
11867
12115
|
directory.closeSync();
|
|
@@ -11916,15 +12164,15 @@ await new Promise((resolve, reject) => process.stdout.write(JSON.stringify(outpu
|
|
|
11916
12164
|
if (failed) process.exitCode = 2;
|
|
11917
12165
|
`;
|
|
11918
12166
|
}
|
|
11919
|
-
function
|
|
12167
|
+
function need3(value, message) {
|
|
11920
12168
|
if (!value)
|
|
11921
12169
|
throw new Error(message);
|
|
11922
12170
|
}
|
|
11923
12171
|
function safe(path) {
|
|
11924
|
-
|
|
11925
|
-
for (let cursor = path;; cursor =
|
|
11926
|
-
|
|
11927
|
-
if (
|
|
12172
|
+
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");
|
|
12173
|
+
for (let cursor = path;; cursor = dirname62(cursor)) {
|
|
12174
|
+
need3(!lstatSync5(cursor, { throwIfNoEntry: false })?.isSymbolicLink(), "Refusing symlink native discovery directory");
|
|
12175
|
+
if (dirname62(cursor) === cursor)
|
|
11928
12176
|
break;
|
|
11929
12177
|
}
|
|
11930
12178
|
}
|
|
@@ -11938,45 +12186,45 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
11938
12186
|
const root = lstatSync5(path, { throwIfNoEntry: false });
|
|
11939
12187
|
if (!root)
|
|
11940
12188
|
return { path, sha256: null };
|
|
11941
|
-
|
|
11942
|
-
const hash =
|
|
12189
|
+
need3(root.isDirectory(), "Unsupported native discovery directory input");
|
|
12190
|
+
const hash = createHash52("sha256");
|
|
11943
12191
|
function walk(current2, relative2, before, depth) {
|
|
11944
|
-
|
|
12192
|
+
need3(depth <= 64, "Native discovery directory depth limit exceeded");
|
|
11945
12193
|
const names = [], directory = opendirSync2(current2);
|
|
11946
12194
|
try {
|
|
11947
12195
|
for (let entry = directory.readSync();entry; entry = directory.readSync()) {
|
|
11948
|
-
|
|
12196
|
+
need3(++budget2.entries <= AGENT_POLICY_LIMITS.discoveryDirectoryEntries, "Native discovery directory entry limit exceeded");
|
|
11949
12197
|
names.push(entry.name);
|
|
11950
12198
|
}
|
|
11951
12199
|
} finally {
|
|
11952
12200
|
directory.closeSync();
|
|
11953
12201
|
}
|
|
11954
|
-
|
|
12202
|
+
need3(new Set(names).size === names.length, "Ambiguous native discovery directory names");
|
|
11955
12203
|
for (const name of names.sort()) {
|
|
11956
|
-
const
|
|
11957
|
-
if (omittedRoots.includes(
|
|
12204
|
+
const child2 = join92(current2, name), childRelative = relative2 ? `${relative2}/${name}` : name;
|
|
12205
|
+
if (omittedRoots.includes(child2))
|
|
11958
12206
|
continue;
|
|
11959
|
-
|
|
11960
|
-
const stat = lstatSync5(
|
|
11961
|
-
|
|
12207
|
+
need3(child2.length <= AGENT_POLICY_LIMITS.pathCharacters, "Native discovery directory path limit exceeded");
|
|
12208
|
+
const stat = lstatSync5(child2);
|
|
12209
|
+
need3(stat.isFile() || stat.isDirectory(), "Refusing symlink or special native discovery directory member");
|
|
11962
12210
|
const row = JSON.stringify([childRelative, stat.isDirectory() ? "directory" : "file"]) + `
|
|
11963
12211
|
`;
|
|
11964
12212
|
budget2.bytes += Buffer.byteLength(row);
|
|
11965
|
-
|
|
12213
|
+
need3(budget2.bytes <= AGENT_POLICY_LIMITS.discoveryDirectoryBytes, "Native discovery directory metadata limit exceeded");
|
|
11966
12214
|
hash.update(row);
|
|
11967
12215
|
rows?.push(row);
|
|
11968
|
-
if (stat.isDirectory() && !excludedRoots.includes(
|
|
11969
|
-
walk(
|
|
12216
|
+
if (stat.isDirectory() && !excludedRoots.includes(child2))
|
|
12217
|
+
walk(child2, childRelative, stat, depth + 1);
|
|
11970
12218
|
}
|
|
11971
|
-
|
|
12219
|
+
need3(same(before, lstatSync5(current2, { throwIfNoEntry: false })), "Native discovery directory changed while reading");
|
|
11972
12220
|
}
|
|
11973
12221
|
walk(path, "", root, 0);
|
|
11974
12222
|
safe(path);
|
|
11975
12223
|
return { path, sha256: hash.digest("hex") };
|
|
11976
12224
|
}
|
|
11977
12225
|
function captureDiscoveryDirectoryProjection(paths, omittedRoots) {
|
|
11978
|
-
|
|
11979
|
-
|
|
12226
|
+
need3(Array.isArray(paths) && paths.length <= AGENT_POLICY_LIMITS.discoveryDirectories && new Set(paths).size === paths.length, "Invalid projected discovery directory collection");
|
|
12227
|
+
need3(omittedRoots.length <= AGENT_POLICY_LIMITS.discoveryRoots && new Set(omittedRoots).size === omittedRoots.length, "Invalid inactive discovery roots");
|
|
11980
12228
|
for (const root of omittedRoots)
|
|
11981
12229
|
safe(root);
|
|
11982
12230
|
const budget2 = { entries: 0, bytes: 0 };
|
|
@@ -11986,57 +12234,57 @@ function captureDiscoveryDirectoryProjection(paths, omittedRoots) {
|
|
|
11986
12234
|
});
|
|
11987
12235
|
}
|
|
11988
12236
|
function verifyDiscoveryDirectoryProjection(directories, omittedRoots) {
|
|
11989
|
-
|
|
12237
|
+
need3(directories.length <= AGENT_POLICY_LIMITS.discoveryDirectories, "Invalid projected discovery directory collection");
|
|
11990
12238
|
let count = 0, bytes = 0;
|
|
11991
12239
|
const expected = directories.map((directory) => {
|
|
11992
12240
|
safe(directory.path);
|
|
11993
|
-
|
|
11994
|
-
const hash =
|
|
12241
|
+
need3(Array.isArray(directory.entries), "Missing reviewed directory membership inventory");
|
|
12242
|
+
const hash = createHash52("sha256");
|
|
11995
12243
|
const kept = [];
|
|
11996
12244
|
for (const row of directory.entries) {
|
|
11997
|
-
|
|
12245
|
+
need3(typeof row === "string" && ++count <= AGENT_POLICY_LIMITS.discoveryDirectoryEntries, "Invalid reviewed directory membership rows");
|
|
11998
12246
|
bytes += Buffer.byteLength(row);
|
|
11999
|
-
|
|
12247
|
+
need3(bytes <= AGENT_POLICY_LIMITS.discoveryDirectoryBytes, "Reviewed directory membership byte limit exceeded");
|
|
12000
12248
|
const value = JSON.parse(row);
|
|
12001
|
-
|
|
12249
|
+
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
12250
|
`, "Invalid reviewed directory member");
|
|
12003
12251
|
hash.update(row);
|
|
12004
12252
|
const path = join92(directory.path, value[0]);
|
|
12005
12253
|
if (!omittedRoots.some((root) => path === root || path.startsWith(root + "/")))
|
|
12006
12254
|
kept.push(row);
|
|
12007
12255
|
}
|
|
12008
|
-
|
|
12256
|
+
need3(directory.sha256 === null ? directory.entries.length === 0 : hash.digest("hex") === directory.sha256, "Reviewed directory inventory does not match its fingerprint");
|
|
12009
12257
|
const absent = omittedRoots.some((root) => directory.path === root || directory.path.startsWith(root + "/"));
|
|
12010
|
-
return { path: directory.path, sha256: absent || directory.sha256 === null ? null :
|
|
12258
|
+
return { path: directory.path, sha256: absent || directory.sha256 === null ? null : createHash52("sha256").update(kept.join("")).digest("hex") };
|
|
12011
12259
|
});
|
|
12012
12260
|
const current2 = captureDiscoveryDirectoryProjection(directories.map((item) => item.path), omittedRoots);
|
|
12013
|
-
|
|
12261
|
+
need3(current2.every((item, index) => item.sha256 === expected[index].sha256), "Native discovery directory membership changed outside retired Codex roots");
|
|
12014
12262
|
}
|
|
12015
12263
|
function captureDiscoveryDirectories(paths, excludedRoots = []) {
|
|
12016
|
-
|
|
12264
|
+
need3(Array.isArray(paths) && paths.length <= AGENT_POLICY_LIMITS.discoveryDirectories && new Set(paths).size === paths.length, "Invalid native discovery directory collection");
|
|
12017
12265
|
const budget2 = { entries: 0, bytes: 0 };
|
|
12018
12266
|
for (const root of excludedRoots)
|
|
12019
12267
|
safe(root);
|
|
12020
12268
|
return paths.map((path) => capture(path, budget2, excludedRoots));
|
|
12021
12269
|
}
|
|
12022
12270
|
function verifyDiscoveryDirectories(directories, excludedRoots = []) {
|
|
12023
|
-
|
|
12271
|
+
need3(Array.isArray(directories) && directories.length <= AGENT_POLICY_LIMITS.discoveryDirectories, "Invalid native discovery directory collection");
|
|
12024
12272
|
for (const directory of directories)
|
|
12025
|
-
|
|
12273
|
+
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
12274
|
const current2 = captureDiscoveryDirectories(directories.map((directory) => directory.path), excludedRoots);
|
|
12027
12275
|
for (let i = 0;i < directories.length; i++)
|
|
12028
|
-
|
|
12276
|
+
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
12277
|
}
|
|
12030
12278
|
function discoveryByteBudget() {
|
|
12031
12279
|
return { remaining: AGENT_POLICY_LIMITS.discoveryRawTotalBytes };
|
|
12032
12280
|
}
|
|
12033
12281
|
function safe2(path) {
|
|
12034
|
-
if (typeof path !== "string" || !
|
|
12282
|
+
if (typeof path !== "string" || !isAbsolute7(path) || path !== resolve7(path) || path.length > AGENT_POLICY_LIMITS.pathCharacters || path.includes("\x00"))
|
|
12035
12283
|
throw new Error("Expected a canonical absolute raw discovery path");
|
|
12036
|
-
for (let cursor = path;; cursor =
|
|
12284
|
+
for (let cursor = path;; cursor = dirname7(cursor)) {
|
|
12037
12285
|
if (lstatSync6(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
12038
12286
|
throw new Error("Refusing symlink raw discovery input");
|
|
12039
|
-
if (
|
|
12287
|
+
if (dirname7(cursor) === cursor)
|
|
12040
12288
|
break;
|
|
12041
12289
|
}
|
|
12042
12290
|
}
|
|
@@ -12055,7 +12303,7 @@ function hashRawDiscoveryFile(path, budget2, changes) {
|
|
|
12055
12303
|
if (bytes > AGENT_POLICY_LIMITS.discoveryRawSourceBytes)
|
|
12056
12304
|
throw new Error("Raw discovery file byte limit exceeded");
|
|
12057
12305
|
consume(budget2, bytes);
|
|
12058
|
-
return
|
|
12306
|
+
return createHash62("sha256").update(text2).digest("hex");
|
|
12059
12307
|
}
|
|
12060
12308
|
const initial = lstatSync6(path, { throwIfNoEntry: false });
|
|
12061
12309
|
if (!initial)
|
|
@@ -12069,7 +12317,7 @@ function hashRawDiscoveryFile(path, budget2, changes) {
|
|
|
12069
12317
|
const opened = fstatSync22(fd);
|
|
12070
12318
|
if (!opened.isFile() || !same2(initial, opened))
|
|
12071
12319
|
throw new Error("Raw discovery input changed during open");
|
|
12072
|
-
const hash =
|
|
12320
|
+
const hash = createHash62("sha256"), buffer = Buffer.alloc(64 * 1024);
|
|
12073
12321
|
let bytes = 0;
|
|
12074
12322
|
while (true) {
|
|
12075
12323
|
const count = readSync2(fd, buffer, 0, Math.min(buffer.length, AGENT_POLICY_LIMITS.discoveryRawSourceBytes - bytes + 1), null);
|
|
@@ -12100,12 +12348,12 @@ function identity2(stat, mutable = false) {
|
|
|
12100
12348
|
...mutable ? { size: String(stat.size), mtimeNs: String(stat.mtimeNs), ctimeNs: String(stat.ctimeNs) } : {}
|
|
12101
12349
|
};
|
|
12102
12350
|
}
|
|
12103
|
-
function
|
|
12104
|
-
if (typeof path !== "string" || !
|
|
12351
|
+
function canonical3(path) {
|
|
12352
|
+
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
12353
|
throw new Error("Expected a canonical absolute discovery path");
|
|
12106
12354
|
}
|
|
12107
12355
|
function trace(path) {
|
|
12108
|
-
|
|
12356
|
+
canonical3(path);
|
|
12109
12357
|
const rows = [], paths = [];
|
|
12110
12358
|
let metadataBytes = 0, steps = 0, links = 0, cursor = parse2(path).root, pending = path.slice(cursor.length).split(sep32);
|
|
12111
12359
|
function record2(path2, row) {
|
|
@@ -12130,7 +12378,7 @@ function trace(path) {
|
|
|
12130
12378
|
if (!component || component === ".")
|
|
12131
12379
|
continue;
|
|
12132
12380
|
if (component === "..") {
|
|
12133
|
-
cursor =
|
|
12381
|
+
cursor = dirname8(cursor);
|
|
12134
12382
|
continue;
|
|
12135
12383
|
}
|
|
12136
12384
|
const candidate = join102(cursor, component);
|
|
@@ -12150,11 +12398,11 @@ function trace(path) {
|
|
|
12150
12398
|
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
12399
|
throw new Error("Discovery link changed during read");
|
|
12152
12400
|
record2(candidate, { type: "link", target, ...identity2(stat, true) });
|
|
12153
|
-
if (
|
|
12401
|
+
if (isAbsolute8(target)) {
|
|
12154
12402
|
cursor = parse2(target).root;
|
|
12155
12403
|
root();
|
|
12156
12404
|
}
|
|
12157
|
-
const remainder =
|
|
12405
|
+
const remainder = isAbsolute8(target) ? target.slice(parse2(target).root.length) : target;
|
|
12158
12406
|
pending = [...remainder.split(sep32), ...pending];
|
|
12159
12407
|
if (pending.length + steps > AGENT_POLICY_LIMITS.discoveryPathSteps)
|
|
12160
12408
|
throw new Error("Discovery path step limit exceeded");
|
|
@@ -12197,12 +12445,12 @@ function hashDiscoveryPathFile(path, budget2, changes) {
|
|
|
12197
12445
|
const after = trace(path);
|
|
12198
12446
|
if (JSON.stringify(before.rows) !== JSON.stringify(after.rows) || before.file !== after.file)
|
|
12199
12447
|
throw new Error("Discovery path input changed during read");
|
|
12200
|
-
return
|
|
12448
|
+
return createHash7("sha256").update(JSON.stringify({ version: 1, path, rows: before.rows, content })).digest("hex");
|
|
12201
12449
|
}
|
|
12202
12450
|
var CLAUDE_PLUGIN_MANIFEST_LIMITS = Object.freeze({ bytes: 1024 * 1024, depth: 32, nodes: 65536, stringCharacters: 16384 });
|
|
12203
|
-
function requireValue(value,
|
|
12451
|
+
function requireValue(value, reason2) {
|
|
12204
12452
|
if (!value)
|
|
12205
|
-
throw new Error("Claude plugin manifest " +
|
|
12453
|
+
throw new Error("Claude plugin manifest " + reason2);
|
|
12206
12454
|
}
|
|
12207
12455
|
function parse32(text2) {
|
|
12208
12456
|
requireValue(Buffer.byteLength(text2, "utf8") <= CLAUDE_PLUGIN_MANIFEST_LIMITS.bytes, "exceeds its byte limit");
|
|
@@ -12278,7 +12526,7 @@ function parse32(text2) {
|
|
|
12278
12526
|
requireValue(at === text2.length && root.kind === "object", "requires a JSON object without trailing content");
|
|
12279
12527
|
return root;
|
|
12280
12528
|
}
|
|
12281
|
-
function
|
|
12529
|
+
function canonical4(value) {
|
|
12282
12530
|
if (value.kind === "string")
|
|
12283
12531
|
return JSON.stringify(value.value);
|
|
12284
12532
|
if (value.kind === "number")
|
|
@@ -12286,19 +12534,19 @@ function canonical3(value) {
|
|
|
12286
12534
|
if (value.kind === "literal")
|
|
12287
12535
|
return value.value;
|
|
12288
12536
|
if (value.kind === "array")
|
|
12289
|
-
return "[" + value.items.map(
|
|
12290
|
-
return "{" + value.entries.map(([key, item]) => JSON.stringify(key) + ":" +
|
|
12537
|
+
return "[" + value.items.map(canonical4).join(",") + "]";
|
|
12538
|
+
return "{" + value.entries.map(([key, item]) => JSON.stringify(key) + ":" + canonical4(item)).join(",") + "}";
|
|
12291
12539
|
}
|
|
12292
12540
|
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 " +
|
|
12541
|
+
function validateText(value, field2) {
|
|
12542
|
+
requireValue(value?.kind === "string" && value.value.length <= CLAUDE_PLUGIN_MANIFEST_LIMITS.stringCharacters, "has an invalid " + field2 + " field");
|
|
12295
12543
|
}
|
|
12296
12544
|
function validateDescriptiveFields(manifest) {
|
|
12297
12545
|
const values = new Map(manifest.entries);
|
|
12298
|
-
for (const
|
|
12299
|
-
const value = values.get(
|
|
12546
|
+
for (const field2 of ["description", "version", "homepage", "license"]) {
|
|
12547
|
+
const value = values.get(field2);
|
|
12300
12548
|
if (value !== undefined)
|
|
12301
|
-
validateText(value,
|
|
12549
|
+
validateText(value, field2);
|
|
12302
12550
|
}
|
|
12303
12551
|
const author = values.get("author");
|
|
12304
12552
|
if (author !== undefined) {
|
|
@@ -12323,10 +12571,10 @@ function hashClaudePluginManifest(text2) {
|
|
|
12323
12571
|
const manifest = parse32(text2);
|
|
12324
12572
|
validateDescriptiveFields(manifest);
|
|
12325
12573
|
const discovery = { kind: "object", entries: manifest.entries.filter(([key]) => !DESCRIPTIVE_FIELDS.has(key)) };
|
|
12326
|
-
return
|
|
12574
|
+
return createHash8("sha256").update(canonical4(discovery)).digest("hex");
|
|
12327
12575
|
}
|
|
12328
12576
|
function projectReviewedClaudePluginManifest(text2, reviewedSha256) {
|
|
12329
|
-
if (!/^[a-f0-9]{64}$/.test(reviewedSha256) ||
|
|
12577
|
+
if (!/^[a-f0-9]{64}$/.test(reviewedSha256) || createHash8("sha256").update(text2).digest("hex") !== reviewedSha256) {
|
|
12330
12578
|
throw new Error("Reviewed Claude plugin manifest changed before semantic projection");
|
|
12331
12579
|
}
|
|
12332
12580
|
return hashClaudePluginManifest(text2);
|
|
@@ -12582,8 +12830,8 @@ class BoundedTarReader {
|
|
|
12582
12830
|
}
|
|
12583
12831
|
}
|
|
12584
12832
|
}
|
|
12585
|
-
function tarOctal(
|
|
12586
|
-
const text2 = new TextDecoder().decode(
|
|
12833
|
+
function tarOctal(field2) {
|
|
12834
|
+
const text2 = new TextDecoder().decode(field2);
|
|
12587
12835
|
if (!/^[0-7]+[\0 ]*$/.test(text2))
|
|
12588
12836
|
invalidBundle("Invalid tar octal field");
|
|
12589
12837
|
const value = Number.parseInt(text2, 8);
|
|
@@ -12621,8 +12869,8 @@ function profileDocumentBytes(value) {
|
|
|
12621
12869
|
}
|
|
12622
12870
|
class SkillSelectionError extends Error {
|
|
12623
12871
|
code;
|
|
12624
|
-
constructor(code, message) {
|
|
12625
|
-
super(message);
|
|
12872
|
+
constructor(code, message, options) {
|
|
12873
|
+
super(message, options);
|
|
12626
12874
|
this.code = code;
|
|
12627
12875
|
this.name = "SkillSelectionError";
|
|
12628
12876
|
}
|
|
@@ -12663,7 +12911,7 @@ function validateResolvedProfile(profile, authority) {
|
|
|
12663
12911
|
}
|
|
12664
12912
|
var package_default = {
|
|
12665
12913
|
name: "@hasna/skills",
|
|
12666
|
-
version: "0.10.
|
|
12914
|
+
version: "0.10.55",
|
|
12667
12915
|
description: "Skills library for AI coding agents",
|
|
12668
12916
|
type: "module",
|
|
12669
12917
|
bin: {
|
|
@@ -12877,11 +13125,11 @@ var fail = () => {
|
|
|
12877
13125
|
};
|
|
12878
13126
|
function physicalTarget(path) {
|
|
12879
13127
|
const suffix = [];
|
|
12880
|
-
for (let cursor = path;; cursor =
|
|
13128
|
+
for (let cursor = path;; cursor = dirname11(cursor)) {
|
|
12881
13129
|
try {
|
|
12882
13130
|
return join15(realpathSync32(cursor), ...suffix);
|
|
12883
13131
|
} catch (error) {
|
|
12884
|
-
if (error.code !== "ENOENT" || cursor ===
|
|
13132
|
+
if (error.code !== "ENOENT" || cursor === dirname11(cursor))
|
|
12885
13133
|
throw error;
|
|
12886
13134
|
try {
|
|
12887
13135
|
if (lstatSync12(cursor).isSymbolicLink())
|
|
@@ -12890,14 +13138,14 @@ function physicalTarget(path) {
|
|
|
12890
13138
|
if (statError.code !== "ENOENT")
|
|
12891
13139
|
throw statError;
|
|
12892
13140
|
}
|
|
12893
|
-
suffix.unshift(
|
|
13141
|
+
suffix.unshift(basename6(cursor));
|
|
12894
13142
|
}
|
|
12895
13143
|
}
|
|
12896
13144
|
}
|
|
12897
13145
|
function codexCorpusRootForPath(path) {
|
|
12898
|
-
const target =
|
|
13146
|
+
const target = resolve10(path), physical = physicalTarget(target);
|
|
12899
13147
|
const selected = process.env.CODEX_HOME;
|
|
12900
|
-
const selectedRoots = selected &&
|
|
13148
|
+
const selectedRoots = selected && isAbsolute10(selected) ? [resolve10(selected), physicalTarget(resolve10(selected))] : [];
|
|
12901
13149
|
const classify = (candidate) => {
|
|
12902
13150
|
const checked = (root2) => {
|
|
12903
13151
|
if (candidate === root2 || candidate === join15(root2, `${KEY}.flock-v1`))
|
|
@@ -12906,10 +13154,10 @@ function codexCorpusRootForPath(path) {
|
|
|
12906
13154
|
};
|
|
12907
13155
|
for (const root2 of selectedRoots) {
|
|
12908
13156
|
const distance = relative4(root2, candidate);
|
|
12909
|
-
if (distance === "" || !distance.startsWith(`..${sep5}`) && distance !== ".." && !
|
|
13157
|
+
if (distance === "" || !distance.startsWith(`..${sep5}`) && distance !== ".." && !isAbsolute10(distance))
|
|
12910
13158
|
return checked(root2);
|
|
12911
13159
|
}
|
|
12912
|
-
for (let cursor = candidate;cursor !==
|
|
13160
|
+
for (let cursor = candidate;cursor !== dirname11(cursor); cursor = dirname11(cursor)) {
|
|
12913
13161
|
if (cursor.endsWith(`${sep5}.codex`))
|
|
12914
13162
|
return checked(cursor);
|
|
12915
13163
|
}
|
|
@@ -12935,10 +13183,10 @@ function executable(options) {
|
|
|
12935
13183
|
if (typeof command !== "string" || !command || command.includes("\x00") || options.codexSha256 !== undefined && !/^[a-f0-9]{64}$/.test(options.codexSha256))
|
|
12936
13184
|
return fail();
|
|
12937
13185
|
let found;
|
|
12938
|
-
if (
|
|
13186
|
+
if (isAbsolute10(command))
|
|
12939
13187
|
found = command;
|
|
12940
13188
|
else if (!command.includes(sep5)) {
|
|
12941
|
-
found = (process.env.PATH ?? "").split(delimiter).filter(
|
|
13189
|
+
found = (process.env.PATH ?? "").split(delimiter).filter(isAbsolute10).map((dir) => join15(dir, command)).find((candidate) => {
|
|
12942
13190
|
try {
|
|
12943
13191
|
accessSync(candidate, constants6.X_OK);
|
|
12944
13192
|
return true;
|
|
@@ -12952,7 +13200,7 @@ function executable(options) {
|
|
|
12952
13200
|
const path = realpathSync32(found), initial = statSync7(path, { bigint: true });
|
|
12953
13201
|
if (!initial.isFile() || (initial.mode & 0o022n) !== 0n || (initial.mode & 0o111n) === 0n || initial.uid !== BigInt(process.getuid()) && initial.uid !== 0n)
|
|
12954
13202
|
return fail();
|
|
12955
|
-
const hash2 = () =>
|
|
13203
|
+
const hash2 = () => createHash12("sha256").update(readFileSync11(path)).digest("hex");
|
|
12956
13204
|
const digest = hash2();
|
|
12957
13205
|
if (options.codexSha256 && digest !== options.codexSha256)
|
|
12958
13206
|
return fail();
|
|
@@ -12976,7 +13224,7 @@ function acquireCodexCorpusWrite(roots, options) {
|
|
|
12976
13224
|
}
|
|
12977
13225
|
};
|
|
12978
13226
|
try {
|
|
12979
|
-
if (roots.some((root) => typeof root !== "string" || !
|
|
13227
|
+
if (roots.some((root) => typeof root !== "string" || !isAbsolute10(root) || root.includes("\x00")))
|
|
12980
13228
|
fail();
|
|
12981
13229
|
const inputs = [...new Set(roots)].map((input) => ({ input, root: realpathSync32(input) })).sort((a, b) => a.root.localeCompare(b.root));
|
|
12982
13230
|
for (const { input, root } of inputs) {
|
|
@@ -13089,23 +13337,6 @@ function isCodexLocalStdioMcpServer(name, server) {
|
|
|
13089
13337
|
return false;
|
|
13090
13338
|
}
|
|
13091
13339
|
}
|
|
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
13340
|
function codexPluginSourceIsConfigControlled(plugin) {
|
|
13110
13341
|
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
13342
|
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 +13350,7 @@ function refuse() {
|
|
|
13119
13350
|
var object4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13120
13351
|
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
13352
|
var remotePluginIdentifier = (value) => typeof value === "string" && /^[A-Za-z0-9_~-]{1,1024}$/.test(value);
|
|
13122
|
-
var absolutePath2 = (value) => scalar(value, MAX_PATH_BYTES) &&
|
|
13353
|
+
var absolutePath2 = (value) => scalar(value, MAX_PATH_BYTES) && isAbsolute12(value);
|
|
13123
13354
|
function canonicalPath(path) {
|
|
13124
13355
|
try {
|
|
13125
13356
|
return realpathSync5(path);
|
|
@@ -13221,7 +13452,7 @@ function mcpControls(path, read2) {
|
|
|
13221
13452
|
function isBundledCleanupHooks(root, namespace, value) {
|
|
13222
13453
|
const object5 = (v) => Boolean(v && typeof v === "object" && !Array.isArray(v));
|
|
13223
13454
|
const exactKeys = (v, keys) => Object.keys(v).length === keys.length && keys.every((key) => Object.hasOwn(v, key));
|
|
13224
|
-
if (
|
|
13455
|
+
if (basename7(dirname12(root)) !== namespace || basename7(dirname12(dirname12(root))) !== "openai-bundled")
|
|
13225
13456
|
return false;
|
|
13226
13457
|
const server = namespace === "unified-computer-use" ? "cua_repl" : ["browser", "chrome", "chrome-dev", "chrome-internal", "computer-use"].includes(namespace) ? "node_repl" : undefined;
|
|
13227
13458
|
if (!server || !object5(value) || !exactKeys(value, ["hooks"]) || !object5(value.hooks))
|
|
@@ -13255,7 +13486,7 @@ function rootControls(root, read2) {
|
|
|
13255
13486
|
}
|
|
13256
13487
|
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || !identifier2(manifest.name))
|
|
13257
13488
|
refuse2();
|
|
13258
|
-
const cacheVersion =
|
|
13489
|
+
const cacheVersion = basename7(root), declaredVersion = manifest.version === undefined ? "" : typeof manifest.version === "string" ? manifest.version.trim() : null;
|
|
13259
13490
|
if (declaredVersion === null || (declaredVersion ? declaredVersion !== cacheVersion : cacheVersion !== CODEX_DEFAULT_AGENT_PLUGIN_VERSION))
|
|
13260
13491
|
refuse2();
|
|
13261
13492
|
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 +13531,7 @@ function documentIdentity(document2, cache, read2) {
|
|
|
13300
13531
|
}
|
|
13301
13532
|
if (!front || typeof front !== "object" || !identifier2(front.name) || typeof front.description !== "string" || !front.description.trim())
|
|
13302
13533
|
refuse2();
|
|
13303
|
-
for (let root =
|
|
13534
|
+
for (let root = dirname12(document2), depth = 0;root.startsWith(cache + sep6) && depth < 12; root = dirname12(root), depth++) {
|
|
13304
13535
|
const path = join17(root, ".codex-plugin", "plugin.json");
|
|
13305
13536
|
if (!lstatSync13(path, { throwIfNoEntry: false }))
|
|
13306
13537
|
continue;
|
|
@@ -13318,9 +13549,9 @@ function documentIdentity(document2, cache, read2) {
|
|
|
13318
13549
|
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || !identifier2(manifest.name))
|
|
13319
13550
|
refuse2();
|
|
13320
13551
|
const declaredVersion = manifest.version === undefined ? "" : typeof manifest.version === "string" ? manifest.version.trim() : null;
|
|
13321
|
-
if (declaredVersion === null || (declaredVersion ? declaredVersion !==
|
|
13552
|
+
if (declaredVersion === null || (declaredVersion ? declaredVersion !== basename7(root) : basename7(root) !== CODEX_DEFAULT_AGENT_PLUGIN_VERSION))
|
|
13322
13553
|
refuse2();
|
|
13323
|
-
return { name: `${manifest.name}:${front.name}`, namespace: manifest.name, pluginParent:
|
|
13554
|
+
return { name: `${manifest.name}:${front.name}`, namespace: manifest.name, pluginParent: dirname12(root), root };
|
|
13324
13555
|
}
|
|
13325
13556
|
refuse2();
|
|
13326
13557
|
}
|
|
@@ -13349,13 +13580,13 @@ function classifyCodexPluginCacheDocument(document2, cache, read2) {
|
|
|
13349
13580
|
function reviewedDisabledCodexPluginParent(cache, parent, controls, rules) {
|
|
13350
13581
|
try {
|
|
13351
13582
|
const parts = relative5(cache, parent).split(sep6), enrolled = controls.filter((control) => control.pluginParent === parent);
|
|
13352
|
-
if (
|
|
13583
|
+
if (resolve11(parent) !== parent || parts.length !== 2 || parts.some((part) => !identifier2(part)) || !enrolled.length || !Array.isArray(rules))
|
|
13353
13584
|
return false;
|
|
13354
|
-
for (let cursor = parent;; cursor =
|
|
13585
|
+
for (let cursor = parent;; cursor = dirname12(cursor)) {
|
|
13355
13586
|
const stat = lstatSync13(cursor, { throwIfNoEntry: false });
|
|
13356
13587
|
if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
|
|
13357
13588
|
return false;
|
|
13358
|
-
if (
|
|
13589
|
+
if (dirname12(cursor) === cursor)
|
|
13359
13590
|
break;
|
|
13360
13591
|
}
|
|
13361
13592
|
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 +13599,14 @@ function absentDisabledCodexPluginParent(cache, parent, controls, rules) {
|
|
|
13368
13599
|
}
|
|
13369
13600
|
function reviewedRetiredCodexRoot(cache, root, controls, rules, read2, allowAbsent = false) {
|
|
13370
13601
|
try {
|
|
13371
|
-
const parent =
|
|
13372
|
-
if (
|
|
13602
|
+
const parent = dirname12(root), parts = relative5(cache, parent).split(sep6), enrolled = controls.filter((control) => control.pluginParent === parent);
|
|
13603
|
+
if (resolve11(root) !== root || parts.length !== 2 || parts.some((part) => !identifier2(part)) || !basename7(root) || basename7(root) === "latest" || !enrolled.length || !Array.isArray(rules))
|
|
13373
13604
|
return false;
|
|
13374
|
-
for (let cursor = root;; cursor =
|
|
13605
|
+
for (let cursor = root;; cursor = dirname12(cursor)) {
|
|
13375
13606
|
const stat = lstatSync13(cursor, { throwIfNoEntry: false });
|
|
13376
13607
|
if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
|
|
13377
13608
|
return false;
|
|
13378
|
-
if (
|
|
13609
|
+
if (dirname12(cursor) === cursor)
|
|
13379
13610
|
break;
|
|
13380
13611
|
}
|
|
13381
13612
|
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 +13653,8 @@ function reviewedCodexPluginCapabilitiesUnchanged(cache, controls, read2, rules)
|
|
|
13422
13653
|
for (const name of names) {
|
|
13423
13654
|
let root = join17(parent, name), stat = lstatSync13(root);
|
|
13424
13655
|
if (stat.isSymbolicLink()) {
|
|
13425
|
-
const target =
|
|
13426
|
-
if (name !== "latest" ||
|
|
13656
|
+
const target = resolve11(parent, readlinkSync3(root));
|
|
13657
|
+
if (name !== "latest" || dirname12(target) !== parent || !lstatSync13(target).isDirectory() || realpathSync6(target) !== target)
|
|
13427
13658
|
return false;
|
|
13428
13659
|
root = target;
|
|
13429
13660
|
stat = lstatSync13(root);
|
|
@@ -13443,7 +13674,7 @@ function reviewedCodexPluginCapabilitiesUnchanged(cache, controls, read2, rules)
|
|
|
13443
13674
|
function sourceInputUnchanged(input, cache, read2) {
|
|
13444
13675
|
try {
|
|
13445
13676
|
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 })) ||
|
|
13677
|
+
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
13678
|
return false;
|
|
13448
13679
|
const path = join17(input.sourceRoot, ".codex-plugin/plugin.json"), stat = lstatSync13(path);
|
|
13449
13680
|
if (!stat.isFile() || stat.size > 1024 * 1024 || realpathSync6(path) !== path)
|
|
@@ -13514,9 +13745,9 @@ function refuse3(code, detail) {
|
|
|
13514
13745
|
throw new Error(`${code}: ${detail}`);
|
|
13515
13746
|
}
|
|
13516
13747
|
var object5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13517
|
-
function boundedId(value,
|
|
13748
|
+
function boundedId(value, field2) {
|
|
13518
13749
|
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", `${
|
|
13750
|
+
refuse3("NATIVE_SKILL_POLICY_INVALID", `${field2} must be a bounded non-empty string`);
|
|
13520
13751
|
return value;
|
|
13521
13752
|
}
|
|
13522
13753
|
function parseCodexNativePolicyTrust(value) {
|
|
@@ -13539,9 +13770,9 @@ function parseCodexNativeHookEnvelope(envelope, bridgeDocument) {
|
|
|
13539
13770
|
if (!object5(value))
|
|
13540
13771
|
refuse3("NATIVE_SKILL_POLICY_INVALID", "native_skill_policy must be an object");
|
|
13541
13772
|
const keys = Object.keys(value);
|
|
13542
|
-
for (const
|
|
13543
|
-
if (!Object.hasOwn(value,
|
|
13544
|
-
refuse3("NATIVE_SKILL_POLICY_INVALID", `native_skill_policy.${
|
|
13773
|
+
for (const field2 of POLICY_FIELDS)
|
|
13774
|
+
if (!Object.hasOwn(value, field2))
|
|
13775
|
+
refuse3("NATIVE_SKILL_POLICY_INVALID", `native_skill_policy.${field2} is missing`);
|
|
13545
13776
|
if (keys.length !== POLICY_FIELDS.length)
|
|
13546
13777
|
refuse3("NATIVE_SKILL_POLICY_INVALID", "native_skill_policy carries unknown fields");
|
|
13547
13778
|
if (value.capability !== CODEX_NATIVE_POLICY_CAPABILITY)
|
|
@@ -13605,19 +13836,19 @@ function readBounded(path, maximum, what) {
|
|
|
13605
13836
|
}
|
|
13606
13837
|
}
|
|
13607
13838
|
function verifyCodexNativeBridgeDocument(path, expectedContent, expectedSha256) {
|
|
13608
|
-
if (!
|
|
13839
|
+
if (!isAbsolute13(path) || resolve12(path) !== path || !path.endsWith("/SKILL.md"))
|
|
13609
13840
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document path is not an exact absolute SKILL.md path");
|
|
13610
|
-
for (let cursor = path;; cursor =
|
|
13841
|
+
for (let cursor = path;; cursor = dirname13(cursor)) {
|
|
13611
13842
|
const stat = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13612
13843
|
if (!stat || stat.isSymbolicLink() || (cursor === path ? !stat.isFile() : !stat.isDirectory()))
|
|
13613
13844
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", `the bridge path has a missing, linked or unexpected component: ${cursor}`);
|
|
13614
|
-
if (
|
|
13845
|
+
if (dirname13(cursor) === cursor)
|
|
13615
13846
|
break;
|
|
13616
13847
|
}
|
|
13617
13848
|
if (realpathSync7.native(path) !== path)
|
|
13618
13849
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document real path differs from its lexical path");
|
|
13619
13850
|
const bytes = readBounded(path, MAX_BRIDGE_DOCUMENT_BYTES, "the bridge document");
|
|
13620
|
-
const sha2562 =
|
|
13851
|
+
const sha2562 = createHash14("sha256").update(bytes).digest("hex");
|
|
13621
13852
|
if (!bytes.equals(Buffer.from(expectedContent, "utf8")) || sha2562 !== expectedSha256)
|
|
13622
13853
|
refuse3("NATIVE_SKILL_POLICY_BRIDGE_UNVERIFIED", "the bridge document bytes differ from the managed bridge");
|
|
13623
13854
|
return { path, sha256: sha2562 };
|
|
@@ -13683,13 +13914,13 @@ function assertExecutableWitnessStat(stat, currentUid) {
|
|
|
13683
13914
|
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
13915
|
}
|
|
13685
13916
|
function executableWitness(path) {
|
|
13686
|
-
if (!
|
|
13917
|
+
if (!isAbsolute13(path) || resolve12(path) !== path)
|
|
13687
13918
|
refuse3("NATIVE_SKILL_POLICY_PROCESS_UNBOUND", "the consumer executable path is not an exact absolute path");
|
|
13688
|
-
for (let cursor =
|
|
13919
|
+
for (let cursor = dirname13(path);; cursor = dirname13(cursor)) {
|
|
13689
13920
|
const stat2 = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13690
13921
|
if (!stat2 || stat2.isSymbolicLink() || !stat2.isDirectory())
|
|
13691
13922
|
refuse3("NATIVE_SKILL_POLICY_PROCESS_UNBOUND", `the consumer executable path has a missing, linked or unexpected component: ${cursor}`);
|
|
13692
|
-
if (
|
|
13923
|
+
if (dirname13(cursor) === cursor)
|
|
13693
13924
|
break;
|
|
13694
13925
|
}
|
|
13695
13926
|
const stat = lstatSync14(path, { throwIfNoEntry: false, bigint: true });
|
|
@@ -13700,7 +13931,7 @@ function executableWitness(path) {
|
|
|
13700
13931
|
var witnessKey = (path, witness) => JSON.stringify([path, witness.dev, witness.ino, witness.size, witness.mtimeNs, witness.ctimeNs, witness.uid]);
|
|
13701
13932
|
var executableDigestMemory = new Map;
|
|
13702
13933
|
function executableCachePath(dataDir22) {
|
|
13703
|
-
return join18(
|
|
13934
|
+
return join18(resolve12(dataDir22), "agent-hooks", "codex-native-policy-executable-cache.json");
|
|
13704
13935
|
}
|
|
13705
13936
|
var currentUid = () => process.getuid?.() ?? -1;
|
|
13706
13937
|
function readTrustedCacheBytes(path, ownerUid) {
|
|
@@ -13745,16 +13976,16 @@ function readExecutableCache(dataDir22, ownerUid = currentUid()) {
|
|
|
13745
13976
|
if (!object5(value) || value.schema !== CODEX_NATIVE_POLICY_EXECUTABLE_CACHE_SCHEMA || !Array.isArray(value.entries) || value.entries.length > 16)
|
|
13746
13977
|
return [];
|
|
13747
13978
|
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((
|
|
13979
|
+
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
13980
|
} catch {
|
|
13750
13981
|
return [];
|
|
13751
13982
|
}
|
|
13752
13983
|
}
|
|
13753
13984
|
function writeExecutableCache(dataDir22, entries) {
|
|
13754
|
-
const path = executableCachePath(dataDir22), directory =
|
|
13985
|
+
const path = executableCachePath(dataDir22), directory = dirname13(path), temporary = `${path}.skills-${randomUUID2()}`;
|
|
13755
13986
|
let descriptor;
|
|
13756
13987
|
try {
|
|
13757
|
-
const parent = lstatSync14(
|
|
13988
|
+
const parent = lstatSync14(dirname13(directory), { throwIfNoEntry: false });
|
|
13758
13989
|
if (!parent || parent.isSymbolicLink() || !parent.isDirectory())
|
|
13759
13990
|
return;
|
|
13760
13991
|
const existing = lstatSync14(directory, { throwIfNoEntry: false });
|
|
@@ -13822,16 +14053,16 @@ function verifyCodexNativeExecutable(inspector, processId, trust, cache = {}, ex
|
|
|
13822
14053
|
}
|
|
13823
14054
|
function assertOperatorTrustRoot(dataDir22) {
|
|
13824
14055
|
const check = (path, what, required) => {
|
|
13825
|
-
if (!
|
|
14056
|
+
if (!isAbsolute13(path) || resolve12(path) !== path)
|
|
13826
14057
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} path is not an exact absolute path`);
|
|
13827
|
-
for (let cursor =
|
|
14058
|
+
for (let cursor = dirname13(path);; cursor = dirname13(cursor)) {
|
|
13828
14059
|
const stat2 = lstatSync14(cursor, { throwIfNoEntry: false });
|
|
13829
14060
|
if (!stat2) {
|
|
13830
14061
|
if (required)
|
|
13831
14062
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} has a missing path component: ${cursor}`);
|
|
13832
14063
|
} else if (stat2.isSymbolicLink() || !stat2.isDirectory())
|
|
13833
14064
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} has a linked or unexpected path component: ${cursor}`);
|
|
13834
|
-
if (
|
|
14065
|
+
if (dirname13(cursor) === cursor)
|
|
13835
14066
|
break;
|
|
13836
14067
|
}
|
|
13837
14068
|
const stat = lstatSync14(path, { throwIfNoEntry: false, bigint: true });
|
|
@@ -13861,9 +14092,9 @@ function assertOperatorTrustRoot(dataDir22) {
|
|
|
13861
14092
|
if ((stat.mode & 0o022n) !== 0n)
|
|
13862
14093
|
refuse3("NATIVE_SKILL_POLICY_TRUST_INVALID", `${what} is group- or world-writable`);
|
|
13863
14094
|
};
|
|
13864
|
-
checkDirectory(
|
|
13865
|
-
checkDirectory(
|
|
13866
|
-
check(join18(
|
|
14095
|
+
checkDirectory(resolve12(dataDir22), "the Skills data directory", true);
|
|
14096
|
+
checkDirectory(dirname13(executableCachePath(dataDir22)), "the agent-hooks directory", false);
|
|
14097
|
+
check(join18(resolve12(dataDir22), "agent-policy.json"), "the managed policy", true);
|
|
13867
14098
|
check(executableCachePath(dataDir22), "the executable identity cache", false);
|
|
13868
14099
|
}
|
|
13869
14100
|
function runCodexNativePolicyHelper(request) {
|
|
@@ -14034,12 +14265,12 @@ function defaultProcessInspector() {
|
|
|
14034
14265
|
return { platform: process.platform, arch: process.arch, pid: process.pid, parentOf: () => null, startTime: () => null, executablePath: () => null };
|
|
14035
14266
|
}
|
|
14036
14267
|
function codexNativePolicyReceiptPath(dataDir22) {
|
|
14037
|
-
return join18(
|
|
14268
|
+
return join18(resolve12(dataDir22), "agent-hooks", "codex-native-policy-acceptance.json");
|
|
14038
14269
|
}
|
|
14039
14270
|
function recordCodexNativePolicyAcceptance(dataDir22, verification, accepted) {
|
|
14040
|
-
const path = codexNativePolicyReceiptPath(dataDir22), directory =
|
|
14271
|
+
const path = codexNativePolicyReceiptPath(dataDir22), directory = dirname13(path);
|
|
14041
14272
|
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) => !
|
|
14273
|
+
if (acceptedCache.some((entry) => !isAbsolute13(entry.path) || !HEX_DIGEST.test(entry.treeSha256)) || new Set(acceptedCache.map((entry) => entry.path)).size !== acceptedCache.length)
|
|
14043
14274
|
refuse3("NATIVE_SKILL_POLICY_RECEIPT_FAILED", "accepted cache entries must be unique absolute paths with tree digests");
|
|
14044
14275
|
const value = {
|
|
14045
14276
|
schema: CODEX_NATIVE_POLICY_RECEIPT_SCHEMA,
|
|
@@ -14083,10 +14314,10 @@ function recordCodexNativePolicyAcceptance(dataDir22, verification, accepted) {
|
|
|
14083
14314
|
}
|
|
14084
14315
|
return path;
|
|
14085
14316
|
}
|
|
14086
|
-
var sha = (text2) =>
|
|
14317
|
+
var sha = (text2) => createHash15("sha256").update(text2).digest("hex");
|
|
14087
14318
|
var EFFORT = new Set(["none", "minimal", "low", "medium", "high", "xhigh"]);
|
|
14088
14319
|
var VERBOSITY = new Set(["low", "medium", "high"]);
|
|
14089
|
-
function
|
|
14320
|
+
function need4(value) {
|
|
14090
14321
|
if (!value)
|
|
14091
14322
|
throw new Error("Invalid Codex settings witness");
|
|
14092
14323
|
}
|
|
@@ -14101,14 +14332,14 @@ function numericTokens(text2) {
|
|
|
14101
14332
|
continue;
|
|
14102
14333
|
}
|
|
14103
14334
|
if (char === '"' || char === "'") {
|
|
14104
|
-
const
|
|
14335
|
+
const quote22 = char, triple = text2.slice(at, at + 3) === quote22.repeat(3);
|
|
14105
14336
|
at += triple ? 3 : 1;
|
|
14106
14337
|
while (at < text2.length) {
|
|
14107
|
-
if (
|
|
14338
|
+
if (quote22 === '"' && text2[at] === "\\") {
|
|
14108
14339
|
at += 2;
|
|
14109
14340
|
continue;
|
|
14110
14341
|
}
|
|
14111
|
-
if (text2.slice(at, at + (triple ? 3 : 1)) ===
|
|
14342
|
+
if (text2.slice(at, at + (triple ? 3 : 1)) === quote22.repeat(triple ? 3 : 1)) {
|
|
14112
14343
|
at += triple ? 3 : 1;
|
|
14113
14344
|
break;
|
|
14114
14345
|
}
|
|
@@ -14129,8 +14360,8 @@ function numericTokens(text2) {
|
|
|
14129
14360
|
}
|
|
14130
14361
|
return result;
|
|
14131
14362
|
}
|
|
14132
|
-
function
|
|
14133
|
-
|
|
14363
|
+
function canonical5(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
14364
|
+
need4(depth <= 32 && --budget2.remaining >= 0);
|
|
14134
14365
|
if (value === null)
|
|
14135
14366
|
return ["null"];
|
|
14136
14367
|
if (typeof value === "string")
|
|
@@ -14138,20 +14369,20 @@ function canonical4(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
|
14138
14369
|
if (typeof value === "boolean")
|
|
14139
14370
|
return ["boolean", value];
|
|
14140
14371
|
if (typeof value === "number") {
|
|
14141
|
-
|
|
14372
|
+
need4(Number.isFinite(value));
|
|
14142
14373
|
return ["number", String(value)];
|
|
14143
14374
|
}
|
|
14144
14375
|
if (value instanceof Date) {
|
|
14145
|
-
|
|
14376
|
+
need4(Number.isFinite(value.getTime()));
|
|
14146
14377
|
return ["date", value.toISOString()];
|
|
14147
14378
|
}
|
|
14148
14379
|
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,
|
|
14380
|
+
return ["array", value.map((child2) => canonical5(child2, depth + 1, budget2))];
|
|
14381
|
+
need4(value && typeof value === "object");
|
|
14382
|
+
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
14383
|
}
|
|
14153
14384
|
function hashCodexSettingsReplacement(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14154
|
-
|
|
14385
|
+
need4(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14155
14386
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14156
14387
|
let config;
|
|
14157
14388
|
try {
|
|
@@ -14159,17 +14390,17 @@ function hashCodexSettingsReplacement(text2, budget2 = { remaining: 256 * 1024 *
|
|
|
14159
14390
|
} catch {
|
|
14160
14391
|
throw new Error("Invalid Codex settings witness");
|
|
14161
14392
|
}
|
|
14162
|
-
|
|
14393
|
+
need4(config && typeof config === "object" && !Array.isArray(config));
|
|
14163
14394
|
if (Object.hasOwn(config, "model")) {
|
|
14164
|
-
|
|
14395
|
+
need4(typeof config.model === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(config.model));
|
|
14165
14396
|
delete config.model;
|
|
14166
14397
|
}
|
|
14167
14398
|
for (const [key, values] of [["model_reasoning_effort", EFFORT], ["model_verbosity", VERBOSITY]])
|
|
14168
14399
|
if (Object.hasOwn(config, key)) {
|
|
14169
|
-
|
|
14400
|
+
need4(typeof config[key] === "string" && values.has(config[key]));
|
|
14170
14401
|
delete config[key];
|
|
14171
14402
|
}
|
|
14172
|
-
return sha(`hasna.skills.codex-settings.v1\x00${JSON.stringify([
|
|
14403
|
+
return sha(`hasna.skills.codex-settings.v1\x00${JSON.stringify([canonical5(config), numericTokens(text2)])}`);
|
|
14173
14404
|
}
|
|
14174
14405
|
function captureCodexSettings(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14175
14406
|
const text2 = readNativeSettingsWitnessFile(path, budget2, "config.toml");
|
|
@@ -14236,13 +14467,13 @@ function projectRegularCodexMcp(config, source) {
|
|
|
14236
14467
|
}
|
|
14237
14468
|
return { config: expected, numericSource };
|
|
14238
14469
|
}
|
|
14239
|
-
var sha2 = (text2) =>
|
|
14470
|
+
var sha2 = (text2) => createHash16("sha256").update(text2).digest("hex");
|
|
14240
14471
|
var EFFORT2 = new Set(["none", "minimal", "low", "medium", "high", "xhigh"]);
|
|
14241
14472
|
var VERBOSITY2 = new Set(["low", "medium", "high"]);
|
|
14242
14473
|
var MODEL = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
14243
14474
|
var CODEX_DISCOVERY_PROJECTION_FIELDS = ["plugins", "marketplaces", "skills"];
|
|
14244
14475
|
var INFERENCE = ["model", "model_reasoning_effort", "model_verbosity"];
|
|
14245
|
-
function
|
|
14476
|
+
function need5(value) {
|
|
14246
14477
|
if (!value)
|
|
14247
14478
|
throw new Error("Invalid Codex settings witness");
|
|
14248
14479
|
}
|
|
@@ -14263,14 +14494,14 @@ function numericTokens2(text2) {
|
|
|
14263
14494
|
continue;
|
|
14264
14495
|
}
|
|
14265
14496
|
if (char === '"' || char === "'") {
|
|
14266
|
-
const
|
|
14497
|
+
const quote22 = char, triple = text2.slice(at, at + 3) === quote22.repeat(3);
|
|
14267
14498
|
at += triple ? 3 : 1;
|
|
14268
14499
|
while (at < text2.length) {
|
|
14269
|
-
if (
|
|
14500
|
+
if (quote22 === '"' && text2[at] === "\\") {
|
|
14270
14501
|
at += 2;
|
|
14271
14502
|
continue;
|
|
14272
14503
|
}
|
|
14273
|
-
if (text2.slice(at, at + (triple ? 3 : 1)) ===
|
|
14504
|
+
if (text2.slice(at, at + (triple ? 3 : 1)) === quote22.repeat(triple ? 3 : 1)) {
|
|
14274
14505
|
at += triple ? 3 : 1;
|
|
14275
14506
|
break;
|
|
14276
14507
|
}
|
|
@@ -14291,8 +14522,8 @@ function numericTokens2(text2) {
|
|
|
14291
14522
|
}
|
|
14292
14523
|
return result.sort();
|
|
14293
14524
|
}
|
|
14294
|
-
function
|
|
14295
|
-
|
|
14525
|
+
function canonical6(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
14526
|
+
need5(depth <= 32 && --budget2.remaining >= 0);
|
|
14296
14527
|
if (value === null)
|
|
14297
14528
|
return ["null"];
|
|
14298
14529
|
if (typeof value === "string")
|
|
@@ -14300,17 +14531,17 @@ function canonical5(value, depth = 0, budget2 = { remaining: 65536 }) {
|
|
|
14300
14531
|
if (typeof value === "boolean")
|
|
14301
14532
|
return ["boolean", value];
|
|
14302
14533
|
if (typeof value === "number") {
|
|
14303
|
-
|
|
14534
|
+
need5(Number.isFinite(value));
|
|
14304
14535
|
return ["number", String(value)];
|
|
14305
14536
|
}
|
|
14306
14537
|
if (isDate(value)) {
|
|
14307
|
-
|
|
14538
|
+
need5(Number.isFinite(value.getTime()));
|
|
14308
14539
|
return ["date", value.toISOString()];
|
|
14309
14540
|
}
|
|
14310
14541
|
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,
|
|
14542
|
+
return ["array", value.map((child2) => canonical6(child2, depth + 1, budget2))];
|
|
14543
|
+
need5(isRecord3(value));
|
|
14544
|
+
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
14545
|
}
|
|
14315
14546
|
function normalize3(config, version = 2) {
|
|
14316
14547
|
if (isRecord3(config.hooks)) {
|
|
@@ -14352,15 +14583,15 @@ function inference(target, version) {
|
|
|
14352
14583
|
if (Object.hasOwn(target, key)) {
|
|
14353
14584
|
const value = target[key];
|
|
14354
14585
|
if (key === "model")
|
|
14355
|
-
|
|
14586
|
+
need5(typeof value === "string" && MODEL.test(value));
|
|
14356
14587
|
else if (key === "personality")
|
|
14357
|
-
|
|
14588
|
+
need5(typeof value === "string" && ["none", "friendly", "pragmatic"].includes(value));
|
|
14358
14589
|
else if (version >= 3 && key !== "model_verbosity") {
|
|
14359
|
-
|
|
14590
|
+
need5(typeof value === "string" && value.length <= 128 && !/[\x00-\x1f\x7f]/.test(value));
|
|
14360
14591
|
if (key !== "service_tier")
|
|
14361
|
-
|
|
14592
|
+
need5(value.length > 0);
|
|
14362
14593
|
} else
|
|
14363
|
-
|
|
14594
|
+
need5(typeof value === "string" && (key === "model_reasoning_effort" ? EFFORT2.has(value) : VERBOSITY2.has(value)));
|
|
14364
14595
|
delete target[key];
|
|
14365
14596
|
}
|
|
14366
14597
|
}
|
|
@@ -14393,14 +14624,14 @@ function projectModelAvailabilityNux(config, text2) {
|
|
|
14393
14624
|
continue;
|
|
14394
14625
|
}
|
|
14395
14626
|
if (char === '"' || char === "'") {
|
|
14396
|
-
const
|
|
14627
|
+
const quote22 = char;
|
|
14397
14628
|
at++;
|
|
14398
14629
|
while (at < span.length) {
|
|
14399
|
-
if (
|
|
14630
|
+
if (quote22 === '"' && span[at] === "\\") {
|
|
14400
14631
|
at += 2;
|
|
14401
14632
|
continue;
|
|
14402
14633
|
}
|
|
14403
|
-
if (span[at++] ===
|
|
14634
|
+
if (span[at++] === quote22)
|
|
14404
14635
|
break;
|
|
14405
14636
|
}
|
|
14406
14637
|
continue;
|
|
@@ -14480,14 +14711,14 @@ function settingsDigest2(text2, version = 2) {
|
|
|
14480
14711
|
} catch {
|
|
14481
14712
|
throw new Error("Invalid Codex settings witness");
|
|
14482
14713
|
}
|
|
14483
|
-
|
|
14714
|
+
need5(isRecord3(config));
|
|
14484
14715
|
const mcp = version >= 3 ? projectRegularCodexMcp(config, text2) : { config, numericSource: text2 };
|
|
14485
14716
|
const projected = version === 4 ? projectModelAvailabilityNux(mcp.config, mcp.numericSource) : mcp;
|
|
14486
14717
|
normalize3(projected.config, version);
|
|
14487
|
-
return sha2(`hasna.skills.codex-settings.v${version}\x00${JSON.stringify([
|
|
14718
|
+
return sha2(`hasna.skills.codex-settings.v${version}\x00${JSON.stringify([canonical6(projected.config), numericTokens2(projected.numericSource)])}`);
|
|
14488
14719
|
}
|
|
14489
14720
|
function hashCodexSettingsReplacementV2(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14490
|
-
|
|
14721
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14491
14722
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14492
14723
|
return settingsDigest2(text2);
|
|
14493
14724
|
}
|
|
@@ -14499,17 +14730,17 @@ function readCodexSettingsPreimage(path, budget2 = { remaining: 2 * 1024 * 1024
|
|
|
14499
14730
|
return readNativeSettingsWitnessFile(path, budget2, "config.toml");
|
|
14500
14731
|
}
|
|
14501
14732
|
function upgradeCodexSettingsWitness(previous, reviewedSettingsPath) {
|
|
14502
|
-
|
|
14733
|
+
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
14734
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14504
14735
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14505
|
-
|
|
14736
|
+
need5((previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before)) === previous.sha256);
|
|
14506
14737
|
const sha2562 = settingsDigest2(current2);
|
|
14507
14738
|
if (settingsDigest2(before) !== sha2562)
|
|
14508
14739
|
throw new Error("Codex non-preference settings changed; explicit discovery review required");
|
|
14509
14740
|
return { path: previous.path, hashMode: "codex-settings-v2", sha256: sha2562 };
|
|
14510
14741
|
}
|
|
14511
14742
|
function hashCodexSettingsReplacementV3(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14512
|
-
|
|
14743
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14513
14744
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14514
14745
|
return settingsDigest2(text2, 3);
|
|
14515
14746
|
}
|
|
@@ -14517,18 +14748,18 @@ function captureCodexSettingsV3(path, budget2 = { remaining: 256 * 1024 * 1024 }
|
|
|
14517
14748
|
return { path, hashMode: "codex-settings-v3", sha256: settingsDigest2(readNativeSettingsWitnessFile(path, budget2, "config.toml"), 3) };
|
|
14518
14749
|
}
|
|
14519
14750
|
function upgradeCodexSettingsWitnessV3(previous, reviewedSettingsPath) {
|
|
14520
|
-
|
|
14751
|
+
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
14752
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14522
14753
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14523
14754
|
const original = previous.hashMode === "codex-settings-v2" ? settingsDigest2(before) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
14524
|
-
|
|
14755
|
+
need5(original === previous.sha256);
|
|
14525
14756
|
const sha2562 = settingsDigest2(current2, 3);
|
|
14526
14757
|
if (settingsDigest2(before, 3) !== sha2562)
|
|
14527
14758
|
throw new Error("Codex settings outside the reviewed V3 contract changed; explicit discovery review required");
|
|
14528
14759
|
return { path: previous.path, hashMode: "codex-settings-v3", sha256: sha2562 };
|
|
14529
14760
|
}
|
|
14530
14761
|
function hashCodexSettingsReplacementV4(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
14531
|
-
|
|
14762
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
14532
14763
|
budget2.remaining -= Buffer.byteLength(text2);
|
|
14533
14764
|
return settingsDigest2(text2, 4);
|
|
14534
14765
|
}
|
|
@@ -14536,18 +14767,18 @@ function captureCodexSettingsV4(path, budget2 = { remaining: 256 * 1024 * 1024 }
|
|
|
14536
14767
|
return { path, hashMode: "codex-settings-v4", sha256: settingsDigest2(readNativeSettingsWitnessFile(path, budget2, "config.toml"), 4) };
|
|
14537
14768
|
}
|
|
14538
14769
|
function upgradeCodexSettingsWitnessV4(previous, reviewedSettingsPath) {
|
|
14539
|
-
|
|
14770
|
+
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
14771
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
14541
14772
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
14542
14773
|
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
|
-
|
|
14774
|
+
need5(original === previous.sha256);
|
|
14544
14775
|
const sha2562 = settingsDigest2(current2, 4);
|
|
14545
14776
|
if (settingsDigest2(before, 4) !== sha2562)
|
|
14546
14777
|
throw new Error("Codex settings outside the reviewed V4 contract changed; explicit discovery review required");
|
|
14547
14778
|
return { path: previous.path, hashMode: "codex-settings-v4", sha256: sha2562 };
|
|
14548
14779
|
}
|
|
14549
|
-
function refusal(
|
|
14550
|
-
return new SkillSelectionError("INVALID_AGENT_POLICY", `The Skills agent loading policy ${
|
|
14780
|
+
function refusal(reason2 = "is unreadable") {
|
|
14781
|
+
return new SkillSelectionError("INVALID_AGENT_POLICY", `The Skills agent loading policy ${reason2}; refusing legacy fallback.`);
|
|
14551
14782
|
}
|
|
14552
14783
|
function parseManagedSkillPolicy(text2) {
|
|
14553
14784
|
if (Buffer.byteLength(text2) > AGENT_POLICY_LIMITS.bytes)
|
|
@@ -14632,7 +14863,7 @@ Use the Skills CLI as the skill authority for this station.
|
|
|
14632
14863
|
|
|
14633
14864
|
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
14865
|
`;
|
|
14635
|
-
var CLI_BRIDGE_DIGEST =
|
|
14866
|
+
var CLI_BRIDGE_DIGEST = createHash17("sha256").update(markdown).digest("hex");
|
|
14636
14867
|
var CLI_BRIDGE_FILES = Object.freeze({
|
|
14637
14868
|
"SKILL.md": markdown,
|
|
14638
14869
|
".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 +14890,22 @@ function sumiConfigDirectory(home, env = process.env) {
|
|
|
14659
14890
|
if (env[key] !== undefined)
|
|
14660
14891
|
throw new Error(`Sumi ${key} requires a dedicated discovery adapter; unset it before Skills integration`);
|
|
14661
14892
|
const selected = (key) => env[key]?.trim() ? env[key] : undefined;
|
|
14662
|
-
const expand = (value) =>
|
|
14893
|
+
const expand = (value) => resolve13(value === "~" ? home : value.startsWith("~/") ? join21(home, value.slice(2)) : value);
|
|
14663
14894
|
const explicit = selected("SUMI_CONFIG_DIR");
|
|
14664
14895
|
const xdg = selected("XDG_CONFIG_HOME");
|
|
14665
14896
|
const custom = selected("SUMI_HOME");
|
|
14666
|
-
const
|
|
14897
|
+
const canonical7 = explicit ? expand(explicit) : xdg ? join21(expand(xdg), "sumi") : join21(custom ? expand(custom) : join21(home, ".hasna-internal/sumi"), "config");
|
|
14667
14898
|
if (explicit || xdg || custom)
|
|
14668
|
-
return
|
|
14899
|
+
return canonical7;
|
|
14669
14900
|
const legacy = join21(home, ".config/sumi");
|
|
14670
|
-
const a = lstatSync17(
|
|
14671
|
-
if (a && b && realpathSync8(
|
|
14901
|
+
const a = lstatSync17(canonical7, { throwIfNoEntry: false }), b = lstatSync17(legacy, { throwIfNoEntry: false });
|
|
14902
|
+
if (a && b && realpathSync8(canonical7) !== realpathSync8(legacy))
|
|
14672
14903
|
throw new Error("Sumi config roots conflict; complete native home adoption before Skills integration");
|
|
14673
|
-
const path = a ?
|
|
14904
|
+
const path = a ? canonical7 : b ? legacy : canonical7;
|
|
14674
14905
|
if (!existsSync82(path))
|
|
14675
14906
|
return path;
|
|
14676
14907
|
const physical = realpathSync8(path);
|
|
14677
|
-
if ((a?.isSymbolicLink() || b?.isSymbolicLink()) && ![
|
|
14908
|
+
if ((a?.isSymbolicLink() || b?.isSymbolicLink()) && ![canonical7, legacy].includes(physical))
|
|
14678
14909
|
throw new Error("Sumi config alias must resolve to its canonical or legacy root");
|
|
14679
14910
|
return physical;
|
|
14680
14911
|
}
|
|
@@ -14772,17 +15003,20 @@ var SUMI_SKILL_PERMISSIONS = [
|
|
|
14772
15003
|
{ action: "skill", resource: "*", effect: "deny" },
|
|
14773
15004
|
{ action: "skill", resource: "skills-cli", effect: "allow" }
|
|
14774
15005
|
];
|
|
14775
|
-
function
|
|
15006
|
+
function need6(value, code) {
|
|
14776
15007
|
if (!value)
|
|
14777
15008
|
throw new Error(`CODEX_HOOK_TRUST_${code}`);
|
|
14778
15009
|
}
|
|
14779
15010
|
var sameStat = (a, b) => ["dev", "ino", "uid", "nlink", "mode", "size", "mtimeNs", "ctimeNs"].every((key) => a[key] === b[key]);
|
|
15011
|
+
function trustedAncestorOwner(uid) {
|
|
15012
|
+
return BigInt(uid) === 0n || BigInt(uid) === BigInt(process.getuid());
|
|
15013
|
+
}
|
|
14780
15014
|
function safeParents(file) {
|
|
14781
|
-
for (let p =
|
|
15015
|
+
for (let p = dirname14(file);; p = dirname14(p)) {
|
|
14782
15016
|
const s = lstatSync18(p);
|
|
14783
|
-
|
|
14784
|
-
|
|
14785
|
-
if (
|
|
15017
|
+
need6(s.isDirectory() && !s.isSymbolicLink() && trustedAncestorOwner(s.uid), "UNSAFE_PARENT");
|
|
15018
|
+
need6((s.mode & 18) === 0 || s.uid === 0 && (s.mode & 512) !== 0, "UNSAFE_PARENT");
|
|
15019
|
+
if (dirname14(p) === p)
|
|
14786
15020
|
break;
|
|
14787
15021
|
}
|
|
14788
15022
|
}
|
|
@@ -14790,12 +15024,12 @@ function snapshot(file, privateFile = false, options = {}) {
|
|
|
14790
15024
|
const readOnlyPackage = options.readOnlyPackage === true && !privateFile;
|
|
14791
15025
|
safeParents(file);
|
|
14792
15026
|
const initial = lstatSync18(file, { bigint: true });
|
|
14793
|
-
|
|
14794
|
-
|
|
15027
|
+
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");
|
|
15028
|
+
need6(initial.size <= 8n * 1024n * 1024n, "FILE_BOUND");
|
|
14795
15029
|
const fd = openSync9(file, constants9.O_RDONLY | constants9.O_NOFOLLOW | constants9.O_NONBLOCK);
|
|
14796
15030
|
try {
|
|
14797
15031
|
const before = fstatSync9(fd, { bigint: true });
|
|
14798
|
-
|
|
15032
|
+
need6(sameStat(initial, before), "INPUT_CHANGED");
|
|
14799
15033
|
const bytes = Buffer.alloc(Number(before.size) + 1);
|
|
14800
15034
|
let length = 0;
|
|
14801
15035
|
while (length < bytes.length) {
|
|
@@ -14804,18 +15038,57 @@ function snapshot(file, privateFile = false, options = {}) {
|
|
|
14804
15038
|
break;
|
|
14805
15039
|
length += n2;
|
|
14806
15040
|
}
|
|
14807
|
-
|
|
15041
|
+
need6(length === Number(before.size) && sameStat(before, fstatSync9(fd, { bigint: true })) && sameStat(before, lstatSync18(file, { bigint: true })), "INPUT_CHANGED");
|
|
14808
15042
|
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:
|
|
15043
|
+
return { file, privateFile, readOnlyPackage, text: text2, bytes: content, stat: before, sha256: createHash18("sha256").update(content).digest("hex") };
|
|
14810
15044
|
} finally {
|
|
14811
15045
|
closeSync9(fd);
|
|
14812
15046
|
}
|
|
14813
15047
|
}
|
|
14814
15048
|
function unchanged2(before) {
|
|
14815
15049
|
const after = snapshot(before.file, before.privateFile, before.readOnlyPackage ? { readOnlyPackage: true } : {});
|
|
14816
|
-
|
|
14817
|
-
}
|
|
14818
|
-
var
|
|
15050
|
+
need6(sameStat(before.stat, after.stat) && after.sha256 === before.sha256, "INPUT_CHANGED");
|
|
15051
|
+
}
|
|
15052
|
+
var PINNED_LAUNCHER_BUN_FLAGS = ["--config=/dev/null", "--no-env-file", "--no-macros", "--no-install"];
|
|
15053
|
+
var PINNED_LAUNCHER_ENV_NAMES = [
|
|
15054
|
+
"HOME",
|
|
15055
|
+
"PATH",
|
|
15056
|
+
"TMPDIR",
|
|
15057
|
+
"TERM",
|
|
15058
|
+
"TERM_PROGRAM",
|
|
15059
|
+
"TERM_PROGRAM_VERSION",
|
|
15060
|
+
"COLORTERM",
|
|
15061
|
+
"LANG",
|
|
15062
|
+
"USER",
|
|
15063
|
+
"LOGNAME",
|
|
15064
|
+
"SHELL",
|
|
15065
|
+
"TZ",
|
|
15066
|
+
"NO_COLOR",
|
|
15067
|
+
"FORCE_COLOR",
|
|
15068
|
+
"CI",
|
|
15069
|
+
"COLUMNS",
|
|
15070
|
+
"LINES",
|
|
15071
|
+
"EDITOR",
|
|
15072
|
+
"VISUAL",
|
|
15073
|
+
"PAGER",
|
|
15074
|
+
"SSH_AUTH_SOCK",
|
|
15075
|
+
"DATABASE_URL",
|
|
15076
|
+
"TERMINAL_CWD",
|
|
15077
|
+
"CODEX_HOME",
|
|
15078
|
+
"HERMES_HOME",
|
|
15079
|
+
"HERMES_ENABLE_PROJECT_PLUGINS",
|
|
15080
|
+
"HOST",
|
|
15081
|
+
"PORT",
|
|
15082
|
+
"NODE_ENV",
|
|
15083
|
+
"AGENT_ID",
|
|
15084
|
+
"ECS_CONTAINER_METADATA_URI_V4"
|
|
15085
|
+
];
|
|
15086
|
+
var PINNED_LAUNCHER_ENV_PREFIXES = ["HASNA", "SKILLS", "SKILL", "MCP", "XDG", "LC", "AWS"];
|
|
15087
|
+
var ENV_PREFIX = new RegExp(`^(${PINNED_LAUNCHER_ENV_PREFIXES.join("|")})_`);
|
|
15088
|
+
var ENV_EXACT = new Set(PINNED_LAUNCHER_ENV_NAMES);
|
|
15089
|
+
var COMMAND_LINE = new RegExp(`^set -- '([^']+)' ${PINNED_LAUNCHER_BUN_FLAGS.join(" ")} '--cwd=([^']+)' '([^']+)' "\\$@"$`, "m");
|
|
15090
|
+
var PINNED_LAUNCHER_MAX_BYTES = 16 * 1024;
|
|
15091
|
+
var sha3 = (data) => createHash20("sha256").update(data).digest("hex");
|
|
14819
15092
|
var ROOTS = NATIVE_SKILL_ROOTS;
|
|
14820
15093
|
function hasTrustedDarwinAcl(fd, allowDenyOnly = false) {
|
|
14821
15094
|
try {
|
|
@@ -14865,12 +15138,13 @@ function isSystemRootAlias(path) {
|
|
|
14865
15138
|
return false;
|
|
14866
15139
|
const target = `/private${path}`, link = `private${path}`;
|
|
14867
15140
|
const identity5 = (stat) => `${stat.dev}:${stat.ino}:${stat.ctimeNs}:${stat.uid}:${stat.mode}`;
|
|
15141
|
+
const directoryIdentity = (stat) => `${stat.dev}:${stat.ino}:${stat.uid}:${stat.mode}`;
|
|
14868
15142
|
try {
|
|
14869
|
-
const before =
|
|
14870
|
-
if (!before.isSymbolicLink() || before.uid !== 0n ||
|
|
15143
|
+
const before = lstatSync20(path, { bigint: true });
|
|
15144
|
+
if (!before.isSymbolicLink() || before.uid !== 0n || readlinkSync7(path) !== link)
|
|
14871
15145
|
return false;
|
|
14872
15146
|
const directories = ["/", "/private", target].map((directory) => {
|
|
14873
|
-
const stat =
|
|
15147
|
+
const stat = lstatSync20(directory, { bigint: true });
|
|
14874
15148
|
if (!stat.isDirectory() || stat.uid !== 0n)
|
|
14875
15149
|
throw new Error("Untrusted system alias directory");
|
|
14876
15150
|
if (directory !== "/private/tmp") {
|
|
@@ -14878,34 +15152,34 @@ function isSystemRootAlias(path) {
|
|
|
14878
15152
|
throw new Error("Writable system alias directory");
|
|
14879
15153
|
} else if ((stat.mode & 0o1000n) === 0n)
|
|
14880
15154
|
throw new Error("Unprotected system temporary directory");
|
|
14881
|
-
const fd =
|
|
15155
|
+
const fd = openSync11(directory, constants11.O_RDONLY | constants11.O_DIRECTORY | constants11.O_NOFOLLOW);
|
|
14882
15156
|
try {
|
|
14883
|
-
if (
|
|
15157
|
+
if (directoryIdentity(fstatSync11(fd, { bigint: true })) !== directoryIdentity(stat) || !hasTrustedDarwinAcl(fd) || directoryIdentity(fstatSync11(fd, { bigint: true })) !== directoryIdentity(stat))
|
|
14884
15158
|
throw new Error("Unverified system alias directory ACL");
|
|
14885
15159
|
} finally {
|
|
14886
|
-
|
|
15160
|
+
closeSync11(fd);
|
|
14887
15161
|
}
|
|
14888
|
-
return { directory, identity:
|
|
15162
|
+
return { directory, identity: directoryIdentity(stat) };
|
|
14889
15163
|
});
|
|
14890
|
-
return
|
|
15164
|
+
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
15165
|
} catch {
|
|
14892
15166
|
return false;
|
|
14893
15167
|
}
|
|
14894
15168
|
}
|
|
14895
15169
|
function canonicalSystemPath(path) {
|
|
14896
|
-
const absolute =
|
|
14897
|
-
if (process.platform !== "darwin" || !["/var", "/tmp", "/etc"].includes(root) || !
|
|
15170
|
+
const absolute = resolve15(path), root = `/${absolute.split(sep7)[1]}`;
|
|
15171
|
+
if (process.platform !== "darwin" || !["/var", "/tmp", "/etc"].includes(root) || !lstatSync20(root, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
14898
15172
|
return absolute;
|
|
14899
15173
|
if (!isSystemRootAlias(root))
|
|
14900
15174
|
throw new Error(`Refusing symlink path: ${root}`);
|
|
14901
15175
|
return `/private${absolute}`;
|
|
14902
15176
|
}
|
|
14903
15177
|
function assertSafePath(path) {
|
|
14904
|
-
let cursor =
|
|
15178
|
+
let cursor = resolve15(path);
|
|
14905
15179
|
while (true) {
|
|
14906
|
-
if (
|
|
15180
|
+
if (lstatSync20(cursor, { throwIfNoEntry: false })?.isSymbolicLink() && !isSystemRootAlias(cursor))
|
|
14907
15181
|
throw new Error(`Refusing symlink path: ${cursor}`);
|
|
14908
|
-
const parent =
|
|
15182
|
+
const parent = dirname15(cursor);
|
|
14909
15183
|
if (parent === cursor)
|
|
14910
15184
|
return;
|
|
14911
15185
|
cursor = parent;
|
|
@@ -14913,17 +15187,17 @@ function assertSafePath(path) {
|
|
|
14913
15187
|
}
|
|
14914
15188
|
function readRootAlias(home, agent) {
|
|
14915
15189
|
assertSafePath(home);
|
|
14916
|
-
const realHome =
|
|
14917
|
-
const stat =
|
|
15190
|
+
const realHome = realpathSync10(home), alias = join23(realHome, `.${agent}`);
|
|
15191
|
+
const stat = lstatSync20(alias, { throwIfNoEntry: false, bigint: true });
|
|
14918
15192
|
if (!stat?.isSymbolicLink())
|
|
14919
15193
|
throw new Error(`Agent root alias changed after planning: ${alias}`);
|
|
14920
|
-
const link =
|
|
15194
|
+
const link = readlinkSync7(alias), targetPath = resolve15(dirname15(alias), link);
|
|
14921
15195
|
assertSafePath(targetPath);
|
|
14922
|
-
const targetStat =
|
|
15196
|
+
const targetStat = lstatSync20(targetPath, { throwIfNoEntry: false });
|
|
14923
15197
|
if (!targetStat?.isDirectory())
|
|
14924
15198
|
throw new Error(`Agent root alias must target an existing directory: ${alias}`);
|
|
14925
|
-
const target =
|
|
14926
|
-
if (!inside || inside === ".." || inside.startsWith(`..${sep7}`) ||
|
|
15199
|
+
const target = realpathSync10(targetPath), inside = relative6(realHome, target);
|
|
15200
|
+
if (!inside || inside === ".." || inside.startsWith(`..${sep7}`) || isAbsolute16(inside))
|
|
14927
15201
|
throw new Error(`Agent root alias target must be inside the real home: ${alias}`);
|
|
14928
15202
|
return { agent, home: realHome, alias, target, link, aliasIdentity: `${stat.dev}:${stat.ino}:${stat.ctimeNs}`, targetIdentity: `${targetStat.dev}:${targetStat.ino}` };
|
|
14929
15203
|
}
|
|
@@ -14932,7 +15206,7 @@ function rootAliases(home, allowed = false) {
|
|
|
14932
15206
|
return [];
|
|
14933
15207
|
const result = [];
|
|
14934
15208
|
for (const agent of ["claude", "codex"])
|
|
14935
|
-
if (
|
|
15209
|
+
if (lstatSync20(join23(home, `.${agent}`), { throwIfNoEntry: false })?.isSymbolicLink())
|
|
14936
15210
|
result.push(readRootAlias(home, agent));
|
|
14937
15211
|
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
15212
|
throw new Error("Agent root alias targets must not overlap");
|
|
@@ -14949,17 +15223,17 @@ function disabledCodexSkillPaths(config, aliases) {
|
|
|
14949
15223
|
const rows = skills.config;
|
|
14950
15224
|
if (!Array.isArray(rows))
|
|
14951
15225
|
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" || !
|
|
15226
|
+
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
15227
|
return [];
|
|
14954
15228
|
if (rows.some((entry) => entry.name !== undefined && entry.enabled !== false))
|
|
14955
15229
|
return [];
|
|
14956
15230
|
const settings = new Map;
|
|
14957
15231
|
for (const entry of rows) {
|
|
14958
|
-
if (typeof entry.path !== "string" || !
|
|
15232
|
+
if (typeof entry.path !== "string" || !isAbsolute16(entry.path))
|
|
14959
15233
|
continue;
|
|
14960
15234
|
let document2;
|
|
14961
15235
|
try {
|
|
14962
|
-
document2 =
|
|
15236
|
+
document2 = realpathSync10(canonicalAgentPath(entry.path, aliases));
|
|
14963
15237
|
} catch {
|
|
14964
15238
|
continue;
|
|
14965
15239
|
}
|
|
@@ -14967,7 +15241,7 @@ function disabledCodexSkillPaths(config, aliases) {
|
|
|
14967
15241
|
continue;
|
|
14968
15242
|
settings.set(document2, [...settings.get(document2) ?? [], entry.enabled === false]);
|
|
14969
15243
|
}
|
|
14970
|
-
return [...settings].filter(([, values]) => values.length === 1 && values[0] === true).map(([document2]) =>
|
|
15244
|
+
return [...settings].filter(([, values]) => values.length === 1 && values[0] === true).map(([document2]) => dirname15(document2));
|
|
14971
15245
|
}
|
|
14972
15246
|
function recheckRootAliases(aliases) {
|
|
14973
15247
|
for (const binding of aliases) {
|
|
@@ -14980,16 +15254,16 @@ function recheckRootAliases(aliases) {
|
|
|
14980
15254
|
}
|
|
14981
15255
|
function nativeSourceDigest(path) {
|
|
14982
15256
|
assertSafePath(path);
|
|
14983
|
-
return
|
|
15257
|
+
return lstatSync20(path, { throwIfNoEntry: false }) ? sha3(readNativeBytes(path, 1024 * 1024)) : null;
|
|
14984
15258
|
}
|
|
14985
15259
|
function readNativeBytes(path, maximum = 64 * 1024 * 1024) {
|
|
14986
15260
|
assertSafePath(path);
|
|
14987
|
-
const before =
|
|
15261
|
+
const before = lstatSync20(path);
|
|
14988
15262
|
if (!before.isFile() || before.size > maximum)
|
|
14989
15263
|
throw new Error("Unsupported or oversized native skill file");
|
|
14990
|
-
const descriptor =
|
|
15264
|
+
const descriptor = openSync11(path, constants11.O_RDONLY | constants11.O_NOFOLLOW | constants11.O_NONBLOCK);
|
|
14991
15265
|
try {
|
|
14992
|
-
const opened =
|
|
15266
|
+
const opened = fstatSync11(descriptor);
|
|
14993
15267
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino || opened.size !== before.size)
|
|
14994
15268
|
throw new Error("Native skill file changed while reading");
|
|
14995
15269
|
const bytes = Buffer.allocUnsafe(before.size + 1);
|
|
@@ -15000,19 +15274,19 @@ function readNativeBytes(path, maximum = 64 * 1024 * 1024) {
|
|
|
15000
15274
|
break;
|
|
15001
15275
|
length += count;
|
|
15002
15276
|
}
|
|
15003
|
-
const after =
|
|
15277
|
+
const after = fstatSync11(descriptor), current2 = lstatSync20(path);
|
|
15004
15278
|
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
15279
|
throw new Error("Native skill file changed while reading");
|
|
15006
15280
|
return bytes.subarray(0, length);
|
|
15007
15281
|
} finally {
|
|
15008
|
-
|
|
15282
|
+
closeSync11(descriptor);
|
|
15009
15283
|
}
|
|
15010
15284
|
}
|
|
15011
15285
|
function treeHash(root) {
|
|
15012
|
-
const hash2 =
|
|
15286
|
+
const hash2 = createHash20("sha256");
|
|
15013
15287
|
let bytes = 0, files = 0;
|
|
15014
15288
|
function visit2(path) {
|
|
15015
|
-
const stat =
|
|
15289
|
+
const stat = lstatSync20(path);
|
|
15016
15290
|
if (stat.isSymbolicLink())
|
|
15017
15291
|
throw new Error(`Refusing symlink in skill: ${path}`);
|
|
15018
15292
|
const rel = relative6(root, path);
|
|
@@ -15042,7 +15316,7 @@ function projectAncestorDirectories(projects) {
|
|
|
15042
15316
|
if (depth >= 100)
|
|
15043
15317
|
throw new Error("NATIVE_SKILL_DRIFT: project ancestor discovery limit exceeded");
|
|
15044
15318
|
directories.add(path);
|
|
15045
|
-
const parent =
|
|
15319
|
+
const parent = dirname15(path);
|
|
15046
15320
|
if (parent === path)
|
|
15047
15321
|
break;
|
|
15048
15322
|
path = parent;
|
|
@@ -15051,7 +15325,7 @@ function projectAncestorDirectories(projects) {
|
|
|
15051
15325
|
return [...directories];
|
|
15052
15326
|
}
|
|
15053
15327
|
function isCodexSkillDiscoveryInput(path) {
|
|
15054
|
-
for (let cursor = canonicalSystemPath(path);cursor !==
|
|
15328
|
+
for (let cursor = canonicalSystemPath(path);cursor !== dirname15(cursor); cursor = dirname15(cursor)) {
|
|
15055
15329
|
if (ROOTS.some(([agent, root]) => agent === "codex" && cursor.endsWith(join23(sep7, root))))
|
|
15056
15330
|
return true;
|
|
15057
15331
|
}
|
|
@@ -15059,9 +15333,9 @@ function isCodexSkillDiscoveryInput(path) {
|
|
|
15059
15333
|
}
|
|
15060
15334
|
function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
15061
15335
|
home = canonicalSystemPath(home);
|
|
15062
|
-
if (options.reviewedCacheAlias !== undefined && (!options.includeVendor || !
|
|
15336
|
+
if (options.reviewedCacheAlias !== undefined && (!options.includeVendor || !isAbsolute16(options.reviewedCacheAlias) || resolve15(options.reviewedCacheAlias) !== options.reviewedCacheAlias))
|
|
15063
15337
|
throw new Error("A reviewed cache alias requires vendor inventory and an exact absolute path");
|
|
15064
|
-
if (options.disabledVendorPaths?.some((path) => !
|
|
15338
|
+
if (options.disabledVendorPaths?.some((path) => !isAbsolute16(path) || resolve15(path) !== path))
|
|
15065
15339
|
throw new Error("Disabled vendor paths must be exact absolute paths");
|
|
15066
15340
|
const reviewedCacheAlias = options.reviewedCacheAlias === undefined ? undefined : canonicalSystemPath(options.reviewedCacheAlias);
|
|
15067
15341
|
const disabledVendorPaths = new Set((options.disabledVendorPaths ?? []).map(canonicalSystemPath));
|
|
@@ -15080,7 +15354,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15080
15354
|
roots.push(["sumi", canonicalAgentPath(join23(project, directory, name), aliases)]);
|
|
15081
15355
|
}
|
|
15082
15356
|
const installationInputs = options.codexInstallationInputRoots ?? [];
|
|
15083
|
-
if (installationInputs.some((input) =>
|
|
15357
|
+
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
15358
|
throw new Error("Native installation input overlaps an unconditional skill-loading root");
|
|
15085
15359
|
const entries = [], seen = new Set;
|
|
15086
15360
|
const cacheScans = new Map, maxAliasProofEntries = 1e4;
|
|
@@ -15094,13 +15368,13 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15094
15368
|
}
|
|
15095
15369
|
let reviewedCacheAliasFound = false;
|
|
15096
15370
|
function verifiedSiblingCacheAlias(agent, path, parent) {
|
|
15097
|
-
const link =
|
|
15098
|
-
if (
|
|
15371
|
+
const link = readlinkSync7(path), lexicalTarget = resolve15(parent, link);
|
|
15372
|
+
if (isAbsolute16(link) ? link !== lexicalTarget : dirname15(link) !== ".")
|
|
15099
15373
|
return false;
|
|
15100
15374
|
const target = canonicalSystemPath(lexicalTarget);
|
|
15101
|
-
if (
|
|
15375
|
+
if (dirname15(target) !== parent)
|
|
15102
15376
|
return false;
|
|
15103
|
-
if (!
|
|
15377
|
+
if (!lstatSync20(target, { throwIfNoEntry: false })?.isDirectory())
|
|
15104
15378
|
return false;
|
|
15105
15379
|
const scan = cacheScans.get(target);
|
|
15106
15380
|
if (!scan?.complete || scan.entries > maxAliasProofEntries)
|
|
@@ -15125,7 +15399,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15125
15399
|
return scan;
|
|
15126
15400
|
if (!existsSync92(path))
|
|
15127
15401
|
return scan;
|
|
15128
|
-
const stat =
|
|
15402
|
+
const stat = lstatSync20(path);
|
|
15129
15403
|
if (stat.isFile()) {
|
|
15130
15404
|
if (agent === "sumi" && depth === 1 && path.endsWith(".md"))
|
|
15131
15405
|
throw new Error("NATIVE_SKILL_DRIFT: flat Sumi skill documents require a dedicated migration adapter");
|
|
@@ -15142,22 +15416,22 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15142
15416
|
const marker = join23(path, ".hasna-skills.json");
|
|
15143
15417
|
if (existsSync92(marker)) {
|
|
15144
15418
|
try {
|
|
15145
|
-
managed = JSON.parse(
|
|
15419
|
+
managed = JSON.parse(readFileSync15(marker, "utf8")).managedBy === "@hasna/skills";
|
|
15146
15420
|
} catch {}
|
|
15147
15421
|
}
|
|
15148
15422
|
const bridge = (!vendor || agent === "sumi") && isOwnedCliBridge(path, bridgePaths);
|
|
15149
15423
|
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:
|
|
15424
|
+
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
15425
|
return scan;
|
|
15152
15426
|
}
|
|
15153
15427
|
if (depth > (agent === "sumi" ? 32 : vendor ? 32 : 3))
|
|
15154
15428
|
return { ...scan, complete: false };
|
|
15155
15429
|
const children = [], directory = opendirSync3(path);
|
|
15156
15430
|
try {
|
|
15157
|
-
let
|
|
15158
|
-
while ((
|
|
15159
|
-
admit(join23(path,
|
|
15160
|
-
children.push(
|
|
15431
|
+
let child2;
|
|
15432
|
+
while ((child2 = directory.readSync()) !== null) {
|
|
15433
|
+
admit(join23(path, child2.name));
|
|
15434
|
+
children.push(child2);
|
|
15161
15435
|
}
|
|
15162
15436
|
} finally {
|
|
15163
15437
|
directory.closeSync();
|
|
@@ -15173,15 +15447,15 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15173
15447
|
const isVendor = vendor || name === ".system";
|
|
15174
15448
|
if (isVendor && !options.includeVendor)
|
|
15175
15449
|
continue;
|
|
15176
|
-
const
|
|
15177
|
-
if (isVendor &&
|
|
15178
|
-
const target = statSync9(
|
|
15179
|
-
if (target?.isFile() || pluginCache && target?.isDirectory() && verifiedSiblingCacheAlias(agent,
|
|
15450
|
+
const child2 = join23(path, name);
|
|
15451
|
+
if (isVendor && lstatSync20(child2, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
15452
|
+
const target = statSync9(child2, { throwIfNoEntry: false });
|
|
15453
|
+
if (target?.isFile() || pluginCache && target?.isDirectory() && verifiedSiblingCacheAlias(agent, child2, path)) {
|
|
15180
15454
|
scan.entries++;
|
|
15181
15455
|
continue;
|
|
15182
15456
|
}
|
|
15183
15457
|
}
|
|
15184
|
-
const childScan = visit2(agent,
|
|
15458
|
+
const childScan = visit2(agent, child2, isVendor, depth + 1, pluginCache, true, configuredRoot);
|
|
15185
15459
|
scan.complete &&= childScan.complete;
|
|
15186
15460
|
scan.hasSkills ||= childScan.hasSkills;
|
|
15187
15461
|
scan.entries += childScan.entries;
|
|
@@ -15217,7 +15491,7 @@ function inventoryNativeSkills(home = homedir22(), options = {}) {
|
|
|
15217
15491
|
}
|
|
15218
15492
|
function readOptional(path) {
|
|
15219
15493
|
assertSafePath(path);
|
|
15220
|
-
return existsSync92(path) ?
|
|
15494
|
+
return existsSync92(path) ? readFileSync15(path, "utf8") : null;
|
|
15221
15495
|
}
|
|
15222
15496
|
function jsonObject(text2, path) {
|
|
15223
15497
|
if (text2 === null)
|
|
@@ -15315,29 +15589,28 @@ function configureHooks(config, agent, command, profileId, nativeReady) {
|
|
|
15315
15589
|
}
|
|
15316
15590
|
}
|
|
15317
15591
|
function claudeSettingsConsumers(home, path, discoveries, aliases) {
|
|
15318
|
-
const
|
|
15592
|
+
const canonical7 = (value) => canonicalAgentPath(value, aliases);
|
|
15319
15593
|
const containsSettings = (root) => {
|
|
15320
|
-
const distance = relative6(
|
|
15321
|
-
return distance === "" || distance !== ".." && !distance.startsWith(`..${sep7}`) && !
|
|
15594
|
+
const distance = relative6(canonical7(root), path);
|
|
15595
|
+
return distance === "" || distance !== ".." && !distance.startsWith(`..${sep7}`) && !isAbsolute16(distance);
|
|
15322
15596
|
};
|
|
15323
|
-
return discoveries.filter((binding) => binding.agent === "claude" || binding.agent === "opencode" ||
|
|
15597
|
+
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
15598
|
}
|
|
15325
|
-
function verifyCoordinatedDiscovery(binding, home, aliases) {
|
|
15599
|
+
function verifyCoordinatedDiscovery(binding, home, aliases, executable2) {
|
|
15326
15600
|
try {
|
|
15327
15601
|
if (binding.method !== "automatic" && binding.method !== "reviewed")
|
|
15328
15602
|
throw new Error("Invalid managed discovery method");
|
|
15329
15603
|
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
|
-
}
|
|
15604
|
+
if (binding.method === "automatic")
|
|
15605
|
+
verifyAutomaticDiscoveryClosure(binding, { home, canonical: (path) => canonicalAgentPath(path, aliases), change: "Configured native discovery roots changed during Claude update", executable: executable2 });
|
|
15335
15606
|
} catch (error) {
|
|
15607
|
+
if (isDiscoveryRootUnresolved(error))
|
|
15608
|
+
throw error;
|
|
15336
15609
|
throw new Error(`NATIVE_SKILL_DRIFT: ${error.message}`);
|
|
15337
15610
|
}
|
|
15338
15611
|
}
|
|
15339
15612
|
function planClaudeHookEventsUpdate(options) {
|
|
15340
|
-
const home =
|
|
15613
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15341
15614
|
const policyPath = join23(dataDir22, "agent-policy.json");
|
|
15342
15615
|
assertSafePath(policyPath);
|
|
15343
15616
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
@@ -15351,7 +15624,7 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15351
15624
|
recheckRootAliases(aliases);
|
|
15352
15625
|
const path = canonicalAgentPath(join23(home, ".claude", "settings.json"), aliases);
|
|
15353
15626
|
assertSafePath(path);
|
|
15354
|
-
const before =
|
|
15627
|
+
const before = lstatSync20(path, { throwIfNoEntry: false }) ? new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readNativeBytes(path, 1024 * 1024)) : null;
|
|
15355
15628
|
if ((before === null ? "absent" : sha3(before)) !== options.expectedSettingsSha256)
|
|
15356
15629
|
throw new Error("Claude settings preimage changed");
|
|
15357
15630
|
assertClaudeHookEventsReplacement(before, options.replacement, options.events);
|
|
@@ -15363,8 +15636,9 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15363
15636
|
});
|
|
15364
15637
|
if (discoveries.length !== agents.length || !agents.includes("claude"))
|
|
15365
15638
|
throw new Error("Missing managed Claude discovery coverage");
|
|
15639
|
+
const discoveryExecutables = bridge.discoveryExecutables;
|
|
15366
15640
|
for (const binding of discoveries)
|
|
15367
|
-
verifyCoordinatedDiscovery(binding, home, aliases);
|
|
15641
|
+
verifyCoordinatedDiscovery(binding, home, aliases, discoveryExecutables?.[binding.agent]);
|
|
15368
15642
|
const consumers = claudeSettingsConsumers(home, path, discoveries, aliases);
|
|
15369
15643
|
for (const agent of consumers)
|
|
15370
15644
|
assertManagedAgentBridge(agent, { home, dataDir: dataDir22, projectDir: home });
|
|
@@ -15399,13 +15673,14 @@ function planClaudeHookEventsUpdate(options) {
|
|
|
15399
15673
|
observedPolicy: { path: policyPath, before: snapshot2.text },
|
|
15400
15674
|
discoveryBefore: discoveries,
|
|
15401
15675
|
discoveryAfter,
|
|
15676
|
+
...discoveryExecutables ? { discoveryExecutables } : {},
|
|
15402
15677
|
rootAliases: aliases,
|
|
15403
15678
|
managedAgentChecks: { home, agents: consumers }
|
|
15404
15679
|
};
|
|
15405
15680
|
}
|
|
15406
15681
|
function atomicWrite2(path, content) {
|
|
15407
15682
|
assertSafePath(path);
|
|
15408
|
-
mkdirSync6(
|
|
15683
|
+
mkdirSync6(dirname15(path), { recursive: true, mode: 448 });
|
|
15409
15684
|
const temporary = `${path}.skills-${randomUUID3()}`;
|
|
15410
15685
|
try {
|
|
15411
15686
|
writeFileSync6(temporary, content, { mode: 384, flag: "wx" });
|
|
@@ -15418,7 +15693,9 @@ function atomicWrite2(path, content) {
|
|
|
15418
15693
|
function planAgentSettingsWitnessUpgrade(options) {
|
|
15419
15694
|
if (options.targetCodexVersion !== undefined && (options.agent !== "codex" || ![2, 3, 4].includes(options.targetCodexVersion)))
|
|
15420
15695
|
throw new Error("Invalid Codex witness target version");
|
|
15421
|
-
|
|
15696
|
+
if (options.targetClaudeVersion !== undefined && (options.agent !== "claude" || ![3, 4].includes(options.targetClaudeVersion)))
|
|
15697
|
+
throw new Error("Invalid Claude witness target version");
|
|
15698
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15422
15699
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
15423
15700
|
if (!snapshot2 || sha3(snapshot2.text) !== options.expectedPolicySha256)
|
|
15424
15701
|
throw new Error("Managed policy preimage changed");
|
|
@@ -15465,7 +15742,7 @@ function planAgentSettingsWitnessUpgrade(options) {
|
|
|
15465
15742
|
replaced.push(source);
|
|
15466
15743
|
}
|
|
15467
15744
|
}
|
|
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);
|
|
15745
|
+
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
15746
|
const rebound = [];
|
|
15470
15747
|
for (const source of binding.sources) {
|
|
15471
15748
|
if (!replaced.includes(source)) {
|
|
@@ -15478,7 +15755,7 @@ function planAgentSettingsWitnessUpgrade(options) {
|
|
|
15478
15755
|
const replacement = { ...binding, sources: rebound };
|
|
15479
15756
|
verifyAgentDiscovery(replacement);
|
|
15480
15757
|
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 })) } };
|
|
15758
|
+
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
15759
|
}
|
|
15483
15760
|
function applyAgentIntegration(plan, options = {}) {
|
|
15484
15761
|
const roots = plan.changes.flatMap((change) => {
|
|
@@ -15496,10 +15773,10 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15496
15773
|
throw new Error("Native settings changed after witness planning");
|
|
15497
15774
|
const policyPath = join23(plan.dataDir, "agent-policy.json");
|
|
15498
15775
|
assertSafePath(policyPath);
|
|
15499
|
-
const currentText = (path) =>
|
|
15776
|
+
const currentText = (path) => resolve15(path) === resolve15(policyPath) ? readManagedSkillPolicySnapshot(plan.dataDir)?.text ?? null : readOptional(path);
|
|
15500
15777
|
readManagedSkillPolicySnapshot(plan.dataDir);
|
|
15501
15778
|
for (const change of plan.changes)
|
|
15502
|
-
if (
|
|
15779
|
+
if (resolve15(change.path) === resolve15(policyPath))
|
|
15503
15780
|
parseManagedSkillPolicy(change.after);
|
|
15504
15781
|
const aliases = plan.rootAliases ?? [];
|
|
15505
15782
|
assertCurrent();
|
|
@@ -15511,7 +15788,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15511
15788
|
const upgrade = plan.settingsWitnessUpgrade;
|
|
15512
15789
|
if (!plan.managedAgentChecks || !plan.observedPolicy?.before)
|
|
15513
15790
|
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 });
|
|
15791
|
+
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
15792
|
if (JSON.stringify(verified.changes) !== JSON.stringify(plan.changes) || JSON.stringify(verified.settingsWitnessUpgrade) !== JSON.stringify(upgrade))
|
|
15516
15793
|
throw new Error("Settings witness upgrade plan changed");
|
|
15517
15794
|
provenDiscovery = verified.discoveryBefore[0];
|
|
@@ -15520,7 +15797,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15520
15797
|
assertManagedAgentBridgeWithDiscovery(agent, { home: plan.managedAgentChecks.home, dataDir: plan.dataDir, projectDir: plan.managedAgentChecks.home }, provenDiscovery?.agent === agent ? provenDiscovery : undefined);
|
|
15521
15798
|
for (const binding of plan.discoveryBefore ?? []) {
|
|
15522
15799
|
if (plan.managedAgentChecks)
|
|
15523
|
-
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases);
|
|
15800
|
+
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases, plan.discoveryExecutables?.[binding.agent]);
|
|
15524
15801
|
else
|
|
15525
15802
|
verifyAgentDiscovery(binding);
|
|
15526
15803
|
}
|
|
@@ -15542,7 +15819,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15542
15819
|
if (change.before !== null) {
|
|
15543
15820
|
const backup = join23(backupRoot, `${index}-${sha3(change.path).slice(0, 12)}.backup`);
|
|
15544
15821
|
writeFileSync6(backup, change.before, { mode: 384, flag: "wx" });
|
|
15545
|
-
if (
|
|
15822
|
+
if (readFileSync15(backup, "utf8") !== change.before)
|
|
15546
15823
|
throw new Error("Native configuration preservation readback failed");
|
|
15547
15824
|
backups.push(backup);
|
|
15548
15825
|
}
|
|
@@ -15552,7 +15829,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15552
15829
|
recheckRootAliases(aliases);
|
|
15553
15830
|
if (currentText(change.path) !== change.before)
|
|
15554
15831
|
throw new Error(`Configuration changed after planning: ${change.path}`);
|
|
15555
|
-
for (let directory =
|
|
15832
|
+
for (let directory = dirname15(change.path);!existsSync92(directory); directory = dirname15(directory))
|
|
15556
15833
|
createdDirectories.add(directory);
|
|
15557
15834
|
const after = change.after;
|
|
15558
15835
|
atomicWrite2(change.path, after);
|
|
@@ -15567,7 +15844,7 @@ function applyAgentIntegrationUnlocked(plan, options = {}, assertCurrent) {
|
|
|
15567
15844
|
throw new Error("Native settings changed during witness application");
|
|
15568
15845
|
for (const binding of plan.discoveryAfter ?? []) {
|
|
15569
15846
|
if (plan.managedAgentChecks)
|
|
15570
|
-
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases);
|
|
15847
|
+
verifyCoordinatedDiscovery(binding, plan.managedAgentChecks.home, aliases, plan.discoveryExecutables?.[binding.agent]);
|
|
15571
15848
|
else
|
|
15572
15849
|
verifyAgentDiscovery(binding);
|
|
15573
15850
|
}
|
|
@@ -15609,12 +15886,12 @@ function isInertCodexPluginCacheCopy(entry, cache, allowedHostPaths, read2) {
|
|
|
15609
15886
|
return false;
|
|
15610
15887
|
const document2 = join23(entry.path, "SKILL.md");
|
|
15611
15888
|
const inside = relative6(cache, entry.path);
|
|
15612
|
-
if (!inside ||
|
|
15889
|
+
if (!inside || isAbsolute16(inside) || inside.split(sep7).some((segment) => segment === ".."))
|
|
15613
15890
|
return false;
|
|
15614
15891
|
assertSafePath(entry.path);
|
|
15615
|
-
if (!
|
|
15892
|
+
if (!lstatSync20(cache).isDirectory() || !lstatSync20(entry.path).isDirectory() || !lstatSync20(document2).isFile())
|
|
15616
15893
|
return false;
|
|
15617
|
-
if (
|
|
15894
|
+
if (realpathSync10.native(cache) !== cache || realpathSync10.native(entry.path) !== entry.path || realpathSync10.native(document2) !== document2)
|
|
15618
15895
|
return false;
|
|
15619
15896
|
if (!classifyCodexPluginCacheDocument(document2, cache, read2))
|
|
15620
15897
|
return false;
|
|
@@ -15629,7 +15906,7 @@ function assertManagedAgentBridge(agent, options = {}) {
|
|
|
15629
15906
|
assertManagedAgentBridgeWithDiscovery(agent, options);
|
|
15630
15907
|
}
|
|
15631
15908
|
function assertManagedAgentBridgeWithDiscovery(agent, options = {}, provenDiscovery) {
|
|
15632
|
-
const home =
|
|
15909
|
+
const home = resolve15(options.home ?? homedir22()), dataDir22 = options.dataDir ?? getDataDirReadOnly();
|
|
15633
15910
|
assertSafePath(join23(dataDir22, "agent-policy.json"));
|
|
15634
15911
|
const snapshot2 = readManagedSkillPolicySnapshot(dataDir22);
|
|
15635
15912
|
if (!snapshot2)
|
|
@@ -15727,12 +16004,11 @@ function assertManagedAgentBridgeWithDiscovery(agent, options = {}, provenDiscov
|
|
|
15727
16004
|
verifyAgentDiscovery(agent === "codex" ? { ...discovery, codexDisabledPluginSkills: binding.codexPluginSkills ?? [] } : discovery, options.codexDiscoveryRecovery);
|
|
15728
16005
|
if (agent === "sumi" && discovery.method === "reviewed")
|
|
15729
16006
|
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
|
-
}
|
|
16007
|
+
if (discovery.method === "automatic")
|
|
16008
|
+
verifyAutomaticDiscoveryClosure(discovery, { home, canonical: (path) => canonicalAgentPath(path, aliases), change: "Configured native discovery roots changed", executable: binding.discoveryExecutables?.[agent] });
|
|
15735
16009
|
} catch (error) {
|
|
16010
|
+
if (isDiscoveryRootUnresolved(error))
|
|
16011
|
+
throw error;
|
|
15736
16012
|
throw new Error(`NATIVE_SKILL_DRIFT: ${error.message}`);
|
|
15737
16013
|
}
|
|
15738
16014
|
let installationInputRoots = [];
|
|
@@ -15779,7 +16055,7 @@ function pluginNeed(value, message) {
|
|
|
15779
16055
|
if (!value)
|
|
15780
16056
|
pluginRefusal(message);
|
|
15781
16057
|
}
|
|
15782
|
-
var pluginHash = (bytes) =>
|
|
16058
|
+
var pluginHash = (bytes) => createHash21("sha256").update(bytes).digest("hex");
|
|
15783
16059
|
function pluginObject(value) {
|
|
15784
16060
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
15785
16061
|
}
|
|
@@ -15850,21 +16126,21 @@ function pluginFileWitnesses(entries) {
|
|
|
15850
16126
|
return { path: item.path, mode: item.mode, size: item.bytes.byteLength, sha256: pluginHash(item.bytes) };
|
|
15851
16127
|
});
|
|
15852
16128
|
}
|
|
15853
|
-
var READ_FLAGS =
|
|
15854
|
-
var WRITE_FLAGS =
|
|
16129
|
+
var READ_FLAGS = constants12.O_RDONLY | constants12.O_NOFOLLOW | constants12.O_NONBLOCK;
|
|
16130
|
+
var WRITE_FLAGS = constants12.O_WRONLY | constants12.O_CREAT | constants12.O_EXCL | constants12.O_NOFOLLOW | constants12.O_NONBLOCK;
|
|
15855
16131
|
var uid = () => typeof process.getuid === "function" ? BigInt(process.getuid()) : undefined;
|
|
15856
16132
|
var missing = (error) => Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
15857
16133
|
function stat(path) {
|
|
15858
16134
|
try {
|
|
15859
|
-
return
|
|
16135
|
+
return lstatSync22(path, { bigint: true });
|
|
15860
16136
|
} catch (error) {
|
|
15861
16137
|
if (missing(error))
|
|
15862
16138
|
return null;
|
|
15863
16139
|
return pluginRefusal("Cannot inspect plugin filesystem entry");
|
|
15864
16140
|
}
|
|
15865
16141
|
}
|
|
15866
|
-
function
|
|
15867
|
-
pluginNeed(typeof path === "string" && path.length <= 8192 &&
|
|
16142
|
+
function canonical7(path) {
|
|
16143
|
+
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
16144
|
}
|
|
15869
16145
|
function owner(stats, system = false) {
|
|
15870
16146
|
const current2 = uid();
|
|
@@ -15874,8 +16150,8 @@ function same3(left, right, identityOnly = false) {
|
|
|
15874
16150
|
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
16151
|
}
|
|
15876
16152
|
function ancestors(path, create = false) {
|
|
15877
|
-
|
|
15878
|
-
const result = [], parent =
|
|
16153
|
+
canonical7(path);
|
|
16154
|
+
const result = [], parent = dirname17(path), filesystemRoot = parse6(parent).root;
|
|
15879
16155
|
let current2 = filesystemRoot;
|
|
15880
16156
|
for (const segment of ["", ...parent.slice(filesystemRoot.length).split("/").filter(Boolean)]) {
|
|
15881
16157
|
if (segment)
|
|
@@ -15925,8 +16201,8 @@ function readBytes(path, maximum, kind) {
|
|
|
15925
16201
|
fileShape(before, maximum, kind);
|
|
15926
16202
|
let fd;
|
|
15927
16203
|
try {
|
|
15928
|
-
fd =
|
|
15929
|
-
const opened =
|
|
16204
|
+
fd = openSync12(path, READ_FLAGS);
|
|
16205
|
+
const opened = fstatSync12(fd, { bigint: true });
|
|
15930
16206
|
same3(before, opened);
|
|
15931
16207
|
fileShape(opened, maximum, kind);
|
|
15932
16208
|
const bytes = new Uint8Array(Number(opened.size));
|
|
@@ -15937,7 +16213,7 @@ function readBytes(path, maximum, kind) {
|
|
|
15937
16213
|
offset += count;
|
|
15938
16214
|
}
|
|
15939
16215
|
pluginNeed(readSync9(fd, new Uint8Array(1), 0, 1, null) === 0, "Plugin file grew while being read");
|
|
15940
|
-
same3(opened,
|
|
16216
|
+
same3(opened, fstatSync12(fd, { bigint: true }));
|
|
15941
16217
|
same3(opened, stat(path));
|
|
15942
16218
|
verifyAncestors(chain);
|
|
15943
16219
|
return bytes;
|
|
@@ -15947,7 +16223,7 @@ function readBytes(path, maximum, kind) {
|
|
|
15947
16223
|
return pluginRefusal("Cannot safely read plugin file");
|
|
15948
16224
|
} finally {
|
|
15949
16225
|
if (fd !== undefined)
|
|
15950
|
-
|
|
16226
|
+
closeSync12(fd);
|
|
15951
16227
|
}
|
|
15952
16228
|
}
|
|
15953
16229
|
function exactPaths(entries) {
|
|
@@ -16076,7 +16352,7 @@ function validatePluginTarget(value) {
|
|
|
16076
16352
|
for (const registration of value.registrations) {
|
|
16077
16353
|
pluginKeys(registration, ["scope", "projectPath"]);
|
|
16078
16354
|
pluginNeed(registration.scope === "user" || registration.scope === "project", "Unsupported plugin registration scope");
|
|
16079
|
-
pluginNeed(registration.scope === "user" ? registration.projectPath === null : typeof registration.projectPath === "string" &&
|
|
16355
|
+
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
16356
|
const key = JSON.stringify([registration.scope, registration.projectPath]);
|
|
16081
16357
|
pluginNeed(!scopes.has(key), "Duplicate plugin registration scope");
|
|
16082
16358
|
scopes.add(key);
|
|
@@ -16084,7 +16360,7 @@ function validatePluginTarget(value) {
|
|
|
16084
16360
|
for (const key of ["native", "resolver"]) {
|
|
16085
16361
|
pluginKeys(value[key], key === "native" ? ["version", "executable", "digest"] : ["executable", "digest"]);
|
|
16086
16362
|
pluginText(value[key].executable);
|
|
16087
|
-
pluginNeed(
|
|
16363
|
+
pluginNeed(isAbsolute18(value[key].executable) && resolve17(value[key].executable) === value[key].executable, "Plugin executable must have a canonical absolute path");
|
|
16088
16364
|
pluginDigest(value[key].digest);
|
|
16089
16365
|
}
|
|
16090
16366
|
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 +16498,10 @@ function validatePlan(value) {
|
|
|
16222
16498
|
pluginNeed(observedEvidenceDigest(plan.observation) === plan.evidenceDigest, "Plugin receipt observed evidence changed");
|
|
16223
16499
|
pluginNeed(identityDigest(plan) === plan.planDigest, "Plugin receipt immutable identity changed");
|
|
16224
16500
|
}
|
|
16225
|
-
var
|
|
16501
|
+
var quote22 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
16226
16502
|
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
16503
|
function pluginResolverCommand(binding) {
|
|
16228
|
-
return `${
|
|
16504
|
+
return `${quote22("/bin/sh")} -eu -c ${quote22(resolverGuard)} plugin-resolver ${quote22(binding.target.resolver.executable)} ${quote22(binding.target.resolver.digest)} ${quote22(bindingId(binding))}`;
|
|
16229
16505
|
}
|
|
16230
16506
|
function pluginBindingPath(storeRoot, id) {
|
|
16231
16507
|
pluginNeed(/^[a-f0-9]{64}$/.test(id), "Invalid plugin binding identifier");
|
|
@@ -16267,25 +16543,25 @@ function validateManagedPluginWitnesses(value) {
|
|
|
16267
16543
|
pluginNeed(typeof item.bindingId === "string" && /^[a-f0-9]{64}$/.test(item.bindingId) && !seen.has(item.bindingId), "Invalid or duplicate managed plugin witness");
|
|
16268
16544
|
seen.add(item.bindingId);
|
|
16269
16545
|
pluginText(item.storeRoot);
|
|
16270
|
-
pluginNeed(
|
|
16546
|
+
pluginNeed(isAbsolute19(item.storeRoot) && resolve18(item.storeRoot) === item.storeRoot, "Invalid plugin receipt store path");
|
|
16271
16547
|
}
|
|
16272
16548
|
}
|
|
16273
16549
|
function safe3(path) {
|
|
16274
16550
|
pluginText(path);
|
|
16275
|
-
pluginNeed(
|
|
16276
|
-
for (let at = path;; at =
|
|
16277
|
-
pluginNeed(!
|
|
16278
|
-
if (at ===
|
|
16551
|
+
pluginNeed(isAbsolute19(path) && resolve18(path) === path, "Invalid plugin registry path");
|
|
16552
|
+
for (let at = path;; at = dirname18(at)) {
|
|
16553
|
+
pluginNeed(!lstatSync23(at, { throwIfNoEntry: false })?.isSymbolicLink(), "Plugin registry path traverses a symlink");
|
|
16554
|
+
if (at === dirname18(at))
|
|
16279
16555
|
break;
|
|
16280
16556
|
}
|
|
16281
16557
|
}
|
|
16282
16558
|
function readRegistry(path) {
|
|
16283
16559
|
safe3(path);
|
|
16284
|
-
const initial =
|
|
16560
|
+
const initial = lstatSync23(path);
|
|
16285
16561
|
pluginNeed(initial.isFile() && initial.size <= 1024 * 1024, "Plugin registry is not a bounded regular file");
|
|
16286
|
-
const fd =
|
|
16562
|
+
const fd = openSync13(path, constants13.O_RDONLY | constants13.O_NOFOLLOW | constants13.O_NONBLOCK);
|
|
16287
16563
|
try {
|
|
16288
|
-
const opened =
|
|
16564
|
+
const opened = fstatSync13(fd);
|
|
16289
16565
|
pluginNeed(opened.isFile() && opened.ino === initial.ino && opened.dev === initial.dev, "Plugin registry changed during open");
|
|
16290
16566
|
const bytes = Buffer.alloc(1024 * 1024 + 1);
|
|
16291
16567
|
let length = 0;
|
|
@@ -16295,7 +16571,7 @@ function readRegistry(path) {
|
|
|
16295
16571
|
break;
|
|
16296
16572
|
length += count;
|
|
16297
16573
|
}
|
|
16298
|
-
const after =
|
|
16574
|
+
const after = fstatSync13(fd), current2 = lstatSync23(path);
|
|
16299
16575
|
safe3(path);
|
|
16300
16576
|
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
16577
|
let value;
|
|
@@ -16307,7 +16583,7 @@ function readRegistry(path) {
|
|
|
16307
16583
|
pluginNeed(pluginObject(value) && value.version === 2 && pluginObject(value.plugins), "Unsupported native plugin registry schema");
|
|
16308
16584
|
return { value, rawDigest: pluginHash(bytes.subarray(0, length)) };
|
|
16309
16585
|
} finally {
|
|
16310
|
-
|
|
16586
|
+
closeSync13(fd);
|
|
16311
16587
|
}
|
|
16312
16588
|
}
|
|
16313
16589
|
function nativeVersionMatches(version, receipt) {
|
|
@@ -16325,7 +16601,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16325
16601
|
seen.add(target.pluginId);
|
|
16326
16602
|
const rows = plugins[target.pluginId];
|
|
16327
16603
|
pluginNeed(Array.isArray(rows) && rows.length === target.registrations.length, "Managed plugin registration membership changed");
|
|
16328
|
-
const [name, market] = target.pluginId.split("@"), cacheRoot = join31(
|
|
16604
|
+
const [name, market] = target.pluginId.split("@"), cacheRoot = join31(dirname18(path), "cache", market, name);
|
|
16329
16605
|
const scopes = new Set, approvals = new Map, currentFiles = new Map;
|
|
16330
16606
|
plugins[target.pluginId] = rows.map((row) => {
|
|
16331
16607
|
pluginNeed(pluginObject(row), "Invalid managed plugin registration");
|
|
@@ -16341,7 +16617,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16341
16617
|
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
16618
|
const approval = (producer) => {
|
|
16343
16619
|
pluginText(producer);
|
|
16344
|
-
const digest = `sha256:${
|
|
16620
|
+
const digest = `sha256:${basename9(producer)}`;
|
|
16345
16621
|
const receipt2 = readPluginAdmissionReceipt(witness.storeRoot, witness.bindingId, digest);
|
|
16346
16622
|
pluginNeed(receipt2.materializedPath === producer, "Managed producer path is not an approved immutable projection");
|
|
16347
16623
|
if (!verified.has(producer)) {
|
|
@@ -16368,7 +16644,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16368
16644
|
return Object.fromEntries(Object.entries(row).filter(([key]) => !["version", "installPath", "sourceProducerPath", "previousProducerPaths", "lastUpdated"].includes(key)));
|
|
16369
16645
|
});
|
|
16370
16646
|
safe3(cacheRoot);
|
|
16371
|
-
const before =
|
|
16647
|
+
const before = lstatSync23(cacheRoot);
|
|
16372
16648
|
pluginNeed(before.isDirectory(), "Invalid managed plugin cache root");
|
|
16373
16649
|
const directory = opendirSync5(cacheRoot), names = [];
|
|
16374
16650
|
try {
|
|
@@ -16391,7 +16667,7 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16391
16667
|
}
|
|
16392
16668
|
for (const row of rows)
|
|
16393
16669
|
pluginNeed(names.includes(row.version), "Managed native plugin installation is missing");
|
|
16394
|
-
const after =
|
|
16670
|
+
const after = lstatSync23(cacheRoot);
|
|
16395
16671
|
safe3(cacheRoot);
|
|
16396
16672
|
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
16673
|
}
|
|
@@ -16399,35 +16675,35 @@ function hashManagedPluginRegistry(path, managed) {
|
|
|
16399
16675
|
return pluginHash(JSON.stringify(snapshot2.value));
|
|
16400
16676
|
}
|
|
16401
16677
|
var CLAUDE_MARKETPLACE_REGISTRY_LIMITS = Object.freeze({ bytes: 1024 * 1024, rows: 1024, depth: 32, nodes: 65536, stringCharacters: 16384, pathCharacters: 4096 });
|
|
16402
|
-
function
|
|
16678
|
+
function need7(value, reason2) {
|
|
16403
16679
|
if (!value)
|
|
16404
|
-
throw new Error(`Claude marketplace registry ${
|
|
16680
|
+
throw new Error(`Claude marketplace registry ${reason2}`);
|
|
16405
16681
|
}
|
|
16406
16682
|
function absolutePath3(value) {
|
|
16407
|
-
|
|
16683
|
+
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
16684
|
}
|
|
16409
16685
|
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
16686
|
function parents2(path) {
|
|
16411
16687
|
const result = [];
|
|
16412
|
-
for (let at =
|
|
16413
|
-
const stat2 =
|
|
16414
|
-
|
|
16688
|
+
for (let at = dirname19(path);; at = dirname19(at)) {
|
|
16689
|
+
const stat2 = lstatSync24(at, { bigint: true });
|
|
16690
|
+
need7(stat2.isDirectory() && !stat2.isSymbolicLink(), "path traverses a symlink or non-directory");
|
|
16415
16691
|
result.push([at, stat2]);
|
|
16416
|
-
if (at ===
|
|
16692
|
+
if (at === dirname19(at))
|
|
16417
16693
|
return result;
|
|
16418
16694
|
}
|
|
16419
16695
|
}
|
|
16420
16696
|
function readRegistry2(path, budget2) {
|
|
16421
16697
|
absolutePath3(path);
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
const ancestors2 = parents2(path), initial =
|
|
16425
|
-
|
|
16426
|
-
|
|
16427
|
-
const fd =
|
|
16698
|
+
need7(basename10(path) === "known_marketplaces.json", "requires known_marketplaces.json");
|
|
16699
|
+
need7(Number.isSafeInteger(budget2.remaining) && budget2.remaining >= 0, "has an invalid byte budget");
|
|
16700
|
+
const ancestors2 = parents2(path), initial = lstatSync24(path, { bigint: true });
|
|
16701
|
+
need7(initial.isFile() && !initial.isSymbolicLink() && initial.size <= BigInt(CLAUDE_MARKETPLACE_REGISTRY_LIMITS.bytes), "is not a bounded regular file");
|
|
16702
|
+
need7(initial.size <= BigInt(budget2.remaining), "exceeds its aggregate byte limit");
|
|
16703
|
+
const fd = openSync14(path, constants14.O_RDONLY | constants14.O_NOFOLLOW | constants14.O_NONBLOCK);
|
|
16428
16704
|
try {
|
|
16429
|
-
const opened =
|
|
16430
|
-
|
|
16705
|
+
const opened = fstatSync14(fd, { bigint: true });
|
|
16706
|
+
need7(opened.isFile() && sameFile2(initial, opened), "changed during open");
|
|
16431
16707
|
const bytes = Buffer.alloc(Number(opened.size) + 1);
|
|
16432
16708
|
let length = 0;
|
|
16433
16709
|
while (length < bytes.length) {
|
|
@@ -16436,11 +16712,11 @@ function readRegistry2(path, budget2) {
|
|
|
16436
16712
|
break;
|
|
16437
16713
|
length += count;
|
|
16438
16714
|
}
|
|
16439
|
-
const after =
|
|
16440
|
-
|
|
16715
|
+
const after = fstatSync14(fd, { bigint: true }), current2 = lstatSync24(path, { bigint: true });
|
|
16716
|
+
need7(current2.isFile() && sameFile2(opened, after) && sameFile2(after, current2) && BigInt(length) === opened.size, "changed during read");
|
|
16441
16717
|
for (const [ancestor, before] of ancestors2) {
|
|
16442
|
-
const now =
|
|
16443
|
-
|
|
16718
|
+
const now = lstatSync24(ancestor, { bigint: true });
|
|
16719
|
+
need7(now.isDirectory() && before.dev === now.dev && before.ino === now.ino && before.mode === now.mode, "parent changed during read");
|
|
16444
16720
|
}
|
|
16445
16721
|
budget2.remaining -= length;
|
|
16446
16722
|
try {
|
|
@@ -16449,7 +16725,7 @@ function readRegistry2(path, budget2) {
|
|
|
16449
16725
|
throw new Error("Claude marketplace registry is not strict UTF-8");
|
|
16450
16726
|
}
|
|
16451
16727
|
} finally {
|
|
16452
|
-
|
|
16728
|
+
closeSync14(fd);
|
|
16453
16729
|
}
|
|
16454
16730
|
}
|
|
16455
16731
|
function parse7(text2) {
|
|
@@ -16460,7 +16736,7 @@ function parse7(text2) {
|
|
|
16460
16736
|
at++;
|
|
16461
16737
|
};
|
|
16462
16738
|
function string() {
|
|
16463
|
-
|
|
16739
|
+
need7(text2[at] === '"', "contains invalid JSON");
|
|
16464
16740
|
const start = at++;
|
|
16465
16741
|
while (at < text2.length) {
|
|
16466
16742
|
const character = text2[at++];
|
|
@@ -16471,7 +16747,7 @@ function parse7(text2) {
|
|
|
16471
16747
|
} catch {
|
|
16472
16748
|
throw new Error("Claude marketplace registry contains invalid JSON string");
|
|
16473
16749
|
}
|
|
16474
|
-
|
|
16750
|
+
need7(value2.length <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.stringCharacters, "exceeds its string limit");
|
|
16475
16751
|
return value2;
|
|
16476
16752
|
}
|
|
16477
16753
|
if (character === "\\")
|
|
@@ -16480,7 +16756,7 @@ function parse7(text2) {
|
|
|
16480
16756
|
throw new Error("Claude marketplace registry contains an unterminated JSON string");
|
|
16481
16757
|
}
|
|
16482
16758
|
function value(depth) {
|
|
16483
|
-
|
|
16759
|
+
need7(depth <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.depth && ++nodes <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.nodes, "exceeds its nesting or node limit");
|
|
16484
16760
|
space();
|
|
16485
16761
|
const character = text2[at];
|
|
16486
16762
|
if (character === '"')
|
|
@@ -16494,17 +16770,17 @@ function parse7(text2) {
|
|
|
16494
16770
|
if (object6) {
|
|
16495
16771
|
space();
|
|
16496
16772
|
const key = string();
|
|
16497
|
-
|
|
16773
|
+
need7(!keys.has(key), "contains a duplicate JSON key");
|
|
16498
16774
|
keys.add(key);
|
|
16499
16775
|
space();
|
|
16500
|
-
|
|
16776
|
+
need7(text2[at++] === ":", "contains invalid JSON");
|
|
16501
16777
|
entries.push([key, value(depth + 1)]);
|
|
16502
16778
|
} else
|
|
16503
16779
|
items.push(value(depth + 1));
|
|
16504
16780
|
space();
|
|
16505
16781
|
if (text2[at] === end)
|
|
16506
16782
|
break;
|
|
16507
|
-
|
|
16783
|
+
need7(text2[at++] === ",", "contains invalid JSON");
|
|
16508
16784
|
}
|
|
16509
16785
|
at++;
|
|
16510
16786
|
return object6 ? { kind: "object", entries } : { kind: "array", items };
|
|
@@ -16516,73 +16792,73 @@ function parse7(text2) {
|
|
|
16516
16792
|
}
|
|
16517
16793
|
numberPattern.lastIndex = at;
|
|
16518
16794
|
const number = numberPattern.exec(text2);
|
|
16519
|
-
|
|
16795
|
+
need7(number, "contains invalid JSON");
|
|
16520
16796
|
at += number[0].length;
|
|
16521
16797
|
return { kind: "number", value: number[0] };
|
|
16522
16798
|
}
|
|
16523
16799
|
const root2 = value(0);
|
|
16524
16800
|
space();
|
|
16525
|
-
|
|
16526
|
-
|
|
16801
|
+
need7(at === text2.length && root2.kind === "object", "requires a JSON object without trailing content");
|
|
16802
|
+
need7(root2.entries.length <= CLAUDE_MARKETPLACE_REGISTRY_LIMITS.rows, "exceeds its marketplace row limit");
|
|
16527
16803
|
return root2;
|
|
16528
16804
|
}
|
|
16529
16805
|
function exactKeys(value, keys) {
|
|
16530
16806
|
return value?.kind === "object" && value.entries.length === keys.length && value.entries.every(([key]) => keys.includes(key));
|
|
16531
16807
|
}
|
|
16532
|
-
var
|
|
16808
|
+
var field2 = (object6, key) => object6.entries.find(([name]) => name === key)?.[1];
|
|
16533
16809
|
function textField(value) {
|
|
16534
|
-
|
|
16810
|
+
need7(value?.kind === "string" && value.value.length > 0 && !/[\x00-\x1f\x7f]/.test(value.value), "contains an invalid recognized field");
|
|
16535
16811
|
return value.value;
|
|
16536
16812
|
}
|
|
16537
16813
|
function normalizeRow(row, version = 1) {
|
|
16538
16814
|
if (!exactKeys(row, ["source", "installLocation", "lastUpdated"])) {
|
|
16539
16815
|
if (version !== 2 || !exactKeys(row, ["source", "installLocation", "lastUpdated", "autoUpdate"]))
|
|
16540
16816
|
return;
|
|
16541
|
-
const autoUpdate =
|
|
16542
|
-
|
|
16817
|
+
const autoUpdate = field2(row, "autoUpdate");
|
|
16818
|
+
need7(autoUpdate?.kind === "literal" && (autoUpdate.value === "true" || autoUpdate.value === "false"), "contains an invalid automatic-update preference");
|
|
16543
16819
|
}
|
|
16544
|
-
const source =
|
|
16820
|
+
const source = field2(row, "source");
|
|
16545
16821
|
if (source?.kind !== "object")
|
|
16546
16822
|
return;
|
|
16547
|
-
const type =
|
|
16823
|
+
const type = field2(source, "source");
|
|
16548
16824
|
if (type?.kind !== "string" || !["github", "directory"].includes(type.value))
|
|
16549
16825
|
return;
|
|
16550
16826
|
const location = type.value === "github" ? "repo" : "path";
|
|
16551
16827
|
if (!exactKeys(source, ["source", location]))
|
|
16552
16828
|
return;
|
|
16553
|
-
const sourceLocation = textField(
|
|
16829
|
+
const sourceLocation = textField(field2(source, location));
|
|
16554
16830
|
if (type.value === "directory")
|
|
16555
16831
|
absolutePath3(sourceLocation);
|
|
16556
|
-
absolutePath3(textField(
|
|
16557
|
-
const updated = textField(
|
|
16558
|
-
|
|
16832
|
+
absolutePath3(textField(field2(row, "installLocation")));
|
|
16833
|
+
const updated = textField(field2(row, "lastUpdated"));
|
|
16834
|
+
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
16835
|
const millis = Date.parse(updated);
|
|
16560
|
-
|
|
16836
|
+
need7(Number.isFinite(millis) && new Date(millis).toISOString() === updated, "contains an invalid recognized update timestamp");
|
|
16561
16837
|
row.entries = row.entries.map(([key, value]) => [key, key === "lastUpdated" ? { kind: "validated-update-time" } : value]);
|
|
16562
16838
|
}
|
|
16563
16839
|
function captureClaudeMarketplaceRegistry(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
16564
16840
|
const value = parse7(readRegistry2(path, budget2));
|
|
16565
16841
|
for (const [, row] of value.entries)
|
|
16566
16842
|
normalizeRow(row);
|
|
16567
|
-
const
|
|
16568
|
-
return { path, hashMode: "claude-marketplace-registry", sha256:
|
|
16843
|
+
const sha2563 = createHash23("sha256").update("hasna.skills.claude-marketplace-registry.v1\x00").update(JSON.stringify(value)).digest("hex");
|
|
16844
|
+
return { path, hashMode: "claude-marketplace-registry", sha256: sha2563 };
|
|
16569
16845
|
}
|
|
16570
16846
|
function captureClaudeMarketplaceRegistryV2(path, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
16571
16847
|
const value = parse7(readRegistry2(path, budget2));
|
|
16572
16848
|
for (const [, row] of value.entries)
|
|
16573
16849
|
normalizeRow(row, 2);
|
|
16574
|
-
const
|
|
16575
|
-
return { path, hashMode: "claude-marketplace-registry-v2", sha256:
|
|
16850
|
+
const sha2563 = createHash23("sha256").update("hasna.skills.claude-marketplace-registry.v2\x00").update(JSON.stringify(value)).digest("hex");
|
|
16851
|
+
return { path, hashMode: "claude-marketplace-registry-v2", sha256: sha2563 };
|
|
16576
16852
|
}
|
|
16577
16853
|
var events = { UserPromptSubmit: ["userPromptSubmit", "user_prompt_submit"], SessionStart: ["sessionStart", "session_start"], SubagentStart: ["subagentStart", "subagent_start"] };
|
|
16578
16854
|
var matchedEvents = { ...events, PreToolUse: ["preToolUse", "pre_tool_use"] };
|
|
16579
16855
|
var proofs = new WeakMap;
|
|
16580
|
-
var sha4 = (text2) =>
|
|
16856
|
+
var sha4 = (text2) => createHash24("sha256").update(text2).digest("hex");
|
|
16581
16857
|
var fields = [...CODEX_DISCOVERY_PROJECTION_FIELDS];
|
|
16582
16858
|
var proofs2 = new WeakMap;
|
|
16583
16859
|
function assertCodexHookDiscoveryRecovery(binding, witness) {
|
|
16584
16860
|
const proof = proofs2.get(witness);
|
|
16585
|
-
|
|
16861
|
+
need6(!!proof && binding.agent === "codex" && witness.discoverySha256 === sha4(JSON.stringify(binding)), "RECONCILE_DISCOVERY_RECOVERY_CHANGED");
|
|
16586
16862
|
unchanged2(proof.before);
|
|
16587
16863
|
unchanged2(proof.current);
|
|
16588
16864
|
proof.recheckAdditions();
|
|
@@ -16591,10 +16867,41 @@ function verifiesCodexHookDiscoverySource(binding, source, currentDigest, witnes
|
|
|
16591
16867
|
if (!witness || source.path !== witness.configPath || source.hashMode !== "bytes")
|
|
16592
16868
|
return false;
|
|
16593
16869
|
assertCodexHookDiscoveryRecovery(binding, witness);
|
|
16594
|
-
|
|
16870
|
+
need6(source.sha256 === witness.beforeSha256 && currentDigest === witness.currentSha256, "RECONCILE_DISCOVERY_RECOVERY_CHANGED");
|
|
16595
16871
|
return true;
|
|
16596
16872
|
}
|
|
16597
|
-
var
|
|
16873
|
+
var DISCOVERY_RUNTIME_COMMANDS = Object.freeze({ gemini: "gemini" });
|
|
16874
|
+
var DISCOVERY_ROOT_UNRESOLVED = "DISCOVERY_ROOT_UNRESOLVED";
|
|
16875
|
+
function discoveryRootUnresolved(agent, command, detail) {
|
|
16876
|
+
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.`);
|
|
16877
|
+
}
|
|
16878
|
+
function isDiscoveryRootUnresolved(error) {
|
|
16879
|
+
return error instanceof Error && error.message.startsWith(`${DISCOVERY_ROOT_UNRESOLVED}: `);
|
|
16880
|
+
}
|
|
16881
|
+
var quotedPath = (path) => JSON.stringify(path).replace(/[^\x20-\x7e]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
16882
|
+
var realpathOrNull = (path) => {
|
|
16883
|
+
try {
|
|
16884
|
+
return realpathSync11(path);
|
|
16885
|
+
} catch {
|
|
16886
|
+
return null;
|
|
16887
|
+
}
|
|
16888
|
+
};
|
|
16889
|
+
function discoveryExecutable(agent) {
|
|
16890
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[agent];
|
|
16891
|
+
const found = command ? Bun.which(command) : null;
|
|
16892
|
+
if (!command || !found)
|
|
16893
|
+
return null;
|
|
16894
|
+
const path = resolve20(found), target = realpathOrNull(path);
|
|
16895
|
+
return target === null ? null : { command, path, target };
|
|
16896
|
+
}
|
|
16897
|
+
function recordedDiscoveryExecutable(agent, recorded) {
|
|
16898
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[agent];
|
|
16899
|
+
if (!command || recorded.command !== command)
|
|
16900
|
+
throw new Error(`Recorded ${agent} discovery executable names another command`);
|
|
16901
|
+
const target = realpathOrNull(recorded.path);
|
|
16902
|
+
return target === null ? null : { command, path: recorded.path, target };
|
|
16903
|
+
}
|
|
16904
|
+
var digest = (text2) => createHash25("sha256").update(text2).digest("hex");
|
|
16598
16905
|
function parseConfig(text2, path, toml = false) {
|
|
16599
16906
|
try {
|
|
16600
16907
|
const value = toml ? Bun.TOML.parse(text2) : JSON.parse(text2);
|
|
@@ -16606,12 +16913,12 @@ function parseConfig(text2, path, toml = false) {
|
|
|
16606
16913
|
}
|
|
16607
16914
|
}
|
|
16608
16915
|
function safe4(path) {
|
|
16609
|
-
if (!
|
|
16916
|
+
if (!isAbsolute21(path) || path.includes("\x00"))
|
|
16610
16917
|
throw new Error("Expected an absolute native discovery path");
|
|
16611
|
-
for (let cursor = path;; cursor =
|
|
16612
|
-
if (
|
|
16918
|
+
for (let cursor = path;; cursor = dirname20(cursor)) {
|
|
16919
|
+
if (lstatSync25(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
16613
16920
|
throw new Error(`Refusing symlink native discovery input: ${cursor}`);
|
|
16614
|
-
if (
|
|
16921
|
+
if (dirname20(cursor) === cursor)
|
|
16615
16922
|
break;
|
|
16616
16923
|
}
|
|
16617
16924
|
}
|
|
@@ -16619,18 +16926,18 @@ function read2(path, changes) {
|
|
|
16619
16926
|
safe4(path);
|
|
16620
16927
|
if (changes?.has(path))
|
|
16621
16928
|
return changes.get(path);
|
|
16622
|
-
const stat2 =
|
|
16929
|
+
const stat2 = lstatSync25(path, { throwIfNoEntry: false });
|
|
16623
16930
|
if (!stat2)
|
|
16624
16931
|
return null;
|
|
16625
16932
|
if (!stat2.isFile() || stat2.size > 16 * 1024 * 1024)
|
|
16626
16933
|
throw new Error(`Unsupported or oversized native discovery input: ${path}`);
|
|
16627
|
-
return
|
|
16934
|
+
return readFileSync20(path, "utf8");
|
|
16628
16935
|
}
|
|
16629
16936
|
function projectNativeDiscoveryFields(text2, format, fields2, path) {
|
|
16630
16937
|
const object6 = format === "yaml" ? parseHermesConfig(text2) : parseConfig(text2, path, format === "toml");
|
|
16631
16938
|
if (!object6 || typeof object6 !== "object" || Array.isArray(object6))
|
|
16632
16939
|
throw new Error("Expected native discovery configuration object");
|
|
16633
|
-
return digest(JSON.stringify(Object.fromEntries(fields2.map((
|
|
16940
|
+
return digest(JSON.stringify(Object.fromEntries(fields2.map((field3) => [field3, object6[field3] ?? null]))));
|
|
16634
16941
|
}
|
|
16635
16942
|
function isSupersededSettingsProjection(agent, configPath, source) {
|
|
16636
16943
|
if (agent === "sumi")
|
|
@@ -16659,21 +16966,29 @@ function projected(source, changes, budget2 = discoveryByteBudget()) {
|
|
|
16659
16966
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16660
16967
|
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
16968
|
}
|
|
16662
|
-
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || source.hashMode === "claude-settings-v3") {
|
|
16969
|
+
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4")) {
|
|
16663
16970
|
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || typeof source.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(source.sha256))
|
|
16664
16971
|
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;
|
|
16972
|
+
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
16973
|
if (current2 !== source.sha256)
|
|
16667
16974
|
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;
|
|
16975
|
+
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
16976
|
}
|
|
16670
16977
|
if (source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2") {
|
|
16671
16978
|
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
16979
|
throw new Error("Claude marketplace witnesses require an exact reviewed registry without synthetic changes");
|
|
16673
|
-
const
|
|
16674
|
-
if (
|
|
16980
|
+
const sha2563 = (source.hashMode === "claude-marketplace-registry-v2" ? captureClaudeMarketplaceRegistryV2 : captureClaudeMarketplaceRegistry)(source.path, budget2).sha256;
|
|
16981
|
+
if (sha2563 !== source.sha256)
|
|
16982
|
+
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16983
|
+
return sha2563;
|
|
16984
|
+
}
|
|
16985
|
+
if (source.hashMode === "claude-marketplace-entry-v1") {
|
|
16986
|
+
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))
|
|
16987
|
+
throw new Error("Claude marketplace entry witnesses require an exact reviewed entry without synthetic changes");
|
|
16988
|
+
const sha2563 = captureClaudeMarketplaceEntry(source.path, source.marketplace, source.plugin, budget2).sha256;
|
|
16989
|
+
if (sha2563 !== source.sha256)
|
|
16675
16990
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16676
|
-
return
|
|
16991
|
+
return sha2563;
|
|
16677
16992
|
}
|
|
16678
16993
|
if (source.hashMode === "claude-plugin-registry") {
|
|
16679
16994
|
if (source.format !== undefined || source.fields !== undefined || !source.managedPlugins || changes?.has(source.path))
|
|
@@ -16710,9 +17025,9 @@ function absentCodexSkillRoots(binding) {
|
|
|
16710
17025
|
return [];
|
|
16711
17026
|
if (binding.agent !== "codex" || !Array.isArray(controls) || controls.length > 4096)
|
|
16712
17027
|
throw new Error("Invalid disabled Codex discovery proof");
|
|
16713
|
-
if (binding.method !== "reviewed" || controls.every((control) =>
|
|
17028
|
+
if (binding.method !== "reviewed" || controls.every((control) => lstatSync25(control.pluginParent, { throwIfNoEntry: false })))
|
|
16714
17029
|
return [];
|
|
16715
|
-
const cache =
|
|
17030
|
+
const cache = dirname20(dirname20(controls[0].pluginParent)), config = join32(dirname20(dirname20(cache)), "config.toml");
|
|
16716
17031
|
const source = binding.sources.find((source2) => source2.path === config && source2.sha256 !== null && source2.format === undefined && source2.fields === undefined);
|
|
16717
17032
|
if (!source || projected(source) !== source.sha256)
|
|
16718
17033
|
throw new Error("Missing current disabled Codex configuration witness");
|
|
@@ -16720,7 +17035,7 @@ function absentCodexSkillRoots(binding) {
|
|
|
16720
17035
|
return [...new Set(controls.map((control) => control.pluginParent))].filter((parent) => !codexDirectHookSelects(cache, parent) && absentDisabledCodexPluginParent(cache, parent, controls, rules));
|
|
16721
17036
|
}
|
|
16722
17037
|
function codexDirectHookSelects(cache, root2) {
|
|
16723
|
-
const codex =
|
|
17038
|
+
const codex = dirname20(dirname20(cache)), config = Bun.TOML.parse(read2(join32(codex, "config.toml")) ?? "");
|
|
16724
17039
|
const hooks = read2(join32(codex, "hooks.json"));
|
|
16725
17040
|
if (hooks !== null)
|
|
16726
17041
|
hashNativeJsonControls(hooks);
|
|
@@ -16733,7 +17048,7 @@ function retiredCodexRoots(binding) {
|
|
|
16733
17048
|
const controls = binding.codexDisabledPluginSkills;
|
|
16734
17049
|
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
17050
|
throw new Error("Invalid retired Codex materialization proof");
|
|
16736
|
-
const cache =
|
|
17051
|
+
const cache = dirname20(dirname20(controls[0].pluginParent)), config = join32(dirname20(dirname20(cache)), "config.toml");
|
|
16737
17052
|
const source = binding.sources.find((source2) => source2.path === config && source2.sha256 !== null && source2.format === undefined && source2.fields === undefined);
|
|
16738
17053
|
if (!source || projected(source) !== source.sha256)
|
|
16739
17054
|
throw new Error("Missing current retired Codex configuration witness");
|
|
@@ -16747,12 +17062,17 @@ function retiredCodexRoots(binding) {
|
|
|
16747
17062
|
}
|
|
16748
17063
|
return proof.roots;
|
|
16749
17064
|
}
|
|
17065
|
+
function retainableAbsentSource(source) {
|
|
17066
|
+
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined)
|
|
17067
|
+
return false;
|
|
17068
|
+
return [undefined, "bytes"].includes(source.hashMode) || source.hashMode === "claude-plugin-manifest-v1" && source.sha256 !== null && source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json"));
|
|
17069
|
+
}
|
|
16750
17070
|
function absentRetiredClaudeRoots(binding) {
|
|
16751
17071
|
if (binding.agent !== "claude" || binding.method !== "reviewed")
|
|
16752
17072
|
return [];
|
|
16753
17073
|
const result = new Set;
|
|
16754
17074
|
for (const source of binding.sources) {
|
|
16755
|
-
if (
|
|
17075
|
+
if (!retainableAbsentSource(source) || source.sha256 === null)
|
|
16756
17076
|
continue;
|
|
16757
17077
|
const marker = sep8 + ".claude" + sep8 + "plugins" + sep8 + "cache" + sep8, at = source.path.indexOf(marker);
|
|
16758
17078
|
if (at < 0 || source.path.indexOf(marker, at + 1) >= 0)
|
|
@@ -16762,9 +17082,9 @@ function absentRetiredClaudeRoots(binding) {
|
|
|
16762
17082
|
continue;
|
|
16763
17083
|
const root2 = join32(cache, ...parts.slice(0, 3));
|
|
16764
17084
|
safe4(root2);
|
|
16765
|
-
if (
|
|
17085
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16766
17086
|
continue;
|
|
16767
|
-
const claude =
|
|
17087
|
+
const claude = dirname20(dirname20(cache)), settings = join32(claude, "settings.json"), registry = join32(claude, "plugins/installed_plugins.json");
|
|
16768
17088
|
const full = (path) => binding.sources.find((item) => item.path === path && item.sha256 !== null && item.format === undefined && item.fields === undefined);
|
|
16769
17089
|
const configSource = full(settings), registrySource = full(registry);
|
|
16770
17090
|
if (!configSource || !registrySource || projected(configSource) !== configSource.sha256 || projected(registrySource) !== registrySource.sha256)
|
|
@@ -16777,17 +17097,41 @@ function absentRetiredClaudeRoots(binding) {
|
|
|
16777
17097
|
continue;
|
|
16778
17098
|
if (JSON.stringify(config.hooks ?? {}).includes(root2))
|
|
16779
17099
|
continue;
|
|
17100
|
+
const registrationScope = (row) => {
|
|
17101
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
17102
|
+
return null;
|
|
17103
|
+
const value = row;
|
|
17104
|
+
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)
|
|
17105
|
+
return null;
|
|
17106
|
+
if (value.scope === "user")
|
|
17107
|
+
return value.projectPath === undefined || value.projectPath === null ? "user\x00" : null;
|
|
17108
|
+
if (value.scope === "project")
|
|
17109
|
+
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;
|
|
17110
|
+
return null;
|
|
17111
|
+
};
|
|
17112
|
+
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))))
|
|
17113
|
+
continue;
|
|
16780
17114
|
const rows = installed.plugins[id];
|
|
16781
|
-
if (!Array.isArray(rows) || rows.length
|
|
17115
|
+
if (!Array.isArray(rows) || rows.length < 1)
|
|
16782
17116
|
continue;
|
|
16783
|
-
const
|
|
16784
|
-
|
|
17117
|
+
const targetScopes = new Set;
|
|
17118
|
+
let targetValid = true;
|
|
17119
|
+
for (const row of rows) {
|
|
17120
|
+
const scope = registrationScope(row), value = row;
|
|
17121
|
+
if (scope === null || targetScopes.has(scope) || value?.installPath !== rows[0]?.installPath || value?.version !== rows[0]?.version) {
|
|
17122
|
+
targetValid = false;
|
|
17123
|
+
break;
|
|
17124
|
+
}
|
|
17125
|
+
targetScopes.add(scope);
|
|
17126
|
+
}
|
|
17127
|
+
if (!targetValid || !targetScopes.has("user\x00"))
|
|
17128
|
+
continue;
|
|
17129
|
+
const active = rows[0]?.installPath;
|
|
17130
|
+
if (typeof active !== "string" || rows[0]?.version !== basename11(active) || dirname20(active) !== dirname20(root2) || active === root2 || !lstatSync25(active, { throwIfNoEntry: false })?.isDirectory() || realpathSync11(active) !== active)
|
|
16785
17131
|
continue;
|
|
16786
17132
|
const activeManifest = full(join32(active, ".claude-plugin/plugin.json"));
|
|
16787
17133
|
if (!activeManifest || projected(activeManifest) !== activeManifest.sha256)
|
|
16788
17134
|
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
17135
|
result.add(root2);
|
|
16792
17136
|
}
|
|
16793
17137
|
return [...result];
|
|
@@ -16812,7 +17156,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16812
17156
|
const projection = binding.codexRetiredMaterializations.directories;
|
|
16813
17157
|
if (projection.length !== ordinary.length || projection.some((item, index) => item.path !== ordinary[index]?.path))
|
|
16814
17158
|
throw new Error("Missing retired Codex directory projection");
|
|
16815
|
-
const omitted = [...retiredRoots, ...(binding.codexRetiredMaterializations.parents ?? []).filter((parent) => !
|
|
17159
|
+
const omitted = [...retiredRoots, ...(binding.codexRetiredMaterializations.parents ?? []).filter((parent) => !lstatSync25(parent, { throwIfNoEntry: false }))];
|
|
16816
17160
|
if (projection.every((item) => Array.isArray(item.entries)))
|
|
16817
17161
|
verifyDiscoveryDirectoryProjection(projection, omitted);
|
|
16818
17162
|
else {
|
|
@@ -16826,13 +17170,13 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16826
17170
|
verifyDiscoveryDirectories(ordinary);
|
|
16827
17171
|
verifyDiscoveryDirectories(projected2, installationRoots);
|
|
16828
17172
|
}
|
|
16829
|
-
const absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredRoots.filter((root2) => !
|
|
17173
|
+
const absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredRoots.filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
16830
17174
|
const budget2 = discoveryByteBudget();
|
|
16831
17175
|
for (const source of binding.sources) {
|
|
16832
17176
|
assertMarketplaceBinding(binding, source);
|
|
16833
17177
|
if (source.hashMode === "claude-plugin-registry" && binding.agent !== "claude")
|
|
16834
17178
|
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((
|
|
17179
|
+
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
17180
|
throw new Error("Invalid native discovery projection");
|
|
16837
17181
|
if (source.sha256 !== null && !/^[a-f0-9]{64}$/.test(source.sha256))
|
|
16838
17182
|
throw new Error("Invalid native discovery digest");
|
|
@@ -16840,7 +17184,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16840
17184
|
safe4(source.path);
|
|
16841
17185
|
continue;
|
|
16842
17186
|
}
|
|
16843
|
-
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
17187
|
+
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)) {
|
|
16844
17188
|
safe4(source.path);
|
|
16845
17189
|
continue;
|
|
16846
17190
|
}
|
|
@@ -16852,7 +17196,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
16852
17196
|
safe4(root2);
|
|
16853
17197
|
for (const root2 of absentRoots) {
|
|
16854
17198
|
safe4(root2);
|
|
16855
|
-
if (
|
|
17199
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16856
17200
|
throw new Error("Retired native materialization changed during discovery verification");
|
|
16857
17201
|
}
|
|
16858
17202
|
}
|
|
@@ -16860,15 +17204,15 @@ function codexInstallationRoots(binding) {
|
|
|
16860
17204
|
const proof = binding.codexInstallationInputs;
|
|
16861
17205
|
if (proof === undefined)
|
|
16862
17206
|
return [];
|
|
16863
|
-
if (binding.agent !== "codex" || binding.method !== "reviewed" || proof.version
|
|
17207
|
+
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
17208
|
throw new Error("Invalid native installation input proof");
|
|
16865
|
-
const cache =
|
|
16866
|
-
const config = join32(
|
|
17209
|
+
const cache = dirname20(dirname20(proof.plugins[0].pluginParent));
|
|
17210
|
+
const config = join32(dirname20(dirname20(cache)), "config.toml"), home = dirname20(dirname20(dirname20(cache)));
|
|
16867
17211
|
const configSource = binding.sources.find((source) => source.path === config && source.sha256 !== null && (!source.format || source.format === "toml" && source.fields?.includes("plugins")));
|
|
16868
17212
|
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) =>
|
|
17213
|
+
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
17214
|
throw new Error("Native installation input overlaps configuration or loading roots");
|
|
16871
|
-
if (proof.plugins.some((input) =>
|
|
17215
|
+
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
17216
|
throw new Error("Missing native installation input source witness");
|
|
16873
17217
|
return reviewedCodexPluginSourceRoots(cache, proof.plugins, (path) => {
|
|
16874
17218
|
const text2 = read2(path);
|
|
@@ -16878,40 +17222,42 @@ function codexInstallationRoots(binding) {
|
|
|
16878
17222
|
});
|
|
16879
17223
|
}
|
|
16880
17224
|
function assertMarketplaceBinding(binding, source) {
|
|
16881
|
-
if (source.hashMode === "claude-plugin-manifest-v1" && (binding.agent !== "claude" ||
|
|
17225
|
+
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
17226
|
throw new Error("Claude plugin manifest witnesses require Claude plugin discovery");
|
|
16883
|
-
if (source.hashMode === "sumi-settings-v1" && (binding.agent !== "sumi" || binding.method !== "reviewed" ||
|
|
17227
|
+
if (source.hashMode === "sumi-settings-v1" && (binding.agent !== "sumi" || binding.method !== "reviewed" || basename11(source.path) !== "sumi.json"))
|
|
16884
17228
|
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" ||
|
|
17229
|
+
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
17230
|
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" ||
|
|
17231
|
+
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
17232
|
throw new Error("Claude settings witnesses require explicit reviewed Claude configuration");
|
|
16889
17233
|
if ((source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2") && (binding.agent !== "claude" || binding.method !== "reviewed"))
|
|
16890
17234
|
throw new Error("Claude marketplace witnesses require explicit reviewed Claude discovery");
|
|
17235
|
+
if (source.hashMode === "claude-marketplace-entry-v1" && (binding.agent !== "claude" || binding.method !== "reviewed" || !claudeMarketplaceEntrySourceValid(source)))
|
|
17236
|
+
throw new Error("Claude marketplace entry witnesses require explicit reviewed Claude discovery of one named entry");
|
|
16891
17237
|
}
|
|
16892
17238
|
function rebindAgentDiscovery(binding, changes) {
|
|
16893
17239
|
const budget2 = discoveryByteBudget();
|
|
16894
|
-
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !
|
|
17240
|
+
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
16895
17241
|
const rebound = { ...binding, sources: binding.sources.map((source) => {
|
|
16896
17242
|
assertMarketplaceBinding(binding, source);
|
|
16897
|
-
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
17243
|
+
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)))
|
|
16898
17244
|
return source;
|
|
16899
|
-
const
|
|
16900
|
-
if (!changes.has(source.path) &&
|
|
17245
|
+
const sha2563 = projected(source, changes, budget2);
|
|
17246
|
+
if (!changes.has(source.path) && sha2563 !== source.sha256)
|
|
16901
17247
|
throw new Error(`Native discovery input changed; run skills hook install with a fresh discovery review: ${source.path}`);
|
|
16902
|
-
return { ...source, sha256:
|
|
17248
|
+
return { ...source, sha256: sha2563 };
|
|
16903
17249
|
}) };
|
|
16904
17250
|
for (const root2 of absentRoots) {
|
|
16905
17251
|
safe4(root2);
|
|
16906
|
-
if (
|
|
17252
|
+
if (lstatSync25(root2, { throwIfNoEntry: false }))
|
|
16907
17253
|
throw new Error("Retired native materialization changed during discovery rebinding");
|
|
16908
17254
|
}
|
|
16909
17255
|
return rebound;
|
|
16910
17256
|
}
|
|
16911
|
-
function assertProjectDiscovery(agent, directories, home,
|
|
16912
|
-
const homeConfigPath =
|
|
17257
|
+
function assertProjectDiscovery(agent, directories, home, canonical8 = resolve20, reviewed) {
|
|
17258
|
+
const homeConfigPath = canonical8(agentDiscoveryConfigPath(home, agent));
|
|
16913
17259
|
for (const directory of directories) {
|
|
16914
|
-
const isHome =
|
|
17260
|
+
const isHome = resolve20(directory) === resolve20(home);
|
|
16915
17261
|
if (agent === "hermes") {
|
|
16916
17262
|
assertHermesEnvironment(home);
|
|
16917
17263
|
continue;
|
|
@@ -16920,7 +17266,7 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16920
17266
|
continue;
|
|
16921
17267
|
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
17268
|
for (const suffix of paths) {
|
|
16923
|
-
const path =
|
|
17269
|
+
const path = canonical8(join32(directory, suffix)), raw = read2(path);
|
|
16924
17270
|
if (raw === null)
|
|
16925
17271
|
continue;
|
|
16926
17272
|
const isRootAliasedHomeConfig = agent === "claude" && suffix === ".claude/settings.json" || agent === "codex" && suffix === ".codex/config.toml";
|
|
@@ -16936,7 +17282,7 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16936
17282
|
const managed = reviewed.sources.flatMap((source) => source.hashMode === "claude-plugin-registry" ? source.managedPlugins ?? [] : []);
|
|
16937
17283
|
if (exact && projected(exact) === exact.sha256 && managed.length) {
|
|
16938
17284
|
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 ===
|
|
17285
|
+
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
17286
|
}
|
|
16941
17287
|
}
|
|
16942
17288
|
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 +17290,15 @@ function assertProjectDiscovery(agent, directories, home, canonical7 = resolve18
|
|
|
16944
17290
|
}
|
|
16945
17291
|
if (agent === "sumi")
|
|
16946
17292
|
for (const name of ["plugin", "plugins"]) {
|
|
16947
|
-
const path =
|
|
17293
|
+
const path = canonical8(join32(directory, ".sumi", name));
|
|
16948
17294
|
safe4(path);
|
|
16949
|
-
if (
|
|
17295
|
+
if (lstatSync25(path, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(path).length)
|
|
16950
17296
|
throw new Error(`NATIVE_SKILL_DRIFT: project Sumi plugins require a dedicated discovery review: ${path}`);
|
|
16951
17297
|
}
|
|
16952
17298
|
if (agent === "claude") {
|
|
16953
|
-
const commands =
|
|
17299
|
+
const commands = canonical8(join32(directory, ".claude/commands"));
|
|
16954
17300
|
safe4(commands);
|
|
16955
|
-
if (
|
|
17301
|
+
if (lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length)
|
|
16956
17302
|
throw new Error("NATIVE_SKILL_DRIFT: legacy project command discovery requires a dedicated format adapter");
|
|
16957
17303
|
}
|
|
16958
17304
|
}
|
|
@@ -16962,11 +17308,37 @@ function agentDiscoveryConfigPath(home, agent) {
|
|
|
16962
17308
|
return sumiConfigPath(home);
|
|
16963
17309
|
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
17310
|
}
|
|
17311
|
+
function verifyAutomaticDiscoveryClosure(binding, options) {
|
|
17312
|
+
const command = DISCOVERY_RUNTIME_COMMANDS[binding.agent], recorded = options.executable;
|
|
17313
|
+
const onPath = discoveryExecutable(binding.agent);
|
|
17314
|
+
let runtime, gap;
|
|
17315
|
+
if (recorded) {
|
|
17316
|
+
runtime = recordedDiscoveryExecutable(binding.agent, recorded);
|
|
17317
|
+
if (runtime && runtime.target !== recorded.target)
|
|
17318
|
+
throw new Error(`${options.change}: the recorded ${binding.agent} executable now resolves to ${quotedPath(runtime.target)}, not the reviewed ${quotedPath(recorded.target)}`);
|
|
17319
|
+
if (onPath && onPath.target !== recorded.target)
|
|
17320
|
+
throw new Error(`${options.change}: the "${command}" on this process's PATH resolves to ${quotedPath(onPath.target)}, not the reviewed ${quotedPath(recorded.target)}`);
|
|
17321
|
+
if (!runtime)
|
|
17322
|
+
gap = `the recorded executable ${quotedPath(recorded.path)} no longer resolves. Restore it, or review the change with skills hook install`;
|
|
17323
|
+
} else {
|
|
17324
|
+
runtime = onPath;
|
|
17325
|
+
if (!runtime)
|
|
17326
|
+
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";
|
|
17327
|
+
}
|
|
17328
|
+
const current2 = resolveAgentDiscovery({ home: options.home, agent: binding.agent, canonical: options.canonical, executable: runtime });
|
|
17329
|
+
if (JSON.stringify(current2) === JSON.stringify(binding))
|
|
17330
|
+
return;
|
|
17331
|
+
const reviewedWithRuntime = (binding.builtinNames?.length ?? 0) > 0 || binding.sources.some((source) => basename11(source.path) === "package.json");
|
|
17332
|
+
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)));
|
|
17333
|
+
if (command && gap && runtime === null && reviewedWithRuntime && otherwiseCurrent)
|
|
17334
|
+
throw discoveryRootUnresolved(binding.agent, command, gap);
|
|
17335
|
+
throw new Error(options.change);
|
|
17336
|
+
}
|
|
16965
17337
|
function resolveAgentDiscovery(options) {
|
|
16966
|
-
const
|
|
17338
|
+
const canonical8 = options.canonical ?? resolve20, home = resolve20(options.home), agent = options.agent;
|
|
16967
17339
|
const sources = [], roots = new Set, builtinNames = [];
|
|
16968
17340
|
const witness = (path, format, fields2, hashMode) => {
|
|
16969
|
-
const source = { path:
|
|
17341
|
+
const source = { path: canonical8(path), sha256: null, ...format ? { format, fields: fields2 } : {}, ...hashMode ? { hashMode } : {} };
|
|
16970
17342
|
source.sha256 = projected(source);
|
|
16971
17343
|
sources.push(source);
|
|
16972
17344
|
return read2(source.path);
|
|
@@ -16988,13 +17360,13 @@ function resolveAgentDiscovery(options) {
|
|
|
16988
17360
|
unresolved("JSONC configuration requires a supported format adapter");
|
|
16989
17361
|
for (const root2 of [directory, join32(home, ".claude"), join32(home, ".agents")])
|
|
16990
17362
|
for (const name of ["skill", "skills"])
|
|
16991
|
-
roots.add(
|
|
17363
|
+
roots.add(canonical8(join32(root2, name)));
|
|
16992
17364
|
if (config.skills !== undefined && (!Array.isArray(config.skills) || config.skills.some((path) => typeof path !== "string")))
|
|
16993
17365
|
unresolved("skills must be a string array");
|
|
16994
17366
|
for (const value of config.skills ?? []) {
|
|
16995
|
-
if (typeof value !== "string" || /[\0$]/.test(value) || !value || !(
|
|
17367
|
+
if (typeof value !== "string" || /[\0$]/.test(value) || !value || !(isAbsolute21(value) || value.startsWith("~/")))
|
|
16996
17368
|
unresolved("remote or relative skill sources need a dedicated discovery adapter");
|
|
16997
|
-
roots.add(
|
|
17369
|
+
roots.add(canonical8(value.startsWith("~/") ? join32(home, value.slice(2)) : value));
|
|
16998
17370
|
}
|
|
16999
17371
|
for (const key of ["plugin", "plugins"])
|
|
17000
17372
|
if (config[key] !== undefined && !Array.isArray(config[key]))
|
|
@@ -17002,19 +17374,19 @@ function resolveAgentDiscovery(options) {
|
|
|
17002
17374
|
const plugins = [join32(directory, "plugin"), join32(directory, "plugins")];
|
|
17003
17375
|
for (const path of plugins) {
|
|
17004
17376
|
safe4(path);
|
|
17005
|
-
if (
|
|
17377
|
+
if (lstatSync25(path, { throwIfNoEntry: false })?.isDirectory())
|
|
17006
17378
|
for (const name of readdirSync10(path).sort()) {
|
|
17007
17379
|
if (name === "skills-cli.js" && path === plugins[1])
|
|
17008
17380
|
continue;
|
|
17009
17381
|
const target = join32(path, name);
|
|
17010
|
-
if (!
|
|
17382
|
+
if (!lstatSync25(target).isFile())
|
|
17011
17383
|
unresolved("local plugin packages need a dedicated discovery adapter");
|
|
17012
17384
|
witness(target);
|
|
17013
17385
|
}
|
|
17014
17386
|
}
|
|
17015
17387
|
for (const root2 of roots) {
|
|
17016
17388
|
safe4(root2);
|
|
17017
|
-
if (
|
|
17389
|
+
if (lstatSync25(root2, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(root2).some((name) => name.endsWith(".md")))
|
|
17018
17390
|
unresolved("flat markdown skills require a dedicated native migration adapter");
|
|
17019
17391
|
}
|
|
17020
17392
|
}
|
|
@@ -17033,30 +17405,30 @@ function resolveAgentDiscovery(options) {
|
|
|
17033
17405
|
continue;
|
|
17034
17406
|
if (normalized.startsWith("~") && normalized !== "~" && !normalized.startsWith("~/"))
|
|
17035
17407
|
unresolved("user-specific tilde expansion requires a separate discovery adapter");
|
|
17036
|
-
const path = normalized === "~" ? home : normalized.startsWith("~/") ? join32(home, normalized.slice(2)) :
|
|
17408
|
+
const path = normalized === "~" ? home : normalized.startsWith("~/") ? join32(home, normalized.slice(2)) : resolve20(home, ".hermes", normalized);
|
|
17037
17409
|
safe4(path);
|
|
17038
17410
|
roots.add(path);
|
|
17039
17411
|
}
|
|
17040
17412
|
}
|
|
17041
17413
|
if (agent === "gemini") {
|
|
17042
|
-
const executable2 =
|
|
17414
|
+
const executable2 = options.executable === undefined ? discoveryExecutable(agent) : options.executable;
|
|
17043
17415
|
if (executable2) {
|
|
17044
17416
|
let packageRoot;
|
|
17045
|
-
for (let directory =
|
|
17417
|
+
for (let directory = dirname20(executable2.target), depth = 0;depth < 8; directory = dirname20(directory), depth++) {
|
|
17046
17418
|
const path = join32(directory, "package.json"), raw = read2(path);
|
|
17047
17419
|
if (raw !== null && parseConfig(raw, path).name === "@google/gemini-cli") {
|
|
17048
17420
|
packageRoot = directory;
|
|
17049
17421
|
witness(path);
|
|
17050
17422
|
break;
|
|
17051
17423
|
}
|
|
17052
|
-
if (
|
|
17424
|
+
if (dirname20(directory) === directory)
|
|
17053
17425
|
break;
|
|
17054
17426
|
}
|
|
17055
17427
|
if (!packageRoot)
|
|
17056
17428
|
unresolved("installed Gemini package layout is not recognized");
|
|
17057
17429
|
const builtinRoot = join32(packageRoot, "bundle/builtin");
|
|
17058
17430
|
safe4(builtinRoot);
|
|
17059
|
-
if (!
|
|
17431
|
+
if (!lstatSync25(builtinRoot, { throwIfNoEntry: false })?.isDirectory())
|
|
17060
17432
|
unresolved("installed Gemini builtin root is missing");
|
|
17061
17433
|
for (const name of readdirSync10(builtinRoot).sort()) {
|
|
17062
17434
|
const text2 = witness(join32(builtinRoot, name, "SKILL.md"));
|
|
@@ -17072,11 +17444,11 @@ function resolveAgentDiscovery(options) {
|
|
|
17072
17444
|
if (retained.agent !== agent || retained.method !== "reviewed")
|
|
17073
17445
|
unresolved("invalid retained review");
|
|
17074
17446
|
verifyAgentDiscovery(retained);
|
|
17075
|
-
if (!retained.sources.some((source) => source.path ===
|
|
17447
|
+
if (!retained.sources.some((source) => source.path === canonical8(configPath) && source.format === undefined && source.fields === undefined))
|
|
17076
17448
|
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 !==
|
|
17449
|
+
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
17450
|
unresolved("retained settings witness names another configuration source");
|
|
17079
|
-
const covered = supersedesSettingsProjection(agent, retained.sources,
|
|
17451
|
+
const covered = supersedesSettingsProjection(agent, retained.sources, canonical8(configPath)) ? sources.filter((source) => !isSupersededSettingsProjection(agent, canonical8(configPath), source)) : sources;
|
|
17080
17452
|
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
17453
|
unresolved("retained review is missing current runtime discovery coverage");
|
|
17082
17454
|
return retained;
|
|
@@ -17088,16 +17460,16 @@ function resolveAgentDiscovery(options) {
|
|
|
17088
17460
|
if (review.sources.some((source) => source.format !== undefined || source.fields !== undefined))
|
|
17089
17461
|
throw new Error("Explicit discovery reviews require full source-file hashes");
|
|
17090
17462
|
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 !==
|
|
17463
|
+
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
17464
|
throw new Error("Semantic settings witnesses must name the configured agent configuration source");
|
|
17093
|
-
if (!review.sources.some((source) => source.path ===
|
|
17465
|
+
if (!review.sources.some((source) => source.path === canonical8(configPath)))
|
|
17094
17466
|
throw new Error("Discovery review must include the agent configuration source");
|
|
17095
|
-
const reviewedSources = supersedesSettingsProjection(agent, review.sources,
|
|
17467
|
+
const reviewedSources = supersedesSettingsProjection(agent, review.sources, canonical8(configPath)) ? sources.filter((source) => !isSupersededSettingsProjection(agent, canonical8(configPath), source)) : sources;
|
|
17096
17468
|
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" ||
|
|
17469
|
+
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
17470
|
return source;
|
|
17099
|
-
const pluginRoot =
|
|
17100
|
-
const hookStat =
|
|
17471
|
+
const pluginRoot = dirname20(dirname20(source.path)), hooksPath = join32(pluginRoot, "hooks/hooks.json");
|
|
17472
|
+
const hookStat = lstatSync25(hooksPath, { throwIfNoEntry: false });
|
|
17101
17473
|
const text2 = read2(source.path);
|
|
17102
17474
|
if (text2 === null)
|
|
17103
17475
|
throw new Error("Reviewed Claude plugin manifest is missing");
|
|
@@ -17111,13 +17483,13 @@ function resolveAgentDiscovery(options) {
|
|
|
17111
17483
|
if (manifest.hooks !== undefined) {
|
|
17112
17484
|
if (typeof manifest.hooks !== "string")
|
|
17113
17485
|
throw new Error("Reviewed Claude plugin manifest has an unsupported hooks target");
|
|
17114
|
-
const declaredHookPath =
|
|
17486
|
+
const declaredHookPath = resolve20(pluginRoot, manifest.hooks);
|
|
17115
17487
|
if (!declaredHookPath.startsWith(pluginRoot + sep8))
|
|
17116
17488
|
throw new Error("Reviewed Claude plugin hooks target escapes its root");
|
|
17117
17489
|
reviewedHookPaths.add(declaredHookPath);
|
|
17118
17490
|
}
|
|
17119
17491
|
for (const hooksFile of reviewedHookPaths)
|
|
17120
|
-
if (!review.sources.some((hook) => hook.path ===
|
|
17492
|
+
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
17493
|
throw new Error("Reviewed Claude plugin manifest requires separately reviewed exact hook file sources");
|
|
17122
17494
|
return { path: source.path, sha256: manifestSha256, hashMode: "claude-plugin-manifest-v1" };
|
|
17123
17495
|
});
|
|
@@ -17126,7 +17498,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17126
17498
|
return { ...supplied, roots: [...new Set([...roots, ...supplied.roots])].sort(), sources: unique, ...agent === "gemini" ? { builtinNames } : {} };
|
|
17127
17499
|
}
|
|
17128
17500
|
function plugin(root2) {
|
|
17129
|
-
root2 =
|
|
17501
|
+
root2 = canonical8(root2);
|
|
17130
17502
|
safe4(root2);
|
|
17131
17503
|
const manifestPath = join32(root2, agent === "claude" ? ".claude-plugin/plugin.json" : ".codex-plugin/plugin.json");
|
|
17132
17504
|
const raw = witness(manifestPath, undefined, undefined, agent === "claude" ? "claude-plugin-manifest-v1" : undefined);
|
|
@@ -17138,7 +17510,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17138
17510
|
unresolved("plugin hooks require a separate no-skill-injection review");
|
|
17139
17511
|
const commands = join32(root2, "commands");
|
|
17140
17512
|
safe4(commands);
|
|
17141
|
-
if (agent === "claude" && (manifest.commands !== undefined ||
|
|
17513
|
+
if (agent === "claude" && (manifest.commands !== undefined || lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length))
|
|
17142
17514
|
unresolved("legacy command discovery requires retirement or a dedicated format adapter");
|
|
17143
17515
|
const rootSkill = witness(join32(root2, "SKILL.md"));
|
|
17144
17516
|
if (rootSkill !== null)
|
|
@@ -17149,18 +17521,18 @@ function resolveAgentDiscovery(options) {
|
|
|
17149
17521
|
if (agent === "claude")
|
|
17150
17522
|
roots.add(join32(root2, "skills"));
|
|
17151
17523
|
for (const value of declared) {
|
|
17152
|
-
const path =
|
|
17524
|
+
const path = resolve20(root2, value);
|
|
17153
17525
|
if (path !== root2 && !path.startsWith(root2 + sep8))
|
|
17154
17526
|
unresolved("plugin skill path escapes its root");
|
|
17155
|
-
roots.add(path.endsWith(`${sep8}SKILL.md`) ?
|
|
17527
|
+
roots.add(path.endsWith(`${sep8}SKILL.md`) ? dirname20(path) : path);
|
|
17156
17528
|
}
|
|
17157
17529
|
}
|
|
17158
17530
|
if (agent === "claude") {
|
|
17159
17531
|
const registrations = witness(join32(home, ".claude/plugins/installed_plugins.json"));
|
|
17160
17532
|
const installed = registrations === null ? {} : parseConfig(registrations, join32(home, ".claude/plugins/installed_plugins.json")).plugins;
|
|
17161
|
-
const commands =
|
|
17533
|
+
const commands = canonical8(join32(home, ".claude/commands"));
|
|
17162
17534
|
safe4(commands);
|
|
17163
|
-
if (
|
|
17535
|
+
if (lstatSync25(commands, { throwIfNoEntry: false })?.isDirectory() && readdirSync10(commands).length)
|
|
17164
17536
|
unresolved("legacy home command discovery requires a dedicated format adapter");
|
|
17165
17537
|
for (const [id, enabled] of Object.entries(config.enabledPlugins ?? {})) {
|
|
17166
17538
|
if (enabled === false)
|
|
@@ -17180,7 +17552,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17180
17552
|
unresolved("unsupported plugin enablement");
|
|
17181
17553
|
const split = id.lastIndexOf("@"), name = id.slice(0, split), marketplace = id.slice(split + 1);
|
|
17182
17554
|
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" || !
|
|
17555
|
+
if (split < 1 || market?.source_type !== "local" || typeof market.source !== "string" || !isAbsolute21(market.source))
|
|
17184
17556
|
unresolved("enabled plugin marketplace is not an explicit local source");
|
|
17185
17557
|
const catalogText = witness(join32(market.source, ".agents/plugins/marketplace.json"));
|
|
17186
17558
|
if (catalogText === null)
|
|
@@ -17188,7 +17560,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17188
17560
|
const catalog = parseConfig(catalogText, join32(market.source, ".agents/plugins/marketplace.json")), matches = Array.isArray(catalog.plugins) ? catalog.plugins.filter((item) => item.name === name) : [];
|
|
17189
17561
|
if (matches.length !== 1 || matches[0]?.source?.source !== "local" || typeof matches[0]?.source?.path !== "string")
|
|
17190
17562
|
unresolved("plugin catalog source is missing or ambiguous");
|
|
17191
|
-
plugin(
|
|
17563
|
+
plugin(resolve20(market.source, matches[0].source.path));
|
|
17192
17564
|
}
|
|
17193
17565
|
} else if (agent === "opencode") {
|
|
17194
17566
|
if (witness(join32(home, ".config/opencode/opencode.jsonc")) !== null || witness(join32(home, ".config/opencode/config.json")) !== null)
|
|
@@ -17196,21 +17568,21 @@ function resolveAgentDiscovery(options) {
|
|
|
17196
17568
|
if ((config.plugin?.length ?? 0) > 0 || config.skills?.urls?.length)
|
|
17197
17569
|
unresolved("external plugin or remote skill source");
|
|
17198
17570
|
for (const path of config.skills?.paths ?? []) {
|
|
17199
|
-
if (typeof path !== "string" || !
|
|
17571
|
+
if (typeof path !== "string" || !isAbsolute21(path))
|
|
17200
17572
|
unresolved("relative or malformed added skill root");
|
|
17201
17573
|
roots.add(path);
|
|
17202
17574
|
}
|
|
17203
17575
|
const localPlugins = join32(home, ".config/opencode/plugins");
|
|
17204
17576
|
safe4(localPlugins);
|
|
17205
|
-
if (
|
|
17577
|
+
if (lstatSync25(localPlugins, { throwIfNoEntry: false }) && readdirSync10(localPlugins).some((name) => name !== "skills-cli.js"))
|
|
17206
17578
|
unresolved("additional local plugin hooks require review");
|
|
17207
17579
|
} else if (agent === "sumi") {
|
|
17208
|
-
if ((config.plugin?.length ?? 0) > 0 || (config.plugins?.length ?? 0) > 0 || sources.some((source) => source.path !==
|
|
17580
|
+
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
17581
|
unresolved("external or foreign local plugins require review");
|
|
17210
17582
|
} else if (agent === "hermes") {
|
|
17211
17583
|
for (const directory of [join32(home, ".hermes/plugins"), join32(home, ".hermes/hermes-agent")]) {
|
|
17212
17584
|
safe4(directory);
|
|
17213
|
-
if (
|
|
17585
|
+
if (lstatSync25(directory, { throwIfNoEntry: false }))
|
|
17214
17586
|
unresolved("installed runtime/plugin discovery requires reviewed source bindings");
|
|
17215
17587
|
}
|
|
17216
17588
|
if (Bun.which("hermes") || Object.keys(config.plugins ?? {}).length)
|
|
@@ -17220,11 +17592,11 @@ function resolveAgentDiscovery(options) {
|
|
|
17220
17592
|
unresolved("custom extension or skill paths");
|
|
17221
17593
|
const directory = join32(home, ".gemini/extensions");
|
|
17222
17594
|
safe4(directory);
|
|
17223
|
-
if (
|
|
17595
|
+
if (lstatSync25(directory, { throwIfNoEntry: false }))
|
|
17224
17596
|
for (const name of readdirSync10(directory)) {
|
|
17225
17597
|
const root2 = join32(directory, name);
|
|
17226
17598
|
safe4(root2);
|
|
17227
|
-
if (!
|
|
17599
|
+
if (!lstatSync25(root2)?.isDirectory())
|
|
17228
17600
|
continue;
|
|
17229
17601
|
const raw = witness(join32(root2, "gemini-extension.json"));
|
|
17230
17602
|
if (raw === null)
|
|
@@ -17235,7 +17607,7 @@ function resolveAgentDiscovery(options) {
|
|
|
17235
17607
|
roots.add(join32(root2, "skills"));
|
|
17236
17608
|
}
|
|
17237
17609
|
}
|
|
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) =>
|
|
17610
|
+
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
17611
|
}
|
|
17240
17612
|
var NATIVE_DISCOVERY_ROOTS = NATIVE_SKILL_ROOTS.map(([, path]) => path.split("/"));
|
|
17241
17613
|
var OFFICIAL_SKILL_NAMES = new Set(SKILLS.map((skill) => skill.name));
|
|
@@ -20686,14 +21058,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
20686
21058
|
const shape = zod.def.shape;
|
|
20687
21059
|
const propValues = {};
|
|
20688
21060
|
for (const key in shape) {
|
|
20689
|
-
const
|
|
20690
|
-
if (
|
|
21061
|
+
const field3 = shape[key]._zod;
|
|
21062
|
+
if (field3.values) {
|
|
20691
21063
|
if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
|
|
20692
21064
|
assignProp(propValues, key, new Set);
|
|
20693
21065
|
}
|
|
20694
|
-
for (const v of
|
|
21066
|
+
for (const v of field3.values)
|
|
20695
21067
|
propValues[key].add(v);
|
|
20696
|
-
if (
|
|
21068
|
+
if (field3.optin !== undefined)
|
|
20697
21069
|
propValues[key].add(undefined);
|
|
20698
21070
|
}
|
|
20699
21071
|
}
|
|
@@ -22106,8 +22478,8 @@ function isRecursive(inst, stack) {
|
|
|
22106
22478
|
return true;
|
|
22107
22479
|
stack.add(inst);
|
|
22108
22480
|
let result = false;
|
|
22109
|
-
const check = (
|
|
22110
|
-
if (!result &&
|
|
22481
|
+
const check = (child2) => {
|
|
22482
|
+
if (!result && child2?._zod && isRecursive(child2, stack))
|
|
22111
22483
|
result = true;
|
|
22112
22484
|
};
|
|
22113
22485
|
const def = inst._zod.def;
|
|
@@ -32815,11 +33187,11 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
32815
33187
|
}
|
|
32816
33188
|
const allKeys = new Set(Object.keys(shape));
|
|
32817
33189
|
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
32818
|
-
const
|
|
33190
|
+
const field3 = def.shape[key];
|
|
32819
33191
|
if (ctx.io === "input") {
|
|
32820
|
-
return inputOptin(
|
|
33192
|
+
return inputOptin(field3) === undefined;
|
|
32821
33193
|
} else {
|
|
32822
|
-
return
|
|
33194
|
+
return field3._zod.optout === undefined;
|
|
32823
33195
|
}
|
|
32824
33196
|
}));
|
|
32825
33197
|
if (requiredKeys.size > 0) {
|
|
@@ -36213,7 +36585,7 @@ var hash3 = (v) => typeof v === "string" && /^[a-f0-9]{64}$/.test(v);
|
|
|
36213
36585
|
var record9 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
36214
36586
|
var exact = (v, keys) => record9(v) && Object.keys(v).sort().join(",") === keys.sort().join(",");
|
|
36215
36587
|
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) =>
|
|
36588
|
+
var publicationSha256 = (bytes) => createHash29("sha256").update(bytes).digest("hex");
|
|
36217
36589
|
function checkedPublicationDeclaration(value) {
|
|
36218
36590
|
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
36591
|
return bad();
|
|
@@ -36458,12 +36830,12 @@ class RemotePrivatePublicationsClient {
|
|
|
36458
36830
|
previous = view;
|
|
36459
36831
|
if (!["queued", "verifying"].includes(view.state) || Date.now() >= until)
|
|
36460
36832
|
return view;
|
|
36461
|
-
await new Promise((
|
|
36833
|
+
await new Promise((resolve23) => {
|
|
36462
36834
|
const timer = setTimeout(done, Math.min(1000, until - Date.now()));
|
|
36463
36835
|
function done() {
|
|
36464
36836
|
clearTimeout(timer);
|
|
36465
36837
|
options.signal?.removeEventListener("abort", done);
|
|
36466
|
-
|
|
36838
|
+
resolve23();
|
|
36467
36839
|
}
|
|
36468
36840
|
options.signal?.addEventListener("abort", done, { once: true });
|
|
36469
36841
|
});
|
|
@@ -36499,7 +36871,7 @@ var stateSchema = exports_external.object({
|
|
|
36499
36871
|
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
36872
|
var context = { userId: uuid13.optional(), membershipId: uuid13.optional() };
|
|
36501
36873
|
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(
|
|
36874
|
+
var directory = exports_external.string().max(4096).refine(isAbsolute23, "Use an absolute recovery directory");
|
|
36503
36875
|
var email4 = exports_external.string().trim().toLowerCase().email().max(254);
|
|
36504
36876
|
var code = exports_external.string().regex(/^\d{6}$/);
|
|
36505
36877
|
var recurringSurfaceSchemas = {
|
|
@@ -37628,6 +38000,8 @@ var STATION_SNAPSHOT_PRODUCER = { name: "@hasna/skills", version: package_defaul
|
|
|
37628
38000
|
var STATION_HYDRATION_PRODUCER = { name: "@hasna/skills", version: package_default.version };
|
|
37629
38001
|
var MANIFEST_HASH_KEY_SEP = String.fromCharCode(0);
|
|
37630
38002
|
var SESSION_RECONCILIATION_PLAN_TTL_MS = 5 * 60 * 1000;
|
|
38003
|
+
var SESSION_RENEWAL_REFUSAL_TTL_MS = 5 * 60 * 1000;
|
|
38004
|
+
var SESSION_RENEWAL_REFUSAL_MAX_BYTES = 4 * 1024;
|
|
37631
38005
|
|
|
37632
38006
|
// src/lib/claude-skills-coordination.ts
|
|
37633
38007
|
class ClaudeSettingsRefusal extends Error {
|
|
@@ -37667,7 +38041,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
37667
38041
|
function skillsPolicyLocations(dataDir3) {
|
|
37668
38042
|
const state = (path) => existsSync11(path) ? "present" : "absent";
|
|
37669
38043
|
if (dataDir3 !== undefined)
|
|
37670
|
-
return [`${join11(
|
|
38044
|
+
return [`${join11(resolve9(dataDir3), "agent-policy.json")} (explicit data directory, absent)`];
|
|
37671
38045
|
const env = process.env, home = env.HOME || env.USERPROFILE || homedir6() || "/tmp", searched = [];
|
|
37672
38046
|
let selected = false;
|
|
37673
38047
|
for (const key of ["HASNA_SKILLS_DIR", "HASNA_SKILLS_HOME", "SKILLS_HOME"]) {
|
|
@@ -37678,7 +38052,7 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
37678
38052
|
searched.push(`$${key} (unset)`);
|
|
37679
38053
|
else {
|
|
37680
38054
|
selected = true;
|
|
37681
|
-
searched.push(`$${key} -> ${join11(
|
|
38055
|
+
searched.push(`$${key} -> ${join11(resolve9(value), "agent-policy.json")} (selected, absent)`);
|
|
37682
38056
|
}
|
|
37683
38057
|
}
|
|
37684
38058
|
const override = env.HASNA_DATA_HOME;
|
|
@@ -37704,7 +38078,7 @@ function planCoordinatedClaudeSettings(before, replacement, options) {
|
|
|
37704
38078
|
const plan = planClaudeHookEventsUpdate({
|
|
37705
38079
|
...options,
|
|
37706
38080
|
events: selected,
|
|
37707
|
-
expectedSettingsSha256: before === null ? "absent" :
|
|
38081
|
+
expectedSettingsSha256: before === null ? "absent" : createHash9("sha256").update(before).digest("hex"),
|
|
37708
38082
|
replacement
|
|
37709
38083
|
});
|
|
37710
38084
|
if (!plan) {
|
|
@@ -37724,7 +38098,7 @@ function coordinateClaudeSettings(before, replacement, options, beforeWrite) {
|
|
|
37724
38098
|
}
|
|
37725
38099
|
|
|
37726
38100
|
// src/lib/installer.ts
|
|
37727
|
-
var __dirname2 =
|
|
38101
|
+
var __dirname2 = dirname9(fileURLToPath3(import.meta.url));
|
|
37728
38102
|
var HOOKS_DIR = existsSync12(join12(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join12(__dirname2, "..", "..", "hooks") : join12(__dirname2, "..", "hooks");
|
|
37729
38103
|
function normalizeHookName(name) {
|
|
37730
38104
|
return name.startsWith("hook-") ? name : `hook-${name}`;
|
|
@@ -37795,9 +38169,9 @@ function getTargetSettingsDir(target) {
|
|
|
37795
38169
|
}
|
|
37796
38170
|
function getGlobalSettingsPathOverride(target) {
|
|
37797
38171
|
if (target === "codex")
|
|
37798
|
-
return process.env.HASNA_HOOKS_CODEX_SETTINGS_PATH ?? (process.env.CODEX_HOME ?
|
|
38172
|
+
return process.env.HASNA_HOOKS_CODEX_SETTINGS_PATH ?? (process.env.CODEX_HOME ? resolve21(process.env.CODEX_HOME, "hooks.json") : undefined);
|
|
37799
38173
|
if (target === "claude")
|
|
37800
|
-
return process.env.HASNA_HOOKS_CLAUDE_SETTINGS_PATH ?? (process.env.CLAUDE_CONFIG_DIR ?
|
|
38174
|
+
return process.env.HASNA_HOOKS_CLAUDE_SETTINGS_PATH ?? (process.env.CLAUDE_CONFIG_DIR ? resolve21(process.env.CLAUDE_CONFIG_DIR, "settings.json") : undefined);
|
|
37801
38175
|
if (target === "gemini")
|
|
37802
38176
|
return process.env.HASNA_HOOKS_GEMINI_SETTINGS_PATH;
|
|
37803
38177
|
return;
|
|
@@ -37835,29 +38209,29 @@ function readSettings(scope = "global", target = "claude") {
|
|
|
37835
38209
|
const path = getSettingsPath(scope, target);
|
|
37836
38210
|
if (target === "codex")
|
|
37837
38211
|
return readCodexSettings(path);
|
|
37838
|
-
let
|
|
38212
|
+
let reason2 = "cannot be read";
|
|
37839
38213
|
try {
|
|
37840
38214
|
if (existsSync12(path)) {
|
|
37841
38215
|
const text3 = readFileSync8(path, "utf-8");
|
|
37842
|
-
|
|
38216
|
+
reason2 = "is not valid JSON";
|
|
37843
38217
|
const value = JSON.parse(text3);
|
|
37844
|
-
|
|
38218
|
+
reason2 = "does not hold a JSON object";
|
|
37845
38219
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
37846
|
-
throw new TypeError(
|
|
38220
|
+
throw new TypeError(reason2);
|
|
37847
38221
|
settingsPreimages.set(value, { path, text: text3 });
|
|
37848
38222
|
return value;
|
|
37849
38223
|
}
|
|
37850
38224
|
} catch (error61) {
|
|
37851
38225
|
const code2 = error61?.code;
|
|
37852
|
-
if (
|
|
37853
|
-
|
|
38226
|
+
if (reason2 === "cannot be read" && typeof code2 === "string")
|
|
38227
|
+
reason2 += ` (${code2})`;
|
|
37854
38228
|
console.warn("[hooks] Cannot read hook settings; repair the selected file before installation.");
|
|
37855
38229
|
}
|
|
37856
38230
|
const empty = {};
|
|
37857
38231
|
if (!existsSync12(path))
|
|
37858
38232
|
settingsPreimages.set(empty, { path, text: null });
|
|
37859
38233
|
else
|
|
37860
|
-
unreadableSettings.set(empty, { path, reason });
|
|
38234
|
+
unreadableSettings.set(empty, { path, reason: reason2 });
|
|
37861
38235
|
return empty;
|
|
37862
38236
|
}
|
|
37863
38237
|
function unreadableSettingsRefusal(settings, path) {
|
|
@@ -37865,13 +38239,13 @@ function unreadableSettingsRefusal(settings, path) {
|
|
|
37865
38239
|
if (captured?.path === path && captured.text !== null || !existsSync12(path))
|
|
37866
38240
|
return;
|
|
37867
38241
|
const failed = unreadableSettings.get(settings);
|
|
37868
|
-
const
|
|
37869
|
-
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${
|
|
38242
|
+
const reason2 = captured?.path === path ? "was created after Hooks read the settings" : failed?.path === path ? failed.reason : "was not read as a settings object";
|
|
38243
|
+
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${reason2}, so Hooks wrote nothing. Repair the file or move it aside, then retry.`);
|
|
37870
38244
|
}
|
|
37871
38245
|
function settingsIdentity(path) {
|
|
37872
38246
|
if (existsSync12(path))
|
|
37873
|
-
return
|
|
37874
|
-
return existsSync12(
|
|
38247
|
+
return realpathSync9(path);
|
|
38248
|
+
return existsSync12(dirname9(path)) ? join12(realpathSync9(dirname9(path)), basename5(path)) : resolve21(path);
|
|
37875
38249
|
}
|
|
37876
38250
|
function coordinatesWithSkills(path, target) {
|
|
37877
38251
|
return target === "claude" && settingsIdentity(path) === settingsIdentity(join12(homedir7(), ".claude/settings.json"));
|
|
@@ -37906,7 +38280,7 @@ function writeSettings(settings, scope = "global", target = "claude", expectedSe
|
|
|
37906
38280
|
if (expectedSettingsSha256 !== undefined)
|
|
37907
38281
|
return writeHookSettingsPreimage(path, settings, captured.text, beforeWrite);
|
|
37908
38282
|
beforeWrite?.();
|
|
37909
|
-
const dir =
|
|
38283
|
+
const dir = dirname9(path);
|
|
37910
38284
|
if (!existsSync12(dir)) {
|
|
37911
38285
|
mkdirSync7(dir, { recursive: true });
|
|
37912
38286
|
}
|
|
@@ -38013,7 +38387,7 @@ function readCodewithConfig(scope, configPath) {
|
|
|
38013
38387
|
}
|
|
38014
38388
|
function appendCodewithFragment(fragment, scope, configPath) {
|
|
38015
38389
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
38016
|
-
const dir =
|
|
38390
|
+
const dir = dirname9(path);
|
|
38017
38391
|
if (!existsSync12(dir))
|
|
38018
38392
|
mkdirSync7(dir, { recursive: true });
|
|
38019
38393
|
const existing = existsSync12(path) ? readFileSync8(path, "utf-8") : "";
|
|
@@ -38459,11 +38833,11 @@ init_transport();
|
|
|
38459
38833
|
init_config();
|
|
38460
38834
|
init_local_opt_in();
|
|
38461
38835
|
var localNoticePrinted = false;
|
|
38462
|
-
function announceLocal(notice,
|
|
38836
|
+
function announceLocal(notice, reason2) {
|
|
38463
38837
|
if (localNoticePrinted)
|
|
38464
38838
|
return;
|
|
38465
38839
|
localNoticePrinted = true;
|
|
38466
|
-
const line = `hooks: LOCAL mode \u2014 ${
|
|
38840
|
+
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
38841
|
if (notice)
|
|
38468
38842
|
notice(line);
|
|
38469
38843
|
else if (typeof process !== "undefined")
|
|
@@ -38970,7 +39344,7 @@ function coerceForSqlite(value) {
|
|
|
38970
39344
|
return String(value);
|
|
38971
39345
|
}
|
|
38972
39346
|
// src/mcp/server.ts
|
|
38973
|
-
var __dirname3 =
|
|
39347
|
+
var __dirname3 = dirname23(fileURLToPath4(import.meta.url));
|
|
38974
39348
|
var pkg = { name: "@hasna/hooks", version: "0.0.0" };
|
|
38975
39349
|
try {
|
|
38976
39350
|
for (const rel of ["../../package.json", "../package.json", "../../../package.json"]) {
|