@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/core/runner.js
CHANGED
|
@@ -18,6 +18,7 @@ const hook_runtime_6 = require("@webpieces/hook-runtime");
|
|
|
18
18
|
const excluded_path_escape_1 = require("./excluded-path-escape");
|
|
19
19
|
const force_to_root_1 = require("./force-to-root");
|
|
20
20
|
const load_rules_1 = require("./load-rules");
|
|
21
|
+
const workflow_hook_rules_1 = require("./workflow-hook-rules");
|
|
21
22
|
const missing_directory_1 = require("./missing-directory");
|
|
22
23
|
const main_sync_timeout_1 = require("./main-sync-timeout");
|
|
23
24
|
const decision_log_1 = require("./decision-log");
|
|
@@ -56,13 +57,6 @@ function filterByMode(rules, mode, registry) {
|
|
|
56
57
|
function effectiveBashCwd(command, cwd) {
|
|
57
58
|
return new hook_runtime_4.EffectiveTreeResolver().effectiveCwd(command, cwd);
|
|
58
59
|
}
|
|
59
|
-
// The resolved gated-command strings the PR-lifecycle guards print, straight off the loaded
|
|
60
|
-
// `commands.guardHints`. Handed to the rules at construction rather than injected into their config
|
|
61
|
-
// entries under guard-name literals — the injection this replaces could miss a rename silently.
|
|
62
|
-
// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
|
|
63
|
-
function guardHintsOf(loaded) {
|
|
64
|
-
return new load_rules_1.GuardHintCommands(loaded.commands.upsertPr, loaded.commands.mergeComplete);
|
|
65
|
-
}
|
|
66
60
|
// A git or gh invocation anywhere in the command (start, or after a ;/&&/|| separator or pipe).
|
|
67
61
|
const GIT_OR_GH_RE = /(?:^|[;&|]\s*)(?:git|gh)\b/;
|
|
68
62
|
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
@@ -89,6 +83,11 @@ function run(toolKind, input, cwd, mode = 'all') {
|
|
|
89
83
|
}
|
|
90
84
|
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
91
85
|
function runInternal(toolKind, input, cwd, mode) {
|
|
86
|
+
if (toolKind !== 'Delete' &&
|
|
87
|
+
(new rules_config_1.ConfigRepairAccess().isRepairFile(new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd), input.filePath) ||
|
|
88
|
+
(0, hook_runtime_8.isRootManifest)(input.filePath) ||
|
|
89
|
+
new rules_config_1.HomeConfigService().isHomeConfigPath(input.filePath)))
|
|
90
|
+
return null;
|
|
92
91
|
const loaded = (0, rules_config_1.loadAndValidate)(cwd);
|
|
93
92
|
if (loaded.configPath === null)
|
|
94
93
|
return configMissingBlock(cwd);
|
|
@@ -103,12 +102,13 @@ function runInternal(toolKind, input, cwd, mode) {
|
|
|
103
102
|
// it. isRootManifest, never a basename: this returns EARLY, so basename would unrule every
|
|
104
103
|
// package.json in the repo. It admits any tree's root (the config sits beside it), which is what a
|
|
105
104
|
// worktree's own cure needs — the same tree `workspaceRoot` above already names.
|
|
106
|
-
if ((0, hook_runtime_8.isRootManifest)(input.filePath) ||
|
|
105
|
+
if ((0, hook_runtime_8.isRootManifest)(input.filePath) ||
|
|
106
|
+
new rules_config_1.HomeConfigService().isHomeConfigPath(input.filePath)) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
109
|
// Built-in/custom rules PLUS the client-authored match-rules (content guards). Match-rules run only
|
|
110
110
|
// in the file-edit path (they are code-style, so filterByMode keeps them out of the bash/guards path).
|
|
111
|
-
const allRules = [...
|
|
111
|
+
const allRules = [...new workflow_hook_rules_1.WorkflowHookRules().load(loaded).rules];
|
|
112
112
|
const modeRules = filterByMode(allRules, mode, loaded.ruleRegistry);
|
|
113
113
|
if (modeRules.length === 0)
|
|
114
114
|
return null;
|
|
@@ -120,11 +120,6 @@ function runInternal(toolKind, input, cwd, mode) {
|
|
|
120
120
|
const rules = new hook_runtime_3.DeleteScopedRules().narrow(toolKind, (0, hook_runtime_6.filterByExcludedPaths)(modeRules, governed, loaded.excludePaths));
|
|
121
121
|
if (rules.length === 0)
|
|
122
122
|
return null;
|
|
123
|
-
// Config-sync applies only to built-in/custom rules; match-rules have their own validated section
|
|
124
|
-
// (loadAndValidate already rejected an invalid `match-rules`), so they must not trip the sync nag.
|
|
125
|
-
const outOfSync = (0, hook_runtime_1.checkConfigSync)(rules, loaded.rulesConfig, loaded.ruleRegistry);
|
|
126
|
-
if (outOfSync)
|
|
127
|
-
return outOfSync;
|
|
128
123
|
const contexts = (0, hook_runtime_2.buildContexts)(toolKind, input, workspaceRoot, governed);
|
|
129
124
|
const editGroups = (0, hook_runtime_1.runEditRules)(rules, contexts.editContexts);
|
|
130
125
|
const fileGroups = (0, hook_runtime_1.runFileRules)(rules, contexts.fileContext);
|
|
@@ -167,7 +162,18 @@ function runRead(filePath, cwd, mode = 'all') {
|
|
|
167
162
|
// Code-style mode has nothing to say about a read.
|
|
168
163
|
if (mode === 'rules')
|
|
169
164
|
return null;
|
|
170
|
-
|
|
165
|
+
let loaded;
|
|
166
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- broken configuration must remain readable without enabling any mutating policy
|
|
167
|
+
try {
|
|
168
|
+
loaded = (0, rules_config_1.loadAndValidate)(cwd);
|
|
169
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
const error = (0, to_error_1.toError)(err);
|
|
173
|
+
if (error instanceof tooling_common_1.InformAiError)
|
|
174
|
+
return null;
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
171
177
|
// No config → nothing to enforce. Unlike the edit path we do NOT block: an unconfigured repo
|
|
172
178
|
// must still be readable.
|
|
173
179
|
if (loaded.configPath === null)
|
|
@@ -179,7 +185,7 @@ function runRead(filePath, cwd, mode = 'all') {
|
|
|
179
185
|
return null;
|
|
180
186
|
const governed = new hook_runtime_5.TargetTreeResolver().governedPath(filePath, workspaceRoot);
|
|
181
187
|
const relativePath = governed.relativePath;
|
|
182
|
-
const all =
|
|
188
|
+
const all = new workflow_hook_rules_1.WorkflowHookRules().load(loaded).rules;
|
|
183
189
|
const rules = (0, hook_runtime_6.filterByExcludedPaths)(all.filter((r) => READ_SCOPED_GUARDS.has(r.name)), governed, loaded.excludePaths);
|
|
184
190
|
if (rules.length === 0)
|
|
185
191
|
return null;
|
|
@@ -250,6 +256,7 @@ function loadConfigOrAllowInspection(command, cwd) {
|
|
|
250
256
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- rethrown unchanged unless the command is provably inert
|
|
251
257
|
try {
|
|
252
258
|
return (0, rules_config_1.loadAndValidate)(cwd);
|
|
259
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
253
260
|
}
|
|
254
261
|
catch (err) {
|
|
255
262
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -399,26 +406,17 @@ function runBashInternal(command, cwd, mode, aiType) {
|
|
|
399
406
|
// ONE resolver answers this for the guards AND for force-to-root below, so the two can never
|
|
400
407
|
// disagree about which tree you are in.
|
|
401
408
|
const tree = new hook_runtime_4.EffectiveTreeResolver().resolve(command, cwd, workspaceRoot);
|
|
402
|
-
|
|
403
|
-
// webpieces.config governs (e.g. a clone under repositories/). Out of scope → allow, hands-off.
|
|
404
|
-
// Intentional, not a silent hole. A LINKED WORKTREE of this repo is deliberately NOT foreign — it
|
|
405
|
-
// is the same project, so the guards run against THAT tree's branch and cache.
|
|
406
|
-
if (tree.kind === 'foreign') {
|
|
407
|
-
(0, decision_log_1.logGuardDecision)(workspaceRoot, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(workspaceRoot), 'ALLOW_EXEMPT', 'foreign git repo (out of scope)', '-', rules_config_2.L0_FAULT_NONE, new decision_log_1.MatrixRef('L1', '1')));
|
|
409
|
+
if (allowForeignTree(command, tree, workspaceRoot))
|
|
408
410
|
return null;
|
|
409
|
-
}
|
|
410
411
|
// Honour excludePaths on the bash path too (not just Read/Edit): a command whose effective
|
|
411
412
|
// cwd sits under an excluded tree (e.g. repositories/**) drops the whole guard set — matching how
|
|
412
413
|
// runInternal/runRead treat file paths. The relative path is '' when there is no `cd` (root), which
|
|
413
414
|
// matches no exclusion glob, so a plain command at the repo root is unaffected.
|
|
414
415
|
const governedCwd = (0, hook_runtime_6.bashGovernedPath)(tree, workspaceRoot);
|
|
415
|
-
const rules = (0, hook_runtime_6.filterByExcludedPaths)(filterByMode(
|
|
416
|
+
const rules = (0, hook_runtime_6.filterByExcludedPaths)(filterByMode(new workflow_hook_rules_1.WorkflowHookRules().load(loaded).rules, mode, loaded.ruleRegistry), governedCwd, loaded.excludePaths);
|
|
416
417
|
const keyless = keylessBashRules(loaded, mode, governedCwd);
|
|
417
418
|
if (rules.length === 0 && keyless.length === 0)
|
|
418
419
|
return null;
|
|
419
|
-
const outOfSync = (0, hook_runtime_1.checkConfigSync)(rules, loaded.rulesConfig, loaded.ruleRegistry); // fault Y — L0 list wins, as under C
|
|
420
|
-
if (outOfSync)
|
|
421
|
-
return l0FaultAllows(command, aiType) ? null : outOfSync;
|
|
422
420
|
const locationBlock = l1LocationBlock(command, tree, aiType);
|
|
423
421
|
if (locationBlock)
|
|
424
422
|
return locationBlock;
|
|
@@ -429,21 +427,7 @@ function runBashInternal(command, cwd, mode, aiType) {
|
|
|
429
427
|
// Keyed on the JUDGED tree, so a worktree's cache is refreshed rather than the primary clone's.
|
|
430
428
|
(0, main_sync_timeout_1.maybeRefreshMainSync)(rules, tree.root, (0, main_sync_timeout_1.branchStateHangTimeout)(loaded.rulesConfig));
|
|
431
429
|
const groups = (0, hook_runtime_1.runBashRules)([...rules, ...keyless], (0, hook_runtime_2.buildBashContext)(command, tree));
|
|
432
|
-
|
|
433
|
-
// Record the ALLOW only for git/gh commands — the operations the bash guards actually reason
|
|
434
|
-
// about (branch create, commit, push, merge, PR). Skipping ls/cat/grep keeps the audit log
|
|
435
|
-
// focused (the whole point of the log is "why did/didn't a guard fire?"). Blocks are always
|
|
436
|
-
// logged below.
|
|
437
|
-
if (/\b(?:git|gh)\b/.test(command)) {
|
|
438
|
-
(0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'ALLOW', 'no bash-guard block', '-', rules_config_2.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
|
|
439
|
-
}
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
const ruleNames = groups.map((g) => g.ruleName).join(',');
|
|
443
|
-
(0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision(ruleNames, 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'BLOCK_AI_CURE', 'bash-guard block', '-', rules_config_2.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
|
|
444
|
-
const report = new excluded_path_escape_1.ExcludedPathEscapeHint(workspaceRoot, tree.effectiveCwd).render(command, loaded.excludePaths)
|
|
445
|
-
+ (0, hook_runtime_7.formatReport)(commandLabel(command), groups, hook_runtime_7.BASH_SUBJECT) + exemptTreesHint(groups, loaded.excludePaths.paths);
|
|
446
|
-
return new hook_runtime_9.BlockedResult(report);
|
|
430
|
+
return bashPolicyResult(command, tree, loaded, groups);
|
|
447
431
|
}
|
|
448
432
|
// The bash report's subject line. It used to be the literal string `<bash>`, which told the agent
|
|
449
433
|
// nothing; the command itself is what was blocked, so name it — truncated, because a heredoc-bearing
|
|
@@ -472,11 +456,39 @@ function exemptTreesHint(groups, exemptGuards) {
|
|
|
472
456
|
return '';
|
|
473
457
|
if (!groups.some((g) => g.ruleName === 'pr-creation-or-push-guard'))
|
|
474
458
|
return '';
|
|
475
|
-
return `\n\nℹ️ Working in a nested repo under one of these exempt trees (${exemptGuards.join(', ')})? `
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
459
|
+
return (`\n\nℹ️ Working in a nested repo under one of these exempt trees (${exemptGuards.join(', ')})? ` +
|
|
460
|
+
`Put a LITERAL \`cd\` at the FRONT of the SAME command — \`cd /abs/path/to/repo && git push\` — and git/gh ` +
|
|
461
|
+
`run normally there: the webpieces guards do NOT govern them (each is its own repo).` +
|
|
462
|
+
`\n \`cd <literal path> && <work>\` is the ONE shape that moves where a command is judged. A \`cd\` ` +
|
|
463
|
+
`anywhere else in the line, or a non-literal target like \`cd "$DIR"\`, is refused outright rather than ` +
|
|
464
|
+
`judged from somewhere you did not intend.`);
|
|
465
|
+
}
|
|
466
|
+
// webpieces-disable no-function-outside-class -- runner result assembly is a pure orchestration helper
|
|
467
|
+
function bashPolicyResult(command, tree, loaded, groups) {
|
|
468
|
+
const workspaceRoot = path.dirname(loaded.configPath);
|
|
469
|
+
if (groups.length === 0) {
|
|
470
|
+
// Record the ALLOW only for git/gh commands — the operations the bash guards actually reason
|
|
471
|
+
// about (branch create, commit, push, merge, PR). Skipping ls/cat/grep keeps the audit log
|
|
472
|
+
// focused (the whole point of the log is "why did/didn't a guard fire?"). Blocks are always
|
|
473
|
+
// logged below.
|
|
474
|
+
if (/\b(?:git|gh)\b/.test(command)) {
|
|
475
|
+
(0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'ALLOW', 'no bash-guard block', '-', rules_config_2.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
|
|
476
|
+
}
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
const ruleNames = groups.map((g) => g.ruleName).join(',');
|
|
480
|
+
(0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision(ruleNames, 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'BLOCK_AI_CURE', 'bash-guard block', '-', rules_config_2.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
|
|
481
|
+
const report = new excluded_path_escape_1.ExcludedPathEscapeHint(workspaceRoot, tree.effectiveCwd).render(command, loaded.excludePaths) +
|
|
482
|
+
(0, hook_runtime_7.formatReport)(commandLabel(command), groups, hook_runtime_7.BASH_SUBJECT) +
|
|
483
|
+
exemptTreesHint(groups, loaded.excludePaths.paths);
|
|
484
|
+
return new hook_runtime_9.BlockedResult(report);
|
|
485
|
+
}
|
|
486
|
+
// webpieces-disable no-function-outside-class -- orchestration helper for the explicit foreign-repository exemption
|
|
487
|
+
function allowForeignTree(command, tree, workspaceRoot) {
|
|
488
|
+
if (tree.kind === 'foreign') {
|
|
489
|
+
(0, decision_log_1.logGuardDecision)(workspaceRoot, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(workspaceRoot), 'ALLOW_EXEMPT', 'foreign git repo (out of scope)', '-', rules_config_2.L0_FAULT_NONE, new decision_log_1.MatrixRef('L1', '1')));
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
481
493
|
}
|
|
482
494
|
//# sourceMappingURL=runner.js.map
|
package/src/core/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/runner.ts"],"names":[],"mappings":";;AAmDA,4CAEC;AAaD,4CAEC;AAkBD,kBAOC;AAuED,0BAEC;AAmBD,0BA8BC;;AAvND,0DAAkH;AAClH,mDAA6B;AAE7B,0DAAwN;AAExN,0DAA0E;AAC1E,0DAA4D;AAC5D,iDAAkD;AAClD,0DAA+E;AAC/E,0DAA2E;AAC3E,0DAAkF;AAClF,iEAAgE;AAChE,mDAAqD;AACrD,6CAAkF;AAClF,2DAA4D;AAC5D,2DAAmF;AACnF,iDAAsJ;AACtJ,iEAA6D;AAC7D,0DAAmF;AACnF,iEAAgE;AAChE,sCAA0D;AAC1D,0DAAyD;AAEzD,0DAA8G;AAC9G,0DAA2F;AAC3F,2CAAsE;AACtE,uCAAkF;AAClF,mDAA4D;AAC5D,0DAAoK;AAEpK,8DAA0D;AAE1D,mGAAmG;AACnG,oGAAoG;AACpG,oGAAoG;AACpG,2BAA2B;AAC3B,oGAAoG;AACpG,2FAA2F;AAC3F,gGAAgG;AAChG,yFAAyF;AACzF,mKAAmK;AACnK,SAAS,YAAY,CAAC,KAAsB,EAAE,IAAc,EAAE,QAA0B;IACpF,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAO,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AAC,CAAC,IAAI,EAAE,CAAC;IACpD,MAAM,GAAG,GAAG,GAAG,CAAC;IAChB,OAAO,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AACzE,CAAC;AAED,wGAAwG;AACxG,wGAAwG;AACxG,sGAAsG;AACtG,yGAAyG;AACzG,qDAAqD;AACrD,EAAE;AACF,mGAAmG;AACnG,+FAA+F;AAC/F,kGAAkG;AAClG,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,qKAAqK;AACrK,SAAS,eAAe,CAAC,MAA4B,EAAE,YAA+B;IAClF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAY,EAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,2BAA2B,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnG,OAAO,qEAAqE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;UAClG,4GAA4G;UAC5G,qFAAqF;UACrF,uGAAuG;UACvG,yGAAyG;UACzG,2CAA2C,CAAC;AACtD,CAAC","sourcesContent":["import { checkConfigSync, runRuleCheck, runEditRules, runFileRules, runBashRules } from '@webpieces/hook-runtime';\nimport * as path from 'path';\n\nimport { loadAndValidate, LoadedConfig, RulePackRegistry, WebpiecesRulesConfig, isHookGuard, HomeConfigService, RepoRootFinder, seedEntryForRule, CONFIG_FILENAME, renderRuleFailForAi } from '@webpieces/rules-config';\n\nimport { buildContexts, buildBashContext } from '@webpieces/hook-runtime';\nimport { DeleteScopedRules } from '@webpieces/hook-runtime';\nimport { VersionSyncGuard } from './version-sync';\nimport { EffectiveTree, EffectiveTreeResolver } from '@webpieces/hook-runtime';\nimport { GovernedPath, TargetTreeResolver } from '@webpieces/hook-runtime';\nimport { bashGovernedPath, filterByExcludedPaths } from '@webpieces/hook-runtime';\nimport { ExcludedPathEscapeHint } from './excluded-path-escape';\nimport { gitFromSubdirBlock } from './force-to-root';\nimport { loadRules, loadKeylessBashRules, GuardHintCommands } from './load-rules';\nimport { missingDirectoryBlock } from './missing-directory';\nimport { branchStateHangTimeout, maybeRefreshMainSync } from './main-sync-timeout';\nimport { logGuardDecision, logL1Decision, GuardDecision, branchForLog, MatrixRef, Verdict, MATRIX_L0_ALLOW, MATRIX_L2_UNROWED } from './decision-log';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { formatReport, READ_SUBJECT, BASH_SUBJECT } from '@webpieces/hook-runtime';\nimport { ReadOnlyInspectionScan } from './read-only-inspection';\nimport { L0_CURE_ALLOW_JS, isAllowed } from '../bin/shim';\nimport { isRootManifest } from '@webpieces/hook-runtime';\nimport { AiType } from '@webpieces/hook-runtime';\nimport { L0_FAULT_CONFIG_MISSING, L0_FAULT_CONFIG_OUT_OF_SYNC, L0_FAULT_NONE } from '@webpieces/rules-config';\nimport { CONFIG_MISSING_REPORT, CONFIG_OUT_OF_SYNC_HEADER } from '@webpieces/rules-config';\nimport { writeGuardMatrixDoc, guardMatrixPointer } from './l0-matrix';\nimport { L1Classification, firstMatchingL1Row, L1_PRESTAGE_ROW } from './l1-rows';\nimport { withLocationMatrixPointer } from './l1-matrix-doc';\nimport { ToolKind, NormalizedToolInput, BlockedResult, HookMode, Rule, Violation, RuleGroup, EditContext, FileContext, BashContext } from '@webpieces/hook-runtime';\nimport { RuleFailError } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\n// Restrict loaded rules to the category this hook invocation runs. The two split hooks each pass a\n// disjoint category ('rules' = code-style, 'guards' = the hookGuards section); 'all' runs both (the\n// openclaw plugin adapter, a single before_tool_call hook). isHookGuard is the shared classifier in\n// @webpieces/rules-config.\n// isHookGuard is asked about the rule's CONFIG KEY, never its name. Since the collapse those differ\n// for every class behind a policy key — `feature-branch-guard` is a rule NAME whose key is\n// `branch-state-guard` — and asking about the name would classify all eight collapsed guards as\n// code-style rules, i.e. run them in the wrong hook and never in the guards hook at all.\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction filterByMode(rules: readonly Rule[], mode: HookMode, registry: RulePackRegistry): readonly Rule[] {\n if (mode === 'all') return rules;\n if (mode === 'guards') return rules.filter((r: Rule): boolean => isHookGuard(r.configKey, registry));\n return rules.filter((r: Rule): boolean => !isHookGuard(r.configKey, registry));\n}\n\n// The cwd a command actually runs from, after its own leading `cd`/`pushd` run. Thin delegate kept\n// for the callers (and specs) that only need the directory; the full tree classification — primary\n// clone vs linked worktree vs nested clone vs outside any repo — is EffectiveTreeResolver.resolve().\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nexport function effectiveBashCwd(command: string, cwd: string): string {\n return new EffectiveTreeResolver().effectiveCwd(command, cwd);\n}\n\n// The resolved gated-command strings the PR-lifecycle guards print, straight off the loaded\n// `commands.guardHints`. Handed to the rules at construction rather than injected into their config\n// entries under guard-name literals — the injection this replaces could miss a rename silently.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction guardHintsOf(loaded: LoadedConfig): GuardHintCommands {\n return new GuardHintCommands(loaded.commands.upsertPr, loaded.commands.mergeComplete);\n}\n\n// A git or gh invocation anywhere in the command (start, or after a ;/&&/|| separator or pipe).\nconst GIT_OR_GH_RE = /(?:^|[;&|]\\s*)(?:git|gh)\\b/;\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function isGitOrGhCommand(command: string): boolean {\n return GIT_OR_GH_RE.test(command);\n}\n\n// Fault C (webpieces.config.json missing) — the deny text lives in ./l0-matrix beside the rest of the\n// L0 fault table, so the message and the allowlist can never prescribe different cures. `cwd` is used\n// only to drop the matrix doc where the AI can read it (the config root does not exist yet here).\n//\n// THE ALLOWLIST ESCAPE IS THE CALLER'S (moved out 2026-09-01): behind an optional `command` it could\n// not see the harness, so the gated half of the list was unreachable under C while\n// CONFIG_MISSING_REPORT promised it. See l0FaultAllows. This has one job now: build the block.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction configMissingBlock(cwd: string): BlockedResult {\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n // Stamped with its L0 letter so the block is greppable as fault C wherever it is recorded — the\n // adapter carries it to the audit line rather than re-deriving it from the report text.\n return new BlockedResult(CONFIG_MISSING_REPORT + guardMatrixPointer(writeGuardMatrixDoc(root)), L0_FAULT_CONFIG_MISSING);\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function run(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n mode: HookMode = 'all',\n): BlockedResult | null {\n return runInternal(toolKind, input, cwd, mode);\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction runInternal(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n mode: HookMode,\n): BlockedResult | null {\n const loaded = loadAndValidate(cwd);\n if (loaded.configPath === null) return configMissingBlock(cwd);\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // Always allow edits to webpieces.config.json — it's the fix target when out of sync\n if (path.resolve(input.filePath) === path.resolve(loaded.configPath)) {\n return null;\n }\n\n // …and the same PASS for the machine-local `~/.webpieces/config.json` (a bad key there fails a `wp-*`\n // command with an instruction to edit it, so blocking the edit would wedge the agent inside the\n // failure) and for the two ROOT MANIFESTS a pin lives in — L1 row 8 PROMISED that edit and its cure IS\n // it. isRootManifest, never a basename: this returns EARLY, so basename would unrule every\n // package.json in the repo. It admits any tree's root (the config sits beside it), which is what a\n // worktree's own cure needs — the same tree `workspaceRoot` above already names.\n if (isRootManifest(input.filePath) || new HomeConfigService().isHomeConfigPath(input.filePath)) {\n return null;\n }\n\n // Built-in/custom rules PLUS the client-authored match-rules (content guards). Match-rules run only\n // in the file-edit path (they are code-style, so filterByMode keeps them out of the bash/guards path).\n const allRules = [...loadRules(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded))];\n const modeRules = filterByMode(allRules, mode, loaded.ruleRegistry);\n if (modeRules.length === 0) return null;\n\n // Suppress enforcement for files under this category's excludePaths (e.g. vendored repos under\n // repositories/**). Exclusion is all-or-nothing per category, so an excluded file drops the whole\n // rule set and is fully hands-off — no violations AND no config-sync nag on those files.\n const governed = new TargetTreeResolver().governedPath(input.filePath, workspaceRoot);\n const relativePath = governed.relativePath;\n const rules = new DeleteScopedRules().narrow(toolKind, filterByExcludedPaths(modeRules, governed, loaded.excludePaths));\n if (rules.length === 0) return null;\n\n // Config-sync applies only to built-in/custom rules; match-rules have their own validated section\n // (loadAndValidate already rejected an invalid `match-rules`), so they must not trip the sync nag.\n const outOfSync = checkConfigSync(rules, loaded.rulesConfig, loaded.ruleRegistry);\n if (outOfSync) return outOfSync;\n\n const contexts = buildContexts(toolKind, input, workspaceRoot, governed);\n\n const editGroups = runEditRules(rules, contexts.editContexts);\n const fileGroups = runFileRules(rules, contexts.fileContext);\n const allGroups = [...editGroups, ...fileGroups];\n\n if (allGroups.length === 0) return null;\n\n const report = formatReport(relativePath, allGroups);\n return new BlockedResult(report);\n}\n\n// SINGLETON, deliberately: WebpiecesVersions memoizes per root, and the same two roots are asked for on\n// every Bash call. A fresh instance per call would spawn `git worktree list` and re-read two manifests\n// on the hook's blocking path each time.\nconst VERSION_SYNC = new VersionSyncGuard();\n\n// There is deliberately NO agent parameter. It existed only for CoordinatorWorktreeGuard, which asked\n// WHO was calling; that guard is gone and its replacement asks WHICH TREE the command acts on. Agent\n// identity was measured untrustworthy for that question anyway — a worktree-isolated agent auto-reaped\n// at a turn boundary silently resumes with its cwd on the primary clone — so a guard must never infer\n// a tree from who is asking.\n// webpieces-disable no-function-outside-class -- sibling of run()/runRead() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nexport function runBash(command: string, cwd: string, mode: HookMode, aiType: AiType): BlockedResult | null {\n return runBashInternal(command, cwd, mode, aiType);\n}\n\n// The name of the ONLY rule permitted to block a Read. Reads are the highest-blast-radius tool\n// there is, so this path is an explicit single-rule allowlist rather than the general rule loop.\nconst READ_SCOPED_GUARDS: ReadonlySet<string> = new Set(['read-stale-guard']);\n\n/**\n * The Read path. Deliberately NOT `run()`:\n *\n * - NO config-sync check. A rule present in code but missing from webpieces.config.json blocks\n * every Write/Edit/Bash by design — but applying that to Read would mean an upgrade that adds\n * any new rule instantly blocks the agent from reading the very config file it must edit to fix\n * it. Reads must never carry that failure mode.\n * - NO general rule loop. Only READ_SCOPED_GUARDS run, so no code-style rule can ever see a Read.\n * - Fails OPEN everywhere, including on a thrown rule (the caller catches and allows).\n *\n * Returns null (allow) unless the one guard fires.\n */\n// webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nexport function runRead(filePath: string, cwd: string, mode: HookMode = 'all'): BlockedResult | null {\n // Code-style mode has nothing to say about a read.\n if (mode === 'rules') return null;\n\n const loaded = loadAndValidate(cwd);\n // No config → nothing to enforce. Unlike the edit path we do NOT block: an unconfigured repo\n // must still be readable.\n if (loaded.configPath === null) return null;\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // Same git-repo-boundary governance as bash, through the SAME resolver: a read inside a different\n // clone is out of scope. (No command to parse here, so the shell cwd IS the effective cwd.)\n if (new EffectiveTreeResolver().resolve('', cwd, workspaceRoot).kind === 'foreign') return null;\n\n const governed = new TargetTreeResolver().governedPath(filePath, workspaceRoot);\n const relativePath = governed.relativePath;\n const all = loadRules(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded));\n const rules = filterByExcludedPaths(\n all.filter((r: Rule): boolean => READ_SCOPED_GUARDS.has(r.name)),\n governed,\n loaded.excludePaths,\n );\n if (rules.length === 0) return null;\n\n const ctx = new FileContext('Read', filePath, relativePath, workspaceRoot, 0, 0, 0, 0);\n const groups = runFileRules(rules, ctx);\n if (groups.length === 0) return null;\n\n return new BlockedResult(formatReport(relativePath, groups, READ_SUBJECT));\n}\n\n// L0 cure bypass — every command on THE L0 allowlist passes here, ahead of any config load. A\n// webpieces.config.json that is ahead of the installed validator (new rule tokens the published\n// binary doesn't know yet) makes loadAndValidate() throw and would deny `pnpm install` — the very\n// command that updates the validator (deadlock).\n//\n// This used to test INSTALLER_ALLOW_JS alone, which made the config faults (C = config missing,\n// Y = config out of sync) accept a bare `pnpm install` while denying `rm -rf node_modules && pnpm\n// install` — the one cure that works when node_modules is CORRUPT rather than merely stale. Same\n// intent, opposite verdict, for no reason anyone recorded. Each alternative is still anchored at both\n// ends, so `pnpm install && rm -rf /` still falls to the guards.\n//\n// It tests the CURE subset (L0_CURE_ALLOW_JS), not the whole list, and the distinction matters here\n// and nowhere else: this call site runs BEFORE any fault has been established, so whatever it accepts\n// is waved past the L1 guards on a perfectly healthy repo too. A repair command has to be waved past —\n// it runs before the config can be loaded at all. Read-only ORIENTATION does not: it fixes nothing, and\n// letting `git status` through here would delete force-to-root as a side effect of adding `pwd`. Under\n// an actual fault, l0FaultAllows() below consults the WHOLE list.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction isL0CureCommand(command: string): boolean {\n return L0_CURE_ALLOW_JS.test(command.trim());\n}\n\n// The FULL L0 list, asked only where this file has actually detected an L0 fault (C = config missing,\n// Y = config out of sync). D/X/U/K are decided in the shim, which greps the same union.\n// IT ASKS `isAllowed()`, not a regex: that is the ONE question both halves of L0 ask, and the only\n// place harness-gated entries are consulted. Testing `L0_ALLOW_JS` directly (which is what this did)\n// dropped the Codex read under C and Y while D/X/U/K honoured it — a per-fault carve-out again.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l0FaultAllows(command: string, aiType: AiType): boolean {\n return isAllowed('Bash', command.trim(), '', aiType) !== null;\n}\n\n// The L0 cure bypass's audit line. Anchored at the repo root that owns `.webpieces` — RepoRootFinder\n// (config-walk-up first, then git toplevel) is the authority for that, and it is correct in a linked\n// worktree because each worktree checks out its own webpieces.config.json. This runs BEFORE\n// loadAndValidate, which is why it resolves the root itself rather than using workspaceRoot.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction logL0CureBypass(command: string, cwd: string): void {\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n logGuardDecision(root, new GuardDecision('-', 'Bash', command, branchForLog(root), 'ALLOW', 'L0 cure bypass (always allowed)', '-', L0_FAULT_NONE, MATRIX_L0_ALLOW));\n}\n\n/**\n * Load the config for the bash path — but do NOT let an unloadable config trap the tools needed to\n * repair it.\n *\n * loadAndValidate throws an InformAiError when webpieces.config.json is unparseable (a real syntax\n * error, or leftover `<<<<<<< HEAD` markers mid-merge) or fails validation. That throw propagates to\n * the hook adapter, which fails CLOSED and denies the command — correct for work, since a config that\n * did not load means no guards ran. But it denied `cat`/`grep`/`sed -n` on webpieces.config.json too,\n * i.e. it blocked the only way to see the problem it was reporting. Observed live, twice.\n *\n * So: on a load failure, a provably-inert INSPECTION command is allowed through (returns null, \"no\n * block\"), matching the escape hatch every other layer already grants this file. Everything else —\n * every write, every git/gh command, every build — still hits the same hard failure as before. The\n * bypass cannot be widened by accident; see ReadOnlyInspectionScan for how narrow \"inert\" is.\n *\n * Returns the loaded config, or null meaning \"allow this command without guards\".\n */\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction loadConfigOrAllowInspection(command: string, cwd: string): LoadedConfig | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- rethrown unchanged unless the command is provably inert\n try {\n return loadAndValidate(cwd);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof InformAiError && new ReadOnlyInspectionScan().isReadOnlyInspection(command)) {\n return null;\n }\n throw error;\n }\n}\n\n// Version skew: this worktree pins a different @webpieces than the MAIN tree that governs it. The guard\n// hooks are absolute, so the main tree's binary judges every tree — which is fine until the two trees\n// disagree about which release that should be. L1 row 8; guards/L1-location.md carries the table.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction versionSkewBlock(command: string, tree: EffectiveTree, aiType: AiType): BlockedResult | null {\n const report = VERSION_SYNC.block(command, tree, aiType);\n return report === null ? null : new BlockedResult(report);\n}\n\n// Where the command lands in L1's five dimensions (K/A/R/G/P). The ONE place the runner's view of the\n// world is translated into the matrix's vocabulary — see L1Classification.forEnforcement for why\n// TreeKind 'outside' currently classifies as `p`.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l1Classify(command: string, tree: EffectiveTree): L1Classification {\n return L1Classification.forEnforcement(\n tree.kind,\n VERSION_SYNC.skewed(tree),\n new ReadOnlyInspectionScan().isReadOnlyInspection(command),\n isGitOrGhCommand(command),\n path.resolve(tree.effectiveCwd) === path.resolve(tree.root),\n );\n}\n\n// The structural L1 blocks, in order: the misplaced-`cd` PRE-STAGE, then version skew (row 8), then\n// force-to-root (row 5). None is a configurable rule — they are decided from the command text, the\n// resolved tree and the caller, so they run as one step here rather than as three near-identical\n// stanzas in runBashInternal.\n//\n// For the two TREE-BASED blocks the ORDER and the CHOICE are not written here: they come from L1_ROWS\n// (l1-rows.ts), the same array guards/L1-location.md is rendered from. Classify, take the first\n// matching row, dispatch on its blockId — so a row deleted from the array is a block that stops firing,\n// and the doc cannot describe a table the guard does not consult. The two report builders below still\n// own their own predicates and their deny strings; l1-matrix.spec.ts asserts the row lookup and those\n// predicates agree.\n//\n// misplacedCdBlock is deliberately OUTSIDE that lookup, and runs ahead of it, for the reason its own\n// docblock gives: it decides from command TEXT, before a tree has been resolved, and the other two\n// reason FROM the resolved tree. Classifying it would mean asking L1_ROWS a question whose answer the\n// classification itself depends on. It is the same shape as L2's `bareCheckoutOfMain` pre-stage. It is\n// therefore ROW 0 — \"pre-stage, decided from command text\" — rather than a row among 1-6, which keeps\n// it IN the table (the drift this table exists to prevent) without pretending it is classified over the\n// same five dimensions. `L1_PRESTAGE_ROW` is the number the doc prints and `row=` logs, so the two join.\n//\n// THIS FUNCTION IS THE ONE PLACE L1 REPORTS. It is the only scope holding the classification, the\n// matched row, the resolved tree and the agent at once — so logging here, BEFORE the early return,\n// is what finally records the outcomes that were previously invisible: the exempt row and the three\n// hand-downs wrote nothing at all, which is why \"L1 had no objection\" could not be observed and\n// \"show me every L1 decision\" had no answer. The three block helpers no longer log for themselves —\n// and, for the same reason, none of them knows about the matrix POINTER either: every deny is stamped\n// with it HERE, from the same scope and the same row number, so deny and log line cannot disagree.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l1LocationBlock(command: string, tree: EffectiveTree, aiType: AiType): BlockedResult | null {\n const misplacedCd = misplacedCdBlock(command, tree);\n if (misplacedCd !== null) {\n logL1(tree, command, 'BLOCK_AI_CURE', L1_PRESTAGE_ROW, 'cd-must-be-first', 'cd not leading/literal');\n return withLocationMatrixPointer(misplacedCd, tree.root, L1_PRESTAGE_ROW);\n }\n\n const row = firstMatchingL1Row(l1Classify(command, tree));\n const rowNum = String(row.num);\n if (row.blockId === null) {\n // ALLOW_EXEMPT stops here; ALLOW means \"no objection, handed down to L2\". Recording the\n // difference is the point — see Verdict. Neither claims the call RAN: the other parallel hook\n // may still have denied it.\n logL1(tree, command, row.action.kind === 'exempt' ? 'ALLOW_EXEMPT' : 'ALLOW', rowNum, '-', row.why);\n return null;\n }\n logL1(tree, command, 'BLOCK_AI_CURE', rowNum, row.blockId, row.why);\n if (row.blockId === 'missing-directory') return withLocationMatrixPointer(missingDirectoryBlock(command, tree), tree.root, rowNum);\n if (row.blockId === 'trinary-version-skew') return withLocationMatrixPointer(versionSkewBlock(command, tree, aiType), tree.root, rowNum);\n return withLocationMatrixPointer(gitFromSubdirBlock(command, tree, isGitOrGhCommand(command)), tree.root, rowNum);\n}\n\n// One L1 line, into L1's OWN stream. `row` is the number the generated doc prints, so a reader who sees\n// `row=5` can open the L1 matrix at row 5 — the deny for that same call names it by absolute path.\n// eslint-disable-next-line @typescript-eslint/max-params -- the six fields of one log line, and a class here would break this file's shape\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions\nfunction logL1(tree: EffectiveTree, command: string, verdict: Verdict, row: string, rule: string, why: string): void {\n logL1Decision(tree.root, new GuardDecision(\n rule, 'Bash', command, branchForLog(tree.root), verdict, why, '-', L0_FAULT_NONE, new MatrixRef('L1', row),\n ));\n}\n\n/**\n * ONE legal shape for relocating a command: `cd <literal path> && <work>`. Anything else — a `cd` after\n * another command or after a `VAR=…` assignment, or a `cd \"$DIR\"` the guard cannot expand — is refused\n * here instead of being silently judged from the shell cwd.\n *\n * This changes no verdict: every command it refuses was ALREADY judged from the shell cwd, so nothing\n * it blocks was previously being allowed on the strength of its `cd`. What changes is that the agent\n * finds out. Two PRs of increasingly precise near-miss wording (#596, #597) still left the fact in a\n * paragraph appended to an unrelated block; the rule is simpler stated as a rule.\n *\n * FIRST in the L1 chain deliberately. version skew and force-to-root both reason from the\n * resolved tree, and if the `cd` did not resolve, that tree is not the one the agent thinks they are\n * in — so their remedies would be steering from a location the command does not actually run in.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole runner is module-scope functions\nfunction misplacedCdBlock(command: string, tree: EffectiveTree): BlockedResult | null {\n const reason = new EffectiveTreeResolver().misplacedCd(command);\n if (reason === null) return null;\n const report =\n `❌ A \\`cd\\` must come FIRST in the command, with a LITERAL path.\\n` +\n ` Why this one was rejected: ${reason}.\\n` +\n ` \\`cd <literal path> && <work>\\` is the ONE shape that moves where webpieces judges a command.\\n` +\n ` Any other \\`cd\\` cannot be resolved, so the command would be judged against ${tree.root}\\n` +\n ` — not where you think it runs. That used to happen silently; this block is that silence, spoken.\\n` +\n ` Fix Option 1: put the \\`cd\\` first, literal path, SAME command: cd /abs/path && <the rest>\\n` +\n ` Fix Option 2: drop the \\`cd\\` — ${tree.root} is where the command is judged anyway.\\n` +\n ` Fix Option 3: if the SECOND \\`cd\\` was there to point a tool at a directory, use that tool's own\\n` +\n ` directory flag instead — \\`git -C <dir>\\`, \\`tar -C <dir>\\`, \\`npm --prefix <dir>\\`,\\n` +\n ` \\`npm pack --pack-destination <dir>\\`, \\`pnpm --dir <dir>\\`. One \\`cd\\`, same result.\\n` +\n ` ONLY for a dir INSIDE this tree. \\`git -C <another tree>\\` is REFUSED to a subagent,\\n` +\n ` and is never the cure for a version skew — for that, tell the MAIN agent.\\n` +\n ` Fix Option 4: split it — run the work in one call, the \\`cd\\` in another (a \\`cd\\` alone still\\n` +\n ` moves nothing the guards judge; see EffectiveTree on why cwd cannot be assumed).`;\n return new BlockedResult(report);\n}\n\n/**\n * The KEYLESS bash guards, deliberately kept OUT of the config-driven rule set. They have no\n * webpieces.config.json entry at all, so passing them through checkConfigSync would make every\n * consumer's next Bash call a fault-Y block (\"this rule has no entry\") for a feature nobody opted into\n * — which is exactly what whole-repo-build-guard did on its first release. Each one decides for itself\n * whether it acts: whole-repo-build-guard reads ~/.webpieces/config.json for a machine-local OPT-IN\n * (absent means OFF); commit-message-substitution-guard and build-output-pipe-guard act unconditionally.\n * They still honour excludePaths, and they do not run in `rules` mode (code-style-only hook).\n */\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction keylessBashRules(loaded: LoadedConfig, mode: HookMode, governed: GovernedPath): readonly Rule[] {\n if (mode === 'rules') return [];\n return filterByExcludedPaths(\n loadKeylessBashRules(loaded.prGate.buildCommand), governed, loaded.excludePaths,\n );\n}\n\n// webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nfunction runBashInternal(command: string, cwd: string, mode: HookMode, aiType: AiType): BlockedResult | null {\n if (isL0CureCommand(command)) {\n logL0CureBypass(command, cwd);\n return null;\n }\n\n const loaded = loadConfigOrAllowInspection(command, cwd);\n // null = the config would not load AND this command only inspects → allow, see the helper.\n if (loaded === null) return null;\n if (loaded.configPath === null) return l0FaultAllows(command, aiType) ? null : configMissingBlock(cwd);\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // WHICH TREE does this command act on? Not the shell's cwd: a `cd` OUT of the workspace is reset\n // by the harness and one INSIDE it persists, so neither can be assumed (see EffectiveTree).\n // ONE resolver answers this for the guards AND for force-to-root below, so the two can never\n // disagree about which tree you are in.\n const tree = new EffectiveTreeResolver().resolve(command, cwd, workspaceRoot);\n\n // Git-repo-boundary governance: the command runs inside a DIFFERENT git repo than this\n // webpieces.config governs (e.g. a clone under repositories/). Out of scope → allow, hands-off.\n // Intentional, not a silent hole. A LINKED WORKTREE of this repo is deliberately NOT foreign — it\n // is the same project, so the guards run against THAT tree's branch and cache.\n if (tree.kind === 'foreign') {\n logGuardDecision(workspaceRoot, new GuardDecision('-', 'Bash', command, branchForLog(workspaceRoot), 'ALLOW_EXEMPT', 'foreign git repo (out of scope)', '-', L0_FAULT_NONE, new MatrixRef('L1', '1')));\n return null;\n }\n\n // Honour excludePaths on the bash path too (not just Read/Edit): a command whose effective\n // cwd sits under an excluded tree (e.g. repositories/**) drops the whole guard set — matching how\n // runInternal/runRead treat file paths. The relative path is '' when there is no `cd` (root), which\n // matches no exclusion glob, so a plain command at the repo root is unaffected.\n const governedCwd = bashGovernedPath(tree, workspaceRoot);\n const rules = filterByExcludedPaths(\n filterByMode(loadRules(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded)), mode, loaded.ruleRegistry), governedCwd, loaded.excludePaths,\n );\n const keyless = keylessBashRules(loaded, mode, governedCwd);\n if (rules.length === 0 && keyless.length === 0) return null;\n\n const outOfSync = checkConfigSync(rules, loaded.rulesConfig, loaded.ruleRegistry); // fault Y — L0 list wins, as under C\n if (outOfSync) return l0FaultAllows(command, aiType) ? null : outOfSync;\n\n const locationBlock = l1LocationBlock(command, tree, aiType);\n if (locationBlock) return locationBlock;\n\n // Keep the feature-branch-guard cache warm on EVERY command (not just Write/Edit): the AI runs\n // far more bash than edits, so refreshing here means the guard's next file-edit check reads a\n // fresh status. Detached + fire-and-forget — never blocks the command. Only when the guard is\n // loaded (guards/all mode) and enabled, so a project that opted out never triggers git fetches.\n // Keyed on the JUDGED tree, so a worktree's cache is refreshed rather than the primary clone's.\n maybeRefreshMainSync(rules, tree.root, branchStateHangTimeout(loaded.rulesConfig));\n\n const groups = runBashRules([...rules, ...keyless], buildBashContext(command, tree));\n if (groups.length === 0) {\n // Record the ALLOW only for git/gh commands — the operations the bash guards actually reason\n // about (branch create, commit, push, merge, PR). Skipping ls/cat/grep keeps the audit log\n // focused (the whole point of the log is \"why did/didn't a guard fire?\"). Blocks are always\n // logged below.\n if (/\\b(?:git|gh)\\b/.test(command)) {\n logGuardDecision(tree.root, new GuardDecision('-', 'Bash', command, branchForLog(tree.root), 'ALLOW', 'no bash-guard block', '-', L0_FAULT_NONE, MATRIX_L2_UNROWED));\n }\n return null;\n }\n\n const ruleNames = groups.map((g: RuleGroup): string => g.ruleName).join(',');\n logGuardDecision(tree.root, new GuardDecision(ruleNames, 'Bash', command, branchForLog(tree.root), 'BLOCK_AI_CURE', 'bash-guard block', '-', L0_FAULT_NONE, MATRIX_L2_UNROWED));\n const report = new ExcludedPathEscapeHint(workspaceRoot, tree.effectiveCwd).render(command, loaded.excludePaths)\n + formatReport(commandLabel(command), groups, BASH_SUBJECT) + exemptTreesHint(groups, loaded.excludePaths.paths);\n return new BlockedResult(report);\n}\n\n// The bash report's subject line. It used to be the literal string `<bash>`, which told the agent\n// nothing; the command itself is what was blocked, so name it — truncated, because a heredoc-bearing\n// command can run to thousands of characters and the violation lines already carry the detail.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction commandLabel(command: string): string {\n const oneLine = command.replace(/\\s+/g, ' ').trim();\n const MAX = 100;\n return oneLine.length <= MAX ? oneLine : oneLine.slice(0, MAX) + '…';\n}\n\n// When a push/PR block fires AND the config exempts vendored/nested trees, surface the escape hatch the\n// AI cannot otherwise discover: git/gh run UNGUARDED inside those trees if it cd's there first (each is\n// governed by its own repo, not this one). Scoped to pr-creation-or-push-guard — for the other guards\n// \"cd into an exempt tree\" is not the remedy — and emitted only when such trees are actually configured,\n// so a repo without exemptions never sees the noise.\n//\n// The hint MUST state the precondition, not just the remedy. \"cd into it first\" is true only for a\n// LITERAL cd at the FRONT of the same command; `D=…; cd \"$D\"; git push` lands in the identical\n// directory and does NOT relocate the verdict. That used to be silent, then a near-miss paragraph\n// appended here; it is now misplacedCdBlock, which refuses the command outright — so by the time this\n// footer is reached, any `cd` in the command is already known to be leading and literal. The wording\n// still states the shape, because this is where an agent LEARNS it, before writing the next command.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction exemptTreesHint(groups: readonly RuleGroup[], exemptGuards: readonly string[]): string {\n if (exemptGuards.length === 0) return '';\n if (!groups.some((g: RuleGroup): boolean => g.ruleName === 'pr-creation-or-push-guard')) return '';\n\n return `\\n\\nℹ️ Working in a nested repo under one of these exempt trees (${exemptGuards.join(', ')})? `\n + `Put a LITERAL \\`cd\\` at the FRONT of the SAME command — \\`cd /abs/path/to/repo && git push\\` — and git/gh `\n + `run normally there: the webpieces guards do NOT govern them (each is its own repo).`\n + `\\n \\`cd <literal path> && <work>\\` is the ONE shape that moves where a command is judged. A \\`cd\\` `\n + `anywhere else in the line, or a non-literal target like \\`cd \"$DIR\"\\`, is refused outright rather than `\n + `judged from somewhere you did not intend.`;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/runner.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AM,CAAC,YAAY,CACtB;QACD,IAAA,2BAAY,EAAC,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,2BAAY,CAAC;QACzD,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,IAAI,4BAAa,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED,oHAAoH;AACpH,SAAS,gBAAgB,CAAC,OAAe,EAAE,IAAmB,EAAE,aAAqB;IACjF,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC1B,IAAA,+BAAgB,EACZ,aAAa,EACb,IAAI,4BAAa,CACb,GAAG,EACH,MAAM,EACN,OAAO,EACP,IAAA,2BAAY,EAAC,aAAa,CAAC,EAC3B,cAAc,EACd,iCAAiC,EACjC,GAAG,EACH,4BAAa,EACb,IAAI,wBAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAC3B,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { runRuleCheck, runEditRules, runFileRules, runBashRules } from '@webpieces/hook-runtime';\nimport * as path from 'path';\n\nimport {\n loadAndValidate,\n LoadedConfig,\n ConfigRepairAccess,\n RulePackRegistry,\n WebpiecesRulesConfig,\n isHookGuard,\n HomeConfigService,\n RepoRootFinder,\n seedEntryForRule,\n CONFIG_FILENAME,\n renderRuleFailForAi,\n} from '@webpieces/rules-config';\n\nimport { buildContexts, buildBashContext } from '@webpieces/hook-runtime';\nimport { DeleteScopedRules } from '@webpieces/hook-runtime';\nimport { VersionSyncGuard } from './version-sync';\nimport { EffectiveTree, EffectiveTreeResolver } from '@webpieces/hook-runtime';\nimport { GovernedPath, TargetTreeResolver } from '@webpieces/hook-runtime';\nimport { bashGovernedPath, filterByExcludedPaths } from '@webpieces/hook-runtime';\nimport { ExcludedPathEscapeHint } from './excluded-path-escape';\nimport { gitFromSubdirBlock } from './force-to-root';\nimport { loadKeylessBashRules } from './load-rules';\nimport { WorkflowHookRules } from './workflow-hook-rules';\nimport { missingDirectoryBlock } from './missing-directory';\nimport { branchStateHangTimeout, maybeRefreshMainSync } from './main-sync-timeout';\nimport { logGuardDecision, logL1Decision, GuardDecision, branchForLog, MatrixRef, Verdict, MATRIX_L0_ALLOW, MATRIX_L2_UNROWED } from './decision-log';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { formatReport, READ_SUBJECT, BASH_SUBJECT } from '@webpieces/hook-runtime';\nimport { ReadOnlyInspectionScan } from './read-only-inspection';\nimport { L0_CURE_ALLOW_JS, isAllowed } from '../bin/shim';\nimport { isRootManifest } from '@webpieces/hook-runtime';\nimport { AiType } from '@webpieces/hook-runtime';\nimport { L0_FAULT_CONFIG_MISSING, L0_FAULT_CONFIG_OUT_OF_SYNC, L0_FAULT_NONE } from '@webpieces/rules-config';\nimport { CONFIG_MISSING_REPORT, CONFIG_OUT_OF_SYNC_HEADER } from '@webpieces/rules-config';\nimport { writeGuardMatrixDoc, guardMatrixPointer } from './l0-matrix';\nimport { L1Classification, firstMatchingL1Row, L1_PRESTAGE_ROW } from './l1-rows';\nimport { withLocationMatrixPointer } from './l1-matrix-doc';\nimport { ToolKind, NormalizedToolInput, BlockedResult, HookMode, Rule, Violation, RuleGroup, EditContext, FileContext, BashContext } from '@webpieces/hook-runtime';\nimport { RuleFailError } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\n// Restrict loaded rules to the category this hook invocation runs. The two split hooks each pass a\n// disjoint category ('rules' = code-style, 'guards' = the hookGuards section); 'all' runs both (the\n// openclaw plugin adapter, a single before_tool_call hook). isHookGuard is the shared classifier in\n// @webpieces/rules-config.\n// isHookGuard is asked about the rule's CONFIG KEY, never its name. Since the collapse those differ\n// for every class behind a policy key — `feature-branch-guard` is a rule NAME whose key is\n// `branch-state-guard` — and asking about the name would classify all eight collapsed guards as\n// code-style rules, i.e. run them in the wrong hook and never in the guards hook at all.\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction filterByMode(rules: readonly Rule[], mode: HookMode, registry: RulePackRegistry): readonly Rule[] {\n if (mode === 'all') return rules;\n if (mode === 'guards') return rules.filter((r: Rule): boolean => isHookGuard(r.configKey, registry));\n return rules.filter((r: Rule): boolean => !isHookGuard(r.configKey, registry));\n}\n\n// The cwd a command actually runs from, after its own leading `cd`/`pushd` run. Thin delegate kept\n// for the callers (and specs) that only need the directory; the full tree classification — primary\n// clone vs linked worktree vs nested clone vs outside any repo — is EffectiveTreeResolver.resolve().\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nexport function effectiveBashCwd(command: string, cwd: string): string {\n return new EffectiveTreeResolver().effectiveCwd(command, cwd);\n}\n\n// A git or gh invocation anywhere in the command (start, or after a ;/&&/|| separator or pipe).\nconst GIT_OR_GH_RE = /(?:^|[;&|]\\s*)(?:git|gh)\\b/;\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function isGitOrGhCommand(command: string): boolean {\n return GIT_OR_GH_RE.test(command);\n}\n\n// Fault C (webpieces.config.json missing) — the deny text lives in ./l0-matrix beside the rest of the\n// L0 fault table, so the message and the allowlist can never prescribe different cures. `cwd` is used\n// only to drop the matrix doc where the AI can read it (the config root does not exist yet here).\n//\n// THE ALLOWLIST ESCAPE IS THE CALLER'S (moved out 2026-09-01): behind an optional `command` it could\n// not see the harness, so the gated half of the list was unreachable under C while\n// CONFIG_MISSING_REPORT promised it. See l0FaultAllows. This has one job now: build the block.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction configMissingBlock(cwd: string): BlockedResult {\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n // Stamped with its L0 letter so the block is greppable as fault C wherever it is recorded — the\n // adapter carries it to the audit line rather than re-deriving it from the report text.\n return new BlockedResult(CONFIG_MISSING_REPORT + guardMatrixPointer(writeGuardMatrixDoc(root)), L0_FAULT_CONFIG_MISSING);\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function run(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n mode: HookMode = 'all',\n): BlockedResult | null {\n return runInternal(toolKind, input, cwd, mode);\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction runInternal(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n mode: HookMode,\n): BlockedResult | null {\n if (\n toolKind !== 'Delete' &&\n (new ConfigRepairAccess().isRepairFile(\n new RepoRootFinder().resolveRepoRoot(cwd),\n input.filePath,\n ) ||\n isRootManifest(input.filePath) ||\n new HomeConfigService().isHomeConfigPath(input.filePath))\n )\n return null;\n const loaded = loadAndValidate(cwd);\n if (loaded.configPath === null) return configMissingBlock(cwd);\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // Always allow edits to webpieces.config.json — it's the fix target when out of sync\n if (path.resolve(input.filePath) === path.resolve(loaded.configPath)) {\n return null;\n }\n\n // …and the same PASS for the machine-local `~/.webpieces/config.json` (a bad key there fails a `wp-*`\n // command with an instruction to edit it, so blocking the edit would wedge the agent inside the\n // failure) and for the two ROOT MANIFESTS a pin lives in — L1 row 8 PROMISED that edit and its cure IS\n // it. isRootManifest, never a basename: this returns EARLY, so basename would unrule every\n // package.json in the repo. It admits any tree's root (the config sits beside it), which is what a\n // worktree's own cure needs — the same tree `workspaceRoot` above already names.\n if (\n isRootManifest(input.filePath) ||\n new HomeConfigService().isHomeConfigPath(input.filePath)\n ) {\n return null;\n }\n\n // Built-in/custom rules PLUS the client-authored match-rules (content guards). Match-rules run only\n // in the file-edit path (they are code-style, so filterByMode keeps them out of the bash/guards path).\n const allRules = [...new WorkflowHookRules().load(loaded).rules];\n const modeRules = filterByMode(allRules, mode, loaded.ruleRegistry);\n if (modeRules.length === 0) return null;\n\n // Suppress enforcement for files under this category's excludePaths (e.g. vendored repos under\n // repositories/**). Exclusion is all-or-nothing per category, so an excluded file drops the whole\n // rule set and is fully hands-off — no violations AND no config-sync nag on those files.\n const governed = new TargetTreeResolver().governedPath(input.filePath, workspaceRoot);\n const relativePath = governed.relativePath;\n const rules = new DeleteScopedRules().narrow(\n toolKind,\n filterByExcludedPaths(modeRules, governed, loaded.excludePaths),\n );\n if (rules.length === 0) return null;\n\n const contexts = buildContexts(toolKind, input, workspaceRoot, governed);\n\n const editGroups = runEditRules(rules, contexts.editContexts);\n const fileGroups = runFileRules(rules, contexts.fileContext);\n const allGroups = [...editGroups, ...fileGroups];\n\n if (allGroups.length === 0) return null;\n\n const report = formatReport(relativePath, allGroups);\n return new BlockedResult(report);\n}\n\n// SINGLETON, deliberately: WebpiecesVersions memoizes per root, and the same two roots are asked for on\n// every Bash call. A fresh instance per call would spawn `git worktree list` and re-read two manifests\n// on the hook's blocking path each time.\nconst VERSION_SYNC = new VersionSyncGuard();\n\n// There is deliberately NO agent parameter. It existed only for CoordinatorWorktreeGuard, which asked\n// WHO was calling; that guard is gone and its replacement asks WHICH TREE the command acts on. Agent\n// identity was measured untrustworthy for that question anyway — a worktree-isolated agent auto-reaped\n// at a turn boundary silently resumes with its cwd on the primary clone — so a guard must never infer\n// a tree from who is asking.\n// webpieces-disable no-function-outside-class -- sibling of run()/runRead() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nexport function runBash(command: string, cwd: string, mode: HookMode, aiType: AiType): BlockedResult | null {\n return runBashInternal(command, cwd, mode, aiType);\n}\n\n// The name of the ONLY rule permitted to block a Read. Reads are the highest-blast-radius tool\n// there is, so this path is an explicit single-rule allowlist rather than the general rule loop.\nconst READ_SCOPED_GUARDS: ReadonlySet<string> = new Set(['read-stale-guard']);\n\n/**\n * The Read path. Deliberately NOT `run()`:\n *\n * - NO config-sync check. A rule present in code but missing from webpieces.config.json blocks\n * every Write/Edit/Bash by design — but applying that to Read would mean an upgrade that adds\n * any new rule instantly blocks the agent from reading the very config file it must edit to fix\n * it. Reads must never carry that failure mode.\n * - NO general rule loop. Only READ_SCOPED_GUARDS run, so no code-style rule can ever see a Read.\n * - Fails OPEN everywhere, including on a thrown rule (the caller catches and allows).\n *\n * Returns null (allow) unless the one guard fires.\n */\n// webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nexport function runRead(\n filePath: string,\n cwd: string,\n mode: HookMode = 'all',\n): BlockedResult | null {\n // Code-style mode has nothing to say about a read.\n if (mode === 'rules') return null;\n\n let loaded: LoadedConfig;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- broken configuration must remain readable without enabling any mutating policy\n try {\n loaded = loadAndValidate(cwd);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof InformAiError) return null;\n throw error;\n }\n // No config → nothing to enforce. Unlike the edit path we do NOT block: an unconfigured repo\n // must still be readable.\n if (loaded.configPath === null) return null;\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // Same git-repo-boundary governance as bash, through the SAME resolver: a read inside a different\n // clone is out of scope. (No command to parse here, so the shell cwd IS the effective cwd.)\n if (new EffectiveTreeResolver().resolve('', cwd, workspaceRoot).kind === 'foreign') return null;\n\n const governed = new TargetTreeResolver().governedPath(filePath, workspaceRoot);\n const relativePath = governed.relativePath;\n const all = new WorkflowHookRules().load(loaded).rules;\n const rules = filterByExcludedPaths(\n all.filter((r: Rule): boolean => READ_SCOPED_GUARDS.has(r.name)),\n governed,\n loaded.excludePaths,\n );\n if (rules.length === 0) return null;\n\n const ctx = new FileContext('Read', filePath, relativePath, workspaceRoot, 0, 0, 0, 0);\n const groups = runFileRules(rules, ctx);\n if (groups.length === 0) return null;\n\n return new BlockedResult(formatReport(relativePath, groups, READ_SUBJECT));\n}\n\n// L0 cure bypass — every command on THE L0 allowlist passes here, ahead of any config load. A\n// webpieces.config.json that is ahead of the installed validator (new rule tokens the published\n// binary doesn't know yet) makes loadAndValidate() throw and would deny `pnpm install` — the very\n// command that updates the validator (deadlock).\n//\n// This used to test INSTALLER_ALLOW_JS alone, which made the config faults (C = config missing,\n// Y = config out of sync) accept a bare `pnpm install` while denying `rm -rf node_modules && pnpm\n// install` — the one cure that works when node_modules is CORRUPT rather than merely stale. Same\n// intent, opposite verdict, for no reason anyone recorded. Each alternative is still anchored at both\n// ends, so `pnpm install && rm -rf /` still falls to the guards.\n//\n// It tests the CURE subset (L0_CURE_ALLOW_JS), not the whole list, and the distinction matters here\n// and nowhere else: this call site runs BEFORE any fault has been established, so whatever it accepts\n// is waved past the L1 guards on a perfectly healthy repo too. A repair command has to be waved past —\n// it runs before the config can be loaded at all. Read-only ORIENTATION does not: it fixes nothing, and\n// letting `git status` through here would delete force-to-root as a side effect of adding `pwd`. Under\n// an actual fault, l0FaultAllows() below consults the WHOLE list.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction isL0CureCommand(command: string): boolean {\n return L0_CURE_ALLOW_JS.test(command.trim());\n}\n\n// The FULL L0 list, asked only where this file has actually detected an L0 fault (C = config missing,\n// Y = config out of sync). D/X/U/K are decided in the shim, which greps the same union.\n// IT ASKS `isAllowed()`, not a regex: that is the ONE question both halves of L0 ask, and the only\n// place harness-gated entries are consulted. Testing `L0_ALLOW_JS` directly (which is what this did)\n// dropped the Codex read under C and Y while D/X/U/K honoured it — a per-fault carve-out again.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l0FaultAllows(command: string, aiType: AiType): boolean {\n return isAllowed('Bash', command.trim(), '', aiType) !== null;\n}\n\n// The L0 cure bypass's audit line. Anchored at the repo root that owns `.webpieces` — RepoRootFinder\n// (config-walk-up first, then git toplevel) is the authority for that, and it is correct in a linked\n// worktree because each worktree checks out its own webpieces.config.json. This runs BEFORE\n// loadAndValidate, which is why it resolves the root itself rather than using workspaceRoot.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction logL0CureBypass(command: string, cwd: string): void {\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n logGuardDecision(root, new GuardDecision('-', 'Bash', command, branchForLog(root), 'ALLOW', 'L0 cure bypass (always allowed)', '-', L0_FAULT_NONE, MATRIX_L0_ALLOW));\n}\n\n/**\n * Load the config for the bash path — but do NOT let an unloadable config trap the tools needed to\n * repair it.\n *\n * loadAndValidate throws an InformAiError when webpieces.config.json is unparseable (a real syntax\n * error, or leftover `<<<<<<< HEAD` markers mid-merge) or fails validation. That throw propagates to\n * the hook adapter, which fails CLOSED and denies the command — correct for work, since a config that\n * did not load means no guards ran. But it denied `cat`/`grep`/`sed -n` on webpieces.config.json too,\n * i.e. it blocked the only way to see the problem it was reporting. Observed live, twice.\n *\n * So: on a load failure, a provably-inert INSPECTION command is allowed through (returns null, \"no\n * block\"), matching the escape hatch every other layer already grants this file. Everything else —\n * every write, every git/gh command, every build — still hits the same hard failure as before. The\n * bypass cannot be widened by accident; see ReadOnlyInspectionScan for how narrow \"inert\" is.\n *\n * Returns the loaded config, or null meaning \"allow this command without guards\".\n */\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction loadConfigOrAllowInspection(command: string, cwd: string): LoadedConfig | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- rethrown unchanged unless the command is provably inert\n try {\n return loadAndValidate(cwd);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof InformAiError && new ReadOnlyInspectionScan().isReadOnlyInspection(command)) {\n return null;\n }\n throw error;\n }\n}\n\n// Version skew: this worktree pins a different @webpieces than the MAIN tree that governs it. The guard\n// hooks are absolute, so the main tree's binary judges every tree — which is fine until the two trees\n// disagree about which release that should be. L1 row 8; guards/L1-location.md carries the table.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction versionSkewBlock(command: string, tree: EffectiveTree, aiType: AiType): BlockedResult | null {\n const report = VERSION_SYNC.block(command, tree, aiType);\n return report === null ? null : new BlockedResult(report);\n}\n\n// Where the command lands in L1's five dimensions (K/A/R/G/P). The ONE place the runner's view of the\n// world is translated into the matrix's vocabulary — see L1Classification.forEnforcement for why\n// TreeKind 'outside' currently classifies as `p`.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l1Classify(command: string, tree: EffectiveTree): L1Classification {\n return L1Classification.forEnforcement(\n tree.kind,\n VERSION_SYNC.skewed(tree),\n new ReadOnlyInspectionScan().isReadOnlyInspection(command),\n isGitOrGhCommand(command),\n path.resolve(tree.effectiveCwd) === path.resolve(tree.root),\n );\n}\n\n// The structural L1 blocks, in order: the misplaced-`cd` PRE-STAGE, then version skew (row 8), then\n// force-to-root (row 5). None is a configurable rule — they are decided from the command text, the\n// resolved tree and the caller, so they run as one step here rather than as three near-identical\n// stanzas in runBashInternal.\n//\n// For the two TREE-BASED blocks the ORDER and the CHOICE are not written here: they come from L1_ROWS\n// (l1-rows.ts), the same array guards/L1-location.md is rendered from. Classify, take the first\n// matching row, dispatch on its blockId — so a row deleted from the array is a block that stops firing,\n// and the doc cannot describe a table the guard does not consult. The two report builders below still\n// own their own predicates and their deny strings; l1-matrix.spec.ts asserts the row lookup and those\n// predicates agree.\n//\n// misplacedCdBlock is deliberately OUTSIDE that lookup, and runs ahead of it, for the reason its own\n// docblock gives: it decides from command TEXT, before a tree has been resolved, and the other two\n// reason FROM the resolved tree. Classifying it would mean asking L1_ROWS a question whose answer the\n// classification itself depends on. It is the same shape as L2's `bareCheckoutOfMain` pre-stage. It is\n// therefore ROW 0 — \"pre-stage, decided from command text\" — rather than a row among 1-6, which keeps\n// it IN the table (the drift this table exists to prevent) without pretending it is classified over the\n// same five dimensions. `L1_PRESTAGE_ROW` is the number the doc prints and `row=` logs, so the two join.\n//\n// THIS FUNCTION IS THE ONE PLACE L1 REPORTS. It is the only scope holding the classification, the\n// matched row, the resolved tree and the agent at once — so logging here, BEFORE the early return,\n// is what finally records the outcomes that were previously invisible: the exempt row and the three\n// hand-downs wrote nothing at all, which is why \"L1 had no objection\" could not be observed and\n// \"show me every L1 decision\" had no answer. The three block helpers no longer log for themselves —\n// and, for the same reason, none of them knows about the matrix POINTER either: every deny is stamped\n// with it HERE, from the same scope and the same row number, so deny and log line cannot disagree.\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction l1LocationBlock(command: string, tree: EffectiveTree, aiType: AiType): BlockedResult | null {\n const misplacedCd = misplacedCdBlock(command, tree);\n if (misplacedCd !== null) {\n logL1(tree, command, 'BLOCK_AI_CURE', L1_PRESTAGE_ROW, 'cd-must-be-first', 'cd not leading/literal');\n return withLocationMatrixPointer(misplacedCd, tree.root, L1_PRESTAGE_ROW);\n }\n\n const row = firstMatchingL1Row(l1Classify(command, tree));\n const rowNum = String(row.num);\n if (row.blockId === null) {\n // ALLOW_EXEMPT stops here; ALLOW means \"no objection, handed down to L2\". Recording the\n // difference is the point — see Verdict. Neither claims the call RAN: the other parallel hook\n // may still have denied it.\n logL1(tree, command, row.action.kind === 'exempt' ? 'ALLOW_EXEMPT' : 'ALLOW', rowNum, '-', row.why);\n return null;\n }\n logL1(tree, command, 'BLOCK_AI_CURE', rowNum, row.blockId, row.why);\n if (row.blockId === 'missing-directory') return withLocationMatrixPointer(missingDirectoryBlock(command, tree), tree.root, rowNum);\n if (row.blockId === 'trinary-version-skew') return withLocationMatrixPointer(versionSkewBlock(command, tree, aiType), tree.root, rowNum);\n return withLocationMatrixPointer(gitFromSubdirBlock(command, tree, isGitOrGhCommand(command)), tree.root, rowNum);\n}\n\n// One L1 line, into L1's OWN stream. `row` is the number the generated doc prints, so a reader who sees\n// `row=5` can open the L1 matrix at row 5 — the deny for that same call names it by absolute path.\n// eslint-disable-next-line @typescript-eslint/max-params -- the six fields of one log line, and a class here would break this file's shape\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions\nfunction logL1(tree: EffectiveTree, command: string, verdict: Verdict, row: string, rule: string, why: string): void {\n logL1Decision(tree.root, new GuardDecision(\n rule, 'Bash', command, branchForLog(tree.root), verdict, why, '-', L0_FAULT_NONE, new MatrixRef('L1', row),\n ));\n}\n\n/**\n * ONE legal shape for relocating a command: `cd <literal path> && <work>`. Anything else — a `cd` after\n * another command or after a `VAR=…` assignment, or a `cd \"$DIR\"` the guard cannot expand — is refused\n * here instead of being silently judged from the shell cwd.\n *\n * This changes no verdict: every command it refuses was ALREADY judged from the shell cwd, so nothing\n * it blocks was previously being allowed on the strength of its `cd`. What changes is that the agent\n * finds out. Two PRs of increasingly precise near-miss wording (#596, #597) still left the fact in a\n * paragraph appended to an unrelated block; the rule is simpler stated as a rule.\n *\n * FIRST in the L1 chain deliberately. version skew and force-to-root both reason from the\n * resolved tree, and if the `cd` did not resolve, that tree is not the one the agent thinks they are\n * in — so their remedies would be steering from a location the command does not actually run in.\n */\n// webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole runner is module-scope functions\nfunction misplacedCdBlock(command: string, tree: EffectiveTree): BlockedResult | null {\n const reason = new EffectiveTreeResolver().misplacedCd(command);\n if (reason === null) return null;\n const report =\n `❌ A \\`cd\\` must come FIRST in the command, with a LITERAL path.\\n` +\n ` Why this one was rejected: ${reason}.\\n` +\n ` \\`cd <literal path> && <work>\\` is the ONE shape that moves where webpieces judges a command.\\n` +\n ` Any other \\`cd\\` cannot be resolved, so the command would be judged against ${tree.root}\\n` +\n ` — not where you think it runs. That used to happen silently; this block is that silence, spoken.\\n` +\n ` Fix Option 1: put the \\`cd\\` first, literal path, SAME command: cd /abs/path && <the rest>\\n` +\n ` Fix Option 2: drop the \\`cd\\` — ${tree.root} is where the command is judged anyway.\\n` +\n ` Fix Option 3: if the SECOND \\`cd\\` was there to point a tool at a directory, use that tool's own\\n` +\n ` directory flag instead — \\`git -C <dir>\\`, \\`tar -C <dir>\\`, \\`npm --prefix <dir>\\`,\\n` +\n ` \\`npm pack --pack-destination <dir>\\`, \\`pnpm --dir <dir>\\`. One \\`cd\\`, same result.\\n` +\n ` ONLY for a dir INSIDE this tree. \\`git -C <another tree>\\` is REFUSED to a subagent,\\n` +\n ` and is never the cure for a version skew — for that, tell the MAIN agent.\\n` +\n ` Fix Option 4: split it — run the work in one call, the \\`cd\\` in another (a \\`cd\\` alone still\\n` +\n ` moves nothing the guards judge; see EffectiveTree on why cwd cannot be assumed).`;\n return new BlockedResult(report);\n}\n\n/**\n * The KEYLESS bash guards, deliberately kept OUT of the config-driven rule set. They have no\n * webpieces.config.json entry at all, so passing them through checkConfigSync would make every\n * consumer's next Bash call a fault-Y block (\"this rule has no entry\") for a feature nobody opted into\n * — which is exactly what whole-repo-build-guard did on its first release. Each one decides for itself\n * whether it acts: whole-repo-build-guard reads ~/.webpieces/config.json for a machine-local OPT-IN\n * (absent means OFF); commit-message-substitution-guard and build-output-pipe-guard act unconditionally.\n * They still honour excludePaths, and they do not run in `rules` mode (code-style-only hook).\n */\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction keylessBashRules(loaded: LoadedConfig, mode: HookMode, governed: GovernedPath): readonly Rule[] {\n if (mode === 'rules') return [];\n return filterByExcludedPaths(\n loadKeylessBashRules(loaded.prGate.buildCommand), governed, loaded.excludePaths,\n );\n}\n\n// webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape\nfunction runBashInternal(\n command: string,\n cwd: string,\n mode: HookMode,\n aiType: AiType,\n): BlockedResult | null {\n if (isL0CureCommand(command)) {\n logL0CureBypass(command, cwd);\n return null;\n }\n\n const loaded = loadConfigOrAllowInspection(command, cwd);\n // null = the config would not load AND this command only inspects → allow, see the helper.\n if (loaded === null) return null;\n if (loaded.configPath === null)\n return l0FaultAllows(command, aiType) ? null : configMissingBlock(cwd);\n\n const workspaceRoot = path.dirname(loaded.configPath);\n\n // WHICH TREE does this command act on? Not the shell's cwd: a `cd` OUT of the workspace is reset\n // by the harness and one INSIDE it persists, so neither can be assumed (see EffectiveTree).\n // ONE resolver answers this for the guards AND for force-to-root below, so the two can never\n // disagree about which tree you are in.\n const tree = new EffectiveTreeResolver().resolve(command, cwd, workspaceRoot);\n\n if (allowForeignTree(command, tree, workspaceRoot)) return null;\n\n // Honour excludePaths on the bash path too (not just Read/Edit): a command whose effective\n // cwd sits under an excluded tree (e.g. repositories/**) drops the whole guard set — matching how\n // runInternal/runRead treat file paths. The relative path is '' when there is no `cd` (root), which\n // matches no exclusion glob, so a plain command at the repo root is unaffected.\n const governedCwd = bashGovernedPath(tree, workspaceRoot);\n const rules = filterByExcludedPaths(\n filterByMode(new WorkflowHookRules().load(loaded).rules, mode, loaded.ruleRegistry),\n governedCwd,\n loaded.excludePaths,\n );\n const keyless = keylessBashRules(loaded, mode, governedCwd);\n if (rules.length === 0 && keyless.length === 0) return null;\n\n const locationBlock = l1LocationBlock(command, tree, aiType);\n if (locationBlock) return locationBlock;\n\n // Keep the feature-branch-guard cache warm on EVERY command (not just Write/Edit): the AI runs\n // far more bash than edits, so refreshing here means the guard's next file-edit check reads a\n // fresh status. Detached + fire-and-forget — never blocks the command. Only when the guard is\n // loaded (guards/all mode) and enabled, so a project that opted out never triggers git fetches.\n // Keyed on the JUDGED tree, so a worktree's cache is refreshed rather than the primary clone's.\n maybeRefreshMainSync(rules, tree.root, branchStateHangTimeout(loaded.rulesConfig));\n\n const groups = runBashRules([...rules, ...keyless], buildBashContext(command, tree));\n return bashPolicyResult(command, tree, loaded, groups);\n}\n\n// The bash report's subject line. It used to be the literal string `<bash>`, which told the agent\n// nothing; the command itself is what was blocked, so name it — truncated, because a heredoc-bearing\n// command can run to thousands of characters and the violation lines already carry the detail.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction commandLabel(command: string): string {\n const oneLine = command.replace(/\\s+/g, ' ').trim();\n const MAX = 100;\n return oneLine.length <= MAX ? oneLine : oneLine.slice(0, MAX) + '…';\n}\n\n// When a push/PR block fires AND the config exempts vendored/nested trees, surface the escape hatch the\n// AI cannot otherwise discover: git/gh run UNGUARDED inside those trees if it cd's there first (each is\n// governed by its own repo, not this one). Scoped to pr-creation-or-push-guard — for the other guards\n// \"cd into an exempt tree\" is not the remedy — and emitted only when such trees are actually configured,\n// so a repo without exemptions never sees the noise.\n//\n// The hint MUST state the precondition, not just the remedy. \"cd into it first\" is true only for a\n// LITERAL cd at the FRONT of the same command; `D=…; cd \"$D\"; git push` lands in the identical\n// directory and does NOT relocate the verdict. That used to be silent, then a near-miss paragraph\n// appended here; it is now misplacedCdBlock, which refuses the command outright — so by the time this\n// footer is reached, any `cd` in the command is already known to be leading and literal. The wording\n// still states the shape, because this is where an agent LEARNS it, before writing the next command.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape\nfunction exemptTreesHint(groups: readonly RuleGroup[], exemptGuards: readonly string[]): string {\n if (exemptGuards.length === 0) return '';\n if (!groups.some((g: RuleGroup): boolean => g.ruleName === 'pr-creation-or-push-guard'))\n return '';\n\n return (\n `\\n\\nℹ️ Working in a nested repo under one of these exempt trees (${exemptGuards.join(', ')})? ` +\n `Put a LITERAL \\`cd\\` at the FRONT of the SAME command — \\`cd /abs/path/to/repo && git push\\` — and git/gh ` +\n `run normally there: the webpieces guards do NOT govern them (each is its own repo).` +\n `\\n \\`cd <literal path> && <work>\\` is the ONE shape that moves where a command is judged. A \\`cd\\` ` +\n `anywhere else in the line, or a non-literal target like \\`cd \"$DIR\"\\`, is refused outright rather than ` +\n `judged from somewhere you did not intend.`\n );\n}\n\n// webpieces-disable no-function-outside-class -- runner result assembly is a pure orchestration helper\nfunction bashPolicyResult(command: string, tree: EffectiveTree, loaded: LoadedConfig, groups: readonly RuleGroup[]): BlockedResult | null {\n const workspaceRoot = path.dirname(loaded.configPath!);\n if (groups.length === 0) {\n // Record the ALLOW only for git/gh commands — the operations the bash guards actually reason\n // about (branch create, commit, push, merge, PR). Skipping ls/cat/grep keeps the audit log\n // focused (the whole point of the log is \"why did/didn't a guard fire?\"). Blocks are always\n // logged below.\n if (/\\b(?:git|gh)\\b/.test(command)) {\n logGuardDecision(\n tree.root,\n new GuardDecision(\n '-',\n 'Bash',\n command,\n branchForLog(tree.root),\n 'ALLOW',\n 'no bash-guard block',\n '-',\n L0_FAULT_NONE,\n MATRIX_L2_UNROWED,\n ),\n );\n }\n return null;\n }\n\n const ruleNames = groups.map((g: RuleGroup): string => g.ruleName).join(',');\n logGuardDecision(\n tree.root,\n new GuardDecision(\n ruleNames,\n 'Bash',\n command,\n branchForLog(tree.root),\n 'BLOCK_AI_CURE',\n 'bash-guard block',\n '-',\n L0_FAULT_NONE,\n MATRIX_L2_UNROWED,\n ),\n );\n const report =\n new ExcludedPathEscapeHint(workspaceRoot, tree.effectiveCwd).render(\n command,\n loaded.excludePaths,\n ) +\n formatReport(commandLabel(command), groups, BASH_SUBJECT) +\n exemptTreesHint(groups, loaded.excludePaths.paths);\n return new BlockedResult(report);\n}\n\n// webpieces-disable no-function-outside-class -- orchestration helper for the explicit foreign-repository exemption\nfunction allowForeignTree(command: string, tree: EffectiveTree, workspaceRoot: string): boolean {\n if (tree.kind === 'foreign') {\n logGuardDecision(\n workspaceRoot,\n new GuardDecision(\n '-',\n 'Bash',\n command,\n branchForLog(workspaceRoot),\n 'ALLOW_EXEMPT',\n 'foreign git repo (out of scope)',\n '-',\n L0_FAULT_NONE,\n new MatrixRef('L1', '1'),\n ),\n );\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WorkflowHookRules = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
4
|
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
7
|
-
const
|
|
5
|
+
const rule_runtime_1 = require("../rule-runtime");
|
|
8
6
|
class WorkflowHookRules {
|
|
9
7
|
load(loaded) {
|
|
10
|
-
const rules =
|
|
11
|
-
return new hook_runtime_1.HookRuleSet(rules
|
|
8
|
+
const rules = new hook_runtime_1.HookPolicyContributions(new Map([['@webpieces/agent-workflow-rules/rule-runtime', new rule_runtime_1.WorkflowRuleRuntime()]])).load(loaded, 'workflow-guard');
|
|
9
|
+
return new hook_runtime_1.HookRuleSet(rules);
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
exports.WorkflowHookRules = WorkflowHookRules;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-hook-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/workflow-hook-rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-hook-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/workflow-hook-rules.ts"],"names":[],"mappings":";;;AACA,0DAA+E;AAC/E,kDAAsD;AAEtD,MAAa,iBAAiB;IAC1B,IAAI,CAAC,MAAoB;QACrB,MAAM,KAAK,GAAG,IAAI,sCAAuB,CACrC,IAAI,GAAG,CAAC,CAAC,CAAC,8CAA8C,EAAE,IAAI,kCAAmB,EAAE,CAAC,CAAC,CAAC,CACzF,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACjC,OAAO,IAAI,0BAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ;AAPD,8CAOC","sourcesContent":["import { LoadedConfig } from '@webpieces/rules-config';\nimport { HookRuleSet, HookPolicyContributions } from '@webpieces/hook-runtime';\nimport { WorkflowRuleRuntime } from '../rule-runtime';\n\nexport class WorkflowHookRules {\n load(loaded: LoadedConfig): HookRuleSet {\n const rules = new HookPolicyContributions(\n new Map([['@webpieces/agent-workflow-rules/rule-runtime', new WorkflowRuleRuntime()]]),\n ).load(loaded, 'workflow-guard');\n return new HookRuleSet(rules);\n }\n}\n"]}
|
package/src/rule-help.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ruleHelp = void 0;
|
|
4
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
5
|
+
/** Owner-authored guidance consumed by the registry catalog. */
|
|
6
|
+
exports.ruleHelp = {
|
|
7
|
+
'branch-creation-guard': new rules_sdk_1.RuleHelp('Create feature branches from the approved base and respect branch/worktree limits.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
8
|
+
'pr-lifecycle-guard': new rules_sdk_1.RuleHelp('Use the reviewed PR flow and complete merge recovery through its prescribed commands.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
9
|
+
'branch-state-guard': new rules_sdk_1.RuleHelp('Work in a current eligible feature tree and keep main synchronization explicit.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=rule-help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-help.js","sourceRoot":"","sources":["../../../../../packages/tooling/agent-workflow-rules/src/rule-help.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD,gEAAgE;AACnD,QAAA,QAAQ,GAAuC;IACxD,uBAAuB,EAAE,IAAI,oBAAQ,CACjC,oFAAoF,EACpF,sIAAsI,CACzI;IACD,oBAAoB,EAAE,IAAI,oBAAQ,CAC9B,uFAAuF,EACvF,sIAAsI,CACzI;IACD,oBAAoB,EAAE,IAAI,oBAAQ,CAC9B,iFAAiF,EACjF,sIAAsI,CACzI;CACJ,CAAC","sourcesContent":["import { RuleHelp } from '@webpieces/rules-sdk';\n\n/** Owner-authored guidance consumed by the registry catalog. */\nexport const ruleHelp: Readonly<Record<string, RuleHelp>> = {\n 'branch-creation-guard': new RuleHelp(\n 'Create feature branches from the approved base and respect branch/worktree limits.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'pr-lifecycle-guard': new RuleHelp(\n 'Use the reviewed PR flow and complete merge recovery through its prescribed commands.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'branch-state-guard': new RuleHelp(\n 'Work in a current eligible feature tree and keep main synchronization explicit.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n};\n"]}
|
package/src/rule-pack.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rulePackManifest = void 0;
|
|
4
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
4
5
|
const rule_migrations_1 = require("./rule-migrations");
|
|
5
6
|
const safeguard_catalog_1 = require("./safeguard-catalog");
|
|
6
|
-
const
|
|
7
|
-
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
8
|
-
const rule_configs_1 = require("./configs/rule-configs");
|
|
9
|
-
const main_sync_guard_configs_1 = require("./configs/main-sync-guard-configs");
|
|
7
|
+
const workflow_policy_registry_1 = require("./workflow-policy-registry");
|
|
10
8
|
const package_json_1 = require("../package.json");
|
|
11
|
-
|
|
12
|
-
const ownedRules = [
|
|
13
|
-
new rules_sdk_1.OwnedRuleDefinition('branch-creation-guard', rule_configs_1.BranchCreationGuardConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['branch-creation-guard'], rule_settings_1.recommendedSeeds['branch-creation-guard'], 'hookGuards'),
|
|
14
|
-
new rules_sdk_1.OwnedRuleDefinition('pr-lifecycle-guard', rule_configs_1.PrLifecycleGuardConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['pr-lifecycle-guard'], rule_settings_1.recommendedSeeds['pr-lifecycle-guard'], 'hookGuards'),
|
|
15
|
-
new rules_sdk_1.OwnedRuleDefinition('branch-state-guard', main_sync_guard_configs_1.BranchStateGuardConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['branch-state-guard'], rule_settings_1.recommendedSeeds['branch-state-guard'], 'hookGuards'),
|
|
16
|
-
];
|
|
17
|
-
exports.rulePackManifest = new rules_sdk_1.RulePackManifest('@webpieces/agent-workflow-rules', package_json_1.version, rules_sdk_1.RULE_PACK_API_VERSION, ownedRules, [
|
|
18
|
-
...ownedRules.map(rule => new rules_sdk_1.RuleContribution(rule.id, '@webpieces/agent-workflow-rules', 'workflow-guard')),
|
|
19
|
-
], rule_migrations_1.ruleMigrations, safeguard_catalog_1.safeguardCatalog);
|
|
9
|
+
exports.rulePackManifest = new rules_sdk_1.RulePackManifest('@webpieces/agent-workflow-rules', package_json_1.version, rules_sdk_1.RULE_PACK_API_VERSION, workflow_policy_registry_1.WORKFLOW_POLICIES.map((policy) => policy.definition), workflow_policy_registry_1.WORKFLOW_POLICIES.map((policy) => new rules_sdk_1.RuleContribution(policy.definition.id, '@webpieces/agent-workflow-rules', 'workflow-guard', '@webpieces/agent-workflow-rules/rule-runtime')), rule_migrations_1.ruleMigrations, safeguard_catalog_1.safeguardCatalog);
|
|
20
10
|
//# sourceMappingURL=rule-pack.js.map
|
package/src/rule-pack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-pack.js","sourceRoot":"","sources":["../../../../../packages/tooling/agent-workflow-rules/src/rule-pack.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,2DAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"rule-pack.js","sourceRoot":"","sources":["../../../../../packages/tooling/agent-workflow-rules/src/rule-pack.ts"],"names":[],"mappings":";;;AAAA,oDAAiG;AACjG,uDAAmD;AACnD,2DAAuD;AACvD,yEAA+E;AAC/E,kDAA0C;AAE7B,QAAA,gBAAgB,GAAG,IAAI,4BAAgB,CAChD,iCAAiC,EACjC,sBAAO,EACP,iCAAqB,EACrB,4CAAiB,CAAC,GAAG,CAAC,CAAC,MAAsB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EACpE,4CAAiB,CAAC,GAAG,CACjB,CAAC,MAAsB,EAAE,EAAE,CACvB,IAAI,4BAAgB,CAChB,MAAM,CAAC,UAAU,CAAC,EAAE,EACpB,iCAAiC,EACjC,gBAAgB,EAChB,8CAA8C,CACjD,CACR,EACD,gCAAc,EACd,oCAAgB,CACnB,CAAC","sourcesContent":["import { RuleContribution, RulePackManifest, RULE_PACK_API_VERSION } from '@webpieces/rules-sdk';\nimport { ruleMigrations } from './rule-migrations';\nimport { safeguardCatalog } from './safeguard-catalog';\nimport { WORKFLOW_POLICIES, WorkflowPolicy } from './workflow-policy-registry';\nimport { version } from '../package.json';\n\nexport const rulePackManifest = new RulePackManifest(\n '@webpieces/agent-workflow-rules',\n version,\n RULE_PACK_API_VERSION,\n WORKFLOW_POLICIES.map((policy: WorkflowPolicy) => policy.definition),\n WORKFLOW_POLICIES.map(\n (policy: WorkflowPolicy) =>\n new RuleContribution(\n policy.definition.id,\n '@webpieces/agent-workflow-rules',\n 'workflow-guard',\n '@webpieces/agent-workflow-rules/rule-runtime',\n ),\n ),\n ruleMigrations,\n safeguardCatalog,\n);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HookPolicyRuntimeRequest, HookRuleRuntime, Rule } from '@webpieces/hook-runtime';
|
|
2
|
+
export declare class WorkflowRuleRuntime implements HookRuleRuntime {
|
|
3
|
+
create(request: HookPolicyRuntimeRequest): readonly Rule[];
|
|
4
|
+
}
|
|
5
|
+
export declare const workflowRuleRuntime: WorkflowRuleRuntime;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workflowRuleRuntime = exports.WorkflowRuleRuntime = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const workflow_policy_registry_1 = require("./workflow-policy-registry");
|
|
7
|
+
const implementations = tslib_1.__importStar(require("./core/rules"));
|
|
8
|
+
class WorkflowRuleRuntime {
|
|
9
|
+
create(request) {
|
|
10
|
+
return request.ruleIds.flatMap((id) => {
|
|
11
|
+
const policy = workflow_policy_registry_1.WORKFLOW_POLICIES.find((entry) => entry.definition.id === id);
|
|
12
|
+
if (!policy)
|
|
13
|
+
throw new tooling_common_1.InformAiError(`Workflow runtime has no implementation of ${id}. Repair its contribution.`);
|
|
14
|
+
const config = request.configs[id];
|
|
15
|
+
if (!config)
|
|
16
|
+
throw new tooling_common_1.InformAiError(`Missing explicit config for ${id}. Repair its declared owner file.`);
|
|
17
|
+
return policy.implementations.map((entry) => {
|
|
18
|
+
const ctor = implementations[entry.exportName];
|
|
19
|
+
if (!ctor)
|
|
20
|
+
throw new tooling_common_1.InformAiError(`Missing workflow implementation ${entry.exportName}. Repair its runtime export.`);
|
|
21
|
+
const command = entry.commandHint === null ? undefined : request.commands[entry.commandHint];
|
|
22
|
+
return Reflect.construct(ctor, [config, command]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.WorkflowRuleRuntime = WorkflowRuleRuntime;
|
|
28
|
+
exports.workflowRuleRuntime = new WorkflowRuleRuntime();
|
|
29
|
+
//# sourceMappingURL=rule-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-runtime.js","sourceRoot":"","sources":["../../../../../packages/tooling/agent-workflow-rules/src/rule-runtime.ts"],"names":[],"mappings":";;;;AACA,8DAA0D;AAC1D,yEAIoC;AACpC,sEAAgD;AAIhD,MAAa,mBAAmB;IAC5B,MAAM,CAAC,OAAiC;QACpC,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAU,EAAE,EAAE;YAC1C,MAAM,MAAM,GAAG,4CAAiB,CAAC,IAAI,CACjC,CAAC,KAAqB,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACxD,CAAC;YACF,IAAI,CAAC,MAAM;gBACP,MAAM,IAAI,8BAAa,CACnB,6CAA6C,EAAE,4BAA4B,CAC9E,CAAC;YACN,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM;gBACP,MAAM,IAAI,8BAAa,CACnB,+BAA+B,EAAE,mCAAmC,CACvE,CAAC;YACN,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,KAA6B,EAAE,EAAE;gBAChE,MAAM,IAAI,GAAI,eAAoD,CAC9D,KAAK,CAAC,UAAU,CACnB,CAAC;gBACF,IAAI,CAAC,IAAI;oBACL,MAAM,IAAI,8BAAa,CACnB,mCAAmC,KAAK,CAAC,UAAU,8BAA8B,CACpF,CAAC;gBACN,MAAM,OAAO,GACT,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBACjF,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAS,CAAC;YAC9D,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA7BD,kDA6BC;AAEY,QAAA,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC","sourcesContent":["import { HookPolicyRuntimeRequest, HookRuleRuntime, Rule } from '@webpieces/hook-runtime';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport {\n WORKFLOW_POLICIES,\n WorkflowPolicy,\n WorkflowImplementation,\n} from './workflow-policy-registry';\nimport * as implementations from './core/rules';\n\ntype WorkflowRuleCtor = new (...args: never[]) => Rule;\n\nexport class WorkflowRuleRuntime implements HookRuleRuntime {\n create(request: HookPolicyRuntimeRequest): readonly Rule[] {\n return request.ruleIds.flatMap((id: string) => {\n const policy = WORKFLOW_POLICIES.find(\n (entry: WorkflowPolicy) => entry.definition.id === id,\n );\n if (!policy)\n throw new InformAiError(\n `Workflow runtime has no implementation of ${id}. Repair its contribution.`,\n );\n const config = request.configs[id];\n if (!config)\n throw new InformAiError(\n `Missing explicit config for ${id}. Repair its declared owner file.`,\n );\n return policy.implementations.map((entry: WorkflowImplementation) => {\n const ctor = (implementations as Record<string, WorkflowRuleCtor>)[\n entry.exportName\n ];\n if (!ctor)\n throw new InformAiError(\n `Missing workflow implementation ${entry.exportName}. Repair its runtime export.`,\n );\n const command =\n entry.commandHint === null ? undefined : request.commands[entry.commandHint];\n return Reflect.construct(ctor, [config, command]) as Rule;\n });\n });\n }\n}\n\nexport const workflowRuleRuntime = new WorkflowRuleRuntime();\n"]}
|