@hasna/hooks 0.12.8 → 0.12.10
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 +13 -7
- package/bin/index.js +86 -47
- package/bin/native-safety-entry.js +19 -19
- package/bin/native-safety-worker.cjs +19 -19
- package/dist/index.js +71 -35
- package/dist/lib/codex-safety-check.d.ts +6 -2
- 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/hooks/hook-scanoutput/src/hook.ts +33 -3
- package/hooks/hook-workspace-repos-guard/src/hook.ts +118 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8140,7 +8140,7 @@ import { existsSync as existsSync11, lstatSync as lstatSync8 } from "fs";
|
|
|
8140
8140
|
import { homedir as homedir6 } from "os";
|
|
8141
8141
|
import { join as join11, resolve as resolve9 } from "path";
|
|
8142
8142
|
|
|
8143
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
8143
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.55+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
8144
8144
|
import { existsSync as existsSync10 } from "fs";
|
|
8145
8145
|
import { homedir as homedir5 } from "os";
|
|
8146
8146
|
import { join as join10, resolve as resolve4 } from "path";
|
|
@@ -8508,7 +8508,7 @@ class KernelLock {
|
|
|
8508
8508
|
}
|
|
8509
8509
|
}
|
|
8510
8510
|
|
|
8511
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
8511
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.55+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
8512
8512
|
import { execFileSync } from "child_process";
|
|
8513
8513
|
import { createHash as createHash12 } from "crypto";
|
|
8514
8514
|
import { accessSync, constants as constants6, lstatSync as lstatSync12, readFileSync as readFileSync11, realpathSync as realpathSync32, statSync as statSync7 } from "fs";
|
|
@@ -16321,7 +16321,8 @@ var MEASURED_CODEX_CAPABILITIES = {
|
|
|
16321
16321
|
"codex-cli 0.159.0": ["hooks"],
|
|
16322
16322
|
"codex-cli 0.159.2": ["hooks", "qualified-skill-catalog"],
|
|
16323
16323
|
"codex-cli 0.160.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
16324
|
-
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
16324
|
+
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
16325
|
+
"codex-cli 0.161.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
16325
16326
|
};
|
|
16326
16327
|
function supportsCodexNativeCapability(version, capability) {
|
|
16327
16328
|
return typeof version === "string" && Object.hasOwn(MEASURED_CODEX_CAPABILITIES, version) && MEASURED_CODEX_CAPABILITIES[version].includes(capability);
|
|
@@ -17676,7 +17677,7 @@ function validateResolvedProfile(profile, authority) {
|
|
|
17676
17677
|
}
|
|
17677
17678
|
var package_default = {
|
|
17678
17679
|
name: "@hasna/skills",
|
|
17679
|
-
version: "0.10.
|
|
17680
|
+
version: "0.10.55",
|
|
17680
17681
|
description: "Skills library for AI coding agents",
|
|
17681
17682
|
type: "module",
|
|
17682
17683
|
bin: {
|
|
@@ -21827,12 +21828,17 @@ function retiredCodexRoots(binding) {
|
|
|
21827
21828
|
}
|
|
21828
21829
|
return proof.roots;
|
|
21829
21830
|
}
|
|
21831
|
+
function retainableAbsentSource(source) {
|
|
21832
|
+
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined)
|
|
21833
|
+
return false;
|
|
21834
|
+
return [undefined, "bytes"].includes(source.hashMode) || source.hashMode === "claude-plugin-manifest-v1" && source.sha256 !== null && source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json"));
|
|
21835
|
+
}
|
|
21830
21836
|
function absentRetiredClaudeRoots(binding) {
|
|
21831
21837
|
if (binding.agent !== "claude" || binding.method !== "reviewed")
|
|
21832
21838
|
return [];
|
|
21833
21839
|
const result = new Set;
|
|
21834
21840
|
for (const source of binding.sources) {
|
|
21835
|
-
if (
|
|
21841
|
+
if (!retainableAbsentSource(source) || source.sha256 === null)
|
|
21836
21842
|
continue;
|
|
21837
21843
|
const marker = sep8 + ".claude" + sep8 + "plugins" + sep8 + "cache" + sep8, at = source.path.indexOf(marker);
|
|
21838
21844
|
if (at < 0 || source.path.indexOf(marker, at + 1) >= 0)
|
|
@@ -21944,7 +21950,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
21944
21950
|
safe4(source.path);
|
|
21945
21951
|
continue;
|
|
21946
21952
|
}
|
|
21947
|
-
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
21953
|
+
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)) {
|
|
21948
21954
|
safe4(source.path);
|
|
21949
21955
|
continue;
|
|
21950
21956
|
}
|
|
@@ -22000,7 +22006,7 @@ function rebindAgentDiscovery(binding, changes) {
|
|
|
22000
22006
|
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
22001
22007
|
const rebound = { ...binding, sources: binding.sources.map((source) => {
|
|
22002
22008
|
assertMarketplaceBinding(binding, source);
|
|
22003
|
-
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
22009
|
+
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)))
|
|
22004
22010
|
return source;
|
|
22005
22011
|
const sha2563 = projected(source, changes, budget2);
|
|
22006
22012
|
if (!changes.has(source.path) && sha2563 !== source.sha256)
|
|
@@ -43335,16 +43341,18 @@ function installHook(name, options = {}) {
|
|
|
43335
43341
|
}
|
|
43336
43342
|
return installForTarget(name, scope, overwrite, target, profile, codewithMode, codewithConfigPath, mementos, expectedSettingsSha256, beforeWrite);
|
|
43337
43343
|
}
|
|
43338
|
-
function previewNativeSafetyRegistration(target, scope = "global") {
|
|
43339
|
-
|
|
43344
|
+
function previewNativeSafetyRegistration(target, scope = "global", guard = "trash-guard") {
|
|
43345
|
+
if (!isNativeSafetyName(guard))
|
|
43346
|
+
throw new Error("Unknown native safety guard");
|
|
43347
|
+
const conflict = detectRewriteConflict(guard, scope, target);
|
|
43340
43348
|
if (conflict)
|
|
43341
43349
|
throw new Error("Conflicting input rewriter; reconcile it before installing the safety guard.");
|
|
43342
43350
|
let result;
|
|
43343
|
-
registerHook(
|
|
43351
|
+
registerHook(guard, scope, target, undefined, undefined, (settings) => {
|
|
43344
43352
|
const before = target === "codex" ? capturedCodexSettings(settings) : settingsPreimages.get(settings)?.text;
|
|
43345
43353
|
if (before === undefined)
|
|
43346
43354
|
throw new Error("Hook settings require a valid captured preimage.");
|
|
43347
|
-
const command = installedNativeSafetyCommand(
|
|
43355
|
+
const command = installedNativeSafetyCommand(guard);
|
|
43348
43356
|
result = { before, after: JSON.stringify(settings, null, 2) + `
|
|
43349
43357
|
`, command };
|
|
43350
43358
|
});
|
|
@@ -44997,8 +45005,25 @@ async function evaluateRecord(event, record4, signal, executionAgent) {
|
|
|
44997
45005
|
} catch {}
|
|
44998
45006
|
throw new NativeSafetyError("guard_failed");
|
|
44999
45007
|
}
|
|
45000
|
-
async function verifyNativeSafetyCommand(command, home = homedir8()) {
|
|
45008
|
+
async function verifyNativeSafetyCommand(command, home = homedir8(), guard = "trash-guard") {
|
|
45009
|
+
if (guard !== "trash-guard" && guard !== "workspace-repos-guard")
|
|
45010
|
+
throw new NativeSafetyError("input_invalid");
|
|
45001
45011
|
home = canonicalHome(home);
|
|
45012
|
+
if (guard === "workspace-repos-guard") {
|
|
45013
|
+
const binding = nativeSafetyCommandBinding(command);
|
|
45014
|
+
if (binding?.name !== guard || binding.home !== home)
|
|
45015
|
+
throw new NativeSafetyError("binding_invalid");
|
|
45016
|
+
const root = join26(home, ".hasna", "repos", "clones"), probe = join26(root, ".hasna-workspace-repos-verification-only");
|
|
45017
|
+
const verdict2 = await evaluateRecord({
|
|
45018
|
+
hook_event_name: "PreToolUse",
|
|
45019
|
+
tool_name: "Bash",
|
|
45020
|
+
cwd: home,
|
|
45021
|
+
tool_input: { command: "rm -- '" + probe.replaceAll("'", "'\\''") + "'" }
|
|
45022
|
+
}, { schema: "hasna.hooks.native-safety.v1", harness: "sumi", command });
|
|
45023
|
+
if (verdict2.decision !== "deny" || verdict2.reason !== `[workspace-repos-guard] delete under the protected repo-checkout root (${root}) is forbidden at any depth: ${probe}`)
|
|
45024
|
+
throw new NativeSafetyError("guard_failed", verdict2.decision === "deny" ? verdict2.reason.slice(0, 512) : undefined);
|
|
45025
|
+
return;
|
|
45026
|
+
}
|
|
45002
45027
|
const record4 = parseRecord(JSON.stringify({ schema: "hasna.hooks.native-safety.v1", harness: "sumi", command }), home);
|
|
45003
45028
|
const verdict = await evaluateRecord({ hook_event_name: "PreToolUse", tool_name: "Bash", cwd: home, tool_input: { command: "rm -- .hasna-trash-verification-only" } }, record4);
|
|
45004
45029
|
if (verdict.decision !== "rewrite")
|
|
@@ -45008,7 +45033,6 @@ async function verifyNativeSafetyCommand(command, home = homedir8()) {
|
|
|
45008
45033
|
// src/lib/codex-safety-check.ts
|
|
45009
45034
|
var SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1", "codex-cli 0.161.0"];
|
|
45010
45035
|
var versions = new Set(SUPPORTED_CODEX_SAFETY_VERSIONS);
|
|
45011
|
-
var matcher = "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$";
|
|
45012
45036
|
|
|
45013
45037
|
class CodexSafetyError extends Error {
|
|
45014
45038
|
code;
|
|
@@ -45195,7 +45219,13 @@ function supportedDiscoveryWarnings(hooks, warnings) {
|
|
|
45195
45219
|
}
|
|
45196
45220
|
return warnings.every((warning) => typeof warning === "string" && allowed.delete(warning));
|
|
45197
45221
|
}
|
|
45198
|
-
function
|
|
45222
|
+
function codexSafetyMatcher(guard) {
|
|
45223
|
+
const meta3 = getHook(guard);
|
|
45224
|
+
need8(meta3, "guard_definition_invalid");
|
|
45225
|
+
return matcherFor(meta3, "codex");
|
|
45226
|
+
}
|
|
45227
|
+
function selectCodexSafety(discovery, configuration, home, cwd, featureEnabled, requireReady = true, readiness = false, guard = "trash-guard") {
|
|
45228
|
+
need8(readiness ? guard === "trash-guard" : guard === "trash-guard" || guard === "workspace-repos-guard", "guard_definition_invalid");
|
|
45199
45229
|
const data = discovery?.data;
|
|
45200
45230
|
need8(Array.isArray(data) && data.length === 1 && data[0]?.cwd === cwd && Array.isArray(data[0]?.hooks) && data[0].hooks.length <= 1e4 && Array.isArray(data[0].errors) && data[0].errors.length === 0 && Array.isArray(data[0].warnings) && supportedDiscoveryWarnings(data[0].hooks, data[0].warnings), "native_discovery_failed");
|
|
45201
45231
|
const config2 = configuration?.config;
|
|
@@ -45209,11 +45239,11 @@ function selectCodexSafety(discovery, configuration, home, cwd, featureEnabled,
|
|
|
45209
45239
|
if (readiness && hook2.command.includes("hasna-native-readiness-v"))
|
|
45210
45240
|
need8(nativeReadinessCommandBinding(hook2.command), "guard_definition_invalid");
|
|
45211
45241
|
}
|
|
45212
|
-
const selected = data[0].hooks.filter((hook2) => typeof hook2?.command === "string" && (readiness ? !!nativeReadinessCommandBinding(hook2.command) : nativeSafetyCommandBinding(hook2.command)?.name ===
|
|
45242
|
+
const selected = data[0].hooks.filter((hook2) => typeof hook2?.command === "string" && (readiness ? !!nativeReadinessCommandBinding(hook2.command) : nativeSafetyCommandBinding(hook2.command)?.name === guard));
|
|
45213
45243
|
need8(selected.length !== 0, "guard_missing");
|
|
45214
45244
|
need8(selected.length === 1, "guard_ambiguous");
|
|
45215
45245
|
const hook = selected[0], binding = readiness ? nativeReadinessCommandBinding(hook.command) : nativeSafetyCommandBinding(hook.command);
|
|
45216
|
-
need8(binding.home === home && (!readiness || binding?.provider === "codex") && hook.eventName === (readiness ? "sessionStart" : "preToolUse") && hook.handlerType === "command" && hook.matcher === (readiness ? "^(startup|resume|clear|fork)$" :
|
|
45246
|
+
need8(binding.home === home && (!readiness || binding?.provider === "codex") && hook.eventName === (readiness ? "sessionStart" : "preToolUse") && hook.handlerType === "command" && hook.matcher === (readiness ? "^(startup|resume|clear|fork)$" : codexSafetyMatcher(guard)) && hook.timeoutSec === (readiness ? TRASH_READINESS_NATIVE_TIMEOUT_SECONDS : 10) && hook.async === false && hook.statusMessage === null && hook.additionalContextLimit === null && typeof hook.key === "string" && hook.key.length <= 4096 && typeof hook.sourcePath === "string" && isAbsolute15(hook.sourcePath) && hook.pluginId === null && hook.isManaged === false && ["user", "project"].includes(hook.source) && typeof hook.currentHash === "string" && /^sha256:[a-f0-9]{64}$/.test(hook.currentHash), "guard_definition_invalid");
|
|
45217
45247
|
need8(typeof hook.enabled === "boolean" && ["trusted", "untrusted", "modified"].includes(hook.trustStatus), "guard_definition_invalid");
|
|
45218
45248
|
if (requireReady) {
|
|
45219
45249
|
need8(hook.enabled === true, "guard_disabled");
|
|
@@ -45246,7 +45276,7 @@ async function readCodexSafety(rpc, home, cwd, options = {}) {
|
|
|
45246
45276
|
}
|
|
45247
45277
|
} while (cursor !== null);
|
|
45248
45278
|
}
|
|
45249
|
-
return { guard: selectCodexSafety(hooks, configuration, home, cwd, enabled, options.requireReady ?? true, options.readiness ?? false), discovery: hooks, configuration };
|
|
45279
|
+
return { guard: selectCodexSafety(hooks, configuration, home, cwd, enabled, options.requireReady ?? true, options.readiness ?? false, options.guard ?? "trash-guard"), discovery: hooks, configuration };
|
|
45250
45280
|
}
|
|
45251
45281
|
|
|
45252
45282
|
// src/lib/codex-safety-trust.ts
|
|
@@ -45336,8 +45366,8 @@ function exclusive(path, bytes) {
|
|
|
45336
45366
|
}
|
|
45337
45367
|
syncDirectory(dirname25(path));
|
|
45338
45368
|
}
|
|
45339
|
-
async function inspect(rpc, home, cwd, readiness = false) {
|
|
45340
|
-
const observed = await readCodexSafety(rpc, home, cwd, { includeLayers: true, requireReady: false, readiness });
|
|
45369
|
+
async function inspect(rpc, home, cwd, readiness = false, selected = "trash-guard") {
|
|
45370
|
+
const observed = await readCodexSafety(rpc, home, cwd, { includeLayers: true, requireReady: false, readiness, guard: selected });
|
|
45341
45371
|
const { guard, configuration, discovery } = observed;
|
|
45342
45372
|
const layers = configuration?.layers;
|
|
45343
45373
|
need10(Array.isArray(layers) && layers.length <= 1000, "native_config_invalid");
|
|
@@ -45362,6 +45392,7 @@ async function inspect(rpc, home, cwd, readiness = false) {
|
|
|
45362
45392
|
configPath: path,
|
|
45363
45393
|
configVersion: layer.version,
|
|
45364
45394
|
action: guard.enabled && guard.trustStatus === "trusted" ? "unchanged" : "trust_and_enable",
|
|
45395
|
+
...!readiness && selected !== "trash-guard" ? { guard: selected } : {},
|
|
45365
45396
|
guardVerified: !readiness,
|
|
45366
45397
|
...readiness ? { readinessRunnerVerified: true } : {},
|
|
45367
45398
|
nativeAdoptionVerified: false
|
|
@@ -45370,22 +45401,23 @@ async function inspect(rpc, home, cwd, readiness = false) {
|
|
|
45370
45401
|
return { ...observed, layer, layers, canonicalPath: canonicalPath2, before, desired, plan };
|
|
45371
45402
|
}
|
|
45372
45403
|
async function context2(options, dependencies) {
|
|
45404
|
+
need10(options.readiness ? options.guard === undefined : options.guard === undefined || isNativeSafetyName(options.guard), "input_invalid");
|
|
45373
45405
|
const home = realpathSync16(options.home ?? homedir9()), cwd = realpathSync16(options.cwd ?? process.cwd());
|
|
45374
45406
|
need10(isAbsolute24(home) && isAbsolute24(cwd), "input_invalid");
|
|
45375
45407
|
return { home, cwd, rpc: await (dependencies.connect ?? connectCodexSafety)({ ...options, home }) };
|
|
45376
45408
|
}
|
|
45377
|
-
async function verify(command, home, readiness, dependencies) {
|
|
45409
|
+
async function verify(command, home, readiness, dependencies, guard = "trash-guard") {
|
|
45378
45410
|
if (readiness)
|
|
45379
45411
|
need10(nativeReadinessCommandVerified(command));
|
|
45380
45412
|
else
|
|
45381
|
-
await (dependencies.verify ?? verifyNativeSafetyCommand)(command, home);
|
|
45413
|
+
await (dependencies.verify ?? verifyNativeSafetyCommand)(command, home, guard);
|
|
45382
45414
|
}
|
|
45383
45415
|
async function planTrust(options = {}, dependencies = {}) {
|
|
45384
45416
|
const { home, cwd, rpc } = await context2(options, dependencies);
|
|
45385
45417
|
try {
|
|
45386
|
-
const before = await inspect(rpc, home, cwd, options.readiness);
|
|
45387
|
-
await verify(before.guard.command, home, !!options.readiness, dependencies);
|
|
45388
|
-
need10((await inspect(rpc, home, cwd, options.readiness)).plan.planDigest === before.plan.planDigest);
|
|
45418
|
+
const before = await inspect(rpc, home, cwd, options.readiness, options.guard);
|
|
45419
|
+
await verify(before.guard.command, home, !!options.readiness, dependencies, options.guard);
|
|
45420
|
+
need10((await inspect(rpc, home, cwd, options.readiness, options.guard)).plan.planDigest === before.plan.planDigest);
|
|
45389
45421
|
return before.plan;
|
|
45390
45422
|
} finally {
|
|
45391
45423
|
await rpc.close();
|
|
@@ -45396,10 +45428,10 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
45396
45428
|
const selected = { ...options }, { home, cwd, rpc } = await context2(selected, dependencies);
|
|
45397
45429
|
let operationId, journal, requested = false;
|
|
45398
45430
|
try {
|
|
45399
|
-
const before = await inspect(rpc, home, cwd, selected.readiness);
|
|
45431
|
+
const before = await inspect(rpc, home, cwd, selected.readiness, selected.guard);
|
|
45400
45432
|
need10(before.plan.planDigest === selected.expectedPlanDigest);
|
|
45401
|
-
await verify(before.guard.command, home, !!selected.readiness, dependencies);
|
|
45402
|
-
need10((await inspect(rpc, home, cwd, selected.readiness)).plan.planDigest === before.plan.planDigest);
|
|
45433
|
+
await verify(before.guard.command, home, !!selected.readiness, dependencies, selected.guard);
|
|
45434
|
+
need10((await inspect(rpc, home, cwd, selected.readiness, selected.guard)).plan.planDigest === before.plan.planDigest);
|
|
45403
45435
|
if (before.plan.action === "unchanged")
|
|
45404
45436
|
return { ok: true, changed: false, ...before.plan };
|
|
45405
45437
|
const expectedConfiguration = structuredClone(before.configuration);
|
|
@@ -45415,7 +45447,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
45415
45447
|
expectedGuard.trustStatus = "trusted";
|
|
45416
45448
|
operationId = randomUUID4();
|
|
45417
45449
|
let directory2 = home;
|
|
45418
|
-
for (const part of [".hasna", "hooks", "native", selected.readiness ? "codex-readiness-trust" : "codex-trash-trust", operationId]) {
|
|
45450
|
+
for (const part of [".hasna", "hooks", "native", selected.readiness ? "codex-readiness-trust" : (selected.guard ?? "trash-guard") === "trash-guard" ? "codex-trash-trust" : "codex-" + selected.guard + "-trust", operationId]) {
|
|
45419
45451
|
directory2 = join27(directory2, part);
|
|
45420
45452
|
try {
|
|
45421
45453
|
mkdirSync14(directory2, { mode: 448 });
|
|
@@ -45439,7 +45471,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
45439
45471
|
edits: [{ keyPath: "hooks.state." + JSON.stringify(before.guard.key), value: before.desired, mergeStrategy: "replace" }]
|
|
45440
45472
|
});
|
|
45441
45473
|
need10(result?.status === "ok" && result.filePath === before.plan.configPath && result.overriddenMetadata === null && /^sha256:[a-f0-9]{64}$/.test(result.version));
|
|
45442
|
-
const after = await inspect(rpc, home, cwd, selected.readiness);
|
|
45474
|
+
const after = await inspect(rpc, home, cwd, selected.readiness, selected.guard);
|
|
45443
45475
|
expectedLayer.version = result.version;
|
|
45444
45476
|
need10(after.layer.version === result.version && after.plan.action === "unchanged" && mergedConfiguration(after.configuration.config) === mergedConfiguration(expectedConfiguration.config) && canonical8(after.configuration.layers) === canonical8(expectedConfiguration.layers) && canonical8(after.discovery) === canonical8(expectedDiscovery));
|
|
45445
45477
|
const receipt = {
|
|
@@ -45448,6 +45480,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
45448
45480
|
operationId,
|
|
45449
45481
|
planDigest: before.plan.planDigest,
|
|
45450
45482
|
configVersion: result.version,
|
|
45483
|
+
...before.plan.guard ? { guard: before.plan.guard } : {},
|
|
45451
45484
|
guardVerified: !selected.readiness,
|
|
45452
45485
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
45453
45486
|
nativeDiscoveryVerified: true,
|
|
@@ -45750,6 +45783,7 @@ function validateSettings(raw) {
|
|
|
45750
45783
|
}
|
|
45751
45784
|
function inspect2(options) {
|
|
45752
45785
|
need12(options?.target === "codex" || options?.target === "claude", "input_invalid");
|
|
45786
|
+
need12(options.readiness ? options.guard === "trash-guard" : isNativeSafetyName(options.guard), "input_invalid");
|
|
45753
45787
|
const home = realpathSync18(homedir11()), path = getSettingsPath("global", options.target);
|
|
45754
45788
|
need12(isAbsolute27(path) && resolve26(path) === path, "input_invalid");
|
|
45755
45789
|
const nativeHome = options.target === "codex" ? process.env.CODEX_HOME : process.env.CLAUDE_CONFIG_DIR;
|
|
@@ -45763,7 +45797,7 @@ function inspect2(options) {
|
|
|
45763
45797
|
const parsed = validateSettings(before.raw);
|
|
45764
45798
|
let preview2;
|
|
45765
45799
|
try {
|
|
45766
|
-
preview2 =
|
|
45800
|
+
preview2 = options.readiness ? previewNativeReadinessRegistration(options.target) : previewNativeSafetyRegistration(options.target, "global", options.guard);
|
|
45767
45801
|
} catch {
|
|
45768
45802
|
throw new NativeRegistrationError("registration_conflict");
|
|
45769
45803
|
}
|
|
@@ -45779,6 +45813,7 @@ function inspect2(options) {
|
|
|
45779
45813
|
desiredSHA256: changed ? sha9(preview2.after) : before.sha256,
|
|
45780
45814
|
commandSHA256: sha9(preview2.command),
|
|
45781
45815
|
action: changed ? "register" : "unchanged",
|
|
45816
|
+
...options.guard !== "trash-guard" ? { guard: options.guard } : {},
|
|
45782
45817
|
guardVerified: !options.readiness,
|
|
45783
45818
|
...options.readiness ? { readinessRunnerVerified: true } : {},
|
|
45784
45819
|
nativeAdoptionVerified: false
|
|
@@ -45834,7 +45869,7 @@ async function planRegistration(options, dependencies = {}) {
|
|
|
45834
45869
|
if (selected.readiness)
|
|
45835
45870
|
need12(nativeReadinessCommandVerified(before.preview.command), "guard_failed");
|
|
45836
45871
|
else
|
|
45837
|
-
await (dependencies.verify ?? verifyNativeSafetyCommand)(before.preview.command, before.home);
|
|
45872
|
+
await (dependencies.verify ?? verifyNativeSafetyCommand)(before.preview.command, before.home, selected.guard);
|
|
45838
45873
|
} catch {
|
|
45839
45874
|
throw new NativeRegistrationError("guard_failed");
|
|
45840
45875
|
}
|
|
@@ -45854,7 +45889,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
45854
45889
|
return { ok: true, changed: false, ...plan };
|
|
45855
45890
|
const operationId = randomUUID6();
|
|
45856
45891
|
let directory2 = before.home;
|
|
45857
|
-
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : "trash-registration", operationId]) {
|
|
45892
|
+
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : selected.guard === "trash-guard" ? "trash-registration" : selected.guard + "-registration", operationId]) {
|
|
45858
45893
|
directory2 = join33(directory2, part);
|
|
45859
45894
|
try {
|
|
45860
45895
|
mkdirSync15(directory2, { mode: 448 });
|
|
@@ -45878,7 +45913,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
45878
45913
|
if (selected.readiness)
|
|
45879
45914
|
installNativeReadinessRegistration(selected.target, plan.beforeSHA256, beforeWrite);
|
|
45880
45915
|
else {
|
|
45881
|
-
const result = installHook(
|
|
45916
|
+
const result = installHook(selected.guard, { target: selected.target, overwrite: true, expectedSettingsSha256: plan.beforeSHA256, beforeWrite });
|
|
45882
45917
|
if (!result.success)
|
|
45883
45918
|
throw Object.assign(new Error(result.error ?? "The installer refused the registration."), { code: result.code ?? "writer_refused" });
|
|
45884
45919
|
}
|
|
@@ -45891,6 +45926,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
45891
45926
|
operationId,
|
|
45892
45927
|
planDigest: plan.planDigest,
|
|
45893
45928
|
settingsSHA256: after.before.sha256,
|
|
45929
|
+
...plan.guard ? { guard: plan.guard } : {},
|
|
45894
45930
|
guardVerified: !selected.readiness,
|
|
45895
45931
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
45896
45932
|
nativeAdoptionVerified: false
|
|
@@ -45904,8 +45940,8 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
45904
45940
|
throw new NativeRegistrationError("apply_outcome_uncertain", operationId);
|
|
45905
45941
|
}
|
|
45906
45942
|
}
|
|
45907
|
-
var planNativeSafetyRegistration = (options, dependencies = {}) => planRegistration({ target: options.target }, dependencies);
|
|
45908
|
-
var applyNativeSafetyRegistration = (options, dependencies = {}) => applyRegistration({ target: options.target, expectedPlanDigest: options.expectedPlanDigest }, dependencies);
|
|
45943
|
+
var planNativeSafetyRegistration = (options, dependencies = {}) => planRegistration({ target: options.target, guard: options.guard ?? "trash-guard" }, dependencies);
|
|
45944
|
+
var applyNativeSafetyRegistration = (options, dependencies = {}) => applyRegistration({ target: options.target, guard: options.guard ?? "trash-guard", expectedPlanDigest: options.expectedPlanDigest }, dependencies);
|
|
45909
45945
|
|
|
45910
45946
|
// src/index.ts
|
|
45911
45947
|
function installHookForProject(name, options = {}) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NativeSafetyName } from "./native-safety.js";
|
|
1
2
|
import { verifyNativeSafetyCommand } from "../native-safety.js";
|
|
2
3
|
/** Exact `codex --version` outputs whose app-server protocol was measured
|
|
3
4
|
* against the real native binary. Anything else refuses as native_unsupported. */
|
|
@@ -30,12 +31,15 @@ type NativeGuard = {
|
|
|
30
31
|
trustStatus: string;
|
|
31
32
|
};
|
|
32
33
|
/** Select only the exact packaged composite definition in native discovery.
|
|
33
|
-
* A name, a settings file, or a trusted hash by itself is not enough.
|
|
34
|
-
|
|
34
|
+
* A name, a settings file, or a trusted hash by itself is not enough. `guard`
|
|
35
|
+
* selects which bundled guard's definition (default trash-guard); every other
|
|
36
|
+
* hook, the other guard's included, is only checked for well-formedness. */
|
|
37
|
+
export declare function selectCodexSafety(discovery: unknown, configuration: unknown, home: string, cwd: string, featureEnabled?: boolean, requireReady?: boolean, readiness?: boolean, guard?: NativeSafetyName): NativeGuard;
|
|
35
38
|
export declare function readCodexSafety(rpc: CodexSafetyRpc, home: string, cwd: string, options?: {
|
|
36
39
|
includeLayers?: boolean;
|
|
37
40
|
requireReady?: boolean;
|
|
38
41
|
readiness?: boolean;
|
|
42
|
+
guard?: NativeSafetyName;
|
|
39
43
|
}): Promise<{
|
|
40
44
|
guard: NativeGuard;
|
|
41
45
|
discovery: unknown;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { connectCodexSafety, type CodexSafetyOptions } from "./codex-safety-check.js";
|
|
2
2
|
import { verifyNativeSafetyCommand } from "../native-safety.js";
|
|
3
|
+
import { type NativeSafetyName } from "./native-safety.js";
|
|
3
4
|
export declare class CodexTrustError extends Error {
|
|
4
5
|
readonly code: "input_invalid" | "native_changed" | "native_config_invalid" | "preimage_unsafe" | "trust_refused" | "trust_outcome_uncertain";
|
|
5
6
|
readonly operationId?: string | undefined;
|
|
@@ -16,6 +17,11 @@ interface Dependencies {
|
|
|
16
17
|
connect?: typeof connectCodexSafety;
|
|
17
18
|
verify?: typeof verifyNativeSafetyCommand;
|
|
18
19
|
}
|
|
20
|
+
/** `guard` selects the bundled native safety guard to trust (default
|
|
21
|
+
* trash-guard). Only `hooks.state[<that guard's key>]` is written. */
|
|
22
|
+
export type CodexSafetyTrustOptions = CodexSafetyOptions & {
|
|
23
|
+
guard?: NativeSafetyName;
|
|
24
|
+
};
|
|
19
25
|
export interface CodexTrustPlan {
|
|
20
26
|
schema: "hasna.hooks.codex-safety-trust/v1" | "hasna.hooks.codex-readiness-trust/v1";
|
|
21
27
|
planDigest: string;
|
|
@@ -26,24 +32,29 @@ export interface CodexTrustPlan {
|
|
|
26
32
|
configPath: string;
|
|
27
33
|
configVersion: string;
|
|
28
34
|
action: "unchanged" | "trust_and_enable";
|
|
35
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
36
|
+
* keep their earlier exact shape. Either way the digest binds the guard: by
|
|
37
|
+
* this field, and by the discovered definition it covers, whose command names it. */
|
|
38
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
29
39
|
guardVerified: boolean;
|
|
30
40
|
readinessRunnerVerified?: true;
|
|
31
41
|
nativeAdoptionVerified: false;
|
|
32
42
|
}
|
|
33
|
-
export declare const planCodexSafetyTrust: (options?:
|
|
34
|
-
export declare const applyCodexSafetyTrust: (options:
|
|
43
|
+
export declare const planCodexSafetyTrust: (options?: CodexSafetyTrustOptions, dependencies?: Dependencies) => Promise<CodexTrustPlan>;
|
|
44
|
+
export declare const applyCodexSafetyTrust: (options: CodexSafetyTrustOptions & {
|
|
35
45
|
expectedPlanDigest: string;
|
|
36
46
|
}, dependencies?: Dependencies) => Promise<{
|
|
37
47
|
nativeDiscoveryVerified: boolean;
|
|
38
48
|
nativeAdoptionVerified: boolean;
|
|
39
49
|
unrelatedConfigurationPreserved: boolean;
|
|
40
50
|
readinessRunnerVerified?: boolean | undefined;
|
|
51
|
+
guardVerified: boolean;
|
|
52
|
+
guard?: "workspace-repos-guard" | undefined;
|
|
41
53
|
ok: boolean;
|
|
42
54
|
changed: boolean;
|
|
43
55
|
operationId: string;
|
|
44
56
|
planDigest: string;
|
|
45
57
|
configVersion: any;
|
|
46
|
-
guardVerified: boolean;
|
|
47
58
|
} | {
|
|
48
59
|
schema: "hasna.hooks.codex-safety-trust/v1" | "hasna.hooks.codex-readiness-trust/v1";
|
|
49
60
|
planDigest: string;
|
|
@@ -54,6 +65,10 @@ export declare const applyCodexSafetyTrust: (options: CodexSafetyOptions & {
|
|
|
54
65
|
configPath: string;
|
|
55
66
|
configVersion: string;
|
|
56
67
|
action: "unchanged" | "trust_and_enable";
|
|
68
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
69
|
+
* keep their earlier exact shape. Either way the digest binds the guard: by
|
|
70
|
+
* this field, and by the discovered definition it covers, whose command names it. */
|
|
71
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
57
72
|
guardVerified: boolean;
|
|
58
73
|
readinessRunnerVerified?: true;
|
|
59
74
|
nativeAdoptionVerified: false;
|
|
@@ -68,12 +83,13 @@ export declare const applyCodexReadinessTrust: (options: CodexSafetyOptions & {
|
|
|
68
83
|
nativeAdoptionVerified: boolean;
|
|
69
84
|
unrelatedConfigurationPreserved: boolean;
|
|
70
85
|
readinessRunnerVerified?: boolean | undefined;
|
|
86
|
+
guardVerified: boolean;
|
|
87
|
+
guard?: "workspace-repos-guard" | undefined;
|
|
71
88
|
ok: boolean;
|
|
72
89
|
changed: boolean;
|
|
73
90
|
operationId: string;
|
|
74
91
|
planDigest: string;
|
|
75
92
|
configVersion: any;
|
|
76
|
-
guardVerified: boolean;
|
|
77
93
|
} | {
|
|
78
94
|
schema: "hasna.hooks.codex-safety-trust/v1" | "hasna.hooks.codex-readiness-trust/v1";
|
|
79
95
|
planDigest: string;
|
|
@@ -84,6 +100,10 @@ export declare const applyCodexReadinessTrust: (options: CodexSafetyOptions & {
|
|
|
84
100
|
configPath: string;
|
|
85
101
|
configVersion: string;
|
|
86
102
|
action: "unchanged" | "trust_and_enable";
|
|
103
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
104
|
+
* keep their earlier exact shape. Either way the digest binds the guard: by
|
|
105
|
+
* this field, and by the discovered definition it covers, whose command names it. */
|
|
106
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
87
107
|
guardVerified: boolean;
|
|
88
108
|
readinessRunnerVerified?: true;
|
|
89
109
|
nativeAdoptionVerified: false;
|
package/dist/lib/installer.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type HookEvent, type HookMeta } from "./registry.js";
|
|
13
13
|
import { type StaleRegistration } from "./registration.js";
|
|
14
|
+
import { type NativeSafetyName } from "./native-safety.js";
|
|
14
15
|
import { type MementosRegistration } from "./mementos-options.js";
|
|
15
16
|
export type Scope = "global" | "project";
|
|
16
17
|
export type Target = "claude" | "gemini" | "codewith" | "codex" | "all";
|
|
@@ -85,8 +86,12 @@ export declare function detectRewriteConflict(name: string, scope: Scope, target
|
|
|
85
86
|
/** Injected for tests: the rewrite claim is a registry concern, the overlap is not. */
|
|
86
87
|
lookup?: (hookName: string) => HookMeta | undefined): string | undefined;
|
|
87
88
|
export declare function installHook(name: string, options?: InstallOptions): InstallResult;
|
|
88
|
-
/** Render through the installer without writing settings or trust state.
|
|
89
|
-
|
|
89
|
+
/** Render through the installer without writing settings or trust state.
|
|
90
|
+
* The rewrite-conflict check is the installer's own, per guard: it refuses only
|
|
91
|
+
* a guard that rewrites tool input (trash-guard) beside another input rewriter
|
|
92
|
+
* on an overlapping matcher. workspace-repos-guard only denies, and a denial is
|
|
93
|
+
* not lost to another hook's rewrite, so no rewrite conflict applies to it. */
|
|
94
|
+
export declare function previewNativeSafetyRegistration(target: "codex" | "claude", scope?: Scope, guard?: NativeSafetyName): {
|
|
90
95
|
before: string | null;
|
|
91
96
|
after: string;
|
|
92
97
|
command: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { verifyNativeSafetyCommand } from "../native-safety.js";
|
|
2
|
+
import { type NativeSafetyName } from "./native-safety.js";
|
|
2
3
|
/** The definite cause of a refusal by the owning settings writer, before it could change the target. */
|
|
3
4
|
export interface RegistrationRefusal {
|
|
4
5
|
code: string;
|
|
@@ -15,8 +16,12 @@ export declare class NativeRegistrationError extends Error {
|
|
|
15
16
|
readonly refusal?: RegistrationRefusal | undefined;
|
|
16
17
|
constructor(code: "input_invalid" | "settings_unsafe" | "settings_invalid" | "settings_changed" | "hooks_disabled" | "registration_conflict" | "guard_failed" | "writer_refused" | "apply_refused" | "apply_outcome_uncertain", operationId?: string | undefined, refusal?: RegistrationRefusal | undefined);
|
|
17
18
|
}
|
|
19
|
+
/** `guard` selects the bundled native safety guard (default trash-guard). Only
|
|
20
|
+
* that guard's own entry is rendered, verified and written; every other entry,
|
|
21
|
+
* a disabled one included, keeps its exact bytes. */
|
|
18
22
|
export interface NativeRegistrationOptions {
|
|
19
23
|
target: "codex" | "claude";
|
|
24
|
+
guard?: NativeSafetyName;
|
|
20
25
|
}
|
|
21
26
|
export interface NativeReadinessRegistrationOptions {
|
|
22
27
|
target: "codex" | "claude" | "sumi";
|
|
@@ -30,6 +35,10 @@ export interface NativeRegistrationPlan {
|
|
|
30
35
|
desiredSHA256: string;
|
|
31
36
|
commandSHA256: string;
|
|
32
37
|
action: "unchanged" | "register";
|
|
38
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
39
|
+
* keep their earlier exact shape. Either way the guard is bound into the
|
|
40
|
+
* digest: by this field, and by `commandSHA256`, whose command names it. */
|
|
41
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
33
42
|
planDigest: string;
|
|
34
43
|
guardVerified: boolean;
|
|
35
44
|
readinessRunnerVerified?: true;
|
|
@@ -59,12 +68,13 @@ export declare const applyNativeSafetyRegistration: (options: NativeRegistration
|
|
|
59
68
|
}, dependencies?: Dependencies) => Promise<{
|
|
60
69
|
nativeAdoptionVerified: boolean;
|
|
61
70
|
readinessRunnerVerified?: boolean | undefined;
|
|
71
|
+
guardVerified: boolean;
|
|
72
|
+
guard?: "workspace-repos-guard" | undefined;
|
|
62
73
|
ok: boolean;
|
|
63
74
|
changed: boolean;
|
|
64
75
|
operationId: `${string}-${string}-${string}-${string}-${string}`;
|
|
65
76
|
planDigest: string;
|
|
66
77
|
settingsSHA256: string;
|
|
67
|
-
guardVerified: boolean;
|
|
68
78
|
} | {
|
|
69
79
|
schema: "hasna.hooks.native-safety-registration/v1" | "hasna.hooks.native-readiness-registration/v1";
|
|
70
80
|
target: "codex" | "claude" | "sumi";
|
|
@@ -74,6 +84,10 @@ export declare const applyNativeSafetyRegistration: (options: NativeRegistration
|
|
|
74
84
|
desiredSHA256: string;
|
|
75
85
|
commandSHA256: string;
|
|
76
86
|
action: "unchanged" | "register";
|
|
87
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
88
|
+
* keep their earlier exact shape. Either way the guard is bound into the
|
|
89
|
+
* digest: by this field, and by `commandSHA256`, whose command names it. */
|
|
90
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
77
91
|
planDigest: string;
|
|
78
92
|
guardVerified: boolean;
|
|
79
93
|
readinessRunnerVerified?: true;
|
|
@@ -88,12 +102,13 @@ export declare const applyNativeReadinessRegistration: (options: NativeReadiness
|
|
|
88
102
|
}, sumiDependencies?: SumiRegistrationDependencies) => Promise<{
|
|
89
103
|
nativeAdoptionVerified: boolean;
|
|
90
104
|
readinessRunnerVerified?: boolean | undefined;
|
|
105
|
+
guardVerified: boolean;
|
|
106
|
+
guard?: "workspace-repos-guard" | undefined;
|
|
91
107
|
ok: boolean;
|
|
92
108
|
changed: boolean;
|
|
93
109
|
operationId: `${string}-${string}-${string}-${string}-${string}`;
|
|
94
110
|
planDigest: string;
|
|
95
111
|
settingsSHA256: string;
|
|
96
|
-
guardVerified: boolean;
|
|
97
112
|
} | {
|
|
98
113
|
schema: "hasna.hooks.native-safety-registration/v1" | "hasna.hooks.native-readiness-registration/v1";
|
|
99
114
|
target: "codex" | "claude" | "sumi";
|
|
@@ -103,6 +118,10 @@ export declare const applyNativeReadinessRegistration: (options: NativeReadiness
|
|
|
103
118
|
desiredSHA256: string;
|
|
104
119
|
commandSHA256: string;
|
|
105
120
|
action: "unchanged" | "register";
|
|
121
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
122
|
+
* keep their earlier exact shape. Either way the guard is bound into the
|
|
123
|
+
* digest: by this field, and by `commandSHA256`, whose command names it. */
|
|
124
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
106
125
|
planDigest: string;
|
|
107
126
|
guardVerified: boolean;
|
|
108
127
|
readinessRunnerVerified?: true;
|
|
@@ -127,6 +146,10 @@ export declare const applyNativeReadinessRegistration: (options: NativeReadiness
|
|
|
127
146
|
desiredSHA256: string;
|
|
128
147
|
commandSHA256: string;
|
|
129
148
|
action: "unchanged" | "register";
|
|
149
|
+
/** Present only for a guard other than trash-guard, whose plans and digests
|
|
150
|
+
* keep their earlier exact shape. Either way the guard is bound into the
|
|
151
|
+
* digest: by this field, and by `commandSHA256`, whose command names it. */
|
|
152
|
+
guard?: Exclude<NativeSafetyName, "trash-guard">;
|
|
130
153
|
planDigest: string;
|
|
131
154
|
guardVerified: boolean;
|
|
132
155
|
readinessRunnerVerified?: true;
|
package/dist/native-safety.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NativeSafetyName } from "./lib/native-safety.js";
|
|
1
2
|
export declare class NativeSafetyError extends Error {
|
|
2
3
|
readonly code: "binding_missing" | "binding_invalid" | "binding_changed" | "binding_busy" | "guard_failed" | "input_invalid";
|
|
3
4
|
readonly reason?: string | undefined;
|
|
@@ -86,8 +87,15 @@ export declare function evaluateNativeSafetyForExecution(event: NativeSafetyEven
|
|
|
86
87
|
}): Promise<NativeSafetyExecutionDecision>;
|
|
87
88
|
/** Classify a synthetic removal through this exact supervisor without executing
|
|
88
89
|
* the returned command or creating a file. A harmless ':' would not test whether
|
|
89
|
-
* the saved PATH can actually resolve Trash.
|
|
90
|
-
|
|
90
|
+
* the saved PATH can actually resolve Trash.
|
|
91
|
+
*
|
|
92
|
+
* `guard` names the capability the command must carry, with the same home.
|
|
93
|
+
* trash-guard must rewrite the removal into Trash. workspace-repos-guard never
|
|
94
|
+
* rewrites, so its probe is a removal below the protected clones root, which it
|
|
95
|
+
* refuses from the path alone: the exact deny proves the pinned runtime and
|
|
96
|
+
* worker, the worker's execution and its classification. Neither probe runs the
|
|
97
|
+
* removal, and neither path is created. */
|
|
98
|
+
export declare function verifyNativeSafetyCommand(command: string, home?: string, guard?: NativeSafetyName): Promise<void>;
|
|
91
99
|
export declare function verifyNativeSafetyRegistration(home?: string): Promise<{
|
|
92
100
|
path: string;
|
|
93
101
|
sha256: string;
|
package/dist/native-safety.js
CHANGED
|
@@ -382,8 +382,25 @@ async function evaluateRecord(event, record, signal, executionAgent) {
|
|
|
382
382
|
} catch {}
|
|
383
383
|
throw new NativeSafetyError("guard_failed");
|
|
384
384
|
}
|
|
385
|
-
async function verifyNativeSafetyCommand(command, home = homedir2()) {
|
|
385
|
+
async function verifyNativeSafetyCommand(command, home = homedir2(), guard = "trash-guard") {
|
|
386
|
+
if (guard !== "trash-guard" && guard !== "workspace-repos-guard")
|
|
387
|
+
throw new NativeSafetyError("input_invalid");
|
|
386
388
|
home = canonicalHome(home);
|
|
389
|
+
if (guard === "workspace-repos-guard") {
|
|
390
|
+
const binding = nativeSafetyCommandBinding(command);
|
|
391
|
+
if (binding?.name !== guard || binding.home !== home)
|
|
392
|
+
throw new NativeSafetyError("binding_invalid");
|
|
393
|
+
const root = join2(home, ".hasna", "repos", "clones"), probe = join2(root, ".hasna-workspace-repos-verification-only");
|
|
394
|
+
const verdict2 = await evaluateRecord({
|
|
395
|
+
hook_event_name: "PreToolUse",
|
|
396
|
+
tool_name: "Bash",
|
|
397
|
+
cwd: home,
|
|
398
|
+
tool_input: { command: "rm -- '" + probe.replaceAll("'", "'\\''") + "'" }
|
|
399
|
+
}, { schema: "hasna.hooks.native-safety.v1", harness: "sumi", command });
|
|
400
|
+
if (verdict2.decision !== "deny" || verdict2.reason !== `[workspace-repos-guard] delete under the protected repo-checkout root (${root}) is forbidden at any depth: ${probe}`)
|
|
401
|
+
throw new NativeSafetyError("guard_failed", verdict2.decision === "deny" ? verdict2.reason.slice(0, 512) : undefined);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
387
404
|
const record = parseRecord(JSON.stringify({ schema: "hasna.hooks.native-safety.v1", harness: "sumi", command }), home);
|
|
388
405
|
const verdict = await evaluateRecord({ hook_event_name: "PreToolUse", tool_name: "Bash", cwd: home, tool_input: { command: "rm -- .hasna-trash-verification-only" } }, record);
|
|
389
406
|
if (verdict.decision !== "rewrite")
|