@webpieces/ai-hook-rules 0.4.839 → 0.4.841
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -140
- package/package.json +7 -15
- package/src/adapters/hook-app-fixtures.d.ts +1 -1
- package/src/adapters/hook-app-fixtures.js +0 -8
- package/src/adapters/hook-app-fixtures.js.map +1 -1
- package/src/adapters/hook-core.d.ts +1 -21
- package/src/adapters/hook-core.js +22 -341
- package/src/adapters/hook-core.js.map +1 -1
- package/src/core/load-rules.d.ts +4 -39
- package/src/core/load-rules.js +15 -127
- package/src/core/load-rules.js.map +1 -1
- package/src/core/rules/catch-error-pattern.d.ts +3 -3
- package/src/core/rules/catch-error-pattern.js +13 -13
- package/src/core/rules/catch-error-pattern.js.map +1 -1
- package/src/core/rules/index.d.ts +1 -14
- package/src/core/rules/index.js +1 -17
- package/src/core/rules/index.js.map +1 -1
- package/src/core/rules/match-rule.d.ts +3 -3
- package/src/core/rules/match-rule.js +6 -6
- package/src/core/rules/match-rule.js.map +1 -1
- package/src/core/rules/max-file-lines.d.ts +3 -3
- package/src/core/rules/max-file-lines.js +7 -7
- package/src/core/rules/max-file-lines.js.map +1 -1
- package/src/core/rules/no-any-unknown.d.ts +3 -3
- package/src/core/rules/no-any-unknown.js +6 -6
- package/src/core/rules/no-any-unknown.js.map +1 -1
- package/src/core/rules/no-custom-css.d.ts +3 -3
- package/src/core/rules/no-custom-css.js +7 -7
- package/src/core/rules/no-custom-css.js.map +1 -1
- package/src/core/rules/no-destructure.d.ts +3 -3
- package/src/core/rules/no-destructure.js +7 -7
- package/src/core/rules/no-destructure.js.map +1 -1
- package/src/core/rules/no-implicit-any.d.ts +3 -3
- package/src/core/rules/no-implicit-any.js +6 -6
- package/src/core/rules/no-implicit-any.js.map +1 -1
- package/src/core/rules/no-js-files.d.ts +3 -3
- package/src/core/rules/no-js-files.js +6 -6
- package/src/core/rules/no-js-files.js.map +1 -1
- package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
- package/src/core/rules/no-process-exit-outside-main.js +7 -7
- package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
- package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
- package/src/core/rules/no-symbol-di-tokens.js +7 -7
- package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
- package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
- package/src/core/rules/no-unmanaged-exceptions.js +9 -9
- package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
- package/src/core/rules/require-return-type.d.ts +3 -3
- package/src/core/rules/require-return-type.js +6 -6
- package/src/core/rules/require-return-type.js.map +1 -1
- package/src/core/rules/throw-cause-required.d.ts +3 -3
- package/src/core/rules/throw-cause-required.js +9 -9
- package/src/core/rules/throw-cause-required.js.map +1 -1
- package/src/core/rules/validate-ts-in-src.d.ts +3 -3
- package/src/core/rules/validate-ts-in-src.js +7 -7
- package/src/core/rules/validate-ts-in-src.js.map +1 -1
- package/src/core/runner.d.ts +10 -19
- package/src/core/runner.js +24 -622
- package/src/core/runner.js.map +1 -1
- package/src/index.d.ts +2 -15
- package/src/index.js +4 -54
- package/src/index.js.map +1 -1
- package/openclaw.plugin.json +0 -15
- package/src/adapters/agent-adapters.d.ts +0 -13
- package/src/adapters/agent-adapters.js +0 -23
- package/src/adapters/agent-adapters.js.map +0 -1
- package/src/adapters/agent-payload.d.ts +0 -48
- package/src/adapters/agent-payload.js +0 -30
- package/src/adapters/agent-payload.js.map +0 -1
- package/src/adapters/agent-response.d.ts +0 -5
- package/src/adapters/agent-response.js +0 -86
- package/src/adapters/agent-response.js.map +0 -1
- package/src/adapters/claude-code-adapter.d.ts +0 -26
- package/src/adapters/claude-code-adapter.js +0 -69
- package/src/adapters/claude-code-adapter.js.map +0 -1
- package/src/adapters/codex-adapter.d.ts +0 -19
- package/src/adapters/codex-adapter.js +0 -48
- package/src/adapters/codex-adapter.js.map +0 -1
- package/src/adapters/codex-subagent-guard.d.ts +0 -45
- package/src/adapters/codex-subagent-guard.js +0 -88
- package/src/adapters/codex-subagent-guard.js.map +0 -1
- package/src/adapters/detect-ai.d.ts +0 -70
- package/src/adapters/detect-ai.js +0 -82
- package/src/adapters/detect-ai.js.map +0 -1
- package/src/adapters/guards-hook.d.ts +0 -3
- package/src/adapters/guards-hook.js +0 -30
- package/src/adapters/guards-hook.js.map +0 -1
- package/src/adapters/openclaw-plugin.d.ts +0 -14
- package/src/adapters/openclaw-plugin.js +0 -87
- package/src/adapters/openclaw-plugin.js.map +0 -1
- package/src/adapters/review-identity-stamper.d.ts +0 -20
- package/src/adapters/review-identity-stamper.js +0 -34
- package/src/adapters/review-identity-stamper.js.map +0 -1
- package/src/bin/codex-trust.d.ts +0 -105
- package/src/bin/codex-trust.js +0 -205
- package/src/bin/codex-trust.js.map +0 -1
- package/src/bin/dev-hook-install.d.ts +0 -1
- package/src/bin/dev-hook-install.js +0 -82
- package/src/bin/dev-hook-install.js.map +0 -1
- package/src/bin/dev-hook-uninstall.d.ts +0 -1
- package/src/bin/dev-hook-uninstall.js +0 -45
- package/src/bin/dev-hook-uninstall.js.map +0 -1
- package/src/bin/hook-registration.d.ts +0 -429
- package/src/bin/hook-registration.js +0 -661
- package/src/bin/hook-registration.js.map +0 -1
- package/src/bin/install-entry.d.ts +0 -19
- package/src/bin/install-entry.js +0 -128
- package/src/bin/install-entry.js.map +0 -1
- package/src/bin/l0-allowlist.d.ts +0 -49
- package/src/bin/l0-allowlist.js +0 -528
- package/src/bin/l0-allowlist.js.map +0 -1
- package/src/bin/l0-codex-read.d.ts +0 -21
- package/src/bin/l0-codex-read.js +0 -109
- package/src/bin/l0-codex-read.js.map +0 -1
- package/src/bin/l0-decide.d.ts +0 -50
- package/src/bin/l0-decide.js +0 -103
- package/src/bin/l0-decide.js.map +0 -1
- package/src/bin/l0-entry.d.ts +0 -103
- package/src/bin/l0-entry.js +0 -98
- package/src/bin/l0-entry.js.map +0 -1
- package/src/bin/l0-ignored-tools.d.ts +0 -38
- package/src/bin/l0-ignored-tools.js +0 -44
- package/src/bin/l0-ignored-tools.js.map +0 -1
- package/src/bin/managed-env.d.ts +0 -46
- package/src/bin/managed-env.js +0 -50
- package/src/bin/managed-env.js.map +0 -1
- package/src/bin/neighbour-hooks.d.ts +0 -42
- package/src/bin/neighbour-hooks.js +0 -177
- package/src/bin/neighbour-hooks.js.map +0 -1
- package/src/bin/reviewer-agent.d.ts +0 -19
- package/src/bin/reviewer-agent.js +0 -135
- package/src/bin/reviewer-agent.js.map +0 -1
- package/src/bin/settings-shape.d.ts +0 -37
- package/src/bin/settings-shape.js +0 -17
- package/src/bin/settings-shape.js.map +0 -1
- package/src/bin/setup-config.d.ts +0 -19
- package/src/bin/setup-config.js +0 -370
- package/src/bin/setup-config.js.map +0 -1
- package/src/bin/setup.d.ts +0 -78
- package/src/bin/setup.js +0 -400
- package/src/bin/setup.js.map +0 -1
- package/src/bin/shim-audit-log.d.ts +0 -119
- package/src/bin/shim-audit-log.js +0 -286
- package/src/bin/shim-audit-log.js.map +0 -1
- package/src/bin/shim-deny-reason.d.ts +0 -1
- package/src/bin/shim-deny-reason.js +0 -244
- package/src/bin/shim-deny-reason.js.map +0 -1
- package/src/bin/shim-drift-fix.d.ts +0 -1
- package/src/bin/shim-drift-fix.js +0 -72
- package/src/bin/shim-drift-fix.js.map +0 -1
- package/src/bin/shim-testkit.d.ts +0 -107
- package/src/bin/shim-testkit.js +0 -197
- package/src/bin/shim-testkit.js.map +0 -1
- package/src/bin/shim-version-drift.d.ts +0 -1
- package/src/bin/shim-version-drift.js +0 -164
- package/src/bin/shim-version-drift.js.map +0 -1
- package/src/bin/shim.d.ts +0 -16
- package/src/bin/shim.js +0 -636
- package/src/bin/shim.js.map +0 -1
- package/src/bin/upgrade-shim.d.ts +0 -18
- package/src/bin/upgrade-shim.js +0 -283
- package/src/bin/upgrade-shim.js.map +0 -1
- package/src/core/ai-type-context.d.ts +0 -36
- package/src/core/ai-type-context.js +0 -45
- package/src/core/ai-type-context.js.map +0 -1
- package/src/core/apply-patch-parse.d.ts +0 -36
- package/src/core/apply-patch-parse.js +0 -154
- package/src/core/apply-patch-parse.js.map +0 -1
- package/src/core/build-context.d.ts +0 -10
- package/src/core/build-context.js +0 -66
- package/src/core/build-context.js.map +0 -1
- package/src/core/command-scan.d.ts +0 -122
- package/src/core/command-scan.js +0 -282
- package/src/core/command-scan.js.map +0 -1
- package/src/core/custom-rule-adapter.d.ts +0 -22
- package/src/core/custom-rule-adapter.js +0 -50
- package/src/core/custom-rule-adapter.js.map +0 -1
- package/src/core/decision-log.d.ts +0 -190
- package/src/core/decision-log.js +0 -406
- package/src/core/decision-log.js.map +0 -1
- package/src/core/delete-scoped-rules.d.ts +0 -8
- package/src/core/delete-scoped-rules.js +0 -31
- package/src/core/delete-scoped-rules.js.map +0 -1
- package/src/core/disable-directives.d.ts +0 -8
- package/src/core/disable-directives.js +0 -80
- package/src/core/disable-directives.js.map +0 -1
- package/src/core/effective-tree.d.ts +0 -204
- package/src/core/effective-tree.js +0 -277
- package/src/core/effective-tree.js.map +0 -1
- package/src/core/excluded-path-escape.d.ts +0 -101
- package/src/core/excluded-path-escape.js +0 -236
- package/src/core/excluded-path-escape.js.map +0 -1
- package/src/core/excluded-paths.d.ts +0 -23
- package/src/core/excluded-paths.js +0 -54
- package/src/core/excluded-paths.js.map +0 -1
- package/src/core/fix-hint.d.ts +0 -40
- package/src/core/fix-hint.js +0 -53
- package/src/core/fix-hint.js.map +0 -1
- package/src/core/force-to-root.d.ts +0 -32
- package/src/core/force-to-root.js +0 -60
- package/src/core/force-to-root.js.map +0 -1
- package/src/core/guard-index-doc.d.ts +0 -63
- package/src/core/guard-index-doc.js +0 -172
- package/src/core/guard-index-doc.js.map +0 -1
- package/src/core/instruct-ai-writer.d.ts +0 -1
- package/src/core/instruct-ai-writer.js +0 -6
- package/src/core/instruct-ai-writer.js.map +0 -1
- package/src/core/l0-fault-codes.d.ts +0 -85
- package/src/core/l0-fault-codes.js +0 -121
- package/src/core/l0-fault-codes.js.map +0 -1
- package/src/core/l0-matrix.d.ts +0 -114
- package/src/core/l0-matrix.js +0 -416
- package/src/core/l0-matrix.js.map +0 -1
- package/src/core/l0-tooling-doc.d.ts +0 -45
- package/src/core/l0-tooling-doc.js +0 -258
- package/src/core/l0-tooling-doc.js.map +0 -1
- package/src/core/l1-doc.d.ts +0 -7
- package/src/core/l1-doc.js +0 -340
- package/src/core/l1-doc.js.map +0 -1
- package/src/core/l1-matrix-doc.d.ts +0 -31
- package/src/core/l1-matrix-doc.js +0 -111
- package/src/core/l1-matrix-doc.js.map +0 -1
- package/src/core/l1-rows.d.ts +0 -167
- package/src/core/l1-rows.js +0 -262
- package/src/core/l1-rows.js.map +0 -1
- package/src/core/l2-doc.d.ts +0 -7
- package/src/core/l2-doc.js +0 -385
- package/src/core/l2-doc.js.map +0 -1
- package/src/core/l2-matrix-doc.d.ts +0 -23
- package/src/core/l2-matrix-doc.js +0 -72
- package/src/core/l2-matrix-doc.js.map +0 -1
- package/src/core/l2-row.d.ts +0 -54
- package/src/core/l2-row.js +0 -75
- package/src/core/l2-row.js.map +0 -1
- package/src/core/l2-rows.d.ts +0 -56
- package/src/core/l2-rows.js +0 -272
- package/src/core/l2-rows.js.map +0 -1
- package/src/core/load-config.d.ts +0 -1
- package/src/core/load-config.js +0 -9
- package/src/core/load-config.js.map +0 -1
- package/src/core/log-stream.d.ts +0 -117
- package/src/core/log-stream.js +0 -156
- package/src/core/log-stream.js.map +0 -1
- package/src/core/log-streams.d.ts +0 -48
- package/src/core/log-streams.js +0 -55
- package/src/core/log-streams.js.map +0 -1
- package/src/core/log-target.d.ts +0 -21
- package/src/core/log-target.js +0 -29
- package/src/core/log-target.js.map +0 -1
- package/src/core/main-sync-log.d.ts +0 -16
- package/src/core/main-sync-log.js +0 -105
- package/src/core/main-sync-log.js.map +0 -1
- package/src/core/main-sync-refresh.d.ts +0 -39
- package/src/core/main-sync-refresh.js +0 -96
- package/src/core/main-sync-refresh.js.map +0 -1
- package/src/core/main-sync-timeout.d.ts +0 -32
- package/src/core/main-sync-timeout.js +0 -94
- package/src/core/main-sync-timeout.js.map +0 -1
- package/src/core/matrix-cures.d.ts +0 -12
- package/src/core/matrix-cures.js +0 -56
- package/src/core/matrix-cures.js.map +0 -1
- package/src/core/missing-directory.d.ts +0 -38
- package/src/core/missing-directory.js +0 -66
- package/src/core/missing-directory.js.map +0 -1
- package/src/core/read-only-inspection.d.ts +0 -34
- package/src/core/read-only-inspection.js +0 -88
- package/src/core/read-only-inspection.js.map +0 -1
- package/src/core/rejection-log.d.ts +0 -9
- package/src/core/rejection-log.js +0 -258
- package/src/core/rejection-log.js.map +0 -1
- package/src/core/report.d.ts +0 -21
- package/src/core/report.js +0 -73
- package/src/core/report.js.map +0 -1
- package/src/core/rule-base.d.ts +0 -39
- package/src/core/rule-base.js +0 -36
- package/src/core/rule-base.js.map +0 -1
- package/src/core/rules/branch-creation-guard.d.ts +0 -113
- package/src/core/rules/branch-creation-guard.js +0 -422
- package/src/core/rules/branch-creation-guard.js.map +0 -1
- package/src/core/rules/branch-switch-scan.d.ts +0 -43
- package/src/core/rules/branch-switch-scan.js +0 -132
- package/src/core/rules/branch-switch-scan.js.map +0 -1
- package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
- package/src/core/rules/build-output-pipe-guard.js +0 -120
- package/src/core/rules/build-output-pipe-guard.js.map +0 -1
- package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
- package/src/core/rules/build-output-pipe-scan.js +0 -84
- package/src/core/rules/build-output-pipe-scan.js.map +0 -1
- package/src/core/rules/cap-remedies.d.ts +0 -39
- package/src/core/rules/cap-remedies.js +0 -59
- package/src/core/rules/cap-remedies.js.map +0 -1
- package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
- package/src/core/rules/commit-message-substitution-guard.js +0 -134
- package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
- package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
- package/src/core/rules/commit-message-substitution-scan.js +0 -145
- package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
- package/src/core/rules/content-read-scan.d.ts +0 -76
- package/src/core/rules/content-read-scan.js +0 -176
- package/src/core/rules/content-read-scan.js.map +0 -1
- package/src/core/rules/cure-prefix-scan.d.ts +0 -64
- package/src/core/rules/cure-prefix-scan.js +0 -133
- package/src/core/rules/cure-prefix-scan.js.map +0 -1
- package/src/core/rules/feature-branch-guard.d.ts +0 -121
- package/src/core/rules/feature-branch-guard.js +0 -326
- package/src/core/rules/feature-branch-guard.js.map +0 -1
- package/src/core/rules/judged-tree.d.ts +0 -66
- package/src/core/rules/judged-tree.js +0 -97
- package/src/core/rules/judged-tree.js.map +0 -1
- package/src/core/rules/main-freshness.d.ts +0 -37
- package/src/core/rules/main-freshness.js +0 -61
- package/src/core/rules/main-freshness.js.map +0 -1
- package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
- package/src/core/rules/merge-in-progress-guard.js +0 -122
- package/src/core/rules/merge-in-progress-guard.js.map +0 -1
- package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
- package/src/core/rules/merged-branch-bash-guard.js +0 -170
- package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
- package/src/core/rules/merged-branch-message.d.ts +0 -59
- package/src/core/rules/merged-branch-message.js +0 -137
- package/src/core/rules/merged-branch-message.js.map +0 -1
- package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
- package/src/core/rules/pr-creation-or-push-guard.js +0 -146
- package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
- package/src/core/rules/pr-merge-guard.d.ts +0 -36
- package/src/core/rules/pr-merge-guard.js +0 -86
- package/src/core/rules/pr-merge-guard.js.map +0 -1
- package/src/core/rules/read-stale-guard.d.ts +0 -136
- package/src/core/rules/read-stale-guard.js +0 -326
- package/src/core/rules/read-stale-guard.js.map +0 -1
- package/src/core/rules/recovery-allowlist.d.ts +0 -49
- package/src/core/rules/recovery-allowlist.js +0 -187
- package/src/core/rules/recovery-allowlist.js.map +0 -1
- package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
- package/src/core/rules/redirect-how-to-merge-main.js +0 -157
- package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
- package/src/core/rules/shell-segment-scan.d.ts +0 -64
- package/src/core/rules/shell-segment-scan.js +0 -88
- package/src/core/rules/shell-segment-scan.js.map +0 -1
- package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
- package/src/core/rules/stale-main-bash-guard.js +0 -361
- package/src/core/rules/stale-main-bash-guard.js.map +0 -1
- package/src/core/rules/stale-main-message.d.ts +0 -62
- package/src/core/rules/stale-main-message.js +0 -102
- package/src/core/rules/stale-main-message.js.map +0 -1
- package/src/core/rules/tree-recovery.d.ts +0 -92
- package/src/core/rules/tree-recovery.js +0 -165
- package/src/core/rules/tree-recovery.js.map +0 -1
- package/src/core/rules/wait-spin-guard.d.ts +0 -128
- package/src/core/rules/wait-spin-guard.js +0 -211
- package/src/core/rules/wait-spin-guard.js.map +0 -1
- package/src/core/rules/wait-spin-scan.d.ts +0 -118
- package/src/core/rules/wait-spin-scan.js +0 -203
- package/src/core/rules/wait-spin-scan.js.map +0 -1
- package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
- package/src/core/rules/whole-repo-build-guard.js +0 -257
- package/src/core/rules/whole-repo-build-guard.js.map +0 -1
- package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
- package/src/core/rules/whole-repo-build-scan.js +0 -198
- package/src/core/rules/whole-repo-build-scan.js.map +0 -1
- package/src/core/session-call-history.d.ts +0 -44
- package/src/core/session-call-history.js +0 -79
- package/src/core/session-call-history.js.map +0 -1
- package/src/core/shell-read-parity.d.ts +0 -56
- package/src/core/shell-read-parity.js +0 -155
- package/src/core/shell-read-parity.js.map +0 -1
- package/src/core/strip-ts-noise.d.ts +0 -1
- package/src/core/strip-ts-noise.js +0 -185
- package/src/core/strip-ts-noise.js.map +0 -1
- package/src/core/sync-main.d.ts +0 -46
- package/src/core/sync-main.js +0 -175
- package/src/core/sync-main.js.map +0 -1
- package/src/core/target-tree.d.ts +0 -84
- package/src/core/target-tree.js +0 -148
- package/src/core/target-tree.js.map +0 -1
- package/src/core/to-error.d.ts +0 -5
- package/src/core/to-error.js +0 -37
- package/src/core/to-error.js.map +0 -1
- package/src/core/types.d.ts +0 -152
- package/src/core/types.js +0 -200
- package/src/core/types.js.map +0 -1
- package/src/core/version-sync.d.ts +0 -219
- package/src/core/version-sync.js +0 -558
- package/src/core/version-sync.js.map +0 -1
- package/src/core/webpieces-versions.d.ts +0 -98
- package/src/core/webpieces-versions.js +0 -206
- package/src/core/webpieces-versions.js.map +0 -1
- package/templates/ai-hook.sh +0 -497
- package/templates/claude-settings-hook.json +0 -28
- package/templates/webpieces-reviewer.md +0 -60
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReadOnlyInspectionScan = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const command_scan_1 = require("./command-scan");
|
|
7
|
-
const shell_segment_scan_1 = require("./rules/shell-segment-scan");
|
|
8
|
-
/**
|
|
9
|
-
* Is this shell command pure INSPECTION — can it be trusted to change nothing?
|
|
10
|
-
*
|
|
11
|
-
* WHY this exists: when webpieces.config.json cannot be loaded (unparseable, or invalid against the
|
|
12
|
-
* installed validator) every bash command is denied, because with no config there are no guards and
|
|
13
|
-
* fail-closed is the only safe answer. That is right for work — and catastrophic for recovery, because
|
|
14
|
-
* the denial also took out `cat`, `grep` and `sed -n` against webpieces.config.json itself. The guard
|
|
15
|
-
* blocked the exact tools needed to see and fix the problem it was reporting, which is a dead end an
|
|
16
|
-
* agent cannot escape from inside the session. (Reproduced live: mid-merge, the config legitimately
|
|
17
|
-
* held `<<<<<<< HEAD` markers and every attempt to look at it was refused.)
|
|
18
|
-
*
|
|
19
|
-
* The rest of the system already models the escape hatch correctly — reading AND editing
|
|
20
|
-
* webpieces.config.json is always allowed (hook-core's config bypass, the stale-shim recovery
|
|
21
|
-
* carve-out, ContentReadScan's escape-hatch paths). This closes the one place that did not honour it.
|
|
22
|
-
*
|
|
23
|
-
* The bar is deliberately paranoid, because this is a bypass of ALL guards:
|
|
24
|
-
* - every invoked segment's command word must be an allowlisted inspector;
|
|
25
|
-
* - `git`/`gh` are excluded outright, even their read-only subcommands — the guards exist to police
|
|
26
|
-
* git, and "read-only git" is not a line worth drawing while flying blind;
|
|
27
|
-
* - any output redirect to a file (`> x`, `>> x`) makes the command a writer;
|
|
28
|
-
* - the in-place/mutating flags of otherwise-read-only tools (`sed -i`, `find -delete`) are refused.
|
|
29
|
-
* Anything not provably inert stays blocked.
|
|
30
|
-
*/
|
|
31
|
-
class ReadOnlyInspectionScan {
|
|
32
|
-
scanner;
|
|
33
|
-
shell;
|
|
34
|
-
constructor(scanner = new command_scan_1.CommandScanner()) {
|
|
35
|
-
this.scanner = scanner;
|
|
36
|
-
this.shell = new shell_segment_scan_1.ShellSegmentScan(this.scanner);
|
|
37
|
-
}
|
|
38
|
-
/** True only when EVERY segment of the command is provably inert. Empty command → false. */
|
|
39
|
-
isReadOnlyInspection(command) {
|
|
40
|
-
const segments = this.scanner.segmentsWithJoins(command);
|
|
41
|
-
if (segments.length === 0)
|
|
42
|
-
return false;
|
|
43
|
-
return segments.every((segment) => this.segmentIsInert(segment));
|
|
44
|
-
}
|
|
45
|
-
segmentIsInert(segment) {
|
|
46
|
-
const words = this.shell.effectiveWords(segment.text);
|
|
47
|
-
if (words.length === 0)
|
|
48
|
-
return true; // pure shell structure (`done`, `fi`)
|
|
49
|
-
if (this.redirectsToFile(words))
|
|
50
|
-
return false; // `… > file` writes, whatever the command is
|
|
51
|
-
const head = path.basename(words[0]);
|
|
52
|
-
if (!INSPECTORS.has(head))
|
|
53
|
-
return false;
|
|
54
|
-
return !this.hasMutatingFlag(head, words.slice(1));
|
|
55
|
-
}
|
|
56
|
-
// `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which only rewire fds and are the single
|
|
57
|
-
// most common decoration an agent appends to a diagnostic command.
|
|
58
|
-
redirectsToFile(words) {
|
|
59
|
-
return words.some((word) => REDIRECT_TO_FILE.test(word));
|
|
60
|
-
}
|
|
61
|
-
// Read-only tools that grow teeth with one flag: `sed -i` rewrites in place, `find -delete`/`-exec`
|
|
62
|
-
// runs arbitrary commands. Matching is prefix-based so `-i.bak` and `-inplace` are caught too.
|
|
63
|
-
hasMutatingFlag(head, args) {
|
|
64
|
-
const mutating = MUTATING_FLAGS[head];
|
|
65
|
-
if (!mutating)
|
|
66
|
-
return false;
|
|
67
|
-
return args.some((arg) => mutating.some((flag) => arg.startsWith(flag)));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ReadOnlyInspectionScan = ReadOnlyInspectionScan;
|
|
71
|
-
// Commands whose entire job is showing what is already there. Kept to viewers/searchers/formatters:
|
|
72
|
-
// no package managers, no build or test runners, no interpreters, no git.
|
|
73
|
-
const INSPECTORS = new Set([
|
|
74
|
-
'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'tac', 'rev', 'strings', 'xxd', 'od',
|
|
75
|
-
'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',
|
|
76
|
-
'ls', 'find', 'tree', 'wc', 'diff', 'cmp', 'file', 'stat', 'realpath', 'readlink',
|
|
77
|
-
'basename', 'dirname', 'sort', 'uniq', 'cut', 'tr', 'column', 'fold', 'expand',
|
|
78
|
-
'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'which', 'test', '[',
|
|
79
|
-
]);
|
|
80
|
-
// Per-command flags that turn an inspector into a mutator.
|
|
81
|
-
const MUTATING_FLAGS = {
|
|
82
|
-
sed: ['-i', '--in-place'],
|
|
83
|
-
find: ['-delete', '-exec', '-execdir', '-ok', '-okdir', '-fprint', '-fls'],
|
|
84
|
-
awk: ['-i'],
|
|
85
|
-
sort: ['-o', '--output'],
|
|
86
|
-
};
|
|
87
|
-
const REDIRECT_TO_FILE = /^\d*>>?(?!&)/;
|
|
88
|
-
//# sourceMappingURL=read-only-inspection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read-only-inspection.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/read-only-inspection.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,iDAAgE;AAChE,mEAA8D;AAE9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,sBAAsB;IAGF;IAFZ,KAAK,CAAmB;IAEzC,YAA6B,UAA0B,IAAI,6BAAc,EAAE;QAA9C,YAAO,GAAP,OAAO,CAAuC;QACvE,IAAI,CAAC,KAAK,GAAG,IAAI,qCAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,4FAA4F;IAC5F,oBAAoB,CAAC,OAAe;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAuB,EAAW,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,CAAC;IAEO,cAAc,CAAC,OAAuB;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,CAAY,sCAAsC;QACtF,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,CAAE,6CAA6C;QAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CA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EAAE,UAAU,EAAE,UAAU;IACjF,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ;IAC9E,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG;CAC5E,CAAC,CAAC;AAEH,2DAA2D;AAC3D,MAAM,cAAc,GAAgD;IAChE,GAAG,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC;IACzB,IAAI,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC1E,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEF,MAAM,gBAAgB,GAAG,cAAc,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { CommandScanner, CommandSegment } from './command-scan';\nimport { ShellSegmentScan } from './rules/shell-segment-scan';\n\n/**\n * Is this shell command pure INSPECTION — can it be trusted to change nothing?\n *\n * WHY this exists: when webpieces.config.json cannot be loaded (unparseable, or invalid against the\n * installed validator) every bash command is denied, because with no config there are no guards and\n * fail-closed is the only safe answer. That is right for work — and catastrophic for recovery, because\n * the denial also took out `cat`, `grep` and `sed -n` against webpieces.config.json itself. The guard\n * blocked the exact tools needed to see and fix the problem it was reporting, which is a dead end an\n * agent cannot escape from inside the session. (Reproduced live: mid-merge, the config legitimately\n * held `<<<<<<< HEAD` markers and every attempt to look at it was refused.)\n *\n * The rest of the system already models the escape hatch correctly — reading AND editing\n * webpieces.config.json is always allowed (hook-core's config bypass, the stale-shim recovery\n * carve-out, ContentReadScan's escape-hatch paths). This closes the one place that did not honour it.\n *\n * The bar is deliberately paranoid, because this is a bypass of ALL guards:\n * - every invoked segment's command word must be an allowlisted inspector;\n * - `git`/`gh` are excluded outright, even their read-only subcommands — the guards exist to police\n * git, and \"read-only git\" is not a line worth drawing while flying blind;\n * - any output redirect to a file (`> x`, `>> x`) makes the command a writer;\n * - the in-place/mutating flags of otherwise-read-only tools (`sed -i`, `find -delete`) are refused.\n * Anything not provably inert stays blocked.\n */\nexport class ReadOnlyInspectionScan {\n private readonly shell: ShellSegmentScan;\n\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {\n this.shell = new ShellSegmentScan(this.scanner);\n }\n\n /** True only when EVERY segment of the command is provably inert. Empty command → false. */\n isReadOnlyInspection(command: string): boolean {\n const segments = this.scanner.segmentsWithJoins(command);\n if (segments.length === 0) return false;\n return segments.every((segment: CommandSegment): boolean => this.segmentIsInert(segment));\n }\n\n private segmentIsInert(segment: CommandSegment): boolean {\n const words = this.shell.effectiveWords(segment.text);\n if (words.length === 0) return true; // pure shell structure (`done`, `fi`)\n if (this.redirectsToFile(words)) return false; // `… > file` writes, whatever the command is\n const head = path.basename(words[0]);\n if (!INSPECTORS.has(head)) return false;\n return !this.hasMutatingFlag(head, words.slice(1));\n }\n\n // `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which only rewire fds and are the single\n // most common decoration an agent appends to a diagnostic command.\n private redirectsToFile(words: readonly string[]): boolean {\n return words.some((word: string): boolean => REDIRECT_TO_FILE.test(word));\n }\n\n // Read-only tools that grow teeth with one flag: `sed -i` rewrites in place, `find -delete`/`-exec`\n // runs arbitrary commands. Matching is prefix-based so `-i.bak` and `-inplace` are caught too.\n private hasMutatingFlag(head: string, args: readonly string[]): boolean {\n const mutating = MUTATING_FLAGS[head];\n if (!mutating) return false;\n return args.some((arg: string): boolean => mutating.some((flag: string): boolean => arg.startsWith(flag)));\n }\n}\n\n// Commands whose entire job is showing what is already there. Kept to viewers/searchers/formatters:\n// no package managers, no build or test runners, no interpreters, no git.\nconst INSPECTORS: ReadonlySet<string> = new Set([\n 'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'tac', 'rev', 'strings', 'xxd', 'od',\n 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',\n 'ls', 'find', 'tree', 'wc', 'diff', 'cmp', 'file', 'stat', 'realpath', 'readlink',\n 'basename', 'dirname', 'sort', 'uniq', 'cut', 'tr', 'column', 'fold', 'expand',\n 'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'which', 'test', '[',\n]);\n\n// Per-command flags that turn an inspector into a mutator.\nconst MUTATING_FLAGS: Readonly<Record<string, readonly string[]>> = {\n sed: ['-i', '--in-place'],\n find: ['-delete', '-exec', '-execdir', '-ok', '-okdir', '-fprint', '-fls'],\n awk: ['-i'],\n sort: ['-o', '--output'],\n};\n\nconst REDIRECT_TO_FILE = /^\\d*>>?(?!&)/;\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ToolKind, NormalizedToolInput, BlockedResult } from './types';
|
|
2
|
-
export declare function logRejection(toolKind: ToolKind, input: NormalizedToolInput, result: BlockedResult, cwd: string): void;
|
|
3
|
-
/**
|
|
4
|
-
* The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because
|
|
5
|
-
* two audit streams need the same answer from the same regex: this file's rejection index, and the
|
|
6
|
-
* `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be
|
|
7
|
-
* two answers to one question.
|
|
8
|
-
*/
|
|
9
|
-
export declare function extractRuleNames(report: string): string[];
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logRejection = logRejection;
|
|
4
|
-
exports.extractRuleNames = extractRuleNames;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
|
-
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
10
|
-
const log_streams_1 = require("./log-streams");
|
|
11
|
-
const log_stream_1 = require("./log-stream");
|
|
12
|
-
const ai_type_context_1 = require("./ai-type-context");
|
|
13
|
-
const to_error_1 = require("./to-error");
|
|
14
|
-
/**
|
|
15
|
-
* The rejection index and its detail files, BOTH inside the `rejections/` stream directory, both
|
|
16
|
-
* named by the same writer key:
|
|
17
|
-
*
|
|
18
|
-
* logs/rejections/<sid>-<agent>-<hook>.log ← the index (one line per block)
|
|
19
|
-
* logs/rejections/<sid>-<agent>-<hook>/ ← its detail dir, SAME key
|
|
20
|
-
* writeInfo-<epochMs>.md
|
|
21
|
-
*
|
|
22
|
-
* The detail files used to be `hooks/<YYYY-MM-DD>/writeInfo-<epochMs>.md` — a directory keyed only by
|
|
23
|
-
* the DATE, shared by every writer in the tree, written with a raw `writeFileSync`. Two agents blocked
|
|
24
|
-
* in the same millisecond produced the same path and one silently overwrote the other's evidence. The
|
|
25
|
-
* comment that licensed it claimed a per-worktree log has exactly one writer; LogStream's class
|
|
26
|
-
* comment is the measurement that disproves it (parallel PreToolUse hooks, non-isolated subagents and
|
|
27
|
-
* multiple Claude Code windows all share a tree). Naming the directory after the LOG THAT POINTS AT IT
|
|
28
|
-
* gives it the same one-owner-by-construction property the log itself has, and makes the pointer
|
|
29
|
-
* readable: the index line, the directory and the file are one name.
|
|
30
|
-
*
|
|
31
|
-
* RETENTION is therefore filename-based, not directory-date-based: there is no date level left, so
|
|
32
|
-
* `DetailPruner` parses `<epochMs>` out of each `writeInfo-*.md` (no `stat` call) and removes any
|
|
33
|
-
* stream directory left empty. Every delete is `force: true` and failures are swallowed, so concurrent
|
|
34
|
-
* agents racing the same week-old files is harmless.
|
|
35
|
-
*/
|
|
36
|
-
const DETAIL_PREFIX = 'writeInfo-';
|
|
37
|
-
const DETAIL_SUFFIX = '.md';
|
|
38
|
-
const DETAIL_RE = /^writeInfo-(\d+)\.md$/;
|
|
39
|
-
const MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded
|
|
40
|
-
const MAX_AGE_DAYS = 7;
|
|
41
|
-
const RULE_NAME_RE = /^\[([^\]]+)\] \(/gm;
|
|
42
|
-
function logRejection(toolKind, input, result, cwd) {
|
|
43
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
44
|
-
try {
|
|
45
|
-
// `.webpieces/` lives at the repo root, NOT the AI's cwd — resolve it so a hook fired while
|
|
46
|
-
// the AI is in a subdirectory never scatters a stray `<subdir>/.webpieces` tree.
|
|
47
|
-
const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
|
|
48
|
-
const now = new Date();
|
|
49
|
-
const timestamp = now.toISOString();
|
|
50
|
-
const epochMs = String(now.getTime());
|
|
51
|
-
// LOCAL scope — a rejection is this worktree's event. WHICH writer's event is answered by the
|
|
52
|
-
// stream prefix, on the index AND on its detail directory, so neither can collide.
|
|
53
|
-
const logsDir = tooling_common_1.dotWebpieces.logsFile(root, log_streams_1.REJECTIONS_STREAM);
|
|
54
|
-
// The detail directory is the writer key with NO extension, sitting beside the `.log` that
|
|
55
|
-
// indexes it — so index and details share one owner, one level down inside the stream dir.
|
|
56
|
-
const detailDirName = log_stream_1.logStream.writerFile('');
|
|
57
|
-
const detailDir = path.join(logsDir, detailDirName);
|
|
58
|
-
fs.mkdirSync(detailDir, { recursive: true });
|
|
59
|
-
const relativePath = computeRelativePath(input.filePath, root);
|
|
60
|
-
const ruleNames = extractRuleNames(result.report);
|
|
61
|
-
const detailFileName = `${DETAIL_PREFIX}${epochMs}${DETAIL_SUFFIX}`;
|
|
62
|
-
// Relative to `rejections/` — the index's own directory — so the pointer resolves from where
|
|
63
|
-
// the reader found the line, and reads as the log's own name plus a file.
|
|
64
|
-
const detailRelPath = `${detailDirName}/${detailFileName}`;
|
|
65
|
-
const detail = buildDetailContent(timestamp, toolKind, relativePath, ruleNames, result.report, input);
|
|
66
|
-
fs.writeFileSync(path.join(detailDir, detailFileName), detail);
|
|
67
|
-
const logPath = path.join(logsDir, log_stream_1.logStream.writerFile('.log'));
|
|
68
|
-
rotateLogFile(logPath, path.join(logsDir, log_stream_1.logStream.writerFile('.1.log')));
|
|
69
|
-
// APPEND-ONLY, and `fault=` is spelled exactly as the L0 sh log spells it. A fault-S storm
|
|
70
|
-
// previously landed here as a couple of lines attributed to whatever rule the report happened
|
|
71
|
-
// to cite, with nothing anywhere identifying L0 as the cause. (WHO made the call is answered by
|
|
72
|
-
// the filename, which logStream prefixes with session/agent/hook — not by a column here.)
|
|
73
|
-
// `ai=` joins the same append-only tail as `fault=`, in the same vocabulary the L0 sh shim and
|
|
74
|
-
// both decision streams use — so `grep ai=codex` spans all five streams. A row from a release
|
|
75
|
-
// that predates the field carries no `ai=` and reads as `unknown`.
|
|
76
|
-
const logLine = `[${timestamp}]\t${toolKind}\t${relativePath}\t[${ruleNames.join(',')}]\t${detailRelPath}\tfault=${result.fault}\tai=${ai_type_context_1.aiTypeContext.forLog()}\n`;
|
|
77
|
-
fs.appendFileSync(logPath, logLine);
|
|
78
|
-
detailPruner.prune(logsDir, MAX_AGE_DAYS);
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
//const error = toError(err);
|
|
82
|
-
void err;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function computeRelativePath(filePath, cwd) {
|
|
86
|
-
if (filePath.startsWith(cwd)) {
|
|
87
|
-
const rel = filePath.slice(cwd.length);
|
|
88
|
-
if (rel.startsWith('/'))
|
|
89
|
-
return rel.slice(1);
|
|
90
|
-
return rel;
|
|
91
|
-
}
|
|
92
|
-
return filePath;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because
|
|
96
|
-
* two audit streams need the same answer from the same regex: this file's rejection index, and the
|
|
97
|
-
* `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be
|
|
98
|
-
* two answers to one question.
|
|
99
|
-
*/
|
|
100
|
-
// webpieces-disable no-function-outside-class -- pure regex scraper beside this module's other module-scope helpers; exported so the invocation log and the rejection index scrape rule names with the SAME code.
|
|
101
|
-
function extractRuleNames(report) {
|
|
102
|
-
const names = [];
|
|
103
|
-
let match = RULE_NAME_RE.exec(report);
|
|
104
|
-
while (match !== null) {
|
|
105
|
-
names.push(match[1]);
|
|
106
|
-
match = RULE_NAME_RE.exec(report);
|
|
107
|
-
}
|
|
108
|
-
RULE_NAME_RE.lastIndex = 0;
|
|
109
|
-
return names;
|
|
110
|
-
}
|
|
111
|
-
function buildDetailContent(timestamp, toolKind, relativePath, ruleNames, report, input) {
|
|
112
|
-
const lines = [];
|
|
113
|
-
lines.push('# Hook Rejection Detail');
|
|
114
|
-
lines.push('');
|
|
115
|
-
lines.push(`- **Timestamp:** ${timestamp}`);
|
|
116
|
-
lines.push(`- **Tool:** ${toolKind}`);
|
|
117
|
-
lines.push(`- **File:** ${relativePath}`);
|
|
118
|
-
lines.push(`- **Rules violated:** ${ruleNames.join(', ')}`);
|
|
119
|
-
lines.push('');
|
|
120
|
-
lines.push('## Report');
|
|
121
|
-
lines.push('');
|
|
122
|
-
lines.push('```');
|
|
123
|
-
lines.push(report.trimEnd());
|
|
124
|
-
lines.push('```');
|
|
125
|
-
lines.push('');
|
|
126
|
-
lines.push('## Content Being Written');
|
|
127
|
-
lines.push('');
|
|
128
|
-
if (toolKind === 'Write') {
|
|
129
|
-
const content = input.edits.length > 0 ? input.edits[0].newString : '';
|
|
130
|
-
lines.push('```typescript');
|
|
131
|
-
lines.push(content.trimEnd());
|
|
132
|
-
lines.push('```');
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
for (let i = 0; i < input.edits.length; i += 1) {
|
|
136
|
-
const edit = input.edits[i];
|
|
137
|
-
lines.push(`### Edit ${String(i + 1)} of ${String(input.edits.length)}`);
|
|
138
|
-
lines.push('');
|
|
139
|
-
lines.push('**old_string:**');
|
|
140
|
-
lines.push('```typescript');
|
|
141
|
-
lines.push(edit.oldString.trimEnd());
|
|
142
|
-
lines.push('```');
|
|
143
|
-
lines.push('');
|
|
144
|
-
lines.push('**new_string:**');
|
|
145
|
-
lines.push('```typescript');
|
|
146
|
-
lines.push(edit.newString.trimEnd());
|
|
147
|
-
lines.push('```');
|
|
148
|
-
lines.push('');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return lines.join('\n') + '\n';
|
|
152
|
-
}
|
|
153
|
-
function rotateLogFile(logPath, prevPath) {
|
|
154
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
155
|
-
try {
|
|
156
|
-
const stat = fs.statSync(logPath);
|
|
157
|
-
if (stat.size > MAX_LOG_BYTES) {
|
|
158
|
-
if (fs.existsSync(prevPath))
|
|
159
|
-
fs.unlinkSync(prevPath);
|
|
160
|
-
fs.renameSync(logPath, prevPath);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
//const error = toError(err);
|
|
165
|
-
void err;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* The 7-day sweep over rejection DETAIL files.
|
|
170
|
-
*
|
|
171
|
-
* A class rather than four module-scope helpers because the four belong together: `prune` is the
|
|
172
|
-
* policy and the other three are the swallow-everything filesystem calls it is built from, none of
|
|
173
|
-
* which means anything on its own.
|
|
174
|
-
*
|
|
175
|
-
* The age comes out of the FILENAME, not out of `stat` — the epoch millis are already in the name, so
|
|
176
|
-
* a sweep costs one `readdir` per stream directory and no syscall per file. (The old scheme could
|
|
177
|
-
* delete a whole `hooks/<YYYY-MM-DD>/` in one recursive `rm` because the date WAS the directory; the
|
|
178
|
-
* directory is now the WRITER, which never expires, so expiry moved down one level.)
|
|
179
|
-
*
|
|
180
|
-
* IDEMPOTENT AND RACE-TOLERANT ON PURPOSE. Several agents sweep the same directory concurrently, so
|
|
181
|
-
* two processes will regularly try to unlink the same week-old file and to rmdir the same emptied
|
|
182
|
-
* directory. `force: true` makes an already-gone target a no-op, an rmdir of a still-populated (or
|
|
183
|
-
* already-removed) directory fails harmlessly, and every error is swallowed: the loser of the race
|
|
184
|
-
* does nothing and reports nothing, which is the correct outcome — the file is gone either way.
|
|
185
|
-
*/
|
|
186
|
-
class DetailPruner {
|
|
187
|
-
prune(logsDir, maxAgeDays) {
|
|
188
|
-
const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;
|
|
189
|
-
for (const dirName of this.readdirOrEmpty(logsDir)) {
|
|
190
|
-
const dir = path.join(logsDir, dirName);
|
|
191
|
-
if (!this.isDirectory(dir))
|
|
192
|
-
continue;
|
|
193
|
-
const names = this.readdirOrEmpty(dir);
|
|
194
|
-
let removed = 0;
|
|
195
|
-
for (const name of names) {
|
|
196
|
-
const match = DETAIL_RE.exec(name);
|
|
197
|
-
if (match === null)
|
|
198
|
-
continue;
|
|
199
|
-
if (Number(match[1]) >= cutoff)
|
|
200
|
-
continue;
|
|
201
|
-
this.removeFile(path.join(dir, name));
|
|
202
|
-
removed += 1;
|
|
203
|
-
}
|
|
204
|
-
// Only a directory we just emptied is a candidate, and the removal is a NON-recursive rmdir
|
|
205
|
-
// on purpose: it fails harmlessly if a concurrent writer dropped a fresh detail in between,
|
|
206
|
-
// so the sweep can never take a file it did not decide was expired.
|
|
207
|
-
if (removed > 0 && removed === names.length)
|
|
208
|
-
this.removeEmptyDir(dir);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
readdirOrEmpty(dir) {
|
|
212
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
213
|
-
try {
|
|
214
|
-
return fs.readdirSync(dir);
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
const error = (0, to_error_1.toError)(err);
|
|
218
|
-
void error;
|
|
219
|
-
return [];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
isDirectory(target) {
|
|
223
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
224
|
-
try {
|
|
225
|
-
return fs.statSync(target).isDirectory();
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
const error = (0, to_error_1.toError)(err);
|
|
229
|
-
void error;
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// `force: true` is what makes the concurrent sweep harmless: a file another agent already deleted
|
|
234
|
-
// is a no-op rather than an ENOENT.
|
|
235
|
-
removeFile(target) {
|
|
236
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
237
|
-
try {
|
|
238
|
-
fs.rmSync(target, { force: true });
|
|
239
|
-
}
|
|
240
|
-
catch (err) {
|
|
241
|
-
const error = (0, to_error_1.toError)(err);
|
|
242
|
-
void error;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
// NON-recursive by design — see prune(). This must refuse a directory that is not empty.
|
|
246
|
-
removeEmptyDir(target) {
|
|
247
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
248
|
-
try {
|
|
249
|
-
fs.rmdirSync(target);
|
|
250
|
-
}
|
|
251
|
-
catch (err) {
|
|
252
|
-
const error = (0, to_error_1.toError)(err);
|
|
253
|
-
void error;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const detailPruner = new DetailPruner();
|
|
258
|
-
//# sourceMappingURL=rejection-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rejection-log.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/rejection-log.ts"],"names":[],"mappings":";;AA0CA,oCAoDC;AAkBD,4CASC;;AAzHD,+CAAyB;AACzB,mDAA6B;AAE7B,8DAAyD;AACzD,0DAAyD;AACzD,+CAAkD;AAGlD,6CAAyC;AACzC,uDAAkD;AAClD,yCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,aAAa,GAAG,YAAY,CAAC;AACnC,MAAM,aAAa,GAAG,KAAK,CAAC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AE,CAAC;QAC7C,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,kGAAkG;IAClG,oCAAoC;IAC5B,UAAU,CAAC,MAAc;QAC7B,8DAA8D;QAC9D,IAAI,CAAC;YACD,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;QACf,CAAC;IACL,CAAC;IAED,yFAAyF;IACjF,cAAc,CAAC,MAAc;QACjC,8DAA8D;QAC9D,IAAI,CAAC;YACD,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;QACf,CAAC;IACL,CAAC;CACJ;AAED,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\nimport { RepoRootFinder } from '@webpieces/rules-config';\nimport { REJECTIONS_STREAM } from './log-streams';\n\nimport type { ToolKind, NormalizedToolInput, BlockedResult } from './types';\nimport { logStream } from './log-stream';\nimport { aiTypeContext } from './ai-type-context';\nimport { toError } from './to-error';\n\n/**\n * The rejection index and its detail files, BOTH inside the `rejections/` stream directory, both\n * named by the same writer key:\n *\n * logs/rejections/<sid>-<agent>-<hook>.log ← the index (one line per block)\n * logs/rejections/<sid>-<agent>-<hook>/ ← its detail dir, SAME key\n * writeInfo-<epochMs>.md\n *\n * The detail files used to be `hooks/<YYYY-MM-DD>/writeInfo-<epochMs>.md` — a directory keyed only by\n * the DATE, shared by every writer in the tree, written with a raw `writeFileSync`. Two agents blocked\n * in the same millisecond produced the same path and one silently overwrote the other's evidence. The\n * comment that licensed it claimed a per-worktree log has exactly one writer; LogStream's class\n * comment is the measurement that disproves it (parallel PreToolUse hooks, non-isolated subagents and\n * multiple Claude Code windows all share a tree). Naming the directory after the LOG THAT POINTS AT IT\n * gives it the same one-owner-by-construction property the log itself has, and makes the pointer\n * readable: the index line, the directory and the file are one name.\n *\n * RETENTION is therefore filename-based, not directory-date-based: there is no date level left, so\n * `DetailPruner` parses `<epochMs>` out of each `writeInfo-*.md` (no `stat` call) and removes any\n * stream directory left empty. Every delete is `force: true` and failures are swallowed, so concurrent\n * agents racing the same week-old files is harmless.\n */\nconst DETAIL_PREFIX = 'writeInfo-';\nconst DETAIL_SUFFIX = '.md';\nconst DETAIL_RE = /^writeInfo-(\\d+)\\.md$/;\nconst MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded\nconst MAX_AGE_DAYS = 7;\n\nconst RULE_NAME_RE = /^\\[([^\\]]+)\\] \\(/gm;\n\nexport function logRejection(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n result: BlockedResult,\n cwd: string,\n): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // `.webpieces/` lives at the repo root, NOT the AI's cwd — resolve it so a hook fired while\n // the AI is in a subdirectory never scatters a stray `<subdir>/.webpieces` tree.\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n const now = new Date();\n const timestamp = now.toISOString();\n const epochMs = String(now.getTime());\n\n // LOCAL scope — a rejection is this worktree's event. WHICH writer's event is answered by the\n // stream prefix, on the index AND on its detail directory, so neither can collide.\n const logsDir = dotWebpieces.logsFile(root, REJECTIONS_STREAM);\n // The detail directory is the writer key with NO extension, sitting beside the `.log` that\n // indexes it — so index and details share one owner, one level down inside the stream dir.\n const detailDirName = logStream.writerFile('');\n const detailDir = path.join(logsDir, detailDirName);\n fs.mkdirSync(detailDir, { recursive: true });\n\n const relativePath = computeRelativePath(input.filePath, root);\n const ruleNames = extractRuleNames(result.report);\n const detailFileName = `${DETAIL_PREFIX}${epochMs}${DETAIL_SUFFIX}`;\n // Relative to `rejections/` — the index's own directory — so the pointer resolves from where\n // the reader found the line, and reads as the log's own name plus a file.\n const detailRelPath = `${detailDirName}/${detailFileName}`;\n\n const detail = buildDetailContent(timestamp, toolKind, relativePath, ruleNames, result.report, input);\n fs.writeFileSync(path.join(detailDir, detailFileName), detail);\n\n const logPath = path.join(logsDir, logStream.writerFile('.log'));\n rotateLogFile(logPath, path.join(logsDir, logStream.writerFile('.1.log')));\n\n // APPEND-ONLY, and `fault=` is spelled exactly as the L0 sh log spells it. A fault-S storm\n // previously landed here as a couple of lines attributed to whatever rule the report happened\n // to cite, with nothing anywhere identifying L0 as the cause. (WHO made the call is answered by\n // the filename, which logStream prefixes with session/agent/hook — not by a column here.)\n // `ai=` joins the same append-only tail as `fault=`, in the same vocabulary the L0 sh shim and\n // both decision streams use — so `grep ai=codex` spans all five streams. A row from a release\n // that predates the field carries no `ai=` and reads as `unknown`.\n const logLine = `[${timestamp}]\\t${toolKind}\\t${relativePath}\\t[${ruleNames.join(',')}]\\t${detailRelPath}\\tfault=${result.fault}\\tai=${aiTypeContext.forLog()}\\n`;\n fs.appendFileSync(logPath, logLine);\n\n detailPruner.prune(logsDir, MAX_AGE_DAYS);\n } catch (err: unknown) {\n //const error = toError(err);\n void err;\n }\n}\n\nfunction computeRelativePath(filePath: string, cwd: string): string {\n if (filePath.startsWith(cwd)) {\n const rel = filePath.slice(cwd.length);\n if (rel.startsWith('/')) return rel.slice(1);\n return rel;\n }\n return filePath;\n}\n\n/**\n * The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because\n * two audit streams need the same answer from the same regex: this file's rejection index, and the\n * `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be\n * two answers to one question.\n */\n// webpieces-disable no-function-outside-class -- pure regex scraper beside this module's other module-scope helpers; exported so the invocation log and the rejection index scrape rule names with the SAME code.\nexport function extractRuleNames(report: string): string[] {\n const names: string[] = [];\n let match = RULE_NAME_RE.exec(report);\n while (match !== null) {\n names.push(match[1]);\n match = RULE_NAME_RE.exec(report);\n }\n RULE_NAME_RE.lastIndex = 0;\n return names;\n}\n\nfunction buildDetailContent(\n timestamp: string,\n toolKind: ToolKind,\n relativePath: string,\n ruleNames: string[],\n report: string,\n input: NormalizedToolInput,\n): string {\n const lines: string[] = [];\n lines.push('# Hook Rejection Detail');\n lines.push('');\n lines.push(`- **Timestamp:** ${timestamp}`);\n lines.push(`- **Tool:** ${toolKind}`);\n lines.push(`- **File:** ${relativePath}`);\n lines.push(`- **Rules violated:** ${ruleNames.join(', ')}`);\n lines.push('');\n lines.push('## Report');\n lines.push('');\n lines.push('```');\n lines.push(report.trimEnd());\n lines.push('```');\n lines.push('');\n lines.push('## Content Being Written');\n lines.push('');\n\n if (toolKind === 'Write') {\n const content = input.edits.length > 0 ? input.edits[0].newString : '';\n lines.push('```typescript');\n lines.push(content.trimEnd());\n lines.push('```');\n } else {\n for (let i = 0; i < input.edits.length; i += 1) {\n const edit = input.edits[i];\n lines.push(`### Edit ${String(i + 1)} of ${String(input.edits.length)}`);\n lines.push('');\n lines.push('**old_string:**');\n lines.push('```typescript');\n lines.push(edit.oldString.trimEnd());\n lines.push('```');\n lines.push('');\n lines.push('**new_string:**');\n lines.push('```typescript');\n lines.push(edit.newString.trimEnd());\n lines.push('```');\n lines.push('');\n }\n }\n\n return lines.join('\\n') + '\\n';\n}\n\nfunction rotateLogFile(logPath: string, prevPath: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const stat = fs.statSync(logPath);\n if (stat.size > MAX_LOG_BYTES) {\n if (fs.existsSync(prevPath)) fs.unlinkSync(prevPath);\n fs.renameSync(logPath, prevPath);\n }\n } catch (err: unknown) {\n //const error = toError(err);\n void err;\n }\n}\n\n/**\n * The 7-day sweep over rejection DETAIL files.\n *\n * A class rather than four module-scope helpers because the four belong together: `prune` is the\n * policy and the other three are the swallow-everything filesystem calls it is built from, none of\n * which means anything on its own.\n *\n * The age comes out of the FILENAME, not out of `stat` — the epoch millis are already in the name, so\n * a sweep costs one `readdir` per stream directory and no syscall per file. (The old scheme could\n * delete a whole `hooks/<YYYY-MM-DD>/` in one recursive `rm` because the date WAS the directory; the\n * directory is now the WRITER, which never expires, so expiry moved down one level.)\n *\n * IDEMPOTENT AND RACE-TOLERANT ON PURPOSE. Several agents sweep the same directory concurrently, so\n * two processes will regularly try to unlink the same week-old file and to rmdir the same emptied\n * directory. `force: true` makes an already-gone target a no-op, an rmdir of a still-populated (or\n * already-removed) directory fails harmlessly, and every error is swallowed: the loser of the race\n * does nothing and reports nothing, which is the correct outcome — the file is gone either way.\n */\nclass DetailPruner {\n prune(logsDir: string, maxAgeDays: number): void {\n const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;\n for (const dirName of this.readdirOrEmpty(logsDir)) {\n const dir = path.join(logsDir, dirName);\n if (!this.isDirectory(dir)) continue;\n const names = this.readdirOrEmpty(dir);\n let removed = 0;\n for (const name of names) {\n const match = DETAIL_RE.exec(name);\n if (match === null) continue;\n if (Number(match[1]) >= cutoff) continue;\n this.removeFile(path.join(dir, name));\n removed += 1;\n }\n // Only a directory we just emptied is a candidate, and the removal is a NON-recursive rmdir\n // on purpose: it fails harmlessly if a concurrent writer dropped a fresh detail in between,\n // so the sweep can never take a file it did not decide was expired.\n if (removed > 0 && removed === names.length) this.removeEmptyDir(dir);\n }\n }\n\n private readdirOrEmpty(dir: string): string[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.readdirSync(dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n private isDirectory(target: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.statSync(target).isDirectory();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // `force: true` is what makes the concurrent sweep harmless: a file another agent already deleted\n // is a no-op rather than an ENOENT.\n private removeFile(target: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmSync(target, { force: true });\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n\n // NON-recursive by design — see prune(). This must refuse a directory that is not empty.\n private removeEmptyDir(target: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmdirSync(target);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n}\n\nconst detailPruner = new DetailPruner();\n"]}
|
package/src/core/report.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { RuleGroup } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* How the report names the tool it just blocked. Data-only, so a class (per CLAUDE.md).
|
|
4
|
-
*
|
|
5
|
-
* WHY it is a parameter: the header and footer used to be hard-coded to "write". A blocked READ
|
|
6
|
-
* therefore printed "\u274c webpieces ai-hooks blocked this write:" and closed with "This is a pre-write
|
|
7
|
-
* check. Fix and retry the Write/Edit." \u2014 observed live, and actively misleading, because the agent is
|
|
8
|
-
* told to fix and retry the one tool it did not use. A blocked Bash command printed the same thing
|
|
9
|
-
* against the path `<bash>`.
|
|
10
|
-
*/
|
|
11
|
-
export declare class ReportSubject {
|
|
12
|
-
/** Fills "blocked this ___". */
|
|
13
|
-
noun: string;
|
|
14
|
-
/** The closing line: what kind of check this was and which tool to retry. */
|
|
15
|
-
footer: string;
|
|
16
|
-
constructor(noun: string, footer: string);
|
|
17
|
-
}
|
|
18
|
-
export declare const WRITE_SUBJECT: ReportSubject;
|
|
19
|
-
export declare const READ_SUBJECT: ReportSubject;
|
|
20
|
-
export declare const BASH_SUBJECT: ReportSubject;
|
|
21
|
-
export declare function formatReport(relativePath: string, ruleGroups: readonly RuleGroup[], subject?: ReportSubject): string;
|
package/src/core/report.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BASH_SUBJECT = exports.READ_SUBJECT = exports.WRITE_SUBJECT = exports.ReportSubject = void 0;
|
|
4
|
-
exports.formatReport = formatReport;
|
|
5
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
/**
|
|
7
|
-
* How the report names the tool it just blocked. Data-only, so a class (per CLAUDE.md).
|
|
8
|
-
*
|
|
9
|
-
* WHY it is a parameter: the header and footer used to be hard-coded to "write". A blocked READ
|
|
10
|
-
* therefore printed "\u274c webpieces ai-hooks blocked this write:" and closed with "This is a pre-write
|
|
11
|
-
* check. Fix and retry the Write/Edit." \u2014 observed live, and actively misleading, because the agent is
|
|
12
|
-
* told to fix and retry the one tool it did not use. A blocked Bash command printed the same thing
|
|
13
|
-
* against the path `<bash>`.
|
|
14
|
-
*/
|
|
15
|
-
class ReportSubject {
|
|
16
|
-
/** Fills "blocked this ___". */
|
|
17
|
-
noun;
|
|
18
|
-
/** The closing line: what kind of check this was and which tool to retry. */
|
|
19
|
-
footer;
|
|
20
|
-
constructor(noun, footer) {
|
|
21
|
-
this.noun = noun;
|
|
22
|
-
this.footer = footer;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.ReportSubject = ReportSubject;
|
|
26
|
-
exports.WRITE_SUBJECT = new ReportSubject('write', 'This is a pre-write check. Fix and retry the Write/Edit.');
|
|
27
|
-
exports.READ_SUBJECT = new ReportSubject('read', 'This is a pre-read check. Follow the fix above, then retry the Read.');
|
|
28
|
-
exports.BASH_SUBJECT = new ReportSubject('command', 'This is a pre-run check. Follow the fix above, then retry the command.');
|
|
29
|
-
// webpieces-disable no-function-outside-class -- pre-existing shape: this whole module is the report formatter as module-scope functions, and a lone class here would break it
|
|
30
|
-
function formatReport(relativePath, ruleGroups, subject = exports.WRITE_SUBJECT) {
|
|
31
|
-
const lines = [];
|
|
32
|
-
lines.push(`\u274c webpieces ai-hooks blocked this ${subject.noun}: ${relativePath}`);
|
|
33
|
-
lines.push('');
|
|
34
|
-
for (const group of ruleGroups) {
|
|
35
|
-
const count = group.violations.length;
|
|
36
|
-
const label = count === 1 ? '1 violation' : `${count} violations`;
|
|
37
|
-
lines.push(`[${group.ruleName}] (${label})`);
|
|
38
|
-
const fh = group.fixHint;
|
|
39
|
-
for (const v of group.violations) {
|
|
40
|
-
const editPrefix = formatEditPrefix(v);
|
|
41
|
-
lines.push(` ${editPrefix}L${String(v.line)}: ${v.snippet}`);
|
|
42
|
-
// Per-occurrence override (dynamic rules), else the rule-level FixHint.violation.
|
|
43
|
-
lines.push(` \u2192 ${v.message ?? fh.violation}`);
|
|
44
|
-
}
|
|
45
|
-
// mainMessage may be '' (guidance already on the violation line) \u2014 skip when empty.
|
|
46
|
-
if (fh.mainMessage)
|
|
47
|
-
for (const l of fh.mainMessage.split('\n'))
|
|
48
|
-
lines.push(` ${l}`);
|
|
49
|
-
// "Fix Option N:" numbering + "(preferred)" are framework-owned so a multi-line message
|
|
50
|
-
// can never become fake options and authors never hand-write those labels. ONE renderer
|
|
51
|
-
// (`formatFixOptions`, in rules-config) serves this report, the thrown-rule path in
|
|
52
|
-
// runner.ts and the build-time console in code-rules.
|
|
53
|
-
for (const l of (0, rules_config_1.formatFixOptions)(fh.fixOptions))
|
|
54
|
-
lines.push(l);
|
|
55
|
-
// Framework-owned disable escape (only the 9 disable-able code-style rules set this).
|
|
56
|
-
if (fh.escape) {
|
|
57
|
-
lines.push(fh.escape.allowed
|
|
58
|
-
? ` Escape (if truly needed): ${fh.escape.comment}`
|
|
59
|
-
: ' \u{1F512} The team disabled escaping via webpieces-disable for this rule (disableAllowed:false) — it must be followed.');
|
|
60
|
-
}
|
|
61
|
-
lines.push('');
|
|
62
|
-
}
|
|
63
|
-
lines.push(subject.footer);
|
|
64
|
-
lines.push('');
|
|
65
|
-
return lines.join('\n');
|
|
66
|
-
}
|
|
67
|
-
function formatEditPrefix(v) {
|
|
68
|
-
if (v.editIndex !== undefined && v.editCount !== undefined && v.editCount > 1) {
|
|
69
|
-
return `edit ${String(v.editIndex + 1)}/${String(v.editCount)} `;
|
|
70
|
-
}
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=report.js.map
|
package/src/core/report.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/report.ts"],"names":[],"mappings":";;;AAgCA,oCAuCC;AAtED,0DAA2D;AAE3D;;;;;;;;GAQG;AACH,MAAa,aAAa;IACtB,gCAAgC;IAChC,IAAI,CAAS;IACb,6EAA6E;IAC7E,MAAM,CAAS;IAEf,YAAY,IAAY,EAAE,MAAc;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAVD,sCAUC;AAEY,QAAA,aAAa,GAAG,IAAI,aAAa,CAC1C,OAAO,EAAE,0DAA0D,CAAC,CAAC;AAC5D,QAAA,YAAY,GAAG,IAAI,aAAa,CACzC,MAAM,EAAE,sEAAsE,CAAC,CAAC;AACvE,QAAA,YAAY,GAAG,IAAI,aAAa,CACzC,SAAS,EAAE,wEAAwE,CAAC,CAAC;AAEzF,+KAA+K;AAC/K,SAAgB,YAAY,CACxB,YAAoB,EACpB,UAAgC,EAChC,UAAyB,qBAAa;IAEtC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,0CAA0C,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC,CAAC;IACtF,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC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,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAY;IAClC,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QAC5E,OAAO,QAAQ,MAAM,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;IACrE,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import type { RuleGroup, Violation } from './types';\nimport { formatFixOptions } from '@webpieces/rules-config';\n\n/**\n * How the report names the tool it just blocked. Data-only, so a class (per CLAUDE.md).\n *\n * WHY it is a parameter: the header and footer used to be hard-coded to \"write\". A blocked READ\n * therefore printed \"\\u274c webpieces ai-hooks blocked this write:\" and closed with \"This is a pre-write\n * check. Fix and retry the Write/Edit.\" \\u2014 observed live, and actively misleading, because the agent is\n * told to fix and retry the one tool it did not use. A blocked Bash command printed the same thing\n * against the path `<bash>`.\n */\nexport class ReportSubject {\n /** Fills \"blocked this ___\". */\n noun: string;\n /** The closing line: what kind of check this was and which tool to retry. */\n footer: string;\n\n constructor(noun: string, footer: string) {\n this.noun = noun;\n this.footer = footer;\n }\n}\n\nexport const WRITE_SUBJECT = new ReportSubject(\n 'write', 'This is a pre-write check. Fix and retry the Write/Edit.');\nexport const READ_SUBJECT = new ReportSubject(\n 'read', 'This is a pre-read check. Follow the fix above, then retry the Read.');\nexport const BASH_SUBJECT = new ReportSubject(\n 'command', 'This is a pre-run check. Follow the fix above, then retry the command.');\n\n// webpieces-disable no-function-outside-class -- pre-existing shape: this whole module is the report formatter as module-scope functions, and a lone class here would break it\nexport function formatReport(\n relativePath: string,\n ruleGroups: readonly RuleGroup[],\n subject: ReportSubject = WRITE_SUBJECT,\n): string {\n const lines: string[] = [];\n lines.push(`\\u274c webpieces ai-hooks blocked this ${subject.noun}: ${relativePath}`);\n lines.push('');\n\n for (const group of ruleGroups) {\n const count = group.violations.length;\n const label = count === 1 ? '1 violation' : `${count} violations`;\n lines.push(`[${group.ruleName}] (${label})`);\n const fh = group.fixHint;\n for (const v of group.violations) {\n const editPrefix = formatEditPrefix(v);\n lines.push(` ${editPrefix}L${String(v.line)}: ${v.snippet}`);\n // Per-occurrence override (dynamic rules), else the rule-level FixHint.violation.\n lines.push(` \\u2192 ${v.message ?? fh.violation}`);\n }\n // mainMessage may be '' (guidance already on the violation line) \\u2014 skip when empty.\n if (fh.mainMessage) for (const l of fh.mainMessage.split('\\n')) lines.push(` ${l}`);\n // \"Fix Option N:\" numbering + \"(preferred)\" are framework-owned so a multi-line message\n // can never become fake options and authors never hand-write those labels. ONE renderer\n // (`formatFixOptions`, in rules-config) serves this report, the thrown-rule path in\n // runner.ts and the build-time console in code-rules.\n for (const l of formatFixOptions(fh.fixOptions)) lines.push(l);\n // Framework-owned disable escape (only the 9 disable-able code-style rules set this).\n if (fh.escape) {\n lines.push(fh.escape.allowed\n ? ` Escape (if truly needed): ${fh.escape.comment}`\n : ' \\u{1F512} The team disabled escaping via webpieces-disable for this rule (disableAllowed:false) — it must be followed.');\n }\n lines.push('');\n }\n\n lines.push(subject.footer);\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction formatEditPrefix(v: Violation): string {\n if (v.editIndex !== undefined && v.editCount !== undefined && v.editCount > 1) {\n return `edit ${String(v.editIndex + 1)}/${String(v.editCount)} `;\n }\n return '';\n}\n"]}
|
package/src/core/rule-base.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { AbstractRule, BaseRuleConfig, RuleOptions } from '@webpieces/rules-config';
|
|
2
|
-
import type { EditContext, BashContext, FileContext, Violation, Rule } from './types';
|
|
3
|
-
import type { FixHint } from './fix-hint';
|
|
4
|
-
/**
|
|
5
|
-
* A concrete, instantiable BaseRuleConfig used as a fallback when a built-in rule has no
|
|
6
|
-
* entry in webpieces.config.json yet. It carries no values, so the rule's `description`,
|
|
7
|
-
* `fixHint`, and `defaultOptions` (which are config-independent) are still readable for the
|
|
8
|
-
* out-of-sync report — the rule never actually runs in that state (the sync check blocks first).
|
|
9
|
-
*/
|
|
10
|
-
export declare class EmptyRuleConfig extends BaseRuleConfig {
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Scope-specific base for edit rules. Extends the shared AbstractRule (which owns `name`,
|
|
14
|
-
* the typed `config`, and `shouldRun()`), and adds the ai-hook execution surface.
|
|
15
|
-
*/
|
|
16
|
-
export declare abstract class EditRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {
|
|
17
|
-
readonly scope: "edit";
|
|
18
|
-
readonly files: readonly string[];
|
|
19
|
-
readonly defaultOptions: RuleOptions;
|
|
20
|
-
abstract readonly description: string;
|
|
21
|
-
abstract readonly fixHint: FixHint;
|
|
22
|
-
abstract check(ctx: EditContext): readonly Violation[];
|
|
23
|
-
}
|
|
24
|
-
export declare abstract class FileRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {
|
|
25
|
-
readonly scope: "file";
|
|
26
|
-
readonly files: readonly string[];
|
|
27
|
-
readonly defaultOptions: RuleOptions;
|
|
28
|
-
abstract readonly description: string;
|
|
29
|
-
abstract readonly fixHint: FixHint;
|
|
30
|
-
abstract check(ctx: FileContext): readonly Violation[];
|
|
31
|
-
}
|
|
32
|
-
export declare abstract class BashRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {
|
|
33
|
-
readonly scope: "bash";
|
|
34
|
-
readonly files: readonly string[];
|
|
35
|
-
readonly defaultOptions: RuleOptions;
|
|
36
|
-
abstract readonly description: string;
|
|
37
|
-
abstract readonly fixHint: FixHint;
|
|
38
|
-
abstract check(ctx: BashContext): readonly Violation[];
|
|
39
|
-
}
|
package/src/core/rule-base.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BashRuleBase = exports.FileRuleBase = exports.EditRuleBase = exports.EmptyRuleConfig = void 0;
|
|
4
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
-
/**
|
|
6
|
-
* A concrete, instantiable BaseRuleConfig used as a fallback when a built-in rule has no
|
|
7
|
-
* entry in webpieces.config.json yet. It carries no values, so the rule's `description`,
|
|
8
|
-
* `fixHint`, and `defaultOptions` (which are config-independent) are still readable for the
|
|
9
|
-
* out-of-sync report — the rule never actually runs in that state (the sync check blocks first).
|
|
10
|
-
*/
|
|
11
|
-
class EmptyRuleConfig extends rules_config_1.BaseRuleConfig {
|
|
12
|
-
}
|
|
13
|
-
exports.EmptyRuleConfig = EmptyRuleConfig;
|
|
14
|
-
/**
|
|
15
|
-
* Scope-specific base for edit rules. Extends the shared AbstractRule (which owns `name`,
|
|
16
|
-
* the typed `config`, and `shouldRun()`), and adds the ai-hook execution surface.
|
|
17
|
-
*/
|
|
18
|
-
class EditRuleBase extends rules_config_1.AbstractRule {
|
|
19
|
-
scope = 'edit';
|
|
20
|
-
files = [];
|
|
21
|
-
defaultOptions = {};
|
|
22
|
-
}
|
|
23
|
-
exports.EditRuleBase = EditRuleBase;
|
|
24
|
-
class FileRuleBase extends rules_config_1.AbstractRule {
|
|
25
|
-
scope = 'file';
|
|
26
|
-
files = [];
|
|
27
|
-
defaultOptions = {};
|
|
28
|
-
}
|
|
29
|
-
exports.FileRuleBase = FileRuleBase;
|
|
30
|
-
class BashRuleBase extends rules_config_1.AbstractRule {
|
|
31
|
-
scope = 'bash';
|
|
32
|
-
files = [];
|
|
33
|
-
defaultOptions = {};
|
|
34
|
-
}
|
|
35
|
-
exports.BashRuleBase = BashRuleBase;
|
|
36
|
-
//# sourceMappingURL=rule-base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rule-base.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/rule-base.ts"],"names":[],"mappings":";;;AAAA,0DAAoF;AAKpF;;;;;GAKG;AACH,MAAa,eAAgB,SAAQ,6BAAc;CAAG;AAAtD,0CAAsD;AAEtD;;;GAGG;AACH,MAAsB,YAAuC,SAAQ,2BAAe;IACvE,KAAK,GAAG,MAAe,CAAC;IACxB,KAAK,GAAsB,EAAE,CAAC;IAC9B,cAAc,GAAgB,EAAE,CAAC;CAK7C;AARD,oCAQC;AAED,MAAsB,YAAuC,SAAQ,2BAAe;IACvE,KAAK,GAAG,MAAe,CAAC;IACxB,KAAK,GAAsB,EAAE,CAAC;IAC9B,cAAc,GAAgB,EAAE,CAAC;CAK7C;AARD,oCAQC;AAED,MAAsB,YAAuC,SAAQ,2BAAe;IACvE,KAAK,GAAG,MAAe,CAAC;IACxB,KAAK,GAAsB,EAAE,CAAC;IAC9B,cAAc,GAAgB,EAAE,CAAC;CAK7C;AARD,oCAQC","sourcesContent":["import { AbstractRule, BaseRuleConfig, RuleOptions } from '@webpieces/rules-config';\n\nimport type { EditContext, BashContext, FileContext, Violation, Rule } from './types';\nimport type { FixHint } from './fix-hint';\n\n/**\n * A concrete, instantiable BaseRuleConfig used as a fallback when a built-in rule has no\n * entry in webpieces.config.json yet. It carries no values, so the rule's `description`,\n * `fixHint`, and `defaultOptions` (which are config-independent) are still readable for the\n * out-of-sync report — the rule never actually runs in that state (the sync check blocks first).\n */\nexport class EmptyRuleConfig extends BaseRuleConfig {}\n\n/**\n * Scope-specific base for edit rules. Extends the shared AbstractRule (which owns `name`,\n * the typed `config`, and `shouldRun()`), and adds the ai-hook execution surface.\n */\nexport abstract class EditRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {\n readonly scope = 'edit' as const;\n readonly files: readonly string[] = [];\n readonly defaultOptions: RuleOptions = {};\n abstract readonly description: string;\n abstract readonly fixHint: FixHint;\n\n abstract check(ctx: EditContext): readonly Violation[];\n}\n\nexport abstract class FileRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {\n readonly scope = 'file' as const;\n readonly files: readonly string[] = [];\n readonly defaultOptions: RuleOptions = {};\n abstract readonly description: string;\n abstract readonly fixHint: FixHint;\n\n abstract check(ctx: FileContext): readonly Violation[];\n}\n\nexport abstract class BashRuleBase<C extends BaseRuleConfig> extends AbstractRule<C> implements Rule {\n readonly scope = 'bash' as const;\n readonly files: readonly string[] = [];\n readonly defaultOptions: RuleOptions = {};\n abstract readonly description: string;\n abstract readonly fixHint: FixHint;\n\n abstract check(ctx: BashContext): readonly Violation[];\n}\n"]}
|