@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,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderL2Doc = renderL2Doc;
|
|
4
|
+
const l2_rows_1 = require("./l2-rows");
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// guards/L2-branch-state.md, rendered from L2_ROWS.
|
|
7
|
+
//
|
|
8
|
+
// Same arrangement as l1-doc.renderL1Doc(): one join('\n') of literal markdown lines with the ROW DATA
|
|
9
|
+
// interpolated from the array. Everything that is not row data is a literal line here, because that is
|
|
10
|
+
// the half a generator cannot own.
|
|
11
|
+
//
|
|
12
|
+
// A unit test (l2-matrix.spec.ts) locks guards/L2-branch-state.md byte-identical to renderL2Doc(), and
|
|
13
|
+
// `pnpm guards:generate` rewrites the file. The doc that stood here before was 100% hand-written and
|
|
14
|
+
// carried its own warning that it could drift; it did, in three places at once (it proposed
|
|
15
|
+
// `branch-state-guard` as a future key while GUARD_MATRIX.md proposed a different name and
|
|
16
|
+
// docs/plans/guard-layer-toggles.md proposed a third).
|
|
17
|
+
//
|
|
18
|
+
// This module, like l2-rows.ts, has no runtime imports outside this pair so the generator can load it
|
|
19
|
+
// without the package's transitive dependencies.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module
|
|
22
|
+
function tableRow(row) {
|
|
23
|
+
return `| ${row.num} | \`${row.toolCell()}\` | ${row.state} | ${row.action.label} | ${row.cure} |`;
|
|
24
|
+
}
|
|
25
|
+
// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module
|
|
26
|
+
function notDoneRow(entry) {
|
|
27
|
+
return `| ${entry.row} | ${entry.gap} | ${entry.why} |`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The "Not done" body — a table when there are gaps, a SENTENCE when there are none.
|
|
31
|
+
*
|
|
32
|
+
* An empty table renders as a bare header with nothing under it, which reads like a rendering bug
|
|
33
|
+
* rather than like an achievement. "Every row is honoured" is a claim worth making in words, and it is
|
|
34
|
+
* the state this section exists to drive the layer towards.
|
|
35
|
+
*/
|
|
36
|
+
// webpieces-disable no-function-outside-class -- section builder for renderL2Doc below, in this render module
|
|
37
|
+
function renderNotDoneBody() {
|
|
38
|
+
if (l2_rows_1.NOT_DONE.length === 0) {
|
|
39
|
+
return [
|
|
40
|
+
'**Nothing. Every row in the table above is a row the guards actually honour today.**',
|
|
41
|
+
'',
|
|
42
|
+
'That has not always been true, and the section stays here for when it stops being true again:',
|
|
43
|
+
'a row the code cannot yet honour is listed here rather than rendered as if it were live, the',
|
|
44
|
+
'same way L1 lists its unreachable `o` row. The three entries this section used to carry were',
|
|
45
|
+
'row 5\'s Bash half (shipped, then moved: Bash on `main` is judged on FRESHNESS at rows 6/7, while',
|
|
46
|
+
'row 5 keeps the unconditional WRITE block) and the DIRTY-TREE',
|
|
47
|
+
'valves on rows 6 and 8 — both closed, because each of those rows cures with',
|
|
48
|
+
'`git checkout -b <new> origin/main`, which carries uncommitted changes onto the new branch. A',
|
|
49
|
+
'dirty tree never trapped anyone; the row 6 message just printed the one cure that could not run',
|
|
50
|
+
'dirty, and the fix was to print both.',
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
'Each row below describes INTENT the code has not caught up with. They are listed rather than',
|
|
55
|
+
'silently rendered as if they were live, the same way L1 lists its unreachable `o` row. Every one of',
|
|
56
|
+
`them currently exits at row ${l2_rows_1.L2_FAIL_OPEN_ROW} instead, so the log never claims the strict row fired.`,
|
|
57
|
+
'',
|
|
58
|
+
'| row | the gap | why it has not shipped |',
|
|
59
|
+
'|---|---|---|',
|
|
60
|
+
...l2_rows_1.NOT_DONE.map(notDoneRow),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module
|
|
64
|
+
function useCaseRow(useCase) {
|
|
65
|
+
return `| ${useCase.num} | ${useCase.symptom} | ${useCase.state} | ${useCase.verdict} | ${useCase.fix} |`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Render guards/L2-branch-state.md.
|
|
69
|
+
*
|
|
70
|
+
* Split into sections purely to stay inside the method-line budget — the join order is what makes them
|
|
71
|
+
* one file, so keep them adjacent and keep the byte-lock test as the arbiter.
|
|
72
|
+
*/
|
|
73
|
+
// webpieces-disable no-function-outside-class -- pure string builder over L2_ROWS, beside the array it reads
|
|
74
|
+
function renderL2Doc() {
|
|
75
|
+
return [
|
|
76
|
+
...renderHead(),
|
|
77
|
+
...renderTable(),
|
|
78
|
+
...renderTableNotes(),
|
|
79
|
+
...renderUseCases(),
|
|
80
|
+
...renderNotes(),
|
|
81
|
+
...renderTail(),
|
|
82
|
+
].join('\n');
|
|
83
|
+
}
|
|
84
|
+
// webpieces-disable no-function-outside-class -- first section of renderL2Doc's string, beside it in this module
|
|
85
|
+
function renderHead() {
|
|
86
|
+
return [
|
|
87
|
+
'# L2 — branch state',
|
|
88
|
+
'',
|
|
89
|
+
'**Goal: may I work here, and is what I read current?**',
|
|
90
|
+
'',
|
|
91
|
+
'**Config key: `branch-state-guard`.** ONE key for the whole policy. It used to be FOUR —',
|
|
92
|
+
'`feature-branch-guard`, `read-stale-guard`, `stale-main-bash-guard`, `merged-branch-bash-guard` —',
|
|
93
|
+
'and three of them carried nothing but `mode` plus the two escape hatches. Four keys made HALF a',
|
|
94
|
+
'policy representable: `read-stale-guard: OFF` beside `merged-branch-bash-guard: ON` is "read the',
|
|
95
|
+
'file, yes; `cat` the same file, no" — the same information, opposite verdicts, chosen by nobody.',
|
|
96
|
+
'One key makes that unconstructible. The four class NAMES are unchanged and still appear as `rule=`',
|
|
97
|
+
'on every decision-log line, so `grep rule=stale-main-bash-guard` keeps working; only the switch',
|
|
98
|
+
'merged. The four old keys are rejected by name with this destination — see `retired-config-keys.ts`.',
|
|
99
|
+
'',
|
|
100
|
+
'**Code:** `agent-workflow-rules/src/core/rules/{feature-branch,read-stale,stale-main-bash,merged-branch-bash}-guard.ts` ·',
|
|
101
|
+
'the rows in `agent-workflow-rules/src/core/l2-rows.ts` · the shared cache in',
|
|
102
|
+
'`rules-config/src/main-sync-status.ts` + `main-sync-file.ts` · the refresher in',
|
|
103
|
+
'`agent-workflow-rules/src/core/sync-main.ts`.',
|
|
104
|
+
'',
|
|
105
|
+
'## The four classes, and why there are four',
|
|
106
|
+
'',
|
|
107
|
+
'| | Write/Edit | Read | Bash |',
|
|
108
|
+
'|---|---|---|---|',
|
|
109
|
+
'| **state A** — stale `main` | `feature-branch-guard` | `read-stale-guard` | `stale-main-bash-guard` |',
|
|
110
|
+
'| **state B** — merged branch | `feature-branch-guard` | `read-stale-guard` | `merged-branch-bash-guard` |',
|
|
111
|
+
'',
|
|
112
|
+
'The split is TOOL WIRING, not policy. A Read names exactly one file; a Bash command is opaque; a',
|
|
113
|
+
'Write is neither.',
|
|
114
|
+
'',
|
|
115
|
+
'**The two Bash guards used to differ in polarity, and no longer do.** merged-branch was',
|
|
116
|
+
'default-DENY + allowlist; stale-main was default-ALLOW + blocklist of content readers, so',
|
|
117
|
+
'`pnpm build` was denied by one and allowed by the other for the same reason — "you should not be',
|
|
118
|
+
'working in this tree". A blocklist of readers structurally cannot catch an installer, a formatter',
|
|
119
|
+
'or a codegen step, so both states now use default-DENY plus one shared `RecoveryAllowlist` (the',
|
|
120
|
+
'row 4 skip list). Two skip lists drift, and the half that drifts is the half that wedges a session',
|
|
121
|
+
'on its own cure.',
|
|
122
|
+
'',
|
|
123
|
+
'**What is gated is WHEN that polarity applies, not the polarity.** stale-main asks the cache',
|
|
124
|
+
'whether cached `commitsBehind` exceeds `branch-state-guard.maxCommitsBehind` (rows 6/7) and',
|
|
125
|
+
'default-denies only then; a current or tolerated `main` — which is',
|
|
126
|
+
'exactly where `pnpm wp-sync-main` leaves you — is not this guard\'s business at all.',
|
|
127
|
+
'',
|
|
128
|
+
'They remain separate CLASSES because the states they detect are different — one reads the branch',
|
|
129
|
+
'name, the other the cached merged flag — and because each carries its own message.',
|
|
130
|
+
'',
|
|
131
|
+
'## The cache',
|
|
132
|
+
'',
|
|
133
|
+
'`<primary clone>/.webpieces/main-sync-status.json`, written by a **detached single-flight',
|
|
134
|
+
'refresher**. It is fire-and-forget: it populates the cache for the NEXT call, never the current',
|
|
135
|
+
'one — so the first tool call of every session sees no cache and takes row ' + String(l2_rows_1.L2_FAIL_OPEN_ROW) + '. That is intended,',
|
|
136
|
+
'and it is why the on-main write block (row 5) must not depend on the cache.',
|
|
137
|
+
'That refresh also computes `commitsBehind`; guards never count on the hot path, and missing counts fail open.',
|
|
138
|
+
'',
|
|
139
|
+
'The file holds a **map of branch → status**, so every worktree\'s guards stay armed. Before that it',
|
|
140
|
+
'held one branch\'s snapshot, so with N worktrees at most one tree was armed at any instant and the',
|
|
141
|
+
'rest abstained, thrashing as the lock changed hands.',
|
|
142
|
+
'',
|
|
143
|
+
'**There is no TTL.** `timestamp` is logged and never enforced; an hours-old cache whose branch',
|
|
144
|
+
'matches is trusted to block. State A is mitigated by a live ancestry check (`git merge-base',
|
|
145
|
+
'--is-ancestor`, not hash equality, so a pull takes effect instantly); state B trusts the cached',
|
|
146
|
+
'merged flag, which is safe only because "merged" is monotonic.',
|
|
147
|
+
'',
|
|
148
|
+
'**`hangTimeoutMinutes` is ONE knob** — `branch-state-guard.hangTimeoutMinutes` — because there is',
|
|
149
|
+
'one refresher writing one cache. It used to be declared four times and read four times, which,',
|
|
150
|
+
'with the refresher\'s at-most-once-per-process latch and two config-blind callers ahead of the',
|
|
151
|
+
'guards, meant at most one of the four values could ever reach a spawn.',
|
|
152
|
+
'',
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
// The legend and the table itself — this is the ROW DATA.
|
|
156
|
+
// webpieces-disable no-function-outside-class -- second section of renderL2Doc's string, beside it in this module
|
|
157
|
+
function renderTable() {
|
|
158
|
+
return [
|
|
159
|
+
'## Table — one table, ordered, first match wins',
|
|
160
|
+
'',
|
|
161
|
+
'**Tools:** `B` Bash · `R` Read · `E` Write/Edit',
|
|
162
|
+
'',
|
|
163
|
+
'| # | tools | state | act | cure |',
|
|
164
|
+
'|---|---|---|---|---|',
|
|
165
|
+
...l2_rows_1.L2_ROWS.map(tableRow),
|
|
166
|
+
'',
|
|
167
|
+
`Rows 1-5 need **no cache** and fire on call #1: rows 1, 2 and 4 are text matches, row 3 is a`,
|
|
168
|
+
`marker-file scan, and row 5 is one \`git rev-parse\`. Row ${l2_rows_1.L2_FAIL_OPEN_ROW} is the divider: everything below it`,
|
|
169
|
+
`reads the main-sync cache, so if the branch is undeterminable, the cache is absent, it holds`,
|
|
170
|
+
`another branch, or the forge could not be reached, evaluation STOPS at row ${l2_rows_1.L2_FAIL_OPEN_ROW} and ALLOWS.`,
|
|
171
|
+
'',
|
|
172
|
+
`Row ${l2_rows_1.L2_FAIL_OPEN_ROW} is numbered after row 10 and PRINTED between 5 and 6, and that is not a mistake. Row`,
|
|
173
|
+
'numbers are identity — they are logged as `row=` and cited here — so renumbering 6-10 to slot it in',
|
|
174
|
+
'would silently re-point every reference. L1 does the same with its row 8.',
|
|
175
|
+
'',
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
// The prose that explains the table's shape — split out of renderTable purely to stay inside the
|
|
179
|
+
// method-line budget. The join order is what makes them one section; keep them adjacent.
|
|
180
|
+
// webpieces-disable no-function-outside-class -- continuation of renderTable above, beside it in this module
|
|
181
|
+
function renderTableNotes() {
|
|
182
|
+
return [
|
|
183
|
+
'### The one rule that explains the tool column',
|
|
184
|
+
'',
|
|
185
|
+
'**`B` tracks `E` everywhere except on `main`, where `B` tracks `R` instead — rows 5, 6 and 7.**',
|
|
186
|
+
'',
|
|
187
|
+
'The hazards differ. A WRITE on `main` lands work somewhere unreviewable and unrevertable at ANY',
|
|
188
|
+
'freshness, so row 5 is `E` only and is judged from the branch alone, above the cache divider. A',
|
|
189
|
+
'READ or a BUILD on a CURRENT `main` harms nothing, and blocking it strands the agent immediately',
|
|
190
|
+
'after `pnpm wp-sync-main` — the command this repo prescribes — put it there. So `B` joins',
|
|
191
|
+
'`R` on the freshness-gated pair: row 6 (behind) blocks, row 7 (current) allows, and "cannot tell"',
|
|
192
|
+
'fails open at row ' + String(l2_rows_1.L2_FAIL_OPEN_ROW) + ' by construction.',
|
|
193
|
+
'',
|
|
194
|
+
'Inside row 6 they still differ in SHAPE: a Read names exactly one file and is evaluated precisely;',
|
|
195
|
+
'a Bash command is opaque and gets the conservative answer, default-deny plus the row 4 skip list.',
|
|
196
|
+
'',
|
|
197
|
+
'### Why the order of row 5 is the most load-bearing thing here',
|
|
198
|
+
'',
|
|
199
|
+
'L2 is armed **from the second tool call onward**, because the refresher populates the cache for the',
|
|
200
|
+
'NEXT call. That is deliberate — it keeps the blocking path free of network git — and it is fine in',
|
|
201
|
+
'practice, because the agent discovers the problem within a command or two.',
|
|
202
|
+
'',
|
|
203
|
+
`Row 5 is the exception that must not be relaxed. Put "on \`main\`" BELOW row ${l2_rows_1.L2_FAIL_OPEN_ROW} and WRITES on \`main\``,
|
|
204
|
+
'are permitted for the whole first call of every session — and permanently in a multi-worktree repo,',
|
|
205
|
+
'where another tree can hold the refresh lock indefinitely. That is why row 5 is `E` only: the Bash',
|
|
206
|
+
'half asks a question the cache CAN answer late without harm ("is `main` behind?"), so it belongs',
|
|
207
|
+
'below the divider, where not knowing means allowing.',
|
|
208
|
+
'',
|
|
209
|
+
'### Why row 9 can block reads without trapping you',
|
|
210
|
+
'',
|
|
211
|
+
'Blocking reads on a broken fork point looks like it traps the agent away from the files it must',
|
|
212
|
+
'read to resolve the conflict. It does not, because **row 3 comes first**:',
|
|
213
|
+
'',
|
|
214
|
+
'blocked → `pnpm wp-start-update` (row 4, skip list) → now merge-in-progress → **row 3 exempts',
|
|
215
|
+
'everything** → read and write freely to resolve → finish. The exemption row is what lets row 9 be',
|
|
216
|
+
'strict.',
|
|
217
|
+
'',
|
|
218
|
+
'### Why row 8 can block reads on a dirty tree',
|
|
219
|
+
'',
|
|
220
|
+
'`git checkout -b <new> origin/main` **carries uncommitted changes onto the new branch**. The work',
|
|
221
|
+
'comes with you, so nothing needs reading first and nothing is trapped. Residual: if `origin/main`',
|
|
222
|
+
'changed the same files you edited, git refuses the switch — `git stash` is on the skip list and',
|
|
223
|
+
'clears it.',
|
|
224
|
+
'',
|
|
225
|
+
'Row 6 looked like the one place the dirty argument had teeth, because its FIRST cure pulls, and a',
|
|
226
|
+
'pull genuinely is not a clean fast-forward on a dirty tree. But row 6 has always carried a SECOND',
|
|
227
|
+
'cure — `git checkout -b <new> origin/main` — and that one works dirty for exactly the reason above.',
|
|
228
|
+
'The teeth were in the MESSAGE, which printed only the pull; it now prints both, labelled, so the',
|
|
229
|
+
'cure an agent reads is always one it can run. **So there is no dirty row anywhere, and no dirty',
|
|
230
|
+
'valve in the code either** — both were closed, and "Not done" is empty as a result.',
|
|
231
|
+
'',
|
|
232
|
+
'### Rows 12 and 13 — the cure may be COMPOSED with the work, but only with `&&`',
|
|
233
|
+
'',
|
|
234
|
+
'`pnpm wp-sync-main && cat src/app.ts` is ALLOWED. `pnpm wp-sync-main ; cat',
|
|
235
|
+
'src/app.ts` is REFUSED, and the refusal names the operator you typed.',
|
|
236
|
+
'',
|
|
237
|
+
'The difference belongs to the shell, not to this guard. `&&` short-circuits: the work cannot run',
|
|
238
|
+
'when the cure exits non-zero, which is exactly the property the row 6 block exists to guarantee.',
|
|
239
|
+
'Refusing that bought nothing and cost a round trip. `;` discards the cure\'s exit code and runs the',
|
|
240
|
+
'work regardless — measured with `>/dev/null 2>&1` on the cure in 7 of 9 observed cases, so the',
|
|
241
|
+
'failure was invisible as well as ignored. The two-step is genuinely safer there, because the NEXT',
|
|
242
|
+
'tool call is a fresh evaluation that recomputes `localMain` against `originMain`: a failed pull',
|
|
243
|
+
're-blocks. An allowed `;` compound never gets that second look.',
|
|
244
|
+
'',
|
|
245
|
+
'`git fetch` may LEAD the prefix (`git fetch --prune origin main && git pull --ff-only origin main`',
|
|
246
|
+
'is the shape agents type) but never satisfies it alone: a fetch moves the remote-tracking ref and',
|
|
247
|
+
'leaves local `main` exactly as far behind, so there is nothing for the `&&` to protect.',
|
|
248
|
+
'',
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
// The use-case table (ROW DATA, in the doc's own global numbering) and the note that explains it.
|
|
252
|
+
// webpieces-disable no-function-outside-class -- third section of renderL2Doc's string, beside it in this module
|
|
253
|
+
function renderUseCases() {
|
|
254
|
+
return [
|
|
255
|
+
'## L2 use cases',
|
|
256
|
+
'',
|
|
257
|
+
'Same row shape as L0 and L1: the **Fix** is literal or it is not a fix. Each case is attached IN',
|
|
258
|
+
'CODE to the row that judges it (`useCases` on `L2Row`), so this table cannot describe a row that no',
|
|
259
|
+
'longer exists and a row cannot quietly acquire behaviour nothing documents.',
|
|
260
|
+
'',
|
|
261
|
+
'**This table is how the layer LEARNS.** When a new situation comes up in a session, the change is',
|
|
262
|
+
'one more `new L2UseCase(...)` on the row that judged it — not a paragraph added here, which the',
|
|
263
|
+
'byte-lock spec would reject anyway. Every case also carries the exact `reason` string the guard',
|
|
264
|
+
'logs, and a spec pushes that back through `l2RowForReason` to assert it lands on the row it is filed',
|
|
265
|
+
'under. So a case whose row is wrong fails the build rather than misinforming a reader.',
|
|
266
|
+
'',
|
|
267
|
+
'| # | what you SEE (exact symptom) | state | verdict | Fix |',
|
|
268
|
+
'|---|---|---|---|---|',
|
|
269
|
+
...(0, l2_rows_1.allL2UseCases)().map(useCaseRow),
|
|
270
|
+
'',
|
|
271
|
+
'The incidental-write case under row 6 is the one to read first: `npx expo install` on `main`, in',
|
|
272
|
+
'another repo on this toolchain, modified two tracked files and no guard fired. It is filed under row',
|
|
273
|
+
'6 rather than row 5 because that is the row that judges Bash on `main` today — a command\'s stated',
|
|
274
|
+
'purpose never says whether it also writes, which is why the shape there is default-deny plus the row',
|
|
275
|
+
'4 skip list rather than a blocklist of readers anybody could have enumerated.',
|
|
276
|
+
'',
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
// How the log joins to this table, and the skip list. Prose plus the reason→row contract.
|
|
280
|
+
// webpieces-disable no-function-outside-class -- fourth section of renderL2Doc's string, beside it in this module
|
|
281
|
+
function renderNotes() {
|
|
282
|
+
return [
|
|
283
|
+
'## How a log line joins to a row',
|
|
284
|
+
'',
|
|
285
|
+
'Every L2 decision is written to `.webpieces/logs/L2-decisions/<writer>.log` with `layer=L2` and',
|
|
286
|
+
'`row=<n>`, where `<n>` is a row number from the table above. So `row=8` means "this call was judged',
|
|
287
|
+
'by row 8" and you read the state, the verdict and the cure straight off this page.',
|
|
288
|
+
'',
|
|
289
|
+
'**The join is by REASON, not by dispatch, and the difference is worth knowing.** L1 takes the first',
|
|
290
|
+
'matching row and switches on it, so deleting an L1 row deletes a block. L2\'s four classes each own',
|
|
291
|
+
'their own ladder (see "The four classes" above for why they cannot be one function), and',
|
|
292
|
+
'`L2_ROW_FOR_REASON` in `l2-rows.ts` maps each ladder exit to the row it is an instance of. A unit',
|
|
293
|
+
'test reads the four guard sources and asserts every reason literal resolves to a row, so a new exit',
|
|
294
|
+
'with no row fails the build rather than logging `row=-` forever.',
|
|
295
|
+
'',
|
|
296
|
+
'## The skip list (row 4)',
|
|
297
|
+
'',
|
|
298
|
+
'Principle: **these get you OUT or tell you where you are.** They are not "working here".',
|
|
299
|
+
'',
|
|
300
|
+
'| group | commands |',
|
|
301
|
+
'|---|---|',
|
|
302
|
+
'| get out | `git checkout -b <new> origin/main` · `git switch -c <new> origin/main` · `git switch <other>` · `git worktree add … -b <new> origin/main` |',
|
|
303
|
+
'| make `main` current | `pnpm wp-sync-main` *(the prescribed form — also reaps dead branches/worktrees and sweeps orphan directories)* · `git pull` · `git fetch` · `git checkout main && git pull origin main` *(paired only; still allowed, and still the L0 recovery cure, where no `pnpm` bin can be trusted)* |',
|
|
304
|
+
'| orient | `git status\\|log\\|diff\\|branch` · `gh` generally (`pr view`, `pr close`, `pr comment`, `api`, `run watch` — it talks to GitHub, not to this tree) |',
|
|
305
|
+
'| talk to the network | `curl` · `wget` — a URL is not this repo. NOT the forms that write a local file: `curl -o`, `wget -O`, `gh repo clone`, `gh pr checkout`, `gh run download`, or any `> file` redirect |',
|
|
306
|
+
'| park work | `git stash` |',
|
|
307
|
+
'| repair / tooling | `pnpm wp-start-update` · `pnpm wp-start-upsert-pr` · the `wp-*` bins |',
|
|
308
|
+
'',
|
|
309
|
+
'**NOT on it:** `git commit` `add` `push` `merge` `rebase` `reset` `restore` `clean` `cherry-pick` ·',
|
|
310
|
+
'`git grep` `show <rev>:<path>` `cat-file` `ls-files` (those read tracked content). **`pnpm build` /',
|
|
311
|
+
'`pnpm test` are not on it either** — there is no point running them on `main` or on a dead branch.',
|
|
312
|
+
'',
|
|
313
|
+
'## Cannot tell — everything that lands on row ' + String(l2_rows_1.L2_FAIL_OPEN_ROW),
|
|
314
|
+
'',
|
|
315
|
+
'| state | expected? | treatment |',
|
|
316
|
+
'|---|---|---|',
|
|
317
|
+
'| cache absent | **yes** — the refresher populates for the NEXT call, so this fires on the first tool call of every session | fail open, log |',
|
|
318
|
+
'| detached HEAD | **yes** — mid-rebase, `git checkout <sha>` | fail open, log |',
|
|
319
|
+
'| forge unreachable | **yes** — `gh` missing, unauthenticated, rate-limited or offline | fail open, log as `no-forge` |',
|
|
320
|
+
'| branch unresolvable | **no** — not a repo, git broken | fail open, log LOUDLY |',
|
|
321
|
+
'| cache for another branch | **no** — unreachable since the cache became branch-keyed | fail open, log LOUDLY |',
|
|
322
|
+
'',
|
|
323
|
+
'**Do NOT block to capture these cases.** `cache-absent` fires on every session\'s first call;',
|
|
324
|
+
'blocking there deadlocks every session behind a network fetch. And if a guard cannot establish',
|
|
325
|
+
'state, blocking means a *broken* guard wedges the session — the exact failure this family exists to',
|
|
326
|
+
'avoid.',
|
|
327
|
+
'',
|
|
328
|
+
'`ALLOW_FAIL_OPEN` is a TYPED VERDICT, not a string suffix on the reason, so abstentions are',
|
|
329
|
+
'countable. `no-forge` is the newest member: `branchAlreadyMerged: false` used to be produced both by',
|
|
330
|
+
'"this branch has no merged PR" and by "we could not ask", and both logged a plain ALLOW — so from',
|
|
331
|
+
'the trail you could not tell whether the merged-branch policy was protecting anything or quietly',
|
|
332
|
+
'standing down.',
|
|
333
|
+
'',
|
|
334
|
+
];
|
|
335
|
+
}
|
|
336
|
+
// The gaps between the table and the code, and the code anchors.
|
|
337
|
+
// webpieces-disable no-function-outside-class -- last section of renderL2Doc's string, beside it in this module
|
|
338
|
+
function renderTail() {
|
|
339
|
+
return [
|
|
340
|
+
'## Not done — rows the guards do not yet honour',
|
|
341
|
+
'',
|
|
342
|
+
...renderNotDoneBody(),
|
|
343
|
+
'',
|
|
344
|
+
'This section is generated from `NOT_DONE` in `l2-rows.ts`, so closing a gap means deleting its entry',
|
|
345
|
+
'and the doc follows — it cannot rot into a list of things that were fixed years ago.',
|
|
346
|
+
'',
|
|
347
|
+
'## Incidents these guards exist because of',
|
|
348
|
+
'',
|
|
349
|
+
'- **The 157-commit checkout.** An agent ran `git checkout main` in a clone whose local `main` was',
|
|
350
|
+
' 157 commits behind. That checkout reverted the `@webpieces` pin, reverted the guard shim — **the',
|
|
351
|
+
' drift guard itself** — to a copy whose message stated the drift backwards, and so reverted the',
|
|
352
|
+
' agent\'s judgment: it ran the `pnpm install` that message named and downgraded `node_modules`.',
|
|
353
|
+
' Lesson, quoted from the code: *a guard a stale checkout can revert cannot be relied on to catch a',
|
|
354
|
+
' stale checkout.* Hence row 2, which is preventive, matches on command TEXT only, and asks git',
|
|
355
|
+
' nothing — deliberately, because the only `main` it could measure is the one it is about to leave.',
|
|
356
|
+
'- **The side door.** An agent on a `main` 18 commits behind (108 files, +8069/−3692 upstream) had',
|
|
357
|
+
' its Read tool blocked exactly as designed, then spent the session `ls`-ing, `grep`-ing and',
|
|
358
|
+
' `cat`-ing the same stale tree, and described a CI workflow set missing a 186-line workflow that',
|
|
359
|
+
' existed upstream. *The logs read "read-stale-guard handled", which is worse than no guard: it',
|
|
360
|
+
' looks covered.*',
|
|
361
|
+
'- **Computed and thrown away.** Both file guards are file-scoped, so Bash reached neither. An agent',
|
|
362
|
+
' that only ran shell sailed through on a merged branch **even though `branchAlreadyMerged` was',
|
|
363
|
+
' loaded and logged on that very path.**',
|
|
364
|
+
'',
|
|
365
|
+
'---',
|
|
366
|
+
'',
|
|
367
|
+
'',
|
|
368
|
+
'## Code anchors',
|
|
369
|
+
'',
|
|
370
|
+
'| section | file | symbol |',
|
|
371
|
+
'|---|---|---|',
|
|
372
|
+
'| the rows + the reason→row join | `agent-workflow-rules/src/core/l2-rows.ts` | `L2_ROWS`, `l2RowForReason`, `NOT_DONE` |',
|
|
373
|
+
'| write policy | `agent-workflow-rules/src/core/rules/feature-branch-guard.ts` | `check` |',
|
|
374
|
+
'| read policy | `agent-workflow-rules/src/core/rules/read-stale-guard.ts` | `checkStaleMain`, `checkMergedBranch` |',
|
|
375
|
+
'| stale-main Bash | `agent-workflow-rules/src/core/rules/stale-main-bash-guard.ts` | `checkFreshness`, `bareCheckoutOfMain` |',
|
|
376
|
+
'| the shared freshness predicate | `agent-workflow-rules/src/core/rules/main-freshness.ts` | `containsOriginMain`, `summarize` |',
|
|
377
|
+
'| merged-branch Bash | `agent-workflow-rules/src/core/rules/merged-branch-bash-guard.ts` | `isFullyRecovery`, `ALLOWED_GIT_SUBCOMMANDS` |',
|
|
378
|
+
'| the cache | `rules-config/src/main-sync-status.ts`, `main-sync-file.ts` | `readMainSyncStatus`, `MainSyncStatusFile`, `forgeReachable` |',
|
|
379
|
+
'| the refresher | `agent-workflow-rules/src/core/sync-main.ts` | `refreshMainSync` |',
|
|
380
|
+
'| command scanning | `agent-workflow-rules/src/core/rules/content-read-scan.ts`, `shell-segment-scan.ts` | `readsStaleContent`, `classify` |',
|
|
381
|
+
'| the config key | `agent-workflow-rules/src/configs/main-sync-guard-configs.ts`, `policy-keys.ts` | `BranchStateGuardConfig`, `BRANCH_STATE_GUARD_KEY` |',
|
|
382
|
+
'',
|
|
383
|
+
];
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=l2-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l2-doc.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/l2-doc.ts"],"names":[],"mappings":"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","sourcesContent":["import { L2Row, L2NotDone, L2UseCase, L2_ROWS, L2_FAIL_OPEN_ROW, NOT_DONE, allL2UseCases } from './l2-rows';\n\n// ---------------------------------------------------------------------------\n// guards/L2-branch-state.md, rendered from L2_ROWS.\n//\n// Same arrangement as l1-doc.renderL1Doc(): one join('\\n') of literal markdown lines with the ROW DATA\n// interpolated from the array. Everything that is not row data is a literal line here, because that is\n// the half a generator cannot own.\n//\n// A unit test (l2-matrix.spec.ts) locks guards/L2-branch-state.md byte-identical to renderL2Doc(), and\n// `pnpm guards:generate` rewrites the file. The doc that stood here before was 100% hand-written and\n// carried its own warning that it could drift; it did, in three places at once (it proposed\n// `branch-state-guard` as a future key while GUARD_MATRIX.md proposed a different name and\n// docs/plans/guard-layer-toggles.md proposed a third).\n//\n// This module, like l2-rows.ts, has no runtime imports outside this pair so the generator can load it\n// without the package's transitive dependencies.\n// ---------------------------------------------------------------------------\n\n// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module\nfunction tableRow(row: L2Row): string {\n return `| ${row.num} | \\`${row.toolCell()}\\` | ${row.state} | ${row.action.label} | ${row.cure} |`;\n}\n\n// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module\nfunction notDoneRow(entry: L2NotDone): string {\n return `| ${entry.row} | ${entry.gap} | ${entry.why} |`;\n}\n\n/**\n * The \"Not done\" body — a table when there are gaps, a SENTENCE when there are none.\n *\n * An empty table renders as a bare header with nothing under it, which reads like a rendering bug\n * rather than like an achievement. \"Every row is honoured\" is a claim worth making in words, and it is\n * the state this section exists to drive the layer towards.\n */\n// webpieces-disable no-function-outside-class -- section builder for renderL2Doc below, in this render module\nfunction renderNotDoneBody(): string[] {\n if (NOT_DONE.length === 0) {\n return [\n '**Nothing. Every row in the table above is a row the guards actually honour today.**',\n '',\n 'That has not always been true, and the section stays here for when it stops being true again:',\n 'a row the code cannot yet honour is listed here rather than rendered as if it were live, the',\n 'same way L1 lists its unreachable `o` row. The three entries this section used to carry were',\n 'row 5\\'s Bash half (shipped, then moved: Bash on `main` is judged on FRESHNESS at rows 6/7, while',\n 'row 5 keeps the unconditional WRITE block) and the DIRTY-TREE',\n 'valves on rows 6 and 8 — both closed, because each of those rows cures with',\n '`git checkout -b <new> origin/main`, which carries uncommitted changes onto the new branch. A',\n 'dirty tree never trapped anyone; the row 6 message just printed the one cure that could not run',\n 'dirty, and the fix was to print both.',\n ];\n }\n return [\n 'Each row below describes INTENT the code has not caught up with. They are listed rather than',\n 'silently rendered as if they were live, the same way L1 lists its unreachable `o` row. Every one of',\n `them currently exits at row ${L2_FAIL_OPEN_ROW} instead, so the log never claims the strict row fired.`,\n '',\n '| row | the gap | why it has not shipped |',\n '|---|---|---|',\n ...NOT_DONE.map(notDoneRow),\n ];\n}\n\n// webpieces-disable no-function-outside-class -- pure row formatter for renderL2Doc below, in this render module\nfunction useCaseRow(useCase: L2UseCase): string {\n return `| ${useCase.num} | ${useCase.symptom} | ${useCase.state} | ${useCase.verdict} | ${useCase.fix} |`;\n}\n\n/**\n * Render guards/L2-branch-state.md.\n *\n * Split into sections purely to stay inside the method-line budget — the join order is what makes them\n * one file, so keep them adjacent and keep the byte-lock test as the arbiter.\n */\n// webpieces-disable no-function-outside-class -- pure string builder over L2_ROWS, beside the array it reads\nexport function renderL2Doc(): string {\n return [\n ...renderHead(),\n ...renderTable(),\n ...renderTableNotes(),\n ...renderUseCases(),\n ...renderNotes(),\n ...renderTail(),\n ].join('\\n');\n}\n\n// webpieces-disable no-function-outside-class -- first section of renderL2Doc's string, beside it in this module\nfunction renderHead(): string[] {\n return [\n '# L2 — branch state',\n '',\n '**Goal: may I work here, and is what I read current?**',\n '',\n '**Config key: `branch-state-guard`.** ONE key for the whole policy. It used to be FOUR —',\n '`feature-branch-guard`, `read-stale-guard`, `stale-main-bash-guard`, `merged-branch-bash-guard` —',\n 'and three of them carried nothing but `mode` plus the two escape hatches. Four keys made HALF a',\n 'policy representable: `read-stale-guard: OFF` beside `merged-branch-bash-guard: ON` is \"read the',\n 'file, yes; `cat` the same file, no\" — the same information, opposite verdicts, chosen by nobody.',\n 'One key makes that unconstructible. The four class NAMES are unchanged and still appear as `rule=`',\n 'on every decision-log line, so `grep rule=stale-main-bash-guard` keeps working; only the switch',\n 'merged. The four old keys are rejected by name with this destination — see `retired-config-keys.ts`.',\n '',\n '**Code:** `agent-workflow-rules/src/core/rules/{feature-branch,read-stale,stale-main-bash,merged-branch-bash}-guard.ts` ·',\n 'the rows in `agent-workflow-rules/src/core/l2-rows.ts` · the shared cache in',\n '`rules-config/src/main-sync-status.ts` + `main-sync-file.ts` · the refresher in',\n '`agent-workflow-rules/src/core/sync-main.ts`.',\n '',\n '## The four classes, and why there are four',\n '',\n '| | Write/Edit | Read | Bash |',\n '|---|---|---|---|',\n '| **state A** — stale `main` | `feature-branch-guard` | `read-stale-guard` | `stale-main-bash-guard` |',\n '| **state B** — merged branch | `feature-branch-guard` | `read-stale-guard` | `merged-branch-bash-guard` |',\n '',\n 'The split is TOOL WIRING, not policy. A Read names exactly one file; a Bash command is opaque; a',\n 'Write is neither.',\n '',\n '**The two Bash guards used to differ in polarity, and no longer do.** merged-branch was',\n 'default-DENY + allowlist; stale-main was default-ALLOW + blocklist of content readers, so',\n '`pnpm build` was denied by one and allowed by the other for the same reason — \"you should not be',\n 'working in this tree\". A blocklist of readers structurally cannot catch an installer, a formatter',\n 'or a codegen step, so both states now use default-DENY plus one shared `RecoveryAllowlist` (the',\n 'row 4 skip list). Two skip lists drift, and the half that drifts is the half that wedges a session',\n 'on its own cure.',\n '',\n '**What is gated is WHEN that polarity applies, not the polarity.** stale-main asks the cache',\n 'whether cached `commitsBehind` exceeds `branch-state-guard.maxCommitsBehind` (rows 6/7) and',\n 'default-denies only then; a current or tolerated `main` — which is',\n 'exactly where `pnpm wp-sync-main` leaves you — is not this guard\\'s business at all.',\n '',\n 'They remain separate CLASSES because the states they detect are different — one reads the branch',\n 'name, the other the cached merged flag — and because each carries its own message.',\n '',\n '## The cache',\n '',\n '`<primary clone>/.webpieces/main-sync-status.json`, written by a **detached single-flight',\n 'refresher**. It is fire-and-forget: it populates the cache for the NEXT call, never the current',\n 'one — so the first tool call of every session sees no cache and takes row ' + String(L2_FAIL_OPEN_ROW) + '. That is intended,',\n 'and it is why the on-main write block (row 5) must not depend on the cache.',\n 'That refresh also computes `commitsBehind`; guards never count on the hot path, and missing counts fail open.',\n '',\n 'The file holds a **map of branch → status**, so every worktree\\'s guards stay armed. Before that it',\n 'held one branch\\'s snapshot, so with N worktrees at most one tree was armed at any instant and the',\n 'rest abstained, thrashing as the lock changed hands.',\n '',\n '**There is no TTL.** `timestamp` is logged and never enforced; an hours-old cache whose branch',\n 'matches is trusted to block. State A is mitigated by a live ancestry check (`git merge-base',\n '--is-ancestor`, not hash equality, so a pull takes effect instantly); state B trusts the cached',\n 'merged flag, which is safe only because \"merged\" is monotonic.',\n '',\n '**`hangTimeoutMinutes` is ONE knob** — `branch-state-guard.hangTimeoutMinutes` — because there is',\n 'one refresher writing one cache. It used to be declared four times and read four times, which,',\n 'with the refresher\\'s at-most-once-per-process latch and two config-blind callers ahead of the',\n 'guards, meant at most one of the four values could ever reach a spawn.',\n '',\n ];\n}\n\n// The legend and the table itself — this is the ROW DATA.\n// webpieces-disable no-function-outside-class -- second section of renderL2Doc's string, beside it in this module\nfunction renderTable(): string[] {\n return [\n '## Table — one table, ordered, first match wins',\n '',\n '**Tools:** `B` Bash · `R` Read · `E` Write/Edit',\n '',\n '| # | tools | state | act | cure |',\n '|---|---|---|---|---|',\n ...L2_ROWS.map(tableRow),\n '',\n `Rows 1-5 need **no cache** and fire on call #1: rows 1, 2 and 4 are text matches, row 3 is a`,\n `marker-file scan, and row 5 is one \\`git rev-parse\\`. Row ${L2_FAIL_OPEN_ROW} is the divider: everything below it`,\n `reads the main-sync cache, so if the branch is undeterminable, the cache is absent, it holds`,\n `another branch, or the forge could not be reached, evaluation STOPS at row ${L2_FAIL_OPEN_ROW} and ALLOWS.`,\n '',\n `Row ${L2_FAIL_OPEN_ROW} is numbered after row 10 and PRINTED between 5 and 6, and that is not a mistake. Row`,\n 'numbers are identity — they are logged as `row=` and cited here — so renumbering 6-10 to slot it in',\n 'would silently re-point every reference. L1 does the same with its row 8.',\n '',\n ];\n}\n\n// The prose that explains the table's shape — split out of renderTable purely to stay inside the\n// method-line budget. The join order is what makes them one section; keep them adjacent.\n// webpieces-disable no-function-outside-class -- continuation of renderTable above, beside it in this module\nfunction renderTableNotes(): string[] {\n return [\n '### The one rule that explains the tool column',\n '',\n '**`B` tracks `E` everywhere except on `main`, where `B` tracks `R` instead — rows 5, 6 and 7.**',\n '',\n 'The hazards differ. A WRITE on `main` lands work somewhere unreviewable and unrevertable at ANY',\n 'freshness, so row 5 is `E` only and is judged from the branch alone, above the cache divider. A',\n 'READ or a BUILD on a CURRENT `main` harms nothing, and blocking it strands the agent immediately',\n 'after `pnpm wp-sync-main` — the command this repo prescribes — put it there. So `B` joins',\n '`R` on the freshness-gated pair: row 6 (behind) blocks, row 7 (current) allows, and \"cannot tell\"',\n 'fails open at row ' + String(L2_FAIL_OPEN_ROW) + ' by construction.',\n '',\n 'Inside row 6 they still differ in SHAPE: a Read names exactly one file and is evaluated precisely;',\n 'a Bash command is opaque and gets the conservative answer, default-deny plus the row 4 skip list.',\n '',\n '### Why the order of row 5 is the most load-bearing thing here',\n '',\n 'L2 is armed **from the second tool call onward**, because the refresher populates the cache for the',\n 'NEXT call. That is deliberate — it keeps the blocking path free of network git — and it is fine in',\n 'practice, because the agent discovers the problem within a command or two.',\n '',\n `Row 5 is the exception that must not be relaxed. Put \"on \\`main\\`\" BELOW row ${L2_FAIL_OPEN_ROW} and WRITES on \\`main\\``,\n 'are permitted for the whole first call of every session — and permanently in a multi-worktree repo,',\n 'where another tree can hold the refresh lock indefinitely. That is why row 5 is `E` only: the Bash',\n 'half asks a question the cache CAN answer late without harm (\"is `main` behind?\"), so it belongs',\n 'below the divider, where not knowing means allowing.',\n '',\n '### Why row 9 can block reads without trapping you',\n '',\n 'Blocking reads on a broken fork point looks like it traps the agent away from the files it must',\n 'read to resolve the conflict. It does not, because **row 3 comes first**:',\n '',\n 'blocked → `pnpm wp-start-update` (row 4, skip list) → now merge-in-progress → **row 3 exempts',\n 'everything** → read and write freely to resolve → finish. The exemption row is what lets row 9 be',\n 'strict.',\n '',\n '### Why row 8 can block reads on a dirty tree',\n '',\n '`git checkout -b <new> origin/main` **carries uncommitted changes onto the new branch**. The work',\n 'comes with you, so nothing needs reading first and nothing is trapped. Residual: if `origin/main`',\n 'changed the same files you edited, git refuses the switch — `git stash` is on the skip list and',\n 'clears it.',\n '',\n 'Row 6 looked like the one place the dirty argument had teeth, because its FIRST cure pulls, and a',\n 'pull genuinely is not a clean fast-forward on a dirty tree. But row 6 has always carried a SECOND',\n 'cure — `git checkout -b <new> origin/main` — and that one works dirty for exactly the reason above.',\n 'The teeth were in the MESSAGE, which printed only the pull; it now prints both, labelled, so the',\n 'cure an agent reads is always one it can run. **So there is no dirty row anywhere, and no dirty',\n 'valve in the code either** — both were closed, and \"Not done\" is empty as a result.',\n '',\n '### Rows 12 and 13 — the cure may be COMPOSED with the work, but only with `&&`',\n '',\n '`pnpm wp-sync-main && cat src/app.ts` is ALLOWED. `pnpm wp-sync-main ; cat',\n 'src/app.ts` is REFUSED, and the refusal names the operator you typed.',\n '',\n 'The difference belongs to the shell, not to this guard. `&&` short-circuits: the work cannot run',\n 'when the cure exits non-zero, which is exactly the property the row 6 block exists to guarantee.',\n 'Refusing that bought nothing and cost a round trip. `;` discards the cure\\'s exit code and runs the',\n 'work regardless — measured with `>/dev/null 2>&1` on the cure in 7 of 9 observed cases, so the',\n 'failure was invisible as well as ignored. The two-step is genuinely safer there, because the NEXT',\n 'tool call is a fresh evaluation that recomputes `localMain` against `originMain`: a failed pull',\n 're-blocks. An allowed `;` compound never gets that second look.',\n '',\n '`git fetch` may LEAD the prefix (`git fetch --prune origin main && git pull --ff-only origin main`',\n 'is the shape agents type) but never satisfies it alone: a fetch moves the remote-tracking ref and',\n 'leaves local `main` exactly as far behind, so there is nothing for the `&&` to protect.',\n '',\n ];\n}\n\n// The use-case table (ROW DATA, in the doc's own global numbering) and the note that explains it.\n// webpieces-disable no-function-outside-class -- third section of renderL2Doc's string, beside it in this module\nfunction renderUseCases(): string[] {\n return [\n '## L2 use cases',\n '',\n 'Same row shape as L0 and L1: the **Fix** is literal or it is not a fix. Each case is attached IN',\n 'CODE to the row that judges it (`useCases` on `L2Row`), so this table cannot describe a row that no',\n 'longer exists and a row cannot quietly acquire behaviour nothing documents.',\n '',\n '**This table is how the layer LEARNS.** When a new situation comes up in a session, the change is',\n 'one more `new L2UseCase(...)` on the row that judged it — not a paragraph added here, which the',\n 'byte-lock spec would reject anyway. Every case also carries the exact `reason` string the guard',\n 'logs, and a spec pushes that back through `l2RowForReason` to assert it lands on the row it is filed',\n 'under. So a case whose row is wrong fails the build rather than misinforming a reader.',\n '',\n '| # | what you SEE (exact symptom) | state | verdict | Fix |',\n '|---|---|---|---|---|',\n ...allL2UseCases().map(useCaseRow),\n '',\n 'The incidental-write case under row 6 is the one to read first: `npx expo install` on `main`, in',\n 'another repo on this toolchain, modified two tracked files and no guard fired. It is filed under row',\n '6 rather than row 5 because that is the row that judges Bash on `main` today — a command\\'s stated',\n 'purpose never says whether it also writes, which is why the shape there is default-deny plus the row',\n '4 skip list rather than a blocklist of readers anybody could have enumerated.',\n '',\n ];\n}\n\n// How the log joins to this table, and the skip list. Prose plus the reason→row contract.\n// webpieces-disable no-function-outside-class -- fourth section of renderL2Doc's string, beside it in this module\nfunction renderNotes(): string[] {\n return [\n '## How a log line joins to a row',\n '',\n 'Every L2 decision is written to `.webpieces/logs/L2-decisions/<writer>.log` with `layer=L2` and',\n '`row=<n>`, where `<n>` is a row number from the table above. So `row=8` means \"this call was judged',\n 'by row 8\" and you read the state, the verdict and the cure straight off this page.',\n '',\n '**The join is by REASON, not by dispatch, and the difference is worth knowing.** L1 takes the first',\n 'matching row and switches on it, so deleting an L1 row deletes a block. L2\\'s four classes each own',\n 'their own ladder (see \"The four classes\" above for why they cannot be one function), and',\n '`L2_ROW_FOR_REASON` in `l2-rows.ts` maps each ladder exit to the row it is an instance of. A unit',\n 'test reads the four guard sources and asserts every reason literal resolves to a row, so a new exit',\n 'with no row fails the build rather than logging `row=-` forever.',\n '',\n '## The skip list (row 4)',\n '',\n 'Principle: **these get you OUT or tell you where you are.** They are not \"working here\".',\n '',\n '| group | commands |',\n '|---|---|',\n '| get out | `git checkout -b <new> origin/main` · `git switch -c <new> origin/main` · `git switch <other>` · `git worktree add … -b <new> origin/main` |',\n '| make `main` current | `pnpm wp-sync-main` *(the prescribed form — also reaps dead branches/worktrees and sweeps orphan directories)* · `git pull` · `git fetch` · `git checkout main && git pull origin main` *(paired only; still allowed, and still the L0 recovery cure, where no `pnpm` bin can be trusted)* |',\n '| orient | `git status\\\\|log\\\\|diff\\\\|branch` · `gh` generally (`pr view`, `pr close`, `pr comment`, `api`, `run watch` — it talks to GitHub, not to this tree) |',\n '| talk to the network | `curl` · `wget` — a URL is not this repo. NOT the forms that write a local file: `curl -o`, `wget -O`, `gh repo clone`, `gh pr checkout`, `gh run download`, or any `> file` redirect |',\n '| park work | `git stash` |',\n '| repair / tooling | `pnpm wp-start-update` · `pnpm wp-start-upsert-pr` · the `wp-*` bins |',\n '',\n '**NOT on it:** `git commit` `add` `push` `merge` `rebase` `reset` `restore` `clean` `cherry-pick` ·',\n '`git grep` `show <rev>:<path>` `cat-file` `ls-files` (those read tracked content). **`pnpm build` /',\n '`pnpm test` are not on it either** — there is no point running them on `main` or on a dead branch.',\n '',\n '## Cannot tell — everything that lands on row ' + String(L2_FAIL_OPEN_ROW),\n '',\n '| state | expected? | treatment |',\n '|---|---|---|',\n '| cache absent | **yes** — the refresher populates for the NEXT call, so this fires on the first tool call of every session | fail open, log |',\n '| detached HEAD | **yes** — mid-rebase, `git checkout <sha>` | fail open, log |',\n '| forge unreachable | **yes** — `gh` missing, unauthenticated, rate-limited or offline | fail open, log as `no-forge` |',\n '| branch unresolvable | **no** — not a repo, git broken | fail open, log LOUDLY |',\n '| cache for another branch | **no** — unreachable since the cache became branch-keyed | fail open, log LOUDLY |',\n '',\n '**Do NOT block to capture these cases.** `cache-absent` fires on every session\\'s first call;',\n 'blocking there deadlocks every session behind a network fetch. And if a guard cannot establish',\n 'state, blocking means a *broken* guard wedges the session — the exact failure this family exists to',\n 'avoid.',\n '',\n '`ALLOW_FAIL_OPEN` is a TYPED VERDICT, not a string suffix on the reason, so abstentions are',\n 'countable. `no-forge` is the newest member: `branchAlreadyMerged: false` used to be produced both by',\n '\"this branch has no merged PR\" and by \"we could not ask\", and both logged a plain ALLOW — so from',\n 'the trail you could not tell whether the merged-branch policy was protecting anything or quietly',\n 'standing down.',\n '',\n ];\n}\n\n// The gaps between the table and the code, and the code anchors.\n// webpieces-disable no-function-outside-class -- last section of renderL2Doc's string, beside it in this module\nfunction renderTail(): string[] {\n return [\n '## Not done — rows the guards do not yet honour',\n '',\n ...renderNotDoneBody(),\n '',\n 'This section is generated from `NOT_DONE` in `l2-rows.ts`, so closing a gap means deleting its entry',\n 'and the doc follows — it cannot rot into a list of things that were fixed years ago.',\n '',\n '## Incidents these guards exist because of',\n '',\n '- **The 157-commit checkout.** An agent ran `git checkout main` in a clone whose local `main` was',\n ' 157 commits behind. That checkout reverted the `@webpieces` pin, reverted the guard shim — **the',\n ' drift guard itself** — to a copy whose message stated the drift backwards, and so reverted the',\n ' agent\\'s judgment: it ran the `pnpm install` that message named and downgraded `node_modules`.',\n ' Lesson, quoted from the code: *a guard a stale checkout can revert cannot be relied on to catch a',\n ' stale checkout.* Hence row 2, which is preventive, matches on command TEXT only, and asks git',\n ' nothing — deliberately, because the only `main` it could measure is the one it is about to leave.',\n '- **The side door.** An agent on a `main` 18 commits behind (108 files, +8069/−3692 upstream) had',\n ' its Read tool blocked exactly as designed, then spent the session `ls`-ing, `grep`-ing and',\n ' `cat`-ing the same stale tree, and described a CI workflow set missing a 186-line workflow that',\n ' existed upstream. *The logs read \"read-stale-guard handled\", which is worse than no guard: it',\n ' looks covered.*',\n '- **Computed and thrown away.** Both file guards are file-scoped, so Bash reached neither. An agent',\n ' that only ran shell sailed through on a merged branch **even though `branchAlreadyMerged` was',\n ' loaded and logged on that very path.**',\n '',\n '---',\n '',\n '',\n '## Code anchors',\n '',\n '| section | file | symbol |',\n '|---|---|---|',\n '| the rows + the reason→row join | `agent-workflow-rules/src/core/l2-rows.ts` | `L2_ROWS`, `l2RowForReason`, `NOT_DONE` |',\n '| write policy | `agent-workflow-rules/src/core/rules/feature-branch-guard.ts` | `check` |',\n '| read policy | `agent-workflow-rules/src/core/rules/read-stale-guard.ts` | `checkStaleMain`, `checkMergedBranch` |',\n '| stale-main Bash | `agent-workflow-rules/src/core/rules/stale-main-bash-guard.ts` | `checkFreshness`, `bareCheckoutOfMain` |',\n '| the shared freshness predicate | `agent-workflow-rules/src/core/rules/main-freshness.ts` | `containsOriginMain`, `summarize` |',\n '| merged-branch Bash | `agent-workflow-rules/src/core/rules/merged-branch-bash-guard.ts` | `isFullyRecovery`, `ALLOWED_GIT_SUBCOMMANDS` |',\n '| the cache | `rules-config/src/main-sync-status.ts`, `main-sync-file.ts` | `readMainSyncStatus`, `MainSyncStatusFile`, `forgeReachable` |',\n '| the refresher | `agent-workflow-rules/src/core/sync-main.ts` | `refreshMainSync` |',\n '| command scanning | `agent-workflow-rules/src/core/rules/content-read-scan.ts`, `shell-segment-scan.ts` | `readsStaleContent`, `classify` |',\n '| the config key | `agent-workflow-rules/src/configs/main-sync-guard-configs.ts`, `policy-keys.ts` | `BranchStateGuardConfig`, `BRANCH_STATE_GUARD_KEY` |',\n '',\n ];\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The delivered copy of guards/L2-branch-state.md, as a rules-config template name. */
|
|
2
|
+
export declare const BRANCH_STATE_MATRIX_DOC = "webpieces.branch-state-matrix.md";
|
|
3
|
+
/**
|
|
4
|
+
* Drop the L2 matrix where the AI can read it, and return its absolute path ('' if it could not be
|
|
5
|
+
* written).
|
|
6
|
+
*
|
|
7
|
+
* Best-effort by design, exactly as `writeGuardMatrixDoc` is: this runs on a path that is already
|
|
8
|
+
* denying the call, and a missing template (a `@webpieces/rules-config` older than this package) must
|
|
9
|
+
* cost the reader a pointer, never turn their deny into a stack trace.
|
|
10
|
+
*/
|
|
11
|
+
export declare function writeBranchStateMatrixDoc(workspaceRoot: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* The `READ <path>` pointer appended to an L2 deny, or '' when the doc could not be written.
|
|
14
|
+
*
|
|
15
|
+
* Opens with a NEWLINE and carries no quotes or backslashes, for the same two reasons L0's does: the
|
|
16
|
+
* deny renders in the house format (a header, a `[guard-name]` block, `Fix Option N:` lines) so a
|
|
17
|
+
* pointer glued onto the last line is the one place that shape breaks; and the text is interpolated
|
|
18
|
+
* into a JSON payload, where a quote would corrupt the decision rather than merely the prose.
|
|
19
|
+
*
|
|
20
|
+
* It names the ROW as well as the path. A bare "read this doc" is a page; a row number is the two
|
|
21
|
+
* lines that explain this exact verdict, and the log line for this call carries the same number.
|
|
22
|
+
*/
|
|
23
|
+
export declare function branchStateMatrixPointer(docPath: string, row: string): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BRANCH_STATE_MATRIX_DOC = void 0;
|
|
4
|
+
exports.writeBranchStateMatrixDoc = writeBranchStateMatrixDoc;
|
|
5
|
+
exports.branchStateMatrixPointer = branchStateMatrixPointer;
|
|
6
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// The L2 matrix, DELIVERED — dropped where a blocked agent can read it, and named in the deny.
|
|
10
|
+
//
|
|
11
|
+
// L0 has done this since the config-missing fault: `writeGuardMatrixDoc` drops
|
|
12
|
+
// webpieces.guard-matrix.md into `.webpieces/instruct-ai/` on a BLOCK, and `guardMatrixPointer` puts
|
|
13
|
+
// its ABSOLUTE path in the deny text. L2 had the better table and none of the delivery: its rows,
|
|
14
|
+
// their cures and their use cases lived in `guards/L2-branch-state.md`, a path an agent has no reason
|
|
15
|
+
// to know and every reason not to find — while the deny it was actually reading named no doc at all.
|
|
16
|
+
//
|
|
17
|
+
// So this is L0's mechanism, applied to L2. Same three pieces, same reasons:
|
|
18
|
+
//
|
|
19
|
+
// the DOC a rules-config TEMPLATE, byte-locked to renderL2Doc() by l2-matrix.spec.ts, so the
|
|
20
|
+
// delivered copy cannot describe a table the guards no longer have.
|
|
21
|
+
// the WRITE lazy and best-effort, ONLY on a block. An agent that is not blocked does not need it,
|
|
22
|
+
// and a failed write must degrade the deny, never replace it with a crash.
|
|
23
|
+
// the POINTER an ABSOLUTE path. A relative one is unusable: the shell's cwd is not the governed
|
|
24
|
+
// root and cannot be assumed (see EffectiveTree), which is the same reason L1's
|
|
25
|
+
// messages name `<root>` explicitly rather than telling the agent to `cd` first.
|
|
26
|
+
//
|
|
27
|
+
// WHY THE POINTER AND THE `cure=` LOG FIELD SHIP TOGETHER (matrix-cures.ts is the other half): the
|
|
28
|
+
// deny hands the agent the row's cure and the path to the table that cure came from; the log records
|
|
29
|
+
// the row AND that same cure literal. So "what did the guard tell it to do" is answerable from the
|
|
30
|
+
// trail alone, and comparing the two is how you find a row whose use cases need updating — which is
|
|
31
|
+
// the whole point of keeping use cases as row data.
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
/** The delivered copy of guards/L2-branch-state.md, as a rules-config template name. */
|
|
34
|
+
exports.BRANCH_STATE_MATRIX_DOC = 'webpieces.branch-state-matrix.md';
|
|
35
|
+
/**
|
|
36
|
+
* Drop the L2 matrix where the AI can read it, and return its absolute path ('' if it could not be
|
|
37
|
+
* written).
|
|
38
|
+
*
|
|
39
|
+
* Best-effort by design, exactly as `writeGuardMatrixDoc` is: this runs on a path that is already
|
|
40
|
+
* denying the call, and a missing template (a `@webpieces/rules-config` older than this package) must
|
|
41
|
+
* cost the reader a pointer, never turn their deny into a stack trace.
|
|
42
|
+
*/
|
|
43
|
+
// webpieces-disable no-function-outside-class -- sibling of branchStateMatrixPointer, the shape L0's writeGuardMatrixDoc already established
|
|
44
|
+
function writeBranchStateMatrixDoc(workspaceRoot) {
|
|
45
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
46
|
+
try {
|
|
47
|
+
return (0, rules_config_1.writeTemplate)(workspaceRoot, exports.BRANCH_STATE_MATRIX_DOC);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
const error = (0, to_error_1.toError)(err);
|
|
51
|
+
void error; // best-effort: no doc → the deny simply omits the pointer
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The `READ <path>` pointer appended to an L2 deny, or '' when the doc could not be written.
|
|
57
|
+
*
|
|
58
|
+
* Opens with a NEWLINE and carries no quotes or backslashes, for the same two reasons L0's does: the
|
|
59
|
+
* deny renders in the house format (a header, a `[guard-name]` block, `Fix Option N:` lines) so a
|
|
60
|
+
* pointer glued onto the last line is the one place that shape breaks; and the text is interpolated
|
|
61
|
+
* into a JSON payload, where a quote would corrupt the decision rather than merely the prose.
|
|
62
|
+
*
|
|
63
|
+
* It names the ROW as well as the path. A bare "read this doc" is a page; a row number is the two
|
|
64
|
+
* lines that explain this exact verdict, and the log line for this call carries the same number.
|
|
65
|
+
*/
|
|
66
|
+
// webpieces-disable no-function-outside-class -- sibling of writeBranchStateMatrixDoc, mirroring l0-matrix.ts
|
|
67
|
+
function branchStateMatrixPointer(docPath, row) {
|
|
68
|
+
if (docPath === '')
|
|
69
|
+
return '';
|
|
70
|
+
return `\nThe full L2 branch-state matrix - every row, its cure, and the observed use cases it covers - is at ${docPath}; this call was judged by ROW ${row}, and the L2-decisions log line for it carries the same row= and cure=. READ that row if you are unsure why this call was blocked.`;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=l2-matrix-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l2-matrix-doc.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/l2-matrix-doc.ts"],"names":[],"mappings":";;;AA0CA,8DASC;AAcD,4DAGC;AApED,0DAAwD;AAExD,iEAA6D;AAE7D,8EAA8E;AAC9E,+FAA+F;AAC/F,EAAE;AACF,+EAA+E;AAC/E,qGAAqG;AACrG,kGAAkG;AAClG,sGAAsG;AACtG,qGAAqG;AACrG,EAAE;AACF,6EAA6E;AAC7E,EAAE;AACF,oGAAoG;AACpG,mFAAmF;AACnF,uGAAuG;AACvG,0FAA0F;AAC1F,mGAAmG;AACnG,+FAA+F;AAC/F,gGAAgG;AAChG,EAAE;AACF,mGAAmG;AACnG,qGAAqG;AACrG,mGAAmG;AACnG,oGAAoG;AACpG,oDAAoD;AACpD,8EAA8E;AAE9E,wFAAwF;AAC3E,QAAA,uBAAuB,GAAG,kCAAkC,CAAC;AAE1E;;;;;;;GAOG;AACH,6IAA6I;AAC7I,SAAgB,yBAAyB,CAAC,aAAqB;IAC3D,8DAA8D;IAC9D,IAAI,CAAC;QACD,OAAO,IAAA,4BAAa,EAAC,aAAa,EAAE,+BAAuB,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC,CAAC,0DAA0D;QACtE,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,8GAA8G;AAC9G,SAAgB,wBAAwB,CAAC,OAAe,EAAE,GAAW;IACjE,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,yGAAyG,OAAO,iCAAiC,GAAG,oIAAoI,CAAC;AACpS,CAAC","sourcesContent":["import { writeTemplate } from '@webpieces/rules-config';\n\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n// ---------------------------------------------------------------------------\n// The L2 matrix, DELIVERED — dropped where a blocked agent can read it, and named in the deny.\n//\n// L0 has done this since the config-missing fault: `writeGuardMatrixDoc` drops\n// webpieces.guard-matrix.md into `.webpieces/instruct-ai/` on a BLOCK, and `guardMatrixPointer` puts\n// its ABSOLUTE path in the deny text. L2 had the better table and none of the delivery: its rows,\n// their cures and their use cases lived in `guards/L2-branch-state.md`, a path an agent has no reason\n// to know and every reason not to find — while the deny it was actually reading named no doc at all.\n//\n// So this is L0's mechanism, applied to L2. Same three pieces, same reasons:\n//\n// the DOC a rules-config TEMPLATE, byte-locked to renderL2Doc() by l2-matrix.spec.ts, so the\n// delivered copy cannot describe a table the guards no longer have.\n// the WRITE lazy and best-effort, ONLY on a block. An agent that is not blocked does not need it,\n// and a failed write must degrade the deny, never replace it with a crash.\n// the POINTER an ABSOLUTE path. A relative one is unusable: the shell's cwd is not the governed\n// root and cannot be assumed (see EffectiveTree), which is the same reason L1's\n// messages name `<root>` explicitly rather than telling the agent to `cd` first.\n//\n// WHY THE POINTER AND THE `cure=` LOG FIELD SHIP TOGETHER (matrix-cures.ts is the other half): the\n// deny hands the agent the row's cure and the path to the table that cure came from; the log records\n// the row AND that same cure literal. So \"what did the guard tell it to do\" is answerable from the\n// trail alone, and comparing the two is how you find a row whose use cases need updating — which is\n// the whole point of keeping use cases as row data.\n// ---------------------------------------------------------------------------\n\n/** The delivered copy of guards/L2-branch-state.md, as a rules-config template name. */\nexport const BRANCH_STATE_MATRIX_DOC = 'webpieces.branch-state-matrix.md';\n\n/**\n * Drop the L2 matrix where the AI can read it, and return its absolute path ('' if it could not be\n * written).\n *\n * Best-effort by design, exactly as `writeGuardMatrixDoc` is: this runs on a path that is already\n * denying the call, and a missing template (a `@webpieces/rules-config` older than this package) must\n * cost the reader a pointer, never turn their deny into a stack trace.\n */\n// webpieces-disable no-function-outside-class -- sibling of branchStateMatrixPointer, the shape L0's writeGuardMatrixDoc already established\nexport function writeBranchStateMatrixDoc(workspaceRoot: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return writeTemplate(workspaceRoot, BRANCH_STATE_MATRIX_DOC);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: no doc → the deny simply omits the pointer\n return '';\n }\n}\n\n/**\n * The `READ <path>` pointer appended to an L2 deny, or '' when the doc could not be written.\n *\n * Opens with a NEWLINE and carries no quotes or backslashes, for the same two reasons L0's does: the\n * deny renders in the house format (a header, a `[guard-name]` block, `Fix Option N:` lines) so a\n * pointer glued onto the last line is the one place that shape breaks; and the text is interpolated\n * into a JSON payload, where a quote would corrupt the decision rather than merely the prose.\n *\n * It names the ROW as well as the path. A bare \"read this doc\" is a page; a row number is the two\n * lines that explain this exact verdict, and the log line for this call carries the same number.\n */\n// webpieces-disable no-function-outside-class -- sibling of writeBranchStateMatrixDoc, mirroring l0-matrix.ts\nexport function branchStateMatrixPointer(docPath: string, row: string): string {\n if (docPath === '') return '';\n return `\\nThe full L2 branch-state matrix - every row, its cure, and the observed use cases it covers - is at ${docPath}; this call was judged by ROW ${row}, and the L2-decisions log line for it carries the same row= and cure=. READ that row if you are unsure why this call was blocked.`;\n}\n"]}
|