@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,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecoveryAllowlist = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const shell_segment_scan_1 = require("./shell-segment-scan");
|
|
7
|
-
const content_read_scan_1 = require("./content-read-scan");
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// THE SKIP LIST — L2 row 4, as one implementation.
|
|
10
|
-
//
|
|
11
|
-
// "These get you OUT, or tell you where you are." That is the whole principle: a command on this list
|
|
12
|
-
// is not "working here", so it is safe in every state where working here is not.
|
|
13
|
-
//
|
|
14
|
-
// It was written for state B (a merged branch) and lived inside merged-branch-bash-guard. Row 5 —
|
|
15
|
-
// on `main` — needs the identical question answered, and the answer must not be a second copy: two
|
|
16
|
-
// skip lists drift, and the half that drifts is the half that wedges a session on its own cure. So the
|
|
17
|
-
// list is ONE class, and both guards ask it.
|
|
18
|
-
//
|
|
19
|
-
// This is the DEFAULT-DENY half of L2. Its sibling ContentReadScan is the default-ALLOW blocklist used
|
|
20
|
-
// where only stale CONTENT is the hazard. The guards docblock is right that the two polarities cannot
|
|
21
|
-
// collapse into one function — but the allowlist itself was never the reason they could not, and
|
|
22
|
-
// sharing it is what makes row 5's `B` half affordable at all.
|
|
23
|
-
//
|
|
24
|
-
// WHAT BELONGS ON THIS LIST — one question, asked of the COMMAND, not of your sympathy for it:
|
|
25
|
-
// **does it read or write repo content?** If it cannot do either, it cannot be "working here", so it
|
|
26
|
-
// belongs here regardless of what else it does. That is why `curl`/`wget` and `gh` are on it: they talk
|
|
27
|
-
// to a network, not to the working tree, and a session parked in an L2 state still has to be able to
|
|
28
|
-
// close a PR, comment on one, or fetch a URL. It is also why the exclusions are the FORMS that write a
|
|
29
|
-
// local file (`curl -o`, `gh repo clone`, `gh pr checkout`, any `> file` redirect) rather than whole
|
|
30
|
-
// programs: the write is the hazard, not the binary.
|
|
31
|
-
//
|
|
32
|
-
// EVERY segment must pass. One `… && scripts/local.sh start` in a chain denies the whole command,
|
|
33
|
-
// because the chain runs it. Segments are judged by ROLE first: shell STRUCTURE (`for … in`, `do`,
|
|
34
|
-
// `done`) invokes nothing and output SHAPING (`| tail -40`) cannot touch the repo, so neither may veto
|
|
35
|
-
// a chain — judging the raw string instead is what once made the guard reject
|
|
36
|
-
// `git fetch origin main 2>&1 | tail -5`, a command its own redirect had just prescribed.
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
class RecoveryAllowlist {
|
|
39
|
-
scanner;
|
|
40
|
-
shell;
|
|
41
|
-
constructor(scanner) {
|
|
42
|
-
this.scanner = scanner;
|
|
43
|
-
this.shell = new shell_segment_scan_1.ShellSegmentScan(scanner);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Is EVERY segment of this command one that gets you out, or tells you where you are?
|
|
47
|
-
*
|
|
48
|
-
* An empty command is `false` — nothing to be sure about, and the default here is deny. (Note this
|
|
49
|
-
* is one of the three places the two Bash guards genuinely differ; the stale-main blocklist allows
|
|
50
|
-
* the empty command because its default is the other way round.)
|
|
51
|
-
*/
|
|
52
|
-
isFullyRecovery(ctx) {
|
|
53
|
-
const segments = this.scanner.segmentsWithJoins(ctx.command);
|
|
54
|
-
if (segments.length === 0)
|
|
55
|
-
return false;
|
|
56
|
-
const content = new content_read_scan_1.ContentReadScan(this.scanner, ctx.workspaceRoot, ctx.effectiveCwd);
|
|
57
|
-
return segments.every((segment) => this.isRecoverySegment(segment, content));
|
|
58
|
-
}
|
|
59
|
-
isRecoverySegment(segment, content) {
|
|
60
|
-
const verdict = this.shell.classify(segment);
|
|
61
|
-
if (verdict.role === 'structure')
|
|
62
|
-
return true;
|
|
63
|
-
// Inert / piped-into filters are fine EXCEPT when they name a workspace path: `git status |
|
|
64
|
-
// cat src/foo.ts` still hands the agent file content out of a tree it should not be reading.
|
|
65
|
-
if (verdict.role === 'shaping')
|
|
66
|
-
return content.readsStaleContent(segment) === null;
|
|
67
|
-
// A read that names NOTHING in this tree cannot be affected by which branch this tree is on.
|
|
68
|
-
// `ls -la ~/.claude/projects/ | grep -i foo` was blocked as "this branch is merged" — the
|
|
69
|
-
// command touches no repo at all. Only CONTENT READERS qualify, so a build, a server or a git
|
|
70
|
-
// write never slips through on the strength of its paths.
|
|
71
|
-
if (content.readsOnlyOutsideContent(segment))
|
|
72
|
-
return true;
|
|
73
|
-
// A segment that reads CONTENT out of this tree is never "getting you out", whatever command
|
|
74
|
-
// it is spelled as. This must come BEFORE the git allowlist, because `show` and `grep` are on
|
|
75
|
-
// that list for their metadata/upstream forms and would otherwise wave through the two git
|
|
76
|
-
// spellings of a local content read: `git show HEAD:package.json` and `git grep TODO`. Their
|
|
77
|
-
// upstream forms (`git show origin/main:…`, `git grep TODO origin/main`) read the CURRENT tree
|
|
78
|
-
// and ContentReadScan already returns null for those, so they stay allowed — which is the
|
|
79
|
-
// point, since reading upstream is exactly what a blocked agent should be doing.
|
|
80
|
-
if (content.readsStaleContent(segment) !== null)
|
|
81
|
-
return false;
|
|
82
|
-
const gitSub = this.scanner.gitSubcommandOf(verdict.words);
|
|
83
|
-
if (gitSub !== null)
|
|
84
|
-
return ALLOWED_GIT_SUBCOMMANDS.has(gitSub);
|
|
85
|
-
if (this.isGh(verdict))
|
|
86
|
-
return true;
|
|
87
|
-
if (this.isNetworkClient(verdict))
|
|
88
|
-
return true;
|
|
89
|
-
return this.isPackageRecovery(verdict);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* `gh` GENERALLY — it talks to GitHub, not to the working tree.
|
|
93
|
-
*
|
|
94
|
-
* This used to be an allowlist of read-only actions (`gh pr view|list|status|checks`, `gh run
|
|
95
|
-
* view`), which fell over the moment an agent needed `gh pr close`, `gh pr comment` or `gh api`
|
|
96
|
-
* from a parked session: those change something on GitHub and NOTHING in this tree, so the branch
|
|
97
|
-
* state cannot be an argument against them. The exclusions are therefore the `gh` subcommands that
|
|
98
|
-
* write LOCAL files — a clone, a checkout, a download — plus any segment carrying a `> file`
|
|
99
|
-
* redirect.
|
|
100
|
-
*
|
|
101
|
-
* gh commands that are wrong for OTHER reasons stay wrong: `gh pr create`/`push` is governed by
|
|
102
|
-
* pr-creation-or-push-guard and `gh pr merge` by pr-merge-guard. Those are separate policies and
|
|
103
|
-
* this list was never what enforced them.
|
|
104
|
-
*
|
|
105
|
-
* YES, THIS ONE SUBLIST IS A BLOCKLIST, and that is the opposite polarity to the guard around it.
|
|
106
|
-
* The argument against a blocklist elsewhere is that the hazardous set is UNBOUNDED — any program
|
|
107
|
-
* can write a file as a side effect of doing something else, so no enumeration could ever be
|
|
108
|
-
* complete. `gh`'s surface is not: it is one vendor's CLI, its verbs are documented, and writing
|
|
109
|
-
* into the working tree is the rare exception rather than the ambient default. A new `gh`
|
|
110
|
-
* subcommand that clones or downloads is a known, greppable maintenance point — `GH_LOCAL_FILE_WRITES`
|
|
111
|
-
* — where "every future program that might write" is not.
|
|
112
|
-
*/
|
|
113
|
-
isGh(verdict) {
|
|
114
|
-
const words = verdict.words;
|
|
115
|
-
if (words.length === 0 || path.basename(words[0]) !== 'gh')
|
|
116
|
-
return false;
|
|
117
|
-
if (this.shell.redirectsToFile(words))
|
|
118
|
-
return false;
|
|
119
|
-
const top = words[1];
|
|
120
|
-
if (top === undefined)
|
|
121
|
-
return false;
|
|
122
|
-
const action = words[2];
|
|
123
|
-
const localWrites = GH_LOCAL_FILE_WRITES.get(top);
|
|
124
|
-
if (localWrites === undefined)
|
|
125
|
-
return true;
|
|
126
|
-
return action === undefined || !localWrites.has(action);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* `curl` / `wget` — a network fetch reads a URL, not this repo.
|
|
130
|
-
*
|
|
131
|
-
* Excluded: the forms that name a local FILE to write (`curl -o`, `curl -O`, `wget -O`, an
|
|
132
|
-
* `--output-dir`/`-P`, or a `> file` redirect), because those are how a fetch becomes a write into
|
|
133
|
-
* the tree. A bare `wget <url>` still drops its download into the cwd; that CREATES an untracked
|
|
134
|
-
* file rather than modifying tracked content, which is the line this list draws everywhere else.
|
|
135
|
-
*/
|
|
136
|
-
isNetworkClient(verdict) {
|
|
137
|
-
const words = verdict.words;
|
|
138
|
-
if (words.length === 0 || !NETWORK_CLIENTS.has(path.basename(words[0])))
|
|
139
|
-
return false;
|
|
140
|
-
if (this.shell.redirectsToFile(words))
|
|
141
|
-
return false;
|
|
142
|
-
return !words.some((word) => OUTPUT_FILE_FLAGS.has(word));
|
|
143
|
-
}
|
|
144
|
-
// pnpm/npm/yarn recovery bins: the `wp-*` cleanup/gated commands and package installs (a chained
|
|
145
|
-
// install that isInstallerCommand — the pure-install bypass — did not catch reaches here).
|
|
146
|
-
isPackageRecovery(verdict) {
|
|
147
|
-
const words = verdict.words;
|
|
148
|
-
if (words.length === 0 || !PACKAGE_MANAGERS.has(words[0]))
|
|
149
|
-
return false;
|
|
150
|
-
return words.slice(1).some((word) => /^wp-[a-z-]+$/.test(word) || PACKAGE_INSTALL_VERBS.has(word));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.RecoveryAllowlist = RecoveryAllowlist;
|
|
154
|
-
const ALLOWED_GIT_SUBCOMMANDS = new Set([
|
|
155
|
-
'status', 'log', 'diff', 'show', 'branch', 'checkout', 'switch', 'worktree', 'fetch', 'pull',
|
|
156
|
-
'rev-parse', 'rev-list', 'merge-base', 'ls-files', 'ls-tree', 'cat-file', 'for-each-ref',
|
|
157
|
-
'symbolic-ref', 'describe', 'name-rev', 'reflog', 'shortlog', 'remote', 'config', 'stash', 'tag',
|
|
158
|
-
'blame', 'whatchanged', 'cherry',
|
|
159
|
-
// `grep` is here ONLY for its upstream form (`git grep TODO origin/main`), which reads the CURRENT
|
|
160
|
-
// tree and is what a blocked agent should be reaching for. The local form is rejected one check
|
|
161
|
-
// earlier by ContentReadScan, as is `show <local-rev>:<path>`.
|
|
162
|
-
'grep',
|
|
163
|
-
]);
|
|
164
|
-
// The `gh` subcommands that write LOCAL files — the only ones the branch state has anything to say
|
|
165
|
-
// about. Everything else `gh` does happens on GitHub's side. (`gh pr create` / `gh pr merge` are absent
|
|
166
|
-
// on purpose: they are remote calls, and their policies live in pr-creation-or-push-guard and
|
|
167
|
-
// pr-merge-guard, which run whatever this list says.)
|
|
168
|
-
const GH_LOCAL_FILE_WRITES = new Map([
|
|
169
|
-
['repo', new Set(['clone', 'fork', 'sync'])],
|
|
170
|
-
['pr', new Set(['checkout'])],
|
|
171
|
-
['run', new Set(['download'])],
|
|
172
|
-
['release', new Set(['download'])],
|
|
173
|
-
['gist', new Set(['clone'])],
|
|
174
|
-
['codespace', new Set(['cp'])],
|
|
175
|
-
['attestation', new Set(['download'])],
|
|
176
|
-
]);
|
|
177
|
-
// Network clients: they read a URL, not the tree.
|
|
178
|
-
const NETWORK_CLIENTS = new Set(['curl', 'wget']);
|
|
179
|
-
// The flags that turn a fetch into a local file write. `-O` is curl's remote-name AND wget's
|
|
180
|
-
// output-document; both write, so one entry covers both.
|
|
181
|
-
const OUTPUT_FILE_FLAGS = new Set([
|
|
182
|
-
'-o', '--output', '-O', '--remote-name', '--remote-name-all', '--output-dir', '--create-dirs',
|
|
183
|
-
'--output-document', '-P', '--directory-prefix',
|
|
184
|
-
]);
|
|
185
|
-
const PACKAGE_MANAGERS = new Set(['pnpm', 'npm', 'npx', 'pnpx', 'yarn']);
|
|
186
|
-
const PACKAGE_INSTALL_VERBS = new Set(['install', 'ci', 'add', 'i']);
|
|
187
|
-
//# sourceMappingURL=recovery-allowlist.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-allowlist.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/recovery-allowlist.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAI7B,6DAAwE;AACxE,2DAAsD;AAEtD,8EAA8E;AAC9E,mDAAmD;AACnD,EAAE;AACF,sGAAsG;AACtG,iFAAiF;AACjF,EAAE;AACF,kGAAkG;AAClG,mGAAmG;AACnG,uGAAuG;AACvG,6CAA6C;AAC7C,EAAE;AACF,uGAAuG;AACvG,sGAAsG;AACtG,iGAAiG;AACjG,+DAA+D;AAC/D,EAAE;AACF,+FAA+F;AAC/F,qGAAqG;AACrG,wGAAwG;AACxG,qGAAqG;AACrG,uGAAuG;AACvG,qGAAqG;AACrG,qDAAqD;AACrD,EAAE;AACF,kGAAkG;AAClG,mGAAmG;AACnG,uGAAuG;AACvG,8EAA8E;AAC9E,0FAA0F;AAC1F,8EAA8E;AAC9E,MAAa,iBAAiB;IACT,OAAO,CAAiB;IACxB,KAAK,CAAmB;IAEzC,YAAY,OAAuB;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,GAAgB;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7D,IAAI,QAAQ,CAAC,MAAM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C;IAC5C,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7B,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9B,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAClC,CAAC,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5B,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9B,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACzC,CAAC,CAAC;AAEH,kDAAkD;AAClD,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACvE,6FAA6F;AAC7F,yDAAyD;AACzD,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACnD,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe;IAC7F,mBAAmB,EAAE,IAAI,EAAE,oBAAoB;CAClD,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC9F,MAAM,qBAAqB,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC","sourcesContent":["import * as path from 'path';\n\nimport type { BashContext } from '../types';\nimport { CommandScanner, CommandSegment } from '../command-scan';\nimport { ShellSegmentScan, SegmentVerdict } from './shell-segment-scan';\nimport { ContentReadScan } from './content-read-scan';\n\n// ---------------------------------------------------------------------------\n// THE SKIP LIST — L2 row 4, as one implementation.\n//\n// \"These get you OUT, or tell you where you are.\" That is the whole principle: a command on this list\n// is not \"working here\", so it is safe in every state where working here is not.\n//\n// It was written for state B (a merged branch) and lived inside merged-branch-bash-guard. Row 5 —\n// on `main` — needs the identical question answered, and the answer must not be a second copy: two\n// skip lists drift, and the half that drifts is the half that wedges a session on its own cure. So the\n// list is ONE class, and both guards ask it.\n//\n// This is the DEFAULT-DENY half of L2. Its sibling ContentReadScan is the default-ALLOW blocklist used\n// where only stale CONTENT is the hazard. The guards docblock is right that the two polarities cannot\n// collapse into one function — but the allowlist itself was never the reason they could not, and\n// sharing it is what makes row 5's `B` half affordable at all.\n//\n// WHAT BELONGS ON THIS LIST — one question, asked of the COMMAND, not of your sympathy for it:\n// **does it read or write repo content?** If it cannot do either, it cannot be \"working here\", so it\n// belongs here regardless of what else it does. That is why `curl`/`wget` and `gh` are on it: they talk\n// to a network, not to the working tree, and a session parked in an L2 state still has to be able to\n// close a PR, comment on one, or fetch a URL. It is also why the exclusions are the FORMS that write a\n// local file (`curl -o`, `gh repo clone`, `gh pr checkout`, any `> file` redirect) rather than whole\n// programs: the write is the hazard, not the binary.\n//\n// EVERY segment must pass. One `… && scripts/local.sh start` in a chain denies the whole command,\n// because the chain runs it. Segments are judged by ROLE first: shell STRUCTURE (`for … in`, `do`,\n// `done`) invokes nothing and output SHAPING (`| tail -40`) cannot touch the repo, so neither may veto\n// a chain — judging the raw string instead is what once made the guard reject\n// `git fetch origin main 2>&1 | tail -5`, a command its own redirect had just prescribed.\n// ---------------------------------------------------------------------------\nexport class RecoveryAllowlist {\n private readonly scanner: CommandScanner;\n private readonly shell: ShellSegmentScan;\n\n constructor(scanner: CommandScanner) {\n this.scanner = scanner;\n this.shell = new ShellSegmentScan(scanner);\n }\n\n /**\n * Is EVERY segment of this command one that gets you out, or tells you where you are?\n *\n * An empty command is `false` — nothing to be sure about, and the default here is deny. (Note this\n * is one of the three places the two Bash guards genuinely differ; the stale-main blocklist allows\n * the empty command because its default is the other way round.)\n */\n isFullyRecovery(ctx: BashContext): boolean {\n const segments = this.scanner.segmentsWithJoins(ctx.command);\n if (segments.length === 0) return false;\n const content = new ContentReadScan(this.scanner, ctx.workspaceRoot, ctx.effectiveCwd);\n return segments.every((segment: CommandSegment): boolean => this.isRecoverySegment(segment, content));\n }\n\n private isRecoverySegment(segment: CommandSegment, content: ContentReadScan): boolean {\n const verdict = this.shell.classify(segment);\n if (verdict.role === 'structure') return true;\n // Inert / piped-into filters are fine EXCEPT when they name a workspace path: `git status |\n // cat src/foo.ts` still hands the agent file content out of a tree it should not be reading.\n if (verdict.role === 'shaping') return content.readsStaleContent(segment) === null;\n\n // A read that names NOTHING in this tree cannot be affected by which branch this tree is on.\n // `ls -la ~/.claude/projects/ | grep -i foo` was blocked as \"this branch is merged\" — the\n // command touches no repo at all. Only CONTENT READERS qualify, so a build, a server or a git\n // write never slips through on the strength of its paths.\n if (content.readsOnlyOutsideContent(segment)) return true;\n\n // A segment that reads CONTENT out of this tree is never \"getting you out\", whatever command\n // it is spelled as. This must come BEFORE the git allowlist, because `show` and `grep` are on\n // that list for their metadata/upstream forms and would otherwise wave through the two git\n // spellings of a local content read: `git show HEAD:package.json` and `git grep TODO`. Their\n // upstream forms (`git show origin/main:…`, `git grep TODO origin/main`) read the CURRENT tree\n // and ContentReadScan already returns null for those, so they stay allowed — which is the\n // point, since reading upstream is exactly what a blocked agent should be doing.\n if (content.readsStaleContent(segment) !== null) return false;\n\n const gitSub = this.scanner.gitSubcommandOf(verdict.words);\n if (gitSub !== null) return ALLOWED_GIT_SUBCOMMANDS.has(gitSub);\n if (this.isGh(verdict)) return true;\n if (this.isNetworkClient(verdict)) return true;\n return this.isPackageRecovery(verdict);\n }\n\n /**\n * `gh` GENERALLY — it talks to GitHub, not to the working tree.\n *\n * This used to be an allowlist of read-only actions (`gh pr view|list|status|checks`, `gh run\n * view`), which fell over the moment an agent needed `gh pr close`, `gh pr comment` or `gh api`\n * from a parked session: those change something on GitHub and NOTHING in this tree, so the branch\n * state cannot be an argument against them. The exclusions are therefore the `gh` subcommands that\n * write LOCAL files — a clone, a checkout, a download — plus any segment carrying a `> file`\n * redirect.\n *\n * gh commands that are wrong for OTHER reasons stay wrong: `gh pr create`/`push` is governed by\n * pr-creation-or-push-guard and `gh pr merge` by pr-merge-guard. Those are separate policies and\n * this list was never what enforced them.\n *\n * YES, THIS ONE SUBLIST IS A BLOCKLIST, and that is the opposite polarity to the guard around it.\n * The argument against a blocklist elsewhere is that the hazardous set is UNBOUNDED — any program\n * can write a file as a side effect of doing something else, so no enumeration could ever be\n * complete. `gh`'s surface is not: it is one vendor's CLI, its verbs are documented, and writing\n * into the working tree is the rare exception rather than the ambient default. A new `gh`\n * subcommand that clones or downloads is a known, greppable maintenance point — `GH_LOCAL_FILE_WRITES`\n * — where \"every future program that might write\" is not.\n */\n private isGh(verdict: SegmentVerdict): boolean {\n const words = verdict.words;\n if (words.length === 0 || path.basename(words[0]) !== 'gh') return false;\n if (this.shell.redirectsToFile(words)) return false;\n const top = words[1];\n if (top === undefined) return false;\n const action = words[2];\n const localWrites = GH_LOCAL_FILE_WRITES.get(top);\n if (localWrites === undefined) return true;\n return action === undefined || !localWrites.has(action);\n }\n\n /**\n * `curl` / `wget` — a network fetch reads a URL, not this repo.\n *\n * Excluded: the forms that name a local FILE to write (`curl -o`, `curl -O`, `wget -O`, an\n * `--output-dir`/`-P`, or a `> file` redirect), because those are how a fetch becomes a write into\n * the tree. A bare `wget <url>` still drops its download into the cwd; that CREATES an untracked\n * file rather than modifying tracked content, which is the line this list draws everywhere else.\n */\n private isNetworkClient(verdict: SegmentVerdict): boolean {\n const words = verdict.words;\n if (words.length === 0 || !NETWORK_CLIENTS.has(path.basename(words[0]))) return false;\n if (this.shell.redirectsToFile(words)) return false;\n return !words.some((word: string): boolean => OUTPUT_FILE_FLAGS.has(word));\n }\n\n // pnpm/npm/yarn recovery bins: the `wp-*` cleanup/gated commands and package installs (a chained\n // install that isInstallerCommand — the pure-install bypass — did not catch reaches here).\n private isPackageRecovery(verdict: SegmentVerdict): boolean {\n const words = verdict.words;\n if (words.length === 0 || !PACKAGE_MANAGERS.has(words[0])) return false;\n return words.slice(1).some((word: string): boolean =>\n /^wp-[a-z-]+$/.test(word) || PACKAGE_INSTALL_VERBS.has(word));\n }\n}\n\nconst ALLOWED_GIT_SUBCOMMANDS: ReadonlySet<string> = new Set([\n 'status', 'log', 'diff', 'show', 'branch', 'checkout', 'switch', 'worktree', 'fetch', 'pull',\n 'rev-parse', 'rev-list', 'merge-base', 'ls-files', 'ls-tree', 'cat-file', 'for-each-ref',\n 'symbolic-ref', 'describe', 'name-rev', 'reflog', 'shortlog', 'remote', 'config', 'stash', 'tag',\n 'blame', 'whatchanged', 'cherry',\n // `grep` is here ONLY for its upstream form (`git grep TODO origin/main`), which reads the CURRENT\n // tree and is what a blocked agent should be reaching for. The local form is rejected one check\n // earlier by ContentReadScan, as is `show <local-rev>:<path>`.\n 'grep',\n]);\n\n// The `gh` subcommands that write LOCAL files — the only ones the branch state has anything to say\n// about. Everything else `gh` does happens on GitHub's side. (`gh pr create` / `gh pr merge` are absent\n// on purpose: they are remote calls, and their policies live in pr-creation-or-push-guard and\n// pr-merge-guard, which run whatever this list says.)\nconst GH_LOCAL_FILE_WRITES: ReadonlyMap<string, ReadonlySet<string>> = new Map([\n ['repo', new Set(['clone', 'fork', 'sync'])],\n ['pr', new Set(['checkout'])],\n ['run', new Set(['download'])],\n ['release', new Set(['download'])],\n ['gist', new Set(['clone'])],\n ['codespace', new Set(['cp'])],\n ['attestation', new Set(['download'])],\n]);\n\n// Network clients: they read a URL, not the tree.\nconst NETWORK_CLIENTS: ReadonlySet<string> = new Set(['curl', 'wget']);\n// The flags that turn a fetch into a local file write. `-O` is curl's remote-name AND wget's\n// output-document; both write, so one entry covers both.\nconst OUTPUT_FILE_FLAGS: ReadonlySet<string> = new Set([\n '-o', '--output', '-O', '--remote-name', '--remote-name-all', '--output-dir', '--create-dirs',\n '--output-document', '-P', '--directory-prefix',\n]);\n\nconst PACKAGE_MANAGERS: ReadonlySet<string> = new Set(['pnpm', 'npm', 'npx', 'pnpx', 'yarn']);\nconst PACKAGE_INSTALL_VERBS: ReadonlySet<string> = new Set(['install', 'ci', 'add', 'i']);\n"]}
|
|
@@ -1,16 +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 RedirectHowToMergeMainRule extends BashRuleBase<PrLifecycleGuardConfig> {
|
|
6
|
-
private readonly scanner;
|
|
7
|
-
private readonly recovery;
|
|
8
|
-
private readonly switches;
|
|
9
|
-
constructor(config: PrLifecycleGuardConfig);
|
|
10
|
-
readonly description = "Block ALL `git merge`/`git rebase` (any branch, any form) and `git pull origin main` on a feature branch. Use the squash-update process instead.";
|
|
11
|
-
readonly fixHint: FixHint;
|
|
12
|
-
check(ctx: BashContext): readonly Violation[];
|
|
13
|
-
private checkSegment;
|
|
14
|
-
private checkPull;
|
|
15
|
-
private block;
|
|
16
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedirectHowToMergeMainRule = 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 command_scan_1 = require("../command-scan");
|
|
10
|
-
const tree_recovery_1 = require("./tree-recovery");
|
|
11
|
-
const branch_switch_scan_1 = require("./branch-switch-scan");
|
|
12
|
-
const INSTRUCT_FILE = 'webpieces.git-workflow.md';
|
|
13
|
-
const GUIDANCE = new rules_config_1.SyncFlowGuidance();
|
|
14
|
-
const FIX_HINT = new fix_hint_1.FixHint('`git merge` / `git rebase` are never run by AI — on any branch, in any form.', 'To bring main\'s changes into your feature branch:\n'
|
|
15
|
-
+ '\n'
|
|
16
|
-
+ GUIDANCE.flows().join('\n') + '\n'
|
|
17
|
-
+ '\n'
|
|
18
|
-
// The fork-point DERIVATION (why the invariant has two halves, and the three consumers a polluted
|
|
19
|
-
// fork point corrupts) and the WORD-FOR-WORD warning to hand the human are NOT here on purpose.
|
|
20
|
-
// Both are stated in full in the git-workflow doc this hint links by absolute path, and a message
|
|
21
|
-
// that re-derives what the linked doc already says is a second copy to keep in step. What survives
|
|
22
|
-
// here is only what changes what the AI types next.
|
|
23
|
-
+ 'Either flow does a 3-point merge, which keeps the fork point a pure main commit — what the build\n'
|
|
24
|
-
+ 'gate\'s --base and the PR review diff are computed from; a raw merge/rebase destroys it. The\n'
|
|
25
|
-
+ 'gated commands merge internally as child processes this hook never sees.\n'
|
|
26
|
-
+ '\n'
|
|
27
|
-
+ GUIDANCE.readOnlyChecks().join('\n') + '\n'
|
|
28
|
-
+ '\n'
|
|
29
|
-
// The "do not run it, ask the human, tell them to push back" instruction is NOT repeated here: the
|
|
30
|
-
// violation line the AI reads first already says it. This paragraph's job is only the pointer.
|
|
31
|
-
// The liveness phrase is kept on ONE line deliberately: it is asserted in full, and a wrap would
|
|
32
|
-
// split the assertion's substring across two chunks. The retired wording ("a branch you do not own")
|
|
33
|
-
// was pinned only by a `never sync a branch` PREFIX, which passed under both framings — which is how
|
|
34
|
-
// this hint kept teaching the removed rule after the doc it links had replaced it.
|
|
35
|
-
+ 'READ the instruct-ai git-workflow doc at the absolute path on the violation line above — the full\n'
|
|
36
|
-
+ 'flow (incl. worktrees), the fork-point invariant, why you must\n'
|
|
37
|
-
+ 'never sync a branch something is ACTIVELY holding (liveness, not authorship — a finished agent\n'
|
|
38
|
-
+ 'holds nothing), and the exact words to warn a human with when you ask them to run a merge.\n'
|
|
39
|
-
// NOT "add that info to memory": "that info" was the whole git-workflow doc, which is REGENERATED
|
|
40
|
-
// per repo and per version — memorizing it guarantees a stale recall in the next session. Only the
|
|
41
|
-
// invariant is stable enough to persist; the doc must be re-read, never remembered.
|
|
42
|
-
+ 'Add to memory: never run a raw `git merge`/`git rebase` — use this repo\'s gated sync flow and\n'
|
|
43
|
-
+ 're-read its git-workflow doc each time rather than recalling it (regenerated per repo/version).');
|
|
44
|
-
// `git merge --abort` / `git rebase --abort|--quit` UNDO an in-progress operation — they cannot create
|
|
45
|
-
// a merge commit or rewrite history, so they cannot violate the fork-point invariant this rule
|
|
46
|
-
// protects. They stay allowed so a repo left mid-operation (e.g. by a human-run rebase) can still be
|
|
47
|
-
// cleaned up. `--continue` is deliberately NOT here: it COMPLETES the operation.
|
|
48
|
-
const UNDO_FLAG = /--(?:abort|quit)\b/;
|
|
49
|
-
// Typed as a query ("would this fast-forward?"), but a successful --ff-only IS the merge.
|
|
50
|
-
const FF_ONLY = /--ff-only\b/;
|
|
51
|
-
function truncate(s) {
|
|
52
|
-
const MAX = 120;
|
|
53
|
-
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
54
|
-
}
|
|
55
|
-
class RedirectHowToMergeMainRule extends rule_base_1.BashRuleBase {
|
|
56
|
-
scanner = new command_scan_1.CommandScanner();
|
|
57
|
-
recovery = new tree_recovery_1.TreeRecovery();
|
|
58
|
-
// "Which branch does this land on?" — see branch-switch-scan.ts. It replaced a pair of regexes
|
|
59
|
-
// here (`/git\s+(?:checkout|switch)\s+main\b/` and its negative-lookahead twin) that assumed the
|
|
60
|
-
// branch name is the token immediately after the subcommand. One flag broke both halves at once:
|
|
61
|
-
// `git checkout -q main && git pull -q origin main` missed the main EXEMPTION and then tripped the
|
|
62
|
-
// feature-switch block, so this guard rejected the very command stale-main-bash-guard prescribes,
|
|
63
|
-
// with a reason ("switches to a feature branch") that was the opposite of the truth.
|
|
64
|
-
switches = new branch_switch_scan_1.BranchSwitchScan(this.scanner);
|
|
65
|
-
constructor(config) { super(config, 'redirect-how-to-merge-main', rules_config_1.PR_LIFECYCLE_GUARD_KEY); }
|
|
66
|
-
description = 'Block ALL `git merge`/`git rebase` (any branch, any form) and `git pull origin main` on a feature branch. Use the squash-update process instead.';
|
|
67
|
-
fixHint = FIX_HINT;
|
|
68
|
-
check(ctx) {
|
|
69
|
-
for (const segment of this.scanner.commandSegments(ctx.command)) {
|
|
70
|
-
const violation = this.checkSegment(ctx, segment);
|
|
71
|
-
if (violation !== null)
|
|
72
|
-
return [violation];
|
|
73
|
-
}
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
checkSegment(ctx, segment) {
|
|
77
|
-
// 1. merge/rebase: unconditional block. Deliberately NO branch lookup.
|
|
78
|
-
//
|
|
79
|
-
// This rule used to read hook-time HEAD and bail out when it was `main`. But a PreToolUse hook
|
|
80
|
-
// runs BEFORE the command, so HEAD-at-hook-time is a value the command itself is about to
|
|
81
|
-
// change: `git checkout feat && git rebase main`, issued while HEAD was still `main` from a
|
|
82
|
-
// prior cleanup, read as "we're on main, this is fine" and was waved through. That is the
|
|
83
|
-
// incident this rule exists to prevent. Since merge/rebase have no legitimate AI-run form on
|
|
84
|
-
// ANY branch, there is no branch to consult — and so no HEAD to spoof.
|
|
85
|
-
if (this.scanner.invokesGit(segment, 'merge') || this.scanner.invokesGit(segment, 'rebase')) {
|
|
86
|
-
if (UNDO_FLAG.test(segment))
|
|
87
|
-
return null;
|
|
88
|
-
// `--ff-only` reads like a probe ("can I fast-forward?") but it MUTATES whenever the answer
|
|
89
|
-
// is yes, so say that here — the AI that typed it was usually only trying to look.
|
|
90
|
-
const probe = FF_ONLY.test(segment)
|
|
91
|
-
? ' `--ff-only` is NOT a read-only check — it moves your branch whenever it succeeds; see the read-only checks below.'
|
|
92
|
-
: '';
|
|
93
|
-
return this.block(ctx, segment, 'Direct `git merge`/`git rebase` is blocked — AI never runs it, on any branch.' + probe);
|
|
94
|
-
}
|
|
95
|
-
// 2. pull: unlike merge/rebase this DOES retain a legitimate on-main form
|
|
96
|
-
// (`git checkout main && git pull origin main`), so it must consult the branch — which is
|
|
97
|
-
// exactly why it also needs the branch-switch check that (1) no longer requires.
|
|
98
|
-
if (this.scanner.invokesGit(segment, 'pull') && /\borigin\s+main\b/.test(segment)) {
|
|
99
|
-
return this.checkPull(ctx, segment);
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
checkPull(ctx, segment) {
|
|
104
|
-
// The two branch questions are COMPLEMENTS of one parse, so they are asked of one parse —
|
|
105
|
-
// that is what keeps them from disagreeing. `git branch -D <x>` is not a checkout so it does
|
|
106
|
-
// not trip this, and `git checkout -` (previous branch, unknowable at hook time) lands
|
|
107
|
-
// nowhere we can name, so it counts as neither.
|
|
108
|
-
const switches = this.switches.switchesIn(ctx.command);
|
|
109
|
-
if (switches.some((s) => !this.switches.isExistingMain(s))) {
|
|
110
|
-
return this.block(ctx, segment, 'Blocked: this command switches to a feature branch and then pulls main into it.');
|
|
111
|
-
}
|
|
112
|
-
// The hand-rolled `git checkout main && git pull origin main` — still ALLOWED, but ONLY in the
|
|
113
|
-
// primary clone. Inside a linked worktree that checkout FATALS ("'main' is already checked out
|
|
114
|
-
// at <primary>"), so waving it through here hands the AI a command that cannot work and costs
|
|
115
|
-
// it a turn to discover. Steer to the fetch, which is all a worktree needs.
|
|
116
|
-
//
|
|
117
|
-
// Note this rule stays a pure ALLOW for the raw pair and always will: the workflow layer now
|
|
118
|
-
// PRESCRIBES `pnpm wp-sync-main` (see TreeRecovery.updateMainSteps, which block()
|
|
119
|
-
// below renders), but prescribing is not blocking. The pair is plain git, and it is the L0
|
|
120
|
-
// recovery cure — a state in which no `pnpm` bin can be trusted to run — so making it a block
|
|
121
|
-
// here would delete the only escape from a deadlock. What changed is what the guards TEACH.
|
|
122
|
-
if (switches.length > 0) {
|
|
123
|
-
if (this.recovery.kindOf(ctx.workspaceRoot) !== 'worktree')
|
|
124
|
-
return null;
|
|
125
|
-
// block() appends updateMainSteps for the tree we are in — don't say it twice here.
|
|
126
|
-
return this.block(ctx, segment, 'Blocked.');
|
|
127
|
-
}
|
|
128
|
-
const currentBranch = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
|
|
129
|
-
cwd: ctx.workspaceRoot,
|
|
130
|
-
encoding: 'utf8',
|
|
131
|
-
}).trim();
|
|
132
|
-
if (currentBranch === 'main')
|
|
133
|
-
return null;
|
|
134
|
-
return this.block(ctx, segment, `Pulling main into feature branch '${currentBranch}' is blocked.`);
|
|
135
|
-
}
|
|
136
|
-
block(ctx, segment, what) {
|
|
137
|
-
// Materialize the doc we are about to send the AI to. This guard fires long before any `wp-*`
|
|
138
|
-
// command runs (those are what normally write it), so the linked path could easily not exist —
|
|
139
|
-
// and a STALE copy from an older @webpieces is just as misleading, hence overwrite.
|
|
140
|
-
(0, rules_config_1.writeTemplate)(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
141
|
-
const docPath = new rules_config_1.RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
142
|
-
// "How do I get MAIN itself current?" is a different question from "sync my feature branch",
|
|
143
|
-
// and it used to have no answer anywhere on this path — the flows cover feature branches and
|
|
144
|
-
// the read-only checks cover looking. An AI on main with no third option improvises, and what
|
|
145
|
-
// it improvises is `git reset --hard origin/main`. Answer the question instead, shaped to the
|
|
146
|
-
// tree we are actually in (in a worktree `git checkout main` fatals).
|
|
147
|
-
const updateMain = [
|
|
148
|
-
'',
|
|
149
|
-
'On main and just wanted to bring MAIN itself up to date? That is a different question from',
|
|
150
|
-
'syncing a feature branch, and merge/reset is not the answer to it:',
|
|
151
|
-
...this.recovery.updateMainSteps(this.recovery.kindOf(ctx.workspaceRoot)),
|
|
152
|
-
].join('\n');
|
|
153
|
-
return new types_1.Violation(1, truncate(segment), `${what} Use the gated 3-point flow instead: 'pnpm wp-start-update' → 'pnpm wp-finish-update' when NO PR is open, or 'pnpm wp-start-upsert-pr' → 'pnpm wp-finish-upsert-pr' when a PR IS open (required then — the merge rewrites the branch and the PR must be re-pointed in the same run). If you truly need a raw merge/rebase, ask the HUMAN to run it — and warn them to push back. Full flow: READ ${docPath}.${updateMain}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.RedirectHowToMergeMainRule = RedirectHowToMergeMainRule;
|
|
157
|
-
//# sourceMappingURL=redirect-how-to-merge-main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redirect-how-to-merge-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/redirect-how-to-merge-main.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAEzC,0DAA0I;AAG1I,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAsC;AACtC,kDAAiD;AACjD,mDAA+C;AAC/C,6DAAsE;AAEtE,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,QAAQ,GAAG,IAAI,+BAAgB,EAAE,CAAC;AAExC,MAAM,QAAQ,GAAG,IAAI,kBAAO,CACxB,8EAA8E,EAC9E,sDAAsD;MACpD,IAAI;MACJ,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;MAClC,IAAI;IACN,kGAAkG;IAClG,gGAAgG;IAChG,kGAAkG;IAClG,mGAAmG;IACnG,oDAAoD;MAClD,oGAAoG;MACpG,gGAAgG;MAChG,4EAA4E;MAC5E,IAAI;MACJ,QAAQ,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI;MAC3C,IAAI;IACN,mGAAmG;IACnG,+FAA+F;IAC/F,iGAAiG;IACjG,qGAAqG;IACrG,qGAAqG;IACrG,mFAAmF;MACjF,qGAAqG;MACrG,kEAAkE;MAClE,kGAAkG;MAClG,8FAA8F;IAChG,kGAAkG;IAClG,mGAAmG;IACnG,oFAAoF;MAClF,kGAAkG;MAClG,iGAAiG,CACtG,CAAC;AAEF,uGAAuG;AACvG,+FAA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M,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;SAC5E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,IAAI,iBAAC,CACR,CAAC,EACD,QAAQ,CAAC,OAAO,CAAC,EACjB,GAAG,IAAI,oYAAoY,OAAO,IAAI,UAAU,EAAE,CACra,CAAC;IACN,CAAC;CACJ;AA9GD,gEA8GC","sourcesContent":["import { execSync } from 'child_process';\n\nimport { PrLifecycleGuardConfig, PR_LIFECYCLE_GUARD_KEY, RepoRootFinder, SyncFlowGuidance, writeTemplate } 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';\nimport { TreeRecovery } from './tree-recovery';\nimport { BranchSwitch, BranchSwitchScan } from './branch-switch-scan';\n\nconst INSTRUCT_FILE = 'webpieces.git-workflow.md';\nconst GUIDANCE = new SyncFlowGuidance();\n\nconst FIX_HINT = new FixHint(\n '`git merge` / `git rebase` are never run by AI — on any branch, in any form.',\n 'To bring main\\'s changes into your feature branch:\\n'\n + '\\n'\n + GUIDANCE.flows().join('\\n') + '\\n'\n + '\\n'\n // The fork-point DERIVATION (why the invariant has two halves, and the three consumers a polluted\n // fork point corrupts) and the WORD-FOR-WORD warning to hand the human are NOT here on purpose.\n // Both are stated in full in the git-workflow doc this hint links by absolute path, and a message\n // that re-derives what the linked doc already says is a second copy to keep in step. What survives\n // here is only what changes what the AI types next.\n + 'Either flow does a 3-point merge, which keeps the fork point a pure main commit — what the build\\n'\n + 'gate\\'s --base and the PR review diff are computed from; a raw merge/rebase destroys it. The\\n'\n + 'gated commands merge internally as child processes this hook never sees.\\n'\n + '\\n'\n + GUIDANCE.readOnlyChecks().join('\\n') + '\\n'\n + '\\n'\n // The \"do not run it, ask the human, tell them to push back\" instruction is NOT repeated here: the\n // violation line the AI reads first already says it. This paragraph's job is only the pointer.\n // The liveness phrase is kept on ONE line deliberately: it is asserted in full, and a wrap would\n // split the assertion's substring across two chunks. The retired wording (\"a branch you do not own\")\n // was pinned only by a `never sync a branch` PREFIX, which passed under both framings — which is how\n // this hint kept teaching the removed rule after the doc it links had replaced it.\n + 'READ the instruct-ai git-workflow doc at the absolute path on the violation line above — the full\\n'\n + 'flow (incl. worktrees), the fork-point invariant, why you must\\n'\n + 'never sync a branch something is ACTIVELY holding (liveness, not authorship — a finished agent\\n'\n + 'holds nothing), and the exact words to warn a human with when you ask them to run a merge.\\n'\n // NOT \"add that info to memory\": \"that info\" was the whole git-workflow doc, which is REGENERATED\n // per repo and per version — memorizing it guarantees a stale recall in the next session. Only the\n // invariant is stable enough to persist; the doc must be re-read, never remembered.\n + 'Add to memory: never run a raw `git merge`/`git rebase` — use this repo\\'s gated sync flow and\\n'\n + 're-read its git-workflow doc each time rather than recalling it (regenerated per repo/version).',\n);\n\n// `git merge --abort` / `git rebase --abort|--quit` UNDO an in-progress operation — they cannot create\n// a merge commit or rewrite history, so they cannot violate the fork-point invariant this rule\n// protects. They stay allowed so a repo left mid-operation (e.g. by a human-run rebase) can still be\n// cleaned up. `--continue` is deliberately NOT here: it COMPLETES the operation.\nconst UNDO_FLAG = /--(?:abort|quit)\\b/;\n\n// Typed as a query (\"would this fast-forward?\"), but a successful --ff-only IS the merge.\nconst FF_ONLY = /--ff-only\\b/;\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\nexport class RedirectHowToMergeMainRule extends BashRuleBase<PrLifecycleGuardConfig> {\n private readonly scanner = new CommandScanner();\n private readonly recovery = new TreeRecovery();\n // \"Which branch does this land on?\" — see branch-switch-scan.ts. It replaced a pair of regexes\n // here (`/git\\s+(?:checkout|switch)\\s+main\\b/` and its negative-lookahead twin) that assumed the\n // branch name is the token immediately after the subcommand. One flag broke both halves at once:\n // `git checkout -q main && git pull -q origin main` missed the main EXEMPTION and then tripped the\n // feature-switch block, so this guard rejected the very command stale-main-bash-guard prescribes,\n // with a reason (\"switches to a feature branch\") that was the opposite of the truth.\n private readonly switches = new BranchSwitchScan(this.scanner);\n\n constructor(config: PrLifecycleGuardConfig) { super(config, 'redirect-how-to-merge-main', PR_LIFECYCLE_GUARD_KEY); }\n\n readonly description = 'Block ALL `git merge`/`git rebase` (any branch, any form) and `git pull origin main` on a feature branch. Use the squash-update process instead.';\n readonly fixHint = FIX_HINT;\n\n check(ctx: BashContext): readonly Violation[] {\n for (const segment of this.scanner.commandSegments(ctx.command)) {\n const violation = this.checkSegment(ctx, segment);\n if (violation !== null) return [violation];\n }\n return [];\n }\n\n private checkSegment(ctx: BashContext, segment: string): Violation | null {\n // 1. merge/rebase: unconditional block. Deliberately NO branch lookup.\n //\n // This rule used to read hook-time HEAD and bail out when it was `main`. But a PreToolUse hook\n // runs BEFORE the command, so HEAD-at-hook-time is a value the command itself is about to\n // change: `git checkout feat && git rebase main`, issued while HEAD was still `main` from a\n // prior cleanup, read as \"we're on main, this is fine\" and was waved through. That is the\n // incident this rule exists to prevent. Since merge/rebase have no legitimate AI-run form on\n // ANY branch, there is no branch to consult — and so no HEAD to spoof.\n if (this.scanner.invokesGit(segment, 'merge') || this.scanner.invokesGit(segment, 'rebase')) {\n if (UNDO_FLAG.test(segment)) return null;\n // `--ff-only` reads like a probe (\"can I fast-forward?\") but it MUTATES whenever the answer\n // is yes, so say that here — the AI that typed it was usually only trying to look.\n const probe = FF_ONLY.test(segment)\n ? ' `--ff-only` is NOT a read-only check — it moves your branch whenever it succeeds; see the read-only checks below.'\n : '';\n return this.block(ctx, segment, 'Direct `git merge`/`git rebase` is blocked — AI never runs it, on any branch.' + probe);\n }\n\n // 2. pull: unlike merge/rebase this DOES retain a legitimate on-main form\n // (`git checkout main && git pull origin main`), so it must consult the branch — which is\n // exactly why it also needs the branch-switch check that (1) no longer requires.\n if (this.scanner.invokesGit(segment, 'pull') && /\\borigin\\s+main\\b/.test(segment)) {\n return this.checkPull(ctx, segment);\n }\n\n return null;\n }\n\n private checkPull(ctx: BashContext, segment: string): Violation | null {\n // The two branch questions are COMPLEMENTS of one parse, so they are asked of one parse —\n // that is what keeps them from disagreeing. `git branch -D <x>` is not a checkout so it does\n // not trip this, and `git checkout -` (previous branch, unknowable at hook time) lands\n // nowhere we can name, so it counts as neither.\n const switches = this.switches.switchesIn(ctx.command);\n if (switches.some((s: BranchSwitch): boolean => !this.switches.isExistingMain(s))) {\n return this.block(ctx, segment, 'Blocked: this command switches to a feature branch and then pulls main into it.');\n }\n // The hand-rolled `git checkout main && git pull origin main` — still ALLOWED, but ONLY in the\n // primary clone. Inside a linked worktree that checkout FATALS (\"'main' is already checked out\n // at <primary>\"), so waving it through here hands the AI a command that cannot work and costs\n // it a turn to discover. Steer to the fetch, which is all a worktree needs.\n //\n // Note this rule stays a pure ALLOW for the raw pair and always will: the workflow layer now\n // PRESCRIBES `pnpm wp-sync-main` (see TreeRecovery.updateMainSteps, which block()\n // below renders), but prescribing is not blocking. The pair is plain git, and it is the L0\n // recovery cure — a state in which no `pnpm` bin can be trusted to run — so making it a block\n // here would delete the only escape from a deadlock. What changed is what the guards TEACH.\n if (switches.length > 0) {\n if (this.recovery.kindOf(ctx.workspaceRoot) !== 'worktree') return null;\n // block() appends updateMainSteps for the tree we are in — don't say it twice here.\n return this.block(ctx, segment, 'Blocked.');\n }\n\n const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n }).trim();\n if (currentBranch === 'main') return null;\n\n return this.block(ctx, segment, `Pulling main into feature branch '${currentBranch}' is blocked.`);\n }\n\n private block(ctx: BashContext, segment: string, what: string): Violation {\n // Materialize the doc we are about to send the AI to. This guard fires long before any `wp-*`\n // command runs (those are what normally write it), so the linked path could easily not exist —\n // and a STALE copy from an older @webpieces is just as misleading, hence overwrite.\n writeTemplate(ctx.workspaceRoot, INSTRUCT_FILE);\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n // \"How do I get MAIN itself current?\" is a different question from \"sync my feature branch\",\n // and it used to have no answer anywhere on this path — the flows cover feature branches and\n // the read-only checks cover looking. An AI on main with no third option improvises, and what\n // it improvises is `git reset --hard origin/main`. Answer the question instead, shaped to the\n // tree we are actually in (in a worktree `git checkout main` fatals).\n const updateMain = [\n '',\n 'On main and just wanted to bring MAIN itself up to date? That is a different question from',\n 'syncing a feature branch, and merge/reset is not the answer to it:',\n ...this.recovery.updateMainSteps(this.recovery.kindOf(ctx.workspaceRoot)),\n ].join('\\n');\n return new V(\n 1,\n truncate(segment),\n `${what} Use the gated 3-point flow instead: 'pnpm wp-start-update' → 'pnpm wp-finish-update' when NO PR is open, or 'pnpm wp-start-upsert-pr' → 'pnpm wp-finish-upsert-pr' when a PR IS open (required then — the merge rewrites the branch and the PR must be re-pointed in the same run). If you truly need a raw merge/rebase, ask the HUMAN to run it — and warn them to push back. Full flow: READ ${docPath}.${updateMain}`,\n );\n }\n}\n"]}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { CommandScanner, CommandSegment } from '../command-scan';
|
|
2
|
-
/**
|
|
3
|
-
* What ROLE one segment of a shell command plays — the question every allowlist-shaped bash guard has
|
|
4
|
-
* to answer before it can judge a compound command.
|
|
5
|
-
*
|
|
6
|
-
* WHY this exists: `merged-branch-bash-guard` allowlists the commands that get you OFF a merged
|
|
7
|
-
* branch, and the redirect it prints tells the agent to run them. An agent bounds tool output by
|
|
8
|
-
* reflex, so it runs `git fetch origin main 2>&1 | tail -5` — and the guard, evaluating `tail -5` as
|
|
9
|
-
* an ordinary command, denied the very remedy it had just printed. Verified pairs from the field:
|
|
10
|
-
*
|
|
11
|
-
* pnpm wp-cleanup allowed
|
|
12
|
-
* pnpm wp-cleanup 2>&1 | tail -40 BLOCKED
|
|
13
|
-
* git fetch origin main allowed
|
|
14
|
-
* git fetch origin main 2>&1; echo BLOCKED
|
|
15
|
-
*
|
|
16
|
-
* Nothing in `| tail -40` or `; echo done` can touch the repo, and `done`/`do`/`for x in a b` are not
|
|
17
|
-
* commands at all. So a segment is one of three things:
|
|
18
|
-
*
|
|
19
|
-
* - STRUCTURE — pure shell syntax, invokes nothing (`for b in a b c`, `done`, `fi`).
|
|
20
|
-
* - SHAPING — cannot change the repo: a pager/filter fed by a PIPE (`| tail`, `| head`, `| wc`),
|
|
21
|
-
* or an always-inert command (`echo`, `cd`, `pwd`, `true`).
|
|
22
|
-
* - COMMAND — a real invocation, with `words` giving the effective argv AFTER leading shell
|
|
23
|
-
* keywords are stripped, so `do gh pr list` classifies as `gh pr list`.
|
|
24
|
-
*
|
|
25
|
-
* Two things keep SHAPING honest. A filter counts only when a PIPE fed it — bare `tail src/x.ts`
|
|
26
|
-
* reads the working tree and stays a COMMAND. And a segment carrying an output REDIRECT (`> file`,
|
|
27
|
-
* `>> file`) is always a COMMAND, because `echo x > src/y.ts` writes the repo. `2>&1` is not a
|
|
28
|
-
* redirect to a file and is deliberately not caught.
|
|
29
|
-
*
|
|
30
|
-
* Deciding WHETHER a shaping segment is acceptable is still the guard's call: merged-branch-bash-guard
|
|
31
|
-
* pairs this with ContentReadScan so `git status | cat src/foo.ts` (a filter with a workspace path)
|
|
32
|
-
* stays blocked.
|
|
33
|
-
*/
|
|
34
|
-
export type SegmentRole = 'structure' | 'shaping' | 'command';
|
|
35
|
-
/** Data-only (per CLAUDE.md, classes for data). */
|
|
36
|
-
export declare class SegmentVerdict {
|
|
37
|
-
role: SegmentRole;
|
|
38
|
-
/** The effective argv for a COMMAND, leading shell keywords stripped. Empty for the other roles. */
|
|
39
|
-
words: readonly string[];
|
|
40
|
-
constructor(role: SegmentRole, words: readonly string[]);
|
|
41
|
-
}
|
|
42
|
-
export declare class ShellSegmentScan {
|
|
43
|
-
private readonly scanner;
|
|
44
|
-
constructor(scanner?: CommandScanner);
|
|
45
|
-
classify(segment: CommandSegment): SegmentVerdict;
|
|
46
|
-
/**
|
|
47
|
-
* The effective argv of a segment with leading shell keywords removed — what a guard should judge
|
|
48
|
-
* instead of the raw words. `for b in $(…); do git status; done` splits into three segments and
|
|
49
|
-
* the middle one is literally `do git status`; without this, `do` is the command name and every
|
|
50
|
-
* loop body walks straight past a git allowlist.
|
|
51
|
-
*/
|
|
52
|
-
effectiveWords(segmentText: string): readonly string[];
|
|
53
|
-
private stripKeywords;
|
|
54
|
-
/**
|
|
55
|
-
* `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which merely rewire fds.
|
|
56
|
-
*
|
|
57
|
-
* PUBLIC because RecoveryAllowlist asks the same question of a segment it is about to allow on the
|
|
58
|
-
* strength of the program name alone (`curl`, `gh`): those cannot touch the tree by themselves, but
|
|
59
|
-
* `curl … > src/x.ts` can. One implementation, so the two callers cannot disagree about what
|
|
60
|
-
* counts as a redirect — the `2>&1` carve-out above is exactly the kind of detail a second copy
|
|
61
|
-
* gets wrong.
|
|
62
|
-
*/
|
|
63
|
-
redirectsToFile(words: readonly string[]): boolean;
|
|
64
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShellSegmentScan = exports.SegmentVerdict = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const command_scan_1 = require("../command-scan");
|
|
7
|
-
/** Data-only (per CLAUDE.md, classes for data). */
|
|
8
|
-
class SegmentVerdict {
|
|
9
|
-
role;
|
|
10
|
-
/** The effective argv for a COMMAND, leading shell keywords stripped. Empty for the other roles. */
|
|
11
|
-
words;
|
|
12
|
-
constructor(role, words) {
|
|
13
|
-
this.role = role;
|
|
14
|
-
this.words = words;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.SegmentVerdict = SegmentVerdict;
|
|
18
|
-
class ShellSegmentScan {
|
|
19
|
-
scanner;
|
|
20
|
-
constructor(scanner = new command_scan_1.CommandScanner()) {
|
|
21
|
-
this.scanner = scanner;
|
|
22
|
-
}
|
|
23
|
-
classify(segment) {
|
|
24
|
-
const words = this.stripKeywords(this.scanner.words(segment.text));
|
|
25
|
-
if (words.length === 0)
|
|
26
|
-
return STRUCTURE;
|
|
27
|
-
const head = path.basename(words[0]);
|
|
28
|
-
if (STRUCTURE_HEADS.has(head))
|
|
29
|
-
return STRUCTURE;
|
|
30
|
-
// A redirect can create or overwrite a file, so it is never inert — judge it as a command.
|
|
31
|
-
if (this.redirectsToFile(words))
|
|
32
|
-
return new SegmentVerdict('command', words);
|
|
33
|
-
if (ALWAYS_INERT.has(head))
|
|
34
|
-
return new SegmentVerdict('shaping', words);
|
|
35
|
-
if (segment.join === '|' && OUTPUT_FILTERS.has(head))
|
|
36
|
-
return new SegmentVerdict('shaping', words);
|
|
37
|
-
return new SegmentVerdict('command', words);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* The effective argv of a segment with leading shell keywords removed — what a guard should judge
|
|
41
|
-
* instead of the raw words. `for b in $(…); do git status; done` splits into three segments and
|
|
42
|
-
* the middle one is literally `do git status`; without this, `do` is the command name and every
|
|
43
|
-
* loop body walks straight past a git allowlist.
|
|
44
|
-
*/
|
|
45
|
-
effectiveWords(segmentText) {
|
|
46
|
-
return this.stripKeywords(this.scanner.words(segmentText));
|
|
47
|
-
}
|
|
48
|
-
stripKeywords(words) {
|
|
49
|
-
let i = 0;
|
|
50
|
-
while (i < words.length && STRIPPABLE_KEYWORDS.has(words[i]))
|
|
51
|
-
i++;
|
|
52
|
-
return words.slice(i);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which merely rewire fds.
|
|
56
|
-
*
|
|
57
|
-
* PUBLIC because RecoveryAllowlist asks the same question of a segment it is about to allow on the
|
|
58
|
-
* strength of the program name alone (`curl`, `gh`): those cannot touch the tree by themselves, but
|
|
59
|
-
* `curl … > src/x.ts` can. One implementation, so the two callers cannot disagree about what
|
|
60
|
-
* counts as a redirect — the `2>&1` carve-out above is exactly the kind of detail a second copy
|
|
61
|
-
* gets wrong.
|
|
62
|
-
*/
|
|
63
|
-
redirectsToFile(words) {
|
|
64
|
-
return words.some((word) => REDIRECT_TO_FILE.test(word));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.ShellSegmentScan = ShellSegmentScan;
|
|
68
|
-
const STRUCTURE = new SegmentVerdict('structure', []);
|
|
69
|
-
// Keywords that PRECEDE a real command; strip them and judge what follows.
|
|
70
|
-
const STRIPPABLE_KEYWORDS = new Set([
|
|
71
|
-
'do', 'then', 'else', 'elif', 'if', 'while', 'until', '!', '{', '}', '(', ')',
|
|
72
|
-
]);
|
|
73
|
-
// Segments that invoke nothing at all: loop/case HEADERS (their tail is a word list, and any `$(…)`
|
|
74
|
-
// inside was already split into its own segment by CommandScanner) and the closing keywords.
|
|
75
|
-
const STRUCTURE_HEADS = new Set([
|
|
76
|
-
'for', 'case', 'select', 'done', 'fi', 'esac', ';;', 'in',
|
|
77
|
-
]);
|
|
78
|
-
// Commands that cannot read repo content or change the repo, piped or not.
|
|
79
|
-
const ALWAYS_INERT = new Set([
|
|
80
|
-
'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'date', 'whoami', 'which', 'sleep', 'test', '[',
|
|
81
|
-
]);
|
|
82
|
-
// Pagers/filters that read STDIN. Only when a pipe fed them — bare, they read the working tree.
|
|
83
|
-
const OUTPUT_FILTERS = new Set([
|
|
84
|
-
'head', 'tail', 'wc', 'cat', 'less', 'more', 'nl', 'tac', 'rev', 'sort', 'uniq', 'cut', 'tr',
|
|
85
|
-
'column', 'fold', 'expand', 'grep', 'egrep', 'fgrep', 'rg', 'sed', 'awk', 'jq', 'yq',
|
|
86
|
-
]);
|
|
87
|
-
const REDIRECT_TO_FILE = /^\d*>>?(?!&)/;
|
|
88
|
-
//# sourceMappingURL=shell-segment-scan.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell-segment-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/shell-segment-scan.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,kDAAiE;AAoCjE,mDAAmD;AACnD,MAAa,cAAc;IACvB,IAAI,CAAc;IAClB,oGAAoG;IACpG,KAAK,CAAoB;IAEzB,YAAY,IAAiB,EAAE,KAAwB;QACnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AATD,wCASC;AAED,MAAa,gBAAgB;IACI;IAA7B,YAA6B,UAA0B,IAAI,6BAAc,EAAE;QAA9C,YAAO,GAAP,OAAO,CAAuC;IAAG,CAAC;IAE/E,QAAQ,CAAC,OAAuB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACnE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAEzC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,SAAS,CAAC;QAEhD,2FAA2F;QAC3F,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAE7E,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACxE,IAAI,OAAO,CAAC,IAAI,KAAK,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,cAAc,CAAC,SAAS,EAA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G,CAAC;IAC9C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG;CACvG,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IAChD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI;IAC5F,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI;CACvF,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,cAAc,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { CommandScanner, CommandSegment } from '../command-scan';\n\n/**\n * What ROLE one segment of a shell command plays — the question every allowlist-shaped bash guard has\n * to answer before it can judge a compound command.\n *\n * WHY this exists: `merged-branch-bash-guard` allowlists the commands that get you OFF a merged\n * branch, and the redirect it prints tells the agent to run them. An agent bounds tool output by\n * reflex, so it runs `git fetch origin main 2>&1 | tail -5` — and the guard, evaluating `tail -5` as\n * an ordinary command, denied the very remedy it had just printed. Verified pairs from the field:\n *\n * pnpm wp-cleanup allowed\n * pnpm wp-cleanup 2>&1 | tail -40 BLOCKED\n * git fetch origin main allowed\n * git fetch origin main 2>&1; echo BLOCKED\n *\n * Nothing in `| tail -40` or `; echo done` can touch the repo, and `done`/`do`/`for x in a b` are not\n * commands at all. So a segment is one of three things:\n *\n * - STRUCTURE — pure shell syntax, invokes nothing (`for b in a b c`, `done`, `fi`).\n * - SHAPING — cannot change the repo: a pager/filter fed by a PIPE (`| tail`, `| head`, `| wc`),\n * or an always-inert command (`echo`, `cd`, `pwd`, `true`).\n * - COMMAND — a real invocation, with `words` giving the effective argv AFTER leading shell\n * keywords are stripped, so `do gh pr list` classifies as `gh pr list`.\n *\n * Two things keep SHAPING honest. A filter counts only when a PIPE fed it — bare `tail src/x.ts`\n * reads the working tree and stays a COMMAND. And a segment carrying an output REDIRECT (`> file`,\n * `>> file`) is always a COMMAND, because `echo x > src/y.ts` writes the repo. `2>&1` is not a\n * redirect to a file and is deliberately not caught.\n *\n * Deciding WHETHER a shaping segment is acceptable is still the guard's call: merged-branch-bash-guard\n * pairs this with ContentReadScan so `git status | cat src/foo.ts` (a filter with a workspace path)\n * stays blocked.\n */\nexport type SegmentRole = 'structure' | 'shaping' | 'command';\n\n/** Data-only (per CLAUDE.md, classes for data). */\nexport class SegmentVerdict {\n role: SegmentRole;\n /** The effective argv for a COMMAND, leading shell keywords stripped. Empty for the other roles. */\n words: readonly string[];\n\n constructor(role: SegmentRole, words: readonly string[]) {\n this.role = role;\n this.words = words;\n }\n}\n\nexport class ShellSegmentScan {\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {}\n\n classify(segment: CommandSegment): SegmentVerdict {\n const words = this.stripKeywords(this.scanner.words(segment.text));\n if (words.length === 0) return STRUCTURE;\n\n const head = path.basename(words[0]);\n if (STRUCTURE_HEADS.has(head)) return STRUCTURE;\n\n // A redirect can create or overwrite a file, so it is never inert — judge it as a command.\n if (this.redirectsToFile(words)) return new SegmentVerdict('command', words);\n\n if (ALWAYS_INERT.has(head)) return new SegmentVerdict('shaping', words);\n if (segment.join === '|' && OUTPUT_FILTERS.has(head)) return new SegmentVerdict('shaping', words);\n\n return new SegmentVerdict('command', words);\n }\n\n /**\n * The effective argv of a segment with leading shell keywords removed — what a guard should judge\n * instead of the raw words. `for b in $(…); do git status; done` splits into three segments and\n * the middle one is literally `do git status`; without this, `do` is the command name and every\n * loop body walks straight past a git allowlist.\n */\n effectiveWords(segmentText: string): readonly string[] {\n return this.stripKeywords(this.scanner.words(segmentText));\n }\n\n private stripKeywords(words: readonly string[]): readonly string[] {\n let i = 0;\n while (i < words.length && STRIPPABLE_KEYWORDS.has(words[i])) i++;\n return words.slice(i);\n }\n\n /**\n * `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which merely rewire fds.\n *\n * PUBLIC because RecoveryAllowlist asks the same question of a segment it is about to allow on the\n * strength of the program name alone (`curl`, `gh`): those cannot touch the tree by themselves, but\n * `curl … > src/x.ts` can. One implementation, so the two callers cannot disagree about what\n * counts as a redirect — the `2>&1` carve-out above is exactly the kind of detail a second copy\n * gets wrong.\n */\n redirectsToFile(words: readonly string[]): boolean {\n return words.some((word: string): boolean => REDIRECT_TO_FILE.test(word));\n }\n}\n\nconst STRUCTURE = new SegmentVerdict('structure', []);\n\n// Keywords that PRECEDE a real command; strip them and judge what follows.\nconst STRIPPABLE_KEYWORDS: ReadonlySet<string> = new Set([\n 'do', 'then', 'else', 'elif', 'if', 'while', 'until', '!', '{', '}', '(', ')',\n]);\n\n// Segments that invoke nothing at all: loop/case HEADERS (their tail is a word list, and any `$(…)`\n// inside was already split into its own segment by CommandScanner) and the closing keywords.\nconst STRUCTURE_HEADS: ReadonlySet<string> = new Set([\n 'for', 'case', 'select', 'done', 'fi', 'esac', ';;', 'in',\n]);\n\n// Commands that cannot read repo content or change the repo, piped or not.\nconst ALWAYS_INERT: ReadonlySet<string> = new Set([\n 'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'date', 'whoami', 'which', 'sleep', 'test', '[',\n]);\n\n// Pagers/filters that read STDIN. Only when a pipe fed them — bare, they read the working tree.\nconst OUTPUT_FILTERS: ReadonlySet<string> = new Set([\n 'head', 'tail', 'wc', 'cat', 'less', 'more', 'nl', 'tac', 'rev', 'sort', 'uniq', 'cut', 'tr',\n 'column', 'fold', 'expand', 'grep', 'egrep', 'fgrep', 'rg', 'sed', 'awk', 'jq', 'yq',\n]);\n\nconst REDIRECT_TO_FILE = /^\\d*>>?(?!&)/;\n"]}
|