@webpieces/rules-config 0.4.1004 → 0.4.1005
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 +5 -5
- package/src/config-repair-access.d.ts +4 -0
- package/src/config-repair-access.js +8 -0
- package/src/config-repair-access.js.map +1 -1
- package/src/config-repair-bootstrap-source.d.ts +1 -1
- package/src/config-repair-bootstrap-source.js +1 -1
- package/src/config-repair-bootstrap-source.js.map +1 -1
- package/src/config-repair-probe.d.ts +51 -3
- package/src/config-repair-probe.js +135 -12
- package/src/config-repair-probe.js.map +1 -1
- package/src/hook-config-diagnostics.d.ts +16 -0
- package/src/hook-config-diagnostics.js +18 -2
- package/src/hook-config-diagnostics.js.map +1 -1
- package/templates/webpieces.guard-matrix.md +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/rules-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1005",
|
|
4
4
|
"description": "Shared webpieces.config.json loader. Single source of truth for validation rule configuration consumed by @webpieces/ai-hook-rules, @webpieces/code-rules, and @webpieces/nx-webpieces-rules.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"inversify": "7.10.4",
|
|
20
20
|
"reflect-metadata": "0.2.2",
|
|
21
21
|
"minimatch": "10.0.1",
|
|
22
|
-
"@webpieces/tooling-common": "0.4.
|
|
23
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
24
|
-
"@webpieces/rules-sdk": "0.4.
|
|
22
|
+
"@webpieces/tooling-common": "0.4.1005",
|
|
23
|
+
"@webpieces/repo-workflow-core": "0.4.1005",
|
|
24
|
+
"@webpieces/rules-sdk": "0.4.1005"
|
|
25
25
|
},
|
|
26
26
|
"author": "Dean Hiller",
|
|
27
27
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
37
|
+
"@webpieces/tooling-testkit": "0.4.1005"
|
|
38
38
|
},
|
|
39
39
|
"types": "./src/index.d.ts",
|
|
40
40
|
"bin": {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/** Repair access has one canonical probe shared with the bootstrap shim. */
|
|
2
2
|
export declare class ConfigRepairAccess {
|
|
3
3
|
isRepairFile(root: string, filename: string): boolean;
|
|
4
|
+
/** The one L0 edit-escape verdict both shim halves ask — see ConfigRepairProbe.recoveryVerdict. */
|
|
5
|
+
recoveryVerdict(cwd: string, toolName: string, filePath: string, command: string): readonly string[];
|
|
6
|
+
/** `functions.apply_patch` → `apply_patch`; every other tool name unchanged. */
|
|
7
|
+
canonicalTool(toolName: string): string;
|
|
4
8
|
}
|
|
@@ -9,6 +9,14 @@ let ConfigRepairAccess = class ConfigRepairAccess {
|
|
|
9
9
|
isRepairFile(root, filename) {
|
|
10
10
|
return new config_repair_probe_1.ConfigRepairProbe().isRepairFile(root, filename);
|
|
11
11
|
}
|
|
12
|
+
/** The one L0 edit-escape verdict both shim halves ask — see ConfigRepairProbe.recoveryVerdict. */
|
|
13
|
+
recoveryVerdict(cwd, toolName, filePath, command) {
|
|
14
|
+
return new config_repair_probe_1.ConfigRepairProbe().recoveryVerdict(cwd, toolName, filePath, command);
|
|
15
|
+
}
|
|
16
|
+
/** `functions.apply_patch` → `apply_patch`; every other tool name unchanged. */
|
|
17
|
+
canonicalTool(toolName) {
|
|
18
|
+
return new config_repair_probe_1.ConfigRepairProbe().canonicalTool(toolName);
|
|
19
|
+
}
|
|
12
20
|
};
|
|
13
21
|
exports.ConfigRepairAccess = ConfigRepairAccess;
|
|
14
22
|
exports.ConfigRepairAccess = ConfigRepairAccess = tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-repair-access.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-access.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,+DAA0D;AAE1D,4EAA4E;AAErE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,YAAY,CAAC,IAAY,EAAE,QAAgB;QACvC,OAAO,IAAI,uCAAiB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;CACJ,CAAA;
|
|
1
|
+
{"version":3,"file":"config-repair-access.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-access.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,+DAA0D;AAE1D,4EAA4E;AAErE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,YAAY,CAAC,IAAY,EAAE,QAAgB;QACvC,OAAO,IAAI,uCAAiB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;IAED,mGAAmG;IACnG,eAAe,CAAC,GAAW,EAAE,QAAgB,EAAE,QAAgB,EAAE,OAAe;QAC5E,OAAO,IAAI,uCAAiB,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrF,CAAC;IAED,gFAAgF;IAChF,aAAa,CAAC,QAAgB;QAC1B,OAAO,IAAI,uCAAiB,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AAdY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,kBAAkB,CAc9B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { ConfigRepairProbe } from './config-repair-probe';\n\n/** Repair access has one canonical probe shared with the bootstrap shim. */\n@injectable(bindingScopeValues.Singleton)\nexport class ConfigRepairAccess {\n isRepairFile(root: string, filename: string): boolean {\n return new ConfigRepairProbe().isRepairFile(root, filename);\n }\n\n /** The one L0 edit-escape verdict both shim halves ask — see ConfigRepairProbe.recoveryVerdict. */\n recoveryVerdict(cwd: string, toolName: string, filePath: string, command: string): readonly string[] {\n return new ConfigRepairProbe().recoveryVerdict(cwd, toolName, filePath, command);\n }\n\n /** `functions.apply_patch` → `apply_patch`; every other tool name unchanged. */\n canonicalTool(toolName: string): string {\n return new ConfigRepairProbe().canonicalTool(toolName);\n }\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Generated from ConfigRepairProbe by pnpm guards:generate; never edit this artifact. */
|
|
2
|
-
export declare const CONFIG_REPAIR_BOOTSTRAP_SOURCE = "/**\n * Self-contained Node probe: serialized into the POSIX shim so repairs work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n */\nclass ConfigRepairProbe {\n rootFor(cwd) {\n const fs = require('node:fs'), path = require('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory)\n return cwd;\n directory = parent;\n }\n return directory;\n }\n isRepairPatch(root, patch) {\n const lines = patch.trim().split('\\n');\n if (lines[0] !== '*** Begin Patch' || lines.at(-1) !== '*** End Patch')\n return false;\n let targets = 0;\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** '))\n continue;\n const match = /^\\*\\*\\* (?:Add|Update) File: (.+)$/.exec(line);\n if (!match || !this.isRepairFile(root, match[1]))\n return false;\n targets += 1;\n }\n return targets > 0;\n }\n isRepairFile(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\n return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\n return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target)\n return true;\n }\n return false;\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n canonical(root, filename) {\n const fs = require('node:fs'), path = require('node:path');\n const pending = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor)\n throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n error(err) {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n";
|
|
2
|
+
export declare const CONFIG_REPAIR_BOOTSTRAP_SOURCE = "/**\n * Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n *\n * A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a\n * `webpieces.config.json` sits beside it) \u2014 the only two files a version pin or a `patchedDependencies`\n * registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.\n *\n * THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,\n * pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate\n * behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and\n * Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.\n * `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half\n * calls it directly, so the two halves cannot answer differently. It used to be answered three ways \u2014 a\n * `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate \u2014 and a\n * Codex rollback of `pnpm-workspace.yaml` matched none of them.\n *\n * ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a\n * recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`\n * segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the\n * repository is refused by `canonical()`.\n */\nclass ConfigRepairProbe {\n rootFor(cwd) {\n const fs = require('node:fs'), path = require('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory)\n return cwd;\n directory = parent;\n }\n return directory;\n }\n /**\n * `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` \u2192 `apply_patch`. Only the Codex\n * edit tool is canonicalized: every other name is returned untouched, so this can never turn an\n * unknown tool into one L0 trusts.\n */\n canonicalTool(toolName) {\n return /^(?:[A-Za-z0-9_-]+[.:/])+apply_patch$/.test(toolName) ? 'apply_patch' : toolName;\n }\n /**\n * The one question both L0 halves ask about an edit. Returns:\n * - `['not-an-edit']` \u2192 not an edit tool; L0 has no edit-escape opinion.\n * - `['config']` / `['manifest']` \u2192 every touched path is permitted (`manifest` when at least one\n * is a root manifest \u2014 the audit label).\n * - `['refused', ...lines]` \u2192 an edit that is NOT permitted, one line per offending path.\n */\n recoveryVerdict(cwd, toolName, filePath, command) {\n const tool = this.canonicalTool(toolName);\n let targets;\n if (['Write', 'Edit', 'MultiEdit'].includes(tool)) {\n if (filePath === '')\n return ['refused', 'the edit names no file_path'];\n targets = [['Edit', filePath]];\n }\n else if (tool === 'apply_patch') {\n const parsed = this.patchTargets(command);\n if (typeof parsed === 'string')\n return ['refused', parsed];\n targets = parsed;\n }\n else {\n return ['not-an-edit'];\n }\n const refusals = [];\n let manifest = false;\n for (const target of targets) {\n const op = target[0];\n const raw = target[1];\n const kind = this.targetKind(cwd, op, raw);\n if (kind === 'manifest')\n manifest = true;\n else if (kind !== 'config')\n refusals.push(`${op} ${raw}: ${kind}`);\n }\n if (refusals.length > 0)\n return ['refused', ...refusals];\n return [manifest ? 'manifest' : 'config'];\n }\n /**\n * Every `[op, rawPath]` an `apply_patch` envelope touches \u2014 Add, Update, Delete, and BOTH sides of a\n * Move \u2014 or a string saying why the envelope could not be read (fail closed: an envelope this does\n * not understand is never partially judged).\n */\n patchTargets(patch) {\n const lines = patch.replace(/\\r\\n/g, '\\n').trim().split('\\n');\n if (lines[0]?.trim() !== '*** Begin Patch' || lines.at(-1)?.trim() !== '*** End Patch')\n return 'the patch has no *** Begin Patch / *** End Patch envelope';\n const targets = [];\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** '))\n continue;\n const match = /^\\*\\*\\* (Add|Update|Delete) File: (.+)$/.exec(line) ?? /^\\*\\*\\* (Move) to: (.+)$/.exec(line);\n if (match) {\n targets.push([match[1], match[2].trim()]);\n continue;\n }\n if (line.trim() === '*** End of File')\n continue;\n return `unrecognised patch directive ${line.trim()}`;\n }\n return targets.length > 0 ? targets : 'the patch names no file';\n }\n /** `config`, `manifest`, or the reason this one path is not a recovery target. */\n targetKind(cwd, op, raw) {\n const path = require('node:path');\n if (op === 'Delete')\n return 'a Delete is never a recovery edit';\n if (raw === '' || raw.includes('\\0'))\n return 'an empty or malformed path';\n if (raw.split(/[\\\\/]/).includes('..'))\n return 'a .. path segment is refused - name the file directly';\n const fs = require('node:fs');\n const absolute = path.resolve(cwd, raw);\n // The governed tree the FILE sits in (main clone or any worktree); with none above it, the\n // session's own tree \u2014 so a path outside every governed tree is judged against, and contained\n // by, the repository the call came from.\n const own = this.rootFor(path.dirname(absolute));\n const root = fs.existsSync(path.join(own, 'webpieces.config.json')) ? own : this.rootFor(cwd);\n if (this.isRepairFile(root, absolute))\n return 'config';\n if (this.isRecoveryManifest(root, absolute))\n return 'manifest';\n return 'not webpieces.config.json, a .webpieces-config/ file, or the package.json / pnpm-workspace.yaml at a governed tree root';\n }\n /** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */\n isRecoveryManifest(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports; an unresolvable path is simply not a manifest\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n if (!['package.json', 'pnpm-workspace.yaml'].includes(path.basename(target)))\n return false;\n return fs.existsSync(path.join(path.dirname(target), 'webpieces.config.json'));\n // webpieces-disable catch-must-propagate -- a path that escapes the repository IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- a path that escapes the repository throws from canonical()\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n isRepairFile(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\n return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\n return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target)\n return true;\n }\n return false;\n // webpieces-disable catch-must-propagate -- an escaping path or malformed declaration IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n canonical(root, filename) {\n const fs = require('node:fs'), path = require('node:path');\n const pending = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor)\n throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n error(err) {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n";
|
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CONFIG_REPAIR_BOOTSTRAP_SOURCE = void 0;
|
|
4
4
|
/** Generated from ConfigRepairProbe by pnpm guards:generate; never edit this artifact. */
|
|
5
5
|
// webpieces-disable no-unmanaged-exceptions -- serialized bootstrap catches malformed external declarations without package imports
|
|
6
|
-
exports.CONFIG_REPAIR_BOOTSTRAP_SOURCE = "/**\n * Self-contained Node probe: serialized into the POSIX shim so repairs work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n */\nclass ConfigRepairProbe {\n rootFor(cwd) {\n const fs = require('node:fs'), path = require('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory)\n return cwd;\n directory = parent;\n }\n return directory;\n }\n isRepairPatch(root, patch) {\n const lines = patch.trim().split('\\n');\n if (lines[0] !== '*** Begin Patch' || lines.at(-1) !== '*** End Patch')\n return false;\n let targets = 0;\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** '))\n continue;\n const match = /^\\*\\*\\* (?:Add|Update) File: (.+)$/.exec(line);\n if (!match || !this.isRepairFile(root, match[1]))\n return false;\n targets += 1;\n }\n return targets > 0;\n }\n isRepairFile(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\n return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\n return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target)\n return true;\n }\n return false;\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n canonical(root, filename) {\n const fs = require('node:fs'), path = require('node:path');\n const pending = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor)\n throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n error(err) {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n";
|
|
6
|
+
exports.CONFIG_REPAIR_BOOTSTRAP_SOURCE = "/**\n * Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n *\n * A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a\n * `webpieces.config.json` sits beside it) — the only two files a version pin or a `patchedDependencies`\n * registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.\n *\n * THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,\n * pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate\n * behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and\n * Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.\n * `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half\n * calls it directly, so the two halves cannot answer differently. It used to be answered three ways — a\n * `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate — and a\n * Codex rollback of `pnpm-workspace.yaml` matched none of them.\n *\n * ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a\n * recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`\n * segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the\n * repository is refused by `canonical()`.\n */\nclass ConfigRepairProbe {\n rootFor(cwd) {\n const fs = require('node:fs'), path = require('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory)\n return cwd;\n directory = parent;\n }\n return directory;\n }\n /**\n * `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` → `apply_patch`. Only the Codex\n * edit tool is canonicalized: every other name is returned untouched, so this can never turn an\n * unknown tool into one L0 trusts.\n */\n canonicalTool(toolName) {\n return /^(?:[A-Za-z0-9_-]+[.:/])+apply_patch$/.test(toolName) ? 'apply_patch' : toolName;\n }\n /**\n * The one question both L0 halves ask about an edit. Returns:\n * - `['not-an-edit']` → not an edit tool; L0 has no edit-escape opinion.\n * - `['config']` / `['manifest']` → every touched path is permitted (`manifest` when at least one\n * is a root manifest — the audit label).\n * - `['refused', ...lines]` → an edit that is NOT permitted, one line per offending path.\n */\n recoveryVerdict(cwd, toolName, filePath, command) {\n const tool = this.canonicalTool(toolName);\n let targets;\n if (['Write', 'Edit', 'MultiEdit'].includes(tool)) {\n if (filePath === '')\n return ['refused', 'the edit names no file_path'];\n targets = [['Edit', filePath]];\n }\n else if (tool === 'apply_patch') {\n const parsed = this.patchTargets(command);\n if (typeof parsed === 'string')\n return ['refused', parsed];\n targets = parsed;\n }\n else {\n return ['not-an-edit'];\n }\n const refusals = [];\n let manifest = false;\n for (const target of targets) {\n const op = target[0];\n const raw = target[1];\n const kind = this.targetKind(cwd, op, raw);\n if (kind === 'manifest')\n manifest = true;\n else if (kind !== 'config')\n refusals.push(`${op} ${raw}: ${kind}`);\n }\n if (refusals.length > 0)\n return ['refused', ...refusals];\n return [manifest ? 'manifest' : 'config'];\n }\n /**\n * Every `[op, rawPath]` an `apply_patch` envelope touches — Add, Update, Delete, and BOTH sides of a\n * Move — or a string saying why the envelope could not be read (fail closed: an envelope this does\n * not understand is never partially judged).\n */\n patchTargets(patch) {\n const lines = patch.replace(/\\r\\n/g, '\\n').trim().split('\\n');\n if (lines[0]?.trim() !== '*** Begin Patch' || lines.at(-1)?.trim() !== '*** End Patch')\n return 'the patch has no *** Begin Patch / *** End Patch envelope';\n const targets = [];\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** '))\n continue;\n const match = /^\\*\\*\\* (Add|Update|Delete) File: (.+)$/.exec(line) ?? /^\\*\\*\\* (Move) to: (.+)$/.exec(line);\n if (match) {\n targets.push([match[1], match[2].trim()]);\n continue;\n }\n if (line.trim() === '*** End of File')\n continue;\n return `unrecognised patch directive ${line.trim()}`;\n }\n return targets.length > 0 ? targets : 'the patch names no file';\n }\n /** `config`, `manifest`, or the reason this one path is not a recovery target. */\n targetKind(cwd, op, raw) {\n const path = require('node:path');\n if (op === 'Delete')\n return 'a Delete is never a recovery edit';\n if (raw === '' || raw.includes('\\0'))\n return 'an empty or malformed path';\n if (raw.split(/[\\\\/]/).includes('..'))\n return 'a .. path segment is refused - name the file directly';\n const fs = require('node:fs');\n const absolute = path.resolve(cwd, raw);\n // The governed tree the FILE sits in (main clone or any worktree); with none above it, the\n // session's own tree — so a path outside every governed tree is judged against, and contained\n // by, the repository the call came from.\n const own = this.rootFor(path.dirname(absolute));\n const root = fs.existsSync(path.join(own, 'webpieces.config.json')) ? own : this.rootFor(cwd);\n if (this.isRepairFile(root, absolute))\n return 'config';\n if (this.isRecoveryManifest(root, absolute))\n return 'manifest';\n return 'not webpieces.config.json, a .webpieces-config/ file, or the package.json / pnpm-workspace.yaml at a governed tree root';\n }\n /** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */\n isRecoveryManifest(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports; an unresolvable path is simply not a manifest\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n if (!['package.json', 'pnpm-workspace.yaml'].includes(path.basename(target)))\n return false;\n return fs.existsSync(path.join(path.dirname(target), 'webpieces.config.json'));\n // webpieces-disable catch-must-propagate -- a path that escapes the repository IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- a path that escapes the repository throws from canonical()\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n isRepairFile(root, filename) {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs'), path = require('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\n return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\n return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target)\n return true;\n }\n return false;\n // webpieces-disable catch-must-propagate -- an escaping path or malformed declaration IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n }\n catch (err) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n canonical(root, filename) {\n const fs = require('node:fs'), path = require('node:path');\n const pending = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor)\n throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n error(err) {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n";
|
|
7
7
|
//# sourceMappingURL=config-repair-bootstrap-source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-repair-bootstrap-source.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-bootstrap-source.ts"],"names":[],"mappings":";;;AAAA,0FAA0F;AAC1F,oIAAoI;AACvH,QAAA,8BAA8B,GAAG,o2IAAo2I,CAAC","sourcesContent":["/** Generated from ConfigRepairProbe by pnpm guards:generate; never edit this artifact. */\n// webpieces-disable no-unmanaged-exceptions -- serialized bootstrap catches malformed external declarations without package imports\nexport const CONFIG_REPAIR_BOOTSTRAP_SOURCE = \"/**\\n * Self-contained Node probe: serialized into the POSIX shim so repairs work with missing packages.\\n *\\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\\n */\\nclass ConfigRepairProbe {\\n rootFor(cwd) {\\n const fs = require('node:fs'), path = require('node:path');\\n let directory = path.resolve(cwd);\\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\\n const parent = path.dirname(directory);\\n if (parent === directory)\\n return cwd;\\n directory = parent;\\n }\\n return directory;\\n }\\n isRepairPatch(root, patch) {\\n const lines = patch.trim().split('\\\\n');\\n if (lines[0] !== '*** Begin Patch' || lines.at(-1) !== '*** End Patch')\\n return false;\\n let targets = 0;\\n for (const line of lines.slice(1, -1)) {\\n if (!line.startsWith('*** '))\\n continue;\\n const match = /^\\\\*\\\\*\\\\* (?:Add|Update) File: (.+)$/.exec(line);\\n if (!match || !this.isRepairFile(root, match[1]))\\n return false;\\n targets += 1;\\n }\\n return targets > 0;\\n }\\n isRepairFile(root, filename) {\\n const toError = this.error;\\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\\n try {\\n const fs = require('node:fs'), path = require('node:path');\\n const target = this.canonical(root, path.resolve(root, filename));\\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\\n return true;\\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\\n return true;\\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\\n return false;\\n for (const declaration of raw.rulePacks) {\\n if (declaration &&\\n typeof declaration === 'object' &&\\n typeof declaration.config === 'string' &&\\n declaration.config.endsWith('.json') &&\\n !path.isAbsolute(declaration.config) &&\\n this.canonical(root, path.join(root, declaration.config)) === target)\\n return true;\\n }\\n return false;\\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\\n }\\n catch (err) {\\n const error = toError(err);\\n void error;\\n return false;\\n }\\n }\\n canonical(root, filename) {\\n const fs = require('node:fs'), path = require('node:path');\\n const pending = [];\\n let ancestor = filename;\\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\\n pending.unshift(path.basename(ancestor));\\n const parent = path.dirname(ancestor);\\n if (parent === ancestor)\\n throw new Error('Cannot resolve config repair path.');\\n ancestor = parent;\\n }\\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\\n throw new Error('Config repair path escapes the repository.');\\n return canonical;\\n }\\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\\n error(err) {\\n return err instanceof Error ? err : new Error(String(err));\\n }\\n}\\n\";\n"]}
|
|
1
|
+
{"version":3,"file":"config-repair-bootstrap-source.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-bootstrap-source.ts"],"names":[],"mappings":";;;AAAA,0FAA0F;AAC1F,oIAAoI;AACvH,QAAA,8BAA8B,GAAG,u+VAAu+V,CAAC","sourcesContent":["/** Generated from ConfigRepairProbe by pnpm guards:generate; never edit this artifact. */\n// webpieces-disable no-unmanaged-exceptions -- serialized bootstrap catches malformed external declarations without package imports\nexport const CONFIG_REPAIR_BOOTSTRAP_SOURCE = \"/**\\n * Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.\\n *\\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\\n *\\n * A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a\\n * `webpieces.config.json` sits beside it) — the only two files a version pin or a `patchedDependencies`\\n * registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.\\n *\\n * THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,\\n * pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate\\n * behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and\\n * Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.\\n * `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half\\n * calls it directly, so the two halves cannot answer differently. It used to be answered three ways — a\\n * `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate — and a\\n * Codex rollback of `pnpm-workspace.yaml` matched none of them.\\n *\\n * ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a\\n * recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`\\n * segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the\\n * repository is refused by `canonical()`.\\n */\\nclass ConfigRepairProbe {\\n rootFor(cwd) {\\n const fs = require('node:fs'), path = require('node:path');\\n let directory = path.resolve(cwd);\\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\\n const parent = path.dirname(directory);\\n if (parent === directory)\\n return cwd;\\n directory = parent;\\n }\\n return directory;\\n }\\n /**\\n * `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` → `apply_patch`. Only the Codex\\n * edit tool is canonicalized: every other name is returned untouched, so this can never turn an\\n * unknown tool into one L0 trusts.\\n */\\n canonicalTool(toolName) {\\n return /^(?:[A-Za-z0-9_-]+[.:/])+apply_patch$/.test(toolName) ? 'apply_patch' : toolName;\\n }\\n /**\\n * The one question both L0 halves ask about an edit. Returns:\\n * - `['not-an-edit']` → not an edit tool; L0 has no edit-escape opinion.\\n * - `['config']` / `['manifest']` → every touched path is permitted (`manifest` when at least one\\n * is a root manifest — the audit label).\\n * - `['refused', ...lines]` → an edit that is NOT permitted, one line per offending path.\\n */\\n recoveryVerdict(cwd, toolName, filePath, command) {\\n const tool = this.canonicalTool(toolName);\\n let targets;\\n if (['Write', 'Edit', 'MultiEdit'].includes(tool)) {\\n if (filePath === '')\\n return ['refused', 'the edit names no file_path'];\\n targets = [['Edit', filePath]];\\n }\\n else if (tool === 'apply_patch') {\\n const parsed = this.patchTargets(command);\\n if (typeof parsed === 'string')\\n return ['refused', parsed];\\n targets = parsed;\\n }\\n else {\\n return ['not-an-edit'];\\n }\\n const refusals = [];\\n let manifest = false;\\n for (const target of targets) {\\n const op = target[0];\\n const raw = target[1];\\n const kind = this.targetKind(cwd, op, raw);\\n if (kind === 'manifest')\\n manifest = true;\\n else if (kind !== 'config')\\n refusals.push(`${op} ${raw}: ${kind}`);\\n }\\n if (refusals.length > 0)\\n return ['refused', ...refusals];\\n return [manifest ? 'manifest' : 'config'];\\n }\\n /**\\n * Every `[op, rawPath]` an `apply_patch` envelope touches — Add, Update, Delete, and BOTH sides of a\\n * Move — or a string saying why the envelope could not be read (fail closed: an envelope this does\\n * not understand is never partially judged).\\n */\\n patchTargets(patch) {\\n const lines = patch.replace(/\\\\r\\\\n/g, '\\\\n').trim().split('\\\\n');\\n if (lines[0]?.trim() !== '*** Begin Patch' || lines.at(-1)?.trim() !== '*** End Patch')\\n return 'the patch has no *** Begin Patch / *** End Patch envelope';\\n const targets = [];\\n for (const line of lines.slice(1, -1)) {\\n if (!line.startsWith('*** '))\\n continue;\\n const match = /^\\\\*\\\\*\\\\* (Add|Update|Delete) File: (.+)$/.exec(line) ?? /^\\\\*\\\\*\\\\* (Move) to: (.+)$/.exec(line);\\n if (match) {\\n targets.push([match[1], match[2].trim()]);\\n continue;\\n }\\n if (line.trim() === '*** End of File')\\n continue;\\n return `unrecognised patch directive ${line.trim()}`;\\n }\\n return targets.length > 0 ? targets : 'the patch names no file';\\n }\\n /** `config`, `manifest`, or the reason this one path is not a recovery target. */\\n targetKind(cwd, op, raw) {\\n const path = require('node:path');\\n if (op === 'Delete')\\n return 'a Delete is never a recovery edit';\\n if (raw === '' || raw.includes('\\\\0'))\\n return 'an empty or malformed path';\\n if (raw.split(/[\\\\\\\\/]/).includes('..'))\\n return 'a .. path segment is refused - name the file directly';\\n const fs = require('node:fs');\\n const absolute = path.resolve(cwd, raw);\\n // The governed tree the FILE sits in (main clone or any worktree); with none above it, the\\n // session's own tree — so a path outside every governed tree is judged against, and contained\\n // by, the repository the call came from.\\n const own = this.rootFor(path.dirname(absolute));\\n const root = fs.existsSync(path.join(own, 'webpieces.config.json')) ? own : this.rootFor(cwd);\\n if (this.isRepairFile(root, absolute))\\n return 'config';\\n if (this.isRecoveryManifest(root, absolute))\\n return 'manifest';\\n return 'not webpieces.config.json, a .webpieces-config/ file, or the package.json / pnpm-workspace.yaml at a governed tree root';\\n }\\n /** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */\\n isRecoveryManifest(root, filename) {\\n const toError = this.error;\\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports; an unresolvable path is simply not a manifest\\n try {\\n const fs = require('node:fs'), path = require('node:path');\\n const target = this.canonical(root, path.resolve(root, filename));\\n if (!['package.json', 'pnpm-workspace.yaml'].includes(path.basename(target)))\\n return false;\\n return fs.existsSync(path.join(path.dirname(target), 'webpieces.config.json'));\\n // webpieces-disable catch-must-propagate -- a path that escapes the repository IS the refusal verdict; the error carries nothing a caller could act on\\n // webpieces-disable no-any-unknown -- a path that escapes the repository throws from canonical()\\n }\\n catch (err) {\\n const error = toError(err);\\n void error;\\n return false;\\n }\\n }\\n isRepairFile(root, filename) {\\n const toError = this.error;\\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\\n try {\\n const fs = require('node:fs'), path = require('node:path');\\n const target = this.canonical(root, path.resolve(root, filename));\\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore')))\\n return true;\\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy))\\n return true;\\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\\n const raw = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\\n return false;\\n for (const declaration of raw.rulePacks) {\\n if (declaration &&\\n typeof declaration === 'object' &&\\n typeof declaration.config === 'string' &&\\n declaration.config.endsWith('.json') &&\\n !path.isAbsolute(declaration.config) &&\\n this.canonical(root, path.join(root, declaration.config)) === target)\\n return true;\\n }\\n return false;\\n // webpieces-disable catch-must-propagate -- an escaping path or malformed declaration IS the refusal verdict; the error carries nothing a caller could act on\\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\\n }\\n catch (err) {\\n const error = toError(err);\\n void error;\\n return false;\\n }\\n }\\n canonical(root, filename) {\\n const fs = require('node:fs'), path = require('node:path');\\n const pending = [];\\n let ancestor = filename;\\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\\n pending.unshift(path.basename(ancestor));\\n const parent = path.dirname(ancestor);\\n if (parent === ancestor)\\n throw new Error('Cannot resolve config repair path.');\\n ancestor = parent;\\n }\\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending), relative = path.relative(fs.realpathSync(root), canonical);\\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\\n throw new Error('Config repair path escapes the repository.');\\n return canonical;\\n }\\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\\n error(err) {\\n return err instanceof Error ? err : new Error(String(err));\\n }\\n}\\n\";\n"]}
|
|
@@ -1,18 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Self-contained Node probe: serialized into the POSIX shim so
|
|
2
|
+
* Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.
|
|
3
3
|
*
|
|
4
4
|
* A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the
|
|
5
5
|
* config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,
|
|
6
6
|
* and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.
|
|
7
|
+
*
|
|
8
|
+
* A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a
|
|
9
|
+
* `webpieces.config.json` sits beside it) — the only two files a version pin or a `patchedDependencies`
|
|
10
|
+
* registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.
|
|
11
|
+
*
|
|
12
|
+
* THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,
|
|
13
|
+
* pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate
|
|
14
|
+
* behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and
|
|
15
|
+
* Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.
|
|
16
|
+
* `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half
|
|
17
|
+
* calls it directly, so the two halves cannot answer differently. It used to be answered three ways — a
|
|
18
|
+
* `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate — and a
|
|
19
|
+
* Codex rollback of `pnpm-workspace.yaml` matched none of them.
|
|
20
|
+
*
|
|
21
|
+
* ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a
|
|
22
|
+
* recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`
|
|
23
|
+
* segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the
|
|
24
|
+
* repository is refused by `canonical()`.
|
|
7
25
|
*/
|
|
8
26
|
export declare class ConfigRepairProbe {
|
|
9
27
|
rootFor(cwd: string): string;
|
|
10
|
-
|
|
28
|
+
/**
|
|
29
|
+
* `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` → `apply_patch`. Only the Codex
|
|
30
|
+
* edit tool is canonicalized: every other name is returned untouched, so this can never turn an
|
|
31
|
+
* unknown tool into one L0 trusts.
|
|
32
|
+
*/
|
|
33
|
+
canonicalTool(toolName: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* The one question both L0 halves ask about an edit. Returns:
|
|
36
|
+
* - `['not-an-edit']` → not an edit tool; L0 has no edit-escape opinion.
|
|
37
|
+
* - `['config']` / `['manifest']` → every touched path is permitted (`manifest` when at least one
|
|
38
|
+
* is a root manifest — the audit label).
|
|
39
|
+
* - `['refused', ...lines]` → an edit that is NOT permitted, one line per offending path.
|
|
40
|
+
*/
|
|
41
|
+
recoveryVerdict(cwd: string, toolName: string, filePath: string, command: string): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Every `[op, rawPath]` an `apply_patch` envelope touches — Add, Update, Delete, and BOTH sides of a
|
|
44
|
+
* Move — or a string saying why the envelope could not be read (fail closed: an envelope this does
|
|
45
|
+
* not understand is never partially judged).
|
|
46
|
+
*/
|
|
47
|
+
patchTargets(patch: string): string[][] | string;
|
|
48
|
+
/** `config`, `manifest`, or the reason this one path is not a recovery target. */
|
|
49
|
+
targetKind(cwd: string, op: string, raw: string): string;
|
|
50
|
+
/** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */
|
|
51
|
+
isRecoveryManifest(root: string, filename: string): boolean;
|
|
11
52
|
isRepairFile(root: string, filename: string): boolean;
|
|
12
53
|
private canonical;
|
|
13
54
|
private error;
|
|
14
55
|
}
|
|
15
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Emits the same compiled probe class; the shell has no separate declaration/path algorithm.
|
|
58
|
+
*
|
|
59
|
+
* `callScript()` is the shim's ONE edit-escape call. Its exit code is the protocol with the sh half:
|
|
60
|
+
* 0 → permitted; stdout is `config` or `manifest` (the audit label).
|
|
61
|
+
* 1 → not an edit tool (or unreadable stdin); the shim keeps going down its allowlist.
|
|
62
|
+
* 3 → an edit that is NOT permitted; stdout is one line per offending path, for the deny.
|
|
63
|
+
*/
|
|
16
64
|
export declare class ConfigRepairBootstrap {
|
|
17
65
|
script(): string;
|
|
18
66
|
callScript(): string;
|
|
@@ -3,11 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConfigRepairBootstrap = exports.ConfigRepairProbe = void 0;
|
|
4
4
|
const config_repair_bootstrap_source_1 = require("./config-repair-bootstrap-source");
|
|
5
5
|
/**
|
|
6
|
-
* Self-contained Node probe: serialized into the POSIX shim so
|
|
6
|
+
* Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.
|
|
7
7
|
*
|
|
8
8
|
* A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the
|
|
9
9
|
* config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,
|
|
10
10
|
* and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.
|
|
11
|
+
*
|
|
12
|
+
* A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a
|
|
13
|
+
* `webpieces.config.json` sits beside it) — the only two files a version pin or a `patchedDependencies`
|
|
14
|
+
* registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.
|
|
15
|
+
*
|
|
16
|
+
* THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,
|
|
17
|
+
* pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate
|
|
18
|
+
* behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and
|
|
19
|
+
* Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.
|
|
20
|
+
* `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half
|
|
21
|
+
* calls it directly, so the two halves cannot answer differently. It used to be answered three ways — a
|
|
22
|
+
* `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate — and a
|
|
23
|
+
* Codex rollback of `pnpm-workspace.yaml` matched none of them.
|
|
24
|
+
*
|
|
25
|
+
* ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a
|
|
26
|
+
* recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`
|
|
27
|
+
* segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the
|
|
28
|
+
* repository is refused by `canonical()`.
|
|
11
29
|
*/
|
|
12
30
|
class ConfigRepairProbe {
|
|
13
31
|
rootFor(cwd) {
|
|
@@ -21,20 +39,117 @@ class ConfigRepairProbe {
|
|
|
21
39
|
}
|
|
22
40
|
return directory;
|
|
23
41
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
/**
|
|
43
|
+
* `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` → `apply_patch`. Only the Codex
|
|
44
|
+
* edit tool is canonicalized: every other name is returned untouched, so this can never turn an
|
|
45
|
+
* unknown tool into one L0 trusts.
|
|
46
|
+
*/
|
|
47
|
+
canonicalTool(toolName) {
|
|
48
|
+
return /^(?:[A-Za-z0-9_-]+[.:/])+apply_patch$/.test(toolName) ? 'apply_patch' : toolName;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The one question both L0 halves ask about an edit. Returns:
|
|
52
|
+
* - `['not-an-edit']` → not an edit tool; L0 has no edit-escape opinion.
|
|
53
|
+
* - `['config']` / `['manifest']` → every touched path is permitted (`manifest` when at least one
|
|
54
|
+
* is a root manifest — the audit label).
|
|
55
|
+
* - `['refused', ...lines]` → an edit that is NOT permitted, one line per offending path.
|
|
56
|
+
*/
|
|
57
|
+
recoveryVerdict(cwd, toolName, filePath, command) {
|
|
58
|
+
const tool = this.canonicalTool(toolName);
|
|
59
|
+
let targets;
|
|
60
|
+
if (['Write', 'Edit', 'MultiEdit'].includes(tool)) {
|
|
61
|
+
if (filePath === '')
|
|
62
|
+
return ['refused', 'the edit names no file_path'];
|
|
63
|
+
targets = [['Edit', filePath]];
|
|
64
|
+
}
|
|
65
|
+
else if (tool === 'apply_patch') {
|
|
66
|
+
const parsed = this.patchTargets(command);
|
|
67
|
+
if (typeof parsed === 'string')
|
|
68
|
+
return ['refused', parsed];
|
|
69
|
+
targets = parsed;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return ['not-an-edit'];
|
|
73
|
+
}
|
|
74
|
+
const refusals = [];
|
|
75
|
+
let manifest = false;
|
|
76
|
+
for (const target of targets) {
|
|
77
|
+
const op = target[0];
|
|
78
|
+
const raw = target[1];
|
|
79
|
+
const kind = this.targetKind(cwd, op, raw);
|
|
80
|
+
if (kind === 'manifest')
|
|
81
|
+
manifest = true;
|
|
82
|
+
else if (kind !== 'config')
|
|
83
|
+
refusals.push(`${op} ${raw}: ${kind}`);
|
|
84
|
+
}
|
|
85
|
+
if (refusals.length > 0)
|
|
86
|
+
return ['refused', ...refusals];
|
|
87
|
+
return [manifest ? 'manifest' : 'config'];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Every `[op, rawPath]` an `apply_patch` envelope touches — Add, Update, Delete, and BOTH sides of a
|
|
91
|
+
* Move — or a string saying why the envelope could not be read (fail closed: an envelope this does
|
|
92
|
+
* not understand is never partially judged).
|
|
93
|
+
*/
|
|
94
|
+
patchTargets(patch) {
|
|
95
|
+
const lines = patch.replace(/\r\n/g, '\n').trim().split('\n');
|
|
96
|
+
if (lines[0]?.trim() !== '*** Begin Patch' || lines.at(-1)?.trim() !== '*** End Patch')
|
|
97
|
+
return 'the patch has no *** Begin Patch / *** End Patch envelope';
|
|
98
|
+
const targets = [];
|
|
29
99
|
for (const line of lines.slice(1, -1)) {
|
|
30
100
|
if (!line.startsWith('*** '))
|
|
31
101
|
continue;
|
|
32
|
-
const match = /^\*\*\* (
|
|
33
|
-
if (
|
|
102
|
+
const match = /^\*\*\* (Add|Update|Delete) File: (.+)$/.exec(line) ?? /^\*\*\* (Move) to: (.+)$/.exec(line);
|
|
103
|
+
if (match) {
|
|
104
|
+
targets.push([match[1], match[2].trim()]);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (line.trim() === '*** End of File')
|
|
108
|
+
continue;
|
|
109
|
+
return `unrecognised patch directive ${line.trim()}`;
|
|
110
|
+
}
|
|
111
|
+
return targets.length > 0 ? targets : 'the patch names no file';
|
|
112
|
+
}
|
|
113
|
+
/** `config`, `manifest`, or the reason this one path is not a recovery target. */
|
|
114
|
+
targetKind(cwd, op, raw) {
|
|
115
|
+
const path = require('node:path');
|
|
116
|
+
if (op === 'Delete')
|
|
117
|
+
return 'a Delete is never a recovery edit';
|
|
118
|
+
if (raw === '' || raw.includes('\0'))
|
|
119
|
+
return 'an empty or malformed path';
|
|
120
|
+
if (raw.split(/[\\/]/).includes('..'))
|
|
121
|
+
return 'a .. path segment is refused - name the file directly';
|
|
122
|
+
const fs = require('node:fs');
|
|
123
|
+
const absolute = path.resolve(cwd, raw);
|
|
124
|
+
// The governed tree the FILE sits in (main clone or any worktree); with none above it, the
|
|
125
|
+
// session's own tree — so a path outside every governed tree is judged against, and contained
|
|
126
|
+
// by, the repository the call came from.
|
|
127
|
+
const own = this.rootFor(path.dirname(absolute));
|
|
128
|
+
const root = fs.existsSync(path.join(own, 'webpieces.config.json')) ? own : this.rootFor(cwd);
|
|
129
|
+
if (this.isRepairFile(root, absolute))
|
|
130
|
+
return 'config';
|
|
131
|
+
if (this.isRecoveryManifest(root, absolute))
|
|
132
|
+
return 'manifest';
|
|
133
|
+
return 'not webpieces.config.json, a .webpieces-config/ file, or the package.json / pnpm-workspace.yaml at a governed tree root';
|
|
134
|
+
}
|
|
135
|
+
/** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */
|
|
136
|
+
isRecoveryManifest(root, filename) {
|
|
137
|
+
const toError = this.error;
|
|
138
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports; an unresolvable path is simply not a manifest
|
|
139
|
+
try {
|
|
140
|
+
const fs = require('node:fs'), path = require('node:path');
|
|
141
|
+
const target = this.canonical(root, path.resolve(root, filename));
|
|
142
|
+
if (!['package.json', 'pnpm-workspace.yaml'].includes(path.basename(target)))
|
|
34
143
|
return false;
|
|
35
|
-
|
|
144
|
+
return fs.existsSync(path.join(path.dirname(target), 'webpieces.config.json'));
|
|
145
|
+
// webpieces-disable catch-must-propagate -- a path that escapes the repository IS the refusal verdict; the error carries nothing a caller could act on
|
|
146
|
+
// webpieces-disable no-any-unknown -- a path that escapes the repository throws from canonical()
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
const error = toError(err);
|
|
150
|
+
void error;
|
|
151
|
+
return false;
|
|
36
152
|
}
|
|
37
|
-
return targets > 0;
|
|
38
153
|
}
|
|
39
154
|
isRepairFile(root, filename) {
|
|
40
155
|
const toError = this.error;
|
|
@@ -62,6 +177,7 @@ class ConfigRepairProbe {
|
|
|
62
177
|
return true;
|
|
63
178
|
}
|
|
64
179
|
return false;
|
|
180
|
+
// webpieces-disable catch-must-propagate -- an escaping path or malformed declaration IS the refusal verdict; the error carries nothing a caller could act on
|
|
65
181
|
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
66
182
|
}
|
|
67
183
|
catch (err) {
|
|
@@ -92,13 +208,20 @@ class ConfigRepairProbe {
|
|
|
92
208
|
}
|
|
93
209
|
}
|
|
94
210
|
exports.ConfigRepairProbe = ConfigRepairProbe;
|
|
95
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Emits the same compiled probe class; the shell has no separate declaration/path algorithm.
|
|
213
|
+
*
|
|
214
|
+
* `callScript()` is the shim's ONE edit-escape call. Its exit code is the protocol with the sh half:
|
|
215
|
+
* 0 → permitted; stdout is `config` or `manifest` (the audit label).
|
|
216
|
+
* 1 → not an edit tool (or unreadable stdin); the shim keeps going down its allowlist.
|
|
217
|
+
* 3 → an edit that is NOT permitted; stdout is one line per offending path, for the deny.
|
|
218
|
+
*/
|
|
96
219
|
class ConfigRepairBootstrap {
|
|
97
220
|
script() {
|
|
98
221
|
return `${config_repair_bootstrap_source_1.CONFIG_REPAIR_BOOTSTRAP_SOURCE} if (!new ConfigRepairProbe().isRepairFile(process.argv[1], process.argv[2])) process.exitCode = 1;`;
|
|
99
222
|
}
|
|
100
223
|
callScript() {
|
|
101
|
-
return `${config_repair_bootstrap_source_1.CONFIG_REPAIR_BOOTSTRAP_SOURCE} const
|
|
224
|
+
return `${config_repair_bootstrap_source_1.CONFIG_REPAIR_BOOTSTRAP_SOURCE} const payload = JSON.parse(require('node:fs').readFileSync(0, 'utf8')); const input = payload.tool_input || {}; const verdict = new ConfigRepairProbe().recoveryVerdict(typeof payload.cwd === 'string' && payload.cwd !== '' ? payload.cwd : process.argv[1], String(payload.tool_name || ''), typeof input.file_path === 'string' ? input.file_path : '', typeof input.command === 'string' ? input.command : ''); if (verdict[0] === 'not-an-edit') process.exitCode = 1; else if (verdict[0] === 'refused') { process.stdout.write(verdict.slice(1).join('\\n')); process.exitCode = 3; } else process.stdout.write(verdict[0]);`;
|
|
102
225
|
}
|
|
103
226
|
}
|
|
104
227
|
exports.ConfigRepairBootstrap = ConfigRepairBootstrap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-repair-probe.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-probe.ts"],"names":[],"mappings":";;;AAAA,qFAAkF;AAElF;;;;;;GAMG;AACH,MAAa,iBAAiB;IAC1B,OAAO,CAAC,GAAW;QACf,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAA6B,EACrD,IAAI,GAAG,OAAO,CAAC,WAAW,CAA+B,CAAC;QAC9D,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC;YACnE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,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AAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACtF,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAClE,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,oHAAoH;IAC5G,KAAK,CAAC,GAAY;QACtB,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;CACJ;AAnFD,8CAmFC;AAED,iGAAiG;AACjG,MAAa,qBAAqB;IAC9B,MAAM;QACF,OAAO,GAAG,+DAA8B,qGAAqG,CAAC;IAClJ,CAAC;IAED,UAAU;QACN,OAAO,GAAG,+DAA8B,ghBAAghB,CAAC;IAC7jB,CAAC;CACJ;AARD,sDAQC","sourcesContent":["import { CONFIG_REPAIR_BOOTSTRAP_SOURCE } from './config-repair-bootstrap-source';\n\n/**\n * Self-contained Node probe: serialized into the POSIX shim so repairs work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n */\nexport class ConfigRepairProbe {\n rootFor(cwd: string): string {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory) return cwd;\n directory = parent;\n }\n return directory;\n }\n\n isRepairPatch(root: string, patch: string): boolean {\n const lines = patch.trim().split('\\n');\n if (lines[0] !== '*** Begin Patch' || lines.at(-1) !== '*** End Patch') return false;\n let targets = 0;\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** ')) continue;\n const match = /^\\*\\*\\* (?:Add|Update) File: (.+)$/.exec(line);\n if (!match || !this.isRepairFile(root, match[1])) return false;\n targets += 1;\n }\n return targets > 0;\n }\n\n isRepairFile(root: string, filename: string): boolean {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore'))) return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy)) return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw: unknown = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (\n declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target\n )\n return true;\n }\n return false;\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n private canonical(root: string, filename: string): string {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n const pending: string[] = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor) throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending),\n relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n private error(err: unknown): Error {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n\n/** Emits the same compiled probe class; the shell has no separate declaration/path algorithm. */\nexport class ConfigRepairBootstrap {\n script(): string {\n return `${CONFIG_REPAIR_BOOTSTRAP_SOURCE} if (!new ConfigRepairProbe().isRepairFile(process.argv[1], process.argv[2])) process.exitCode = 1;`;\n }\n\n callScript(): string {\n return `${CONFIG_REPAIR_BOOTSTRAP_SOURCE} const probe = new ConfigRepairProbe(); const root = probe.rootFor(process.argv[1]); const payload = JSON.parse(require('node:fs').readFileSync(0, 'utf8')); const input = payload.tool_input; const tool = payload.tool_name; const allowed = ['Write','Edit','MultiEdit'].includes(tool) && input && typeof input.file_path === 'string' ? probe.isRepairFile(root, input.file_path) : tool === 'apply_patch' && input && typeof input.command === 'string' && probe.isRepairPatch(root, input.command); if (!allowed) process.exitCode = 1;`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config-repair-probe.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-repair-probe.ts"],"names":[],"mappings":";;;AAAA,qFAAkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,iBAAiB;IAC1B,OAAO,CAAC,GAAW;QACf,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAA6B,EACrD,IAAI,GAAG,OAAO,CAAC,WAAW,CAA+B,CAAC;QAC9D,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC;YACnE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACvC,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,GAAG,CAAC;YACrC,SAAS,GAAG,MAAM,CAAC;QACvB,CAAC;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K,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACtF,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAClE,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,oHAAoH;IAC5G,KAAK,CAAC,GAAY;QACtB,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;CACJ;AA7KD,8CA6KC;AAED;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAC9B,MAAM;QACF,OAAO,GAAG,+DAA8B,qGAAqG,CAAC;IAClJ,CAAC;IAED,UAAU;QACN,OAAO,GAAG,+DAA8B,umBAAumB,CAAC;IACppB,CAAC;CACJ;AARD,sDAQC","sourcesContent":["import { CONFIG_REPAIR_BOOTSTRAP_SOURCE } from './config-repair-bootstrap-source';\n\n/**\n * Self-contained Node probe: serialized into the POSIX shim so recovery edits work with missing packages.\n *\n * A REPAIR FILE is one a config-repair deny can tell the agent to edit, so it is permitted while the\n * config is invalid: the root `webpieces.config.json`, `.gitignore`, everything under `.webpieces-config/`,\n * and any owner file `rulePacks` declares elsewhere. Nothing that resolves outside the repository counts.\n *\n * A RECOVERY MANIFEST is the `package.json` / `pnpm-workspace.yaml` at the ROOT of a governed tree (a\n * `webpieces.config.json` sits beside it) — the only two files a version pin or a `patchedDependencies`\n * registration lives in. Every OTHER `package.json` in the repo is ordinary code and is NOT one.\n *\n * THE ONE EDIT ESCAPE (issue #1448). Every L0 deny promises that an edit of webpieces.config.json,\n * pnpm-workspace.yaml or package.json is still allowed. `recoveryVerdict()` is the single predicate\n * behind that promise, for EVERY edit-tool spelling: Claude's Write/Edit/MultiEdit (`file_path`) and\n * Codex's `apply_patch` (`command` holds the patch; the name may arrive namespace-qualified, e.g.\n * `functions.apply_patch`). The sh half of L0 runs this compiled class through `node -e` and the JS half\n * calls it directly, so the two halves cannot answer differently. It used to be answered three ways — a\n * `file_path` scrape in sh, a config-only patch check here, and a `file_path`-only JS predicate — and a\n * Codex rollback of `pnpm-workspace.yaml` matched none of them.\n *\n * ATOMIC: a patch is permitted only when EVERY path it touches is permitted. A Delete is never a\n * recovery edit. A Move is judged on BOTH its source and its destination. A raw path carrying a `..`\n * segment is refused outright (a recovery edit never needs one), and a symlink that resolves outside the\n * repository is refused by `canonical()`.\n */\nexport class ConfigRepairProbe {\n rootFor(cwd: string): string {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n let directory = path.resolve(cwd);\n while (!fs.existsSync(path.join(directory, 'webpieces.config.json'))) {\n const parent = path.dirname(directory);\n if (parent === directory) return cwd;\n directory = parent;\n }\n return directory;\n }\n\n /**\n * `functions.apply_patch`, `tools.apply_patch`, `codex:apply_patch` → `apply_patch`. Only the Codex\n * edit tool is canonicalized: every other name is returned untouched, so this can never turn an\n * unknown tool into one L0 trusts.\n */\n canonicalTool(toolName: string): string {\n return /^(?:[A-Za-z0-9_-]+[.:/])+apply_patch$/.test(toolName) ? 'apply_patch' : toolName;\n }\n\n /**\n * The one question both L0 halves ask about an edit. Returns:\n * - `['not-an-edit']` → not an edit tool; L0 has no edit-escape opinion.\n * - `['config']` / `['manifest']` → every touched path is permitted (`manifest` when at least one\n * is a root manifest — the audit label).\n * - `['refused', ...lines]` → an edit that is NOT permitted, one line per offending path.\n */\n recoveryVerdict(cwd: string, toolName: string, filePath: string, command: string): string[] {\n const tool = this.canonicalTool(toolName);\n let targets: string[][];\n if (['Write', 'Edit', 'MultiEdit'].includes(tool)) {\n if (filePath === '') return ['refused', 'the edit names no file_path'];\n targets = [['Edit', filePath]];\n } else if (tool === 'apply_patch') {\n const parsed = this.patchTargets(command);\n if (typeof parsed === 'string') return ['refused', parsed];\n targets = parsed;\n } else {\n return ['not-an-edit'];\n }\n const refusals: string[] = [];\n let manifest = false;\n for (const target of targets) {\n const op = target[0];\n const raw = target[1];\n const kind = this.targetKind(cwd, op, raw);\n if (kind === 'manifest') manifest = true;\n else if (kind !== 'config') refusals.push(`${op} ${raw}: ${kind}`);\n }\n if (refusals.length > 0) return ['refused', ...refusals];\n return [manifest ? 'manifest' : 'config'];\n }\n\n /**\n * Every `[op, rawPath]` an `apply_patch` envelope touches — Add, Update, Delete, and BOTH sides of a\n * Move — or a string saying why the envelope could not be read (fail closed: an envelope this does\n * not understand is never partially judged).\n */\n patchTargets(patch: string): string[][] | string {\n const lines = patch.replace(/\\r\\n/g, '\\n').trim().split('\\n');\n if (lines[0]?.trim() !== '*** Begin Patch' || lines.at(-1)?.trim() !== '*** End Patch')\n return 'the patch has no *** Begin Patch / *** End Patch envelope';\n const targets: string[][] = [];\n for (const line of lines.slice(1, -1)) {\n if (!line.startsWith('*** ')) continue;\n const match = /^\\*\\*\\* (Add|Update|Delete) File: (.+)$/.exec(line) ?? /^\\*\\*\\* (Move) to: (.+)$/.exec(line);\n if (match) {\n targets.push([match[1], match[2].trim()]);\n continue;\n }\n if (line.trim() === '*** End of File') continue;\n return `unrecognised patch directive ${line.trim()}`;\n }\n return targets.length > 0 ? targets : 'the patch names no file';\n }\n\n /** `config`, `manifest`, or the reason this one path is not a recovery target. */\n targetKind(cwd: string, op: string, raw: string): string {\n const path = require('node:path') as typeof import('node:path');\n if (op === 'Delete') return 'a Delete is never a recovery edit';\n if (raw === '' || raw.includes('\\0')) return 'an empty or malformed path';\n if (raw.split(/[\\\\/]/).includes('..')) return 'a .. path segment is refused - name the file directly';\n const fs = require('node:fs') as typeof import('node:fs');\n const absolute = path.resolve(cwd, raw);\n // The governed tree the FILE sits in (main clone or any worktree); with none above it, the\n // session's own tree — so a path outside every governed tree is judged against, and contained\n // by, the repository the call came from.\n const own = this.rootFor(path.dirname(absolute));\n const root = fs.existsSync(path.join(own, 'webpieces.config.json')) ? own : this.rootFor(cwd);\n if (this.isRepairFile(root, absolute)) return 'config';\n if (this.isRecoveryManifest(root, absolute)) return 'manifest';\n return 'not webpieces.config.json, a .webpieces-config/ file, or the package.json / pnpm-workspace.yaml at a governed tree root';\n }\n\n /** The root `package.json` / `pnpm-workspace.yaml` of a governed tree, resolved inside the repository. */\n isRecoveryManifest(root: string, filename: string): boolean {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports; an unresolvable path is simply not a manifest\n try {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n if (!['package.json', 'pnpm-workspace.yaml'].includes(path.basename(target))) return false;\n return fs.existsSync(path.join(path.dirname(target), 'webpieces.config.json'));\n // webpieces-disable catch-must-propagate -- a path that escapes the repository IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- a path that escapes the repository throws from canonical()\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n isRepairFile(root: string, filename: string): boolean {\n const toError = this.error;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- bootstrap cannot trust package imports or malformed declarations\n try {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n const target = this.canonical(root, path.resolve(root, filename));\n const rootFile = this.canonical(root, path.join(root, 'webpieces.config.json'));\n if (target === rootFile || target === this.canonical(root, path.join(root, '.gitignore'))) return true;\n const policy = path.relative(this.canonical(root, path.join(root, '.webpieces-config')), target);\n if (policy !== '' && !policy.startsWith('..') && !path.isAbsolute(policy)) return true;\n // webpieces-disable no-any-unknown -- only validated declaration strings grant repair access\n const raw: unknown = JSON.parse(fs.readFileSync(rootFile, 'utf8'));\n if (!raw || typeof raw !== 'object' || !('rulePacks' in raw) || !Array.isArray(raw.rulePacks))\n return false;\n for (const declaration of raw.rulePacks) {\n if (\n declaration &&\n typeof declaration === 'object' &&\n typeof declaration.config === 'string' &&\n declaration.config.endsWith('.json') &&\n !path.isAbsolute(declaration.config) &&\n this.canonical(root, path.join(root, declaration.config)) === target\n )\n return true;\n }\n return false;\n // webpieces-disable catch-must-propagate -- an escaping path or malformed declaration IS the refusal verdict; the error carries nothing a caller could act on\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n private canonical(root: string, filename: string): string {\n const fs = require('node:fs') as typeof import('node:fs'),\n path = require('node:path') as typeof import('node:path');\n const pending: string[] = [];\n let ancestor = filename;\n while (!fs.lstatSync(ancestor, { throwIfNoEntry: false })) {\n pending.unshift(path.basename(ancestor));\n const parent = path.dirname(ancestor);\n if (parent === ancestor) throw new Error('Cannot resolve config repair path.');\n ancestor = parent;\n }\n const canonical = path.resolve(fs.realpathSync(ancestor), ...pending),\n relative = path.relative(fs.realpathSync(root), canonical);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error('Config repair path escapes the repository.');\n return canonical;\n }\n\n // webpieces-disable no-any-unknown -- the bootstrap adapter must remain self-contained when node_modules is corrupt\n private error(err: unknown): Error {\n return err instanceof Error ? err : new Error(String(err));\n }\n}\n\n/**\n * Emits the same compiled probe class; the shell has no separate declaration/path algorithm.\n *\n * `callScript()` is the shim's ONE edit-escape call. Its exit code is the protocol with the sh half:\n * 0 → permitted; stdout is `config` or `manifest` (the audit label).\n * 1 → not an edit tool (or unreadable stdin); the shim keeps going down its allowlist.\n * 3 → an edit that is NOT permitted; stdout is one line per offending path, for the deny.\n */\nexport class ConfigRepairBootstrap {\n script(): string {\n return `${CONFIG_REPAIR_BOOTSTRAP_SOURCE} if (!new ConfigRepairProbe().isRepairFile(process.argv[1], process.argv[2])) process.exitCode = 1;`;\n }\n\n callScript(): string {\n return `${CONFIG_REPAIR_BOOTSTRAP_SOURCE} const payload = JSON.parse(require('node:fs').readFileSync(0, 'utf8')); const input = payload.tool_input || {}; const verdict = new ConfigRepairProbe().recoveryVerdict(typeof payload.cwd === 'string' && payload.cwd !== '' ? payload.cwd : process.argv[1], String(payload.tool_name || ''), typeof input.file_path === 'string' ? input.file_path : '', typeof input.command === 'string' ? input.command : ''); if (verdict[0] === 'not-an-edit') process.exitCode = 1; else if (verdict[0] === 'refused') { process.stdout.write(verdict.slice(1).join('\\\\n')); process.exitCode = 3; } else process.stdout.write(verdict[0]);`;\n }\n}\n"]}
|
|
@@ -4,6 +4,22 @@ export declare const WORKSPACE_MANIFEST = "pnpm-workspace.yaml";
|
|
|
4
4
|
export declare const PACKAGE_MANIFEST = "package.json";
|
|
5
5
|
export declare const MANIFEST_FILENAMES: ReadonlySet<string>;
|
|
6
6
|
export declare const CODEX_READ_STILL_ALLOWED: string;
|
|
7
|
+
/**
|
|
8
|
+
* THE EDIT ESCAPE, named for BOTH harnesses' edit tools (issue #1448). Every L0 deny used to promise
|
|
9
|
+
* "any Write/Edit", which a Codex agent cannot type: its only edit tool is `apply_patch`. Each phrase is
|
|
10
|
+
* exactly what `ConfigRepairProbe.recoveryVerdict()` admits on that fault's path, so the message cannot
|
|
11
|
+
* promise an edit the installed entrypoint then refuses. No double quotes and no backslashes: the shim
|
|
12
|
+
* splices these into a JSON string.
|
|
13
|
+
*/
|
|
14
|
+
export declare const EDIT_TOOLS_PHRASE = "a Write/Edit/MultiEdit or Codex apply_patch of ONLY";
|
|
15
|
+
/**
|
|
16
|
+
* Faults D/X/U/K/S: the config repair files AND the two root manifests a version pin and a
|
|
17
|
+
* patchedDependencies registration live in. One other file in the same patch, or any Delete, refuses
|
|
18
|
+
* the whole patch.
|
|
19
|
+
*/
|
|
20
|
+
export declare const RECOVERY_EDIT_STILL_ALLOWED = "a Write/Edit/MultiEdit or Codex apply_patch of ONLY webpieces.config.json, .webpieces-config/ files, or a tree-root package.json / pnpm-workspace.yaml";
|
|
21
|
+
/** Fault C: there is no config yet, so no tree root exists either - only creating the config is a repair. */
|
|
22
|
+
export declare const CONFIG_EDIT_STILL_ALLOWED = "a Write/Edit/MultiEdit or Codex apply_patch of ONLY webpieces.config.json";
|
|
7
23
|
export declare const CONFIG_MISSING_REPORT: string;
|
|
8
24
|
export declare const CONFIG_OUT_OF_SYNC_HEADER: string;
|
|
9
25
|
export declare const GUARD_MATRIX_DOC = "webpieces.guard-matrix.md";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GUARD_MATRIX_DOC = exports.CONFIG_OUT_OF_SYNC_HEADER = exports.CONFIG_MISSING_REPORT = exports.CODEX_READ_STILL_ALLOWED = exports.MANIFEST_FILENAMES = exports.PACKAGE_MANIFEST = exports.WORKSPACE_MANIFEST = exports.CODEX_READ_CMD = exports.READ_COMMANDS = void 0;
|
|
3
|
+
exports.GUARD_MATRIX_DOC = exports.CONFIG_OUT_OF_SYNC_HEADER = exports.CONFIG_MISSING_REPORT = exports.CONFIG_EDIT_STILL_ALLOWED = exports.RECOVERY_EDIT_STILL_ALLOWED = exports.EDIT_TOOLS_PHRASE = exports.CODEX_READ_STILL_ALLOWED = exports.MANIFEST_FILENAMES = exports.PACKAGE_MANIFEST = exports.WORKSPACE_MANIFEST = exports.CODEX_READ_CMD = exports.READ_COMMANDS = void 0;
|
|
4
4
|
exports.writeGuardMatrixDoc = writeGuardMatrixDoc;
|
|
5
5
|
exports.guardMatrixPointer = guardMatrixPointer;
|
|
6
6
|
const config_file_1 = require("./config-file");
|
|
@@ -12,6 +12,22 @@ exports.PACKAGE_MANIFEST = 'package.json';
|
|
|
12
12
|
exports.MANIFEST_FILENAMES = new Set([exports.WORKSPACE_MANIFEST, exports.PACKAGE_MANIFEST]);
|
|
13
13
|
exports.CODEX_READ_STILL_ALLOWED = `on CODEX (no Read tool): a bare read command - ${[...exports.READ_COMMANDS].join('/')} <file>, `
|
|
14
14
|
+ `or ${exports.CODEX_READ_CMD} - with nothing piped, redirected or chained onto it`;
|
|
15
|
+
/**
|
|
16
|
+
* THE EDIT ESCAPE, named for BOTH harnesses' edit tools (issue #1448). Every L0 deny used to promise
|
|
17
|
+
* "any Write/Edit", which a Codex agent cannot type: its only edit tool is `apply_patch`. Each phrase is
|
|
18
|
+
* exactly what `ConfigRepairProbe.recoveryVerdict()` admits on that fault's path, so the message cannot
|
|
19
|
+
* promise an edit the installed entrypoint then refuses. No double quotes and no backslashes: the shim
|
|
20
|
+
* splices these into a JSON string.
|
|
21
|
+
*/
|
|
22
|
+
exports.EDIT_TOOLS_PHRASE = 'a Write/Edit/MultiEdit or Codex apply_patch of ONLY';
|
|
23
|
+
/**
|
|
24
|
+
* Faults D/X/U/K/S: the config repair files AND the two root manifests a version pin and a
|
|
25
|
+
* patchedDependencies registration live in. One other file in the same patch, or any Delete, refuses
|
|
26
|
+
* the whole patch.
|
|
27
|
+
*/
|
|
28
|
+
exports.RECOVERY_EDIT_STILL_ALLOWED = `${exports.EDIT_TOOLS_PHRASE} ${config_file_1.CONFIG_FILENAME}, .webpieces-config/ files, or a tree-root ${exports.PACKAGE_MANIFEST} / ${exports.WORKSPACE_MANIFEST}`;
|
|
29
|
+
/** Fault C: there is no config yet, so no tree root exists either - only creating the config is a repair. */
|
|
30
|
+
exports.CONFIG_EDIT_STILL_ALLOWED = `${exports.EDIT_TOOLS_PHRASE} ${config_file_1.CONFIG_FILENAME}`;
|
|
15
31
|
exports.CONFIG_MISSING_REPORT = [
|
|
16
32
|
`❌ webpieces ai-hooks blocked this call: ${config_file_1.CONFIG_FILENAME} not found.`,
|
|
17
33
|
'',
|
|
@@ -22,7 +38,7 @@ exports.CONFIG_MISSING_REPORT = [
|
|
|
22
38
|
'',
|
|
23
39
|
'Still allowed while this block is up:',
|
|
24
40
|
` - any Read, and ${exports.CODEX_READ_STILL_ALLOWED}`,
|
|
25
|
-
` -
|
|
41
|
+
` - ${exports.CONFIG_EDIT_STILL_ALLOWED}`,
|
|
26
42
|
' - every command on the L0 allowlist, including the Fix Options below',
|
|
27
43
|
' THIS IS NOT A DEADLOCK - run one YOURSELF now; do not hand it back to the human.',
|
|
28
44
|
'',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-config-diagnostics.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/hook-config-diagnostics.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"hook-config-diagnostics.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/hook-config-diagnostics.ts"],"names":[],"mappings":";;;AA4EA,kDASC;AAWD,gDAGC;AAnGD,+CAAgD;AACnC,QAAA,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7F,QAAA,cAAc,GAAG,8BAA8B,CAAC;AAC7D,yDAA2H;AAE9G,QAAA,kBAAkB,GAAG,qBAAqB,CAAC;AAC3C,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,0BAAkB,EAAE,wBAAgB,CAAC,CAAC,CAAC;AAE1F,QAAA,wBAAwB,GACjC,kDAAkD,CAAC,GAAG,qBAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW;MACvF,MAAM,sBAAc,sDAAsD,CAAC;AAEjF;;;;;;GAMG;AACU,QAAA,iBAAiB,GAAG,qDAAqD,CAAC;AAEvF;;;;GAIG;AACU,QAAA,2BAA2B,GACpC,GAAG,yBAAiB,IAAI,6BAAe,8CAA8C,wBAAgB,MAAM,0BAAkB,EAAE,CAAC;AAEpI,6GAA6G;AAChG,QAAA,yBAAyB,GAAG,GAAG,yBAAiB,IAAI,6BAAe,EAAE,CAAC;AAEtE,QAAA,qBAAqB,GAAG;IACjC,2CAA2C,6BAAe,aAAa;IACvE,EAAE;IACF,IAAA,gCAAa,EAAC,0CAAuB,EAAE,aAAa,CAAC;IACrD,KAAK,6BAAe,EAAE;IACtB,wFAAwF;IACxF,SAAS,IAAA,m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CONFIG_FILENAME } from './config-file';\nexport const READ_COMMANDS: ReadonlySet<string> = new Set(['cat', 'head', 'tail', 'less', 'more', 'bat']);\nexport const CODEX_READ_CMD = \"sed -n '1,240p' package.json\";\nimport { L0_FAULT_CONFIG_MISSING, L0_FAULT_CONFIG_OUT_OF_SYNC, l0GuardHeader, l0MatrixCitation } from './hook-fault-codes';\n\nexport const WORKSPACE_MANIFEST = 'pnpm-workspace.yaml';\nexport const PACKAGE_MANIFEST = 'package.json';\nexport const MANIFEST_FILENAMES: ReadonlySet<string> = new Set([WORKSPACE_MANIFEST, PACKAGE_MANIFEST]);\n\nexport const CODEX_READ_STILL_ALLOWED =\n `on CODEX (no Read tool): a bare read command - ${[...READ_COMMANDS].join('/')} <file>, `\n + `or ${CODEX_READ_CMD} - with nothing piped, redirected or chained onto it`;\n\n/**\n * THE EDIT ESCAPE, named for BOTH harnesses' edit tools (issue #1448). Every L0 deny used to promise\n * \"any Write/Edit\", which a Codex agent cannot type: its only edit tool is `apply_patch`. Each phrase is\n * exactly what `ConfigRepairProbe.recoveryVerdict()` admits on that fault's path, so the message cannot\n * promise an edit the installed entrypoint then refuses. No double quotes and no backslashes: the shim\n * splices these into a JSON string.\n */\nexport const EDIT_TOOLS_PHRASE = 'a Write/Edit/MultiEdit or Codex apply_patch of ONLY';\n\n/**\n * Faults D/X/U/K/S: the config repair files AND the two root manifests a version pin and a\n * patchedDependencies registration live in. One other file in the same patch, or any Delete, refuses\n * the whole patch.\n */\nexport const RECOVERY_EDIT_STILL_ALLOWED =\n `${EDIT_TOOLS_PHRASE} ${CONFIG_FILENAME}, .webpieces-config/ files, or a tree-root ${PACKAGE_MANIFEST} / ${WORKSPACE_MANIFEST}`;\n\n/** Fault C: there is no config yet, so no tree root exists either - only creating the config is a repair. */\nexport const CONFIG_EDIT_STILL_ALLOWED = `${EDIT_TOOLS_PHRASE} ${CONFIG_FILENAME}`;\n\nexport const CONFIG_MISSING_REPORT = [\n `❌ webpieces ai-hooks blocked this call: ${CONFIG_FILENAME} not found.`,\n '',\n l0GuardHeader(L0_FAULT_CONFIG_MISSING, '1 violation'),\n ` ${CONFIG_FILENAME}`,\n ' → the webpieces guards cannot run without it, so every OTHER tool call is blocked.',\n ` → ${l0MatrixCitation(L0_FAULT_CONFIG_MISSING)}`,\n '',\n 'Still allowed while this block is up:',\n ` - any Read, and ${CODEX_READ_STILL_ALLOWED}`,\n ` - ${CONFIG_EDIT_STILL_ALLOWED}`,\n ' - every command on the L0 allowlist, including the Fix Options below',\n ' THIS IS NOT A DEADLOCK - run one YOURSELF now; do not hand it back to the human.',\n '',\n ` Fix Option 1: (preferred) it needs no other tool and it never prompts - create ${CONFIG_FILENAME}`,\n ' yourself. The validator reports EVERY missing/invalid entry at once (each with the snippet to',\n ' paste), so a minimal first draft converges in about two passes.',\n ' Fix Option 2: pick this ONLY at an interactive terminal where you can answer its two prompts - it',\n ' goes on to wire the Claude Code hooks and asks for a target twice, which hangs a non-interactive',\n ' session.',\n ' run EXACTLY: `pnpm exec wp-install-ai-hooks`',\n '',\n 'Do not append anything to the option you pick — the allowlist is anchored to the whole command.',\n].join('\\n');\n\n// The HEADER of the fault-Y deny (built out in runner.checkConfigSync, which appends the per-rule\n// detail as the `[…]` block's offenders). Kept here so the fault table quotes the same text the runner\n// emits, and so Y opens with the same `[guard-name] (layer=L0 fault=Y row=3)` coordinates as every\n// other L0 fault — that triple is what joins the deny to the audit line and to the matrix row.\nexport const CONFIG_OUT_OF_SYNC_HEADER = [\n `❌ webpieces ai-hooks blocked this call: ${CONFIG_FILENAME} is out of sync.`,\n '',\n l0GuardHeader(L0_FAULT_CONFIG_OUT_OF_SYNC, '1 violation'),\n ` new built-in rules are present that have no entry in ${CONFIG_FILENAME}`,\n ` → ${l0MatrixCitation(L0_FAULT_CONFIG_OUT_OF_SYNC)}`,\n].join('\\n');\n\n\nimport { writeTemplate } from './load-template';\nimport { toError } from '@webpieces/tooling-common/to-error';\nexport const GUARD_MATRIX_DOC = 'webpieces.guard-matrix.md';\n\n// webpieces-disable no-function-outside-class -- shared best-effort configuration diagnostic template writer\nexport function writeGuardMatrixDoc(workspaceRoot: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return writeTemplate(workspaceRoot, GUARD_MATRIX_DOC);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: no doc → the deny simply omits the pointer\n return '';\n }\n}\n\n/**\n * The `READ <path>` pointer appended to an L0 deny, or '' when the doc could not be written.\n *\n * It opens with a NEWLINE, not a space: the JS-side L0 denies render in the house format now (a header,\n * a `[guard-name]` block, `Fix Option N:` lines), so a pointer glued onto the end of the last line would\n * be the one place the shape broke. A real newline is safe on both call paths — denyJson() JSON.stringifies\n * it, exactly as it does for every multi-line L1 report.\n */\n// webpieces-disable no-function-outside-class -- sibling of writeGuardMatrixDoc in this module\nexport function guardMatrixPointer(docPath: string): string {\n if (docPath === '') return '';\n return `\\nThe full L0 guard matrix - every fault and everything that is allowed through - is at ${docPath}; READ it if you are unsure why this call was blocked.`;\n}\n"]}
|
|
@@ -95,8 +95,8 @@ that denied `rm -rf node_modules && pnpm install` while allowing a bare `pnpm in
|
|
|
95
95
|
|---|---|---|
|
|
96
96
|
| 1 | any Read | PASS |
|
|
97
97
|
| 2 | a Codex tool with nothing to judge: webrun, collaborationspawn_agent, collaborationwait_agent, view_image, update_plan | PASS |
|
|
98
|
-
| 3 | a Write/Edit
|
|
99
|
-
| 4 | a Write/Edit
|
|
98
|
+
| 3 | a Write/Edit/MultiEdit or Codex apply_patch of ONLY webpieces.config.json or a .webpieces-config/ file | PASS |
|
|
99
|
+
| 4 | a Write/Edit/MultiEdit or Codex apply_patch of ONLY a tree ROOT's pnpm-workspace.yaml or package.json - the version pin and patchedDependencies | PASS |
|
|
100
100
|
| 5 | pnpm|npm install | ALLOW |
|
|
101
101
|
| 6 | rm -rf node_modules && pnpm install - the cure for a CORRUPT node_modules | ALLOW |
|
|
102
102
|
| 7 | git fetch - a bare git pull and git merge are NOT on the list | ALLOW |
|