@webpieces/rules-config 0.4.925 → 0.4.926
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 -6
- package/src/config-file.js +4 -2
- package/src/config-file.js.map +1 -1
- package/src/config-key-rules.js +1 -1
- package/src/config-key-rules.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-error.d.ts +46 -0
- package/src/config-repair-error.js +83 -0
- package/src/config-repair-error.js.map +1 -0
- package/src/config-repair-probe.d.ts +7 -1
- package/src/config-repair-probe.js +19 -29
- package/src/config-repair-probe.js.map +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +7 -7
- package/src/index.js.map +1 -1
- package/src/legacy-config-upgrade.d.ts +1 -1
- package/src/legacy-config-upgrade.js +6 -6
- package/src/legacy-config-upgrade.js.map +1 -1
- package/src/load-config.d.ts +1 -3
- package/src/load-config.js +10 -10
- package/src/load-config.js.map +1 -1
- package/src/migrate-dirs-cli.js +1 -3
- package/src/migrate-dirs-cli.js.map +1 -1
- package/src/pack-policy-files.d.ts +10 -1
- package/src/pack-policy-files.js +97 -38
- package/src/pack-policy-files.js.map +1 -1
- package/src/policy-tracking.js +8 -8
- package/src/policy-tracking.js.map +1 -1
- package/src/rule-pack-sync.d.ts +8 -15
- package/src/rule-pack-sync.js +17 -137
- package/src/rule-pack-sync.js.map +1 -1
- package/templates/webpieces.guard-matrix.md +4 -5
- package/src/rule-pack-artifacts.d.ts +0 -23
- package/src/rule-pack-artifacts.js +0 -180
- package/src/rule-pack-artifacts.js.map +0 -1
- package/src/rules-sync-cli.d.ts +0 -7
- package/src/rules-sync-cli.js +0 -48
- package/src/rules-sync-cli.js.map +0 -1
package/src/pack-policy-files.js
CHANGED
|
@@ -11,6 +11,8 @@ const rule_pack_registry_1 = require("./rule-pack-registry");
|
|
|
11
11
|
const repository_path_1 = require("./repository-path");
|
|
12
12
|
const retired_config_keys_1 = require("./retired-config-keys");
|
|
13
13
|
const config_error_banner_1 = require("./config-error-banner");
|
|
14
|
+
const config_repair_error_1 = require("./config-repair-error");
|
|
15
|
+
const config_file_1 = require("./config-file");
|
|
14
16
|
/** The root declaration identifies an exact package/module and its owner-specific config file. */
|
|
15
17
|
class PackPolicyDeclaration {
|
|
16
18
|
config;
|
|
@@ -46,12 +48,21 @@ class PackPolicyFilesResult {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
exports.PackPolicyFilesResult = PackPolicyFilesResult;
|
|
49
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Configuration belongs to explicitly selected owners; loading never supplies recommended seeds.
|
|
53
|
+
*
|
|
54
|
+
* Every problem this class finds is a ConfigRepairError naming the file to edit and the exact entry to
|
|
55
|
+
* paste or delete (#1273). The hooks permit those edits while the config is invalid, so an upgrade that
|
|
56
|
+
* adds a required rule costs the agent one edit of one named file, and no command.
|
|
57
|
+
*/
|
|
50
58
|
let PackPolicyFiles = class PackPolicyFiles {
|
|
51
59
|
// webpieces-disable no-any-unknown -- root JSON is narrowed before resolving modules or files.
|
|
52
60
|
declarations(raw, root) {
|
|
61
|
+
const rootFile = path.join(root, config_file_1.CONFIG_FILENAME);
|
|
53
62
|
if (!Array.isArray(raw) || raw.length === 0) {
|
|
54
|
-
throw new
|
|
63
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: rulePacks is required.`, [
|
|
64
|
+
new config_repair_error_1.EditFileCure(rootFile, 'Add "rulePacks": [{"package":"<pack>","config":".webpieces-config/rules/<pack>.json"}, ...] with one declaration per selected rule pack; each rule then names the owner file its entry belongs in.'),
|
|
65
|
+
]);
|
|
55
66
|
}
|
|
56
67
|
const packages = new Set(), files = new Set();
|
|
57
68
|
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
@@ -66,11 +77,15 @@ let PackPolicyFiles = class PackPolicyFiles {
|
|
|
66
77
|
typeof entry.config !== 'string' ||
|
|
67
78
|
!entry.config ||
|
|
68
79
|
Object.keys(entry).some((key) => !['package', 'config'].includes(key))) {
|
|
69
|
-
throw new
|
|
80
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: invalid rulePacks entry ${JSON.stringify(entry)}.`, [
|
|
81
|
+
new config_repair_error_1.EditFileCure(rootFile, 'Give the entry exactly two string fields: {"package":"<pack>","config":".webpieces-config/rules/<pack>.json"}.'),
|
|
82
|
+
]);
|
|
70
83
|
}
|
|
71
84
|
const filename = this.configPath(root, entry.config);
|
|
72
85
|
if (packages.has(entry.package) || files.has(filename)) {
|
|
73
|
-
throw new
|
|
86
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: duplicate rule-pack declaration or config path: ${entry.package}, ${entry.config}.`, [
|
|
87
|
+
new config_repair_error_1.EditFileCure(rootFile, 'Delete the second rulePacks entry; declare each pack and config once.'),
|
|
88
|
+
]);
|
|
74
89
|
}
|
|
75
90
|
packages.add(entry.package);
|
|
76
91
|
files.add(filename);
|
|
@@ -93,15 +108,18 @@ let PackPolicyFiles = class PackPolicyFiles {
|
|
|
93
108
|
}
|
|
94
109
|
catch (err) {
|
|
95
110
|
const error = (0, to_error_1.toError)(err);
|
|
96
|
-
|
|
111
|
+
const rootFile = path.join(root, config_file_1.CONFIG_FILENAME);
|
|
112
|
+
throw new config_repair_error_1.ConfigRepairError(`Rule-pack selection in ${rootFile} needs repair: ${error.message}`, [
|
|
113
|
+
new config_repair_error_1.EditFileCure(rootFile, 'Fix the rulePacks entry named above: declare the package that actually owns the pack, or delete the entry.'),
|
|
114
|
+
new config_repair_error_1.RunCommandCure('pnpm install', 'pnpm install — when the declared pack is simply missing from node_modules.'),
|
|
115
|
+
], { cause: error });
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
118
|
resolve(root, selected) {
|
|
100
|
-
const registry =
|
|
101
|
-
for (const pack of selected)
|
|
102
|
-
registry.recordModuleLocation(pack.manifest.packageName, pack.declaration.moduleName());
|
|
119
|
+
const registry = this.registry(root, selected);
|
|
103
120
|
const values = {}, targetFiles = new Map();
|
|
104
121
|
const errors = [];
|
|
122
|
+
const filesToEdit = new Set();
|
|
105
123
|
for (const pack of selected) {
|
|
106
124
|
const filename = this.configPath(root, pack.declaration.config);
|
|
107
125
|
for (const definition of pack.manifest.ownedRules)
|
|
@@ -109,39 +127,40 @@ let PackPolicyFiles = class PackPolicyFiles {
|
|
|
109
127
|
}
|
|
110
128
|
for (const pack of selected) {
|
|
111
129
|
const filename = this.configPath(root, pack.declaration.config);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.migrations()
|
|
117
|
-
.find((entry) => entry.scope === retired_config_keys_1.RETIRED_SCOPE_RULE && entry.key === id);
|
|
118
|
-
errors.push(`${filename}: ${retired ? (0, retired_config_keys_1.retiredKeyError)(retired) : `${id} has no declared configurable owner. Remove this entry.`}`);
|
|
119
|
-
}
|
|
120
|
-
else if (registry.ownerOf(id) !== pack.manifest.packageName) {
|
|
121
|
-
errors.push(`${filename}: ${id} belongs to ${registry.ownerOf(id)}. Move it to ${targetFiles.get(id)}.`);
|
|
122
|
-
}
|
|
130
|
+
if (!fs.existsSync(filename)) {
|
|
131
|
+
filesToEdit.add(filename);
|
|
132
|
+
errors.push(`${filename}: missing rule-pack config for ${pack.manifest.packageName}. Create it with this content (the owner's recommended seeds — review every value):\n${JSON.stringify(this.seeds(pack), null, 2)}`);
|
|
133
|
+
continue;
|
|
123
134
|
}
|
|
135
|
+
const entries = this.read(filename);
|
|
136
|
+
this.foreignEntries(filename, entries, pack, registry, targetFiles, errors, filesToEdit);
|
|
124
137
|
for (const definition of pack.manifest.ownedRules) {
|
|
125
138
|
if (!Object.hasOwn(entries, definition.id)) {
|
|
126
|
-
|
|
139
|
+
filesToEdit.add(filename);
|
|
140
|
+
errors.push(`${filename}: missing required entry "${definition.id}". Paste this entry into that file (the owner's recommended seed — choose your own values; OFF still states every required field):\n"${definition.id}": ${JSON.stringify(registry.seedFor(definition.id))}`);
|
|
127
141
|
continue;
|
|
128
142
|
}
|
|
129
143
|
const value = entries[definition.id];
|
|
130
|
-
|
|
144
|
+
const invalid = registry
|
|
131
145
|
.validateRuleConfig(definition.id, value)
|
|
132
|
-
.map((error) => `${filename}: ${error}`)
|
|
146
|
+
.map((error) => `${filename}: ${error}`);
|
|
147
|
+
if (invalid.length)
|
|
148
|
+
filesToEdit.add(filename);
|
|
149
|
+
errors.push(...invalid);
|
|
133
150
|
values[definition.id] = value;
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
153
|
if (errors.length) {
|
|
137
|
-
throw new
|
|
138
|
-
'\nEditing webpieces.config.json and
|
|
154
|
+
throw new config_repair_error_1.ConfigRepairError((0, config_error_banner_1.formatConfigErrorsBanner)(errors).replace('THE FIX: edit webpieces.config.json', 'THE FIX: edit the declared owner config files named above') +
|
|
155
|
+
'\nEditing webpieces.config.json and every file under .webpieces-config/ is ALWAYS allowed, even while the config is invalid. Required settings are never supplied during loading.', [...filesToEdit].map((file) => new config_repair_error_1.EditFileCure(file, `Edit ${file} and apply every bullet above that names it.`)));
|
|
139
156
|
}
|
|
140
157
|
return new PackPolicyFilesResult(registry, selected, values, targetFiles);
|
|
141
158
|
}
|
|
142
159
|
configPath(root, relative) {
|
|
160
|
+
const rootFile = path.join(root, config_file_1.CONFIG_FILENAME);
|
|
161
|
+
const fixPath = new config_repair_error_1.EditFileCure(rootFile, `Change the rulePacks config "${relative}" to a distinct repository-relative JSON path such as .webpieces-config/rules/code.json.`);
|
|
143
162
|
if (path.isAbsolute(relative) || !relative.endsWith('.json')) {
|
|
144
|
-
throw new
|
|
163
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: invalid pack config path ${relative}.`, [fixPath]);
|
|
145
164
|
}
|
|
146
165
|
let target;
|
|
147
166
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- path faults name the declaration that needs repair
|
|
@@ -151,31 +170,27 @@ let PackPolicyFiles = class PackPolicyFiles {
|
|
|
151
170
|
}
|
|
152
171
|
catch (err) {
|
|
153
172
|
const error = (0, to_error_1.toError)(err);
|
|
154
|
-
throw new
|
|
155
|
-
cause: error,
|
|
156
|
-
});
|
|
173
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: invalid pack config path ${relative}: ${error.message}`, [fixPath], { cause: error });
|
|
157
174
|
}
|
|
158
175
|
const normalized = path.relative(fs.realpathSync(root), target);
|
|
159
176
|
if (path.isAbsolute(relative) ||
|
|
160
177
|
normalized.startsWith('..') ||
|
|
161
178
|
!normalized.endsWith('.json') ||
|
|
162
|
-
normalized ===
|
|
163
|
-
|
|
164
|
-
throw new tooling_common_1.InformAiError(`Invalid pack config path ${relative}. Use a distinct repository-relative JSON path such as .webpieces-config/rules/code.json.`);
|
|
179
|
+
normalized === config_file_1.CONFIG_FILENAME) {
|
|
180
|
+
throw new config_repair_error_1.ConfigRepairError(`${rootFile}: invalid pack config path ${relative}.`, [fixPath]);
|
|
165
181
|
}
|
|
166
|
-
new tooling_common_1.RepositoryLayout().assertPolicyPath(normalized);
|
|
182
|
+
new config_repair_error_1.RepositoryLayoutRepair().run(() => new tooling_common_1.RepositoryLayout().assertPolicyPath(normalized));
|
|
167
183
|
return target;
|
|
168
184
|
}
|
|
169
185
|
read(filename) {
|
|
170
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- malformed
|
|
186
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- malformed pack files name their exact repair path.
|
|
171
187
|
try {
|
|
172
|
-
if (!fs.existsSync(filename)) {
|
|
173
|
-
throw new tooling_common_1.InformAiError(`Missing rule-pack config ${filename}. Run pnpm wp-rules-sync to create explicit owner seeds, then review the diff.`);
|
|
174
|
-
}
|
|
175
188
|
// webpieces-disable no-any-unknown -- registry validation narrows the parsed option bags.
|
|
176
189
|
const entries = JSON.parse(fs.readFileSync(filename, 'utf8'));
|
|
177
190
|
if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {
|
|
178
|
-
throw new
|
|
191
|
+
throw new config_repair_error_1.ConfigRepairError(`${filename} must be an object mapping owned rule IDs to explicit config objects.`, [
|
|
192
|
+
new config_repair_error_1.EditFileCure(filename, `Rewrite ${filename} as one JSON object: {"<rule-id>": {...}, ...}.`),
|
|
193
|
+
]);
|
|
179
194
|
}
|
|
180
195
|
return entries;
|
|
181
196
|
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
@@ -184,9 +199,53 @@ let PackPolicyFiles = class PackPolicyFiles {
|
|
|
184
199
|
const error = (0, to_error_1.toError)(err);
|
|
185
200
|
if (error instanceof tooling_common_1.InformAiError)
|
|
186
201
|
throw error;
|
|
187
|
-
throw new
|
|
202
|
+
throw new config_repair_error_1.ConfigRepairError(`Cannot parse rule-pack config ${filename}: ${error.message}.`, [new config_repair_error_1.EditFileCure(filename, `Edit ${filename} to restore valid JSON.`)], { cause: error });
|
|
188
203
|
}
|
|
189
204
|
}
|
|
205
|
+
// Entries this owner file must not hold: unknown or retired IDs (delete), and another owner's (move).
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/max-params -- the accumulators of resolve(), passed through once
|
|
207
|
+
foreignEntries(filename, entries, pack, registry, targetFiles, errors, filesToEdit) {
|
|
208
|
+
for (const id of Object.keys(entries)) {
|
|
209
|
+
if (!registry.hasRule(id)) {
|
|
210
|
+
const retired = registry
|
|
211
|
+
.migrations()
|
|
212
|
+
.find((entry) => entry.scope === retired_config_keys_1.RETIRED_SCOPE_RULE && entry.key === id);
|
|
213
|
+
filesToEdit.add(filename);
|
|
214
|
+
errors.push(`${filename}: ${retired ? (0, retired_config_keys_1.retiredKeyError)(retired) : `"${id}" has no declared configurable owner. Delete the "${id}" entry from this file.`}`);
|
|
215
|
+
}
|
|
216
|
+
else if (registry.ownerOf(id) !== pack.manifest.packageName) {
|
|
217
|
+
const owner = targetFiles.get(id) ?? '';
|
|
218
|
+
filesToEdit.add(filename);
|
|
219
|
+
filesToEdit.add(owner);
|
|
220
|
+
errors.push(`${filename}: "${id}" belongs to ${registry.ownerOf(id)}. Delete the "${id}" entry here and paste it into ${owner}.`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Conflicting manifests (two packs owning one rule) are a SELECTION problem: the declaration is the fix.
|
|
225
|
+
registry(root, selected) {
|
|
226
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- converts a manifest conflict into the declaration's structured repair
|
|
227
|
+
try {
|
|
228
|
+
const registry = new rule_pack_registry_1.RulePackRegistry(selected.map((pack) => pack.manifest));
|
|
229
|
+
for (const pack of selected)
|
|
230
|
+
registry.recordModuleLocation(pack.manifest.packageName, pack.declaration.moduleName());
|
|
231
|
+
return registry;
|
|
232
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
const error = (0, to_error_1.toError)(err);
|
|
236
|
+
if (!(error instanceof tooling_common_1.InformAiError))
|
|
237
|
+
throw error;
|
|
238
|
+
const rootFile = path.join(root, config_file_1.CONFIG_FILENAME);
|
|
239
|
+
throw new config_repair_error_1.ConfigRepairError(`The rule packs declared in ${rootFile} conflict: ${error.message}`, [new config_repair_error_1.EditFileCure(rootFile, 'Delete one of the conflicting rulePacks declarations.')], { cause: error });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// The exact owner file a missing declaration needs: every owned rule's recommended seed, for review.
|
|
243
|
+
seeds(pack) {
|
|
244
|
+
return Object.fromEntries(pack.manifest.ownedRules.map((definition) => [
|
|
245
|
+
definition.id,
|
|
246
|
+
structuredClone(definition.recommendedSeed),
|
|
247
|
+
]));
|
|
248
|
+
}
|
|
190
249
|
};
|
|
191
250
|
exports.PackPolicyFiles = PackPolicyFiles;
|
|
192
251
|
exports.PackPolicyFiles = PackPolicyFiles = tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack-policy-files.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/pack-policy-files.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,oDAA8B;AAC9B,wDAAkC;AAElC,8DAA4E;AAC5E,iEAA6D;AAC7D,6DAAkF;AAClF,uDAAmD;AACnD,+DAA4E;AAC5E,+DAAiE;AAEjE,kGAAkG;AAClG,MAAa,qBAAqB;IAKjB;IAJJ,OAAO,CAAS;IAEzB,YACI,WAAmB,EACV,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAEvB,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;IAC/B,CAAC;IAED,UAAU;QACN,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,YAAY,CAAC;IAC/F,CAAC;CACJ;AAbD,sDAaC;AAED,MAAa,kBAAkB;IAEd;IACA;IAFb,YACa,WAAkC,EAClC,QAA0B;QAD1B,gBAAW,GAAX,WAAW,CAAuB;QAClC,aAAQ,GAAR,QAAQ,CAAkB;IACpC,CAAC;CACP;AALD,gDAKC;AAED,MAAa,qBAAqB;IAEjB;IACA;IACA;IACA;IAJb,YACa,QAA0B,EAC1B,QAAuC,EACvC,MAAoC,EACpC,WAAwC;QAHxC,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,aAAQ,GAAR,QAAQ,CAA+B;QACvC,WAAM,GAAN,MAAM,CAA8B;QACpC,gBAAW,GAAX,WAAW,CAA6B;IAClD,CAAC;CACP;AAPD,sDAOC;AAED,qGAAqG;AAE9F,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,+FAA+F;IAC/F,YAAY,CAAC,GAAY,EAAE,IAAY;QACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CA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AC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,8BAAa,CACnB,4BAA4B,QAAQ,gFAAgF,CACvH,CAAC;YACN,CAAC;YACD,0FAA0F;YAC1F,MAAM,OAAO,GAAY,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;YACvE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpE,MAAM,IAAI,8BAAa,CACnB,GAAG,QAAQ,uEAAuE,CACrF,CAAC;YACN,CAAC;YACD,OAAO,OAAuC,CAAC;YAC/C,6GAA6G;QACjH,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,KAAK,YAAY,8BAAa;gBAAE,MAAM,KAAK,CAAC;YAChD,MAAM,IAAI,8BAAa,CACnB,iCAAiC,QAAQ,KAAK,KAAK,CAAC,OAAO,yCAAyC,EACpG,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AA3LY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,eAAe,CA2L3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { RulePackManifest, ConfigObject, RetiredConfigKey } from '@webpieces/rules-sdk';\nimport { InformAiError, RepositoryLayout } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { NodeRulePackModuleLoader, RulePackRegistry } from './rule-pack-registry';\nimport { RepositoryPath } from './repository-path';\nimport { retiredKeyError, RETIRED_SCOPE_RULE } from './retired-config-keys';\nimport { formatConfigErrorsBanner } from './config-error-banner';\n\n/** The root declaration identifies an exact package/module and its owner-specific config file. */\nexport class PackPolicyDeclaration {\n readonly package: string;\n\n constructor(\n packageName: string,\n readonly config: string,\n ) {\n this.package = packageName;\n }\n\n moduleName(): string {\n return /\\.(?:cjs|mjs|js)$/.test(this.package) ? this.package : `${this.package}/rule-pack`;\n }\n}\n\nexport class SelectedPolicyPack {\n constructor(\n readonly declaration: PackPolicyDeclaration,\n readonly manifest: RulePackManifest,\n ) {}\n}\n\nexport class PackPolicyFilesResult {\n constructor(\n readonly registry: RulePackRegistry,\n readonly selected: readonly SelectedPolicyPack[],\n readonly values: Record<string, ConfigObject>,\n readonly targetFiles: ReadonlyMap<string, string>,\n ) {}\n}\n\n/** Configuration belongs to explicitly selected owners; loading never supplies recommended seeds. */\n@injectable(bindingScopeValues.Singleton)\nexport class PackPolicyFiles {\n // webpieces-disable no-any-unknown -- root JSON is narrowed before resolving modules or files.\n declarations(raw: unknown, root: string): PackPolicyDeclaration[] {\n if (!Array.isArray(raw) || raw.length === 0) {\n throw new InformAiError(\n 'webpieces.config.json.rulePacks is required. Run pnpm wp-rules-sync --upgrade to split the existing explicit config, or add exact {\"package\":\"<pack>\",\"config\":\".webpieces-config/rules/<pack>.json\"} declarations.',\n );\n }\n const packages = new Set<string>(),\n files = new Set<string>();\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n return raw.map((entry: unknown) => {\n if (\n !entry ||\n typeof entry !== 'object' ||\n Array.isArray(entry) ||\n !('package' in entry) ||\n !('config' in entry) ||\n typeof entry.package !== 'string' ||\n !entry.package ||\n typeof entry.config !== 'string' ||\n !entry.config ||\n Object.keys(entry).some((key: string) => !['package', 'config'].includes(key))\n ) {\n throw new InformAiError(\n 'Invalid rulePacks entry in webpieces.config.json. Supply exactly package and config strings.',\n );\n }\n const filename = this.configPath(root, entry.config);\n if (packages.has(entry.package) || files.has(filename)) {\n throw new InformAiError(\n `Duplicate rule-pack declaration or config path: ${entry.package}, ${entry.config}. Declare each pack and config once.`,\n );\n }\n packages.add(entry.package);\n files.add(filename);\n return new PackPolicyDeclaration(entry.package, entry.config);\n });\n }\n\n select(root: string, declarations: readonly PackPolicyDeclaration[]): SelectedPolicyPack[] {\n const loader = new NodeRulePackModuleLoader(root);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- module failures identify the declaration's actual repair file.\n try {\n return declarations.map((declaration: PackPolicyDeclaration) => {\n const manifest = loader.load(declaration.moduleName());\n if (\n declaration.moduleName() === `${declaration.package}/rule-pack` &&\n manifest.packageName !== declaration.package\n ) {\n throw new InformAiError(\n `Declared package ${declaration.package} exports owner ${manifest.packageName}. Declare the actual owning package or an explicit client manifest module.`,\n );\n }\n return new SelectedPolicyPack(declaration, manifest);\n });\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 throw new InformAiError(\n `Rule-pack selection in ${path.join(root, 'webpieces.config.json')} needs repair: ${error.message}`,\n { cause: error },\n );\n }\n }\n\n resolve(root: string, selected: readonly SelectedPolicyPack[]): PackPolicyFilesResult {\n const registry = new RulePackRegistry(\n selected.map((pack: SelectedPolicyPack) => pack.manifest),\n );\n for (const pack of selected)\n registry.recordModuleLocation(pack.manifest.packageName, pack.declaration.moduleName());\n const values: Record<string, ConfigObject> = {},\n targetFiles = new Map<string, string>();\n const errors: string[] = [];\n for (const pack of selected) {\n const filename = this.configPath(root, pack.declaration.config);\n for (const definition of pack.manifest.ownedRules)\n targetFiles.set(definition.id, filename);\n }\n for (const pack of selected) {\n const filename = this.configPath(root, pack.declaration.config);\n const entries = this.read(filename);\n for (const id of Object.keys(entries)) {\n if (!registry.hasRule(id)) {\n const retired = registry\n .migrations()\n .find(\n (entry: RetiredConfigKey) =>\n entry.scope === RETIRED_SCOPE_RULE && entry.key === id,\n );\n errors.push(\n `${filename}: ${retired ? retiredKeyError(retired) : `${id} has no declared configurable owner. Remove this entry.`}`,\n );\n } else if (registry.ownerOf(id) !== pack.manifest.packageName) {\n errors.push(\n `${filename}: ${id} belongs to ${registry.ownerOf(id)}. Move it to ${targetFiles.get(id)}.`,\n );\n }\n }\n for (const definition of pack.manifest.ownedRules) {\n if (!Object.hasOwn(entries, definition.id)) {\n errors.push(\n `${filename}: missing required entry ${definition.id}. Run pnpm wp-rules-sync to write its owner seed and review it, or configure it explicitly; OFF still requires every required field.`,\n );\n continue;\n }\n const value = entries[definition.id];\n errors.push(\n ...registry\n .validateRuleConfig(definition.id, value)\n .map((error: string) => `${filename}: ${error}`),\n );\n values[definition.id] = value;\n }\n }\n if (errors.length) {\n throw new InformAiError(\n formatConfigErrorsBanner(errors).replace(\n 'THE FIX: edit webpieces.config.json',\n 'THE FIX: edit declared owner config files',\n ) +\n '\\nEditing webpieces.config.json and the named owner files is ALWAYS allowed. Missing required settings can be written explicitly with pnpm wp-rules-sync; review and commit the diff. Required settings are never supplied during loading.',\n );\n }\n return new PackPolicyFilesResult(registry, selected, values, targetFiles);\n }\n\n configPath(root: string, relative: string): string {\n if (path.isAbsolute(relative) || !relative.endsWith('.json')) {\n throw new InformAiError(\n `Invalid pack config path ${relative}. Use a distinct repository-relative JSON file.`,\n );\n }\n let target: string;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- path faults name the declaration that needs repair\n try {\n target = new RepositoryPath(root).resolve(relative);\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 throw new InformAiError(`Invalid pack config path ${relative}: ${error.message}`, {\n cause: error,\n });\n }\n const normalized = path.relative(fs.realpathSync(root), target);\n if (\n path.isAbsolute(relative) ||\n normalized.startsWith('..') ||\n !normalized.endsWith('.json') ||\n normalized === 'webpieces.config.json' ||\n normalized === '.webpieces-config/rules.lock.json'\n ) {\n throw new InformAiError(\n `Invalid pack config path ${relative}. Use a distinct repository-relative JSON path such as .webpieces-config/rules/code.json.`,\n );\n }\n new RepositoryLayout().assertPolicyPath(normalized);\n return target;\n }\n\n read(filename: string): Record<string, ConfigObject> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- malformed or absent pack files name their exact repair path.\n try {\n if (!fs.existsSync(filename)) {\n throw new InformAiError(\n `Missing rule-pack config ${filename}. Run pnpm wp-rules-sync to create explicit owner seeds, then review the diff.`,\n );\n }\n // webpieces-disable no-any-unknown -- registry validation narrows the parsed option bags.\n const entries: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'));\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new InformAiError(\n `${filename} must be an object mapping owned rule IDs to explicit config objects.`,\n );\n }\n return entries as Record<string, ConfigObject>;\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 (error instanceof InformAiError) throw error;\n throw new InformAiError(\n `Cannot parse rule-pack config ${filename}: ${error.message}. Edit this file to restore valid JSON.`,\n { cause: error },\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pack-policy-files.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/pack-policy-files.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,oDAA8B;AAC9B,wDAAkC;AAElC,8DAA4E;AAC5E,iEAA6D;AAC7D,6DAAkF;AAClF,uDAAmD;AACnD,+DAA4E;AAC5E,+DAAiE;AACjE,+DAAgH;AAChH,+CAAgD;AAEhD,kGAAkG;AAClG,MAAa,qBAAqB;IAKjB;IAJJ,OAAO,CAAS;IAEzB,YACI,WAAmB,EACV,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAEvB,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;IAC/B,CAAC;IAED,UAAU;QACN,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,YAAY,CAAC;IAC/F,CAAC;CACJ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AAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC;YAC5F,OAAO,QAAQ,CAAC;YAChB,6GAA6G;QACjH,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,CAAC,CAAC,KAAK,YAAY,8BAAa,CAAC;gBAAE,MAAM,KAAK,CAAC;YACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,6BAAe,CAAC,CAAC;YAClD,MAAM,IAAI,uCAAiB,CACvB,8BAA8B,QAAQ,cAAc,KAAK,CAAC,OAAO,EAAE,EACnE,CAAC,IAAI,kCAAY,CAAC,QAAQ,EAAE,uDAAuD,CAAC,CAAC,EACrF,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CAAC;QACN,CAAC;IACL,CAAC;IAED,qGAAqG;IAC7F,KAAK,CAAC,IAAwB;QAClC,OAAO,MAAM,CAAC,WAAW,CACrB,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAA+B,EAAE,EAAE,CAAC;YAC9D,UAAU,CAAC,EAAE;YACb,eAAe,CAAC,UAAU,CAAC,eAAe,CAAC;SAC9C,CAAC,CACL,CAAC;IACN,CAAC;CACJ,CAAA;AArRY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,eAAe,CAqR3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { RulePackManifest, ConfigObject, RetiredConfigKey, OwnedRuleDefinition } from '@webpieces/rules-sdk';\nimport { InformAiError, RepositoryLayout } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { NodeRulePackModuleLoader, RulePackRegistry } from './rule-pack-registry';\nimport { RepositoryPath } from './repository-path';\nimport { retiredKeyError, RETIRED_SCOPE_RULE } from './retired-config-keys';\nimport { formatConfigErrorsBanner } from './config-error-banner';\nimport { ConfigRepairError, EditFileCure, RepositoryLayoutRepair, RunCommandCure } from './config-repair-error';\nimport { CONFIG_FILENAME } from './config-file';\n\n/** The root declaration identifies an exact package/module and its owner-specific config file. */\nexport class PackPolicyDeclaration {\n readonly package: string;\n\n constructor(\n packageName: string,\n readonly config: string,\n ) {\n this.package = packageName;\n }\n\n moduleName(): string {\n return /\\.(?:cjs|mjs|js)$/.test(this.package) ? this.package : `${this.package}/rule-pack`;\n }\n}\n\nexport class SelectedPolicyPack {\n constructor(\n readonly declaration: PackPolicyDeclaration,\n readonly manifest: RulePackManifest,\n ) {}\n}\n\nexport class PackPolicyFilesResult {\n constructor(\n readonly registry: RulePackRegistry,\n readonly selected: readonly SelectedPolicyPack[],\n readonly values: Record<string, ConfigObject>,\n readonly targetFiles: ReadonlyMap<string, string>,\n ) {}\n}\n\n/**\n * Configuration belongs to explicitly selected owners; loading never supplies recommended seeds.\n *\n * Every problem this class finds is a ConfigRepairError naming the file to edit and the exact entry to\n * paste or delete (#1273). The hooks permit those edits while the config is invalid, so an upgrade that\n * adds a required rule costs the agent one edit of one named file, and no command.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PackPolicyFiles {\n // webpieces-disable no-any-unknown -- root JSON is narrowed before resolving modules or files.\n declarations(raw: unknown, root: string): PackPolicyDeclaration[] {\n const rootFile = path.join(root, CONFIG_FILENAME);\n if (!Array.isArray(raw) || raw.length === 0) {\n throw new ConfigRepairError(`${rootFile}: rulePacks is required.`, [\n new EditFileCure(\n rootFile,\n 'Add \"rulePacks\": [{\"package\":\"<pack>\",\"config\":\".webpieces-config/rules/<pack>.json\"}, ...] with one declaration per selected rule pack; each rule then names the owner file its entry belongs in.',\n ),\n ]);\n }\n const packages = new Set<string>(),\n files = new Set<string>();\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n return raw.map((entry: unknown) => {\n if (\n !entry ||\n typeof entry !== 'object' ||\n Array.isArray(entry) ||\n !('package' in entry) ||\n !('config' in entry) ||\n typeof entry.package !== 'string' ||\n !entry.package ||\n typeof entry.config !== 'string' ||\n !entry.config ||\n Object.keys(entry).some((key: string) => !['package', 'config'].includes(key))\n ) {\n throw new ConfigRepairError(\n `${rootFile}: invalid rulePacks entry ${JSON.stringify(entry)}.`,\n [\n new EditFileCure(\n rootFile,\n 'Give the entry exactly two string fields: {\"package\":\"<pack>\",\"config\":\".webpieces-config/rules/<pack>.json\"}.',\n ),\n ],\n );\n }\n const filename = this.configPath(root, entry.config);\n if (packages.has(entry.package) || files.has(filename)) {\n throw new ConfigRepairError(\n `${rootFile}: duplicate rule-pack declaration or config path: ${entry.package}, ${entry.config}.`,\n [\n new EditFileCure(\n rootFile,\n 'Delete the second rulePacks entry; declare each pack and config once.',\n ),\n ],\n );\n }\n packages.add(entry.package);\n files.add(filename);\n return new PackPolicyDeclaration(entry.package, entry.config);\n });\n }\n\n select(root: string, declarations: readonly PackPolicyDeclaration[]): SelectedPolicyPack[] {\n const loader = new NodeRulePackModuleLoader(root);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- module failures identify the declaration's actual repair file.\n try {\n return declarations.map((declaration: PackPolicyDeclaration) => {\n const manifest = loader.load(declaration.moduleName());\n if (\n declaration.moduleName() === `${declaration.package}/rule-pack` &&\n manifest.packageName !== declaration.package\n ) {\n throw new InformAiError(\n `Declared package ${declaration.package} exports owner ${manifest.packageName}. Declare the actual owning package or an explicit client manifest module.`,\n );\n }\n return new SelectedPolicyPack(declaration, manifest);\n });\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 const rootFile = path.join(root, CONFIG_FILENAME);\n throw new ConfigRepairError(\n `Rule-pack selection in ${rootFile} needs repair: ${error.message}`,\n [\n new EditFileCure(\n rootFile,\n 'Fix the rulePacks entry named above: declare the package that actually owns the pack, or delete the entry.',\n ),\n new RunCommandCure(\n 'pnpm install',\n 'pnpm install — when the declared pack is simply missing from node_modules.',\n ),\n ],\n { cause: error },\n );\n }\n }\n\n resolve(root: string, selected: readonly SelectedPolicyPack[]): PackPolicyFilesResult {\n const registry = this.registry(root, selected);\n const values: Record<string, ConfigObject> = {},\n targetFiles = new Map<string, string>();\n const errors: string[] = [];\n const filesToEdit = new Set<string>();\n for (const pack of selected) {\n const filename = this.configPath(root, pack.declaration.config);\n for (const definition of pack.manifest.ownedRules)\n targetFiles.set(definition.id, filename);\n }\n for (const pack of selected) {\n const filename = this.configPath(root, pack.declaration.config);\n if (!fs.existsSync(filename)) {\n filesToEdit.add(filename);\n errors.push(\n `${filename}: missing rule-pack config for ${pack.manifest.packageName}. Create it with this content (the owner's recommended seeds — review every value):\\n${JSON.stringify(this.seeds(pack), null, 2)}`,\n );\n continue;\n }\n const entries = this.read(filename);\n this.foreignEntries(filename, entries, pack, registry, targetFiles, errors, filesToEdit);\n for (const definition of pack.manifest.ownedRules) {\n if (!Object.hasOwn(entries, definition.id)) {\n filesToEdit.add(filename);\n errors.push(\n `${filename}: missing required entry \"${definition.id}\". Paste this entry into that file (the owner's recommended seed — choose your own values; OFF still states every required field):\\n\"${definition.id}\": ${JSON.stringify(registry.seedFor(definition.id))}`,\n );\n continue;\n }\n const value = entries[definition.id];\n const invalid = registry\n .validateRuleConfig(definition.id, value)\n .map((error: string) => `${filename}: ${error}`);\n if (invalid.length) filesToEdit.add(filename);\n errors.push(...invalid);\n values[definition.id] = value;\n }\n }\n if (errors.length) {\n throw new ConfigRepairError(\n formatConfigErrorsBanner(errors).replace(\n 'THE FIX: edit webpieces.config.json',\n 'THE FIX: edit the declared owner config files named above',\n ) +\n '\\nEditing webpieces.config.json and every file under .webpieces-config/ is ALWAYS allowed, even while the config is invalid. Required settings are never supplied during loading.',\n [...filesToEdit].map((file: string) =>\n new EditFileCure(file, `Edit ${file} and apply every bullet above that names it.`),\n ),\n );\n }\n return new PackPolicyFilesResult(registry, selected, values, targetFiles);\n }\n\n configPath(root: string, relative: string): string {\n const rootFile = path.join(root, CONFIG_FILENAME);\n const fixPath = new EditFileCure(\n rootFile,\n `Change the rulePacks config \"${relative}\" to a distinct repository-relative JSON path such as .webpieces-config/rules/code.json.`,\n );\n if (path.isAbsolute(relative) || !relative.endsWith('.json')) {\n throw new ConfigRepairError(`${rootFile}: invalid pack config path ${relative}.`, [fixPath]);\n }\n let target: string;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- path faults name the declaration that needs repair\n try {\n target = new RepositoryPath(root).resolve(relative);\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 throw new ConfigRepairError(\n `${rootFile}: invalid pack config path ${relative}: ${error.message}`,\n [fixPath],\n { cause: error },\n );\n }\n const normalized = path.relative(fs.realpathSync(root), target);\n if (\n path.isAbsolute(relative) ||\n normalized.startsWith('..') ||\n !normalized.endsWith('.json') ||\n normalized === CONFIG_FILENAME\n ) {\n throw new ConfigRepairError(`${rootFile}: invalid pack config path ${relative}.`, [fixPath]);\n }\n new RepositoryLayoutRepair().run(() => new RepositoryLayout().assertPolicyPath(normalized));\n return target;\n }\n\n read(filename: string): Record<string, ConfigObject> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- malformed pack files name their exact repair path.\n try {\n // webpieces-disable no-any-unknown -- registry validation narrows the parsed option bags.\n const entries: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'));\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new ConfigRepairError(\n `${filename} must be an object mapping owned rule IDs to explicit config objects.`,\n [\n new EditFileCure(\n filename,\n `Rewrite ${filename} as one JSON object: {\"<rule-id>\": {...}, ...}.`,\n ),\n ],\n );\n }\n return entries as Record<string, ConfigObject>;\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 (error instanceof InformAiError) throw error;\n throw new ConfigRepairError(\n `Cannot parse rule-pack config ${filename}: ${error.message}.`,\n [new EditFileCure(filename, `Edit ${filename} to restore valid JSON.`)],\n { cause: error },\n );\n }\n }\n\n // Entries this owner file must not hold: unknown or retired IDs (delete), and another owner's (move).\n // eslint-disable-next-line @typescript-eslint/max-params -- the accumulators of resolve(), passed through once\n private foreignEntries(\n filename: string,\n entries: Record<string, ConfigObject>,\n pack: SelectedPolicyPack,\n registry: RulePackRegistry,\n targetFiles: ReadonlyMap<string, string>,\n errors: string[],\n filesToEdit: Set<string>,\n ): void {\n for (const id of Object.keys(entries)) {\n if (!registry.hasRule(id)) {\n const retired = registry\n .migrations()\n .find(\n (entry: RetiredConfigKey) =>\n entry.scope === RETIRED_SCOPE_RULE && entry.key === id,\n );\n filesToEdit.add(filename);\n errors.push(\n `${filename}: ${retired ? retiredKeyError(retired) : `\"${id}\" has no declared configurable owner. Delete the \"${id}\" entry from this file.`}`,\n );\n } else if (registry.ownerOf(id) !== pack.manifest.packageName) {\n const owner = targetFiles.get(id) ?? '';\n filesToEdit.add(filename);\n filesToEdit.add(owner);\n errors.push(\n `${filename}: \"${id}\" belongs to ${registry.ownerOf(id)}. Delete the \"${id}\" entry here and paste it into ${owner}.`,\n );\n }\n }\n }\n\n // Conflicting manifests (two packs owning one rule) are a SELECTION problem: the declaration is the fix.\n private registry(root: string, selected: readonly SelectedPolicyPack[]): RulePackRegistry {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- converts a manifest conflict into the declaration's structured repair\n try {\n const registry = new RulePackRegistry(\n selected.map((pack: SelectedPolicyPack) => pack.manifest),\n );\n for (const pack of selected)\n registry.recordModuleLocation(pack.manifest.packageName, pack.declaration.moduleName());\n return registry;\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 (!(error instanceof InformAiError)) throw error;\n const rootFile = path.join(root, CONFIG_FILENAME);\n throw new ConfigRepairError(\n `The rule packs declared in ${rootFile} conflict: ${error.message}`,\n [new EditFileCure(rootFile, 'Delete one of the conflicting rulePacks declarations.')],\n { cause: error },\n );\n }\n }\n\n // The exact owner file a missing declaration needs: every owned rule's recommended seed, for review.\n private seeds(pack: SelectedPolicyPack): Record<string, ConfigObject> {\n return Object.fromEntries(\n pack.manifest.ownedRules.map((definition: OwnedRuleDefinition) => [\n definition.id,\n structuredClone(definition.recommendedSeed),\n ]),\n );\n }\n}\n"]}
|
package/src/policy-tracking.js
CHANGED
|
@@ -6,7 +6,7 @@ const fs = tslib_1.__importStar(require("node:fs"));
|
|
|
6
6
|
const path = tslib_1.__importStar(require("node:path"));
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
-
const
|
|
9
|
+
const config_repair_error_1 = require("./config-repair-error");
|
|
10
10
|
/** Git repositories must share policy through their index, including rules switched OFF. */
|
|
11
11
|
class PolicyTracking {
|
|
12
12
|
check(root, declarations) {
|
|
@@ -21,13 +21,17 @@ class PolicyTracking {
|
|
|
21
21
|
if (ignored.status !== 0 && ignored.status !== 1)
|
|
22
22
|
throw new tooling_common_1.InformAiError(`Cannot verify policy ignore status: ${ignored.stderr}. Repair git access, then retry.`);
|
|
23
23
|
if (ignored.stdout.trim())
|
|
24
|
-
throw new
|
|
24
|
+
throw new config_repair_error_1.ConfigRepairError(`Committed Webpieces policy is gitignored:\n${ignored.stdout}Only .webpieces/ belongs in .gitignore; .webpieces-config/ must be tracked.`, [
|
|
25
|
+
new config_repair_error_1.EditFileCure(path.join(root, '.gitignore'), `Delete the .gitignore patterns that match the files listed above.`),
|
|
26
|
+
]);
|
|
25
27
|
const tracked = (0, node_child_process_1.spawnSync)('git', ['--literal-pathspecs', 'ls-files', '--error-unmatch', '--', ...files], {
|
|
26
28
|
cwd: root,
|
|
27
29
|
encoding: 'utf8',
|
|
28
30
|
});
|
|
29
31
|
if (tracked.status !== 0)
|
|
30
|
-
throw new
|
|
32
|
+
throw new config_repair_error_1.ConfigRepairError(`Webpieces policy must be tracked by git: ${tracked.stderr}\nReview the policy files, stage them, and commit them with your change.`, [
|
|
33
|
+
new config_repair_error_1.RunCommandCure(`${tooling_common_1.MIGRATE_DIRS_COMMAND} --stage`, `${tooling_common_1.MIGRATE_DIRS_COMMAND} --stage — stages the declaration and the owner files.`),
|
|
34
|
+
]);
|
|
31
35
|
}
|
|
32
36
|
stage(root, declarations) {
|
|
33
37
|
// `.webpieces/` is the gitignored state directory, so `git add` refuses its paths. Untrack whatever
|
|
@@ -48,11 +52,7 @@ class PolicyTracking {
|
|
|
48
52
|
throw new tooling_common_1.InformAiError(`Could not stage Webpieces policy: ${result.stderr}. Remove policy ignore patterns and verify git access before retrying.`);
|
|
49
53
|
}
|
|
50
54
|
files(root, declarations) {
|
|
51
|
-
const declared =
|
|
52
|
-
...declarations.map((declaration) => declaration.config),
|
|
53
|
-
rule_pack_artifacts_1.RULE_LOCK_FILE,
|
|
54
|
-
rule_pack_artifacts_1.RULE_CATALOG_FILE,
|
|
55
|
-
];
|
|
55
|
+
const declared = declarations.map((declaration) => declaration.config);
|
|
56
56
|
return [
|
|
57
57
|
...new Set(declared.flatMap((filename) => [
|
|
58
58
|
filename,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-tracking.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/policy-tracking.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,2DAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"policy-tracking.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/policy-tracking.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,2DAA+C;AAC/C,8DAAgF;AAEhF,+DAAwF;AAExF,4FAA4F;AAC5F,MAAa,cAAc;IACvB,KAAK,CAAC,IAAY,EAAE,YAA8C;QAC9D,0FAA0F;QAC1F,IAAI,CAAC,EAAE,CAAC,UAAU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';\nimport * as path from 'node:path';\nimport { spawnSync } from 'node:child_process';\nimport { InformAiError, MIGRATE_DIRS_COMMAND } from '@webpieces/tooling-common';\nimport type { PackPolicyDeclaration } from './pack-policy-files';\nimport { ConfigRepairError, EditFileCure, RunCommandCure } from './config-repair-error';\n\n/** Git repositories must share policy through their index, including rules switched OFF. */\nexport class PolicyTracking {\n check(root: string, declarations: readonly PackPolicyDeclaration[]): void {\n // Standalone non-git schema validation is supported; CI and governed checkouts have .git.\n if (!fs.existsSync(path.join(root, '.git'))) return;\n const files = this.files(root, declarations);\n const ignored = spawnSync('git', ['check-ignore', '--no-index', '--', ...files], {\n cwd: root,\n encoding: 'utf8',\n });\n if (ignored.status !== 0 && ignored.status !== 1)\n throw new InformAiError(\n `Cannot verify policy ignore status: ${ignored.stderr}. Repair git access, then retry.`,\n );\n if (ignored.stdout.trim())\n throw new ConfigRepairError(\n `Committed Webpieces policy is gitignored:\\n${ignored.stdout}Only .webpieces/ belongs in .gitignore; .webpieces-config/ must be tracked.`,\n [\n new EditFileCure(\n path.join(root, '.gitignore'),\n `Delete the .gitignore patterns that match the files listed above.`,\n ),\n ],\n );\n const tracked = spawnSync(\n 'git',\n ['--literal-pathspecs', 'ls-files', '--error-unmatch', '--', ...files],\n {\n cwd: root,\n encoding: 'utf8',\n },\n );\n if (tracked.status !== 0)\n throw new ConfigRepairError(\n `Webpieces policy must be tracked by git: ${tracked.stderr}\\nReview the policy files, stage them, and commit them with your change.`,\n [\n new RunCommandCure(\n `${MIGRATE_DIRS_COMMAND} --stage`,\n `${MIGRATE_DIRS_COMMAND} --stage — stages the declaration and the owner files.`,\n ),\n ],\n );\n }\n\n stage(root: string, declarations: readonly PackPolicyDeclaration[]): void {\n // `.webpieces/` is the gitignored state directory, so `git add` refuses its paths. Untrack whatever\n // policy older releases committed there with `rm --cached`, which keeps every file on disk.\n const retired = spawnSync(\n 'git',\n ['rm', '-r', '-q', '--cached', '--ignore-unmatch', '--', '.webpieces'],\n { cwd: root, encoding: 'utf8' },\n );\n if (retired.status !== 0)\n throw new InformAiError(\n `Cannot untrack retired policy paths in .webpieces/: ${retired.stderr}. Verify git access before retrying.`,\n );\n const result = spawnSync(\n 'git',\n [\n '--literal-pathspecs',\n 'add',\n '-A',\n '--',\n 'webpieces.config.json',\n '.gitignore',\n ...this.files(root, declarations),\n ],\n { cwd: root, encoding: 'utf8' },\n );\n if (result.status !== 0)\n throw new InformAiError(\n `Could not stage Webpieces policy: ${result.stderr}. Remove policy ignore patterns and verify git access before retrying.`,\n );\n }\n\n private files(root: string, declarations: readonly PackPolicyDeclaration[]): string[] {\n const declared = declarations.map((declaration) => declaration.config);\n return [\n ...new Set(\n declared.flatMap((filename) => [\n filename,\n path.relative(\n fs.realpathSync(root),\n fs.realpathSync(path.join(root, filename)),\n ),\n ]),\n ),\n ];\n }\n}\n"]}
|
package/src/rule-pack-sync.d.ts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { AtomicFile } from '@webpieces/tooling-common';
|
|
2
2
|
import { ConfigFile } from './config-file';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
/** Explicit file mutation; normal configuration loading never calls this service. */
|
|
3
|
+
import { PackPolicyFiles } from './pack-policy-files';
|
|
4
|
+
/**
|
|
5
|
+
* Writes the owners' recommended seeds into the declared owner files, for review — the installer's and
|
|
6
|
+
* `wp-migrate-dirs`' explicit file mutation. Normal configuration loading never calls this service: a
|
|
7
|
+
* missing entry is a deny naming the file and the entry to paste, not something loading supplies.
|
|
8
|
+
*/
|
|
11
9
|
export declare class RulePackSync {
|
|
12
10
|
private readonly configFile;
|
|
13
11
|
private readonly files;
|
|
14
|
-
private readonly artifacts;
|
|
15
12
|
private readonly atomic;
|
|
16
|
-
constructor(configFile: ConfigFile, files: PackPolicyFiles,
|
|
17
|
-
run(root: string
|
|
18
|
-
private selectedDeclarations;
|
|
19
|
-
private upgradeDocument;
|
|
20
|
-
private legacyEntries;
|
|
13
|
+
constructor(configFile: ConfigFile, files: PackPolicyFiles, atomic: AtomicFile);
|
|
14
|
+
run(root: string): readonly string[];
|
|
21
15
|
private prepare;
|
|
22
16
|
private seedMissing;
|
|
23
|
-
private rootDocument;
|
|
24
17
|
private validateRoot;
|
|
25
18
|
private object;
|
|
26
19
|
}
|