@webpieces/agent-workflow-rules 0.4.846 → 0.4.848
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -8
- package/src/adapters/hook-app-fixtures.d.ts +2 -2
- package/src/adapters/hook-app-fixtures.js +39 -13
- package/src/adapters/hook-app-fixtures.js.map +1 -1
- package/src/bin/l0-allowlist.js +13 -21
- package/src/bin/l0-allowlist.js.map +1 -1
- package/src/bin/l0-decide.js +3 -1
- package/src/bin/l0-decide.js.map +1 -1
- package/src/bin/setup-config.d.ts +1 -19
- package/src/bin/setup-config.js +18 -363
- package/src/bin/setup-config.js.map +1 -1
- package/src/bin/shim.js +11 -4
- package/src/bin/shim.js.map +1 -1
- package/src/core/load-rules.d.ts +0 -7
- package/src/core/load-rules.js +0 -48
- package/src/core/load-rules.js.map +1 -1
- package/src/core/rules/index.d.ts +9 -1
- package/src/core/rules/index.js +19 -2
- package/src/core/rules/index.js.map +1 -1
- package/src/core/runner.js +60 -48
- package/src/core/runner.js.map +1 -1
- package/src/core/workflow-hook-rules.js +3 -5
- package/src/core/workflow-hook-rules.js.map +1 -1
- package/src/rule-help.d.ts +3 -0
- package/src/rule-help.js +11 -0
- package/src/rule-help.js.map +1 -0
- package/src/rule-pack.js +3 -13
- package/src/rule-pack.js.map +1 -1
- package/src/rule-runtime.d.ts +5 -0
- package/src/rule-runtime.js +29 -0
- package/src/rule-runtime.js.map +1 -0
- package/src/workflow-policy-registry.d.ts +12 -0
- package/src/workflow-policy-registry.js +42 -0
- package/src/workflow-policy-registry.js.map +1 -0
- package/templates/ai-hook.sh +105 -4
package/src/bin/setup-config.js
CHANGED
|
@@ -1,371 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrate = migrate;
|
|
4
3
|
exports.seedOrSyncConfig = seedOrSyncConfig;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
5
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
7
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
8
8
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* SEEDING AND MIGRATING `webpieces.config.json` — the installer's OTHER job.
|
|
12
|
-
*
|
|
13
|
-
* Split out of ./setup.ts purely for size, and along the seam that was already there: setup.ts is now
|
|
14
|
-
* hook WIRING (which settings file gets which matcher and which shim command) and this module is CONFIG
|
|
15
|
-
* SHAPE (which rules exist, where a retired key moves to). They share only `main()`, which calls this
|
|
16
|
-
* once and then wires the hooks.
|
|
17
|
-
*
|
|
18
|
-
* Like setup.ts it is deliberately DI-FREE: `wp-install-ai-hooks` has to run on a half-written
|
|
19
|
-
* node_modules (see install-entry.ts), so every function here is module-scope and imports nothing that
|
|
20
|
-
* needs a container.
|
|
21
|
-
*/
|
|
22
|
-
const CONFIG_FILENAME = 'webpieces.config.json';
|
|
23
|
-
// The seeded buildCommand comes from @webpieces/rules-config, NOT from a copy here. This file used to
|
|
24
|
-
// hold its own — with `--base=origin/main`, a DIFFERENT base from the one the gate documents — so a
|
|
25
|
-
// freshly set-up repo was seeded with a command that rebuilds projects touched by other people's
|
|
26
|
-
// merged PRs, and whole-repo-build-guard then quoted that command back in its refusals.
|
|
27
|
-
const DEFAULT_UPSERT_PR = 'pnpm wp-start-upsert-pr';
|
|
28
|
-
const DEFAULT_MERGE_COMPLETE = 'pnpm wp-finish-upsert-pr';
|
|
29
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed* helpers; this module is config-shape builders by design
|
|
30
|
-
function seedRule(ruleName, registry) {
|
|
31
|
-
// Both escape hatches are seeded (and REQUIRED) so every rule block shows them: 0 = active,
|
|
32
|
-
// null = no branch scoping. A human/AI edits these to time-box or branch-scope a rule off.
|
|
33
|
-
//
|
|
34
|
-
// The ENTIRE entry comes from rules-config's seedEntryForRule() — the same module that owns the
|
|
35
|
-
// schema the loader validates against, so the installer can never emit an entry the loader
|
|
36
|
-
// rejects. It supplies: the recommended mode (the SAME recommendation the validator prints in its
|
|
37
|
-
// copy-paste snippet, so seed and advice cannot disagree), both hatches, and a default for every
|
|
38
|
-
// other schema-REQUIRED field. Seeding used to be a flat 'OFF' plus the two hatches, which was
|
|
39
|
-
// wrong twice over: adopters got nothing enforced, AND the entry was missing required fields
|
|
40
|
-
// (e.g. branch-creation-guard.autoReapMergedBranches), so the config failed to load on first run.
|
|
41
|
-
return (0, rules_config_1.seedEntryForRule)(ruleName, registry);
|
|
42
|
-
}
|
|
43
|
-
// The guard-hint command strings live under `guardHints`. The flat `upsertPr`/`mergeComplete` keys this
|
|
44
|
-
// used to seed are RETIRED and now fail validation — seeding them meant every freshly installed repo was
|
|
45
|
-
// born on a shape the validator rejects.
|
|
46
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
47
|
-
function seedCommands() {
|
|
48
|
-
return {
|
|
49
|
-
'pr-gate': { mode: 'OFF', buildCommand: rules_config_1.DEFAULT_BUILD_COMMAND, gates: [] },
|
|
50
|
-
guardHints: { prCreationOrPush: DEFAULT_UPSERT_PR, mergeInProgress: DEFAULT_MERGE_COMPLETE },
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
// Required excludePaths block: ONE glob list suppressing hook enforcement per file path. Seeded empty
|
|
54
|
-
// (enforce everywhere) — a client adds paths (e.g. "repositories/**") to exempt vendored trees.
|
|
55
|
-
//
|
|
56
|
-
// Deliberately NOT seeded with webpieces' own `.webpieces/` state dir. That exemption lives in CODE
|
|
57
|
-
// (`isWebpiecesStateDir`, consulted by `filterByExcludedPaths` ahead of this list and regardless of it),
|
|
58
|
-
// and a glob here would be a second, weaker spelling of it — weaker because `.webpieces/**` compiles to
|
|
59
|
-
// an anchored regex that misses the bare directory the predicate matches, and because a config entry
|
|
60
|
-
// invites a consumer to delete it and believe the exemption went with it.
|
|
61
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed* helpers; this module is config-shape builders by design
|
|
62
|
-
function seedExcludePaths() {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
// Bring an existing `excludePaths` forward to the single-list shape. Already a list → untouched.
|
|
66
|
-
// Legacy `{ rules, guards }` → unioned (order preserved, duplicates dropped) and recorded as a change
|
|
67
|
-
// so `wp-install-ai-hooks` is the migration path rather than a hand-edit. Anything else → seeded [].
|
|
68
|
-
// webpieces-disable no-any-unknown -- `raw` is opaque consumer JSON until narrowed here
|
|
69
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design
|
|
70
|
-
function migrateExcludePaths(raw, changes) {
|
|
71
|
-
if (Array.isArray(raw))
|
|
72
|
-
return raw.filter(p => typeof p === 'string');
|
|
73
|
-
if (typeof raw === 'object' && raw !== null) {
|
|
74
|
-
// webpieces-disable no-any-unknown -- narrowing the opaque legacy block from consumer JSON
|
|
75
|
-
const legacy = raw;
|
|
76
|
-
const rules = Array.isArray(legacy['rules']) ? legacy['rules'] : [];
|
|
77
|
-
const guards = Array.isArray(legacy['guards']) ? legacy['guards'] : [];
|
|
78
|
-
const merged = [...new Set([...rules, ...guards].filter(p => typeof p === 'string'))];
|
|
79
|
-
changes.push(`migrated excludePaths {rules,guards} -> one list (${merged.length} path(s))`);
|
|
80
|
-
return merged;
|
|
81
|
-
}
|
|
82
|
-
changes.push('added excludePaths ([])');
|
|
83
|
-
return seedExcludePaths();
|
|
84
|
-
}
|
|
85
|
-
/** One retired flat command string and the guardHints field it becomes. Data-only (per CLAUDE.md). */
|
|
86
|
-
class GuardHintMove {
|
|
87
|
-
retiredKey;
|
|
88
|
-
hintKey;
|
|
89
|
-
fallback;
|
|
90
|
-
constructor(retiredKey, hintKey, fallback) {
|
|
91
|
-
this.retiredKey = retiredKey;
|
|
92
|
-
this.hintKey = hintKey;
|
|
93
|
-
this.fallback = fallback;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Bring `commands` forward to the `guardHints` shape, moving the RETIRED flat `upsertPr`/`mergeComplete`
|
|
98
|
-
* strings and DELETING them. Deleting is the point: the validator now rejects them, so leaving them behind
|
|
99
|
-
* would keep the config failing after a "successful" sync.
|
|
100
|
-
*
|
|
101
|
-
* The consumer's own value wins over the default — a repo that renamed its gated command keeps that name.
|
|
102
|
-
*/
|
|
103
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design
|
|
104
|
-
function migrateGuardHints(commands, changes) {
|
|
105
|
-
const hints = (typeof commands['guardHints'] === 'object' && commands['guardHints'] !== null)
|
|
106
|
-
? commands['guardHints'] : {};
|
|
107
|
-
const moves = [
|
|
108
|
-
new GuardHintMove('upsertPr', 'prCreationOrPush', DEFAULT_UPSERT_PR),
|
|
109
|
-
new GuardHintMove('mergeComplete', 'mergeInProgress', DEFAULT_MERGE_COMPLETE),
|
|
110
|
-
];
|
|
111
|
-
for (const move of moves) {
|
|
112
|
-
const retiredKey = move.retiredKey;
|
|
113
|
-
const hintKey = move.hintKey;
|
|
114
|
-
const fallback = move.fallback;
|
|
115
|
-
const carried = commands[retiredKey];
|
|
116
|
-
if (carried !== undefined) {
|
|
117
|
-
delete commands[retiredKey];
|
|
118
|
-
if (hints[hintKey] === undefined)
|
|
119
|
-
hints[hintKey] = carried;
|
|
120
|
-
changes.push(`moved retired commands.${retiredKey} -> commands.guardHints.${hintKey}`);
|
|
121
|
-
}
|
|
122
|
-
if (hints[hintKey] === undefined) {
|
|
123
|
-
hints[hintKey] = fallback;
|
|
124
|
-
changes.push(`added commands.guardHints.${hintKey}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
commands['guardHints'] = hints;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Apply the RETIRED rule/guard retirements in place. These used to be rewritten silently at load time, so
|
|
131
|
-
* a consumer's file kept the dead name forever; the loader now rejects it, which makes this the one
|
|
132
|
-
* command that can fix the file. Skips a rename when the new name is already configured, so an explicit
|
|
133
|
-
* entry is never clobbered by a stale one.
|
|
134
|
-
*
|
|
135
|
-
* NOT EVERY RETIREMENT IS A RENAME, and treating them all as one produced garbage. `whole-repo-build-guard`
|
|
136
|
-
* moved OUT of webpieces.config.json entirely — its `movedTo` is the PROSE destination
|
|
137
|
-
* `~/.webpieces/config.json → experimental.whole-repo-build-guard`, not a sibling key — so the rename
|
|
138
|
-
* branch below would have created a hookGuards entry literally named that whole sentence, which no
|
|
139
|
-
* validator knows and which the next run reports as another unknown rule. `prunable` is the discriminator:
|
|
140
|
-
* when the entry says deleting is the whole fix, DELETE it, exactly as `ConfigPruner` does.
|
|
141
|
-
*/
|
|
142
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design
|
|
143
|
-
function migrateRetiredRuleNames(section, changes, registry) {
|
|
144
|
-
for (const entry of registry.migrations()) {
|
|
145
|
-
if (entry.scope !== rules_config_1.RETIRED_SCOPE_RULE)
|
|
146
|
-
continue;
|
|
147
|
-
if (!(entry.key in section))
|
|
148
|
-
continue;
|
|
149
|
-
if (entry.prunable) {
|
|
150
|
-
delete section[entry.key];
|
|
151
|
-
changes.push(`deleted retired "${entry.key}" (it moved to ${entry.movedTo})`);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
mergeIntoDestination(section, entry.key, entry.movedTo, changes, registry);
|
|
155
|
-
}
|
|
156
|
-
fillRequiredFields(section, changes, registry);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Fold one retired key's entry into its destination, whether the destination exists yet or not.
|
|
160
|
-
*
|
|
161
|
-
* THIS IS N→1, NOT 1:1, and the difference is the whole reason this helper exists. Four retired keys
|
|
162
|
-
* now point at ONE destination (`branch-state-guard`, `pr-lifecycle-guard`). The previous code renamed
|
|
163
|
-
* the first key it met and then, finding the destination already present, DELETED each of the other
|
|
164
|
-
* three outright — so which guard's settings survived depended on RETIRED_CONFIG_KEYS declaration
|
|
165
|
-
* order rather than on the consumer's file, and the survivor carried only that one guard's fields, so
|
|
166
|
-
* it was missing required fields of the merged schema. `wp-install-ai-hooks` is the command advertised
|
|
167
|
-
* as the migration path; half-migrating every consumer into an invalid config is not an option.
|
|
168
|
-
*
|
|
169
|
-
* UNION, first writer wins per field. Earlier-declared keys are the more specific ones (only
|
|
170
|
-
* feature-branch-guard carries `branchNamingConvention`), and a field already present on the
|
|
171
|
-
* destination — because the consumer wrote it, or an earlier key contributed it — is never overwritten.
|
|
172
|
-
* Fields the merged schema does not know are dropped by the same pass, since carrying a deleted field
|
|
173
|
-
* across (`upsertPrCommand`) would produce a config the validator immediately rejects.
|
|
174
|
-
*/
|
|
175
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design
|
|
176
|
-
function mergeIntoDestination(section, key, destination, changes, registry) {
|
|
177
|
-
const source = asSection(section[key]);
|
|
178
|
-
delete section[key];
|
|
179
|
-
const fields = (0, rules_config_1.schemaFieldNames)(destination, registry);
|
|
180
|
-
const target = asSection(section[destination]);
|
|
181
|
-
const existed = destination in section;
|
|
182
|
-
const carried = [];
|
|
183
|
-
const dropped = [];
|
|
184
|
-
for (const field of Object.keys(source)) {
|
|
185
|
-
if (fields !== null && !fields.includes(field)) {
|
|
186
|
-
dropped.push(field);
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (field in target)
|
|
190
|
-
continue;
|
|
191
|
-
target[field] = source[field];
|
|
192
|
-
carried.push(field);
|
|
193
|
-
}
|
|
194
|
-
section[destination] = target;
|
|
195
|
-
const verb = existed ? 'merged' : 'renamed';
|
|
196
|
-
const droppedNote = dropped.length > 0 ? `; dropped deleted field(s) ${dropped.join(', ')}` : '';
|
|
197
|
-
changes.push(`${verb} retired "${key}" -> "${destination}" (carried ${carried.join(', ') || 'nothing new'}${droppedNote})`);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Fill any schema-REQUIRED field a migrated entry ended up without.
|
|
201
|
-
*
|
|
202
|
-
* A union of four partial entries is not guaranteed to satisfy the destination's schema — the merged
|
|
203
|
-
* `branch-state-guard` needs `mode` and both escape hatches, and a consumer whose four old entries
|
|
204
|
-
* predate one of them would land short. Seeding the gap from the SAME source the installer and the
|
|
205
|
-
* validator use (seedEntryForRule) is what makes the install command a complete instruction
|
|
206
|
-
* rather than a first step. Only ever ADDS; a value the consumer stated is never touched.
|
|
207
|
-
*/
|
|
208
|
-
// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design
|
|
209
|
-
function fillRequiredFields(section, changes, registry) {
|
|
210
|
-
for (const name of Object.keys(section)) {
|
|
211
|
-
if ((0, rules_config_1.schemaFieldNames)(name, registry) === null)
|
|
212
|
-
continue;
|
|
213
|
-
// A rule ENTRY is a flat bag of scalars, so it is read as Json here rather than through
|
|
214
|
-
// asSection (whose values are whole entries). Same object either way; only the view differs.
|
|
215
|
-
const entry = asSection(section[name]);
|
|
216
|
-
const seed = (0, rules_config_1.seedEntryForRule)(name, registry);
|
|
217
|
-
const added = [];
|
|
218
|
-
for (const field of Object.keys(seed)) {
|
|
219
|
-
if (field in entry)
|
|
220
|
-
continue;
|
|
221
|
-
entry[field] = seed[field];
|
|
222
|
-
added.push(field);
|
|
223
|
-
}
|
|
224
|
-
if (added.length === 0)
|
|
225
|
-
continue;
|
|
226
|
-
section[name] = entry;
|
|
227
|
-
changes.push(`filled required field(s) on "${name}": ${added.join(', ')}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
// Deep-copy the framework's default match-rules (the no-fetch guard) into plain JSON for the config
|
|
231
|
-
// file. Round-tripping through JSON turns the MatchRuleConfig instances into plain objects.
|
|
232
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
233
|
-
function seedMatchRules() {
|
|
234
|
-
return JSON.parse(JSON.stringify(rules_config_1.DEFAULT_MATCH_RULES));
|
|
235
|
-
}
|
|
236
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
237
|
-
function buildSeedConfig(registry) {
|
|
238
|
-
const rules = {};
|
|
239
|
-
const hookGuards = {};
|
|
240
|
-
for (const name of (0, rules_config_1.allRuleNames)(registry)) {
|
|
241
|
-
if ((0, rules_config_1.sectionForRule)(name, registry) === 'hookGuards')
|
|
242
|
-
hookGuards[name] = seedRule(name, registry);
|
|
243
|
-
else
|
|
244
|
-
rules[name] = seedRule(name, registry);
|
|
245
|
-
}
|
|
246
|
-
return {
|
|
247
|
-
rules, hookGuards, commands: seedCommands(), excludePaths: seedExcludePaths(),
|
|
248
|
-
// Seed the required match-rules array with the framework's default no-fetch guard. A fresh
|
|
249
|
-
// project gets contract-first enforcement out of the box; clients edit it and add more entries.
|
|
250
|
-
'match-rules': seedMatchRules(),
|
|
251
|
-
rulesDir: [],
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
255
|
-
function writeConfig(configPath, config) {
|
|
256
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 4) + '\n');
|
|
257
|
-
}
|
|
258
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
259
|
-
function readConfig(configPath) {
|
|
260
|
-
const raw = fs.readFileSync(configPath, 'utf8');
|
|
261
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
262
|
-
try {
|
|
263
|
-
return JSON.parse(raw);
|
|
264
|
-
}
|
|
265
|
-
catch (err) {
|
|
266
|
-
const error = (0, to_error_1.toError)(err);
|
|
267
|
-
throw new Error(`${CONFIG_FILENAME} has invalid JSON — fix it, then retry: ${error.message}`, { cause: error });
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
271
|
-
function asSection(value) {
|
|
272
|
-
return (typeof value === 'object' && value !== null && !Array.isArray(value)) ? value : {};
|
|
273
|
-
}
|
|
274
|
-
// Migrate an existing config to the rules / hookGuards / commands layout and add any missing rules.
|
|
275
|
-
// Returns a human-readable list of what changed (empty = already up to date).
|
|
276
|
-
// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method
|
|
277
|
-
function migrate(existing, registry) {
|
|
278
|
-
const changes = [];
|
|
279
|
-
const rules = asSection(existing['rules']);
|
|
280
|
-
const hookGuards = asSection(existing['hookGuards']);
|
|
281
|
-
const commands = (typeof existing['commands'] === 'object' && existing['commands'] !== null)
|
|
282
|
-
? existing['commands'] : {};
|
|
283
|
-
// Move a deprecated top-level pr-gate block under commands.
|
|
284
|
-
if (existing['pr-gate'] !== undefined && commands['pr-gate'] === undefined) {
|
|
285
|
-
commands['pr-gate'] = existing['pr-gate'];
|
|
286
|
-
changes.push('moved top-level "pr-gate" → commands["pr-gate"]');
|
|
287
|
-
}
|
|
288
|
-
// Apply retired RENAMES first, so a renamed guard is placed and presence-checked under its new name
|
|
289
|
-
// rather than being treated as unknown and re-added alongside its own stale entry.
|
|
290
|
-
migrateRetiredRuleNames(rules, changes, registry);
|
|
291
|
-
migrateRetiredRuleNames(hookGuards, changes, registry);
|
|
292
|
-
// Move guards mistakenly left in rules into hookGuards.
|
|
293
|
-
for (const name of Object.keys(rules)) {
|
|
294
|
-
if ((0, rules_config_1.isHookGuard)(name, registry)) {
|
|
295
|
-
hookGuards[name] = rules[name];
|
|
296
|
-
delete rules[name];
|
|
297
|
-
changes.push(`moved "${name}" from rules → hookGuards`);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// Move code rules mistakenly placed in hookGuards back into rules.
|
|
301
|
-
for (const name of Object.keys(hookGuards)) {
|
|
302
|
-
if (!(0, rules_config_1.isHookGuard)(name, registry) && (0, rules_config_1.allRuleNames)(registry).includes(name)) {
|
|
303
|
-
rules[name] = hookGuards[name];
|
|
304
|
-
delete hookGuards[name];
|
|
305
|
-
changes.push(`moved "${name}" from hookGuards → rules`);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// Add any missing built-in into its correct section, ENFORCING at its recommended mode (not OFF).
|
|
309
|
-
for (const name of (0, rules_config_1.allRuleNames)(registry)) {
|
|
310
|
-
const target = (0, rules_config_1.sectionForRule)(name, registry) === 'hookGuards' ? hookGuards : rules;
|
|
311
|
-
if (!(name in target)) {
|
|
312
|
-
const entry = seedRule(name, registry);
|
|
313
|
-
target[name] = entry;
|
|
314
|
-
changes.push(`added "${name}" (${String(entry['mode'])}) to ${(0, rules_config_1.sectionForRule)(name, registry)}`);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
// Fill command defaults.
|
|
318
|
-
if (commands['pr-gate'] === undefined) {
|
|
319
|
-
commands['pr-gate'] = { mode: 'OFF', buildCommand: rules_config_1.DEFAULT_BUILD_COMMAND, gates: [] };
|
|
320
|
-
changes.push('added commands["pr-gate"] (OFF)');
|
|
321
|
-
}
|
|
322
|
-
migrateGuardHints(commands, changes);
|
|
323
|
-
// Seed the now-required excludePaths list (empty = enforce everywhere) if the config predates it,
|
|
324
|
-
// and MIGRATE the legacy `{ rules: [], guards: [] }` object to the single list by unioning them.
|
|
325
|
-
// The union is behaviour-preserving for every config we have seen (both lists set identically), and
|
|
326
|
-
// widening is the safe direction anyway: a path either side excluded stays excluded.
|
|
327
|
-
const excludePaths = migrateExcludePaths(existing['excludePaths'], changes);
|
|
328
|
-
// Seed the now-required match-rules array (with the default no-fetch guard) if the config predates
|
|
329
|
-
// it. A client that has already customized it keeps their array untouched.
|
|
330
|
-
let matchRules;
|
|
331
|
-
if (Array.isArray(existing['match-rules'])) {
|
|
332
|
-
matchRules = existing['match-rules'];
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
matchRules = seedMatchRules();
|
|
336
|
-
changes.push('added "match-rules" (seeded with the no-fetch guard)');
|
|
337
|
-
}
|
|
338
|
-
const rulesDir = Array.isArray(existing['rulesDir']) ? existing['rulesDir'] : [];
|
|
339
|
-
const config = { rules, hookGuards, commands, excludePaths, 'match-rules': matchRules, rulesDir };
|
|
340
|
-
if (typeof existing['extends'] === 'string')
|
|
341
|
-
config.extends = existing['extends'];
|
|
342
|
-
return { config, changes };
|
|
343
|
-
}
|
|
344
|
-
// Seed the config when it is missing, migrate it when it is not. ONE behaviour, always — there is no
|
|
345
|
-
// "migrate but stop here" mode any more. The flag that used to select it was never NECESSARY (the validator prints
|
|
346
|
-
// the exact edit for every error at once, and editing webpieces.config.json is always allowed through the
|
|
347
|
-
// guard — the documented primary cure), it REFUSED to act when the config was missing (useless in the one
|
|
348
|
-
// case automation would have helped), and it gave deny messages a second competing path when they are
|
|
349
|
-
// supposed to end in exactly one action. Readers also mistook it for the shim-repair command, which it
|
|
350
|
-
// never was — `wp-upgrade-shim` is that.
|
|
351
|
-
// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope
|
|
9
|
+
/** Installation syncs declared owner files; flat roots require the explicit upgrade operation. */
|
|
10
|
+
// webpieces-disable no-function-outside-class -- DI-free installer composition must work before hooks are wired
|
|
352
11
|
function seedOrSyncConfig(projectRoot) {
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
writeConfig(configPath, result.config);
|
|
367
|
-
console.log(` [ai-hooks] Migrated ${CONFIG_FILENAME}:`);
|
|
368
|
-
for (const change of result.changes)
|
|
369
|
-
console.log(` - ${change}`);
|
|
12
|
+
const filename = path.join(projectRoot, rules_config_1.CONFIG_FILENAME);
|
|
13
|
+
if (!fs.existsSync(filename)) {
|
|
14
|
+
throw new tooling_common_1.InformAiError('Create webpieces.config.json with explicit rulePacks, commands, excludePaths and match-rules, then run pnpm wp-rules-sync to write reviewed owner seeds. Installed packages are never inferred as selected policy packs.');
|
|
15
|
+
}
|
|
16
|
+
const configFile = new rules_config_1.ConfigFile(), raw = configFile.readRawConfig(filename);
|
|
17
|
+
if (raw.rulePacks === undefined) {
|
|
18
|
+
throw new tooling_common_1.InformAiError('The flat root config is retired. Run pnpm wp-rules-sync --upgrade with explicit --pack=<package>=<config.json> declarations, review the owner files and artifacts, then rerun hook installation.');
|
|
19
|
+
}
|
|
20
|
+
const atomic = new tooling_common_1.AtomicFile();
|
|
21
|
+
const changed = new rules_config_1.RulePackSync(configFile, new rules_config_1.PackPolicyFiles(), new rules_config_1.RulePackArtifacts(atomic), atomic).run(projectRoot, new rules_config_1.RulePackSyncOptions('sync', null));
|
|
22
|
+
console.log(changed.length
|
|
23
|
+
? `[ai-hooks] Review explicit owner config/artifact changes:\n${changed.join('\n')}`
|
|
24
|
+
: '[ai-hooks] Declared owner config and artifacts already agree.');
|
|
370
25
|
}
|
|
371
26
|
//# sourceMappingURL=setup-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/setup-config.ts"],"names":[],"mappings":";;AA0SA,0BAqEC;AAUD,4CAiBC;;AA1Y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,GAAG,CAAC,wBAAwB,eAAe,4IAA4I,CAAC,CAAC;QACjM,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAC9D,OAAO;IACX,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,gBAAgB,eAAe,sEAAsE,CAAC,CAAC;QACnH,OAAO;IACX,CAAC;IACD,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,yBAAyB,eAAe,GAAG,CAAC,CAAC;IACzD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { RulePackRegistry, RulePackSelection, allRuleNames, seedEntryForRule, schemaFieldNames, sectionForRule, isHookGuard, DEFAULT_MATCH_RULES, DEFAULT_BUILD_COMMAND, RETIRED_SCOPE_RULE } from '@webpieces/rules-config';\n\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n/**\n * SEEDING AND MIGRATING `webpieces.config.json` — the installer's OTHER job.\n *\n * Split out of ./setup.ts purely for size, and along the seam that was already there: setup.ts is now\n * hook WIRING (which settings file gets which matcher and which shim command) and this module is CONFIG\n * SHAPE (which rules exist, where a retired key moves to). They share only `main()`, which calls this\n * once and then wires the hooks.\n *\n * Like setup.ts it is deliberately DI-FREE: `wp-install-ai-hooks` has to run on a half-written\n * node_modules (see install-entry.ts), so every function here is module-scope and imports nothing that\n * needs a container.\n */\nconst CONFIG_FILENAME = 'webpieces.config.json';\n// The seeded buildCommand comes from @webpieces/rules-config, NOT from a copy here. This file used to\n// hold its own — with `--base=origin/main`, a DIFFERENT base from the one the gate documents — so a\n// freshly set-up repo was seeded with a command that rebuilds projects touched by other people's\n// merged PRs, and whole-repo-build-guard then quoted that command back in its refusals.\nconst DEFAULT_UPSERT_PR = 'pnpm wp-start-upsert-pr';\nconst DEFAULT_MERGE_COMPLETE = 'pnpm wp-finish-upsert-pr';\n// ---------------------------------------------------------------------------\n// webpieces.config.json seeding + migration to the rules / hookGuards / commands layout.\n// ---------------------------------------------------------------------------\n// webpieces-disable no-any-unknown -- webpieces.config.json / settings.json are opaque consumer JSON\ntype Json = Record<string, unknown>;\ntype RuleEntry = Json;\ntype Section = Record<string, RuleEntry>;\n\ninterface ConfigFile {\n extends?: string;\n rules: Section;\n hookGuards: Section;\n commands: Json;\n excludePaths: string[];\n 'match-rules': Json[];\n rulesDir: string[];\n}\n\ninterface MigrateResult {\n config: ConfigFile;\n changes: string[];\n}\n\n// webpieces-disable no-function-outside-class -- sibling of the other seed* helpers; this module is config-shape builders by design\nfunction seedRule(ruleName: string, registry: RulePackRegistry): RuleEntry {\n // Both escape hatches are seeded (and REQUIRED) so every rule block shows them: 0 = active,\n // null = no branch scoping. A human/AI edits these to time-box or branch-scope a rule off.\n //\n // The ENTIRE entry comes from rules-config's seedEntryForRule() — the same module that owns the\n // schema the loader validates against, so the installer can never emit an entry the loader\n // rejects. It supplies: the recommended mode (the SAME recommendation the validator prints in its\n // copy-paste snippet, so seed and advice cannot disagree), both hatches, and a default for every\n // other schema-REQUIRED field. Seeding used to be a flat 'OFF' plus the two hatches, which was\n // wrong twice over: adopters got nothing enforced, AND the entry was missing required fields\n // (e.g. branch-creation-guard.autoReapMergedBranches), so the config failed to load on first run.\n return seedEntryForRule(ruleName, registry);\n}\n\n// The guard-hint command strings live under `guardHints`. The flat `upsertPr`/`mergeComplete` keys this\n// used to seed are RETIRED and now fail validation — seeding them meant every freshly installed repo was\n// born on a shape the validator rejects.\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction seedCommands(): Json {\n return {\n 'pr-gate': { mode: 'OFF', buildCommand: DEFAULT_BUILD_COMMAND, gates: [] },\n guardHints: { prCreationOrPush: DEFAULT_UPSERT_PR, mergeInProgress: DEFAULT_MERGE_COMPLETE },\n };\n}\n\n// Required excludePaths block: ONE glob list suppressing hook enforcement per file path. Seeded empty\n// (enforce everywhere) — a client adds paths (e.g. \"repositories/**\") to exempt vendored trees.\n//\n// Deliberately NOT seeded with webpieces' own `.webpieces/` state dir. That exemption lives in CODE\n// (`isWebpiecesStateDir`, consulted by `filterByExcludedPaths` ahead of this list and regardless of it),\n// and a glob here would be a second, weaker spelling of it — weaker because `.webpieces/**` compiles to\n// an anchored regex that misses the bare directory the predicate matches, and because a config entry\n// invites a consumer to delete it and believe the exemption went with it.\n// webpieces-disable no-function-outside-class -- sibling of the other seed* helpers; this module is config-shape builders by design\nfunction seedExcludePaths(): string[] {\n return [];\n}\n\n// Bring an existing `excludePaths` forward to the single-list shape. Already a list → untouched.\n// Legacy `{ rules, guards }` → unioned (order preserved, duplicates dropped) and recorded as a change\n// so `wp-install-ai-hooks` is the migration path rather than a hand-edit. Anything else → seeded [].\n// webpieces-disable no-any-unknown -- `raw` is opaque consumer JSON until narrowed here\n// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design\nfunction migrateExcludePaths(raw: unknown, changes: string[]): string[] {\n if (Array.isArray(raw)) return (raw as string[]).filter(p => typeof p === 'string');\n if (typeof raw === 'object' && raw !== null) {\n // webpieces-disable no-any-unknown -- narrowing the opaque legacy block from consumer JSON\n const legacy = raw as Record<string, unknown>;\n const rules = Array.isArray(legacy['rules']) ? (legacy['rules'] as string[]) : [];\n const guards = Array.isArray(legacy['guards']) ? (legacy['guards'] as string[]) : [];\n const merged = [...new Set([...rules, ...guards].filter(p => typeof p === 'string'))];\n changes.push(`migrated excludePaths {rules,guards} -> one list (${merged.length} path(s))`);\n return merged;\n }\n changes.push('added excludePaths ([])');\n return seedExcludePaths();\n}\n\n/** One retired flat command string and the guardHints field it becomes. Data-only (per CLAUDE.md). */\nclass GuardHintMove {\n retiredKey: string;\n hintKey: string;\n fallback: string;\n\n constructor(retiredKey: string, hintKey: string, fallback: string) {\n this.retiredKey = retiredKey;\n this.hintKey = hintKey;\n this.fallback = fallback;\n }\n}\n\n/**\n * Bring `commands` forward to the `guardHints` shape, moving the RETIRED flat `upsertPr`/`mergeComplete`\n * strings and DELETING them. Deleting is the point: the validator now rejects them, so leaving them behind\n * would keep the config failing after a \"successful\" sync.\n *\n * The consumer's own value wins over the default — a repo that renamed its gated command keeps that name.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design\nfunction migrateGuardHints(commands: Json, changes: string[]): void {\n const hints: Json = (typeof commands['guardHints'] === 'object' && commands['guardHints'] !== null)\n ? (commands['guardHints'] as Json) : {};\n const moves: readonly GuardHintMove[] = [\n new GuardHintMove('upsertPr', 'prCreationOrPush', DEFAULT_UPSERT_PR),\n new GuardHintMove('mergeComplete', 'mergeInProgress', DEFAULT_MERGE_COMPLETE),\n ];\n for (const move of moves) {\n const retiredKey = move.retiredKey;\n const hintKey = move.hintKey;\n const fallback = move.fallback;\n const carried = commands[retiredKey];\n if (carried !== undefined) {\n delete commands[retiredKey];\n if (hints[hintKey] === undefined) hints[hintKey] = carried;\n changes.push(`moved retired commands.${retiredKey} -> commands.guardHints.${hintKey}`);\n }\n if (hints[hintKey] === undefined) {\n hints[hintKey] = fallback;\n changes.push(`added commands.guardHints.${hintKey}`);\n }\n }\n commands['guardHints'] = hints;\n}\n\n/**\n * Apply the RETIRED rule/guard retirements in place. These used to be rewritten silently at load time, so\n * a consumer's file kept the dead name forever; the loader now rejects it, which makes this the one\n * command that can fix the file. Skips a rename when the new name is already configured, so an explicit\n * entry is never clobbered by a stale one.\n *\n * NOT EVERY RETIREMENT IS A RENAME, and treating them all as one produced garbage. `whole-repo-build-guard`\n * moved OUT of webpieces.config.json entirely — its `movedTo` is the PROSE destination\n * `~/.webpieces/config.json → experimental.whole-repo-build-guard`, not a sibling key — so the rename\n * branch below would have created a hookGuards entry literally named that whole sentence, which no\n * validator knows and which the next run reports as another unknown rule. `prunable` is the discriminator:\n * when the entry says deleting is the whole fix, DELETE it, exactly as `ConfigPruner` does.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design\nfunction migrateRetiredRuleNames(section: Section, changes: string[], registry: RulePackRegistry): void {\n for (const entry of registry.migrations()) {\n if (entry.scope !== RETIRED_SCOPE_RULE) continue;\n if (!(entry.key in section)) continue;\n if (entry.prunable) {\n delete section[entry.key];\n changes.push(`deleted retired \"${entry.key}\" (it moved to ${entry.movedTo})`);\n continue;\n }\n mergeIntoDestination(section, entry.key, entry.movedTo, changes, registry);\n }\n fillRequiredFields(section, changes, registry);\n}\n\n/**\n * Fold one retired key's entry into its destination, whether the destination exists yet or not.\n *\n * THIS IS N→1, NOT 1:1, and the difference is the whole reason this helper exists. Four retired keys\n * now point at ONE destination (`branch-state-guard`, `pr-lifecycle-guard`). The previous code renamed\n * the first key it met and then, finding the destination already present, DELETED each of the other\n * three outright — so which guard's settings survived depended on RETIRED_CONFIG_KEYS declaration\n * order rather than on the consumer's file, and the survivor carried only that one guard's fields, so\n * it was missing required fields of the merged schema. `wp-install-ai-hooks` is the command advertised\n * as the migration path; half-migrating every consumer into an invalid config is not an option.\n *\n * UNION, first writer wins per field. Earlier-declared keys are the more specific ones (only\n * feature-branch-guard carries `branchNamingConvention`), and a field already present on the\n * destination — because the consumer wrote it, or an earlier key contributed it — is never overwritten.\n * Fields the merged schema does not know are dropped by the same pass, since carrying a deleted field\n * across (`upsertPrCommand`) would produce a config the validator immediately rejects.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design\nfunction mergeIntoDestination(section: Section, key: string, destination: string, changes: string[], registry: RulePackRegistry): void {\n const source = asSection(section[key]);\n delete section[key];\n const fields = schemaFieldNames(destination, registry);\n const target = asSection(section[destination]);\n const existed = destination in section;\n const carried: string[] = [];\n const dropped: string[] = [];\n for (const field of Object.keys(source)) {\n if (fields !== null && !fields.includes(field)) { dropped.push(field); continue; }\n if (field in target) continue;\n target[field] = source[field];\n carried.push(field);\n }\n section[destination] = target;\n const verb = existed ? 'merged' : 'renamed';\n const droppedNote = dropped.length > 0 ? `; dropped deleted field(s) ${dropped.join(', ')}` : '';\n changes.push(`${verb} retired \"${key}\" -> \"${destination}\" (carried ${carried.join(', ') || 'nothing new'}${droppedNote})`);\n}\n\n/**\n * Fill any schema-REQUIRED field a migrated entry ended up without.\n *\n * A union of four partial entries is not guaranteed to satisfy the destination's schema — the merged\n * `branch-state-guard` needs `mode` and both escape hatches, and a consumer whose four old entries\n * predate one of them would land short. Seeding the gap from the SAME source the installer and the\n * validator use (seedEntryForRule) is what makes the install command a complete instruction\n * rather than a first step. Only ever ADDS; a value the consumer stated is never touched.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other seed*/migrate* helpers; this module is config-shape builders by design\nfunction fillRequiredFields(section: Section, changes: string[], registry: RulePackRegistry): void {\n for (const name of Object.keys(section)) {\n if (schemaFieldNames(name, registry) === null) continue;\n // A rule ENTRY is a flat bag of scalars, so it is read as Json here rather than through\n // asSection (whose values are whole entries). Same object either way; only the view differs.\n const entry: Json = asSection(section[name]);\n const seed = seedEntryForRule(name, registry);\n const added: string[] = [];\n for (const field of Object.keys(seed)) {\n if (field in entry) continue;\n entry[field] = seed[field];\n added.push(field);\n }\n if (added.length === 0) continue;\n section[name] = entry;\n changes.push(`filled required field(s) on \"${name}\": ${added.join(', ')}`);\n }\n}\n\n// Deep-copy the framework's default match-rules (the no-fetch guard) into plain JSON for the config\n// file. Round-tripping through JSON turns the MatchRuleConfig instances into plain objects.\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction seedMatchRules(): Json[] {\n return JSON.parse(JSON.stringify(DEFAULT_MATCH_RULES)) as Json[];\n}\n\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction buildSeedConfig(registry: RulePackRegistry): ConfigFile {\n const rules: Section = {};\n const hookGuards: Section = {};\n for (const name of allRuleNames(registry)) {\n if (sectionForRule(name, registry) === 'hookGuards') hookGuards[name] = seedRule(name, registry);\n else rules[name] = seedRule(name, registry);\n }\n return {\n rules, hookGuards, commands: seedCommands(), excludePaths: seedExcludePaths(),\n // Seed the required match-rules array with the framework's default no-fetch guard. A fresh\n // project gets contract-first enforcement out of the box; clients edit it and add more entries.\n 'match-rules': seedMatchRules(),\n rulesDir: [],\n };\n}\n\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction writeConfig(configPath: string, config: ConfigFile): void {\n fs.writeFileSync(configPath, JSON.stringify(config, null, 4) + '\\n');\n}\n\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction readConfig(configPath: string): Json {\n const raw = fs.readFileSync(configPath, 'utf8');\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return JSON.parse(raw) as Json;\n } catch (err: unknown) {\n const error = toError(err);\n throw new Error(`${CONFIG_FILENAME} has invalid JSON — fix it, then retry: ${error.message}`, { cause: error });\n }\n}\n\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nfunction asSection(value: Json[string]): Section {\n return (typeof value === 'object' && value !== null && !Array.isArray(value)) ? (value as Section) : {};\n}\n\n// Migrate an existing config to the rules / hookGuards / commands layout and add any missing rules.\n// Returns a human-readable list of what changed (empty = already up to date).\n// webpieces-disable no-function-outside-class -- this module is deliberately DI-FREE: `wp-install-ai-hooks` must run on a half-written node_modules (see install-entry.ts), so it cannot build a container to hold a method\nexport function migrate(existing: Json, registry: RulePackRegistry): MigrateResult {\n const changes: string[] = [];\n const rules: Section = asSection(existing['rules']);\n const hookGuards: Section = asSection(existing['hookGuards']);\n const commands: Json = (typeof existing['commands'] === 'object' && existing['commands'] !== null)\n ? (existing['commands'] as Json) : {};\n\n // Move a deprecated top-level pr-gate block under commands.\n if (existing['pr-gate'] !== undefined && commands['pr-gate'] === undefined) {\n commands['pr-gate'] = existing['pr-gate'];\n changes.push('moved top-level \"pr-gate\" → commands[\"pr-gate\"]');\n }\n // Apply retired RENAMES first, so a renamed guard is placed and presence-checked under its new name\n // rather than being treated as unknown and re-added alongside its own stale entry.\n migrateRetiredRuleNames(rules, changes, registry);\n migrateRetiredRuleNames(hookGuards, changes, registry);\n\n // Move guards mistakenly left in rules into hookGuards.\n for (const name of Object.keys(rules)) {\n if (isHookGuard(name, registry)) {\n hookGuards[name] = rules[name];\n delete rules[name];\n changes.push(`moved \"${name}\" from rules → hookGuards`);\n }\n }\n // Move code rules mistakenly placed in hookGuards back into rules.\n for (const name of Object.keys(hookGuards)) {\n if (!isHookGuard(name, registry) && allRuleNames(registry).includes(name)) {\n rules[name] = hookGuards[name];\n delete hookGuards[name];\n changes.push(`moved \"${name}\" from hookGuards → rules`);\n }\n }\n // Add any missing built-in into its correct section, ENFORCING at its recommended mode (not OFF).\n for (const name of allRuleNames(registry)) {\n const target = sectionForRule(name, registry) === 'hookGuards' ? hookGuards : rules;\n if (!(name in target)) {\n const entry = seedRule(name, registry);\n target[name] = entry;\n changes.push(`added \"${name}\" (${String(entry['mode'])}) to ${sectionForRule(name, registry)}`);\n }\n }\n // Fill command defaults.\n if (commands['pr-gate'] === undefined) {\n commands['pr-gate'] = { mode: 'OFF', buildCommand: DEFAULT_BUILD_COMMAND, gates: [] };\n changes.push('added commands[\"pr-gate\"] (OFF)');\n }\n migrateGuardHints(commands, changes);\n\n // Seed the now-required excludePaths list (empty = enforce everywhere) if the config predates it,\n // and MIGRATE the legacy `{ rules: [], guards: [] }` object to the single list by unioning them.\n // The union is behaviour-preserving for every config we have seen (both lists set identically), and\n // widening is the safe direction anyway: a path either side excluded stays excluded.\n const excludePaths: string[] = migrateExcludePaths(existing['excludePaths'], changes);\n\n // Seed the now-required match-rules array (with the default no-fetch guard) if the config predates\n // it. A client that has already customized it keeps their array untouched.\n let matchRules: Json[];\n if (Array.isArray(existing['match-rules'])) {\n matchRules = existing['match-rules'] as Json[];\n } else {\n matchRules = seedMatchRules();\n changes.push('added \"match-rules\" (seeded with the no-fetch guard)');\n }\n\n const rulesDir: string[] = Array.isArray(existing['rulesDir']) ? (existing['rulesDir'] as string[]) : [];\n const config: ConfigFile = { rules, hookGuards, commands, excludePaths, 'match-rules': matchRules, rulesDir };\n if (typeof existing['extends'] === 'string') config.extends = existing['extends'];\n return { config, changes };\n}\n\n// Seed the config when it is missing, migrate it when it is not. ONE behaviour, always — there is no\n// \"migrate but stop here\" mode any more. The flag that used to select it was never NECESSARY (the validator prints\n// the exact edit for every error at once, and editing webpieces.config.json is always allowed through the\n// guard — the documented primary cure), it REFUSED to act when the config was missing (useless in the one\n// case automation would have helped), and it gave deny messages a second competing path when they are\n// supposed to end in exactly one action. Readers also mistook it for the shim-repair command, which it\n// never was — `wp-upgrade-shim` is that.\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nexport function seedOrSyncConfig(projectRoot: string): void {\n const registry = new RulePackSelection().loadFrom(projectRoot);\n const configPath = path.join(projectRoot, CONFIG_FILENAME);\n if (!fs.existsSync(configPath)) {\n writeConfig(configPath, buildSeedConfig(registry));\n console.log(` [ai-hooks] Created ${CONFIG_FILENAME} (rules / hookGuards / commands); each rule seeded at its recommended mode — gradual where supported, so only code you change is enforced.`);\n console.log(' Enable the ones you want by changing \"mode\".');\n return;\n }\n const result = migrate(readConfig(configPath), registry);\n if (result.changes.length === 0) {\n console.log(` [ai-hooks] ${CONFIG_FILENAME} already uses the rules / hookGuards / commands layout — no changes.`);\n return;\n }\n writeConfig(configPath, result.config);\n console.log(` [ai-hooks] Migrated ${CONFIG_FILENAME}:`);\n for (const change of result.changes) console.log(` - ${change}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"setup-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/setup-config.ts"],"names":[],"mappings":";;AAcA,4CA0BC;;AAxCD,oDAA8B;AAC9B,wDAAkC;AAClC,8DAAsE;AACtE,0DAOiC;AAEjC,kGAAkG;AAClG,gHAAgH;AAChH,SAAgB,gBAAgB,CAAC,WAAmB;IAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,8BAAe,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,8BAAa,CACnB,0NAA0N,CAC7N,CAAC;IACN,CAAC;IACD,MAAM,UAAU,GAAG,IAAI,yBAAU,EAAE,EAC/B,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,8BAAa,CACnB,kMAAkM,CACrM,CAAC;IACN,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,2BAAU,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,2BAAY,CAC5B,UAAU,EACV,IAAI,8BAAe,EAAE,EACrB,IAAI,gCAAiB,CAAC,MAAM,CAAC,EAC7B,MAAM,CACT,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,kCAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CACP,OAAO,CAAC,MAAM;QACV,CAAC,CAAC,8DAA8D,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACpF,CAAC,CAAC,+DAA+D,CACxE,CAAC;AACN,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { AtomicFile, InformAiError } from '@webpieces/tooling-common';\nimport {\n ConfigFile,\n CONFIG_FILENAME,\n PackPolicyFiles,\n RulePackArtifacts,\n RulePackSync,\n RulePackSyncOptions,\n} from '@webpieces/rules-config';\n\n/** Installation syncs declared owner files; flat roots require the explicit upgrade operation. */\n// webpieces-disable no-function-outside-class -- DI-free installer composition must work before hooks are wired\nexport function seedOrSyncConfig(projectRoot: string): void {\n const filename = path.join(projectRoot, CONFIG_FILENAME);\n if (!fs.existsSync(filename)) {\n throw new InformAiError(\n 'Create webpieces.config.json with explicit rulePacks, commands, excludePaths and match-rules, then run pnpm wp-rules-sync to write reviewed owner seeds. Installed packages are never inferred as selected policy packs.',\n );\n }\n const configFile = new ConfigFile(),\n raw = configFile.readRawConfig(filename);\n if (raw.rulePacks === undefined) {\n throw new InformAiError(\n 'The flat root config is retired. Run pnpm wp-rules-sync --upgrade with explicit --pack=<package>=<config.json> declarations, review the owner files and artifacts, then rerun hook installation.',\n );\n }\n const atomic = new AtomicFile();\n const changed = new RulePackSync(\n configFile,\n new PackPolicyFiles(),\n new RulePackArtifacts(atomic),\n atomic,\n ).run(projectRoot, new RulePackSyncOptions('sync', null));\n console.log(\n changed.length\n ? `[ai-hooks] Review explicit owner config/artifact changes:\\n${changed.join('\\n')}`\n : '[ai-hooks] Declared owner config and artifacts already agree.',\n );\n}\n"]}
|
package/src/bin/shim.js
CHANGED
|
@@ -268,10 +268,12 @@ case "\$TOOL" in
|
|
|
268
268
|
wp_log "\$WP_FAULT" ALLOW-IGNORED
|
|
269
269
|
exit 0 ;;
|
|
270
270
|
esac
|
|
271
|
+
# The same compiled Node probe is used by the live runner; it requires no installed package.
|
|
272
|
+
if printf '%s' "\$PAYLOAD" | node -e '${new rules_config_1.ConfigRepairBootstrap().callScript().replaceAll("'", "'\\''")}' "\$WP_CWD" >/dev/null 2>&1; then
|
|
273
|
+
wp_log "\$WP_FAULT" ALLOW-CONFIG
|
|
274
|
+
exit 0
|
|
275
|
+
fi
|
|
271
276
|
case "\$FILE" in
|
|
272
|
-
*/${rules_config_1.CONFIG_FILENAME}|${rules_config_1.CONFIG_FILENAME})
|
|
273
|
-
wp_log "\$WP_FAULT" ALLOW-CONFIG # the always-allowed recovery target — every guard is configured from it
|
|
274
|
-
exit 0 ;;
|
|
275
277
|
*/${rules_config_3.WORKSPACE_MANIFEST}|${rules_config_3.WORKSPACE_MANIFEST}|*/${rules_config_3.PACKAGE_MANIFEST}|${rules_config_3.PACKAGE_MANIFEST})
|
|
276
278
|
# A manifest AT THE ROOT OF A GOVERNED TREE, which is the only place the version pin lives. The test
|
|
277
279
|
# is the sibling ${rules_config_1.CONFIG_FILENAME} — TRACKED, so the main clone has one and every worktree has its
|
|
@@ -516,6 +518,7 @@ function healShim(cwd) {
|
|
|
516
518
|
return;
|
|
517
519
|
fs.writeFileSync(target, desired, { mode: 0o755 });
|
|
518
520
|
fs.chmodSync(target, 0o755);
|
|
521
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
519
522
|
}
|
|
520
523
|
catch (err) {
|
|
521
524
|
//const error = toError(err);
|
|
@@ -606,6 +609,7 @@ function committedShimStale(root = governingShimRoot()) {
|
|
|
606
609
|
if (root === null)
|
|
607
610
|
return false;
|
|
608
611
|
return fs.readFileSync(shimPath(root), 'utf8') !== renderShim();
|
|
612
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
609
613
|
}
|
|
610
614
|
catch (err) {
|
|
611
615
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -620,7 +624,9 @@ function committedShimStale(root = governingShimRoot()) {
|
|
|
620
624
|
// webpieces-disable no-function-outside-class -- pure predicate over the exported allowlist twins; belongs beside them in the shim module.
|
|
621
625
|
function isShimCureCommand(command) {
|
|
622
626
|
const cmd = command.trim();
|
|
623
|
-
return l0_allowlist_1.INSTALL_HOOKS_ALLOW_JS.test(cmd) ||
|
|
627
|
+
return (l0_allowlist_1.INSTALL_HOOKS_ALLOW_JS.test(cmd) ||
|
|
628
|
+
l0_allowlist_1.UPGRADE_SHIM_ALLOW_JS.test(cmd) ||
|
|
629
|
+
l0_allowlist_1.RESTORE_SHIM_ALLOW_JS.test(cmd));
|
|
624
630
|
}
|
|
625
631
|
// The installed @webpieces/agent-workflow-rules version, for shimStaleDenyReason's note. The binary IS this
|
|
626
632
|
// package, so it reads its OWN package.json (two dirs up from src/bin). Best-effort: '' on any failure,
|
|
@@ -631,6 +637,7 @@ function installedShimRulesVersion() {
|
|
|
631
637
|
try {
|
|
632
638
|
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8'));
|
|
633
639
|
return pkg.version ?? '';
|
|
640
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
634
641
|
}
|
|
635
642
|
catch (err) {
|
|
636
643
|
const error = (0, to_error_1.toError)(err);
|