@hasna/hooks 0.12.8 → 0.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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 install workspace-repos-guard --target claude --overwrite
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.53+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
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.53+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
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.53",
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 (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || ![undefined, "bytes"].includes(source.hashMode) || source.sha256 === null)
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)) && source.format === undefined && source.fields === undefined && source.managedPlugins === undefined && [undefined, "bytes"].includes(source.hashMode)) {
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)) && source.format === undefined && source.fields === undefined && source.managedPlugins === undefined && [undefined, "bytes"].includes(source.hashMode)))
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.53+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
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 (source.format !== undefined || source.fields !== undefined || source.managedPlugins !== undefined || ![undefined, "bytes"].includes(source.hashMode) || source.sha256 === null)
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)) && source.format === undefined && source.fields === undefined && source.managedPlugins === undefined && [undefined, "bytes"].includes(source.hashMode)) {
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)) && source.format === undefined && source.fields === undefined && source.managedPlugins === undefined && [undefined, "bytes"].includes(source.hashMode)))
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.53",
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
- const conflict = detectRewriteConflict("trash-guard", scope, target);
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("trash-guard", scope, target, undefined, undefined, (settings) => {
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("trash-guard");
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 = (options.readiness ? previewNativeReadinessRegistration : previewNativeSafetyRegistration)(options.target);
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("trash-guard", { target: selected.target, overwrite: true, expectedSettingsSha256: plan.beforeSHA256, beforeWrite });
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 selectCodexSafety(discovery, configuration, home, cwd, featureEnabled, requireReady = true, readiness = false) {
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 === "trash-guard"));
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)$" : matcher) && 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");
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, matcher = "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$", CodexSafetyError, digest3 = (bytes) => createHash26("sha256").update(bytes).digest("hex");
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, matcher2, options = {}) {
47482
- if (matcher2 === undefined)
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(matcher2) ? matcher2 : [matcher2];
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, matcher2) {
47490
- if (!matcher2)
47528
+ function matchRecord(input2, matcher) {
47529
+ if (!matcher)
47491
47530
  return true;
47492
- return Object.entries(matcher2).every(([path, expected]) => {
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 matcher2 = hook.matcher ? ` ${hook.matcher}` : "";
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}${matcher2}]`)} ${chalk2.dim(hook.category)}${description}`;
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 Trash guard registration without changing settings" : "Apply the exact planned registration and retain its private preimage");
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({