@webpieces/ai-hook-rules 0.4.839 → 0.4.841
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 +12 -140
- package/package.json +7 -15
- package/src/adapters/hook-app-fixtures.d.ts +1 -1
- package/src/adapters/hook-app-fixtures.js +0 -8
- package/src/adapters/hook-app-fixtures.js.map +1 -1
- package/src/adapters/hook-core.d.ts +1 -21
- package/src/adapters/hook-core.js +22 -341
- package/src/adapters/hook-core.js.map +1 -1
- package/src/core/load-rules.d.ts +4 -39
- package/src/core/load-rules.js +15 -127
- package/src/core/load-rules.js.map +1 -1
- package/src/core/rules/catch-error-pattern.d.ts +3 -3
- package/src/core/rules/catch-error-pattern.js +13 -13
- package/src/core/rules/catch-error-pattern.js.map +1 -1
- package/src/core/rules/index.d.ts +1 -14
- package/src/core/rules/index.js +1 -17
- package/src/core/rules/index.js.map +1 -1
- package/src/core/rules/match-rule.d.ts +3 -3
- package/src/core/rules/match-rule.js +6 -6
- package/src/core/rules/match-rule.js.map +1 -1
- package/src/core/rules/max-file-lines.d.ts +3 -3
- package/src/core/rules/max-file-lines.js +7 -7
- package/src/core/rules/max-file-lines.js.map +1 -1
- package/src/core/rules/no-any-unknown.d.ts +3 -3
- package/src/core/rules/no-any-unknown.js +6 -6
- package/src/core/rules/no-any-unknown.js.map +1 -1
- package/src/core/rules/no-custom-css.d.ts +3 -3
- package/src/core/rules/no-custom-css.js +7 -7
- package/src/core/rules/no-custom-css.js.map +1 -1
- package/src/core/rules/no-destructure.d.ts +3 -3
- package/src/core/rules/no-destructure.js +7 -7
- package/src/core/rules/no-destructure.js.map +1 -1
- package/src/core/rules/no-implicit-any.d.ts +3 -3
- package/src/core/rules/no-implicit-any.js +6 -6
- package/src/core/rules/no-implicit-any.js.map +1 -1
- package/src/core/rules/no-js-files.d.ts +3 -3
- package/src/core/rules/no-js-files.js +6 -6
- package/src/core/rules/no-js-files.js.map +1 -1
- package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
- package/src/core/rules/no-process-exit-outside-main.js +7 -7
- package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
- package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
- package/src/core/rules/no-symbol-di-tokens.js +7 -7
- package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
- package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
- package/src/core/rules/no-unmanaged-exceptions.js +9 -9
- package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
- package/src/core/rules/require-return-type.d.ts +3 -3
- package/src/core/rules/require-return-type.js +6 -6
- package/src/core/rules/require-return-type.js.map +1 -1
- package/src/core/rules/throw-cause-required.d.ts +3 -3
- package/src/core/rules/throw-cause-required.js +9 -9
- package/src/core/rules/throw-cause-required.js.map +1 -1
- package/src/core/rules/validate-ts-in-src.d.ts +3 -3
- package/src/core/rules/validate-ts-in-src.js +7 -7
- package/src/core/rules/validate-ts-in-src.js.map +1 -1
- package/src/core/runner.d.ts +10 -19
- package/src/core/runner.js +24 -622
- package/src/core/runner.js.map +1 -1
- package/src/index.d.ts +2 -15
- package/src/index.js +4 -54
- package/src/index.js.map +1 -1
- package/openclaw.plugin.json +0 -15
- package/src/adapters/agent-adapters.d.ts +0 -13
- package/src/adapters/agent-adapters.js +0 -23
- package/src/adapters/agent-adapters.js.map +0 -1
- package/src/adapters/agent-payload.d.ts +0 -48
- package/src/adapters/agent-payload.js +0 -30
- package/src/adapters/agent-payload.js.map +0 -1
- package/src/adapters/agent-response.d.ts +0 -5
- package/src/adapters/agent-response.js +0 -86
- package/src/adapters/agent-response.js.map +0 -1
- package/src/adapters/claude-code-adapter.d.ts +0 -26
- package/src/adapters/claude-code-adapter.js +0 -69
- package/src/adapters/claude-code-adapter.js.map +0 -1
- package/src/adapters/codex-adapter.d.ts +0 -19
- package/src/adapters/codex-adapter.js +0 -48
- package/src/adapters/codex-adapter.js.map +0 -1
- package/src/adapters/codex-subagent-guard.d.ts +0 -45
- package/src/adapters/codex-subagent-guard.js +0 -88
- package/src/adapters/codex-subagent-guard.js.map +0 -1
- package/src/adapters/detect-ai.d.ts +0 -70
- package/src/adapters/detect-ai.js +0 -82
- package/src/adapters/detect-ai.js.map +0 -1
- package/src/adapters/guards-hook.d.ts +0 -3
- package/src/adapters/guards-hook.js +0 -30
- package/src/adapters/guards-hook.js.map +0 -1
- package/src/adapters/openclaw-plugin.d.ts +0 -14
- package/src/adapters/openclaw-plugin.js +0 -87
- package/src/adapters/openclaw-plugin.js.map +0 -1
- package/src/adapters/review-identity-stamper.d.ts +0 -20
- package/src/adapters/review-identity-stamper.js +0 -34
- package/src/adapters/review-identity-stamper.js.map +0 -1
- package/src/bin/codex-trust.d.ts +0 -105
- package/src/bin/codex-trust.js +0 -205
- package/src/bin/codex-trust.js.map +0 -1
- package/src/bin/dev-hook-install.d.ts +0 -1
- package/src/bin/dev-hook-install.js +0 -82
- package/src/bin/dev-hook-install.js.map +0 -1
- package/src/bin/dev-hook-uninstall.d.ts +0 -1
- package/src/bin/dev-hook-uninstall.js +0 -45
- package/src/bin/dev-hook-uninstall.js.map +0 -1
- package/src/bin/hook-registration.d.ts +0 -429
- package/src/bin/hook-registration.js +0 -661
- package/src/bin/hook-registration.js.map +0 -1
- package/src/bin/install-entry.d.ts +0 -19
- package/src/bin/install-entry.js +0 -128
- package/src/bin/install-entry.js.map +0 -1
- package/src/bin/l0-allowlist.d.ts +0 -49
- package/src/bin/l0-allowlist.js +0 -528
- package/src/bin/l0-allowlist.js.map +0 -1
- package/src/bin/l0-codex-read.d.ts +0 -21
- package/src/bin/l0-codex-read.js +0 -109
- package/src/bin/l0-codex-read.js.map +0 -1
- package/src/bin/l0-decide.d.ts +0 -50
- package/src/bin/l0-decide.js +0 -103
- package/src/bin/l0-decide.js.map +0 -1
- package/src/bin/l0-entry.d.ts +0 -103
- package/src/bin/l0-entry.js +0 -98
- package/src/bin/l0-entry.js.map +0 -1
- package/src/bin/l0-ignored-tools.d.ts +0 -38
- package/src/bin/l0-ignored-tools.js +0 -44
- package/src/bin/l0-ignored-tools.js.map +0 -1
- package/src/bin/managed-env.d.ts +0 -46
- package/src/bin/managed-env.js +0 -50
- package/src/bin/managed-env.js.map +0 -1
- package/src/bin/neighbour-hooks.d.ts +0 -42
- package/src/bin/neighbour-hooks.js +0 -177
- package/src/bin/neighbour-hooks.js.map +0 -1
- package/src/bin/reviewer-agent.d.ts +0 -19
- package/src/bin/reviewer-agent.js +0 -135
- package/src/bin/reviewer-agent.js.map +0 -1
- package/src/bin/settings-shape.d.ts +0 -37
- package/src/bin/settings-shape.js +0 -17
- package/src/bin/settings-shape.js.map +0 -1
- package/src/bin/setup-config.d.ts +0 -19
- package/src/bin/setup-config.js +0 -370
- package/src/bin/setup-config.js.map +0 -1
- package/src/bin/setup.d.ts +0 -78
- package/src/bin/setup.js +0 -400
- package/src/bin/setup.js.map +0 -1
- package/src/bin/shim-audit-log.d.ts +0 -119
- package/src/bin/shim-audit-log.js +0 -286
- package/src/bin/shim-audit-log.js.map +0 -1
- package/src/bin/shim-deny-reason.d.ts +0 -1
- package/src/bin/shim-deny-reason.js +0 -244
- package/src/bin/shim-deny-reason.js.map +0 -1
- package/src/bin/shim-drift-fix.d.ts +0 -1
- package/src/bin/shim-drift-fix.js +0 -72
- package/src/bin/shim-drift-fix.js.map +0 -1
- package/src/bin/shim-testkit.d.ts +0 -107
- package/src/bin/shim-testkit.js +0 -197
- package/src/bin/shim-testkit.js.map +0 -1
- package/src/bin/shim-version-drift.d.ts +0 -1
- package/src/bin/shim-version-drift.js +0 -164
- package/src/bin/shim-version-drift.js.map +0 -1
- package/src/bin/shim.d.ts +0 -16
- package/src/bin/shim.js +0 -636
- package/src/bin/shim.js.map +0 -1
- package/src/bin/upgrade-shim.d.ts +0 -18
- package/src/bin/upgrade-shim.js +0 -283
- package/src/bin/upgrade-shim.js.map +0 -1
- package/src/core/ai-type-context.d.ts +0 -36
- package/src/core/ai-type-context.js +0 -45
- package/src/core/ai-type-context.js.map +0 -1
- package/src/core/apply-patch-parse.d.ts +0 -36
- package/src/core/apply-patch-parse.js +0 -154
- package/src/core/apply-patch-parse.js.map +0 -1
- package/src/core/build-context.d.ts +0 -10
- package/src/core/build-context.js +0 -66
- package/src/core/build-context.js.map +0 -1
- package/src/core/command-scan.d.ts +0 -122
- package/src/core/command-scan.js +0 -282
- package/src/core/command-scan.js.map +0 -1
- package/src/core/custom-rule-adapter.d.ts +0 -22
- package/src/core/custom-rule-adapter.js +0 -50
- package/src/core/custom-rule-adapter.js.map +0 -1
- package/src/core/decision-log.d.ts +0 -190
- package/src/core/decision-log.js +0 -406
- package/src/core/decision-log.js.map +0 -1
- package/src/core/delete-scoped-rules.d.ts +0 -8
- package/src/core/delete-scoped-rules.js +0 -31
- package/src/core/delete-scoped-rules.js.map +0 -1
- package/src/core/disable-directives.d.ts +0 -8
- package/src/core/disable-directives.js +0 -80
- package/src/core/disable-directives.js.map +0 -1
- package/src/core/effective-tree.d.ts +0 -204
- package/src/core/effective-tree.js +0 -277
- package/src/core/effective-tree.js.map +0 -1
- package/src/core/excluded-path-escape.d.ts +0 -101
- package/src/core/excluded-path-escape.js +0 -236
- package/src/core/excluded-path-escape.js.map +0 -1
- package/src/core/excluded-paths.d.ts +0 -23
- package/src/core/excluded-paths.js +0 -54
- package/src/core/excluded-paths.js.map +0 -1
- package/src/core/fix-hint.d.ts +0 -40
- package/src/core/fix-hint.js +0 -53
- package/src/core/fix-hint.js.map +0 -1
- package/src/core/force-to-root.d.ts +0 -32
- package/src/core/force-to-root.js +0 -60
- package/src/core/force-to-root.js.map +0 -1
- package/src/core/guard-index-doc.d.ts +0 -63
- package/src/core/guard-index-doc.js +0 -172
- package/src/core/guard-index-doc.js.map +0 -1
- package/src/core/instruct-ai-writer.d.ts +0 -1
- package/src/core/instruct-ai-writer.js +0 -6
- package/src/core/instruct-ai-writer.js.map +0 -1
- package/src/core/l0-fault-codes.d.ts +0 -85
- package/src/core/l0-fault-codes.js +0 -121
- package/src/core/l0-fault-codes.js.map +0 -1
- package/src/core/l0-matrix.d.ts +0 -114
- package/src/core/l0-matrix.js +0 -416
- package/src/core/l0-matrix.js.map +0 -1
- package/src/core/l0-tooling-doc.d.ts +0 -45
- package/src/core/l0-tooling-doc.js +0 -258
- package/src/core/l0-tooling-doc.js.map +0 -1
- package/src/core/l1-doc.d.ts +0 -7
- package/src/core/l1-doc.js +0 -340
- package/src/core/l1-doc.js.map +0 -1
- package/src/core/l1-matrix-doc.d.ts +0 -31
- package/src/core/l1-matrix-doc.js +0 -111
- package/src/core/l1-matrix-doc.js.map +0 -1
- package/src/core/l1-rows.d.ts +0 -167
- package/src/core/l1-rows.js +0 -262
- package/src/core/l1-rows.js.map +0 -1
- package/src/core/l2-doc.d.ts +0 -7
- package/src/core/l2-doc.js +0 -385
- package/src/core/l2-doc.js.map +0 -1
- package/src/core/l2-matrix-doc.d.ts +0 -23
- package/src/core/l2-matrix-doc.js +0 -72
- package/src/core/l2-matrix-doc.js.map +0 -1
- package/src/core/l2-row.d.ts +0 -54
- package/src/core/l2-row.js +0 -75
- package/src/core/l2-row.js.map +0 -1
- package/src/core/l2-rows.d.ts +0 -56
- package/src/core/l2-rows.js +0 -272
- package/src/core/l2-rows.js.map +0 -1
- package/src/core/load-config.d.ts +0 -1
- package/src/core/load-config.js +0 -9
- package/src/core/load-config.js.map +0 -1
- package/src/core/log-stream.d.ts +0 -117
- package/src/core/log-stream.js +0 -156
- package/src/core/log-stream.js.map +0 -1
- package/src/core/log-streams.d.ts +0 -48
- package/src/core/log-streams.js +0 -55
- package/src/core/log-streams.js.map +0 -1
- package/src/core/log-target.d.ts +0 -21
- package/src/core/log-target.js +0 -29
- package/src/core/log-target.js.map +0 -1
- package/src/core/main-sync-log.d.ts +0 -16
- package/src/core/main-sync-log.js +0 -105
- package/src/core/main-sync-log.js.map +0 -1
- package/src/core/main-sync-refresh.d.ts +0 -39
- package/src/core/main-sync-refresh.js +0 -96
- package/src/core/main-sync-refresh.js.map +0 -1
- package/src/core/main-sync-timeout.d.ts +0 -32
- package/src/core/main-sync-timeout.js +0 -94
- package/src/core/main-sync-timeout.js.map +0 -1
- package/src/core/matrix-cures.d.ts +0 -12
- package/src/core/matrix-cures.js +0 -56
- package/src/core/matrix-cures.js.map +0 -1
- package/src/core/missing-directory.d.ts +0 -38
- package/src/core/missing-directory.js +0 -66
- package/src/core/missing-directory.js.map +0 -1
- package/src/core/read-only-inspection.d.ts +0 -34
- package/src/core/read-only-inspection.js +0 -88
- package/src/core/read-only-inspection.js.map +0 -1
- package/src/core/rejection-log.d.ts +0 -9
- package/src/core/rejection-log.js +0 -258
- package/src/core/rejection-log.js.map +0 -1
- package/src/core/report.d.ts +0 -21
- package/src/core/report.js +0 -73
- package/src/core/report.js.map +0 -1
- package/src/core/rule-base.d.ts +0 -39
- package/src/core/rule-base.js +0 -36
- package/src/core/rule-base.js.map +0 -1
- package/src/core/rules/branch-creation-guard.d.ts +0 -113
- package/src/core/rules/branch-creation-guard.js +0 -422
- package/src/core/rules/branch-creation-guard.js.map +0 -1
- package/src/core/rules/branch-switch-scan.d.ts +0 -43
- package/src/core/rules/branch-switch-scan.js +0 -132
- package/src/core/rules/branch-switch-scan.js.map +0 -1
- package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
- package/src/core/rules/build-output-pipe-guard.js +0 -120
- package/src/core/rules/build-output-pipe-guard.js.map +0 -1
- package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
- package/src/core/rules/build-output-pipe-scan.js +0 -84
- package/src/core/rules/build-output-pipe-scan.js.map +0 -1
- package/src/core/rules/cap-remedies.d.ts +0 -39
- package/src/core/rules/cap-remedies.js +0 -59
- package/src/core/rules/cap-remedies.js.map +0 -1
- package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
- package/src/core/rules/commit-message-substitution-guard.js +0 -134
- package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
- package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
- package/src/core/rules/commit-message-substitution-scan.js +0 -145
- package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
- package/src/core/rules/content-read-scan.d.ts +0 -76
- package/src/core/rules/content-read-scan.js +0 -176
- package/src/core/rules/content-read-scan.js.map +0 -1
- package/src/core/rules/cure-prefix-scan.d.ts +0 -64
- package/src/core/rules/cure-prefix-scan.js +0 -133
- package/src/core/rules/cure-prefix-scan.js.map +0 -1
- package/src/core/rules/feature-branch-guard.d.ts +0 -121
- package/src/core/rules/feature-branch-guard.js +0 -326
- package/src/core/rules/feature-branch-guard.js.map +0 -1
- package/src/core/rules/judged-tree.d.ts +0 -66
- package/src/core/rules/judged-tree.js +0 -97
- package/src/core/rules/judged-tree.js.map +0 -1
- package/src/core/rules/main-freshness.d.ts +0 -37
- package/src/core/rules/main-freshness.js +0 -61
- package/src/core/rules/main-freshness.js.map +0 -1
- package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
- package/src/core/rules/merge-in-progress-guard.js +0 -122
- package/src/core/rules/merge-in-progress-guard.js.map +0 -1
- package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
- package/src/core/rules/merged-branch-bash-guard.js +0 -170
- package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
- package/src/core/rules/merged-branch-message.d.ts +0 -59
- package/src/core/rules/merged-branch-message.js +0 -137
- package/src/core/rules/merged-branch-message.js.map +0 -1
- package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
- package/src/core/rules/pr-creation-or-push-guard.js +0 -146
- package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
- package/src/core/rules/pr-merge-guard.d.ts +0 -36
- package/src/core/rules/pr-merge-guard.js +0 -86
- package/src/core/rules/pr-merge-guard.js.map +0 -1
- package/src/core/rules/read-stale-guard.d.ts +0 -136
- package/src/core/rules/read-stale-guard.js +0 -326
- package/src/core/rules/read-stale-guard.js.map +0 -1
- package/src/core/rules/recovery-allowlist.d.ts +0 -49
- package/src/core/rules/recovery-allowlist.js +0 -187
- package/src/core/rules/recovery-allowlist.js.map +0 -1
- package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
- package/src/core/rules/redirect-how-to-merge-main.js +0 -157
- package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
- package/src/core/rules/shell-segment-scan.d.ts +0 -64
- package/src/core/rules/shell-segment-scan.js +0 -88
- package/src/core/rules/shell-segment-scan.js.map +0 -1
- package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
- package/src/core/rules/stale-main-bash-guard.js +0 -361
- package/src/core/rules/stale-main-bash-guard.js.map +0 -1
- package/src/core/rules/stale-main-message.d.ts +0 -62
- package/src/core/rules/stale-main-message.js +0 -102
- package/src/core/rules/stale-main-message.js.map +0 -1
- package/src/core/rules/tree-recovery.d.ts +0 -92
- package/src/core/rules/tree-recovery.js +0 -165
- package/src/core/rules/tree-recovery.js.map +0 -1
- package/src/core/rules/wait-spin-guard.d.ts +0 -128
- package/src/core/rules/wait-spin-guard.js +0 -211
- package/src/core/rules/wait-spin-guard.js.map +0 -1
- package/src/core/rules/wait-spin-scan.d.ts +0 -118
- package/src/core/rules/wait-spin-scan.js +0 -203
- package/src/core/rules/wait-spin-scan.js.map +0 -1
- package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
- package/src/core/rules/whole-repo-build-guard.js +0 -257
- package/src/core/rules/whole-repo-build-guard.js.map +0 -1
- package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
- package/src/core/rules/whole-repo-build-scan.js +0 -198
- package/src/core/rules/whole-repo-build-scan.js.map +0 -1
- package/src/core/session-call-history.d.ts +0 -44
- package/src/core/session-call-history.js +0 -79
- package/src/core/session-call-history.js.map +0 -1
- package/src/core/shell-read-parity.d.ts +0 -56
- package/src/core/shell-read-parity.js +0 -155
- package/src/core/shell-read-parity.js.map +0 -1
- package/src/core/strip-ts-noise.d.ts +0 -1
- package/src/core/strip-ts-noise.js +0 -185
- package/src/core/strip-ts-noise.js.map +0 -1
- package/src/core/sync-main.d.ts +0 -46
- package/src/core/sync-main.js +0 -175
- package/src/core/sync-main.js.map +0 -1
- package/src/core/target-tree.d.ts +0 -84
- package/src/core/target-tree.js +0 -148
- package/src/core/target-tree.js.map +0 -1
- package/src/core/to-error.d.ts +0 -5
- package/src/core/to-error.js +0 -37
- package/src/core/to-error.js.map +0 -1
- package/src/core/types.d.ts +0 -152
- package/src/core/types.js +0 -200
- package/src/core/types.js.map +0 -1
- package/src/core/version-sync.d.ts +0 -219
- package/src/core/version-sync.js +0 -558
- package/src/core/version-sync.js.map +0 -1
- package/src/core/webpieces-versions.d.ts +0 -98
- package/src/core/webpieces-versions.js +0 -206
- package/src/core/webpieces-versions.js.map +0 -1
- package/templates/ai-hook.sh +0 -497
- package/templates/claude-settings-hook.json +0 -28
- package/templates/webpieces-reviewer.md +0 -60
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MainFreshness = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
/**
|
|
6
|
-
* The two primitives every "is local `main` stale?" ladder is built out of: the ANCESTRY test, and the
|
|
7
|
-
* one-line cache summary the decision log records beside the verdict.
|
|
8
|
-
*
|
|
9
|
-
* ONE implementation, because two guards now ask the same question of the same cache —
|
|
10
|
-
* `read-stale-guard` for the Read tool (rows 6/7) and `stale-main-bash-guard` for Bash. The ladders
|
|
11
|
-
* themselves deliberately stay in the guards: each exit's `reason` string is a LITERAL there, which is
|
|
12
|
-
* what `l2-matrix.spec.ts` scrapes to prove every exit maps to a row. What must not be written twice is
|
|
13
|
-
* the predicate — a second copy of the ancestry rule is exactly how the two halves of one row start
|
|
14
|
-
* disagreeing about whether a pull has landed.
|
|
15
|
-
*/
|
|
16
|
-
class MainFreshness {
|
|
17
|
-
/** Null means the async cache predates the count or could not establish it: callers fail open. */
|
|
18
|
-
isWithinAllowedDrift(status, maxCommitsBehind) {
|
|
19
|
-
const behind = status.commitsBehind;
|
|
20
|
-
if (behind === null || !Number.isInteger(behind) || behind < 0)
|
|
21
|
-
return null;
|
|
22
|
-
return behind <= maxCommitsBehind;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Is `commit` an ancestor of (i.e. already contained in) HEAD? Local-only and fast — no network.
|
|
26
|
-
*
|
|
27
|
-
* ANCESTRY, NOT HASH EQUALITY, and this is the single most important line in the freshness story.
|
|
28
|
-
* The cached `originMain` is written by the detached refresher and is arbitrarily old, so
|
|
29
|
-
* `local !== origin` stays true for a while AFTER a successful pull — which would spin the agent
|
|
30
|
-
* forever against a hash nobody can reach. Asking "does local main already CONTAIN the cached
|
|
31
|
-
* origin/main?" flips the instant the pull lands, with no refresher round-trip.
|
|
32
|
-
*
|
|
33
|
-
* spawnSync, not execSync, precisely because the EXIT CODE is the answer and three outcomes must be
|
|
34
|
-
* told apart: 0 = ancestor (up to date), 1 = cleanly NOT an ancestor (genuinely behind), anything
|
|
35
|
-
* else = git could not answer (bad/pruned object, not a repo) which must fail OPEN. execSync
|
|
36
|
-
* collapses 1 and "git broke" into the same thrown Error, so it cannot make that call. The
|
|
37
|
-
* arg-array form also means the commit hash is never parsed by a shell.
|
|
38
|
-
*/
|
|
39
|
-
containsOriginMain(workspaceRoot, commit) {
|
|
40
|
-
const result = (0, child_process_1.spawnSync)('git', ['merge-base', '--is-ancestor', commit, 'HEAD'], {
|
|
41
|
-
cwd: workspaceRoot,
|
|
42
|
-
encoding: 'utf8',
|
|
43
|
-
});
|
|
44
|
-
if (result.status === 0)
|
|
45
|
-
return true;
|
|
46
|
-
if (result.status === 1)
|
|
47
|
-
return false;
|
|
48
|
-
return true; // unknown/failed → treat as "contained" so the guard allows
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The async-written cache that drove this decision, as one log field — so a wrong allow/block is
|
|
52
|
-
* traceable to the exact (possibly stale) `main-sync-status.json` that produced it.
|
|
53
|
-
*/
|
|
54
|
-
summarize(status) {
|
|
55
|
-
const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';
|
|
56
|
-
const behind = status.commitsBehind === null ? '?' : String(status.commitsBehind);
|
|
57
|
-
return `cache=${status.branch} localMain=${status.localMain.slice(0, 8)} originMain=${status.originMain.slice(0, 8)} behind=${behind} merged=${merged} ts=${status.timestamp}`;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.MainFreshness = MainFreshness;
|
|
61
|
-
//# sourceMappingURL=main-freshness.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main-freshness.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/main-freshness.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAI1C;;;;;;;;;;GAUG;AACH,MAAa,aAAa;IACtB,kGAAkG;IAClG,oBAAoB,CAAC,MAAsB,EAAE,gBAAwB;QACjE,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;QACpC,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC5E,OAAO,MAAM,IAAI,gBAAgB,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,aAAqB,EAAE,MAAc;QACpD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;YAC7E,GAAG,EAAE,aAAa;YAClB,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACrC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,OAAO,IAAI,CAAC,CAAC,4DAA4D;IAC7E,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAAsB;QAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1G,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAClF,OAAO,SAAS,MAAM,CAAC,MAAM,cAAc,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,eAAe,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,WAAW,MAAM,WAAW,MAAM,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC;IACnL,CAAC;CACJ;AA1CD,sCA0CC","sourcesContent":["import { spawnSync } from 'child_process';\n\nimport { MainSyncStatus } from '@webpieces/repo-workflow-core';\n\n/**\n * The two primitives every \"is local `main` stale?\" ladder is built out of: the ANCESTRY test, and the\n * one-line cache summary the decision log records beside the verdict.\n *\n * ONE implementation, because two guards now ask the same question of the same cache —\n * `read-stale-guard` for the Read tool (rows 6/7) and `stale-main-bash-guard` for Bash. The ladders\n * themselves deliberately stay in the guards: each exit's `reason` string is a LITERAL there, which is\n * what `l2-matrix.spec.ts` scrapes to prove every exit maps to a row. What must not be written twice is\n * the predicate — a second copy of the ancestry rule is exactly how the two halves of one row start\n * disagreeing about whether a pull has landed.\n */\nexport class MainFreshness {\n /** Null means the async cache predates the count or could not establish it: callers fail open. */\n isWithinAllowedDrift(status: MainSyncStatus, maxCommitsBehind: number): boolean | null {\n const behind = status.commitsBehind;\n if (behind === null || !Number.isInteger(behind) || behind < 0) return null;\n return behind <= maxCommitsBehind;\n }\n\n /**\n * Is `commit` an ancestor of (i.e. already contained in) HEAD? Local-only and fast — no network.\n *\n * ANCESTRY, NOT HASH EQUALITY, and this is the single most important line in the freshness story.\n * The cached `originMain` is written by the detached refresher and is arbitrarily old, so\n * `local !== origin` stays true for a while AFTER a successful pull — which would spin the agent\n * forever against a hash nobody can reach. Asking \"does local main already CONTAIN the cached\n * origin/main?\" flips the instant the pull lands, with no refresher round-trip.\n *\n * spawnSync, not execSync, precisely because the EXIT CODE is the answer and three outcomes must be\n * told apart: 0 = ancestor (up to date), 1 = cleanly NOT an ancestor (genuinely behind), anything\n * else = git could not answer (bad/pruned object, not a repo) which must fail OPEN. execSync\n * collapses 1 and \"git broke\" into the same thrown Error, so it cannot make that call. The\n * arg-array form also means the commit hash is never parsed by a shell.\n */\n containsOriginMain(workspaceRoot: string, commit: string): boolean {\n const result = spawnSync('git', ['merge-base', '--is-ancestor', commit, 'HEAD'], {\n cwd: workspaceRoot,\n encoding: 'utf8',\n });\n if (result.status === 0) return true;\n if (result.status === 1) return false;\n return true; // unknown/failed → treat as \"contained\" so the guard allows\n }\n\n /**\n * The async-written cache that drove this decision, as one log field — so a wrong allow/block is\n * traceable to the exact (possibly stale) `main-sync-status.json` that produced it.\n */\n summarize(status: MainSyncStatus): string {\n const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';\n const behind = status.commitsBehind === null ? '?' : String(status.commitsBehind);\n return `cache=${status.branch} localMain=${status.localMain.slice(0, 8)} originMain=${status.originMain.slice(0, 8)} behind=${behind} merged=${merged} ts=${status.timestamp}`;\n }\n}\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PrLifecycleGuardConfig } from '@webpieces/rules-config';
|
|
2
|
-
import type { BashContext, Violation } from '../types';
|
|
3
|
-
import { BashRuleBase } from '../rule-base';
|
|
4
|
-
import { FixHint } from '../fix-hint';
|
|
5
|
-
export declare class MergeInProgressGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {
|
|
6
|
-
/**
|
|
7
|
-
* The gated command this guard names, handed in by the LOADER from `commands.guardHints
|
|
8
|
-
* .mergeInProgress` (already defaulted there). A constructor parameter, not a config field: the
|
|
9
|
-
* field `merge-in-progress-guard.mergeCompleteCommand` was a SECOND SPELLING that beat the commands
|
|
10
|
-
* section, and the loader's name-keyed injection that fed it could miss a rename silently.
|
|
11
|
-
*/
|
|
12
|
-
private readonly mergeCompleteCommand;
|
|
13
|
-
constructor(config: PrLifecycleGuardConfig, mergeCompleteCommand: string);
|
|
14
|
-
readonly description = "Block commit/push/merge/PR while a 3-point merge marker is unvalidated, forcing the merge-complete command.";
|
|
15
|
-
get fixHint(): FixHint;
|
|
16
|
-
check(ctx: BashContext): readonly Violation[];
|
|
17
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MergeInProgressGuardRule = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
8
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
9
|
-
const types_1 = require("../types");
|
|
10
|
-
const rule_base_1 = require("../rule-base");
|
|
11
|
-
const fix_hint_1 = require("../fix-hint");
|
|
12
|
-
const command_scan_1 = require("../command-scan");
|
|
13
|
-
// The ENTIRE enforcement surface of this guard, declared up here because the fixHint RENDERS ITSELF
|
|
14
|
-
// from these two lists (see `blockedCommandList`). The hint used to hand-write "do not run other
|
|
15
|
-
// commands" — an unbounded claim that forbade the reads, the `git add`, the build and the tests that
|
|
16
|
-
// finishing a merge actually requires, and that survived every edit to these lists. It was also wrapped
|
|
17
|
-
// in an "Add to memory" directive, so it outlived the session that read it. Generating the sentence
|
|
18
|
-
// from the code is what stops the two drifting apart again.
|
|
19
|
-
const BLOCKED_GIT_SUBCOMMANDS = ['commit', 'push', 'merge', 'rebase'];
|
|
20
|
-
const BLOCKED_GH_PR_SUBCOMMANDS = ['create', 'edit', 'merge'];
|
|
21
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
22
|
-
function blockedCommandList() {
|
|
23
|
-
return BLOCKED_GIT_SUBCOMMANDS.map((sub) => `\`git ${sub}\``).join(', ')
|
|
24
|
-
+ `, and \`gh pr ${BLOCKED_GH_PR_SUBCOMMANDS.join('|')}\``;
|
|
25
|
-
}
|
|
26
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
27
|
-
function fixHintFor(mergeCompleteCommand) {
|
|
28
|
-
return new fix_hint_1.FixHint('A merge is in progress and not yet validated — this command is blocked.', 'You started a merge but never called the finish-merge command, so a 3-point merge is still in progress.\n'
|
|
29
|
-
+ `Blocked until the merge is validated: ${blockedCommandList()}. That is the whole list;\n`
|
|
30
|
-
+ 'the finish command below does the commit for you.\n'
|
|
31
|
-
+ 'EXPECTED of you right now, and NOT blocked: read the conflicted files, edit them until every\n'
|
|
32
|
-
+ 'conflict marker is gone, `git add` each file you resolve, write the merge explanation for each\n'
|
|
33
|
-
+ 'one, and run the build and the tests. Finishing a merge requires all of those.\n'
|
|
34
|
-
+ 'Then run:\n'
|
|
35
|
-
+ ` ${mergeCompleteCommand}\n`
|
|
36
|
-
+ 'That scans for leftover conflict markers and runs the build; only when green does it commit,\n'
|
|
37
|
-
+ 'unblock commit/push/PR, render the dashboard, and create/update the PR.\n'
|
|
38
|
-
+ 'Add to memory: finish a started merge before beginning other work.');
|
|
39
|
-
}
|
|
40
|
-
// Returns the path of the first UNVALIDATED merge marker found, or null. We detect validation
|
|
41
|
-
// by a raw substring (no JSON.parse) so a malformed marker can never crash the guard.
|
|
42
|
-
/**
|
|
43
|
-
* DEPTH-BOUNDED SCAN, not a fixed level. The marker's home has moved twice: it was
|
|
44
|
-
* `merge-info/<feature>/`, then `merge-info/<feature>/merge-<n>/` once each sync got its own run dir,
|
|
45
|
-
* and is now `merge-info/staged/<feature>/merge-<n>/` since merge-info split into staged/merged. This
|
|
46
|
-
* guard was still looking only at the FIRST layout's depth, so it silently found nothing and stopped
|
|
47
|
-
* blocking — a guard failing open without saying so. A bounded walk covers every layout, legacy
|
|
48
|
-
* included, and stops long before it could descend into anything large.
|
|
49
|
-
*/
|
|
50
|
-
const MARKER_SCAN_MAX_DEPTH = 3;
|
|
51
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
52
|
-
function findMarkerUnder(dir, depth) {
|
|
53
|
-
if (depth < 0 || !fs.existsSync(dir))
|
|
54
|
-
return null;
|
|
55
|
-
const marker = path.join(dir, rules_config_1.MERGE_IN_PROGRESS_FILE);
|
|
56
|
-
if (fs.existsSync(marker)) {
|
|
57
|
-
const raw = fs.readFileSync(marker, 'utf8');
|
|
58
|
-
if (!/"validated"\s*:\s*true/.test(raw))
|
|
59
|
-
return marker;
|
|
60
|
-
}
|
|
61
|
-
if (depth === 0)
|
|
62
|
-
return null;
|
|
63
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
64
|
-
if (!entry.isDirectory())
|
|
65
|
-
continue;
|
|
66
|
-
const found = findMarkerUnder(path.join(dir, entry.name), depth - 1);
|
|
67
|
-
if (found !== null)
|
|
68
|
-
return found;
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
73
|
-
function findUnvalidatedMerge(workspaceRoot) {
|
|
74
|
-
// LOCAL scope: the merge this guard blocks on is the one THIS worktree started. Another
|
|
75
|
-
// worktree's in-flight merge must not block commits here — that was never the intent, and under a
|
|
76
|
-
// shared merge-info dir it would be the behaviour.
|
|
77
|
-
return findMarkerUnder(tooling_common_1.dotWebpieces.localFile(workspaceRoot, rules_config_1.MERGE_INFO_DIR), MARKER_SCAN_MAX_DEPTH);
|
|
78
|
-
}
|
|
79
|
-
const SCANNER = new command_scan_1.CommandScanner();
|
|
80
|
-
// Built from BLOCKED_GH_PR_SUBCOMMANDS so the enforcement and the sentence the fixHint prints can
|
|
81
|
-
// never name different commands.
|
|
82
|
-
const BLOCKED_GH_PR_PATTERN = new RegExp(`\\bgh\\s+pr\\s+(${BLOCKED_GH_PR_SUBCOMMANDS.join('|')})\\b`);
|
|
83
|
-
// Operations that would let an agent route around the merge gate.
|
|
84
|
-
//
|
|
85
|
-
// Routed through CommandScanner rather than `/\bgit\s+merge\b/`: that pattern matches the read-only
|
|
86
|
-
// `git merge-base origin/main HEAD` (`\b` sits between `e` and `-`), which appears in this repo's own
|
|
87
|
-
// documented build command — so an in-progress merge used to block a harmless diff-scope lookup.
|
|
88
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
89
|
-
function isBlockedDuringMerge(cmd) {
|
|
90
|
-
return SCANNER.commandInvokesAnyGit(cmd, BLOCKED_GIT_SUBCOMMANDS)
|
|
91
|
-
|| BLOCKED_GH_PR_PATTERN.test(cmd);
|
|
92
|
-
}
|
|
93
|
-
function truncate(s) {
|
|
94
|
-
const MAX = 120;
|
|
95
|
-
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
96
|
-
}
|
|
97
|
-
class MergeInProgressGuardRule extends rule_base_1.BashRuleBase {
|
|
98
|
-
/**
|
|
99
|
-
* The gated command this guard names, handed in by the LOADER from `commands.guardHints
|
|
100
|
-
* .mergeInProgress` (already defaulted there). A constructor parameter, not a config field: the
|
|
101
|
-
* field `merge-in-progress-guard.mergeCompleteCommand` was a SECOND SPELLING that beat the commands
|
|
102
|
-
* section, and the loader's name-keyed injection that fed it could miss a rename silently.
|
|
103
|
-
*/
|
|
104
|
-
mergeCompleteCommand;
|
|
105
|
-
constructor(config, mergeCompleteCommand) {
|
|
106
|
-
super(config, 'merge-in-progress-guard', rules_config_1.PR_LIFECYCLE_GUARD_KEY);
|
|
107
|
-
this.mergeCompleteCommand = mergeCompleteCommand;
|
|
108
|
-
}
|
|
109
|
-
description = 'Block commit/push/merge/PR while a 3-point merge marker is unvalidated, forcing the merge-complete command.';
|
|
110
|
-
get fixHint() { return fixHintFor(this.mergeCompleteCommand); }
|
|
111
|
-
check(ctx) {
|
|
112
|
-
if (!isBlockedDuringMerge(ctx.commandCode))
|
|
113
|
-
return [];
|
|
114
|
-
const marker = findUnvalidatedMerge(ctx.workspaceRoot);
|
|
115
|
-
if (!marker)
|
|
116
|
-
return [];
|
|
117
|
-
return [new types_1.Violation(1, truncate(ctx.command), 'A merge is in progress and not yet validated — this command is blocked.\n'
|
|
118
|
-
+ `Marker: ${marker}`)];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.MergeInProgressGuardRule = MergeInProgressGuardRule;
|
|
122
|
-
//# sourceMappingURL=merge-in-progress-guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-in-progress-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/merge-in-progress-guard.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAE7B,8DAAyD;AACzD,0DAAiI;AAGjI,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAsC;AACtC,kDAAiD;AAGjD,oGAAoG;AACpG,iGAAiG;AACjG,qGAAqG;AACrG,wGAAwG;AACxG,oGAAoG;AACpG,4DAA4D;AAC5D,MAAM,uBAAuB,GAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACzF,MAAM,yBAAyB,GAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjF,0GAA0G;AAC1G,SAAS,kBAAkB;IACvB,OAAO,uBAAuB,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;UAC1E,iBAAiB,yBA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AAC;IACrD,CAAC;IAEQ,WAAW,GAAG,6GAA6G,CAAC;IACrI,IAAI,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAExE,KAAK,CAAC,GAAgB;QAClB,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC;YAAE,OAAO,EAAE,CAAC;QACtD,MAAM,MAAM,GAAG,oBAAoB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,iBAAC,CACT,CAAC,EACD,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EACrB,2EAA2E;kBACzE,WAAW,MAAM,EAAE,CACxB,CAAC,CAAC;IACP,CAAC;CACJ;AA5BD,4DA4BC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\nimport { MERGE_INFO_DIR, MERGE_IN_PROGRESS_FILE, PrLifecycleGuardConfig, PR_LIFECYCLE_GUARD_KEY } from '@webpieces/rules-config';\n\nimport type { BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { BashRuleBase } from '../rule-base';\nimport { FixHint } from '../fix-hint';\nimport { CommandScanner } from '../command-scan';\n\n\n// The ENTIRE enforcement surface of this guard, declared up here because the fixHint RENDERS ITSELF\n// from these two lists (see `blockedCommandList`). The hint used to hand-write \"do not run other\n// commands\" — an unbounded claim that forbade the reads, the `git add`, the build and the tests that\n// finishing a merge actually requires, and that survived every edit to these lists. It was also wrapped\n// in an \"Add to memory\" directive, so it outlived the session that read it. Generating the sentence\n// from the code is what stops the two drifting apart again.\nconst BLOCKED_GIT_SUBCOMMANDS: readonly string[] = ['commit', 'push', 'merge', 'rebase'];\nconst BLOCKED_GH_PR_SUBCOMMANDS: readonly string[] = ['create', 'edit', 'merge'];\n\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction blockedCommandList(): string {\n return BLOCKED_GIT_SUBCOMMANDS.map((sub: string) => `\\`git ${sub}\\``).join(', ')\n + `, and \\`gh pr ${BLOCKED_GH_PR_SUBCOMMANDS.join('|')}\\``;\n}\n\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction fixHintFor(mergeCompleteCommand: string): FixHint {\n return new FixHint(\n 'A merge is in progress and not yet validated — this command is blocked.',\n 'You started a merge but never called the finish-merge command, so a 3-point merge is still in progress.\\n'\n + `Blocked until the merge is validated: ${blockedCommandList()}. That is the whole list;\\n`\n + 'the finish command below does the commit for you.\\n'\n + 'EXPECTED of you right now, and NOT blocked: read the conflicted files, edit them until every\\n'\n + 'conflict marker is gone, `git add` each file you resolve, write the merge explanation for each\\n'\n + 'one, and run the build and the tests. Finishing a merge requires all of those.\\n'\n + 'Then run:\\n'\n + ` ${mergeCompleteCommand}\\n`\n + 'That scans for leftover conflict markers and runs the build; only when green does it commit,\\n'\n + 'unblock commit/push/PR, render the dashboard, and create/update the PR.\\n'\n + 'Add to memory: finish a started merge before beginning other work.',\n );\n}\n\n// Returns the path of the first UNVALIDATED merge marker found, or null. We detect validation\n// by a raw substring (no JSON.parse) so a malformed marker can never crash the guard.\n/**\n * DEPTH-BOUNDED SCAN, not a fixed level. The marker's home has moved twice: it was\n * `merge-info/<feature>/`, then `merge-info/<feature>/merge-<n>/` once each sync got its own run dir,\n * and is now `merge-info/staged/<feature>/merge-<n>/` since merge-info split into staged/merged. This\n * guard was still looking only at the FIRST layout's depth, so it silently found nothing and stopped\n * blocking — a guard failing open without saying so. A bounded walk covers every layout, legacy\n * included, and stops long before it could descend into anything large.\n */\nconst MARKER_SCAN_MAX_DEPTH = 3;\n\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction findMarkerUnder(dir: string, depth: number): string | null {\n if (depth < 0 || !fs.existsSync(dir)) return null;\n const marker = path.join(dir, MERGE_IN_PROGRESS_FILE);\n if (fs.existsSync(marker)) {\n const raw = fs.readFileSync(marker, 'utf8');\n if (!/\"validated\"\\s*:\\s*true/.test(raw)) return marker;\n }\n if (depth === 0) return null;\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory()) continue;\n const found = findMarkerUnder(path.join(dir, entry.name), depth - 1);\n if (found !== null) return found;\n }\n return null;\n}\n\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction findUnvalidatedMerge(workspaceRoot: string): string | null {\n // LOCAL scope: the merge this guard blocks on is the one THIS worktree started. Another\n // worktree's in-flight merge must not block commits here — that was never the intent, and under a\n // shared merge-info dir it would be the behaviour.\n return findMarkerUnder(dotWebpieces.localFile(workspaceRoot, MERGE_INFO_DIR), MARKER_SCAN_MAX_DEPTH);\n}\n\nconst SCANNER = new CommandScanner();\n// Built from BLOCKED_GH_PR_SUBCOMMANDS so the enforcement and the sentence the fixHint prints can\n// never name different commands.\nconst BLOCKED_GH_PR_PATTERN = new RegExp(`\\\\bgh\\\\s+pr\\\\s+(${BLOCKED_GH_PR_SUBCOMMANDS.join('|')})\\\\b`);\n\n// Operations that would let an agent route around the merge gate.\n//\n// Routed through CommandScanner rather than `/\\bgit\\s+merge\\b/`: that pattern matches the read-only\n// `git merge-base origin/main HEAD` (`\\b` sits between `e` and `-`), which appears in this repo's own\n// documented build command — so an in-progress merge used to block a harmless diff-scope lookup.\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction isBlockedDuringMerge(cmd: string): boolean {\n return SCANNER.commandInvokesAnyGit(cmd, BLOCKED_GIT_SUBCOMMANDS)\n || BLOCKED_GH_PR_PATTERN.test(cmd);\n}\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\nexport class MergeInProgressGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {\n /**\n * The gated command this guard names, handed in by the LOADER from `commands.guardHints\n * .mergeInProgress` (already defaulted there). A constructor parameter, not a config field: the\n * field `merge-in-progress-guard.mergeCompleteCommand` was a SECOND SPELLING that beat the commands\n * section, and the loader's name-keyed injection that fed it could miss a rename silently.\n */\n private readonly mergeCompleteCommand: string;\n\n constructor(config: PrLifecycleGuardConfig, mergeCompleteCommand: string) {\n super(config, 'merge-in-progress-guard', PR_LIFECYCLE_GUARD_KEY);\n this.mergeCompleteCommand = mergeCompleteCommand;\n }\n\n readonly description = 'Block commit/push/merge/PR while a 3-point merge marker is unvalidated, forcing the merge-complete command.';\n get fixHint(): FixHint { return fixHintFor(this.mergeCompleteCommand); }\n\n check(ctx: BashContext): readonly Violation[] {\n if (!isBlockedDuringMerge(ctx.commandCode)) return [];\n const marker = findUnvalidatedMerge(ctx.workspaceRoot);\n if (!marker) return [];\n return [new V(\n 1,\n truncate(ctx.command),\n 'A merge is in progress and not yet validated — this command is blocked.\\n'\n + `Marker: ${marker}`,\n )];\n }\n}\n"]}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { BranchStateGuardConfig } from '@webpieces/rules-config';
|
|
2
|
-
import type { BashContext, Violation } from '../types';
|
|
3
|
-
import { BashRuleBase } from '../rule-base';
|
|
4
|
-
import { FixHint } from '../fix-hint';
|
|
5
|
-
/**
|
|
6
|
-
* The BASH half of the merged-branch protection — the gap that let a whole session run on an
|
|
7
|
-
* already-merged branch.
|
|
8
|
-
*
|
|
9
|
-
* feature-branch-guard blocks Write/Edit and read-stale-guard blocks the Read tool when the
|
|
10
|
-
* checked-out branch's PR is already merged into main, but BOTH are file-scoped: a `runBash()` command
|
|
11
|
-
* never reaches either. So an agent that only ran shell — `scripts/local.sh start lang` (boots
|
|
12
|
-
* servers), `cat`/`ls` of repo files, git — sailed through, even though the very same
|
|
13
|
-
* `branchAlreadyMerged` flag was loaded and logged on the Bash path (the `calls/` stream →
|
|
14
|
-
* `merged=PR#…`). It was computed and thrown away; nothing consulted it for a block.
|
|
15
|
-
*
|
|
16
|
-
* Those two file guards intentionally leave Bash alone ("every cure is a Bash command, so Bash is the
|
|
17
|
-
* escape hatch — never wedge it"). This guard therefore DEFAULT-DENIES Bash on a merged branch but
|
|
18
|
-
* allowlists exactly the commands that get you OFF the branch (the fresh-start / cleanup git commands,
|
|
19
|
-
* switching away, read-only orientation, wp-* cleanup, installs). The redirect it returns names those
|
|
20
|
-
* same commands, so following it can never re-trip the guard — the agent is redirected, not wedged.
|
|
21
|
-
*
|
|
22
|
-
* FAIL-OPEN like its siblings: branch undeterminable, no cache yet, or a cache for a DIFFERENT branch
|
|
23
|
-
* → allow. The cache is per-branch (`status.branch` is the branch it was computed FOR), so acting on
|
|
24
|
-
* another branch's snapshot is never allowed.
|
|
25
|
-
*
|
|
26
|
-
* On the DELIBERATELY-UNFIXED staleness window: the cache is only as fresh as the last detached
|
|
27
|
-
* refresh, so for a few seconds after a merge lands mid-session it can still read `merged=NO` and this
|
|
28
|
-
* guard fails open. That window is tiny and self-closing — agents burst tool calls every few seconds
|
|
29
|
-
* and every Bash call re-triggers the refresh, so `branchAlreadyMerged` flips within 1–3 calls and the
|
|
30
|
-
* next command is caught. Closing it synchronously would require the slow `gh pr list` on the blocking
|
|
31
|
-
* path (the thing the whole cache design avoids) and would mean blocking on stale/uncertain data,
|
|
32
|
-
* which violates the fail-open principle every one of these guards is built on. Not worth it.
|
|
33
|
-
*/
|
|
34
|
-
export declare class MergedBranchBashGuardRule extends BashRuleBase<BranchStateGuardConfig> {
|
|
35
|
-
constructor(config: BranchStateGuardConfig);
|
|
36
|
-
private readonly scanner;
|
|
37
|
-
private readonly recoveryList;
|
|
38
|
-
readonly description: string;
|
|
39
|
-
readonly defaultOptions: {
|
|
40
|
-
hangTimeoutMinutes: number;
|
|
41
|
-
};
|
|
42
|
-
readonly fixHint: FixHint;
|
|
43
|
-
check(ctx: BashContext): readonly Violation[];
|
|
44
|
-
private mergedMessage;
|
|
45
|
-
private cacheSummary;
|
|
46
|
-
/**
|
|
47
|
-
* The guard could not ESTABLISH the state it judges on, so it judged nothing.
|
|
48
|
-
*
|
|
49
|
-
* A sibling of allow() rather than a reason string passed to it, because the difference has to
|
|
50
|
-
* reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`
|
|
51
|
-
* suffix on the free-text reason, which meant an abstention and a real approval were the same
|
|
52
|
-
* verdict and the abstentions could not be counted — so nobody could tell whether these guards
|
|
53
|
-
* were protecting anything or quietly standing down. Never block on data you could not
|
|
54
|
-
* establish; but say out loud, in a field, that you did not establish it.
|
|
55
|
-
*/
|
|
56
|
-
private failOpen;
|
|
57
|
-
private allow;
|
|
58
|
-
private block;
|
|
59
|
-
private truncate;
|
|
60
|
-
private logDecision;
|
|
61
|
-
private currentBranch;
|
|
62
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MergedBranchBashGuardRule = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
7
|
-
const types_1 = require("../types");
|
|
8
|
-
const rule_base_1 = require("../rule-base");
|
|
9
|
-
const fix_hint_1 = require("../fix-hint");
|
|
10
|
-
const to_error_1 = require("../to-error");
|
|
11
|
-
const main_sync_refresh_1 = require("../main-sync-refresh");
|
|
12
|
-
const main_sync_timeout_1 = require("../main-sync-timeout");
|
|
13
|
-
const decision_log_1 = require("../decision-log");
|
|
14
|
-
const l2_matrix_doc_1 = require("../l2-matrix-doc");
|
|
15
|
-
const l0_fault_codes_1 = require("../l0-fault-codes");
|
|
16
|
-
const command_scan_1 = require("../command-scan");
|
|
17
|
-
const merged_branch_message_1 = require("./merged-branch-message");
|
|
18
|
-
const tree_recovery_1 = require("./tree-recovery");
|
|
19
|
-
const recovery_allowlist_1 = require("./recovery-allowlist");
|
|
20
|
-
/**
|
|
21
|
-
* The BASH half of the merged-branch protection — the gap that let a whole session run on an
|
|
22
|
-
* already-merged branch.
|
|
23
|
-
*
|
|
24
|
-
* feature-branch-guard blocks Write/Edit and read-stale-guard blocks the Read tool when the
|
|
25
|
-
* checked-out branch's PR is already merged into main, but BOTH are file-scoped: a `runBash()` command
|
|
26
|
-
* never reaches either. So an agent that only ran shell — `scripts/local.sh start lang` (boots
|
|
27
|
-
* servers), `cat`/`ls` of repo files, git — sailed through, even though the very same
|
|
28
|
-
* `branchAlreadyMerged` flag was loaded and logged on the Bash path (the `calls/` stream →
|
|
29
|
-
* `merged=PR#…`). It was computed and thrown away; nothing consulted it for a block.
|
|
30
|
-
*
|
|
31
|
-
* Those two file guards intentionally leave Bash alone ("every cure is a Bash command, so Bash is the
|
|
32
|
-
* escape hatch — never wedge it"). This guard therefore DEFAULT-DENIES Bash on a merged branch but
|
|
33
|
-
* allowlists exactly the commands that get you OFF the branch (the fresh-start / cleanup git commands,
|
|
34
|
-
* switching away, read-only orientation, wp-* cleanup, installs). The redirect it returns names those
|
|
35
|
-
* same commands, so following it can never re-trip the guard — the agent is redirected, not wedged.
|
|
36
|
-
*
|
|
37
|
-
* FAIL-OPEN like its siblings: branch undeterminable, no cache yet, or a cache for a DIFFERENT branch
|
|
38
|
-
* → allow. The cache is per-branch (`status.branch` is the branch it was computed FOR), so acting on
|
|
39
|
-
* another branch's snapshot is never allowed.
|
|
40
|
-
*
|
|
41
|
-
* On the DELIBERATELY-UNFIXED staleness window: the cache is only as fresh as the last detached
|
|
42
|
-
* refresh, so for a few seconds after a merge lands mid-session it can still read `merged=NO` and this
|
|
43
|
-
* guard fails open. That window is tiny and self-closing — agents burst tool calls every few seconds
|
|
44
|
-
* and every Bash call re-triggers the refresh, so `branchAlreadyMerged` flips within 1–3 calls and the
|
|
45
|
-
* next command is caught. Closing it synchronously would require the slow `gh pr list` on the blocking
|
|
46
|
-
* path (the thing the whole cache design avoids) and would mean blocking on stale/uncertain data,
|
|
47
|
-
* which violates the fail-open principle every one of these guards is built on. Not worth it.
|
|
48
|
-
*/
|
|
49
|
-
class MergedBranchBashGuardRule extends rule_base_1.BashRuleBase {
|
|
50
|
-
constructor(config) { super(config, 'merged-branch-bash-guard', rules_config_1.BRANCH_STATE_GUARD_KEY); }
|
|
51
|
-
scanner = new command_scan_1.CommandScanner();
|
|
52
|
-
// ROW 4, the skip list — shared with stale-main-bash-guard so the two states cannot drift apart
|
|
53
|
-
// about what "gets you out" means. See recovery-allowlist.ts.
|
|
54
|
-
recoveryList = new recovery_allowlist_1.RecoveryAllowlist(this.scanner);
|
|
55
|
-
description = 'Block ordinary Bash on an already-merged branch (allowlisting only recovery/cleanup and ' +
|
|
56
|
-
'read-only inspection commands), so a session cannot proceed on a stale post-merge branch.';
|
|
57
|
-
defaultOptions = {
|
|
58
|
-
hangTimeoutMinutes: repo_workflow_core_1.DEFAULT_HANG_TIMEOUT_MINUTES,
|
|
59
|
-
};
|
|
60
|
-
fixHint = new fix_hint_1.FixHint('This branch is already merged into main — do not keep working here.', 'Get onto a fresh branch off origin/main, then retry:', [
|
|
61
|
-
new rules_config_1.Option('git fetch origin main && git checkout -b <new-branch> origin/main (in a worktree: git worktree add ../<dir> -b <new> origin/main). Then re-run your command.', true),
|
|
62
|
-
new rules_config_1.Option('Still allowed here: recovery/cleanup git, read-only git status|log|diff|show|branch, gh GENERALLY (it talks to GitHub, not to this tree — but not gh repo clone / pr checkout / run download, which write local files), curl/wget without -o/-O or a > redirect, switching branches/worktrees, pnpm wp-sync-main and pnpm wp-cleanup, and installs/upgrades.'),
|
|
63
|
-
new rules_config_1.Option('Disable in webpieces.config.json under hookGuards → branch-state-guard (mode OFF) if intentional — that one key governs the Write, Read and Bash halves of this policy together.'),
|
|
64
|
-
]);
|
|
65
|
-
check(ctx) {
|
|
66
|
-
const branch = this.currentBranch(ctx.workspaceRoot);
|
|
67
|
-
// Can't determine the branch (not a git repo, git unavailable) → never block. Fail-open.
|
|
68
|
-
if (branch === null)
|
|
69
|
-
return this.failOpen(ctx, branch, 'branch-undeterminable');
|
|
70
|
-
// Keep the shared cache warm for the next call. Detached; never blocks this command. (The
|
|
71
|
-
// runner also warms it, but only when feature-branch-guard is loaded — do it here too so this
|
|
72
|
-
// guard is self-sufficient when that one is off.)
|
|
73
|
-
(0, main_sync_refresh_1.triggerMainSyncRefresh)(ctx.workspaceRoot, (0, main_sync_timeout_1.hangTimeoutOf)(this.config));
|
|
74
|
-
const status = (0, repo_workflow_core_1.readMainSyncStatus)(ctx.workspaceRoot, branch);
|
|
75
|
-
// No cache yet (first command of the session), or a branch this refresh has not seen → allow;
|
|
76
|
-
// the refresh we just spawned populates it.
|
|
77
|
-
if (status === null)
|
|
78
|
-
return this.failOpen(ctx, branch, 'no-sync-cache', 'cache=none');
|
|
79
|
-
const cache = this.cacheSummary(status);
|
|
80
|
-
// BELT-AND-BRACES since the cache became branch-keyed: the entry was looked up BY `branch`, so
|
|
81
|
-
// a mismatch is a shape bug rather than the old "cache is for another branch" state. Kept so
|
|
82
|
-
// such a bug degrades to an allow. Unreachable in normal operation.
|
|
83
|
-
if (status.branch !== branch)
|
|
84
|
-
return this.failOpen(ctx, branch, 'stale-cross-branch-cache', cache);
|
|
85
|
-
// NOT-MERGED, or NOT-ASKED? `branchAlreadyMerged: false` is produced both by "this branch has
|
|
86
|
-
// no merged PR" and by "the forge could not be reached" (`gh` missing, unauthenticated,
|
|
87
|
-
// rate-limited, offline). Same allow either way — never block on data you could not establish
|
|
88
|
-
// — but the LOG must not call the second one an approval, or the trail cannot tell a policy
|
|
89
|
-
// that is protecting something from one that is quietly standing down.
|
|
90
|
-
// For THIS guard the merged flag is the ONLY block condition, so an unreachable forge means
|
|
91
|
-
// it is fully abstaining — the state it exists to catch cannot be observed at all.
|
|
92
|
-
if (!status.branchAlreadyMerged) {
|
|
93
|
-
return status.forgeReachable
|
|
94
|
-
? this.allow(ctx, branch, 'clean-feature-branch', cache)
|
|
95
|
-
: this.failOpen(ctx, branch, 'no-forge', cache);
|
|
96
|
-
}
|
|
97
|
-
// Merged. Allow ONLY when every segment of the command is a recovery / cleanup / read-only
|
|
98
|
-
// inspection command — anything else (servers, builds, tests, cat/ls of repo files, git writes)
|
|
99
|
-
// is denied with the redirect.
|
|
100
|
-
if (this.recoveryList.isFullyRecovery(ctx)) {
|
|
101
|
-
return this.allow(ctx, branch, 'merged-branch recovery/inspection (allowlisted)', cache);
|
|
102
|
-
}
|
|
103
|
-
const pr = status.mergedPr !== '' ? status.mergedPr : '?';
|
|
104
|
-
return this.block(ctx, branch, `already-merged PR#${pr}`, this.mergedMessage(ctx.workspaceRoot, branch, status.mergedPr), cache);
|
|
105
|
-
}
|
|
106
|
-
mergedMessage(workspaceRoot, branch, mergedPr) {
|
|
107
|
-
return new merged_branch_message_1.MergedBranchMessage(workspaceRoot).forBash(branch, mergedPr, new tree_recovery_1.TreeRecovery().kindOf(workspaceRoot), workspaceRoot);
|
|
108
|
-
}
|
|
109
|
-
// One-line summary of the async-written cache that drove this decision (mirrors the file guards),
|
|
110
|
-
// so a wrong allow/block is traceable to the exact main-sync-status.json read.
|
|
111
|
-
cacheSummary(status) {
|
|
112
|
-
const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';
|
|
113
|
-
return `cache=${status.branch} merged=${merged} conflict=${String(status.conflict)} ts=${status.timestamp}`;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* The guard could not ESTABLISH the state it judges on, so it judged nothing.
|
|
117
|
-
*
|
|
118
|
-
* A sibling of allow() rather than a reason string passed to it, because the difference has to
|
|
119
|
-
* reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`
|
|
120
|
-
* suffix on the free-text reason, which meant an abstention and a real approval were the same
|
|
121
|
-
* verdict and the abstentions could not be counted — so nobody could tell whether these guards
|
|
122
|
-
* were protecting anything or quietly standing down. Never block on data you could not
|
|
123
|
-
* establish; but say out loud, in a field, that you did not establish it.
|
|
124
|
-
*/
|
|
125
|
-
failOpen(ctx, branch, reason, cache = '-') {
|
|
126
|
-
this.logDecision(ctx, branch, 'ALLOW_FAIL_OPEN', reason, cache);
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
allow(ctx, branch, reason, cache = '-') {
|
|
130
|
-
this.logDecision(ctx, branch, 'ALLOW', reason, cache);
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
block(ctx, branch, reason, message, cache = '-') {
|
|
134
|
-
this.logDecision(ctx, branch, 'BLOCK_AI_CURE', reason, cache);
|
|
135
|
-
// Deliver the matrix and name the row — see stale-main-bash-guard.block for why it is lazy.
|
|
136
|
-
const pointer = (0, l2_matrix_doc_1.branchStateMatrixPointer)((0, l2_matrix_doc_1.writeBranchStateMatrixDoc)(ctx.workspaceRoot), (0, decision_log_1.matrixL2Row)(reason).row);
|
|
137
|
-
return [new types_1.Violation(1, this.truncate(ctx.command), message + pointer)];
|
|
138
|
-
}
|
|
139
|
-
truncate(s) {
|
|
140
|
-
const MAX = 120;
|
|
141
|
-
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
142
|
-
}
|
|
143
|
-
logDecision(ctx, branch, verdict, reason, cache) {
|
|
144
|
-
(0, decision_log_1.logGuardDecision)(ctx.workspaceRoot, new decision_log_1.GuardDecision('merged-branch-bash-guard', 'Bash', ctx.command, branch ?? 'unknown', verdict, reason, cache, l0_fault_codes_1.L0_FAULT_NONE, (0, decision_log_1.matrixL2Row)(reason)));
|
|
145
|
-
}
|
|
146
|
-
currentBranch(workspaceRoot) {
|
|
147
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
148
|
-
try {
|
|
149
|
-
return (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
|
|
150
|
-
cwd: workspaceRoot,
|
|
151
|
-
encoding: 'utf8',
|
|
152
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
153
|
-
}).trim();
|
|
154
|
-
}
|
|
155
|
-
catch (err) {
|
|
156
|
-
const error = (0, to_error_1.toError)(err);
|
|
157
|
-
void error;
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.MergedBranchBashGuardRule = MergedBranchBashGuardRule;
|
|
163
|
-
// git subcommands that are recovery/cleanup OR read-only orientation, and so stay allowed on a merged
|
|
164
|
-
// branch. Everything NOT here (commit, merge, rebase, push, reset, add, restore, clean, cherry-pick,
|
|
165
|
-
// …) is a "keep working" operation and is denied with the redirect. `worktree` covers add/remove/prune
|
|
166
|
-
// (branch-creation-guard governs which worktree adds are legal); `branch` covers listing and `-D`
|
|
167
|
-
// cleanup (branch-creation-guard governs creation); `pull` is the on-main update, itself gated by
|
|
168
|
-
// redirect-how-to-merge-main. Reading git METADATA (log/diff/show) is fine — it is not the stale FILE
|
|
169
|
-
// CONTENT that `cat` would surface, which is exactly why `git grep` (reads tracked content) is absent.
|
|
170
|
-
//# sourceMappingURL=merged-branch-bash-guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merged-branch-bash-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/merged-branch-bash-guard.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAEzC,0DAAiG;AACjG,sEAAiH;AAGjH,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAsC;AACtC,0CAAsC;AACtC,4DAA8D;AAC9D,4DAAqD;AACrD,kDAAwF;AACxF,oDAAuF;AACvF,sDAAkD;AAClD,kDAAiD;AACjD,mEAA8D;AAC9D,mDAA+C;AAC/C,6DAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,yBAA0B,SAAQ,wBAAoC;IAC/E,YAAY,MAA8B,IAAI,KAAK,CAAC,MAAM,EAAE,0BAA0B,EAAE,qCAAsB,CAAC,CAAC,CAAC,CAAC;IAEjG,OAAO,GAAG,IAAI,6BAAc,EAAE,C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GuardConfig, BRANCH_STATE_GUARD_KEY, Option } from '@webpieces/rules-config';\nimport { DEFAULT_HANG_TIMEOUT_MINUTES, readMainSyncStatus, MainSyncStatus } from '@webpieces/repo-workflow-core';\n\nimport type { BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { BashRuleBase } from '../rule-base';\nimport { FixHint } from '../fix-hint';\nimport { toError } from '../to-error';\nimport { triggerMainSyncRefresh } from '../main-sync-refresh';\nimport { hangTimeoutOf } from '../main-sync-timeout';\nimport { logGuardDecision, GuardDecision, Verdict, matrixL2Row } from '../decision-log';\nimport { writeBranchStateMatrixDoc, branchStateMatrixPointer } from '../l2-matrix-doc';\nimport { L0_FAULT_NONE } from '../l0-fault-codes';\nimport { CommandScanner } from '../command-scan';\nimport { MergedBranchMessage } from './merged-branch-message';\nimport { TreeRecovery } from './tree-recovery';\nimport { RecoveryAllowlist } from './recovery-allowlist';\n\n/**\n * The BASH half of the merged-branch protection — the gap that let a whole session run on an\n * already-merged branch.\n *\n * feature-branch-guard blocks Write/Edit and read-stale-guard blocks the Read tool when the\n * checked-out branch's PR is already merged into main, but BOTH are file-scoped: a `runBash()` command\n * never reaches either. So an agent that only ran shell — `scripts/local.sh start lang` (boots\n * servers), `cat`/`ls` of repo files, git — sailed through, even though the very same\n * `branchAlreadyMerged` flag was loaded and logged on the Bash path (the `calls/` stream →\n * `merged=PR#…`). It was computed and thrown away; nothing consulted it for a block.\n *\n * Those two file guards intentionally leave Bash alone (\"every cure is a Bash command, so Bash is the\n * escape hatch — never wedge it\"). This guard therefore DEFAULT-DENIES Bash on a merged branch but\n * allowlists exactly the commands that get you OFF the branch (the fresh-start / cleanup git commands,\n * switching away, read-only orientation, wp-* cleanup, installs). The redirect it returns names those\n * same commands, so following it can never re-trip the guard — the agent is redirected, not wedged.\n *\n * FAIL-OPEN like its siblings: branch undeterminable, no cache yet, or a cache for a DIFFERENT branch\n * → allow. The cache is per-branch (`status.branch` is the branch it was computed FOR), so acting on\n * another branch's snapshot is never allowed.\n *\n * On the DELIBERATELY-UNFIXED staleness window: the cache is only as fresh as the last detached\n * refresh, so for a few seconds after a merge lands mid-session it can still read `merged=NO` and this\n * guard fails open. That window is tiny and self-closing — agents burst tool calls every few seconds\n * and every Bash call re-triggers the refresh, so `branchAlreadyMerged` flips within 1–3 calls and the\n * next command is caught. Closing it synchronously would require the slow `gh pr list` on the blocking\n * path (the thing the whole cache design avoids) and would mean blocking on stale/uncertain data,\n * which violates the fail-open principle every one of these guards is built on. Not worth it.\n */\nexport class MergedBranchBashGuardRule extends BashRuleBase<BranchStateGuardConfig> {\n constructor(config: BranchStateGuardConfig) { super(config, 'merged-branch-bash-guard', BRANCH_STATE_GUARD_KEY); }\n\n private readonly scanner = new CommandScanner();\n // ROW 4, the skip list — shared with stale-main-bash-guard so the two states cannot drift apart\n // about what \"gets you out\" means. See recovery-allowlist.ts.\n private readonly recoveryList = new RecoveryAllowlist(this.scanner);\n\n readonly description =\n 'Block ordinary Bash on an already-merged branch (allowlisting only recovery/cleanup and ' +\n 'read-only inspection commands), so a session cannot proceed on a stale post-merge branch.';\n override readonly defaultOptions = {\n hangTimeoutMinutes: DEFAULT_HANG_TIMEOUT_MINUTES,\n };\n readonly fixHint = new FixHint(\n 'This branch is already merged into main — do not keep working here.',\n 'Get onto a fresh branch off origin/main, then retry:',\n [\n new Option('git fetch origin main && git checkout -b <new-branch> origin/main (in a worktree: git worktree add ../<dir> -b <new> origin/main). Then re-run your command.', true),\n new Option('Still allowed here: recovery/cleanup git, read-only git status|log|diff|show|branch, gh GENERALLY (it talks to GitHub, not to this tree — but not gh repo clone / pr checkout / run download, which write local files), curl/wget without -o/-O or a > redirect, switching branches/worktrees, pnpm wp-sync-main and pnpm wp-cleanup, and installs/upgrades.'),\n new Option('Disable in webpieces.config.json under hookGuards → branch-state-guard (mode OFF) if intentional — that one key governs the Write, Read and Bash halves of this policy together.'),\n ],\n );\n\n check(ctx: BashContext): readonly Violation[] {\n const branch = this.currentBranch(ctx.workspaceRoot);\n // Can't determine the branch (not a git repo, git unavailable) → never block. Fail-open.\n if (branch === null) return this.failOpen(ctx, branch, 'branch-undeterminable');\n\n // Keep the shared cache warm for the next call. Detached; never blocks this command. (The\n // runner also warms it, but only when feature-branch-guard is loaded — do it here too so this\n // guard is self-sufficient when that one is off.)\n triggerMainSyncRefresh(ctx.workspaceRoot, hangTimeoutOf(this.config));\n\n const status = readMainSyncStatus(ctx.workspaceRoot, branch);\n // No cache yet (first command of the session), or a branch this refresh has not seen → allow;\n // the refresh we just spawned populates it.\n if (status === null) return this.failOpen(ctx, branch, 'no-sync-cache', 'cache=none');\n\n const cache = this.cacheSummary(status);\n // BELT-AND-BRACES since the cache became branch-keyed: the entry was looked up BY `branch`, so\n // a mismatch is a shape bug rather than the old \"cache is for another branch\" state. Kept so\n // such a bug degrades to an allow. Unreachable in normal operation.\n if (status.branch !== branch) return this.failOpen(ctx, branch, 'stale-cross-branch-cache', cache);\n\n // NOT-MERGED, or NOT-ASKED? `branchAlreadyMerged: false` is produced both by \"this branch has\n // no merged PR\" and by \"the forge could not be reached\" (`gh` missing, unauthenticated,\n // rate-limited, offline). Same allow either way — never block on data you could not establish\n // — but the LOG must not call the second one an approval, or the trail cannot tell a policy\n // that is protecting something from one that is quietly standing down.\n // For THIS guard the merged flag is the ONLY block condition, so an unreachable forge means\n // it is fully abstaining — the state it exists to catch cannot be observed at all.\n if (!status.branchAlreadyMerged) {\n return status.forgeReachable\n ? this.allow(ctx, branch, 'clean-feature-branch', cache)\n : this.failOpen(ctx, branch, 'no-forge', cache);\n }\n\n // Merged. Allow ONLY when every segment of the command is a recovery / cleanup / read-only\n // inspection command — anything else (servers, builds, tests, cat/ls of repo files, git writes)\n // is denied with the redirect.\n if (this.recoveryList.isFullyRecovery(ctx)) {\n return this.allow(ctx, branch, 'merged-branch recovery/inspection (allowlisted)', cache);\n }\n\n const pr = status.mergedPr !== '' ? status.mergedPr : '?';\n return this.block(ctx, branch, `already-merged PR#${pr}`, this.mergedMessage(ctx.workspaceRoot, branch, status.mergedPr), cache);\n }\n\n private mergedMessage(workspaceRoot: string, branch: string, mergedPr: string): string {\n return new MergedBranchMessage(workspaceRoot).forBash(\n branch, mergedPr, new TreeRecovery().kindOf(workspaceRoot), workspaceRoot,\n );\n }\n\n // One-line summary of the async-written cache that drove this decision (mirrors the file guards),\n // so a wrong allow/block is traceable to the exact main-sync-status.json read.\n private cacheSummary(status: MainSyncStatus): string {\n const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';\n return `cache=${status.branch} merged=${merged} conflict=${String(status.conflict)} ts=${status.timestamp}`;\n }\n\n /**\n * The guard could not ESTABLISH the state it judges on, so it judged nothing.\n *\n * A sibling of allow() rather than a reason string passed to it, because the difference has to\n * reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`\n * suffix on the free-text reason, which meant an abstention and a real approval were the same\n * verdict and the abstentions could not be counted — so nobody could tell whether these guards\n * were protecting anything or quietly standing down. Never block on data you could not\n * establish; but say out loud, in a field, that you did not establish it.\n */\n private failOpen(ctx: BashContext, branch: string | null, reason: string, cache: string = '-'): readonly Violation[] {\n this.logDecision(ctx, branch, 'ALLOW_FAIL_OPEN', reason, cache);\n return [];\n }\n\n private allow(ctx: BashContext, branch: string | null, reason: string, cache: string = '-'): readonly Violation[] {\n this.logDecision(ctx, branch, 'ALLOW', reason, cache);\n return [];\n }\n\n private block(ctx: BashContext, branch: string, reason: string, message: string, cache: string = '-'): readonly Violation[] {\n this.logDecision(ctx, branch, 'BLOCK_AI_CURE', reason, cache);\n // Deliver the matrix and name the row — see stale-main-bash-guard.block for why it is lazy.\n const pointer = branchStateMatrixPointer(writeBranchStateMatrixDoc(ctx.workspaceRoot), matrixL2Row(reason).row);\n return [new V(1, this.truncate(ctx.command), message + pointer)];\n }\n\n private truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n }\n\n private logDecision(ctx: BashContext, branch: string | null, verdict: Verdict, reason: string, cache: string): void {\n logGuardDecision(\n ctx.workspaceRoot,\n new GuardDecision('merged-branch-bash-guard', 'Bash', ctx.command, branch ?? 'unknown', verdict, reason, cache, L0_FAULT_NONE, matrixL2Row(reason)),\n );\n }\n\n private currentBranch(workspaceRoot: string): string | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: workspaceRoot,\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n}\n\n// git subcommands that are recovery/cleanup OR read-only orientation, and so stay allowed on a merged\n// branch. Everything NOT here (commit, merge, rebase, push, reset, add, restore, clean, cherry-pick,\n// …) is a \"keep working\" operation and is denied with the redirect. `worktree` covers add/remove/prune\n// (branch-creation-guard governs which worktree adds are legal); `branch` covers listing and `-D`\n// cleanup (branch-creation-guard governs creation); `pull` is the on-main update, itself gated by\n// redirect-how-to-merge-main. Reading git METADATA (log/diff/show) is fine — it is not the stale FILE\n// CONTENT that `cat` would surface, which is exactly why `git grep` (reads tracked content) is absent.\n"]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { TreeKind } from './tree-recovery';
|
|
2
|
-
/**
|
|
3
|
-
* The "this branch is already merged, start fresh" text, shared by the TWO guards that detect the
|
|
4
|
-
* state from the same cached signal (`MainSyncStatus.branchAlreadyMerged`):
|
|
5
|
-
*
|
|
6
|
-
* - feature-branch-guard blocks Write/Edit → {@link MergedBranchMessage.forEdits}
|
|
7
|
-
* - read-stale-guard blocks Read → {@link MergedBranchMessage.forReads}
|
|
8
|
-
*
|
|
9
|
-
* One source of truth on purpose: the recovery steps are instructions the AI follows LITERALLY, so
|
|
10
|
-
* two drifting copies would mean two different behaviors for the same repo state. Only the
|
|
11
|
-
* "what is still allowed" tail differs, because the two guards block different tools.
|
|
12
|
-
*
|
|
13
|
-
* The steps themselves come from {@link TreeRecovery}, which renders them in the flavour of the tree
|
|
14
|
-
* we are actually standing in — a merged LINKED WORKTREE is told to open a new worktree and remove
|
|
15
|
-
* this dead one, a merged branch in the primary clone is told to `git checkout -b … origin/main`.
|
|
16
|
-
*
|
|
17
|
-
* ONE VOICE on `git checkout main`: only the WORKTREE flavour says never to run it (there it fatals —
|
|
18
|
-
* main is checked out in the primary clone). In the primary clone it is a perfectly good move and the
|
|
19
|
-
* allowance list below says so explicitly. The two used to disagree inside a single message — the
|
|
20
|
-
* header forbade it while the allowance list permitted "git checkout <other-branch>", and `main` is an
|
|
21
|
-
* other-branch — and an agent that resolved the contradiction in favour of the prohibition concluded
|
|
22
|
-
* its only exit was creating a branch, which the branch cap then refused.
|
|
23
|
-
*/
|
|
24
|
-
export declare class MergedBranchMessage {
|
|
25
|
-
private readonly treeRoot;
|
|
26
|
-
private readonly recovery;
|
|
27
|
-
/**
|
|
28
|
-
* `treeRoot` is the tree the guard judged — pass it and every prescribed command comes out as
|
|
29
|
-
* `cd <treeRoot> && …`. That form is the only one that is correct across tool calls: the harness
|
|
30
|
-
* RESETS a cwd that left the workspace, so an agent in a linked worktree is back in the primary
|
|
31
|
-
* clone by the time it runs the cure, and a bare `git checkout -b` would branch the WRONG tree.
|
|
32
|
-
*/
|
|
33
|
-
constructor(treeRoot?: string);
|
|
34
|
-
/**
|
|
35
|
-
* The ONE allowance list, shared by every guard that blocks while this state is up.
|
|
36
|
-
*
|
|
37
|
-
* Each guard used to print its own view of the world: this one's narrow bash allowlist, and
|
|
38
|
-
* read-stale-guard's "EVERY Bash command". Both statements were true of their own guard and false
|
|
39
|
-
* of the session — on a merged branch BOTH fire, so the agent was told simultaneously that all
|
|
40
|
-
* Bash runs and that most Bash is blocked. One list, printed by both.
|
|
41
|
-
*/
|
|
42
|
-
private allowances;
|
|
43
|
-
private common;
|
|
44
|
-
forEdits(branch: string, mergedPr: string, kind?: TreeKind, worktreePath?: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* The Bash variant. merged-branch-bash-guard DEFAULT-DENIES Bash on a merged branch, so the message
|
|
47
|
-
* has to spell out the narrow allowlist — otherwise an agent reads "blocked" and believes it is
|
|
48
|
-
* wedged. The cure commands it lists are exactly the ones the allowlist lets through (including the
|
|
49
|
-
* `| tail`/`; echo` shaping an agent reflexively appends), so following this message can never hit
|
|
50
|
-
* the guard again.
|
|
51
|
-
*/
|
|
52
|
-
forBash(branch: string, mergedPr: string, kind?: TreeKind, worktreePath?: string): string;
|
|
53
|
-
/**
|
|
54
|
-
* The Read variant. Says WHY a read (not an edit) is blocked — reading this branch feeds the AI a
|
|
55
|
-
* pre-merge snapshot of the codebase and every plan built on it is built on code main has already
|
|
56
|
-
* moved past — and spells out the escape valves so the agent never believes it is stuck.
|
|
57
|
-
*/
|
|
58
|
-
forReads(branch: string, mergedPr: string, kind?: TreeKind, worktreePath?: string): string;
|
|
59
|
-
}
|