@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,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExcludedPathEscapeHint = exports.ExcludedPathEscapeScan = exports.ExcludedPathReference = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
7
|
+
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
8
|
+
/**
|
|
9
|
+
* One path the denied command NAMED that `excludePaths` already exempts, plus how to reach it.
|
|
10
|
+
*
|
|
11
|
+
* Data-only, so a class (per CLAUDE.md).
|
|
12
|
+
*
|
|
13
|
+
* `cdDirectory` is the whole point of the class rather than a bare string: it is a directory that
|
|
14
|
+
* ITSELF satisfies `globMatches` against one of the configured globs, or null when no such directory
|
|
15
|
+
* exists for this reference. Callers must never invent one — see ExcludedPathEscapeScan for why a
|
|
16
|
+
* naive `dirname` is wrong exactly when it looks most obviously right.
|
|
17
|
+
*/
|
|
18
|
+
class ExcludedPathReference {
|
|
19
|
+
/** The referenced path, workspace-relative, as it was matched. */
|
|
20
|
+
referencedPath;
|
|
21
|
+
/** The `excludePaths` glob that matched it — quoted back so the agent need not re-derive it. */
|
|
22
|
+
matchedGlob;
|
|
23
|
+
/** A directory a `cd` may legally land in (matches a glob on its own), or null when none does. */
|
|
24
|
+
cdDirectory;
|
|
25
|
+
/** `referencedPath` re-expressed relative to `cdDirectory`; '' when there is no `cdDirectory`. */
|
|
26
|
+
pathFromCdDirectory;
|
|
27
|
+
constructor(referencedPath, matchedGlob, cdDirectory, pathFromCdDirectory) {
|
|
28
|
+
this.referencedPath = referencedPath;
|
|
29
|
+
this.matchedGlob = matchedGlob;
|
|
30
|
+
this.cdDirectory = cdDirectory;
|
|
31
|
+
this.pathFromCdDirectory = pathFromCdDirectory;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ExcludedPathReference = ExcludedPathReference;
|
|
35
|
+
/**
|
|
36
|
+
* Finds the paths a BASH command names that the top-level `excludePaths` already exempts.
|
|
37
|
+
*
|
|
38
|
+
* WHY this exists: the bash guards judge the shell's effective CWD, not the paths in the command, so
|
|
39
|
+
* `cat .webpieces/tasks.md` at the repo root is DENIED even though that exact file is exempt from
|
|
40
|
+
* every guard and was reachable, that instant, through Read/Write. Every remedy the deny body printed
|
|
41
|
+
* was a git state change — strictly more destructive than the one it omitted. This class supplies the
|
|
42
|
+
* missing sentence; it changes no verdict.
|
|
43
|
+
*
|
|
44
|
+
* A token is treated as a candidate path with no filesystem check: whether it exists says nothing
|
|
45
|
+
* about whether it is exempt, and a stat per token on the blocking hook path is exactly the cost these
|
|
46
|
+
* guards avoid. Non-path tokens (a `grep` pattern, a `sed` script) simply match no glob.
|
|
47
|
+
*/
|
|
48
|
+
class ExcludedPathEscapeScan {
|
|
49
|
+
scanner;
|
|
50
|
+
workspaceRoot;
|
|
51
|
+
effectiveCwd;
|
|
52
|
+
/**
|
|
53
|
+
* `effectiveCwd` is the directory the command really runs in, after its own leading `cd` — the
|
|
54
|
+
* same base ContentReadScan resolves relative operands against. RELATIVE tokens are resolved
|
|
55
|
+
* there and ABSOLUTE ones normalised straight to workspace-relative, which is how
|
|
56
|
+
* `cat /abs/path/to/repo/.webpieces/tasks.md` reaches the same verdict as `cat .webpieces/tasks.md`.
|
|
57
|
+
*/
|
|
58
|
+
constructor(scanner, workspaceRoot, effectiveCwd) {
|
|
59
|
+
this.scanner = scanner;
|
|
60
|
+
this.workspaceRoot = workspaceRoot;
|
|
61
|
+
this.effectiveCwd = effectiveCwd;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Every excluded path this command references, in command order, de-duplicated.
|
|
65
|
+
*
|
|
66
|
+
* Scans EVERY segment, not just a leading `cd`: `cat x`, `grep -n foo x`, `sed -n '1,5p' x` and a
|
|
67
|
+
* path inside an `&&` compound all count, because the agent's next move depends on the file it
|
|
68
|
+
* wanted, wherever in the line it named it.
|
|
69
|
+
*/
|
|
70
|
+
references(command, ex) {
|
|
71
|
+
if (ex.paths.length === 0)
|
|
72
|
+
return [];
|
|
73
|
+
const found = [];
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
for (const token of this.candidateTokens(command)) {
|
|
76
|
+
const relative = this.workspaceRelative(token);
|
|
77
|
+
if (relative === null || seen.has(relative))
|
|
78
|
+
continue;
|
|
79
|
+
seen.add(relative);
|
|
80
|
+
const glob = this.matchingGlob(relative, ex);
|
|
81
|
+
if (glob === null)
|
|
82
|
+
continue;
|
|
83
|
+
found.push(this.reference(relative, glob, ex));
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
// Build the reference, including the `cd` target — the ONE subtle part, see cdDirectory below.
|
|
88
|
+
reference(relative, glob, ex) {
|
|
89
|
+
const dir = this.cdDirectory(relative, ex);
|
|
90
|
+
return new ExcludedPathReference(relative, glob, dir, dir === null ? '' : path.relative(dir, relative));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A directory the agent may `cd` into and have the guards actually stand down, or null.
|
|
94
|
+
*
|
|
95
|
+
* THE TRAP: the bash path matches the relative cwd with `globMatches`, which compiles
|
|
96
|
+
* `.webpieces/**` to the anchored `/^\.webpieces\/.*$/` — the `/` is a LITERAL, so the bare
|
|
97
|
+
* directory `.webpieces` does NOT match its own glob. `cd .webpieces && cat tasks.md` is still
|
|
98
|
+
* denied. Emitting that would be worse than emitting nothing: it looks authoritative and costs a
|
|
99
|
+
* turn to disprove. So the directory is only offered when it passes the very same matcher the
|
|
100
|
+
* runner will use, and the renderer says so plainly when nothing does.
|
|
101
|
+
*/
|
|
102
|
+
cdDirectory(relative, ex) {
|
|
103
|
+
const dir = path.dirname(relative);
|
|
104
|
+
if (dir === '.' || dir === '' || dir === relative)
|
|
105
|
+
return null;
|
|
106
|
+
return this.matchingGlob(dir, ex) === null ? null : dir;
|
|
107
|
+
}
|
|
108
|
+
// The first configured glob this workspace-relative path satisfies, under the runner's OWN matcher
|
|
109
|
+
// (globMatches, load-rules.ts) — never a looser one, or the stanza would promise an exemption the
|
|
110
|
+
// guards do not grant.
|
|
111
|
+
matchingGlob(relative, ex) {
|
|
112
|
+
for (const pattern of ex.paths) {
|
|
113
|
+
if ((0, hook_runtime_2.globMatches)(pattern, relative))
|
|
114
|
+
return pattern;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Workspace-relative form of a token, or null when it is not a path inside this workspace.
|
|
120
|
+
*
|
|
121
|
+
* `~`-rooted and out-of-tree paths are nothing to do with this repo's exclusions, and the
|
|
122
|
+
* workspace root itself ('') matches no glob by construction.
|
|
123
|
+
*/
|
|
124
|
+
workspaceRelative(token) {
|
|
125
|
+
const cleaned = token.replace(REDIRECT_PREFIX, '');
|
|
126
|
+
if (cleaned === '' || cleaned.startsWith('~'))
|
|
127
|
+
return null;
|
|
128
|
+
const absolute = path.isAbsolute(cleaned) ? cleaned : path.resolve(this.effectiveCwd, cleaned);
|
|
129
|
+
const relative = path.relative(this.workspaceRoot, absolute);
|
|
130
|
+
if (relative === '' || relative.startsWith('..'))
|
|
131
|
+
return null;
|
|
132
|
+
return relative;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Every token that could name a file: each segment's words minus the command word itself and
|
|
136
|
+
* minus flags. Deliberately generous — a token that is not a path matches no glob, while a token
|
|
137
|
+
* dropped by a cleverer filter is a file the agent is never told it can read.
|
|
138
|
+
*/
|
|
139
|
+
candidateTokens(command) {
|
|
140
|
+
const tokens = [];
|
|
141
|
+
for (const segment of this.scanner.commandSegments(command)) {
|
|
142
|
+
const words = this.scanner.words(segment);
|
|
143
|
+
for (let i = 1; i < words.length; i++) {
|
|
144
|
+
if (words[i].startsWith('-'))
|
|
145
|
+
continue;
|
|
146
|
+
tokens.push(words[i]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return tokens;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.ExcludedPathEscapeScan = ExcludedPathEscapeScan;
|
|
153
|
+
// A redirection glued to its target (`>out.log`, `2>>err.log`, `<in.txt`) — strip the operator so the
|
|
154
|
+
// target is scanned as the path it is.
|
|
155
|
+
const REDIRECT_PREFIX = /^\d*(?:>>?|<)/;
|
|
156
|
+
/**
|
|
157
|
+
* Renders the leading stanza of a bash deny body: the Read/Write escape the agent already has, and —
|
|
158
|
+
* when one genuinely exists — the `cd` that makes bash itself work.
|
|
159
|
+
*
|
|
160
|
+
* It goes at the TOP of the report, above the git remedies, because the agent acts on the first
|
|
161
|
+
* actionable thing it reads. The live incident this fixes had the agent create a branch in a human's
|
|
162
|
+
* working tree to record a row in a gitignored scratch file; the cheap, side-effect-free path was one
|
|
163
|
+
* sentence away and never printed. Returns '' when the command names no excluded path, so a repo
|
|
164
|
+
* without exemptions — and every command that names nothing exempt — sees no extra noise.
|
|
165
|
+
*/
|
|
166
|
+
class ExcludedPathEscapeHint {
|
|
167
|
+
scan;
|
|
168
|
+
/** `effectiveCwd` is the directory the command really runs in — see ExcludedPathEscapeScan. */
|
|
169
|
+
constructor(workspaceRoot, effectiveCwd) {
|
|
170
|
+
this.scan = new ExcludedPathEscapeScan(new hook_runtime_1.CommandScanner(), workspaceRoot, effectiveCwd);
|
|
171
|
+
}
|
|
172
|
+
render(command, ex) {
|
|
173
|
+
const references = this.scan.references(command, ex);
|
|
174
|
+
if (references.length === 0)
|
|
175
|
+
return '';
|
|
176
|
+
const lines = [];
|
|
177
|
+
lines.push('✅ YOU CAN USE THE READ/WRITE TOOLS RIGHT NOW — no git operation needed.');
|
|
178
|
+
lines.push(' These paths are in excludePaths and are exempt from every guard:');
|
|
179
|
+
for (const glob of ex.paths)
|
|
180
|
+
lines.push(` ${glob}`);
|
|
181
|
+
lines.push(` Your command referenced: ${references.map((r) => r.referencedPath).join(', ')}`);
|
|
182
|
+
// Scoped to the FILE, deliberately. The stanza fires on any rule block whose command names an
|
|
183
|
+
// exempt path, and `git push … && cat .webpieces/tasks.md` is blocked for the push — for which
|
|
184
|
+
// Read/Write substitutes for nothing. Claiming the remedies below were optional would be false.
|
|
185
|
+
lines.push(' Read/Write/Edit reaches that file RIGHT NOW, with no git operation at all.');
|
|
186
|
+
lines.push(' Anything ELSE this command does — a git/gh operation, a build — still needs the');
|
|
187
|
+
lines.push(' remedies below.');
|
|
188
|
+
const bash = this.bashLines(references);
|
|
189
|
+
if (bash.length > 0) {
|
|
190
|
+
lines.push('');
|
|
191
|
+
for (const line of bash)
|
|
192
|
+
lines.push(line);
|
|
193
|
+
}
|
|
194
|
+
lines.push('');
|
|
195
|
+
return lines.join('\n');
|
|
196
|
+
}
|
|
197
|
+
// The bash half: the `cd` when one matches, the honest refusal to invent one when none does, and
|
|
198
|
+
// silence when there is not even a directory worth naming.
|
|
199
|
+
bashLines(references) {
|
|
200
|
+
const withCd = references.find((r) => r.cdDirectory !== null);
|
|
201
|
+
if (withCd !== undefined)
|
|
202
|
+
return this.cdLines(withCd);
|
|
203
|
+
// A workspace-ROOT-level file — matched by a file-shaped glob like `*.md` — has no directory to
|
|
204
|
+
// name: `dirname` is `.`, which no excludePaths glob can usefully exempt (the relative cwd at
|
|
205
|
+
// the root is '', so `.` would never match) and which reads as "exempt the whole repo". Say
|
|
206
|
+
// nothing about bash rather than something false.
|
|
207
|
+
const nested = references.find((r) => path.dirname(r.referencedPath) !== '.');
|
|
208
|
+
return nested === undefined ? [] : this.noCdLines(nested);
|
|
209
|
+
}
|
|
210
|
+
// A `cd` the guards will actually honour: its directory passed globMatches in the scan.
|
|
211
|
+
cdLines(withCd) {
|
|
212
|
+
return [
|
|
213
|
+
'✅ OR KEEP USING BASH — put a `cd` into the excluded tree FIRST:',
|
|
214
|
+
` cd ${String(withCd.cdDirectory)} && <your command, writing \`${withCd.referencedPath}\` as \`${withCd.pathFromCdDirectory}\`>`,
|
|
215
|
+
' The guard resolves a LEADING `cd` and judges that directory, so this runs.',
|
|
216
|
+
' It must be the first thing in the command: no leading VAR= assignment,',
|
|
217
|
+
' no subshell wrapper — those defeat the resolution.',
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
// No directory on the way to the file matches a glob on its own, so there is no `cd` to offer.
|
|
221
|
+
// Say WHY and give the one-line config edit that would create one, rather than printing a `cd`
|
|
222
|
+
// that would be denied.
|
|
223
|
+
noCdLines(first) {
|
|
224
|
+
const dir = path.dirname(first.referencedPath);
|
|
225
|
+
return [
|
|
226
|
+
'⚠️ A `cd` CANNOT rescue bash here, so do not try one.',
|
|
227
|
+
` \`${dir}\` (the directory itself) matches no excludePaths glob: \`${first.matchedGlob}\` compiles to`,
|
|
228
|
+
' an anchored regex whose `/` is literal, so the bare directory fails it and a `cd` into',
|
|
229
|
+
' it is STILL denied. That form is deliberately not printed here — it looks right and is not.',
|
|
230
|
+
' Use Read/Write/Edit above — or, to make bash work here too, list the bare directory',
|
|
231
|
+
` alongside the glob in webpieces.config.json → excludePaths: ["${dir}", "${first.matchedGlob}"]`,
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.ExcludedPathEscapeHint = ExcludedPathEscapeHint;
|
|
236
|
+
//# sourceMappingURL=excluded-path-escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excluded-path-escape.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/excluded-path-escape.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAI7B,0DAAyD;AACzD,0DA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C,cAAc,CAAC,CAAC;QAC/C,OAAO;YACH,wDAAwD;YACxD,QAAQ,GAAG,6DAA6D,KAAK,CAAC,WAAW,gBAAgB;YACzG,2FAA2F;YAC3F,gGAAgG;YAChG,wFAAwF;YACxF,oEAAoE,GAAG,OAAO,KAAK,CAAC,WAAW,IAAI;SACtG,CAAC;IACN,CAAC;CACJ;AAxED,wDAwEC","sourcesContent":["import * as path from 'path';\n\nimport { ExcludePaths } from '@webpieces/rules-config';\n\nimport { CommandScanner } from '@webpieces/hook-runtime';\nimport { globMatches } from '@webpieces/hook-runtime';\n\n/**\n * One path the denied command NAMED that `excludePaths` already exempts, plus how to reach it.\n *\n * Data-only, so a class (per CLAUDE.md).\n *\n * `cdDirectory` is the whole point of the class rather than a bare string: it is a directory that\n * ITSELF satisfies `globMatches` against one of the configured globs, or null when no such directory\n * exists for this reference. Callers must never invent one — see ExcludedPathEscapeScan for why a\n * naive `dirname` is wrong exactly when it looks most obviously right.\n */\nexport class ExcludedPathReference {\n /** The referenced path, workspace-relative, as it was matched. */\n readonly referencedPath: string;\n /** The `excludePaths` glob that matched it — quoted back so the agent need not re-derive it. */\n readonly matchedGlob: string;\n /** A directory a `cd` may legally land in (matches a glob on its own), or null when none does. */\n readonly cdDirectory: string | null;\n /** `referencedPath` re-expressed relative to `cdDirectory`; '' when there is no `cdDirectory`. */\n readonly pathFromCdDirectory: string;\n\n constructor(\n referencedPath: string,\n matchedGlob: string,\n cdDirectory: string | null,\n pathFromCdDirectory: string,\n ) {\n this.referencedPath = referencedPath;\n this.matchedGlob = matchedGlob;\n this.cdDirectory = cdDirectory;\n this.pathFromCdDirectory = pathFromCdDirectory;\n }\n}\n\n/**\n * Finds the paths a BASH command names that the top-level `excludePaths` already exempts.\n *\n * WHY this exists: the bash guards judge the shell's effective CWD, not the paths in the command, so\n * `cat .webpieces/tasks.md` at the repo root is DENIED even though that exact file is exempt from\n * every guard and was reachable, that instant, through Read/Write. Every remedy the deny body printed\n * was a git state change — strictly more destructive than the one it omitted. This class supplies the\n * missing sentence; it changes no verdict.\n *\n * A token is treated as a candidate path with no filesystem check: whether it exists says nothing\n * about whether it is exempt, and a stat per token on the blocking hook path is exactly the cost these\n * guards avoid. Non-path tokens (a `grep` pattern, a `sed` script) simply match no glob.\n */\nexport class ExcludedPathEscapeScan {\n private readonly scanner: CommandScanner;\n private readonly workspaceRoot: string;\n private readonly effectiveCwd: string;\n\n /**\n * `effectiveCwd` is the directory the command really runs in, after its own leading `cd` — the\n * same base ContentReadScan resolves relative operands against. RELATIVE tokens are resolved\n * there and ABSOLUTE ones normalised straight to workspace-relative, which is how\n * `cat /abs/path/to/repo/.webpieces/tasks.md` reaches the same verdict as `cat .webpieces/tasks.md`.\n */\n constructor(scanner: CommandScanner, workspaceRoot: string, effectiveCwd: string) {\n this.scanner = scanner;\n this.workspaceRoot = workspaceRoot;\n this.effectiveCwd = effectiveCwd;\n }\n\n /**\n * Every excluded path this command references, in command order, de-duplicated.\n *\n * Scans EVERY segment, not just a leading `cd`: `cat x`, `grep -n foo x`, `sed -n '1,5p' x` and a\n * path inside an `&&` compound all count, because the agent's next move depends on the file it\n * wanted, wherever in the line it named it.\n */\n references(command: string, ex: ExcludePaths): readonly ExcludedPathReference[] {\n if (ex.paths.length === 0) return [];\n\n const found: ExcludedPathReference[] = [];\n const seen = new Set<string>();\n for (const token of this.candidateTokens(command)) {\n const relative = this.workspaceRelative(token);\n if (relative === null || seen.has(relative)) continue;\n seen.add(relative);\n const glob = this.matchingGlob(relative, ex);\n if (glob === null) continue;\n found.push(this.reference(relative, glob, ex));\n }\n return found;\n }\n\n // Build the reference, including the `cd` target — the ONE subtle part, see cdDirectory below.\n private reference(relative: string, glob: string, ex: ExcludePaths): ExcludedPathReference {\n const dir = this.cdDirectory(relative, ex);\n return new ExcludedPathReference(\n relative, glob, dir, dir === null ? '' : path.relative(dir, relative),\n );\n }\n\n /**\n * A directory the agent may `cd` into and have the guards actually stand down, or null.\n *\n * THE TRAP: the bash path matches the relative cwd with `globMatches`, which compiles\n * `.webpieces/**` to the anchored `/^\\.webpieces\\/.*$/` — the `/` is a LITERAL, so the bare\n * directory `.webpieces` does NOT match its own glob. `cd .webpieces && cat tasks.md` is still\n * denied. Emitting that would be worse than emitting nothing: it looks authoritative and costs a\n * turn to disprove. So the directory is only offered when it passes the very same matcher the\n * runner will use, and the renderer says so plainly when nothing does.\n */\n private cdDirectory(relative: string, ex: ExcludePaths): string | null {\n const dir = path.dirname(relative);\n if (dir === '.' || dir === '' || dir === relative) return null;\n return this.matchingGlob(dir, ex) === null ? null : dir;\n }\n\n // The first configured glob this workspace-relative path satisfies, under the runner's OWN matcher\n // (globMatches, load-rules.ts) — never a looser one, or the stanza would promise an exemption the\n // guards do not grant.\n private matchingGlob(relative: string, ex: ExcludePaths): string | null {\n for (const pattern of ex.paths) {\n if (globMatches(pattern, relative)) return pattern;\n }\n return null;\n }\n\n /**\n * Workspace-relative form of a token, or null when it is not a path inside this workspace.\n *\n * `~`-rooted and out-of-tree paths are nothing to do with this repo's exclusions, and the\n * workspace root itself ('') matches no glob by construction.\n */\n private workspaceRelative(token: string): string | null {\n const cleaned = token.replace(REDIRECT_PREFIX, '');\n if (cleaned === '' || cleaned.startsWith('~')) return null;\n const absolute = path.isAbsolute(cleaned) ? cleaned : path.resolve(this.effectiveCwd, cleaned);\n const relative = path.relative(this.workspaceRoot, absolute);\n if (relative === '' || relative.startsWith('..')) return null;\n return relative;\n }\n\n /**\n * Every token that could name a file: each segment's words minus the command word itself and\n * minus flags. Deliberately generous — a token that is not a path matches no glob, while a token\n * dropped by a cleverer filter is a file the agent is never told it can read.\n */\n private candidateTokens(command: string): readonly string[] {\n const tokens: string[] = [];\n for (const segment of this.scanner.commandSegments(command)) {\n const words = this.scanner.words(segment);\n for (let i = 1; i < words.length; i++) {\n if (words[i].startsWith('-')) continue;\n tokens.push(words[i]);\n }\n }\n return tokens;\n }\n}\n\n// A redirection glued to its target (`>out.log`, `2>>err.log`, `<in.txt`) — strip the operator so the\n// target is scanned as the path it is.\nconst REDIRECT_PREFIX = /^\\d*(?:>>?|<)/;\n\n/**\n * Renders the leading stanza of a bash deny body: the Read/Write escape the agent already has, and —\n * when one genuinely exists — the `cd` that makes bash itself work.\n *\n * It goes at the TOP of the report, above the git remedies, because the agent acts on the first\n * actionable thing it reads. The live incident this fixes had the agent create a branch in a human's\n * working tree to record a row in a gitignored scratch file; the cheap, side-effect-free path was one\n * sentence away and never printed. Returns '' when the command names no excluded path, so a repo\n * without exemptions — and every command that names nothing exempt — sees no extra noise.\n */\nexport class ExcludedPathEscapeHint {\n private readonly scan: ExcludedPathEscapeScan;\n\n /** `effectiveCwd` is the directory the command really runs in — see ExcludedPathEscapeScan. */\n constructor(workspaceRoot: string, effectiveCwd: string) {\n this.scan = new ExcludedPathEscapeScan(new CommandScanner(), workspaceRoot, effectiveCwd);\n }\n\n render(command: string, ex: ExcludePaths): string {\n const references = this.scan.references(command, ex);\n if (references.length === 0) return '';\n\n const lines: string[] = [];\n lines.push('✅ YOU CAN USE THE READ/WRITE TOOLS RIGHT NOW — no git operation needed.');\n lines.push(' These paths are in excludePaths and are exempt from every guard:');\n for (const glob of ex.paths) lines.push(` ${glob}`);\n lines.push(` Your command referenced: ${references.map((r: ExcludedPathReference): string => r.referencedPath).join(', ')}`);\n // Scoped to the FILE, deliberately. The stanza fires on any rule block whose command names an\n // exempt path, and `git push … && cat .webpieces/tasks.md` is blocked for the push — for which\n // Read/Write substitutes for nothing. Claiming the remedies below were optional would be false.\n lines.push(' Read/Write/Edit reaches that file RIGHT NOW, with no git operation at all.');\n lines.push(' Anything ELSE this command does — a git/gh operation, a build — still needs the');\n lines.push(' remedies below.');\n const bash = this.bashLines(references);\n if (bash.length > 0) {\n lines.push('');\n for (const line of bash) lines.push(line);\n }\n lines.push('');\n return lines.join('\\n');\n }\n\n // The bash half: the `cd` when one matches, the honest refusal to invent one when none does, and\n // silence when there is not even a directory worth naming.\n private bashLines(references: readonly ExcludedPathReference[]): readonly string[] {\n const withCd = references.find((r: ExcludedPathReference): boolean => r.cdDirectory !== null);\n if (withCd !== undefined) return this.cdLines(withCd);\n // A workspace-ROOT-level file — matched by a file-shaped glob like `*.md` — has no directory to\n // name: `dirname` is `.`, which no excludePaths glob can usefully exempt (the relative cwd at\n // the root is '', so `.` would never match) and which reads as \"exempt the whole repo\". Say\n // nothing about bash rather than something false.\n const nested = references.find(\n (r: ExcludedPathReference): boolean => path.dirname(r.referencedPath) !== '.',\n );\n return nested === undefined ? [] : this.noCdLines(nested);\n }\n\n // A `cd` the guards will actually honour: its directory passed globMatches in the scan.\n private cdLines(withCd: ExcludedPathReference): readonly string[] {\n return [\n '✅ OR KEEP USING BASH — put a `cd` into the excluded tree FIRST:',\n ` cd ${String(withCd.cdDirectory)} && <your command, writing \\`${withCd.referencedPath}\\` as \\`${withCd.pathFromCdDirectory}\\`>`,\n ' The guard resolves a LEADING `cd` and judges that directory, so this runs.',\n ' It must be the first thing in the command: no leading VAR= assignment,',\n ' no subshell wrapper — those defeat the resolution.',\n ];\n }\n\n // No directory on the way to the file matches a glob on its own, so there is no `cd` to offer.\n // Say WHY and give the one-line config edit that would create one, rather than printing a `cd`\n // that would be denied.\n private noCdLines(first: ExcludedPathReference): readonly string[] {\n const dir = path.dirname(first.referencedPath);\n return [\n '⚠️ A `cd` CANNOT rescue bash here, so do not try one.',\n ` \\`${dir}\\` (the directory itself) matches no excludePaths glob: \\`${first.matchedGlob}\\` compiles to`,\n ' an anchored regex whose `/` is literal, so the bare directory fails it and a `cd` into',\n ' it is STILL denied. That form is deliberately not printed here — it looks right and is not.',\n ' Use Read/Write/Edit above — or, to make bash work here too, list the bare directory',\n ` alongside the glob in webpieces.config.json → excludePaths: [\"${dir}\", \"${first.matchedGlob}\"]`,\n ];\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EffectiveTree } from '@webpieces/hook-runtime';
|
|
2
|
+
import { BlockedResult } from '@webpieces/hook-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* L1 row 5: git/gh commands must run from the repo root of the tree they act on, where the guards can
|
|
5
|
+
* reason about git state coherently. guards/L1-location.md carries the table and the use cases; change
|
|
6
|
+
* this predicate and that file is stale until you update it.
|
|
7
|
+
*
|
|
8
|
+
* ONE variable decides it: `tree.effectiveCwd` — the directory the command actually runs in, which is
|
|
9
|
+
* the shell's cwd unless the command leads with `cd <dir> &&`. Root or not-root, nothing else.
|
|
10
|
+
*
|
|
11
|
+
* It used to be `shellAtRoot || cdsToRoot`, two variables OR'd, and that produced opposite verdicts for
|
|
12
|
+
* the same destination: `git status` with the shell in packages/http/ was BLOCKED, while
|
|
13
|
+
* `cd packages/http && git status` from the root was ALLOWED, because shellAtRoot short-circuited before
|
|
14
|
+
* the destination was ever considered. An agent that cd's INTO a subdir has the same broken mental model
|
|
15
|
+
* as one stranded there, so it gets the same answer now.
|
|
16
|
+
*
|
|
17
|
+
* The remedy is ONE runnable line, `cd <root> && <the work>`, not "cd first, then re-run" — that advice
|
|
18
|
+
* made this guard print the very command it had just rejected, and a `cd` is unreliable in both
|
|
19
|
+
* directions (INTO this repo it sticks; OUT of it the harness resets it).
|
|
20
|
+
*
|
|
21
|
+
* It goes through remedyAtRoot(), NOT bare atRoot(), and that is load-bearing: A REMEDY MUST SATISFY THE
|
|
22
|
+
* PREDICATE THAT PRINTED IT. Prefixing `cd '<root>' &&` onto a command already leading with
|
|
23
|
+
* `cd <elsewhere> &&` left effectiveCwd in `<elsewhere>`, so the identical block fired on the remedy with
|
|
24
|
+
* the prefix doubled, then tripled. remedyAtRoot REPLACES the leading `cd` run instead, and
|
|
25
|
+
* effective-tree.spec.ts asserts that property for every L1 remedy, not just this one.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ForceToRootGuard {
|
|
28
|
+
private readonly resolver;
|
|
29
|
+
/** The deny report, or null to allow. */
|
|
30
|
+
block(command: string, tree: EffectiveTree, isGitOrGh: boolean): string | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function gitFromSubdirBlock(command: string, tree: EffectiveTree, isGitOrGh: boolean): BlockedResult | null;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ForceToRootGuard = void 0;
|
|
4
|
+
exports.gitFromSubdirBlock = gitFromSubdirBlock;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
8
|
+
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
9
|
+
/**
|
|
10
|
+
* L1 row 5: git/gh commands must run from the repo root of the tree they act on, where the guards can
|
|
11
|
+
* reason about git state coherently. guards/L1-location.md carries the table and the use cases; change
|
|
12
|
+
* this predicate and that file is stale until you update it.
|
|
13
|
+
*
|
|
14
|
+
* ONE variable decides it: `tree.effectiveCwd` — the directory the command actually runs in, which is
|
|
15
|
+
* the shell's cwd unless the command leads with `cd <dir> &&`. Root or not-root, nothing else.
|
|
16
|
+
*
|
|
17
|
+
* It used to be `shellAtRoot || cdsToRoot`, two variables OR'd, and that produced opposite verdicts for
|
|
18
|
+
* the same destination: `git status` with the shell in packages/http/ was BLOCKED, while
|
|
19
|
+
* `cd packages/http && git status` from the root was ALLOWED, because shellAtRoot short-circuited before
|
|
20
|
+
* the destination was ever considered. An agent that cd's INTO a subdir has the same broken mental model
|
|
21
|
+
* as one stranded there, so it gets the same answer now.
|
|
22
|
+
*
|
|
23
|
+
* The remedy is ONE runnable line, `cd <root> && <the work>`, not "cd first, then re-run" — that advice
|
|
24
|
+
* made this guard print the very command it had just rejected, and a `cd` is unreliable in both
|
|
25
|
+
* directions (INTO this repo it sticks; OUT of it the harness resets it).
|
|
26
|
+
*
|
|
27
|
+
* It goes through remedyAtRoot(), NOT bare atRoot(), and that is load-bearing: A REMEDY MUST SATISFY THE
|
|
28
|
+
* PREDICATE THAT PRINTED IT. Prefixing `cd '<root>' &&` onto a command already leading with
|
|
29
|
+
* `cd <elsewhere> &&` left effectiveCwd in `<elsewhere>`, so the identical block fired on the remedy with
|
|
30
|
+
* the prefix doubled, then tripled. remedyAtRoot REPLACES the leading `cd` run instead, and
|
|
31
|
+
* effective-tree.spec.ts asserts that property for every L1 remedy, not just this one.
|
|
32
|
+
*/
|
|
33
|
+
class ForceToRootGuard {
|
|
34
|
+
resolver = new hook_runtime_1.EffectiveTreeResolver();
|
|
35
|
+
/** The deny report, or null to allow. */
|
|
36
|
+
block(command, tree, isGitOrGh) {
|
|
37
|
+
const targetAtRoot = path.resolve(tree.effectiveCwd) === path.resolve(tree.root);
|
|
38
|
+
if (!isGitOrGh || targetAtRoot)
|
|
39
|
+
return null;
|
|
40
|
+
return [
|
|
41
|
+
'❌ Run git/gh commands from the repo root, not a subdirectory.',
|
|
42
|
+
` Command runs in: ${tree.effectiveCwd}`,
|
|
43
|
+
` Judged against: ${tree.root}`,
|
|
44
|
+
' Run EXACTLY this instead, as ONE line (a bare `cd` in a separate call is not equivalent —',
|
|
45
|
+
' a `cd` inside this repo STICKS for later calls, and a `cd` out of it is reset by the harness):',
|
|
46
|
+
` ${this.resolver.remedyAtRoot(tree.root, command)}`,
|
|
47
|
+
' A leading `cd <path> &&` is ACCEPTED by the guards — it cannot change what the command',
|
|
48
|
+
" does to the repo. (The webpieces guards evaluate the repo's git state at its root.)",
|
|
49
|
+
].join('\n');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ForceToRootGuard = ForceToRootGuard;
|
|
53
|
+
// L1 row 5's dispatch entry, beside the guard it wraps — see missing-directory.ts for why these live
|
|
54
|
+
// with their guard rather than in runner.ts.
|
|
55
|
+
// webpieces-disable no-function-outside-class -- the one-line runner entry point for the class above, beside it
|
|
56
|
+
function gitFromSubdirBlock(command, tree, isGitOrGh) {
|
|
57
|
+
const report = new ForceToRootGuard().block(command, tree, isGitOrGh);
|
|
58
|
+
return report === null ? null : new hook_runtime_2.BlockedResult(report);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=force-to-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"force-to-root.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/force-to-root.ts"],"names":[],"mappings":";;;AAoDA,gDAGC;;AAvDD,mDAA6B;AAE7B,0DAA+E;AAC/E,0DAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,gBAAgB;IACR,QAAQ,GAAG,IAAI,oCAAqB,EAAE,CAAC;IAExD,yCAAyC;IACzC,KAAK,CAAC,OAAe,EAAE,IAAmB,EAAE,SAAkB;QAC1D,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjF,IAAI,CAAC,SAAS,IAAI,YAAY;YAAE,OAAO,IAAI,CAAC;QAC5C,OAAO;YACH,+DAA+D;YAC/D,uBAAuB,IAAI,CAAC,YAAY,EAAE;YAC1C,sBAAsB,IAAI,CAAC,IAAI,EAAE;YACjC,8FAA8F;YAC9F,mGAAmG;YACnG,QAAQ,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE;YACxD,2FAA2F;YAC3F,wFAAwF;SAC3F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACJ;AAlBD,4CAkBC;AAED,qGAAqG;AACrG,6CAA6C;AAC7C,gHAAgH;AAChH,SAAgB,kBAAkB,CAAC,OAAe,EAAE,IAAmB,EAAE,SAAkB;IACvF,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IACtE,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,4BAAa,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { EffectiveTree, EffectiveTreeResolver } from '@webpieces/hook-runtime';\nimport { BlockedResult } from '@webpieces/hook-runtime';\n\n/**\n * L1 row 5: git/gh commands must run from the repo root of the tree they act on, where the guards can\n * reason about git state coherently. guards/L1-location.md carries the table and the use cases; change\n * this predicate and that file is stale until you update it.\n *\n * ONE variable decides it: `tree.effectiveCwd` — the directory the command actually runs in, which is\n * the shell's cwd unless the command leads with `cd <dir> &&`. Root or not-root, nothing else.\n *\n * It used to be `shellAtRoot || cdsToRoot`, two variables OR'd, and that produced opposite verdicts for\n * the same destination: `git status` with the shell in packages/http/ was BLOCKED, while\n * `cd packages/http && git status` from the root was ALLOWED, because shellAtRoot short-circuited before\n * the destination was ever considered. An agent that cd's INTO a subdir has the same broken mental model\n * as one stranded there, so it gets the same answer now.\n *\n * The remedy is ONE runnable line, `cd <root> && <the work>`, not \"cd first, then re-run\" — that advice\n * made this guard print the very command it had just rejected, and a `cd` is unreliable in both\n * directions (INTO this repo it sticks; OUT of it the harness resets it).\n *\n * It goes through remedyAtRoot(), NOT bare atRoot(), and that is load-bearing: A REMEDY MUST SATISFY THE\n * PREDICATE THAT PRINTED IT. Prefixing `cd '<root>' &&` onto a command already leading with\n * `cd <elsewhere> &&` left effectiveCwd in `<elsewhere>`, so the identical block fired on the remedy with\n * the prefix doubled, then tripled. remedyAtRoot REPLACES the leading `cd` run instead, and\n * effective-tree.spec.ts asserts that property for every L1 remedy, not just this one.\n */\nexport class ForceToRootGuard {\n private readonly resolver = new EffectiveTreeResolver();\n\n /** The deny report, or null to allow. */\n block(command: string, tree: EffectiveTree, isGitOrGh: boolean): string | null {\n const targetAtRoot = path.resolve(tree.effectiveCwd) === path.resolve(tree.root);\n if (!isGitOrGh || targetAtRoot) return null;\n return [\n '❌ Run git/gh commands from the repo root, not a subdirectory.',\n ` Command runs in: ${tree.effectiveCwd}`,\n ` Judged against: ${tree.root}`,\n ' Run EXACTLY this instead, as ONE line (a bare `cd` in a separate call is not equivalent —',\n ' a `cd` inside this repo STICKS for later calls, and a `cd` out of it is reset by the harness):',\n ` ${this.resolver.remedyAtRoot(tree.root, command)}`,\n ' A leading `cd <path> &&` is ACCEPTED by the guards — it cannot change what the command',\n \" does to the repo. (The webpieces guards evaluate the repo's git state at its root.)\",\n ].join('\\n');\n }\n}\n\n// L1 row 5's dispatch entry, beside the guard it wraps — see missing-directory.ts for why these live\n// with their guard rather than in runner.ts.\n// webpieces-disable no-function-outside-class -- the one-line runner entry point for the class above, beside it\nexport function gitFromSubdirBlock(command: string, tree: EffectiveTree, isGitOrGh: boolean): BlockedResult | null {\n const report = new ForceToRootGuard().block(command, tree, isGitOrGh);\n return report === null ? null : new BlockedResult(report);\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Opening marker of the generated block, as it appears in GUARD_MATRIX.md. */
|
|
2
|
+
export declare const GUARD_INDEX_BEGIN = "<!-- BEGIN GENERATED \u2014 GuardIndexDoc.render() in agent-workflow-rules/src/core/guard-index-doc.ts; run `pnpm guards:generate` -->";
|
|
3
|
+
/** Closing marker. Everything between the two is machine-owned; everything outside is prose. */
|
|
4
|
+
export declare const GUARD_INDEX_END = "<!-- END GENERATED \u2014 hand-written prose resumes here -->";
|
|
5
|
+
/** How much of a layer's doc is rendered from code. Data-only → a class, per CLAUDE.md. */
|
|
6
|
+
export declare class LayerGeneration {
|
|
7
|
+
/** `L0`, `L1`, … as the doc prints it. */
|
|
8
|
+
readonly layer: string;
|
|
9
|
+
/** The question this layer answers, for the layer table. */
|
|
10
|
+
readonly goal: string;
|
|
11
|
+
/** The `webpieces.config.json` key, or '' when the layer has none on purpose. */
|
|
12
|
+
readonly configKey: string;
|
|
13
|
+
/** Repo-relative path of the layer's doc. */
|
|
14
|
+
readonly doc: string;
|
|
15
|
+
/** The array the doc is rendered FROM, or '' when nothing is generated yet. */
|
|
16
|
+
readonly source: string;
|
|
17
|
+
/** The status cell, verbatim. */
|
|
18
|
+
readonly status: string;
|
|
19
|
+
constructor(
|
|
20
|
+
/** `L0`, `L1`, … as the doc prints it. */
|
|
21
|
+
layer: string,
|
|
22
|
+
/** The question this layer answers, for the layer table. */
|
|
23
|
+
goal: string,
|
|
24
|
+
/** The `webpieces.config.json` key, or '' when the layer has none on purpose. */
|
|
25
|
+
configKey: string,
|
|
26
|
+
/** Repo-relative path of the layer's doc. */
|
|
27
|
+
doc: string,
|
|
28
|
+
/** The array the doc is rendered FROM, or '' when nothing is generated yet. */
|
|
29
|
+
source: string,
|
|
30
|
+
/** The status cell, verbatim. */
|
|
31
|
+
status: string);
|
|
32
|
+
/** The config-key cell — layers with no key say so, and say it is deliberate. */
|
|
33
|
+
keyCell(): string;
|
|
34
|
+
sourceCell(): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* THE FIVE LAYERS, and how much of each doc is machine-owned.
|
|
38
|
+
*
|
|
39
|
+
* Adding a layer, or converting one to generated, is an edit HERE and nowhere else — the index table,
|
|
40
|
+
* the layer table and the one-command sentence all render from this array, so they cannot disagree
|
|
41
|
+
* with each other the way the hand-written version did.
|
|
42
|
+
*/
|
|
43
|
+
export declare const LAYER_GENERATION: readonly LayerGeneration[];
|
|
44
|
+
/**
|
|
45
|
+
* The generated block of GUARD_MATRIX.md, and the splice that puts it there.
|
|
46
|
+
*
|
|
47
|
+
* Same class shape as L0ToolingDoc — renderer, extractor and splicer as one unit, driven by one spec.
|
|
48
|
+
*/
|
|
49
|
+
export declare class GuardIndexDoc {
|
|
50
|
+
/** The whole generated block, WITHOUT the markers — those belong to the file, not the renderer. */
|
|
51
|
+
render(): string;
|
|
52
|
+
/**
|
|
53
|
+
* The generated text of `doc`, exactly as committed. Throws when a marker is missing or doubled —
|
|
54
|
+
* a silently-unspliced doc is the drift this arrangement exists to end.
|
|
55
|
+
*/
|
|
56
|
+
extract(doc: string): string;
|
|
57
|
+
/** `doc` with the generated block replaced by today's render. Preserves every byte outside it. */
|
|
58
|
+
splice(doc: string): string;
|
|
59
|
+
private preamble;
|
|
60
|
+
private statusTable;
|
|
61
|
+
private layerTable;
|
|
62
|
+
private generatedWholeCount;
|
|
63
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// GUARD_MATRIX.md's generation-status block, rendered from the one array that knows.
|
|
4
|
+
//
|
|
5
|
+
// THE BUG THIS FIXES IS IN THE FILE ITSELF. GUARD_MATRIX.md is the INDEX — the page that tells you
|
|
6
|
+
// which layer docs are generated and which are hand-written — and it was hand-written, so it went out
|
|
7
|
+
// of date about generation. It ended up contradicting itself inside ten lines: a blockquote asserting
|
|
8
|
+
// "L1's table ... generated" and "EVERY REMAINING LAYER FILE IS HAND-WRITTEN TODAY", directly above a
|
|
9
|
+
// table listing L2 as generated and byte-locked. Both were once true; L2 was converted and only one of
|
|
10
|
+
// the two places was updated.
|
|
11
|
+
//
|
|
12
|
+
// A doc that describes generation is exactly the doc that must be generated, because it is the one
|
|
13
|
+
// place a reader goes to find out whether to trust the others. So the STATUS is data here, the block
|
|
14
|
+
// between the markers is spliced from it, and a spec byte-locks the result — the same treatment
|
|
15
|
+
// guards/L0-tooling.md gets, and for the same reason: everything outside the markers stays
|
|
16
|
+
// hand-written prose that the splice preserves byte for byte.
|
|
17
|
+
//
|
|
18
|
+
// WHAT IS DELIBERATELY NOT GENERATED: the rest of GUARD_MATRIX.md — the action codebook, the launch
|
|
19
|
+
// guarantee, the two rules that constrain guard changes. Those are prose about DESIGN, not facts about
|
|
20
|
+
// the code, and a generator that owns them would be inventing a schema for essays.
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.GuardIndexDoc = exports.LAYER_GENERATION = exports.LayerGeneration = exports.GUARD_INDEX_END = exports.GUARD_INDEX_BEGIN = void 0;
|
|
24
|
+
/** Opening marker of the generated block, as it appears in GUARD_MATRIX.md. */
|
|
25
|
+
exports.GUARD_INDEX_BEGIN = '<!-- BEGIN GENERATED — GuardIndexDoc.render() in agent-workflow-rules/src/core/guard-index-doc.ts; run `pnpm guards:generate` -->';
|
|
26
|
+
/** Closing marker. Everything between the two is machine-owned; everything outside is prose. */
|
|
27
|
+
exports.GUARD_INDEX_END = '<!-- END GENERATED — hand-written prose resumes here -->';
|
|
28
|
+
/** How much of a layer's doc is rendered from code. Data-only → a class, per CLAUDE.md. */
|
|
29
|
+
class LayerGeneration {
|
|
30
|
+
layer;
|
|
31
|
+
goal;
|
|
32
|
+
configKey;
|
|
33
|
+
doc;
|
|
34
|
+
source;
|
|
35
|
+
status;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/max-params -- the five cells of one status row
|
|
37
|
+
constructor(
|
|
38
|
+
/** `L0`, `L1`, … as the doc prints it. */
|
|
39
|
+
layer,
|
|
40
|
+
/** The question this layer answers, for the layer table. */
|
|
41
|
+
goal,
|
|
42
|
+
/** The `webpieces.config.json` key, or '' when the layer has none on purpose. */
|
|
43
|
+
configKey,
|
|
44
|
+
/** Repo-relative path of the layer's doc. */
|
|
45
|
+
doc,
|
|
46
|
+
/** The array the doc is rendered FROM, or '' when nothing is generated yet. */
|
|
47
|
+
source,
|
|
48
|
+
/** The status cell, verbatim. */
|
|
49
|
+
status) {
|
|
50
|
+
this.layer = layer;
|
|
51
|
+
this.goal = goal;
|
|
52
|
+
this.configKey = configKey;
|
|
53
|
+
this.doc = doc;
|
|
54
|
+
this.source = source;
|
|
55
|
+
this.status = status;
|
|
56
|
+
}
|
|
57
|
+
/** The config-key cell — layers with no key say so, and say it is deliberate. */
|
|
58
|
+
keyCell() {
|
|
59
|
+
return this.configKey === '' ? '*(none — deliberate, see below)*' : `\`${this.configKey}\``;
|
|
60
|
+
}
|
|
61
|
+
sourceCell() {
|
|
62
|
+
return this.source === '' ? '—' : `\`${this.source}\``;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.LayerGeneration = LayerGeneration;
|
|
66
|
+
/**
|
|
67
|
+
* THE FIVE LAYERS, and how much of each doc is machine-owned.
|
|
68
|
+
*
|
|
69
|
+
* Adding a layer, or converting one to generated, is an edit HERE and nowhere else — the index table,
|
|
70
|
+
* the layer table and the one-command sentence all render from this array, so they cannot disagree
|
|
71
|
+
* with each other the way the hand-written version did.
|
|
72
|
+
*/
|
|
73
|
+
exports.LAYER_GENERATION = [
|
|
74
|
+
new LayerGeneration('L0', 'Is webpieces itself trustworthy right now?', '', 'guards/L0-tooling.md', 'L0_FAULTS + L0_ALLOWLIST', '**PARTLY generated, byte-locked** — only the block between the `L0_DOC_BEGIN` / `L0_DOC_END` markers; every byte outside it is hand-written prose the splice preserves'),
|
|
75
|
+
new LayerGeneration('L1', 'Is this call ours to judge, are the versions in sync, and is git run from the root?', '', 'guards/L1-location.md', 'L1_ROWS', '**generated whole, byte-locked** — table, use cases and cures all render from the array the runner dispatches on'),
|
|
76
|
+
new LayerGeneration('L2', 'May I work here, and is what I read current?', 'branch-state-guard', 'guards/L2-branch-state.md', 'L2_ROWS', '**generated whole, byte-locked** — table, use cases and the "Not done" gaps all render from the rows'),
|
|
77
|
+
new LayerGeneration('L3', 'Which dead branches and worktrees get reaped?', 'branch-creation-guard', 'guards/L3-branch-cleanup.md', '', '**hand-written** — not yet converted, so it CAN go out of date; the code is the authority'),
|
|
78
|
+
new LayerGeneration('L4', 'Does every merge and PR go through the gated flow?', 'pr-lifecycle-guard', 'guards/L4-pr-lifecycle.md', '', '**hand-written** — not yet converted, so it CAN go out of date; the code is the authority'),
|
|
79
|
+
];
|
|
80
|
+
/**
|
|
81
|
+
* The generated block of GUARD_MATRIX.md, and the splice that puts it there.
|
|
82
|
+
*
|
|
83
|
+
* Same class shape as L0ToolingDoc — renderer, extractor and splicer as one unit, driven by one spec.
|
|
84
|
+
*/
|
|
85
|
+
class GuardIndexDoc {
|
|
86
|
+
/** The whole generated block, WITHOUT the markers — those belong to the file, not the renderer. */
|
|
87
|
+
render() {
|
|
88
|
+
return [
|
|
89
|
+
...this.preamble(),
|
|
90
|
+
...this.statusTable(),
|
|
91
|
+
...this.layerTable(),
|
|
92
|
+
].join('\n');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The generated text of `doc`, exactly as committed. Throws when a marker is missing or doubled —
|
|
96
|
+
* a silently-unspliced doc is the drift this arrangement exists to end.
|
|
97
|
+
*/
|
|
98
|
+
extract(doc) {
|
|
99
|
+
const opens = doc.split(exports.GUARD_INDEX_BEGIN).length - 1;
|
|
100
|
+
const closes = doc.split(exports.GUARD_INDEX_END).length - 1;
|
|
101
|
+
if (opens !== 1 || closes !== 1) {
|
|
102
|
+
throw new Error(`GUARD_MATRIX.md must carry exactly one BEGIN/END marker pair, found ${String(opens)}/${String(closes)}`);
|
|
103
|
+
}
|
|
104
|
+
const afterBegin = doc.slice(doc.indexOf(exports.GUARD_INDEX_BEGIN) + exports.GUARD_INDEX_BEGIN.length);
|
|
105
|
+
return afterBegin.slice(0, afterBegin.indexOf(exports.GUARD_INDEX_END)).replace(/^\n/, '').replace(/\n$/, '');
|
|
106
|
+
}
|
|
107
|
+
/** `doc` with the generated block replaced by today's render. Preserves every byte outside it. */
|
|
108
|
+
splice(doc) {
|
|
109
|
+
const head = doc.slice(0, doc.indexOf(exports.GUARD_INDEX_BEGIN) + exports.GUARD_INDEX_BEGIN.length);
|
|
110
|
+
const tail = doc.slice(doc.indexOf(exports.GUARD_INDEX_END));
|
|
111
|
+
// extract() is called for its VALIDATION — one marker pair — before anything is rewritten.
|
|
112
|
+
this.extract(doc);
|
|
113
|
+
return `${head}\n${this.render()}\n${tail}`;
|
|
114
|
+
}
|
|
115
|
+
preamble() {
|
|
116
|
+
return [
|
|
117
|
+
'> **GENERATED — do not hand-edit between the markers.** Rendered by `GuardIndexDoc.render()`',
|
|
118
|
+
'> from `LAYER_GENERATION` (`agent-workflow-rules/src/core/guard-index-doc.ts`); regenerate with',
|
|
119
|
+
'> `pnpm guards:generate`. A spec byte-locks it.',
|
|
120
|
+
'>',
|
|
121
|
+
'> This block used to be prose, and it drifted about the one subject it exists to report: it',
|
|
122
|
+
'> claimed every layer but L0 and L1 was hand-written, ten lines above a table listing L2 as',
|
|
123
|
+
'> generated. The index that tells you which docs to trust is the last place that can afford',
|
|
124
|
+
'> to be wrong, so it is data now.',
|
|
125
|
+
'',
|
|
126
|
+
'## Generation status',
|
|
127
|
+
'',
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
statusTable() {
|
|
131
|
+
return [
|
|
132
|
+
'| layer | source of truth | doc |',
|
|
133
|
+
'|---|---|---|',
|
|
134
|
+
...exports.LAYER_GENERATION.map((entry) => `| ${entry.layer} | ${entry.sourceCell()} | ${entry.status} |`),
|
|
135
|
+
'',
|
|
136
|
+
`One command regenerates every generated artifact: \`pnpm guards:generate\`. It rewrites the`,
|
|
137
|
+
`${this.generatedWholeCount()} whole-file docs, SPLICES the marked blocks in L0's doc and in this file, writes the`,
|
|
138
|
+
'AI-facing copy of the L2 matrix, and renders the POSIX-sh shim template.',
|
|
139
|
+
'',
|
|
140
|
+
'For a WHOLE-file layer the split is: **row data** lives in the array, **prose** lives as literal',
|
|
141
|
+
'lines inside the renderer, there is no third place, and the byte-lock spec fails on any hand',
|
|
142
|
+
'edit. **The two SPLICED files are the exception**: everything outside their marker pairs is',
|
|
143
|
+
'hand-written prose the splice preserves byte for byte, and the spec deliberately permits you to',
|
|
144
|
+
'edit it.',
|
|
145
|
+
'',
|
|
146
|
+
'**L1 and L2 differ in one way worth knowing.** L1 DISPATCHES from its rows — the runner takes the',
|
|
147
|
+
'first matching row and switches on its `blockId`, so deleting a row deletes a block. L2\'s four',
|
|
148
|
+
'guard classes each own their own ladder (they diverge in polarity, quantifier and empty-command',
|
|
149
|
+
'handling, deliberately), so L2 joins to its rows by REASON instead: every decision-log line carries',
|
|
150
|
+
'`row=<n>` derived from the reason the guard logged, plus the `cure=` that row prescribed, and a spec',
|
|
151
|
+
'asserts the reason map is exhaustive against the guard sources.',
|
|
152
|
+
'',
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
layerTable() {
|
|
156
|
+
return [
|
|
157
|
+
'## The layers',
|
|
158
|
+
'',
|
|
159
|
+
'| layer | goal — the question it answers | config key | doc |',
|
|
160
|
+
'|---|---|---|---|',
|
|
161
|
+
...exports.LAYER_GENERATION.map((entry) => `| **${entry.layer}** | ${entry.goal} | ${entry.keyCell()} | [${entry.layer}](${entry.doc}) |`),
|
|
162
|
+
'',
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
// Rendered into the prose so the sentence cannot claim a count the array disagrees with — the exact
|
|
166
|
+
// failure mode this file is fixing ("One command regenerates all three" survived L2's conversion).
|
|
167
|
+
generatedWholeCount() {
|
|
168
|
+
return String(exports.LAYER_GENERATION.filter((entry) => entry.status.includes('generated whole')).length);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.GuardIndexDoc = GuardIndexDoc;
|
|
172
|
+
//# sourceMappingURL=guard-index-doc.js.map
|