@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
package/src/core/log-stream.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WHO is writing — the three fields that make a log filename unique, carried as one value.
|
|
3
|
-
*
|
|
4
|
-
* Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather
|
|
5
|
-
* than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached
|
|
6
|
-
* main-sync refresher is a separate node process, and the spawner hands it these three fields on
|
|
7
|
-
* argv so parent and child write ONE stream. A single named carrier is what makes "read it back out
|
|
8
|
-
* of the parent, put it on argv, set it in the child" a three-line round trip instead of three
|
|
9
|
-
* parallel string parameters that can be reordered at either end.
|
|
10
|
-
*/
|
|
11
|
-
export declare class StreamIdentity {
|
|
12
|
-
readonly sessionId: string;
|
|
13
|
-
readonly agentId: string;
|
|
14
|
-
readonly hook: string;
|
|
15
|
-
constructor(sessionId: string, agentId: string, hook: string);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* WHICH LOG FILE does this hook invocation append to?
|
|
19
|
-
*
|
|
20
|
-
* ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────
|
|
21
|
-
* Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share
|
|
22
|
-
* a worktree, so three separate things shared one file:
|
|
23
|
-
*
|
|
24
|
-
* 1. **Parallel hooks.** The hooks reference says "when multiple PreToolUse hooks match a tool call,
|
|
25
|
-
* ALL matching hooks run in parallel". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match
|
|
26
|
-
* Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same
|
|
27
|
-
* time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)
|
|
28
|
-
* 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.
|
|
29
|
-
* 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`
|
|
30
|
-
* is absent for every one of them — so agent identity alone cannot tell them apart.
|
|
31
|
-
*
|
|
32
|
-
* `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured
|
|
33
|
-
* 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;
|
|
34
|
-
* the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line
|
|
35
|
-
* is exactly the long one — the `recover=` line a human needs most.
|
|
36
|
-
*
|
|
37
|
-
* ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────
|
|
38
|
-
* <local>/logs/<stream>/<sessionId>-<agentId | "coordinator">-<hook>.log
|
|
39
|
-
*
|
|
40
|
-
* stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)
|
|
41
|
-
* sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)
|
|
42
|
-
* agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)
|
|
43
|
-
* hook separates the PARALLEL hooks ('guards' | 'rules')
|
|
44
|
-
*
|
|
45
|
-
* This class owns the FILE half. One writer per file, by construction, so appends cannot interleave
|
|
46
|
-
* and nothing needs a lock — and all three identity dimensions must stay in the filename for that to
|
|
47
|
-
* hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN
|
|
48
|
-
* PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders
|
|
49
|
-
* on one path, which is the tearing measured above.
|
|
50
|
-
*
|
|
51
|
-
* Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY
|
|
52
|
-
* (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The
|
|
53
|
-
* layer is the one axis you almost always want to slice by first, and it was previously not
|
|
54
|
-
* expressible at all: L1 had no stream, so "show me every L1 decision" had no answer. Now
|
|
55
|
-
* `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —
|
|
56
|
-
* `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.
|
|
57
|
-
*
|
|
58
|
-
* `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of
|
|
59
|
-
* separators that would have to be flattened anyway — and `session_id` is its stable identifier, so
|
|
60
|
-
* session_id is the better key.
|
|
61
|
-
*
|
|
62
|
-
* The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —
|
|
63
|
-
* so nothing is lost by the filename not encoding it.
|
|
64
|
-
*
|
|
65
|
-
* ─── There is no un-split path ─────────────────────────────────────────────────────────────────────
|
|
66
|
-
* Every name is prefixed, always. A caller that never identifies renders as
|
|
67
|
-
* `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a
|
|
68
|
-
* bare-name fallback would have meant two reachable spellings of one filename, with the tearing one
|
|
69
|
-
* reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it
|
|
70
|
-
* is not offered.
|
|
71
|
-
*/
|
|
72
|
-
export declare class LogStream {
|
|
73
|
-
private sessionId;
|
|
74
|
-
private agentId;
|
|
75
|
-
private hook;
|
|
76
|
-
/**
|
|
77
|
-
* Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the
|
|
78
|
-
* coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is
|
|
79
|
-
* the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see
|
|
80
|
-
* core/version-sync.ts), never from who is asking.
|
|
81
|
-
* An empty `sessionId` renders as `unknown`: visible, never merged into another stream.
|
|
82
|
-
*/
|
|
83
|
-
identify(identity: StreamIdentity): void;
|
|
84
|
-
/**
|
|
85
|
-
* This process's identity, readable so it can be HANDED TO A CHILD PROCESS.
|
|
86
|
-
*
|
|
87
|
-
* The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node
|
|
88
|
-
* process with a fresh, unidentified `logStream`. Before this existed the parent logged
|
|
89
|
-
* SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the
|
|
90
|
-
* shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across
|
|
91
|
-
* two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this
|
|
92
|
-
* class exists to remove, still live on that stream), and the documented
|
|
93
|
-
* "SPAWN_ATTEMPT with no START means the child never launched" check read as a false failure on
|
|
94
|
-
* every single cycle. The spawner now reads this and puts it on the child's argv.
|
|
95
|
-
*/
|
|
96
|
-
identity(): StreamIdentity;
|
|
97
|
-
/**
|
|
98
|
-
* This WRITER's file name within a stream directory —
|
|
99
|
-
* `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.
|
|
100
|
-
*
|
|
101
|
-
* The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY
|
|
102
|
-
* (see log-streams.ts), because they are what makes one writer per file true and the stream is not:
|
|
103
|
-
* `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in
|
|
104
|
-
* PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on
|
|
105
|
-
* one path — the exact tearing this class exists to remove, reintroduced by a rename.
|
|
106
|
-
*
|
|
107
|
-
* `suffix` carries the extension so the rotation sibling gets the identical writer key: pass
|
|
108
|
-
* `.log`, and separately `.1.log`.
|
|
109
|
-
*/
|
|
110
|
-
writerFile(suffix: string): string;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Process-wide instance. The hook adapters identify it once at the top of the invocation and every
|
|
114
|
-
* writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures
|
|
115
|
-
* unchanged — the alternative was threading three more parameters through every call site.
|
|
116
|
-
*/
|
|
117
|
-
export declare const logStream: LogStream;
|
package/src/core/log-stream.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logStream = exports.LogStream = exports.StreamIdentity = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* WHO is writing — the three fields that make a log filename unique, carried as one value.
|
|
6
|
-
*
|
|
7
|
-
* Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather
|
|
8
|
-
* than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached
|
|
9
|
-
* main-sync refresher is a separate node process, and the spawner hands it these three fields on
|
|
10
|
-
* argv so parent and child write ONE stream. A single named carrier is what makes "read it back out
|
|
11
|
-
* of the parent, put it on argv, set it in the child" a three-line round trip instead of three
|
|
12
|
-
* parallel string parameters that can be reordered at either end.
|
|
13
|
-
*/
|
|
14
|
-
class StreamIdentity {
|
|
15
|
-
sessionId;
|
|
16
|
-
agentId;
|
|
17
|
-
hook;
|
|
18
|
-
constructor(sessionId, agentId, hook) {
|
|
19
|
-
this.sessionId = sessionId;
|
|
20
|
-
this.agentId = agentId;
|
|
21
|
-
this.hook = hook;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.StreamIdentity = StreamIdentity;
|
|
25
|
-
/**
|
|
26
|
-
* WHICH LOG FILE does this hook invocation append to?
|
|
27
|
-
*
|
|
28
|
-
* ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────
|
|
29
|
-
* Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share
|
|
30
|
-
* a worktree, so three separate things shared one file:
|
|
31
|
-
*
|
|
32
|
-
* 1. **Parallel hooks.** The hooks reference says "when multiple PreToolUse hooks match a tool call,
|
|
33
|
-
* ALL matching hooks run in parallel". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match
|
|
34
|
-
* Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same
|
|
35
|
-
* time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)
|
|
36
|
-
* 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.
|
|
37
|
-
* 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`
|
|
38
|
-
* is absent for every one of them — so agent identity alone cannot tell them apart.
|
|
39
|
-
*
|
|
40
|
-
* `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured
|
|
41
|
-
* 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;
|
|
42
|
-
* the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line
|
|
43
|
-
* is exactly the long one — the `recover=` line a human needs most.
|
|
44
|
-
*
|
|
45
|
-
* ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────
|
|
46
|
-
* <local>/logs/<stream>/<sessionId>-<agentId | "coordinator">-<hook>.log
|
|
47
|
-
*
|
|
48
|
-
* stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)
|
|
49
|
-
* sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)
|
|
50
|
-
* agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)
|
|
51
|
-
* hook separates the PARALLEL hooks ('guards' | 'rules')
|
|
52
|
-
*
|
|
53
|
-
* This class owns the FILE half. One writer per file, by construction, so appends cannot interleave
|
|
54
|
-
* and nothing needs a lock — and all three identity dimensions must stay in the filename for that to
|
|
55
|
-
* hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN
|
|
56
|
-
* PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders
|
|
57
|
-
* on one path, which is the tearing measured above.
|
|
58
|
-
*
|
|
59
|
-
* Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY
|
|
60
|
-
* (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The
|
|
61
|
-
* layer is the one axis you almost always want to slice by first, and it was previously not
|
|
62
|
-
* expressible at all: L1 had no stream, so "show me every L1 decision" had no answer. Now
|
|
63
|
-
* `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —
|
|
64
|
-
* `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.
|
|
65
|
-
*
|
|
66
|
-
* `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of
|
|
67
|
-
* separators that would have to be flattened anyway — and `session_id` is its stable identifier, so
|
|
68
|
-
* session_id is the better key.
|
|
69
|
-
*
|
|
70
|
-
* The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —
|
|
71
|
-
* so nothing is lost by the filename not encoding it.
|
|
72
|
-
*
|
|
73
|
-
* ─── There is no un-split path ─────────────────────────────────────────────────────────────────────
|
|
74
|
-
* Every name is prefixed, always. A caller that never identifies renders as
|
|
75
|
-
* `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a
|
|
76
|
-
* bare-name fallback would have meant two reachable spellings of one filename, with the tearing one
|
|
77
|
-
* reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it
|
|
78
|
-
* is not offered.
|
|
79
|
-
*/
|
|
80
|
-
class LogStream {
|
|
81
|
-
// ALWAYS a real identity. There is no "unset" state and no bare-name branch, so there is exactly
|
|
82
|
-
// ONE spelling of a log filename and a writer cannot reach the shared, tearing stream by doing
|
|
83
|
-
// nothing. A caller with no Claude Code payload (the openclaw adapter, library consumers, specs)
|
|
84
|
-
// gets UNIDENTIFIED below — which still prefixes, with `unknown`, so it is a distinct greppable
|
|
85
|
-
// stream rather than a merge point.
|
|
86
|
-
sessionId = 'unknown';
|
|
87
|
-
agentId = '';
|
|
88
|
-
hook = 'hook';
|
|
89
|
-
/**
|
|
90
|
-
* Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the
|
|
91
|
-
* coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is
|
|
92
|
-
* the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see
|
|
93
|
-
* core/version-sync.ts), never from who is asking.
|
|
94
|
-
* An empty `sessionId` renders as `unknown`: visible, never merged into another stream.
|
|
95
|
-
*/
|
|
96
|
-
identify(identity) {
|
|
97
|
-
this.sessionId = identity.sessionId;
|
|
98
|
-
this.agentId = identity.agentId;
|
|
99
|
-
this.hook = identity.hook;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* This process's identity, readable so it can be HANDED TO A CHILD PROCESS.
|
|
103
|
-
*
|
|
104
|
-
* The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node
|
|
105
|
-
* process with a fresh, unidentified `logStream`. Before this existed the parent logged
|
|
106
|
-
* SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the
|
|
107
|
-
* shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across
|
|
108
|
-
* two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this
|
|
109
|
-
* class exists to remove, still live on that stream), and the documented
|
|
110
|
-
* "SPAWN_ATTEMPT with no START means the child never launched" check read as a false failure on
|
|
111
|
-
* every single cycle. The spawner now reads this and puts it on the child's argv.
|
|
112
|
-
*/
|
|
113
|
-
identity() {
|
|
114
|
-
return new StreamIdentity(this.sessionId, this.agentId, this.hook);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* This WRITER's file name within a stream directory —
|
|
118
|
-
* `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.
|
|
119
|
-
*
|
|
120
|
-
* The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY
|
|
121
|
-
* (see log-streams.ts), because they are what makes one writer per file true and the stream is not:
|
|
122
|
-
* `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in
|
|
123
|
-
* PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on
|
|
124
|
-
* one path — the exact tearing this class exists to remove, reintroduced by a rename.
|
|
125
|
-
*
|
|
126
|
-
* `suffix` carries the extension so the rotation sibling gets the identical writer key: pass
|
|
127
|
-
* `.log`, and separately `.1.log`.
|
|
128
|
-
*/
|
|
129
|
-
writerFile(suffix) {
|
|
130
|
-
const agent = segment(this.agentId === '' ? 'coordinator' : this.agentId);
|
|
131
|
-
return `${segment(this.sessionId)}-${agent}-${segment(this.hook)}${suffix}`;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.LogStream = LogStream;
|
|
135
|
-
/**
|
|
136
|
-
* One path segment, sanitised. `session_id` and `agent_id` arrive from a JSON payload, so they are
|
|
137
|
-
* UNTRUSTED INPUT being used to build a filesystem path: `../../../etc` must become a harmless name and
|
|
138
|
-
* never escape the logs directory. Everything outside `[A-Za-z0-9._-]` collapses to `_`, a leading dot
|
|
139
|
-
* is neutralised so nothing becomes a hidden file or `..`, and the result is capped and never empty.
|
|
140
|
-
*/
|
|
141
|
-
// webpieces-disable no-function-outside-class -- pure string sanitiser, the module's own leaf helper beside the class it serves
|
|
142
|
-
function segment(raw) {
|
|
143
|
-
const cleaned = raw
|
|
144
|
-
.replace(/[^A-Za-z0-9._-]/g, '_') // kills every separator, so nothing can traverse
|
|
145
|
-
.replace(/\.{2,}/g, '_') // and no run of dots survives, so no segment reads as `..`
|
|
146
|
-
.replace(/^\.+/, '_') // nor becomes a hidden file
|
|
147
|
-
.slice(0, 64);
|
|
148
|
-
return cleaned === '' ? 'unknown' : cleaned;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Process-wide instance. The hook adapters identify it once at the top of the invocation and every
|
|
152
|
-
* writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures
|
|
153
|
-
* unchanged — the alternative was threading three more parameters through every call site.
|
|
154
|
-
*/
|
|
155
|
-
exports.logStream = new LogStream();
|
|
156
|
-
//# sourceMappingURL=log-stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-stream.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/log-stream.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,cAAc;IACd,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,IAAI,CAAS;IAEtB,YAAY,SAAiB,EAAE,OAAe,EAAE,IAAY;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,wCAUC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAa,SAAS;IAClB,iGAAiG;IACjG,+FAA+F;IAC/F,iGAAiG;IACjG,gGAAgG;IAChG,oCAAoC;IAC5B,SAAS,GAAG,SAAS,CAAC;IACtB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAwB;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,QAAQ;QACJ,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,MAAc;QACrB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1E,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;IAChF,CAAC;CACJ;AAxDD,8BAwDC;AAED;;;;;GAKG;AACH,gIAAgI;AAChI,SAAS,OAAO,CAAC,GAAW;IACxB,MAAM,OAAO,GAAG,GAAG;SACd,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAG,iDAAiD;SACpF,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAY,2DAA2D;SAC9F,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAe,4BAA4B;SAC/D,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClB,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACU,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["/**\n * WHO is writing — the three fields that make a log filename unique, carried as one value.\n *\n * Data-only (per CLAUDE.md: classes for data, explicit construction). It exists as a class rather\n * than three loose parameters because the identity has to CROSS A PROCESS BOUNDARY: the detached\n * main-sync refresher is a separate node process, and the spawner hands it these three fields on\n * argv so parent and child write ONE stream. A single named carrier is what makes \"read it back out\n * of the parent, put it on argv, set it in the child\" a three-line round trip instead of three\n * parallel string parameters that can be reordered at either end.\n */\nexport class StreamIdentity {\n readonly sessionId: string;\n readonly agentId: string;\n readonly hook: string;\n\n constructor(sessionId: string, agentId: string, hook: string) {\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.hook = hook;\n }\n}\n\n/**\n * WHICH LOG FILE does this hook invocation append to?\n *\n * ─── The bug this exists to fix ────────────────────────────────────────────────────────────────────\n * Log paths used to be keyed by the git WORKTREE alone (`<local>/logs/…`). Three separate things share\n * a worktree, so three separate things shared one file:\n *\n * 1. **Parallel hooks.** The hooks reference says \"when multiple PreToolUse hooks match a tool call,\n * ALL matching hooks run in parallel\". `wp-ai-rules-hook` and `wp-ai-guards-hook` both match\n * Write/Edit/MultiEdit, so on every file edit TWO PROCESSES append to the same file at the same\n * time. (A retired third hook, L-1's `guarantee-root.sh`, once made it three.)\n * 2. **Subagents.** A subagent without worktree isolation shares the coordinator's tree.\n * 3. **Whole sessions.** Four Claude Code windows on one clone are four coordinators, and `agent_id`\n * is absent for every one of them — so agent identity alone cannot tell them apart.\n *\n * `O_APPEND` is indivisible only under `PIPE_BUF`, which is **512 bytes on macOS**. Measured\n * 2026-08-06 across three repos: the invocation stream 208/3306 lines (6.3%) exceed it, max 608 B;\n * the decision stream 209/4097 (5.1%), max 625 B. So this tears TODAY, and the corrupted line\n * is exactly the long one — the `recover=` line a human needs most.\n *\n * ─── The key: the LAYER is the directory, the WRITER is the file ──────────────────────────────────\n * <local>/logs/<stream>/<sessionId>-<agentId | \"coordinator\">-<hook>.log\n *\n * stream separates the LAYERS ('L0-shim' | 'L1-location' | 'L2-decisions' | …)\n * sessionId separates concurrent Claude Code windows (`session_id`, on every hook payload)\n * agentId separates subagents within one window (`agent_id`, subagent-only — absent = coordinator)\n * hook separates the PARALLEL hooks ('guards' | 'rules')\n *\n * This class owns the FILE half. One writer per file, by construction, so appends cannot interleave\n * and nothing needs a lock — and all three identity dimensions must stay in the filename for that to\n * hold. `hook` especially: Claude Code runs the guards and rules hooks as separate processes IN\n * PARALLEL on one tool call, so folding `hook` into the directory would put two concurrent appenders\n * on one path, which is the tearing measured above.\n *\n * Nesting by STREAM is NOT the nesting this layout rejects. What it rejects is nesting by IDENTITY\n * (`sessions/<id>/<agent>/…`), which turns every cross-session question into a directory walk. The\n * layer is the one axis you almost always want to slice by first, and it was previously not\n * expressible at all: L1 had no stream, so \"show me every L1 decision\" had no answer. Now\n * `ls logs/L1-location/` is that answer, and a one-level wildcard recovers the flat view —\n * `ls -t logs/[*]/<sid>-*` is still every layer at once, in time order.\n *\n * `transcript_path` is also unique per session, but it is a filesystem PATH — long, and full of\n * separators that would have to be flattened anyway — and `session_id` is its stable identifier, so\n * session_id is the better key.\n *\n * The tree is still visible — every line already carries `root=` / `projectDir=` / `tree=` columns —\n * so nothing is lost by the filename not encoding it.\n *\n * ─── There is no un-split path ─────────────────────────────────────────────────────────────────────\n * Every name is prefixed, always. A caller that never identifies renders as\n * `unknown-coordinator-hook.log` — a distinct, greppable writer, NOT a shared file. Keeping a\n * bare-name fallback would have meant two reachable spellings of one filename, with the tearing one\n * reached by doing nothing; that is the widening-as-absence this whole class exists to remove, so it\n * is not offered.\n */\nexport class LogStream {\n // ALWAYS a real identity. There is no \"unset\" state and no bare-name branch, so there is exactly\n // ONE spelling of a log filename and a writer cannot reach the shared, tearing stream by doing\n // nothing. A caller with no Claude Code payload (the openclaw adapter, library consumers, specs)\n // gets UNIDENTIFIED below — which still prefixes, with `unknown`, so it is a distinct greppable\n // stream rather than a merge point.\n private sessionId = 'unknown';\n private agentId = '';\n private hook = 'hook';\n\n /**\n * Called once per invocation by the adapter that parsed the payload. `agentId` is empty for the\n * coordinator — that absence IS the signal — and renders as `coordinator`. Naming the writer file is\n * the ONLY thing this identity is used for; which tree a call acts on is measured from the path (see\n * core/version-sync.ts), never from who is asking.\n * An empty `sessionId` renders as `unknown`: visible, never merged into another stream.\n */\n identify(identity: StreamIdentity): void {\n this.sessionId = identity.sessionId;\n this.agentId = identity.agentId;\n this.hook = identity.hook;\n }\n\n /**\n * This process's identity, readable so it can be HANDED TO A CHILD PROCESS.\n *\n * The detached main-sync refresher (main-sync-refresh.ts → sync-main.ts) is a separate node\n * process with a fresh, unidentified `logStream`. Before this existed the parent logged\n * SPAWN_ATTEMPT to its own prefixed stream while the child logged START/FINISH/ERROR to the\n * shared, unidentified `unknown-coordinator-hook` writer — so ONE refresh cycle was split across\n * two files, every agent's child appended to that one shared file (the PIPE_BUF tearing this\n * class exists to remove, still live on that stream), and the documented\n * \"SPAWN_ATTEMPT with no START means the child never launched\" check read as a false failure on\n * every single cycle. The spawner now reads this and puts it on the child's argv.\n */\n identity(): StreamIdentity {\n return new StreamIdentity(this.sessionId, this.agentId, this.hook);\n }\n\n /**\n * This WRITER's file name within a stream directory —\n * `<sessionId>-<agentId|coordinator>-<hook><suffix>`, ALWAYS.\n *\n * The three identity dimensions stay in the FILE while the stream moves to the DIRECTORY\n * (see log-streams.ts), because they are what makes one writer per file true and the stream is not:\n * `wp-ai-guards-hook` and `wp-ai-rules-hook` are separate processes that Claude Code launches in\n * PARALLEL on the same tool call, so dropping `hook` here would put two concurrent appenders on\n * one path — the exact tearing this class exists to remove, reintroduced by a rename.\n *\n * `suffix` carries the extension so the rotation sibling gets the identical writer key: pass\n * `.log`, and separately `.1.log`.\n */\n writerFile(suffix: string): string {\n const agent = segment(this.agentId === '' ? 'coordinator' : this.agentId);\n return `${segment(this.sessionId)}-${agent}-${segment(this.hook)}${suffix}`;\n }\n}\n\n/**\n * One path segment, sanitised. `session_id` and `agent_id` arrive from a JSON payload, so they are\n * UNTRUSTED INPUT being used to build a filesystem path: `../../../etc` must become a harmless name and\n * never escape the logs directory. Everything outside `[A-Za-z0-9._-]` collapses to `_`, a leading dot\n * is neutralised so nothing becomes a hidden file or `..`, and the result is capped and never empty.\n */\n// webpieces-disable no-function-outside-class -- pure string sanitiser, the module's own leaf helper beside the class it serves\nfunction segment(raw: string): string {\n const cleaned = raw\n .replace(/[^A-Za-z0-9._-]/g, '_') // kills every separator, so nothing can traverse\n .replace(/\\.{2,}/g, '_') // and no run of dots survives, so no segment reads as `..`\n .replace(/^\\.+/, '_') // nor becomes a hidden file\n .slice(0, 64);\n return cleaned === '' ? 'unknown' : cleaned;\n}\n\n/**\n * Process-wide instance. The hook adapters identify it once at the top of the invocation and every\n * writer downstream reads it, which is what keeps `logGuardDecision()` / `logRejection()` signatures\n * unchanged — the alternative was threading three more parameters through every call site.\n */\nexport const logStream = new LogStream();\n"]}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.
|
|
3
|
-
*
|
|
4
|
-
* The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the
|
|
5
|
-
* LAYER in the path, so "show me every L1 decision this session" is one glob
|
|
6
|
-
* (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be
|
|
7
|
-
* either a suffix on a flat name or, for L1, nothing at all.
|
|
8
|
-
*
|
|
9
|
-
* These live in ai-hook-rules beside LogStream, because all FOUR writers are here of this layout and
|
|
10
|
-
* not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh
|
|
11
|
-
* rendered from `bin/shim-audit-log.ts`, and it must spell these
|
|
12
|
-
* directories identically or the layers scatter. One constant, four consumers — the same reason
|
|
13
|
-
* LogStream itself lives here.
|
|
14
|
-
*
|
|
15
|
-
* NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as
|
|
16
|
-
* processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED
|
|
17
|
-
* copy in node_modules — a release behind local source. A stream name defined there would render as
|
|
18
|
-
* `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,
|
|
19
|
-
* and the two shims would differ by exactly the constant. Same-package means same source, always.
|
|
20
|
-
*
|
|
21
|
-
* Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by
|
|
22
|
-
* IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level
|
|
23
|
-
* wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time
|
|
24
|
-
* order, across every layer at once.
|
|
25
|
-
*/
|
|
26
|
-
export declare const L0_SHIM_STREAM = "L0-shim";
|
|
27
|
-
export declare const L1_LOCATION_STREAM = "L1-location";
|
|
28
|
-
export declare const L2_DECISIONS_STREAM = "L2-decisions";
|
|
29
|
-
export declare const CALLS_STREAM = "calls";
|
|
30
|
-
export declare const ASYNC_REFRESH_STREAM = "async-refresh";
|
|
31
|
-
export declare const REJECTIONS_STREAM = "rejections";
|
|
32
|
-
/**
|
|
33
|
-
* Every stream directory, for the sweeps and specs that must enumerate them rather than name one.
|
|
34
|
-
* A new stream that is not added here is invisible to retention — which is why this is a list and not
|
|
35
|
-
* a doc sentence.
|
|
36
|
-
*/
|
|
37
|
-
export declare const ALL_LOG_STREAMS: readonly string[];
|
|
38
|
-
/**
|
|
39
|
-
* Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a
|
|
40
|
-
* directory that is in neither is invisible to every sweep, so its files would sit on disk forever.
|
|
41
|
-
*
|
|
42
|
-
* `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;
|
|
43
|
-
* `ALL_LOG_STREAMS` stays the answer to "what may be WRITTEN". Keeping the two separate is what stops a
|
|
44
|
-
* retired name from quietly becoming a writable one again.
|
|
45
|
-
*/
|
|
46
|
-
export declare const RETIRED_LOG_STREAMS: readonly string[];
|
|
47
|
-
/** Every directory retention may reap: what this release writes, plus what older ones left behind. */
|
|
48
|
-
export declare const SWEEPABLE_LOG_STREAMS: readonly string[];
|
package/src/core/log-streams.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SWEEPABLE_LOG_STREAMS = exports.RETIRED_LOG_STREAMS = exports.ALL_LOG_STREAMS = exports.REJECTIONS_STREAM = exports.ASYNC_REFRESH_STREAM = exports.CALLS_STREAM = exports.L2_DECISIONS_STREAM = exports.L1_LOCATION_STREAM = exports.L0_SHIM_STREAM = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.
|
|
6
|
-
*
|
|
7
|
-
* The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the
|
|
8
|
-
* LAYER in the path, so "show me every L1 decision this session" is one glob
|
|
9
|
-
* (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be
|
|
10
|
-
* either a suffix on a flat name or, for L1, nothing at all.
|
|
11
|
-
*
|
|
12
|
-
* These live in ai-hook-rules beside LogStream, because all FOUR writers are here of this layout and
|
|
13
|
-
* not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh
|
|
14
|
-
* rendered from `bin/shim-audit-log.ts`, and it must spell these
|
|
15
|
-
* directories identically or the layers scatter. One constant, four consumers — the same reason
|
|
16
|
-
* LogStream itself lives here.
|
|
17
|
-
*
|
|
18
|
-
* NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as
|
|
19
|
-
* processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED
|
|
20
|
-
* copy in node_modules — a release behind local source. A stream name defined there would render as
|
|
21
|
-
* `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,
|
|
22
|
-
* and the two shims would differ by exactly the constant. Same-package means same source, always.
|
|
23
|
-
*
|
|
24
|
-
* Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by
|
|
25
|
-
* IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level
|
|
26
|
-
* wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time
|
|
27
|
-
* order, across every layer at once.
|
|
28
|
-
*/
|
|
29
|
-
exports.L0_SHIM_STREAM = 'L0-shim';
|
|
30
|
-
exports.L1_LOCATION_STREAM = 'L1-location';
|
|
31
|
-
exports.L2_DECISIONS_STREAM = 'L2-decisions';
|
|
32
|
-
exports.CALLS_STREAM = 'calls';
|
|
33
|
-
exports.ASYNC_REFRESH_STREAM = 'async-refresh';
|
|
34
|
-
exports.REJECTIONS_STREAM = 'rejections';
|
|
35
|
-
/**
|
|
36
|
-
* Every stream directory, for the sweeps and specs that must enumerate them rather than name one.
|
|
37
|
-
* A new stream that is not added here is invisible to retention — which is why this is a list and not
|
|
38
|
-
* a doc sentence.
|
|
39
|
-
*/
|
|
40
|
-
exports.ALL_LOG_STREAMS = [
|
|
41
|
-
exports.L0_SHIM_STREAM, exports.L1_LOCATION_STREAM, exports.L2_DECISIONS_STREAM,
|
|
42
|
-
exports.CALLS_STREAM, exports.ASYNC_REFRESH_STREAM, exports.REJECTIONS_STREAM,
|
|
43
|
-
];
|
|
44
|
-
/**
|
|
45
|
-
* Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a
|
|
46
|
-
* directory that is in neither is invisible to every sweep, so its files would sit on disk forever.
|
|
47
|
-
*
|
|
48
|
-
* `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;
|
|
49
|
-
* `ALL_LOG_STREAMS` stays the answer to "what may be WRITTEN". Keeping the two separate is what stops a
|
|
50
|
-
* retired name from quietly becoming a writable one again.
|
|
51
|
-
*/
|
|
52
|
-
exports.RETIRED_LOG_STREAMS = ['L-1-cd'];
|
|
53
|
-
/** Every directory retention may reap: what this release writes, plus what older ones left behind. */
|
|
54
|
-
exports.SWEEPABLE_LOG_STREAMS = [...exports.ALL_LOG_STREAMS, ...exports.RETIRED_LOG_STREAMS];
|
|
55
|
-
//# sourceMappingURL=log-streams.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-streams.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/log-streams.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACU,QAAA,cAAc,GAAG,SAAS,CAAC;AAC3B,QAAA,kBAAkB,GAAG,aAAa,CAAC;AACnC,QAAA,mBAAmB,GAAG,cAAc,CAAC;AACrC,QAAA,YAAY,GAAG,OAAO,CAAC;AACvB,QAAA,oBAAoB,GAAG,eAAe,CAAC;AACvC,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;GAIG;AACU,QAAA,eAAe,GAAsB;IAC9C,sBAAc,EAAE,0BAAkB,EAAE,2BAAmB;IACvD,oBAAY,EAAE,4BAAoB,EAAE,yBAAiB;CACxD,CAAC;AAEF;;;;;;;GAOG;AACU,QAAA,mBAAmB,GAAsB,CAAC,QAAQ,CAAC,CAAC;AAEjE,sGAAsG;AACzF,QAAA,qBAAqB,GAAsB,CAAC,GAAG,uBAAe,EAAE,GAAG,2BAAmB,CAAC,CAAC","sourcesContent":["/**\n * THE STREAM DIRECTORIES — `<state>/logs/<stream>/<sessionId>-<agentId|coordinator>-<hook>.log`.\n *\n * The stream is the DIRECTORY and the writer is the FILE. That split is the whole point: it puts the\n * LAYER in the path, so \"show me every L1 decision this session\" is one glob\n * (`logs/L1-location/<sid>-*`) instead of a question no glob could answer — every layer used to be\n * either a suffix on a flat name or, for L1, nothing at all.\n *\n * These live in ai-hook-rules beside LogStream, because all FOUR writers are here of this layout and\n * not all of them are TypeScript: the L0 `ai-hook.sh` is POSIX sh\n * rendered from `bin/shim-audit-log.ts`, and it must spell these\n * directories identically or the layers scatter. One constant, four consumers — the same reason\n * LogStream itself lives here.\n *\n * NOT in rules-config, and that is load-bearing rather than tidiness: the `wp-*` bins are SPAWNED as\n * processes with no tsconfig path mapping, so they resolve `@webpieces/rules-config` to the PUBLISHED\n * copy in node_modules — a release behind local source. A stream name defined there would render as\n * `undefined` inside a spawned `wp-upgrade-shim` while the in-process renderer used the real value,\n * and the two shims would differ by exactly the constant. Same-package means same source, always.\n *\n * Nesting by STREAM is not the nesting that was rejected. What `logs/` refused was nesting by\n * IDENTITY (`sessions/<id>/<agent>/…`), which breaks every cross-session question. A one-level\n * wildcard recovers the flat view here — `ls -t logs/[star]/<sid>-*` is still every stream in time\n * order, across every layer at once.\n */\nexport const L0_SHIM_STREAM = 'L0-shim';\nexport const L1_LOCATION_STREAM = 'L1-location';\nexport const L2_DECISIONS_STREAM = 'L2-decisions';\nexport const CALLS_STREAM = 'calls';\nexport const ASYNC_REFRESH_STREAM = 'async-refresh';\nexport const REJECTIONS_STREAM = 'rejections';\n\n/**\n * Every stream directory, for the sweeps and specs that must enumerate them rather than name one.\n * A new stream that is not added here is invisible to retention — which is why this is a list and not\n * a doc sentence.\n */\nexport const ALL_LOG_STREAMS: readonly string[] = [\n L0_SHIM_STREAM, L1_LOCATION_STREAM, L2_DECISIONS_STREAM,\n CALLS_STREAM, ASYNC_REFRESH_STREAM, REJECTIONS_STREAM,\n];\n\n/**\n * Stream directories an OLDER release wrote and this one never will. Kept beside the live list because a\n * directory that is in neither is invisible to every sweep, so its files would sit on disk forever.\n *\n * `SWEEPABLE_LOG_STREAMS` — live + retired — is what retention and the layout specs must enumerate;\n * `ALL_LOG_STREAMS` stays the answer to \"what may be WRITTEN\". Keeping the two separate is what stops a\n * retired name from quietly becoming a writable one again.\n */\nexport const RETIRED_LOG_STREAMS: readonly string[] = ['L-1-cd'];\n\n/** Every directory retention may reap: what this release writes, plus what older ones left behind. */\nexport const SWEEPABLE_LOG_STREAMS: readonly string[] = [...ALL_LOG_STREAMS, ...RETIRED_LOG_STREAMS];\n"]}
|
package/src/core/log-target.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The ONE spelling of "how a command or file path is written into a log line's target field".
|
|
3
|
-
*
|
|
4
|
-
* It exists because the format now has a READER as well as a writer. `InvocationLog` and
|
|
5
|
-
* `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`
|
|
6
|
-
* has to reproduce that byte for byte to recognise the same command coming back. Two private copies of
|
|
7
|
-
* a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —
|
|
8
|
-
* and the failure it produces is silent, since a mismatched cap simply means a long command never
|
|
9
|
-
* matches itself and the guard that depends on it quietly never fires.
|
|
10
|
-
*/
|
|
11
|
-
export declare class LogTarget {
|
|
12
|
-
/**
|
|
13
|
-
* Collapse newlines and tabs so one decision is always one log line, and cap the length so a
|
|
14
|
-
* pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.
|
|
15
|
-
*/
|
|
16
|
-
oneLine(value: string): string;
|
|
17
|
-
}
|
|
18
|
-
/** The cap, exported so a spec can assert against it rather than re-typing the number. */
|
|
19
|
-
export declare const MAX_TARGET_LEN = 160;
|
|
20
|
-
/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */
|
|
21
|
-
export declare const logTarget: LogTarget;
|
package/src/core/log-target.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logTarget = exports.MAX_TARGET_LEN = exports.LogTarget = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The ONE spelling of "how a command or file path is written into a log line's target field".
|
|
6
|
-
*
|
|
7
|
-
* It exists because the format now has a READER as well as a writer. `InvocationLog` and
|
|
8
|
-
* `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`
|
|
9
|
-
* has to reproduce that byte for byte to recognise the same command coming back. Two private copies of
|
|
10
|
-
* a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —
|
|
11
|
-
* and the failure it produces is silent, since a mismatched cap simply means a long command never
|
|
12
|
-
* matches itself and the guard that depends on it quietly never fires.
|
|
13
|
-
*/
|
|
14
|
-
class LogTarget {
|
|
15
|
-
/**
|
|
16
|
-
* Collapse newlines and tabs so one decision is always one log line, and cap the length so a
|
|
17
|
-
* pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.
|
|
18
|
-
*/
|
|
19
|
-
oneLine(value) {
|
|
20
|
-
const flat = value.replace(/[\t\r\n]+/g, ' ').trim();
|
|
21
|
-
return flat.length <= exports.MAX_TARGET_LEN ? flat : flat.slice(0, exports.MAX_TARGET_LEN) + '…';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.LogTarget = LogTarget;
|
|
25
|
-
/** The cap, exported so a spec can assert against it rather than re-typing the number. */
|
|
26
|
-
exports.MAX_TARGET_LEN = 160;
|
|
27
|
-
/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */
|
|
28
|
-
exports.logTarget = new LogTarget();
|
|
29
|
-
//# sourceMappingURL=log-target.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-target.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/log-target.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,SAAS;IAClB;;;OAGG;IACH,OAAO,CAAC,KAAa;QACjB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,IAAI,sBAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAc,CAAC,GAAG,GAAG,CAAC;IACtF,CAAC;CACJ;AATD,8BASC;AAED,0FAA0F;AAC7E,QAAA,cAAc,GAAG,GAAG,CAAC;AAElC,yGAAyG;AAC5F,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["/**\n * The ONE spelling of \"how a command or file path is written into a log line's target field\".\n *\n * It exists because the format now has a READER as well as a writer. `InvocationLog` and\n * `logGuardDecision` collapse a command to one capped line before appending it; `SessionCallHistory`\n * has to reproduce that byte for byte to recognise the same command coming back. Two private copies of\n * a collapse-and-cap is exactly the second spelling `.claude/rules/no-backwards-compat.md` rejects —\n * and the failure it produces is silent, since a mismatched cap simply means a long command never\n * matches itself and the guard that depends on it quietly never fires.\n */\nexport class LogTarget {\n /**\n * Collapse newlines and tabs so one decision is always one log line, and cap the length so a\n * pasted heredoc cannot make a log line unreadable. The ellipsis is part of the stored value.\n */\n oneLine(value: string): string {\n const flat = value.replace(/[\\t\\r\\n]+/g, ' ').trim();\n return flat.length <= MAX_TARGET_LEN ? flat : flat.slice(0, MAX_TARGET_LEN) + '…';\n }\n}\n\n/** The cap, exported so a spec can assert against it rather than re-typing the number. */\nexport const MAX_TARGET_LEN = 160;\n\n/** Process-wide instance: it is a pure function of its input, so there is nothing to construct twice. */\nexport const logTarget = new LogTarget();\n"]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type SyncPhase = 'SPAWN_ATTEMPT' | 'START' | 'SKIP_INPROGRESS' | 'FINISH' | 'ERROR';
|
|
2
|
-
export declare class SyncLogEvent {
|
|
3
|
-
phase: SyncPhase;
|
|
4
|
-
pid: number;
|
|
5
|
-
branchArg: string;
|
|
6
|
-
detail: string;
|
|
7
|
-
constructor(phase: SyncPhase, pid: number, branchArg: string, detail: string);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Append one tab-separated line per refresher event to
|
|
11
|
-
* `.webpieces/logs/async-refresh/<writer>.log` (see LogStream for the writer key). `root` is
|
|
12
|
-
* the workspace root holding `.webpieces`. Swallows all errors — logging must never block or fail
|
|
13
|
-
* the refresher (or the hook that spawns it).
|
|
14
|
-
*/
|
|
15
|
-
export declare function logSyncEvent(root: string, event: SyncLogEvent): void;
|
|
16
|
-
export declare function refresherChildStdioPath(root: string): string;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SyncLogEvent = void 0;
|
|
4
|
-
exports.logSyncEvent = logSyncEvent;
|
|
5
|
-
exports.refresherChildStdioPath = refresherChildStdioPath;
|
|
6
|
-
const tslib_1 = require("tslib");
|
|
7
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
8
|
-
const path = tslib_1.__importStar(require("path"));
|
|
9
|
-
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
10
|
-
const log_streams_1 = require("./log-streams");
|
|
11
|
-
const to_error_1 = require("./to-error");
|
|
12
|
-
const log_stream_1 = require("./log-stream");
|
|
13
|
-
// The ASYNC log — observability for the detached background refresher (sync-main.ts) that writes
|
|
14
|
-
// main-sync-status.json. Its companion is the SYNC log (sync-decisions.log, decision-log.ts) which
|
|
15
|
-
// records what the hook DECIDED using that cache. The refresher runs AFTER the spawning hook has
|
|
16
|
-
// exited, with stdio discarded, so when it fails to update the cache there is normally no trace.
|
|
17
|
-
// This log captures its lifecycle — SPAWN_ATTEMPT (parent side), then START / SKIP_INPROGRESS /
|
|
18
|
-
// FINISH / ERROR (child side) — so we can tell whether the detached child never launched, was killed
|
|
19
|
-
// mid-run (START with no FINISH), or threw. Writes to
|
|
20
|
-
// `.webpieces/logs/async-refresh/<writer>.log`, where <writer> is LogStream's
|
|
21
|
-
// `<sessionId>-<agentId|coordinator>-<hook>` key (see LOGS_STATE_DIR and ASYNC_REFRESH_STREAM).
|
|
22
|
-
//
|
|
23
|
-
// THE CHILD'S RAW STDIO GOES TO THIS SAME FILE. It used to have a `.stderr.log` sibling, which was
|
|
24
|
-
// 0 bytes on every measured run — it is written to ONLY when the child dies before its own logging
|
|
25
|
-
// (a module-load failure, say), and that is precisely the moment you want the crash output sitting
|
|
26
|
-
// directly beneath the SPAWN_ATTEMPT that preceded it, in time order, rather than in a second file
|
|
27
|
-
// you have to think to open. Same cycle, same writer, one file.
|
|
28
|
-
const MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded (mirrors decision-log)
|
|
29
|
-
const MAX_DETAIL_LEN = 300;
|
|
30
|
-
// Data-only record of one refresher lifecycle event (per CLAUDE.md: classes for data).
|
|
31
|
-
class SyncLogEvent {
|
|
32
|
-
phase;
|
|
33
|
-
pid;
|
|
34
|
-
branchArg;
|
|
35
|
-
detail;
|
|
36
|
-
constructor(phase, pid, branchArg, detail) {
|
|
37
|
-
this.phase = phase;
|
|
38
|
-
this.pid = pid;
|
|
39
|
-
this.branchArg = branchArg;
|
|
40
|
-
this.detail = detail;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.SyncLogEvent = SyncLogEvent;
|
|
44
|
-
/**
|
|
45
|
-
* Append one tab-separated line per refresher event to
|
|
46
|
-
* `.webpieces/logs/async-refresh/<writer>.log` (see LogStream for the writer key). `root` is
|
|
47
|
-
* the workspace root holding `.webpieces`. Swallows all errors — logging must never block or fail
|
|
48
|
-
* the refresher (or the hook that spawns it).
|
|
49
|
-
*/
|
|
50
|
-
function logSyncEvent(root, event) {
|
|
51
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
52
|
-
try {
|
|
53
|
-
const timestamp = new Date().toISOString();
|
|
54
|
-
// LOCAL scope: this is the refresher's own lifecycle trace for THIS worktree. One writer per
|
|
55
|
-
// log, so its appends cannot interleave with another agent's.
|
|
56
|
-
const logsDir = tooling_common_1.dotWebpieces.logsFile(root, log_streams_1.ASYNC_REFRESH_STREAM);
|
|
57
|
-
fs.mkdirSync(logsDir, { recursive: true });
|
|
58
|
-
const logPath = path.join(logsDir, log_stream_1.logStream.writerFile('.log'));
|
|
59
|
-
rotateLogFile(logPath, path.join(logsDir, log_stream_1.logStream.writerFile('.1.log')));
|
|
60
|
-
const line = [
|
|
61
|
-
`[${timestamp}]`,
|
|
62
|
-
event.phase,
|
|
63
|
-
`pid=${String(event.pid)}`,
|
|
64
|
-
event.branchArg,
|
|
65
|
-
oneLine(event.detail),
|
|
66
|
-
].join('\t') + '\n';
|
|
67
|
-
fs.appendFileSync(logPath, line);
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
const error = (0, to_error_1.toError)(err);
|
|
71
|
-
void error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// The path the detached child's stdout/stderr are redirected to (opened with fs.openSync(p,'a') by
|
|
75
|
-
// the spawner), so even a crash BEFORE our own logging runs — e.g. a module-load failure — is
|
|
76
|
-
// captured instead of vanishing into /dev/null. Callers must ensure the log dir exists first
|
|
77
|
-
// (logSyncEvent's mkdir, called for SPAWN_ATTEMPT, does that).
|
|
78
|
-
//
|
|
79
|
-
// This is THE SAME FILE logSyncEvent appends to — see the header. It is not a second stream and it
|
|
80
|
-
// no longer has a name of its own.
|
|
81
|
-
// webpieces-disable no-function-outside-class -- sibling of logSyncEvent in this module-scope writer; it must stay callable from a tree too broken to build a DI container
|
|
82
|
-
function refresherChildStdioPath(root) {
|
|
83
|
-
return tooling_common_1.dotWebpieces.logsFile(root, log_streams_1.ASYNC_REFRESH_STREAM, log_stream_1.logStream.writerFile('.log'));
|
|
84
|
-
}
|
|
85
|
-
// Collapse newlines/tabs and cap length so one event is always one log line.
|
|
86
|
-
function oneLine(value) {
|
|
87
|
-
const flat = value.replace(/[\t\r\n]+/g, ' ').trim();
|
|
88
|
-
return flat.length <= MAX_DETAIL_LEN ? flat : flat.slice(0, MAX_DETAIL_LEN) + '…';
|
|
89
|
-
}
|
|
90
|
-
function rotateLogFile(logPath, prevPath) {
|
|
91
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
92
|
-
try {
|
|
93
|
-
const stat = fs.statSync(logPath);
|
|
94
|
-
if (stat.size > MAX_LOG_BYTES) {
|
|
95
|
-
if (fs.existsSync(prevPath))
|
|
96
|
-
fs.unlinkSync(prevPath);
|
|
97
|
-
fs.renameSync(logPath, prevPath);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
const error = (0, to_error_1.toError)(err);
|
|
102
|
-
void error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=main-sync-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main-sync-log.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/main-sync-log.ts"],"names":[],"mappings":";;;AAkDA,oCAwBC;AAUD,0DAEC;;AAtFD,+CAAyB;AACzB,mDAA6B;AAE7B,8DAAyD;AACzD,+CAAqD;AAErD,yCAAqC;AACrC,6CAAyC;AAEzC,iGAAiG;AACjG,mGAAmG;AACnG,iGAAiG;AACjG,iGAAiG;AACjG,gGAAgG;AAChG,qGAAqG;AACrG,sDAAsD;AACtD,8EAA8E;AAC9E,gGAAgG;AAChG,EAAE;AACF,mGAAmG;AACnG,mGAAmG;AACnG,mGAAmG;AACnG,mGAAmG;AACnG,gEAAgE;AAChE,MAAM,aAAa,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,uDAAuD;AACzF,MAAM,cAAc,GAAG,GAAG,CAAC;AAI3B,uFAAuF;AACvF,MAAa,YAAY;IACrB,KAAK,CAAY;IACjB,GAAG,CAAS;IACZ,SAAS,CAAS;IAClB,MAAM,CAAS;IAEf,YAAY,KAAgB,EAAE,GAAW,EAAE,SAAiB,EAAE,MAAc;QACxE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAZD,oCAYC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,KAAmB;IAC1D,8DAA8D;IAC9D,IAAI,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,6FAA6F;QAC7F,8DAA8D;QAC9D,MAAM,OAAO,GAAG,6BAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,kCAAoB,CAAC,CAAC;QAClE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE3C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACjE,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAE3E,MAAM,IAAI,GAAG;YACT,IAAI,SAAS,GAAG;YAChB,KAAK,CAAC,KAAK;YACX,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YAC1B,KAAK,CAAC,SAAS;YACf,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;SACxB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACpB,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC;IACf,CAAC;AACL,CAAC;AAED,mGAAmG;AACnG,8FAA8F;AAC9F,6FAA6F;AAC7F,+DAA+D;AAC/D,EAAE;AACF,mGAAmG;AACnG,mCAAmC;AACnC,2KAA2K;AAC3K,SAAgB,uBAAuB,CAAC,IAAY;IAChD,OAAO,6BAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,kCAAoB,EAAE,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED,6EAA6E;AAC7E,SAAS,OAAO,CAAC,KAAa;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrD,OAAO,IAAI,CAAC,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG,GAAG,CAAC;AACtF,CAAC;AAED,SAAS,aAAa,CAAC,OAAe,EAAE,QAAgB;IACpD,8DAA8D;IAC9D,IAAI,CAAC;QACD,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,GAAG,aAAa,EAAE,CAAC;YAC5B,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACrD,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC;IACf,CAAC;AACL,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\nimport { ASYNC_REFRESH_STREAM } from './log-streams';\n\nimport { toError } from './to-error';\nimport { logStream } from './log-stream';\n\n// The ASYNC log — observability for the detached background refresher (sync-main.ts) that writes\n// main-sync-status.json. Its companion is the SYNC log (sync-decisions.log, decision-log.ts) which\n// records what the hook DECIDED using that cache. The refresher runs AFTER the spawning hook has\n// exited, with stdio discarded, so when it fails to update the cache there is normally no trace.\n// This log captures its lifecycle — SPAWN_ATTEMPT (parent side), then START / SKIP_INPROGRESS /\n// FINISH / ERROR (child side) — so we can tell whether the detached child never launched, was killed\n// mid-run (START with no FINISH), or threw. Writes to\n// `.webpieces/logs/async-refresh/<writer>.log`, where <writer> is LogStream's\n// `<sessionId>-<agentId|coordinator>-<hook>` key (see LOGS_STATE_DIR and ASYNC_REFRESH_STREAM).\n//\n// THE CHILD'S RAW STDIO GOES TO THIS SAME FILE. It used to have a `.stderr.log` sibling, which was\n// 0 bytes on every measured run — it is written to ONLY when the child dies before its own logging\n// (a module-load failure, say), and that is precisely the moment you want the crash output sitting\n// directly beneath the SPAWN_ATTEMPT that preceded it, in time order, rather than in a second file\n// you have to think to open. Same cycle, same writer, one file.\nconst MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded (mirrors decision-log)\nconst MAX_DETAIL_LEN = 300;\n\nexport type SyncPhase = 'SPAWN_ATTEMPT' | 'START' | 'SKIP_INPROGRESS' | 'FINISH' | 'ERROR';\n\n// Data-only record of one refresher lifecycle event (per CLAUDE.md: classes for data).\nexport class SyncLogEvent {\n phase: SyncPhase;\n pid: number;\n branchArg: string;\n detail: string;\n\n constructor(phase: SyncPhase, pid: number, branchArg: string, detail: string) {\n this.phase = phase;\n this.pid = pid;\n this.branchArg = branchArg;\n this.detail = detail;\n }\n}\n\n/**\n * Append one tab-separated line per refresher event to\n * `.webpieces/logs/async-refresh/<writer>.log` (see LogStream for the writer key). `root` is\n * the workspace root holding `.webpieces`. Swallows all errors — logging must never block or fail\n * the refresher (or the hook that spawns it).\n */\nexport function logSyncEvent(root: string, event: SyncLogEvent): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const timestamp = new Date().toISOString();\n // LOCAL scope: this is the refresher's own lifecycle trace for THIS worktree. One writer per\n // log, so its appends cannot interleave with another agent's.\n const logsDir = dotWebpieces.logsFile(root, ASYNC_REFRESH_STREAM);\n fs.mkdirSync(logsDir, { recursive: true });\n\n const logPath = path.join(logsDir, logStream.writerFile('.log'));\n rotateLogFile(logPath, path.join(logsDir, logStream.writerFile('.1.log')));\n\n const line = [\n `[${timestamp}]`,\n event.phase,\n `pid=${String(event.pid)}`,\n event.branchArg,\n oneLine(event.detail),\n ].join('\\t') + '\\n';\n fs.appendFileSync(logPath, line);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n}\n\n// The path the detached child's stdout/stderr are redirected to (opened with fs.openSync(p,'a') by\n// the spawner), so even a crash BEFORE our own logging runs — e.g. a module-load failure — is\n// captured instead of vanishing into /dev/null. Callers must ensure the log dir exists first\n// (logSyncEvent's mkdir, called for SPAWN_ATTEMPT, does that).\n//\n// This is THE SAME FILE logSyncEvent appends to — see the header. It is not a second stream and it\n// no longer has a name of its own.\n// webpieces-disable no-function-outside-class -- sibling of logSyncEvent in this module-scope writer; it must stay callable from a tree too broken to build a DI container\nexport function refresherChildStdioPath(root: string): string {\n return dotWebpieces.logsFile(root, ASYNC_REFRESH_STREAM, logStream.writerFile('.log'));\n}\n\n// Collapse newlines/tabs and cap length so one event is always one log line.\nfunction oneLine(value: string): string {\n const flat = value.replace(/[\\t\\r\\n]+/g, ' ').trim();\n return flat.length <= MAX_DETAIL_LEN ? flat : flat.slice(0, MAX_DETAIL_LEN) + '…';\n}\n\nfunction rotateLogFile(logPath: string, prevPath: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const stat = fs.statSync(logPath);\n if (stat.size > MAX_LOG_BYTES) {\n if (fs.existsSync(prevPath)) fs.unlinkSync(prevPath);\n fs.renameSync(logPath, prevPath);\n }\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n}\n"]}
|