@webpieces/ai-hook-rules 0.4.838 → 0.4.840
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -140
- package/package.json +7 -15
- package/src/adapters/hook-app-fixtures.d.ts +1 -1
- package/src/adapters/hook-app-fixtures.js +0 -8
- package/src/adapters/hook-app-fixtures.js.map +1 -1
- package/src/adapters/hook-core.d.ts +1 -21
- package/src/adapters/hook-core.js +22 -341
- package/src/adapters/hook-core.js.map +1 -1
- package/src/core/load-rules.d.ts +4 -39
- package/src/core/load-rules.js +15 -127
- package/src/core/load-rules.js.map +1 -1
- package/src/core/rules/catch-error-pattern.d.ts +3 -3
- package/src/core/rules/catch-error-pattern.js +13 -13
- package/src/core/rules/catch-error-pattern.js.map +1 -1
- package/src/core/rules/index.d.ts +1 -14
- package/src/core/rules/index.js +1 -17
- package/src/core/rules/index.js.map +1 -1
- package/src/core/rules/match-rule.d.ts +3 -3
- package/src/core/rules/match-rule.js +6 -6
- package/src/core/rules/match-rule.js.map +1 -1
- package/src/core/rules/max-file-lines.d.ts +3 -3
- package/src/core/rules/max-file-lines.js +7 -7
- package/src/core/rules/max-file-lines.js.map +1 -1
- package/src/core/rules/no-any-unknown.d.ts +3 -3
- package/src/core/rules/no-any-unknown.js +6 -6
- package/src/core/rules/no-any-unknown.js.map +1 -1
- package/src/core/rules/no-custom-css.d.ts +3 -3
- package/src/core/rules/no-custom-css.js +7 -7
- package/src/core/rules/no-custom-css.js.map +1 -1
- package/src/core/rules/no-destructure.d.ts +3 -3
- package/src/core/rules/no-destructure.js +7 -7
- package/src/core/rules/no-destructure.js.map +1 -1
- package/src/core/rules/no-implicit-any.d.ts +3 -3
- package/src/core/rules/no-implicit-any.js +6 -6
- package/src/core/rules/no-implicit-any.js.map +1 -1
- package/src/core/rules/no-js-files.d.ts +3 -3
- package/src/core/rules/no-js-files.js +6 -6
- package/src/core/rules/no-js-files.js.map +1 -1
- package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
- package/src/core/rules/no-process-exit-outside-main.js +7 -7
- package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
- package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
- package/src/core/rules/no-symbol-di-tokens.js +7 -7
- package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
- package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
- package/src/core/rules/no-unmanaged-exceptions.js +9 -9
- package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
- package/src/core/rules/require-return-type.d.ts +3 -3
- package/src/core/rules/require-return-type.js +6 -6
- package/src/core/rules/require-return-type.js.map +1 -1
- package/src/core/rules/throw-cause-required.d.ts +3 -3
- package/src/core/rules/throw-cause-required.js +9 -9
- package/src/core/rules/throw-cause-required.js.map +1 -1
- package/src/core/rules/validate-ts-in-src.d.ts +3 -3
- package/src/core/rules/validate-ts-in-src.js +7 -7
- package/src/core/rules/validate-ts-in-src.js.map +1 -1
- package/src/core/runner.d.ts +10 -19
- package/src/core/runner.js +24 -622
- package/src/core/runner.js.map +1 -1
- package/src/index.d.ts +2 -15
- package/src/index.js +4 -54
- package/src/index.js.map +1 -1
- package/openclaw.plugin.json +0 -15
- package/src/adapters/agent-adapters.d.ts +0 -13
- package/src/adapters/agent-adapters.js +0 -23
- package/src/adapters/agent-adapters.js.map +0 -1
- package/src/adapters/agent-payload.d.ts +0 -48
- package/src/adapters/agent-payload.js +0 -30
- package/src/adapters/agent-payload.js.map +0 -1
- package/src/adapters/agent-response.d.ts +0 -5
- package/src/adapters/agent-response.js +0 -86
- package/src/adapters/agent-response.js.map +0 -1
- package/src/adapters/claude-code-adapter.d.ts +0 -26
- package/src/adapters/claude-code-adapter.js +0 -69
- package/src/adapters/claude-code-adapter.js.map +0 -1
- package/src/adapters/codex-adapter.d.ts +0 -19
- package/src/adapters/codex-adapter.js +0 -48
- package/src/adapters/codex-adapter.js.map +0 -1
- package/src/adapters/codex-subagent-guard.d.ts +0 -45
- package/src/adapters/codex-subagent-guard.js +0 -88
- package/src/adapters/codex-subagent-guard.js.map +0 -1
- package/src/adapters/detect-ai.d.ts +0 -70
- package/src/adapters/detect-ai.js +0 -82
- package/src/adapters/detect-ai.js.map +0 -1
- package/src/adapters/guards-hook.d.ts +0 -3
- package/src/adapters/guards-hook.js +0 -30
- package/src/adapters/guards-hook.js.map +0 -1
- package/src/adapters/openclaw-plugin.d.ts +0 -14
- package/src/adapters/openclaw-plugin.js +0 -87
- package/src/adapters/openclaw-plugin.js.map +0 -1
- package/src/adapters/review-identity-stamper.d.ts +0 -20
- package/src/adapters/review-identity-stamper.js +0 -34
- package/src/adapters/review-identity-stamper.js.map +0 -1
- package/src/bin/codex-trust.d.ts +0 -105
- package/src/bin/codex-trust.js +0 -205
- package/src/bin/codex-trust.js.map +0 -1
- package/src/bin/dev-hook-install.d.ts +0 -1
- package/src/bin/dev-hook-install.js +0 -82
- package/src/bin/dev-hook-install.js.map +0 -1
- package/src/bin/dev-hook-uninstall.d.ts +0 -1
- package/src/bin/dev-hook-uninstall.js +0 -45
- package/src/bin/dev-hook-uninstall.js.map +0 -1
- package/src/bin/hook-registration.d.ts +0 -429
- package/src/bin/hook-registration.js +0 -661
- package/src/bin/hook-registration.js.map +0 -1
- package/src/bin/install-entry.d.ts +0 -19
- package/src/bin/install-entry.js +0 -128
- package/src/bin/install-entry.js.map +0 -1
- package/src/bin/l0-allowlist.d.ts +0 -49
- package/src/bin/l0-allowlist.js +0 -528
- package/src/bin/l0-allowlist.js.map +0 -1
- package/src/bin/l0-codex-read.d.ts +0 -21
- package/src/bin/l0-codex-read.js +0 -109
- package/src/bin/l0-codex-read.js.map +0 -1
- package/src/bin/l0-decide.d.ts +0 -50
- package/src/bin/l0-decide.js +0 -103
- package/src/bin/l0-decide.js.map +0 -1
- package/src/bin/l0-entry.d.ts +0 -103
- package/src/bin/l0-entry.js +0 -98
- package/src/bin/l0-entry.js.map +0 -1
- package/src/bin/l0-ignored-tools.d.ts +0 -38
- package/src/bin/l0-ignored-tools.js +0 -44
- package/src/bin/l0-ignored-tools.js.map +0 -1
- package/src/bin/managed-env.d.ts +0 -46
- package/src/bin/managed-env.js +0 -50
- package/src/bin/managed-env.js.map +0 -1
- package/src/bin/neighbour-hooks.d.ts +0 -42
- package/src/bin/neighbour-hooks.js +0 -177
- package/src/bin/neighbour-hooks.js.map +0 -1
- package/src/bin/reviewer-agent.d.ts +0 -19
- package/src/bin/reviewer-agent.js +0 -135
- package/src/bin/reviewer-agent.js.map +0 -1
- package/src/bin/settings-shape.d.ts +0 -37
- package/src/bin/settings-shape.js +0 -17
- package/src/bin/settings-shape.js.map +0 -1
- package/src/bin/setup-config.d.ts +0 -19
- package/src/bin/setup-config.js +0 -370
- package/src/bin/setup-config.js.map +0 -1
- package/src/bin/setup.d.ts +0 -78
- package/src/bin/setup.js +0 -400
- package/src/bin/setup.js.map +0 -1
- package/src/bin/shim-audit-log.d.ts +0 -119
- package/src/bin/shim-audit-log.js +0 -286
- package/src/bin/shim-audit-log.js.map +0 -1
- package/src/bin/shim-deny-reason.d.ts +0 -1
- package/src/bin/shim-deny-reason.js +0 -244
- package/src/bin/shim-deny-reason.js.map +0 -1
- package/src/bin/shim-drift-fix.d.ts +0 -1
- package/src/bin/shim-drift-fix.js +0 -72
- package/src/bin/shim-drift-fix.js.map +0 -1
- package/src/bin/shim-testkit.d.ts +0 -107
- package/src/bin/shim-testkit.js +0 -197
- package/src/bin/shim-testkit.js.map +0 -1
- package/src/bin/shim-version-drift.d.ts +0 -1
- package/src/bin/shim-version-drift.js +0 -164
- package/src/bin/shim-version-drift.js.map +0 -1
- package/src/bin/shim.d.ts +0 -16
- package/src/bin/shim.js +0 -636
- package/src/bin/shim.js.map +0 -1
- package/src/bin/upgrade-shim.d.ts +0 -18
- package/src/bin/upgrade-shim.js +0 -283
- package/src/bin/upgrade-shim.js.map +0 -1
- package/src/core/ai-type-context.d.ts +0 -36
- package/src/core/ai-type-context.js +0 -45
- package/src/core/ai-type-context.js.map +0 -1
- package/src/core/apply-patch-parse.d.ts +0 -36
- package/src/core/apply-patch-parse.js +0 -154
- package/src/core/apply-patch-parse.js.map +0 -1
- package/src/core/build-context.d.ts +0 -10
- package/src/core/build-context.js +0 -66
- package/src/core/build-context.js.map +0 -1
- package/src/core/command-scan.d.ts +0 -122
- package/src/core/command-scan.js +0 -282
- package/src/core/command-scan.js.map +0 -1
- package/src/core/custom-rule-adapter.d.ts +0 -22
- package/src/core/custom-rule-adapter.js +0 -50
- package/src/core/custom-rule-adapter.js.map +0 -1
- package/src/core/decision-log.d.ts +0 -190
- package/src/core/decision-log.js +0 -406
- package/src/core/decision-log.js.map +0 -1
- package/src/core/delete-scoped-rules.d.ts +0 -8
- package/src/core/delete-scoped-rules.js +0 -31
- package/src/core/delete-scoped-rules.js.map +0 -1
- package/src/core/disable-directives.d.ts +0 -8
- package/src/core/disable-directives.js +0 -80
- package/src/core/disable-directives.js.map +0 -1
- package/src/core/effective-tree.d.ts +0 -204
- package/src/core/effective-tree.js +0 -277
- package/src/core/effective-tree.js.map +0 -1
- package/src/core/excluded-path-escape.d.ts +0 -101
- package/src/core/excluded-path-escape.js +0 -236
- package/src/core/excluded-path-escape.js.map +0 -1
- package/src/core/excluded-paths.d.ts +0 -23
- package/src/core/excluded-paths.js +0 -54
- package/src/core/excluded-paths.js.map +0 -1
- package/src/core/fix-hint.d.ts +0 -40
- package/src/core/fix-hint.js +0 -53
- package/src/core/fix-hint.js.map +0 -1
- package/src/core/force-to-root.d.ts +0 -32
- package/src/core/force-to-root.js +0 -60
- package/src/core/force-to-root.js.map +0 -1
- package/src/core/guard-index-doc.d.ts +0 -63
- package/src/core/guard-index-doc.js +0 -172
- package/src/core/guard-index-doc.js.map +0 -1
- package/src/core/instruct-ai-writer.d.ts +0 -1
- package/src/core/instruct-ai-writer.js +0 -6
- package/src/core/instruct-ai-writer.js.map +0 -1
- package/src/core/l0-fault-codes.d.ts +0 -85
- package/src/core/l0-fault-codes.js +0 -121
- package/src/core/l0-fault-codes.js.map +0 -1
- package/src/core/l0-matrix.d.ts +0 -114
- package/src/core/l0-matrix.js +0 -416
- package/src/core/l0-matrix.js.map +0 -1
- package/src/core/l0-tooling-doc.d.ts +0 -45
- package/src/core/l0-tooling-doc.js +0 -258
- package/src/core/l0-tooling-doc.js.map +0 -1
- package/src/core/l1-doc.d.ts +0 -7
- package/src/core/l1-doc.js +0 -340
- package/src/core/l1-doc.js.map +0 -1
- package/src/core/l1-matrix-doc.d.ts +0 -31
- package/src/core/l1-matrix-doc.js +0 -111
- package/src/core/l1-matrix-doc.js.map +0 -1
- package/src/core/l1-rows.d.ts +0 -167
- package/src/core/l1-rows.js +0 -262
- package/src/core/l1-rows.js.map +0 -1
- package/src/core/l2-doc.d.ts +0 -7
- package/src/core/l2-doc.js +0 -385
- package/src/core/l2-doc.js.map +0 -1
- package/src/core/l2-matrix-doc.d.ts +0 -23
- package/src/core/l2-matrix-doc.js +0 -72
- package/src/core/l2-matrix-doc.js.map +0 -1
- package/src/core/l2-row.d.ts +0 -54
- package/src/core/l2-row.js +0 -75
- package/src/core/l2-row.js.map +0 -1
- package/src/core/l2-rows.d.ts +0 -56
- package/src/core/l2-rows.js +0 -272
- package/src/core/l2-rows.js.map +0 -1
- package/src/core/load-config.d.ts +0 -1
- package/src/core/load-config.js +0 -9
- package/src/core/load-config.js.map +0 -1
- package/src/core/log-stream.d.ts +0 -117
- package/src/core/log-stream.js +0 -156
- package/src/core/log-stream.js.map +0 -1
- package/src/core/log-streams.d.ts +0 -48
- package/src/core/log-streams.js +0 -55
- package/src/core/log-streams.js.map +0 -1
- package/src/core/log-target.d.ts +0 -21
- package/src/core/log-target.js +0 -29
- package/src/core/log-target.js.map +0 -1
- package/src/core/main-sync-log.d.ts +0 -16
- package/src/core/main-sync-log.js +0 -105
- package/src/core/main-sync-log.js.map +0 -1
- package/src/core/main-sync-refresh.d.ts +0 -39
- package/src/core/main-sync-refresh.js +0 -96
- package/src/core/main-sync-refresh.js.map +0 -1
- package/src/core/main-sync-timeout.d.ts +0 -32
- package/src/core/main-sync-timeout.js +0 -94
- package/src/core/main-sync-timeout.js.map +0 -1
- package/src/core/matrix-cures.d.ts +0 -12
- package/src/core/matrix-cures.js +0 -56
- package/src/core/matrix-cures.js.map +0 -1
- package/src/core/missing-directory.d.ts +0 -38
- package/src/core/missing-directory.js +0 -66
- package/src/core/missing-directory.js.map +0 -1
- package/src/core/read-only-inspection.d.ts +0 -34
- package/src/core/read-only-inspection.js +0 -88
- package/src/core/read-only-inspection.js.map +0 -1
- package/src/core/rejection-log.d.ts +0 -9
- package/src/core/rejection-log.js +0 -258
- package/src/core/rejection-log.js.map +0 -1
- package/src/core/report.d.ts +0 -21
- package/src/core/report.js +0 -73
- package/src/core/report.js.map +0 -1
- package/src/core/rule-base.d.ts +0 -39
- package/src/core/rule-base.js +0 -36
- package/src/core/rule-base.js.map +0 -1
- package/src/core/rules/branch-creation-guard.d.ts +0 -113
- package/src/core/rules/branch-creation-guard.js +0 -422
- package/src/core/rules/branch-creation-guard.js.map +0 -1
- package/src/core/rules/branch-switch-scan.d.ts +0 -43
- package/src/core/rules/branch-switch-scan.js +0 -132
- package/src/core/rules/branch-switch-scan.js.map +0 -1
- package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
- package/src/core/rules/build-output-pipe-guard.js +0 -120
- package/src/core/rules/build-output-pipe-guard.js.map +0 -1
- package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
- package/src/core/rules/build-output-pipe-scan.js +0 -84
- package/src/core/rules/build-output-pipe-scan.js.map +0 -1
- package/src/core/rules/cap-remedies.d.ts +0 -39
- package/src/core/rules/cap-remedies.js +0 -59
- package/src/core/rules/cap-remedies.js.map +0 -1
- package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
- package/src/core/rules/commit-message-substitution-guard.js +0 -134
- package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
- package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
- package/src/core/rules/commit-message-substitution-scan.js +0 -145
- package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
- package/src/core/rules/content-read-scan.d.ts +0 -76
- package/src/core/rules/content-read-scan.js +0 -176
- package/src/core/rules/content-read-scan.js.map +0 -1
- package/src/core/rules/cure-prefix-scan.d.ts +0 -64
- package/src/core/rules/cure-prefix-scan.js +0 -133
- package/src/core/rules/cure-prefix-scan.js.map +0 -1
- package/src/core/rules/feature-branch-guard.d.ts +0 -121
- package/src/core/rules/feature-branch-guard.js +0 -326
- package/src/core/rules/feature-branch-guard.js.map +0 -1
- package/src/core/rules/judged-tree.d.ts +0 -66
- package/src/core/rules/judged-tree.js +0 -97
- package/src/core/rules/judged-tree.js.map +0 -1
- package/src/core/rules/main-freshness.d.ts +0 -37
- package/src/core/rules/main-freshness.js +0 -61
- package/src/core/rules/main-freshness.js.map +0 -1
- package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
- package/src/core/rules/merge-in-progress-guard.js +0 -122
- package/src/core/rules/merge-in-progress-guard.js.map +0 -1
- package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
- package/src/core/rules/merged-branch-bash-guard.js +0 -170
- package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
- package/src/core/rules/merged-branch-message.d.ts +0 -59
- package/src/core/rules/merged-branch-message.js +0 -137
- package/src/core/rules/merged-branch-message.js.map +0 -1
- package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
- package/src/core/rules/pr-creation-or-push-guard.js +0 -146
- package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
- package/src/core/rules/pr-merge-guard.d.ts +0 -36
- package/src/core/rules/pr-merge-guard.js +0 -86
- package/src/core/rules/pr-merge-guard.js.map +0 -1
- package/src/core/rules/read-stale-guard.d.ts +0 -136
- package/src/core/rules/read-stale-guard.js +0 -326
- package/src/core/rules/read-stale-guard.js.map +0 -1
- package/src/core/rules/recovery-allowlist.d.ts +0 -49
- package/src/core/rules/recovery-allowlist.js +0 -187
- package/src/core/rules/recovery-allowlist.js.map +0 -1
- package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
- package/src/core/rules/redirect-how-to-merge-main.js +0 -157
- package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
- package/src/core/rules/shell-segment-scan.d.ts +0 -64
- package/src/core/rules/shell-segment-scan.js +0 -88
- package/src/core/rules/shell-segment-scan.js.map +0 -1
- package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
- package/src/core/rules/stale-main-bash-guard.js +0 -361
- package/src/core/rules/stale-main-bash-guard.js.map +0 -1
- package/src/core/rules/stale-main-message.d.ts +0 -62
- package/src/core/rules/stale-main-message.js +0 -102
- package/src/core/rules/stale-main-message.js.map +0 -1
- package/src/core/rules/tree-recovery.d.ts +0 -92
- package/src/core/rules/tree-recovery.js +0 -165
- package/src/core/rules/tree-recovery.js.map +0 -1
- package/src/core/rules/wait-spin-guard.d.ts +0 -128
- package/src/core/rules/wait-spin-guard.js +0 -211
- package/src/core/rules/wait-spin-guard.js.map +0 -1
- package/src/core/rules/wait-spin-scan.d.ts +0 -118
- package/src/core/rules/wait-spin-scan.js +0 -203
- package/src/core/rules/wait-spin-scan.js.map +0 -1
- package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
- package/src/core/rules/whole-repo-build-guard.js +0 -257
- package/src/core/rules/whole-repo-build-guard.js.map +0 -1
- package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
- package/src/core/rules/whole-repo-build-scan.js +0 -198
- package/src/core/rules/whole-repo-build-scan.js.map +0 -1
- package/src/core/session-call-history.d.ts +0 -44
- package/src/core/session-call-history.js +0 -79
- package/src/core/session-call-history.js.map +0 -1
- package/src/core/shell-read-parity.d.ts +0 -56
- package/src/core/shell-read-parity.js +0 -155
- package/src/core/shell-read-parity.js.map +0 -1
- package/src/core/strip-ts-noise.d.ts +0 -1
- package/src/core/strip-ts-noise.js +0 -185
- package/src/core/strip-ts-noise.js.map +0 -1
- package/src/core/sync-main.d.ts +0 -46
- package/src/core/sync-main.js +0 -175
- package/src/core/sync-main.js.map +0 -1
- package/src/core/target-tree.d.ts +0 -84
- package/src/core/target-tree.js +0 -148
- package/src/core/target-tree.js.map +0 -1
- package/src/core/to-error.d.ts +0 -5
- package/src/core/to-error.js +0 -37
- package/src/core/to-error.js.map +0 -1
- package/src/core/types.d.ts +0 -152
- package/src/core/types.js +0 -200
- package/src/core/types.js.map +0 -1
- package/src/core/version-sync.d.ts +0 -219
- package/src/core/version-sync.js +0 -558
- package/src/core/version-sync.js.map +0 -1
- package/src/core/webpieces-versions.d.ts +0 -98
- package/src/core/webpieces-versions.js +0 -206
- package/src/core/webpieces-versions.js.map +0 -1
- package/templates/ai-hook.sh +0 -497
- package/templates/claude-settings-hook.json +0 -28
- package/templates/webpieces-reviewer.md +0 -60
|
@@ -1,357 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shimStaleRecoveryDecision = shimStaleRecoveryDecision;
|
|
4
3
|
exports.runPipeline = runPipeline;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const path = tslib_1.__importStar(require("path"));
|
|
7
|
-
const runner_1 = require("../core/runner");
|
|
8
|
-
const main_sync_timeout_1 = require("../core/main-sync-timeout");
|
|
9
|
-
const rejection_log_1 = require("../core/rejection-log");
|
|
10
|
-
const decision_log_1 = require("../core/decision-log");
|
|
11
|
-
const main_sync_refresh_1 = require("../core/main-sync-refresh");
|
|
12
|
-
const load_config_1 = require("../core/load-config");
|
|
13
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
14
|
-
const types_1 = require("../core/types");
|
|
15
|
-
const to_error_1 = require("../core/to-error");
|
|
16
|
-
const agent_response_1 = require("./agent-response");
|
|
17
4
|
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const shim_1 = require("../bin/shim");
|
|
24
|
-
const hook_registration_1 = require("../bin/hook-registration");
|
|
25
|
-
const shim_deny_reason_1 = require("../bin/shim-deny-reason");
|
|
26
|
-
const l0_matrix_1 = require("../core/l0-matrix");
|
|
27
|
-
const log_stream_1 = require("../core/log-stream");
|
|
28
|
-
const ai_type_context_1 = require("../core/ai-type-context");
|
|
29
|
-
const l0_fault_codes_1 = require("../core/l0-fault-codes");
|
|
30
|
-
const ADAPTERS = new agent_adapters_1.AgentAdapters();
|
|
31
|
-
const SUBAGENT_GUARD = new codex_subagent_guard_1.CodexSubagentSharedTreeGuard();
|
|
32
|
-
const REVIEW_IDENTITY_STAMPER = new review_identity_stamper_1.ReviewIdentityStamper();
|
|
33
|
-
// The rule name for a block's audit line: the FIRST rule the report cites, or `fallback` when the
|
|
34
|
-
// report opens with no `[rule]` header (a hand-written guard message). Comma-joined when a report
|
|
35
|
-
// cites several, so `rule=` never silently drops one.
|
|
36
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
37
|
-
function blockingRule(report, fallback) {
|
|
38
|
-
const names = (0, rejection_log_1.extractRuleNames)(report);
|
|
39
|
-
return names.length > 0 ? names.join(',') : fallback;
|
|
40
|
-
}
|
|
41
|
-
// webpieces-disable no-function-outside-class -- sibling of handleRead()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
42
|
-
function handleBash(event, cwd, mode) {
|
|
43
|
-
const command = event.bash === null ? '' : event.bash.command;
|
|
44
|
-
if (command.trim() === '') {
|
|
45
|
-
(0, agent_response_1.emitAllow)();
|
|
46
|
-
}
|
|
47
|
-
// READ PARITY, and it can only ever be reached from a Codex event: the adapter leaves `reads`
|
|
48
|
-
// empty for Claude Code, which has a real `Read` tool and its own fast path. A Codex read arrives
|
|
49
|
-
// as `Bash` running a pager, so without this the read guard and the `calls/` audit trail see none
|
|
50
|
-
// of them. The command is STILL run through the bash guards below — this adds a verdict, it never
|
|
51
|
-
// replaces one.
|
|
52
|
-
for (const readPath of event.reads) {
|
|
53
|
-
handleRead(event, readPath, cwd, mode);
|
|
54
|
-
}
|
|
55
|
-
// The HARNESS travels with the command. Fault C and fault Y are decided inside the runner, and
|
|
56
|
-
// both consult the L0 allowlist — which since the gated entry exists cannot be asked without
|
|
57
|
-
// knowing who is calling. `event.aiType` is the adapter's answer, the same one that routed this
|
|
58
|
-
// call to the Codex read-parity loop above.
|
|
59
|
-
const result = (0, runner_1.runBash)(command, cwd, mode, event.aiType);
|
|
60
|
-
if (!result) {
|
|
61
|
-
// ALLOWED — so if this call submits a reviewer verdict, record who is submitting it before the
|
|
62
|
-
// command runs. `wp-write-review` cannot learn that from its env (see ReviewIdentityStamper).
|
|
63
|
-
REVIEW_IDENTITY_STAMPER.stamp(event, command, cwd);
|
|
64
|
-
(0, agent_response_1.emitAllow)();
|
|
65
|
-
}
|
|
66
|
-
// NO DECISION LINE HERE. This used to write a generic `bash-guard` line because a Bash deny once
|
|
67
|
-
// had no audit trail at all — but every layer now records its own: L1 into `L1-location/` with its
|
|
68
|
-
// row, L2's guards into `L2-decisions/` with their rule and cache, and emitDeny below stamps the
|
|
69
|
-
// call-level outcome onto `calls/`. So this was the THIRD line for one block, and the worst of the
|
|
70
|
-
// three: it re-resolved the root from `cwd` via RepoRootFinder, which is not necessarily the tree
|
|
71
|
-
// the guard actually judged, so a `cd`-relocated command scattered one block across two different
|
|
72
|
-
// `.webpieces` directories.
|
|
73
|
-
//
|
|
74
|
-
// Bash deny → the event's kind is 'Bash', so denyJson adds the ANSI-red systemMessage (the only
|
|
75
|
-
// field a Bash deny shows the human; permissionDecisionReason is invisible on Bash). See
|
|
76
|
-
// agent-response.ts.
|
|
77
|
-
(0, agent_response_1.emitDeny)(event, result.report, blockingRule(result.report, 'bash-guard'), result.fault);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The read-scoped guard pass. Returns normally to ALLOW; only calls emitDeny when the guard fires.
|
|
81
|
-
*
|
|
82
|
-
* Wrapped in its own catch that swallows into an allow. Every other path in this hook fails CLOSED,
|
|
83
|
-
* and that is right for edits and shell commands — but a crash here would block the agent from
|
|
84
|
-
* READING, which includes reading webpieces.config.json to turn the offending guard off. So this one
|
|
85
|
-
* path deliberately inverts the policy: a broken read-guard degrades to a no-op, never to a wedge.
|
|
86
|
-
*/
|
|
87
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
88
|
-
function handleRead(event, filePath, cwd, mode) {
|
|
89
|
-
if (filePath === '')
|
|
90
|
-
return;
|
|
91
|
-
let result = null;
|
|
92
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
93
|
-
try {
|
|
94
|
-
result = (0, runner_1.runRead)(filePath, cwd, mode);
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
const error = (0, to_error_1.toError)(err);
|
|
98
|
-
void error;
|
|
99
|
-
return; // fail OPEN — see the doc comment
|
|
100
|
-
}
|
|
101
|
-
if (!result)
|
|
102
|
-
return;
|
|
103
|
-
(0, rejection_log_1.logRejection)('Read', new types_1.NormalizedToolInput(filePath, []), result, cwd);
|
|
104
|
-
(0, agent_response_1.emitDeny)(event, result.report, blockingRule(result.report, 'read-guard'), result.fault);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Read-only tools (Read): audit-log, warm the main-sync cache, then run the ONE read-scoped guard
|
|
108
|
-
* (read-stale-guard) and allow. Runs BEFORE the general rule engine — no code-style rule ever sees a
|
|
109
|
-
* Read, and the only way this path can deny is a stale `main`. The audit trail still records every
|
|
110
|
-
* file the AI opened (see setup.ts).
|
|
111
|
-
*
|
|
112
|
-
* Returns normally ONLY when the event is not a Read; otherwise it ends the invocation.
|
|
113
|
-
*/
|
|
114
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
115
|
-
function handleReadFastPath(event, cwd, mode) {
|
|
116
|
-
if (event.kind !== 'Read')
|
|
117
|
-
return;
|
|
118
|
-
const readPath = event.reads.length > 0 ? event.reads[0] : '';
|
|
119
|
-
if (mode !== 'rules') {
|
|
120
|
-
decision_log_1.invocationLog.begin(cwd, event.rawToolName, readPath);
|
|
121
|
-
// Reads vastly outnumber edits, so refreshing here is what actually keeps the shared
|
|
122
|
-
// main-sync cache warm for feature-branch-guard. Detached; never slows the read.
|
|
123
|
-
(0, main_sync_refresh_1.triggerMainSyncRefresh)(cwd, (0, main_sync_timeout_1.branchStateHangTimeoutFor)(cwd));
|
|
124
|
-
}
|
|
125
|
-
handleRead(event, readPath, cwd, mode);
|
|
126
|
-
(0, agent_response_1.emitAllow)();
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* The file/edit pipeline, run once per file the call touches.
|
|
130
|
-
*
|
|
131
|
-
* `event.files` is a LIST because ONE Codex `apply_patch` carries many files with mixed operations.
|
|
132
|
-
* A Claude Code event always has exactly one entry, so the loop runs once and the behaviour is the
|
|
133
|
-
* single-file behaviour it has always had.
|
|
134
|
-
*/
|
|
135
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleRead() in this module; the adapter is module-scope functions by design
|
|
136
|
-
function handleFileTool(event, cwd, mode) {
|
|
137
|
-
if (event.files.length === 0) {
|
|
138
|
-
(0, agent_response_1.emitAllow)();
|
|
139
|
-
}
|
|
140
|
-
// A Codex SUBAGENT writing into the tree it shares with its coordinator. Returns null for every
|
|
141
|
-
// Claude Code event — that harness can hand a subagent its own worktree, and does.
|
|
142
|
-
const subagentBlock = SUBAGENT_GUARD.check(event, new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd));
|
|
143
|
-
if (subagentBlock) {
|
|
144
|
-
(0, agent_response_1.emitDeny)(event, subagentBlock.report, codex_subagent_guard_1.CODEX_SUBAGENT_RULE, subagentBlock.fault);
|
|
145
|
-
}
|
|
146
|
-
for (const file of event.files) {
|
|
147
|
-
handleOneFile(event, file, cwd, mode);
|
|
148
|
-
}
|
|
149
|
-
(0, agent_response_1.emitAllow)();
|
|
150
|
-
}
|
|
151
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
152
|
-
function handleOneFile(event, file, cwd, mode) {
|
|
153
|
-
const input = file.input;
|
|
154
|
-
// Always allow edits to webpieces.config.json — it's the fix target when the config is broken.
|
|
155
|
-
// This returns BEFORE run(), so feature-branch-guard never sees a config edit; record that so the
|
|
156
|
-
// audit trail explains why a config edit on a bad branch was not blocked (see decision-log.ts).
|
|
157
|
-
if (path.basename(input.filePath) === load_config_1.CONFIG_FILENAME) {
|
|
158
|
-
if (mode !== 'rules') {
|
|
159
|
-
// `.webpieces/` (the decision log + sync cache these two calls write) lives at the repo
|
|
160
|
-
// root, not the AI's cwd — resolve it so a config edit from a subdir doesn't create a
|
|
161
|
-
// stray `<subdir>/.webpieces` tree.
|
|
162
|
-
const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
|
|
163
|
-
(0, decision_log_1.logGuardDecision)(root, new decision_log_1.GuardDecision('feature-branch-guard', file.toolKind, input.filePath, (0, decision_log_1.branchForLog)(root), 'ALLOW_EXEMPT', 'config-bypass (feature-branch-guard skipped)', '-', l0_fault_codes_1.L0_FAULT_NONE, (0, decision_log_1.matrixL2Row)('config-bypass (feature-branch-guard skipped)')));
|
|
164
|
-
// The guard's own refresh trigger lives inside its check(), which we skip here — so warm
|
|
165
|
-
// the cache directly, otherwise a session that only edits webpieces.config.json never
|
|
166
|
-
// refreshes the sync status. Fire-and-forget; never blocks the edit.
|
|
167
|
-
(0, main_sync_refresh_1.triggerMainSyncRefresh)(root, (0, main_sync_timeout_1.branchStateHangTimeoutFor)(cwd));
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const result = (0, runner_1.run)(file.toolKind, input, cwd, mode);
|
|
172
|
-
if (!result)
|
|
173
|
-
return;
|
|
174
|
-
(0, rejection_log_1.logRejection)(file.toolKind, input, result, cwd);
|
|
175
|
-
// File-tool deny → the event's kind is 'File', so denyJson omits systemMessage (the reason
|
|
176
|
-
// already renders red natively for these tools). See agent-response.ts.
|
|
177
|
-
(0, agent_response_1.emitDeny)(event, result.report, blockingRule(result.report, 'file-guard'), result.fault);
|
|
178
|
-
}
|
|
179
|
-
// webpieces-disable no-function-outside-class -- pure decision helper beside the adapter's other module-scope functions; exported for direct unit testing.
|
|
180
|
-
function shimStaleRecoveryDecision(toolName, command, filePath, aiType) {
|
|
181
|
-
const allowed = (0, shim_1.isAllowed)(toolName, command, filePath, aiType);
|
|
182
|
-
if (allowed === 'pass')
|
|
183
|
-
return 'pass';
|
|
184
|
-
if (allowed === 'allow')
|
|
185
|
-
return 'allow-cure';
|
|
186
|
-
return 'deny';
|
|
187
|
-
}
|
|
188
|
-
// MANAGED-HOOK-SURFACE self-guard, moved here from the rendered shim (2026-07-24) and widened from one
|
|
189
|
-
// file to three (2026-08-07). The committed
|
|
190
|
-
// .claude/webpieces/ai-hook.sh is webpieces-MANAGED and generated from renderShim(); if it no longer
|
|
191
|
-
// matches, it was reverted / hand-edited / predates this binary, so its OWN fail-closed logic can't be
|
|
192
|
-
// trusted. We are the CURRENT binary from node_modules — the trustworthy party — so WE decide here
|
|
193
|
-
// instead of the (possibly stale) shim. It used to `cmp` itself inside the shim: a double-edged trap,
|
|
194
|
-
// since the check lived in the very file it guarded and a fix could only ship by regenerating that
|
|
195
|
-
// file. Now we fail closed on all real WORK while always leaving the recovery path open (see
|
|
196
|
-
// shimStaleRecoveryDecision): the whole L0 allowlist, any Read, and editing webpieces.config.json. We deny +
|
|
197
|
-
// tell the AI; we do NOT silently rewrite the file under it. 'rules' hook skips it (guards owns the
|
|
198
|
-
// shim). Returns normally (pass / nothing to do) or exits via emitAllow/emitDeny.
|
|
199
|
-
//
|
|
200
|
-
// It asks the allowlist about the RAW WIRE FIELDS, not about the normalized event, and that ordering is
|
|
201
|
-
// deliberate: L0 has to hold on a tree too broken to trust anything above it, including the adapters.
|
|
202
|
-
// The raw fields are the same key names in both harnesses (measured), so one reading serves both, and
|
|
203
|
-
// the answer cannot change because a normalizer changed. `event` is here only to decorate the deny.
|
|
204
|
-
// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design
|
|
205
|
-
function enforceCommittedShim(payload, event, cwd, mode) {
|
|
206
|
-
// ONE root for the whole decision, resolved from the RUNNING MODULE (governingShimRoot), never from
|
|
207
|
-
// `cwd`: the shim file we compare and the renderShim() we compare it TO must come from the same
|
|
208
|
-
// install, or the check straddles two trees and can never converge (see governingShimRoot's header).
|
|
209
|
-
// `cwd` still selects where the L0 matrix doc is dropped — that is a "where does the AI read" question,
|
|
210
|
-
// not part of the judgement.
|
|
211
|
-
const shimRoot = (0, shim_1.governingShimRoot)();
|
|
212
|
-
if (mode === 'rules')
|
|
213
|
-
return;
|
|
214
|
-
// WHICH of the managed things moved — ai-hook.sh, either harness's hook registration
|
|
215
|
-
// (.claude/settings.json, .codex/hooks.json), or the Claude settings' managed env entry (the
|
|
216
|
-
// Bash-cwd pin that keeps a guard's verdict independent of where an earlier `cd` left the shell;
|
|
217
|
-
// see managed-env.ts). Nothing validated the registration before it joined this
|
|
218
|
-
// fault, so a settings file left on a superseded form silently changed WHO GOVERNS, with no signal
|
|
219
|
-
// anywhere — which is the whole reason the registration is a drift surface and not just an install
|
|
220
|
-
// step.
|
|
221
|
-
const drifted = (0, hook_registration_1.managedSurfaceDrift)(shimRoot);
|
|
222
|
-
if (drifted.length === 0)
|
|
223
|
-
return;
|
|
224
|
-
// The harness comes from the RAW envelope too — `detectAiType` asks one question of one key, so it
|
|
225
|
-
// is as trustworthy here as the wire fields beside it, and it is the PRECISE test the shim's sh half
|
|
226
|
-
// can only approximate. Reading it off the normalized event instead would put a normalizer between
|
|
227
|
-
// L0 and its decision, which is the coupling the paragraph above exists to refuse.
|
|
228
|
-
const decision = shimStaleRecoveryDecision(payload.tool_name, payload.tool_input.command ?? '', payload.tool_input.file_path ?? '', (0, detect_ai_1.detectAiType)(payload));
|
|
229
|
-
if (decision === 'pass')
|
|
230
|
-
return;
|
|
231
|
-
if (decision === 'allow-cure')
|
|
232
|
-
(0, agent_response_1.emitAllow)();
|
|
233
|
-
// Drop the L0 matrix doc where the AI can read it and point the deny at it — a Read is entry 1 of
|
|
234
|
-
// the same allowlist, so the pointer is always followable. Best-effort: no doc → no pointer.
|
|
235
|
-
const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
|
|
236
|
-
const docPath = (0, l0_matrix_1.writeGuardMatrixDoc)(root);
|
|
237
|
-
// WRITE THE AUDIT LINE HERE. This block happens BEFORE invocationLog.begin() — it has to, since a
|
|
238
|
-
// stale shim invalidates everything downstream — so emitDeny's flush finds nothing pending and an
|
|
239
|
-
// `S` storm left NO trace at all: the one fault most likely to block twenty consecutive tool calls
|
|
240
|
-
// was the one fault the trail could not show. A decision line is the fix that costs no reordering.
|
|
241
|
-
const target = payload.tool_input.command ?? payload.tool_input.file_path ?? '';
|
|
242
|
-
(0, decision_log_1.logGuardDecision)(root, new decision_log_1.GuardDecision('committed-shim-stale', payload.tool_name, target, (0, decision_log_1.branchForLog)(root), 'BLOCK_AI_CURE', 'L0 fault S (committed shim != renderShim)', '-', l0_fault_codes_1.L0_FAULT_SHIM_STALE, decision_log_1.MATRIX_L0_BLOCK));
|
|
243
|
-
// L0 fault S in GUARD_MATRIX.md's codebook — named as the blocking rule so the invocation line
|
|
244
|
-
// says WHAT stopped the call, not merely that something did, and stamped as `fault=S` so the same
|
|
245
|
-
// grep finds it here as in the sh half's `L0-shim/` stream.
|
|
246
|
-
// A subagent is discriminated by `agent_id`, which BOTH harnesses populate on stdin only off the
|
|
247
|
-
// main loop (main falls back to the session id / leaves it empty). Its cure differs: the hooks
|
|
248
|
-
// blocking it resolve through CLAUDE_PROJECT_DIR, which names the MAIN tree.
|
|
249
|
-
const inSubagent = event.agentId !== '';
|
|
250
|
-
(0, agent_response_1.emitDeny)(event, (0, shim_deny_reason_1.shimStaleDenyReason)((0, shim_1.installedShimRulesVersion)(), shimRoot ?? '', drifted, inSubagent) + (0, l0_matrix_1.guardMatrixPointer)(docPath), 'committed-shim-stale', l0_fault_codes_1.L0_FAULT_SHIM_STALE);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* THE PIPELINE, from raw stdin bytes to the decision — the whole of `parse -> adapter -> runner ->
|
|
254
|
-
* emit`, as ONE function returning ONE value.
|
|
255
|
-
*
|
|
256
|
-
* `mode` selects which tool kinds to validate; payloads outside the mode's scope pass through
|
|
257
|
-
* (emitAllow). A block is a PreToolUse `permissionDecision:"deny"` JSON on stdout with exit 0 — see
|
|
258
|
-
* agent-response.ts. Fails CLOSED on any unexpected crash (returns a deny) so a broken hook never
|
|
259
|
-
* silently lets an edit through, and the reason surfaces in the agent's UI instead of being hidden on
|
|
260
|
-
* a stderr+exit-2 block.
|
|
261
|
-
*
|
|
262
|
-
* It reads NO stdin, writes NO stdout and calls NO exit: those three couplings are ports owned by
|
|
263
|
-
* HookApp (see hook-ports.ts), which is what makes the composed pipeline drivable from a test. This
|
|
264
|
-
* function is what `runMain` was; it is not a second spelling of it — `runMain` is deleted, and
|
|
265
|
-
* `HookApp.run()` is the only entry point.
|
|
266
|
-
*/
|
|
267
|
-
// webpieces-disable no-function-outside-class -- the module-scope hook body itself, sibling of handleBash()/handleFileTool(); the adapter is module-scope functions by design and must stay callable from a tree too broken to build a DI container
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
7
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const runner_1 = require("../core/runner");
|
|
9
|
+
// webpieces-disable no-function-outside-class -- callable source pipeline consumed by the injected HookApp evaluator
|
|
268
10
|
function runPipeline(raw, mode) {
|
|
269
|
-
// Captured as soon as the ENVELOPE parses so the fail-closed catch below can tell denyJson which
|
|
270
|
-
// kind of call it is denying — a crash on a Bash call still gets the visible red systemMessage, a
|
|
271
|
-
// crash on a file tool does not. Null (before parse / malformed input) → treated as non-Bash.
|
|
272
11
|
let event = null;
|
|
273
12
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
274
13
|
try {
|
|
275
|
-
const payload = new
|
|
276
|
-
if (!payload)
|
|
277
|
-
(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// fail, and it is what the crash path needs. The full normalization below reads `tool_input`
|
|
281
|
-
// and CAN fail (a malformed Codex patch envelope denies rather than being half-understood).
|
|
282
|
-
event = ADAPTERS.envelope(payload);
|
|
283
|
-
// BEFORE enforceCommittedShim(), which can itself write a BLOCK line. See LogStream for why
|
|
284
|
-
// all three of session/agent/hook are needed to keep concurrent writers off one file.
|
|
285
|
-
log_stream_1.logStream.identify(new log_stream_1.StreamIdentity(event.sessionId, event.agentId, mode));
|
|
286
|
-
// Same moment, same reason: every JS-side stream stamps `ai=`, and the fault-S line written
|
|
287
|
-
// inside enforceCommittedShim() is one of them. See AiTypeContext for why the harness is a
|
|
288
|
-
// process-wide holder rather than a parameter on four writers.
|
|
289
|
-
ai_type_context_1.aiTypeContext.identify(event.aiType);
|
|
290
|
-
// Prefer the payload cwd (the AI's actual working dir, follows a persisted `cd`) over
|
|
291
|
-
// process.cwd(); they match today, but the payload is the authoritative signal and stays
|
|
292
|
-
// correct if the hook is ever invoked from a fixed dir (e.g. via $CLAUDE_PROJECT_DIR).
|
|
14
|
+
const payload = new hook_runtime_1.AgentPayloadParser().parse(raw);
|
|
15
|
+
if (!payload)
|
|
16
|
+
return new hook_runtime_1.HookOutcome('', 0);
|
|
17
|
+
const adapters = new hook_runtime_1.AgentAdapters();
|
|
18
|
+
event = adapters.envelope(payload);
|
|
293
19
|
const cwd = payload.cwd ?? process.cwd();
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
// main-sync-status snapshot, on EVERY guards call, for later cleanup automation. Best-effort;
|
|
302
|
-
// never blocks the call. (The committed shim is no longer silently healed here — a mismatch is
|
|
303
|
-
// reported by the self-guard above, not rewritten out from under the AI.)
|
|
304
|
-
if (mode !== 'rules') {
|
|
305
|
-
decision_log_1.invocationLog.begin(cwd, event.rawToolName, logTarget(event));
|
|
306
|
-
}
|
|
307
|
-
if (event.kind === 'Bash') {
|
|
308
|
-
// No code-style rule is bash-scoped, so the rules hook ignores Bash.
|
|
309
|
-
if (mode === 'rules') {
|
|
310
|
-
(0, agent_response_1.emitAllow)();
|
|
311
|
-
}
|
|
312
|
-
handleBash(event, cwd, mode);
|
|
20
|
+
event = adapters.toEvent(payload, cwd);
|
|
21
|
+
if (mode === 'guards' || event.kind === 'Bash' || event.kind === 'Read')
|
|
22
|
+
return new hook_runtime_1.HookOutcome('', 0);
|
|
23
|
+
for (const file of event.files) {
|
|
24
|
+
const result = (0, runner_1.run)(file.toolKind, file.input, cwd, 'rules');
|
|
25
|
+
if (result)
|
|
26
|
+
return new hook_runtime_1.HookOutcome((0, hook_runtime_1.denyJson)(event, result.report) + '\n', 0);
|
|
313
27
|
}
|
|
314
|
-
|
|
315
|
-
// feature-branch-guard), and 'all'. The runner filters to the right category.
|
|
316
|
-
handleFileTool(event, cwd, mode);
|
|
28
|
+
return new hook_runtime_1.HookOutcome('', 0);
|
|
317
29
|
}
|
|
318
30
|
catch (err) {
|
|
319
31
|
const error = (0, to_error_1.toError)(err);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return error.outcome;
|
|
325
|
-
return denyForCrash(error, event);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
// What the `calls/` audit line names as the call's target: the command for a shell call, else the first
|
|
329
|
-
// file it touches. A Codex `apply_patch` touching several files names the first — the rejection log and
|
|
330
|
-
// the decision log carry the rest, per file.
|
|
331
|
-
// webpieces-disable no-function-outside-class -- sibling of the module-scope hook entry points in this adapter
|
|
332
|
-
function logTarget(event) {
|
|
333
|
-
if (event.kind === 'Bash')
|
|
334
|
-
return event.bash === null ? '' : event.bash.command;
|
|
335
|
-
return event.files.length > 0 ? event.files[0].input.filePath : '';
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* The fail-closed boundary for anything that escaped the hook body. An escaped RuleFailError (a rule
|
|
339
|
-
* that threw past the runner's per-rule catch) or an InformAiError (bad config/stdin, or a Codex patch
|
|
340
|
-
* envelope this parser refuses to guess at) both carry an AI-readable message; anything else is an
|
|
341
|
-
* unexpected bug. All three DENY and surface their reason, because a hook that crashed established
|
|
342
|
-
* nothing and must never be read as an allow.
|
|
343
|
-
*
|
|
344
|
-
* It BUILDS the deny (denyOutcome) rather than throwing it (emitDeny), because it is already inside
|
|
345
|
-
* the catch that the throw would land in — see HookTerminated. Same bytes either way.
|
|
346
|
-
*/
|
|
347
|
-
// webpieces-disable no-function-outside-class -- sibling of the module-scope hook entry points in this adapter; a lone class for one terminal boundary would break the file's shape
|
|
348
|
-
function denyForCrash(error, event) {
|
|
349
|
-
if (error instanceof types_1.RuleFailError) {
|
|
350
|
-
return (0, agent_response_1.denyOutcome)(event, (0, rules_config_1.renderRuleFailForAi)(error), 'rule-crash');
|
|
351
|
-
}
|
|
352
|
-
if (error instanceof types_1.InformAiError) {
|
|
353
|
-
return (0, agent_response_1.denyOutcome)(event, error.message, 'bad-config-or-stdin');
|
|
32
|
+
const reason = error instanceof rules_config_1.RuleFailError ? (0, rules_config_1.renderRuleFailForAi)(error)
|
|
33
|
+
: error instanceof tooling_common_1.InformAiError ? error.message
|
|
34
|
+
: `[ai-hooks] hook crashed unexpectedly — failing closed: ${error.message}`;
|
|
35
|
+
return new hook_runtime_1.HookOutcome((0, hook_runtime_1.denyJson)(event, reason) + '\n', 0);
|
|
354
36
|
}
|
|
355
|
-
return (0, agent_response_1.denyOutcome)(event, `[ai-hooks] hook crashed unexpectedly — failing closed: ${error.message}`, 'hook-crash');
|
|
356
37
|
}
|
|
357
38
|
//# sourceMappingURL=hook-core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-core.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/hook-core.ts"],"names":[],"mappings":";;AAmOA,8DAKC;AAoFD,kCA6DC;;AAzXD,mDAA6B;AAE7B,2CAAuD;AACvD,iEAAsE;AACtE,yDAAuE;AACvE,uDAAkI;AAClI,iEAAmE;AACnE,qDAAsD;AACtD,0DAA8E;AAC9E,yCAA2G;AAE3G,+CAA2C;AAC3C,qDAAoE;AACpE,0DAAsE;AACtE,mDAAmE;AACnE,qDAAiD;AACjD,2CAA2C;AAC3C,iEAA2F;AAC3F,uEAAkE;AAClE,sCAAsF;AACtF,gEAA+D;AAC/D,8DAA8D;AAC9D,iDAA4E;AAC5E,mDAA+D;AAC/D,6DAAwD;AACxD,2DAA4E;AAW5E,MAAM,QAAQ,GAAG,IAAI,8BAAa,EAAE,CAAC;AACrC,MAAM,cAAc,GAAG,IAAI,mDAA4B,EAAE,CAAC;AAC1D,MAAM,uBAAuB,GAAG,IAAI,+CAAqB,EAAE,CAAC;AAE5D,kGAAkG;AAClG,kGAAkG;AAClG,sDAAsD;AACtD,0JAA0J;AAC1J,SAAS,YAAY,CAAC,MAAc,EAAE,QAAgB;IAClD,MAAM,KAAK,GAAG,IAAA,gCAAgB,EAAC,MAAM,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACzD,CAAC;AAED,0JAA0J;AAC1J,SAAS,UAAU,CAAC,KAAqB,EAAE,GAAW,EAAE,IAAc;IAClE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9D,IAAI,OAAO,CAAC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AC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;AACL,CAAC;AAED,wGAAwG;AACxG,wGAAwG;AACxG,6CAA6C;AAC7C,+GAA+G;AAC/G,SAAS,SAAS,CAAC,KAAqB;IACpC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAChF,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;;;;GASG;AACH,oLAAoL;AACpL,SAAS,YAAY,CAAC,KAAY,EAAE,KAA4B;IAC5D,IAAI,KAAK,YAAY,qBAAa,EAAE,CAAC;QACjC,OAAO,IAAA,4BAAW,EAAC,KAAK,EAAE,IAAA,kCAAmB,EAAC,KAAK,CAAC,EAAE,YAAY,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,KAAK,YAAY,qBAAa,EAAE,CAAC;QACjC,OAAO,IAAA,4BAAW,EAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,IAAA,4BAAW,EAAC,KAAK,EAAE,0DAA0D,KAAK,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AACvH,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { run, runBash, runRead } from '../core/runner';\nimport { branchStateHangTimeoutFor } from '../core/main-sync-timeout';\nimport { logRejection, extractRuleNames } from '../core/rejection-log';\nimport { logGuardDecision, GuardDecision, branchForLog, invocationLog, MATRIX_L0_BLOCK, matrixL2Row } from '../core/decision-log';\nimport { triggerMainSyncRefresh } from '../core/main-sync-refresh';\nimport { CONFIG_FILENAME } from '../core/load-config';\nimport { RepoRootFinder, renderRuleFailForAi } from '@webpieces/rules-config';\nimport { NormalizedToolInput, InformAiError, RuleFailError, HookMode, BlockedResult } from '../core/types';\nimport { AgentHookEvent, AiType, FileOperation } from '@webpieces/hook-runtime';\nimport { toError } from '../core/to-error';\nimport { emitDeny, emitAllow, denyOutcome } from './agent-response';\nimport { HookOutcome, HookTerminated } from '@webpieces/hook-runtime';\nimport { AgentPayload, AgentPayloadParser } from './agent-payload';\nimport { AgentAdapters } from './agent-adapters';\nimport { detectAiType } from './detect-ai';\nimport { CodexSubagentSharedTreeGuard, CODEX_SUBAGENT_RULE } from './codex-subagent-guard';\nimport { ReviewIdentityStamper } from './review-identity-stamper';\nimport { governingShimRoot, isAllowed, installedShimRulesVersion } from '../bin/shim';\nimport { managedSurfaceDrift } from '../bin/hook-registration';\nimport { shimStaleDenyReason } from '../bin/shim-deny-reason';\nimport { writeGuardMatrixDoc, guardMatrixPointer } from '../core/l0-matrix';\nimport { logStream, StreamIdentity } from '../core/log-stream';\nimport { aiTypeContext } from '../core/ai-type-context';\nimport { L0_FAULT_SHIM_STALE, L0_FAULT_NONE } from '../core/l0-fault-codes';\n\n// Which category of rules this hook invocation runs. The hook is split into two independently\n// installable PreToolUse hooks; each runs ONE category (the runner filters by it), and both can\n// receive file AND bash payloads:\n// - 'rules' → code-style rules (file/edit scope). Bash payloads pass through (no code rules apply).\n// - 'guards' → hookGuards section: bash git/PR guards on Bash AND file guards (feature-branch-guard)\n// on Write/Edit, PLUS a log-and-allow audit of Read. Matcher is Write|Edit|MultiEdit|Bash|Read.\n// - 'all' → both categories, used by the openclaw plugin adapter (a single before_tool_call hook).\nexport type { HookMode };\n\nconst ADAPTERS = new AgentAdapters();\nconst SUBAGENT_GUARD = new CodexSubagentSharedTreeGuard();\nconst REVIEW_IDENTITY_STAMPER = new ReviewIdentityStamper();\n\n// The rule name for a block's audit line: the FIRST rule the report cites, or `fallback` when the\n// report opens with no `[rule]` header (a hand-written guard message). Comma-joined when a report\n// cites several, so `rule=` never silently drops one.\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction blockingRule(report: string, fallback: string): string {\n const names = extractRuleNames(report);\n return names.length > 0 ? names.join(',') : fallback;\n}\n\n// webpieces-disable no-function-outside-class -- sibling of handleRead()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction handleBash(event: AgentHookEvent, cwd: string, mode: HookMode): never {\n const command = event.bash === null ? '' : event.bash.command;\n if (command.trim() === '') { emitAllow(); }\n\n // READ PARITY, and it can only ever be reached from a Codex event: the adapter leaves `reads`\n // empty for Claude Code, which has a real `Read` tool and its own fast path. A Codex read arrives\n // as `Bash` running a pager, so without this the read guard and the `calls/` audit trail see none\n // of them. The command is STILL run through the bash guards below — this adds a verdict, it never\n // replaces one.\n for (const readPath of event.reads) {\n handleRead(event, readPath, cwd, mode);\n }\n\n // The HARNESS travels with the command. Fault C and fault Y are decided inside the runner, and\n // both consult the L0 allowlist — which since the gated entry exists cannot be asked without\n // knowing who is calling. `event.aiType` is the adapter's answer, the same one that routed this\n // call to the Codex read-parity loop above.\n const result = runBash(command, cwd, mode, event.aiType);\n if (!result) {\n // ALLOWED — so if this call submits a reviewer verdict, record who is submitting it before the\n // command runs. `wp-write-review` cannot learn that from its env (see ReviewIdentityStamper).\n REVIEW_IDENTITY_STAMPER.stamp(event, command, cwd);\n emitAllow();\n }\n // NO DECISION LINE HERE. This used to write a generic `bash-guard` line because a Bash deny once\n // had no audit trail at all — but every layer now records its own: L1 into `L1-location/` with its\n // row, L2's guards into `L2-decisions/` with their rule and cache, and emitDeny below stamps the\n // call-level outcome onto `calls/`. So this was the THIRD line for one block, and the worst of the\n // three: it re-resolved the root from `cwd` via RepoRootFinder, which is not necessarily the tree\n // the guard actually judged, so a `cd`-relocated command scattered one block across two different\n // `.webpieces` directories.\n //\n // Bash deny → the event's kind is 'Bash', so denyJson adds the ANSI-red systemMessage (the only\n // field a Bash deny shows the human; permissionDecisionReason is invisible on Bash). See\n // agent-response.ts.\n emitDeny(event, result.report, blockingRule(result.report, 'bash-guard'), result.fault);\n}\n\n/**\n * The read-scoped guard pass. Returns normally to ALLOW; only calls emitDeny when the guard fires.\n *\n * Wrapped in its own catch that swallows into an allow. Every other path in this hook fails CLOSED,\n * and that is right for edits and shell commands — but a crash here would block the agent from\n * READING, which includes reading webpieces.config.json to turn the offending guard off. So this one\n * path deliberately inverts the policy: a broken read-guard degrades to a no-op, never to a wedge.\n */\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction handleRead(event: AgentHookEvent, filePath: string, cwd: string, mode: HookMode): void {\n if (filePath === '') return;\n let result: BlockedResult | null = null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n result = runRead(filePath, cwd, mode);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return; // fail OPEN — see the doc comment\n }\n if (!result) return;\n logRejection('Read', new NormalizedToolInput(filePath, []), result, cwd);\n emitDeny(event, result.report, blockingRule(result.report, 'read-guard'), result.fault);\n}\n\n/**\n * Read-only tools (Read): audit-log, warm the main-sync cache, then run the ONE read-scoped guard\n * (read-stale-guard) and allow. Runs BEFORE the general rule engine — no code-style rule ever sees a\n * Read, and the only way this path can deny is a stale `main`. The audit trail still records every\n * file the AI opened (see setup.ts).\n *\n * Returns normally ONLY when the event is not a Read; otherwise it ends the invocation.\n */\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction handleReadFastPath(event: AgentHookEvent, cwd: string, mode: HookMode): void {\n if (event.kind !== 'Read') return;\n const readPath = event.reads.length > 0 ? event.reads[0] : '';\n if (mode !== 'rules') {\n invocationLog.begin(cwd, event.rawToolName, readPath);\n // Reads vastly outnumber edits, so refreshing here is what actually keeps the shared\n // main-sync cache warm for feature-branch-guard. Detached; never slows the read.\n triggerMainSyncRefresh(cwd, branchStateHangTimeoutFor(cwd));\n }\n handleRead(event, readPath, cwd, mode);\n emitAllow();\n}\n\n/**\n * The file/edit pipeline, run once per file the call touches.\n *\n * `event.files` is a LIST because ONE Codex `apply_patch` carries many files with mixed operations.\n * A Claude Code event always has exactly one entry, so the loop runs once and the behaviour is the\n * single-file behaviour it has always had.\n */\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleRead() in this module; the adapter is module-scope functions by design\nfunction handleFileTool(event: AgentHookEvent, cwd: string, mode: HookMode): never {\n if (event.files.length === 0) { emitAllow(); }\n\n // A Codex SUBAGENT writing into the tree it shares with its coordinator. Returns null for every\n // Claude Code event — that harness can hand a subagent its own worktree, and does.\n const subagentBlock = SUBAGENT_GUARD.check(event, new RepoRootFinder().resolveRepoRoot(cwd));\n if (subagentBlock) {\n emitDeny(event, subagentBlock.report, CODEX_SUBAGENT_RULE, subagentBlock.fault);\n }\n\n for (const file of event.files) {\n handleOneFile(event, file, cwd, mode);\n }\n emitAllow();\n}\n\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction handleOneFile(event: AgentHookEvent, file: FileOperation, cwd: string, mode: HookMode): void {\n const input = file.input;\n\n // Always allow edits to webpieces.config.json — it's the fix target when the config is broken.\n // This returns BEFORE run(), so feature-branch-guard never sees a config edit; record that so the\n // audit trail explains why a config edit on a bad branch was not blocked (see decision-log.ts).\n if (path.basename(input.filePath) === CONFIG_FILENAME) {\n if (mode !== 'rules') {\n // `.webpieces/` (the decision log + sync cache these two calls write) lives at the repo\n // root, not the AI's cwd — resolve it so a config edit from a subdir doesn't create a\n // stray `<subdir>/.webpieces` tree.\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n logGuardDecision(\n root,\n new GuardDecision('feature-branch-guard', file.toolKind, input.filePath, branchForLog(root), 'ALLOW_EXEMPT', 'config-bypass (feature-branch-guard skipped)', '-', L0_FAULT_NONE, matrixL2Row('config-bypass (feature-branch-guard skipped)')),\n );\n // The guard's own refresh trigger lives inside its check(), which we skip here — so warm\n // the cache directly, otherwise a session that only edits webpieces.config.json never\n // refreshes the sync status. Fire-and-forget; never blocks the edit.\n triggerMainSyncRefresh(root, branchStateHangTimeoutFor(cwd));\n }\n return;\n }\n\n const result = run(file.toolKind, input, cwd, mode);\n if (!result) return;\n\n logRejection(file.toolKind, input, result, cwd);\n // File-tool deny → the event's kind is 'File', so denyJson omits systemMessage (the reason\n // already renders red natively for these tools). See agent-response.ts.\n emitDeny(event, result.report, blockingRule(result.report, 'file-guard'), result.fault);\n}\n\n// What a stale committed shim lets through — now a thin adapter over the ONE L0 allowlist (isAllowed in\n// ../bin/shim), not a list of its own. A stale shim must NEVER trap the actions needed to recover: the\n// original \"block everything but the cures\" version also shadowed the always-allowed\n// webpieces.config.json edit (handleFileTool) and blocked reads, so a repo that ALSO needed its config\n// fixed would deadlock — blocked from editing the one file whose edit is normally always allowed, and\n// blocked from reading it to know how.\n//\n// It used to carry its OWN narrower list (isShimCureCommand: the three shim cures only), and that\n// narrowness was a defect, not a safety property: `pnpm install` and `git pull` — the two commands that\n// resolve the version disagreement underneath a stale shim — were denied. Consulting the shared\n// allowlist fixes that by construction.\n//\n// What is NOT a defect, and must not be \"fixed\": those cures rewrite the committed shim from the\n// INSTALLED binary's renderShim(), overwriting whatever was there. That is the invariant, not\n// collateral damage. The shim (D/X/K, in POSIX sh, pre-binary) and this binary (S/C/Y, in JS) are two\n// halves of ONE L0 and they exchange assumptions — the shim parses file_path and carries ALLOW-READ /\n// ALLOW-CONFIG entries this binary relies on. Pair a binary with a shim rendered by a DIFFERENT\n// release and L0 acquires holes that nothing reports. So the rule is absolute: the committed shim\n// equals renderShim() of the binary in node_modules, and a cure that forces that is the cure working.\n// See healShim's header, which states the same invariant from the other side.\n//\n// Corollary for anyone regenerating the shim in a webpieces PR: commit `templates/ai-hook.sh` (source,\n// locked to renderShim() by unit test) and leave `.claude/webpieces/ai-hook.sh` (generated artifact)\n// alone. In THIS repo the local source runs ahead of the pinned node_modules, so committing a shim\n// rendered from local source produces a commit whose shim and whose @webpieces pin come from different\n// releases — precisely the mismatch above. The artifact heals on the next upgrade; that is its job.\n//\n// - 'allow-cure' → a Bash cure on the allowlist: emitAllow directly, bypassing the git guards.\n// - 'pass' → a recovery action the normal flow already permits, so fall THROUGH and let it: ANY\n// Read (you must read to know how to fix — see handleRead, which itself fails open),\n// or an edit to webpieces.config.json (the always-allowed recovery target).\n// - 'deny' → all OTHER work: blocked until the committed shim matches renderShim() again.\nexport type ShimStaleDecision = 'allow-cure' | 'pass' | 'deny';\n// webpieces-disable no-function-outside-class -- pure decision helper beside the adapter's other module-scope functions; exported for direct unit testing.\nexport function shimStaleRecoveryDecision(toolName: string, command: string, filePath: string, aiType: AiType): ShimStaleDecision {\n const allowed = isAllowed(toolName, command, filePath, aiType);\n if (allowed === 'pass') return 'pass';\n if (allowed === 'allow') return 'allow-cure';\n return 'deny';\n}\n\n// MANAGED-HOOK-SURFACE self-guard, moved here from the rendered shim (2026-07-24) and widened from one\n// file to three (2026-08-07). The committed\n// .claude/webpieces/ai-hook.sh is webpieces-MANAGED and generated from renderShim(); if it no longer\n// matches, it was reverted / hand-edited / predates this binary, so its OWN fail-closed logic can't be\n// trusted. We are the CURRENT binary from node_modules — the trustworthy party — so WE decide here\n// instead of the (possibly stale) shim. It used to `cmp` itself inside the shim: a double-edged trap,\n// since the check lived in the very file it guarded and a fix could only ship by regenerating that\n// file. Now we fail closed on all real WORK while always leaving the recovery path open (see\n// shimStaleRecoveryDecision): the whole L0 allowlist, any Read, and editing webpieces.config.json. We deny +\n// tell the AI; we do NOT silently rewrite the file under it. 'rules' hook skips it (guards owns the\n// shim). Returns normally (pass / nothing to do) or exits via emitAllow/emitDeny.\n//\n// It asks the allowlist about the RAW WIRE FIELDS, not about the normalized event, and that ordering is\n// deliberate: L0 has to hold on a tree too broken to trust anything above it, including the adapters.\n// The raw fields are the same key names in both harnesses (measured), so one reading serves both, and\n// the answer cannot change because a normalizer changed. `event` is here only to decorate the deny.\n// webpieces-disable no-function-outside-class -- sibling of handleBash()/handleFileTool() in this module; the adapter is module-scope functions by design\nfunction enforceCommittedShim(payload: AgentPayload, event: AgentHookEvent, cwd: string, mode: HookMode): void {\n // ONE root for the whole decision, resolved from the RUNNING MODULE (governingShimRoot), never from\n // `cwd`: the shim file we compare and the renderShim() we compare it TO must come from the same\n // install, or the check straddles two trees and can never converge (see governingShimRoot's header).\n // `cwd` still selects where the L0 matrix doc is dropped — that is a \"where does the AI read\" question,\n // not part of the judgement.\n const shimRoot = governingShimRoot();\n if (mode === 'rules') return;\n // WHICH of the managed things moved — ai-hook.sh, either harness's hook registration\n // (.claude/settings.json, .codex/hooks.json), or the Claude settings' managed env entry (the\n // Bash-cwd pin that keeps a guard's verdict independent of where an earlier `cd` left the shell;\n // see managed-env.ts). Nothing validated the registration before it joined this\n // fault, so a settings file left on a superseded form silently changed WHO GOVERNS, with no signal\n // anywhere — which is the whole reason the registration is a drift surface and not just an install\n // step.\n const drifted = managedSurfaceDrift(shimRoot);\n if (drifted.length === 0) return;\n // The harness comes from the RAW envelope too — `detectAiType` asks one question of one key, so it\n // is as trustworthy here as the wire fields beside it, and it is the PRECISE test the shim's sh half\n // can only approximate. Reading it off the normalized event instead would put a normalizer between\n // L0 and its decision, which is the coupling the paragraph above exists to refuse.\n const decision = shimStaleRecoveryDecision(\n payload.tool_name, payload.tool_input.command ?? '', payload.tool_input.file_path ?? '',\n detectAiType(payload));\n if (decision === 'pass') return;\n if (decision === 'allow-cure') emitAllow();\n // Drop the L0 matrix doc where the AI can read it and point the deny at it — a Read is entry 1 of\n // the same allowlist, so the pointer is always followable. Best-effort: no doc → no pointer.\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n const docPath = writeGuardMatrixDoc(root);\n // WRITE THE AUDIT LINE HERE. This block happens BEFORE invocationLog.begin() — it has to, since a\n // stale shim invalidates everything downstream — so emitDeny's flush finds nothing pending and an\n // `S` storm left NO trace at all: the one fault most likely to block twenty consecutive tool calls\n // was the one fault the trail could not show. A decision line is the fix that costs no reordering.\n const target = payload.tool_input.command ?? payload.tool_input.file_path ?? '';\n logGuardDecision(\n root,\n new GuardDecision('committed-shim-stale', payload.tool_name, target, branchForLog(root), 'BLOCK_AI_CURE', 'L0 fault S (committed shim != renderShim)', '-', L0_FAULT_SHIM_STALE, MATRIX_L0_BLOCK),\n );\n // L0 fault S in GUARD_MATRIX.md's codebook — named as the blocking rule so the invocation line\n // says WHAT stopped the call, not merely that something did, and stamped as `fault=S` so the same\n // grep finds it here as in the sh half's `L0-shim/` stream.\n // A subagent is discriminated by `agent_id`, which BOTH harnesses populate on stdin only off the\n // main loop (main falls back to the session id / leaves it empty). Its cure differs: the hooks\n // blocking it resolve through CLAUDE_PROJECT_DIR, which names the MAIN tree.\n const inSubagent = event.agentId !== '';\n emitDeny(event, shimStaleDenyReason(installedShimRulesVersion(), shimRoot ?? '', drifted, inSubagent) + guardMatrixPointer(docPath), 'committed-shim-stale', L0_FAULT_SHIM_STALE);\n}\n\n/**\n * THE PIPELINE, from raw stdin bytes to the decision — the whole of `parse -> adapter -> runner ->\n * emit`, as ONE function returning ONE value.\n *\n * `mode` selects which tool kinds to validate; payloads outside the mode's scope pass through\n * (emitAllow). A block is a PreToolUse `permissionDecision:\"deny\"` JSON on stdout with exit 0 — see\n * agent-response.ts. Fails CLOSED on any unexpected crash (returns a deny) so a broken hook never\n * silently lets an edit through, and the reason surfaces in the agent's UI instead of being hidden on\n * a stderr+exit-2 block.\n *\n * It reads NO stdin, writes NO stdout and calls NO exit: those three couplings are ports owned by\n * HookApp (see hook-ports.ts), which is what makes the composed pipeline drivable from a test. This\n * function is what `runMain` was; it is not a second spelling of it — `runMain` is deleted, and\n * `HookApp.run()` is the only entry point.\n */\n// webpieces-disable no-function-outside-class -- the module-scope hook body itself, sibling of handleBash()/handleFileTool(); the adapter is module-scope functions by design and must stay callable from a tree too broken to build a DI container\nexport function runPipeline(raw: string, mode: HookMode): HookOutcome {\n // Captured as soon as the ENVELOPE parses so the fail-closed catch below can tell denyJson which\n // kind of call it is denying — a crash on a Bash call still gets the visible red systemMessage, a\n // crash on a file tool does not. Null (before parse / malformed input) → treated as non-Bash.\n let event: AgentHookEvent | null = null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const payload = new AgentPayloadParser().parse(raw);\n if (!payload) { emitAllow(); }\n // The envelope shape first: it reads only `tool_name` and the identity fields, so it cannot\n // fail, and it is what the crash path needs. The full normalization below reads `tool_input`\n // and CAN fail (a malformed Codex patch envelope denies rather than being half-understood).\n event = ADAPTERS.envelope(payload);\n\n // BEFORE enforceCommittedShim(), which can itself write a BLOCK line. See LogStream for why\n // all three of session/agent/hook are needed to keep concurrent writers off one file.\n logStream.identify(new StreamIdentity(event.sessionId, event.agentId, mode));\n // Same moment, same reason: every JS-side stream stamps `ai=`, and the fault-S line written\n // inside enforceCommittedShim() is one of them. See AiTypeContext for why the harness is a\n // process-wide holder rather than a parameter on four writers.\n aiTypeContext.identify(event.aiType);\n\n // Prefer the payload cwd (the AI's actual working dir, follows a persisted `cd`) over\n // process.cwd(); they match today, but the payload is the authoritative signal and stays\n // correct if the hook is ever invoked from a fixed dir (e.g. via $CLAUDE_PROJECT_DIR).\n const cwd = payload.cwd ?? process.cwd();\n\n // Committed-shim self-guard: blocks real work while the committed shim is stale, but keeps the\n // recovery path open (cures, reads, config edit). See enforceCommittedShim / shimStaleRecoveryDecision.\n enforceCommittedShim(payload, event, cwd, mode);\n\n event = ADAPTERS.toEvent(payload, cwd);\n\n // Read-only tools: their own fast path, which never returns when it applies.\n handleReadFastPath(event, cwd, mode);\n\n // Per-invocation guard log (the `calls/` stream): tool + command/file + live branch +\n // main-sync-status snapshot, on EVERY guards call, for later cleanup automation. Best-effort;\n // never blocks the call. (The committed shim is no longer silently healed here — a mismatch is\n // reported by the self-guard above, not rewritten out from under the AI.)\n if (mode !== 'rules') {\n invocationLog.begin(cwd, event.rawToolName, logTarget(event));\n }\n\n if (event.kind === 'Bash') {\n // No code-style rule is bash-scoped, so the rules hook ignores Bash.\n if (mode === 'rules') { emitAllow(); }\n handleBash(event, cwd, mode);\n }\n\n // File payloads run in 'rules' (code-style), 'guards' (file-scoped guards like\n // feature-branch-guard), and 'all'. The runner filters to the right category.\n handleFileTool(event, cwd, mode);\n } catch (err: unknown) {\n const error = toError(err);\n // The pipeline's own terminal control flow, not a failure: emitAllow/emitDeny threw the answer\n // out to here from wherever they were called. Treating it as a crash would turn every allow\n // into a deny, so this branch comes FIRST and returns the carried outcome verbatim.\n if (error instanceof HookTerminated) return error.outcome;\n return denyForCrash(error, event);\n }\n}\n\n// What the `calls/` audit line names as the call's target: the command for a shell call, else the first\n// file it touches. A Codex `apply_patch` touching several files names the first — the rejection log and\n// the decision log carry the rest, per file.\n// webpieces-disable no-function-outside-class -- sibling of the module-scope hook entry points in this adapter\nfunction logTarget(event: AgentHookEvent): string {\n if (event.kind === 'Bash') return event.bash === null ? '' : event.bash.command;\n return event.files.length > 0 ? event.files[0].input.filePath : '';\n}\n\n/**\n * The fail-closed boundary for anything that escaped the hook body. An escaped RuleFailError (a rule\n * that threw past the runner's per-rule catch) or an InformAiError (bad config/stdin, or a Codex patch\n * envelope this parser refuses to guess at) both carry an AI-readable message; anything else is an\n * unexpected bug. All three DENY and surface their reason, because a hook that crashed established\n * nothing and must never be read as an allow.\n *\n * It BUILDS the deny (denyOutcome) rather than throwing it (emitDeny), because it is already inside\n * the catch that the throw would land in — see HookTerminated. Same bytes either way.\n */\n// webpieces-disable no-function-outside-class -- sibling of the module-scope hook entry points in this adapter; a lone class for one terminal boundary would break the file's shape\nfunction denyForCrash(error: Error, event: AgentHookEvent | null): HookOutcome {\n if (error instanceof RuleFailError) {\n return denyOutcome(event, renderRuleFailForAi(error), 'rule-crash');\n }\n if (error instanceof InformAiError) {\n return denyOutcome(event, error.message, 'bad-config-or-stdin');\n }\n return denyOutcome(event, `[ai-hooks] hook crashed unexpectedly — failing closed: ${error.message}`, 'hook-crash');\n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AI,EAAE,CAAC,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,0BAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,KAAK,YAAY,4BAAa,CAAC,CAAC,CAAC,IAAA,kCAAmB,EAAC,KAAK,CAAC;YACtE,CAAC,CAAC,KAAK,YAAY,8BAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO;gBAChD,CAAC,CAAC,0DAA0D,KAAK,CAAC,OAAO,EAAE,CAAC;QAChF,OAAO,IAAI,0BAAW,CAAC,IAAA,uBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC","sourcesContent":["import { AgentPayloadParser, AgentAdapters, AgentHookEvent, HookMode, HookOutcome, denyJson } from '@webpieces/hook-runtime';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RuleFailError, renderRuleFailForAi } from '@webpieces/rules-config';\nimport { run } from '../core/runner';\n\n// webpieces-disable no-function-outside-class -- callable source pipeline consumed by the injected HookApp evaluator\nexport function runPipeline(raw: string, mode: HookMode): HookOutcome {\n let event: AgentHookEvent | null = null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const payload = new AgentPayloadParser().parse(raw);\n if (!payload) return new HookOutcome('', 0);\n const adapters = new AgentAdapters();\n event = adapters.envelope(payload);\n const cwd = payload.cwd ?? process.cwd();\n event = adapters.toEvent(payload, cwd);\n if (mode === 'guards' || event.kind === 'Bash' || event.kind === 'Read') return new HookOutcome('', 0);\n for (const file of event.files) {\n const result = run(file.toolKind, file.input, cwd, 'rules');\n if (result) return new HookOutcome(denyJson(event, result.report) + '\\n', 0);\n }\n return new HookOutcome('', 0);\n } catch (err: unknown) {\n const error = toError(err);\n const reason = error instanceof RuleFailError ? renderRuleFailForAi(error)\n : error instanceof InformAiError ? error.message\n : `[ai-hooks] hook crashed unexpectedly — failing closed: ${error.message}`;\n return new HookOutcome(denyJson(event, reason) + '\\n', 0);\n }\n}\n"]}
|
package/src/core/load-rules.d.ts
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
1
|
import { WebpiecesRulesConfig, MatchRuleConfig } from '@webpieces/rules-config';
|
|
2
|
-
import type { Rule } from '
|
|
3
|
-
|
|
4
|
-
export declare class GuardHintCommands {
|
|
5
|
-
readonly upsertPr: string;
|
|
6
|
-
readonly mergeComplete: string;
|
|
7
|
-
constructor(upsertPr: string, mergeComplete: string);
|
|
8
|
-
}
|
|
9
|
-
export declare function loadRules(config: WebpiecesRulesConfig, workspaceRoot: string, guardHints: GuardHintCommands): readonly Rule[];
|
|
10
|
-
/**
|
|
11
|
-
* The KEYLESS bash guards: rules that have NO webpieces.config.json entry, and are therefore
|
|
12
|
-
* deliberately kept out of `builtInConfigKeys`/`BUILT_IN_RULE_MAP` — so the config-sync check (fault Y,
|
|
13
|
-
* "every built-in rule needs an entry, or every Bash call is blocked") can never see them. That
|
|
14
|
-
* containment is the whole point: whole-repo-build-guard shipped inside the config-driven set once and
|
|
15
|
-
* took every upgrading consumer's shell down with it.
|
|
16
|
-
*
|
|
17
|
-
* Each rule here decides for ITSELF whether it acts, and the two do it differently on purpose:
|
|
18
|
-
*
|
|
19
|
-
* - `whole-repo-build-guard` is EXPERIMENTAL and inert unless the optional machine-local
|
|
20
|
-
* `~/.webpieces/config.json` opts IN with `experimental.whole-repo-build-guard: true`. Every
|
|
21
|
-
* experimental flag defaults OFF, and it takes no file and no key to be in that default state —
|
|
22
|
-
* which is the difference between this and the required-key release that blocked every upgrading
|
|
23
|
-
* consumer's shell.
|
|
24
|
-
* - `commit-message-substitution-guard` acts unconditionally. Nobody legitimately wants a backtick
|
|
25
|
-
* expanded inside a commit message, and its cure (`git commit -F <file>`) is available for every
|
|
26
|
-
* input and can never itself match the guard — so there is nothing for a switch to rescue.
|
|
27
|
-
* - `build-output-pipe-guard` acts unconditionally, on the same test. Piping `wp-build` /
|
|
28
|
-
* `wp-review-upsert-pr` / `wp-finish-upsert-pr` withholds their heartbeat until they exit and gets
|
|
29
|
-
* the build killed by the 600s watchdog; the cure is the SAME command with less typing, available
|
|
30
|
-
* for every input, and it cannot itself match the guard.
|
|
31
|
-
* - `wait-spin-guard` acts unconditionally, on the same test again. An `echo .` keep-alive spends a
|
|
32
|
-
* whole turn (~557k tokens) to do nothing, and its cure — `pnpm wp-await-reviews` /
|
|
33
|
-
* `pnpm wp-await-checks` for a worktree subagent, a Monitor or the backgrounded command itself for a
|
|
34
|
-
* main agent — is available for every input and can never itself match the guard.
|
|
35
|
-
*
|
|
36
|
-
* `affectedBuildCommand` is the project's gate command, passed through so a refusal quotes what THIS
|
|
37
|
-
* repo's gate actually runs.
|
|
38
|
-
*/
|
|
39
|
-
export declare function loadKeylessBashRules(affectedBuildCommand: string): Rule[];
|
|
2
|
+
import type { Rule } from '@webpieces/hook-runtime';
|
|
3
|
+
export declare function loadRules(config: WebpiecesRulesConfig, workspaceRoot: string): readonly Rule[];
|
|
40
4
|
export declare function loadMatchRules(matchRules: readonly MatchRuleConfig[]): Rule[];
|
|
41
|
-
export declare function
|
|
5
|
+
export declare function loadBuiltInRules(config: WebpiecesRulesConfig): Rule[];
|
|
6
|
+
export declare function loadCustomRules(config: WebpiecesRulesConfig, workspaceRoot: string): Rule[];
|