@node9/policy-engine 2.43.0 → 2.44.0

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/dist/index.d.mts CHANGED
@@ -916,6 +916,10 @@ interface PolicyHostHooks {
916
916
  * this registry host (node9Firewall#415 item 4). Absent: only the public
917
917
  * registries and the machine itself count as configured. */
918
918
  isConfiguredRegistry?: (host: string, cwd?: string) => boolean;
919
+ /** True when `dir` (relative to `cwd`) is the top of a git work tree: it
920
+ * holds a `.git` entry. Decides `git -C <dir> add .` (node9Firewall#413).
921
+ * Absent, or no cwd: the stage-all finding stands. */
922
+ isGitWorkTreeTop?: (dir: string, cwd: string) => boolean;
919
923
  }
920
924
  interface PolicyVerdict {
921
925
  decision: 'allow' | 'review' | 'block';
@@ -1156,6 +1160,15 @@ interface GitFinding {
1156
1160
  description: string;
1157
1161
  /** The invocation as resolved, for the reason and the explain trace. */
1158
1162
  shown: string;
1163
+ /**
1164
+ * A stage-all finding that holds only if this directory (as written after
1165
+ * `-C`, relative to where the command runs) is the top of a work tree:
1166
+ * `git -C sub add .` stages `sub` alone, `git -C myapp add .` run from the
1167
+ * folder above the repository stages all of it. The command cannot tell
1168
+ * them apart; a host that knows the working directory asks the disk, and
1169
+ * without an answer the finding stands (node9Firewall#413).
1170
+ */
1171
+ ifWorkTreeTop?: string;
1159
1172
  }
1160
1173
  interface GitAnalysis {
1161
1174
  /** False when mvdan-sh could not parse the command: nothing was judged. */
@@ -1174,6 +1187,8 @@ interface GitInvocation {
1174
1187
  env: Map<string, string | null>;
1175
1188
  /** How the call was written, for the reason. */
1176
1189
  shown: string;
1190
+ /** Each `-C <path>` given before the subcommand, in order; null marks a dynamic word. */
1191
+ chdir?: (string | null)[];
1177
1192
  }
1178
1193
  /**
1179
1194
  * Every git finding in a shell command. Cached by the raw text; pure.
@@ -2373,7 +2388,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
2373
2388
  * and fails CI when the hash drifts without a version bump — forgetting
2374
2389
  * is loud, not silent.
2375
2390
  */
2376
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
2391
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
2377
2392
  /**
2378
2393
  * SHA-256 prefix of the detector-source files
2379
2394
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -2384,7 +2399,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
2384
2399
  * files changed, this hash must change too, and you must consciously
2385
2400
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2386
2401
  */
2387
- declare const CANONICAL_EXTRACTOR_HASH = "45158fa38836036f";
2402
+ declare const CANONICAL_EXTRACTOR_HASH = "3b56e19906016767";
2388
2403
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2389
2404
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2390
2405
  /**
package/dist/index.d.ts CHANGED
@@ -916,6 +916,10 @@ interface PolicyHostHooks {
916
916
  * this registry host (node9Firewall#415 item 4). Absent: only the public
917
917
  * registries and the machine itself count as configured. */
918
918
  isConfiguredRegistry?: (host: string, cwd?: string) => boolean;
919
+ /** True when `dir` (relative to `cwd`) is the top of a git work tree: it
920
+ * holds a `.git` entry. Decides `git -C <dir> add .` (node9Firewall#413).
921
+ * Absent, or no cwd: the stage-all finding stands. */
922
+ isGitWorkTreeTop?: (dir: string, cwd: string) => boolean;
919
923
  }
920
924
  interface PolicyVerdict {
921
925
  decision: 'allow' | 'review' | 'block';
@@ -1156,6 +1160,15 @@ interface GitFinding {
1156
1160
  description: string;
1157
1161
  /** The invocation as resolved, for the reason and the explain trace. */
1158
1162
  shown: string;
1163
+ /**
1164
+ * A stage-all finding that holds only if this directory (as written after
1165
+ * `-C`, relative to where the command runs) is the top of a work tree:
1166
+ * `git -C sub add .` stages `sub` alone, `git -C myapp add .` run from the
1167
+ * folder above the repository stages all of it. The command cannot tell
1168
+ * them apart; a host that knows the working directory asks the disk, and
1169
+ * without an answer the finding stands (node9Firewall#413).
1170
+ */
1171
+ ifWorkTreeTop?: string;
1159
1172
  }
1160
1173
  interface GitAnalysis {
1161
1174
  /** False when mvdan-sh could not parse the command: nothing was judged. */
@@ -1174,6 +1187,8 @@ interface GitInvocation {
1174
1187
  env: Map<string, string | null>;
1175
1188
  /** How the call was written, for the reason. */
1176
1189
  shown: string;
1190
+ /** Each `-C <path>` given before the subcommand, in order; null marks a dynamic word. */
1191
+ chdir?: (string | null)[];
1177
1192
  }
1178
1193
  /**
1179
1194
  * Every git finding in a shell command. Cached by the raw text; pure.
@@ -2373,7 +2388,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
2373
2388
  * and fails CI when the hash drifts without a version bump — forgetting
2374
2389
  * is loud, not silent.
2375
2390
  */
2376
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
2391
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
2377
2392
  /**
2378
2393
  * SHA-256 prefix of the detector-source files
2379
2394
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -2384,7 +2399,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
2384
2399
  * files changed, this hash must change too, and you must consciously
2385
2400
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2386
2401
  */
2387
- declare const CANONICAL_EXTRACTOR_HASH = "45158fa38836036f";
2402
+ declare const CANONICAL_EXTRACTOR_HASH = "3b56e19906016767";
2388
2403
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2389
2404
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2390
2405
  /**
package/dist/index.js CHANGED
@@ -13065,6 +13065,7 @@ var GitWalk = class {
13065
13065
  /** The words after `git`: global options, then the subcommand. */
13066
13066
  visitGit(rest, env, depth, viaXargs, fromAlias, shown) {
13067
13067
  const config = /* @__PURE__ */ new Map();
13068
+ const chdir = [];
13068
13069
  let i = 0;
13069
13070
  while (i < rest.length) {
13070
13071
  const w = rest[i];
@@ -13079,6 +13080,7 @@ var GitWalk = class {
13079
13080
  i++;
13080
13081
  value = i < rest.length ? rest[i] : null;
13081
13082
  }
13083
+ if (name === "-C") chdir.push(viaXargs || (value ?? "").includes("{}") ? null : value);
13082
13084
  if (name === "-c" && value !== null) {
13083
13085
  const ceq = value.indexOf("=");
13084
13086
  const key = (ceq > 0 ? value.slice(0, ceq) : value).toLowerCase();
@@ -13095,7 +13097,7 @@ var GitWalk = class {
13095
13097
  }
13096
13098
  const subWord = i < rest.length ? rest[i] : void 0;
13097
13099
  const args = rest.slice(i + 1);
13098
- const inv = { sub: null, args, config, env, shown };
13100
+ const inv = { sub: null, args, config, env, shown, chdir };
13099
13101
  if (subWord === void 0) {
13100
13102
  if (!viaXargs) return;
13101
13103
  this.emit(inv);
@@ -13109,16 +13111,23 @@ var GitWalk = class {
13109
13111
  const fromConfig = config.get(`alias.${subWord.toLowerCase()}`);
13110
13112
  const alias = fromConfig !== void 0 ? fromConfig : this.aliases.get(subWord);
13111
13113
  if (alias !== void 0 && !fromAlias) {
13112
- this.expandAlias(subWord, alias, args, env, depth, 0, shown);
13114
+ this.expandAlias(subWord, alias, args, env, depth, 0, shown, chdir);
13113
13115
  return;
13114
13116
  }
13115
13117
  inv.sub = subWord;
13116
13118
  this.emit(inv);
13117
13119
  this.recordAliasDefinition(inv, env, depth);
13118
13120
  }
13119
- expandAlias(name, value, args, env, depth, level, shown) {
13121
+ expandAlias(name, value, args, env, depth, level, shown, chdir) {
13120
13122
  if (value === null) {
13121
- this.emit({ sub: null, args, config: /* @__PURE__ */ new Map(), env, shown: `${shown} (alias ${name})` });
13123
+ this.emit({
13124
+ sub: null,
13125
+ args,
13126
+ config: /* @__PURE__ */ new Map(),
13127
+ env,
13128
+ shown: `${shown} (alias ${name})`,
13129
+ chdir
13130
+ });
13122
13131
  return;
13123
13132
  }
13124
13133
  if (value.startsWith("!")) {
@@ -13132,7 +13141,16 @@ var GitWalk = class {
13132
13141
  const nested = this.aliases.get(sub);
13133
13142
  const expandedShown = `${shown} (alias ${name} = ${value})`;
13134
13143
  if (nested !== void 0 && level < MAX_ALIAS_DEPTH) {
13135
- this.expandAlias(sub, nested, [...words.slice(1), ...args], env, depth, level + 1, shown);
13144
+ this.expandAlias(
13145
+ sub,
13146
+ nested,
13147
+ [...words.slice(1), ...args],
13148
+ env,
13149
+ depth,
13150
+ level + 1,
13151
+ shown,
13152
+ chdir
13153
+ );
13136
13154
  return;
13137
13155
  }
13138
13156
  this.emit({
@@ -13140,7 +13158,8 @@ var GitWalk = class {
13140
13158
  args: [...words.slice(1), ...args],
13141
13159
  config: /* @__PURE__ */ new Map(),
13142
13160
  env,
13143
- shown: expandedShown
13161
+ shown: expandedShown,
13162
+ chdir
13144
13163
  });
13145
13164
  }
13146
13165
  /**
@@ -13174,7 +13193,7 @@ var GitWalk = class {
13174
13193
  if (i + 1 >= args.length) return;
13175
13194
  const value = args[i + 1];
13176
13195
  this.aliases.set(m[1], value);
13177
- this.expandAlias(m[1], value, [], env, depth, 0, `${inv.shown}`);
13196
+ this.expandAlias(m[1], value, [], env, depth, 0, `${inv.shown}`, []);
13178
13197
  }
13179
13198
  };
13180
13199
  var POSITIONAL2 = "\0positional";
@@ -13367,7 +13386,10 @@ function classify(inv) {
13367
13386
  out.push({ ...f, shown: inv.shown, reason: `${f.reason}: ${inv.shown}` });
13368
13387
  };
13369
13388
  if (hooksBypass(inv)) found(HOOKS_BYPASS);
13370
- if (stagesEverything(inv)) found(STAGE_ALL);
13389
+ const staged = stagesEverything(inv);
13390
+ if (staged) {
13391
+ found(staged.ifWorkTreeTop === void 0 ? STAGE_ALL : { ...STAGE_ALL, ...staged });
13392
+ }
13371
13393
  if (inv.sub === null) {
13372
13394
  found(UNREADABLE);
13373
13395
  return out;
@@ -13437,12 +13459,35 @@ function appliedValue(env, name) {
13437
13459
  const word = f?.Stmts?.[0]?.Cmd?.Args?.[1];
13438
13460
  return word ? resolveWordLiteral(word) : null;
13439
13461
  }
13462
+ function lexicalPath(p) {
13463
+ if (/^[\\/~$]/.test(p) || /^[A-Za-z]:/.test(p)) return null;
13464
+ const parts = [];
13465
+ let climbed = false;
13466
+ for (const part of p.split(/[\\/]+/)) {
13467
+ if (part === "" || part === ".") continue;
13468
+ if (part === "..") {
13469
+ if (parts.length === 0) climbed = true;
13470
+ else parts.pop();
13471
+ } else parts.push(part);
13472
+ }
13473
+ return { parts, climbed };
13474
+ }
13475
+ function hooksPathBypasses(value) {
13476
+ if (value === null || value === void 0) return true;
13477
+ const v = value.trim();
13478
+ if (v === "" || v === "true") return true;
13479
+ const lp = lexicalPath(v);
13480
+ if (lp === null || lp.climbed || lp.parts.length === 0) return true;
13481
+ return lp.parts[0] === ".git" && lp.parts[1] !== "hooks";
13482
+ }
13440
13483
  function hooksBypass(inv) {
13441
- if (inv.config.has("core.hookspath")) return true;
13484
+ if (inv.config.has("core.hookspath") && hooksPathBypasses(inv.config.get("core.hookspath")))
13485
+ return true;
13442
13486
  for (const [name, value] of inv.env) {
13443
13487
  if (name === "GIT_CONFIG_PARAMETERS" && value !== null && /core\.hookspath/i.test(value))
13444
13488
  return true;
13445
- if (/^GIT_CONFIG_KEY_\d+$/.test(name) && value !== null && value.toLowerCase() === "core.hookspath")
13489
+ const key = /^GIT_CONFIG_KEY_(\d+)$/.exec(name);
13490
+ if (key && value !== null && value.toLowerCase() === "core.hookspath" && hooksPathBypasses(inv.env.get(`GIT_CONFIG_VALUE_${key[1]}`)))
13446
13491
  return true;
13447
13492
  }
13448
13493
  for (const name of HOOK_KILL_SWITCHES) {
@@ -13499,7 +13544,10 @@ function configWritesHooksPath(args) {
13499
13544
  }
13500
13545
  const key = args[i];
13501
13546
  if (key === null || key === void 0 || key.toLowerCase() !== "core.hookspath") return false;
13502
- return write || i + 1 < args.length;
13547
+ const unset = args.slice(0, i).some((w) => w === "--unset" || w === "--unset-all") || args[0] === "unset";
13548
+ if (unset) return true;
13549
+ if (i + 1 < args.length) return hooksPathBypasses(args[i + 1]);
13550
+ return write;
13503
13551
  }
13504
13552
  function isHookPath(word) {
13505
13553
  return /(^|[\\/])(\.git[\\/]hooks|\.husky)([\\/]|$)/.test(word);
@@ -13543,31 +13591,49 @@ var ADD_LONG_VALUE = /* @__PURE__ */ new Set(["--chmod", "--pathspec-from-file"]
13543
13591
  function wholeTree(operand) {
13544
13592
  if (/^:\(top\)\.?$/.test(operand) || operand === ":/" || operand === "*") return true;
13545
13593
  if (operand.startsWith(":")) return false;
13594
+ const lp = lexicalPath(operand);
13595
+ return lp !== null && lp.parts.length === 0;
13596
+ }
13597
+ function chdirPrefix(inv) {
13598
+ const dirs = inv.chdir ?? [];
13599
+ if (dirs.length === 0) return null;
13546
13600
  const parts = [];
13547
- for (const part of operand.split("/")) {
13548
- if (!part || part === ".") continue;
13549
- if (part === "..") parts.pop();
13550
- else parts.push(part);
13601
+ for (const d of dirs) {
13602
+ if (d === null || d === "") return null;
13603
+ const lp = lexicalPath(d);
13604
+ if (lp === null || lp.climbed) return null;
13605
+ parts.push(...lp.parts);
13551
13606
  }
13552
- return parts.length === 0 && !operand.startsWith("/");
13607
+ return parts.length === 0 ? null : parts.join("/");
13553
13608
  }
13554
13609
  function stagesEverything(inv) {
13555
13610
  const sub = inv.sub?.toLowerCase();
13611
+ const prefix = chdirPrefix(inv);
13612
+ const judge = (operands2) => {
13613
+ let conditional = false;
13614
+ for (const operand of operands2) {
13615
+ if (!wholeTree(operand)) continue;
13616
+ if (prefix === null || operand.startsWith(":") || operand.startsWith("/")) return {};
13617
+ if (wholeTree(`${prefix}/${operand === "*" ? "." : operand}`)) return {};
13618
+ conditional = true;
13619
+ }
13620
+ return conditional && prefix !== null ? { ifWorkTreeTop: prefix } : null;
13621
+ };
13556
13622
  if (sub === "add") {
13557
13623
  const o = parseOptions(inv.args, "", ADD_LONG_VALUE);
13558
13624
  if (o.flags.has("-n") || o.flags.has("--dry-run") || o.flags.has("-i") || o.flags.has("--interactive") || o.flags.has("-p") || o.flags.has("--patch") || o.flags.has("-e") || o.flags.has("--edit"))
13559
- return false;
13625
+ return null;
13560
13626
  const all = o.flags.has("-A") || o.flags.has("--all") || o.flags.has("--no-ignore-removal") || o.flags.has("-u") || o.flags.has("--update");
13561
- if (all && o.operands.length === 0) return true;
13562
- return o.operands.some(wholeTree);
13627
+ if (all && o.operands.length === 0) return {};
13628
+ return judge(o.operands);
13563
13629
  }
13564
13630
  if (sub === "commit") {
13565
13631
  const o = parseOptions(inv.args, "mFCcut", COMMIT_LONG_VALUE);
13566
- if (o.flags.has("--dry-run")) return false;
13567
- if (o.flags.has("-a") || o.flags.has("--all")) return true;
13568
- return o.operands.some(wholeTree);
13632
+ if (o.flags.has("--dry-run")) return null;
13633
+ if (o.flags.has("-a") || o.flags.has("--all")) return {};
13634
+ return judge(o.operands);
13569
13635
  }
13570
- return false;
13636
+ return null;
13571
13637
  }
13572
13638
 
13573
13639
  // src/files/git-hooks.ts
@@ -16729,7 +16795,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hostHooks =
16729
16795
  }
16730
16796
  async function evaluatePolicyCore(config, toolName, args, context = {}, hooks = {}) {
16731
16797
  const { agent, cwd, activeEnvironment } = context;
16732
- const { checkProvenance, isTrustedHost, isConfiguredRegistry } = hooks;
16798
+ const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop } = hooks;
16733
16799
  const settingsView = catalogSettings(config);
16734
16800
  const layers = inspectionLayers(config.policy);
16735
16801
  const cv = (id) => checkValue(settingsView, id);
@@ -16883,6 +16949,8 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
16883
16949
  const action = cv(id);
16884
16950
  const finding = action === "off" ? void 0 : git.findings.find((f) => f.checkId === id);
16885
16951
  if (!finding) continue;
16952
+ if (finding.ifWorkTreeTop !== void 0 && isGitWorkTreeTop && cwd && !isGitWorkTreeTop(finding.ifWorkTreeTop, cwd))
16953
+ continue;
16886
16954
  const v = applyCheckValue(action, {
16887
16955
  decision: "review",
16888
16956
  blockedByLabel: `Node9 (AST): ${finding.ruleName}`,
@@ -18847,8 +18915,8 @@ function matchCanaryArgs(args, values) {
18847
18915
 
18848
18916
  // src/scan/canonical.ts
18849
18917
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
18850
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
18851
- var CANONICAL_EXTRACTOR_HASH = "45158fa38836036f";
18918
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
18919
+ var CANONICAL_EXTRACTOR_HASH = "3b56e19906016767";
18852
18920
  var DEDUPE_PREVIEW_LEN = 120;
18853
18921
  function extractCanonicalFindings(call, ctx) {
18854
18922
  const out = [];
package/dist/index.mjs CHANGED
@@ -12805,6 +12805,7 @@ var GitWalk = class {
12805
12805
  /** The words after `git`: global options, then the subcommand. */
12806
12806
  visitGit(rest, env, depth, viaXargs, fromAlias, shown) {
12807
12807
  const config = /* @__PURE__ */ new Map();
12808
+ const chdir = [];
12808
12809
  let i = 0;
12809
12810
  while (i < rest.length) {
12810
12811
  const w = rest[i];
@@ -12819,6 +12820,7 @@ var GitWalk = class {
12819
12820
  i++;
12820
12821
  value = i < rest.length ? rest[i] : null;
12821
12822
  }
12823
+ if (name === "-C") chdir.push(viaXargs || (value ?? "").includes("{}") ? null : value);
12822
12824
  if (name === "-c" && value !== null) {
12823
12825
  const ceq = value.indexOf("=");
12824
12826
  const key = (ceq > 0 ? value.slice(0, ceq) : value).toLowerCase();
@@ -12835,7 +12837,7 @@ var GitWalk = class {
12835
12837
  }
12836
12838
  const subWord = i < rest.length ? rest[i] : void 0;
12837
12839
  const args = rest.slice(i + 1);
12838
- const inv = { sub: null, args, config, env, shown };
12840
+ const inv = { sub: null, args, config, env, shown, chdir };
12839
12841
  if (subWord === void 0) {
12840
12842
  if (!viaXargs) return;
12841
12843
  this.emit(inv);
@@ -12849,16 +12851,23 @@ var GitWalk = class {
12849
12851
  const fromConfig = config.get(`alias.${subWord.toLowerCase()}`);
12850
12852
  const alias = fromConfig !== void 0 ? fromConfig : this.aliases.get(subWord);
12851
12853
  if (alias !== void 0 && !fromAlias) {
12852
- this.expandAlias(subWord, alias, args, env, depth, 0, shown);
12854
+ this.expandAlias(subWord, alias, args, env, depth, 0, shown, chdir);
12853
12855
  return;
12854
12856
  }
12855
12857
  inv.sub = subWord;
12856
12858
  this.emit(inv);
12857
12859
  this.recordAliasDefinition(inv, env, depth);
12858
12860
  }
12859
- expandAlias(name, value, args, env, depth, level, shown) {
12861
+ expandAlias(name, value, args, env, depth, level, shown, chdir) {
12860
12862
  if (value === null) {
12861
- this.emit({ sub: null, args, config: /* @__PURE__ */ new Map(), env, shown: `${shown} (alias ${name})` });
12863
+ this.emit({
12864
+ sub: null,
12865
+ args,
12866
+ config: /* @__PURE__ */ new Map(),
12867
+ env,
12868
+ shown: `${shown} (alias ${name})`,
12869
+ chdir
12870
+ });
12862
12871
  return;
12863
12872
  }
12864
12873
  if (value.startsWith("!")) {
@@ -12872,7 +12881,16 @@ var GitWalk = class {
12872
12881
  const nested = this.aliases.get(sub);
12873
12882
  const expandedShown = `${shown} (alias ${name} = ${value})`;
12874
12883
  if (nested !== void 0 && level < MAX_ALIAS_DEPTH) {
12875
- this.expandAlias(sub, nested, [...words.slice(1), ...args], env, depth, level + 1, shown);
12884
+ this.expandAlias(
12885
+ sub,
12886
+ nested,
12887
+ [...words.slice(1), ...args],
12888
+ env,
12889
+ depth,
12890
+ level + 1,
12891
+ shown,
12892
+ chdir
12893
+ );
12876
12894
  return;
12877
12895
  }
12878
12896
  this.emit({
@@ -12880,7 +12898,8 @@ var GitWalk = class {
12880
12898
  args: [...words.slice(1), ...args],
12881
12899
  config: /* @__PURE__ */ new Map(),
12882
12900
  env,
12883
- shown: expandedShown
12901
+ shown: expandedShown,
12902
+ chdir
12884
12903
  });
12885
12904
  }
12886
12905
  /**
@@ -12914,7 +12933,7 @@ var GitWalk = class {
12914
12933
  if (i + 1 >= args.length) return;
12915
12934
  const value = args[i + 1];
12916
12935
  this.aliases.set(m[1], value);
12917
- this.expandAlias(m[1], value, [], env, depth, 0, `${inv.shown}`);
12936
+ this.expandAlias(m[1], value, [], env, depth, 0, `${inv.shown}`, []);
12918
12937
  }
12919
12938
  };
12920
12939
  var POSITIONAL2 = "\0positional";
@@ -13107,7 +13126,10 @@ function classify(inv) {
13107
13126
  out.push({ ...f, shown: inv.shown, reason: `${f.reason}: ${inv.shown}` });
13108
13127
  };
13109
13128
  if (hooksBypass(inv)) found(HOOKS_BYPASS);
13110
- if (stagesEverything(inv)) found(STAGE_ALL);
13129
+ const staged = stagesEverything(inv);
13130
+ if (staged) {
13131
+ found(staged.ifWorkTreeTop === void 0 ? STAGE_ALL : { ...STAGE_ALL, ...staged });
13132
+ }
13111
13133
  if (inv.sub === null) {
13112
13134
  found(UNREADABLE);
13113
13135
  return out;
@@ -13177,12 +13199,35 @@ function appliedValue(env, name) {
13177
13199
  const word = f?.Stmts?.[0]?.Cmd?.Args?.[1];
13178
13200
  return word ? resolveWordLiteral(word) : null;
13179
13201
  }
13202
+ function lexicalPath(p) {
13203
+ if (/^[\\/~$]/.test(p) || /^[A-Za-z]:/.test(p)) return null;
13204
+ const parts = [];
13205
+ let climbed = false;
13206
+ for (const part of p.split(/[\\/]+/)) {
13207
+ if (part === "" || part === ".") continue;
13208
+ if (part === "..") {
13209
+ if (parts.length === 0) climbed = true;
13210
+ else parts.pop();
13211
+ } else parts.push(part);
13212
+ }
13213
+ return { parts, climbed };
13214
+ }
13215
+ function hooksPathBypasses(value) {
13216
+ if (value === null || value === void 0) return true;
13217
+ const v = value.trim();
13218
+ if (v === "" || v === "true") return true;
13219
+ const lp = lexicalPath(v);
13220
+ if (lp === null || lp.climbed || lp.parts.length === 0) return true;
13221
+ return lp.parts[0] === ".git" && lp.parts[1] !== "hooks";
13222
+ }
13180
13223
  function hooksBypass(inv) {
13181
- if (inv.config.has("core.hookspath")) return true;
13224
+ if (inv.config.has("core.hookspath") && hooksPathBypasses(inv.config.get("core.hookspath")))
13225
+ return true;
13182
13226
  for (const [name, value] of inv.env) {
13183
13227
  if (name === "GIT_CONFIG_PARAMETERS" && value !== null && /core\.hookspath/i.test(value))
13184
13228
  return true;
13185
- if (/^GIT_CONFIG_KEY_\d+$/.test(name) && value !== null && value.toLowerCase() === "core.hookspath")
13229
+ const key = /^GIT_CONFIG_KEY_(\d+)$/.exec(name);
13230
+ if (key && value !== null && value.toLowerCase() === "core.hookspath" && hooksPathBypasses(inv.env.get(`GIT_CONFIG_VALUE_${key[1]}`)))
13186
13231
  return true;
13187
13232
  }
13188
13233
  for (const name of HOOK_KILL_SWITCHES) {
@@ -13239,7 +13284,10 @@ function configWritesHooksPath(args) {
13239
13284
  }
13240
13285
  const key = args[i];
13241
13286
  if (key === null || key === void 0 || key.toLowerCase() !== "core.hookspath") return false;
13242
- return write || i + 1 < args.length;
13287
+ const unset = args.slice(0, i).some((w) => w === "--unset" || w === "--unset-all") || args[0] === "unset";
13288
+ if (unset) return true;
13289
+ if (i + 1 < args.length) return hooksPathBypasses(args[i + 1]);
13290
+ return write;
13243
13291
  }
13244
13292
  function isHookPath(word) {
13245
13293
  return /(^|[\\/])(\.git[\\/]hooks|\.husky)([\\/]|$)/.test(word);
@@ -13283,31 +13331,49 @@ var ADD_LONG_VALUE = /* @__PURE__ */ new Set(["--chmod", "--pathspec-from-file"]
13283
13331
  function wholeTree(operand) {
13284
13332
  if (/^:\(top\)\.?$/.test(operand) || operand === ":/" || operand === "*") return true;
13285
13333
  if (operand.startsWith(":")) return false;
13334
+ const lp = lexicalPath(operand);
13335
+ return lp !== null && lp.parts.length === 0;
13336
+ }
13337
+ function chdirPrefix(inv) {
13338
+ const dirs = inv.chdir ?? [];
13339
+ if (dirs.length === 0) return null;
13286
13340
  const parts = [];
13287
- for (const part of operand.split("/")) {
13288
- if (!part || part === ".") continue;
13289
- if (part === "..") parts.pop();
13290
- else parts.push(part);
13341
+ for (const d of dirs) {
13342
+ if (d === null || d === "") return null;
13343
+ const lp = lexicalPath(d);
13344
+ if (lp === null || lp.climbed) return null;
13345
+ parts.push(...lp.parts);
13291
13346
  }
13292
- return parts.length === 0 && !operand.startsWith("/");
13347
+ return parts.length === 0 ? null : parts.join("/");
13293
13348
  }
13294
13349
  function stagesEverything(inv) {
13295
13350
  const sub = inv.sub?.toLowerCase();
13351
+ const prefix = chdirPrefix(inv);
13352
+ const judge = (operands2) => {
13353
+ let conditional = false;
13354
+ for (const operand of operands2) {
13355
+ if (!wholeTree(operand)) continue;
13356
+ if (prefix === null || operand.startsWith(":") || operand.startsWith("/")) return {};
13357
+ if (wholeTree(`${prefix}/${operand === "*" ? "." : operand}`)) return {};
13358
+ conditional = true;
13359
+ }
13360
+ return conditional && prefix !== null ? { ifWorkTreeTop: prefix } : null;
13361
+ };
13296
13362
  if (sub === "add") {
13297
13363
  const o = parseOptions(inv.args, "", ADD_LONG_VALUE);
13298
13364
  if (o.flags.has("-n") || o.flags.has("--dry-run") || o.flags.has("-i") || o.flags.has("--interactive") || o.flags.has("-p") || o.flags.has("--patch") || o.flags.has("-e") || o.flags.has("--edit"))
13299
- return false;
13365
+ return null;
13300
13366
  const all = o.flags.has("-A") || o.flags.has("--all") || o.flags.has("--no-ignore-removal") || o.flags.has("-u") || o.flags.has("--update");
13301
- if (all && o.operands.length === 0) return true;
13302
- return o.operands.some(wholeTree);
13367
+ if (all && o.operands.length === 0) return {};
13368
+ return judge(o.operands);
13303
13369
  }
13304
13370
  if (sub === "commit") {
13305
13371
  const o = parseOptions(inv.args, "mFCcut", COMMIT_LONG_VALUE);
13306
- if (o.flags.has("--dry-run")) return false;
13307
- if (o.flags.has("-a") || o.flags.has("--all")) return true;
13308
- return o.operands.some(wholeTree);
13372
+ if (o.flags.has("--dry-run")) return null;
13373
+ if (o.flags.has("-a") || o.flags.has("--all")) return {};
13374
+ return judge(o.operands);
13309
13375
  }
13310
- return false;
13376
+ return null;
13311
13377
  }
13312
13378
 
13313
13379
  // src/files/git-hooks.ts
@@ -16469,7 +16535,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hostHooks =
16469
16535
  }
16470
16536
  async function evaluatePolicyCore(config, toolName, args, context = {}, hooks = {}) {
16471
16537
  const { agent, cwd, activeEnvironment } = context;
16472
- const { checkProvenance, isTrustedHost, isConfiguredRegistry } = hooks;
16538
+ const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop } = hooks;
16473
16539
  const settingsView = catalogSettings(config);
16474
16540
  const layers = inspectionLayers(config.policy);
16475
16541
  const cv = (id) => checkValue(settingsView, id);
@@ -16623,6 +16689,8 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
16623
16689
  const action = cv(id);
16624
16690
  const finding = action === "off" ? void 0 : git.findings.find((f) => f.checkId === id);
16625
16691
  if (!finding) continue;
16692
+ if (finding.ifWorkTreeTop !== void 0 && isGitWorkTreeTop && cwd && !isGitWorkTreeTop(finding.ifWorkTreeTop, cwd))
16693
+ continue;
16626
16694
  const v = applyCheckValue(action, {
16627
16695
  decision: "review",
16628
16696
  blockedByLabel: `Node9 (AST): ${finding.ruleName}`,
@@ -18587,8 +18655,8 @@ function matchCanaryArgs(args, values) {
18587
18655
 
18588
18656
  // src/scan/canonical.ts
18589
18657
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
18590
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v34";
18591
- var CANONICAL_EXTRACTOR_HASH = "45158fa38836036f";
18658
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
18659
+ var CANONICAL_EXTRACTOR_HASH = "3b56e19906016767";
18592
18660
  var DEDUPE_PREVIEW_LEN = 120;
18593
18661
  function extractCanonicalFindings(call, ctx) {
18594
18662
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://node9.ai",