@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
package/src/core/command-scan.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared shell-command scanning for the bash guards.
|
|
4
|
-
*
|
|
5
|
-
* A guard that bans a command family (`git merge`, `git push`, …) must answer one question
|
|
6
|
-
* precisely: *does this command actually invoke `git <subcommand>`?* A bare
|
|
7
|
-
* `/\bgit\s+merge\b/.test(command)` gets that wrong in both directions:
|
|
8
|
-
*
|
|
9
|
-
* - False positive: `grep 'git merge main' notes.md` or `echo "git rebase main"` merely MENTION
|
|
10
|
-
* the phrase. A diagnostic grep was blocked this way while triaging the incident that motivated
|
|
11
|
-
* the merge/rebase ban.
|
|
12
|
-
* - False positive: `\b` sits between `e` and `-`, so `/\bgit\s+merge\b/` matches the read-only
|
|
13
|
-
* `git merge-base origin/main HEAD` — which appears in this repo's own documented build command.
|
|
14
|
-
*
|
|
15
|
-
* Both classes vanish if you tokenize instead of substring-match: a command invokes git only when a
|
|
16
|
-
* segment's first word IS `git`, and the subcommand is then an exact token (`merge-base` is simply
|
|
17
|
-
* not the token `merge`). No lookahead regex needed.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.CommandScanner = exports.CommandSegment = void 0;
|
|
21
|
-
// Wrappers/prefixes that may precede the real command word (`sudo git merge`, `GIT_DIR=x git merge`).
|
|
22
|
-
const COMMAND_PREFIXES = new Set(['sudo', 'command', 'nohup', 'time', 'env', 'exec']);
|
|
23
|
-
// git's own global flags that consume the FOLLOWING token as their value, so
|
|
24
|
-
// `git -C /some/path merge main` still resolves to the `merge` subcommand.
|
|
25
|
-
const GIT_FLAGS_WITH_VALUE = new Set([
|
|
26
|
-
'-C', '-c', '--git-dir', '--work-tree', '--namespace', '--exec-path',
|
|
27
|
-
]);
|
|
28
|
-
const ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
29
|
-
// Package-manager wrappers that precede the real program (`pnpm exec vitest`, `npx nx`, `yarn build-all`).
|
|
30
|
-
const RUNNERS = new Set(['pnpm', 'npm', 'yarn', 'npx', 'pnpx', 'bun', 'bunx']);
|
|
31
|
-
// The runner's own verb, consumed with it: `pnpm run build-all` and `pnpm build-all` are one command.
|
|
32
|
-
const RUNNER_VERBS = new Set(['run', 'run-script', 'exec', 'dlx', 'x']);
|
|
33
|
-
/**
|
|
34
|
-
* One invoked segment of a command, plus the operator that joined it to its predecessor.
|
|
35
|
-
*
|
|
36
|
-
* `join === '|'` is what separates `git log | grep foo` (grep consumes the pipe — reads no file) from
|
|
37
|
-
* `grep foo src/` (grep reads the working tree). A guard that cares about which FILES a command
|
|
38
|
-
* reads cannot tell those apart from the segment text alone, because splitting on `|` throws exactly
|
|
39
|
-
* that fact away. `join === '&&'` vs `';'` is the same argument one operator over — see
|
|
40
|
-
* {@link SegmentJoin}. Data-only, so a class (per CLAUDE.md).
|
|
41
|
-
*/
|
|
42
|
-
class CommandSegment {
|
|
43
|
-
text;
|
|
44
|
-
join;
|
|
45
|
-
constructor(text, join) {
|
|
46
|
-
this.text = text;
|
|
47
|
-
this.join = join;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.CommandSegment = CommandSegment;
|
|
51
|
-
class CommandScanner {
|
|
52
|
-
/**
|
|
53
|
-
* Split a raw command into individually-invoked segments.
|
|
54
|
-
*
|
|
55
|
-
* Splits on `&&`, `||`, `;`, `|`, `&`, newline, and the `(`/`)` of subshells and `$(…)` command
|
|
56
|
-
* substitution — the last of these matters, since it means `--base=$(git rebase main)` is scanned
|
|
57
|
-
* as its own `git rebase main` segment rather than hiding inside a `pnpm …` segment.
|
|
58
|
-
*
|
|
59
|
-
* Quoted spans are opaque: a separator inside quotes is literal text, so
|
|
60
|
-
* `git commit -m "fix; ship it"` stays one segment. (Corollary: a `$(…)` nested inside double
|
|
61
|
-
* quotes is not split out. Bash would expand it; we do not scan it. Contrived enough to accept.)
|
|
62
|
-
*/
|
|
63
|
-
commandSegments(command) {
|
|
64
|
-
return this.segmentsWithJoins(command).map((s) => s.text);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* commandSegments, but each segment also carries the OPERATOR that joined it to its predecessor.
|
|
68
|
-
* Only a guard reasoning about which files a segment reads, or about whether a failed first
|
|
69
|
-
* segment can stop the rest, needs that; everything else uses commandSegments, which is this
|
|
70
|
-
* method with the join dropped.
|
|
71
|
-
*/
|
|
72
|
-
segmentsWithJoins(command) {
|
|
73
|
-
const segments = [];
|
|
74
|
-
let current = '';
|
|
75
|
-
let quote = null;
|
|
76
|
-
let join = 'none'; // the operator that ENDED the previous segment
|
|
77
|
-
for (let i = 0; i < command.length; i++) {
|
|
78
|
-
const ch = command[i];
|
|
79
|
-
if (quote !== null) {
|
|
80
|
-
current += ch;
|
|
81
|
-
// A backslash-escaped quote does not close the span (only meaningful inside "…").
|
|
82
|
-
if (ch === quote && command[i - 1] !== '\\')
|
|
83
|
-
quote = null;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (ch === '"' || ch === "'") {
|
|
87
|
-
quote = ch;
|
|
88
|
-
current += ch;
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
// The `&` of a REDIRECTION (`2>&1`, `1>&2`, `&>log`) is not a separator. Splitting on it
|
|
92
|
-
// tore `git fetch origin main 2>&1 | tail -5` into THREE segments — `git fetch … 2>`, `1`
|
|
93
|
-
// and `tail -5` — and the bare `1` is not an allowlisted command, so every guard that
|
|
94
|
-
// requires all segments to pass denied the command. That is `2>&1`, the single most common
|
|
95
|
-
// decoration an agent appends.
|
|
96
|
-
if (ch === '&' && command[i + 1] !== '&' && (current.trimEnd().endsWith('>') || command[i + 1] === '>')) {
|
|
97
|
-
current += ch;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (ch === '\n' || ch === ';' || ch === '|' || ch === '&' || ch === '(' || ch === ')') {
|
|
101
|
-
// Consume the second char of `&&` / `||` so it does not start an empty segment.
|
|
102
|
-
const doubled = (ch === '|' || ch === '&') && command[i + 1] === ch;
|
|
103
|
-
if (doubled)
|
|
104
|
-
i++;
|
|
105
|
-
segments.push(new CommandSegment(current, join));
|
|
106
|
-
// `|` pipes into the next segment; `||` is a separator, not a pipe.
|
|
107
|
-
join = doubled ? (ch + ch) : ch;
|
|
108
|
-
current = '';
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
current += ch;
|
|
112
|
-
}
|
|
113
|
-
segments.push(new CommandSegment(current, join));
|
|
114
|
-
return segments
|
|
115
|
-
.map((s) => new CommandSegment(s.text.trim(), s.join))
|
|
116
|
-
.filter((s) => s.text.length > 0);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* One segment's shell words, with wrappers/env-assignments stripped, so `words('sudo cat a b')`
|
|
120
|
-
* is `['cat', 'a', 'b']`. The public view of the same tokenizer gitSubcommand uses — a guard that
|
|
121
|
-
* must inspect a NON-git command's arguments (which paths does this `grep` actually read?) needs
|
|
122
|
-
* the tokens, and re-splitting on whitespace in the guard would get quoting wrong.
|
|
123
|
-
*/
|
|
124
|
-
words(segment) {
|
|
125
|
-
return this.stripPrefixes(this.tokenize(segment));
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* The git subcommand a segment invokes, or null when the segment does not invoke git at all
|
|
129
|
-
* (a different program, a mere mention inside quotes, an empty segment).
|
|
130
|
-
*
|
|
131
|
-
* Returns the subcommand as an EXACT token: `git merge-base …` yields `'merge-base'`, never `'merge'`.
|
|
132
|
-
*/
|
|
133
|
-
gitSubcommand(segment) {
|
|
134
|
-
return this.gitSubcommandOf(this.stripPrefixes(this.tokenize(segment)));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* gitSubcommand, for a caller that already holds the segment's effective words (ShellSegmentScan
|
|
138
|
-
* strips leading shell keywords, so `do git status` must be resolved from ITS words, not from the
|
|
139
|
-
* raw segment text where `do` is the command).
|
|
140
|
-
*/
|
|
141
|
-
gitSubcommandOf(words) {
|
|
142
|
-
const tokens = this.stripPrefixes(words);
|
|
143
|
-
const at = this.gitSubcommandIndex(tokens);
|
|
144
|
-
return at === -1 ? null : tokens[at];
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* The ARGUMENTS following `git <subcommand>` in this segment, or null when the segment does not
|
|
148
|
-
* invoke that subcommand.
|
|
149
|
-
*
|
|
150
|
-
* `gitSubcommand` answers *which* subcommand; a guard that judges the subcommand's own flags needs
|
|
151
|
-
* the tokens after it, and slicing them in the guard would mean re-deriving where the subcommand
|
|
152
|
-
* sits — i.e. re-deriving the `sudo` / `env VAR=x` / `-C <path>` skipping this class exists to own.
|
|
153
|
-
* `git -C /x commit -m "msg"` yields `['-m', 'msg']`, never `['/x', 'commit', '-m', 'msg']`.
|
|
154
|
-
*
|
|
155
|
-
* The tokens are QUOTE-STRIPPED (see tokenize), so a quoted argument arrives as ONE token holding
|
|
156
|
-
* its literal text — newlines, backticks and all. That is what makes an argument's CONTENT
|
|
157
|
-
* inspectable at all.
|
|
158
|
-
*/
|
|
159
|
-
gitSubcommandArgs(segment, subcommand) {
|
|
160
|
-
const tokens = this.stripPrefixes(this.tokenize(segment));
|
|
161
|
-
const at = this.gitSubcommandIndex(tokens);
|
|
162
|
-
if (at === -1 || tokens[at] !== subcommand)
|
|
163
|
-
return null;
|
|
164
|
-
return tokens.slice(at + 1);
|
|
165
|
-
}
|
|
166
|
-
/** Index of the subcommand token in already-prefix-stripped words, or -1 when git is not invoked. */
|
|
167
|
-
gitSubcommandIndex(tokens) {
|
|
168
|
-
if (tokens.length === 0 || tokens[0] !== 'git')
|
|
169
|
-
return -1;
|
|
170
|
-
let i = 1;
|
|
171
|
-
while (i < tokens.length) {
|
|
172
|
-
const token = tokens[i];
|
|
173
|
-
if (GIT_FLAGS_WITH_VALUE.has(token)) {
|
|
174
|
-
i += 2;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
// `--git-dir=/x` style (value attached) and any other global flag.
|
|
178
|
-
if (token.startsWith('-')) {
|
|
179
|
-
i++;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
return i;
|
|
183
|
-
}
|
|
184
|
-
return -1;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* The segment's words with the package-manager WRAPPER stripped, so `pnpm exec vitest run` and
|
|
188
|
-
* `vitest run` reduce to the same words. `pnpm --silent run build-all` → `['build-all']`.
|
|
189
|
-
*
|
|
190
|
-
* Lives HERE rather than in a guard because two guards now need it and they must agree: one blocks a
|
|
191
|
-
* whole-repo build, the other blocks piping a build's output. If they disagreed about whether
|
|
192
|
-
* `npx wp-build` is `wp-build`, one of them would have a spelling-shaped side door — which is exactly
|
|
193
|
-
* the failure mode the runner stripping exists to close.
|
|
194
|
-
*/
|
|
195
|
-
runnerStrippedWords(segment) {
|
|
196
|
-
let words = this.words(segment);
|
|
197
|
-
while (words.length > 0 && RUNNERS.has(this.programName(words[0]))) {
|
|
198
|
-
words = words.slice(1);
|
|
199
|
-
// The runner's own flags (`--silent`, `-r`) sit between it and the program.
|
|
200
|
-
while (words.length > 0 && words[0].startsWith('-'))
|
|
201
|
-
words = words.slice(1);
|
|
202
|
-
if (words.length > 0 && RUNNER_VERBS.has(words[0]))
|
|
203
|
-
words = words.slice(1);
|
|
204
|
-
}
|
|
205
|
-
return words;
|
|
206
|
-
}
|
|
207
|
-
/** `./node_modules/.bin/nx` and `/usr/local/bin/pnpm.cmd` are the programs `nx` and `pnpm`. */
|
|
208
|
-
programName(token) {
|
|
209
|
-
const base = token.split('/').pop() ?? token;
|
|
210
|
-
return base.endsWith('.cmd') ? base.slice(0, -'.cmd'.length) : base;
|
|
211
|
-
}
|
|
212
|
-
/** True when a package-manager runner precedes the program (`pnpm …`, `npx …`). */
|
|
213
|
-
viaRunner(segment) {
|
|
214
|
-
const raw = this.words(segment);
|
|
215
|
-
return raw.length > 0 && RUNNERS.has(this.programName(raw[0]));
|
|
216
|
-
}
|
|
217
|
-
/** True when this segment actually invokes `git <subcommand>`. */
|
|
218
|
-
invokesGit(segment, subcommand) {
|
|
219
|
-
return this.gitSubcommand(segment) === subcommand;
|
|
220
|
-
}
|
|
221
|
-
/** True when ANY segment of the command invokes one of `subcommands`. */
|
|
222
|
-
commandInvokesAnyGit(command, subcommands) {
|
|
223
|
-
return this.commandSegments(command).some((seg) => subcommands.some((sub) => this.invokesGit(seg, sub)));
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Split one segment into shell words, dropping quote characters (so the ARGUMENT of
|
|
227
|
-
* `echo "git merge main"` is the single word `git merge main`, never the word `git`).
|
|
228
|
-
*/
|
|
229
|
-
tokenize(segment) {
|
|
230
|
-
const tokens = [];
|
|
231
|
-
let current = '';
|
|
232
|
-
let started = false;
|
|
233
|
-
let quote = null;
|
|
234
|
-
for (let i = 0; i < segment.length; i++) {
|
|
235
|
-
const ch = segment[i];
|
|
236
|
-
if (quote !== null) {
|
|
237
|
-
if (ch === quote)
|
|
238
|
-
quote = null;
|
|
239
|
-
else
|
|
240
|
-
current += ch;
|
|
241
|
-
started = true;
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (ch === '"' || ch === "'") {
|
|
245
|
-
quote = ch;
|
|
246
|
-
started = true;
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (/\s/.test(ch)) {
|
|
250
|
-
if (started) {
|
|
251
|
-
tokens.push(current);
|
|
252
|
-
current = '';
|
|
253
|
-
started = false;
|
|
254
|
-
}
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
current += ch;
|
|
258
|
-
started = true;
|
|
259
|
-
}
|
|
260
|
-
if (started)
|
|
261
|
-
tokens.push(current);
|
|
262
|
-
return tokens;
|
|
263
|
-
}
|
|
264
|
-
stripPrefixes(tokens) {
|
|
265
|
-
let i = 0;
|
|
266
|
-
while (i < tokens.length) {
|
|
267
|
-
const token = tokens[i];
|
|
268
|
-
if (COMMAND_PREFIXES.has(token)) {
|
|
269
|
-
i++;
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
if (ENV_ASSIGNMENT.test(token)) {
|
|
273
|
-
i++;
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
return tokens.slice(i);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
exports.CommandScanner = CommandScanner;
|
|
282
|
-
//# sourceMappingURL=command-scan.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-scan.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/command-scan.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,sGAAsG;AACtG,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAE3G,6EAA6E;AAC7E,2EAA2E;AAC3E,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACtD,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa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OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAAC,CAAC,EAAE,CAAC;gBAAC,SAAS;YAAC,CAAC;YACnD,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAAC,CAAC,EAAE,CAAC;gBAAC,SAAS;YAAC,CAAC;YAClD,MAAM;QACV,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;CACJ;AA5OD,wCA4OC","sourcesContent":["/**\n * Shared shell-command scanning for the bash guards.\n *\n * A guard that bans a command family (`git merge`, `git push`, …) must answer one question\n * precisely: *does this command actually invoke `git <subcommand>`?* A bare\n * `/\\bgit\\s+merge\\b/.test(command)` gets that wrong in both directions:\n *\n * - False positive: `grep 'git merge main' notes.md` or `echo \"git rebase main\"` merely MENTION\n * the phrase. A diagnostic grep was blocked this way while triaging the incident that motivated\n * the merge/rebase ban.\n * - False positive: `\\b` sits between `e` and `-`, so `/\\bgit\\s+merge\\b/` matches the read-only\n * `git merge-base origin/main HEAD` — which appears in this repo's own documented build command.\n *\n * Both classes vanish if you tokenize instead of substring-match: a command invokes git only when a\n * segment's first word IS `git`, and the subcommand is then an exact token (`merge-base` is simply\n * not the token `merge`). No lookahead regex needed.\n */\n\n// Wrappers/prefixes that may precede the real command word (`sudo git merge`, `GIT_DIR=x git merge`).\nconst COMMAND_PREFIXES: ReadonlySet<string> = new Set(['sudo', 'command', 'nohup', 'time', 'env', 'exec']);\n\n// git's own global flags that consume the FOLLOWING token as their value, so\n// `git -C /some/path merge main` still resolves to the `merge` subcommand.\nconst GIT_FLAGS_WITH_VALUE: ReadonlySet<string> = new Set([\n '-C', '-c', '--git-dir', '--work-tree', '--namespace', '--exec-path',\n]);\n\nconst ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;\n\n// Package-manager wrappers that precede the real program (`pnpm exec vitest`, `npx nx`, `yarn build-all`).\nconst RUNNERS: ReadonlySet<string> = new Set(['pnpm', 'npm', 'yarn', 'npx', 'pnpx', 'bun', 'bunx']);\n\n// The runner's own verb, consumed with it: `pnpm run build-all` and `pnpm build-all` are one command.\nconst RUNNER_VERBS: ReadonlySet<string> = new Set(['run', 'run-script', 'exec', 'dlx', 'x']);\n\n/**\n * The shell operator that JOINED one segment to the one before it. `'none'` for the first segment.\n *\n * This used to be a single boolean, `pipedInto`, and the widening is what makes composition\n * judgeable. A pipe is only one of the joins whose MEANING differs: `cure && work` short-circuits, so\n * the work cannot run when the cure failed, while `cure ; work` discards the cure's exit code and\n * runs the work anyway. A boolean that answered only \"was it a pipe?\" threw that distinction away,\n * and a guard cannot refuse the dangerous join while allowing the safe one without it.\n */\nexport type SegmentJoin = 'none' | '|' | '&&' | '||' | ';' | '&' | '\\n' | '(' | ')';\n\n/**\n * One invoked segment of a command, plus the operator that joined it to its predecessor.\n *\n * `join === '|'` is what separates `git log | grep foo` (grep consumes the pipe — reads no file) from\n * `grep foo src/` (grep reads the working tree). A guard that cares about which FILES a command\n * reads cannot tell those apart from the segment text alone, because splitting on `|` throws exactly\n * that fact away. `join === '&&'` vs `';'` is the same argument one operator over — see\n * {@link SegmentJoin}. Data-only, so a class (per CLAUDE.md).\n */\nexport class CommandSegment {\n text: string;\n join: SegmentJoin;\n\n constructor(text: string, join: SegmentJoin) {\n this.text = text;\n this.join = join;\n }\n}\n\nexport class CommandScanner {\n /**\n * Split a raw command into individually-invoked segments.\n *\n * Splits on `&&`, `||`, `;`, `|`, `&`, newline, and the `(`/`)` of subshells and `$(…)` command\n * substitution — the last of these matters, since it means `--base=$(git rebase main)` is scanned\n * as its own `git rebase main` segment rather than hiding inside a `pnpm …` segment.\n *\n * Quoted spans are opaque: a separator inside quotes is literal text, so\n * `git commit -m \"fix; ship it\"` stays one segment. (Corollary: a `$(…)` nested inside double\n * quotes is not split out. Bash would expand it; we do not scan it. Contrived enough to accept.)\n */\n commandSegments(command: string): readonly string[] {\n return this.segmentsWithJoins(command).map((s: CommandSegment): string => s.text);\n }\n\n /**\n * commandSegments, but each segment also carries the OPERATOR that joined it to its predecessor.\n * Only a guard reasoning about which files a segment reads, or about whether a failed first\n * segment can stop the rest, needs that; everything else uses commandSegments, which is this\n * method with the join dropped.\n */\n segmentsWithJoins(command: string): readonly CommandSegment[] {\n const segments: CommandSegment[] = [];\n let current = '';\n let quote: string | null = null;\n let join: SegmentJoin = 'none'; // the operator that ENDED the previous segment\n\n for (let i = 0; i < command.length; i++) {\n const ch = command[i];\n\n if (quote !== null) {\n current += ch;\n // A backslash-escaped quote does not close the span (only meaningful inside \"…\").\n if (ch === quote && command[i - 1] !== '\\\\') quote = null;\n continue;\n }\n\n if (ch === '\"' || ch === \"'\") {\n quote = ch;\n current += ch;\n continue;\n }\n\n // The `&` of a REDIRECTION (`2>&1`, `1>&2`, `&>log`) is not a separator. Splitting on it\n // tore `git fetch origin main 2>&1 | tail -5` into THREE segments — `git fetch … 2>`, `1`\n // and `tail -5` — and the bare `1` is not an allowlisted command, so every guard that\n // requires all segments to pass denied the command. That is `2>&1`, the single most common\n // decoration an agent appends.\n if (ch === '&' && command[i + 1] !== '&' && (current.trimEnd().endsWith('>') || command[i + 1] === '>')) {\n current += ch;\n continue;\n }\n\n if (ch === '\\n' || ch === ';' || ch === '|' || ch === '&' || ch === '(' || ch === ')') {\n // Consume the second char of `&&` / `||` so it does not start an empty segment.\n const doubled = (ch === '|' || ch === '&') && command[i + 1] === ch;\n if (doubled) i++;\n segments.push(new CommandSegment(current, join));\n // `|` pipes into the next segment; `||` is a separator, not a pipe.\n join = doubled ? ((ch + ch) as SegmentJoin) : (ch as SegmentJoin);\n current = '';\n continue;\n }\n\n current += ch;\n }\n segments.push(new CommandSegment(current, join));\n\n return segments\n .map((s: CommandSegment): CommandSegment => new CommandSegment(s.text.trim(), s.join))\n .filter((s: CommandSegment): boolean => s.text.length > 0);\n }\n\n /**\n * One segment's shell words, with wrappers/env-assignments stripped, so `words('sudo cat a b')`\n * is `['cat', 'a', 'b']`. The public view of the same tokenizer gitSubcommand uses — a guard that\n * must inspect a NON-git command's arguments (which paths does this `grep` actually read?) needs\n * the tokens, and re-splitting on whitespace in the guard would get quoting wrong.\n */\n words(segment: string): readonly string[] {\n return this.stripPrefixes(this.tokenize(segment));\n }\n\n /**\n * The git subcommand a segment invokes, or null when the segment does not invoke git at all\n * (a different program, a mere mention inside quotes, an empty segment).\n *\n * Returns the subcommand as an EXACT token: `git merge-base …` yields `'merge-base'`, never `'merge'`.\n */\n gitSubcommand(segment: string): string | null {\n return this.gitSubcommandOf(this.stripPrefixes(this.tokenize(segment)));\n }\n\n /**\n * gitSubcommand, for a caller that already holds the segment's effective words (ShellSegmentScan\n * strips leading shell keywords, so `do git status` must be resolved from ITS words, not from the\n * raw segment text where `do` is the command).\n */\n gitSubcommandOf(words: readonly string[]): string | null {\n const tokens = this.stripPrefixes(words);\n const at = this.gitSubcommandIndex(tokens);\n return at === -1 ? null : tokens[at];\n }\n\n /**\n * The ARGUMENTS following `git <subcommand>` in this segment, or null when the segment does not\n * invoke that subcommand.\n *\n * `gitSubcommand` answers *which* subcommand; a guard that judges the subcommand's own flags needs\n * the tokens after it, and slicing them in the guard would mean re-deriving where the subcommand\n * sits — i.e. re-deriving the `sudo` / `env VAR=x` / `-C <path>` skipping this class exists to own.\n * `git -C /x commit -m \"msg\"` yields `['-m', 'msg']`, never `['/x', 'commit', '-m', 'msg']`.\n *\n * The tokens are QUOTE-STRIPPED (see tokenize), so a quoted argument arrives as ONE token holding\n * its literal text — newlines, backticks and all. That is what makes an argument's CONTENT\n * inspectable at all.\n */\n gitSubcommandArgs(segment: string, subcommand: string): readonly string[] | null {\n const tokens = this.stripPrefixes(this.tokenize(segment));\n const at = this.gitSubcommandIndex(tokens);\n if (at === -1 || tokens[at] !== subcommand) return null;\n return tokens.slice(at + 1);\n }\n\n /** Index of the subcommand token in already-prefix-stripped words, or -1 when git is not invoked. */\n private gitSubcommandIndex(tokens: readonly string[]): number {\n if (tokens.length === 0 || tokens[0] !== 'git') return -1;\n\n let i = 1;\n while (i < tokens.length) {\n const token = tokens[i];\n if (GIT_FLAGS_WITH_VALUE.has(token)) { i += 2; continue; }\n // `--git-dir=/x` style (value attached) and any other global flag.\n if (token.startsWith('-')) { i++; continue; }\n return i;\n }\n return -1;\n }\n\n /**\n * The segment's words with the package-manager WRAPPER stripped, so `pnpm exec vitest run` and\n * `vitest run` reduce to the same words. `pnpm --silent run build-all` → `['build-all']`.\n *\n * Lives HERE rather than in a guard because two guards now need it and they must agree: one blocks a\n * whole-repo build, the other blocks piping a build's output. If they disagreed about whether\n * `npx wp-build` is `wp-build`, one of them would have a spelling-shaped side door — which is exactly\n * the failure mode the runner stripping exists to close.\n */\n runnerStrippedWords(segment: string): readonly string[] {\n let words = this.words(segment);\n while (words.length > 0 && RUNNERS.has(this.programName(words[0]))) {\n words = words.slice(1);\n // The runner's own flags (`--silent`, `-r`) sit between it and the program.\n while (words.length > 0 && words[0].startsWith('-')) words = words.slice(1);\n if (words.length > 0 && RUNNER_VERBS.has(words[0])) words = words.slice(1);\n }\n return words;\n }\n\n /** `./node_modules/.bin/nx` and `/usr/local/bin/pnpm.cmd` are the programs `nx` and `pnpm`. */\n programName(token: string): string {\n const base = token.split('/').pop() ?? token;\n return base.endsWith('.cmd') ? base.slice(0, -'.cmd'.length) : base;\n }\n\n /** True when a package-manager runner precedes the program (`pnpm …`, `npx …`). */\n viaRunner(segment: string): boolean {\n const raw = this.words(segment);\n return raw.length > 0 && RUNNERS.has(this.programName(raw[0]));\n }\n\n /** True when this segment actually invokes `git <subcommand>`. */\n invokesGit(segment: string, subcommand: string): boolean {\n return this.gitSubcommand(segment) === subcommand;\n }\n\n /** True when ANY segment of the command invokes one of `subcommands`. */\n commandInvokesAnyGit(command: string, subcommands: readonly string[]): boolean {\n return this.commandSegments(command).some((seg: string) =>\n subcommands.some((sub: string) => this.invokesGit(seg, sub)));\n }\n\n /**\n * Split one segment into shell words, dropping quote characters (so the ARGUMENT of\n * `echo \"git merge main\"` is the single word `git merge main`, never the word `git`).\n */\n private tokenize(segment: string): readonly string[] {\n const tokens: string[] = [];\n let current = '';\n let started = false;\n let quote: string | null = null;\n\n for (let i = 0; i < segment.length; i++) {\n const ch = segment[i];\n\n if (quote !== null) {\n if (ch === quote) quote = null;\n else current += ch;\n started = true;\n continue;\n }\n\n if (ch === '\"' || ch === \"'\") {\n quote = ch;\n started = true;\n continue;\n }\n\n if (/\\s/.test(ch)) {\n if (started) {\n tokens.push(current);\n current = '';\n started = false;\n }\n continue;\n }\n\n current += ch;\n started = true;\n }\n if (started) tokens.push(current);\n\n return tokens;\n }\n\n private stripPrefixes(tokens: readonly string[]): readonly string[] {\n let i = 0;\n while (i < tokens.length) {\n const token = tokens[i];\n if (COMMAND_PREFIXES.has(token)) { i++; continue; }\n if (ENV_ASSIGNMENT.test(token)) { i++; continue; }\n break;\n }\n return tokens.slice(i);\n }\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AbstractRule, BaseRuleConfig, RuleOptions } from '@webpieces/rules-config';
|
|
2
|
-
import type { PlainRule, Rule, RuleScope, EditContext, FileContext, BashContext, Violation } from './types';
|
|
3
|
-
import type { FixHint } from './fix-hint';
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a custom rule loaded from a `rulesDir` (a plain object) so it satisfies the same
|
|
6
|
-
* runtime `Rule` contract as the built-in rule classes: it gains `shouldRun()` (driven by the
|
|
7
|
-
* rule's config entry in webpieces.config.json) from AbstractRule, and it seeds `ctx.options`
|
|
8
|
-
* with the merged option bag before delegating to the plain rule's `check()` — preserving the
|
|
9
|
-
* exact behavior custom rules had under the old options-based runner.
|
|
10
|
-
*/
|
|
11
|
-
export declare class CustomRuleAdapter extends AbstractRule<BaseRuleConfig> implements Rule {
|
|
12
|
-
readonly scope: RuleScope;
|
|
13
|
-
readonly files: readonly string[];
|
|
14
|
-
readonly description: string;
|
|
15
|
-
readonly fixHint: FixHint;
|
|
16
|
-
readonly defaultOptions: RuleOptions;
|
|
17
|
-
private readonly impl;
|
|
18
|
-
private readonly rawConfig;
|
|
19
|
-
constructor(impl: PlainRule, rawConfig: RuleOptions);
|
|
20
|
-
private buildOptions;
|
|
21
|
-
check(ctx: EditContext | FileContext | BashContext): readonly Violation[];
|
|
22
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomRuleAdapter = void 0;
|
|
4
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
-
/**
|
|
6
|
-
* Wraps a custom rule loaded from a `rulesDir` (a plain object) so it satisfies the same
|
|
7
|
-
* runtime `Rule` contract as the built-in rule classes: it gains `shouldRun()` (driven by the
|
|
8
|
-
* rule's config entry in webpieces.config.json) from AbstractRule, and it seeds `ctx.options`
|
|
9
|
-
* with the merged option bag before delegating to the plain rule's `check()` — preserving the
|
|
10
|
-
* exact behavior custom rules had under the old options-based runner.
|
|
11
|
-
*/
|
|
12
|
-
class CustomRuleAdapter extends rules_config_1.AbstractRule {
|
|
13
|
-
scope;
|
|
14
|
-
files;
|
|
15
|
-
description;
|
|
16
|
-
fixHint;
|
|
17
|
-
defaultOptions;
|
|
18
|
-
impl;
|
|
19
|
-
rawConfig;
|
|
20
|
-
constructor(impl, rawConfig) {
|
|
21
|
-
// A custom rule from `rulesDir` is keyed in webpieces.config.json by its own `name`, so the
|
|
22
|
-
// two identities coincide. Stated twice rather than defaulted — see AbstractRule.
|
|
23
|
-
super(rawConfig, impl.name, impl.name);
|
|
24
|
-
this.impl = impl;
|
|
25
|
-
this.scope = impl.scope;
|
|
26
|
-
this.files = impl.files;
|
|
27
|
-
this.description = impl.description;
|
|
28
|
-
this.fixHint = impl.fixHint;
|
|
29
|
-
this.defaultOptions = impl.defaultOptions;
|
|
30
|
-
this.rawConfig = rawConfig;
|
|
31
|
-
}
|
|
32
|
-
buildOptions() {
|
|
33
|
-
const out = {};
|
|
34
|
-
for (const key of Object.keys(this.defaultOptions))
|
|
35
|
-
out[key] = this.defaultOptions[key];
|
|
36
|
-
for (const key of Object.keys(this.rawConfig)) {
|
|
37
|
-
// 'mode' is the framework-level on/off switch, not a rule option.
|
|
38
|
-
if (key === 'mode')
|
|
39
|
-
continue;
|
|
40
|
-
out[key] = this.rawConfig[key];
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
check(ctx) {
|
|
45
|
-
ctx.options = this.buildOptions();
|
|
46
|
-
return this.impl.check(ctx);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.CustomRuleAdapter = CustomRuleAdapter;
|
|
50
|
-
//# sourceMappingURL=custom-rule-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-rule-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/custom-rule-adapter.ts"],"names":[],"mappings":";;;AAAA,0DAAoF;AAQpF;;;;;;GAMG;AACH,MAAa,iBAAkB,SAAQ,2BAA4B;IACtD,KAAK,CAAY;IACjB,KAAK,CAAoB;IACzB,WAAW,CAAS;IACpB,OAAO,CAAU;IACjB,cAAc,CAAc;IACpB,IAAI,CAAY;IAChB,SAAS,CAAc;IAExC,YAAY,IAAe,EAAE,SAAsB;QAC/C,4FAA4F;QAC5F,kFAAkF;QAClF,KAAK,CAAC,SAA2B,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAEO,YAAY;QAChB,MAAM,GAAG,GAAgB,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACxF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5C,kEAAkE;YAClE,IAAI,GAAG,KAAK,MAAM;gBAAE,SAAS;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,KAAK,CAAC,GAA4C;QAC9C,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;CACJ;AArCD,8CAqCC","sourcesContent":["import { AbstractRule, BaseRuleConfig, RuleOptions } from '@webpieces/rules-config';\n\nimport type {\n PlainRule, Rule, RuleScope,\n EditContext, FileContext, BashContext, Violation,\n} from './types';\nimport type { FixHint } from './fix-hint';\n\n/**\n * Wraps a custom rule loaded from a `rulesDir` (a plain object) so it satisfies the same\n * runtime `Rule` contract as the built-in rule classes: it gains `shouldRun()` (driven by the\n * rule's config entry in webpieces.config.json) from AbstractRule, and it seeds `ctx.options`\n * with the merged option bag before delegating to the plain rule's `check()` — preserving the\n * exact behavior custom rules had under the old options-based runner.\n */\nexport class CustomRuleAdapter extends AbstractRule<BaseRuleConfig> implements Rule {\n readonly scope: RuleScope;\n readonly files: readonly string[];\n readonly description: string;\n readonly fixHint: FixHint;\n readonly defaultOptions: RuleOptions;\n private readonly impl: PlainRule;\n private readonly rawConfig: RuleOptions;\n\n constructor(impl: PlainRule, rawConfig: RuleOptions) {\n // A custom rule from `rulesDir` is keyed in webpieces.config.json by its own `name`, so the\n // two identities coincide. Stated twice rather than defaulted — see AbstractRule.\n super(rawConfig as BaseRuleConfig, impl.name, impl.name);\n this.impl = impl;\n this.scope = impl.scope;\n this.files = impl.files;\n this.description = impl.description;\n this.fixHint = impl.fixHint;\n this.defaultOptions = impl.defaultOptions;\n this.rawConfig = rawConfig;\n }\n\n private buildOptions(): RuleOptions {\n const out: RuleOptions = {};\n for (const key of Object.keys(this.defaultOptions)) out[key] = this.defaultOptions[key];\n for (const key of Object.keys(this.rawConfig)) {\n // 'mode' is the framework-level on/off switch, not a rule option.\n if (key === 'mode') continue;\n out[key] = this.rawConfig[key];\n }\n return out;\n }\n\n check(ctx: EditContext | FileContext | BashContext): readonly Violation[] {\n ctx.options = this.buildOptions();\n return this.impl.check(ctx);\n }\n}\n"]}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE ACTION CODEBOOK, as a type. These are the five actions GUARD_MATRIX.md numbers 1-5, and they
|
|
3
|
-
* are the vocabulary EVERY layer reports in — so one grep spans L-1, L0, L1 and L2.
|
|
4
|
-
*
|
|
5
|
-
* The three distinctions this exists to make, none of which `'ALLOW' | 'BLOCK'` could:
|
|
6
|
-
*
|
|
7
|
-
* ALLOW no objection — the call was HANDED DOWN to the next layer. A layer saying ALLOW
|
|
8
|
-
* is NOT saying the call ran: the layer below it, or the OTHER parallel hook, may
|
|
9
|
-
* still deny. This is L1's `ACT_DOWN`.
|
|
10
|
-
* ALLOW_EXEMPT out of scope by construction — allowed, and evaluation STOPS here. L1's
|
|
11
|
-
* `ACT_EXEMPT`.
|
|
12
|
-
* ALLOW_FAIL_OPEN state could not be established, so nothing was judged. Keeping this distinct
|
|
13
|
-
* from ALLOW is the entire point of the type: a fail-open allow and a real allow
|
|
14
|
-
* that look identical make it impossible to tell whether the guards are protecting
|
|
15
|
-
* anything or quietly abstaining. It used to be a `' (fail-open)'` SUBSTRING on the
|
|
16
|
-
* reason field, which is exactly why the abstentions were never countable.
|
|
17
|
-
* BLOCK_AI_CURE blocked, and the printed cure is a command the AI can run itself.
|
|
18
|
-
* BLOCK_HUMAN blocked, and it needs a human decision — or a delegation (spawn a subagent) that
|
|
19
|
-
* the blocked agent cannot perform for itself.
|
|
20
|
-
*
|
|
21
|
-
* Hard cut, per `.claude/rules/no-backwards-compat.md`: `'BLOCK'` is GONE rather than aliased, so every
|
|
22
|
-
* construction site fails to
|
|
23
|
-
* compile and has to say which kind of block it is. Before, that question had exactly one wrong
|
|
24
|
-
* answer available — silence.
|
|
25
|
-
*/
|
|
26
|
-
export type Verdict = 'ALLOW' | 'ALLOW_EXEMPT' | 'ALLOW_FAIL_OPEN' | 'BLOCK_AI_CURE' | 'BLOCK_HUMAN';
|
|
27
|
-
/**
|
|
28
|
-
* WHICH ROW of WHICH layer's decision table produced this line. Data-only → a class, per CLAUDE.md.
|
|
29
|
-
*
|
|
30
|
-
* `row` is the row NUMBER from the layer's row array (`L1_ROWS[i].num`, `L2_ROWS[i].num`) — the
|
|
31
|
-
* same number the generated doc prints, because the doc is rendered from that same array. So a log
|
|
32
|
-
* line joins to its matrix row BY NUMBER, and checking observed behaviour against the documented use
|
|
33
|
-
* cases becomes a lookup rather than an investigation.
|
|
34
|
-
*/
|
|
35
|
-
export declare class MatrixRef {
|
|
36
|
-
readonly layer: string;
|
|
37
|
-
readonly row: string;
|
|
38
|
-
constructor(layer: string, row: string);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The layer tokens. EVERY layer now cites a row: L0 through its two decision-matrix rows, L1 through
|
|
42
|
-
* L1_ROWS, and L2 through L2_ROWS (see `matrixL2Row`). This used to say `'-'` was for "a layer with no
|
|
43
|
-
* row array YET (L2 is the un-converted one)" — L2 is converted, and a comment describing a state the
|
|
44
|
-
* code left behind is exactly the kind of doc a reader trusts and should not.
|
|
45
|
-
*
|
|
46
|
-
* `'-'` survives for ONE case, and it is a real one: an L2 reason that no row claims. See matrixL2Row.
|
|
47
|
-
*
|
|
48
|
-
* These are REQUIRED at the constructor, not defaulted: a defaulted `MatrixRef` would make the
|
|
49
|
-
* uncited case reachable by doing nothing and impossible to grep — the same defect this file's own
|
|
50
|
-
* docblock argues against for `'BLOCK'`, where silence was the one wrong answer available.
|
|
51
|
-
*
|
|
52
|
-
* L0 NOW CITES ITS ROW TOO. It used to be `'-'` on the grounds that "L0's faults are a table of letters
|
|
53
|
-
* rather than numbered rows" — but L0 has BOTH: the letter says WHICH fault, and the numbered decision
|
|
54
|
-
* matrix (`renderGuardMatrixDoc`) says which of its three rows was taken. There is one ALLOW row and one
|
|
55
|
-
* BLOCK row, so the pair `row=` + `fault=` pins the decision exactly, and the deny an agent reads now
|
|
56
|
-
* carries the identical pair. That is the join: one grep spans the deny, the log line and the doc.
|
|
57
|
-
* Two constants, not one `MATRIX_L0`, because the two call sites are a cure-bypass ALLOW and an L0
|
|
58
|
-
* BLOCK — one token covering both is what made the row unciteable in the first place.
|
|
59
|
-
*/
|
|
60
|
-
export declare const MATRIX_L0_ALLOW: MatrixRef;
|
|
61
|
-
export declare const MATRIX_L0_BLOCK: MatrixRef;
|
|
62
|
-
/**
|
|
63
|
-
* The L2 reference for one decision, with the row DERIVED FROM THE REASON.
|
|
64
|
-
*
|
|
65
|
-
* There is no `MATRIX_L2` constant any more, and its absence is the point: a single shared instance
|
|
66
|
-
* meant every L2 line in the repo carried `row=-`, which reads as "L2 has no rows" rather than "this
|
|
67
|
-
* decision was not classified". Deleting it makes every construction site name a reason, and the reason
|
|
68
|
-
* is the only thing a call site has that identifies which row it is an instance of.
|
|
69
|
-
*
|
|
70
|
-
* `l2RowForReason` returns null for a reason no row claims, and that renders as `'-'` — visible in the
|
|
71
|
-
* log, not silently absorbed into a default row. l2-matrix.spec.ts reads the four guard sources and
|
|
72
|
-
* fails the build if any reason literal in them is unmapped, so `-` should never appear in practice;
|
|
73
|
-
* when it does, it is a genuine hole in the table and the log says so.
|
|
74
|
-
*/
|
|
75
|
-
export declare function matrixL2Row(reason: string): MatrixRef;
|
|
76
|
-
/**
|
|
77
|
-
* The L2 stream, with NO row — for the two kinds of line that genuinely are not an instance of a row.
|
|
78
|
-
*
|
|
79
|
-
* 1. The runner's AGGREGATE bash lines ("no bash-guard block" / "bash-guard block"). They summarise
|
|
80
|
-
* the whole guard set's answer for one command, not one row's verdict; the per-guard lines that
|
|
81
|
-
* DO cite rows are written alongside them by the guards themselves.
|
|
82
|
-
* 2. `whole-repo-build-guard`, which is not a branch-state policy at all — it is the experimental
|
|
83
|
-
* home-config guard, has no webpieces.config.json entry, and shares this stream only because the
|
|
84
|
-
* stream is "bash decisions", not "L2 rows".
|
|
85
|
-
*
|
|
86
|
-
* A NAMED constant rather than an inline `new MatrixRef('L2', '-')`, so `grep MATRIX_L2_UNROWED` lists
|
|
87
|
-
* every uncited line and the list stays short and arguable. It is deliberately NOT called `MATRIX_L2`:
|
|
88
|
-
* the old name was used by everything and made "L2 has no rows" indistinguishable from "this line is
|
|
89
|
-
* not a row".
|
|
90
|
-
*/
|
|
91
|
-
export declare const MATRIX_L2_UNROWED: MatrixRef;
|
|
92
|
-
export declare class GuardDecision {
|
|
93
|
-
rule: string;
|
|
94
|
-
tool: string;
|
|
95
|
-
target: string;
|
|
96
|
-
branch: string;
|
|
97
|
-
verdict: Verdict;
|
|
98
|
-
reason: string;
|
|
99
|
-
cache: string;
|
|
100
|
-
/**
|
|
101
|
-
* The L0 fault this decision IS, in the codebook's letter (core/l0-fault-codes.ts), or `-` for an
|
|
102
|
-
* ordinary rule decision. The `sh` shim has always stamped `fault=` on its own stream; the three
|
|
103
|
-
* JS-side faults (S/C/Y) reached this one with no label at all, so `grep fault=S` found nothing
|
|
104
|
-
* even while an S storm was blocking every call.
|
|
105
|
-
*/
|
|
106
|
-
fault: string;
|
|
107
|
-
/** Which layer + row decided this. See MatrixRef — it is what joins a log line to the doc. */
|
|
108
|
-
matrix: MatrixRef;
|
|
109
|
-
constructor(rule: string, tool: string, target: string, branch: string, verdict: Verdict, reason: string, cache: string | undefined, fault: string, matrix: MatrixRef);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Append one tab-separated line per L2 decision to `.webpieces/logs/L2-decisions/<writer>.log`, where
|
|
113
|
-
* <writer> is LogStream's `<sessionId>-<agentId|coordinator>-<hook>` key (a caller that never
|
|
114
|
-
* identified renders as `unknown-coordinator-hook` — there is no un-keyed name).
|
|
115
|
-
* `root` is
|
|
116
|
-
* the repo/workspace root that holds `.webpieces` (callers pass workspaceRoot, or a
|
|
117
|
-
* RepoRootFinder-resolved root at the pre-load config-bypass site — never a raw cwd, so a bypass
|
|
118
|
-
* logged from a subdir never scatters a stray `.webpieces`). Swallows all errors — logging must never
|
|
119
|
-
* block or fail a hook.
|
|
120
|
-
*/
|
|
121
|
-
export declare function logGuardDecision(root: string, decision: GuardDecision): void;
|
|
122
|
-
/**
|
|
123
|
-
* The L1 stream — `.webpieces/logs/L1-location/<writer>.log`.
|
|
124
|
-
*
|
|
125
|
-
* L1 had NO stream. Its three blocking paths wrote into L2's file under an implementation name
|
|
126
|
-
* (`force-to-root`, `trinary-version-skew`, `cd-must-be-first`), and its NON-blocking outcomes —
|
|
127
|
-
* the exempt row and the three hand-down rows — wrote nothing at all. So "L1 had no objection" was
|
|
128
|
-
* unobservable, and "show me every L1 decision" had no answer: L1 existed in the trail only as the
|
|
129
|
-
* `root=` / `projectDir=` / `tree=` columns stapled onto somebody else's line.
|
|
130
|
-
*
|
|
131
|
-
* A SIBLING rather than a `base` parameter on logGuardDecision, deliberately: that signature is what
|
|
132
|
-
* the process-wide `logStream` singleton exists to keep unchanged (see LogStream's docblock), and
|
|
133
|
-
* `INVOCATION_LOG_FILE` already establishes the pattern of a second stream owning its own name in
|
|
134
|
-
* this same module.
|
|
135
|
-
*/
|
|
136
|
-
export declare function logL1Decision(root: string, decision: GuardDecision): void;
|
|
137
|
-
/**
|
|
138
|
-
* What the guard SAW on one invocation, captured up front and held until the outcome is known.
|
|
139
|
-
* Data-only (per CLAUDE.md: classes for data, explicit construction).
|
|
140
|
-
*/
|
|
141
|
-
export declare class GuardInvocation {
|
|
142
|
-
readonly root: string;
|
|
143
|
-
readonly timestamp: string;
|
|
144
|
-
readonly tool: string;
|
|
145
|
-
readonly target: string;
|
|
146
|
-
readonly branch: string;
|
|
147
|
-
readonly sync: string;
|
|
148
|
-
readonly projectDir: string;
|
|
149
|
-
constructor(root: string, timestamp: string, tool: string, target: string, branch: string, sync: string, projectDir: string);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* The per-INVOCATION stream — `.webpieces/logs/calls/<writer>.log` (see LogStream for the writer
|
|
153
|
-
* key), one line for EVERY guards-hook
|
|
154
|
-
* call (allow or block, bash or file), unlike `L2-decisions/` which records only the calls a
|
|
155
|
-
* rule actually judged. It captures the tool, the command/file, the live git branch, the async-written
|
|
156
|
-
* main-sync-status.json snapshot (branch / merged / fork-point / conflict), and — since this class
|
|
157
|
-
* replaced a bare log-and-forget function — HOW THE CALL ENDED.
|
|
158
|
-
*
|
|
159
|
-
* WHY IT IS TWO CALLS. The line used to be written the moment the hook started, so it could not carry
|
|
160
|
-
* a verdict: the decision had not been made yet. Answering "what happened to this call?" therefore
|
|
161
|
-
* meant joining this file against the L2 decision stream BY TIMESTAMP, which is exactly the kind of
|
|
162
|
-
* reconstruction a log exists to make unnecessary. So {@link begin} now only CAPTURES (including the
|
|
163
|
-
* git/cache reads, which must still happen while the hook is running), and {@link finish} — called
|
|
164
|
-
* from the hook's single terminal boundary, emitAllow/emitDeny — writes the whole line once the
|
|
165
|
-
* outcome is known. The two streams stay distinct in purpose: this one is "every call and how it
|
|
166
|
-
* ended", the decision log remains "every judgement and why".
|
|
167
|
-
*
|
|
168
|
-
* Every error is swallowed: logging must never block or fail a hook.
|
|
169
|
-
*/
|
|
170
|
-
export declare class InvocationLog {
|
|
171
|
-
private pending;
|
|
172
|
-
/**
|
|
173
|
-
* Capture the context of one invocation. `cwd` is the AI's working dir; the repo root that owns
|
|
174
|
-
* `.webpieces` is resolved from it. Writes NOTHING — {@link finish} does that.
|
|
175
|
-
*/
|
|
176
|
-
begin(cwd: string, tool: string, target: string): void;
|
|
177
|
-
/**
|
|
178
|
-
* Write the captured line, now stamped with the outcome. A no-op when nothing was captured (the
|
|
179
|
-
* 'rules' hook, or a terminal boundary reached before begin()), and it clears the pending entry so
|
|
180
|
-
* a second emit cannot double-log.
|
|
181
|
-
*
|
|
182
|
-
* `rule` is the rule that blocked, or '-' when there is none; `fault` is the L0 fault code when this
|
|
183
|
-
* call ended on one (S/C/Y — the JS-side faults), else '-'. FIELD ORDER IS APPEND-ONLY: the five
|
|
184
|
-
* original fields keep their positions (cleanup automation mines this file), and `guards=` /
|
|
185
|
-
* `rule=` / … / `fault=` are added at the end.
|
|
186
|
-
*/
|
|
187
|
-
finish(verdict: Verdict, rule: string, fault?: string): void;
|
|
188
|
-
}
|
|
189
|
-
export declare const invocationLog: InvocationLog;
|
|
190
|
-
export declare function branchForLog(root: string): string;
|