@webpieces/agent-workflow-rules 0.4.847 → 0.4.849

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/agent-workflow-rules",
3
- "version": "0.4.847",
3
+ "version": "0.4.849",
4
4
  "description": "Independent workflow guards, guard hook, installation and shim management for AI coding agents.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,8 @@
8
8
  ".": "./src/index.js",
9
9
  "./package.json": "./package.json",
10
10
  "./claude-code-guards": "./src/adapters/guards-hook.js",
11
- "./rule-pack": "./src/rule-pack.js"
11
+ "./rule-pack": "./src/rule-pack.js",
12
+ "./rule-runtime": "./src/rule-runtime.js"
12
13
  },
13
14
  "files": [
14
15
  "src/**/*",
@@ -23,20 +24,20 @@
23
24
  "directory": "packages/tooling/agent-workflow-rules"
24
25
  },
25
26
  "dependencies": {
26
- "@webpieces/hook-runtime": "0.4.847",
27
- "@webpieces/rules-config": "0.4.847",
27
+ "@webpieces/hook-runtime": "0.4.849",
28
+ "@webpieces/rules-config": "0.4.849",
28
29
  "inversify": "7.10.4",
29
30
  "reflect-metadata": "0.2.2",
30
- "@webpieces/tooling-common": "0.4.847",
31
- "@webpieces/repo-workflow-core": "0.4.847",
31
+ "@webpieces/tooling-common": "0.4.849",
32
+ "@webpieces/repo-workflow-core": "0.4.849",
32
33
  "tslib": "2.8.1",
33
- "@webpieces/rules-sdk": "0.4.847"
34
+ "@webpieces/rules-sdk": "0.4.849"
34
35
  },
35
36
  "publishConfig": {
36
37
  "access": "public"
37
38
  },
38
39
  "devDependencies": {
39
- "@webpieces/tooling-testkit": "0.4.847"
40
+ "@webpieces/tooling-testkit": "0.4.849"
40
41
  },
41
42
  "types": "./src/index.d.ts",
42
43
  "bin": {
@@ -23,8 +23,8 @@ export declare class GoldenFixture {
23
23
  */
24
24
  readonly stdin: string;
25
25
  /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */
26
- readonly crashingRulesDir: boolean;
27
- constructor(name: string, mode: HookMode, stdin: string, crashingRulesDir?: boolean);
26
+ readonly crashingRuntime: boolean;
27
+ constructor(name: string, mode: HookMode, stdin: string, crashingRuntime?: boolean);
28
28
  }
29
29
  /** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */
30
30
  export declare class PreparedFixture {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GoldenRepoBuilder = exports.GOLDEN_FIXTURES = exports.REPO_TOKEN = exports.PreparedFixture = exports.GoldenFixture = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const rules_sdk_1 = require("@webpieces/rules-sdk");
5
6
  const rule_pack_1 = require("../rule-pack");
6
7
  const tooling_testkit_1 = require("@webpieces/tooling-testkit");
7
8
  const tooling_testkit_2 = require("@webpieces/tooling-testkit");
@@ -32,12 +33,12 @@ class GoldenFixture {
32
33
  */
33
34
  stdin;
34
35
  /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */
35
- crashingRulesDir;
36
- constructor(name, mode, stdin, crashingRulesDir = false) {
36
+ crashingRuntime;
37
+ constructor(name, mode, stdin, crashingRuntime = false) {
37
38
  this.name = name;
38
39
  this.mode = mode;
39
40
  this.stdin = stdin;
40
- this.crashingRulesDir = crashingRulesDir;
41
+ this.crashingRuntime = crashingRuntime;
41
42
  }
42
43
  }
43
44
  exports.GoldenFixture = GoldenFixture;
@@ -61,14 +62,27 @@ exports.PreparedFixture = PreparedFixture;
61
62
  * a golden nobody else could run.
62
63
  */
63
64
  exports.REPO_TOKEN = '<REPO>';
64
- const CLAUDE_ENVELOPE = { hook_event_name: 'PreToolUse', session_id: 'sess-golden', transcript_path: '/dev/null', cwd: exports.REPO_TOKEN };
65
+ const CLAUDE_ENVELOPE = {
66
+ hook_event_name: 'PreToolUse',
67
+ session_id: 'sess-golden',
68
+ transcript_path: '/dev/null',
69
+ cwd: exports.REPO_TOKEN,
70
+ };
65
71
  /**
66
72
  * The Codex additions, MEASURED from codex-cli 0.151.0: it uses Claude's key names and merely ADDS
67
73
  * `model`, `turn_id`, `tool_use_id` and `permission_mode`. `turn_id` is the one discriminator (see
68
74
  * detect-ai.ts). `agent_id` empty ⇒ the coordinator, populated ⇒ a subagent — identical semantics in
69
75
  * both harnesses.
70
76
  */
71
- const CODEX_ENVELOPE = { ...CLAUDE_ENVELOPE, model: 'gpt-5-codex', turn_id: 'turn-golden', tool_use_id: 'call_1', permission_mode: 'default', agent_type: 'default', agent_id: '' };
77
+ const CODEX_ENVELOPE = {
78
+ ...CLAUDE_ENVELOPE,
79
+ model: 'gpt-5-codex',
80
+ turn_id: 'turn-golden',
81
+ tool_use_id: 'call_1',
82
+ permission_mode: 'default',
83
+ agent_type: 'default',
84
+ agent_id: '',
85
+ };
72
86
  // Codex's edit tool. MEASURED: the tool is named `apply_patch`, it carries `tool_input.command` (not
73
87
  // file_path), hunk headers are a bare `@@`, and ONE patch may carry many files with mixed operations.
74
88
  const PATCH_ADD_JS = '*** Begin Patch\n*** Add File: src/foo.js\n+var x = 1;\n*** End Patch\n';
@@ -80,7 +94,11 @@ const PATCH_ADD_TS = '*** Begin Patch\n*** Add File: scripts/added.ts\n+export c
80
94
  */
81
95
  class WirePayload {
82
96
  // webpieces-disable no-any-unknown -- these objects ARE the wire envelope; JSON.stringify of a plain object is the payload under test, and naming a type for it would assert a shape the fixtures exist to state literally
83
- write(envelope, toolName, toolInput) {
97
+ write(
98
+ // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
99
+ envelope, toolName,
100
+ // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
101
+ toolInput) {
84
102
  return JSON.stringify({ ...envelope, tool_name: toolName, tool_input: toolInput });
85
103
  }
86
104
  }
@@ -137,14 +155,22 @@ class GoldenRepoBuilder {
137
155
  this.git(repo, 'config core.hooksPath /dev/null');
138
156
  this.git(repo, 'config user.email t@t.co');
139
157
  this.git(repo, 'config user.name tester');
140
- fs.writeFileSync(path.join(repo, 'webpieces.config.json'), this.repoConfig(fixture));
141
- tooling_testkit_1.policyFixture.declareIn(repo, tooling_testkit_1.policyFixture.manifests().map(pack => pack.packageName === rule_pack_1.rulePackManifest.packageName ? rule_pack_1.rulePackManifest : pack));
158
+ const manifests = tooling_testkit_1.policyFixture
159
+ .manifests()
160
+ .map((pack) => pack.packageName === rule_pack_1.rulePackManifest.packageName ? rule_pack_1.rulePackManifest : pack);
161
+ if (fixture.crashingRuntime) {
162
+ const seed = Object.assign(new rules_sdk_1.ConfigObject(), { mode: 'ON' });
163
+ const definition = new rules_sdk_1.OwnedRuleDefinition('client-crash', { mode: new rules_sdk_1.FieldDef('string', ['ON', 'OFF']) }, 1, {}, seed, 'rules', new rules_sdk_1.RuleHelp('Client failure fixture', 'Repair {configFile}.'));
164
+ manifests.push(new rules_sdk_1.RulePackManifest('@client/crash', '1.0.0-fixture', 3, [definition], [
165
+ new rules_sdk_1.RuleContribution('client-crash', '@client/crash', 'source-hook', './crash-runtime.cjs'),
166
+ ], [], []));
167
+ }
168
+ tooling_testkit_1.policyFixture.writeOwnerConfig(repo, JSON.parse(this.repoConfig(fixture)), manifests);
142
169
  fs.writeFileSync(path.join(repo, 'f.txt'), 'hello\n');
143
170
  fs.mkdirSync(path.join(repo, 'scripts'));
144
171
  fs.writeFileSync(path.join(repo, 'scripts', 'ok.ts'), 'const a = 1;\n');
145
- if (fixture.crashingRulesDir) {
146
- fs.mkdirSync(path.join(repo, 'wprules'));
147
- fs.writeFileSync(path.join(repo, 'wprules', 'crash.js'), CRASHING_RULE_MODULE);
172
+ if (fixture.crashingRuntime) {
173
+ fs.writeFileSync(path.join(repo, 'crash-runtime.cjs'), CRASHING_RULE_MODULE);
148
174
  }
149
175
  this.git(repo, 'add -A');
150
176
  this.git(repo, 'commit -qm init');
@@ -155,11 +181,11 @@ class GoldenRepoBuilder {
155
181
  return new PreparedFixture(repo, root, fixture.stdin.split(exports.REPO_TOKEN).join(repo));
156
182
  }
157
183
  repoConfig(fixture) {
158
- if (!fixture.crashingRulesDir)
184
+ if (!fixture.crashingRuntime)
159
185
  return this.configJson;
160
186
  // webpieces-disable no-any-unknown -- the frozen fixture config is data on disk; re-parsing it into a named type here would be a second declaration of a file whose whole point is being literal
161
187
  const parsed = JSON.parse(this.configJson);
162
- parsed['rulesDir'] = ['wprules'];
188
+ parsed['rules']['client-crash'] = Object.assign(new rules_sdk_1.ConfigObject(), { mode: 'ON' });
163
189
  return JSON.stringify(parsed, null, 4);
164
190
  }
165
191
  git(repo, args) {
@@ -1 +1 @@
1
- {"version":3,"file":"hook-app-fixtures.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/adapters/hook-app-fixtures.ts"],"names":[],"mappings":";;;;AAAA,4CAAgD;AAChD,gEAA2D;AAC3D,gEAA0D;AAC1D,iDAAyC;AACzC,+CAAyB;AAEzB,mDAA6B;AAK7B;;;;;;;;;;;GAWG;AAEH,yFAAyF;AACzF,MAAa,aAAa;IACtB,2DAA2D;IAClD,IAAI,CAAS;IACtB,sDAAsD;IAC7C,IAAI,CAAW;IACxB;;;OAGG;IACM,KAAK,CAAS;IACvB,4FAA4F;IACnF,gBAAgB,CAAU;IAEnC,YAAY,IAAY,EAAE,IAAc,EAAE,KAAa,EAAE,mBAA4B,KAAK;QACtF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;CACJ;AAnBD,sCAmBC;AAED,gGAAgG;AAChG,MAAa,eAAe;IACf,IAAI,CAAS;IACb,IAAI,CAAS;IACb,KAAK,CAAS;IAEvB,YAAY,IAAY,EAAE,IAAY,EAAE,KAAa;QACjD,IAAI,CAAC,IAAI,GAAG,IAA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C,CAAC;YACzC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAClC,+FAA+F;QAC/F,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,0CAA0C,CAAC,CAAC;QAC3D,mEAAmE;QACnE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;QAC9C,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACvF,CAAC;IAEO,UAAU,CAAC,OAAsB;QACrC,IAAI,CAAC,OAAO,CAAC,gBAAgB;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC;QACtD,iMAAiM;QACjM,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAA4B,CAAC;QACtE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAEO,GAAG,CAAC,IAAY,EAAE,IAAY;QAClC,IAAA,wBAAQ,EAAC,OAAO,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;CACJ;AA7CD,8CA6CC","sourcesContent":["import { rulePackManifest } from '../rule-pack';\nimport { policyFixture } from '@webpieces/tooling-testkit';\nimport { specTempDirs } from '@webpieces/tooling-testkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\n\nimport { HookMode } from '@webpieces/hook-runtime';\n\n\n/**\n * THE WIRE BYTES the golden tests drive, and the throwaway repo they are judged against.\n *\n * Everything here exists so a reader can see EXACTLY what a harness sends: the payloads are built from\n * the measured envelope key sets (see the fixture docs on GoldenFixture below), not from anything the\n * hook itself produces, and the repo is a real `git init` with a frozen webpieces.config.json rather\n * than whatever tree the suite happens to be running in. A golden computed against the live repo would\n * change verdict with the branch you are standing on.\n *\n * This is NOT a spec file, deliberately: `tsconfig.lib.json` excludes `*.spec.ts`, so a payload builder\n * living in one would never be type-checked by the build.\n */\n\n/** How one PreToolUse call is presented to the hook. Data class per CLAUDE.md rule 1. */\nexport class GoldenFixture {\n /** Stable key into `__goldens__/hook-app-goldens.json`. */\n readonly name: string;\n /** Which hook binary's mode — `guards` or `rules`. */\n readonly mode: HookMode;\n /**\n * The raw stdin bytes. A STRING, never an object, because malformed stdin is one of the fixtures\n * and a shape that cannot express \"not JSON\" would quietly drop the case that matters most.\n */\n readonly stdin: string;\n /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */\n readonly crashingRulesDir: boolean;\n\n constructor(name: string, mode: HookMode, stdin: string, crashingRulesDir: boolean = false) {\n this.name = name;\n this.mode = mode;\n this.stdin = stdin;\n this.crashingRulesDir = crashingRulesDir;\n }\n}\n\n/** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */\nexport class PreparedFixture {\n readonly repo: string;\n readonly root: string;\n readonly stdin: string;\n\n constructor(repo: string, root: string, stdin: string) {\n this.repo = repo;\n this.root = root;\n this.stdin = stdin;\n }\n}\n\n/**\n * The placeholder that stands for the fixture repo's absolute path, in BOTH directions: payloads are\n * written with it and it is substituted in before the run; golden bytes are compared with the real\n * path substituted back out. Guard reports legitimately name absolute paths (the git-workflow doc\n * pointer, the blocked file), and a golden that hard-coded one machine's `/var/folders/...` would be\n * a golden nobody else could run.\n */\nexport const REPO_TOKEN = '<REPO>';\n\nconst CLAUDE_ENVELOPE = { hook_event_name: 'PreToolUse', session_id: 'sess-golden', transcript_path: '/dev/null', cwd: REPO_TOKEN };\n\n/**\n * The Codex additions, MEASURED from codex-cli 0.151.0: it uses Claude's key names and merely ADDS\n * `model`, `turn_id`, `tool_use_id` and `permission_mode`. `turn_id` is the one discriminator (see\n * detect-ai.ts). `agent_id` empty ⇒ the coordinator, populated ⇒ a subagent — identical semantics in\n * both harnesses.\n */\nconst CODEX_ENVELOPE = { ...CLAUDE_ENVELOPE, model: 'gpt-5-codex', turn_id: 'turn-golden', tool_use_id: 'call_1', permission_mode: 'default', agent_type: 'default', agent_id: '' };\n\n// Codex's edit tool. MEASURED: the tool is named `apply_patch`, it carries `tool_input.command` (not\n// file_path), hunk headers are a bare `@@`, and ONE patch may carry many files with mixed operations.\nconst PATCH_ADD_JS = '*** Begin Patch\\n*** Add File: src/foo.js\\n+var x = 1;\\n*** End Patch\\n';\nconst PATCH_ADD_TS = '*** Begin Patch\\n*** Add File: scripts/added.ts\\n+export const b = 2;\\n*** End Patch\\n';\n\n/**\n * Serializes ONE PreToolUse envelope to the bytes a harness would put on stdin. A class rather than a\n * module-scope function because that is the repo rule, and the one instance below is built at module\n * load so the fixture table can stay a plain literal list.\n */\nclass WirePayload {\n // webpieces-disable no-any-unknown -- these objects ARE the wire envelope; JSON.stringify of a plain object is the payload under test, and naming a type for it would assert a shape the fixtures exist to state literally\n write(envelope: Record<string, unknown>, toolName: string, toolInput: Record<string, unknown>): string {\n return JSON.stringify({ ...envelope, tool_name: toolName, tool_input: toolInput });\n }\n}\n\nconst WIRE = new WirePayload();\n\n/**\n * ONE fixture per row of the coverage the composed pipeline had none of before: for BOTH harnesses a\n * Bash deny (the ANSI-red systemMessage), a file-tool deny (NO systemMessage), an allow, a read-only\n * tool, malformed stdin, and a fail-closed crash.\n */\nexport const GOLDEN_FIXTURES: readonly GoldenFixture[] = [\n // ── Claude Code ────────────────────────────────────────────────────────────────────────────────\n // A Bash deny. `git merge` is blocked on every branch, so this verdict does not depend on repo\n // state — and a Bash deny is the ONE case that carries the red `systemMessage`.\n new GoldenFixture('claude/bash-deny', 'guards', WIRE.write(CLAUDE_ENVELOPE, 'Bash', { command: 'git merge main' })),\n new GoldenFixture('claude/bash-allow', 'guards', WIRE.write(CLAUDE_ENVELOPE, 'Bash', { command: 'echo hi' })),\n // The read-only tool: log-and-allow, and the only guard that can deny it is a stale `main`.\n new GoldenFixture('claude/read-allow', 'guards', WIRE.write(CLAUDE_ENVELOPE, 'Read', { file_path: `${REPO_TOKEN}/f.txt` })),\n // Write / Edit / MultiEdit denies — all three must emit NO systemMessage.\n new GoldenFixture('claude/malformed', 'guards', 'not json at all'),\n\n // ── Codex ──────────────────────────────────────────────────────────────────────────────────────\n new GoldenFixture('codex/bash-deny', 'guards', WIRE.write(CODEX_ENVELOPE, 'Bash', { command: 'git merge main' })),\n new GoldenFixture('codex/bash-allow', 'guards', WIRE.write(CODEX_ENVELOPE, 'Bash', { command: 'echo hi' })),\n // Codex has no Read tool: a read arrives as `Bash` running a pager, which read parity turns into a\n // read-scoped verdict ON TOP of the bash guards.\n new GoldenFixture('codex/read-allow', 'guards', WIRE.write(CODEX_ENVELOPE, 'Bash', { command: `sed -n '1,240p' ${REPO_TOKEN}/f.txt` })),\n new GoldenFixture('codex/malformed', 'guards', '{\"turn_id\": broken'),\n];\n\n// A rules module that blows up the moment it is required — the shortest honest way to reach the hook's\n// fail-closed boundary from OUTSIDE the hook, i.e. without stubbing anything the pipeline owns.\nconst CRASHING_RULE_MODULE = \"throw new Error('boom from a custom rule module');\\n\";\n\n/**\n * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.\n *\n * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the\n * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's\n * verdict — an order-dependent suite, which is the one kind of golden test worse than none.\n *\n * `realpathSync` matters on macOS: `os.tmpdir()` hands back `/var/folders/...` which resolves to\n * `/private/var/...`, and the L1 location guard compares the payload's cwd against the resolved repo\n * root. Without it every fixture denies with \"run git from the repo root\" instead of the verdict under\n * test.\n */\nexport class GoldenRepoBuilder {\n private readonly configJson: string;\n\n constructor() {\n this.configJson = fs.readFileSync(path.join(__dirname, '__goldens__', 'fixture-webpieces.config.json'), 'utf8');\n }\n\n build(fixture: GoldenFixture): PreparedFixture {\n const root = specTempDirs.makeReal('wp-hook-golden-');\n const repo = path.join(root, 'repo');\n fs.mkdirSync(repo);\n this.git(repo, 'init -q -b main');\n // The developer's own commit hooks would otherwise fire inside this throwaway repo.\n this.git(repo, 'config core.hooksPath /dev/null');\n this.git(repo, 'config user.email t@t.co');\n this.git(repo, 'config user.name tester');\n fs.writeFileSync(path.join(repo, 'webpieces.config.json'), this.repoConfig(fixture));\n policyFixture.declareIn(repo, policyFixture.manifests().map(pack => pack.packageName === rulePackManifest.packageName ? rulePackManifest : pack));\n fs.writeFileSync(path.join(repo, 'f.txt'), 'hello\\n');\n fs.mkdirSync(path.join(repo, 'scripts'));\n fs.writeFileSync(path.join(repo, 'scripts', 'ok.ts'), 'const a = 1;\\n');\n if (fixture.crashingRulesDir) {\n fs.mkdirSync(path.join(repo, 'wprules'));\n fs.writeFileSync(path.join(repo, 'wprules', 'crash.js'), CRASHING_RULE_MODULE);\n }\n this.git(repo, 'add -A');\n this.git(repo, 'commit -qm init');\n // A local origin/main, so `origin/main..<branch>` resolves exactly as it does in a real clone.\n this.git(repo, 'update-ref refs/remotes/origin/main HEAD');\n // A feature branch, because that is where an agent actually works.\n this.git(repo, 'checkout -q -b dean/fixture');\n return new PreparedFixture(repo, root, fixture.stdin.split(REPO_TOKEN).join(repo));\n }\n\n private repoConfig(fixture: GoldenFixture): string {\n if (!fixture.crashingRulesDir) return this.configJson;\n // webpieces-disable no-any-unknown -- the frozen fixture config is data on disk; re-parsing it into a named type here would be a second declaration of a file whose whole point is being literal\n const parsed = JSON.parse(this.configJson) as Record<string, unknown>;\n parsed['rulesDir'] = ['wprules'];\n return JSON.stringify(parsed, null, 4);\n }\n\n private git(repo: string, args: string): void {\n execSync(`git ${args}`, { cwd: repo, encoding: 'utf8' });\n }\n}\n"]}
1
+ {"version":3,"file":"hook-app-fixtures.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/adapters/hook-app-fixtures.ts"],"names":[],"mappings":";;;;AAAA,oDAO8B;AAC9B,4CAAgD;AAChD,gEAA2D;AAC3D,gEAA0D;AAC1D,iDAAyC;AACzC,+CAAyB;AAEzB,mDAA6B;AAI7B;;;;;;;;;;;GAWG;AAEH,yFAAyF;AACzF,MAAa,aAAa;IACtB,2DAA2D;IAClD,IAAI,CAAS;IACtB,sDAAsD;IAC7C,IAAI,CAAW;IACxB;;;OAGG;IACM,KAAK,CAAS;IACvB,4FAA4F;IACnF,eAAe,CAAU;IAElC,YAAY,IAAY,EAAE,IAAc,EAAE,KAAa,EAAE,kBAA2B,KAAK;QACrF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;CACJ;AAnBD,sCAmBC;AAED,gGAAgG;AAChG,MAAa,eAAe;IACf,IAAI,CAAS;IACb,IAAI,CAAS;IACb,KAAK,CAAS;IAEvB,YAAY,IAAY,EAAE,IAAY,EAAE,KAAa;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAVD,0CAUC;AAED;;;;;;GAMG;AACU,QAAA,UAAU,GAAG,QAAQ,CAAC;AAEnC,MAAM,eAAe,GAAG;IACpB,eAAe,EAAE,YAAY;IAC7B,UAAU,EAAE,aAAa;IACzB,eAAe,EAAE,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,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAEO,GAAG,CAAC,IAAY,EAAE,IAAY;QAClC,IAAA,wBAAQ,EAAC,OAAO,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;CACJ;AApFD,8CAoFC","sourcesContent":["import {\n ConfigObject,\n FieldDef,\n OwnedRuleDefinition,\n RuleContribution,\n RuleHelp,\n RulePackManifest,\n} from '@webpieces/rules-sdk';\nimport { rulePackManifest } from '../rule-pack';\nimport { policyFixture } from '@webpieces/tooling-testkit';\nimport { specTempDirs } from '@webpieces/tooling-testkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\n\nimport { HookMode } from '@webpieces/hook-runtime';\n\n/**\n * THE WIRE BYTES the golden tests drive, and the throwaway repo they are judged against.\n *\n * Everything here exists so a reader can see EXACTLY what a harness sends: the payloads are built from\n * the measured envelope key sets (see the fixture docs on GoldenFixture below), not from anything the\n * hook itself produces, and the repo is a real `git init` with a frozen webpieces.config.json rather\n * than whatever tree the suite happens to be running in. A golden computed against the live repo would\n * change verdict with the branch you are standing on.\n *\n * This is NOT a spec file, deliberately: `tsconfig.lib.json` excludes `*.spec.ts`, so a payload builder\n * living in one would never be type-checked by the build.\n */\n\n/** How one PreToolUse call is presented to the hook. Data class per CLAUDE.md rule 1. */\nexport class GoldenFixture {\n /** Stable key into `__goldens__/hook-app-goldens.json`. */\n readonly name: string;\n /** Which hook binary's mode — `guards` or `rules`. */\n readonly mode: HookMode;\n /**\n * The raw stdin bytes. A STRING, never an object, because malformed stdin is one of the fixtures\n * and a shape that cannot express \"not JSON\" would quietly drop the case that matters most.\n */\n readonly stdin: string;\n /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */\n readonly crashingRuntime: boolean;\n\n constructor(name: string, mode: HookMode, stdin: string, crashingRuntime: boolean = false) {\n this.name = name;\n this.mode = mode;\n this.stdin = stdin;\n this.crashingRuntime = crashingRuntime;\n }\n}\n\n/** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */\nexport class PreparedFixture {\n readonly repo: string;\n readonly root: string;\n readonly stdin: string;\n\n constructor(repo: string, root: string, stdin: string) {\n this.repo = repo;\n this.root = root;\n this.stdin = stdin;\n }\n}\n\n/**\n * The placeholder that stands for the fixture repo's absolute path, in BOTH directions: payloads are\n * written with it and it is substituted in before the run; golden bytes are compared with the real\n * path substituted back out. Guard reports legitimately name absolute paths (the git-workflow doc\n * pointer, the blocked file), and a golden that hard-coded one machine's `/var/folders/...` would be\n * a golden nobody else could run.\n */\nexport const REPO_TOKEN = '<REPO>';\n\nconst CLAUDE_ENVELOPE = {\n hook_event_name: 'PreToolUse',\n session_id: 'sess-golden',\n transcript_path: '/dev/null',\n cwd: REPO_TOKEN,\n};\n\n/**\n * The Codex additions, MEASURED from codex-cli 0.151.0: it uses Claude's key names and merely ADDS\n * `model`, `turn_id`, `tool_use_id` and `permission_mode`. `turn_id` is the one discriminator (see\n * detect-ai.ts). `agent_id` empty ⇒ the coordinator, populated ⇒ a subagent — identical semantics in\n * both harnesses.\n */\nconst CODEX_ENVELOPE = {\n ...CLAUDE_ENVELOPE,\n model: 'gpt-5-codex',\n turn_id: 'turn-golden',\n tool_use_id: 'call_1',\n permission_mode: 'default',\n agent_type: 'default',\n agent_id: '',\n};\n\n// Codex's edit tool. MEASURED: the tool is named `apply_patch`, it carries `tool_input.command` (not\n// file_path), hunk headers are a bare `@@`, and ONE patch may carry many files with mixed operations.\nconst PATCH_ADD_JS = '*** Begin Patch\\n*** Add File: src/foo.js\\n+var x = 1;\\n*** End Patch\\n';\nconst PATCH_ADD_TS =\n '*** Begin Patch\\n*** Add File: scripts/added.ts\\n+export const b = 2;\\n*** End Patch\\n';\n\n/**\n * Serializes ONE PreToolUse envelope to the bytes a harness would put on stdin. A class rather than a\n * module-scope function because that is the repo rule, and the one instance below is built at module\n * load so the fixture table can stay a plain literal list.\n */\nclass WirePayload {\n // webpieces-disable no-any-unknown -- these objects ARE the wire envelope; JSON.stringify of a plain object is the payload under test, and naming a type for it would assert a shape the fixtures exist to state literally\n write(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n envelope: Record<string, unknown>,\n toolName: string,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n toolInput: Record<string, unknown>,\n ): string {\n return JSON.stringify({ ...envelope, tool_name: toolName, tool_input: toolInput });\n }\n}\n\nconst WIRE = new WirePayload();\n\n/**\n * ONE fixture per row of the coverage the composed pipeline had none of before: for BOTH harnesses a\n * Bash deny (the ANSI-red systemMessage), a file-tool deny (NO systemMessage), an allow, a read-only\n * tool, malformed stdin, and a fail-closed crash.\n */\nexport const GOLDEN_FIXTURES: readonly GoldenFixture[] = [\n // ── Claude Code ────────────────────────────────────────────────────────────────────────────────\n // A Bash deny. `git merge` is blocked on every branch, so this verdict does not depend on repo\n // state — and a Bash deny is the ONE case that carries the red `systemMessage`.\n new GoldenFixture(\n 'claude/bash-deny',\n 'guards',\n WIRE.write(CLAUDE_ENVELOPE, 'Bash', { command: 'git merge main' }),\n ),\n new GoldenFixture(\n 'claude/bash-allow',\n 'guards',\n WIRE.write(CLAUDE_ENVELOPE, 'Bash', { command: 'echo hi' }),\n ),\n // The read-only tool: log-and-allow, and the only guard that can deny it is a stale `main`.\n new GoldenFixture(\n 'claude/read-allow',\n 'guards',\n WIRE.write(CLAUDE_ENVELOPE, 'Read', { file_path: `${REPO_TOKEN}/f.txt` }),\n ),\n // Write / Edit / MultiEdit denies — all three must emit NO systemMessage.\n new GoldenFixture('claude/malformed', 'guards', 'not json at all'),\n\n // ── Codex ──────────────────────────────────────────────────────────────────────────────────────\n new GoldenFixture(\n 'codex/bash-deny',\n 'guards',\n WIRE.write(CODEX_ENVELOPE, 'Bash', { command: 'git merge main' }),\n ),\n new GoldenFixture(\n 'codex/bash-allow',\n 'guards',\n WIRE.write(CODEX_ENVELOPE, 'Bash', { command: 'echo hi' }),\n ),\n // Codex has no Read tool: a read arrives as `Bash` running a pager, which read parity turns into a\n // read-scoped verdict ON TOP of the bash guards.\n new GoldenFixture(\n 'codex/read-allow',\n 'guards',\n WIRE.write(CODEX_ENVELOPE, 'Bash', { command: `sed -n '1,240p' ${REPO_TOKEN}/f.txt` }),\n ),\n new GoldenFixture('codex/malformed', 'guards', '{\"turn_id\": broken'),\n];\n\n// A rules module that blows up the moment it is required — the shortest honest way to reach the hook's\n// fail-closed boundary from OUTSIDE the hook, i.e. without stubbing anything the pipeline owns.\nconst CRASHING_RULE_MODULE = \"throw new Error('boom from a custom rule module');\\n\";\n\n/**\n * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.\n *\n * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the\n * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's\n * verdict — an order-dependent suite, which is the one kind of golden test worse than none.\n *\n * `realpathSync` matters on macOS: `os.tmpdir()` hands back `/var/folders/...` which resolves to\n * `/private/var/...`, and the L1 location guard compares the payload's cwd against the resolved repo\n * root. Without it every fixture denies with \"run git from the repo root\" instead of the verdict under\n * test.\n */\nexport class GoldenRepoBuilder {\n private readonly configJson: string;\n\n constructor() {\n this.configJson = fs.readFileSync(\n path.join(__dirname, '__goldens__', 'fixture-webpieces.config.json'),\n 'utf8',\n );\n }\n\n build(fixture: GoldenFixture): PreparedFixture {\n const root = specTempDirs.makeReal('wp-hook-golden-');\n const repo = path.join(root, 'repo');\n fs.mkdirSync(repo);\n this.git(repo, 'init -q -b main');\n // The developer's own commit hooks would otherwise fire inside this throwaway repo.\n this.git(repo, 'config core.hooksPath /dev/null');\n this.git(repo, 'config user.email t@t.co');\n this.git(repo, 'config user.name tester');\n const manifests = policyFixture\n .manifests()\n .map((pack: RulePackManifest) =>\n pack.packageName === rulePackManifest.packageName ? rulePackManifest : pack,\n );\n if (fixture.crashingRuntime) {\n const seed = Object.assign(new ConfigObject(), { mode: 'ON' });\n const definition = new OwnedRuleDefinition(\n 'client-crash',\n { mode: new FieldDef('string', ['ON', 'OFF']) },\n 1,\n {},\n seed,\n 'rules',\n new RuleHelp('Client failure fixture', 'Repair {configFile}.'),\n );\n manifests.push(\n new RulePackManifest(\n '@client/crash',\n '1.0.0-fixture',\n 3,\n [definition],\n [\n new RuleContribution(\n 'client-crash',\n '@client/crash',\n 'source-hook',\n './crash-runtime.cjs',\n ),\n ],\n [],\n [],\n ),\n );\n }\n policyFixture.writeOwnerConfig(repo, JSON.parse(this.repoConfig(fixture)), manifests);\n fs.writeFileSync(path.join(repo, 'f.txt'), 'hello\\n');\n fs.mkdirSync(path.join(repo, 'scripts'));\n fs.writeFileSync(path.join(repo, 'scripts', 'ok.ts'), 'const a = 1;\\n');\n if (fixture.crashingRuntime) {\n fs.writeFileSync(path.join(repo, 'crash-runtime.cjs'), CRASHING_RULE_MODULE);\n }\n this.git(repo, 'add -A');\n this.git(repo, 'commit -qm init');\n // A local origin/main, so `origin/main..<branch>` resolves exactly as it does in a real clone.\n this.git(repo, 'update-ref refs/remotes/origin/main HEAD');\n // A feature branch, because that is where an agent actually works.\n this.git(repo, 'checkout -q -b dean/fixture');\n return new PreparedFixture(repo, root, fixture.stdin.split(REPO_TOKEN).join(repo));\n }\n\n private repoConfig(fixture: GoldenFixture): string {\n if (!fixture.crashingRuntime) return this.configJson;\n // webpieces-disable no-any-unknown -- the frozen fixture config is data on disk; re-parsing it into a named type here would be a second declaration of a file whose whole point is being literal\n const parsed = JSON.parse(this.configJson) as Record<string, unknown>;\n (parsed['rules'] as Record<string, ConfigObject>)['client-crash'] = Object.assign(\n new ConfigObject(),\n { mode: 'ON' },\n );\n return JSON.stringify(parsed, null, 4);\n }\n\n private git(repo: string, args: string): void {\n execSync(`git ${args}`, { cwd: repo, encoding: 'utf8' });\n }\n}\n"]}
@@ -26,22 +26,8 @@ const l0_ignored_tools_1 = require("./l0-ignored-tools");
26
26
  // re-exports everything here, so every existing import keeps working, and this module stays as
27
27
  // dependency-free as shim.ts must be: it has to load on a tree too broken to load the rule engine.
28
28
  // ---------------------------------------------------------------------------
29
- // The OUTPUT-CAPTURE TAIL every escape hatch below tolerates — the 2026-07-21 deadlock report, part 2.
30
- // Every allowlist was anchored to a BARE command, but the way an AI assistant actually spells a
31
- // diagnostic command is `<cmd> 2>&1 | tail -20` (it trims the output it has to read back). The audit
32
- // log proves it: `.webpieces/logs/L0-shim/<writer>.log` has `pnpm install 2>&1 | tail -15` logged as
33
- // DENY-STALE seconds away from a bare `pnpm install` logged as ALLOW-INSTALL — the same cure, denied
34
- // for its redirection. A cure that is denied when spelled the natural way reads to the assistant as
35
- // "the guard blocks its own fix", which is exactly the conclusion it drew before handing the fix back
36
- // to the human.
37
- //
38
- // So each hatch accepts an OPTIONAL trailing stderr redirect (`2>&1` to fold stderr in, or `2>/dev/null`
39
- // to drop it — I hit the missing `2>/dev/null` case myself within the hour, running `pnpm install
40
- // 2>/dev/null | tail -2` against a drift block) and an OPTIONAL pipe into `tail`/`head` carrying at
41
- // most a line-count flag (`-20`, `-n 20`). Nothing else: the pipe target is one of two literal,
42
- // read-only pager words and its only argument is digits, so `| sh`, `| curl …`, `| tee /etc/x` and
43
- // every other operator stay DENIED. Spliced in place of each pattern's old `[[:space:]]*$` tail, so the
44
- // anchoring at both ends is unchanged. Keep in sync with CAPTURE_TAIL_JS_SRC (locked by a unit test).
29
+ // Cures tolerate output-only stderr redirection and a numeric head/tail pipe. This keeps
30
+ // ordinary diagnostic capture usable without granting arbitrary pipelines or mutations.
45
31
  exports.CAPTURE_TAIL_ERE = '([[:space:]]+2>(&1|/dev/null))?([[:space:]]*\\|[[:space:]]*(tail|head)([[:space:]]+-(n[[:space:]]+)?[0-9]+)?)?[[:space:]]*$';
46
32
  // JS-regex-source twin of CAPTURE_TAIL_ERE (POSIX `[[:space:]]` → `\s`). A unit test asserts they agree.
47
33
  exports.CAPTURE_TAIL_JS_SRC = '(\\s+2>(&1|\\/dev\\/null))?(\\s*\\|\\s*(tail|head)(\\s+-(n\\s+)?[0-9]+)?)?\\s*$';
@@ -261,6 +247,9 @@ exports.UPGRADE_SHIM_CMD = 'pnpm exec wp-upgrade-shim';
261
247
  const PRUNE_CONFIG_BODY_ERE = '(pnpm|npm|npx)([[:space:]]+(exec|run))?[[:space:]]+wp-prune-unknown-config';
262
248
  // JS-regex twin of PRUNE_CONFIG_BODY_ERE (POSIX `[[:space:]]` → `\s`).
263
249
  const PRUNE_CONFIG_BODY_JS = '(pnpm|npm|npx)(\\s+(exec|run))?\\s+wp-prune-unknown-config';
250
+ // Literal sync arguments only: no shell operators, substitutions, arbitrary switches or sibling commands.
251
+ const RULES_SYNC_BODY_ERE = '(pnpm|npm|npx)([[:space:]]+(exec|run))?[[:space:]]+wp-rules-sync([[:space:]]+(--upgrade|--pack(=|[[:space:]]+)[[:alnum:]_@./-]+=[[:alnum:]_./-]+))*';
252
+ const RULES_SYNC_BODY_JS = '(pnpm|npm|npx)(\\s+(exec|run))?\\s+wp-rules-sync(\\s+(--upgrade|--pack(=|\\s+)[a-zA-Z0-9_@./-]+=[a-zA-Z0-9_./-]+))*';
264
253
  // The entry below spells the command as PRUNE_UNKNOWN_COMMAND, IMPORTED rather than re-typed: that
265
254
  // constant is the single spelling, and a second literal here is exactly the drift that would let a
266
255
  // message prescribe a command this allowlist does not match.
@@ -453,6 +442,9 @@ exports.L0_ALLOWLIST = [
453
442
  // The cure for unknown keys in webpieces.config.json — see PRUNE_CONFIG_BODY_ERE for why a cure the
454
443
  // messages name must be reachable from inside the block those messages are read under.
455
444
  new l0_entry_1.L0AllowEntry(rules_config_3.PRUNE_UNKNOWN_COMMAND, 'allow', true, PRUNE_CONFIG_BODY_ERE, PRUNE_CONFIG_BODY_JS, l0_entry_1.EVERY_HARNESS, new l0_entry_1.L0Call('Bash', rules_config_3.PRUNE_UNKNOWN_COMMAND, ''), [new l0_entry_1.L0Call('Bash', 'pnpm exec wp-prune-unknown-config', '')]),
445
+ new l0_entry_1.L0AllowEntry('pnpm wp-rules-sync — explicit owner seeds and lock/catalog repair', 'allow', true, RULES_SYNC_BODY_ERE, RULES_SYNC_BODY_JS, l0_entry_1.EVERY_HARNESS, new l0_entry_1.L0Call('Bash', 'pnpm wp-rules-sync', ''), [
446
+ new l0_entry_1.L0Call('Bash', 'pnpm wp-rules-sync --upgrade --pack=@client/policy=.webpieces/rules/client.json', ''),
447
+ ]),
456
448
  new l0_entry_1.L0AllowEntry(`${exports.INSTALL_HOOKS_CMD} (flags allowed, e.g. --target=project)`, 'allow', true, INSTALL_HOOKS_BODY_ERE, INSTALL_HOOKS_BODY_JS, l0_entry_1.EVERY_HARNESS, new l0_entry_1.L0Call('Bash', exports.INSTALL_HOOKS_CMD, ''), [new l0_entry_1.L0Call('Bash', exports.INSTALL_HOOKS_TARGET_CMD, '')]),
457
449
  // The fault-U cure. `@<version>` is pinned as an extra sample because the deny INFERS a pin from the
458
450
  // repo's other @webpieces pins and prescribes the versioned spelling — the exact shape that must not
@@ -479,8 +471,8 @@ exports.L0_ALLOWLIST = [
479
471
  // guards. And `pass`, not `allow`, so it mirrors entry 1 exactly: where the bin is running (fault
480
472
  // S) the read falls THROUGH to read-stale-guard, and where it is not (D/X/U/K) the sh half is
481
473
  // terminal by construction, which is the documented asymmetry entry 1 already has.
482
- new l0_entry_1.L0AllowEntry('CODEX ONLY - a read-shaped Bash command (the harness has no Read tool): '
483
- + `${[...harness_vocabulary_1.READ_COMMANDS].join(', ')}, or sed -n '<range>p'`, 'pass', false, l0_codex_read_1.CODEX_READ_BODY_ERE, l0_codex_read_1.CODEX_READ_BODY_JS, 'codex', new l0_entry_1.L0Call('Bash', l0_codex_read_1.CODEX_READ_CMD, ''), [
474
+ new l0_entry_1.L0AllowEntry('CODEX ONLY - a read-shaped Bash command (the harness has no Read tool): ' +
475
+ `${[...harness_vocabulary_1.READ_COMMANDS].join(', ')}, or sed -n '<range>p'`, 'pass', false, l0_codex_read_1.CODEX_READ_BODY_ERE, l0_codex_read_1.CODEX_READ_BODY_JS, 'codex', new l0_entry_1.L0Call('Bash', l0_codex_read_1.CODEX_READ_CMD, ''), [
484
476
  new l0_entry_1.L0Call('Bash', 'cat webpieces.config.json', ''),
485
477
  new l0_entry_1.L0Call('Bash', 'head -50 .webpieces/instruct-ai/webpieces.guard-matrix.md', ''),
486
478
  new l0_entry_1.L0Call('Bash', 'tail -n 20 package.json', ''),
@@ -489,8 +481,8 @@ exports.L0_ALLOWLIST = [
489
481
  ];
490
482
  // The UNGATED bodies — every entry that is not scoped to one harness. A gated entry is spliced into its
491
483
  // own union below instead, which is what makes it unreachable from the harness it is not for.
492
- const L0_BODIES_ERE = exports.L0_ALLOWLIST.flatMap((e) => (e.ere === null || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.ere]));
493
- const L0_BODIES_JS = exports.L0_ALLOWLIST.flatMap((e) => (e.js === null || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.js]));
484
+ const L0_BODIES_ERE = exports.L0_ALLOWLIST.flatMap((e) => e.ere === null || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.ere]);
485
+ const L0_BODIES_JS = exports.L0_ALLOWLIST.flatMap((e) => e.js === null || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.js]);
494
486
  // The ONE Bash allowlist. Anchored and tailed exactly like each individual hatch, so it inherits every
495
487
  // security property: no shell operator can ride along, and only the optional leading `cd <path> &&` /
496
488
  // trailing `2>&1 | tail -N` are tolerated.
@@ -522,6 +514,6 @@ exports.L0_ALLOW_JS = new RegExp(CD_PREFIX_JS_ANCHORED + '(' + L0_BODIES_JS.join
522
514
  // A harness-GATED entry is excluded here too, and not merely because today's one is a non-cure: this
523
515
  // union is consulted by runner.ts where NO harness has been established either, so a gated body spliced
524
516
  // in would be judged with the gate missing — i.e. reachable from the harness it was written to exclude.
525
- const L0_CURE_BODIES_JS = exports.L0_ALLOWLIST.flatMap((e) => (e.js === null || !e.cure || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.js]));
517
+ const L0_CURE_BODIES_JS = exports.L0_ALLOWLIST.flatMap((e) => e.js === null || !e.cure || e.harness !== l0_entry_1.EVERY_HARNESS ? [] : [e.js]);
526
518
  exports.L0_CURE_ALLOW_JS = new RegExp(CD_PREFIX_JS_ANCHORED + '(' + L0_CURE_BODIES_JS.join('|') + ')' + exports.CAPTURE_TAIL_JS_SRC);
527
519
  //# sourceMappingURL=l0-allowlist.js.map