@webpieces/agent-workflow-rules 0.0.0-stage → 0.0.1
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/README.md +23 -2
- package/package.json +45 -4
- package/src/adapters/agent-response.d.ts +5 -0
- package/src/adapters/agent-response.js +86 -0
- package/src/adapters/agent-response.js.map +1 -0
- package/src/adapters/codex-subagent-guard.d.ts +45 -0
- package/src/adapters/codex-subagent-guard.js +88 -0
- package/src/adapters/codex-subagent-guard.js.map +1 -0
- package/src/adapters/guards-hook.d.ts +3 -0
- package/src/adapters/guards-hook.js +30 -0
- package/src/adapters/guards-hook.js.map +1 -0
- package/src/adapters/hook-app-fixtures.d.ts +68 -0
- package/src/adapters/hook-app-fixtures.js +170 -0
- package/src/adapters/hook-app-fixtures.js.map +1 -0
- package/src/adapters/hook-core.d.ts +22 -0
- package/src/adapters/hook-core.js +359 -0
- package/src/adapters/hook-core.js.map +1 -0
- package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
- package/src/adapters/hook-pipeline-evaluator.js +18 -0
- package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
- package/src/adapters/review-identity-stamper.d.ts +20 -0
- package/src/adapters/review-identity-stamper.js +34 -0
- package/src/adapters/review-identity-stamper.js.map +1 -0
- package/src/bin/codex-trust.d.ts +105 -0
- package/src/bin/codex-trust.js +205 -0
- package/src/bin/codex-trust.js.map +1 -0
- package/src/bin/dev-hook-install.d.ts +1 -0
- package/src/bin/dev-hook-install.js +80 -0
- package/src/bin/dev-hook-install.js.map +1 -0
- package/src/bin/dev-hook-uninstall.d.ts +1 -0
- package/src/bin/dev-hook-uninstall.js +45 -0
- package/src/bin/dev-hook-uninstall.js.map +1 -0
- package/src/bin/hook-registration.d.ts +429 -0
- package/src/bin/hook-registration.js +661 -0
- package/src/bin/hook-registration.js.map +1 -0
- package/src/bin/install-entry.d.ts +19 -0
- package/src/bin/install-entry.js +128 -0
- package/src/bin/install-entry.js.map +1 -0
- package/src/bin/l0-allowlist.d.ts +46 -0
- package/src/bin/l0-allowlist.js +527 -0
- package/src/bin/l0-allowlist.js.map +1 -0
- package/src/bin/l0-codex-read.d.ts +20 -0
- package/src/bin/l0-codex-read.js +108 -0
- package/src/bin/l0-codex-read.js.map +1 -0
- package/src/bin/l0-decide.d.ts +49 -0
- package/src/bin/l0-decide.js +90 -0
- package/src/bin/l0-decide.js.map +1 -0
- package/src/bin/l0-entry.d.ts +103 -0
- package/src/bin/l0-entry.js +98 -0
- package/src/bin/l0-entry.js.map +1 -0
- package/src/bin/l0-ignored-tools.d.ts +38 -0
- package/src/bin/l0-ignored-tools.js +44 -0
- package/src/bin/l0-ignored-tools.js.map +1 -0
- package/src/bin/managed-env.d.ts +46 -0
- package/src/bin/managed-env.js +50 -0
- package/src/bin/managed-env.js.map +1 -0
- package/src/bin/neighbour-hooks.d.ts +42 -0
- package/src/bin/neighbour-hooks.js +177 -0
- package/src/bin/neighbour-hooks.js.map +1 -0
- package/src/bin/reviewer-agent.d.ts +19 -0
- package/src/bin/reviewer-agent.js +135 -0
- package/src/bin/reviewer-agent.js.map +1 -0
- package/src/bin/settings-shape.d.ts +37 -0
- package/src/bin/settings-shape.js +17 -0
- package/src/bin/settings-shape.js.map +1 -0
- package/src/bin/setup-config.d.ts +20 -0
- package/src/bin/setup-config.js +371 -0
- package/src/bin/setup-config.js.map +1 -0
- package/src/bin/setup.d.ts +78 -0
- package/src/bin/setup.js +411 -0
- package/src/bin/setup.js.map +1 -0
- package/src/bin/shim-audit-log.d.ts +119 -0
- package/src/bin/shim-audit-log.js +286 -0
- package/src/bin/shim-audit-log.js.map +1 -0
- package/src/bin/shim-deny-reason.d.ts +1 -0
- package/src/bin/shim-deny-reason.js +244 -0
- package/src/bin/shim-deny-reason.js.map +1 -0
- package/src/bin/shim-drift-fix.d.ts +1 -0
- package/src/bin/shim-drift-fix.js +73 -0
- package/src/bin/shim-drift-fix.js.map +1 -0
- package/src/bin/shim-testkit.d.ts +107 -0
- package/src/bin/shim-testkit.js +197 -0
- package/src/bin/shim-testkit.js.map +1 -0
- package/src/bin/shim-version-drift.d.ts +1 -0
- package/src/bin/shim-version-drift.js +164 -0
- package/src/bin/shim-version-drift.js.map +1 -0
- package/src/bin/shim.d.ts +16 -0
- package/src/bin/shim.js +641 -0
- package/src/bin/shim.js.map +1 -0
- package/src/bin/upgrade-shim.d.ts +18 -0
- package/src/bin/upgrade-shim.js +283 -0
- package/src/bin/upgrade-shim.js.map +1 -0
- package/src/configs/main-sync-guard-configs.d.ts +38 -0
- package/src/configs/main-sync-guard-configs.js +54 -0
- package/src/configs/main-sync-guard-configs.js.map +1 -0
- package/src/configs/rule-configs.d.ts +47 -0
- package/src/configs/rule-configs.js +96 -0
- package/src/configs/rule-configs.js.map +1 -0
- package/src/core/ai-type-context.d.ts +36 -0
- package/src/core/ai-type-context.js +45 -0
- package/src/core/ai-type-context.js.map +1 -0
- package/src/core/decision-log.d.ts +190 -0
- package/src/core/decision-log.js +409 -0
- package/src/core/decision-log.js.map +1 -0
- package/src/core/excluded-path-escape.d.ts +101 -0
- package/src/core/excluded-path-escape.js +236 -0
- package/src/core/excluded-path-escape.js.map +1 -0
- package/src/core/force-to-root.d.ts +32 -0
- package/src/core/force-to-root.js +60 -0
- package/src/core/force-to-root.js.map +1 -0
- package/src/core/guard-index-doc.d.ts +63 -0
- package/src/core/guard-index-doc.js +172 -0
- package/src/core/guard-index-doc.js.map +1 -0
- package/src/core/instruct-ai-writer.d.ts +1 -0
- package/src/core/instruct-ai-writer.js +6 -0
- package/src/core/instruct-ai-writer.js.map +1 -0
- package/src/core/l0-matrix.d.ts +102 -0
- package/src/core/l0-matrix.js +357 -0
- package/src/core/l0-matrix.js.map +1 -0
- package/src/core/l0-tooling-doc.d.ts +45 -0
- package/src/core/l0-tooling-doc.js +258 -0
- package/src/core/l0-tooling-doc.js.map +1 -0
- package/src/core/l1-doc.d.ts +7 -0
- package/src/core/l1-doc.js +340 -0
- package/src/core/l1-doc.js.map +1 -0
- package/src/core/l1-matrix-doc.d.ts +31 -0
- package/src/core/l1-matrix-doc.js +111 -0
- package/src/core/l1-matrix-doc.js.map +1 -0
- package/src/core/l1-rows.d.ts +167 -0
- package/src/core/l1-rows.js +262 -0
- package/src/core/l1-rows.js.map +1 -0
- package/src/core/l2-doc.d.ts +7 -0
- package/src/core/l2-doc.js +385 -0
- package/src/core/l2-doc.js.map +1 -0
- package/src/core/l2-matrix-doc.d.ts +23 -0
- package/src/core/l2-matrix-doc.js +72 -0
- package/src/core/l2-matrix-doc.js.map +1 -0
- package/src/core/l2-row.d.ts +54 -0
- package/src/core/l2-row.js +75 -0
- package/src/core/l2-row.js.map +1 -0
- package/src/core/l2-rows.d.ts +56 -0
- package/src/core/l2-rows.js +272 -0
- package/src/core/l2-rows.js.map +1 -0
- package/src/core/load-rules.d.ts +9 -0
- package/src/core/load-rules.js +65 -0
- package/src/core/load-rules.js.map +1 -0
- package/src/core/log-stream.d.ts +117 -0
- package/src/core/log-stream.js +156 -0
- package/src/core/log-stream.js.map +1 -0
- package/src/core/log-streams.d.ts +48 -0
- package/src/core/log-streams.js +55 -0
- package/src/core/log-streams.js.map +1 -0
- package/src/core/log-target.d.ts +21 -0
- package/src/core/log-target.js +29 -0
- package/src/core/log-target.js.map +1 -0
- package/src/core/main-sync-log.d.ts +16 -0
- package/src/core/main-sync-log.js +108 -0
- package/src/core/main-sync-log.js.map +1 -0
- package/src/core/main-sync-refresh.d.ts +39 -0
- package/src/core/main-sync-refresh.js +96 -0
- package/src/core/main-sync-refresh.js.map +1 -0
- package/src/core/main-sync-timeout.d.ts +33 -0
- package/src/core/main-sync-timeout.js +95 -0
- package/src/core/main-sync-timeout.js.map +1 -0
- package/src/core/matrix-cures.d.ts +12 -0
- package/src/core/matrix-cures.js +56 -0
- package/src/core/matrix-cures.js.map +1 -0
- package/src/core/missing-directory.d.ts +38 -0
- package/src/core/missing-directory.js +66 -0
- package/src/core/missing-directory.js.map +1 -0
- package/src/core/read-only-inspection.d.ts +34 -0
- package/src/core/read-only-inspection.js +88 -0
- package/src/core/read-only-inspection.js.map +1 -0
- package/src/core/rejection-log.d.ts +9 -0
- package/src/core/rejection-log.js +262 -0
- package/src/core/rejection-log.js.map +1 -0
- package/src/core/rules/branch-creation-guard.d.ts +113 -0
- package/src/core/rules/branch-creation-guard.js +425 -0
- package/src/core/rules/branch-creation-guard.js.map +1 -0
- package/src/core/rules/branch-switch-scan.d.ts +43 -0
- package/src/core/rules/branch-switch-scan.js +132 -0
- package/src/core/rules/branch-switch-scan.js.map +1 -0
- package/src/core/rules/build-output-pipe-guard.d.ts +56 -0
- package/src/core/rules/build-output-pipe-guard.js +120 -0
- package/src/core/rules/build-output-pipe-guard.js.map +1 -0
- package/src/core/rules/build-output-pipe-scan.d.ts +47 -0
- package/src/core/rules/build-output-pipe-scan.js +84 -0
- package/src/core/rules/build-output-pipe-scan.js.map +1 -0
- package/src/core/rules/cap-remedies.d.ts +39 -0
- package/src/core/rules/cap-remedies.js +59 -0
- package/src/core/rules/cap-remedies.js.map +1 -0
- package/src/core/rules/commit-message-substitution-guard.d.ts +72 -0
- package/src/core/rules/commit-message-substitution-guard.js +134 -0
- package/src/core/rules/commit-message-substitution-guard.js.map +1 -0
- package/src/core/rules/commit-message-substitution-scan.d.ts +42 -0
- package/src/core/rules/commit-message-substitution-scan.js +145 -0
- package/src/core/rules/commit-message-substitution-scan.js.map +1 -0
- package/src/core/rules/content-read-scan.d.ts +76 -0
- package/src/core/rules/content-read-scan.js +176 -0
- package/src/core/rules/content-read-scan.js.map +1 -0
- package/src/core/rules/cure-prefix-scan.d.ts +64 -0
- package/src/core/rules/cure-prefix-scan.js +133 -0
- package/src/core/rules/cure-prefix-scan.js.map +1 -0
- package/src/core/rules/feature-branch-guard.d.ts +121 -0
- package/src/core/rules/feature-branch-guard.js +327 -0
- package/src/core/rules/feature-branch-guard.js.map +1 -0
- package/src/core/rules/index.d.ts +1 -0
- package/src/core/rules/index.js +5 -0
- package/src/core/rules/index.js.map +1 -0
- package/src/core/rules/judged-tree.d.ts +66 -0
- package/src/core/rules/judged-tree.js +97 -0
- package/src/core/rules/judged-tree.js.map +1 -0
- package/src/core/rules/main-freshness.d.ts +37 -0
- package/src/core/rules/main-freshness.js +61 -0
- package/src/core/rules/main-freshness.js.map +1 -0
- package/src/core/rules/merge-in-progress-guard.d.ts +17 -0
- package/src/core/rules/merge-in-progress-guard.js +124 -0
- package/src/core/rules/merge-in-progress-guard.js.map +1 -0
- package/src/core/rules/merged-branch-bash-guard.d.ts +62 -0
- package/src/core/rules/merged-branch-bash-guard.js +171 -0
- package/src/core/rules/merged-branch-bash-guard.js.map +1 -0
- package/src/core/rules/merged-branch-message.d.ts +59 -0
- package/src/core/rules/merged-branch-message.js +137 -0
- package/src/core/rules/merged-branch-message.js.map +1 -0
- package/src/core/rules/pr-creation-or-push-guard.d.ts +26 -0
- package/src/core/rules/pr-creation-or-push-guard.js +150 -0
- package/src/core/rules/pr-creation-or-push-guard.js.map +1 -0
- package/src/core/rules/pr-merge-guard.d.ts +36 -0
- package/src/core/rules/pr-merge-guard.js +87 -0
- package/src/core/rules/pr-merge-guard.js.map +1 -0
- package/src/core/rules/read-stale-guard.d.ts +136 -0
- package/src/core/rules/read-stale-guard.js +328 -0
- package/src/core/rules/read-stale-guard.js.map +1 -0
- package/src/core/rules/recovery-allowlist.d.ts +49 -0
- package/src/core/rules/recovery-allowlist.js +187 -0
- package/src/core/rules/recovery-allowlist.js.map +1 -0
- package/src/core/rules/redirect-how-to-merge-main.d.ts +16 -0
- package/src/core/rules/redirect-how-to-merge-main.js +159 -0
- package/src/core/rules/redirect-how-to-merge-main.js.map +1 -0
- package/src/core/rules/stale-main-bash-guard.d.ts +198 -0
- package/src/core/rules/stale-main-bash-guard.js +363 -0
- package/src/core/rules/stale-main-bash-guard.js.map +1 -0
- package/src/core/rules/stale-main-message.d.ts +62 -0
- package/src/core/rules/stale-main-message.js +102 -0
- package/src/core/rules/stale-main-message.js.map +1 -0
- package/src/core/rules/tree-recovery.d.ts +92 -0
- package/src/core/rules/tree-recovery.js +165 -0
- package/src/core/rules/tree-recovery.js.map +1 -0
- package/src/core/rules/wait-spin-guard.d.ts +128 -0
- package/src/core/rules/wait-spin-guard.js +211 -0
- package/src/core/rules/wait-spin-guard.js.map +1 -0
- package/src/core/rules/wait-spin-scan.d.ts +118 -0
- package/src/core/rules/wait-spin-scan.js +203 -0
- package/src/core/rules/wait-spin-scan.js.map +1 -0
- package/src/core/rules/whole-repo-build-guard.d.ts +125 -0
- package/src/core/rules/whole-repo-build-guard.js +257 -0
- package/src/core/rules/whole-repo-build-guard.js.map +1 -0
- package/src/core/rules/whole-repo-build-scan.d.ts +28 -0
- package/src/core/rules/whole-repo-build-scan.js +198 -0
- package/src/core/rules/whole-repo-build-scan.js.map +1 -0
- package/src/core/runner.d.ts +19 -0
- package/src/core/runner.js +482 -0
- package/src/core/runner.js.map +1 -0
- package/src/core/session-call-history.d.ts +44 -0
- package/src/core/session-call-history.js +79 -0
- package/src/core/session-call-history.js.map +1 -0
- package/src/core/sync-main.d.ts +46 -0
- package/src/core/sync-main.js +176 -0
- package/src/core/sync-main.js.map +1 -0
- package/src/core/version-sync.d.ts +219 -0
- package/src/core/version-sync.js +558 -0
- package/src/core/version-sync.js.map +1 -0
- package/src/core/webpieces-versions.d.ts +98 -0
- package/src/core/webpieces-versions.js +206 -0
- package/src/core/webpieces-versions.js.map +1 -0
- package/src/core/workflow-hook-rules.d.ts +5 -0
- package/src/core/workflow-hook-rules.js +15 -0
- package/src/core/workflow-hook-rules.js.map +1 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +28 -0
- package/src/index.js.map +1 -0
- package/src/policy-keys.d.ts +2 -0
- package/src/policy-keys.js +6 -0
- package/src/policy-keys.js.map +1 -0
- package/src/rule-migrations.d.ts +3 -0
- package/src/rule-migrations.js +22 -0
- package/src/rule-migrations.js.map +1 -0
- package/src/rule-pack.d.ts +2 -0
- package/src/rule-pack.js +20 -0
- package/src/rule-pack.js.map +1 -0
- package/src/rule-settings.d.ts +5 -0
- package/src/rule-settings.js +31 -0
- package/src/rule-settings.js.map +1 -0
- package/src/safeguard-catalog.d.ts +3 -0
- package/src/safeguard-catalog.js +16 -0
- package/src/safeguard-catalog.js.map +1 -0
- package/templates/ai-hook.sh +497 -0
- package/templates/claude-settings-hook.json +28 -0
- package/templates/webpieces-reviewer.md +60 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BranchSwitchScan = exports.BranchSwitch = void 0;
|
|
4
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
5
|
+
/**
|
|
6
|
+
* "Which branch does this `git checkout` / `git switch` land me on?" — the ONE place that question is
|
|
7
|
+
* answered, for every guard that asks it.
|
|
8
|
+
*
|
|
9
|
+
* It used to be answered by two regexes in redirect-how-to-merge-main
|
|
10
|
+
* (`/git\s+(?:checkout|switch)\s+main\b/` to EXEMPT main, and a negative-lookahead twin to catch a
|
|
11
|
+
* feature switch) and by a third, hand-rolled word walk in stale-main-bash-guard. The regex pair
|
|
12
|
+
* assumed the branch name is the token immediately after the subcommand, so ONE flag broke it:
|
|
13
|
+
*
|
|
14
|
+
* git checkout main → exempted (correct)
|
|
15
|
+
* git checkout -q main → `main` no longer follows `checkout`, so the exemption MISSED, the
|
|
16
|
+
* lookahead concluded the target was not main, and the command was
|
|
17
|
+
* blocked with "this switches to a feature branch and then pulls main
|
|
18
|
+
* into it" — the exact opposite of what it does.
|
|
19
|
+
*
|
|
20
|
+
* That block landed on the cure stale-main-bash-guard itself prescribes, so the two guards
|
|
21
|
+
* contradicted each other and a human had to route around both to update main. The fix is not a
|
|
22
|
+
* cleverer regex: it is to TOKENIZE (CommandScanner already does the hard part) and walk the flags,
|
|
23
|
+
* which is also why it must exist once rather than three times.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately NOT "does the string contain main" — over-matching here is worse than the original
|
|
26
|
+
* bug, because `git checkout -b feature/main-thing` and `git checkout -- main.ts` would then read as
|
|
27
|
+
* "switching to main" and be EXEMPTED from a guard whose whole job is to catch a feature-branch pull.
|
|
28
|
+
*/
|
|
29
|
+
const CREATE_FLAGS = new Set(['-b', '-B', '-c', '-C', '--orphan']);
|
|
30
|
+
// Non-creating flags that consume the FOLLOWING token, so its value is never mistaken for the target.
|
|
31
|
+
const FLAGS_WITH_VALUE = new Set(['--conflict', '--pathspec-from-file', '--start-point']);
|
|
32
|
+
/**
|
|
33
|
+
* The branch a checkout/switch lands on, and whether that command CREATES it.
|
|
34
|
+
*
|
|
35
|
+
* `created` is load-bearing rather than cosmetic: `git checkout -b x origin/main` lands on a branch
|
|
36
|
+
* that is current by construction (nothing to be stale about), whereas landing on an EXISTING local
|
|
37
|
+
* `main` is exactly the stale-checkout hazard. Data-only, so a class (per CLAUDE.md).
|
|
38
|
+
*/
|
|
39
|
+
class BranchSwitch {
|
|
40
|
+
branch;
|
|
41
|
+
created;
|
|
42
|
+
constructor(branch, created) {
|
|
43
|
+
this.branch = branch;
|
|
44
|
+
this.created = created;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BranchSwitch = BranchSwitch;
|
|
48
|
+
class BranchSwitchScan {
|
|
49
|
+
scanner;
|
|
50
|
+
constructor(scanner = new hook_runtime_1.CommandScanner()) {
|
|
51
|
+
this.scanner = scanner;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The branch this segment switches to, or null when the segment does not land on a branch at all:
|
|
55
|
+
* a different command, no target word, `git checkout -` (the previous branch — unknowable here),
|
|
56
|
+
* or anything after `--` (which ends option parsing, making the rest PATHSPECS, so
|
|
57
|
+
* `git checkout -- main` restores a FILE named main and moves no branch).
|
|
58
|
+
*
|
|
59
|
+
* Flag-tolerant by construction: every leading flag is walked past, so `-q`, `--quiet`,
|
|
60
|
+
* `--no-track`, `--detach` and friends change nothing about which word is the target.
|
|
61
|
+
*/
|
|
62
|
+
targetOf(segment) {
|
|
63
|
+
const subcommand = this.scanner.gitSubcommand(segment);
|
|
64
|
+
if (subcommand !== 'checkout' && subcommand !== 'switch')
|
|
65
|
+
return null;
|
|
66
|
+
const words = this.scanner.words(segment);
|
|
67
|
+
const args = words.slice(words.indexOf(subcommand) + 1);
|
|
68
|
+
for (let i = 0; i < args.length; i++) {
|
|
69
|
+
const word = args[i];
|
|
70
|
+
if (word === '--')
|
|
71
|
+
return null;
|
|
72
|
+
if (word === '-')
|
|
73
|
+
return null;
|
|
74
|
+
const created = this.createdBranch(args, i);
|
|
75
|
+
if (created !== null)
|
|
76
|
+
return created;
|
|
77
|
+
if (FLAGS_WITH_VALUE.has(word)) {
|
|
78
|
+
i++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (word.startsWith('-'))
|
|
82
|
+
continue;
|
|
83
|
+
return new BranchSwitch(word, false);
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* True only for landing on an EXISTING branch named `main` — the form that can hand you a stale
|
|
89
|
+
* tree, and the form `git checkout main && git pull origin main` uses. `-b`/`-B`/`-c`/`-C` are
|
|
90
|
+
* excluded because they create the branch here and now.
|
|
91
|
+
*
|
|
92
|
+
* This scan reads raw GIT, and it has to keep doing so even though the workflow messages now
|
|
93
|
+
* prescribe `pnpm wp-sync-main` instead: what the guards recommend is not what an agent
|
|
94
|
+
* necessarily types, the raw pair is still allowed and is still the L0 recovery cure, and a scan
|
|
95
|
+
* that stopped recognising it would stop catching the bare `git checkout main` it exists to catch.
|
|
96
|
+
*/
|
|
97
|
+
landsOnExistingMain(segment) {
|
|
98
|
+
const target = this.targetOf(segment);
|
|
99
|
+
return target !== null && this.isExistingMain(target);
|
|
100
|
+
}
|
|
101
|
+
/** The same question for a target already parsed (switchesIn). One spelling, two entry shapes. */
|
|
102
|
+
isExistingMain(target) {
|
|
103
|
+
return target.branch === 'main' && !target.created;
|
|
104
|
+
}
|
|
105
|
+
/** Every segment of a whole command that lands on a branch, in order. */
|
|
106
|
+
switchesIn(command) {
|
|
107
|
+
const found = [];
|
|
108
|
+
for (const segment of this.scanner.commandSegments(command)) {
|
|
109
|
+
const target = this.targetOf(segment);
|
|
110
|
+
if (target !== null)
|
|
111
|
+
found.push(target);
|
|
112
|
+
}
|
|
113
|
+
return found;
|
|
114
|
+
}
|
|
115
|
+
// `-b <name>` / `--orphan=<name>` — the new branch's name, or null when this word creates nothing.
|
|
116
|
+
createdBranch(args, i) {
|
|
117
|
+
const word = args[i];
|
|
118
|
+
if (CREATE_FLAGS.has(word)) {
|
|
119
|
+
const name = args[i + 1];
|
|
120
|
+
if (name === undefined || name.startsWith('-'))
|
|
121
|
+
return null;
|
|
122
|
+
return new BranchSwitch(name, true);
|
|
123
|
+
}
|
|
124
|
+
const equals = word.indexOf('=');
|
|
125
|
+
if (equals > 0 && CREATE_FLAGS.has(word.slice(0, equals))) {
|
|
126
|
+
return new BranchSwitch(word.slice(equals + 1), true);
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.BranchSwitchScan = BranchSwitchScan;
|
|
132
|
+
//# sourceMappingURL=branch-switch-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch-switch-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/branch-switch-scan.ts"],"names":[],"mappings":"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","sourcesContent":["import { CommandScanner } from '@webpieces/hook-runtime';\n\n/**\n * \"Which branch does this `git checkout` / `git switch` land me on?\" — the ONE place that question is\n * answered, for every guard that asks it.\n *\n * It used to be answered by two regexes in redirect-how-to-merge-main\n * (`/git\\s+(?:checkout|switch)\\s+main\\b/` to EXEMPT main, and a negative-lookahead twin to catch a\n * feature switch) and by a third, hand-rolled word walk in stale-main-bash-guard. The regex pair\n * assumed the branch name is the token immediately after the subcommand, so ONE flag broke it:\n *\n * git checkout main → exempted (correct)\n * git checkout -q main → `main` no longer follows `checkout`, so the exemption MISSED, the\n * lookahead concluded the target was not main, and the command was\n * blocked with \"this switches to a feature branch and then pulls main\n * into it\" — the exact opposite of what it does.\n *\n * That block landed on the cure stale-main-bash-guard itself prescribes, so the two guards\n * contradicted each other and a human had to route around both to update main. The fix is not a\n * cleverer regex: it is to TOKENIZE (CommandScanner already does the hard part) and walk the flags,\n * which is also why it must exist once rather than three times.\n *\n * Deliberately NOT \"does the string contain main\" — over-matching here is worse than the original\n * bug, because `git checkout -b feature/main-thing` and `git checkout -- main.ts` would then read as\n * \"switching to main\" and be EXEMPTED from a guard whose whole job is to catch a feature-branch pull.\n */\nconst CREATE_FLAGS: ReadonlySet<string> = new Set(['-b', '-B', '-c', '-C', '--orphan']);\n\n// Non-creating flags that consume the FOLLOWING token, so its value is never mistaken for the target.\nconst FLAGS_WITH_VALUE: ReadonlySet<string> = new Set(['--conflict', '--pathspec-from-file', '--start-point']);\n\n/**\n * The branch a checkout/switch lands on, and whether that command CREATES it.\n *\n * `created` is load-bearing rather than cosmetic: `git checkout -b x origin/main` lands on a branch\n * that is current by construction (nothing to be stale about), whereas landing on an EXISTING local\n * `main` is exactly the stale-checkout hazard. Data-only, so a class (per CLAUDE.md).\n */\nexport class BranchSwitch {\n branch: string;\n created: boolean;\n\n constructor(branch: string, created: boolean) {\n this.branch = branch;\n this.created = created;\n }\n}\n\nexport class BranchSwitchScan {\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {}\n\n /**\n * The branch this segment switches to, or null when the segment does not land on a branch at all:\n * a different command, no target word, `git checkout -` (the previous branch — unknowable here),\n * or anything after `--` (which ends option parsing, making the rest PATHSPECS, so\n * `git checkout -- main` restores a FILE named main and moves no branch).\n *\n * Flag-tolerant by construction: every leading flag is walked past, so `-q`, `--quiet`,\n * `--no-track`, `--detach` and friends change nothing about which word is the target.\n */\n targetOf(segment: string): BranchSwitch | null {\n const subcommand = this.scanner.gitSubcommand(segment);\n if (subcommand !== 'checkout' && subcommand !== 'switch') return null;\n\n const words = this.scanner.words(segment);\n const args = words.slice(words.indexOf(subcommand) + 1);\n\n for (let i = 0; i < args.length; i++) {\n const word = args[i];\n if (word === '--') return null;\n if (word === '-') return null;\n const created = this.createdBranch(args, i);\n if (created !== null) return created;\n if (FLAGS_WITH_VALUE.has(word)) { i++; continue; }\n if (word.startsWith('-')) continue;\n return new BranchSwitch(word, false);\n }\n return null;\n }\n\n /**\n * True only for landing on an EXISTING branch named `main` — the form that can hand you a stale\n * tree, and the form `git checkout main && git pull origin main` uses. `-b`/`-B`/`-c`/`-C` are\n * excluded because they create the branch here and now.\n *\n * This scan reads raw GIT, and it has to keep doing so even though the workflow messages now\n * prescribe `pnpm wp-sync-main` instead: what the guards recommend is not what an agent\n * necessarily types, the raw pair is still allowed and is still the L0 recovery cure, and a scan\n * that stopped recognising it would stop catching the bare `git checkout main` it exists to catch.\n */\n landsOnExistingMain(segment: string): boolean {\n const target = this.targetOf(segment);\n return target !== null && this.isExistingMain(target);\n }\n\n /** The same question for a target already parsed (switchesIn). One spelling, two entry shapes. */\n isExistingMain(target: BranchSwitch): boolean {\n return target.branch === 'main' && !target.created;\n }\n\n /** Every segment of a whole command that lands on a branch, in order. */\n switchesIn(command: string): readonly BranchSwitch[] {\n const found: BranchSwitch[] = [];\n for (const segment of this.scanner.commandSegments(command)) {\n const target = this.targetOf(segment);\n if (target !== null) found.push(target);\n }\n return found;\n }\n\n // `-b <name>` / `--orphan=<name>` — the new branch's name, or null when this word creates nothing.\n private createdBranch(args: readonly string[], i: number): BranchSwitch | null {\n const word = args[i];\n if (CREATE_FLAGS.has(word)) {\n const name = args[i + 1];\n if (name === undefined || name.startsWith('-')) return null;\n return new BranchSwitch(name, true);\n }\n const equals = word.indexOf('=');\n if (equals > 0 && CREATE_FLAGS.has(word.slice(0, equals))) {\n return new BranchSwitch(word.slice(equals + 1), true);\n }\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BashContext, Violation } from '@webpieces/hook-runtime';
|
|
2
|
+
import { BashRuleBase, EmptyRuleConfig } from '@webpieces/hook-runtime';
|
|
3
|
+
import { FixHint } from '@webpieces/hook-runtime';
|
|
4
|
+
/**
|
|
5
|
+
* Blocks a Bash command that PIPES or REDIRECTS the output of `pnpm wp-build`,
|
|
6
|
+
* `pnpm wp-review-upsert-pr` or `pnpm wp-finish-upsert-pr`, and hands back the bare command plus a
|
|
7
|
+
* `grep` of the log those commands already write.
|
|
8
|
+
*
|
|
9
|
+
* ─── The incident, measured ────────────────────────────────────────────────────────────────────────
|
|
10
|
+
* The Claude Code harness backgrounds — and then kills — a foreground Bash command that has produced
|
|
11
|
+
* no output for 600 seconds. Those three commands defend against that already: the build's output goes
|
|
12
|
+
* to a FILE, and the console gets a heartbeat roughly every ten seconds plus a `FullLog :` pointer.
|
|
13
|
+
*
|
|
14
|
+
* A PIPE deletes that defence. `pnpm wp-review-upsert-pr 2>&1 | tail -50` withholds every byte until
|
|
15
|
+
* the writer exits, because that is what `tail` is — so the terminal sees NOTHING for the length of a
|
|
16
|
+
* full build, the watchdog fires, and the work is thrown away. The last fleet audit attributed ≥100
|
|
17
|
+
* minutes of wall time to those kills across 8 agents, and this repo's primary tree alone holds 85
|
|
18
|
+
* piped `wp-*` calls, 42 of them on a build-running command (`wp-review-upsert-pr` 22,
|
|
19
|
+
* `wp-finish-upsert-pr` 17, `wp-build` 3).
|
|
20
|
+
*
|
|
21
|
+
* A `> file` redirect is the same silence, and additionally writes a second copy of a log the command
|
|
22
|
+
* already wrote.
|
|
23
|
+
*
|
|
24
|
+
* ─── Why the ORDER of the fix matters, and why this half came second ───────────────────────────────
|
|
25
|
+
* Agents pipe these commands for a REASON: stage ② and stage ③ used to print everything they did. So
|
|
26
|
+
* the output was shrunk FIRST — both stages now capture their verbose body to a log and keep only the
|
|
27
|
+
* lines an agent must act on (see `StageOutputLog` in @webpieces/pr-gate). Blocking the pipe before
|
|
28
|
+
* that would have traded a watchdog kill for a flooded context, and an agent would have routed around
|
|
29
|
+
* it with `> file` — which is why the redirect is on the blocklist too.
|
|
30
|
+
*
|
|
31
|
+
* ─── It acts UNCONDITIONALLY, and has NO config key ────────────────────────────────────────────────
|
|
32
|
+
* Like `commit-message-substitution-guard`, and for the same two reasons.
|
|
33
|
+
*
|
|
34
|
+
* It has no key because a NEW key under `hookGuards` is a key every consumer must ADD or have every
|
|
35
|
+
* Bash call blocked on upgrade (fault Y) — that shipped once already, with `whole-repo-build-guard`,
|
|
36
|
+
* and took upgrading consumers' shells down for a feature nobody had asked for. Loading here, outside
|
|
37
|
+
* the config-driven set, makes the config-sync check structurally unable to see it.
|
|
38
|
+
*
|
|
39
|
+
* It needs no switch because there is nothing for one to rescue: the cure is available for every
|
|
40
|
+
* input, is strictly better than what was blocked, and can never itself match this guard. Running the
|
|
41
|
+
* command bare gives you a heartbeat instead of silence and a log you can `grep` any number of times
|
|
42
|
+
* instead of a fixed 50 lines you have to re-run a build to change.
|
|
43
|
+
*/
|
|
44
|
+
export declare class BuildOutputPipeGuardRule extends BashRuleBase<EmptyRuleConfig> {
|
|
45
|
+
constructor();
|
|
46
|
+
private readonly scan;
|
|
47
|
+
readonly description: string;
|
|
48
|
+
get fixHint(): FixHint;
|
|
49
|
+
check(ctx: BashContext): readonly Violation[];
|
|
50
|
+
private allow;
|
|
51
|
+
private block;
|
|
52
|
+
private message;
|
|
53
|
+
private what;
|
|
54
|
+
private truncate;
|
|
55
|
+
private logDecision;
|
|
56
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuildOutputPipeGuardRule = void 0;
|
|
4
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
6
|
+
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
7
|
+
const hook_runtime_3 = require("@webpieces/hook-runtime");
|
|
8
|
+
const rules_config_2 = require("@webpieces/rules-config");
|
|
9
|
+
const decision_log_1 = require("../decision-log");
|
|
10
|
+
const hook_runtime_4 = require("@webpieces/hook-runtime");
|
|
11
|
+
const hook_runtime_5 = require("@webpieces/hook-runtime");
|
|
12
|
+
const build_output_pipe_scan_1 = require("./build-output-pipe-scan");
|
|
13
|
+
/**
|
|
14
|
+
* Blocks a Bash command that PIPES or REDIRECTS the output of `pnpm wp-build`,
|
|
15
|
+
* `pnpm wp-review-upsert-pr` or `pnpm wp-finish-upsert-pr`, and hands back the bare command plus a
|
|
16
|
+
* `grep` of the log those commands already write.
|
|
17
|
+
*
|
|
18
|
+
* ─── The incident, measured ────────────────────────────────────────────────────────────────────────
|
|
19
|
+
* The Claude Code harness backgrounds — and then kills — a foreground Bash command that has produced
|
|
20
|
+
* no output for 600 seconds. Those three commands defend against that already: the build's output goes
|
|
21
|
+
* to a FILE, and the console gets a heartbeat roughly every ten seconds plus a `FullLog :` pointer.
|
|
22
|
+
*
|
|
23
|
+
* A PIPE deletes that defence. `pnpm wp-review-upsert-pr 2>&1 | tail -50` withholds every byte until
|
|
24
|
+
* the writer exits, because that is what `tail` is — so the terminal sees NOTHING for the length of a
|
|
25
|
+
* full build, the watchdog fires, and the work is thrown away. The last fleet audit attributed ≥100
|
|
26
|
+
* minutes of wall time to those kills across 8 agents, and this repo's primary tree alone holds 85
|
|
27
|
+
* piped `wp-*` calls, 42 of them on a build-running command (`wp-review-upsert-pr` 22,
|
|
28
|
+
* `wp-finish-upsert-pr` 17, `wp-build` 3).
|
|
29
|
+
*
|
|
30
|
+
* A `> file` redirect is the same silence, and additionally writes a second copy of a log the command
|
|
31
|
+
* already wrote.
|
|
32
|
+
*
|
|
33
|
+
* ─── Why the ORDER of the fix matters, and why this half came second ───────────────────────────────
|
|
34
|
+
* Agents pipe these commands for a REASON: stage ② and stage ③ used to print everything they did. So
|
|
35
|
+
* the output was shrunk FIRST — both stages now capture their verbose body to a log and keep only the
|
|
36
|
+
* lines an agent must act on (see `StageOutputLog` in @webpieces/pr-gate). Blocking the pipe before
|
|
37
|
+
* that would have traded a watchdog kill for a flooded context, and an agent would have routed around
|
|
38
|
+
* it with `> file` — which is why the redirect is on the blocklist too.
|
|
39
|
+
*
|
|
40
|
+
* ─── It acts UNCONDITIONALLY, and has NO config key ────────────────────────────────────────────────
|
|
41
|
+
* Like `commit-message-substitution-guard`, and for the same two reasons.
|
|
42
|
+
*
|
|
43
|
+
* It has no key because a NEW key under `hookGuards` is a key every consumer must ADD or have every
|
|
44
|
+
* Bash call blocked on upgrade (fault Y) — that shipped once already, with `whole-repo-build-guard`,
|
|
45
|
+
* and took upgrading consumers' shells down for a feature nobody had asked for. Loading here, outside
|
|
46
|
+
* the config-driven set, makes the config-sync check structurally unable to see it.
|
|
47
|
+
*
|
|
48
|
+
* It needs no switch because there is nothing for one to rescue: the cure is available for every
|
|
49
|
+
* input, is strictly better than what was blocked, and can never itself match this guard. Running the
|
|
50
|
+
* command bare gives you a heartbeat instead of silence and a log you can `grep` any number of times
|
|
51
|
+
* instead of a fixed 50 lines you have to re-run a build to change.
|
|
52
|
+
*/
|
|
53
|
+
class BuildOutputPipeGuardRule extends hook_runtime_2.BashRuleBase {
|
|
54
|
+
constructor() {
|
|
55
|
+
// configKey === name and is DELIBERATELY not a real webpieces.config.json key — see the class
|
|
56
|
+
// docstring on fault Y.
|
|
57
|
+
super(new hook_runtime_2.EmptyRuleConfig(), 'build-output-pipe-guard', 'build-output-pipe-guard');
|
|
58
|
+
}
|
|
59
|
+
scan = new build_output_pipe_scan_1.BuildOutputPipeScan(new hook_runtime_4.CommandScanner(), new hook_runtime_5.ShellSegmentScan());
|
|
60
|
+
description = 'Block piping or redirecting the output of pnpm wp-build / wp-review-upsert-pr / ' +
|
|
61
|
+
'wp-finish-upsert-pr — a pipe withholds their heartbeat until exit, so the 600s watchdog kills ' +
|
|
62
|
+
'the build — and name the bare command plus a grep of the log they already write.';
|
|
63
|
+
get fixHint() {
|
|
64
|
+
return new hook_runtime_3.FixHint('Piping one of these commands hides the heartbeat that proves it is alive, and the harness ' +
|
|
65
|
+
'kills a command that has printed nothing for 600 seconds — after a full build has run.', 'Their output is ALREADY in a file. Run the command bare and read the file it names:', [
|
|
66
|
+
// Names NO command. `fixHint` is static per-rule and cannot see which command was
|
|
67
|
+
// actually piped, while `message(hit)` above already prints that exact command bare —
|
|
68
|
+
// so hardcoding one here spelled `wp-build` at somebody who piped `wp-review-upsert-pr`,
|
|
69
|
+
// which is a cure that does not match the block. One statement of the command, in the
|
|
70
|
+
// one place that knows it.
|
|
71
|
+
new rules_config_1.Option('Re-run the command named above with nothing after it — no pipe, no redirect.\n' +
|
|
72
|
+
'The console stays short — a size heartbeat, then the result and a "FullLog : <path>" line.', true),
|
|
73
|
+
new rules_config_1.Option('Then read as much or as little of that log as you like, as many times as you like:\n' +
|
|
74
|
+
' grep -n error "<the FullLog path it printed>"\n' +
|
|
75
|
+
' tail -50 "<the FullLog path it printed>"\n' +
|
|
76
|
+
'Use the path from THIS run, never one typed from memory — a stale relative path ' +
|
|
77
|
+
'greps nothing, which reads exactly like a clean build.'),
|
|
78
|
+
new rules_config_1.Option('The previous run is still on disk as "<that path>.bak", so comparing two runs ' +
|
|
79
|
+
'needs no third one.'),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
check(ctx) {
|
|
83
|
+
// Blocklist-shaped, so match on commandCode: stripping heredocs and quoted prose can only ever
|
|
84
|
+
// block LESS, and this repo's own commit messages and docs are full of these command names.
|
|
85
|
+
const hit = this.scan.firstHit(ctx.commandCode);
|
|
86
|
+
if (hit === null)
|
|
87
|
+
return this.allow(ctx);
|
|
88
|
+
return this.block(ctx, hit);
|
|
89
|
+
}
|
|
90
|
+
allow(ctx) {
|
|
91
|
+
this.logDecision(ctx, 'ALLOW', 'output-not-bounded');
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
block(ctx, hit) {
|
|
95
|
+
// BLOCK_AI_CURE: the cure is the SAME command with less typing, which the agent runs itself.
|
|
96
|
+
this.logDecision(ctx, 'BLOCK_AI_CURE', `${hit.command}-${hit.shape}`);
|
|
97
|
+
return [new hook_runtime_1.Violation(1, this.truncate(ctx.command), this.message(hit))];
|
|
98
|
+
}
|
|
99
|
+
// Short on purpose: it is read mid-task by an agent that needs the ONE next move.
|
|
100
|
+
message(hit) {
|
|
101
|
+
return `Blocked: ${this.what(hit)} \`${hit.command}\`. That command already writes its full output `
|
|
102
|
+
+ 'to a log file and prints a heartbeat while it runs — and bounding it withholds every byte '
|
|
103
|
+
+ 'until the command exits, so the harness sees a silent command and KILLS it at 600s, after '
|
|
104
|
+
+ 'the whole build has run.\n\n'
|
|
105
|
+
+ ` pnpm ${hit.command}\n\n`
|
|
106
|
+
+ 'Then grep the "FullLog : <path>" it prints. The previous run is kept beside it as `.bak`.';
|
|
107
|
+
}
|
|
108
|
+
what(hit) {
|
|
109
|
+
return hit.shape === build_output_pipe_scan_1.BOUND_BY_PIPE ? 'you piped' : 'you redirected the output of';
|
|
110
|
+
}
|
|
111
|
+
truncate(s) {
|
|
112
|
+
const MAX = 120;
|
|
113
|
+
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
114
|
+
}
|
|
115
|
+
logDecision(ctx, verdict, reason) {
|
|
116
|
+
(0, decision_log_1.logGuardDecision)(ctx.workspaceRoot, new decision_log_1.GuardDecision('build-output-pipe-guard', 'Bash', ctx.command, '-', verdict, reason, '-', rules_config_2.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.BuildOutputPipeGuardRule = BuildOutputPipeGuardRule;
|
|
120
|
+
//# sourceMappingURL=build-output-pipe-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-output-pipe-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/build-output-pipe-guard.ts"],"names":[],"mappings":"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","sourcesContent":["import { Option } from '@webpieces/rules-config';\n\nimport type { BashContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { BashRuleBase, EmptyRuleConfig } from '@webpieces/hook-runtime';\nimport { FixHint } from '@webpieces/hook-runtime';\nimport { L0_FAULT_NONE } from '@webpieces/rules-config';\nimport { logGuardDecision, GuardDecision, Verdict, MATRIX_L2_UNROWED } from '../decision-log';\nimport { CommandScanner } from '@webpieces/hook-runtime';\nimport { ShellSegmentScan } from '@webpieces/hook-runtime';\nimport { BuildOutputPipeScan, BoundedOutputHit, BOUND_BY_PIPE } from './build-output-pipe-scan';\n\n/**\n * Blocks a Bash command that PIPES or REDIRECTS the output of `pnpm wp-build`,\n * `pnpm wp-review-upsert-pr` or `pnpm wp-finish-upsert-pr`, and hands back the bare command plus a\n * `grep` of the log those commands already write.\n *\n * ─── The incident, measured ────────────────────────────────────────────────────────────────────────\n * The Claude Code harness backgrounds — and then kills — a foreground Bash command that has produced\n * no output for 600 seconds. Those three commands defend against that already: the build's output goes\n * to a FILE, and the console gets a heartbeat roughly every ten seconds plus a `FullLog :` pointer.\n *\n * A PIPE deletes that defence. `pnpm wp-review-upsert-pr 2>&1 | tail -50` withholds every byte until\n * the writer exits, because that is what `tail` is — so the terminal sees NOTHING for the length of a\n * full build, the watchdog fires, and the work is thrown away. The last fleet audit attributed ≥100\n * minutes of wall time to those kills across 8 agents, and this repo's primary tree alone holds 85\n * piped `wp-*` calls, 42 of them on a build-running command (`wp-review-upsert-pr` 22,\n * `wp-finish-upsert-pr` 17, `wp-build` 3).\n *\n * A `> file` redirect is the same silence, and additionally writes a second copy of a log the command\n * already wrote.\n *\n * ─── Why the ORDER of the fix matters, and why this half came second ───────────────────────────────\n * Agents pipe these commands for a REASON: stage ② and stage ③ used to print everything they did. So\n * the output was shrunk FIRST — both stages now capture their verbose body to a log and keep only the\n * lines an agent must act on (see `StageOutputLog` in @webpieces/pr-gate). Blocking the pipe before\n * that would have traded a watchdog kill for a flooded context, and an agent would have routed around\n * it with `> file` — which is why the redirect is on the blocklist too.\n *\n * ─── It acts UNCONDITIONALLY, and has NO config key ────────────────────────────────────────────────\n * Like `commit-message-substitution-guard`, and for the same two reasons.\n *\n * It has no key because a NEW key under `hookGuards` is a key every consumer must ADD or have every\n * Bash call blocked on upgrade (fault Y) — that shipped once already, with `whole-repo-build-guard`,\n * and took upgrading consumers' shells down for a feature nobody had asked for. Loading here, outside\n * the config-driven set, makes the config-sync check structurally unable to see it.\n *\n * It needs no switch because there is nothing for one to rescue: the cure is available for every\n * input, is strictly better than what was blocked, and can never itself match this guard. Running the\n * command bare gives you a heartbeat instead of silence and a log you can `grep` any number of times\n * instead of a fixed 50 lines you have to re-run a build to change.\n */\nexport class BuildOutputPipeGuardRule extends BashRuleBase<EmptyRuleConfig> {\n constructor() {\n // configKey === name and is DELIBERATELY not a real webpieces.config.json key — see the class\n // docstring on fault Y.\n super(new EmptyRuleConfig(), 'build-output-pipe-guard', 'build-output-pipe-guard');\n }\n\n private readonly scan = new BuildOutputPipeScan(new CommandScanner(), new ShellSegmentScan());\n\n readonly description =\n 'Block piping or redirecting the output of pnpm wp-build / wp-review-upsert-pr / ' +\n 'wp-finish-upsert-pr — a pipe withholds their heartbeat until exit, so the 600s watchdog kills ' +\n 'the build — and name the bare command plus a grep of the log they already write.';\n\n get fixHint(): FixHint {\n return new FixHint(\n 'Piping one of these commands hides the heartbeat that proves it is alive, and the harness ' +\n 'kills a command that has printed nothing for 600 seconds — after a full build has run.',\n 'Their output is ALREADY in a file. Run the command bare and read the file it names:',\n [\n // Names NO command. `fixHint` is static per-rule and cannot see which command was\n // actually piped, while `message(hit)` above already prints that exact command bare —\n // so hardcoding one here spelled `wp-build` at somebody who piped `wp-review-upsert-pr`,\n // which is a cure that does not match the block. One statement of the command, in the\n // one place that knows it.\n new Option(\n 'Re-run the command named above with nothing after it — no pipe, no redirect.\\n' +\n 'The console stays short — a size heartbeat, then the result and a \"FullLog : <path>\" line.',\n true),\n new Option(\n 'Then read as much or as little of that log as you like, as many times as you like:\\n' +\n ' grep -n error \"<the FullLog path it printed>\"\\n' +\n ' tail -50 \"<the FullLog path it printed>\"\\n' +\n 'Use the path from THIS run, never one typed from memory — a stale relative path ' +\n 'greps nothing, which reads exactly like a clean build.'),\n new Option(\n 'The previous run is still on disk as \"<that path>.bak\", so comparing two runs ' +\n 'needs no third one.'),\n ],\n );\n }\n\n check(ctx: BashContext): readonly Violation[] {\n // Blocklist-shaped, so match on commandCode: stripping heredocs and quoted prose can only ever\n // block LESS, and this repo's own commit messages and docs are full of these command names.\n const hit = this.scan.firstHit(ctx.commandCode);\n if (hit === null) return this.allow(ctx);\n return this.block(ctx, hit);\n }\n\n private allow(ctx: BashContext): readonly Violation[] {\n this.logDecision(ctx, 'ALLOW', 'output-not-bounded');\n return [];\n }\n\n private block(ctx: BashContext, hit: BoundedOutputHit): readonly Violation[] {\n // BLOCK_AI_CURE: the cure is the SAME command with less typing, which the agent runs itself.\n this.logDecision(ctx, 'BLOCK_AI_CURE', `${hit.command}-${hit.shape}`);\n return [new V(1, this.truncate(ctx.command), this.message(hit))];\n }\n\n // Short on purpose: it is read mid-task by an agent that needs the ONE next move.\n private message(hit: BoundedOutputHit): string {\n return `Blocked: ${this.what(hit)} \\`${hit.command}\\`. That command already writes its full output `\n + 'to a log file and prints a heartbeat while it runs — and bounding it withholds every byte '\n + 'until the command exits, so the harness sees a silent command and KILLS it at 600s, after '\n + 'the whole build has run.\\n\\n'\n + ` pnpm ${hit.command}\\n\\n`\n + 'Then grep the \"FullLog : <path>\" it prints. The previous run is kept beside it as `.bak`.';\n }\n\n private what(hit: BoundedOutputHit): string {\n return hit.shape === BOUND_BY_PIPE ? 'you piped' : 'you redirected the output of';\n }\n\n private truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n }\n\n private logDecision(ctx: BashContext, verdict: Verdict, reason: string): void {\n logGuardDecision(\n ctx.workspaceRoot,\n new GuardDecision(\n 'build-output-pipe-guard', 'Bash', ctx.command, '-', verdict, reason,\n '-', L0_FAULT_NONE, MATRIX_L2_UNROWED,\n ),\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CommandScanner } from '@webpieces/hook-runtime';
|
|
2
|
+
import { ShellSegmentScan } from '@webpieces/hook-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* Decides the one question `build-output-pipe-guard` asks: does this command BOUND the output of a
|
|
5
|
+
* webpieces command that already writes its output to a file?
|
|
6
|
+
*
|
|
7
|
+
* ─── The three commands, and why only these three ──────────────────────────────────────────────────
|
|
8
|
+
* `wp-build`, `wp-review-upsert-pr` and `wp-finish-upsert-pr` are the commands that RUN A BUILD. Each
|
|
9
|
+
* one redirects the build's full stdout+stderr to a log file, prints a ~10-second heartbeat while it
|
|
10
|
+
* runs, and ends with a `FullLog :` pointer at the file. Nothing else in the `wp-*` family both takes
|
|
11
|
+
* minutes and writes a log, so nothing else belongs on this list — a guard that also refused
|
|
12
|
+
* `pnpm wp-cleanup | tail` would be refusing something with no cure.
|
|
13
|
+
*
|
|
14
|
+
* ─── What is a hit ─────────────────────────────────────────────────────────────────────────────────
|
|
15
|
+
* BLOCKED a PIPE out of the command — `pnpm wp-build | tail -50`, `… 2>&1 | grep error`, `| tee`.
|
|
16
|
+
* A pipe is the measured hazard and it does not depend on WHAT it feeds: the pipeline's
|
|
17
|
+
* reader (`tail`, `head`, `grep`, `wc`) withholds every byte until the writer EXITS, so the
|
|
18
|
+
* heartbeat never reaches the terminal, the harness sees a command silent for 600 seconds,
|
|
19
|
+
* and it kills a full build. Measured in this repo's own call log: 85 piped `wp-*` calls,
|
|
20
|
+
* 42 of them on one of these three commands.
|
|
21
|
+
* BLOCKED a stdout REDIRECT to a file — `pnpm wp-build > /tmp/out.log`. Same silence, and it also
|
|
22
|
+
* makes a SECOND copy of a log the command already wrote.
|
|
23
|
+
*
|
|
24
|
+
* ALLOWED the bare command, which is the whole cure.
|
|
25
|
+
* ALLOWED `2>&1` on its own — it rewires fds and buffers nothing. `ShellSegmentScan.redirectsToFile`
|
|
26
|
+
* owns that carve-out, and it is shared rather than re-spelled here.
|
|
27
|
+
* ALLOWED every other command, piped or not. This guard is blocklist-shaped and narrow on purpose.
|
|
28
|
+
*/
|
|
29
|
+
/** The commands whose output already goes to a file, so bounding it can only ever lose information. */
|
|
30
|
+
export declare const LOGGED_BUILD_COMMANDS: readonly string[];
|
|
31
|
+
/** How the output was bounded. The two shapes read differently in a refusal, so they are named. */
|
|
32
|
+
export declare const BOUND_BY_PIPE = "pipe";
|
|
33
|
+
export declare const BOUND_BY_REDIRECT = "redirect";
|
|
34
|
+
/** One bounded invocation: WHICH command, and HOW its output was bounded. Data-only (per CLAUDE.md). */
|
|
35
|
+
export declare class BoundedOutputHit {
|
|
36
|
+
command: string;
|
|
37
|
+
shape: string;
|
|
38
|
+
constructor(command: string, shape: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class BuildOutputPipeScan {
|
|
41
|
+
private readonly scanner;
|
|
42
|
+
private readonly segments;
|
|
43
|
+
constructor(scanner: CommandScanner, segments: ShellSegmentScan);
|
|
44
|
+
/** The first bounded logging command in `command`, or null when there is none. */
|
|
45
|
+
firstHit(command: string): BoundedOutputHit | null;
|
|
46
|
+
private loggingCommandIn;
|
|
47
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuildOutputPipeScan = exports.BoundedOutputHit = exports.BOUND_BY_REDIRECT = exports.BOUND_BY_PIPE = exports.LOGGED_BUILD_COMMANDS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Decides the one question `build-output-pipe-guard` asks: does this command BOUND the output of a
|
|
6
|
+
* webpieces command that already writes its output to a file?
|
|
7
|
+
*
|
|
8
|
+
* ─── The three commands, and why only these three ──────────────────────────────────────────────────
|
|
9
|
+
* `wp-build`, `wp-review-upsert-pr` and `wp-finish-upsert-pr` are the commands that RUN A BUILD. Each
|
|
10
|
+
* one redirects the build's full stdout+stderr to a log file, prints a ~10-second heartbeat while it
|
|
11
|
+
* runs, and ends with a `FullLog :` pointer at the file. Nothing else in the `wp-*` family both takes
|
|
12
|
+
* minutes and writes a log, so nothing else belongs on this list — a guard that also refused
|
|
13
|
+
* `pnpm wp-cleanup | tail` would be refusing something with no cure.
|
|
14
|
+
*
|
|
15
|
+
* ─── What is a hit ─────────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
* BLOCKED a PIPE out of the command — `pnpm wp-build | tail -50`, `… 2>&1 | grep error`, `| tee`.
|
|
17
|
+
* A pipe is the measured hazard and it does not depend on WHAT it feeds: the pipeline's
|
|
18
|
+
* reader (`tail`, `head`, `grep`, `wc`) withholds every byte until the writer EXITS, so the
|
|
19
|
+
* heartbeat never reaches the terminal, the harness sees a command silent for 600 seconds,
|
|
20
|
+
* and it kills a full build. Measured in this repo's own call log: 85 piped `wp-*` calls,
|
|
21
|
+
* 42 of them on one of these three commands.
|
|
22
|
+
* BLOCKED a stdout REDIRECT to a file — `pnpm wp-build > /tmp/out.log`. Same silence, and it also
|
|
23
|
+
* makes a SECOND copy of a log the command already wrote.
|
|
24
|
+
*
|
|
25
|
+
* ALLOWED the bare command, which is the whole cure.
|
|
26
|
+
* ALLOWED `2>&1` on its own — it rewires fds and buffers nothing. `ShellSegmentScan.redirectsToFile`
|
|
27
|
+
* owns that carve-out, and it is shared rather than re-spelled here.
|
|
28
|
+
* ALLOWED every other command, piped or not. This guard is blocklist-shaped and narrow on purpose.
|
|
29
|
+
*/
|
|
30
|
+
/** The commands whose output already goes to a file, so bounding it can only ever lose information. */
|
|
31
|
+
exports.LOGGED_BUILD_COMMANDS = [
|
|
32
|
+
'wp-build', 'wp-review-upsert-pr', 'wp-finish-upsert-pr',
|
|
33
|
+
];
|
|
34
|
+
const LOGGED_SET = new Set(exports.LOGGED_BUILD_COMMANDS);
|
|
35
|
+
/** How the output was bounded. The two shapes read differently in a refusal, so they are named. */
|
|
36
|
+
exports.BOUND_BY_PIPE = 'pipe';
|
|
37
|
+
exports.BOUND_BY_REDIRECT = 'redirect';
|
|
38
|
+
/** One bounded invocation: WHICH command, and HOW its output was bounded. Data-only (per CLAUDE.md). */
|
|
39
|
+
class BoundedOutputHit {
|
|
40
|
+
command;
|
|
41
|
+
shape;
|
|
42
|
+
constructor(command, shape) {
|
|
43
|
+
this.command = command;
|
|
44
|
+
this.shape = shape;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BoundedOutputHit = BoundedOutputHit;
|
|
48
|
+
class BuildOutputPipeScan {
|
|
49
|
+
scanner;
|
|
50
|
+
segments;
|
|
51
|
+
constructor(scanner, segments) {
|
|
52
|
+
this.scanner = scanner;
|
|
53
|
+
this.segments = segments;
|
|
54
|
+
}
|
|
55
|
+
/** The first bounded logging command in `command`, or null when there is none. */
|
|
56
|
+
firstHit(command) {
|
|
57
|
+
const parts = this.scanner.segmentsWithJoins(command);
|
|
58
|
+
for (let i = 0; i < parts.length; i++) {
|
|
59
|
+
const name = this.loggingCommandIn(parts[i]);
|
|
60
|
+
if (name === '')
|
|
61
|
+
continue;
|
|
62
|
+
// The NEXT segment carries the separator that preceded it, so "this segment pipes OUT" is
|
|
63
|
+
// "the segment after me was piped into". Splitting on `|` throws that away; CommandSegment
|
|
64
|
+
// exists precisely so it does not have to be re-derived here.
|
|
65
|
+
if (i + 1 < parts.length && parts[i + 1].join === '|')
|
|
66
|
+
return new BoundedOutputHit(name, exports.BOUND_BY_PIPE);
|
|
67
|
+
if (this.segments.redirectsToFile(this.scanner.words(parts[i].text))) {
|
|
68
|
+
return new BoundedOutputHit(name, exports.BOUND_BY_REDIRECT);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// The logging command this segment invokes, or '' — `pnpm wp-build`, `npx wp-build` and a bare
|
|
74
|
+
// `wp-build` are one command, which is CommandScanner's `runnerStrippedWords` to decide.
|
|
75
|
+
loggingCommandIn(segment) {
|
|
76
|
+
const words = this.scanner.runnerStrippedWords(segment.text);
|
|
77
|
+
if (words.length === 0)
|
|
78
|
+
return '';
|
|
79
|
+
const program = this.scanner.programName(words[0]);
|
|
80
|
+
return LOGGED_SET.has(program) ? program : '';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.BuildOutputPipeScan = BuildOutputPipeScan;
|
|
84
|
+
//# sourceMappingURL=build-output-pipe-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-output-pipe-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/build-output-pipe-scan.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,uGAAuG;AAC1F,QAAA,qBAAqB,GAAsB;IACpD,UAAU,EAAE,qBAAqB,EAAE,qBAAqB;CAC3D,CAAC;AAEF,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC,6BAAqB,CAAC,CAAC;AAEvE,mGAAmG;AACtF,QAAA,aAAa,GAAG,MAAM,CAAC;AACvB,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAE5C,wGAAwG;AACxG,MAAa,gBAAgB;IACzB,OAAO,CAAS;IAChB,KAAK,CAAS;IAEd,YAAY,OAAe,EAAE,KAAa;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AARD,4CAQC;AAED,MAAa,mBAAmB;IAEP;IACA;IAFrB,YACqB,OAAuB,EACvB,QAA0B;QAD1B,YAAO,GAAP,OAAO,CAAgB;QACvB,aAAQ,GAAR,QAAQ,CAAkB;IAC5C,CAAC;IAEJ,kFAAkF;IAClF,QAAQ,CAAC,OAAe;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,IAAI,KAAK,EAAE;gBAAE,SAAS;YAC1B,0FAA0F;YAC1F,2FAA2F;YAC3F,8DAA8D;YAC9D,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG;gBAAE,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,qBAAa,CAAC,CAAC;YACxG,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,yBAAiB,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,+FAA+F;IAC/F,yFAAyF;IACjF,gBAAgB,CAAC,OAAuB;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ;AA/BD,kDA+BC","sourcesContent":["import { CommandScanner, CommandSegment } from '@webpieces/hook-runtime';\nimport { ShellSegmentScan } from '@webpieces/hook-runtime';\n\n/**\n * Decides the one question `build-output-pipe-guard` asks: does this command BOUND the output of a\n * webpieces command that already writes its output to a file?\n *\n * ─── The three commands, and why only these three ──────────────────────────────────────────────────\n * `wp-build`, `wp-review-upsert-pr` and `wp-finish-upsert-pr` are the commands that RUN A BUILD. Each\n * one redirects the build's full stdout+stderr to a log file, prints a ~10-second heartbeat while it\n * runs, and ends with a `FullLog :` pointer at the file. Nothing else in the `wp-*` family both takes\n * minutes and writes a log, so nothing else belongs on this list — a guard that also refused\n * `pnpm wp-cleanup | tail` would be refusing something with no cure.\n *\n * ─── What is a hit ─────────────────────────────────────────────────────────────────────────────────\n * BLOCKED a PIPE out of the command — `pnpm wp-build | tail -50`, `… 2>&1 | grep error`, `| tee`.\n * A pipe is the measured hazard and it does not depend on WHAT it feeds: the pipeline's\n * reader (`tail`, `head`, `grep`, `wc`) withholds every byte until the writer EXITS, so the\n * heartbeat never reaches the terminal, the harness sees a command silent for 600 seconds,\n * and it kills a full build. Measured in this repo's own call log: 85 piped `wp-*` calls,\n * 42 of them on one of these three commands.\n * BLOCKED a stdout REDIRECT to a file — `pnpm wp-build > /tmp/out.log`. Same silence, and it also\n * makes a SECOND copy of a log the command already wrote.\n *\n * ALLOWED the bare command, which is the whole cure.\n * ALLOWED `2>&1` on its own — it rewires fds and buffers nothing. `ShellSegmentScan.redirectsToFile`\n * owns that carve-out, and it is shared rather than re-spelled here.\n * ALLOWED every other command, piped or not. This guard is blocklist-shaped and narrow on purpose.\n */\n\n/** The commands whose output already goes to a file, so bounding it can only ever lose information. */\nexport const LOGGED_BUILD_COMMANDS: readonly string[] = [\n 'wp-build', 'wp-review-upsert-pr', 'wp-finish-upsert-pr',\n];\n\nconst LOGGED_SET: ReadonlySet<string> = new Set(LOGGED_BUILD_COMMANDS);\n\n/** How the output was bounded. The two shapes read differently in a refusal, so they are named. */\nexport const BOUND_BY_PIPE = 'pipe';\nexport const BOUND_BY_REDIRECT = 'redirect';\n\n/** One bounded invocation: WHICH command, and HOW its output was bounded. Data-only (per CLAUDE.md). */\nexport class BoundedOutputHit {\n command: string;\n shape: string;\n\n constructor(command: string, shape: string) {\n this.command = command;\n this.shape = shape;\n }\n}\n\nexport class BuildOutputPipeScan {\n constructor(\n private readonly scanner: CommandScanner,\n private readonly segments: ShellSegmentScan,\n ) {}\n\n /** The first bounded logging command in `command`, or null when there is none. */\n firstHit(command: string): BoundedOutputHit | null {\n const parts = this.scanner.segmentsWithJoins(command);\n for (let i = 0; i < parts.length; i++) {\n const name = this.loggingCommandIn(parts[i]);\n if (name === '') continue;\n // The NEXT segment carries the separator that preceded it, so \"this segment pipes OUT\" is\n // \"the segment after me was piped into\". Splitting on `|` throws that away; CommandSegment\n // exists precisely so it does not have to be re-derived here.\n if (i + 1 < parts.length && parts[i + 1].join === '|') return new BoundedOutputHit(name, BOUND_BY_PIPE);\n if (this.segments.redirectsToFile(this.scanner.words(parts[i].text))) {\n return new BoundedOutputHit(name, BOUND_BY_REDIRECT);\n }\n }\n return null;\n }\n\n // The logging command this segment invokes, or '' — `pnpm wp-build`, `npx wp-build` and a bare\n // `wp-build` are one command, which is CommandScanner's `runnerStrippedWords` to decide.\n private loggingCommandIn(segment: CommandSegment): string {\n const words = this.scanner.runnerStrippedWords(segment.text);\n if (words.length === 0) return '';\n const program = this.scanner.programName(words[0]);\n return LOGGED_SET.has(program) ? program : '';\n }\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FixHint } from '@webpieces/hook-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* What branch-creation-guard says when a CAP is what blocked. TWO SHORT LINES, and never a
|
|
4
|
+
* destructive command.
|
|
5
|
+
*
|
|
6
|
+
* It used to be forty. The branch remedy printed every spared branch with its SHA, PR state, unique
|
|
7
|
+
* commit count and prose reason, told the agent to paste that table at the human and ask which may
|
|
8
|
+
* go, and then listed the config knobs it must not touch. The human's verdict on that, verbatim:
|
|
9
|
+
* "I am tired of AI asking me to cleanup things it can do by itself". They were right twice over —
|
|
10
|
+
* the wall of text buried the one actionable line, and the biggest spared group (pre-merge snapshots
|
|
11
|
+
* of a branch that still exists) was never a judgement call at all. That group is auto-reaped now
|
|
12
|
+
* (see CLASSIFICATION_BACKUP_OF_LIVE), so the remedy is one command.
|
|
13
|
+
*
|
|
14
|
+
* Everything this class used to say still exists — in `pnpm wp-cleanup`, which recomputes the
|
|
15
|
+
* verdicts fresh, archives each branch as an `archive/<date>/<branch>` tag before deleting, logs a
|
|
16
|
+
* `recover=` command per removal, refuses the primary clone and the tree it is standing in, never
|
|
17
|
+
* passes `--force`, and PROMPTS about anything not provably dead. A guard that duplicates that
|
|
18
|
+
* inventory is a second copy to keep in sync and a wall to read before running the command anyway.
|
|
19
|
+
* So: name the command, stop talking.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CapRemedies {
|
|
22
|
+
/**
|
|
23
|
+
* Deliberately takes no cache and quotes no figures. The cache is allowed to be stale by design,
|
|
24
|
+
* and a stale table is worse than no table when the reader's next move is `wp-cleanup` — which
|
|
25
|
+
* recomputes from scratch — either way.
|
|
26
|
+
*
|
|
27
|
+
* "ASK THE HUMAN" stays spelled out. Shortening it to a bare "ask" saves two words and loses the
|
|
28
|
+
* object of the verb — and the reader is an agent, which can satisfy a bare "ask" by asking
|
|
29
|
+
* itself. Every other guard in this codebase says ASK THE HUMAN for the same reason.
|
|
30
|
+
*/
|
|
31
|
+
branchCap(): FixHint;
|
|
32
|
+
/**
|
|
33
|
+
* Same shape for worktrees, with one extra sentence that is not boilerplate: a worktree whose
|
|
34
|
+
* branch has no commits yet is almost always one an agent is working in RIGHT NOW. That is why
|
|
35
|
+
* this never emits `git worktree remove` — it once printed a `prune && remove && branch -D` chain
|
|
36
|
+
* naming three live worktrees under the words "so no work can be lost".
|
|
37
|
+
*/
|
|
38
|
+
worktreeCap(): FixHint;
|
|
39
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CapRemedies = void 0;
|
|
4
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
5
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
/**
|
|
7
|
+
* What branch-creation-guard says when a CAP is what blocked. TWO SHORT LINES, and never a
|
|
8
|
+
* destructive command.
|
|
9
|
+
*
|
|
10
|
+
* It used to be forty. The branch remedy printed every spared branch with its SHA, PR state, unique
|
|
11
|
+
* commit count and prose reason, told the agent to paste that table at the human and ask which may
|
|
12
|
+
* go, and then listed the config knobs it must not touch. The human's verdict on that, verbatim:
|
|
13
|
+
* "I am tired of AI asking me to cleanup things it can do by itself". They were right twice over —
|
|
14
|
+
* the wall of text buried the one actionable line, and the biggest spared group (pre-merge snapshots
|
|
15
|
+
* of a branch that still exists) was never a judgement call at all. That group is auto-reaped now
|
|
16
|
+
* (see CLASSIFICATION_BACKUP_OF_LIVE), so the remedy is one command.
|
|
17
|
+
*
|
|
18
|
+
* Everything this class used to say still exists — in `pnpm wp-cleanup`, which recomputes the
|
|
19
|
+
* verdicts fresh, archives each branch as an `archive/<date>/<branch>` tag before deleting, logs a
|
|
20
|
+
* `recover=` command per removal, refuses the primary clone and the tree it is standing in, never
|
|
21
|
+
* passes `--force`, and PROMPTS about anything not provably dead. A guard that duplicates that
|
|
22
|
+
* inventory is a second copy to keep in sync and a wall to read before running the command anyway.
|
|
23
|
+
* So: name the command, stop talking.
|
|
24
|
+
*/
|
|
25
|
+
class CapRemedies {
|
|
26
|
+
/**
|
|
27
|
+
* Deliberately takes no cache and quotes no figures. The cache is allowed to be stale by design,
|
|
28
|
+
* and a stale table is worse than no table when the reader's next move is `wp-cleanup` — which
|
|
29
|
+
* recomputes from scratch — either way.
|
|
30
|
+
*
|
|
31
|
+
* "ASK THE HUMAN" stays spelled out. Shortening it to a bare "ask" saves two words and loses the
|
|
32
|
+
* object of the verb — and the reader is an agent, which can satisfy a bare "ask" by asking
|
|
33
|
+
* itself. Every other guard in this codebase says ASK THE HUMAN for the same reason.
|
|
34
|
+
*/
|
|
35
|
+
branchCap() {
|
|
36
|
+
return new hook_runtime_1.FixHint('Too many local branches.', '', [
|
|
37
|
+
new rules_config_1.Option('Run: pnpm wp-cleanup — reaps the dead branches and the zero-commit husks.', true),
|
|
38
|
+
new rules_config_1.Option('Only if that leaves you at the cap: ASK THE HUMAN which of the branches it spared ' +
|
|
39
|
+
'may go. Never delete a spared branch or edit webpieces.config.json ' +
|
|
40
|
+
'(maxLocalBranches / turnOffRuleUntilEpoch) without their explicit yes.'),
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Same shape for worktrees, with one extra sentence that is not boilerplate: a worktree whose
|
|
45
|
+
* branch has no commits yet is almost always one an agent is working in RIGHT NOW. That is why
|
|
46
|
+
* this never emits `git worktree remove` — it once printed a `prune && remove && branch -D` chain
|
|
47
|
+
* naming three live worktrees under the words "so no work can be lost".
|
|
48
|
+
*/
|
|
49
|
+
worktreeCap() {
|
|
50
|
+
return new hook_runtime_1.FixHint('Too many worktrees. Do NOT remove one by hand — an agent may be working in it right now.', '', [
|
|
51
|
+
new rules_config_1.Option('Run: pnpm wp-cleanup — removes the dead worktrees and the unheld husks.', true),
|
|
52
|
+
new rules_config_1.Option('Only if that leaves you at the cap: ASK THE HUMAN which of the worktrees it spared ' +
|
|
53
|
+
'may go. Never edit webpieces.config.json (maxWorktrees / turnOffRuleUntilEpoch) ' +
|
|
54
|
+
'without their explicit yes.'),
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.CapRemedies = CapRemedies;
|
|
59
|
+
//# sourceMappingURL=cap-remedies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cap-remedies.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/cap-remedies.ts"],"names":[],"mappings":";;;AAAA,0DAAkD;AAClD,0DAAiD;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,WAAW;IACpB;;;;;;;;OAQG;IACH,SAAS;QACL,OAAO,IAAI,sBAAO,CACd,0BAA0B,EAC1B,EAAE,EACF;YACI,IAAI,qBAAM,CAAC,2EAA2E,EAAE,IAAI,CAAC;YAC7F,IAAI,qBAAM,CACN,oFAAoF;gBACpF,qEAAqE;gBACrE,wEAAwE,CAC3E;SACJ,CACJ,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,WAAW;QACP,OAAO,IAAI,sBAAO,CACd,0FAA0F,EAC1F,EAAE,EACF;YACI,IAAI,qBAAM,CAAC,yEAAyE,EAAE,IAAI,CAAC;YAC3F,IAAI,qBAAM,CACN,qFAAqF;gBACrF,kFAAkF;gBAClF,6BAA6B,CAChC;SACJ,CACJ,CAAC;IACN,CAAC;CACJ;AA7CD,kCA6CC","sourcesContent":["import { FixHint } from '@webpieces/hook-runtime';\nimport { Option } from '@webpieces/rules-config';\n\n/**\n * What branch-creation-guard says when a CAP is what blocked. TWO SHORT LINES, and never a\n * destructive command.\n *\n * It used to be forty. The branch remedy printed every spared branch with its SHA, PR state, unique\n * commit count and prose reason, told the agent to paste that table at the human and ask which may\n * go, and then listed the config knobs it must not touch. The human's verdict on that, verbatim:\n * \"I am tired of AI asking me to cleanup things it can do by itself\". They were right twice over —\n * the wall of text buried the one actionable line, and the biggest spared group (pre-merge snapshots\n * of a branch that still exists) was never a judgement call at all. That group is auto-reaped now\n * (see CLASSIFICATION_BACKUP_OF_LIVE), so the remedy is one command.\n *\n * Everything this class used to say still exists — in `pnpm wp-cleanup`, which recomputes the\n * verdicts fresh, archives each branch as an `archive/<date>/<branch>` tag before deleting, logs a\n * `recover=` command per removal, refuses the primary clone and the tree it is standing in, never\n * passes `--force`, and PROMPTS about anything not provably dead. A guard that duplicates that\n * inventory is a second copy to keep in sync and a wall to read before running the command anyway.\n * So: name the command, stop talking.\n */\nexport class CapRemedies {\n /**\n * Deliberately takes no cache and quotes no figures. The cache is allowed to be stale by design,\n * and a stale table is worse than no table when the reader's next move is `wp-cleanup` — which\n * recomputes from scratch — either way.\n *\n * \"ASK THE HUMAN\" stays spelled out. Shortening it to a bare \"ask\" saves two words and loses the\n * object of the verb — and the reader is an agent, which can satisfy a bare \"ask\" by asking\n * itself. Every other guard in this codebase says ASK THE HUMAN for the same reason.\n */\n branchCap(): FixHint {\n return new FixHint(\n 'Too many local branches.',\n '',\n [\n new Option('Run: pnpm wp-cleanup — reaps the dead branches and the zero-commit husks.', true),\n new Option(\n 'Only if that leaves you at the cap: ASK THE HUMAN which of the branches it spared ' +\n 'may go. Never delete a spared branch or edit webpieces.config.json ' +\n '(maxLocalBranches / turnOffRuleUntilEpoch) without their explicit yes.',\n ),\n ],\n );\n }\n\n /**\n * Same shape for worktrees, with one extra sentence that is not boilerplate: a worktree whose\n * branch has no commits yet is almost always one an agent is working in RIGHT NOW. That is why\n * this never emits `git worktree remove` — it once printed a `prune && remove && branch -D` chain\n * naming three live worktrees under the words \"so no work can be lost\".\n */\n worktreeCap(): FixHint {\n return new FixHint(\n 'Too many worktrees. Do NOT remove one by hand — an agent may be working in it right now.',\n '',\n [\n new Option('Run: pnpm wp-cleanup — removes the dead worktrees and the unheld husks.', true),\n new Option(\n 'Only if that leaves you at the cap: ASK THE HUMAN which of the worktrees it spared ' +\n 'may go. Never edit webpieces.config.json (maxWorktrees / turnOffRuleUntilEpoch) ' +\n 'without their explicit yes.',\n ),\n ],\n );\n }\n}\n"]}
|