@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.
Files changed (40) hide show
  1. package/package.json +5 -6
  2. package/src/config-file.js +4 -2
  3. package/src/config-file.js.map +1 -1
  4. package/src/config-key-rules.js +1 -1
  5. package/src/config-key-rules.js.map +1 -1
  6. package/src/config-repair-bootstrap-source.d.ts +1 -1
  7. package/src/config-repair-bootstrap-source.js +1 -1
  8. package/src/config-repair-bootstrap-source.js.map +1 -1
  9. package/src/config-repair-error.d.ts +46 -0
  10. package/src/config-repair-error.js +83 -0
  11. package/src/config-repair-error.js.map +1 -0
  12. package/src/config-repair-probe.d.ts +7 -1
  13. package/src/config-repair-probe.js +19 -29
  14. package/src/config-repair-probe.js.map +1 -1
  15. package/src/index.d.ts +2 -2
  16. package/src/index.js +7 -7
  17. package/src/index.js.map +1 -1
  18. package/src/legacy-config-upgrade.d.ts +1 -1
  19. package/src/legacy-config-upgrade.js +6 -6
  20. package/src/legacy-config-upgrade.js.map +1 -1
  21. package/src/load-config.d.ts +1 -3
  22. package/src/load-config.js +10 -10
  23. package/src/load-config.js.map +1 -1
  24. package/src/migrate-dirs-cli.js +1 -3
  25. package/src/migrate-dirs-cli.js.map +1 -1
  26. package/src/pack-policy-files.d.ts +10 -1
  27. package/src/pack-policy-files.js +97 -38
  28. package/src/pack-policy-files.js.map +1 -1
  29. package/src/policy-tracking.js +8 -8
  30. package/src/policy-tracking.js.map +1 -1
  31. package/src/rule-pack-sync.d.ts +8 -15
  32. package/src/rule-pack-sync.js +17 -137
  33. package/src/rule-pack-sync.js.map +1 -1
  34. package/templates/webpieces.guard-matrix.md +4 -5
  35. package/src/rule-pack-artifacts.d.ts +0 -23
  36. package/src/rule-pack-artifacts.js +0 -180
  37. package/src/rule-pack-artifacts.js.map +0 -1
  38. package/src/rules-sync-cli.d.ts +0 -7
  39. package/src/rules-sync-cli.js +0 -48
  40. package/src/rules-sync-cli.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RulePackSync = exports.RulePackSyncOptions = void 0;
3
+ exports.RulePackSync = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("node:fs"));
6
6
  const path = tslib_1.__importStar(require("node:path"));
@@ -9,21 +9,10 @@ const rules_sdk_1 = require("@webpieces/rules-sdk");
9
9
  const tooling_common_1 = require("@webpieces/tooling-common");
10
10
  const config_file_1 = require("./config-file");
11
11
  const pack_policy_files_1 = require("./pack-policy-files");
12
- const rule_pack_artifacts_1 = require("./rule-pack-artifacts");
13
12
  const rule_pack_registry_1 = require("./rule-pack-registry");
14
13
  const config_key_rules_1 = require("./config-key-rules");
15
14
  const commands_section_validators_1 = require("./commands-section-validators");
16
15
  const validate_config_1 = require("./validate-config");
17
- const legacy_config_upgrade_1 = require("./legacy-config-upgrade");
18
- class RulePackSyncOptions {
19
- mode;
20
- declarations;
21
- constructor(mode, declarations) {
22
- this.mode = mode;
23
- this.declarations = declarations;
24
- }
25
- }
26
- exports.RulePackSyncOptions = RulePackSyncOptions;
27
16
  class OwnerFilePlan {
28
17
  filename;
29
18
  entries;
@@ -32,118 +21,40 @@ class OwnerFilePlan {
32
21
  this.entries = entries;
33
22
  }
34
23
  }
35
- /** Explicit file mutation; normal configuration loading never calls this service. */
24
+ /**
25
+ * Writes the owners' recommended seeds into the declared owner files, for review — the installer's and
26
+ * `wp-migrate-dirs`' explicit file mutation. Normal configuration loading never calls this service: a
27
+ * missing entry is a deny naming the file and the entry to paste, not something loading supplies.
28
+ */
36
29
  let RulePackSync = class RulePackSync {
37
30
  configFile;
38
31
  files;
39
- artifacts;
40
32
  atomic;
41
- constructor(configFile, files, artifacts, atomic) {
33
+ constructor(configFile, files, atomic) {
42
34
  this.configFile = configFile;
43
35
  this.files = files;
44
- this.artifacts = artifacts;
45
36
  this.atomic = atomic;
46
37
  }
47
- run(root, options) {
38
+ run(root) {
48
39
  const layoutChanges = new tooling_common_1.RepositoryLayout().migrate(root);
49
40
  const filename = path.join(root, config_file_1.CONFIG_FILENAME);
50
- // webpieces-disable no-any-unknown -- migration reads opaque JSON only at this explicit command boundary
41
+ // webpieces-disable no-any-unknown -- the sync reads opaque JSON only at this explicit command boundary
51
42
  const document = this.configFile.readRawConfig(filename);
52
- const declarations = options.declarations ?? this.selectedDeclarations(document, root, options.mode);
53
- const selected = this.files.select(root, this.files.declarations(declarations, root));
43
+ const selected = this.files.select(root, this.files.declarations(document['rulePacks'], root));
54
44
  const registry = new rule_pack_registry_1.RulePackRegistry(selected.map((pack) => pack.manifest));
55
45
  for (const pack of selected)
56
46
  registry.recordModuleLocation(pack.manifest.packageName, pack.declaration.moduleName());
57
- const upgraded = options.mode === 'upgrade' ? this.upgradeDocument(document, registry) : document;
58
- const legacy = options.mode === 'upgrade'
59
- ? this.legacyEntries(upgraded, registry)
60
- : new Map();
61
- const prepared = this.prepare(root, selected, registry, legacy);
62
- const next = this.rootDocument(upgraded, declarations, options.mode);
63
- this.validateRoot(next, root);
64
- // Validate artifact data and canonical destination paths before changing any owner file.
65
- this.artifacts.render(prepared.resolved);
66
- this.artifacts.paths(root);
47
+ this.validateRoot(document, root);
48
+ const plans = this.prepare(root, selected, registry);
67
49
  const changed = [...layoutChanges];
68
- for (const plan of prepared.plans) {
50
+ for (const plan of plans) {
69
51
  if (this.atomic.writeIfChanged(plan.filename, JSON.stringify(plan.entries, null, 2) + '\n'))
70
52
  changed.push(plan.filename);
71
53
  }
72
- changed.push(...this.artifacts.write(root, prepared.resolved));
73
- // Commit the root declaration last: all referenced files have already been validated and written.
74
- if (this.atomic.writeIfChanged(filename, JSON.stringify(next, null, 2) + '\n'))
75
- changed.push(filename);
76
54
  return changed;
77
55
  }
78
- // webpieces-disable no-any-unknown -- only an explicit upgrade may read the previous root shape
79
- selectedDeclarations(
80
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
81
- document, root, mode) {
82
- if (document['rulePacks'] !== undefined)
83
- return this.files.declarations(document['rulePacks'], root);
84
- if (mode !== 'upgrade')
85
- return this.files.declarations(undefined, root);
86
- const pkg = this.configFile.readRawConfig(path.join(root, 'package.json'));
87
- const metadata = this.object(pkg['webpieces'], 'package.json.webpieces');
88
- const entries = metadata['rulePacks'];
89
- if (!Array.isArray(entries) || !entries.length) {
90
- throw new tooling_common_1.InformAiError('Upgrade requires explicit pack selection. Supply --pack=<package>=.webpieces-config/rules/<owner>.json for every selected pack. Installed dependencies are never inferred as selected packs.');
91
- }
92
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
93
- return entries.map((entry) => {
94
- const declaration = this.object(entry, 'legacy package.json.webpieces.rulePacks entry');
95
- const moduleName = declaration['module'];
96
- if (typeof moduleName !== 'string' || !moduleName.endsWith('/rule-pack')) {
97
- throw new tooling_common_1.InformAiError('Legacy pack modules must end in /rule-pack. Supply explicit --pack=<package-or-module>=<config.json> declarations for other modules.');
98
- }
99
- const packageName = moduleName.slice(0, -'/rule-pack'.length);
100
- return new pack_policy_files_1.PackPolicyDeclaration(packageName, `.webpieces-config/rules/${packageName.split('/').at(-1)}.json`);
101
- });
102
- }
103
- // webpieces-disable no-any-unknown -- inherited settings and untyped directory rules cannot be silently converted into declared owners
104
- upgradeDocument(
105
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
106
- document, registry) {
107
- if (document['extends'] !== undefined)
108
- throw new tooling_common_1.InformAiError('Remove extends after making inherited values explicit. Upgrade cannot infer inherited policy settings.');
109
- const directories = document['rulesDir'];
110
- if (directories !== undefined &&
111
- (!Array.isArray(directories) || directories.length !== 0)) {
112
- throw new tooling_common_1.InformAiError('Replace rulesDir with a declared client rule pack, its owned schemas, and implementation modules before upgrade. Directory implementations cannot supply an inferred schema.');
113
- }
114
- if (!Object.hasOwn(document, 'rules') && !Object.hasOwn(document, 'hookGuards'))
115
- return document;
116
- const prepared = (0, legacy_config_upgrade_1.prepareLegacyUpgrade)(structuredClone(document), registry);
117
- return { ...document, ...prepared.config };
118
- }
119
- // webpieces-disable no-any-unknown -- explicit upgrade gathers settings by canonical owner after applying owner-declared retirements
120
- legacyEntries(
121
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
122
- document, registry) {
123
- if (document['extends'] !== undefined)
124
- throw new tooling_common_1.InformAiError('Remove extends after making inherited values explicit. Upgrade cannot infer inherited policy settings.');
125
- const directories = document['rulesDir'];
126
- if (directories !== undefined &&
127
- (!Array.isArray(directories) || directories.length !== 0)) {
128
- throw new tooling_common_1.InformAiError('Replace rulesDir with a declared client rule pack, its owned schemas, and implementation modules before upgrade. Directory implementations cannot supply an inferred schema.');
129
- }
130
- const entries = new Map();
131
- for (const section of ['rules', 'hookGuards']) {
132
- if (document[section] === undefined)
133
- continue;
134
- const old = this.object(document[section], section);
135
- for (const id of Object.keys(old)) {
136
- if (!registry.hasRule(id))
137
- throw new tooling_common_1.InformAiError(`${section}.${id} has no selected owner. Declare its owner or remove the entry explicitly before upgrading.`);
138
- if (entries.has(id))
139
- throw new tooling_common_1.InformAiError(`${id} appears in both legacy sections. Choose one explicit value before upgrading.`);
140
- entries.set(id, this.object(old[id], `${section}.${id}`));
141
- }
142
- }
143
- return entries;
144
- }
145
- prepare(root, selected, registry, legacy) {
146
- const plans = [], values = {}, targets = new Map();
56
+ prepare(root, selected, registry) {
57
+ const plans = [];
147
58
  const errors = [];
148
59
  for (const pack of selected) {
149
60
  const filename = this.files.configPath(root, pack.declaration.config);
@@ -154,28 +65,17 @@ let RulePackSync = class RulePackSync {
154
65
  }
155
66
  }
156
67
  for (const definition of pack.manifest.ownedRules) {
157
- const previous = Object.hasOwn(entries, definition.id)
158
- ? entries[definition.id]
159
- : legacy.get(definition.id);
160
- if (entries[definition.id] !== undefined &&
161
- legacy.has(definition.id) &&
162
- JSON.stringify(entries[definition.id]) !==
163
- JSON.stringify(legacy.get(definition.id))) {
164
- errors.push(`${filename}: ${definition.id} conflicts with the legacy value. Choose one explicit value before upgrade.`);
165
- }
166
- const value = this.seedMissing(previous, definition);
68
+ const value = this.seedMissing(entries[definition.id], definition);
167
69
  errors.push(...registry
168
70
  .validateRuleConfig(definition.id, value)
169
71
  .map((error) => `${filename}: ${error}`));
170
72
  entries[definition.id] = value;
171
- values[definition.id] = value;
172
- targets.set(definition.id, filename);
173
73
  }
174
74
  plans.push(new OwnerFilePlan(filename, entries));
175
75
  }
176
76
  if (errors.length)
177
77
  throw new tooling_common_1.InformAiError(`Sync made no changes:\n${errors.join('\n')}`);
178
- return new RulePackSyncPlan(plans, new pack_policy_files_1.PackPolicyFilesResult(registry, selected, values, targets));
78
+ return plans;
179
79
  }
180
80
  seedMissing(previous, definition) {
181
81
  const value = previous === undefined
@@ -188,17 +88,6 @@ let RulePackSync = class RulePackSync {
188
88
  }
189
89
  return value;
190
90
  }
191
- // webpieces-disable no-any-unknown -- explicit upgrade removes only the retired sections it actually converted
192
- rootDocument(
193
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
194
- document, declarations, mode) {
195
- const next = { ...document, rulePacks: declarations };
196
- if (mode === 'upgrade')
197
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
198
- for (const key of ['rules', 'hookGuards', 'rulesDir', 'extends'])
199
- delete next[key];
200
- return next;
201
- }
202
91
  // webpieces-disable no-any-unknown -- the same generic-root validators run before any write
203
92
  validateRoot(document, root) {
204
93
  const errors = [
@@ -223,15 +112,6 @@ exports.RulePackSync = RulePackSync = tslib_1.__decorate([
223
112
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
224
113
  tslib_1.__metadata("design:paramtypes", [config_file_1.ConfigFile,
225
114
  pack_policy_files_1.PackPolicyFiles,
226
- rule_pack_artifacts_1.RulePackArtifacts,
227
115
  tooling_common_1.AtomicFile])
228
116
  ], RulePackSync);
229
- class RulePackSyncPlan {
230
- plans;
231
- resolved;
232
- constructor(plans, resolved) {
233
- this.plans = plans;
234
- this.resolved = resolved;
235
- }
236
- }
237
117
  //# sourceMappingURL=rule-pack-sync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rule-pack-sync.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-pack-sync.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,yCAA2D;AAC3D,oDAAyE;AACzE,8DAAwF;AACxF,+CAA4D;AAC5D,2DAK6B;AAC7B,+DAA0D;AAC1D,6DAAwD;AACxD,yDAA0D;AAC1D,+EAAwE;AACxE,uDAAoF;AACpF,mEAA+D;AAE/D,MAAa,mBAAmB;IAEf;IACA;IAFb,YACa,IAAwB,EACxB,YAAqD;QADrD,SAAI,GAAJ,IAAI,CAAoB;QACxB,iBAAY,GAAZ,YAAY,CAAyC;IAC/D,CAAC;CACP;AALD,kDAKC;AAED,MAAM,aAAa;IAEF;IACA;IAFb,YACa,QAAgB,EAChB,OAAqC;QADrC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAA8B;IAC/C,CAAC;CACP;AAED,qFAAqF;AAE9E,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEA;IACA;IACA;IACA;IAJrB,YACqB,UAAsB,EACtB,KAAsB,EACtB,SAA4B,EAC5B,MAAkB;QAHlB,eAAU,GAAV,UAAU,CAAY;QACtB,UAAK,GAAL,KAAK,CAAiB;QACtB,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAY;IACpC,CAAC;IAEJ,GAAG,CAAC,IAAY,EAAE,OAA4B;QAC1C,MAAM,aAAa,GAAG,IAAI,iCAAgB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,6BAAe,CAAC,CAAC;QAClD,yGAAyG;QACzG,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,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ACA;IAFb,YACa,KAA+B,EAC/B,QAA+B;QAD/B,UAAK,GAAL,KAAK,CAA0B;QAC/B,aAAQ,GAAR,QAAQ,CAAuB;IACzC,CAAC;CACP","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ConfigObject, OwnedRuleDefinition } from '@webpieces/rules-sdk';\nimport { AtomicFile, InformAiError, RepositoryLayout } from '@webpieces/tooling-common';\nimport { ConfigFile, CONFIG_FILENAME } from './config-file';\nimport {\n PackPolicyDeclaration,\n PackPolicyFiles,\n PackPolicyFilesResult,\n SelectedPolicyPack,\n} from './pack-policy-files';\nimport { RulePackArtifacts } from './rule-pack-artifacts';\nimport { RulePackRegistry } from './rule-pack-registry';\nimport { validateTopLevelKeys } from './config-key-rules';\nimport { validateCommandsSection } from './commands-section-validators';\nimport { validateExcludePaths, validateMatchRulesSection } from './validate-config';\nimport { prepareLegacyUpgrade } from './legacy-config-upgrade';\n\nexport class RulePackSyncOptions {\n constructor(\n readonly mode: 'sync' | 'upgrade',\n readonly declarations: readonly PackPolicyDeclaration[] | null,\n ) {}\n}\n\nclass OwnerFilePlan {\n constructor(\n readonly filename: string,\n readonly entries: Record<string, ConfigObject>,\n ) {}\n}\n\n/** Explicit file mutation; normal configuration loading never calls this service. */\n@injectable(bindingScopeValues.Singleton)\nexport class RulePackSync {\n constructor(\n private readonly configFile: ConfigFile,\n private readonly files: PackPolicyFiles,\n private readonly artifacts: RulePackArtifacts,\n private readonly atomic: AtomicFile,\n ) {}\n\n run(root: string, options: RulePackSyncOptions): readonly string[] {\n const layoutChanges = new RepositoryLayout().migrate(root);\n const filename = path.join(root, CONFIG_FILENAME);\n // webpieces-disable no-any-unknown -- migration reads opaque JSON only at this explicit command boundary\n const document = this.configFile.readRawConfig(filename) as Record<string, unknown>;\n const declarations =\n options.declarations ?? this.selectedDeclarations(document, root, options.mode);\n const selected = this.files.select(root, this.files.declarations(declarations, root));\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 upgraded =\n options.mode === 'upgrade' ? this.upgradeDocument(document, registry) : document;\n const legacy =\n options.mode === 'upgrade'\n ? this.legacyEntries(upgraded, registry)\n : new Map<string, ConfigObject>();\n const prepared = this.prepare(root, selected, registry, legacy);\n const next = this.rootDocument(upgraded, declarations, options.mode);\n this.validateRoot(next, root);\n // Validate artifact data and canonical destination paths before changing any owner file.\n this.artifacts.render(prepared.resolved);\n this.artifacts.paths(root);\n const changed: string[] = [...layoutChanges];\n for (const plan of prepared.plans) {\n if (\n this.atomic.writeIfChanged(\n plan.filename,\n JSON.stringify(plan.entries, null, 2) + '\\n',\n )\n )\n changed.push(plan.filename);\n }\n changed.push(...this.artifacts.write(root, prepared.resolved));\n // Commit the root declaration last: all referenced files have already been validated and written.\n if (this.atomic.writeIfChanged(filename, JSON.stringify(next, null, 2) + '\\n'))\n changed.push(filename);\n return changed;\n }\n\n // webpieces-disable no-any-unknown -- only an explicit upgrade may read the previous root shape\n private selectedDeclarations(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n document: Record<string, unknown>,\n root: string,\n mode: 'sync' | 'upgrade',\n ): readonly PackPolicyDeclaration[] {\n if (document['rulePacks'] !== undefined)\n return this.files.declarations(document['rulePacks'], root);\n if (mode !== 'upgrade') return this.files.declarations(undefined, root);\n const pkg = this.configFile.readRawConfig(path.join(root, 'package.json')) as Record<\n string,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n unknown\n >;\n const metadata = this.object(pkg['webpieces'], 'package.json.webpieces');\n const entries = metadata['rulePacks'];\n if (!Array.isArray(entries) || !entries.length) {\n throw new InformAiError(\n 'Upgrade requires explicit pack selection. Supply --pack=<package>=.webpieces-config/rules/<owner>.json for every selected pack. Installed dependencies are never inferred as selected packs.',\n );\n }\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n return entries.map((entry: unknown) => {\n const declaration = this.object(entry, 'legacy package.json.webpieces.rulePacks entry');\n const moduleName = declaration['module'];\n if (typeof moduleName !== 'string' || !moduleName.endsWith('/rule-pack')) {\n throw new InformAiError(\n 'Legacy pack modules must end in /rule-pack. Supply explicit --pack=<package-or-module>=<config.json> declarations for other modules.',\n );\n }\n const packageName = moduleName.slice(0, -'/rule-pack'.length);\n return new PackPolicyDeclaration(\n packageName,\n `.webpieces-config/rules/${packageName.split('/').at(-1)}.json`,\n );\n });\n }\n\n // webpieces-disable no-any-unknown -- inherited settings and untyped directory rules cannot be silently converted into declared owners\n private upgradeDocument(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n document: Record<string, unknown>,\n registry: RulePackRegistry,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n ): Record<string, unknown> {\n if (document['extends'] !== undefined)\n throw new InformAiError(\n 'Remove extends after making inherited values explicit. Upgrade cannot infer inherited policy settings.',\n );\n const directories = document['rulesDir'];\n if (\n directories !== undefined &&\n (!Array.isArray(directories) || directories.length !== 0)\n ) {\n throw new InformAiError(\n 'Replace rulesDir with a declared client rule pack, its owned schemas, and implementation modules before upgrade. Directory implementations cannot supply an inferred schema.',\n );\n }\n if (!Object.hasOwn(document, 'rules') && !Object.hasOwn(document, 'hookGuards'))\n return document;\n const prepared = prepareLegacyUpgrade(structuredClone(document), registry);\n return { ...document, ...prepared.config };\n }\n\n // webpieces-disable no-any-unknown -- explicit upgrade gathers settings by canonical owner after applying owner-declared retirements\n private legacyEntries(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n document: Record<string, unknown>,\n registry: RulePackRegistry,\n ): Map<string, ConfigObject> {\n if (document['extends'] !== undefined)\n throw new InformAiError(\n 'Remove extends after making inherited values explicit. Upgrade cannot infer inherited policy settings.',\n );\n const directories = document['rulesDir'];\n if (\n directories !== undefined &&\n (!Array.isArray(directories) || directories.length !== 0)\n ) {\n throw new InformAiError(\n 'Replace rulesDir with a declared client rule pack, its owned schemas, and implementation modules before upgrade. Directory implementations cannot supply an inferred schema.',\n );\n }\n const entries = new Map<string, ConfigObject>();\n for (const section of ['rules', 'hookGuards']) {\n if (document[section] === undefined) continue;\n const old = this.object(document[section], section);\n for (const id of Object.keys(old)) {\n if (!registry.hasRule(id))\n throw new InformAiError(\n `${section}.${id} has no selected owner. Declare its owner or remove the entry explicitly before upgrading.`,\n );\n if (entries.has(id))\n throw new InformAiError(\n `${id} appears in both legacy sections. Choose one explicit value before upgrading.`,\n );\n entries.set(id, this.object(old[id], `${section}.${id}`) as ConfigObject);\n }\n }\n return entries;\n }\n\n private prepare(\n root: string,\n selected: readonly SelectedPolicyPack[],\n registry: RulePackRegistry,\n legacy: ReadonlyMap<string, ConfigObject>,\n ): RulePackSyncPlan {\n const plans: OwnerFilePlan[] = [],\n values: Record<string, ConfigObject> = {},\n targets = new Map<string, string>();\n const errors: string[] = [];\n for (const pack of selected) {\n const filename = this.files.configPath(root, pack.declaration.config);\n const entries = fs.existsSync(filename) ? this.files.read(filename) : {};\n for (const id of Object.keys(entries)) {\n if (!registry.hasRule(id) || registry.ownerOf(id) !== pack.manifest.packageName) {\n errors.push(\n `${filename}: ${id} has another owner or is unknown. Move or remove it explicitly before sync.`,\n );\n }\n }\n for (const definition of pack.manifest.ownedRules) {\n const previous = Object.hasOwn(entries, definition.id)\n ? entries[definition.id]\n : legacy.get(definition.id);\n if (\n entries[definition.id] !== undefined &&\n legacy.has(definition.id) &&\n JSON.stringify(entries[definition.id]) !==\n JSON.stringify(legacy.get(definition.id))\n ) {\n errors.push(\n `${filename}: ${definition.id} conflicts with the legacy value. Choose one explicit value before upgrade.`,\n );\n }\n const value = this.seedMissing(previous, definition);\n errors.push(\n ...registry\n .validateRuleConfig(definition.id, value)\n .map((error: string) => `${filename}: ${error}`),\n );\n entries[definition.id] = value;\n values[definition.id] = value;\n targets.set(definition.id, filename);\n }\n plans.push(new OwnerFilePlan(filename, entries));\n }\n if (errors.length) throw new InformAiError(`Sync made no changes:\\n${errors.join('\\n')}`);\n return new RulePackSyncPlan(\n plans,\n new PackPolicyFilesResult(registry, selected, values, targets),\n );\n }\n\n private seedMissing(\n previous: ConfigObject | undefined,\n definition: OwnedRuleDefinition,\n ): ConfigObject {\n const value =\n previous === undefined\n ? structuredClone(definition.recommendedSeed)\n : Object.assign(new ConfigObject(), this.object(previous, definition.id));\n for (const field of Object.keys(definition.schema)) {\n if (!definition.schema[field].optional && !Object.hasOwn(value, field)) {\n value[field] = structuredClone(definition.recommendedSeed[field]);\n }\n }\n return value;\n }\n\n // webpieces-disable no-any-unknown -- explicit upgrade removes only the retired sections it actually converted\n private rootDocument(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n document: Record<string, unknown>,\n declarations: readonly PackPolicyDeclaration[],\n mode: 'sync' | 'upgrade',\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n ): Record<string, unknown> {\n const next = { ...document, rulePacks: declarations };\n if (mode === 'upgrade')\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n for (const key of ['rules', 'hookGuards', 'rulesDir', 'extends'])\n delete (next as Record<string, unknown>)[key];\n return next;\n }\n\n // webpieces-disable no-any-unknown -- the same generic-root validators run before any write\n private validateRoot(document: Record<string, unknown>, root: string): void {\n const errors = [\n ...validateTopLevelKeys(document),\n ...validateCommandsSection(document['commands'], document['pr-gate'], root),\n ...validateExcludePaths(document['excludePaths']),\n ...validateMatchRulesSection(document['match-rules']),\n ];\n if (errors.length) throw new InformAiError(`Sync made no changes:\\n${errors.join('\\n')}`);\n }\n\n // webpieces-disable no-any-unknown -- JSON object narrowing preserves explicit values for subsequent schema validation\n private object(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value))\n throw new InformAiError(`${label} must be a JSON object. Repair it before sync.`);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n return value as Record<string, unknown>;\n }\n}\n\nclass RulePackSyncPlan {\n constructor(\n readonly plans: readonly OwnerFilePlan[],\n readonly resolved: PackPolicyFilesResult,\n ) {}\n}\n"]}
1
+ {"version":3,"file":"rule-pack-sync.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-pack-sync.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,yCAA2D;AAC3D,oDAAyE;AACzE,8DAAwF;AACxF,+CAA4D;AAC5D,2DAA0E;AAC1E,6DAAwD;AACxD,yDAA0D;AAC1D,+EAAwE;AACxE,uDAAoF;AAEpF,MAAM,aAAa;IAEF;IACA;IAFb,YACa,QAAgB,EAChB,OAAqC;QADrC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAA8B;IAC/C,CAAC;CACP;AAED;;;;GAIG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEA;IACA;IACA;IAHrB,YACqB,UAAsB,EACtB,KAAsB,EACtB,MAAkB;QAFlB,eAAU,GAAV,UAAU,CAAY;QACtB,UAAK,GAAL,KAAK,CAAiB;QACtB,WAAM,GAAN,MAAM,CAAY;IACpC,CAAC;IAEJ,GAAG,CAAC,IAAY;QACZ,MAAM,aAAa,GAAG,IAAI,iCAAgB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,6BAAe,CAAC,CAAC;QAClD,wGAAwG;QACxG,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAA4B,CAAC;QACpF,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAC/F,MAAM,QAAQ,GAAG,I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,CAAC;IAC5C,CAAC;CACJ,CAAA;AAnGY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGJ,wBAAU;QACf,mCAAe;QACd,2BAAU;GAJ9B,YAAY,CAmGxB","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ConfigObject, OwnedRuleDefinition } from '@webpieces/rules-sdk';\nimport { AtomicFile, InformAiError, RepositoryLayout } from '@webpieces/tooling-common';\nimport { ConfigFile, CONFIG_FILENAME } from './config-file';\nimport { PackPolicyFiles, SelectedPolicyPack } from './pack-policy-files';\nimport { RulePackRegistry } from './rule-pack-registry';\nimport { validateTopLevelKeys } from './config-key-rules';\nimport { validateCommandsSection } from './commands-section-validators';\nimport { validateExcludePaths, validateMatchRulesSection } from './validate-config';\n\nclass OwnerFilePlan {\n constructor(\n readonly filename: string,\n readonly entries: Record<string, ConfigObject>,\n ) {}\n}\n\n/**\n * Writes the owners' recommended seeds into the declared owner files, for review — the installer's and\n * `wp-migrate-dirs`' explicit file mutation. Normal configuration loading never calls this service: a\n * missing entry is a deny naming the file and the entry to paste, not something loading supplies.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class RulePackSync {\n constructor(\n private readonly configFile: ConfigFile,\n private readonly files: PackPolicyFiles,\n private readonly atomic: AtomicFile,\n ) {}\n\n run(root: string): readonly string[] {\n const layoutChanges = new RepositoryLayout().migrate(root);\n const filename = path.join(root, CONFIG_FILENAME);\n // webpieces-disable no-any-unknown -- the sync reads opaque JSON only at this explicit command boundary\n const document = this.configFile.readRawConfig(filename) as Record<string, unknown>;\n const selected = this.files.select(root, this.files.declarations(document['rulePacks'], root));\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 this.validateRoot(document, root);\n const plans = this.prepare(root, selected, registry);\n const changed: string[] = [...layoutChanges];\n for (const plan of plans) {\n if (\n this.atomic.writeIfChanged(\n plan.filename,\n JSON.stringify(plan.entries, null, 2) + '\\n',\n )\n )\n changed.push(plan.filename);\n }\n return changed;\n }\n\n private prepare(\n root: string,\n selected: readonly SelectedPolicyPack[],\n registry: RulePackRegistry,\n ): readonly OwnerFilePlan[] {\n const plans: OwnerFilePlan[] = [];\n const errors: string[] = [];\n for (const pack of selected) {\n const filename = this.files.configPath(root, pack.declaration.config);\n const entries = fs.existsSync(filename) ? this.files.read(filename) : {};\n for (const id of Object.keys(entries)) {\n if (!registry.hasRule(id) || registry.ownerOf(id) !== pack.manifest.packageName) {\n errors.push(\n `${filename}: ${id} has another owner or is unknown. Move or remove it explicitly before sync.`,\n );\n }\n }\n for (const definition of pack.manifest.ownedRules) {\n const value = this.seedMissing(entries[definition.id], definition);\n errors.push(\n ...registry\n .validateRuleConfig(definition.id, value)\n .map((error: string) => `${filename}: ${error}`),\n );\n entries[definition.id] = value;\n }\n plans.push(new OwnerFilePlan(filename, entries));\n }\n if (errors.length) throw new InformAiError(`Sync made no changes:\\n${errors.join('\\n')}`);\n return plans;\n }\n\n private seedMissing(\n previous: ConfigObject | undefined,\n definition: OwnedRuleDefinition,\n ): ConfigObject {\n const value =\n previous === undefined\n ? structuredClone(definition.recommendedSeed)\n : Object.assign(new ConfigObject(), this.object(previous, definition.id));\n for (const field of Object.keys(definition.schema)) {\n if (!definition.schema[field].optional && !Object.hasOwn(value, field)) {\n value[field] = structuredClone(definition.recommendedSeed[field]);\n }\n }\n return value;\n }\n\n // webpieces-disable no-any-unknown -- the same generic-root validators run before any write\n private validateRoot(document: Record<string, unknown>, root: string): void {\n const errors = [\n ...validateTopLevelKeys(document),\n ...validateCommandsSection(document['commands'], document['pr-gate'], root),\n ...validateExcludePaths(document['excludePaths']),\n ...validateMatchRulesSection(document['match-rules']),\n ];\n if (errors.length) throw new InformAiError(`Sync made no changes:\\n${errors.join('\\n')}`);\n }\n\n // webpieces-disable no-any-unknown -- JSON object narrowing preserves explicit values for subsequent schema validation\n private object(value: unknown, label: string): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value))\n throw new InformAiError(`${label} must be a JSON object. Repair it before sync.`);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n return value as Record<string, unknown>;\n }\n}\n"]}
@@ -105,11 +105,10 @@ that denied `rm -rf node_modules && pnpm install` while allowing a bare `pnpm in
105
105
  | 10 | cp node_modules/@webpieces/agent-workflow-rules/templates/ai-hook.sh .claude/webpieces/ai-hook.sh | ALLOW |
106
106
  | 11 | pnpm wp-prune-unknown-config | ALLOW |
107
107
  | 12 | pnpm wp-migrate-dirs | ALLOW |
108
- | 13 | pnpm wp-rules-sync — explicit owner seeds and lock/catalog repair | ALLOW |
109
- | 14 | pnpm exec wp-install-ai-hooks (flags allowed, e.g. --target=project) | ALLOW |
110
- | 15 | pnpm add -D @webpieces/agent-workflow-rules (an @version and extra flags allowed) | ALLOW |
111
- | 16 | read-only orientation: pwd, git status/log/diff/show/branch/rev-parse, git worktree list | ALLOW |
112
- | 17 | CODEX ONLY - a read-shaped Bash command (the harness has no Read tool): cat, head, tail, less, more, bat, or sed -n '<range>p' | PASS |
108
+ | 13 | pnpm exec wp-install-ai-hooks (flags allowed, e.g. --target=project) | ALLOW |
109
+ | 14 | pnpm add -D @webpieces/agent-workflow-rules (an @version and extra flags allowed) | ALLOW |
110
+ | 15 | read-only orientation: pwd, git status/log/diff/show/branch/rev-parse, git worktree list | ALLOW |
111
+ | 16 | CODEX ONLY - a read-shaped Bash command (the harness has no Read tool): cat, head, tail, less, more, bat, or sed -n '<range>p' | PASS |
113
112
 
114
113
  - **PASS** — L0 has no objection; the call falls THROUGH so the downstream guards still judge it.
115
114
  - **ALLOW** — terminal; bypasses everything, because a cure must stay reachable even when a
@@ -1,23 +0,0 @@
1
- import { AtomicFile } from '@webpieces/tooling-common';
2
- import { PackPolicyFilesResult } from './pack-policy-files';
3
- export declare const RULE_LOCK_FILE = ".webpieces-config/rules.lock.json";
4
- export declare const RULE_CATALOG_FILE = ".webpieces-config/rules-catalog.md";
5
- export declare class RuleArtifactContents {
6
- readonly lock: string;
7
- readonly catalog: string;
8
- constructor(lock: string, catalog: string);
9
- }
10
- /** One resolved owner/contributor registry produces both deterministic committed artifacts. */
11
- export declare class RulePackArtifacts {
12
- private readonly atomic;
13
- constructor(atomic: AtomicFile);
14
- paths(root: string): readonly string[];
15
- render(resolved: PackPolicyFilesResult): RuleArtifactContents;
16
- check(root: string, resolved: PackPolicyFilesResult): void;
17
- write(root: string, resolved: PackPolicyFilesResult): readonly string[];
18
- private policyRow;
19
- private cell;
20
- private digest;
21
- private stable;
22
- private canonical;
23
- }
@@ -1,180 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RulePackArtifacts = exports.RuleArtifactContents = exports.RULE_CATALOG_FILE = exports.RULE_LOCK_FILE = void 0;
4
- const tslib_1 = require("tslib");
5
- const inversify_1 = require("inversify");
6
- const fs = tslib_1.__importStar(require("node:fs"));
7
- const repository_path_1 = require("./repository-path");
8
- const node_crypto_1 = require("node:crypto");
9
- const tooling_common_1 = require("@webpieces/tooling-common");
10
- exports.RULE_LOCK_FILE = '.webpieces-config/rules.lock.json';
11
- exports.RULE_CATALOG_FILE = '.webpieces-config/rules-catalog.md';
12
- class LockedOwnedRule {
13
- id;
14
- schemaApiVersion;
15
- constructor(id, schemaApiVersion) {
16
- this.id = id;
17
- this.schemaApiVersion = schemaApiVersion;
18
- }
19
- }
20
- class LockedRulePack {
21
- manifestDigest;
22
- package;
23
- config;
24
- packageName;
25
- packageVersion;
26
- manifestApiVersion;
27
- ownedRules;
28
- contributions;
29
- safeguards;
30
- constructor(pack, manifestDigest) {
31
- this.manifestDigest = manifestDigest;
32
- this.package = pack.declaration.package;
33
- this.config = pack.declaration.config;
34
- this.packageName = pack.manifest.packageName;
35
- this.packageVersion = pack.manifest.packageVersion;
36
- this.manifestApiVersion = pack.manifest.apiVersion;
37
- this.ownedRules = pack.manifest.ownedRules.map((definition) => new LockedOwnedRule(definition.id, definition.schemaApiVersion));
38
- this.contributions = pack.manifest.contributions;
39
- this.safeguards = pack.manifest.safeguards;
40
- }
41
- }
42
- class RuleLock {
43
- packs;
44
- schemaVersion = 1;
45
- constructor(packs) {
46
- this.packs = packs;
47
- }
48
- }
49
- class RuleArtifactContents {
50
- lock;
51
- catalog;
52
- constructor(lock, catalog) {
53
- this.lock = lock;
54
- this.catalog = catalog;
55
- }
56
- }
57
- exports.RuleArtifactContents = RuleArtifactContents;
58
- /** One resolved owner/contributor registry produces both deterministic committed artifacts. */
59
- let RulePackArtifacts = class RulePackArtifacts {
60
- atomic;
61
- constructor(atomic) {
62
- this.atomic = atomic;
63
- }
64
- paths(root) {
65
- const repository = new repository_path_1.RepositoryPath(root);
66
- return [repository.resolve(exports.RULE_LOCK_FILE), repository.resolve(exports.RULE_CATALOG_FILE)];
67
- }
68
- render(resolved) {
69
- const selected = [...resolved.selected].sort((a, b) => a.manifest.packageName < b.manifest.packageName
70
- ? -1
71
- : a.manifest.packageName > b.manifest.packageName
72
- ? 1
73
- : 0);
74
- const locks = selected.map((pack) => new LockedRulePack(pack, this.digest(pack.manifest)));
75
- const rows = [];
76
- for (const pack of selected) {
77
- for (const definition of pack.manifest.ownedRules) {
78
- rows.push(this.policyRow(pack, definition, resolved.values[definition.id], selected));
79
- }
80
- for (const safeguard of pack.manifest.safeguards) {
81
- rows.push(`| ${this.cell(safeguard.id)} | ${this.cell(pack.manifest.packageName)} | ${safeguard.activation} safeguard | — | ${this.cell(safeguard.description)} | Owner safety invariant |`);
82
- }
83
- }
84
- const catalog = [
85
- '# Declared rule catalog',
86
- '',
87
- 'Generated by `pnpm wp-rules-sync` from the selected installed manifests and explicit owner config files.',
88
- 'Configurable policies require every required setting even when mode is `OFF`. Fixed safeguards have no config switch.',
89
- '',
90
- '| Policy | Owner | Status / contributors | Config file | Description | Remediation |',
91
- '| --- | --- | --- | --- | --- | --- |',
92
- ...rows,
93
- '',
94
- ].join('\n');
95
- return new RuleArtifactContents(this.stable(new RuleLock(locks)), catalog);
96
- }
97
- check(root, resolved) {
98
- const contents = this.render(resolved);
99
- const errors = [];
100
- for (const artifact of [
101
- [exports.RULE_LOCK_FILE, contents.lock],
102
- [exports.RULE_CATALOG_FILE, contents.catalog],
103
- ]) {
104
- const filename = new repository_path_1.RepositoryPath(root).resolve(artifact[0]);
105
- if (!fs.existsSync(filename))
106
- errors.push(`Missing ${filename}.`);
107
- else if (fs.readFileSync(filename, 'utf8') !== artifact[1]) {
108
- errors.push(`${filename} disagrees with the root declaration, installed manifests, or explicit owner config.`);
109
- }
110
- }
111
- if (errors.length) {
112
- throw new tooling_common_1.InformAiError(`Rule artifacts need repair:\n${errors.map((error) => `• ${error}`).join('\n')}\nRun pnpm wp-rules-sync, review the generated diff, and commit the lock and catalog.`);
113
- }
114
- }
115
- write(root, resolved) {
116
- const contents = this.render(resolved), changed = [];
117
- for (const artifact of [
118
- [exports.RULE_LOCK_FILE, contents.lock],
119
- [exports.RULE_CATALOG_FILE, contents.catalog],
120
- ]) {
121
- const filename = new repository_path_1.RepositoryPath(root).resolve(artifact[0]);
122
- if (this.atomic.writeIfChanged(filename, artifact[1]))
123
- changed.push(filename);
124
- }
125
- return changed;
126
- }
127
- policyRow(pack, definition, config, selected) {
128
- const contributors = selected.flatMap((provider) => provider.manifest.contributions
129
- .filter((contribution) => contribution.ruleId === definition.id)
130
- .map((contribution) => `${provider.manifest.packageName}:${contribution.executionKind}`));
131
- const status = `${String(config['mode'])}; ${contributors.join(', ')}`;
132
- const remediation = definition.help.remediation.replaceAll('{configFile}', pack.declaration.config);
133
- return [
134
- definition.id,
135
- pack.manifest.packageName,
136
- status,
137
- pack.declaration.config,
138
- definition.help.description,
139
- remediation,
140
- ]
141
- .map((text) => this.cell(text))
142
- .join(' | ')
143
- .replace(/^/, '| ')
144
- .concat(' |');
145
- }
146
- cell(value) {
147
- return value.replaceAll('|', '\\|').replaceAll('\n', ' ');
148
- }
149
- // webpieces-disable no-any-unknown -- canonical serialization accepts only the manifest's data boundary.
150
- digest(value) {
151
- return (0, node_crypto_1.createHash)('sha256').update(this.stable(value)).digest('hex');
152
- }
153
- // webpieces-disable no-any-unknown -- JSON keys are sorted recursively; functions must stay in runtime modules.
154
- stable(value) {
155
- return JSON.stringify(this.canonical(value), null, 2) + '\n';
156
- }
157
- // webpieces-disable no-any-unknown -- recursively narrow arbitrary manifest data before serialization.
158
- canonical(value) {
159
- if (value === null || ['string', 'boolean', 'number'].includes(typeof value))
160
- return value;
161
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
162
- if (Array.isArray(value))
163
- return value.map((entry) => this.canonical(entry));
164
- if (typeof value !== 'object') {
165
- throw new tooling_common_1.InformAiError('Rule manifests must contain only serializable data. Keep executable functions in the declared implementation modules.');
166
- }
167
- // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
168
- const record = value;
169
- return Object.fromEntries(Object.keys(record)
170
- .sort()
171
- .filter((key) => record[key] !== undefined)
172
- .map((key) => [key, this.canonical(record[key])]));
173
- }
174
- };
175
- exports.RulePackArtifacts = RulePackArtifacts;
176
- exports.RulePackArtifacts = RulePackArtifacts = tslib_1.__decorate([
177
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
178
- tslib_1.__metadata("design:paramtypes", [tooling_common_1.AtomicFile])
179
- ], RulePackArtifacts);
180
- //# sourceMappingURL=rule-pack-artifacts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-pack-artifacts.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-pack-artifacts.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,oDAA8B;AAC9B,uDAAmD;AACnD,6CAAyC;AAOzC,8DAAsE;AAGzD,QAAA,cAAc,GAAG,mCAAmC,CAAC;AACrD,QAAA,iBAAiB,GAAG,oCAA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s from 'node:fs';\nimport { RepositoryPath } from './repository-path';\nimport { createHash } from 'node:crypto';\nimport {\n ConfigObject,\n OwnedRuleDefinition,\n RuleContribution,\n SafeguardDefinition,\n} from '@webpieces/rules-sdk';\nimport { AtomicFile, InformAiError } from '@webpieces/tooling-common';\nimport { PackPolicyFilesResult, SelectedPolicyPack } from './pack-policy-files';\n\nexport const RULE_LOCK_FILE = '.webpieces-config/rules.lock.json';\nexport const RULE_CATALOG_FILE = '.webpieces-config/rules-catalog.md';\n\nclass LockedOwnedRule {\n constructor(\n readonly id: string,\n readonly schemaApiVersion: number,\n ) {}\n}\n\nclass LockedRulePack {\n readonly package: string;\n readonly config: string;\n readonly packageName: string;\n readonly packageVersion: string;\n readonly manifestApiVersion: number;\n readonly ownedRules: readonly LockedOwnedRule[];\n readonly contributions: readonly RuleContribution[];\n readonly safeguards: readonly SafeguardDefinition[];\n\n constructor(\n pack: SelectedPolicyPack,\n readonly manifestDigest: string,\n ) {\n this.package = pack.declaration.package;\n this.config = pack.declaration.config;\n this.packageName = pack.manifest.packageName;\n this.packageVersion = pack.manifest.packageVersion;\n this.manifestApiVersion = pack.manifest.apiVersion;\n this.ownedRules = pack.manifest.ownedRules.map(\n (definition: OwnedRuleDefinition) =>\n new LockedOwnedRule(definition.id, definition.schemaApiVersion),\n );\n this.contributions = pack.manifest.contributions;\n this.safeguards = pack.manifest.safeguards;\n }\n}\n\nclass RuleLock {\n readonly schemaVersion = 1;\n constructor(readonly packs: readonly LockedRulePack[]) {}\n}\n\nexport class RuleArtifactContents {\n constructor(\n readonly lock: string,\n readonly catalog: string,\n ) {}\n}\n\n/** One resolved owner/contributor registry produces both deterministic committed artifacts. */\n@injectable(bindingScopeValues.Singleton)\nexport class RulePackArtifacts {\n constructor(private readonly atomic: AtomicFile) {}\n\n paths(root: string): readonly string[] {\n const repository = new RepositoryPath(root);\n return [repository.resolve(RULE_LOCK_FILE), repository.resolve(RULE_CATALOG_FILE)];\n }\n\n render(resolved: PackPolicyFilesResult): RuleArtifactContents {\n const selected = [...resolved.selected].sort(\n (a: SelectedPolicyPack, b: SelectedPolicyPack) =>\n a.manifest.packageName < b.manifest.packageName\n ? -1\n : a.manifest.packageName > b.manifest.packageName\n ? 1\n : 0,\n );\n const locks = selected.map(\n (pack: SelectedPolicyPack) => new LockedRulePack(pack, this.digest(pack.manifest)),\n );\n const rows: string[] = [];\n for (const pack of selected) {\n for (const definition of pack.manifest.ownedRules) {\n rows.push(\n this.policyRow(pack, definition, resolved.values[definition.id], selected),\n );\n }\n for (const safeguard of pack.manifest.safeguards) {\n rows.push(\n `| ${this.cell(safeguard.id)} | ${this.cell(pack.manifest.packageName)} | ${safeguard.activation} safeguard | — | ${this.cell(safeguard.description)} | Owner safety invariant |`,\n );\n }\n }\n const catalog = [\n '# Declared rule catalog',\n '',\n 'Generated by `pnpm wp-rules-sync` from the selected installed manifests and explicit owner config files.',\n 'Configurable policies require every required setting even when mode is `OFF`. Fixed safeguards have no config switch.',\n '',\n '| Policy | Owner | Status / contributors | Config file | Description | Remediation |',\n '| --- | --- | --- | --- | --- | --- |',\n ...rows,\n '',\n ].join('\\n');\n return new RuleArtifactContents(this.stable(new RuleLock(locks)), catalog);\n }\n\n check(root: string, resolved: PackPolicyFilesResult): void {\n const contents = this.render(resolved);\n const errors: string[] = [];\n for (const artifact of [\n [RULE_LOCK_FILE, contents.lock],\n [RULE_CATALOG_FILE, contents.catalog],\n ]) {\n const filename = new RepositoryPath(root).resolve(artifact[0]);\n if (!fs.existsSync(filename)) errors.push(`Missing ${filename}.`);\n else if (fs.readFileSync(filename, 'utf8') !== artifact[1]) {\n errors.push(\n `${filename} disagrees with the root declaration, installed manifests, or explicit owner config.`,\n );\n }\n }\n if (errors.length) {\n throw new InformAiError(\n `Rule artifacts need repair:\\n${errors.map((error: string) => `• ${error}`).join('\\n')}\\nRun pnpm wp-rules-sync, review the generated diff, and commit the lock and catalog.`,\n );\n }\n }\n\n write(root: string, resolved: PackPolicyFilesResult): readonly string[] {\n const contents = this.render(resolved),\n changed: string[] = [];\n for (const artifact of [\n [RULE_LOCK_FILE, contents.lock],\n [RULE_CATALOG_FILE, contents.catalog],\n ]) {\n const filename = new RepositoryPath(root).resolve(artifact[0]);\n if (this.atomic.writeIfChanged(filename, artifact[1])) changed.push(filename);\n }\n return changed;\n }\n\n private policyRow(\n pack: SelectedPolicyPack,\n definition: OwnedRuleDefinition,\n config: ConfigObject,\n selected: readonly SelectedPolicyPack[],\n ): string {\n const contributors = selected.flatMap((provider: SelectedPolicyPack) =>\n provider.manifest.contributions\n .filter((contribution: RuleContribution) => contribution.ruleId === definition.id)\n .map(\n (contribution: RuleContribution) =>\n `${provider.manifest.packageName}:${contribution.executionKind}`,\n ),\n );\n const status = `${String(config['mode'])}; ${contributors.join(', ')}`;\n const remediation = definition.help.remediation.replaceAll(\n '{configFile}',\n pack.declaration.config,\n );\n return [\n definition.id,\n pack.manifest.packageName,\n status,\n pack.declaration.config,\n definition.help.description,\n remediation,\n ]\n .map((text: string) => this.cell(text))\n .join(' | ')\n .replace(/^/, '| ')\n .concat(' |');\n }\n\n private cell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ');\n }\n\n // webpieces-disable no-any-unknown -- canonical serialization accepts only the manifest's data boundary.\n private digest(value: unknown): string {\n return createHash('sha256').update(this.stable(value)).digest('hex');\n }\n\n // webpieces-disable no-any-unknown -- JSON keys are sorted recursively; functions must stay in runtime modules.\n private stable(value: unknown): string {\n return JSON.stringify(this.canonical(value), null, 2) + '\\n';\n }\n\n // webpieces-disable no-any-unknown -- recursively narrow arbitrary manifest data before serialization.\n private canonical(value: unknown): unknown {\n if (value === null || ['string', 'boolean', 'number'].includes(typeof value)) return value;\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n if (Array.isArray(value)) return value.map((entry: unknown) => this.canonical(entry));\n if (typeof value !== 'object') {\n throw new InformAiError(\n 'Rule manifests must contain only serializable data. Keep executable functions in the declared implementation modules.',\n );\n }\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n const record = value as Record<string, unknown>;\n return Object.fromEntries(\n Object.keys(record)\n .sort()\n .filter((key: string) => record[key] !== undefined)\n .map((key: string) => [key, this.canonical(record[key])]),\n );\n }\n}\n"]}
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import { RulePackSyncOptions } from './rule-pack-sync';
3
- /** CLI parsing does not validate the live config: this command repairs missing required settings. */
4
- export declare class RulesSyncCli {
5
- parse(args: readonly string[]): RulePackSyncOptions;
6
- main(): Promise<void>;
7
- }
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RulesSyncCli = void 0;
5
- const tooling_common_1 = require("@webpieces/tooling-common");
6
- const config_file_1 = require("./config-file");
7
- const pack_policy_files_1 = require("./pack-policy-files");
8
- const rule_pack_artifacts_1 = require("./rule-pack-artifacts");
9
- const rule_pack_sync_1 = require("./rule-pack-sync");
10
- const repo_root_1 = require("./repo-root");
11
- const run_main_1 = require("./run-main");
12
- /** CLI parsing does not validate the live config: this command repairs missing required settings. */
13
- class RulesSyncCli {
14
- parse(args) {
15
- let mode = 'sync';
16
- const declarations = [];
17
- for (let index = 0; index < args.length; index++) {
18
- const argument = args[index];
19
- if (argument === '--upgrade') {
20
- mode = 'upgrade';
21
- continue;
22
- }
23
- const value = argument === '--pack'
24
- ? args[++index]
25
- : argument.startsWith('--pack=')
26
- ? argument.slice(7)
27
- : undefined;
28
- if (!value || value.indexOf('=') <= 0 || value.endsWith('=')) {
29
- throw new tooling_common_1.InformAiError('Usage: pnpm wp-rules-sync [--upgrade] [--pack=<package-or-module>=<repository-relative-config.json>] ...');
30
- }
31
- const separator = value.indexOf('=');
32
- declarations.push(new pack_policy_files_1.PackPolicyDeclaration(value.slice(0, separator), value.slice(separator + 1)));
33
- }
34
- return new rule_pack_sync_1.RulePackSyncOptions(mode, declarations.length ? declarations : null);
35
- }
36
- async main() {
37
- const atomic = new tooling_common_1.AtomicFile(), root = new repo_root_1.RepoRootFinder().resolveRepoRoot(process.cwd());
38
- const sync = new rule_pack_sync_1.RulePackSync(new config_file_1.ConfigFile(), new pack_policy_files_1.PackPolicyFiles(), new rule_pack_artifacts_1.RulePackArtifacts(atomic), atomic);
39
- const changed = sync.run(root, this.parse(process.argv.slice(2)));
40
- console.log(changed.length
41
- ? `Review and commit these explicit config/artifact changes:\n${changed.join('\n')}`
42
- : 'Rule config and generated artifacts already agree.');
43
- }
44
- }
45
- exports.RulesSyncCli = RulesSyncCli;
46
- if (require.main === module)
47
- (0, run_main_1.runMain)(() => new RulesSyncCli().main());
48
- //# sourceMappingURL=rules-sync-cli.js.map