@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"whole-repo-build-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/whole-repo-build-guard.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAEzC,0DAA+F;AAC/F,8DAA0D;AAG1D,oCAA0C;AAC1C,4CAA6D;AAC7D,0CAAsC;AACtC,0CAAsC;AACtC,sDAAkD;AAClD,kDAA8F;AAC9F,kDAAiD;AACjD,mEAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,MAAa,uBAAwB,SAAQ,wBAA6B;IAMzC;IAL7B;;;;OAIG;IACH,YAA6B,oBAA4B;QACrD,2EAA2E;QAC3E,6FAA6F;QAC7F,sFAAsF;QACtF,+EAA+E;QAC/E,KAAK,CAAC,IAAI,2BAAe,EAAE,EAAE,wBAAwB,EAAE,wBAAwB,CAAC,CAAC;QALxD,yBAAoB,GAApB,oBAAoB,CAAQ;IAMzD,CAAC;IAEgB,OAAO,GAAG,IAAI,6BAAc,EAAE,CAAC;IAC/B,UAAU,GAAG,IAAI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GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,GAAgB,EAAE,MAAc;QAC1C,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,GAAgB,EAAE,GAAsB,EAAE,OAAe;QACnE,yFAAyF;QACzF,0CAA0C;QAC1C,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QAClD,OAAO,CAAC,IAAI,iBAAC,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAEO,QAAQ,CAAC,CAAS;QACtB,MAAM,GAAG,GAAG,GAAG,CAAC;QAChB,OAAO,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;IACvD,CAAC;IAEO,WAAW,CAAC,GAAgB,EAAE,OAAgB,EAAE,MAAc;QAClE,IAAA,+BAAgB,EACZ,GAAG,CAAC,aAAa,EACjB,IAAI,4BAAa,CAAC,wBAAwB,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,8BAAa,EAAE,gCAAiB,CAAC,CAChI,CAAC;IACN,CAAC;CACJ;AA9LD,0DA8LC","sourcesContent":["import { execSync } from 'child_process';\n\nimport { DEFAULT_BUILD_COMMAND, HomeConfig, HomeConfigService } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport type { BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { BashRuleBase, EmptyRuleConfig } from '../rule-base';\nimport { FixHint } from '../fix-hint';\nimport { toError } from '../to-error';\nimport { L0_FAULT_NONE } from '../l0-fault-codes';\nimport { logGuardDecision, GuardDecision, Verdict, MATRIX_L2_UNROWED } from '../decision-log';\nimport { CommandScanner } from '../command-scan';\nimport { WholeRepoBuildScan, WholeRepoBuildHit } from './whole-repo-build-scan';\n\n/**\n * Blocks a Bash command that would build or test the WHOLE monorepo, and hands back the narrow\n * command to run instead. Which shapes count is `WholeRepoBuildScan`'s job; this rule owns the\n * decision, the log line and the two refusal messages.\n *\n * ─── Why: SCOPE and AGREEMENT, not a speed claim ───────────────────────────────────────────────────\n * `nx affected --target=ci --base=<fork point>` is the command the PR gate itself runs\n * (`commands.pr-gate.buildCommand`), so a green local result is evidence about the gate. A whole-repo\n * build is a different, wider command whose green says nothing extra — it just also compiles projects\n * the change cannot reach.\n *\n * It is NOT automatically faster, and this guard deliberately does not claim it is. Measured on a\n * `core-util` change, `affected` selected the IDENTICAL 20 projects / 104 tasks as the whole-repo\n * build: a package at the BASE of the dependency graph prunes nothing. The pruning win is real for\n * LEAF projects and absent for base ones. The long builds people blamed on scope were caused by a cold\n * nx cache and by CPU contention between agents running full sweeps at once (measured: ~3.2x total\n * test time under contention) — neither of which a narrower target list fixes on its own.\n *\n * So what this guard buys is the scope being right by default. Building the world is never the\n * correct inner-loop move in a monorepo; the correct one has existed all along, and nothing stopped\n * the wide one.\n *\n * ─── The message is READ FROM CONFIG, and it is RESOLVED ───────────────────────────────────────────\n * The replacement command comes from `commands.pr-gate.buildCommand` (injected into this guard's\n * config by load-config), so the refusal follows the project when the gate command changes. The `$(…)`\n * in it is EXPANDED before printing: handing an agent `--base=$(git merge-base origin/main HEAD)` is\n * handing it a template, and a template pasted where no shell expands it produces a confusing failure\n * that reads like the guard's advice was wrong. Only `$(git …)` is expanded, and only read-only git;\n * anything else is left verbatim.\n *\n * ─── EXPERIMENTAL, OFF by default, with ONE machine-local opt-in ───────────────────────────────────\n * `experimental.whole-repo-build-guard` in `~/.webpieces/config.json` is this guard's only switch, and\n * it is an OPT-IN: ON requires the explicit boolean `true`. Absent key, absent `experimental` section,\n * absent file, and an explicit `false` are ONE state, and that state is OFF.\n *\n * That direction is a standing policy, not a per-flag judgement: EVERY `experimental.*` flag in this\n * codebase ships OFF and stays OFF for two years. A flag that defaults ON is not an experiment — it is\n * a shipped behaviour that skipped its soak period, and it changes what every agent on every machine\n * can do the moment they upgrade. If few machines opt in, that is information about the experiment; it\n * is not a reason to force it on everybody.\n *\n * There is also NO webpieces.config.json entry, for a separate reason: a live incident. This guard\n * first shipped with `mode: 'ON'` by default AND a REQUIRED entry under `hookGuards`, and every\n * consumer that upgraded hit fault Y — EVERY Bash call blocked — for a feature they had never asked\n * for. The fault was the REQUIRED KEY: the failure was at config LOAD, before any command was judged,\n * and the cure was \"edit a file to get your shell back\". Keeping the switch in an OPTIONAL\n * machine-local file is what makes the default state need no file, no key and no edit.\n *\n * Three states, and only three:\n * - the file does not exist (essentially every machine), or exists without the key → the guard is\n * OFF, and inert: no block, no log, no message. Every key in that file is optional, because it is\n * MACHINE-GLOBAL and the repos on one machine pin different webpieces releases — a required key\n * there is unsatisfiable (see home-config.ts).\n * - the key is present → its boolean decides, and only `true` arms the guard.\n * - the file exists and is unparseable, or a key it DOES define has the wrong type → HARD FAILURE\n * naming the edit. That is a file somebody wrote wrongly, not one written for another release.\n * Editing that file is an unconditional PASS in the guards, so the block is always self-curable.\n *\n * ─── ONE message, because the gate now always captures ─────────────────────────────────────────────\n * There used to be two refusals here, chosen by `experimental.buildGateLogCapture`: one naming the\n * narrower build to run, and one saying \"do not build at all — stage ② already builds and you can READ\n * the result\". That key is gone, because capturing the build's full output to a file is no longer\n * optional. What survived is the FIRST of those, now carrying the log pointer the second one existed to\n * offer: a refusal still has to answer \"so what do I run?\", and \"run nothing\" is only an answer when the\n * caller was already inside the PR flow.\n *\n * ─── Humans are not affected, by construction ──────────────────────────────────────────────────────\n * This is a PreToolUse hook. It sees the AI's Bash tool calls and nothing else — a human typing\n * `pnpm run build-all` in their own terminal never reaches a hook, and the `build-all` script itself is\n * deliberately left in package.json for exactly that reason. The guard is about what the AI does in a\n * loop, not about the command being wrong for a person who chooses to run it once.\n */\nexport class WholeRepoBuildGuardRule extends BashRuleBase<EmptyRuleConfig> {\n /**\n * `affectedBuildCommand` is the project's gate command (`commands.pr-gate.buildCommand`), handed in\n * by the runner off the loaded config. It is a CONSTRUCTOR ARGUMENT rather than a config field\n * because this guard has no config entry to read one from — and that is the point.\n */\n constructor(private readonly affectedBuildCommand: string) {\n // configKey === name and is DELIBERATELY not a real key: this guard has no\n // webpieces.config.json entry at all (see RETIRED_CONFIG_KEYS), and it is loaded outside the\n // config-driven set so the fault-Y sync check never sees it. Naming it here keeps the\n // AbstractRule contract honest without putting the string in HOOK_GUARD_NAMES.\n super(new EmptyRuleConfig(), 'whole-repo-build-guard', 'whole-repo-build-guard');\n }\n\n private readonly scanner = new CommandScanner();\n private readonly homeConfig = new HomeConfigService();\n\n /** Set by check() when the home config is unreadable, so the fix hint names the same repair. */\n private homeConfigError = '';\n\n readonly description =\n 'Block a whole-monorepo build (build-all, an unnarrowed nx run-many, nx affected with no ' +\n '--base, a bare vitest run) and name the affected-scoped command to run instead.';\n\n /**\n * The command this rule last printed, so the fix hint and the violation message are one string and\n * cannot disagree. Empty until check() runs (fixHint is also read without it), at which point the\n * getter falls back to the configured TEMPLATE — never to a second literal, which is exactly the\n * drift this guard's own docstring says a duplicated command string causes.\n */\n private resolvedCommand = '';\n\n get fixHint(): FixHint {\n if (this.homeConfigError !== '') {\n return new FixHint(\n '~/.webpieces/config.json exists but cannot be read.',\n 'Edit ~/.webpieces/config.json (editing it is always permitted, including right now), or ' +\n 'delete it outright — with no such file every webpieces command behaves exactly as it ' +\n 'does by default.',\n );\n }\n const command = this.resolvedCommand !== '' ? this.resolvedCommand : this.buildCommandTemplate();\n return new FixHint(\n 'That command builds the WHOLE monorepo. Build only what your change affects.',\n 'Build the affected projects, or one project, or one spec file — never the workspace:\\n' +\n ` pnpm wp-build # the gate's own build; runs: ${command}\\n` +\n ' pnpm nx run <project>:ci # one project\\n' +\n ' pnpm exec vitest run <path> # one suite\\n' +\n 'This guard is OFF unless a machine opts in with \"experimental\": ' +\n '{ \"whole-repo-build-guard\": true } in ~/.webpieces/config.json — remove that line to turn ' +\n 'it off again (there is no webpieces.config.json entry for it).',\n );\n }\n\n check(ctx: BashContext): readonly Violation[] {\n const home = this.loadHome();\n // A file someone deliberately created must be correct — see the class docstring. Reported for\n // whatever command happens to be running, because a broken opt-in file is not a build question.\n if (home instanceof Error) return this.blockOnBrokenHomeConfig(ctx, home);\n\n // THE OPT-IN. False for every machine that has not said `true` out loud, including every machine\n // with no `~/.webpieces/config.json` at all. Being off is silent on purpose: no block, no log, no\n // file touched — the default must be indistinguishable from \"this guard does not exist\".\n this.homeConfigError = '';\n if (!home.wholeRepoBuildGuard) return [];\n\n // Blocklist-shaped, so match on commandCode: stripping heredocs and quoted prose can only ever\n // block LESS, and this repo's own commit messages are full of the command names above.\n const hit = new WholeRepoBuildScan(this.scanner, ctx.effectiveCwd === ctx.workspaceRoot)\n .firstHit(ctx.commandCode);\n if (hit === null) return this.allow(ctx, 'not-a-whole-repo-build');\n\n // Resolved ONCE, here, and read by both the violation message and the fix hint.\n this.resolvedCommand = this.resolvedBuildCommand(ctx.workspaceRoot);\n return this.block(ctx, hit, this.message());\n }\n\n /**\n * The home config, or the Error explaining why it is unusable. NOT a boolean: \"absent\" is already\n * folded into the returned HomeConfig (each key's default — for this guard, OFF), so the only thing\n * left to distinguish is \"present and wrong\", which must be reported rather than swallowed.\n */\n private loadHome(): HomeConfig | Error {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a rejected home config is converted\n // into this guard's own block, which carries the loader's fix instruction verbatim\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return this.homeConfig.load();\n } catch (err: unknown) {\n const error = toError(err);\n return error;\n }\n }\n\n private blockOnBrokenHomeConfig(ctx: BashContext, error: Error): readonly Violation[] {\n this.homeConfigError = error.message;\n this.logDecision(ctx, 'BLOCK_AI_CURE', 'home-config-invalid');\n return [new V(1, this.truncate(ctx.command), this.brokenHomeConfigMessage(error))];\n }\n\n private brokenHomeConfigMessage(error: Error): string {\n const detail = error instanceof InformAiError\n ? error.message\n : `~/.webpieces/config.json could not be read: ${error.message}`;\n return `Blocked: ~/.webpieces/config.json is present but unusable.\\n\\n${detail}`;\n }\n\n // The whole refusal. Short on purpose: it is read mid-task by an agent that needs the ONE command\n // to run next, and a guard message long enough to skim is a guard message that gets skimmed.\n //\n // `pnpm wp-build` FIRST, with the command it resolves to shown beside it. One thing to type, and it\n // runs `commands.pr-gate.buildCommand` through the gate's own resolver — so this refusal can never\n // teach a command the gate does not run, however the project reconfigures it.\n //\n // The log note is attached to the `wp-build` line ONLY, and that placement is the whole point. A\n // `FullLog :` pointer is written by `GateLogFile.pointer`, which is reachable solely through\n // `BuildGateLog` / `StageOutputLog` — i.e. through the gate. A bare `nx run <project>:ci` or\n // `vitest run <path>` writes no such file, so a blanket \"whichever you run\" claim would send an\n // agent to grep a path that does not exist while this same message forbids the re-run that is its\n // only remaining option. A cure that names an artifact the command does not produce is worse than\n // no cure at all.\n private message(): string {\n return 'Blocked: that builds the WHOLE monorepo. Build only what your change affects:\\n\\n'\n + ` pnpm wp-build # runs: ${this.resolvedCommand}\\n`\n + ' (its full output goes to a FILE — it prints \"FullLog : <path>\"; grep THAT instead of\\n'\n + ' rebuilding. Never re-run a build to read a different slice of it.)\\n\\n'\n + 'Narrower still: pnpm nx run <project>:ci, or pnpm exec vitest run <path>.';\n }\n\n /**\n * The project's build command, unexpanded. ONE source: `commands.pr-gate.buildCommand`, handed to\n * the constructor by the runner, falling back to the same DEFAULT_BUILD_COMMAND the gate itself\n * falls back to. This guard never spells a build command of its own — a second copy is how a refusal\n * starts teaching a command the gate does not run.\n */\n private buildCommandTemplate(): string {\n return this.affectedBuildCommand.trim() === '' ? DEFAULT_BUILD_COMMAND : this.affectedBuildCommand;\n }\n\n /**\n * The configured build command with its `$(git …)` substitutions expanded, so what is printed is\n * runnable as-is. Expansion is limited to git, and any failure leaves the template untouched — a\n * guard may degrade its own message, never fail the tool call it is judging.\n */\n private resolvedBuildCommand(workspaceRoot: string): string {\n const template = this.buildCommandTemplate();\n return template.replace(/\\$\\(([^()]*)\\)/g, (match: string, inner: string): string => {\n const trimmed = inner.trim();\n if (!trimmed.startsWith('git ')) return match;\n const output = this.capture(trimmed, workspaceRoot);\n return output === null ? match : output;\n });\n }\n\n private capture(command: string, workspaceRoot: string): string | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return execSync(command, {\n cwd: workspaceRoot, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n private allow(ctx: BashContext, reason: string): readonly Violation[] {\n this.logDecision(ctx, 'ALLOW', reason);\n return [];\n }\n\n private block(ctx: BashContext, hit: WholeRepoBuildHit, message: string): readonly Violation[] {\n // BLOCK_AI_CURE, not BLOCK_HUMAN: the cure is one command the agent runs itself, and the\n // refusal hands it over already resolved.\n this.logDecision(ctx, 'BLOCK_AI_CURE', hit.shape);\n return [new V(1, this.truncate(ctx.command), message)];\n }\n\n private truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n }\n\n private logDecision(ctx: BashContext, verdict: Verdict, reason: string): void {\n logGuardDecision(\n ctx.workspaceRoot,\n new GuardDecision('whole-repo-build-guard', 'Bash', ctx.command, '-', verdict, reason, '-', L0_FAULT_NONE, MATRIX_L2_UNROWED),\n );\n }\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { CommandScanner } from '../command-scan';
|
|
2
|
-
/** One whole-repo build found in a command: the segment, and the SHAPE that made it one. Data-only. */
|
|
3
|
-
export declare class WholeRepoBuildHit {
|
|
4
|
-
segment: string;
|
|
5
|
-
shape: string;
|
|
6
|
-
constructor(segment: string, shape: string);
|
|
7
|
-
}
|
|
8
|
-
export declare class WholeRepoBuildScan {
|
|
9
|
-
private readonly scanner;
|
|
10
|
-
private readonly atWorkspaceRoot;
|
|
11
|
-
constructor(scanner: CommandScanner, atWorkspaceRoot: boolean);
|
|
12
|
-
/** The first segment of `command` that builds the whole repo, or null when none does. */
|
|
13
|
-
firstHit(command: string): WholeRepoBuildHit | null;
|
|
14
|
-
private shapeOf;
|
|
15
|
-
private isNarrowed;
|
|
16
|
-
private nxShape;
|
|
17
|
-
private vitestShape;
|
|
18
|
-
/**
|
|
19
|
-
* Does this nx invocation run a COMPILE/TEST target? Targets come from `-t`/`--target`/`--targets`
|
|
20
|
-
* in either spelling, comma-separated, plus (for `run-many <target>`) a second positional.
|
|
21
|
-
*
|
|
22
|
-
* An invocation naming NO target is not judged a build: nx errors on it, and guessing would block a
|
|
23
|
-
* typo with a message about build scope. An invocation naming only regeneration targets
|
|
24
|
-
* (`di-graph-generate`, `generate`) is deliberately allowed workspace-wide — see BUILD_TARGETS.
|
|
25
|
-
*/
|
|
26
|
-
private buildsAnything;
|
|
27
|
-
private hasFlag;
|
|
28
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WholeRepoBuildScan = exports.WholeRepoBuildHit = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Decides the one question whole-repo-build-guard asks of a command: would this segment build (or
|
|
6
|
-
* test) the ENTIRE monorepo rather than the part the change touches?
|
|
7
|
-
*
|
|
8
|
-
* ─── Why this is a SHAPE test and not a string match ───────────────────────────────────────────────
|
|
9
|
-
* The command that motivated the guard is `pnpm run build-all`, but matching that literal buys about a
|
|
10
|
-
* day: `npm run build-all`, `pnpm nx run-many -t ci`, `pnpm exec vitest run` and `time pnpm build-all`
|
|
11
|
-
* are the same build with a different spelling, and an agent that is blocked reaches for the next
|
|
12
|
-
* spelling rather than the smaller build. So the classifier normalizes away the package-manager
|
|
13
|
-
* wrapper first, then judges the PROGRAM and its narrowing arguments:
|
|
14
|
-
*
|
|
15
|
-
* BLOCKED a whole-repo script name — `build-all`, `webpieces:ci`, `wp-ci`, … — under any runner
|
|
16
|
-
* BLOCKED `nx run-many` of a BUILD target with no `-p`/`--projects`, or with `--all`
|
|
17
|
-
* BLOCKED `nx affected` of a BUILD target with no `--base` (a far wider base than the fork point)
|
|
18
|
-
* BLOCKED `nx <target>` with no project argument (`nx test`)
|
|
19
|
-
* BLOCKED `vitest`/`vitest run` with no path, `--project` or `--dir` to narrow it
|
|
20
|
-
* BLOCKED a bare `pnpm test` AT THE WORKSPACE ROOT — the root `test` script is the whole suite.
|
|
21
|
-
* Only under a RUNNER: a naked `test` word is POSIX test(1), and classifying it as the
|
|
22
|
-
* script blocked a polling loop whose jq filter merely contained `test(`.
|
|
23
|
-
*
|
|
24
|
-
* ALLOWED `nx affected --target=ci --base=<anything>` — the gate's own command
|
|
25
|
-
* ALLOWED `nx run <project>:<target>`, `nx run-many -t test -p a b`, `nx test core-util`
|
|
26
|
-
* ALLOWED `vitest run packages/core/core-util`, `vitest run --project core-util`
|
|
27
|
-
* ALLOWED anything carrying `--filter` (pnpm's own narrowing), and every non-build command
|
|
28
|
-
* ALLOWED a workspace-wide REGENERATION — `nx run-many --target=di-graph-generate` — which is
|
|
29
|
-
* supposed to cover every project and which this repo's own docs prescribe
|
|
30
|
-
*
|
|
31
|
-
* Narrowing is judged POSITIVELY: a command is blocked only when the shape is whole-repo AND nothing
|
|
32
|
-
* in it narrows the scope. A flag this file has never heard of therefore fails toward ALLOW, which is
|
|
33
|
-
* the right direction for a guard whose false positive costs an agent its next legitimate command.
|
|
34
|
-
*/
|
|
35
|
-
// The package-manager wrapper (`pnpm exec vitest`, `npx nx`) is stripped by CommandScanner, which owns
|
|
36
|
-
// that list — see `runnerStrippedWords`. It used to be duplicated here, and a second guard needing the
|
|
37
|
-
// same normalization is exactly when a duplicate starts to drift.
|
|
38
|
-
// Any of these ANYWHERE in the segment means the human/agent already scoped the work, so nothing here
|
|
39
|
-
// applies. `--filter` is pnpm's project selector; the nx selectors are checked again per-subcommand.
|
|
40
|
-
const NARROWING_FLAGS = ['--filter', '-p', '--projects', '--project', '--dir', '--projectPath'];
|
|
41
|
-
// Script/bin names that ARE "build the world" in every repo that defines them. `wp-ci` is webpieces'
|
|
42
|
-
// own whole-repo validator and is listed as a PROGRAM as well as a script: blocking `build-all` while
|
|
43
|
-
// leaving the thing it delegates to open would be a guard with a labelled side door.
|
|
44
|
-
const WHOLE_REPO_SCRIPTS = new Set([
|
|
45
|
-
'build-all', 'build:all', 'buildall',
|
|
46
|
-
'test-all', 'test:all', 'lint-all', 'ci-all', 'ci:all',
|
|
47
|
-
'webpieces:ci', 'wp-ci',
|
|
48
|
-
]);
|
|
49
|
-
// nx verbs that are NOT "run this target across the workspace". Anything else in the first position is
|
|
50
|
-
// read as a TARGET name (`nx test`, `nx build`), which is whole-repo unless a project follows.
|
|
51
|
-
const NX_COMMANDS = new Set([
|
|
52
|
-
'run', 'run-many', 'affected', 'affected:graph', 'print-affected',
|
|
53
|
-
'show', 'graph', 'dep-graph', 'reset', 'daemon', 'list', 'report', 'migrate',
|
|
54
|
-
'generate', 'g', 'new', 'format', 'repair', 'connect', 'add', 'init', 'release',
|
|
55
|
-
'sync', 'watch', 'exec', 'login', 'logout', 'record', 'view-logs', 'import',
|
|
56
|
-
]);
|
|
57
|
-
/**
|
|
58
|
-
* The targets this guard is about. A workspace-wide `nx run-many -t di-graph-generate` or
|
|
59
|
-
* `-t architecture:generate` is a REGENERATION and is supposed to cover every project — the repo's own
|
|
60
|
-
* docs prescribe exactly that, and blocking it would make the guard wrong about a command an agent has
|
|
61
|
-
* to run. Only the compile/test/lint family is a "build of the world".
|
|
62
|
-
*/
|
|
63
|
-
const BUILD_TARGETS = new Set([
|
|
64
|
-
'ci', 'build', 'test', 'lint', 'e2e', 'typecheck', 'check', 'compile', 'verify',
|
|
65
|
-
]);
|
|
66
|
-
// vitest's leading verb, dropped before looking for a path filter.
|
|
67
|
-
const VITEST_VERBS = new Set(['run', 'watch', 'dev', 'related', 'bench', 'list', 'typecheck', 'init']);
|
|
68
|
-
// vitest flags whose VALUE is the next token, so the value is never mistaken for a path filter.
|
|
69
|
-
const VITEST_VALUE_FLAGS = new Set([
|
|
70
|
-
'--reporter', '--config', '-c', '--mode', '-m', '--shard', '--pool', '--environment',
|
|
71
|
-
'--outputFile', '--maxWorkers', '--minWorkers', '--testNamePattern', '-t', '--retry',
|
|
72
|
-
'--testTimeout', '--hookTimeout', '--exclude', '--include', '--coverage.reporter',
|
|
73
|
-
]);
|
|
74
|
-
/** One whole-repo build found in a command: the segment, and the SHAPE that made it one. Data-only. */
|
|
75
|
-
class WholeRepoBuildHit {
|
|
76
|
-
segment;
|
|
77
|
-
shape;
|
|
78
|
-
constructor(segment, shape) {
|
|
79
|
-
this.segment = segment;
|
|
80
|
-
this.shape = shape;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.WholeRepoBuildHit = WholeRepoBuildHit;
|
|
84
|
-
class WholeRepoBuildScan {
|
|
85
|
-
scanner;
|
|
86
|
-
atWorkspaceRoot;
|
|
87
|
-
constructor(scanner,
|
|
88
|
-
// True when the command runs at the workspace ROOT, where a bare `pnpm test` is the whole suite.
|
|
89
|
-
atWorkspaceRoot) {
|
|
90
|
-
this.scanner = scanner;
|
|
91
|
-
this.atWorkspaceRoot = atWorkspaceRoot;
|
|
92
|
-
}
|
|
93
|
-
/** The first segment of `command` that builds the whole repo, or null when none does. */
|
|
94
|
-
firstHit(command) {
|
|
95
|
-
for (const segment of this.scanner.commandSegments(command)) {
|
|
96
|
-
const shape = this.shapeOf(segment);
|
|
97
|
-
if (shape !== null)
|
|
98
|
-
return new WholeRepoBuildHit(segment, shape);
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
// The whole-repo shape this segment is, or null. One dispatch per program family.
|
|
103
|
-
shapeOf(segment) {
|
|
104
|
-
// Narrowing is judged on the RAW words, BEFORE the runner is stripped: `pnpm --filter core-util
|
|
105
|
-
// test` carries its selector on the RUNNER, and stripping first throws that fact away — which is
|
|
106
|
-
// exactly how a scoped command ends up blocked.
|
|
107
|
-
if (this.isNarrowed(this.scanner.words(segment)))
|
|
108
|
-
return null;
|
|
109
|
-
const words = this.scanner.runnerStrippedWords(segment);
|
|
110
|
-
if (words.length === 0)
|
|
111
|
-
return null;
|
|
112
|
-
const program = this.scanner.programName(words[0]);
|
|
113
|
-
const args = words.slice(1);
|
|
114
|
-
if (WHOLE_REPO_SCRIPTS.has(program))
|
|
115
|
-
return `${program} builds every project`;
|
|
116
|
-
if (program === 'nx')
|
|
117
|
-
return this.nxShape(args);
|
|
118
|
-
if (program === 'vitest')
|
|
119
|
-
return this.vitestShape(args);
|
|
120
|
-
// `test` ONLY as a package-manager script — `pnpm test`, `npm test`, `yarn test`. A NAKED `test`
|
|
121
|
-
// is POSIX test(1) (the `[` builtin), never a build, and treating the bare word as the script
|
|
122
|
-
// is how a fragment of somebody's data ends up classified as a workspace-wide test run.
|
|
123
|
-
if (program === 'test' && args.length === 0 && this.atWorkspaceRoot && this.scanner.viaRunner(segment)) {
|
|
124
|
-
return 'the root `test` script runs every spec in the repo';
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
// Did the caller already scope this command? Judged over the WHOLE segment, so a selector attached
|
|
129
|
-
// to the runner (`pnpm --filter core-util test`) counts just as much as one attached to nx.
|
|
130
|
-
isNarrowed(words) {
|
|
131
|
-
return words.some((w) => NARROWING_FLAGS.some((flag) => w === flag || w.startsWith(`${flag}=`)));
|
|
132
|
-
}
|
|
133
|
-
nxShape(args) {
|
|
134
|
-
const positional = args.filter((a) => !a.startsWith('-'));
|
|
135
|
-
const subcommand = positional[0] ?? '';
|
|
136
|
-
if (subcommand === 'run-many') {
|
|
137
|
-
if (!this.buildsAnything(args, positional))
|
|
138
|
-
return null;
|
|
139
|
-
if (this.hasFlag(args, '--all'))
|
|
140
|
-
return 'nx run-many --all builds every project';
|
|
141
|
-
return 'nx run-many with no --projects builds every project';
|
|
142
|
-
}
|
|
143
|
-
if (subcommand === 'affected') {
|
|
144
|
-
if (this.hasFlag(args, '--base'))
|
|
145
|
-
return null;
|
|
146
|
-
if (!this.buildsAnything(args, positional))
|
|
147
|
-
return null;
|
|
148
|
-
return 'nx affected with no --base compares against a far wider base than the fork point';
|
|
149
|
-
}
|
|
150
|
-
if (subcommand === '' || NX_COMMANDS.has(subcommand))
|
|
151
|
-
return null;
|
|
152
|
-
// `nx <target>` — whole-workspace unless a project name follows it.
|
|
153
|
-
if (positional.length > 1)
|
|
154
|
-
return null;
|
|
155
|
-
if (!BUILD_TARGETS.has(subcommand))
|
|
156
|
-
return null;
|
|
157
|
-
return `nx ${subcommand} with no project runs that target everywhere`;
|
|
158
|
-
}
|
|
159
|
-
vitestShape(args) {
|
|
160
|
-
let rest = args;
|
|
161
|
-
if (rest.length > 0 && VITEST_VERBS.has(rest[0]))
|
|
162
|
-
rest = rest.slice(1);
|
|
163
|
-
for (let i = 0; i < rest.length; i++) {
|
|
164
|
-
const word = rest[i];
|
|
165
|
-
if (!word.startsWith('-'))
|
|
166
|
-
return null; // a path filter — narrowed
|
|
167
|
-
if (VITEST_VALUE_FLAGS.has(word))
|
|
168
|
-
i++; // skip the flag's value
|
|
169
|
-
}
|
|
170
|
-
return 'vitest with no path filter runs every spec in the repo';
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Does this nx invocation run a COMPILE/TEST target? Targets come from `-t`/`--target`/`--targets`
|
|
174
|
-
* in either spelling, comma-separated, plus (for `run-many <target>`) a second positional.
|
|
175
|
-
*
|
|
176
|
-
* An invocation naming NO target is not judged a build: nx errors on it, and guessing would block a
|
|
177
|
-
* typo with a message about build scope. An invocation naming only regeneration targets
|
|
178
|
-
* (`di-graph-generate`, `generate`) is deliberately allowed workspace-wide — see BUILD_TARGETS.
|
|
179
|
-
*/
|
|
180
|
-
buildsAnything(args, positional) {
|
|
181
|
-
const targets = positional.slice(1);
|
|
182
|
-
for (let i = 0; i < args.length; i++) {
|
|
183
|
-
const word = args[i];
|
|
184
|
-
const flag = ['-t', '--target', '--targets'].find((f) => word === f || word.startsWith(`${f}=`));
|
|
185
|
-
if (flag === undefined)
|
|
186
|
-
continue;
|
|
187
|
-
const value = word === flag ? (args[i + 1] ?? '') : word.slice(flag.length + 1);
|
|
188
|
-
targets.push(...value.split(','));
|
|
189
|
-
}
|
|
190
|
-
return targets.some((t) => BUILD_TARGETS.has(t.trim()));
|
|
191
|
-
}
|
|
192
|
-
// `--base` / `--base=<x>` / `--base <x>` — the attached and detached spellings of one flag.
|
|
193
|
-
hasFlag(args, flag) {
|
|
194
|
-
return args.some((a) => a === flag || a.startsWith(`${flag}=`));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.WholeRepoBuildScan = WholeRepoBuildScan;
|
|
198
|
-
//# sourceMappingURL=whole-repo-build-scan.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"whole-repo-build-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/whole-repo-build-scan.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,uGAAuG;AACvG,uGAAuG;AACvG,kEAAkE;AAElE,sGAAsG;AACtG,qGAAqG;AACrG,MAAM,eAAe,GAAsB,CAAC,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;AAEnH,qGAAqG;AACrG,sGAAsG;AACtG,qFAAqF;AACrF,MAAM,kBAAkB,GAAwB,IAAI,GAAG,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AAC;IACrF,CAAC;CACJ;AAzGD,gDAyGC","sourcesContent":["import { CommandScanner } from '../command-scan';\n\n/**\n * Decides the one question whole-repo-build-guard asks of a command: would this segment build (or\n * test) the ENTIRE monorepo rather than the part the change touches?\n *\n * ─── Why this is a SHAPE test and not a string match ───────────────────────────────────────────────\n * The command that motivated the guard is `pnpm run build-all`, but matching that literal buys about a\n * day: `npm run build-all`, `pnpm nx run-many -t ci`, `pnpm exec vitest run` and `time pnpm build-all`\n * are the same build with a different spelling, and an agent that is blocked reaches for the next\n * spelling rather than the smaller build. So the classifier normalizes away the package-manager\n * wrapper first, then judges the PROGRAM and its narrowing arguments:\n *\n * BLOCKED a whole-repo script name — `build-all`, `webpieces:ci`, `wp-ci`, … — under any runner\n * BLOCKED `nx run-many` of a BUILD target with no `-p`/`--projects`, or with `--all`\n * BLOCKED `nx affected` of a BUILD target with no `--base` (a far wider base than the fork point)\n * BLOCKED `nx <target>` with no project argument (`nx test`)\n * BLOCKED `vitest`/`vitest run` with no path, `--project` or `--dir` to narrow it\n * BLOCKED a bare `pnpm test` AT THE WORKSPACE ROOT — the root `test` script is the whole suite.\n * Only under a RUNNER: a naked `test` word is POSIX test(1), and classifying it as the\n * script blocked a polling loop whose jq filter merely contained `test(`.\n *\n * ALLOWED `nx affected --target=ci --base=<anything>` — the gate's own command\n * ALLOWED `nx run <project>:<target>`, `nx run-many -t test -p a b`, `nx test core-util`\n * ALLOWED `vitest run packages/core/core-util`, `vitest run --project core-util`\n * ALLOWED anything carrying `--filter` (pnpm's own narrowing), and every non-build command\n * ALLOWED a workspace-wide REGENERATION — `nx run-many --target=di-graph-generate` — which is\n * supposed to cover every project and which this repo's own docs prescribe\n *\n * Narrowing is judged POSITIVELY: a command is blocked only when the shape is whole-repo AND nothing\n * in it narrows the scope. A flag this file has never heard of therefore fails toward ALLOW, which is\n * the right direction for a guard whose false positive costs an agent its next legitimate command.\n */\n\n// The package-manager wrapper (`pnpm exec vitest`, `npx nx`) is stripped by CommandScanner, which owns\n// that list — see `runnerStrippedWords`. It used to be duplicated here, and a second guard needing the\n// same normalization is exactly when a duplicate starts to drift.\n\n// Any of these ANYWHERE in the segment means the human/agent already scoped the work, so nothing here\n// applies. `--filter` is pnpm's project selector; the nx selectors are checked again per-subcommand.\nconst NARROWING_FLAGS: readonly string[] = ['--filter', '-p', '--projects', '--project', '--dir', '--projectPath'];\n\n// Script/bin names that ARE \"build the world\" in every repo that defines them. `wp-ci` is webpieces'\n// own whole-repo validator and is listed as a PROGRAM as well as a script: blocking `build-all` while\n// leaving the thing it delegates to open would be a guard with a labelled side door.\nconst WHOLE_REPO_SCRIPTS: ReadonlySet<string> = new Set([\n 'build-all', 'build:all', 'buildall',\n 'test-all', 'test:all', 'lint-all', 'ci-all', 'ci:all',\n 'webpieces:ci', 'wp-ci',\n]);\n\n// nx verbs that are NOT \"run this target across the workspace\". Anything else in the first position is\n// read as a TARGET name (`nx test`, `nx build`), which is whole-repo unless a project follows.\nconst NX_COMMANDS: ReadonlySet<string> = new Set([\n 'run', 'run-many', 'affected', 'affected:graph', 'print-affected',\n 'show', 'graph', 'dep-graph', 'reset', 'daemon', 'list', 'report', 'migrate',\n 'generate', 'g', 'new', 'format', 'repair', 'connect', 'add', 'init', 'release',\n 'sync', 'watch', 'exec', 'login', 'logout', 'record', 'view-logs', 'import',\n]);\n\n/**\n * The targets this guard is about. A workspace-wide `nx run-many -t di-graph-generate` or\n * `-t architecture:generate` is a REGENERATION and is supposed to cover every project — the repo's own\n * docs prescribe exactly that, and blocking it would make the guard wrong about a command an agent has\n * to run. Only the compile/test/lint family is a \"build of the world\".\n */\nconst BUILD_TARGETS: ReadonlySet<string> = new Set([\n 'ci', 'build', 'test', 'lint', 'e2e', 'typecheck', 'check', 'compile', 'verify',\n]);\n\n// vitest's leading verb, dropped before looking for a path filter.\nconst VITEST_VERBS: ReadonlySet<string> = new Set(['run', 'watch', 'dev', 'related', 'bench', 'list', 'typecheck', 'init']);\n\n// vitest flags whose VALUE is the next token, so the value is never mistaken for a path filter.\nconst VITEST_VALUE_FLAGS: ReadonlySet<string> = new Set([\n '--reporter', '--config', '-c', '--mode', '-m', '--shard', '--pool', '--environment',\n '--outputFile', '--maxWorkers', '--minWorkers', '--testNamePattern', '-t', '--retry',\n '--testTimeout', '--hookTimeout', '--exclude', '--include', '--coverage.reporter',\n]);\n\n/** One whole-repo build found in a command: the segment, and the SHAPE that made it one. Data-only. */\nexport class WholeRepoBuildHit {\n segment: string;\n shape: string;\n\n constructor(segment: string, shape: string) {\n this.segment = segment;\n this.shape = shape;\n }\n}\n\nexport class WholeRepoBuildScan {\n constructor(\n private readonly scanner: CommandScanner,\n // True when the command runs at the workspace ROOT, where a bare `pnpm test` is the whole suite.\n private readonly atWorkspaceRoot: boolean,\n ) {}\n\n /** The first segment of `command` that builds the whole repo, or null when none does. */\n firstHit(command: string): WholeRepoBuildHit | null {\n for (const segment of this.scanner.commandSegments(command)) {\n const shape = this.shapeOf(segment);\n if (shape !== null) return new WholeRepoBuildHit(segment, shape);\n }\n return null;\n }\n\n // The whole-repo shape this segment is, or null. One dispatch per program family.\n private shapeOf(segment: string): string | null {\n // Narrowing is judged on the RAW words, BEFORE the runner is stripped: `pnpm --filter core-util\n // test` carries its selector on the RUNNER, and stripping first throws that fact away — which is\n // exactly how a scoped command ends up blocked.\n if (this.isNarrowed(this.scanner.words(segment))) return null;\n\n const words = this.scanner.runnerStrippedWords(segment);\n if (words.length === 0) return null;\n\n const program = this.scanner.programName(words[0]);\n const args = words.slice(1);\n\n if (WHOLE_REPO_SCRIPTS.has(program)) return `${program} builds every project`;\n if (program === 'nx') return this.nxShape(args);\n if (program === 'vitest') return this.vitestShape(args);\n // `test` ONLY as a package-manager script — `pnpm test`, `npm test`, `yarn test`. A NAKED `test`\n // is POSIX test(1) (the `[` builtin), never a build, and treating the bare word as the script\n // is how a fragment of somebody's data ends up classified as a workspace-wide test run.\n if (program === 'test' && args.length === 0 && this.atWorkspaceRoot && this.scanner.viaRunner(segment)) {\n return 'the root `test` script runs every spec in the repo';\n }\n return null;\n }\n\n // Did the caller already scope this command? Judged over the WHOLE segment, so a selector attached\n // to the runner (`pnpm --filter core-util test`) counts just as much as one attached to nx.\n private isNarrowed(words: readonly string[]): boolean {\n return words.some((w: string): boolean =>\n NARROWING_FLAGS.some((flag: string): boolean => w === flag || w.startsWith(`${flag}=`)));\n }\n\n private nxShape(args: readonly string[]): string | null {\n const positional = args.filter((a: string): boolean => !a.startsWith('-'));\n const subcommand = positional[0] ?? '';\n\n if (subcommand === 'run-many') {\n if (!this.buildsAnything(args, positional)) return null;\n if (this.hasFlag(args, '--all')) return 'nx run-many --all builds every project';\n return 'nx run-many with no --projects builds every project';\n }\n if (subcommand === 'affected') {\n if (this.hasFlag(args, '--base')) return null;\n if (!this.buildsAnything(args, positional)) return null;\n return 'nx affected with no --base compares against a far wider base than the fork point';\n }\n if (subcommand === '' || NX_COMMANDS.has(subcommand)) return null;\n // `nx <target>` — whole-workspace unless a project name follows it.\n if (positional.length > 1) return null;\n if (!BUILD_TARGETS.has(subcommand)) return null;\n return `nx ${subcommand} with no project runs that target everywhere`;\n }\n\n private vitestShape(args: readonly string[]): string | null {\n let rest = args;\n if (rest.length > 0 && VITEST_VERBS.has(rest[0])) rest = rest.slice(1);\n for (let i = 0; i < rest.length; i++) {\n const word = rest[i];\n if (!word.startsWith('-')) return null; // a path filter — narrowed\n if (VITEST_VALUE_FLAGS.has(word)) i++; // skip the flag's value\n }\n return 'vitest with no path filter runs every spec in the repo';\n }\n\n /**\n * Does this nx invocation run a COMPILE/TEST target? Targets come from `-t`/`--target`/`--targets`\n * in either spelling, comma-separated, plus (for `run-many <target>`) a second positional.\n *\n * An invocation naming NO target is not judged a build: nx errors on it, and guessing would block a\n * typo with a message about build scope. An invocation naming only regeneration targets\n * (`di-graph-generate`, `generate`) is deliberately allowed workspace-wide — see BUILD_TARGETS.\n */\n private buildsAnything(args: readonly string[], positional: readonly string[]): boolean {\n const targets: string[] = positional.slice(1);\n for (let i = 0; i < args.length; i++) {\n const word = args[i];\n const flag = ['-t', '--target', '--targets'].find(\n (f: string): boolean => word === f || word.startsWith(`${f}=`));\n if (flag === undefined) continue;\n const value = word === flag ? (args[i + 1] ?? '') : word.slice(flag.length + 1);\n targets.push(...value.split(','));\n }\n return targets.some((t: string): boolean => BUILD_TARGETS.has(t.trim()));\n }\n\n // `--base` / `--base=<x>` / `--base <x>` — the attached and detached spellings of one flag.\n private hasFlag(args: readonly string[], flag: string): boolean {\n return args.some((a: string): boolean => a === flag || a.startsWith(`${flag}=`));\n }\n}\n"]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HOW MANY TIMES has this session already run this exact Bash command?
|
|
3
|
-
*
|
|
4
|
-
* ─── Why a guard is allowed to ask a question about HISTORY at all ─────────────────────────────────
|
|
5
|
-
* Every other guard here answers from the command TEXT plus the tree's git state, and `managed-env.ts`
|
|
6
|
-
* states that preference out loud: same command, same verdict, every time. That rule exists so a
|
|
7
|
-
* verdict cannot depend on where an unrelated earlier command left the shell — an accident.
|
|
8
|
-
*
|
|
9
|
-
* A SPIN is not an accident, and it is not visible in one command. `gh pr checks 874` asked once is a
|
|
10
|
-
* snapshot somebody acts on; asked for the ninetieth time in four minutes it is the wait loop this
|
|
11
|
-
* whole feature exists to delete, and the two are byte-identical. Repetition IS the defect, so
|
|
12
|
-
* repetition is the only thing that can be measured. Nothing else about the call differs.
|
|
13
|
-
*
|
|
14
|
-
* ─── Where the count comes from ────────────────────────────────────────────────────────────────────
|
|
15
|
-
* `InvocationLog` already writes ONE tab-separated line per guards-hook call to
|
|
16
|
-
* `<state>/logs/calls/<sessionId>-<agentId|coordinator>-<hook>.log`, and `logStream` has already been
|
|
17
|
-
* identified with this session and agent by the time a rule's `check()` runs. So the file IS the
|
|
18
|
-
* session, for free — no new state, no new writer, and a worktree-isolated subagent gets its own
|
|
19
|
-
* because the path is resolved from the tree it acts on.
|
|
20
|
-
*
|
|
21
|
-
* Each tool call is its own process and flushes that line at its terminal boundary, so on call N the
|
|
22
|
-
* file holds calls 1..N-1. The count this returns is therefore PRIOR calls, never including the one
|
|
23
|
-
* being judged.
|
|
24
|
-
*
|
|
25
|
-
* ─── It fails OPEN, always ─────────────────────────────────────────────────────────────────────────
|
|
26
|
-
* A missing file (the first call of a session), a rotated one, an unreadable one — all of them mean
|
|
27
|
-
* "no evidence", which is 0, which blocks nothing. A logging failure may never become a refusal.
|
|
28
|
-
*/
|
|
29
|
-
export declare class SessionCallHistory {
|
|
30
|
-
/**
|
|
31
|
-
* How many times `command` already appears as a Bash target in THIS session's call log.
|
|
32
|
-
*
|
|
33
|
-
* The comparison is against the same one-line normalization `InvocationLog` writes, so a command
|
|
34
|
-
* spanning two lines in the payload and the same command on one line count as the same command.
|
|
35
|
-
*/
|
|
36
|
-
priorBashCalls(root: string, command: string): number;
|
|
37
|
-
/**
|
|
38
|
-
* One logged call is `[<iso>]\tBash\t<target>\tbranch=…` — so field 1 is the tool and field 2 the
|
|
39
|
-
* command. Split rather than `includes`, because a command that MENTIONS another command in its
|
|
40
|
-
* text would otherwise count as that command.
|
|
41
|
-
*/
|
|
42
|
-
private isBashCallOf;
|
|
43
|
-
private lines;
|
|
44
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SessionCallHistory = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
-
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
7
|
-
const log_streams_1 = require("./log-streams");
|
|
8
|
-
const log_stream_1 = require("./log-stream");
|
|
9
|
-
const log_target_1 = require("./log-target");
|
|
10
|
-
const to_error_1 = require("./to-error");
|
|
11
|
-
/**
|
|
12
|
-
* HOW MANY TIMES has this session already run this exact Bash command?
|
|
13
|
-
*
|
|
14
|
-
* ─── Why a guard is allowed to ask a question about HISTORY at all ─────────────────────────────────
|
|
15
|
-
* Every other guard here answers from the command TEXT plus the tree's git state, and `managed-env.ts`
|
|
16
|
-
* states that preference out loud: same command, same verdict, every time. That rule exists so a
|
|
17
|
-
* verdict cannot depend on where an unrelated earlier command left the shell — an accident.
|
|
18
|
-
*
|
|
19
|
-
* A SPIN is not an accident, and it is not visible in one command. `gh pr checks 874` asked once is a
|
|
20
|
-
* snapshot somebody acts on; asked for the ninetieth time in four minutes it is the wait loop this
|
|
21
|
-
* whole feature exists to delete, and the two are byte-identical. Repetition IS the defect, so
|
|
22
|
-
* repetition is the only thing that can be measured. Nothing else about the call differs.
|
|
23
|
-
*
|
|
24
|
-
* ─── Where the count comes from ────────────────────────────────────────────────────────────────────
|
|
25
|
-
* `InvocationLog` already writes ONE tab-separated line per guards-hook call to
|
|
26
|
-
* `<state>/logs/calls/<sessionId>-<agentId|coordinator>-<hook>.log`, and `logStream` has already been
|
|
27
|
-
* identified with this session and agent by the time a rule's `check()` runs. So the file IS the
|
|
28
|
-
* session, for free — no new state, no new writer, and a worktree-isolated subagent gets its own
|
|
29
|
-
* because the path is resolved from the tree it acts on.
|
|
30
|
-
*
|
|
31
|
-
* Each tool call is its own process and flushes that line at its terminal boundary, so on call N the
|
|
32
|
-
* file holds calls 1..N-1. The count this returns is therefore PRIOR calls, never including the one
|
|
33
|
-
* being judged.
|
|
34
|
-
*
|
|
35
|
-
* ─── It fails OPEN, always ─────────────────────────────────────────────────────────────────────────
|
|
36
|
-
* A missing file (the first call of a session), a rotated one, an unreadable one — all of them mean
|
|
37
|
-
* "no evidence", which is 0, which blocks nothing. A logging failure may never become a refusal.
|
|
38
|
-
*/
|
|
39
|
-
class SessionCallHistory {
|
|
40
|
-
/**
|
|
41
|
-
* How many times `command` already appears as a Bash target in THIS session's call log.
|
|
42
|
-
*
|
|
43
|
-
* The comparison is against the same one-line normalization `InvocationLog` writes, so a command
|
|
44
|
-
* spanning two lines in the payload and the same command on one line count as the same command.
|
|
45
|
-
*/
|
|
46
|
-
priorBashCalls(root, command) {
|
|
47
|
-
const wanted = log_target_1.logTarget.oneLine(command);
|
|
48
|
-
if (wanted === '')
|
|
49
|
-
return 0;
|
|
50
|
-
return this.lines(root).filter((line) => this.isBashCallOf(line, wanted)).length;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* One logged call is `[<iso>]\tBash\t<target>\tbranch=…` — so field 1 is the tool and field 2 the
|
|
54
|
-
* command. Split rather than `includes`, because a command that MENTIONS another command in its
|
|
55
|
-
* text would otherwise count as that command.
|
|
56
|
-
*/
|
|
57
|
-
isBashCallOf(line, wanted) {
|
|
58
|
-
const fields = line.split('\t');
|
|
59
|
-
return fields.length > 2 && fields[1] === 'Bash' && fields[2] === wanted;
|
|
60
|
-
}
|
|
61
|
-
lines(root) {
|
|
62
|
-
// webpieces-disable no-unmanaged-exceptions -- a log that cannot be read is NO EVIDENCE, which
|
|
63
|
-
// is the fail-open answer; a logging failure must never become a refusal
|
|
64
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
65
|
-
try {
|
|
66
|
-
const file = tooling_common_1.dotWebpieces.logsFile(root, log_streams_1.CALLS_STREAM, log_stream_1.logStream.writerFile('.log'));
|
|
67
|
-
if (!fs.existsSync(file))
|
|
68
|
-
return [];
|
|
69
|
-
return fs.readFileSync(file, 'utf8').split('\n');
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
const error = (0, to_error_1.toError)(err);
|
|
73
|
-
void error;
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.SessionCallHistory = SessionCallHistory;
|
|
79
|
-
//# sourceMappingURL=session-call-history.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-call-history.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/session-call-history.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AAEzB,8DAAyD;A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;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AArCD,gDAqCC","sourcesContent":["import * as fs from 'fs';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\n\nimport { CALLS_STREAM } from './log-streams';\nimport { logStream } from './log-stream';\nimport { logTarget } from './log-target';\nimport { toError } from './to-error';\n\n/**\n * HOW MANY TIMES has this session already run this exact Bash command?\n *\n * ─── Why a guard is allowed to ask a question about HISTORY at all ─────────────────────────────────\n * Every other guard here answers from the command TEXT plus the tree's git state, and `managed-env.ts`\n * states that preference out loud: same command, same verdict, every time. That rule exists so a\n * verdict cannot depend on where an unrelated earlier command left the shell — an accident.\n *\n * A SPIN is not an accident, and it is not visible in one command. `gh pr checks 874` asked once is a\n * snapshot somebody acts on; asked for the ninetieth time in four minutes it is the wait loop this\n * whole feature exists to delete, and the two are byte-identical. Repetition IS the defect, so\n * repetition is the only thing that can be measured. Nothing else about the call differs.\n *\n * ─── Where the count comes from ────────────────────────────────────────────────────────────────────\n * `InvocationLog` already writes ONE tab-separated line per guards-hook call to\n * `<state>/logs/calls/<sessionId>-<agentId|coordinator>-<hook>.log`, and `logStream` has already been\n * identified with this session and agent by the time a rule's `check()` runs. So the file IS the\n * session, for free — no new state, no new writer, and a worktree-isolated subagent gets its own\n * because the path is resolved from the tree it acts on.\n *\n * Each tool call is its own process and flushes that line at its terminal boundary, so on call N the\n * file holds calls 1..N-1. The count this returns is therefore PRIOR calls, never including the one\n * being judged.\n *\n * ─── It fails OPEN, always ─────────────────────────────────────────────────────────────────────────\n * A missing file (the first call of a session), a rotated one, an unreadable one — all of them mean\n * \"no evidence\", which is 0, which blocks nothing. A logging failure may never become a refusal.\n */\nexport class SessionCallHistory {\n /**\n * How many times `command` already appears as a Bash target in THIS session's call log.\n *\n * The comparison is against the same one-line normalization `InvocationLog` writes, so a command\n * spanning two lines in the payload and the same command on one line count as the same command.\n */\n priorBashCalls(root: string, command: string): number {\n const wanted = logTarget.oneLine(command);\n if (wanted === '') return 0;\n return this.lines(root).filter((line: string): boolean => this.isBashCallOf(line, wanted)).length;\n }\n\n /**\n * One logged call is `[<iso>]\\tBash\\t<target>\\tbranch=…` — so field 1 is the tool and field 2 the\n * command. Split rather than `includes`, because a command that MENTIONS another command in its\n * text would otherwise count as that command.\n */\n private isBashCallOf(line: string, wanted: string): boolean {\n const fields = line.split('\\t');\n return fields.length > 2 && fields[1] === 'Bash' && fields[2] === wanted;\n }\n\n private lines(root: string): readonly string[] {\n // webpieces-disable no-unmanaged-exceptions -- a log that cannot be read is NO EVIDENCE, which\n // is the fail-open answer; a logging failure must never become a refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const file = dotWebpieces.logsFile(root, CALLS_STREAM, logStream.writerFile('.log'));\n if (!fs.existsSync(file)) return [];\n return fs.readFileSync(file, 'utf8').split('\\n');\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n}\n"]}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* READ PARITY, and it is a CODEX-ONLY surface.
|
|
3
|
-
*
|
|
4
|
-
* Claude Code has a first-class `Read` tool, so the read-scoped guard (read-stale-guard) and the
|
|
5
|
-
* `calls/` audit trail see every file the agent opens. Codex has no such tool: a file read arrives as
|
|
6
|
-
* `Bash` running `sed -n '1,240p' <path>` (measured). Without this, every Codex read is invisible to
|
|
7
|
-
* the read guard and to the audit log, and the two harnesses cannot be compared at all.
|
|
8
|
-
*
|
|
9
|
-
* The caller gates this on `aiType === 'codex'`. Nothing here is reachable from a Claude Code payload,
|
|
10
|
-
* and a spec pins that.
|
|
11
|
-
*
|
|
12
|
-
* DELIBERATELY CONSERVATIVE, because a false positive here is not a missed read — it is a Read GUARD
|
|
13
|
-
* verdict applied to a command that was never a read, i.e. a new way to block work:
|
|
14
|
-
*
|
|
15
|
-
* - ONE command only. Any `;` `&&` `||` `|` backtick `$(` or redirect and the answer is "not a read";
|
|
16
|
-
* the command still runs the ordinary bash guards, exactly as today.
|
|
17
|
-
* - `argv[0]` must be one of the six pure pagers, or `sed -n '<range>p'`.
|
|
18
|
-
* - EVERY non-flag argument must resolve to a file that exists inside the tree. `cat /etc/passwd` is
|
|
19
|
-
* not a read of this repo, and neither is a heredoc.
|
|
20
|
-
*
|
|
21
|
-
* A match does NOT replace the bash guards — the caller runs BOTH, and either may deny.
|
|
22
|
-
*/
|
|
23
|
-
export declare const READ_COMMANDS: ReadonlySet<string>;
|
|
24
|
-
/**
|
|
25
|
-
* The only `sed` script shape that is a read: a line range printed with `-n` — as a regex BODY, so the
|
|
26
|
-
* L0 allowlist's ERE twin can be built from the same characters instead of retyping them.
|
|
27
|
-
*
|
|
28
|
-
* EXPORTED for `bin/l0-allowlist.ts`. The L0 entry that lets a Codex session read its way out of an L0
|
|
29
|
-
* fault has to mean the same thing as this module or the two definitions of "read-shaped" drift, and a
|
|
30
|
-
* drifted L0 entry is either a hole or a deadlock. It cannot literally CALL this module — L0's sh half
|
|
31
|
-
* has no JS at all — so the shared thing is the vocabulary, and `codex-l0-read.spec.ts` asserts the two
|
|
32
|
-
* agree over a corpus.
|
|
33
|
-
*/
|
|
34
|
-
export declare const SED_RANGE_BODY = "[0-9]+(,[0-9]+)?p";
|
|
35
|
-
export declare class ShellReadParity {
|
|
36
|
-
/**
|
|
37
|
-
* The absolute paths this command reads, or an empty list when it is not a read-shaped command.
|
|
38
|
-
* `root` is the tree the read must fall inside; a path outside it is not this repo's read.
|
|
39
|
-
*/
|
|
40
|
-
readTargets(command: string, cwd: string, root: string): readonly string[];
|
|
41
|
-
/**
|
|
42
|
-
* `sed`'s operands, or null when this `sed` invocation is not a plain range print. `-n` and a
|
|
43
|
-
* single `<range>p` script are BOTH required: without `-n` sed echoes and edits, and any other
|
|
44
|
-
* script is a transformation, not a read.
|
|
45
|
-
*/
|
|
46
|
-
private sedOperands;
|
|
47
|
-
private isFileInTree;
|
|
48
|
-
/**
|
|
49
|
-
* Split on whitespace, honouring single and double quotes. Returns null on an unterminated quote —
|
|
50
|
-
* a command we cannot read confidently is never a read.
|
|
51
|
-
*
|
|
52
|
-
* There is no escape or expansion handling here on purpose: `NOT_ONE_COMMAND` has already refused
|
|
53
|
-
* everything carrying shell syntax, so what reaches this is a literal argv.
|
|
54
|
-
*/
|
|
55
|
-
private tokenize;
|
|
56
|
-
}
|