@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
package/templates/ai-hook.sh
DELETED
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# Managed by @webpieces/ai-hook-rules (wp-install-ai-hooks) — do not edit. This file is GENERATED from
|
|
3
|
-
# renderShim() and is intentionally VERSION-AGNOSTIC and byte-STABLE across releases: it carries no
|
|
4
|
-
# version stamp, so it only changes when its own logic changes. The installed guards binary is what
|
|
5
|
-
# checks that this committed copy still matches renderShim() (the committed-shim self-guard); if you
|
|
6
|
-
# revert or hand-edit this file the binary fails closed and names the cure. Checked in on purpose so
|
|
7
|
-
# the hook has a stable entry point even when node_modules is absent. Safe to delete along with the
|
|
8
|
-
# matching .claude/settings.json entries if you remove @webpieces/ai-hook-rules.
|
|
9
|
-
#
|
|
10
|
-
# Usage (wired into .claude/settings.json, ABSOLUTE so the MAIN tree governs every tree):
|
|
11
|
-
# sh "$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh" <bin-name>
|
|
12
|
-
BIN_NAME="$1"
|
|
13
|
-
shift
|
|
14
|
-
# Resolve the tree relative to THIS script (…/<root>/.claude/webpieces/ai-hook.sh → <root>), not the
|
|
15
|
-
# caller's cwd — the hook can be invoked from any directory (a subdir, or a nested clone).
|
|
16
|
-
ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)"
|
|
17
|
-
# The JSON escapes every deny message below is assembled from (ANSI red, and the newlines that give the
|
|
18
|
-
# deny the same scannable shape formatReport() gives every L1/L2 deny). See ESCAPES_SH's header.
|
|
19
|
-
BS='\' # one literal backslash, so no \u001b / \n escape sits in this source
|
|
20
|
-
ESC="${BS}u001b" # the 6 chars: backslash u 0 0 1 b — Claude Code parses \u001b → ESC
|
|
21
|
-
NL="${BS}n" # the 2 chars: backslash n — parsed as a real newline inside the JSON string
|
|
22
|
-
WP_STILL_ALLOWED="Still allowed while this block is up:${NL} - any Read, and on CODEX (no Read tool): a bare read command - cat/head/tail/less/more/bat <file>, or sed -n '1,240p' package.json - with nothing piped, redirected or chained onto it${NL} - any Write/Edit whose target is webpieces.config.json, pnpm-workspace.yaml or package.json${NL} - every command on the L0 allowlist, including the Fix Options below${NL} THIS IS NOT A DEADLOCK - run one YOURSELF now; do not hand it back to the human."
|
|
23
|
-
# The BIN is resolved by walking UP from ROOT (as Node does), and BIN_ROOT records which tree supplied
|
|
24
|
-
# it — the version-drift guard below compares THIS tree's pin against THAT tree's installed version.
|
|
25
|
-
BIN_ROOT="$ROOT"
|
|
26
|
-
BIN="$ROOT/node_modules/.bin/$BIN_NAME"
|
|
27
|
-
WP_WALK="$ROOT"
|
|
28
|
-
while [ ! -x "$WP_WALK/node_modules/.bin/$BIN_NAME" ]; do
|
|
29
|
-
WP_UP="$(dirname -- "$WP_WALK")"
|
|
30
|
-
[ "$WP_UP" != "$WP_WALK" ] || break
|
|
31
|
-
WP_WALK="$WP_UP"
|
|
32
|
-
done
|
|
33
|
-
if [ -x "$WP_WALK/node_modules/.bin/$BIN_NAME" ]; then
|
|
34
|
-
BIN_ROOT="$WP_WALK"
|
|
35
|
-
BIN="$WP_WALK/node_modules/.bin/$BIN_NAME"
|
|
36
|
-
fi
|
|
37
|
-
# --- webpieces version-drift guard (pure sh — runs even when the installed guard bin is stale) -----
|
|
38
|
-
# The committed shim is version-agnostic, so it keeps working right after a git pull, BEFORE the
|
|
39
|
-
# matching pnpm install. That is exactly when node_modules can be STALE: an OLDER @webpieces than
|
|
40
|
-
# package.json now pins, whose outdated validator rejects the NEWER webpieces.config.json with baffling
|
|
41
|
-
# "unknown rule" errors. Detect that drift HERE (before exec'ing the possibly-stale bin): compare every
|
|
42
|
-
# EXACT-pinned @webpieces/* version in the root package.json against the version actually installed in
|
|
43
|
-
# node_modules; the first mismatch wins. Range specs (^ ~ workspace:*) are skipped, so they never
|
|
44
|
-
# false-positive; best-effort — a version we cannot read is skipped. On drift we fall through to the
|
|
45
|
-
# SAME fail-closed path as a missing bin (allow only pnpm install, deny the rest).
|
|
46
|
-
#
|
|
47
|
-
# pnpm CATALOGS: a dep pinned via "catalog:" / "catalog:<name>" carries NO digit-version in package.json,
|
|
48
|
-
# so the old scraper matched nothing and the guard was BLIND to it — DRIFT_PKG stayed empty and the
|
|
49
|
-
# stale bin ran (the 2026-07 "0.3.369 vs 0.4.405" incident). Resolve those specs through the top-level
|
|
50
|
-
# `catalogs:` block of pnpm-lock.yaml (catalog -> pkg -> resolved version) before comparing.
|
|
51
|
-
#
|
|
52
|
-
# THE SAME PASS ANSWERS FAULT U (2026-08-05). Scraping root package.json is also the only way to learn
|
|
53
|
-
# whether @webpieces/ai-hook-rules is DECLARED at all, and that is the difference between "not installed
|
|
54
|
-
# yet" (X, cured by pnpm install) and "nothing asks for it" (U, where pnpm install is a guaranteed
|
|
55
|
-
# no-op). WP_PIN carries the first EXACT @webpieces pin found, so U's deny can prescribe the version the
|
|
56
|
-
# rest of the repo is already on rather than an unpinned add. Both are set BEFORE the range/catalog
|
|
57
|
-
# `continue`s, so a repo pinning the package by range still counts as having declared it.
|
|
58
|
-
DRIFT_PKG=""
|
|
59
|
-
DRIFT_DECLARED=""
|
|
60
|
-
DRIFT_INSTALLED=""
|
|
61
|
-
WP_HOOK_PKG_DECLARED=""
|
|
62
|
-
WP_PIN=""
|
|
63
|
-
if [ -f "$ROOT/package.json" ]; then
|
|
64
|
-
# Only when a @webpieces dep actually uses a "catalog:" spec do we scan the (possibly huge) lockfile —
|
|
65
|
-
# a cheap grep keeps the common, catalog-free repo from paying that cost on every tool call. One awk
|
|
66
|
-
# pass over pnpm-lock.yaml emits "<catalog> <@webpieces/pkg> <version>" lines for the sh lookup below;
|
|
67
|
-
# \047 is a single quote (so this awk program carries none and stays safely single-quotable in sh).
|
|
68
|
-
WP_CATALOGS=""
|
|
69
|
-
WP_WS_CATALOGS=""
|
|
70
|
-
# THE PIN LIVES IN pnpm-workspace.yaml, and the LOCK is only the fallback (2026-08-20).
|
|
71
|
-
#
|
|
72
|
-
# L0 used to learn the pin from pnpm-lock.yaml's `catalogs:` alone, while L1's WebpiecesVersions.readPin
|
|
73
|
-
# reads pnpm-workspace.yaml. Two notions of "the pin", and the gap is exactly where the cure lands: an
|
|
74
|
-
# agent told to raise this tree's pin edits pnpm-workspace.yaml, re-runs, and L0 still reports the OLD
|
|
75
|
-
# number — because only `pnpm install` rewrites the lock — so it concludes the edit did nothing and
|
|
76
|
-
# reaches for something worse. Reading the workspace manifest FIRST makes the edit visible immediately.
|
|
77
|
-
#
|
|
78
|
-
# It resolves the same two YAML shapes readPin does, and that is not optional: a repo pinning the whole
|
|
79
|
-
# @webpieces family in lockstep writes the version ONCE as `&wp 0.4.669` and aliases the rest as `*wp`,
|
|
80
|
-
# so an anchor-blind read silently nulls the leg on precisely the repos that pin most carefully. Both
|
|
81
|
-
# `catalog:` (the default catalog) and `catalogs:` (named ones) are walked. A value that is not a plain
|
|
82
|
-
# digit-version (a range) is NOT emitted, so a loose pinner falls through to the lock rather than being
|
|
83
|
-
# compared against an incomparable spec.
|
|
84
|
-
if grep -Eq '"@webpieces/[^"]*"[[:space:]]*:[[:space:]]*"catalog:' "$ROOT/package.json" 2>/dev/null && [ -f "$ROOT/pnpm-workspace.yaml" ]; then
|
|
85
|
-
WP_WS_CATALOGS="$(awk '
|
|
86
|
-
{ n=0; while (substr($0,n+1,1)==" ") n++; c=substr($0,n+1) }
|
|
87
|
-
c=="" || substr(c,1,1)=="#" { next }
|
|
88
|
-
{
|
|
89
|
-
ai=index(c,":")
|
|
90
|
-
if (ai>0) {
|
|
91
|
-
av=substr(c,ai+1); sub(/^[ \t]+/,"",av)
|
|
92
|
-
if (substr(av,1,1)=="&") {
|
|
93
|
-
an=substr(av,2); sub(/[ \t].*/,"",an)
|
|
94
|
-
sub(/^&[^ \t]+[ \t]*/,"",av)
|
|
95
|
-
sub(/[ \t]+#.*/,"",av); gsub(/["\047]/,"",av); sub(/[ \t].*/,"",av)
|
|
96
|
-
if (an!="" && av!="") anch[an]=av
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
n==0 { mode=(c ~ /^catalog: *$/)?1:((c ~ /^catalogs: *$/)?2:0); cat=(mode==1)?"default":""; next }
|
|
101
|
-
mode==0 { next }
|
|
102
|
-
mode==2 && c ~ /^[^:]+: *$/ { cat=c; sub(/: *$/,"",cat); gsub(/["\047 ]/,"",cat); next }
|
|
103
|
-
{
|
|
104
|
-
ki=index(c,":")
|
|
105
|
-
if (ki<=0) next
|
|
106
|
-
k=substr(c,1,ki-1); gsub(/["\047 ]/,"",k)
|
|
107
|
-
if (substr(k,1,11)!="@webpieces/") next
|
|
108
|
-
v=substr(c,ki+1); sub(/^[ \t]+/,"",v); sub(/^&[^ \t]+[ \t]*/,"",v)
|
|
109
|
-
sub(/[ \t]+#.*/,"",v); gsub(/["\047]/,"",v); sub(/[ \t].*/,"",v)
|
|
110
|
-
if (v=="") next
|
|
111
|
-
nn++; key[nn]=cat " " k; ali[nn]=(substr(v,1,1)=="*")?substr(v,2):""; val[nn]=v
|
|
112
|
-
}
|
|
113
|
-
END { for (i=1;i<=nn;i++) { vv=(ali[i]=="")?val[i]:anch[ali[i]]; if (vv ~ /^[0-9]/) print key[i] " " vv } }
|
|
114
|
-
' "$ROOT/pnpm-workspace.yaml" 2>/dev/null)"
|
|
115
|
-
fi
|
|
116
|
-
if grep -Eq '"@webpieces/[^"]*"[[:space:]]*:[[:space:]]*"catalog:' "$ROOT/package.json" 2>/dev/null && [ -f "$ROOT/pnpm-lock.yaml" ]; then
|
|
117
|
-
WP_CATALOGS="$(awk '
|
|
118
|
-
{ n=0; while (substr($0,n+1,1)==" ") n++; c=substr($0,n+1) }
|
|
119
|
-
c=="" { next }
|
|
120
|
-
n==0 { incat=(c ~ /^catalogs: *$/)?1:0; cat=""; pkg=""; next }
|
|
121
|
-
incat==0 { next }
|
|
122
|
-
n==2 { cat=c; sub(/:.*/,"",cat); pkg=""; next }
|
|
123
|
-
n==4 { pkg=c; sub(/: *$/,"",pkg); gsub(/["\047]/,"",pkg); next }
|
|
124
|
-
n==6 && substr(pkg,1,11)=="@webpieces/" && c ~ /^version:/ {
|
|
125
|
-
v=c; sub(/^version: */,"",v); gsub(/["\047 ]/,"",v);
|
|
126
|
-
if (cat!="" && v!="") print cat " " pkg " " v
|
|
127
|
-
}
|
|
128
|
-
' "$ROOT/pnpm-lock.yaml" 2>/dev/null)"
|
|
129
|
-
fi
|
|
130
|
-
while IFS=' ' read -r WP_NAME WP_DECL; do
|
|
131
|
-
[ -n "$WP_NAME" ] || continue
|
|
132
|
-
# Fault U's input: the package is DECLARED (in any spec shape, in any dependency block of the root
|
|
133
|
-
# manifest). Recorded before every `continue` below, so a range or catalog spec still counts.
|
|
134
|
-
[ "$WP_NAME" = "ai-hook-rules" ] && WP_HOOK_PKG_DECLARED=1
|
|
135
|
-
# Resolve the declared spec to an EXACT version, or skip it: ranges (^ ~ workspace:*) never drift,
|
|
136
|
-
# and a catalog spec we cannot resolve is best-effort skipped rather than guessed.
|
|
137
|
-
case "$WP_DECL" in
|
|
138
|
-
catalog:*)
|
|
139
|
-
WP_CAT="${WP_DECL#catalog:}"; [ -n "$WP_CAT" ] || WP_CAT="default"
|
|
140
|
-
WP_DECL="$(printf '%s\n' "$WP_WS_CATALOGS" | awk -v c="$WP_CAT" -v p="@webpieces/$WP_NAME" '$1==c && $2==p {print $3; exit}')"
|
|
141
|
-
[ -n "$WP_DECL" ] || WP_DECL="$(printf '%s\n' "$WP_CATALOGS" | awk -v c="$WP_CAT" -v p="@webpieces/$WP_NAME" '$1==c && $2==p {print $3; exit}')"
|
|
142
|
-
[ -n "$WP_DECL" ] || continue ;;
|
|
143
|
-
[0-9]*) : ;;
|
|
144
|
-
*) continue ;;
|
|
145
|
-
esac
|
|
146
|
-
# The release the rest of this repo is on — what fault U's cure should pin to.
|
|
147
|
-
[ -n "$WP_PIN" ] || WP_PIN="$WP_DECL"
|
|
148
|
-
WP_MANIFEST="$BIN_ROOT/node_modules/@webpieces/$WP_NAME/package.json"
|
|
149
|
-
[ -f "$WP_MANIFEST" ] || continue
|
|
150
|
-
WP_INST="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$WP_MANIFEST" | head -n1)"
|
|
151
|
-
[ -n "$WP_INST" ] || continue
|
|
152
|
-
if [ "$WP_DECL" != "$WP_INST" ]; then
|
|
153
|
-
DRIFT_PKG="@webpieces/$WP_NAME"
|
|
154
|
-
DRIFT_DECLARED="$WP_DECL"
|
|
155
|
-
DRIFT_INSTALLED="$WP_INST"
|
|
156
|
-
break
|
|
157
|
-
fi
|
|
158
|
-
done <<WPEOF
|
|
159
|
-
$(sed -n 's/.*"@webpieces\/\([A-Za-z0-9._-]*\)"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1 \2/p' "$ROOT/package.json")
|
|
160
|
-
WPEOF
|
|
161
|
-
fi
|
|
162
|
-
# A BORROWED BIN IS NOT SINGLE-TREE DRIFT, SO L0 MUST NOT ANSWER IT (2026-08-20).
|
|
163
|
-
#
|
|
164
|
-
# RESOLVE_BIN_SH walks UP for the bin, so in a linked worktree with no node_modules of its own BIN_ROOT
|
|
165
|
-
# is the MAIN tree. The scan above then compares $ROOT's DECLARED pin against $BIN_ROOT's INSTALLED
|
|
166
|
-
# version — a CROSS-TREE comparison it was reporting as fault D, single-tree drift. Everything
|
|
167
|
-
# downstream of that mislabel was wrong:
|
|
168
|
-
# • the cure. 'pnpm install' cannot "align node_modules" in a tree that has none; it MANUFACTURES one,
|
|
169
|
-
# at this tree's stale pin. That is precisely the state L1 row 8 (trinary-version-skew) blocks, so
|
|
170
|
-
# the L0 cure created the next block. One measured agent was walked from a pin disagreement, through
|
|
171
|
-
# 'pnpm install' offered as "(preferred) ... usually right", to a DOWNGRADED engine and a total block.
|
|
172
|
-
# • the analysis. Row 8 already reads all FOUR versions (both trees' pins and both installs), already
|
|
173
|
-
# knows which direction to move, already detects a deliberate pin bump, and already carries the
|
|
174
|
-
# escalate-and-STOP protocol. It could never run: ai-hook.sh hard-exits on any sh-side fault, so D
|
|
175
|
-
# PREEMPTED the guard that had the right answer.
|
|
176
|
-
# So: when the bin came from another tree, raise NO fault here and let the binary run. D stays exactly as
|
|
177
|
-
# it was when ROOT == BIN_ROOT — that IS single-tree drift, and row 8 cannot see it (VersionSyncGuard
|
|
178
|
-
# only applies to a linked worktree compared against a DIFFERENT main tree). Coverage does not gap: if
|
|
179
|
-
# the two pins agree but the two installs differ, row 8's quartet still has two distinct members and it
|
|
180
|
-
# still fires. X / U / K are untouched — a MISSING or CRASHED bin is about the bin, not about a version.
|
|
181
|
-
if [ "$BIN_ROOT" != "$ROOT" ]; then
|
|
182
|
-
DRIFT_PKG=""
|
|
183
|
-
DRIFT_DECLARED=""
|
|
184
|
-
DRIFT_INSTALLED=""
|
|
185
|
-
fi
|
|
186
|
-
# Read the tool payload ONCE, up front. The shim no longer exec's the bin (see RUN_BIN_SH), so it must
|
|
187
|
-
# forward stdin to the bin itself — and it needs the payload again on the fail-closed path below.
|
|
188
|
-
PAYLOAD="$(cat)"
|
|
189
|
-
CMD="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
190
|
-
CMD_LOG="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"\\]*\).*/\1/p')"
|
|
191
|
-
[ -n "$CMD_LOG" ] || CMD_LOG="$CMD"
|
|
192
|
-
TOOL="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"tool_name"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
193
|
-
WP_SID="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"session_id"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
194
|
-
WP_AID="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"agent_id"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
195
|
-
FILE="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
196
|
-
WP_CWD="$(printf '%s' "$PAYLOAD" | sed -n 's/.*"cwd"[[:space:]]*:[[:space:]]*"\([^"\\]*\)".*/\1/p')"
|
|
197
|
-
[ -n "$WP_CWD" ] || WP_CWD="$ROOT" # no cwd in the payload (older client, or a hand-run) → the shim's own tree
|
|
198
|
-
# WHICH HARNESS sent this call — the ONE discriminator, imported from ../adapters/detect-ai so the sh
|
|
199
|
-
# half of L0 and the JS half answer the identical question from one definition (the same twin pattern
|
|
200
|
-
# L0_ALLOW_ERE_SH / L0_ALLOW_JS uses). One `case`, no JSON parser: consistent with how every field
|
|
201
|
-
# above is `sed`-scraped, and the values are the AiType union's own strings so the twin-agreement spec
|
|
202
|
-
# compares them byte for byte instead of translating between two vocabularies.
|
|
203
|
-
WP_AI_ENV="$(printf '%s' "$PAYLOAD" | tr -d ' \t\n\r')"
|
|
204
|
-
case "$WP_AI_ENV" in *[{,]'"turn_id":'*) AI=codex ;; *) AI=claude-code ;; esac
|
|
205
|
-
# Best-effort AUDIT TRAIL of what L0 did with this call — every call, not just the broken ones. One
|
|
206
|
-
# tab-separated line per invocation into this TREE's own
|
|
207
|
-
# logs/L0-shim/<session>-<agent|coordinator>-<binName>.log (gitignored), so the
|
|
208
|
-
# observed behaviour can be diffed against the matrix in guards/L0-tooling.md. NEVER breaks or blocks the
|
|
209
|
-
# hook: every write is swallowed, and nothing ever goes to stdout (stdout is the PreToolUse decision
|
|
210
|
-
# channel — a stray byte there would corrupt allow/deny).
|
|
211
|
-
WP_TREE=""
|
|
212
|
-
WP_LOG_DIR=""
|
|
213
|
-
WP_PRIMARY_LOG_DIR=""
|
|
214
|
-
WP_TAB="$(printf '\t')" # one real tab, so the OPTIONAL bin= field can carry its own separator
|
|
215
|
-
wp_resolve_log_dir() {
|
|
216
|
-
_wp_rp="$(git -C "$WP_CWD" rev-parse --git-dir --git-common-dir 2>/dev/null)"
|
|
217
|
-
_wp_gd="$(printf '%s\n' "$_wp_rp" | sed -n 1p)"
|
|
218
|
-
_wp_cd="$(printf '%s\n' "$_wp_rp" | sed -n 2p)"
|
|
219
|
-
if [ -z "$_wp_gd" ] || [ -z "$_wp_cd" ]; then
|
|
220
|
-
WP_TREE=primary; WP_LOG_DIR="$WP_CWD/.webpieces/logs"
|
|
221
|
-
WP_PRIMARY_LOG_DIR="$WP_LOG_DIR"; return 0
|
|
222
|
-
fi
|
|
223
|
-
# git prints a BARE .git from the primary clone and an absolute path from a linked worktree; the TS
|
|
224
|
-
# twin runs path.resolve(cwd, printed), so do the same before comparing or taking a basename.
|
|
225
|
-
case "$_wp_gd" in /*) : ;; *) _wp_gd="$WP_CWD/$_wp_gd" ;; esac
|
|
226
|
-
case "$_wp_cd" in /*) : ;; *) _wp_cd="$WP_CWD/$_wp_cd" ;; esac
|
|
227
|
-
# The primary clone's root is the parent of the SHARED git dir — declining any layout whose shared
|
|
228
|
-
# dir is not named .git (a bare repo, --separate-git-dir), same test as primaryRoot().
|
|
229
|
-
_wp_primary="$WP_CWD"
|
|
230
|
-
case "$_wp_cd" in
|
|
231
|
-
*/.git) [ -d "${_wp_cd%/*}" ] && _wp_primary="${_wp_cd%/*}" ;;
|
|
232
|
-
esac
|
|
233
|
-
# The PRIMARY clone's log dir, resolved on both branches. A deny that has to tell a human WHERE the
|
|
234
|
-
# audit trail is (the inverse-drift escalation in shim.ts) must be able to name both the tree it is
|
|
235
|
-
# standing in and the primary — a subagent has no reach into the second one, so the deny has to quote
|
|
236
|
-
# that path rather than send anyone to go and look.
|
|
237
|
-
WP_PRIMARY_LOG_DIR="$_wp_primary/.webpieces/logs"
|
|
238
|
-
if [ "$_wp_gd" = "$_wp_cd" ]; then
|
|
239
|
-
WP_TREE=primary
|
|
240
|
-
WP_LOG_DIR="$WP_PRIMARY_LOG_DIR"
|
|
241
|
-
else
|
|
242
|
-
# git's OWN name for the worktree (the basename of <primary>/.git/worktrees/<name>), not the
|
|
243
|
-
# directory's basename — two worktrees under different parents may share a directory name.
|
|
244
|
-
WP_TREE="${_wp_gd##*/}"
|
|
245
|
-
WP_LOG_DIR="$_wp_primary/.webpieces/worktrees/$WP_TREE/logs"
|
|
246
|
-
fi
|
|
247
|
-
}
|
|
248
|
-
wp_clean() { # one path segment from an UNTRUSTED payload id — twin of LogStream's segment()
|
|
249
|
-
printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_' | sed -e 's/\.\{2,\}/_/g' -e 's/^\.\{1,\}/_/' | cut -c1-64
|
|
250
|
-
}
|
|
251
|
-
wp_log() { # $1 = L0 fault code (D|X|K|-), $2 = verdict label
|
|
252
|
-
{
|
|
253
|
-
[ -n "$WP_LOG_DIR" ] || wp_resolve_log_dir
|
|
254
|
-
# The LAYER is the directory and the WRITER is the file — same layout the TS writers use, spelled
|
|
255
|
-
# from the same constant so the two halves cannot drift apart.
|
|
256
|
-
_wp_sd="$WP_LOG_DIR/L0-shim"
|
|
257
|
-
mkdir -p "$_wp_sd" 2>/dev/null || return 0
|
|
258
|
-
# Same writer key as LogStream.writerFile(): <session>-<agent|coordinator>-<hook>.log. $BIN_NAME
|
|
259
|
-
# IS the hook discriminator here (wp-ai-guards-hook vs wp-ai-rules-hook), and Claude Code runs those
|
|
260
|
-
# two IN PARALLEL on every file edit — without this prefix they append to ONE file and tear above
|
|
261
|
-
# PIPE_BUF. An empty session id renders 'unknown' — this has no bare-name branch, matching
|
|
262
|
-
# LogStream.writerFile(), which has none either.
|
|
263
|
-
# ALWAYS prefixed - a missing session_id renders as 'unknown', never as the shared bare name.
|
|
264
|
-
# Gating this on a non-empty id would drop both parallel hooks back onto one file, which is the
|
|
265
|
-
# torn-append case this exists to remove. Twin of LogStream.writerFile(), which has no bare branch.
|
|
266
|
-
_wp_pfx="$(wp_clean "${WP_SID:-unknown}")-$(wp_clean "${WP_AID:-coordinator}")-$BIN_NAME"
|
|
267
|
-
_wp_f="$_wp_sd/${_wp_pfx}.log"
|
|
268
|
-
# Rotate at the SAME 512 KB into the SAME .1.log sibling as every JS-side webpieces log. This runs
|
|
269
|
-
# on every tool call, so it is one wc and no more; a size we cannot read counts as 0 (no rotation).
|
|
270
|
-
_wp_sz="$(wc -c < "$_wp_f" 2>/dev/null | tr -d ' ')"
|
|
271
|
-
case "$_wp_sz" in ''|*[!0-9]*) _wp_sz=0 ;; esac
|
|
272
|
-
[ "$_wp_sz" -gt 524288 ] && mv -f "$_wp_f" "$_wp_sd/${_wp_pfx}.1.log" 2>/dev/null
|
|
273
|
-
# shim= and bin= are the two facts this log could not previously answer, and they are the ones that
|
|
274
|
-
# decide whether a tree was governed by its OWN release or a borrowed one:
|
|
275
|
-
# shim= WHICH COPY OF ai-hook.sh RAN — $ROOT, resolved from $0. The file is TRACKED, so every
|
|
276
|
-
# worktree carries the version at ITS commit; settings.json registers it ABSOLUTE, so the copy
|
|
277
|
-
# that runs is the SESSION ROOT's. Logged rather than assumed, on EVERY line: compared against
|
|
278
|
-
# tree= it is the STRADDLE detector (tree=agent-X shim=<repo> = standing in one tree, judged by
|
|
279
|
-
# another), and that pair varies constantly.
|
|
280
|
-
# bin= WHICH TREE SUPPLIED THE BINARY — $BIN_ROOT, the upward walk's answer.
|
|
281
|
-
#
|
|
282
|
-
# bin= IS PRINTED ONLY WHEN IT DIFFERS FROM shim=, so its mere PRESENCE is the diagnostic ("the binary
|
|
283
|
-
# came from a different tree than the shim") instead of ~50 bytes repeated on every line. Measured
|
|
284
|
-
# across 549 logged lines: it differed on 39, every one a worktree agent's first few calls before it
|
|
285
|
-
# ran pnpm install — after that they matched for the rest of that agent's life. And since the hooks
|
|
286
|
-
# went ABSOLUTE, shim= is always the MAIN tree, so the two can now only differ when the main tree
|
|
287
|
-
# itself has no node_modules (a fresh clone before install). ~7% of lines then, near 0% going forward.
|
|
288
|
-
# A unit test asserts the field appears if and only if the roots differ, so it cannot quietly become
|
|
289
|
-
# unconditional noise again.
|
|
290
|
-
_wp_bin=""
|
|
291
|
-
[ "$BIN_ROOT" != "$ROOT" ] && _wp_bin="bin=$BIN_ROOT$WP_TAB"
|
|
292
|
-
# layer= and row= are the JOIN KEYS, and they are here so the join is REAL rather than promised.
|
|
293
|
-
# Every L0 deny now opens '[<guard>] (layer=L0 fault=<code> row=<n>)' and cites "the same coordinates
|
|
294
|
-
# the audit line carries" — which was true of the JS half (MATRIX_L0_BLOCK, via decision-log) and
|
|
295
|
-
# FALSE of this one, which carried 'fault=' alone. Fixing the message instead of the line would have
|
|
296
|
-
# left 'grep 'layer=L0 row=3'' finding one half of L0 and silently missing the other four faults.
|
|
297
|
-
#
|
|
298
|
-
# 'row=' is NOT a constant: it is the row of the three-row matrix this call actually took, read off
|
|
299
|
-
# the verdict — hand-down, allowlisted, or blocked — exactly as L1 logs 'row=' from L1_ROWS. That is
|
|
300
|
-
# what distinguishes it from the ~50 constant bytes 'bin=' used to spend above.
|
|
301
|
-
_wp_row=1
|
|
302
|
-
case "$2" in ALLOW*) _wp_row=2 ;; DENY*) _wp_row=3 ;; esac
|
|
303
|
-
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%s\t%s\t%s\n' "$(date '+%Y-%m-%dT%H:%M:%S%z' 2>/dev/null)" "$BIN_NAME" "$TOOL" "ai=$AI" "tree=$WP_TREE" "layer=L0" "row=$_wp_row" "shim=$ROOT" "$_wp_bin" "fault=$1" "$2" "$CMD_LOG" >> "$_wp_f"
|
|
304
|
-
} 2>/dev/null || true
|
|
305
|
-
}
|
|
306
|
-
BROKEN_BIN=""
|
|
307
|
-
CRASH_MSG=""
|
|
308
|
-
if [ -x "$BIN" ] && [ -z "$DRIFT_PKG" ]; then
|
|
309
|
-
OUT_FILE="${TMPDIR:-/tmp}/wp-ai-hook-out.$$"
|
|
310
|
-
ERR_FILE="${TMPDIR:-/tmp}/wp-ai-hook-err.$$"
|
|
311
|
-
printf '%s' "$PAYLOAD" | "$BIN" "$@" >"$OUT_FILE" 2>"$ERR_FILE"
|
|
312
|
-
RC=$?
|
|
313
|
-
if [ "$RC" = 0 ] || [ "$RC" = 2 ]; then
|
|
314
|
-
cat "$OUT_FILE" # the guard's real decision — verbatim
|
|
315
|
-
cat "$ERR_FILE" >&2
|
|
316
|
-
rm -f "$OUT_FILE" "$ERR_FILE" 2>/dev/null
|
|
317
|
-
# THE HEALTHY CALL, which this log used to be silent about (see WP_LOG_SH's header). No sh-side
|
|
318
|
-
# fault, the bin ran, and its own exit code says how it ended — 0 allow, 2 block. Logged AFTER the
|
|
319
|
-
# decision bytes are already on stdout, so the audit trail never sits between the guard and Claude
|
|
320
|
-
# Code. Without this line, "no entry" meant either healthy or never-ran, and those are the two
|
|
321
|
-
# answers a reader most needs to tell apart.
|
|
322
|
-
WP_VERDICT=PASS-BIN-ALLOW
|
|
323
|
-
[ "$RC" = 2 ] && WP_VERDICT=PASS-BIN-BLOCK
|
|
324
|
-
wp_log - "$WP_VERDICT"
|
|
325
|
-
exit "$RC"
|
|
326
|
-
fi
|
|
327
|
-
# Crashed. Keep the most useful stderr line for the human. Strip " and backslash so the text stays a
|
|
328
|
-
# valid JSON string, and cap the length so a giant node stack cannot blow up the deny payload.
|
|
329
|
-
CRASH_MSG="$(grep -m1 'Cannot find module' "$ERR_FILE" 2>/dev/null | tr -d '"\\' | cut -c1-120)"
|
|
330
|
-
[ -n "$CRASH_MSG" ] || CRASH_MSG="$(head -n1 "$ERR_FILE" 2>/dev/null | tr -d '"\\' | cut -c1-120)"
|
|
331
|
-
[ -n "$CRASH_MSG" ] || CRASH_MSG="exit code $RC, no stderr"
|
|
332
|
-
rm -f "$OUT_FILE" "$ERR_FILE" 2>/dev/null
|
|
333
|
-
BROKEN_BIN=1
|
|
334
|
-
fi
|
|
335
|
-
# Bin missing (fresh clone before install) OR a version drift (stale node_modules) OR the bin is
|
|
336
|
-
# installed but CRASHED (corrupt node_modules). The webpieces guards CANNOT safely run.
|
|
337
|
-
# Before failing closed, peek at the tool payload and let ONLY package-manager install/recovery commands
|
|
338
|
-
# through: the assistant's own Bash tool routes through this hook too, so blocking everything would
|
|
339
|
-
# deadlock the very commands (pnpm install / rm -rf node_modules && pnpm install) that re-enable the
|
|
340
|
-
# guards. A silent exit 0 = "allow" in the PreToolUse protocol; the guards resume once the tree is sane.
|
|
341
|
-
# WHICH of the guards/L0-tooling.md faults fired, in the doc's own letters. Only the four sh-side
|
|
342
|
-
# codes can be decided here; S/C/Y live in the binary, which never got to run on this path.
|
|
343
|
-
WP_FAULT=X # X — bin missing (fresh clone, new worktree)
|
|
344
|
-
[ -z "$WP_HOOK_PKG_DECLARED" ] && WP_FAULT=U # U — X, but nothing declares the package: install is a no-op
|
|
345
|
-
[ -n "$DRIFT_PKG" ] && WP_FAULT=D # D — version drift; D and K are mutually exclusive
|
|
346
|
-
[ -n "$BROKEN_BIN" ] && WP_FAULT=K # K — bin present but CRASHED (corrupt node_modules)
|
|
347
|
-
DENY_LABEL="DENY"
|
|
348
|
-
[ -z "$WP_HOOK_PKG_DECLARED" ] && DENY_LABEL="DENY-UNDECLARED" # nothing in package.json asks for the package
|
|
349
|
-
[ -n "$DRIFT_PKG" ] && DENY_LABEL="DENY-STALE" # version drift, not a missing bin
|
|
350
|
-
[ -n "$BROKEN_BIN" ] && DENY_LABEL="DENY-BROKEN" # bin present but CRASHED (corrupt node_modules)
|
|
351
|
-
# THE L0 ALLOWLIST, entry order identical to isAllowed(). No fault is consulted: a cure that cannot
|
|
352
|
-
# help a given fault also cannot hurt it, and gating each entry on a fault is what produced the four
|
|
353
|
-
# defects recorded above L0_ALLOW_ERE.
|
|
354
|
-
if [ "$TOOL" = "Read" ]; then
|
|
355
|
-
wp_log "$WP_FAULT" ALLOW-READ # you must be able to read to work out how to fix this
|
|
356
|
-
exit 0
|
|
357
|
-
fi
|
|
358
|
-
case "$TOOL" in
|
|
359
|
-
webrun|collaborationspawn_agent|collaborationwait_agent|view_image|update_plan)
|
|
360
|
-
# Nothing to judge — the Codex tools that are neither a shell command nor a file edit. sh twin of
|
|
361
|
-
# isAllowed()'s L0_IGNORED_TOOLS branch; see there for why the list is EXPLICIT and why apply_patch
|
|
362
|
-
# (Codex's only WRITE) is not on it.
|
|
363
|
-
wp_log "$WP_FAULT" ALLOW-IGNORED
|
|
364
|
-
exit 0 ;;
|
|
365
|
-
esac
|
|
366
|
-
case "$FILE" in
|
|
367
|
-
*/webpieces.config.json|webpieces.config.json)
|
|
368
|
-
wp_log "$WP_FAULT" ALLOW-CONFIG # the always-allowed recovery target — every guard is configured from it
|
|
369
|
-
exit 0 ;;
|
|
370
|
-
*/pnpm-workspace.yaml|pnpm-workspace.yaml|*/package.json|package.json)
|
|
371
|
-
# A manifest AT THE ROOT OF A GOVERNED TREE, which is the only place the version pin lives. The test
|
|
372
|
-
# is the sibling webpieces.config.json — TRACKED, so the main clone has one and every worktree has its
|
|
373
|
-
# own — and NOT $ROOT, which names whichever tree supplied this shim and would deny the other's.
|
|
374
|
-
# Basename alone would be far worse here than in the JS half: this arm is TERMINAL (exit 0, the bin
|
|
375
|
-
# never runs), so every packages/**/package.json would be editable with nothing judging it.
|
|
376
|
-
if [ -f "$(dirname -- "$FILE")/webpieces.config.json" ]; then
|
|
377
|
-
wp_log "$WP_FAULT" ALLOW-MANIFEST # raising the pin must be typable from inside the block
|
|
378
|
-
exit 0
|
|
379
|
-
fi ;;
|
|
380
|
-
esac
|
|
381
|
-
if printf '%s' "$CMD" | grep -Eq '^(cd[[:space:]]+([A-Za-z0-9._/@~+-]+|'\''[^'\'']+'\'')[[:space:]]*&&[[:space:]]*)?((pnpm|npm)[[:space:]]+(install|i)([[:space:]]+--[A-Za-z][A-Za-z0-9=._/@:-]*)*|rm[[:space:]]+-rf[[:space:]]+(\./)?node_modules/?([[:space:]]*&&[[:space:]]*(pnpm|npm)[[:space:]]+(install|i)([[:space:]]+--[A-Za-z][A-Za-z0-9=._/@:-]*)*)?|git[[:space:]]+fetch([[:space:]]+(--)?[A-Za-z0-9][A-Za-z0-9=._/@:-]*)*|git[[:space:]]+checkout[[:space:]]+main[[:space:]]*&&[[:space:]]*git[[:space:]]+pull[[:space:]]+origin[[:space:]]+main|(pnpm|npm|npx)([[:space:]]+(exec|run))?[[:space:]]+wp-upgrade-shim|cp[[:space:]]+(\./)?node_modules/@webpieces/ai-hook-rules/templates/ai-hook\.sh[[:space:]]+(\./)?\.claude/webpieces/ai-hook\.sh|(pnpm|npm|npx)([[:space:]]+(exec|run))?[[:space:]]+wp-prune-unknown-config|(pnpm|npm|npx)([[:space:]]+(exec|run))?[[:space:]]+wp-install-ai-hooks([[:space:]]+--[A-Za-z][A-Za-z0-9=._/@:-]*)*|(pnpm|npm)[[:space:]]+add([[:space:]]+(-[A-Za-z]|--[A-Za-z][A-Za-z0-9=._/@:-]*))*[[:space:]]+@webpieces/ai-hook-rules(@[A-Za-z0-9._+-]+)?([[:space:]]+(-[A-Za-z]|--[A-Za-z][A-Za-z0-9=._/@:-]*))*|(pwd|git[[:space:]]+(status|log|diff|show|branch|rev-parse)|git[[:space:]]+worktree[[:space:]]+list)([[:space:]]+(--)?[A-Za-z0-9][A-Za-z0-9=._/@:-]*)*)([[:space:]]+2>(&1|/dev/null))?([[:space:]]*\|[[:space:]]*(tail|head)([[:space:]]+-(n[[:space:]]+)?[0-9]+)?)?[[:space:]]*$'; then
|
|
382
|
-
wp_log "$WP_FAULT" ALLOW-CURE # record the self-heal we let through (re-enables the guards)
|
|
383
|
-
exit 0 # allow the cure so the assistant can break the deadlock
|
|
384
|
-
fi
|
|
385
|
-
# THE HARNESS-GATED TAIL OF THE SAME LIST, and the ONLY place $AI changes a decision. Under Claude Code
|
|
386
|
-
# the guard is false and the next line is the deny — byte for byte the path a Claude payload took before
|
|
387
|
-
# this branch existed. Under Codex it is the twin of the ALLOW-READ arm above: Codex has NO Read tool, so
|
|
388
|
-
# a read arrives as this Bash command, and without this every L0 fault denies a Codex session the very
|
|
389
|
-
# reads the deny is telling it to perform. The pattern is anchored on its own (no cd prefix, no capture
|
|
390
|
-
# tail) — see L0_CODEX_ALLOW_ERE. TERMINAL, exactly like the Read arm, and for the same reason: on this
|
|
391
|
-
# path the bin never runs, so there is nothing to fall through to.
|
|
392
|
-
if [ "$AI" = codex ] && printf '%s' "$CMD" | grep -Eq '^(((cat|head|tail|less|more|bat)([[:space:]]+((-[0-9]+|-{1,2}[A-Za-z][A-Za-z0-9=._-]*)|([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')))*[[:space:]]+([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')([[:space:]]+((-[0-9]+|-{1,2}[A-Za-z][A-Za-z0-9=._-]*)|([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')))*|sed[[:space:]]+-n[[:space:]]+([0-9]+(,[0-9]+)?p|'\''[0-9]+(,[0-9]+)?p'\'')([[:space:]]+((-[0-9]+|-{1,2}[A-Za-z][A-Za-z0-9=._-]*)|([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')))*[[:space:]]+([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')([[:space:]]+((-[0-9]+|-{1,2}[A-Za-z][A-Za-z0-9=._-]*)|([A-Za-z0-9._/@~+,:][A-Za-z0-9._/@~+,:-]*|'\''[^'\'']+'\'')))*))[[:space:]]*$'; then
|
|
393
|
-
wp_log "$WP_FAULT" ALLOW-CODEX-READ
|
|
394
|
-
exit 0
|
|
395
|
-
fi
|
|
396
|
-
wp_log "$WP_FAULT" "$DENY_LABEL" # every fail-closed block, with the fault that caused it
|
|
397
|
-
if [ -n "$BROKEN_BIN" ]; then
|
|
398
|
-
# Report (do NOT auto-clean) the orphaned pnpm staging dirs — a package pnpm was mid-way through
|
|
399
|
-
# writing is left behind as <name>_<pid>_<hash>. Their presence is the fingerprint of an install that
|
|
400
|
-
# was killed, which is what corrupts node_modules in the first place. Best-effort; never fatal.
|
|
401
|
-
STAGING_N="$(ls "$BIN_ROOT/node_modules" 2>/dev/null | grep -Ec '_[0-9a-f]+_[0-9a-f]+$' || true)"
|
|
402
|
-
STAGING_NOTE=""
|
|
403
|
-
if [ "${STAGING_N:-0}" -gt 0 ] 2>/dev/null; then
|
|
404
|
-
STAGING_NOTE="${NL} → also found $STAGING_N orphaned pnpm staging dirs (name_pid_hash) under node_modules - the fingerprint of an install that was killed mid-write." # only when N > 0
|
|
405
|
-
fi
|
|
406
|
-
# The HEADLINE, kept in its own variable so DENY_EMIT_SH can paint ONLY it red (see there).
|
|
407
|
-
WP_HEAD="❌ webpieces ai-hooks blocked this call: the webpieces guards are DOWN."
|
|
408
|
-
REASON="$WP_HEAD${NL}${NL}[guard-bin-crashed] (layer=L0 fault=K row=3, 1 violation)${NL} ${BIN_NAME} ($CRASH_MSG)${NL} → it is installed but CRASHED, so your node_modules is corrupt or partially written; the guards cannot run and they must not be silently skipped. Every OTHER tool call is BLOCKED until they can.${STAGING_NOTE}${NL} → matrix row 3: fault=K present / on the allowlist? no -> BLOCK. Those are the same coordinates the audit line carries (layer=L0 row=3 fault=K) and the same row webpieces.guard-matrix.md prints.${NL}${NL}${WP_STILL_ALLOWED}${NL}${NL} Fix Option 1: (preferred) the only cure. A bare 'pnpm install' will NOT fix this, because pnpm sees the correct version on disk and skips the broken package${NL} run EXACTLY: 'rm -rf node_modules && pnpm install'${NL}${NL}Run it EXACTLY as written - the allowlist matches the whole command, so appending anything (even && git status) makes it a different command and it is rejected; that is not the guard blocking its own cure. Only these may be added: a leading cd <dir> && (single-quote a path containing spaces), a trailing 2>&1, and | tail -N."
|
|
409
|
-
elif [ -n "$DRIFT_PKG" ]; then
|
|
410
|
-
# DECIDE THE DIRECTION, do not make the reader do it (2026-08-03). The detection is a plain !=, so it
|
|
411
|
-
# fires BOTH ways, and the message used to carry OPTION 1/2/3 covering every direction at once — 3343
|
|
412
|
-
# chars of which only about a third was the decision. A reader on the wrong branch of that menu was
|
|
413
|
-
# one misread away from a downgrade. So compare the two versions HERE and emit only the relevant half.
|
|
414
|
-
#
|
|
415
|
-
# WITH AWK, not `sort -V`: -V is a GNU extension (absent/different on BSD sort), while the shim
|
|
416
|
-
# already runs an awk pass to resolve catalog: specs, so awk adds no dependency. The program compares
|
|
417
|
-
# the numeric cores component-by-component; a pre-release/build suffix (-rc.1, +sha) is stripped from
|
|
418
|
-
# the core, and when the cores are EQUAL the side carrying a PRE-RELEASE suffix is the older one
|
|
419
|
-
# (semver precedence). Build metadata (+sha) carries NO precedence, so two versions differing only
|
|
420
|
-
# there come back undecidable rather than ordered. Anything it cannot parse prints NOTHING, and an
|
|
421
|
-
# empty answer falls through to the ambiguous wording below rather than guessing a direction.
|
|
422
|
-
#
|
|
423
|
-
# WHAT WAS DELETED, so it does not creep back: the "how to get main itself current" paragraph and the
|
|
424
|
-
# "do NOT reach for git merge --ff-only / reset --hard / checkout -B main" paragraph both belong to
|
|
425
|
-
# redirect-how-to-merge-main, which fires on its own with its own message; and the sentence that named
|
|
426
|
-
# wp-start-update / wp-start-upsert-pr ONLY to forbid them while the block is up — naming a command
|
|
427
|
-
# purely to forbid it is pure cost, and the install that clears this fault comes first regardless.
|
|
428
|
-
DRIFT_DIR="$(awk -v i="$DRIFT_INSTALLED" -v d="$DRIFT_DECLARED" 'BEGIN {
|
|
429
|
-
iv = i; sub(/\+.*/, "", iv); ic = iv; sub(/-.*/, "", ic); ip = substr(iv, length(ic) + 1)
|
|
430
|
-
dv = d; sub(/\+.*/, "", dv); dc = dv; sub(/-.*/, "", dc); dp = substr(dv, length(dc) + 1)
|
|
431
|
-
if (ic !~ /^[0-9]+(\.[0-9]+)*$/ || dc !~ /^[0-9]+(\.[0-9]+)*$/) exit
|
|
432
|
-
n = split(ic, ia, "."); m = split(dc, da, "."); k = (n > m) ? n : m
|
|
433
|
-
for (x = 1; x <= k; x++) {
|
|
434
|
-
av = (x <= n) ? ia[x] + 0 : 0; bv = (x <= m) ? da[x] + 0 : 0
|
|
435
|
-
if (av < bv) { print "older"; exit }
|
|
436
|
-
if (av > bv) { print "newer"; exit }
|
|
437
|
-
}
|
|
438
|
-
if (ip == dp) exit
|
|
439
|
-
if (ip != "" && dp == "") print "older"
|
|
440
|
-
if (ip == "" && dp != "") print "newer"
|
|
441
|
-
}' 2>/dev/null)"
|
|
442
|
-
if [ "$DRIFT_DIR" = older ]; then
|
|
443
|
-
# The HEADLINE, kept in its own variable so DENY_EMIT_SH can paint ONLY it red (see there).
|
|
444
|
-
WP_HEAD="❌ webpieces ai-hooks blocked this call: webpieces version drift."
|
|
445
|
-
REASON="$WP_HEAD${NL}${NL}[version-drift] (layer=L0 fault=D row=3, 1 violation)${NL} package.json pins $DRIFT_PKG@$DRIFT_DECLARED but node_modules has $DRIFT_INSTALLED${NL} → node_modules is OLDER, so the pin is what you want. Every OTHER tool call is BLOCKED until the two agree.${NL} → matrix row 3: fault=D present / on the allowlist? no -> BLOCK. Those are the same coordinates the audit line carries (layer=L0 row=3 fault=D) and the same row webpieces.guard-matrix.md prints.${NL}${NL}${WP_STILL_ALLOWED}${NL}${NL} Fix Option 1: (preferred) the only cure - it makes node_modules match the pin${NL} run EXACTLY: 'pnpm install'${NL}${NL}Run it EXACTLY as written - the allowlist matches the whole command, so appending anything (even && git status) makes it a different command and it is rejected; that is not the guard blocking its own cure. Only these may be added: a leading cd <dir> && (single-quote a path containing spaces), a trailing 2>&1, and | tail -N."
|
|
446
|
-
else
|
|
447
|
-
# NEWER, or undecidable — the same choices apply either way, so the only thing the ambiguous
|
|
448
|
-
# case changes is the claim about which side is stale.
|
|
449
|
-
DRIFT_NOTE="node_modules is NEWER, so the PIN is the stale side and a bare 'pnpm install' DOWNGRADES you to $DRIFT_DECLARED"
|
|
450
|
-
[ "$DRIFT_DIR" = newer ] || DRIFT_NOTE="these two versions could not be ordered automatically - compare them yourself: if node_modules is the NEWER side then the PIN is the stale side and a bare 'pnpm install' DOWNGRADES you to $DRIFT_DECLARED"
|
|
451
|
-
WP_BRANCH="$(git -C "$ROOT" branch --show-current 2>/dev/null)"
|
|
452
|
-
WP_PIN_EDIT="edit $ROOT/pnpm-workspace.yaml - the catalog line for $DRIFT_PKG, or that dependency in $ROOT/package.json if this repo pins directly - and set it to $DRIFT_INSTALLED, then run 'pnpm install'"
|
|
453
|
-
if [ -z "$WP_BRANCH" ]; then
|
|
454
|
-
WP_FIX=" Fix Option 1: (preferred) HEAD is DETACHED here, so a pin edit would belong to no branch - get onto main instead, whose pin is already at or ahead of what is installed, so the drift clears with no edit at all${NL} run EXACTLY: 'git checkout main && git pull origin main', then 'pnpm install'${NL} Fix Option 2: you mean to stay on this exact commit - the downgrade to $DRIFT_DECLARED is the point${NL} run EXACTLY: 'pnpm install'"
|
|
455
|
-
elif [ "$WP_BRANCH" = main ]; then
|
|
456
|
-
WP_FIX=" Fix Option 1: (preferred) go FORWARD - keep what is installed and raise the pin to match it${NL} ${WP_PIN_EDIT}${NL} That edit is ALLOWED while this block is up, and the install then only rewrites the lock - nothing is downgraded, because the pin now names what is already on disk.${NL} Fix Option 2: you are on main and want what origin pins instead${NL} run EXACTLY: 'git checkout main && git pull origin main', then 'pnpm install'"
|
|
457
|
-
else
|
|
458
|
-
WP_FIX=" Fix Option 1: (preferred) go FORWARD - keep what is installed and raise THIS branch's pin to match it${NL} ${WP_PIN_EDIT}${NL} That edit is ALLOWED while this block is up, and the install then only rewrites the lock - nothing is downgraded, because the pin now names what is already on disk.${NL} Fix Option 2: you mean to align node_modules to YOUR branch pin - that is a DOWNGRADE to $DRIFT_DECLARED, so pick it only if you meant to${NL} run EXACTLY: 'pnpm install'${NL} Do NOT reach for 'git pull origin main': pulling main into a feature branch destroys the fork point the build gate --base and the PR review diff are computed from, and the guards block it."
|
|
459
|
-
fi
|
|
460
|
-
# The HEADLINE, kept in its own variable so DENY_EMIT_SH can paint ONLY it red (see there).
|
|
461
|
-
WP_HEAD="❌ webpieces ai-hooks blocked this call: webpieces version drift."
|
|
462
|
-
REASON="$WP_HEAD${NL}${NL}[version-drift] (layer=L0 fault=D row=3, 1 violation)${NL} package.json pins $DRIFT_PKG@$DRIFT_DECLARED but node_modules has $DRIFT_INSTALLED${NL} → $DRIFT_NOTE. That may be exactly what you want. Every OTHER tool call is BLOCKED until the two agree.${NL} → matrix row 3: fault=D present / on the allowlist? no -> BLOCK. Those are the same coordinates the audit line carries (layer=L0 row=3 fault=D) and the same row webpieces.guard-matrix.md prints.${NL}${NL}${WP_STILL_ALLOWED}${NL}${NL}${WP_FIX}${NL}${NL}Run it EXACTLY as written - the allowlist matches the whole command, so appending anything (even && git status) makes it a different command and it is rejected; that is not the guard blocking its own cure. Only these may be added: a leading cd <dir> && (single-quote a path containing spaces), a trailing 2>&1, and | tail -N."
|
|
463
|
-
fi
|
|
464
|
-
else
|
|
465
|
-
# A LINKED WORKTREE is the overwhelmingly common way to land here with a perfectly healthy repo:
|
|
466
|
-
# git gives the new worktree a .git FILE (the primary clone has a .git directory) and copies no
|
|
467
|
-
# node_modules, so the very first tool call in a brand-new worktree fail-closes on a missing bin.
|
|
468
|
-
# Naming that explicitly turns a baffling "not installed" into a one-command fix, and the HERE is
|
|
469
|
-
# load-bearing: installing in the primary clone does nothing for this tree.
|
|
470
|
-
WORKTREE_NOTE=""
|
|
471
|
-
if [ -f "$ROOT/.git" ]; then
|
|
472
|
-
WORKTREE_NOTE="${NL} → $ROOT is a LINKED WORKTREE - git does not copy node_modules into a new worktree, so this is expected on a fresh one. Run the Fix Option HERE, in this worktree, not in the primary clone."
|
|
473
|
-
fi
|
|
474
|
-
if [ -z "$WP_HOOK_PKG_DECLARED" ]; then
|
|
475
|
-
# FAULT U — the one shape where the X message is not merely unhelpful but actively WRONG. It asserted
|
|
476
|
-
# "declared in package.json" without ever checking, and prescribed the one command that provably
|
|
477
|
-
# cannot help: with nothing asking for the package, `pnpm install` reports "Lockfile is up to date"
|
|
478
|
-
# and converges to the identical broken tree, forever. So say what is actually true, say out loud
|
|
479
|
-
# that the install is a no-op (an agent that has already run it needs to be told to STOP), and
|
|
480
|
-
# prescribe the add — which is allowlist entry ADD_HOOK_PKG, so it is reachable while this block is up.
|
|
481
|
-
WP_ADD_CMD="pnpm add -D @webpieces/ai-hook-rules"
|
|
482
|
-
[ -n "$WP_PIN" ] && WP_ADD_CMD="${WP_ADD_CMD}@$WP_PIN"
|
|
483
|
-
# The HEADLINE, kept in its own variable so DENY_EMIT_SH can paint ONLY it red (see there).
|
|
484
|
-
WP_HEAD="❌ webpieces ai-hooks blocked this call: the guard package is not declared anywhere."
|
|
485
|
-
REASON="$WP_HEAD${NL}${NL}[guard-pkg-undeclared] (layer=L0 fault=U row=3, 1 violation)${NL} @webpieces/ai-hook-rules is NOT declared in this tree's root package.json, and is not installed (${BIN_NAME} not found)${NL} → .claude/settings.json still runs its hooks, so every OTHER tool call is BLOCKED. A BARE 'pnpm install' is a NO-OP here: the root manifest asks for nothing, so it reports 'Lockfile is up to date' and converges to this same state. CHANGE something first - sync, or the pin - and install AFTER that.${NL} → matrix row 3: fault=U present / on the allowlist? no -> BLOCK. Those are the same coordinates the audit line carries (layer=L0 row=3 fault=U) and the same row webpieces.guard-matrix.md prints.${NL}${NL}${WP_STILL_ALLOWED}${NL}${NL} Fix Option 1: (preferred) @webpieces/ai-hook-rules normally arrives WITH @webpieces/nx-webpieces-rules, the umbrella that bundles the whole toolchain - so the usual cause is a tree that is behind, not a missing declaration. Sync, then install:${NL} run EXACTLY: 'git checkout main && git pull origin main'${NL} then run EXACTLY: 'pnpm install'${NL} Fix Option 2: still missing? the pinned release predates the umbrella carrying it. Raise the ONE catalog entry in pnpm-workspace.yaml to a newer @webpieces/nx-webpieces-rules - editing that file is allowed while this block is up - then:${NL} run EXACTLY: 'pnpm install'${NL} Fix Option 3: LAST RESORT, only to unblock yourself right now${NL} run EXACTLY: '$WP_ADD_CMD'${NL} then REVERT IT BEFORE YOU COMMIT: 'pnpm remove @webpieces/ai-hook-rules'. A direct root dependency on @webpieces/ai-hook-rules violates the umbrella rule - the root manifest depends on @webpieces/nx-webpieces-rules ALONE - so it must never reach a PR. It unblocks this session; it is not the fix.${NL} NOT an option: if you removed @webpieces/ai-hook-rules on purpose, delete its hooks from .claude/settings.json instead.${NL}${NL}Run it EXACTLY as written - the allowlist matches the whole command, so appending anything (even && git status) makes it a different command and it is rejected; that is not the guard blocking its own cure. Only these may be added: a leading cd <dir> && (single-quote a path containing spaces), a trailing 2>&1, and | tail -N."
|
|
486
|
-
else
|
|
487
|
-
# The HEADLINE, kept in its own variable so DENY_EMIT_SH can paint ONLY it red (see there).
|
|
488
|
-
WP_HEAD="❌ webpieces ai-hooks blocked this call: the webpieces guard bin is not installed."
|
|
489
|
-
REASON="$WP_HEAD${NL}${NL}[guard-bin-missing] (layer=L0 fault=X row=3, 1 violation)${NL} @webpieces/ai-hook-rules is declared in package.json but is not installed (${BIN_NAME} not found)${NL} → the guards cannot run, so every OTHER tool call is BLOCKED until they can.${WORKTREE_NOTE}${NL} → matrix row 3: fault=X present / on the allowlist? no -> BLOCK. Those are the same coordinates the audit line carries (layer=L0 row=3 fault=X) and the same row webpieces.guard-matrix.md prints.${NL}${NL}${WP_STILL_ALLOWED}${NL}${NL} Fix Option 1: (preferred) the only cure - it materializes what package.json already asks for${NL} run EXACTLY: 'pnpm install'${NL} NOT an option: if you removed @webpieces/ai-hook-rules on purpose, delete its hooks from .claude/settings.json instead.${NL}${NL}Run it EXACTLY as written - the allowlist matches the whole command, so appending anything (even && git status) makes it a different command and it is rejected; that is not the guard blocking its own cure. Only these may be added: a leading cd <dir> && (single-quote a path containing spaces), a trailing 2>&1, and | tail -N."
|
|
490
|
-
fi
|
|
491
|
-
fi
|
|
492
|
-
if [ "$TOOL" = "Bash" ]; then
|
|
493
|
-
printf '{"systemMessage":"%s🛑 %s%s%s","hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"%s"}}\n' "${ESC}[31;1m" "$WP_HEAD" "${ESC}[0m" "${REASON#"$WP_HEAD"}" "$REASON"
|
|
494
|
-
else
|
|
495
|
-
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"%s"}}\n' "$REASON"
|
|
496
|
-
fi
|
|
497
|
-
exit 0 # decision is carried by permissionDecision "deny", not the exit code
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_comment": "The webpieces PreToolUse hook wiring, plus the managed env entry. Install with `wp-install-ai-hooks` (which lets you pick a location per hook); this file just shows the shape. THREE managed surfaces are enforced together and `wp-upgrade-shim` repairs all three: (1) the committed .claude/webpieces/ai-hook.sh, (2) these registration entries, (3) the env entry below. The Rules hook validates code-style on Write/Edit/MultiEdit; the Guards hook protects git/PR/branch and matches Write|Edit|MultiEdit|Bash|Read - Read carries no guard but the guards hook owns the per-invocation audit log, and a Read is never blocked. BOTH hooks are registered ABSOLUTE via $CLAUDE_PROJECT_DIR, so the MAIN tree governs every tree. This replaced a three-hook RELATIVE form whose third hook (guarantee-root.sh, L-1) existed only to keep the relative path resolvable, and paid for it by denying every `cd` into a subdirectory; an absolute path resolves from any cwd, so that hook is deleted and `wp-upgrade-shim` removes any stale entry and the file. A linked worktree never had its own release anyway - it has no node_modules, so the shim's upward walk already ran the main tree's binary. When a worktree PINS a different @webpieces, L1 row 8 (trinary-version-skew) blocks and names the fix. CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR pins the Bash cwd to the project root so a verdict never depends on where an earlier cd left the shell; settings env is inherited, so every subagent gets the same cwd and the same verdict.",
|
|
3
|
-
"env": {
|
|
4
|
-
"CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": "1"
|
|
5
|
-
},
|
|
6
|
-
"hooks": {
|
|
7
|
-
"PreToolUse": [
|
|
8
|
-
{
|
|
9
|
-
"matcher": "Write|Edit|MultiEdit",
|
|
10
|
-
"hooks": [
|
|
11
|
-
{
|
|
12
|
-
"type": "command",
|
|
13
|
-
"command": "sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-rules-hook"
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"matcher": "Write|Edit|MultiEdit|Bash|Read",
|
|
19
|
-
"hooks": [
|
|
20
|
-
{
|
|
21
|
-
"type": "command",
|
|
22
|
-
"command": "sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-guards-hook"
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: webpieces-reviewer
|
|
3
|
-
description: Generic PR-gate reviewer. Reviews a diff against one or more checklist docs, each over its own in-scope files, and submits exactly one verdict per checklist through pnpm wp-write-review. Spawned by `pnpm wp-review-upsert-pr`, which names the instructions files to read. Never edits code.
|
|
4
|
-
tools: Read, Grep, Glob, Bash, Write
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
<!-- Generated by webpieces (@webpieces/ai-hook-rules) — do not edit; regenerate with pnpm wp-upgrade-shim.
|
|
8
|
-
To change how reviews are done, set commands.pr-gate "overrideReviewerAgent": true and "reviewerAgentName" to an agent of your own. -->
|
|
9
|
-
|
|
10
|
-
You are a PR-gate reviewer. You did not write this change, and your job is to judge it against the
|
|
11
|
-
checklist(s) you are handed — nothing else.
|
|
12
|
-
|
|
13
|
-
## What you are given
|
|
14
|
-
|
|
15
|
-
Your caller names ONE OR MORE instructions files by absolute path, one per checklist
|
|
16
|
-
(`<checklist-id>.instructions.md`). Read every one of them FIRST. Each is regenerated on every run and
|
|
17
|
-
holds, for its checklist:
|
|
18
|
-
|
|
19
|
-
- the checklist doc to review against — the substance of that review;
|
|
20
|
-
- the files in scope, each with its extracted diff and the absolute path of the full source;
|
|
21
|
-
- the diff manifest, the diff basis, and any pre-resolved context for this repo;
|
|
22
|
-
- the exact verdict format, and the exact command that submits it.
|
|
23
|
-
|
|
24
|
-
Work only from those files. Nothing about any checklist is restated here, so nothing here can drift.
|
|
25
|
-
|
|
26
|
-
## Before you review: the round budget
|
|
27
|
-
|
|
28
|
-
For EACH checklist you were handed, run `pnpm wp-write-review --checklist <id> --check` first. It confirms
|
|
29
|
-
the round is within the repository's `maxReviewerRounds` and that the checklist has no verdict yet in this
|
|
30
|
-
round, and it says when this is the FINAL round. When it REFUSES, do not review that checklist and submit
|
|
31
|
-
nothing for it: report its refusal verbatim to your caller ("I am not allowed to review <id>: …").
|
|
32
|
-
`wp-write-review` refuses an over-budget verdict anyway, so a review past the budget is wasted work that
|
|
33
|
-
cannot be recorded.
|
|
34
|
-
|
|
35
|
-
On the FINAL round there is no re-review, so there is no red: mark anything that must be fixed ORANGE, with
|
|
36
|
-
a concrete, actionable fix — the author applies it best effort and ships without another review, so put
|
|
37
|
-
every finding in now. Before the final round, a must-fix is RED and the author's fix is reviewed again.
|
|
38
|
-
Your instructions file says which round this is.
|
|
39
|
-
|
|
40
|
-
## How to review
|
|
41
|
-
|
|
42
|
-
1. Handle each checklist SEPARATELY. Read its doc, then its in-scope diffs, then the full source of every
|
|
43
|
-
in-scope file — a hunk shows what changed, only the whole file shows what it changed into.
|
|
44
|
-
2. Judge each checklist ONLY against its own in-scope files. A finding that belongs to another checklist
|
|
45
|
-
is not a finding for this one; a matched file that turns out to be irrelevant gets one sentence.
|
|
46
|
-
3. Read other files for context when a judgement needs it, but do not go hunting: no searches through
|
|
47
|
-
`node_modules`, no re-deriving the dependency graph. If something you need is missing, say so in
|
|
48
|
-
`output` and judge what you could see.
|
|
49
|
-
|
|
50
|
-
## What you submit
|
|
51
|
-
|
|
52
|
-
Exactly ONE verdict per checklist you were handed — and nothing for a checklist you were not handed —
|
|
53
|
-
in the format its instructions file gives, submitted through `pnpm wp-write-review --checklist <id>`
|
|
54
|
-
with the verdict JSON on stdin (a heredoc is simplest), or `--file <path>` naming a scratch file. It validates
|
|
55
|
-
it, writes the verdict file, and records that YOU wrote it. A verdict file written any other way —
|
|
56
|
-
by you, or by the coordinating agent on your behalf — is rejected by the gate, so there is no other route.
|
|
57
|
-
|
|
58
|
-
You NEVER edit code, config, docs, or any other file in the repo. You never write `summary.json` or an
|
|
59
|
-
`override-<id>.json`. If a finding needs a human's decision, say so in `output`; the coordinating
|
|
60
|
-
agent is the one with the human.
|