@webpieces/rules-config 0.4.847 → 0.4.848
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 +10 -7
- package/src/WebpiecesRulesConfig.d.ts +1 -2
- package/src/WebpiecesRulesConfig.js +0 -1
- package/src/WebpiecesRulesConfig.js.map +1 -1
- package/src/client-module-resolution.d.ts +9 -0
- package/src/client-module-resolution.js +102 -0
- package/src/client-module-resolution.js.map +1 -0
- package/src/config-error-banner.d.ts +0 -2
- package/src/config-error-banner.js +1 -3
- package/src/config-error-banner.js.map +1 -1
- package/src/config-file.d.ts +3 -6
- package/src/config-file.js +14 -1
- package/src/config-file.js.map +1 -1
- package/src/config-key-rules.js +16 -5
- package/src/config-key-rules.js.map +1 -1
- package/src/config-pruner.d.ts +5 -42
- package/src/config-pruner.js +31 -76
- package/src/config-pruner.js.map +1 -1
- package/src/config-repair-access.d.ts +4 -0
- package/src/config-repair-access.js +17 -0
- package/src/config-repair-access.js.map +1 -0
- package/src/config-repair-bootstrap-source.d.ts +2 -0
- package/src/config-repair-bootstrap-source.js +7 -0
- package/src/config-repair-bootstrap-source.js.map +1 -0
- package/src/config-repair-probe.d.ts +13 -0
- package/src/config-repair-probe.js +115 -0
- package/src/config-repair-probe.js.map +1 -0
- package/src/first-path-match.d.ts +14 -0
- package/src/first-path-match.js +35 -0
- package/src/first-path-match.js.map +1 -0
- package/src/index.d.ts +15 -8
- package/src/index.js +40 -10
- package/src/index.js.map +1 -1
- package/src/legacy-config-upgrade.d.ts +22 -0
- package/src/legacy-config-upgrade.js +328 -0
- package/src/legacy-config-upgrade.js.map +1 -0
- package/src/load-config.d.ts +11 -23
- package/src/load-config.js +50 -138
- package/src/load-config.js.map +1 -1
- package/src/pack-policy-files.d.ts +29 -0
- package/src/pack-policy-files.js +194 -0
- package/src/pack-policy-files.js.map +1 -0
- package/src/policy-field-constraints.d.ts +9 -0
- package/src/policy-field-constraints.js +31 -0
- package/src/policy-field-constraints.js.map +1 -0
- package/src/repository-path.d.ts +7 -0
- package/src/repository-path.js +50 -0
- package/src/repository-path.js.map +1 -0
- package/src/rule-pack-artifacts.d.ts +23 -0
- package/src/rule-pack-artifacts.js +180 -0
- package/src/rule-pack-artifacts.js.map +1 -0
- package/src/rule-pack-registry.d.ts +7 -0
- package/src/rule-pack-registry.js +149 -47
- package/src/rule-pack-registry.js.map +1 -1
- package/src/rule-pack-sync.d.ts +26 -0
- package/src/rule-pack-sync.js +236 -0
- package/src/rule-pack-sync.js.map +1 -0
- package/src/rule-runtime-modules.d.ts +27 -0
- package/src/rule-runtime-modules.js +135 -0
- package/src/rule-runtime-modules.js.map +1 -0
- package/src/rules-sync-cli.d.ts +7 -0
- package/src/rules-sync-cli.js +48 -0
- package/src/rules-sync-cli.js.map +1 -0
- package/src/seed-entry.js +1 -3
- package/src/seed-entry.js.map +1 -1
- package/src/types.d.ts +4 -6
- package/src/types.js +4 -7
- package/src/types.js.map +1 -1
- package/src/validate-config.d.ts +3 -29
- package/src/validate-config.js +99 -244
- package/src/validate-config.js.map +1 -1
- package/src/validate-pr-gate.d.ts +8 -0
- package/src/validate-pr-gate.js +161 -0
- package/src/validate-pr-gate.js.map +1 -0
- package/templates/webpieces.guard-matrix.md +5 -4
- package/src/rule-pack-selection.d.ts +0 -6
- package/src/rule-pack-selection.js +0 -50
- package/src/rule-pack-selection.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/rules-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.848",
|
|
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.848",
|
|
23
|
+
"@webpieces/repo-workflow-core": "0.4.848",
|
|
24
|
+
"@webpieces/rules-sdk": "0.4.848"
|
|
25
25
|
},
|
|
26
26
|
"author": "Dean Hiller",
|
|
27
27
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,10 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
37
|
+
"@webpieces/tooling-testkit": "0.4.848"
|
|
38
38
|
},
|
|
39
|
-
"types": "./src/index.d.ts"
|
|
40
|
-
|
|
39
|
+
"types": "./src/index.d.ts",
|
|
40
|
+
"bin": {
|
|
41
|
+
"wp-rules-sync": "./src/rules-sync-cli.js"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseRuleConfig } from '@webpieces/rules-sdk';
|
|
2
2
|
/** The framework carries validated values; concrete packs supply and interpret their own types. */
|
|
3
3
|
export declare class WebpiecesRulesConfig {
|
|
4
|
-
[configKey: string]: BaseRuleConfig |
|
|
5
|
-
rulesDir?: string[];
|
|
4
|
+
[configKey: string]: BaseRuleConfig | undefined;
|
|
6
5
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebpiecesRulesConfig = void 0;
|
|
4
4
|
/** The framework carries validated values; concrete packs supply and interpret their own types. */
|
|
5
5
|
class WebpiecesRulesConfig {
|
|
6
|
-
rulesDir;
|
|
7
6
|
}
|
|
8
7
|
exports.WebpiecesRulesConfig = WebpiecesRulesConfig;
|
|
9
8
|
//# sourceMappingURL=WebpiecesRulesConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebpiecesRulesConfig.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/WebpiecesRulesConfig.ts"],"names":[],"mappings":";;;AAEA,mGAAmG;AACnG,MAAa,oBAAoB;
|
|
1
|
+
{"version":3,"file":"WebpiecesRulesConfig.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/WebpiecesRulesConfig.ts"],"names":[],"mappings":";;;AAEA,mGAAmG;AACnG,MAAa,oBAAoB;CAEhC;AAFD,oDAEC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\n\n/** The framework carries validated values; concrete packs supply and interpret their own types. */\nexport class WebpiecesRulesConfig {\n [configKey: string]: BaseRuleConfig | undefined;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Resolve a selected module through the client's declared installation graph, including pnpm bundles. */
|
|
2
|
+
export declare class ClientModuleResolution {
|
|
3
|
+
private readonly clientRoot;
|
|
4
|
+
constructor(clientRoot: string);
|
|
5
|
+
resolve(moduleName: string): string;
|
|
6
|
+
private fromDeclaredDependencies;
|
|
7
|
+
private dependencyManifest;
|
|
8
|
+
private tryResolve;
|
|
9
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientModuleResolution = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_module_1 = require("node:module");
|
|
6
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
7
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
8
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
10
|
+
class DependencyPackageIdentity {
|
|
11
|
+
name;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve a selected module through the client's declared installation graph, including pnpm bundles. */
|
|
14
|
+
class ClientModuleResolution {
|
|
15
|
+
clientRoot;
|
|
16
|
+
constructor(clientRoot) {
|
|
17
|
+
this.clientRoot = clientRoot;
|
|
18
|
+
}
|
|
19
|
+
resolve(moduleName) {
|
|
20
|
+
const direct = this.tryResolve((0, node_module_1.createRequire)(path.join(this.clientRoot, 'package.json')), moduleName);
|
|
21
|
+
if (direct !== null)
|
|
22
|
+
return direct;
|
|
23
|
+
if (moduleName.startsWith('.') || path.isAbsolute(moduleName)) {
|
|
24
|
+
throw new tooling_common_1.InformAiError(`Cannot resolve declared local rule-pack module ${moduleName} from ${this.clientRoot}; repair the module declarations to point to its existing public module.`);
|
|
25
|
+
}
|
|
26
|
+
const candidates = this.fromDeclaredDependencies(moduleName);
|
|
27
|
+
if (candidates.length !== 1) {
|
|
28
|
+
const cause = candidates.length === 0
|
|
29
|
+
? 'is not installed through a declared client dependency'
|
|
30
|
+
: 'resolves to multiple installed versions';
|
|
31
|
+
throw new tooling_common_1.InformAiError(`Declared rule-pack module ${moduleName} ${cause}. Pin and install one version of its package or tooling bundle in package.json, then run pnpm install.`);
|
|
32
|
+
}
|
|
33
|
+
return candidates[0];
|
|
34
|
+
}
|
|
35
|
+
fromDeclaredDependencies(moduleName) {
|
|
36
|
+
const pending = [path.join(this.clientRoot, 'package.json')], visited = new Set(), candidates = new Set();
|
|
37
|
+
while (pending.length > 0) {
|
|
38
|
+
const manifestPath = pending.shift();
|
|
39
|
+
if (visited.has(manifestPath))
|
|
40
|
+
continue;
|
|
41
|
+
visited.add(manifestPath);
|
|
42
|
+
const requireHere = (0, node_module_1.createRequire)(manifestPath);
|
|
43
|
+
if (path.dirname(manifestPath) !== this.clientRoot) {
|
|
44
|
+
const found = this.tryResolve(requireHere, moduleName);
|
|
45
|
+
if (found !== null)
|
|
46
|
+
candidates.add(fs.realpathSync(found));
|
|
47
|
+
}
|
|
48
|
+
// webpieces-disable no-any-unknown -- only declared dependency key names are consumed from package JSON.
|
|
49
|
+
const pkg = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
50
|
+
for (const section of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
51
|
+
const dependencies = pkg[section];
|
|
52
|
+
if (!dependencies ||
|
|
53
|
+
typeof dependencies !== 'object' ||
|
|
54
|
+
Array.isArray(dependencies))
|
|
55
|
+
continue;
|
|
56
|
+
for (const name of Object.keys(dependencies)) {
|
|
57
|
+
const dependencyManifest = this.dependencyManifest(requireHere, name);
|
|
58
|
+
if (dependencyManifest !== null)
|
|
59
|
+
pending.push(dependencyManifest);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return [...candidates];
|
|
64
|
+
}
|
|
65
|
+
dependencyManifest(requireHere, name) {
|
|
66
|
+
const manifest = this.tryResolve(requireHere, `${name}/package.json`);
|
|
67
|
+
if (manifest !== null)
|
|
68
|
+
return fs.realpathSync(manifest);
|
|
69
|
+
const entry = this.tryResolve(requireHere, name);
|
|
70
|
+
if (entry === null)
|
|
71
|
+
return null;
|
|
72
|
+
let directory = path.dirname(entry);
|
|
73
|
+
while (true) {
|
|
74
|
+
const candidate = path.join(directory, 'package.json');
|
|
75
|
+
if (fs.existsSync(candidate)) {
|
|
76
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, 'utf8'));
|
|
77
|
+
if (pkg.name === name)
|
|
78
|
+
return fs.realpathSync(candidate);
|
|
79
|
+
}
|
|
80
|
+
const parent = path.dirname(directory);
|
|
81
|
+
if (parent === directory)
|
|
82
|
+
return null;
|
|
83
|
+
directory = parent;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
tryResolve(requireHere, name) {
|
|
87
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- resolution probes enumerate declared dependency roots, never infer selected packs.
|
|
88
|
+
try {
|
|
89
|
+
return requireHere.resolve(name);
|
|
90
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
const error = (0, to_error_1.toError)(err);
|
|
94
|
+
if ('code' in error &&
|
|
95
|
+
['MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'].includes(String(error.code)))
|
|
96
|
+
return null;
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ClientModuleResolution = ClientModuleResolution;
|
|
102
|
+
//# sourceMappingURL=client-module-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-module-resolution.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/client-module-resolution.ts"],"names":[],"mappings":";;;;AAAA,6CAA4C;AAC5C,oDAA8B;AAC9B,wDAAkC;AAClC,8DAA0D;AAC1D,iEAA6D;AAE7D,MAAM,yBAAyB;IAC3B,IAAI,CAAU;CACjB;AAED,0GAA0G;AAC1G,MAAa,sBAAsB;IACF;IAA7B,YAA6B,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAEnD,OAAO,CAAC,UAAkB;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAC1B,IAAA,2BAAa,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,EACzD,UAAU,CACb,CAAC;QACF,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACnC,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,8BAAa,CACnB,kDAAkD,UAAU,SAAS,IAAI,CAAC,UAAU,0EAA0E,CACjK,CAAC;QACN,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;QAC7D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,MA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,KAAK,IAAI;oBAAE,OAAO,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAC7D,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACvC,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YACtC,SAAS,GAAG,MAAM,CAAC;QACvB,CAAC;IACL,CAAC;IAEO,UAAU,CAAC,WAAwB,EAAE,IAAY;QACrD,oJAAoJ;QACpJ,IAAI,CAAC;YACD,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,6GAA6G;QAC7G,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,IACI,MAAM,IAAI,KAAK;gBACf,CAAC,kBAAkB,EAAE,+BAA+B,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAElF,OAAO,IAAI,CAAC;YAChB,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAlGD,wDAkGC","sourcesContent":["import { createRequire } from 'node:module';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\nclass DependencyPackageIdentity {\n name?: string;\n}\n\n/** Resolve a selected module through the client's declared installation graph, including pnpm bundles. */\nexport class ClientModuleResolution {\n constructor(private readonly clientRoot: string) {}\n\n resolve(moduleName: string): string {\n const direct = this.tryResolve(\n createRequire(path.join(this.clientRoot, 'package.json')),\n moduleName,\n );\n if (direct !== null) return direct;\n if (moduleName.startsWith('.') || path.isAbsolute(moduleName)) {\n throw new InformAiError(\n `Cannot resolve declared local rule-pack module ${moduleName} from ${this.clientRoot}; repair the module declarations to point to its existing public module.`,\n );\n }\n const candidates = this.fromDeclaredDependencies(moduleName);\n if (candidates.length !== 1) {\n const cause =\n candidates.length === 0\n ? 'is not installed through a declared client dependency'\n : 'resolves to multiple installed versions';\n throw new InformAiError(\n `Declared rule-pack module ${moduleName} ${cause}. Pin and install one version of its package or tooling bundle in package.json, then run pnpm install.`,\n );\n }\n return candidates[0];\n }\n\n private fromDeclaredDependencies(moduleName: string): string[] {\n const pending = [path.join(this.clientRoot, 'package.json')],\n visited = new Set<string>(),\n candidates = new Set<string>();\n while (pending.length > 0) {\n const manifestPath = pending.shift()!;\n if (visited.has(manifestPath)) continue;\n visited.add(manifestPath);\n const requireHere = createRequire(manifestPath);\n if (path.dirname(manifestPath) !== this.clientRoot) {\n const found = this.tryResolve(requireHere, moduleName);\n if (found !== null) candidates.add(fs.realpathSync(found));\n }\n // webpieces-disable no-any-unknown -- only declared dependency key names are consumed from package JSON.\n const pkg = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<\n string,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n unknown\n >;\n for (const section of ['dependencies', 'devDependencies', 'optionalDependencies']) {\n const dependencies = pkg[section];\n if (\n !dependencies ||\n typeof dependencies !== 'object' ||\n Array.isArray(dependencies)\n )\n continue;\n for (const name of Object.keys(dependencies)) {\n const dependencyManifest = this.dependencyManifest(requireHere, name);\n if (dependencyManifest !== null) pending.push(dependencyManifest);\n }\n }\n }\n return [...candidates];\n }\n\n private dependencyManifest(requireHere: NodeRequire, name: string): string | null {\n const manifest = this.tryResolve(requireHere, `${name}/package.json`);\n if (manifest !== null) return fs.realpathSync(manifest);\n const entry = this.tryResolve(requireHere, name);\n if (entry === null) return null;\n let directory = path.dirname(entry);\n while (true) {\n const candidate = path.join(directory, 'package.json');\n if (fs.existsSync(candidate)) {\n const pkg = JSON.parse(\n fs.readFileSync(candidate, 'utf8'),\n ) as DependencyPackageIdentity;\n if (pkg.name === name) return fs.realpathSync(candidate);\n }\n const parent = path.dirname(directory);\n if (parent === directory) return null;\n directory = parent;\n }\n }\n\n private tryResolve(requireHere: NodeRequire, name: string): string | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- resolution probes enumerate declared dependency roots, never infer selected packs.\n try {\n return requireHere.resolve(name);\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 if (\n 'code' in error &&\n ['MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'].includes(String(error.code))\n )\n return null;\n throw error;\n }\n }\n}\n"]}
|
|
@@ -67,8 +67,6 @@ export declare const CONFIG_POLICY_DOC = "webpieces.config-policy.md";
|
|
|
67
67
|
export declare const RETIRED_KEY_MARKER = "is a RETIRED webpieces.config.json key";
|
|
68
68
|
/** `validateCommandsSection` — the retired TOP-LEVEL pr-gate block (a shape, so it has its own text). */
|
|
69
69
|
export declare const RETIRED_TOP_LEVEL_MARKER = "block is RETIRED";
|
|
70
|
-
/** `validateSectionPlacement` — a built-in configured under the wrong section. */
|
|
71
|
-
export declare const SECTION_PLACEMENT_MARKER = "belongs in the";
|
|
72
70
|
/**
|
|
73
71
|
* Assemble the banner: the errors, then the ONE cure, then the warnings. Nothing else belongs here —
|
|
74
72
|
* see the module comment.
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
* phrase other code searches for cannot drift apart.
|
|
57
57
|
*/
|
|
58
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
exports.
|
|
59
|
+
exports.RETIRED_TOP_LEVEL_MARKER = exports.RETIRED_KEY_MARKER = exports.CONFIG_POLICY_DOC = void 0;
|
|
60
60
|
exports.formatConfigErrorsBanner = formatConfigErrorsBanner;
|
|
61
61
|
const constants_1 = require("./constants");
|
|
62
62
|
/**
|
|
@@ -72,8 +72,6 @@ exports.CONFIG_POLICY_DOC = 'webpieces.config-policy.md';
|
|
|
72
72
|
exports.RETIRED_KEY_MARKER = 'is a RETIRED webpieces.config.json key';
|
|
73
73
|
/** `validateCommandsSection` — the retired TOP-LEVEL pr-gate block (a shape, so it has its own text). */
|
|
74
74
|
exports.RETIRED_TOP_LEVEL_MARKER = 'block is RETIRED';
|
|
75
|
-
/** `validateSectionPlacement` — a built-in configured under the wrong section. */
|
|
76
|
-
exports.SECTION_PLACEMENT_MARKER = 'belongs in the';
|
|
77
75
|
/**
|
|
78
76
|
* Assemble the banner: the errors, then the ONE cure, then the warnings. Nothing else belongs here —
|
|
79
77
|
* see the module comment.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-error-banner.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-error-banner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;;;
|
|
1
|
+
{"version":3,"file":"config-error-banner.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-error-banner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;;;AA0BH,4DA2BC;AAnDD,2CAAoD;AAEpD;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG,4BAA4B,CAAC;AAE9D,uGAAuG;AAC1F,QAAA,kBAAkB,GAAG,wCAAwC,CAAC;AAE3E,yGAAyG;AAC5F,QAAA,wBAAwB,GAAG,kBAAkB,CAAC;AAE3D;;;GAGG;AACH,uFAAuF;AACvF,2GAA2G;AAC3G,SAAgB,wBAAwB,CAAC,MAAyB;IAC9D,OAAO;IACH,8FAA8F;IAC9F,wFAAwF;IACxF,6BAA6B,MAAM,CAAC,MAAM,6CAA6C;QACvF,MAAM,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACxD,kGAAkG;QAClG,8FAA8F;QAC9F,qDAAqD;QACrD,8FAA8F;QAC9F,2FAA2F;QAC3F,gGAAgG;QAChG,8BAA8B;QAC9B,oGAAoG;QACpG,iGAAiG;QACjG,gDAAgD,iCAAqB,gCAAgC;QACrG,6EAA6E;QAC7E,iGAAiG;QACjG,kGAAkG;QAClG,kGAAkG;QAClG,oGAAoG;QACpG,iBAAiB;QACjB,iFAAiF;QACjF,qGAAqG;QACrG,iEAAiE;QACjE,0CAA0C,yBAAiB,EAAE,CAChE,CAAC;AACN,CAAC","sourcesContent":["/**\n * THE validation-failure banner for webpieces.config.json.\n *\n * ## The invariant: there is exactly ONE cure\n *\n * Every error this banner carries came from VALIDATING webpieces.config.json, so the file is the\n * defect and editing it is the fix. That is the whole instruction. Editing it is unconditionally\n * allowed (L0 allowlist entry 2) even while it is invalid, so the cure is always reachable.\n *\n * The banner this replaces printed a FIXED four-step \"FIX ORDER\" that led with `pnpm install`, and each\n * of those steps was wrong in its own way:\n *\n * - `pnpm install` CANNOT help. The committed shim (templates/ai-hook.sh) runs the guard bin only\n * under `[ -x \"$BIN\" ] && [ -z \"$DRIFT_PKG\" ]`, and DRIFT_PKG is set by comparing every exact-pinned\n * `@webpieces/*` spec in the root package.json against the installed version (a `catalog:` spec is\n * resolved through pnpm-lock.yaml first). So the validator only ever runs when package.json and\n * node_modules ALREADY agree: nothing is out of date to install. It is not a first step, it is a\n * detour — and it is the detour that sent an agent down the wrong path in the incident that\n * produced this rewrite. The one gap: the drift check skips RANGE specs (`^`, `~`, `workspace:*`),\n * so a repo pinning with ranges is outside that guarantee. This repo pins exactly\n * (validate-versions-locked).\n * - \"Retry your command\" was not a fix step at all. Retrying is implied by the first line.\n * - A fourth step prescribed an installer flag as a competing \"edit the config\" command. That flag no\n * longer exists, and the paragraph that offered it is gone with it: the banner names ONE action, and\n * an optional second command is how a reader comes to believe there is a choice to make.\n *\n * ## Why the negative instruction is here\n *\n * The failure mode was not a missing instruction, it was a generic ordered list — which is exactly how\n * an agent picks the wrong step. So the banner states what NOT to do as plainly as what to do: do not\n * run `pnpm install`. That is the only DO-NOT left, and it is the only one there was ever evidence for.\n *\n * ## The delete advice used to be INVERTED, and that inversion cost a consumer a day\n *\n * This banner used to say \"Do NOT delete a key just because it is reported unknown\", steering the reader\n * at the stale-PIN case first. That is backwards. A key the running validator has no schema for controls\n * NOTHING; leaving it in place is dead config that reads as live config to the next reader, and for a\n * RETIRED key deleting it is the entire fix. The sentence told the reader not to do the one thing that\n * works, for a key (`whole-repo-build-guard`) whose own retirement instruction is \"DELETE this entry\".\n *\n * So deletion is now the PRIMARY cure and it is MECHANICAL — `PRUNE_UNKNOWN_COMMAND` strips every unknown\n * key — while the stale pin is a secondary note. The stale pin can afford to be secondary because it is\n * not this banner's job at all: the version-drift guard in the shim compares the pin against the installed\n * version BEFORE exec'ing the validator, and on drift it denies every tool call with its own message and\n * its own cure. Reaching this banner is therefore evidence that no drift was detected.\n *\n * ## Nothing here is conditional\n *\n * The banner is the SAME for one error and for twenty: the bullets change, the instruction does not. It\n * names no installer command at all — a unit test asserts that — because every error it can carry is\n * cured by editing the file the errors came from.\n *\n * The markers below are the phrases the message builders (retired-config-keys.ts,\n * commands-section-validators.ts, validate-config.ts) embed rather than re-type, so a message and the\n * phrase other code searches for cannot drift apart.\n */\n\nimport { PRUNE_UNKNOWN_COMMAND } from './constants';\n\n/**\n * The background doc this banner sends the reader to, named ONCE so the link, the installer that ships\n * the file, and the spec that holds it to the banner's advice cannot drift apart.\n *\n * That drift is not hypothetical: the first cut of the delete-first rewrite fixed the banner and left\n * this document still saying \"Do not start by deleting keys\" and prescribing `pnpm install` first — i.e.\n * the message was cured and the page it cites went on teaching the thing that was removed.\n */\nexport const CONFIG_POLICY_DOC = 'webpieces.config-policy.md';\n\n/** `retiredKeyError` — every RETIRED_CONFIG_KEYS entry is one `migrate()` knows how to move/rename. */\nexport const RETIRED_KEY_MARKER = 'is a RETIRED webpieces.config.json key';\n\n/** `validateCommandsSection` — the retired TOP-LEVEL pr-gate block (a shape, so it has its own text). */\nexport const RETIRED_TOP_LEVEL_MARKER = 'block is RETIRED';\n\n/**\n * Assemble the banner: the errors, then the ONE cure, then the warnings. Nothing else belongs here —\n * see the module comment.\n */\n// webpieces-disable no-function-outside-class -- sibling string builder in this module\n// webpieces-disable max-lines-new-methods -- one contiguous string literal; splitting it hides the message\nexport function formatConfigErrorsBanner(errors: readonly string[]): string {\n return (\n // No \"then retry\". Retrying is not a fix STEP — the old banner spent one of its four numbered\n // steps on it, which is how \"run the command again\" came to look like a candidate cure.\n `webpieces.config.json has ${errors.length} validation error(s) — fix ALL of them:\\n\\n` +\n errors.map((e: string): string => ` • ${e}`).join('\\n') +\n `\\n\\n👉 THE FIX: edit webpieces.config.json and apply every • above. Each bullet names the exact ` +\n `change to make, and editing this file is ALWAYS allowed through the guard — including right ` +\n `now, while it is invalid. There is no other step.\\n` +\n ` • Do NOT run \\`pnpm install\\` — it cannot help. The guards only run when package.json and ` +\n `node_modules already agree, so there is nothing out of date to install. (Only exception: ` +\n `@webpieces deps pinned with a RANGE — ^ / ~ / workspace:* — which drift detection skips. This ` +\n `repo pins exact versions.)\\n` +\n ` • DO delete any key reported as an unknown rule. A key the validator has no schema for controls ` +\n `NOTHING — it is dead config that reads as live config to the next reader — and when the key is ` +\n `RETIRED, deleting it is the WHOLE fix. Run \\`${PRUNE_UNKNOWN_COMMAND}\\` to strip every unknown key ` +\n `mechanically, or delete them by hand; either way the file then validates.\\n` +\n ` • Secondary, and rare: a key can be valid-but-unlearned when package.json pins an @webpieces ` +\n `OLDER than this config was written for. You are not in that case here — the version-drift guard ` +\n `compares the pin against the installed version BEFORE this validator runs and denies every tool ` +\n `call with its own message and its own cure (bump the pin), so reaching this banner means no drift ` +\n `was detected.\\n` +\n ` • A MACHINE-LOCAL setting does not belong in this file at all. Those live in ` +\n `~/.webpieces/config.json under \"experimental\" — an optional file tracked by no repo, whose absence ` +\n `is the default behaviour. Delete the key here and put it there.` +\n `\\n\\nBackground: .webpieces/instruct-ai/${CONFIG_POLICY_DOC}`\n );\n}\n"]}
|
package/src/config-file.d.ts
CHANGED
|
@@ -21,15 +21,12 @@ export declare class ConfigParseAttempt {
|
|
|
21
21
|
readonly error: Error | null;
|
|
22
22
|
constructor(config: RawConfigFile | null, error: Error | null);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
hookGuards?: Record<string, Record<string, unknown>>;
|
|
24
|
+
/** Parsed but unvalidated root declaration. Concrete policy settings live only in declared owner files. */
|
|
25
|
+
export declare class RawConfigFile {
|
|
26
|
+
rulePacks?: unknown;
|
|
28
27
|
commands?: unknown;
|
|
29
28
|
excludePaths?: unknown;
|
|
30
29
|
'match-rules'?: unknown;
|
|
31
|
-
rulesDir?: string[];
|
|
32
|
-
'pr-gate'?: unknown;
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* Locates + reads webpieces.config.json. `@injectable(bindingScopeValues.Singleton)` so it can be injected into the config
|
package/src/config-file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigFile = exports.ConfigParseAttempt = exports.CONFIG_PARSE_RETRY_MILLIS = exports.CONFIG_PARSE_ATTEMPTS = exports.CONFIG_FILENAME = void 0;
|
|
3
|
+
exports.ConfigFile = exports.RawConfigFile = exports.ConfigParseAttempt = exports.CONFIG_PARSE_RETRY_MILLIS = exports.CONFIG_PARSE_ATTEMPTS = exports.CONFIG_FILENAME = void 0;
|
|
4
4
|
exports.findConfigFile = findConfigFile;
|
|
5
5
|
exports.readRawConfig = readRawConfig;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
@@ -36,6 +36,18 @@ class ConfigParseAttempt {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.ConfigParseAttempt = ConfigParseAttempt;
|
|
39
|
+
/** Parsed but unvalidated root declaration. Concrete policy settings live only in declared owner files. */
|
|
40
|
+
class RawConfigFile {
|
|
41
|
+
// webpieces-disable no-any-unknown -- opaque client JSON is validated at the root/owner boundary
|
|
42
|
+
rulePacks;
|
|
43
|
+
// webpieces-disable no-any-unknown -- command behavior has its own structural validator
|
|
44
|
+
commands;
|
|
45
|
+
// webpieces-disable no-any-unknown -- generic exclusions are validated before interpretation
|
|
46
|
+
excludePaths;
|
|
47
|
+
// webpieces-disable no-any-unknown -- client match rules have their own structural validator
|
|
48
|
+
'match-rules';
|
|
49
|
+
}
|
|
50
|
+
exports.RawConfigFile = RawConfigFile;
|
|
39
51
|
/**
|
|
40
52
|
* Locates + reads webpieces.config.json. `@injectable(bindingScopeValues.Singleton)` so it can be injected into the config
|
|
41
53
|
* loader and appear in the rules-config DI design.
|
|
@@ -82,6 +94,7 @@ let ConfigFile = class ConfigFile {
|
|
|
82
94
|
try {
|
|
83
95
|
const raw = this.readFileText(configPath);
|
|
84
96
|
return new ConfigParseAttempt(JSON.parse(raw), null);
|
|
97
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
85
98
|
}
|
|
86
99
|
catch (err) {
|
|
87
100
|
const error = (0, to_error_1.toError)(err);
|
package/src/config-file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-file.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-file.ts"],"names":[],"mappings":";;;AA+JA,wCAEC;AAKD,sCAEC;;AAxKD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,8DAA0D;AAC1D,iEAA6D;AAEhD,QAAA,eAAe,GAAG,uBAAuB,CAAC;AAEvD;;;;;;;;;GASG;AACU,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAEvC,uGAAuG;AAC1F,QAAA,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;GAGG;AACH,MAAa,kBAAkB;IAEd;IACA;IAFb,YACa,MAA4B,EAC5B,KAAmB;QADnB,WAAM,GAAN,MAAM,CAAsB;QAC5B,UAAK,GAAL,KAAK,CAAc;IAC7B,CAAC;CACP;AALD,gDAKC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a,GAAG,IAAI,UAAU,EAAE,CAAC;AAEvC;;GAEG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC3C,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,UAAkB;IAC5C,OAAO,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\nexport const CONFIG_FILENAME = 'webpieces.config.json';\n\n/**\n * How many times a read+parse of webpieces.config.json is attempted before the failure is treated as\n * REAL. On a machine running several agents at once the file is routinely rewritten underneath us\n * (a dep bump, another worktree's `wp-*` command, an editor's write-then-rename), and for the few\n * milliseconds of that write the bytes on disk are a truncated/half-written JSON document. Reading\n * exactly then produced a hard block that self-healed seconds later — a false positive that also\n * blocked the tools needed to look into it. Three attempts spanning ~50ms covers a normal write with\n * a cost no human or agent can perceive, and cannot mask a file that is genuinely malformed (a\n * conflict-marked or typo'd config fails all three, identically, and still blocks).\n */\nexport const CONFIG_PARSE_ATTEMPTS = 3;\n\n/** Pause between parse attempts. Small enough to be invisible, long enough to outlast a file write. */\nexport const CONFIG_PARSE_RETRY_MILLIS = 25;\n\n/**\n * One read+parse attempt: EITHER a parsed config OR the error that attempt hit, never both.\n * Data-only (per CLAUDE.md, classes for data).\n */\nexport class ConfigParseAttempt {\n constructor(\n readonly config: RawConfigFile | null,\n readonly error: Error | null,\n ) {}\n}\n\n// Raw shape of webpieces.config.json as parsed from JSON, before validation/typing.\n// - `rules` — code-style validators (scope edit/file).\n// - `hookGuards` — git/PR/branch protection guards (scope bash).\n// - `commands` — gated command config the guards point at; `pr-gate` lives inside it. Carried as\n// opaque JSON because its nested `gates` array can't be expressed in the FieldDef\n// schema; validated structurally by validateCommandsSection.\n// - `pr-gate` — DEPRECATED top-level block (pre-migration layout). Read only as a back-compat\n// fallback / to emit a \"move it under commands\" migration error.\n// webpieces-disable no-any-unknown -- consumer JSON config has opaque rule option values\nexport interface RawConfigFile {\n extends?: string;\n rules?: Record<string, Record<string, unknown>>;\n hookGuards?: Record<string, Record<string, unknown>>;\n // webpieces-disable no-any-unknown -- opaque commands JSON, validated by validateCommandsSection\n commands?: unknown;\n // REQUIRED top-level block: two glob lists that suppress hook enforcement per file path.\n // Opaque here (validated structurally by validateExcludePaths, then parsed into ExcludePaths).\n // webpieces-disable no-any-unknown -- opaque excludePaths JSON, validated by validateExcludePaths\n excludePaths?: unknown;\n // REQUIRED top-level array of client-authored content guards (regex patterns + message + scoping).\n // Opaque here; validated structurally by validateMatchRulesSection, then parsed into MatchRuleConfig[].\n // webpieces-disable no-any-unknown -- opaque match-rules JSON, validated by validateMatchRulesSection\n 'match-rules'?: unknown;\n rulesDir?: string[];\n // webpieces-disable no-any-unknown -- DEPRECATED top-level pr-gate, migrated under `commands`\n 'pr-gate'?: unknown;\n}\n\n/**\n * Locates + reads webpieces.config.json. `@injectable(bindingScopeValues.Singleton)` so it can be injected into the config\n * loader and appear in the rules-config DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ConfigFile {\n /** Walk up from `startDir` looking for webpieces.config.json. Returns its absolute path or null. */\n findConfigFile(startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const primary = path.join(dir, CONFIG_FILENAME);\n if (fs.existsSync(primary)) return primary;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n }\n\n /**\n * Read + JSON.parse webpieces.config.json, RETRYING a failed attempt before escalating.\n *\n * A single failed read is not evidence of a broken config: another process on this machine may be\n * mid-write, and a half-written file is unparseable for a few milliseconds and then fine. Only a\n * failure that survives every attempt is treated as real — and then it still throws, so a\n * genuinely invalid config blocks exactly as before. See {@link CONFIG_PARSE_ATTEMPTS}.\n */\n readRawConfig(configPath: string): RawConfigFile {\n let lastError: Error | null = null;\n for (let attempt = 1; attempt <= CONFIG_PARSE_ATTEMPTS; attempt++) {\n if (attempt > 1) this.sleepSync(CONFIG_PARSE_RETRY_MILLIS);\n const outcome = this.attemptReadAndParse(configPath);\n if (outcome.config !== null) return outcome.config;\n lastError = outcome.error;\n }\n throw new InformAiError(this.formatParseFailure(configPath, lastError));\n }\n\n // ONE read+parse attempt. The read is inside the try too: a file being replaced can momentarily\n // fail to open (ENOENT between unlink and rename), which is the same transient class as a\n // half-written parse failure and must be retried the same way.\n private attemptReadAndParse(configPath: string): ConfigParseAttempt {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const raw = this.readFileText(configPath);\n return new ConfigParseAttempt(JSON.parse(raw) as RawConfigFile, null);\n } catch (err: unknown) {\n const error = toError(err);\n return new ConfigParseAttempt(null, error);\n }\n }\n\n /** Read the file's bytes. `protected` so a test can inject a transient failure deterministically. */\n protected readFileText(configPath: string): string {\n return fs.readFileSync(configPath, 'utf8');\n }\n\n /**\n * Block this thread for `millis`. The hook path is synchronous top to bottom (a PreToolUse hook\n * answers on stdout before the tool runs), so an async delay is not available; `Atomics.wait` on a\n * never-notified word is the standard dependency-free synchronous sleep.\n */\n protected sleepSync(millis: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, millis);\n }\n\n // The AI-facing message for a parse failure that survived every attempt. It names the retry count\n // on purpose: an agent that sees \"invalid JSON\" for a file that reads fine three seconds later has\n // no way to tell a race from a real syntax error, and the FIRST thing it needs to know is that\n // read-only inspection of the file is still available so it can go look.\n private formatParseFailure(configPath: string, error: Error | null): string {\n return (\n `webpieces.config.json could not be parsed as JSON — retried ${CONFIG_PARSE_ATTEMPTS} times ` +\n `over ~${CONFIG_PARSE_RETRY_MILLIS * (CONFIG_PARSE_ATTEMPTS - 1)}ms and it failed every time.\\n` +\n `Parse error: ${error?.message ?? 'unknown'}\\n` +\n `File: ${configPath}\\n\\n` +\n `Two causes, in the order to check them:\\n` +\n ` 1. GENUINELY INVALID — most likely. Look at the file: a trailing comma, a missing brace, ` +\n `or leftover conflict markers (\\`<<<<<<< HEAD\\`) from a merge you are in the middle of.\\n` +\n ` 2. STILL BEING WRITTEN by another process (another agent/worktree on this machine, a dep ` +\n `bump, an editor save). ${CONFIG_PARSE_ATTEMPTS} attempts already ruled out a brief write, but a ` +\n `long-running writer can outlast them — if so, simply retrying your command now will succeed.\\n\\n` +\n `👉 READING AND EDITING ${CONFIG_FILENAME} IS ALWAYS ALLOWED, including right now: \\`Read\\`, ` +\n `\\`cat\\`, \\`grep\\`, \\`sed -n\\` and the other read-only inspection commands still work while the ` +\n `config is broken. Go look at the file, fix it, then retry. (Writes to OTHER files stay ` +\n `blocked — with an unparseable config every guard is disabled, so nothing else may proceed.)`\n );\n }\n}\n\n// Temporary migration delegators — consumers migrate to injecting ConfigFile over follow-up PRs, then\n// these free functions are removed. Declarations kept identical to the originals (unchanged lines).\nconst configFileSvc = new ConfigFile();\n\n/**\n * Walk up from `startDir` looking for webpieces.config.json. Returns its absolute path or null.\n */\nexport function findConfigFile(startDir: string): string | null {\n return configFileSvc.findConfigFile(startDir);\n}\n\n/**\n * Read + JSON.parse webpieces.config.json, surfacing parse failures as a readable InformAiError.\n */\nexport function readRawConfig(configPath: string): RawConfigFile {\n return configFileSvc.readRawConfig(configPath);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config-file.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-file.ts"],"names":[],"mappings":";;;AAgJA,wCAEC;AAKD,sCAEC;;AAzJD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,8DAA0D;AAC1D,iEAA6D;AAEhD,QAAA,eAAe,GAAG,uBAAuB,CAAC;AAEvD;;;;;;;;;GASG;AACU,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAEvC,uGAAuG;AAC1F,QAAA,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;GAGG;AACH,MAAa,kBAAkB;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YAC7F,0FAA0F;YAC1F,6FAA6F;YAC7F,0BAA0B,6BAAqB,mDAAmD;YAClG,kGAAkG;YAClG,0BAA0B,uBAAe,qDAAqD;YAC9F,iGAAiG;YACjG,yFAAyF;YACzF,6FAA6F,CAChG,CAAC;IACN,CAAC;CACJ,CAAA;AAnFY,gCAAU;qBAAV,UAAU;IADtB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,UAAU,CAmFtB;AAED,sGAAsG;AACtG,oGAAoG;AACpG,MAAM,aAAa,GAAG,IAAI,UAAU,EAAE,CAAC;AAEvC;;GAEG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC3C,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,UAAkB;IAC5C,OAAO,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\nexport const CONFIG_FILENAME = 'webpieces.config.json';\n\n/**\n * How many times a read+parse of webpieces.config.json is attempted before the failure is treated as\n * REAL. On a machine running several agents at once the file is routinely rewritten underneath us\n * (a dep bump, another worktree's `wp-*` command, an editor's write-then-rename), and for the few\n * milliseconds of that write the bytes on disk are a truncated/half-written JSON document. Reading\n * exactly then produced a hard block that self-healed seconds later — a false positive that also\n * blocked the tools needed to look into it. Three attempts spanning ~50ms covers a normal write with\n * a cost no human or agent can perceive, and cannot mask a file that is genuinely malformed (a\n * conflict-marked or typo'd config fails all three, identically, and still blocks).\n */\nexport const CONFIG_PARSE_ATTEMPTS = 3;\n\n/** Pause between parse attempts. Small enough to be invisible, long enough to outlast a file write. */\nexport const CONFIG_PARSE_RETRY_MILLIS = 25;\n\n/**\n * One read+parse attempt: EITHER a parsed config OR the error that attempt hit, never both.\n * Data-only (per CLAUDE.md, classes for data).\n */\nexport class ConfigParseAttempt {\n constructor(\n readonly config: RawConfigFile | null,\n readonly error: Error | null,\n ) {}\n}\n\n/** Parsed but unvalidated root declaration. Concrete policy settings live only in declared owner files. */\nexport class RawConfigFile {\n // webpieces-disable no-any-unknown -- opaque client JSON is validated at the root/owner boundary\n rulePacks?: unknown;\n // webpieces-disable no-any-unknown -- command behavior has its own structural validator\n commands?: unknown;\n // webpieces-disable no-any-unknown -- generic exclusions are validated before interpretation\n excludePaths?: unknown;\n // webpieces-disable no-any-unknown -- client match rules have their own structural validator\n 'match-rules'?: unknown;\n}\n\n/**\n * Locates + reads webpieces.config.json. `@injectable(bindingScopeValues.Singleton)` so it can be injected into the config\n * loader and appear in the rules-config DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ConfigFile {\n /** Walk up from `startDir` looking for webpieces.config.json. Returns its absolute path or null. */\n findConfigFile(startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const primary = path.join(dir, CONFIG_FILENAME);\n if (fs.existsSync(primary)) return primary;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n }\n\n /**\n * Read + JSON.parse webpieces.config.json, RETRYING a failed attempt before escalating.\n *\n * A single failed read is not evidence of a broken config: another process on this machine may be\n * mid-write, and a half-written file is unparseable for a few milliseconds and then fine. Only a\n * failure that survives every attempt is treated as real — and then it still throws, so a\n * genuinely invalid config blocks exactly as before. See {@link CONFIG_PARSE_ATTEMPTS}.\n */\n readRawConfig(configPath: string): RawConfigFile {\n let lastError: Error | null = null;\n for (let attempt = 1; attempt <= CONFIG_PARSE_ATTEMPTS; attempt++) {\n if (attempt > 1) this.sleepSync(CONFIG_PARSE_RETRY_MILLIS);\n const outcome = this.attemptReadAndParse(configPath);\n if (outcome.config !== null) return outcome.config;\n lastError = outcome.error;\n }\n throw new InformAiError(this.formatParseFailure(configPath, lastError));\n }\n\n // ONE read+parse attempt. The read is inside the try too: a file being replaced can momentarily\n // fail to open (ENOENT between unlink and rename), which is the same transient class as a\n // half-written parse failure and must be retried the same way.\n private attemptReadAndParse(configPath: string): ConfigParseAttempt {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const raw = this.readFileText(configPath);\n return new ConfigParseAttempt(JSON.parse(raw) as RawConfigFile, null);\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 return new ConfigParseAttempt(null, error);\n }\n }\n\n /** Read the file's bytes. `protected` so a test can inject a transient failure deterministically. */\n protected readFileText(configPath: string): string {\n return fs.readFileSync(configPath, 'utf8');\n }\n\n /**\n * Block this thread for `millis`. The hook path is synchronous top to bottom (a PreToolUse hook\n * answers on stdout before the tool runs), so an async delay is not available; `Atomics.wait` on a\n * never-notified word is the standard dependency-free synchronous sleep.\n */\n protected sleepSync(millis: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, millis);\n }\n\n // The AI-facing message for a parse failure that survived every attempt. It names the retry count\n // on purpose: an agent that sees \"invalid JSON\" for a file that reads fine three seconds later has\n // no way to tell a race from a real syntax error, and the FIRST thing it needs to know is that\n // read-only inspection of the file is still available so it can go look.\n private formatParseFailure(configPath: string, error: Error | null): string {\n return (\n `webpieces.config.json could not be parsed as JSON — retried ${CONFIG_PARSE_ATTEMPTS} times ` +\n `over ~${CONFIG_PARSE_RETRY_MILLIS * (CONFIG_PARSE_ATTEMPTS - 1)}ms and it failed every time.\\n` +\n `Parse error: ${error?.message ?? 'unknown'}\\n` +\n `File: ${configPath}\\n\\n` +\n `Two causes, in the order to check them:\\n` +\n ` 1. GENUINELY INVALID — most likely. Look at the file: a trailing comma, a missing brace, ` +\n `or leftover conflict markers (\\`<<<<<<< HEAD\\`) from a merge you are in the middle of.\\n` +\n ` 2. STILL BEING WRITTEN by another process (another agent/worktree on this machine, a dep ` +\n `bump, an editor save). ${CONFIG_PARSE_ATTEMPTS} attempts already ruled out a brief write, but a ` +\n `long-running writer can outlast them — if so, simply retrying your command now will succeed.\\n\\n` +\n `👉 READING AND EDITING ${CONFIG_FILENAME} IS ALWAYS ALLOWED, including right now: \\`Read\\`, ` +\n `\\`cat\\`, \\`grep\\`, \\`sed -n\\` and the other read-only inspection commands still work while the ` +\n `config is broken. Go look at the file, fix it, then retry. (Writes to OTHER files stay ` +\n `blocked — with an unparseable config every guard is disabled, so nothing else may proceed.)`\n );\n }\n}\n\n// Temporary migration delegators — consumers migrate to injecting ConfigFile over follow-up PRs, then\n// these free functions are removed. Declarations kept identical to the originals (unchanged lines).\nconst configFileSvc = new ConfigFile();\n\n/**\n * Walk up from `startDir` looking for webpieces.config.json. Returns its absolute path or null.\n */\nexport function findConfigFile(startDir: string): string | null {\n return configFileSvc.findConfigFile(startDir);\n}\n\n/**\n * Read + JSON.parse webpieces.config.json, surfacing parse failures as a readable InformAiError.\n */\nexport function readRawConfig(configPath: string): RawConfigFile {\n return configFileSvc.readRawConfig(configPath);\n}\n"]}
|
package/src/config-key-rules.js
CHANGED
|
@@ -14,9 +14,7 @@ const retired_config_keys_1 = require("./retired-config-keys");
|
|
|
14
14
|
* retired top-level block, and validateCommandsSection already reports it with the move instruction, so
|
|
15
15
|
* listing it here would replace that precise message with a generic "unknown key".
|
|
16
16
|
*/
|
|
17
|
-
const TOP_LEVEL_KEYS = [
|
|
18
|
-
'extends', 'rules', 'hookGuards', 'commands', 'excludePaths', 'match-rules', 'rulesDir',
|
|
19
|
-
];
|
|
17
|
+
const TOP_LEVEL_KEYS = ['rulePacks', 'commands', 'excludePaths', 'match-rules'];
|
|
20
18
|
/**
|
|
21
19
|
* Reject unknown TOP-LEVEL keys. Without this, a key that was retired at the top level (or simply
|
|
22
20
|
* misspelled) is silently ignored — the config looks configured and behaves as if it were not, and the dead
|
|
@@ -26,8 +24,19 @@ const TOP_LEVEL_KEYS = [
|
|
|
26
24
|
*/
|
|
27
25
|
// webpieces-disable no-any-unknown -- the raw parsed config is opaque; only key names are read here
|
|
28
26
|
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
27
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
29
28
|
function validateTopLevelKeys(raw) {
|
|
30
|
-
|
|
29
|
+
const retired = ['rules', 'hookGuards', 'rulesDir', 'extends'].filter((key) => Object.hasOwn(raw, key));
|
|
30
|
+
const errors = retired.map((key) => `[webpieces.config.json] Retired top-level key "${key}". ` +
|
|
31
|
+
(key === 'rulesDir'
|
|
32
|
+
? 'Declare a client-owned rule pack with a schema and implementation module; directory scanning is retired.'
|
|
33
|
+
: key === 'extends'
|
|
34
|
+
? 'Declare exact rulePacks and explicit owner files; inherited central config is retired.'
|
|
35
|
+
: 'Run pnpm wp-rules-sync --upgrade to move the existing explicit entries into declared owner files.'));
|
|
36
|
+
return [
|
|
37
|
+
...errors,
|
|
38
|
+
...unknownKeyErrors(raw, [...TOP_LEVEL_KEYS, 'pr-gate', ...retired], '[webpieces.config.json]'),
|
|
39
|
+
];
|
|
31
40
|
}
|
|
32
41
|
/**
|
|
33
42
|
* The `*Why` convention: any key ending in "Why" is free-form rationale a consumer keeps beside the key it
|
|
@@ -51,7 +60,9 @@ function isCommentKey(key) {
|
|
|
51
60
|
*/
|
|
52
61
|
// webpieces-disable no-any-unknown -- `section` is opaque consumer JSON; only key names are read
|
|
53
62
|
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
54
|
-
function unknownKeyErrors(
|
|
63
|
+
function unknownKeyErrors(
|
|
64
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
65
|
+
section, knownKeys, label) {
|
|
55
66
|
const errors = [];
|
|
56
67
|
for (const key of Object.keys(section)) {
|
|
57
68
|
if (knownKeys.includes(key) || (0, retired_config_keys_1.isRetiredKey)(key, label))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-key-rules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-key-rules.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"config-key-rules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/config-key-rules.ts"],"names":[],"mappings":";;;AAwBA,oDAqBC;AAeD,oCAEC;AASD,4CAsBC;AA7FD,+DAAqD;AAErD,0GAA0G;AAC1G,qFAAqF;AACrF,sGAAsG;AACtG,yBAAyB;AAEzB;;;;GAIG;AACH,MAAM,cAAc,GAAsB,CAAC,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAEnG;;;;;;GAMG;AACH,oGAAoG;AACpG,8GAA8G;AAC9G,6GAA6G;AAC7G,SAAgB,oBAAoB,CAAC,GAA4B;IAC7D,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,EAAE,CAClF,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAC1B,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CACtB,CAAC,GAAW,EAAE,EAAE,CACZ,kDAAkD,GAAG,KAAK;QAC1D,CAAC,GAAG,KAAK,UAAU;YACf,CAAC,CAAC,0GAA0G;YAC5G,CAAC,CAAC,GAAG,KAAK,SAAS;gBACjB,CAAC,CAAC,wFAAwF;gBAC1F,CAAC,CAAC,mGAAmG,CAAC,CACnH,CAAC;IACF,OAAO;QACH,GAAG,MAAM;QACT,GAAG,gBAAgB,CACf,GAAG,EACH,CAAC,GAAG,cAAc,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,EAC1C,yBAAyB,CAC5B;KACJ,CAAC;AACN,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,kBAAkB,GAAG,KAAK,CAAC;AAExC,8GAA8G;AAC9G,SAAgB,YAAY,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,GAAG,0BAAkB,CAAC,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,0BAAkB,CAAC,CAAC;AACtF,CAAC;AAED;;;;GAIG;AACH,iGAAiG;AACjG,8GAA8G;AAC9G,SAAgB,gBAAgB;AAC5B,6GAA6G;AAC7G,OAAgC,EAChC,SAA4B,EAC5B,KAAa;IAEb,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACrC,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAA,kCAAY,EAAC,GAAG,EAAE,KAAK,CAAC;YAAE,SAAS;QAClE,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,GAAG,kDAAkD,CAAC,CAAC;YACpF,CAAC;YACD,SAAS;QACb,CAAC;QACD,MAAM,CAAC,IAAI,CACP,GAAG,KAAK,iBAAiB,GAAG,mBAAmB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;YACpE,6FAA6F;YAC7F,oGAAoG,CAC3G,CAAC;IACN,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { isRetiredKey } from './retired-config-keys';\n\n// Key-level rules every webpieces.config.json section shares: strict unknown-key rejection and the `*Why`\n// comment convention. Its own module because both validate-config.ts (top level) and\n// commands-section-validators.ts (the commands section) need it, and either importing the other would\n// close an import cycle.\n\n/**\n * Every key webpieces.config.json defines at the TOP level. `pr-gate` is deliberately absent — it is the\n * retired top-level block, and validateCommandsSection already reports it with the move instruction, so\n * listing it here would replace that precise message with a generic \"unknown key\".\n */\nconst TOP_LEVEL_KEYS: readonly string[] = ['rulePacks', 'commands', 'excludePaths', 'match-rules'];\n\n/**\n * Reject unknown TOP-LEVEL keys. Without this, a key that was retired at the top level (or simply\n * misspelled) is silently ignored — the config looks configured and behaves as if it were not, and the dead\n * key survives every upgrade. `*Why` rationale keys are allowed, which is what lets the file document\n * itself: this repo ships a top-level `upgradePolicyWhy` stating that config is validated on startup and\n * migrated by the agent, so no backwards-compatible release is needed.\n */\n// webpieces-disable no-any-unknown -- the raw parsed config is opaque; only key names are read here\n// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file\n// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\nexport function validateTopLevelKeys(raw: Record<string, unknown>): string[] {\n const retired = ['rules', 'hookGuards', 'rulesDir', 'extends'].filter((key: string) =>\n Object.hasOwn(raw, key),\n );\n const errors = retired.map(\n (key: string) =>\n `[webpieces.config.json] Retired top-level key \"${key}\". ` +\n (key === 'rulesDir'\n ? 'Declare a client-owned rule pack with a schema and implementation module; directory scanning is retired.'\n : key === 'extends'\n ? 'Declare exact rulePacks and explicit owner files; inherited central config is retired.'\n : 'Run pnpm wp-rules-sync --upgrade to move the existing explicit entries into declared owner files.'),\n );\n return [\n ...errors,\n ...unknownKeyErrors(\n raw,\n [...TOP_LEVEL_KEYS, 'pr-gate', ...retired],\n '[webpieces.config.json]',\n ),\n ];\n}\n\n/**\n * The `*Why` convention: any key ending in \"Why\" is free-form rationale a consumer keeps beside the key it\n * explains. JSON has no comments, so this is how this repo documents non-obvious config — and it is the only\n * way the config file can carry the note that matters most to the agent reading it (see the top-level\n * \"upgradePolicyWhy\" this repo ships). Comment keys are therefore allowed wherever unknown keys are\n * otherwise rejected, and must be strings.\n *\n * ONE exception, enforced separately: `gateSaltWhy` is rejected outright, because rationale next to the gate\n * salt is a bypass how-to in the most-read file in the repo. See validateNoGateSaltRationale.\n */\nexport const COMMENT_KEY_SUFFIX = 'Why';\n\n// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file\nexport function isCommentKey(key: string): boolean {\n return key.length > COMMENT_KEY_SUFFIX.length && key.endsWith(COMMENT_KEY_SUFFIX);\n}\n\n/**\n * Reject keys a section does not define. Without this a retired or misspelled key is simply ignored, which is\n * how a stale shape survives an upgrade forever — the whole failure mode RETIRED_CONFIG_KEYS exists to end.\n * Retired keys are skipped here so they get their own migration message instead of a generic \"unknown key\".\n */\n// webpieces-disable no-any-unknown -- `section` is opaque consumer JSON; only key names are read\n// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file\nexport function unknownKeyErrors(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n section: Record<string, unknown>,\n knownKeys: readonly string[],\n label: string,\n): string[] {\n const errors: string[] = [];\n for (const key of Object.keys(section)) {\n if (knownKeys.includes(key) || isRetiredKey(key, label)) continue;\n if (isCommentKey(key)) {\n if (typeof section[key] !== 'string') {\n errors.push(`${label} \"${key}\" is a *Why rationale note and must be a string.`);\n }\n continue;\n }\n errors.push(\n `${label} Unknown key \"${key}\". Valid keys: [${knownKeys.join(', ')}]. ` +\n `Delete it, or — if it is rationale you want to keep beside a key — rename it to \"<key>Why\" ` +\n `with a string value (JSON has no comments, so \"*Why\" siblings are how this repo documents config).`,\n );\n }\n return errors;\n}\n"]}
|
package/src/config-pruner.d.ts
CHANGED
|
@@ -1,45 +1,10 @@
|
|
|
1
1
|
import { AtomicFile } from '@webpieces/tooling-common';
|
|
2
2
|
import { ConfigFile } from './config-file';
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
* `wp-prune-unknown-config` — the MECHANICAL cure for "[x] Unknown rule".
|
|
6
|
-
*
|
|
7
|
-
* ## Why a command and not just advice
|
|
8
|
-
*
|
|
9
|
-
* An unknown key controls nothing, so deleting it is the fix, and the validator now says so. But the
|
|
10
|
-
* moment that advice is read is the worst possible moment to act on it by hand: the hook guard denies
|
|
11
|
-
* every Bash call while the config is invalid, so the reader is editing JSON blind, with no way to
|
|
12
|
-
* re-run the validator between edits. Making the cleanup one command means cleanliness is the default
|
|
13
|
-
* path rather than a judgement call taken under a total block — and it makes "the file validates" mean
|
|
14
|
-
* "every key in it is real", which is the property that keeps dead config from reading as live config.
|
|
15
|
-
*
|
|
16
|
-
* ## What it removes, and what it deliberately does NOT
|
|
17
|
-
*
|
|
18
|
-
* Removed, from the `rules` and `hookGuards` sections only:
|
|
19
|
-
* - a name with no entry in RULE_SCHEMAS and no entry in RETIRED_CONFIG_KEYS (a typo, or a rule some
|
|
20
|
-
* release deleted). Nothing reads it, by construction.
|
|
21
|
-
* - a name in RETIRED_CONFIG_KEYS whose entry is `prunable` — the retirement's own instruction is
|
|
22
|
-
* "delete this entry", because the setting left webpieces.config.json entirely.
|
|
23
|
-
*
|
|
24
|
-
* NOT removed:
|
|
25
|
-
* - a RENAME or an in-file move (`prunable: false`). Deleting those discards a value the new key still
|
|
26
|
-
* needs, so they keep their migration instruction and a human/agent applies it.
|
|
27
|
-
* - anything at all when `rulesDir` is configured. A custom rule legitimately has no built-in schema,
|
|
28
|
-
* and this command must never eat one.
|
|
29
|
-
* - top-level keys, `commands`, `excludePaths`, `match-rules`. Those are validated by shape, not by a
|
|
30
|
-
* name table, so "unknown" is not defined for them and a pruner would be guessing.
|
|
31
|
-
*
|
|
32
|
-
* ## The one destructive case, and why the drift guard already covers it
|
|
33
|
-
*
|
|
34
|
-
* A key CAN be valid-but-unlearned when package.json pins an @webpieces older than the config. Pruning
|
|
35
|
-
* then would delete live config. That case cannot reach here: the shim's version-drift guard compares
|
|
36
|
-
* the pin against the installed version and denies every tool call — including this one — before the
|
|
37
|
-
* validator or this command ever runs. It is also why `PruneResult` names every key it removed rather
|
|
38
|
-
* than reporting a count: a silent sweep is the thing that would make the rare case unrecoverable.
|
|
39
|
-
*/
|
|
3
|
+
import { PackPolicyFiles } from './pack-policy-files';
|
|
4
|
+
/** Prune only owner-file entries that no selected schema reads, retaining renames and wrong-owner entries for explicit repair. */
|
|
40
5
|
/** One key this run removed, and the reason it was safe to remove. Data-only (per CLAUDE.md). */
|
|
41
6
|
export declare class PrunedKey {
|
|
42
|
-
/**
|
|
7
|
+
/** The declared owner config path containing the key. */
|
|
43
8
|
section: string;
|
|
44
9
|
/** The rule/guard name exactly as it appeared in the file. */
|
|
45
10
|
key: string;
|
|
@@ -61,8 +26,8 @@ export declare class PruneResult {
|
|
|
61
26
|
export declare class ConfigPruner {
|
|
62
27
|
private readonly configFile;
|
|
63
28
|
private readonly atomicFile;
|
|
64
|
-
private readonly
|
|
65
|
-
constructor(configFile: ConfigFile, atomicFile: AtomicFile,
|
|
29
|
+
private readonly files;
|
|
30
|
+
constructor(configFile: ConfigFile, atomicFile: AtomicFile, files: PackPolicyFiles);
|
|
66
31
|
/**
|
|
67
32
|
* Strip every unknown key from the webpieces.config.json above `cwd` and rewrite it. Throws when no
|
|
68
33
|
* config file is found — a prune with no target is a mistake, not a no-op.
|
|
@@ -74,8 +39,6 @@ export declare class ConfigPruner {
|
|
|
74
39
|
* file that fails validation.
|
|
75
40
|
*/
|
|
76
41
|
prune(configPath: string): PruneResult;
|
|
77
|
-
/** Mutates `document`, deleting every prunable name from the two rule sections. */
|
|
78
|
-
private removeUnknown;
|
|
79
42
|
/** Why `key` is safe to delete, or null when it must be kept. */
|
|
80
43
|
private reasonToRemove;
|
|
81
44
|
/**
|