@hasna/hooks 0.12.9 → 0.12.14
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 +69 -6
- package/bin/hooks/stop-review.js +1235 -0
- package/bin/hooks-mcp.js +298 -85
- package/bin/index.js +3309 -1086
- package/bin/native-readiness-entry.js +5 -1
- package/bin/native-safety-entry.js +27 -25
- package/bin/native-safety-worker.cjs +27 -25
- package/bin/serve.js +1362 -70
- package/dist/db/remote-storage.d.ts +7 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1665 -257
- package/dist/lib/codex-safety-check.d.ts +1 -1
- package/dist/lib/hosted-registry.d.ts +70 -0
- package/dist/lib/legacy-registry-artifact.d.ts +23 -0
- package/dist/lib/manifest.d.ts +7 -0
- package/dist/lib/native-safety.d.ts +1 -0
- package/dist/lib/native-target.d.ts +7 -0
- package/dist/lib/opencode-stop-plugin.d.ts +55 -0
- package/dist/lib/registry-artifact.d.ts +36 -0
- package/dist/lib/registry.d.ts +4 -0
- package/dist/lib/stop-review-context.d.ts +12 -0
- package/dist/lib/store.d.ts +4 -0
- package/dist/lib/sumi-stop-plugin.d.ts +129 -0
- package/dist/lib/sync.d.ts +10 -0
- package/dist/lib/transport.d.ts +1 -1
- package/dist/native-readiness.d.ts +1 -1
- package/dist/native-readiness.js +5 -1
- package/dist/openapi.d.ts +160 -16
- package/dist/opencode-stop-plugin.js +384 -0
- package/dist/registry-auth.d.ts +5 -0
- package/dist/registry-http.d.ts +4 -0
- package/dist/sdk/generated.d.ts +32 -12
- package/dist/sdk/index.d.ts +28 -5
- package/dist/sdk/index.js +49 -24
- package/dist/sdk/registry-client.d.ts +1 -1
- package/dist/serve.d.ts +4 -4
- package/dist/storage.js +33 -2
- package/dist/sumi-stop-plugin.js +380 -0
- package/hooks/hook-scanoutput/src/hook.ts +33 -3
- package/hooks/hook-stop-review/README.md +109 -0
- package/hooks/hook-stop-review/manifest.json +10 -0
- package/hooks/hook-stop-review/package.json +11 -0
- package/hooks/hook-stop-review/src/hook.ts +59 -0
- package/hooks/hook-stop-review/src/index.ts +3 -0
- package/hooks/hook-stop-review/src/jev.ts +121 -0
- package/hooks/hook-stop-review/src/native.ts +246 -0
- package/hooks/hook-stop-review/src/policy.ts +145 -0
- package/hooks/hook-stop-review/src/runtime.ts +309 -0
- package/hooks/hook-stop-review/src/types.ts +121 -0
- package/hooks/hook-trash-guard/src/hook.ts +96 -0
- package/hooks/hook-workspace-repos-guard/src/hook.ts +231 -3
- package/hooks/local-executors.ts +841 -0
- package/package.json +22 -4
- package/scripts/build-bundled-hooks.ts +40 -0
- package/scripts/validate-bundled-hooks.ts +78 -0
- package/scripts/validate-opencode-stop-plugin.ts +42 -0
- package/scripts/validate-package.ts +9 -0
- package/scripts/validate-sumi-stop-plugin.ts +47 -0
package/bin/hooks-mcp.js
CHANGED
|
@@ -607,6 +607,20 @@ var init_registry = __esm(() => {
|
|
|
607
607
|
matcher: "",
|
|
608
608
|
tags: ["codewith", "session", "context", "conversations", "heartbeat"]
|
|
609
609
|
},
|
|
610
|
+
{
|
|
611
|
+
name: "stop-review",
|
|
612
|
+
bundledEntry: "bin/hooks/stop-review.js",
|
|
613
|
+
displayName: "Stop Review",
|
|
614
|
+
description: "Reviews turn completion against the latest user request and active goal",
|
|
615
|
+
version: "0.1.0",
|
|
616
|
+
category: "Agent Teams",
|
|
617
|
+
event: "Stop",
|
|
618
|
+
events: ["Stop"],
|
|
619
|
+
nativeTargetDispatch: true,
|
|
620
|
+
timeoutSeconds: 20,
|
|
621
|
+
matcher: "",
|
|
622
|
+
tags: ["stop", "goals", "continuity", "review"]
|
|
623
|
+
},
|
|
610
624
|
{
|
|
611
625
|
name: "stop-sync",
|
|
612
626
|
displayName: "Stop Sync",
|
|
@@ -826,7 +840,10 @@ function resolveScript(manifest, manifestDir) {
|
|
|
826
840
|
return { path: rel, content: readFileSync(resolved, "utf-8") };
|
|
827
841
|
}
|
|
828
842
|
function customHookDir(name) {
|
|
829
|
-
|
|
843
|
+
const canonical = shortManifestName(name);
|
|
844
|
+
if (!HOOK_NAME_RE.test(canonical))
|
|
845
|
+
throw new HookIdentityError;
|
|
846
|
+
return join3(getCustomHooksDir(), canonical);
|
|
830
847
|
}
|
|
831
848
|
function readCustomManifest(name) {
|
|
832
849
|
const dir = customHookDir(name);
|
|
@@ -835,16 +852,18 @@ function readCustomManifest(name) {
|
|
|
835
852
|
return;
|
|
836
853
|
try {
|
|
837
854
|
const manifest = parseManifest(readFileSync(manifestPath, "utf-8"));
|
|
855
|
+
if (shortManifestName(manifest.name) !== shortManifestName(name))
|
|
856
|
+
throw new HookIdentityError;
|
|
838
857
|
const script = resolveScript(manifest, dir);
|
|
839
858
|
const scriptIsInline = isInlineScript(manifest);
|
|
840
859
|
return { manifest, scriptPath: join3(dir, script.path), scriptContent: script.content, scriptIsInline };
|
|
841
860
|
} catch (err) {
|
|
842
|
-
if (err instanceof ScriptContainmentError)
|
|
861
|
+
if (err instanceof ScriptContainmentError || err instanceof HookIdentityError)
|
|
843
862
|
throw err;
|
|
844
863
|
return;
|
|
845
864
|
}
|
|
846
865
|
}
|
|
847
|
-
var HOOK_NAME_RE, manifestSchema, ScriptContainmentError;
|
|
866
|
+
var HOOK_NAME_RE, manifestSchema, ScriptContainmentError, HookIdentityError;
|
|
848
867
|
var init_manifest = __esm(() => {
|
|
849
868
|
init_config();
|
|
850
869
|
init_semver();
|
|
@@ -857,6 +876,7 @@ var init_manifest = __esm(() => {
|
|
|
857
876
|
script: z.string().min(1, "script must name a relative path or inline content"),
|
|
858
877
|
script_kind: z.enum(["inline", "file"]).optional(),
|
|
859
878
|
args: z.array(z.string()).optional(),
|
|
879
|
+
nativeTargetDispatch: z.boolean().optional(),
|
|
860
880
|
timeout_ms: z.number().int().positive().optional(),
|
|
861
881
|
env: z.record(z.string(), z.string()).optional()
|
|
862
882
|
});
|
|
@@ -866,6 +886,11 @@ var init_manifest = __esm(() => {
|
|
|
866
886
|
this.name = "ScriptContainmentError";
|
|
867
887
|
}
|
|
868
888
|
};
|
|
889
|
+
HookIdentityError = class HookIdentityError extends Error {
|
|
890
|
+
constructor() {
|
|
891
|
+
super("Hook name must be canonical and match its manifest identity");
|
|
892
|
+
}
|
|
893
|
+
};
|
|
869
894
|
});
|
|
870
895
|
|
|
871
896
|
// src/lib/resolve.ts
|
|
@@ -905,6 +930,13 @@ function resolveScriptPath(name) {
|
|
|
905
930
|
const custom = readCustomManifest(name);
|
|
906
931
|
if (custom)
|
|
907
932
|
return custom.scriptPath;
|
|
933
|
+
const meta = getHook(shortManifestName(name));
|
|
934
|
+
if (meta?.bundledEntry) {
|
|
935
|
+
if (!/^bin\/hooks\/[a-z0-9-]+\.js$/.test(meta.bundledEntry))
|
|
936
|
+
return;
|
|
937
|
+
const bundle = join4(resolveBundledHooksDir(), "..", meta.bundledEntry);
|
|
938
|
+
return existsSync3(bundle) ? bundle : undefined;
|
|
939
|
+
}
|
|
908
940
|
const dir = resolveHookDir(name);
|
|
909
941
|
if (!dir)
|
|
910
942
|
return;
|
|
@@ -924,7 +956,9 @@ function resolveHookMeta(name) {
|
|
|
924
956
|
event: manifest.events[0] ?? "PostToolUse",
|
|
925
957
|
events: manifest.events,
|
|
926
958
|
matcher: "",
|
|
927
|
-
tags: ["custom"]
|
|
959
|
+
tags: ["custom"],
|
|
960
|
+
nativeTargetDispatch: manifest.nativeTargetDispatch,
|
|
961
|
+
timeoutSeconds: manifest.timeout_ms === undefined ? undefined : Math.ceil(manifest.timeout_ms / 1000)
|
|
928
962
|
};
|
|
929
963
|
}
|
|
930
964
|
return getHook(shortManifestName(name));
|
|
@@ -1447,7 +1481,7 @@ var init_redact = __esm(() => {
|
|
|
1447
1481
|
];
|
|
1448
1482
|
});
|
|
1449
1483
|
|
|
1450
|
-
//
|
|
1484
|
+
// node_modules/@hasna/contracts/dist/client/transport.js
|
|
1451
1485
|
import { isIP } from "net";
|
|
1452
1486
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
1453
1487
|
import { closeSync as closeSync23, fstatSync as fstatSync23, openSync as openSync23, readFileSync as readFileSync22 } from "fs";
|
|
@@ -2256,6 +2290,76 @@ var init_local_opt_in = __esm(() => {
|
|
|
2256
2290
|
CONTRACTS_AMBIENT_ENVIRONMENT = Symbol.for("hasna:contracts:ambientClientEnvironment");
|
|
2257
2291
|
});
|
|
2258
2292
|
|
|
2293
|
+
// src/lib/stop-review-context.ts
|
|
2294
|
+
function isStopReviewContextCarrier(name) {
|
|
2295
|
+
return name.startsWith("HOOKS_CLIENT_");
|
|
2296
|
+
}
|
|
2297
|
+
function isCanonicalAuthority(value, app) {
|
|
2298
|
+
if (/[\u0000-\u001f\u007f]/.test(value))
|
|
2299
|
+
return false;
|
|
2300
|
+
const trimmed = value.trim();
|
|
2301
|
+
return ["", ":443"].some((port) => ["", "/", "/v1", "/v1/"].some((suffix) => trimmed === `https://api.hasna.com${port}/${app}${suffix}`));
|
|
2302
|
+
}
|
|
2303
|
+
function projectStopReviewClientContext(source, extra = {}) {
|
|
2304
|
+
const out = {};
|
|
2305
|
+
const values = (names) => names.flatMap((name) => [source[name], extra[name]]).filter((value) => value !== undefined);
|
|
2306
|
+
let refused2 = values([REFUSED]).some((value) => value.trim() === "1");
|
|
2307
|
+
for (const [name, alias] of HOOK_CLIENT_CONFIG_PROJECTIONS) {
|
|
2308
|
+
const value = source[name] ?? extra[name] ?? extra[alias] ?? source[alias];
|
|
2309
|
+
if (value !== undefined)
|
|
2310
|
+
out[alias] = value;
|
|
2311
|
+
}
|
|
2312
|
+
for (const names of LOCAL_FLAGS) {
|
|
2313
|
+
if (values(names).some((value) => value.trim() === "1")) {
|
|
2314
|
+
out[names[1]] = "1";
|
|
2315
|
+
refused2 = true;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
if (values(["HASNA_HOOKS_LOCAL", "HOOKS_LOCAL"]).some((value) => value.trim() !== ""))
|
|
2319
|
+
refused2 = true;
|
|
2320
|
+
if (values(["HASNA_SECRETS_LOCAL_VAULT", "HASNA_SECRETS_DB_PATH", "OPEN_SECRETS_DB"]).some((value) => value !== ""))
|
|
2321
|
+
refused2 = true;
|
|
2322
|
+
for (const { app, name, legacy, alias } of AUTHORITY_PROJECTIONS) {
|
|
2323
|
+
const declared = values([name, legacy, alias]);
|
|
2324
|
+
if (declared.some((value) => !isCanonicalAuthority(value, app)))
|
|
2325
|
+
refused2 = true;
|
|
2326
|
+
else if (declared.length)
|
|
2327
|
+
out[alias] = `https://api.hasna.com/${app}`;
|
|
2328
|
+
const prefix3 = app.toUpperCase();
|
|
2329
|
+
if (values([`HASNA_${prefix3}_API_KEY_OVERRIDE`]).length)
|
|
2330
|
+
refused2 = true;
|
|
2331
|
+
const deliberate = out[`HOOKS_CLIENT_${prefix3}_API_KEY_REF`]?.trim() || out.HOOKS_CLIENT_PROFILE?.trim();
|
|
2332
|
+
if (!deliberate && values([`HASNA_${prefix3}_API_KEY`, `${prefix3}_API_KEY`]).length)
|
|
2333
|
+
refused2 = true;
|
|
2334
|
+
}
|
|
2335
|
+
if (refused2)
|
|
2336
|
+
out[REFUSED] = "1";
|
|
2337
|
+
return out;
|
|
2338
|
+
}
|
|
2339
|
+
var APPS, REFUSED = "HOOKS_CLIENT_CONTEXT_REFUSED", LOCAL_FLAGS, HOOK_CLIENT_CONFIG_PROJECTIONS, AUTHORITY_PROJECTIONS;
|
|
2340
|
+
var init_stop_review_context = __esm(() => {
|
|
2341
|
+
APPS = ["hooks", "instructions", "secrets"];
|
|
2342
|
+
LOCAL_FLAGS = [
|
|
2343
|
+
["HASNA_INSTRUCTIONS_LOCAL", "HOOKS_CLIENT_INSTRUCTIONS_LOCAL", "INSTRUCTIONS_LOCAL"],
|
|
2344
|
+
["HASNA_CONFIGS_LOCAL", "HOOKS_CLIENT_CONFIGS_LOCAL", "CONFIGS_LOCAL"],
|
|
2345
|
+
["HASNA_SECRETS_LOCAL", "HOOKS_CLIENT_SECRETS_LOCAL", "SECRETS_LOCAL"]
|
|
2346
|
+
];
|
|
2347
|
+
HOOK_CLIENT_CONFIG_PROJECTIONS = [
|
|
2348
|
+
["HASNA_HOME", "HOOKS_CLIENT_HOME"],
|
|
2349
|
+
["HASNA_CONFIG_HOME", "HOOKS_CLIENT_CONFIG_HOME"],
|
|
2350
|
+
["HASNA_PROFILE", "HOOKS_CLIENT_PROFILE"],
|
|
2351
|
+
["HASNA_STATION", "HOOKS_CLIENT_STATION"],
|
|
2352
|
+
...APPS.map((app) => [`HASNA_${app.toUpperCase()}_API_KEY_REF`, `HOOKS_CLIENT_${app.toUpperCase()}_API_KEY_REF`]),
|
|
2353
|
+
...LOCAL_FLAGS.map(([name, alias]) => [name, alias])
|
|
2354
|
+
];
|
|
2355
|
+
AUTHORITY_PROJECTIONS = APPS.map((app) => ({
|
|
2356
|
+
app,
|
|
2357
|
+
name: `HASNA_${app.toUpperCase()}_API_URL`,
|
|
2358
|
+
legacy: `${app.toUpperCase()}_API_URL`,
|
|
2359
|
+
alias: `HOOKS_CLIENT_${app.toUpperCase()}_AUTHORITY`
|
|
2360
|
+
}));
|
|
2361
|
+
});
|
|
2362
|
+
|
|
2259
2363
|
// src/lib/hook-env.ts
|
|
2260
2364
|
import { dirname as dirname16, isAbsolute as isAbsolute11 } from "path";
|
|
2261
2365
|
import { existsSync as existsSync14, realpathSync as realpathSync12, statSync } from "fs";
|
|
@@ -2358,6 +2462,8 @@ function buildHookEnv(source, extra) {
|
|
|
2358
2462
|
for (const [name, value] of Object.entries(merged)) {
|
|
2359
2463
|
if (out[name] !== undefined)
|
|
2360
2464
|
continue;
|
|
2465
|
+
if (isStopReviewContextCarrier(name))
|
|
2466
|
+
continue;
|
|
2361
2467
|
if (isDeniedEnvName(name))
|
|
2362
2468
|
continue;
|
|
2363
2469
|
if (isInterpreterInjectionEnvName(name))
|
|
@@ -2367,10 +2473,14 @@ function buildHookEnv(source, extra) {
|
|
|
2367
2473
|
if (value !== undefined && value !== null)
|
|
2368
2474
|
out[name] = value;
|
|
2369
2475
|
}
|
|
2476
|
+
Object.assign(out, projectStopReviewClientContext(source, extra));
|
|
2477
|
+
out.HOOKS_DATA_DIR = getEffectiveDataRoot({ ...source, ...extra ?? {}, HOME: out.HOME });
|
|
2370
2478
|
return out;
|
|
2371
2479
|
}
|
|
2372
2480
|
var ALLOWLIST, INTERPRETER_INJECTION, INTERPRETER_INJECTION_PREFIXES, DENY_SUFFIXES, DENY_PREFIXES, DENY_CONTAINS, PATH_BASELINE, CONFIG_PROJECTIONS;
|
|
2373
2481
|
var init_hook_env = __esm(() => {
|
|
2482
|
+
init_app_home();
|
|
2483
|
+
init_stop_review_context();
|
|
2374
2484
|
ALLOWLIST = new Set(["PATH", "HOME", "LANG", "TZ", "SHELL", "TERM", "USER", "PWD"]);
|
|
2375
2485
|
INTERPRETER_INJECTION = new Set([
|
|
2376
2486
|
"BASH_ENV",
|
|
@@ -2433,7 +2543,7 @@ __export(exports_run, {
|
|
|
2433
2543
|
});
|
|
2434
2544
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
2435
2545
|
import { rmSync as rmSync2, writeFileSync as writeFileSync10 } from "fs";
|
|
2436
|
-
import { basename as basename8, dirname as dirname21, isAbsolute as isAbsolute15, join as
|
|
2546
|
+
import { basename as basename8, dirname as dirname21, isAbsolute as isAbsolute15, join as join16 } from "path";
|
|
2437
2547
|
function extensionOf(scriptPath) {
|
|
2438
2548
|
const base = basename8(scriptPath);
|
|
2439
2549
|
const dot = base.lastIndexOf(".");
|
|
@@ -2504,7 +2614,7 @@ async function readPipeWithDeadline(stream, deadlineMs) {
|
|
|
2504
2614
|
async function executeVerifiedScript(options) {
|
|
2505
2615
|
const scriptDir = dirname21(options.scriptPath);
|
|
2506
2616
|
const interpreter = interpreterFor(options.name, options.scriptPath, options.content);
|
|
2507
|
-
const tempPath =
|
|
2617
|
+
const tempPath = join16(scriptDir, `.hooks-verified-${randomBytes2(12).toString("hex")}.${interpreter.tempExt}`);
|
|
2508
2618
|
let proc = null;
|
|
2509
2619
|
let timedOut = false;
|
|
2510
2620
|
const timeoutTimer = options.timeout ? setTimeout(() => {
|
|
@@ -2713,13 +2823,13 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
2713
2823
|
import { z as z3 } from "zod";
|
|
2714
2824
|
init_registry();
|
|
2715
2825
|
import { existsSync as existsSync15, readFileSync as readFileSync10 } from "fs";
|
|
2716
|
-
import { join as
|
|
2826
|
+
import { join as join24, dirname as dirname23 } from "path";
|
|
2717
2827
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2718
2828
|
|
|
2719
2829
|
// src/lib/installer.ts
|
|
2720
2830
|
init_registry();
|
|
2721
2831
|
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
|
|
2832
|
+
import { join as join13, dirname as dirname9, basename as basename5, resolve as resolve21 } from "path";
|
|
2723
2833
|
import { homedir as homedir7 } from "os";
|
|
2724
2834
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2725
2835
|
|
|
@@ -2780,7 +2890,11 @@ var safeFailureCodes = new Set([
|
|
|
2780
2890
|
"instructions_changed",
|
|
2781
2891
|
"native_config_changed",
|
|
2782
2892
|
"guard_refused",
|
|
2783
|
-
"owner_refused"
|
|
2893
|
+
"owner_refused",
|
|
2894
|
+
"native_executable_changed",
|
|
2895
|
+
"runtime_changed",
|
|
2896
|
+
"installed_cli_changed",
|
|
2897
|
+
"plan_changed"
|
|
2784
2898
|
]);
|
|
2785
2899
|
|
|
2786
2900
|
// src/lib/installer.ts
|
|
@@ -3074,7 +3188,7 @@ function retainedMementosRegistration(commands) {
|
|
|
3074
3188
|
}
|
|
3075
3189
|
|
|
3076
3190
|
// src/lib/registration.ts
|
|
3077
|
-
var REGISTRATION_COMMAND_RE = /^(?:hooks run ([\w-]+)(?:\s+--profile\s+[\w-]+)?|hook-([\w-]+))$/;
|
|
3191
|
+
var REGISTRATION_COMMAND_RE = /^(?:hooks run ([\w-]+)(?:\s+--profile\s+[\w-]+)?(?:\s+--target\s+(?:claude|codex|gemini|codewith|sumi|opencode))?|hook-([\w-]+))$/;
|
|
3078
3192
|
function registrationName(command) {
|
|
3079
3193
|
if (typeof command !== "string")
|
|
3080
3194
|
return;
|
|
@@ -3149,13 +3263,32 @@ function hookRegisteredInSettings(settings, name, eventSpec, hookMatcher) {
|
|
|
3149
3263
|
}
|
|
3150
3264
|
|
|
3151
3265
|
// src/lib/store.ts
|
|
3152
|
-
import { createHash as
|
|
3153
|
-
import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2, renameSync } from "fs";
|
|
3266
|
+
import { createHash as createHash4 } from "crypto";
|
|
3267
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2, renameSync, lstatSync as lstatSync3 } from "fs";
|
|
3268
|
+
import { join as join9 } from "path";
|
|
3154
3269
|
init_db();
|
|
3155
3270
|
init_config();
|
|
3271
|
+
init_manifest();
|
|
3272
|
+
|
|
3273
|
+
// src/lib/registry-artifact.ts
|
|
3274
|
+
init_semver();
|
|
3275
|
+
import { createHash as createHash3 } from "crypto";
|
|
3276
|
+
var REGISTRY_MAX_BYTES = 2 * 1024 * 1024;
|
|
3277
|
+
function canonicalJson(value) {
|
|
3278
|
+
if (Array.isArray(value))
|
|
3279
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
3280
|
+
if (value && typeof value === "object")
|
|
3281
|
+
return `{${Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
3282
|
+
return JSON.stringify(value);
|
|
3283
|
+
}
|
|
3284
|
+
function registryDigest(value) {
|
|
3285
|
+
return createHash3("sha256").update(canonicalJson(value)).digest("hex");
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
// src/lib/store.ts
|
|
3156
3289
|
import { randomBytes } from "crypto";
|
|
3157
3290
|
function sha256Of(input) {
|
|
3158
|
-
return
|
|
3291
|
+
return createHash4("sha256").update(input).digest("hex");
|
|
3159
3292
|
}
|
|
3160
3293
|
function storeDb() {
|
|
3161
3294
|
return isLocalStoreRefused() ? null : getDb();
|
|
@@ -3249,11 +3382,47 @@ function setPinnedHook(name, entry) {
|
|
|
3249
3382
|
function getPinnedHook(name) {
|
|
3250
3383
|
return readLock().hooks[name];
|
|
3251
3384
|
}
|
|
3385
|
+
function registryManagedMarker(name) {
|
|
3386
|
+
return join9(getHooksDataDir(), "registry-managed", sha256Of(name) + ".json");
|
|
3387
|
+
}
|
|
3388
|
+
function isRegistryManaged(name) {
|
|
3389
|
+
try {
|
|
3390
|
+
lstatSync3(registryManagedMarker(name));
|
|
3391
|
+
return true;
|
|
3392
|
+
} catch (error) {
|
|
3393
|
+
if (error.code === "ENOENT")
|
|
3394
|
+
return false;
|
|
3395
|
+
throw error;
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3252
3398
|
function checkScriptHash(name, actual) {
|
|
3399
|
+
const canonical = shortManifestName(name);
|
|
3400
|
+
if (!HOOK_NAME_RE.test(canonical))
|
|
3401
|
+
return { ok: false, pinned: false, expected: "invalid-hook-name", actual, name };
|
|
3402
|
+
let customIdentity;
|
|
3403
|
+
try {
|
|
3404
|
+
const custom = readCustomManifest(name);
|
|
3405
|
+
customIdentity = custom && shortManifestName(custom.manifest.name);
|
|
3406
|
+
} catch (error) {
|
|
3407
|
+
if (!(error instanceof HookIdentityError))
|
|
3408
|
+
throw error;
|
|
3409
|
+
return { ok: false, pinned: false, expected: "hook-manifest-identity-mismatch", actual, name };
|
|
3410
|
+
}
|
|
3411
|
+
if (isRegistryManaged(customIdentity ?? canonical))
|
|
3412
|
+
name = customIdentity ?? canonical;
|
|
3253
3413
|
const db = storeDb();
|
|
3254
3414
|
const record = db ? getHookRecord(db, name) : null;
|
|
3255
3415
|
const pin2 = getPinnedHook(name);
|
|
3256
3416
|
const expected = record?.sha256 ?? pin2?.sha256 ?? null;
|
|
3417
|
+
if (isRegistryManaged(name) && (!pin2 || !pin2.manifest_sha256)) {
|
|
3418
|
+
return { ok: false, pinned: false, expected: "registry-manifest-pin-required", actual, name };
|
|
3419
|
+
}
|
|
3420
|
+
if (pin2?.manifest_sha256) {
|
|
3421
|
+
const custom = readCustomManifest(name);
|
|
3422
|
+
if (!custom || registryDigest(custom.manifest) !== pin2.manifest_sha256) {
|
|
3423
|
+
return { ok: false, pinned: true, expected: pin2.manifest_sha256, actual: custom ? registryDigest(custom.manifest) : "missing-manifest", name };
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3257
3426
|
if (expected !== null && expected !== actual) {
|
|
3258
3427
|
return { ok: false, pinned: true, expected, actual, name };
|
|
3259
3428
|
}
|
|
@@ -3287,13 +3456,13 @@ function checkScriptHash(name, actual) {
|
|
|
3287
3456
|
}
|
|
3288
3457
|
|
|
3289
3458
|
// src/lib/codex-settings.ts
|
|
3290
|
-
import { closeSync as closeSync3, existsSync as existsSync9, lstatSync as
|
|
3459
|
+
import { closeSync as closeSync3, existsSync as existsSync9, lstatSync as lstatSync4, mkdirSync as mkdirSync4, openSync as openSync3, readFileSync as readFileSync6, renameSync as renameSync2, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
|
|
3291
3460
|
import { dirname as dirname5 } from "path";
|
|
3292
|
-
import { createHash as
|
|
3461
|
+
import { createHash as createHash5, randomUUID } from "crypto";
|
|
3293
3462
|
var snapshots = new WeakMap;
|
|
3294
3463
|
function current(path) {
|
|
3295
3464
|
try {
|
|
3296
|
-
const stat =
|
|
3465
|
+
const stat = lstatSync4(path);
|
|
3297
3466
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1048576)
|
|
3298
3467
|
throw new Error("invalid_file");
|
|
3299
3468
|
return readFileSync6(path, "utf8");
|
|
@@ -3327,7 +3496,7 @@ function readCodexSettings(path) {
|
|
|
3327
3496
|
function assertSettingsPreimage(raw, expected) {
|
|
3328
3497
|
if (expected === undefined)
|
|
3329
3498
|
return;
|
|
3330
|
-
if (!/^(?:absent|[a-f0-9]{64})$/.test(expected) || (raw === null ? "absent" :
|
|
3499
|
+
if (!/^(?:absent|[a-f0-9]{64})$/.test(expected) || (raw === null ? "absent" : createHash5("sha256").update(raw).digest("hex")) !== expected) {
|
|
3331
3500
|
throw new Error("Hook settings changed since planning; no settings were written.");
|
|
3332
3501
|
}
|
|
3333
3502
|
}
|
|
@@ -3372,15 +3541,15 @@ function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
|
3372
3541
|
import { createHash as createHash9 } from "crypto";
|
|
3373
3542
|
import { existsSync as existsSync11, lstatSync as lstatSync8 } from "fs";
|
|
3374
3543
|
import { homedir as homedir6 } from "os";
|
|
3375
|
-
import { join as
|
|
3544
|
+
import { join as join12, resolve as resolve9 } from "path";
|
|
3376
3545
|
|
|
3377
|
-
//
|
|
3546
|
+
// node_modules/@hasna/skills/dist/index.js
|
|
3378
3547
|
import { existsSync as existsSync10 } from "fs";
|
|
3379
3548
|
import { homedir as homedir5 } from "os";
|
|
3380
|
-
import { join as
|
|
3549
|
+
import { join as join11, resolve as resolve4 } from "path";
|
|
3381
3550
|
import { homedir as pathsResolverHomedir2 } from "os";
|
|
3382
3551
|
import { join as pathsResolverJoin2 } from "path";
|
|
3383
|
-
import { createHash as
|
|
3552
|
+
import { createHash as createHash7 } from "crypto";
|
|
3384
3553
|
import { existsSync as existsSync52, readdirSync as readdirSync3, readFileSync as readFileSync42, statSync as statSync3 } from "fs";
|
|
3385
3554
|
import { join as join52, sep as sep3 } from "path";
|
|
3386
3555
|
import { createHash as createHash32 } from "crypto";
|
|
@@ -3397,12 +3566,12 @@ import { isDeepStrictEqual as isDeepStrictEqual7 } from "util";
|
|
|
3397
3566
|
import { dirname as dirname52, isAbsolute as isAbsolute5, join as join82, resolve as resolve5 } from "path";
|
|
3398
3567
|
import { lstatSync as lstatSync42, readFileSync as readFileSync62, opendirSync } from "fs";
|
|
3399
3568
|
import { createHash as createHash52 } from "crypto";
|
|
3400
|
-
import { lstatSync as
|
|
3569
|
+
import { lstatSync as lstatSync52, opendirSync as opendirSync2 } from "fs";
|
|
3401
3570
|
import { dirname as dirname62, isAbsolute as isAbsolute6, join as join92, resolve as resolve6 } from "path";
|
|
3402
3571
|
import { createHash as createHash62 } from "crypto";
|
|
3403
3572
|
import { closeSync as closeSync22, constants as constants22, fstatSync as fstatSync22, lstatSync as lstatSync6, openSync as openSync22, readSync as readSync2 } from "fs";
|
|
3404
3573
|
import { dirname as dirname7, isAbsolute as isAbsolute7, resolve as resolve7 } from "path";
|
|
3405
|
-
import { createHash as
|
|
3574
|
+
import { createHash as createHash72 } from "crypto";
|
|
3406
3575
|
import { lstatSync as lstatSync7, readlinkSync } from "fs";
|
|
3407
3576
|
import { dirname as dirname8, isAbsolute as isAbsolute8, join as join102, parse as parse2, resolve as resolve8, sep as sep32 } from "path";
|
|
3408
3577
|
import { createHash as createHash8 } from "crypto";
|
|
@@ -3411,12 +3580,12 @@ import { basename as basename9, dirname as dirname18, isAbsolute as isAbsolute19
|
|
|
3411
3580
|
import { isAbsolute as isAbsolute18, join as join30, resolve as resolve17 } from "path";
|
|
3412
3581
|
import { createRequire } from "module";
|
|
3413
3582
|
|
|
3414
|
-
//
|
|
3415
|
-
import { createHash as
|
|
3583
|
+
// node_modules/@hasna/skills/node_modules/@hasna/contracts/dist/kernel-lock.js
|
|
3584
|
+
import { createHash as createHash6 } from "crypto";
|
|
3416
3585
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3417
3586
|
import { spawn, spawnSync } from "child_process";
|
|
3418
|
-
import { closeSync as closeSync4, constants as constants3, fstatSync as fstatSync3, lstatSync as
|
|
3419
|
-
import { dirname as dirname6, join as
|
|
3587
|
+
import { closeSync as closeSync4, constants as constants3, fstatSync as fstatSync3, lstatSync as lstatSync5, openSync as openSync4, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "fs";
|
|
3588
|
+
import { dirname as dirname6, join as join10, parse, relative, resolve as resolve3, sep as sep2 } from "path";
|
|
3420
3589
|
class KernelLockError extends Error {
|
|
3421
3590
|
code = "KERNEL_LOCK_UNAVAILABLE";
|
|
3422
3591
|
constructor(reason) {
|
|
@@ -3439,7 +3608,7 @@ function darwinAcls(entries, deadline) {
|
|
|
3439
3608
|
refused("unsafe ACL helper path");
|
|
3440
3609
|
fd = openSync4(helper, constants3.O_RDONLY | constants3.O_NOFOLLOW | constants3.O_NONBLOCK);
|
|
3441
3610
|
const info = fstatSync3(fd);
|
|
3442
|
-
if (!info.isFile() || info.nlink !== 1 || info.uid !== 0 && info.uid !== process.getuid() || (info.mode & 18) !== 0 || (info.mode & 73) === 0 || info.size > 1048576 ||
|
|
3611
|
+
if (!info.isFile() || info.nlink !== 1 || info.uid !== 0 && info.uid !== process.getuid() || (info.mode & 18) !== 0 || (info.mode & 73) === 0 || info.size > 1048576 || createHash6("sha256").update(readFileSync7(fd)).digest("hex") !== DARWIN_HELPER_SHA256 || !sameEntry(info, lstatSync5(helper)))
|
|
3443
3612
|
refused("ACL helper integrity check failed");
|
|
3444
3613
|
const result = spawnSync(helper, entries.flatMap(([path, stat]) => [path, String(stat.dev), String(stat.ino)]), {
|
|
3445
3614
|
env: { LANG: "C" },
|
|
@@ -3449,7 +3618,7 @@ function darwinAcls(entries, deadline) {
|
|
|
3449
3618
|
timeout: timeout(deadline - performance.now()),
|
|
3450
3619
|
killSignal: "SIGKILL"
|
|
3451
3620
|
});
|
|
3452
|
-
if (result.error || result.signal || !sameEntry(info,
|
|
3621
|
+
if (result.error || result.signal || !sameEntry(info, lstatSync5(helper)))
|
|
3453
3622
|
refused("ACL helper failed");
|
|
3454
3623
|
if (result.status === 76)
|
|
3455
3624
|
refused("unsafe lock ACL");
|
|
@@ -3477,7 +3646,7 @@ function sameEntry(a, b) {
|
|
|
3477
3646
|
}
|
|
3478
3647
|
function statOptional(path) {
|
|
3479
3648
|
try {
|
|
3480
|
-
return
|
|
3649
|
+
return lstatSync5(path);
|
|
3481
3650
|
} catch (error) {
|
|
3482
3651
|
if (error.code === "ENOENT")
|
|
3483
3652
|
return;
|
|
@@ -3495,7 +3664,7 @@ function canonicalRoot(root) {
|
|
|
3495
3664
|
const parts = relative(cursor, requested).split(sep2).filter(Boolean);
|
|
3496
3665
|
for (const part of ["", ...parts]) {
|
|
3497
3666
|
if (part)
|
|
3498
|
-
cursor =
|
|
3667
|
+
cursor = join10(cursor, part);
|
|
3499
3668
|
const info = statOptional(cursor);
|
|
3500
3669
|
if (!info)
|
|
3501
3670
|
refused("existing lock root is required");
|
|
@@ -3552,10 +3721,10 @@ class KernelLock {
|
|
|
3552
3721
|
let fd;
|
|
3553
3722
|
try {
|
|
3554
3723
|
const rootPath = canonicalRoot(root);
|
|
3555
|
-
this.#path =
|
|
3556
|
-
this.#legacyPath =
|
|
3724
|
+
this.#path = join10(rootPath, key + LOCK_SUFFIX);
|
|
3725
|
+
this.#legacyPath = join10(rootPath, `${key}.lock`);
|
|
3557
3726
|
for (let path = rootPath;; path = dirname6(path)) {
|
|
3558
|
-
const info =
|
|
3727
|
+
const info = lstatSync5(path);
|
|
3559
3728
|
const stickyParent = path !== rootPath && info.uid === 0 && (info.mode & 512) !== 0;
|
|
3560
3729
|
if (!info.isDirectory() || info.isSymbolicLink() || info.uid !== process.getuid() && info.uid !== 0 || (info.mode & 18) !== 0 && !stickyParent || path === rootPath && info.uid !== process.getuid())
|
|
3561
3730
|
refused("unsafe lock directory");
|
|
@@ -3604,11 +3773,11 @@ class KernelLock {
|
|
|
3604
3773
|
try {
|
|
3605
3774
|
this.#checkLegacy();
|
|
3606
3775
|
for (const [path, initial] of this.#directories) {
|
|
3607
|
-
const current22 =
|
|
3776
|
+
const current22 = lstatSync5(path);
|
|
3608
3777
|
if (!sameEntry(initial, current22) || current22.mode !== initial.mode || current22.uid !== initial.uid || current22.isSymbolicLink())
|
|
3609
3778
|
refused("lock directory changed");
|
|
3610
3779
|
}
|
|
3611
|
-
const current2 =
|
|
3780
|
+
const current2 = lstatSync5(this.#path), descriptor = fstatSync3(this.#fd);
|
|
3612
3781
|
this.#checkFile(current2);
|
|
3613
3782
|
this.#checkFile(descriptor);
|
|
3614
3783
|
if (!sameEntry(current2, this.#opened) || !sameEntry(descriptor, this.#opened))
|
|
@@ -3622,7 +3791,7 @@ class KernelLock {
|
|
|
3622
3791
|
refused("lock ACL changed");
|
|
3623
3792
|
}
|
|
3624
3793
|
for (const [path, initial] of [...this.#directories, [this.#path, current2]]) {
|
|
3625
|
-
const after =
|
|
3794
|
+
const after = lstatSync5(path);
|
|
3626
3795
|
if (!sameEntry(initial, after) || after.mode !== initial.mode || after.uid !== initial.uid)
|
|
3627
3796
|
refused("lock identity changed during ACL inspection");
|
|
3628
3797
|
}
|
|
@@ -3742,7 +3911,7 @@ class KernelLock {
|
|
|
3742
3911
|
}
|
|
3743
3912
|
}
|
|
3744
3913
|
|
|
3745
|
-
//
|
|
3914
|
+
// node_modules/@hasna/skills/dist/index.js
|
|
3746
3915
|
import { execFileSync } from "child_process";
|
|
3747
3916
|
import { createHash as createHash12 } from "crypto";
|
|
3748
3917
|
import { accessSync, constants as constants6, lstatSync as lstatSync12, readFileSync as readFileSync11, realpathSync as realpathSync32, statSync as statSync7 } from "fs";
|
|
@@ -10637,7 +10806,7 @@ function effectiveHome() {
|
|
|
10637
10806
|
return process.env["HOME"] || process.env["USERPROFILE"] || homedir5() || "/tmp";
|
|
10638
10807
|
}
|
|
10639
10808
|
function legacyDataRoot() {
|
|
10640
|
-
return
|
|
10809
|
+
return join11(effectiveHome(), ".hasna", "skills");
|
|
10641
10810
|
}
|
|
10642
10811
|
function resolverDataRoot(home = effectiveHome(), env) {
|
|
10643
10812
|
return dataDir2({ app: "skills", home, env });
|
|
@@ -10646,7 +10815,7 @@ function adoptResolverDataRoot2(resolved, env = process.env) {
|
|
|
10646
10815
|
const dataOverride = env.HASNA_DATA_HOME;
|
|
10647
10816
|
if (typeof dataOverride === "string" && dataOverride.trim().length > 0)
|
|
10648
10817
|
return true;
|
|
10649
|
-
return existsSync10(
|
|
10818
|
+
return existsSync10(join11(resolved, DEFAULT_SQLITE_FILENAME)) || existsSync10(join11(resolved, GLOBAL_CONFIG_FILENAME));
|
|
10650
10819
|
}
|
|
10651
10820
|
function exactDataRoot() {
|
|
10652
10821
|
for (const key of [DATA_DIR_ENV, HASNA_SKILLS_HOME_ENV, SKILLS_HOME_ENV]) {
|
|
@@ -10880,7 +11049,7 @@ function* bundleHashParts(files) {
|
|
|
10880
11049
|
yield new TextEncoder().encode("\x00");
|
|
10881
11050
|
}
|
|
10882
11051
|
function hashBundleFiles(files) {
|
|
10883
|
-
const hash =
|
|
11052
|
+
const hash = createHash7(CONTENT_HASH_ALGORITHM);
|
|
10884
11053
|
for (const part of bundleHashParts(files))
|
|
10885
11054
|
hash.update(part);
|
|
10886
11055
|
return hash.digest("hex");
|
|
@@ -12171,7 +12340,7 @@ function need3(value, message) {
|
|
|
12171
12340
|
function safe(path) {
|
|
12172
12341
|
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
12342
|
for (let cursor = path;; cursor = dirname62(cursor)) {
|
|
12174
|
-
need3(!
|
|
12343
|
+
need3(!lstatSync52(cursor, { throwIfNoEntry: false })?.isSymbolicLink(), "Refusing symlink native discovery directory");
|
|
12175
12344
|
if (dirname62(cursor) === cursor)
|
|
12176
12345
|
break;
|
|
12177
12346
|
}
|
|
@@ -12183,7 +12352,7 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
12183
12352
|
safe(path);
|
|
12184
12353
|
if (omittedRoots.some((root2) => path === root2 || path.startsWith(root2 + "/")))
|
|
12185
12354
|
return { path, sha256: null };
|
|
12186
|
-
const root =
|
|
12355
|
+
const root = lstatSync52(path, { throwIfNoEntry: false });
|
|
12187
12356
|
if (!root)
|
|
12188
12357
|
return { path, sha256: null };
|
|
12189
12358
|
need3(root.isDirectory(), "Unsupported native discovery directory input");
|
|
@@ -12205,7 +12374,7 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
12205
12374
|
if (omittedRoots.includes(child2))
|
|
12206
12375
|
continue;
|
|
12207
12376
|
need3(child2.length <= AGENT_POLICY_LIMITS.pathCharacters, "Native discovery directory path limit exceeded");
|
|
12208
|
-
const stat =
|
|
12377
|
+
const stat = lstatSync52(child2);
|
|
12209
12378
|
need3(stat.isFile() || stat.isDirectory(), "Refusing symlink or special native discovery directory member");
|
|
12210
12379
|
const row = JSON.stringify([childRelative, stat.isDirectory() ? "directory" : "file"]) + `
|
|
12211
12380
|
`;
|
|
@@ -12216,7 +12385,7 @@ function capture(path, budget2, excludedRoots, omittedRoots = [], rows) {
|
|
|
12216
12385
|
if (stat.isDirectory() && !excludedRoots.includes(child2))
|
|
12217
12386
|
walk(child2, childRelative, stat, depth + 1);
|
|
12218
12387
|
}
|
|
12219
|
-
need3(same(before,
|
|
12388
|
+
need3(same(before, lstatSync52(current2, { throwIfNoEntry: false })), "Native discovery directory changed while reading");
|
|
12220
12389
|
}
|
|
12221
12390
|
walk(path, "", root, 0);
|
|
12222
12391
|
safe(path);
|
|
@@ -12445,7 +12614,7 @@ function hashDiscoveryPathFile(path, budget2, changes) {
|
|
|
12445
12614
|
const after = trace(path);
|
|
12446
12615
|
if (JSON.stringify(before.rows) !== JSON.stringify(after.rows) || before.file !== after.file)
|
|
12447
12616
|
throw new Error("Discovery path input changed during read");
|
|
12448
|
-
return
|
|
12617
|
+
return createHash72("sha256").update(JSON.stringify({ version: 1, path, rows: before.rows, content })).digest("hex");
|
|
12449
12618
|
}
|
|
12450
12619
|
var CLAUDE_PLUGIN_MANIFEST_LIMITS = Object.freeze({ bytes: 1024 * 1024, depth: 32, nodes: 65536, stringCharacters: 16384 });
|
|
12451
12620
|
function requireValue(value, reason2) {
|
|
@@ -16365,14 +16534,14 @@ function validatePluginTarget(value) {
|
|
|
16365
16534
|
}
|
|
16366
16535
|
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)");
|
|
16367
16536
|
}
|
|
16368
|
-
function
|
|
16537
|
+
function canonicalJson2(value) {
|
|
16369
16538
|
return JSON.stringify(value, (_key, item) => pluginObject(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
|
|
16370
16539
|
}
|
|
16371
16540
|
function canonicalTarget(target) {
|
|
16372
|
-
return JSON.parse(
|
|
16541
|
+
return JSON.parse(canonicalJson2({ ...target, registrations: [...target.registrations].sort((a, b) => canonicalJson2(a) < canonicalJson2(b) ? -1 : canonicalJson2(a) > canonicalJson2(b) ? 1 : 0) }));
|
|
16373
16542
|
}
|
|
16374
16543
|
function bindingId(binding) {
|
|
16375
|
-
return pluginHash(
|
|
16544
|
+
return pluginHash(canonicalJson2({ ...binding, target: canonicalTarget(binding.target) }));
|
|
16376
16545
|
}
|
|
16377
16546
|
function selectedIdentity(selection) {
|
|
16378
16547
|
return { slug: selection.slug, version: selection.version, bundleDigest: selection.bundleDigest };
|
|
@@ -16387,10 +16556,10 @@ function planIdentity(plan) {
|
|
|
16387
16556
|
return { schemaVersion: 3, binding: plan.binding, bindingId: plan.bindingId, profileRevision: plan.profileRevision, selection: routingIdentity(plan.selection), payloadSelections: plan.payloadSelections.map(routingIdentity), manifest: plan.manifest, originalTreeDigest: plan.originalTreeDigest, projectionTreeDigest: plan.projectionTreeDigest, files: plan.files, removed: plan.removed, sourceCommand: plan.sourceCommand, evidenceDigest: plan.evidenceDigest };
|
|
16388
16557
|
}
|
|
16389
16558
|
function identityDigest(plan) {
|
|
16390
|
-
return `sha256:${pluginHash(
|
|
16559
|
+
return `sha256:${pluginHash(canonicalJson2(planIdentity(plan)))}`;
|
|
16391
16560
|
}
|
|
16392
16561
|
function observedEvidenceDigest(observation) {
|
|
16393
|
-
return `sha256:${pluginHash(
|
|
16562
|
+
return `sha256:${pluginHash(canonicalJson2(observation))}`;
|
|
16394
16563
|
}
|
|
16395
16564
|
function validatePrincipal(value) {
|
|
16396
16565
|
pluginKeys(value, ["userId", "accountId", "role"]);
|
|
@@ -16423,7 +16592,7 @@ function validateObservedSelection(value) {
|
|
|
16423
16592
|
function validateRoutingIdentity(value) {
|
|
16424
16593
|
pluginKeys(value, ["slug", "version", "bundleDigest", "aliases", "triggers"]);
|
|
16425
16594
|
validateObservedSelection({ ...value, authority: "https://example.com/skills/v1", workspaceId: "validation", profileRevision: "validation" });
|
|
16426
|
-
pluginNeed(
|
|
16595
|
+
pluginNeed(canonicalJson2(value) === canonicalJson2(routingIdentity(value)), "Plugin routing identity is not canonical");
|
|
16427
16596
|
}
|
|
16428
16597
|
function validateWitnesses(value, empty = false) {
|
|
16429
16598
|
pluginNeed(Array.isArray(value) && (empty || value.length > 0) && value.length <= PLUGIN_PROJECTION_LIMITS.files, "Invalid plugin file witnesses");
|
|
@@ -16469,7 +16638,7 @@ function validatePlan(value) {
|
|
|
16469
16638
|
const mapped = new Map;
|
|
16470
16639
|
for (const mapping of value.manifest.payloads) {
|
|
16471
16640
|
const prior = mapped.get(mapping.target.slug);
|
|
16472
|
-
pluginNeed(!prior ||
|
|
16641
|
+
pluginNeed(!prior || canonicalJson2(prior) === canonicalJson2(mapping.target), "Plugin mappings disagree about a canonical payload");
|
|
16473
16642
|
mapped.set(mapping.target.slug, mapping.target);
|
|
16474
16643
|
const removed = value.removed.find((item) => item.path === mapping.path);
|
|
16475
16644
|
pluginNeed(removed && mapping.sourceDigest === `sha256:${pluginHash(JSON.stringify(normalizedWitnesses([removed])))}`, "Plugin mapped source differs from its removed witness");
|
|
@@ -16478,7 +16647,7 @@ function validatePlan(value) {
|
|
|
16478
16647
|
let previous = "";
|
|
16479
16648
|
for (const selection of value.payloadSelections) {
|
|
16480
16649
|
validateRoutingIdentity(selection);
|
|
16481
|
-
pluginNeed(selection.slug > previous && selection.slug !== value.selection.slug &&
|
|
16650
|
+
pluginNeed(selection.slug > previous && selection.slug !== value.selection.slug && canonicalJson2(selectedIdentity(selection)) === canonicalJson2(mapped.get(selection.slug)), "Plugin payload selection differs from its canonical mapping");
|
|
16482
16651
|
previous = selection.slug;
|
|
16483
16652
|
}
|
|
16484
16653
|
pluginKeys(value.observation, ["principal", "profileRevision", "integration", "payloads"]);
|
|
@@ -16490,9 +16659,9 @@ function validatePlan(value) {
|
|
|
16490
16659
|
for (let index = 0;index < observed.length; index++) {
|
|
16491
16660
|
const selection = observed[index];
|
|
16492
16661
|
validateRoutingIdentity(selection);
|
|
16493
|
-
pluginNeed(
|
|
16662
|
+
pluginNeed(canonicalJson2(selection) === canonicalJson2(selected[index]), "Plugin observed routing selection differs from its identity");
|
|
16494
16663
|
}
|
|
16495
|
-
pluginNeed(value.profileRevision === value.observation.profileRevision &&
|
|
16664
|
+
pluginNeed(value.profileRevision === value.observation.profileRevision && canonicalJson2(binding.principal) === canonicalJson2(value.observation.principal), "Plugin observed profile or principal differs from its approved identity");
|
|
16496
16665
|
validateResolvedProfile({ profileId: binding.profileId, authority: binding.authority, workspaceId: binding.workspaceId, profileRevision: value.profileRevision, selections: observed.map((selection) => ({ ...selection, authority: binding.authority, workspaceId: binding.workspaceId, profileRevision: value.profileRevision })) }, binding.authority);
|
|
16497
16666
|
const plan = value;
|
|
16498
16667
|
pluginNeed(observedEvidenceDigest(plan.observation) === plan.evidenceDigest, "Plugin receipt observed evidence changed");
|
|
@@ -16529,7 +16698,7 @@ function readPluginAdmissionReceipt(storeRoot, id, digest) {
|
|
|
16529
16698
|
receipt.plan.removed = normalizedWitnesses(receipt.plan.removed);
|
|
16530
16699
|
pluginNeed(receipt.plan.bindingId === id && receipt.plan.planDigest === digest, "Plugin receipt identity differs from its filename");
|
|
16531
16700
|
const binding = readPluginBinding(storeRoot, id);
|
|
16532
|
-
pluginNeed(
|
|
16701
|
+
pluginNeed(canonicalJson2(binding) === canonicalJson2(receipt.plan.binding) && receipt.plan.sourceCommand === pluginResolverCommand(binding), "Plugin receipt binding changed");
|
|
16533
16702
|
pluginNeed(receipt.materializedPath === join30(storeRoot, "objects", id, digest.slice(7)), "Plugin receipt points outside its immutable materialization");
|
|
16534
16703
|
pluginText(receipt.admittedAt, 64);
|
|
16535
16704
|
pluginNeed(Number.isFinite(Date.parse(receipt.admittedAt)), "Invalid plugin admission time");
|
|
@@ -38027,7 +38196,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
38027
38196
|
}
|
|
38028
38197
|
if (events2.length)
|
|
38029
38198
|
evidence.push(`Skills-managed hook entries in ${events2.join(", ")}`);
|
|
38030
|
-
const bridge =
|
|
38199
|
+
const bridge = join12(home, ".claude", "skills", "skills-cli", "SKILL.md");
|
|
38031
38200
|
let bridgePresent;
|
|
38032
38201
|
try {
|
|
38033
38202
|
bridgePresent = lstatSync8(bridge, { throwIfNoEntry: false }) !== undefined;
|
|
@@ -38041,7 +38210,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
38041
38210
|
function skillsPolicyLocations(dataDir3) {
|
|
38042
38211
|
const state = (path) => existsSync11(path) ? "present" : "absent";
|
|
38043
38212
|
if (dataDir3 !== undefined)
|
|
38044
|
-
return [`${
|
|
38213
|
+
return [`${join12(resolve9(dataDir3), "agent-policy.json")} (explicit data directory, absent)`];
|
|
38045
38214
|
const env = process.env, home = env.HOME || env.USERPROFILE || homedir6() || "/tmp", searched = [];
|
|
38046
38215
|
let selected = false;
|
|
38047
38216
|
for (const key of ["HASNA_SKILLS_DIR", "HASNA_SKILLS_HOME", "SKILLS_HOME"]) {
|
|
@@ -38052,13 +38221,13 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
38052
38221
|
searched.push(`$${key} (unset)`);
|
|
38053
38222
|
else {
|
|
38054
38223
|
selected = true;
|
|
38055
|
-
searched.push(`$${key} -> ${
|
|
38224
|
+
searched.push(`$${key} -> ${join12(resolve9(value), "agent-policy.json")} (selected, absent)`);
|
|
38056
38225
|
}
|
|
38057
38226
|
}
|
|
38058
38227
|
const override = env.HASNA_DATA_HOME;
|
|
38059
|
-
const base = typeof override === "string" && override.length > 0 ? override : process.platform === "darwin" ?
|
|
38060
|
-
const xdg =
|
|
38061
|
-
const adopted = typeof override === "string" && override.trim().length > 0 || existsSync11(
|
|
38228
|
+
const base = typeof override === "string" && override.length > 0 ? override : process.platform === "darwin" ? join12(home, "Library", "Application Support", "Hasna") : join12(home, ".local", "share", "hasna");
|
|
38229
|
+
const xdg = join12(base, "skills"), xdgPolicy = join12(xdg, "agent-policy.json");
|
|
38230
|
+
const adopted = typeof override === "string" && override.trim().length > 0 || existsSync11(join12(xdg, "server.db")) || existsSync11(join12(xdg, "config.json"));
|
|
38062
38231
|
if (selected)
|
|
38063
38232
|
searched.push(`${xdgPolicy} (not consulted, ${state(xdgPolicy)})`);
|
|
38064
38233
|
else if (adopted) {
|
|
@@ -38066,7 +38235,7 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
38066
38235
|
searched.push(`${xdgPolicy} (selected, absent)`);
|
|
38067
38236
|
} else
|
|
38068
38237
|
searched.push(`${xdgPolicy} (not selected: the directory holds no server.db or config.json and HASNA_DATA_HOME is unset; ${state(xdgPolicy)})`);
|
|
38069
|
-
const legacy =
|
|
38238
|
+
const legacy = join12(home, ".hasna", "skills", "agent-policy.json");
|
|
38070
38239
|
searched.push(selected ? `${legacy} (not consulted, ${state(legacy)})` : `${legacy} (selected, absent)`);
|
|
38071
38240
|
return searched;
|
|
38072
38241
|
}
|
|
@@ -38084,7 +38253,7 @@ function planCoordinatedClaudeSettings(before, replacement, options) {
|
|
|
38084
38253
|
if (!plan) {
|
|
38085
38254
|
const usage = claudeSkillsUsage(before, options.home);
|
|
38086
38255
|
if (usage.length)
|
|
38087
|
-
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${
|
|
38256
|
+
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${join12(options.home, ".claude", "settings.json")} (${usage.join("; ")}), but no Skills agent policy resolved, ` + "so Hooks cannot coordinate this change and wrote nothing. Locations searched, in Skills resolution order: " + skillsPolicyLocations(options.dataDir).map((location, index) => `${index + 1}) ${location}`).join("; ") + ". Run hooks with the environment that selects the Skills data directory (for example HASNA_SKILLS_DIR), " + "or repair the integration with `skills hook install`.");
|
|
38088
38257
|
}
|
|
38089
38258
|
return plan;
|
|
38090
38259
|
}
|
|
@@ -38097,9 +38266,22 @@ function coordinateClaudeSettings(before, replacement, options, beforeWrite) {
|
|
|
38097
38266
|
return true;
|
|
38098
38267
|
}
|
|
38099
38268
|
|
|
38269
|
+
// src/lib/native-target.ts
|
|
38270
|
+
var HOOK_RUN_TARGETS = ["claude", "codex", "gemini", "codewith", "sumi", "opencode"];
|
|
38271
|
+
function isHookRunTarget(value) {
|
|
38272
|
+
return typeof value === "string" && HOOK_RUN_TARGETS.includes(value);
|
|
38273
|
+
}
|
|
38274
|
+
function nativeTargetCommandSuffix(dispatch, target) {
|
|
38275
|
+
if (!dispatch)
|
|
38276
|
+
return "";
|
|
38277
|
+
if (!isHookRunTarget(target))
|
|
38278
|
+
throw new Error("Native registration requires a supported target");
|
|
38279
|
+
return ` --target ${target}`;
|
|
38280
|
+
}
|
|
38281
|
+
|
|
38100
38282
|
// src/lib/installer.ts
|
|
38101
38283
|
var __dirname2 = dirname9(fileURLToPath3(import.meta.url));
|
|
38102
|
-
var HOOKS_DIR = existsSync12(
|
|
38284
|
+
var HOOKS_DIR = existsSync12(join13(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join13(__dirname2, "..", "..", "hooks") : join13(__dirname2, "..", "hooks");
|
|
38103
38285
|
function normalizeHookName(name) {
|
|
38104
38286
|
return name.startsWith("hook-") ? name : `hook-${name}`;
|
|
38105
38287
|
}
|
|
@@ -38187,18 +38369,18 @@ function getSettingsPath(scope = "global", target = "claude", codewithConfigPath
|
|
|
38187
38369
|
return globalOverride;
|
|
38188
38370
|
const dir = getTargetSettingsDir(target);
|
|
38189
38371
|
if (target === "codex")
|
|
38190
|
-
return
|
|
38372
|
+
return join13(scope === "project" ? process.cwd() : homedir7(), dir, "hooks.json");
|
|
38191
38373
|
if (scope === "project") {
|
|
38192
|
-
return target === "codewith" ?
|
|
38374
|
+
return target === "codewith" ? join13(process.cwd(), dir, "config.toml") : join13(process.cwd(), dir, "settings.json");
|
|
38193
38375
|
}
|
|
38194
|
-
return target === "codewith" ?
|
|
38376
|
+
return target === "codewith" ? join13(homedir7(), dir, "config.toml") : join13(homedir7(), dir, "settings.json");
|
|
38195
38377
|
}
|
|
38196
38378
|
function getHookPath(name) {
|
|
38197
38379
|
const shortName = shortHookName(name);
|
|
38198
38380
|
const resolved = resolveHookDir(shortName);
|
|
38199
38381
|
if (resolved)
|
|
38200
38382
|
return resolved;
|
|
38201
|
-
return
|
|
38383
|
+
return join13(HOOKS_DIR, normalizeHookName(shortName));
|
|
38202
38384
|
}
|
|
38203
38385
|
function hookExists(name) {
|
|
38204
38386
|
return existsSync12(getHookPath(name));
|
|
@@ -38245,10 +38427,10 @@ function unreadableSettingsRefusal(settings, path) {
|
|
|
38245
38427
|
function settingsIdentity(path) {
|
|
38246
38428
|
if (existsSync12(path))
|
|
38247
38429
|
return realpathSync9(path);
|
|
38248
|
-
return existsSync12(dirname9(path)) ?
|
|
38430
|
+
return existsSync12(dirname9(path)) ? join13(realpathSync9(dirname9(path)), basename5(path)) : resolve21(path);
|
|
38249
38431
|
}
|
|
38250
38432
|
function coordinatesWithSkills(path, target) {
|
|
38251
|
-
return target === "claude" && settingsIdentity(path) === settingsIdentity(
|
|
38433
|
+
return target === "claude" && settingsIdentity(path) === settingsIdentity(join13(homedir7(), ".claude/settings.json"));
|
|
38252
38434
|
}
|
|
38253
38435
|
function writerRefusal(error61) {
|
|
38254
38436
|
return { error: error61 instanceof Error ? error61.message : "Unknown error", ...error61 instanceof ClaudeSettingsRefusal ? { code: error61.code } : {} };
|
|
@@ -38355,7 +38537,7 @@ function buildCodewithTomlFragment(name, profile, mementos) {
|
|
|
38355
38537
|
if (!meta3)
|
|
38356
38538
|
throw new Error(`Hook '${shortName}' not found`);
|
|
38357
38539
|
validateMementosRegistration(shortName, mementos);
|
|
38358
|
-
const command = isNativeSafetyName(shortName) ? installedNativeSafetyCommand(shortName) : (profile ? `hooks run ${shortName} --profile ${profile}` : `hooks run ${shortName}`) + mementosCommandSuffix(mementos);
|
|
38540
|
+
const command = isNativeSafetyName(shortName) ? installedNativeSafetyCommand(shortName) : (profile ? `hooks run ${shortName} --profile ${profile}` : `hooks run ${shortName}`) + nativeTargetCommandSuffix(meta3.nativeTargetDispatch, "codewith") + mementosCommandSuffix(mementos);
|
|
38359
38541
|
const matcher = codewithMatcher(meta3.matcher);
|
|
38360
38542
|
const fragments = [];
|
|
38361
38543
|
for (const event of getHookEvents(meta3)) {
|
|
@@ -38615,7 +38797,7 @@ function registerHook(name, scope = "global", target = "claude", profile, mement
|
|
|
38615
38797
|
}
|
|
38616
38798
|
}
|
|
38617
38799
|
const retained = name === "mementos-context" && mementos === undefined ? retainedMementosRegistration(Object.values(settings.hooks).flatMap((groups) => Array.isArray(groups) ? groups.flatMap((group) => Array.isArray(group.hooks) ? group.hooks.map((hook) => hook.command).filter((command) => typeof command === "string") : []) : [])) : undefined;
|
|
38618
|
-
const hookCommand = readiness ? installedNativeReadinessCommand(target) : isNativeSafetyName(name) ? installedNativeSafetyCommand(name) : (profile ? `hooks run ${name} --profile ${profile}` : `hooks run ${name}`) + mementosCommandSuffix(mementos ?? retained);
|
|
38800
|
+
const hookCommand = readiness ? installedNativeReadinessCommand(target) : isNativeSafetyName(name) ? installedNativeSafetyCommand(name) : (profile ? `hooks run ${name} --profile ${profile}` : `hooks run ${name}`) + nativeTargetCommandSuffix(meta3.nativeTargetDispatch, target) + mementosCommandSuffix(mementos ?? retained);
|
|
38619
38801
|
if (target === "codex" || target === "claude" && (isNativeSafetyName(name) || readiness)) {
|
|
38620
38802
|
const positions = [];
|
|
38621
38803
|
for (const [event, groups] of Object.entries(settings.hooks)) {
|
|
@@ -38750,10 +38932,10 @@ function removeHookForTarget(name, scope, target) {
|
|
|
38750
38932
|
// src/lib/profiles.ts
|
|
38751
38933
|
init_app_home();
|
|
38752
38934
|
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync9, writeFileSync as writeFileSync9, readdirSync as readdirSync9, rmSync, cpSync as cpSync2 } from "fs";
|
|
38753
|
-
import { join as
|
|
38935
|
+
import { join as join14 } from "path";
|
|
38754
38936
|
function getProfilesDir() {
|
|
38755
|
-
const newDir =
|
|
38756
|
-
const oldDir =
|
|
38937
|
+
const newDir = join14(getEffectiveDataRoot(), "profiles");
|
|
38938
|
+
const oldDir = join14(getHomeDir(), ".hooks", "profiles");
|
|
38757
38939
|
if (!existsSync13(newDir) && existsSync13(oldDir)) {
|
|
38758
38940
|
mkdirSync10(newDir, { recursive: true });
|
|
38759
38941
|
cpSync2(oldDir, newDir, { recursive: true });
|
|
@@ -38767,7 +38949,7 @@ function ensureProfilesDir() {
|
|
|
38767
38949
|
}
|
|
38768
38950
|
}
|
|
38769
38951
|
function profilePath(id) {
|
|
38770
|
-
return
|
|
38952
|
+
return join14(getProfilesDir(), `${id}.json`);
|
|
38771
38953
|
}
|
|
38772
38954
|
function shortUuid() {
|
|
38773
38955
|
return crypto.randomUUID().slice(0, 8);
|
|
@@ -38809,7 +38991,7 @@ function listProfiles() {
|
|
|
38809
38991
|
const profiles = [];
|
|
38810
38992
|
for (const file2 of files) {
|
|
38811
38993
|
try {
|
|
38812
|
-
const content = readFileSync9(
|
|
38994
|
+
const content = readFileSync9(join14(dir, file2), "utf-8");
|
|
38813
38995
|
profiles.push(JSON.parse(content));
|
|
38814
38996
|
} catch {}
|
|
38815
38997
|
}
|
|
@@ -39008,8 +39190,39 @@ function wantsSslFor(connectionString) {
|
|
|
39008
39190
|
|
|
39009
39191
|
class PgAdapterAsync {
|
|
39010
39192
|
pool;
|
|
39011
|
-
constructor(connectionString) {
|
|
39012
|
-
|
|
39193
|
+
constructor(connectionString, options = {}) {
|
|
39194
|
+
const timeout2 = options.timeoutMs;
|
|
39195
|
+
this.pool = new pg.Pool({ connectionString, ssl: sslConfigFor(connectionString), ...timeout2 ? { connectionTimeoutMillis: timeout2, query_timeout: timeout2, statement_timeout: timeout2 } : {} });
|
|
39196
|
+
}
|
|
39197
|
+
async readOnlyAll(sql, ...params) {
|
|
39198
|
+
const client = await this.pool.connect();
|
|
39199
|
+
try {
|
|
39200
|
+
await client.query("BEGIN READ ONLY");
|
|
39201
|
+
return (await client.query(translatePlaceholders(sql), normalizeParams2(params))).rows;
|
|
39202
|
+
} finally {
|
|
39203
|
+
try {
|
|
39204
|
+
await client.query("ROLLBACK");
|
|
39205
|
+
} finally {
|
|
39206
|
+
client.release();
|
|
39207
|
+
}
|
|
39208
|
+
}
|
|
39209
|
+
}
|
|
39210
|
+
async transaction(operation) {
|
|
39211
|
+
const client = await this.pool.connect();
|
|
39212
|
+
try {
|
|
39213
|
+
await client.query("BEGIN");
|
|
39214
|
+
const result = await operation({
|
|
39215
|
+
run: async (sql, ...params) => ({ changes: (await client.query(translatePlaceholders(sql), normalizeParams2(params))).rowCount ?? 0 }),
|
|
39216
|
+
all: async (sql, ...params) => (await client.query(translatePlaceholders(sql), normalizeParams2(params))).rows
|
|
39217
|
+
});
|
|
39218
|
+
await client.query("COMMIT");
|
|
39219
|
+
return result;
|
|
39220
|
+
} catch (error61) {
|
|
39221
|
+
await client.query("ROLLBACK");
|
|
39222
|
+
throw error61;
|
|
39223
|
+
} finally {
|
|
39224
|
+
client.release();
|
|
39225
|
+
}
|
|
39013
39226
|
}
|
|
39014
39227
|
async run(sql, ...params) {
|
|
39015
39228
|
const result = await this.pool.query(translatePlaceholders(sql), normalizeParams2(params));
|
|
@@ -39348,7 +39561,7 @@ var __dirname3 = dirname23(fileURLToPath4(import.meta.url));
|
|
|
39348
39561
|
var pkg = { name: "@hasna/hooks", version: "0.0.0" };
|
|
39349
39562
|
try {
|
|
39350
39563
|
for (const rel of ["../../package.json", "../package.json", "../../../package.json"]) {
|
|
39351
|
-
const p =
|
|
39564
|
+
const p = join24(__dirname3, rel);
|
|
39352
39565
|
if (existsSync15(p)) {
|
|
39353
39566
|
pkg = JSON.parse(readFileSync10(p, "utf-8"));
|
|
39354
39567
|
break;
|
|
@@ -39594,7 +39807,7 @@ function createHooksServer() {
|
|
|
39594
39807
|
continue;
|
|
39595
39808
|
}
|
|
39596
39809
|
const hookDir = getHookPath(name);
|
|
39597
|
-
if (!existsSync15(
|
|
39810
|
+
if (!existsSync15(join24(hookDir, "src", "hook.ts"))) {
|
|
39598
39811
|
issues.push({ hook: name, issue: "Missing src/hook.ts in package", severity: "error" });
|
|
39599
39812
|
hookHealthy = false;
|
|
39600
39813
|
}
|
|
@@ -39638,7 +39851,7 @@ function createHooksServer() {
|
|
|
39638
39851
|
return { content: [{ type: "text", text: JSON.stringify({ error: `Hook '${name}' not found` }) }] };
|
|
39639
39852
|
}
|
|
39640
39853
|
const hookPath = getHookPath(name);
|
|
39641
|
-
const readmePath =
|
|
39854
|
+
const readmePath = join24(hookPath, "README.md");
|
|
39642
39855
|
let readme = "";
|
|
39643
39856
|
if (existsSync15(readmePath)) {
|
|
39644
39857
|
readme = readFileSync10(readmePath, "utf-8");
|