@hasna/hooks 0.12.8 → 0.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/bin/hooks-mcp.js +13 -7
- package/bin/index.js +86 -47
- package/bin/native-safety-worker.cjs +1 -1
- 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/package.json +2 -2
package/README.md
CHANGED
|
@@ -235,6 +235,16 @@ hooks safety registration-apply --target codex --expected-plan-digest PLAN_SHA25
|
|
|
235
235
|
# The same two commands support --target claude.
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
+
Both commands, and `trust-plan`/`trust-apply` below, take
|
|
239
|
+
`--guard trash-guard|workspace-repos-guard` (default `trash-guard`). Only the
|
|
240
|
+
selected guard's own entry is rendered and written; every other entry, a
|
|
241
|
+
disabled one included, keeps its exact bytes. A plan digest for one guard is
|
|
242
|
+
never accepted by an apply for the other. trash-guard is verified by having its
|
|
243
|
+
supervisor rewrite a synthetic removal into Trash; workspace-repos-guard, which
|
|
244
|
+
never rewrites, by having its supervisor refuse a synthetic removal below
|
|
245
|
+
`~/.hasna/repos/clones` with the guard's exact reason. Neither removal is run,
|
|
246
|
+
and neither path is created.
|
|
247
|
+
|
|
238
248
|
Apply checks the exact predecessor, retains an owner-only original and intent,
|
|
239
249
|
and reads back the result. An identical registration returns unchanged without
|
|
240
250
|
rewriting its settings. The planner honors `CODEX_HOME` and `CLAUDE_CONFIG_DIR`;
|
|
@@ -289,13 +299,16 @@ CLI (`hooks --version`), after installing that version:
|
|
|
289
299
|
hooks safety registration-plan --target claude
|
|
290
300
|
hooks safety registration-apply --target claude --expected-plan-digest PLAN_SHA256
|
|
291
301
|
# Only where the repository guard is registered under its own name:
|
|
292
|
-
hooks safety
|
|
302
|
+
hooks safety registration-plan --target claude --guard workspace-repos-guard
|
|
303
|
+
hooks safety registration-apply --target claude --guard workspace-repos-guard --expected-plan-digest PLAN_SHA256
|
|
293
304
|
|
|
294
305
|
# Codex (a changed definition runs only after it is trusted again)
|
|
295
306
|
hooks safety registration-plan --target codex
|
|
296
307
|
hooks safety registration-apply --target codex --expected-plan-digest PLAN_SHA256
|
|
297
308
|
hooks safety trust-plan --target codex --cwd /path/to/project --codex-command /absolute/path/to/native/codex
|
|
298
309
|
hooks safety trust-apply --target codex --cwd /path/to/project --codex-command /absolute/path/to/native/codex --expected-plan-digest PLAN_SHA256
|
|
310
|
+
# Where Codex runs the repository guard under its own name, repeat the four
|
|
311
|
+
# Codex commands with --guard workspace-repos-guard.
|
|
299
312
|
|
|
300
313
|
# Sumi
|
|
301
314
|
hooks safety verify --target sumi # prints the current binding's sha256
|
package/bin/hooks-mcp.js
CHANGED
|
@@ -3374,7 +3374,7 @@ import { existsSync as existsSync11, lstatSync as lstatSync8 } from "fs";
|
|
|
3374
3374
|
import { homedir as homedir6 } from "os";
|
|
3375
3375
|
import { join as join11, resolve as resolve9 } from "path";
|
|
3376
3376
|
|
|
3377
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
3377
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.55+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
3378
3378
|
import { existsSync as existsSync10 } from "fs";
|
|
3379
3379
|
import { homedir as homedir5 } from "os";
|
|
3380
3380
|
import { join as join10, resolve as resolve4 } from "path";
|
|
@@ -3742,7 +3742,7 @@ class KernelLock {
|
|
|
3742
3742
|
}
|
|
3743
3743
|
}
|
|
3744
3744
|
|
|
3745
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
3745
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.55+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
3746
3746
|
import { execFileSync } from "child_process";
|
|
3747
3747
|
import { createHash as createHash12 } from "crypto";
|
|
3748
3748
|
import { accessSync, constants as constants6, lstatSync as lstatSync12, readFileSync as readFileSync11, realpathSync as realpathSync32, statSync as statSync7 } from "fs";
|
|
@@ -11555,7 +11555,8 @@ var MEASURED_CODEX_CAPABILITIES = {
|
|
|
11555
11555
|
"codex-cli 0.159.0": ["hooks"],
|
|
11556
11556
|
"codex-cli 0.159.2": ["hooks", "qualified-skill-catalog"],
|
|
11557
11557
|
"codex-cli 0.160.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
11558
|
-
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
11558
|
+
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
11559
|
+
"codex-cli 0.161.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
11559
11560
|
};
|
|
11560
11561
|
function supportsCodexNativeCapability(version, capability) {
|
|
11561
11562
|
return typeof version === "string" && Object.hasOwn(MEASURED_CODEX_CAPABILITIES, version) && MEASURED_CODEX_CAPABILITIES[version].includes(capability);
|
|
@@ -12910,7 +12911,7 @@ function validateResolvedProfile(profile, authority) {
|
|
|
12910
12911
|
}
|
|
12911
12912
|
var package_default = {
|
|
12912
12913
|
name: "@hasna/skills",
|
|
12913
|
-
version: "0.10.
|
|
12914
|
+
version: "0.10.55",
|
|
12914
12915
|
description: "Skills library for AI coding agents",
|
|
12915
12916
|
type: "module",
|
|
12916
12917
|
bin: {
|
|
@@ -17061,12 +17062,17 @@ function retiredCodexRoots(binding) {
|
|
|
17061
17062
|
}
|
|
17062
17063
|
return proof.roots;
|
|
17063
17064
|
}
|
|
17065
|
+
function retainableAbsentSource(source) {
|
|
17066
|
+
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined)
|
|
17067
|
+
return false;
|
|
17068
|
+
return [undefined, "bytes"].includes(source.hashMode) || source.hashMode === "claude-plugin-manifest-v1" && source.sha256 !== null && source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json"));
|
|
17069
|
+
}
|
|
17064
17070
|
function absentRetiredClaudeRoots(binding) {
|
|
17065
17071
|
if (binding.agent !== "claude" || binding.method !== "reviewed")
|
|
17066
17072
|
return [];
|
|
17067
17073
|
const result = new Set;
|
|
17068
17074
|
for (const source of binding.sources) {
|
|
17069
|
-
if (
|
|
17075
|
+
if (!retainableAbsentSource(source) || source.sha256 === null)
|
|
17070
17076
|
continue;
|
|
17071
17077
|
const marker = sep8 + ".claude" + sep8 + "plugins" + sep8 + "cache" + sep8, at = source.path.indexOf(marker);
|
|
17072
17078
|
if (at < 0 || source.path.indexOf(marker, at + 1) >= 0)
|
|
@@ -17178,7 +17184,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
17178
17184
|
safe4(source.path);
|
|
17179
17185
|
continue;
|
|
17180
17186
|
}
|
|
17181
|
-
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
17187
|
+
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)) {
|
|
17182
17188
|
safe4(source.path);
|
|
17183
17189
|
continue;
|
|
17184
17190
|
}
|
|
@@ -17234,7 +17240,7 @@ function rebindAgentDiscovery(binding, changes) {
|
|
|
17234
17240
|
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
17235
17241
|
const rebound = { ...binding, sources: binding.sources.map((source) => {
|
|
17236
17242
|
assertMarketplaceBinding(binding, source);
|
|
17237
|
-
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
17243
|
+
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)))
|
|
17238
17244
|
return source;
|
|
17239
17245
|
const sha2563 = projected(source, changes, budget2);
|
|
17240
17246
|
if (!changes.has(source.path) && sha2563 !== source.sha256)
|
package/bin/index.js
CHANGED
|
@@ -2879,7 +2879,7 @@ var init_kernel_lock = __esm(() => {
|
|
|
2879
2879
|
};
|
|
2880
2880
|
});
|
|
2881
2881
|
|
|
2882
|
-
// ../../node_modules/.bun/@hasna+skills@0.10.
|
|
2882
|
+
// ../../node_modules/.bun/@hasna+skills@0.10.55+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
|
|
2883
2883
|
import { existsSync as existsSync10 } from "fs";
|
|
2884
2884
|
import { homedir as homedir6 } from "os";
|
|
2885
2885
|
import { join as join11, resolve as resolve5 } from "path";
|
|
@@ -8620,12 +8620,17 @@ function retiredCodexRoots(binding) {
|
|
|
8620
8620
|
}
|
|
8621
8621
|
return proof.roots;
|
|
8622
8622
|
}
|
|
8623
|
+
function retainableAbsentSource(source) {
|
|
8624
|
+
if (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined)
|
|
8625
|
+
return false;
|
|
8626
|
+
return [undefined, "bytes"].includes(source.hashMode) || source.hashMode === "claude-plugin-manifest-v1" && source.sha256 !== null && source.path.endsWith(join32(sep8, ".claude-plugin", "plugin.json"));
|
|
8627
|
+
}
|
|
8623
8628
|
function absentRetiredClaudeRoots(binding) {
|
|
8624
8629
|
if (binding.agent !== "claude" || binding.method !== "reviewed")
|
|
8625
8630
|
return [];
|
|
8626
8631
|
const result = new Set;
|
|
8627
8632
|
for (const source of binding.sources) {
|
|
8628
|
-
if (
|
|
8633
|
+
if (!retainableAbsentSource(source) || source.sha256 === null)
|
|
8629
8634
|
continue;
|
|
8630
8635
|
const marker = sep8 + ".claude" + sep8 + "plugins" + sep8 + "cache" + sep8, at = source.path.indexOf(marker);
|
|
8631
8636
|
if (at < 0 || source.path.indexOf(marker, at + 1) >= 0)
|
|
@@ -8737,7 +8742,7 @@ function verifyAgentDiscovery(binding, codexRecovery) {
|
|
|
8737
8742
|
safe4(source.path);
|
|
8738
8743
|
continue;
|
|
8739
8744
|
}
|
|
8740
|
-
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
8745
|
+
if (absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)) {
|
|
8741
8746
|
safe4(source.path);
|
|
8742
8747
|
continue;
|
|
8743
8748
|
}
|
|
@@ -8793,7 +8798,7 @@ function rebindAgentDiscovery(binding, changes) {
|
|
|
8793
8798
|
const installationRoots = codexInstallationRoots(binding), absentRoots = [...absentCodexSkillRoots(binding), ...absentRetiredClaudeRoots(binding), ...retiredCodexRoots(binding).filter((root2) => !lstatSync25(root2, { throwIfNoEntry: false }))];
|
|
8794
8799
|
const rebound = { ...binding, sources: binding.sources.map((source) => {
|
|
8795
8800
|
assertMarketplaceBinding(binding, source);
|
|
8796
|
-
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) &&
|
|
8801
|
+
if (!changes.has(source.path) && (installationRoots.some((root2) => source.path.startsWith(root2 + sep8)) || absentRoots.some((root2) => source.path.startsWith(root2 + sep8)) && retainableAbsentSource(source)))
|
|
8797
8802
|
return source;
|
|
8798
8803
|
const sha2563 = projected(source, changes, budget2);
|
|
8799
8804
|
if (!changes.has(source.path) && sha2563 !== source.sha256)
|
|
@@ -30274,7 +30279,8 @@ ${end.comment}` : end.comment;
|
|
|
30274
30279
|
"codex-cli 0.159.0": ["hooks"],
|
|
30275
30280
|
"codex-cli 0.159.2": ["hooks", "qualified-skill-catalog"],
|
|
30276
30281
|
"codex-cli 0.160.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
30277
|
-
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
30282
|
+
"codex-cli 0.160.1": ["hooks", "qualified-skill-catalog", "installed-plugin-review"],
|
|
30283
|
+
"codex-cli 0.161.0": ["hooks", "qualified-skill-catalog", "installed-plugin-review"]
|
|
30278
30284
|
};
|
|
30279
30285
|
SUPPORTED_CODEX_HOOK_VERSIONS = Object.freeze(Object.keys(MEASURED_CODEX_CAPABILITIES).filter((version) => supportsCodexNativeCapability(version, "hooks")));
|
|
30280
30286
|
NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
@@ -30514,7 +30520,7 @@ ${end.comment}` : end.comment;
|
|
|
30514
30520
|
MAX_CACHED_PROFILE_AGE_MS = 24 * 60 * 60 * 1000;
|
|
30515
30521
|
package_default = {
|
|
30516
30522
|
name: "@hasna/skills",
|
|
30517
|
-
version: "0.10.
|
|
30523
|
+
version: "0.10.55",
|
|
30518
30524
|
description: "Skills library for AI coding agents",
|
|
30519
30525
|
type: "module",
|
|
30520
30526
|
bin: {
|
|
@@ -37490,16 +37496,18 @@ function installHook(name, options = {}) {
|
|
|
37490
37496
|
}
|
|
37491
37497
|
return installForTarget(name, scope, overwrite, target, profile, codewithMode, codewithConfigPath, mementos, expectedSettingsSha256, beforeWrite);
|
|
37492
37498
|
}
|
|
37493
|
-
function previewNativeSafetyRegistration(target, scope = "global") {
|
|
37494
|
-
|
|
37499
|
+
function previewNativeSafetyRegistration(target, scope = "global", guard = "trash-guard") {
|
|
37500
|
+
if (!isNativeSafetyName(guard))
|
|
37501
|
+
throw new Error("Unknown native safety guard");
|
|
37502
|
+
const conflict = detectRewriteConflict(guard, scope, target);
|
|
37495
37503
|
if (conflict)
|
|
37496
37504
|
throw new Error("Conflicting input rewriter; reconcile it before installing the safety guard.");
|
|
37497
37505
|
let result;
|
|
37498
|
-
registerHook(
|
|
37506
|
+
registerHook(guard, scope, target, undefined, undefined, (settings) => {
|
|
37499
37507
|
const before = target === "codex" ? capturedCodexSettings(settings) : settingsPreimages.get(settings)?.text;
|
|
37500
37508
|
if (before === undefined)
|
|
37501
37509
|
throw new Error("Hook settings require a valid captured preimage.");
|
|
37502
|
-
const command = installedNativeSafetyCommand(
|
|
37510
|
+
const command = installedNativeSafetyCommand(guard);
|
|
37503
37511
|
result = { before, after: JSON.stringify(settings, null, 2) + `
|
|
37504
37512
|
`, command };
|
|
37505
37513
|
});
|
|
@@ -38214,8 +38222,25 @@ async function evaluateRecord(event, record4, signal, executionAgent) {
|
|
|
38214
38222
|
} catch {}
|
|
38215
38223
|
throw new NativeSafetyError("guard_failed");
|
|
38216
38224
|
}
|
|
38217
|
-
async function verifyNativeSafetyCommand(command, home = homedir9()) {
|
|
38225
|
+
async function verifyNativeSafetyCommand(command, home = homedir9(), guard = "trash-guard") {
|
|
38226
|
+
if (guard !== "trash-guard" && guard !== "workspace-repos-guard")
|
|
38227
|
+
throw new NativeSafetyError("input_invalid");
|
|
38218
38228
|
home = canonicalHome(home);
|
|
38229
|
+
if (guard === "workspace-repos-guard") {
|
|
38230
|
+
const binding = nativeSafetyCommandBinding(command);
|
|
38231
|
+
if (binding?.name !== guard || binding.home !== home)
|
|
38232
|
+
throw new NativeSafetyError("binding_invalid");
|
|
38233
|
+
const root = join14(home, ".hasna", "repos", "clones"), probe = join14(root, ".hasna-workspace-repos-verification-only");
|
|
38234
|
+
const verdict2 = await evaluateRecord({
|
|
38235
|
+
hook_event_name: "PreToolUse",
|
|
38236
|
+
tool_name: "Bash",
|
|
38237
|
+
cwd: home,
|
|
38238
|
+
tool_input: { command: "rm -- '" + probe.replaceAll("'", "'\\''") + "'" }
|
|
38239
|
+
}, { schema: "hasna.hooks.native-safety.v1", harness: "sumi", command });
|
|
38240
|
+
if (verdict2.decision !== "deny" || verdict2.reason !== `[workspace-repos-guard] delete under the protected repo-checkout root (${root}) is forbidden at any depth: ${probe}`)
|
|
38241
|
+
throw new NativeSafetyError("guard_failed", verdict2.decision === "deny" ? verdict2.reason.slice(0, 512) : undefined);
|
|
38242
|
+
return;
|
|
38243
|
+
}
|
|
38219
38244
|
const record4 = parseRecord(JSON.stringify({ schema: "hasna.hooks.native-safety.v1", harness: "sumi", command }), home);
|
|
38220
38245
|
const verdict = await evaluateRecord({ hook_event_name: "PreToolUse", tool_name: "Bash", cwd: home, tool_input: { command: "rm -- .hasna-trash-verification-only" } }, record4);
|
|
38221
38246
|
if (verdict.decision !== "rewrite")
|
|
@@ -38410,6 +38435,7 @@ function validateSettings(raw) {
|
|
|
38410
38435
|
}
|
|
38411
38436
|
function inspect(options) {
|
|
38412
38437
|
need8(options?.target === "codex" || options?.target === "claude", "input_invalid");
|
|
38438
|
+
need8(options.readiness ? options.guard === "trash-guard" : isNativeSafetyName(options.guard), "input_invalid");
|
|
38413
38439
|
const home = realpathSync14(homedir10()), path = getSettingsPath("global", options.target);
|
|
38414
38440
|
need8(isAbsolute11(path) && resolve24(path) === path, "input_invalid");
|
|
38415
38441
|
const nativeHome = options.target === "codex" ? process.env.CODEX_HOME : process.env.CLAUDE_CONFIG_DIR;
|
|
@@ -38423,7 +38449,7 @@ function inspect(options) {
|
|
|
38423
38449
|
const parsed = validateSettings(before.raw);
|
|
38424
38450
|
let preview2;
|
|
38425
38451
|
try {
|
|
38426
|
-
preview2 =
|
|
38452
|
+
preview2 = options.readiness ? previewNativeReadinessRegistration(options.target) : previewNativeSafetyRegistration(options.target, "global", options.guard);
|
|
38427
38453
|
} catch {
|
|
38428
38454
|
throw new NativeRegistrationError("registration_conflict");
|
|
38429
38455
|
}
|
|
@@ -38439,6 +38465,7 @@ function inspect(options) {
|
|
|
38439
38465
|
desiredSHA256: changed ? sha6(preview2.after) : before.sha256,
|
|
38440
38466
|
commandSHA256: sha6(preview2.command),
|
|
38441
38467
|
action: changed ? "register" : "unchanged",
|
|
38468
|
+
...options.guard !== "trash-guard" ? { guard: options.guard } : {},
|
|
38442
38469
|
guardVerified: !options.readiness,
|
|
38443
38470
|
...options.readiness ? { readinessRunnerVerified: true } : {},
|
|
38444
38471
|
nativeAdoptionVerified: false
|
|
@@ -38494,7 +38521,7 @@ async function planRegistration(options, dependencies = {}) {
|
|
|
38494
38521
|
if (selected.readiness)
|
|
38495
38522
|
need8(nativeReadinessCommandVerified(before.preview.command), "guard_failed");
|
|
38496
38523
|
else
|
|
38497
|
-
await (dependencies.verify ?? verifyNativeSafetyCommand)(before.preview.command, before.home);
|
|
38524
|
+
await (dependencies.verify ?? verifyNativeSafetyCommand)(before.preview.command, before.home, selected.guard);
|
|
38498
38525
|
} catch {
|
|
38499
38526
|
throw new NativeRegistrationError("guard_failed");
|
|
38500
38527
|
}
|
|
@@ -38514,7 +38541,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
38514
38541
|
return { ok: true, changed: false, ...plan };
|
|
38515
38542
|
const operationId = randomUUID6();
|
|
38516
38543
|
let directory2 = before.home;
|
|
38517
|
-
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : "trash-registration", operationId]) {
|
|
38544
|
+
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : selected.guard === "trash-guard" ? "trash-registration" : selected.guard + "-registration", operationId]) {
|
|
38518
38545
|
directory2 = join16(directory2, part);
|
|
38519
38546
|
try {
|
|
38520
38547
|
mkdirSync12(directory2, { mode: 448 });
|
|
@@ -38538,7 +38565,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
38538
38565
|
if (selected.readiness)
|
|
38539
38566
|
installNativeReadinessRegistration(selected.target, plan.beforeSHA256, beforeWrite);
|
|
38540
38567
|
else {
|
|
38541
|
-
const result = installHook(
|
|
38568
|
+
const result = installHook(selected.guard, { target: selected.target, overwrite: true, expectedSettingsSha256: plan.beforeSHA256, beforeWrite });
|
|
38542
38569
|
if (!result.success)
|
|
38543
38570
|
throw Object.assign(new Error(result.error ?? "The installer refused the registration."), { code: result.code ?? "writer_refused" });
|
|
38544
38571
|
}
|
|
@@ -38551,6 +38578,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
38551
38578
|
operationId,
|
|
38552
38579
|
planDigest: plan.planDigest,
|
|
38553
38580
|
settingsSHA256: after.before.sha256,
|
|
38581
|
+
...plan.guard ? { guard: plan.guard } : {},
|
|
38554
38582
|
guardVerified: !selected.readiness,
|
|
38555
38583
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
38556
38584
|
nativeAdoptionVerified: false
|
|
@@ -38679,7 +38707,7 @@ async function applySumiRegistration(expectedPlanDigest, dependencies) {
|
|
|
38679
38707
|
var NativeRegistrationError, need8 = (value, code2) => {
|
|
38680
38708
|
if (!value)
|
|
38681
38709
|
throw new NativeRegistrationError(code2);
|
|
38682
|
-
}, sha6 = (value) => createHash13("sha256").update(value).digest("hex"), planNativeSafetyRegistration = (options, dependencies = {}) => planRegistration({ target: options.target }, dependencies), applyNativeSafetyRegistration = (options, dependencies = {}) => applyRegistration({ target: options.target, expectedPlanDigest: options.expectedPlanDigest }, dependencies), planNativeReadinessRegistration = (options, sumiDependencies = {}) => options?.target === "sumi" ? planSumiRegistration(sumiDependencies) : planRegistration({ target: options?.target, readiness: true }), applyNativeReadinessRegistration = (options, sumiDependencies = {}) => options?.target === "sumi" ? applySumiRegistration(options.expectedPlanDigest, sumiDependencies) : applyRegistration({ target: options?.target, expectedPlanDigest: options?.expectedPlanDigest, readiness: true });
|
|
38710
|
+
}, sha6 = (value) => createHash13("sha256").update(value).digest("hex"), planNativeSafetyRegistration = (options, dependencies = {}) => planRegistration({ target: options.target, guard: options.guard ?? "trash-guard" }, dependencies), applyNativeSafetyRegistration = (options, dependencies = {}) => applyRegistration({ target: options.target, guard: options.guard ?? "trash-guard", expectedPlanDigest: options.expectedPlanDigest }, dependencies), planNativeReadinessRegistration = (options, sumiDependencies = {}) => options?.target === "sumi" ? planSumiRegistration(sumiDependencies) : planRegistration({ target: options?.target, guard: "trash-guard", readiness: true }), applyNativeReadinessRegistration = (options, sumiDependencies = {}) => options?.target === "sumi" ? applySumiRegistration(options.expectedPlanDigest, sumiDependencies) : applyRegistration({ target: options?.target, guard: "trash-guard", expectedPlanDigest: options?.expectedPlanDigest, readiness: true });
|
|
38683
38711
|
var init_native_safety_registration = __esm(() => {
|
|
38684
38712
|
init_installer();
|
|
38685
38713
|
init_native_safety2();
|
|
@@ -38928,7 +38956,13 @@ function supportedDiscoveryWarnings(hooks, warnings) {
|
|
|
38928
38956
|
}
|
|
38929
38957
|
return warnings.every((warning) => typeof warning === "string" && allowed.delete(warning));
|
|
38930
38958
|
}
|
|
38931
|
-
function
|
|
38959
|
+
function codexSafetyMatcher(guard) {
|
|
38960
|
+
const meta3 = getHook(guard);
|
|
38961
|
+
need11(meta3, "guard_definition_invalid");
|
|
38962
|
+
return matcherFor(meta3, "codex");
|
|
38963
|
+
}
|
|
38964
|
+
function selectCodexSafety(discovery, configuration, home, cwd, featureEnabled, requireReady = true, readiness = false, guard = "trash-guard") {
|
|
38965
|
+
need11(readiness ? guard === "trash-guard" : guard === "trash-guard" || guard === "workspace-repos-guard", "guard_definition_invalid");
|
|
38932
38966
|
const data = discovery?.data;
|
|
38933
38967
|
need11(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");
|
|
38934
38968
|
const config2 = configuration?.config;
|
|
@@ -38942,11 +38976,11 @@ function selectCodexSafety(discovery, configuration, home, cwd, featureEnabled,
|
|
|
38942
38976
|
if (readiness && hook2.command.includes("hasna-native-readiness-v"))
|
|
38943
38977
|
need11(nativeReadinessCommandBinding(hook2.command), "guard_definition_invalid");
|
|
38944
38978
|
}
|
|
38945
|
-
const selected = data[0].hooks.filter((hook2) => typeof hook2?.command === "string" && (readiness ? !!nativeReadinessCommandBinding(hook2.command) : nativeSafetyCommandBinding(hook2.command)?.name ===
|
|
38979
|
+
const selected = data[0].hooks.filter((hook2) => typeof hook2?.command === "string" && (readiness ? !!nativeReadinessCommandBinding(hook2.command) : nativeSafetyCommandBinding(hook2.command)?.name === guard));
|
|
38946
38980
|
need11(selected.length !== 0, "guard_missing");
|
|
38947
38981
|
need11(selected.length === 1, "guard_ambiguous");
|
|
38948
38982
|
const hook = selected[0], binding = readiness ? nativeReadinessCommandBinding(hook.command) : nativeSafetyCommandBinding(hook.command);
|
|
38949
|
-
need11(binding.home === home && (!readiness || binding?.provider === "codex") && hook.eventName === (readiness ? "sessionStart" : "preToolUse") && hook.handlerType === "command" && hook.matcher === (readiness ? "^(startup|resume|clear|fork)$" :
|
|
38983
|
+
need11(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" && isAbsolute24(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");
|
|
38950
38984
|
need11(typeof hook.enabled === "boolean" && ["trusted", "untrusted", "modified"].includes(hook.trustStatus), "guard_definition_invalid");
|
|
38951
38985
|
if (requireReady) {
|
|
38952
38986
|
need11(hook.enabled === true, "guard_disabled");
|
|
@@ -38979,7 +39013,7 @@ async function readCodexSafety(rpc, home, cwd, options = {}) {
|
|
|
38979
39013
|
}
|
|
38980
39014
|
} while (cursor !== null);
|
|
38981
39015
|
}
|
|
38982
|
-
return { guard: selectCodexSafety(hooks, configuration, home, cwd, enabled, options.requireReady ?? true, options.readiness ?? false), discovery: hooks, configuration };
|
|
39016
|
+
return { guard: selectCodexSafety(hooks, configuration, home, cwd, enabled, options.requireReady ?? true, options.readiness ?? false, options.guard ?? "trash-guard"), discovery: hooks, configuration };
|
|
38983
39017
|
}
|
|
38984
39018
|
async function verifyCodexNativeSafety(options = {}, dependencies = {}) {
|
|
38985
39019
|
const home = realpathSync16(options.home ?? homedir12()), cwd = realpathSync16(options.cwd ?? process.cwd());
|
|
@@ -39012,9 +39046,10 @@ async function verifyCodexNativeSafety(options = {}, dependencies = {}) {
|
|
|
39012
39046
|
await rpc.close();
|
|
39013
39047
|
}
|
|
39014
39048
|
}
|
|
39015
|
-
var SUPPORTED_CODEX_SAFETY_VERSIONS, versions,
|
|
39049
|
+
var SUPPORTED_CODEX_SAFETY_VERSIONS, versions, CodexSafetyError, digest3 = (bytes) => createHash26("sha256").update(bytes).digest("hex");
|
|
39016
39050
|
var init_codex_safety_check = __esm(() => {
|
|
39017
39051
|
init_native_safety();
|
|
39052
|
+
init_registry();
|
|
39018
39053
|
init_native_readiness_command();
|
|
39019
39054
|
init_native_child_env();
|
|
39020
39055
|
init_native_safety2();
|
|
@@ -39117,8 +39152,8 @@ function exclusive2(path, bytes) {
|
|
|
39117
39152
|
}
|
|
39118
39153
|
syncDirectory3(dirname25(path));
|
|
39119
39154
|
}
|
|
39120
|
-
async function inspect2(rpc, home, cwd, readiness = false) {
|
|
39121
|
-
const observed = await readCodexSafety(rpc, home, cwd, { includeLayers: true, requireReady: false, readiness });
|
|
39155
|
+
async function inspect2(rpc, home, cwd, readiness = false, selected = "trash-guard") {
|
|
39156
|
+
const observed = await readCodexSafety(rpc, home, cwd, { includeLayers: true, requireReady: false, readiness, guard: selected });
|
|
39122
39157
|
const { guard, configuration, discovery } = observed;
|
|
39123
39158
|
const layers = configuration?.layers;
|
|
39124
39159
|
need12(Array.isArray(layers) && layers.length <= 1000, "native_config_invalid");
|
|
@@ -39143,6 +39178,7 @@ async function inspect2(rpc, home, cwd, readiness = false) {
|
|
|
39143
39178
|
configPath: path,
|
|
39144
39179
|
configVersion: layer.version,
|
|
39145
39180
|
action: guard.enabled && guard.trustStatus === "trusted" ? "unchanged" : "trust_and_enable",
|
|
39181
|
+
...!readiness && selected !== "trash-guard" ? { guard: selected } : {},
|
|
39146
39182
|
guardVerified: !readiness,
|
|
39147
39183
|
...readiness ? { readinessRunnerVerified: true } : {},
|
|
39148
39184
|
nativeAdoptionVerified: false
|
|
@@ -39151,22 +39187,23 @@ async function inspect2(rpc, home, cwd, readiness = false) {
|
|
|
39151
39187
|
return { ...observed, layer, layers, canonicalPath: canonicalPath2, before, desired, plan };
|
|
39152
39188
|
}
|
|
39153
39189
|
async function context2(options, dependencies) {
|
|
39190
|
+
need12(options.readiness ? options.guard === undefined : options.guard === undefined || isNativeSafetyName(options.guard), "input_invalid");
|
|
39154
39191
|
const home = realpathSync17(options.home ?? homedir13()), cwd = realpathSync17(options.cwd ?? process.cwd());
|
|
39155
39192
|
need12(isAbsolute26(home) && isAbsolute26(cwd), "input_invalid");
|
|
39156
39193
|
return { home, cwd, rpc: await (dependencies.connect ?? connectCodexSafety)({ ...options, home }) };
|
|
39157
39194
|
}
|
|
39158
|
-
async function verify(command, home, readiness, dependencies) {
|
|
39195
|
+
async function verify(command, home, readiness, dependencies, guard = "trash-guard") {
|
|
39159
39196
|
if (readiness)
|
|
39160
39197
|
need12(nativeReadinessCommandVerified(command));
|
|
39161
39198
|
else
|
|
39162
|
-
await (dependencies.verify ?? verifyNativeSafetyCommand)(command, home);
|
|
39199
|
+
await (dependencies.verify ?? verifyNativeSafetyCommand)(command, home, guard);
|
|
39163
39200
|
}
|
|
39164
39201
|
async function planTrust(options = {}, dependencies = {}) {
|
|
39165
39202
|
const { home, cwd, rpc } = await context2(options, dependencies);
|
|
39166
39203
|
try {
|
|
39167
|
-
const before = await inspect2(rpc, home, cwd, options.readiness);
|
|
39168
|
-
await verify(before.guard.command, home, !!options.readiness, dependencies);
|
|
39169
|
-
need12((await inspect2(rpc, home, cwd, options.readiness)).plan.planDigest === before.plan.planDigest);
|
|
39204
|
+
const before = await inspect2(rpc, home, cwd, options.readiness, options.guard);
|
|
39205
|
+
await verify(before.guard.command, home, !!options.readiness, dependencies, options.guard);
|
|
39206
|
+
need12((await inspect2(rpc, home, cwd, options.readiness, options.guard)).plan.planDigest === before.plan.planDigest);
|
|
39170
39207
|
return before.plan;
|
|
39171
39208
|
} finally {
|
|
39172
39209
|
await rpc.close();
|
|
@@ -39177,10 +39214,10 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
39177
39214
|
const selected = { ...options }, { home, cwd, rpc } = await context2(selected, dependencies);
|
|
39178
39215
|
let operationId, journal, requested = false;
|
|
39179
39216
|
try {
|
|
39180
|
-
const before = await inspect2(rpc, home, cwd, selected.readiness);
|
|
39217
|
+
const before = await inspect2(rpc, home, cwd, selected.readiness, selected.guard);
|
|
39181
39218
|
need12(before.plan.planDigest === selected.expectedPlanDigest);
|
|
39182
|
-
await verify(before.guard.command, home, !!selected.readiness, dependencies);
|
|
39183
|
-
need12((await inspect2(rpc, home, cwd, selected.readiness)).plan.planDigest === before.plan.planDigest);
|
|
39219
|
+
await verify(before.guard.command, home, !!selected.readiness, dependencies, selected.guard);
|
|
39220
|
+
need12((await inspect2(rpc, home, cwd, selected.readiness, selected.guard)).plan.planDigest === before.plan.planDigest);
|
|
39184
39221
|
if (before.plan.action === "unchanged")
|
|
39185
39222
|
return { ok: true, changed: false, ...before.plan };
|
|
39186
39223
|
const expectedConfiguration = structuredClone(before.configuration);
|
|
@@ -39196,7 +39233,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
39196
39233
|
expectedGuard.trustStatus = "trusted";
|
|
39197
39234
|
operationId = randomUUID7();
|
|
39198
39235
|
let directory2 = home;
|
|
39199
|
-
for (const part of [".hasna", "hooks", "native", selected.readiness ? "codex-readiness-trust" : "codex-trash-trust", operationId]) {
|
|
39236
|
+
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]) {
|
|
39200
39237
|
directory2 = join24(directory2, part);
|
|
39201
39238
|
try {
|
|
39202
39239
|
mkdirSync13(directory2, { mode: 448 });
|
|
@@ -39220,7 +39257,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
39220
39257
|
edits: [{ keyPath: "hooks.state." + JSON.stringify(before.guard.key), value: before.desired, mergeStrategy: "replace" }]
|
|
39221
39258
|
});
|
|
39222
39259
|
need12(result?.status === "ok" && result.filePath === before.plan.configPath && result.overriddenMetadata === null && /^sha256:[a-f0-9]{64}$/.test(result.version));
|
|
39223
|
-
const after = await inspect2(rpc, home, cwd, selected.readiness);
|
|
39260
|
+
const after = await inspect2(rpc, home, cwd, selected.readiness, selected.guard);
|
|
39224
39261
|
expectedLayer.version = result.version;
|
|
39225
39262
|
need12(after.layer.version === result.version && after.plan.action === "unchanged" && mergedConfiguration(after.configuration.config) === mergedConfiguration(expectedConfiguration.config) && canonical10(after.configuration.layers) === canonical10(expectedConfiguration.layers) && canonical10(after.discovery) === canonical10(expectedDiscovery));
|
|
39226
39263
|
const receipt = {
|
|
@@ -39229,6 +39266,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
39229
39266
|
operationId,
|
|
39230
39267
|
planDigest: before.plan.planDigest,
|
|
39231
39268
|
configVersion: result.version,
|
|
39269
|
+
...before.plan.guard ? { guard: before.plan.guard } : {},
|
|
39232
39270
|
guardVerified: !selected.readiness,
|
|
39233
39271
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
39234
39272
|
nativeDiscoveryVerified: true,
|
|
@@ -39263,6 +39301,7 @@ var init_codex_safety_trust = __esm(() => {
|
|
|
39263
39301
|
init_codex_safety_check();
|
|
39264
39302
|
init_native_safety2();
|
|
39265
39303
|
init_native_readiness_command();
|
|
39304
|
+
init_native_safety();
|
|
39266
39305
|
CodexTrustError = class CodexTrustError extends Error {
|
|
39267
39306
|
code;
|
|
39268
39307
|
operationId;
|
|
@@ -47478,18 +47517,18 @@ function wildcardToRegExp(pattern, options = {}) {
|
|
|
47478
47517
|
}
|
|
47479
47518
|
return new RegExp(`^${body}$`);
|
|
47480
47519
|
}
|
|
47481
|
-
function matchString(value,
|
|
47482
|
-
if (
|
|
47520
|
+
function matchString(value, matcher, options = {}) {
|
|
47521
|
+
if (matcher === undefined)
|
|
47483
47522
|
return true;
|
|
47484
47523
|
if (value === undefined)
|
|
47485
47524
|
return false;
|
|
47486
|
-
const matchers = Array.isArray(
|
|
47525
|
+
const matchers = Array.isArray(matcher) ? matcher : [matcher];
|
|
47487
47526
|
return matchers.some((item) => wildcardToRegExp(item, options).test(value));
|
|
47488
47527
|
}
|
|
47489
|
-
function matchRecord(input2,
|
|
47490
|
-
if (!
|
|
47528
|
+
function matchRecord(input2, matcher) {
|
|
47529
|
+
if (!matcher)
|
|
47491
47530
|
return true;
|
|
47492
|
-
return Object.entries(
|
|
47531
|
+
return Object.entries(matcher).every(([path, expected]) => {
|
|
47493
47532
|
const actualValues = getFieldValues(input2, path);
|
|
47494
47533
|
return matchField(actualValues, expected, path);
|
|
47495
47534
|
});
|
|
@@ -50629,9 +50668,9 @@ function readmePreview(readme, max = 280) {
|
|
|
50629
50668
|
return preview2 ? truncateText2(preview2, max) : undefined;
|
|
50630
50669
|
}
|
|
50631
50670
|
function hookSummaryLine(hook, options = {}) {
|
|
50632
|
-
const
|
|
50671
|
+
const matcher = hook.matcher ? ` ${hook.matcher}` : "";
|
|
50633
50672
|
const description = options.verbose ? ` - ${truncateText2(hook.description, 110)}` : "";
|
|
50634
|
-
return ` ${chalk2.cyan(hook.name.padEnd(17))} ${chalk2.dim(`[${hook.event}${
|
|
50673
|
+
return ` ${chalk2.cyan(hook.name.padEnd(17))} ${chalk2.dim(`[${hook.event}${matcher}]`)} ${chalk2.dim(hook.category)}${description}`;
|
|
50635
50674
|
}
|
|
50636
50675
|
function listStoreHooks() {
|
|
50637
50676
|
const out = [];
|
|
@@ -52372,14 +52411,14 @@ safety.command("install <guard>").option("--target <target>", "codex, claude or
|
|
|
52372
52411
|
process.exitCode = 1;
|
|
52373
52412
|
});
|
|
52374
52413
|
for (const action of ["registration-plan", "registration-apply"]) {
|
|
52375
|
-
const command = safety.command(action).requiredOption("--target <target>", "codex or claude").description(action === "registration-plan" ? "Plan a bounded
|
|
52414
|
+
const command = safety.command(action).requiredOption("--target <target>", "codex or claude").option("--guard <name>", "Bundled native safety guard: trash-guard or workspace-repos-guard", "trash-guard").description(action === "registration-plan" ? "Plan a bounded native safety guard registration without changing settings" : "Apply the exact planned registration and retain its private preimage");
|
|
52376
52415
|
if (action === "registration-apply")
|
|
52377
52416
|
command.requiredOption("--expected-plan-digest <sha256>", "Exact digest from registration-plan");
|
|
52378
52417
|
command.action(async (options) => {
|
|
52379
52418
|
try {
|
|
52380
|
-
if (options.target !== "codex" && options.target !== "claude")
|
|
52419
|
+
if (options.target !== "codex" && options.target !== "claude" || !isNativeSafetyName(options.guard))
|
|
52381
52420
|
throw new NativeRegistrationError("input_invalid");
|
|
52382
|
-
console.log(JSON.stringify(action === "registration-plan" ? await planNativeSafetyRegistration({ target: options.target }) : await applyNativeSafetyRegistration({ target: options.target, expectedPlanDigest: options.expectedPlanDigest })));
|
|
52421
|
+
console.log(JSON.stringify(action === "registration-plan" ? await planNativeSafetyRegistration({ target: options.target, guard: options.guard }) : await applyNativeSafetyRegistration({ target: options.target, guard: options.guard, expectedPlanDigest: options.expectedPlanDigest })));
|
|
52383
52422
|
} catch (error61) {
|
|
52384
52423
|
console.log(JSON.stringify({
|
|
52385
52424
|
ok: false,
|
|
@@ -52393,14 +52432,14 @@ for (const action of ["registration-plan", "registration-apply"]) {
|
|
|
52393
52432
|
});
|
|
52394
52433
|
}
|
|
52395
52434
|
for (const action of ["trust-plan", "trust-apply"]) {
|
|
52396
|
-
const command = safety.command(action).requiredOption("--target <target>", "codex").option("--cwd <path>", "Native project context").option("--codex-command <path>", "Installed native Codex executable").description(action === "trust-plan" ? "Inspect the exact bundled guard and prepare native trust without writing" : "Trust and enable only the exact planned guard through Codex's guarded native API");
|
|
52435
|
+
const command = safety.command(action).requiredOption("--target <target>", "codex").option("--cwd <path>", "Native project context").option("--codex-command <path>", "Installed native Codex executable").option("--guard <name>", "Bundled native safety guard: trash-guard or workspace-repos-guard", "trash-guard").description(action === "trust-plan" ? "Inspect the exact bundled guard and prepare native trust without writing" : "Trust and enable only the exact planned guard through Codex's guarded native API");
|
|
52397
52436
|
if (action === "trust-apply")
|
|
52398
52437
|
command.requiredOption("--expected-plan-digest <sha256>", "Exact digest returned by trust-plan");
|
|
52399
52438
|
command.action(async (options) => {
|
|
52400
52439
|
try {
|
|
52401
|
-
if (options.target !== "codex")
|
|
52440
|
+
if (options.target !== "codex" || !isNativeSafetyName(options.guard))
|
|
52402
52441
|
throw new CodexTrustError("input_invalid");
|
|
52403
|
-
const selected = { command: options.codexCommand, cwd: options.cwd, codexHome: process.env.CODEX_HOME };
|
|
52442
|
+
const selected = { command: options.codexCommand, cwd: options.cwd, codexHome: process.env.CODEX_HOME, ...options.guard === "trash-guard" ? {} : { guard: options.guard } };
|
|
52404
52443
|
console.log(JSON.stringify(action === "trust-plan" ? await planCodexSafetyTrust(selected) : await applyCodexSafetyTrust({ ...selected, expectedPlanDigest: options.expectedPlanDigest })));
|
|
52405
52444
|
} catch (error61) {
|
|
52406
52445
|
console.log(JSON.stringify({
|
|
@@ -22,4 +22,4 @@ var{defineProperty:oZ,getOwnPropertyNames:S2,getOwnPropertyDescriptor:b2}=Object
|
|
|
22
22
|
`).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(z==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let H=GZ(Z,Q),K=Z.indexOf(`
|
|
23
23
|
`,Q);if(!H||K<0)return null;let B=hZ(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function T0(Z,X,$){for(let J of D0(Z).bodies){let z=P0(J);if(z===null)continue;let Y=d(z,X+1,$.debug);if(Y.refused)return Y}return _}function d(Z,X=0,$=!1){if(typeof Z!=="string"||!Z.trim())return _;if(X>z5)return pZ.test(Z)?N("unclassifiable"):_;let{segments:J,trustworthy:z}=y0(Z);if(!z)return pZ.test(Z)?N("unclassifiable"):_;let Y=$,Q=(H)=>d(H,X+1,Y);for(let H of K5(Z)){if(H.runsBody){let K=Q(H.body);if(K.refused)return K}if(!H.quoted){let K=D0(H.body,"heredoc");if(!K.complete&&pZ.test(H.body))return N("unclassifiable");for(let B of K.bodies){let M=Q(B);if(M.refused)return M}}}for(let H=0;H<J.length;H++){let K=J[H];for(let W of K.words){let A=D0(W.text);if(!A.complete&&pZ.test(W.text))return N("unclassifiable");for(let w of A.bodies){let f=Q(w);if(f.refused)return f}}let B=p(K),M=K.words.map((W,A)=>({word:VZ(W.text),redirect:K.redirects.has(A)})),V=M.slice(0,B<0?M.length:B).map((W)=>W.word),G=B>=0?QZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Y=F2([...V,...M.slice(B+1).map((W)=>W.word)],Y),B<0)continue}let j=F2(V,Y),D=M.slice(B+1).filter((W)=>!W.redirect).map((W)=>W.word),v=M.slice(B+1).filter((W)=>W.redirect).map((W)=>W.word),b=M[B].word,E=QZ(b.value),JZ={depth:X,appendsArgs:!1,debug:j};if(B>0&&M[B-1].word.value==="function"){let W=D.filter((w)=>!["{","()","(",")"].includes(w.value)),A=O0(W,JZ);if(A.refused)return A;continue}if(H>0&&L2(K.sepBefore)&&F0(E,D)){let W=J[H-1],A=Y5(Z,W),w=A===null?null:P0(A);if(w!==null){let f=d(w,X+1,j);if(f.refused)return f}}let i=J[H+1];if(i&&/<\(\s*$/.test(i.sepBefore)&&(iZ.has(E)||E==="source"||E===".")){let W=i.words[0].start-i.sepBefore.length+i.sepBefore.lastIndexOf("("),A=YZ(Z,W),w=A<0?null:P0(Z.slice(W+1,A-1));if(w!==null){let f=d(w,X+1,j);if(f.refused)return f}}let I=v2(E,b,D,v,K.words.slice(0,B+1),JZ);if(I.refused)return I}return _}function Y5(Z,X){let $=X.words[0],J=X.words[X.words.length-1];return $&&J?Z.slice($.start,J.end):null}function Q5(Z){let X=QZ(Z.value);return/[$`]/.test(X)||X===""?void 0:X}function v2(Z,X,$,J,z,Y){let Q=Y.depth,H=(K)=>d(K,Q+1,Y.debug);if(X.opaque){let K=Q5(X);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=cZ($,Y);if(!M.refused)return _;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&b4.has(B.value)?M:_}Z=K}if(Z==="gh")return cZ($,Y);if(iZ.has(Z)){let K=R0($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return T0(K.raw,Q,Y)}for(let B of J){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=T0(B.raw,Q,Y);if(V.refused)return V}}return _}if(t4.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):C0($,Y)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=T0(M.raw,Q,Y);if(V.refused)return V}return _}if(Z==="env")return H(PZ([...z.map((K)=>VZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let V=$[K].value;if(!V.startsWith("-"))break;if(J5.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):_}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if($5.has(M))K++}return O0($.slice(K),{depth:Q,appendsArgs:!B,debug:Y.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=O0($.slice(K+1,B),Y);if(M.refused)return M;K=B}return _}if(e4.has(Z))return C0($,Y);if(Z5.get(Z)?.includes($[0]?.value??""))return C0($.slice(1),Y);return _}function O0(Z,X){if(Z.length===0)return _;let $=QZ(Z[0].value);if($==="gh")return cZ(Z.slice(1),X);if(iZ.has($)){let J=R0(Z.slice(1));return J?d(J.value,X.depth+1,X.debug):_}return v2($,Z[0],Z.slice(1),[],[],X)}function C0(Z,X){let $=Z.findIndex((J)=>!J.opaque&&QZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?cZ(Z.slice($+1),X):_}function R0(Z){for(let X=0;X<Z.length;X++){let $=Z[X].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(X+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))X++}return}function K5(Z){let X=[],$=0;for(;;){let J=Z.indexOf("<<",$);if(J<0)break;if($=J+2,Z[J+2]==="<"||J>0&&Z[J-1]==="<"){$=J+3;continue}let z=GZ(Z,J);if(!z)continue;let Y=Z.lastIndexOf(`
|
|
24
24
|
`,J)+1,Q=Z.indexOf(`
|
|
25
|
-
`,J);if(Q<0)continue;let H=hZ(Z,Q,[z]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),M=Z.slice(Y,J)+" HEREDOC_OPERATOR "+Z.slice(z.end,Q);X.push({body:B,runsBody:H5(M),quoted:z.quoted})}return X}function H5(Z){let{segments:X}=y0(Z),$=X.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=p(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>VZ(M.text));return{verb:QZ(VZ(H.words[K].text).value),args:B}},{verb:z,args:Y}=J(X[$]);if(z==="ssh"||F0(z,Y))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Y[0]?.value??""))return!0;let Q=X[$+1];if(z==="cat"&&Q&&L2(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||F0(H.verb,H.args)}return!1}var B5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function A2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:L0}}}var M5=new Set(["Bash","Monitor"]);function y2(Z){if(Z?.hook_event_name!=="PreToolUse"||!M5.has(Z.tool_name??""))return{continue:!0};let X=BZ(Z);if(!X.trim())return{continue:!0};try{return d(X).refused?A2():{continue:!0}}catch{return B5.test(X)?A2():{continue:!0}}}function G5(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function R2(Z,X){G5(Z);let $=Z,J=JSON.parse(X);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!E0.isAbsolute(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let z=J.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Y=z===void 0?void 0:{runtime:process.execPath,home:sZ.homedir(),path:process.env.PATH,agent:z.agent};if(Y&&(!E0.isAbsolute(Y.runtime)||!Y.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let v=J.tool_input.command??J.tool_input.patch;if(typeof v!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:v,patch:v}}let Q=J.tool_name==="Monitor",H=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&H?{...J,tool_name:"Bash"}:J,B=(v)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:v}}),M=V2(K).output,V=y2(K),G=H&&LZ(K.tool_input.command,{home:sZ.homedir(),cwd:J.cwd}).handoffHits.length>0,j=$==="trash-guard"&&(!Q||H)?e0(K,{home:sZ.homedir(),cwd:J.cwd,findTrash:bZ,inspectTrash:TZ,execution:Y}):{continue:!0};if(Q&&j.hookSpecificOutput?.permissionDecision==="allow")j=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let D=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):j;return JSON.stringify({verdict:"continue"in D?null:D})}var V5=2,U5="0.12.
|
|
25
|
+
`,J);if(Q<0)continue;let H=hZ(Z,Q,[z]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),M=Z.slice(Y,J)+" HEREDOC_OPERATOR "+Z.slice(z.end,Q);X.push({body:B,runsBody:H5(M),quoted:z.quoted})}return X}function H5(Z){let{segments:X}=y0(Z),$=X.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=p(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>VZ(M.text));return{verb:QZ(VZ(H.words[K].text).value),args:B}},{verb:z,args:Y}=J(X[$]);if(z==="ssh"||F0(z,Y))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Y[0]?.value??""))return!0;let Q=X[$+1];if(z==="cat"&&Q&&L2(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||F0(H.verb,H.args)}return!1}var B5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function A2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:L0}}}var M5=new Set(["Bash","Monitor"]);function y2(Z){if(Z?.hook_event_name!=="PreToolUse"||!M5.has(Z.tool_name??""))return{continue:!0};let X=BZ(Z);if(!X.trim())return{continue:!0};try{return d(X).refused?A2():{continue:!0}}catch{return B5.test(X)?A2():{continue:!0}}}function G5(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function R2(Z,X){G5(Z);let $=Z,J=JSON.parse(X);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!E0.isAbsolute(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let z=J.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Y=z===void 0?void 0:{runtime:process.execPath,home:sZ.homedir(),path:process.env.PATH,agent:z.agent};if(Y&&(!E0.isAbsolute(Y.runtime)||!Y.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let v=J.tool_input.command??J.tool_input.patch;if(typeof v!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:v,patch:v}}let Q=J.tool_name==="Monitor",H=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&H?{...J,tool_name:"Bash"}:J,B=(v)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:v}}),M=V2(K).output,V=y2(K),G=H&&LZ(K.tool_input.command,{home:sZ.homedir(),cwd:J.cwd}).handoffHits.length>0,j=$==="trash-guard"&&(!Q||H)?e0(K,{home:sZ.homedir(),cwd:J.cwd,findTrash:bZ,inspectTrash:TZ,execution:Y}):{continue:!0};if(Q&&j.hookSpecificOutput?.permissionDecision==="allow")j=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let D=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):j;return JSON.stringify({verdict:"continue"in D?null:D})}var V5=2,U5="0.12.9";function j5(Z,X){return R2(Z,X)}
|
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")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/hooks",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.9",
|
|
4
4
|
"description": "Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@hasna/contracts": "~1.2.1"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@hasna/skills": "0.10.
|
|
73
|
+
"@hasna/skills": "0.10.55",
|
|
74
74
|
"@hasna/events": "^0.1.16",
|
|
75
75
|
"@hasna/secrets": "0.4.2",
|
|
76
76
|
"@modelcontextprotocol/sdk": "^1.26.0",
|