@webpieces/ai-hook-rules 0.4.839 → 0.4.840
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,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MergedBranchMessage = void 0;
|
|
4
|
-
const tree_recovery_1 = require("./tree-recovery");
|
|
5
|
-
/**
|
|
6
|
-
* The "this branch is already merged, start fresh" text, shared by the TWO guards that detect the
|
|
7
|
-
* state from the same cached signal (`MainSyncStatus.branchAlreadyMerged`):
|
|
8
|
-
*
|
|
9
|
-
* - feature-branch-guard blocks Write/Edit → {@link MergedBranchMessage.forEdits}
|
|
10
|
-
* - read-stale-guard blocks Read → {@link MergedBranchMessage.forReads}
|
|
11
|
-
*
|
|
12
|
-
* One source of truth on purpose: the recovery steps are instructions the AI follows LITERALLY, so
|
|
13
|
-
* two drifting copies would mean two different behaviors for the same repo state. Only the
|
|
14
|
-
* "what is still allowed" tail differs, because the two guards block different tools.
|
|
15
|
-
*
|
|
16
|
-
* The steps themselves come from {@link TreeRecovery}, which renders them in the flavour of the tree
|
|
17
|
-
* we are actually standing in — a merged LINKED WORKTREE is told to open a new worktree and remove
|
|
18
|
-
* this dead one, a merged branch in the primary clone is told to `git checkout -b … origin/main`.
|
|
19
|
-
*
|
|
20
|
-
* ONE VOICE on `git checkout main`: only the WORKTREE flavour says never to run it (there it fatals —
|
|
21
|
-
* main is checked out in the primary clone). In the primary clone it is a perfectly good move and the
|
|
22
|
-
* allowance list below says so explicitly. The two used to disagree inside a single message — the
|
|
23
|
-
* header forbade it while the allowance list permitted "git checkout <other-branch>", and `main` is an
|
|
24
|
-
* other-branch — and an agent that resolved the contradiction in favour of the prohibition concluded
|
|
25
|
-
* its only exit was creating a branch, which the branch cap then refused.
|
|
26
|
-
*/
|
|
27
|
-
class MergedBranchMessage {
|
|
28
|
-
treeRoot;
|
|
29
|
-
recovery;
|
|
30
|
-
/**
|
|
31
|
-
* `treeRoot` is the tree the guard judged — pass it and every prescribed command comes out as
|
|
32
|
-
* `cd <treeRoot> && …`. That form is the only one that is correct across tool calls: the harness
|
|
33
|
-
* RESETS a cwd that left the workspace, so an agent in a linked worktree is back in the primary
|
|
34
|
-
* clone by the time it runs the cure, and a bare `git checkout -b` would branch the WRONG tree.
|
|
35
|
-
*/
|
|
36
|
-
constructor(treeRoot = '') {
|
|
37
|
-
this.treeRoot = treeRoot;
|
|
38
|
-
this.recovery = new tree_recovery_1.TreeRecovery(treeRoot);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The ONE allowance list, shared by every guard that blocks while this state is up.
|
|
42
|
-
*
|
|
43
|
-
* Each guard used to print its own view of the world: this one's narrow bash allowlist, and
|
|
44
|
-
* read-stale-guard's "EVERY Bash command". Both statements were true of their own guard and false
|
|
45
|
-
* of the session — on a merged branch BOTH fire, so the agent was told simultaneously that all
|
|
46
|
-
* Bash runs and that most Bash is blocked. One list, printed by both.
|
|
47
|
-
*/
|
|
48
|
-
allowances(kind) {
|
|
49
|
-
const switching = kind === 'worktree'
|
|
50
|
-
? ' - switching away: git checkout/switch <other-branch> (NOT `git checkout main` — it fatals ' +
|
|
51
|
-
'in a worktree; use `git fetch origin main`), git worktree add/remove/prune'
|
|
52
|
-
: ' - switching away: git checkout/switch <other-branch> — `main` included, so ' +
|
|
53
|
-
'`pnpm wp-sync-main` (checkout main, pull it, reap dead branches and ' +
|
|
54
|
-
'worktrees, sweep orphan directories) is allowed and is the shortest exit; also ' +
|
|
55
|
-
'git worktree add/remove/prune';
|
|
56
|
-
return [
|
|
57
|
-
'Still allowed while this block is up (these get you OFF this branch — run one, then retry):',
|
|
58
|
-
' - the fresh-start / cleanup git commands above',
|
|
59
|
-
' - read-only orientation: git status|log|diff|show|branch',
|
|
60
|
-
' - gh GENERALLY (pr view, pr close, pr comment, api, run watch — it talks to GitHub, not to this tree), and curl/wget; NOT gh repo clone / pr checkout / run download, curl -o, or any `> file`, which write here',
|
|
61
|
-
switching,
|
|
62
|
-
' - pnpm wp-sync-main, pnpm wp-cleanup and the gated wp-start-*/wp-finish-* commands, pnpm install / upgrades',
|
|
63
|
-
' - output shaping on any of the above: `… 2>&1 | tail -40`, `… | head -5`, `…; echo done`',
|
|
64
|
-
' - reading and editing webpieces.config.json (the mode-OFF escape hatch for these guards)',
|
|
65
|
-
'',
|
|
66
|
-
'NOT allowed on this branch, by the sibling guards that fire on the same state: ordinary Bash',
|
|
67
|
-
'(merged-branch-bash-guard), Read (read-stale-guard) and Write/Edit (feature-branch-guard).',
|
|
68
|
-
'One list — all three guards print exactly this one.',
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
// The diagnosis + cure. Identical for both guards — this is the part that must never drift.
|
|
72
|
-
common(branch, mergedPr, kind, worktreePath) {
|
|
73
|
-
const pr = mergedPr !== '' ? ` (merged PR #${mergedPr})` : '';
|
|
74
|
-
const where = kind === 'worktree' ? 'worktree' : 'branch';
|
|
75
|
-
const lines = [
|
|
76
|
-
`It looks like you forgot to clean up this ${where} "${branch}" — its PR is already merged into main${pr}.`,
|
|
77
|
-
// Name the tree that was judged. With several agents running in parallel worktrees, a guard
|
|
78
|
-
// that reasons from the shell cwd can block a command while citing an UNRELATED agent's
|
|
79
|
-
// branch — observed live. Printing the directory makes a wrong judgement visible instead of
|
|
80
|
-
// baffling, and lets the reader see immediately that it is not the tree they meant.
|
|
81
|
-
...(this.treeRoot !== '' ? [`Evaluated against: ${this.treeRoot} (branch ${branch})`] : []),
|
|
82
|
-
'Your work is in main — do NOT keep working here (you will reconflict with main).',
|
|
83
|
-
'',
|
|
84
|
-
...this.recovery.freshStartSteps(kind, '<new-feature-branch>'),
|
|
85
|
-
];
|
|
86
|
-
// Only when we KNOW we are in a dead worktree: the branch cure alone leaves the worktree
|
|
87
|
-
// sitting there, spending the worktree budget (branch-creation-guard.maxWorktrees) forever.
|
|
88
|
-
if (kind === 'worktree') {
|
|
89
|
-
lines.push('', 'Then reap this dead worktree:', ...this.recovery.cleanupSteps(kind, branch, worktreePath).slice(-1));
|
|
90
|
-
}
|
|
91
|
-
return lines;
|
|
92
|
-
}
|
|
93
|
-
forEdits(branch, mergedPr, kind = 'unknown', worktreePath = '<worktree-dir>') {
|
|
94
|
-
return this.common(branch, mergedPr, kind, worktreePath).concat([
|
|
95
|
-
'',
|
|
96
|
-
...this.allowances(kind),
|
|
97
|
-
'',
|
|
98
|
-
'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',
|
|
99
|
-
]).join('\n');
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* The Bash variant. merged-branch-bash-guard DEFAULT-DENIES Bash on a merged branch, so the message
|
|
103
|
-
* has to spell out the narrow allowlist — otherwise an agent reads "blocked" and believes it is
|
|
104
|
-
* wedged. The cure commands it lists are exactly the ones the allowlist lets through (including the
|
|
105
|
-
* `| tail`/`; echo` shaping an agent reflexively appends), so following this message can never hit
|
|
106
|
-
* the guard again.
|
|
107
|
-
*/
|
|
108
|
-
forBash(branch, mergedPr, kind = 'unknown', worktreePath = '<worktree-dir>') {
|
|
109
|
-
return this.common(branch, mergedPr, kind, worktreePath).concat([
|
|
110
|
-
'',
|
|
111
|
-
'Bash is blocked here because working on a merged branch (booting servers, running builds,',
|
|
112
|
-
'reading files with cat/ls) operates on a PRE-MERGE snapshot that origin/main has moved past.',
|
|
113
|
-
'',
|
|
114
|
-
...this.allowances(kind),
|
|
115
|
-
'',
|
|
116
|
-
'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',
|
|
117
|
-
]).join('\n');
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* The Read variant. Says WHY a read (not an edit) is blocked — reading this branch feeds the AI a
|
|
121
|
-
* pre-merge snapshot of the codebase and every plan built on it is built on code main has already
|
|
122
|
-
* moved past — and spells out the escape valves so the agent never believes it is stuck.
|
|
123
|
-
*/
|
|
124
|
-
forReads(branch, mergedPr, kind = 'unknown', worktreePath = '<worktree-dir>') {
|
|
125
|
-
return this.common(branch, mergedPr, kind, worktreePath).concat([
|
|
126
|
-
'',
|
|
127
|
-
'Reads are blocked here because this tree is a PRE-MERGE snapshot: anything you read is',
|
|
128
|
-
'stale relative to origin/main, and a plan built on it is built on code that has moved.',
|
|
129
|
-
'',
|
|
130
|
-
...this.allowances(kind),
|
|
131
|
-
'',
|
|
132
|
-
'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',
|
|
133
|
-
]).join('\n');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
exports.MergedBranchMessage = MergedBranchMessage;
|
|
137
|
-
//# sourceMappingURL=merged-branch-message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merged-branch-message.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/merged-branch-message.ts"],"names":[],"mappings":";;;AAAA,mDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,mBAAmB;IASC;IARZ,QAAQ,CAAe;IAExC;;;;;OAKG;IACH,YAA6B,WAAmB,EAAE;QAArB,aAAQ,GAAR,QAAQ,CAAa;QAC9C,IAAI,CAAC,QAAQ,GAAG,IAAI,4BAAY,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACK,UAAU,CAAC,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AAC;IAClB,CAAC;CACJ;AAjHD,kDAiHC","sourcesContent":["import { TreeRecovery, TreeKind } from './tree-recovery';\n\n/**\n * The \"this branch is already merged, start fresh\" text, shared by the TWO guards that detect the\n * state from the same cached signal (`MainSyncStatus.branchAlreadyMerged`):\n *\n * - feature-branch-guard blocks Write/Edit → {@link MergedBranchMessage.forEdits}\n * - read-stale-guard blocks Read → {@link MergedBranchMessage.forReads}\n *\n * One source of truth on purpose: the recovery steps are instructions the AI follows LITERALLY, so\n * two drifting copies would mean two different behaviors for the same repo state. Only the\n * \"what is still allowed\" tail differs, because the two guards block different tools.\n *\n * The steps themselves come from {@link TreeRecovery}, which renders them in the flavour of the tree\n * we are actually standing in — a merged LINKED WORKTREE is told to open a new worktree and remove\n * this dead one, a merged branch in the primary clone is told to `git checkout -b … origin/main`.\n *\n * ONE VOICE on `git checkout main`: only the WORKTREE flavour says never to run it (there it fatals —\n * main is checked out in the primary clone). In the primary clone it is a perfectly good move and the\n * allowance list below says so explicitly. The two used to disagree inside a single message — the\n * header forbade it while the allowance list permitted \"git checkout <other-branch>\", and `main` is an\n * other-branch — and an agent that resolved the contradiction in favour of the prohibition concluded\n * its only exit was creating a branch, which the branch cap then refused.\n */\nexport class MergedBranchMessage {\n private readonly recovery: TreeRecovery;\n\n /**\n * `treeRoot` is the tree the guard judged — pass it and every prescribed command comes out as\n * `cd <treeRoot> && …`. That form is the only one that is correct across tool calls: the harness\n * RESETS a cwd that left the workspace, so an agent in a linked worktree is back in the primary\n * clone by the time it runs the cure, and a bare `git checkout -b` would branch the WRONG tree.\n */\n constructor(private readonly treeRoot: string = '') {\n this.recovery = new TreeRecovery(treeRoot);\n }\n\n /**\n * The ONE allowance list, shared by every guard that blocks while this state is up.\n *\n * Each guard used to print its own view of the world: this one's narrow bash allowlist, and\n * read-stale-guard's \"EVERY Bash command\". Both statements were true of their own guard and false\n * of the session — on a merged branch BOTH fire, so the agent was told simultaneously that all\n * Bash runs and that most Bash is blocked. One list, printed by both.\n */\n private allowances(kind: TreeKind): string[] {\n const switching = kind === 'worktree'\n ? ' - switching away: git checkout/switch <other-branch> (NOT `git checkout main` — it fatals ' +\n 'in a worktree; use `git fetch origin main`), git worktree add/remove/prune'\n : ' - switching away: git checkout/switch <other-branch> — `main` included, so ' +\n '`pnpm wp-sync-main` (checkout main, pull it, reap dead branches and ' +\n 'worktrees, sweep orphan directories) is allowed and is the shortest exit; also ' +\n 'git worktree add/remove/prune';\n return [\n 'Still allowed while this block is up (these get you OFF this branch — run one, then retry):',\n ' - the fresh-start / cleanup git commands above',\n ' - read-only orientation: git status|log|diff|show|branch',\n ' - gh GENERALLY (pr view, pr close, pr comment, api, run watch — it talks to GitHub, not to this tree), and curl/wget; NOT gh repo clone / pr checkout / run download, curl -o, or any `> file`, which write here',\n switching,\n ' - pnpm wp-sync-main, pnpm wp-cleanup and the gated wp-start-*/wp-finish-* commands, pnpm install / upgrades',\n ' - output shaping on any of the above: `… 2>&1 | tail -40`, `… | head -5`, `…; echo done`',\n ' - reading and editing webpieces.config.json (the mode-OFF escape hatch for these guards)',\n '',\n 'NOT allowed on this branch, by the sibling guards that fire on the same state: ordinary Bash',\n '(merged-branch-bash-guard), Read (read-stale-guard) and Write/Edit (feature-branch-guard).',\n 'One list — all three guards print exactly this one.',\n ];\n }\n\n // The diagnosis + cure. Identical for both guards — this is the part that must never drift.\n private common(branch: string, mergedPr: string, kind: TreeKind, worktreePath: string): string[] {\n const pr = mergedPr !== '' ? ` (merged PR #${mergedPr})` : '';\n const where = kind === 'worktree' ? 'worktree' : 'branch';\n const lines = [\n `It looks like you forgot to clean up this ${where} \"${branch}\" — its PR is already merged into main${pr}.`,\n // Name the tree that was judged. With several agents running in parallel worktrees, a guard\n // that reasons from the shell cwd can block a command while citing an UNRELATED agent's\n // branch — observed live. Printing the directory makes a wrong judgement visible instead of\n // baffling, and lets the reader see immediately that it is not the tree they meant.\n ...(this.treeRoot !== '' ? [`Evaluated against: ${this.treeRoot} (branch ${branch})`] : []),\n 'Your work is in main — do NOT keep working here (you will reconflict with main).',\n '',\n ...this.recovery.freshStartSteps(kind, '<new-feature-branch>'),\n ];\n\n // Only when we KNOW we are in a dead worktree: the branch cure alone leaves the worktree\n // sitting there, spending the worktree budget (branch-creation-guard.maxWorktrees) forever.\n if (kind === 'worktree') {\n lines.push('', 'Then reap this dead worktree:', ...this.recovery.cleanupSteps(kind, branch, worktreePath).slice(-1));\n }\n return lines;\n }\n\n forEdits(branch: string, mergedPr: string, kind: TreeKind = 'unknown', worktreePath: string = '<worktree-dir>'): string {\n return this.common(branch, mergedPr, kind, worktreePath).concat([\n '',\n ...this.allowances(kind),\n '',\n 'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',\n ]).join('\\n');\n }\n\n /**\n * The Bash variant. merged-branch-bash-guard DEFAULT-DENIES Bash on a merged branch, so the message\n * has to spell out the narrow allowlist — otherwise an agent reads \"blocked\" and believes it is\n * wedged. The cure commands it lists are exactly the ones the allowlist lets through (including the\n * `| tail`/`; echo` shaping an agent reflexively appends), so following this message can never hit\n * the guard again.\n */\n forBash(branch: string, mergedPr: string, kind: TreeKind = 'unknown', worktreePath: string = '<worktree-dir>'): string {\n return this.common(branch, mergedPr, kind, worktreePath).concat([\n '',\n 'Bash is blocked here because working on a merged branch (booting servers, running builds,',\n 'reading files with cat/ls) operates on a PRE-MERGE snapshot that origin/main has moved past.',\n '',\n ...this.allowances(kind),\n '',\n 'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',\n ]).join('\\n');\n }\n\n /**\n * The Read variant. Says WHY a read (not an edit) is blocked — reading this branch feeds the AI a\n * pre-merge snapshot of the codebase and every plan built on it is built on code main has already\n * moved past — and spells out the escape valves so the agent never believes it is stuck.\n */\n forReads(branch: string, mergedPr: string, kind: TreeKind = 'unknown', worktreePath: string = '<worktree-dir>'): string {\n return this.common(branch, mergedPr, kind, worktreePath).concat([\n '',\n 'Reads are blocked here because this tree is a PRE-MERGE snapshot: anything you read is',\n 'stale relative to origin/main, and a plan built on it is built on code that has moved.',\n '',\n ...this.allowances(kind),\n '',\n 'Please add to memory: start a new branch/worktree off origin/main after a PR is merged.',\n ]).join('\\n');\n }\n}\n"]}
|
|
@@ -1,26 +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 PrCreationOrPushGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {
|
|
6
|
-
/**
|
|
7
|
-
* The gated command this guard names, handed in by the LOADER from `commands.guardHints
|
|
8
|
-
* .prCreationOrPush` (already defaulted there). It is a constructor parameter, not a config field:
|
|
9
|
-
* the field `pr-creation-or-push-guard.upsertPrCommand` was a SECOND SPELLING that beat the
|
|
10
|
-
* commands section at the point of use, and the loader's name-keyed injection that fed it could
|
|
11
|
-
* miss a rename without failing the build. One spelling, wired at compile time.
|
|
12
|
-
*/
|
|
13
|
-
private readonly upsertPrCommand;
|
|
14
|
-
constructor(config: PrLifecycleGuardConfig, upsertPrCommand: string);
|
|
15
|
-
readonly description = "Block manual `git push` and direct PR creation/edit so AI uses the gated flow; a human may personally use the interactive wp-human-post-pr escape hatch.";
|
|
16
|
-
get fixHint(): FixHint;
|
|
17
|
-
check(ctx: BashContext): readonly Violation[];
|
|
18
|
-
/**
|
|
19
|
-
* Read the configured dev refs, falling back to the defaults when this repo has no `pr-gate` section
|
|
20
|
-
* at all (a consumer that has not adopted the gate still gets a correct hint for the default names).
|
|
21
|
-
*
|
|
22
|
-
* Calling the loader here is safe by construction: an INVALID config blocks every Bash call long
|
|
23
|
-
* before a rule runs, so reaching this line already means the config loaded.
|
|
24
|
-
*/
|
|
25
|
-
private aimedAtDevEnvironment;
|
|
26
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrCreationOrPushGuardRule = void 0;
|
|
4
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
const rule_base_1 = require("../rule-base");
|
|
7
|
-
const fix_hint_1 = require("../fix-hint");
|
|
8
|
-
const INSTRUCT_FILE = 'webpieces.git-workflow.md';
|
|
9
|
-
/**
|
|
10
|
-
* The hint BRANCHES ON INTENT, and that is not polish.
|
|
11
|
-
*
|
|
12
|
-
* There are now two legitimate destinations for a blocked push — land it on `main`, or get it onto the
|
|
13
|
-
* shared dev server — and the block alone cannot tell them apart. The old flat hint said "everything goes
|
|
14
|
-
* through `wp-start-upsert-pr`", so an AI told "put my branch on dev" would try `git push`, get blocked,
|
|
15
|
-
* read this, and open a PR to main: the exact opposite of what it was asked to do, and the destructive
|
|
16
|
-
* direction of the two. Naming both destinations is what makes the dev flow discoverable at all — nothing
|
|
17
|
-
* else the AI can see mentions it.
|
|
18
|
-
*/
|
|
19
|
-
function fixHintFor(upsertPrCommand) {
|
|
20
|
-
return new fix_hint_1.FixHint('Direct PR creation/update AND manual `git push` are blocked.', 'Never push or open/update a PR by hand. There are TWO gated destinations — pick by what you were\n' +
|
|
21
|
-
'actually trying to do:\n\n' +
|
|
22
|
-
'LANDING ON MAIN (a PR, prod-quality, reviewed):\n' +
|
|
23
|
-
` ${upsertPrCommand}\n` +
|
|
24
|
-
' It updates the branch from main (3-point merge) and runs the real build (nx affected), then\n' +
|
|
25
|
-
' instructs you to write summary.json and run `pnpm wp-finish-upsert-pr`, which assembles the\n' +
|
|
26
|
-
' dashboard and creates/updates the PR — and pushes for you. A failing build = no push, no PR.\n\n' +
|
|
27
|
-
'JUST WANT IT ON THE SHARED DEV SERVER (no PR, not landing on main):\n' +
|
|
28
|
-
` ${rules_config_1.WP_PUSH_DEV}\n` +
|
|
29
|
-
' It publishes a DISPOSABLE copy of your branch that the dev environment composes and rebuilds.\n' +
|
|
30
|
-
" Your feature branch is never moved and never acquires another developer's commits, which is\n" +
|
|
31
|
-
' the whole reason the copy exists. Do NOT open a PR to main just to test something in dev.\n\n' +
|
|
32
|
-
'ON A /hotfix/ BRANCH (cut from the production sha, so it must NOT take main):\n' +
|
|
33
|
-
' pnpm wp-upsert-hotfix-pr\n' +
|
|
34
|
-
' One command: hotfix-ci (build + test), no merge from main, one fast-forward push, then it\n' +
|
|
35
|
-
' creates or updates the bannered PR to main and never auto-merges it.\n\n' +
|
|
36
|
-
'All of them push internally as child processes this hook never sees, so the gated commands are\n' +
|
|
37
|
-
'unaffected by this guard. There is nothing to paste or attest to; the commands do the work.\n' +
|
|
38
|
-
'A HUMAN who has personally inspected the work may run `pnpm wp-human-post-pr` themselves.\n' +
|
|
39
|
-
'That is an interactive human attestation and visibly skips automated build/review. AI must\n' +
|
|
40
|
-
"never run it for the human or answer `human` on the human's behalf.\n" +
|
|
41
|
-
'Full branch → update → PR flow: READ the instruct-ai git-workflow doc at the absolute path on the violation line above.\n' +
|
|
42
|
-
"Add this to your memory so you don't forget next time and waste tokens.");
|
|
43
|
-
}
|
|
44
|
-
// Detect every way an agent could push or open/update a PR directly, so the ONLY path left is the
|
|
45
|
-
// gated flow (wp-start-upsert-pr → wp-finish-upsert-pr, whose internal `git push` / `gh pr create`
|
|
46
|
-
// run as child processes the hook never sees). Read-only `gh pr list` / `gh api .../pulls` GET are
|
|
47
|
-
// intentionally allowed.
|
|
48
|
-
function isBlockedPrOrPush(cmd) {
|
|
49
|
-
// A manual push is always blocked — the gated flow pushes for you behind the build gate.
|
|
50
|
-
if (/\bgit\s+push\b/.test(cmd))
|
|
51
|
-
return true;
|
|
52
|
-
if (/\bgh\s+pr\s+(create|edit)\b/.test(cmd))
|
|
53
|
-
return true;
|
|
54
|
-
const ghApiPulls = /\bgh\s+api\b[^\n]*\/pulls\b/.test(cmd);
|
|
55
|
-
if (ghApiPulls &&
|
|
56
|
-
(/--method\s+POST/i.test(cmd) ||
|
|
57
|
-
/-X\s+POST/i.test(cmd) ||
|
|
58
|
-
/\s-f\b/.test(cmd) ||
|
|
59
|
-
/\s-F\b/.test(cmd) ||
|
|
60
|
-
/--field\b/.test(cmd))) {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
const curlPulls = /\bcurl\b[^\n]*api\.github\.com[^\n]*\/pulls\b/.test(cmd);
|
|
64
|
-
if (curlPulls &&
|
|
65
|
-
(/-X\s*POST/i.test(cmd) || /--request\s+POST/i.test(cmd) || /(\s-d\b|--data\b)/.test(cmd))) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
function truncate(s) {
|
|
71
|
-
const MAX = 120;
|
|
72
|
-
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Does this blocked push AIM at the shared dev environment?
|
|
76
|
-
*
|
|
77
|
-
* The refspec is the one place the AI already stated its intent unambiguously, so reading it is strictly
|
|
78
|
-
* better than making the AI choose between two hints it has no way to disambiguate. A push whose
|
|
79
|
-
* destination is the dev namespace or the dev branch itself gets the `wp-push-dev` remedy on the `→`
|
|
80
|
-
* line; everything else keeps the PR-flow remedy it has always had.
|
|
81
|
-
*/
|
|
82
|
-
// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
|
|
83
|
-
function targetsDevEnvironment(cmd, namespace, devBranch) {
|
|
84
|
-
if (cmd.includes(`${namespace}/`))
|
|
85
|
-
return true;
|
|
86
|
-
const push = /\bgit\s+push\b([^\n;&|]*)/.exec(cmd);
|
|
87
|
-
if (push === null)
|
|
88
|
-
return false;
|
|
89
|
-
// Split on whitespace AND `:` so both halves of a `HEAD:<dest>` refspec are examined. Matching whole
|
|
90
|
-
// tokens (never a substring) keeps a branch merely NAMED `develop` from reading as the dev branch.
|
|
91
|
-
return push[1]
|
|
92
|
-
.split(/[\s:]+/)
|
|
93
|
-
.some((token) => token === devBranch || token === `refs/heads/${devBranch}`);
|
|
94
|
-
}
|
|
95
|
-
class PrCreationOrPushGuardRule extends rule_base_1.BashRuleBase {
|
|
96
|
-
/**
|
|
97
|
-
* The gated command this guard names, handed in by the LOADER from `commands.guardHints
|
|
98
|
-
* .prCreationOrPush` (already defaulted there). It is a constructor parameter, not a config field:
|
|
99
|
-
* the field `pr-creation-or-push-guard.upsertPrCommand` was a SECOND SPELLING that beat the
|
|
100
|
-
* commands section at the point of use, and the loader's name-keyed injection that fed it could
|
|
101
|
-
* miss a rename without failing the build. One spelling, wired at compile time.
|
|
102
|
-
*/
|
|
103
|
-
upsertPrCommand;
|
|
104
|
-
constructor(config, upsertPrCommand) {
|
|
105
|
-
super(config, 'pr-creation-or-push-guard', rules_config_1.PR_LIFECYCLE_GUARD_KEY);
|
|
106
|
-
this.upsertPrCommand = upsertPrCommand;
|
|
107
|
-
}
|
|
108
|
-
description = 'Block manual `git push` and direct PR creation/edit so AI uses the gated flow; a human may personally use the interactive wp-human-post-pr escape hatch.';
|
|
109
|
-
get fixHint() {
|
|
110
|
-
return fixHintFor(this.upsertPrCommand);
|
|
111
|
-
}
|
|
112
|
-
check(ctx) {
|
|
113
|
-
if (!isBlockedPrOrPush(ctx.commandCode))
|
|
114
|
-
return [];
|
|
115
|
-
// Materialize the doc we are about to send the AI to. Pointing at a path that does not exist
|
|
116
|
-
// (nothing has run a `wp-*` command in this tree yet) costs the AI a turn to discover; a STALE
|
|
117
|
-
// copy from an older @webpieces is just as bad, so overwrite rather than write-if-missing.
|
|
118
|
-
(0, rules_config_1.writeTemplate)(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
119
|
-
const docPath = new rules_config_1.RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
120
|
-
if (this.aimedAtDevEnvironment(ctx)) {
|
|
121
|
-
return [
|
|
122
|
-
new types_1.Violation(1, truncate(ctx.command), 'Manual push is blocked — but this one is aimed at the shared DEV environment, which has its own\n' +
|
|
123
|
-
`gated command. Use \`${rules_config_1.WP_PUSH_DEV}\` (publishes a disposable copy; never moves your branch, never\n` +
|
|
124
|
-
`opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`),
|
|
125
|
-
];
|
|
126
|
-
}
|
|
127
|
-
return [
|
|
128
|
-
new types_1.Violation(1, truncate(ctx.command), `Manual push / direct PR is blocked — AI uses the gated flow (${this.upsertPrCommand}). A human may personally run pnpm wp-human-post-pr; AI never answers its attestation. Full flow: READ ${docPath}.`),
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Read the configured dev refs, falling back to the defaults when this repo has no `pr-gate` section
|
|
133
|
-
* at all (a consumer that has not adopted the gate still gets a correct hint for the default names).
|
|
134
|
-
*
|
|
135
|
-
* Calling the loader here is safe by construction: an INVALID config blocks every Bash call long
|
|
136
|
-
* before a rule runs, so reaching this line already means the config loaded.
|
|
137
|
-
*/
|
|
138
|
-
aimedAtDevEnvironment(ctx) {
|
|
139
|
-
const devDeploy = (0, rules_config_1.loadAndValidate)(ctx.governedRoot).prGate.devDeploy;
|
|
140
|
-
return targetsDevEnvironment(ctx.commandCode, devDeploy.branchNamespace === ''
|
|
141
|
-
? rules_config_1.DEFAULT_DEV_BRANCH_NAMESPACE
|
|
142
|
-
: devDeploy.branchNamespace, devDeploy.devBranch === '' ? rules_config_1.DEFAULT_DEV_BRANCH : devDeploy.devBranch);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.PrCreationOrPushGuardRule = PrCreationOrPushGuardRule;
|
|
146
|
-
//# sourceMappingURL=pr-creation-or-push-guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pr-creation-or-push-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/pr-creation-or-push-guard.ts"],"names":[],"mappings":";;;AAAA,0DASiC;AAGjC,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAsC;AAEtC,MAAM,aAA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J;AAjED,8DAiEC","sourcesContent":["import {\n DEFAULT_DEV_BRANCH,\n DEFAULT_DEV_BRANCH_NAMESPACE,\n PrLifecycleGuardConfig,\n PR_LIFECYCLE_GUARD_KEY,\n RepoRootFinder,\n WP_PUSH_DEV,\n loadAndValidate,\n writeTemplate,\n} 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';\n\nconst INSTRUCT_FILE = 'webpieces.git-workflow.md';\n\n/**\n * The hint BRANCHES ON INTENT, and that is not polish.\n *\n * There are now two legitimate destinations for a blocked push — land it on `main`, or get it onto the\n * shared dev server — and the block alone cannot tell them apart. The old flat hint said \"everything goes\n * through `wp-start-upsert-pr`\", so an AI told \"put my branch on dev\" would try `git push`, get blocked,\n * read this, and open a PR to main: the exact opposite of what it was asked to do, and the destructive\n * direction of the two. Naming both destinations is what makes the dev flow discoverable at all — nothing\n * else the AI can see mentions it.\n */\nfunction fixHintFor(upsertPrCommand: string): FixHint {\n return new FixHint(\n 'Direct PR creation/update AND manual `git push` are blocked.',\n 'Never push or open/update a PR by hand. There are TWO gated destinations — pick by what you were\\n' +\n 'actually trying to do:\\n\\n' +\n 'LANDING ON MAIN (a PR, prod-quality, reviewed):\\n' +\n ` ${upsertPrCommand}\\n` +\n ' It updates the branch from main (3-point merge) and runs the real build (nx affected), then\\n' +\n ' instructs you to write summary.json and run `pnpm wp-finish-upsert-pr`, which assembles the\\n' +\n ' dashboard and creates/updates the PR — and pushes for you. A failing build = no push, no PR.\\n\\n' +\n 'JUST WANT IT ON THE SHARED DEV SERVER (no PR, not landing on main):\\n' +\n ` ${WP_PUSH_DEV}\\n` +\n ' It publishes a DISPOSABLE copy of your branch that the dev environment composes and rebuilds.\\n' +\n \" Your feature branch is never moved and never acquires another developer's commits, which is\\n\" +\n ' the whole reason the copy exists. Do NOT open a PR to main just to test something in dev.\\n\\n' +\n 'ON A /hotfix/ BRANCH (cut from the production sha, so it must NOT take main):\\n' +\n ' pnpm wp-upsert-hotfix-pr\\n' +\n ' One command: hotfix-ci (build + test), no merge from main, one fast-forward push, then it\\n' +\n ' creates or updates the bannered PR to main and never auto-merges it.\\n\\n' +\n 'All of them push internally as child processes this hook never sees, so the gated commands are\\n' +\n 'unaffected by this guard. There is nothing to paste or attest to; the commands do the work.\\n' +\n 'A HUMAN who has personally inspected the work may run `pnpm wp-human-post-pr` themselves.\\n' +\n 'That is an interactive human attestation and visibly skips automated build/review. AI must\\n' +\n \"never run it for the human or answer `human` on the human's behalf.\\n\" +\n 'Full branch → update → PR flow: READ the instruct-ai git-workflow doc at the absolute path on the violation line above.\\n' +\n \"Add this to your memory so you don't forget next time and waste tokens.\",\n );\n}\n\n// Detect every way an agent could push or open/update a PR directly, so the ONLY path left is the\n// gated flow (wp-start-upsert-pr → wp-finish-upsert-pr, whose internal `git push` / `gh pr create`\n// run as child processes the hook never sees). Read-only `gh pr list` / `gh api .../pulls` GET are\n// intentionally allowed.\nfunction isBlockedPrOrPush(cmd: string): boolean {\n // A manual push is always blocked — the gated flow pushes for you behind the build gate.\n if (/\\bgit\\s+push\\b/.test(cmd)) return true;\n\n if (/\\bgh\\s+pr\\s+(create|edit)\\b/.test(cmd)) return true;\n\n const ghApiPulls = /\\bgh\\s+api\\b[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n ghApiPulls &&\n (/--method\\s+POST/i.test(cmd) ||\n /-X\\s+POST/i.test(cmd) ||\n /\\s-f\\b/.test(cmd) ||\n /\\s-F\\b/.test(cmd) ||\n /--field\\b/.test(cmd))\n ) {\n return true;\n }\n\n const curlPulls = /\\bcurl\\b[^\\n]*api\\.github\\.com[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n curlPulls &&\n (/-X\\s*POST/i.test(cmd) || /--request\\s+POST/i.test(cmd) || /(\\s-d\\b|--data\\b)/.test(cmd))\n ) {\n return true;\n }\n return false;\n}\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\n/**\n * Does this blocked push AIM at the shared dev environment?\n *\n * The refspec is the one place the AI already stated its intent unambiguously, so reading it is strictly\n * better than making the AI choose between two hints it has no way to disambiguate. A push whose\n * destination is the dev namespace or the dev branch itself gets the `wp-push-dev` remedy on the `→`\n * line; everything else keeps the PR-flow remedy it has always had.\n */\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction targetsDevEnvironment(cmd: string, namespace: string, devBranch: string): boolean {\n if (cmd.includes(`${namespace}/`)) return true;\n const push = /\\bgit\\s+push\\b([^\\n;&|]*)/.exec(cmd);\n if (push === null) return false;\n // Split on whitespace AND `:` so both halves of a `HEAD:<dest>` refspec are examined. Matching whole\n // tokens (never a substring) keeps a branch merely NAMED `develop` from reading as the dev branch.\n return push[1]\n .split(/[\\s:]+/)\n .some(\n (token: string): boolean => token === devBranch || token === `refs/heads/${devBranch}`,\n );\n}\n\nexport class PrCreationOrPushGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {\n /**\n * The gated command this guard names, handed in by the LOADER from `commands.guardHints\n * .prCreationOrPush` (already defaulted there). It is a constructor parameter, not a config field:\n * the field `pr-creation-or-push-guard.upsertPrCommand` was a SECOND SPELLING that beat the\n * commands section at the point of use, and the loader's name-keyed injection that fed it could\n * miss a rename without failing the build. One spelling, wired at compile time.\n */\n private readonly upsertPrCommand: string;\n\n constructor(config: PrLifecycleGuardConfig, upsertPrCommand: string) {\n super(config, 'pr-creation-or-push-guard', PR_LIFECYCLE_GUARD_KEY);\n this.upsertPrCommand = upsertPrCommand;\n }\n\n readonly description =\n 'Block manual `git push` and direct PR creation/edit so AI uses the gated flow; a human may personally use the interactive wp-human-post-pr escape hatch.';\n get fixHint(): FixHint {\n return fixHintFor(this.upsertPrCommand);\n }\n\n check(ctx: BashContext): readonly Violation[] {\n if (!isBlockedPrOrPush(ctx.commandCode)) return [];\n // Materialize the doc we are about to send the AI to. Pointing at a path that does not exist\n // (nothing has run a `wp-*` command in this tree yet) costs the AI a turn to discover; a STALE\n // copy from an older @webpieces is just as bad, so overwrite rather than write-if-missing.\n writeTemplate(ctx.workspaceRoot, INSTRUCT_FILE);\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n if (this.aimedAtDevEnvironment(ctx)) {\n return [\n new V(\n 1,\n truncate(ctx.command),\n 'Manual push is blocked — but this one is aimed at the shared DEV environment, which has its own\\n' +\n `gated command. Use \\`${WP_PUSH_DEV}\\` (publishes a disposable copy; never moves your branch, never\\n` +\n `opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n return [\n new V(\n 1,\n truncate(ctx.command),\n `Manual push / direct PR is blocked — AI uses the gated flow (${this.upsertPrCommand}). A human may personally run pnpm wp-human-post-pr; AI never answers its attestation. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n\n /**\n * Read the configured dev refs, falling back to the defaults when this repo has no `pr-gate` section\n * at all (a consumer that has not adopted the gate still gets a correct hint for the default names).\n *\n * Calling the loader here is safe by construction: an INVALID config blocks every Bash call long\n * before a rule runs, so reaching this line already means the config loaded.\n */\n private aimedAtDevEnvironment(ctx: BashContext): boolean {\n const devDeploy = loadAndValidate(ctx.governedRoot).prGate.devDeploy;\n return targetsDevEnvironment(\n ctx.commandCode,\n devDeploy.branchNamespace === ''\n ? DEFAULT_DEV_BRANCH_NAMESPACE\n : devDeploy.branchNamespace,\n devDeploy.devBranch === '' ? DEFAULT_DEV_BRANCH : devDeploy.devBranch,\n );\n }\n}\n"]}
|
|
@@ -1,36 +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 PrMergeGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {
|
|
6
|
-
constructor(config: PrLifecycleGuardConfig);
|
|
7
|
-
readonly description = "Redirect a hand-rolled `gh pr merge` to `pnpm wp-land-pr`, then require branch cleanup.";
|
|
8
|
-
private currentBranch;
|
|
9
|
-
private treeKind;
|
|
10
|
-
private worktreePath;
|
|
11
|
-
private readonly recovery;
|
|
12
|
-
get fixHint(): FixHint;
|
|
13
|
-
/**
|
|
14
|
-
* Any hand-rolled `gh pr merge` is blocked outright — there is no "but I cleaned up afterwards"
|
|
15
|
-
* escape, because the damage is the commit message that merge writes into main, which cleanup
|
|
16
|
-
* cannot undo. `pnpm wp-land-pr` is the way through; its own `gh pr merge` runs as a child
|
|
17
|
-
* process this hook never sees, exactly like the other gated commands.
|
|
18
|
-
*
|
|
19
|
-
* ─── Why a CORRECT-LOOKING `gh pr merge --auto --subject --body-file` is still blocked ──────────
|
|
20
|
-
* Full reasoning, and what was rejected: `decisions/0005-the-pr-description-is-the-merge-body.md`
|
|
21
|
-
* § "pr-merge-guard stays blocking" (which supersedes `0004` § 8). It has now been re-examined
|
|
22
|
-
* twice — once when the gated body moved out of the worktree, and again when it moved onto the PR
|
|
23
|
-
* itself — and the block stands. A `--body-file` proves a file was passed, never that it holds the
|
|
24
|
-
* GATED bytes: the guard sees a command string and cannot read the file, so any file at all — a
|
|
25
|
-
* hand-written one, an older run's — could land as the reviewed body with nothing to distinguish it
|
|
26
|
-
* afterwards.
|
|
27
|
-
*
|
|
28
|
-
* One more thing depends on that: landing DECIDES whether the archive/merge-info/reap bookkeeping
|
|
29
|
-
* belongs to this tree, by comparing this tree's branch tip against the PR's `headRefOid`. A
|
|
30
|
-
* hand-rolled merge skips that decision silently, which is how a landed worktree becomes a corpse.
|
|
31
|
-
*
|
|
32
|
-
* The tree kind still decides which cleanup steps the hint prints: in a linked worktree
|
|
33
|
-
* `git checkout main` FATALS, so demanding it there would be demanding an impossible command.
|
|
34
|
-
*/
|
|
35
|
-
check(ctx: BashContext): readonly Violation[];
|
|
36
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrMergeGuardRule = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const rule_base_1 = require("../rule-base");
|
|
8
|
-
const fix_hint_1 = require("../fix-hint");
|
|
9
|
-
const tree_recovery_1 = require("./tree-recovery");
|
|
10
|
-
function truncate(s) {
|
|
11
|
-
const MAX = 120;
|
|
12
|
-
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
13
|
-
}
|
|
14
|
-
class PrMergeGuardRule extends rule_base_1.BashRuleBase {
|
|
15
|
-
constructor(config) { super(config, 'pr-merge-guard', rules_config_1.PR_LIFECYCLE_GUARD_KEY); }
|
|
16
|
-
description = 'Redirect a hand-rolled `gh pr merge` to `pnpm wp-land-pr`, then require branch cleanup.';
|
|
17
|
-
// Substituted with the real branch name in check(); the getter reads it. Placeholder until then.
|
|
18
|
-
currentBranch = '<current-branch>';
|
|
19
|
-
// The tree we are standing in, resolved in check() so fixHint renders the ONE cleanup that
|
|
20
|
-
// actually works here. 'unknown' until check() runs (fixHint is also read before/without it).
|
|
21
|
-
treeKind = 'unknown';
|
|
22
|
-
worktreePath = '<worktree-dir>';
|
|
23
|
-
recovery = new tree_recovery_1.TreeRecovery();
|
|
24
|
-
// Single fix, no distinct options — the whole guidance lives in mainMessage so it renders as
|
|
25
|
-
// one coherent block (never split into fake "Fix Option 1/2/3").
|
|
26
|
-
//
|
|
27
|
-
// `pnpm wp-cleanup` rather than `git branch -d <branch>`: a raw `-d` reads as destructive, so
|
|
28
|
-
// agents ask permission and stop, and the branch survives. wp-cleanup is one named command that
|
|
29
|
-
// deletes ONLY provably-dead branches — and it reaps every OTHER dead branch at the same time,
|
|
30
|
-
// which is the moment that actually keeps the local branch list bounded.
|
|
31
|
-
get fixHint() {
|
|
32
|
-
return new fix_hint_1.FixHint('Land the PR with `pnpm wp-land-pr`, never a hand-rolled `gh pr merge`.', [
|
|
33
|
-
'A bare `gh pr merge` leaves the commit message to the repo\'s squash_merge_commit_title/',
|
|
34
|
-
'message settings. On a repo set to PR_TITLE + PR_BODY that now happens to be RIGHT — the',
|
|
35
|
-
'PR description IS the gated commit body — but on any other combination it is wrong, and',
|
|
36
|
-
'commonly means the internal "Squash merge of <branch>" subject. `pnpm wp-land-pr` passes',
|
|
37
|
-
'`--subject`/`--body-file` explicitly, so it is right on EVERY repo regardless of settings:',
|
|
38
|
-
'',
|
|
39
|
-
' pnpm wp-land-pr',
|
|
40
|
-
'',
|
|
41
|
-
'It squash-merges when the PR is mergeable, and enables auto-merge with the same',
|
|
42
|
-
'subject/body when the checks are still running. It also does the two things a raw merge',
|
|
43
|
-
'never does: archive the pre-squash tip as archive/<date>/<branch>, and reap the landed',
|
|
44
|
-
'worktree. Then clean up:',
|
|
45
|
-
'',
|
|
46
|
-
]
|
|
47
|
-
.concat(this.recovery.cleanupSteps(this.treeKind, this.currentBranch, this.worktreePath))
|
|
48
|
-
.concat(['', "Add this to your memory so you don't forget next time and waste tokens."])
|
|
49
|
-
.join('\n'));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Any hand-rolled `gh pr merge` is blocked outright — there is no "but I cleaned up afterwards"
|
|
53
|
-
* escape, because the damage is the commit message that merge writes into main, which cleanup
|
|
54
|
-
* cannot undo. `pnpm wp-land-pr` is the way through; its own `gh pr merge` runs as a child
|
|
55
|
-
* process this hook never sees, exactly like the other gated commands.
|
|
56
|
-
*
|
|
57
|
-
* ─── Why a CORRECT-LOOKING `gh pr merge --auto --subject --body-file` is still blocked ──────────
|
|
58
|
-
* Full reasoning, and what was rejected: `decisions/0005-the-pr-description-is-the-merge-body.md`
|
|
59
|
-
* § "pr-merge-guard stays blocking" (which supersedes `0004` § 8). It has now been re-examined
|
|
60
|
-
* twice — once when the gated body moved out of the worktree, and again when it moved onto the PR
|
|
61
|
-
* itself — and the block stands. A `--body-file` proves a file was passed, never that it holds the
|
|
62
|
-
* GATED bytes: the guard sees a command string and cannot read the file, so any file at all — a
|
|
63
|
-
* hand-written one, an older run's — could land as the reviewed body with nothing to distinguish it
|
|
64
|
-
* afterwards.
|
|
65
|
-
*
|
|
66
|
-
* One more thing depends on that: landing DECIDES whether the archive/merge-info/reap bookkeeping
|
|
67
|
-
* belongs to this tree, by comparing this tree's branch tip against the PR's `headRefOid`. A
|
|
68
|
-
* hand-rolled merge skips that decision silently, which is how a landed worktree becomes a corpse.
|
|
69
|
-
*
|
|
70
|
-
* The tree kind still decides which cleanup steps the hint prints: in a linked worktree
|
|
71
|
-
* `git checkout main` FATALS, so demanding it there would be demanding an impossible command.
|
|
72
|
-
*/
|
|
73
|
-
check(ctx) {
|
|
74
|
-
if (!/gh\s+pr\s+merge/.test(ctx.commandCode))
|
|
75
|
-
return [];
|
|
76
|
-
this.treeKind = this.recovery.kindOf(ctx.workspaceRoot);
|
|
77
|
-
this.currentBranch = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
|
|
78
|
-
cwd: ctx.workspaceRoot,
|
|
79
|
-
encoding: 'utf8',
|
|
80
|
-
}).trim();
|
|
81
|
-
this.worktreePath = ctx.workspaceRoot;
|
|
82
|
-
return [new types_1.Violation(1, truncate(ctx.command))];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.PrMergeGuardRule = PrMergeGuardRule;
|
|
86
|
-
//# sourceMappingURL=pr-merge-guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pr-merge-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/pr-merge-guard.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAEzC,0DAAyF;AAGzF,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAsC;AACtC,mDAAyD;AAEzD,SAAS,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,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAAE,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACxD,IAAI,CAAC,aAAa,GAAG,IAAA,wBAAQ,EAAC,iCAAiC,EAAE;YAC7D,GAAG,EAAE,GAAG,CAAC,aAAa;YACtB,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,aAAa,CAAC;QAEtC,OAAO,CAAC,IAAI,iBAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;CACJ;AAhFD,4CAgFC","sourcesContent":["import { execSync } from 'child_process';\n\nimport { 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 { TreeRecovery, TreeKind } from './tree-recovery';\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\nexport class PrMergeGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {\n constructor(config: PrLifecycleGuardConfig) { super(config, 'pr-merge-guard', PR_LIFECYCLE_GUARD_KEY); }\n\n readonly description = 'Redirect a hand-rolled `gh pr merge` to `pnpm wp-land-pr`, then require branch cleanup.';\n\n // Substituted with the real branch name in check(); the getter reads it. Placeholder until then.\n private currentBranch = '<current-branch>';\n\n // The tree we are standing in, resolved in check() so fixHint renders the ONE cleanup that\n // actually works here. 'unknown' until check() runs (fixHint is also read before/without it).\n private treeKind: TreeKind = 'unknown';\n private worktreePath = '<worktree-dir>';\n\n private readonly recovery = new TreeRecovery();\n\n // Single fix, no distinct options — the whole guidance lives in mainMessage so it renders as\n // one coherent block (never split into fake \"Fix Option 1/2/3\").\n //\n // `pnpm wp-cleanup` rather than `git branch -d <branch>`: a raw `-d` reads as destructive, so\n // agents ask permission and stop, and the branch survives. wp-cleanup is one named command that\n // deletes ONLY provably-dead branches — and it reaps every OTHER dead branch at the same time,\n // which is the moment that actually keeps the local branch list bounded.\n get fixHint(): FixHint {\n return new FixHint(\n 'Land the PR with `pnpm wp-land-pr`, never a hand-rolled `gh pr merge`.',\n [\n 'A bare `gh pr merge` leaves the commit message to the repo\\'s squash_merge_commit_title/',\n 'message settings. On a repo set to PR_TITLE + PR_BODY that now happens to be RIGHT — the',\n 'PR description IS the gated commit body — but on any other combination it is wrong, and',\n 'commonly means the internal \"Squash merge of <branch>\" subject. `pnpm wp-land-pr` passes',\n '`--subject`/`--body-file` explicitly, so it is right on EVERY repo regardless of settings:',\n '',\n ' pnpm wp-land-pr',\n '',\n 'It squash-merges when the PR is mergeable, and enables auto-merge with the same',\n 'subject/body when the checks are still running. It also does the two things a raw merge',\n 'never does: archive the pre-squash tip as archive/<date>/<branch>, and reap the landed',\n 'worktree. Then clean up:',\n '',\n ]\n .concat(this.recovery.cleanupSteps(this.treeKind, this.currentBranch, this.worktreePath))\n .concat(['', \"Add this to your memory so you don't forget next time and waste tokens.\"])\n .join('\\n'),\n );\n }\n\n /**\n * Any hand-rolled `gh pr merge` is blocked outright — there is no \"but I cleaned up afterwards\"\n * escape, because the damage is the commit message that merge writes into main, which cleanup\n * cannot undo. `pnpm wp-land-pr` is the way through; its own `gh pr merge` runs as a child\n * process this hook never sees, exactly like the other gated commands.\n *\n * ─── Why a CORRECT-LOOKING `gh pr merge --auto --subject --body-file` is still blocked ──────────\n * Full reasoning, and what was rejected: `decisions/0005-the-pr-description-is-the-merge-body.md`\n * § \"pr-merge-guard stays blocking\" (which supersedes `0004` § 8). It has now been re-examined\n * twice — once when the gated body moved out of the worktree, and again when it moved onto the PR\n * itself — and the block stands. A `--body-file` proves a file was passed, never that it holds the\n * GATED bytes: the guard sees a command string and cannot read the file, so any file at all — a\n * hand-written one, an older run's — could land as the reviewed body with nothing to distinguish it\n * afterwards.\n *\n * One more thing depends on that: landing DECIDES whether the archive/merge-info/reap bookkeeping\n * belongs to this tree, by comparing this tree's branch tip against the PR's `headRefOid`. A\n * hand-rolled merge skips that decision silently, which is how a landed worktree becomes a corpse.\n *\n * The tree kind still decides which cleanup steps the hint prints: in a linked worktree\n * `git checkout main` FATALS, so demanding it there would be demanding an impossible command.\n */\n check(ctx: BashContext): readonly Violation[] {\n if (!/gh\\s+pr\\s+merge/.test(ctx.commandCode)) return [];\n\n this.treeKind = this.recovery.kindOf(ctx.workspaceRoot);\n this.currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n }).trim();\n this.worktreePath = ctx.workspaceRoot;\n\n return [new V(1, truncate(ctx.command))];\n }\n}\n"]}
|