@webpieces/agent-workflow-rules 0.0.0-stage → 0.4.846
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 +23 -2
- package/package.json +45 -4
- package/src/adapters/agent-response.d.ts +5 -0
- package/src/adapters/agent-response.js +86 -0
- package/src/adapters/agent-response.js.map +1 -0
- package/src/adapters/codex-subagent-guard.d.ts +45 -0
- package/src/adapters/codex-subagent-guard.js +88 -0
- package/src/adapters/codex-subagent-guard.js.map +1 -0
- package/src/adapters/guards-hook.d.ts +3 -0
- package/src/adapters/guards-hook.js +30 -0
- package/src/adapters/guards-hook.js.map +1 -0
- package/src/adapters/hook-app-fixtures.d.ts +68 -0
- package/src/adapters/hook-app-fixtures.js +170 -0
- package/src/adapters/hook-app-fixtures.js.map +1 -0
- package/src/adapters/hook-core.d.ts +22 -0
- package/src/adapters/hook-core.js +359 -0
- package/src/adapters/hook-core.js.map +1 -0
- package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
- package/src/adapters/hook-pipeline-evaluator.js +18 -0
- package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
- package/src/adapters/review-identity-stamper.d.ts +20 -0
- package/src/adapters/review-identity-stamper.js +34 -0
- package/src/adapters/review-identity-stamper.js.map +1 -0
- package/src/bin/codex-trust.d.ts +105 -0
- package/src/bin/codex-trust.js +205 -0
- package/src/bin/codex-trust.js.map +1 -0
- package/src/bin/dev-hook-install.d.ts +1 -0
- package/src/bin/dev-hook-install.js +80 -0
- package/src/bin/dev-hook-install.js.map +1 -0
- package/src/bin/dev-hook-uninstall.d.ts +1 -0
- package/src/bin/dev-hook-uninstall.js +45 -0
- package/src/bin/dev-hook-uninstall.js.map +1 -0
- package/src/bin/hook-registration.d.ts +429 -0
- package/src/bin/hook-registration.js +661 -0
- package/src/bin/hook-registration.js.map +1 -0
- package/src/bin/install-entry.d.ts +19 -0
- package/src/bin/install-entry.js +128 -0
- package/src/bin/install-entry.js.map +1 -0
- package/src/bin/l0-allowlist.d.ts +46 -0
- package/src/bin/l0-allowlist.js +527 -0
- package/src/bin/l0-allowlist.js.map +1 -0
- package/src/bin/l0-codex-read.d.ts +20 -0
- package/src/bin/l0-codex-read.js +108 -0
- package/src/bin/l0-codex-read.js.map +1 -0
- package/src/bin/l0-decide.d.ts +49 -0
- package/src/bin/l0-decide.js +90 -0
- package/src/bin/l0-decide.js.map +1 -0
- package/src/bin/l0-entry.d.ts +103 -0
- package/src/bin/l0-entry.js +98 -0
- package/src/bin/l0-entry.js.map +1 -0
- package/src/bin/l0-ignored-tools.d.ts +38 -0
- package/src/bin/l0-ignored-tools.js +44 -0
- package/src/bin/l0-ignored-tools.js.map +1 -0
- package/src/bin/managed-env.d.ts +46 -0
- package/src/bin/managed-env.js +50 -0
- package/src/bin/managed-env.js.map +1 -0
- package/src/bin/neighbour-hooks.d.ts +42 -0
- package/src/bin/neighbour-hooks.js +177 -0
- package/src/bin/neighbour-hooks.js.map +1 -0
- package/src/bin/reviewer-agent.d.ts +19 -0
- package/src/bin/reviewer-agent.js +135 -0
- package/src/bin/reviewer-agent.js.map +1 -0
- package/src/bin/settings-shape.d.ts +37 -0
- package/src/bin/settings-shape.js +17 -0
- package/src/bin/settings-shape.js.map +1 -0
- package/src/bin/setup-config.d.ts +20 -0
- package/src/bin/setup-config.js +371 -0
- package/src/bin/setup-config.js.map +1 -0
- package/src/bin/setup.d.ts +78 -0
- package/src/bin/setup.js +411 -0
- package/src/bin/setup.js.map +1 -0
- package/src/bin/shim-audit-log.d.ts +119 -0
- package/src/bin/shim-audit-log.js +286 -0
- package/src/bin/shim-audit-log.js.map +1 -0
- package/src/bin/shim-deny-reason.d.ts +1 -0
- package/src/bin/shim-deny-reason.js +244 -0
- package/src/bin/shim-deny-reason.js.map +1 -0
- package/src/bin/shim-drift-fix.d.ts +1 -0
- package/src/bin/shim-drift-fix.js +73 -0
- package/src/bin/shim-drift-fix.js.map +1 -0
- package/src/bin/shim-testkit.d.ts +107 -0
- package/src/bin/shim-testkit.js +197 -0
- package/src/bin/shim-testkit.js.map +1 -0
- package/src/bin/shim-version-drift.d.ts +1 -0
- package/src/bin/shim-version-drift.js +164 -0
- package/src/bin/shim-version-drift.js.map +1 -0
- package/src/bin/shim.d.ts +16 -0
- package/src/bin/shim.js +641 -0
- package/src/bin/shim.js.map +1 -0
- package/src/bin/upgrade-shim.d.ts +18 -0
- package/src/bin/upgrade-shim.js +283 -0
- package/src/bin/upgrade-shim.js.map +1 -0
- package/src/configs/main-sync-guard-configs.d.ts +38 -0
- package/src/configs/main-sync-guard-configs.js +54 -0
- package/src/configs/main-sync-guard-configs.js.map +1 -0
- package/src/configs/rule-configs.d.ts +47 -0
- package/src/configs/rule-configs.js +96 -0
- package/src/configs/rule-configs.js.map +1 -0
- package/src/core/ai-type-context.d.ts +36 -0
- package/src/core/ai-type-context.js +45 -0
- package/src/core/ai-type-context.js.map +1 -0
- package/src/core/decision-log.d.ts +190 -0
- package/src/core/decision-log.js +409 -0
- package/src/core/decision-log.js.map +1 -0
- package/src/core/excluded-path-escape.d.ts +101 -0
- package/src/core/excluded-path-escape.js +236 -0
- package/src/core/excluded-path-escape.js.map +1 -0
- package/src/core/force-to-root.d.ts +32 -0
- package/src/core/force-to-root.js +60 -0
- package/src/core/force-to-root.js.map +1 -0
- package/src/core/guard-index-doc.d.ts +63 -0
- package/src/core/guard-index-doc.js +172 -0
- package/src/core/guard-index-doc.js.map +1 -0
- package/src/core/instruct-ai-writer.d.ts +1 -0
- package/src/core/instruct-ai-writer.js +6 -0
- package/src/core/instruct-ai-writer.js.map +1 -0
- package/src/core/l0-matrix.d.ts +102 -0
- package/src/core/l0-matrix.js +357 -0
- package/src/core/l0-matrix.js.map +1 -0
- package/src/core/l0-tooling-doc.d.ts +45 -0
- package/src/core/l0-tooling-doc.js +258 -0
- package/src/core/l0-tooling-doc.js.map +1 -0
- package/src/core/l1-doc.d.ts +7 -0
- package/src/core/l1-doc.js +340 -0
- package/src/core/l1-doc.js.map +1 -0
- package/src/core/l1-matrix-doc.d.ts +31 -0
- package/src/core/l1-matrix-doc.js +111 -0
- package/src/core/l1-matrix-doc.js.map +1 -0
- package/src/core/l1-rows.d.ts +167 -0
- package/src/core/l1-rows.js +262 -0
- package/src/core/l1-rows.js.map +1 -0
- package/src/core/l2-doc.d.ts +7 -0
- package/src/core/l2-doc.js +385 -0
- package/src/core/l2-doc.js.map +1 -0
- package/src/core/l2-matrix-doc.d.ts +23 -0
- package/src/core/l2-matrix-doc.js +72 -0
- package/src/core/l2-matrix-doc.js.map +1 -0
- package/src/core/l2-row.d.ts +54 -0
- package/src/core/l2-row.js +75 -0
- package/src/core/l2-row.js.map +1 -0
- package/src/core/l2-rows.d.ts +56 -0
- package/src/core/l2-rows.js +272 -0
- package/src/core/l2-rows.js.map +1 -0
- package/src/core/load-rules.d.ts +9 -0
- package/src/core/load-rules.js +65 -0
- package/src/core/load-rules.js.map +1 -0
- package/src/core/log-stream.d.ts +117 -0
- package/src/core/log-stream.js +156 -0
- package/src/core/log-stream.js.map +1 -0
- package/src/core/log-streams.d.ts +48 -0
- package/src/core/log-streams.js +55 -0
- package/src/core/log-streams.js.map +1 -0
- package/src/core/log-target.d.ts +21 -0
- package/src/core/log-target.js +29 -0
- package/src/core/log-target.js.map +1 -0
- package/src/core/main-sync-log.d.ts +16 -0
- package/src/core/main-sync-log.js +108 -0
- package/src/core/main-sync-log.js.map +1 -0
- package/src/core/main-sync-refresh.d.ts +39 -0
- package/src/core/main-sync-refresh.js +96 -0
- package/src/core/main-sync-refresh.js.map +1 -0
- package/src/core/main-sync-timeout.d.ts +33 -0
- package/src/core/main-sync-timeout.js +95 -0
- package/src/core/main-sync-timeout.js.map +1 -0
- package/src/core/matrix-cures.d.ts +12 -0
- package/src/core/matrix-cures.js +56 -0
- package/src/core/matrix-cures.js.map +1 -0
- package/src/core/missing-directory.d.ts +38 -0
- package/src/core/missing-directory.js +66 -0
- package/src/core/missing-directory.js.map +1 -0
- package/src/core/read-only-inspection.d.ts +34 -0
- package/src/core/read-only-inspection.js +88 -0
- package/src/core/read-only-inspection.js.map +1 -0
- package/src/core/rejection-log.d.ts +9 -0
- package/src/core/rejection-log.js +262 -0
- package/src/core/rejection-log.js.map +1 -0
- package/src/core/rules/branch-creation-guard.d.ts +113 -0
- package/src/core/rules/branch-creation-guard.js +425 -0
- package/src/core/rules/branch-creation-guard.js.map +1 -0
- package/src/core/rules/branch-switch-scan.d.ts +43 -0
- package/src/core/rules/branch-switch-scan.js +132 -0
- package/src/core/rules/branch-switch-scan.js.map +1 -0
- package/src/core/rules/build-output-pipe-guard.d.ts +56 -0
- package/src/core/rules/build-output-pipe-guard.js +120 -0
- package/src/core/rules/build-output-pipe-guard.js.map +1 -0
- package/src/core/rules/build-output-pipe-scan.d.ts +47 -0
- package/src/core/rules/build-output-pipe-scan.js +84 -0
- package/src/core/rules/build-output-pipe-scan.js.map +1 -0
- package/src/core/rules/cap-remedies.d.ts +39 -0
- package/src/core/rules/cap-remedies.js +59 -0
- package/src/core/rules/cap-remedies.js.map +1 -0
- package/src/core/rules/commit-message-substitution-guard.d.ts +72 -0
- package/src/core/rules/commit-message-substitution-guard.js +134 -0
- package/src/core/rules/commit-message-substitution-guard.js.map +1 -0
- package/src/core/rules/commit-message-substitution-scan.d.ts +42 -0
- package/src/core/rules/commit-message-substitution-scan.js +145 -0
- package/src/core/rules/commit-message-substitution-scan.js.map +1 -0
- package/src/core/rules/content-read-scan.d.ts +76 -0
- package/src/core/rules/content-read-scan.js +176 -0
- package/src/core/rules/content-read-scan.js.map +1 -0
- package/src/core/rules/cure-prefix-scan.d.ts +64 -0
- package/src/core/rules/cure-prefix-scan.js +133 -0
- package/src/core/rules/cure-prefix-scan.js.map +1 -0
- package/src/core/rules/feature-branch-guard.d.ts +121 -0
- package/src/core/rules/feature-branch-guard.js +327 -0
- package/src/core/rules/feature-branch-guard.js.map +1 -0
- package/src/core/rules/index.d.ts +1 -0
- package/src/core/rules/index.js +5 -0
- package/src/core/rules/index.js.map +1 -0
- package/src/core/rules/judged-tree.d.ts +66 -0
- package/src/core/rules/judged-tree.js +97 -0
- package/src/core/rules/judged-tree.js.map +1 -0
- package/src/core/rules/main-freshness.d.ts +37 -0
- package/src/core/rules/main-freshness.js +61 -0
- package/src/core/rules/main-freshness.js.map +1 -0
- package/src/core/rules/merge-in-progress-guard.d.ts +17 -0
- package/src/core/rules/merge-in-progress-guard.js +124 -0
- package/src/core/rules/merge-in-progress-guard.js.map +1 -0
- package/src/core/rules/merged-branch-bash-guard.d.ts +62 -0
- package/src/core/rules/merged-branch-bash-guard.js +171 -0
- package/src/core/rules/merged-branch-bash-guard.js.map +1 -0
- package/src/core/rules/merged-branch-message.d.ts +59 -0
- package/src/core/rules/merged-branch-message.js +137 -0
- package/src/core/rules/merged-branch-message.js.map +1 -0
- package/src/core/rules/pr-creation-or-push-guard.d.ts +26 -0
- package/src/core/rules/pr-creation-or-push-guard.js +150 -0
- package/src/core/rules/pr-creation-or-push-guard.js.map +1 -0
- package/src/core/rules/pr-merge-guard.d.ts +36 -0
- package/src/core/rules/pr-merge-guard.js +87 -0
- package/src/core/rules/pr-merge-guard.js.map +1 -0
- package/src/core/rules/read-stale-guard.d.ts +136 -0
- package/src/core/rules/read-stale-guard.js +328 -0
- package/src/core/rules/read-stale-guard.js.map +1 -0
- package/src/core/rules/recovery-allowlist.d.ts +49 -0
- package/src/core/rules/recovery-allowlist.js +187 -0
- package/src/core/rules/recovery-allowlist.js.map +1 -0
- package/src/core/rules/redirect-how-to-merge-main.d.ts +16 -0
- package/src/core/rules/redirect-how-to-merge-main.js +159 -0
- package/src/core/rules/redirect-how-to-merge-main.js.map +1 -0
- package/src/core/rules/stale-main-bash-guard.d.ts +198 -0
- package/src/core/rules/stale-main-bash-guard.js +363 -0
- package/src/core/rules/stale-main-bash-guard.js.map +1 -0
- package/src/core/rules/stale-main-message.d.ts +62 -0
- package/src/core/rules/stale-main-message.js +102 -0
- package/src/core/rules/stale-main-message.js.map +1 -0
- package/src/core/rules/tree-recovery.d.ts +92 -0
- package/src/core/rules/tree-recovery.js +165 -0
- package/src/core/rules/tree-recovery.js.map +1 -0
- package/src/core/rules/wait-spin-guard.d.ts +128 -0
- package/src/core/rules/wait-spin-guard.js +211 -0
- package/src/core/rules/wait-spin-guard.js.map +1 -0
- package/src/core/rules/wait-spin-scan.d.ts +118 -0
- package/src/core/rules/wait-spin-scan.js +203 -0
- package/src/core/rules/wait-spin-scan.js.map +1 -0
- package/src/core/rules/whole-repo-build-guard.d.ts +125 -0
- package/src/core/rules/whole-repo-build-guard.js +257 -0
- package/src/core/rules/whole-repo-build-guard.js.map +1 -0
- package/src/core/rules/whole-repo-build-scan.d.ts +28 -0
- package/src/core/rules/whole-repo-build-scan.js +198 -0
- package/src/core/rules/whole-repo-build-scan.js.map +1 -0
- package/src/core/runner.d.ts +19 -0
- package/src/core/runner.js +482 -0
- package/src/core/runner.js.map +1 -0
- package/src/core/session-call-history.d.ts +44 -0
- package/src/core/session-call-history.js +79 -0
- package/src/core/session-call-history.js.map +1 -0
- package/src/core/sync-main.d.ts +46 -0
- package/src/core/sync-main.js +176 -0
- package/src/core/sync-main.js.map +1 -0
- package/src/core/version-sync.d.ts +219 -0
- package/src/core/version-sync.js +558 -0
- package/src/core/version-sync.js.map +1 -0
- package/src/core/webpieces-versions.d.ts +98 -0
- package/src/core/webpieces-versions.js +206 -0
- package/src/core/webpieces-versions.js.map +1 -0
- package/src/core/workflow-hook-rules.d.ts +5 -0
- package/src/core/workflow-hook-rules.js +15 -0
- package/src/core/workflow-hook-rules.js.map +1 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +28 -0
- package/src/index.js.map +1 -0
- package/src/policy-keys.d.ts +2 -0
- package/src/policy-keys.js +6 -0
- package/src/policy-keys.js.map +1 -0
- package/src/rule-migrations.d.ts +3 -0
- package/src/rule-migrations.js +22 -0
- package/src/rule-migrations.js.map +1 -0
- package/src/rule-pack.d.ts +2 -0
- package/src/rule-pack.js +20 -0
- package/src/rule-pack.js.map +1 -0
- package/src/rule-settings.d.ts +5 -0
- package/src/rule-settings.js +31 -0
- package/src/rule-settings.js.map +1 -0
- package/src/safeguard-catalog.d.ts +3 -0
- package/src/safeguard-catalog.js +16 -0
- package/src/safeguard-catalog.js.map +1 -0
- package/templates/ai-hook.sh +497 -0
- package/templates/claude-settings-hook.json +28 -0
- package/templates/webpieces-reviewer.md +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/setup.ts"],"names":[],"mappings":";;;AAuJA,wCAaC;AAMD,0BAGC;AAwBD,8BA8CC;AAyCD,kDAWC;AAID,wCAGC;AAUD,kCAOC;AA2CD,oBA4CC;;AAtZD,+CAAyB;AACzB,mDAA6B;AAC7B,2BAA6B;AAC7B,uCAA2C;AAE3C,0DAAmH;AAEnH,iCAA2D;AAC3D,qDAA6E;AAC7E,2DAA2O;AAE3O,+CAAqE;AACrE,+CAAgD;AAChD,uGAAuG;AACvG,yFAAyF;AACzF,iDAAkD;AAGlD,8EAA8E;AAC9E,iGAAiG;AACjG,kGAAkG;AAClG,wGAAwG;AACxG,oGAAoG;AACpG,0FAA0F;AAC1F,8EAA8E;AAC9E,MAAM,QAAQ;IAEG;IACA;IACA;IAHb,YACa,GAAW,EACX,KAAa,EACb,GAAW;QAFX,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QACb,QAAG,GAAH,GAAG,CAAQ;IACrB,CAAC;IAEJ;;;;;;;OAOG;IACH,UAAU,CAAC,MAAqB;QAC5B,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,6FAA6F;IAC7F,qGAAqG;IACrG,+FAA+F;IAC/F,mGAAmG;IACnG,UAAU,CAAC,MAAqB,EAAE,WAAmB;QACjD,IAAI,MAAM,CAAC,QAAQ,EAA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AC;IAC5C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,8EAA8E,CAAC,CAAC;IAC5F,OAAO,CAAC,GAAG,CAAC,2FAA2F,CAAC,CAAC;AAC7G,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,KAAK,IAAI,EAAE,CAAC;AAChB,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { homedir } from 'os';\nimport { createInterface } from 'readline';\n\nimport { RepoRootFinder, writeTemplate, writeTemplateIfMissing, CONFIG_POLICY_DOC } from '@webpieces/rules-config';\n\nimport { SHIM_MARKER, shimPath, renderShim } from './shim';\nimport { REVIEWER_AGENT_MARKER, writeReviewerAgent } from './reviewer-agent';\nimport { HookRegistrationEntry, GUARDS_BIN, LEGACY_GUARANTEE_ROOT_MARKER, RULES_BIN, addHookEntry, applyManagedEnv, readSettings, writeSettings, HarnessRegistration, CLAUDE_REGISTRATION, CODEX_REGISTRATION } from './hook-registration';\nimport type { ClaudeSettings, HookCommand, HookEntry } from './settings-shape';\nimport { BASH_CWD_ENV_KEY, BASH_CWD_ENV_VALUE } from './managed-env';\nimport { CodexTrustProbe } from './codex-trust';\n// The config half of the installer — seeding and migrating webpieces.config.json. Split for size along\n// the seam that was already there: this module is hook WIRING, that one is CONFIG SHAPE.\nimport { seedOrSyncConfig } from './setup-config';\n\n\n// ---------------------------------------------------------------------------\n// The two independently-installable GUARD hooks. Each can land in a different settings file (see\n// InstallTarget) so a team can ship the guards while a developer keeps the code-style rules local\n// while iterating. Both are registered ABSOLUTE via $CLAUDE_PROJECT_DIR, so the MAIN tree governs every\n// tree. There used to be a third — the L-1 hook, which existed only to keep a RELATIVE registration\n// resolvable; it is retired, and purgeRetiredGuaranteeRoot() removes anything left of it.\n// ---------------------------------------------------------------------------\nclass HookSpec {\n constructor(\n readonly key: string,\n readonly label: string,\n readonly bin: string,\n ) {}\n\n /**\n * WHICH TOOL NAMES this hook must see, in the harness the target belongs to.\n *\n * It is a lookup on the target rather than a field on the spec because the answer is not a property\n * of the hook: the rules hook matches `Write|Edit|MultiEdit` under Claude Code and `apply_patch`\n * under Codex, and a single stored matcher is exactly how `.codex/hooks.json` came to be registered\n * against tool names Codex never emits.\n */\n matcherFor(target: InstallTarget): string {\n return target.harness.matcherFor(this.bin);\n }\n\n // Absolute targets (global) need the exact path to this repo's bin — no ~/.webpieces bridge.\n // Project targets get the ABSOLUTE shim command, anchored on the harness's own project-root variable\n // (see HarnessRegistration.shimCommand): it resolves from ANY cwd, so a hook can never fail to\n // launch — which per the hooks reference would be exit 127, a SILENT UNGUARDED ALLOW, not a block.\n commandFor(target: InstallTarget, projectRoot: string): string {\n if (target.absolute) {\n return `node ${path.join(projectRoot, 'node_modules', '.bin', this.bin)}`;\n }\n return target.harness.shimCommand(this.bin);\n }\n}\n\n// Idempotent: re-running the installer overwrites the managed shim in place.\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nfunction writeShim(projectRoot: string): void {\n const target = shimPath(projectRoot);\n fs.mkdirSync(path.dirname(target), { recursive: true });\n fs.writeFileSync(target, renderShim(), { mode: 0o755 });\n // writeFileSync's mode is only applied when creating the file; force it on overwrite too.\n fs.chmodSync(target, 0o755);\n}\n\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nfunction removeShim(projectRoot: string): void {\n const target = shimPath(projectRoot);\n if (fs.existsSync(target)) fs.rmSync(target);\n}\n\n// A managed .sh is shared by the project hooks — only safe to delete once no project settings file\n// references it anymore (i.e. the other hook was moved to global or uninstalled too).\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nfunction markerReferenced(targets: InstallTarget[], marker: string): boolean {\n return targets.some((t: InstallTarget) => {\n const entries = readSettings(t.settingsPath).hooks?.PreToolUse ?? [];\n return entries.some((e: HookEntry) => e.hooks.some((h: HookCommand) => h.command.includes(marker)));\n });\n}\n\n/**\n * Remove every trace of the RETIRED L-1 hook (`guarantee-root.sh`) — the file and any PreToolUse entry\n * still pointing at it. REMOVAL ONLY: nothing here can ever write one back.\n *\n * L-1 existed to guarantee a RELATIVE guard-hook path resolved, by refusing any `cd` that would park the\n * shell in a subdirectory. The guard hooks are ABSOLUTE now (`$CLAUDE_PROJECT_DIR/...`), so they resolve\n * from any cwd and the guarantee is structural — there is nothing left to police, and the subdirectory\n * denial that used to pay for it is gone with it.\n */\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nfunction purgeRetiredGuaranteeRoot(targets: InstallTarget[], projectRoot: string): void {\n for (const target of targets) {\n const settings = readSettings(target.settingsPath);\n if (removeHookByMarker(settings, LEGACY_GUARANTEE_ROOT_MARKER)) {\n writeSettings(target.settingsPath, settings);\n console.log(` 🗑️ removed the retired L-1 guarantee-root hook from ${target.label}`);\n }\n }\n const legacyFile = path.join(projectRoot, LEGACY_GUARANTEE_ROOT_MARKER);\n if (fs.existsSync(legacyFile)) {\n fs.rmSync(legacyFile, { force: true });\n console.log(' 🗑️ deleted the retired .claude/webpieces/guarantee-root.sh');\n }\n}\n\nexport class InstallTarget {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly choice: string,\n readonly label: string,\n readonly settingsPath: string,\n readonly absolute: boolean,\n /**\n * WHICH HARNESS this file arms — it decides the matcher and the shim anchor written into it.\n *\n * REQUIRED, with no default, and the absence of one is the point. A default of\n * CLAUDE_REGISTRATION would make \"omit the harness\" mean \"Claude Code\" — a widening that is an\n * ABSENCE rather than a token, so a target built for Codex without it would silently carry\n * `Write|Edit|MultiEdit` and `$CLAUDE_PROJECT_DIR`, which is EXACTLY the silently-unguarded\n * state this class exists to end, and ungreppable besides.\n */\n readonly harness: HarnessRegistration,\n ) {}\n}\n\n// The bin names come from ./hook-registration, which is also what the drift check and wp-upgrade-shim\n// compare against — one spelling of the registration, or the installer and the validator can disagree\n// about what \"installed\" means. The MATCHER is not here: it belongs to the harness, not the hook (see\n// HookSpec.matcherFor).\nexport const RULES_HOOK = new HookSpec('rules', 'Rules hook (code-style validation)', RULES_BIN);\nexport const GUARDS_HOOK = new HookSpec('guards', 'Guards hook (git/PR/branch protection)', GUARDS_BIN);\n\n/**\n * Every file the installer can write, keyed by the CHOICE a human makes.\n *\n * TWO TARGETS SHARE CHOICE `1`, and that is the design rather than an oversight: \"the project, committed,\n * for the team\" is ONE intention, and a repo that is worked on by both harnesses needs both files armed\n * to mean it. Splitting it into two questions would let a human answer them differently and end up with a\n * repo where Codex is silently unguarded — which is the state this whole change exists to end. Every\n * caller selects by choice id (`targets.filter(t => t.choice === answer)`), never by index, so adding a\n * harness adds a row and changes no numbering.\n *\n * `2` (personal) and `3` (global) stay Claude-only because neither has a Codex counterpart: Codex reads\n * one repo-local `hooks.json` and has no personal or home-scoped hook file.\n *\n * `homeDir` is injectable so tests can point the global target at a temp dir instead of the real\n * ~/.claude/settings.json (a unit test must never write the user's actual global settings).\n */\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport function installTargets(projectRoot: string, homeDir: string = homedir()): InstallTarget[] {\n return [\n new InstallTarget('1', 'project (.claude/settings.json — committed, for the team)',\n path.join(projectRoot, '.claude', 'settings.json'), false, CLAUDE_REGISTRATION),\n new InstallTarget('2', 'project for you (.claude/settings.local.json — personal)',\n path.join(projectRoot, '.claude', 'settings.local.json'), false, CLAUDE_REGISTRATION),\n new InstallTarget('3', 'global (~/.claude/settings.json — exact path, this repo only)',\n path.join(homeDir, '.claude', 'settings.json'), true, CLAUDE_REGISTRATION),\n // Given choice `1` so one answer arms the whole project — see the docblock. Its position in the\n // array carries no meaning: every caller selects by choice id.\n new InstallTarget('1', 'project, for Codex too (.codex/hooks.json — committed, for the team)',\n path.join(projectRoot, ...CODEX_REGISTRATION.settingsFiles[0].split('/')), false, CODEX_REGISTRATION),\n ];\n}\n\n// ---------------------------------------------------------------------------\n// Claude Code settings.json hook wiring.\n// ---------------------------------------------------------------------------\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport function hasHook(settings: ClaudeSettings, bin: string): boolean {\n const entries = settings.hooks?.PreToolUse ?? [];\n return entries.some((e: HookEntry) => e.hooks.some((h: HookCommand) => h.command.includes(bin)));\n}\n\n// Drop every PreToolUse command containing `marker` (a bin name, or a managed .sh path); returns true\n// if anything was removed. REMOVE-then-ADD is what keeps an upgrade from leaving a superseded spelling\n// (a relative command, or the retired L-1 entry) beside the current one — two spellings of one\n// registration is the compatibility shim the backwards-compat reviewer rejects.\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nfunction removeHookByMarker(settings: ClaudeSettings, marker: string): boolean {\n const entries = settings.hooks?.PreToolUse;\n if (!entries) return false;\n let changed = false;\n const kept: HookEntry[] = [];\n for (const entry of entries) {\n const hooks = entry.hooks.filter((h: HookCommand) => !h.command.includes(marker));\n if (hooks.length !== entry.hooks.length) changed = true;\n if (hooks.length > 0) kept.push({ matcher: entry.matcher, hooks });\n }\n if (changed) settings.hooks!.PreToolUse = kept;\n return changed;\n}\n\n// Apply the chosen install for one hook: remove it from every target file, then add it back to the\n// chosen one (or nowhere, for uninstall). Writes only the files that changed.\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport function applyHook(hook: HookSpec, chosen: InstallTarget | null, targets: InstallTarget[], projectRoot: string): void {\n // SCOPED TO THE CHOSEN HARNESS, and this is what makes one call per target composable. Installing\n // the Claude hook must not strip the Codex one, so \"remove it from everywhere else\" means everywhere\n // else THIS HARNESS could live. Uninstall (chosen === null) is the one case that means every\n // harness, because \"not installed\" has to be true everywhere or the hook is still armed somewhere.\n const scope = chosen === null ? targets : targets.filter((t: InstallTarget) => t.harness === chosen.harness);\n for (const target of scope) {\n const settings = readSettings(target.settingsPath);\n const removed = removeHookByMarker(settings, hook.bin);\n const isChosen = chosen !== null && chosen.settingsPath === target.settingsPath;\n if (isChosen) {\n addHookEntry(settings, new HookRegistrationEntry(hook.matcherFor(target), hook.commandFor(target, projectRoot)));\n // The managed `env` entry goes into the SAME file the hooks go into, on every path that\n // writes hooks — interactive or `--target=`. It pins the Bash cwd to the project root, so a\n // guard's answer depends on the command rather than on where an earlier `cd` left the shell,\n // and settings `env` is inherited, so every subagent gets the identical cwd and therefore the\n // identical guard verdict. (It no longer has a RESOLUTION job — the hooks are absolute.) See\n // hook-registration.ts for the full argument; `wp-upgrade-shim` self-heals it afterwards.\n // …in the harness that HAS that surface. Codex has no settings `env`, and needs none: its\n // cwd is MEASURED not to drift, which is the whole thing this entry buys under Claude Code.\n if (target.harness.managesEnv && applyManagedEnv(settings)) {\n console.log(` ✅ env.${BASH_CWD_ENV_KEY}=${BASH_CWD_ENV_VALUE} → ${target.label} (pins the Bash cwd to the project root, for this session and every subagent)`);\n }\n writeSettings(target.settingsPath, settings);\n console.log(` ✅ ${hook.label} → ${target.label}`);\n } else if (removed) {\n writeSettings(target.settingsPath, settings);\n }\n }\n // Manage the shared checked-in shim: (re)write it whenever a project (relative) install exists,\n // otherwise clean it up once neither hook references it anymore.\n if (chosen !== null && !chosen.absolute) {\n writeShim(projectRoot);\n // The generic PR-gate reviewer agent is part of the same committed, managed set as the shim — the\n // drift check reports it beside the shim, so the installer writes it beside the shim.\n if (writeReviewerAgent(projectRoot)) {\n console.log(` ✅ ${REVIEWER_AGENT_MARKER} (the generic PR-gate reviewer; generated — commit it, do not edit it)`);\n }\n } else if (!markerReferenced(targets, SHIM_MARKER)) {\n removeShim(projectRoot);\n }\n // The RETIRED L-1 hook rode with the GUARDS hook, so its removal does too. Doing it here rather than\n // at a separate call site means every existing caller of applyHook — the installer's interactive and\n // --target paths, and every test — converges on the two-hook absolute form with no second step.\n if (hook.bin === GUARDS_BIN) purgeRetiredGuaranteeRoot(targets, projectRoot);\n if (chosen === null) console.log(` ⛔ ${hook.label} not installed (removed from all locations).`);\n}\n\n/**\n * Say whether Codex will actually RUN what we just registered — the one thing the installer cannot do\n * anything about and therefore must not leave silent.\n *\n * Codex trusts a hook entry TOFU and re-prompts whenever its bytes change, and the prompt's third option\n * is \"Continue without trusting (hooks won't run)\". So a perfectly successful install can be followed by\n * a fully unguarded session, and the only honest thing to print is what is true plus the one action a\n * HUMAN has to take. Nothing here writes `~/.codex/config.toml` — see codex-trust.ts for why forging a\n * `trusted_hash` is not on the table.\n *\n * Silent when this repo did not arm Codex, so a Claude-only install gains no noise.\n */\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nfunction reportCodexTrust(projectRoot: string, targets: InstallTarget[], choice: string): void {\n const armed = targets.some((t: InstallTarget): boolean => t.choice === choice && t.harness === CODEX_REGISTRATION);\n if (!armed) return;\n const lines = new CodexTrustProbe().read(projectRoot).lines();\n if (lines.length === 0) return;\n console.log('');\n for (const line of lines) console.log(line);\n}\n\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nfunction currentLocation(hook: HookSpec, targets: InstallTarget[]): string {\n const here = targets.filter((t: InstallTarget) => hasHook(readSettings(t.settingsPath), hook.bin));\n return here.length === 0 ? 'none' : here.map((t: InstallTarget) => t.label.split(' (')[0]).join(', ');\n}\n\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nfunction prompt(question: string): Promise<string> {\n return new Promise((resolve: (answer: string) => void) => {\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n rl.question(question, (answer: string) => { rl.close(); resolve(answer.trim()); });\n });\n}\n\n// Map a friendly `--target` name to an InstallTarget choice id (see installTargets). Returns null\n// for an unknown name so the caller can error out. Kept separate + exported for unit testing.\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport function resolveTargetChoice(name: string): string | null {\n switch (name) {\n case 'project': return '1';\n case 'project-personal':\n case 'projectpersonal':\n case 'local': return '2';\n case 'global': return '3';\n case 'none':\n case 'uninstall': return '4';\n default: return null;\n }\n}\n\n// Extract the value of `--target=<name>` from argv (null if the flag is absent).\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport function parseTargetArg(args: string[]): string | null {\n const flag = args.find((a: string): boolean => a.startsWith('--target='));\n return flag ? flag.slice('--target='.length) : null;\n}\n\n/**\n * Apply ONE choice for one hook: every target that answer selects, or uninstall when it selects none.\n *\n * The loop is what lets one choice arm several harnesses (choice `1` writes both the Claude settings\n * file and the Codex hooks file — see installTargets). `applyHook` scopes its removals to the chosen\n * target's harness, which is what keeps these calls from undoing one another.\n */\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nexport function applyChoice(hook: HookSpec, choice: string, targets: InstallTarget[], projectRoot: string): void {\n const chosen = targets.filter((t: InstallTarget): boolean => t.choice === choice);\n if (chosen.length === 0) {\n applyHook(hook, null, targets, projectRoot);\n return;\n }\n for (const target of chosen) applyHook(hook, target, targets, projectRoot);\n}\n\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nasync function wireHook(hook: HookSpec, targets: InstallTarget[], projectRoot: string): Promise<void> {\n console.log('');\n console.log(`${hook.label}`);\n console.log(` currently installed in: ${currentLocation(hook, targets)}`);\n // The matcher is printed PER TARGET now, because it differs per harness — Codex's file tool is\n // `apply_patch`, Claude's are Write|Edit|MultiEdit — and one matcher printed above the list would be\n // wrong for whichever harness it did not describe.\n for (const target of targets) console.log(` ${target.choice}) ${target.label} [matcher: ${hook.matcherFor(target)}]`);\n console.log(' 4) none / uninstall');\n const answer = await prompt(' Where should it live? [1/2/3/4, default 4]: ');\n applyChoice(hook, answer, targets, projectRoot);\n}\n\n/**\n * Scaffold the SERVER-SIDE PR gate: the CI workflow plus the doc explaining how to turn it on.\n *\n * This lives in the installer, not the PR flow. `wp-start-upsert-pr` used to do it — printing\n * copy-to-`.github` and branch-protection instructions on EVERY run, at an agent doing feature work\n * that could not act on them anyway (marking a check required needs a repo admin). Setup is a\n * one-time, admin-shaped act, so it belongs with the other one-time setup.\n *\n * Written UNCONDITIONALLY, unlike the old version which required a `gateSalt` to already be set: the\n * whole point of the doc is to tell you to set one, so gating it on the thing it teaches meant the\n * instructions only appeared to repos that no longer needed them.\n *\n * Both land in gitignored `.webpieces/instruct-ai/`, never `.github/` directly — writing there would\n * dirty the tree, and copying it is the human's decision. `IfMissing` for the yml so a repo that has\n * customized its workflow never gets it clobbered; the doc itself is refreshed so it cannot go stale.\n */\n// webpieces-disable no-function-outside-class -- setup.ts is deliberately DI-free (it must run on a half-written node_modules; see install-entry.ts), so every function here is module-scope\nfunction scaffoldCiGate(projectRoot: string): void {\n writeTemplateIfMissing(projectRoot, 'webpieces-pr-gate.yml');\n writeTemplate(projectRoot, 'webpieces.ci-gate-setup.md');\n console.log('');\n console.log('ℹ️ Optional: server-side PR gate (stops an UNHOOKED teammate opening a PR in the web UI).');\n console.log(' It is OFF until you set a gateSalt. Three steps, one of which needs a repo admin:');\n console.log(' .webpieces/instruct-ai/webpieces.ci-gate-setup.md');\n}\n\n// webpieces-disable no-function-outside-class -- existing CLI/shim bootstrap function moved intact; it must remain callable without constructing a DI container\nexport async function main(): Promise<void> {\n const args = process.argv.slice(2);\n // Anchor the install at the repo root (git toplevel — webpieces.config.json may not exist yet on\n // a first install), never a subdir cwd, so `.webpieces`/hooks/config all land at the root.\n const projectRoot = new RepoRootFinder().resolveRepoRoot(process.cwd());\n\n seedOrSyncConfig(projectRoot);\n // Always refreshed: it explains why a retired key is rejected rather than accepted, and what to do\n // about it — which is exactly what an agent needs on the run where a migration just moved keys out\n // from under its config.\n writeTemplate(projectRoot, CONFIG_POLICY_DOC);\n\n scaffoldCiGate(projectRoot);\n\n const targets = installTargets(projectRoot);\n\n // Non-interactive: `--target=project|project-personal|global|none` installs BOTH hooks at that\n // location without prompting, so an agent or CI can run the installer unattended (e.g. after a\n // @webpieces upgrade that changed the hook entry). Omit the flag for the interactive per-hook chooser.\n const targetName = parseTargetArg(args);\n if (targetName !== null) {\n const choice = resolveTargetChoice(targetName);\n if (choice === null) {\n console.error(`❌ Unknown --target '${targetName}'. Use one of: project | project-personal | global | none`);\n process.exitCode = 1;\n return;\n }\n applyChoice(RULES_HOOK, choice, targets, projectRoot);\n applyChoice(GUARDS_HOOK, choice, targets, projectRoot);\n console.log(`\\nDone. Both hooks set to: ${targetName}.`);\n reportCodexTrust(projectRoot, targets, choice);\n return;\n }\n\n console.log('');\n console.log('Two webpieces hooks can be installed independently — choose a location for each:');\n await wireHook(RULES_HOOK, targets, projectRoot);\n await wireHook(GUARDS_HOOK, targets, projectRoot);\n // Whichever choices were made above, report Codex trust for the project choice — an interactive run\n // that armed Codex needs the same warning the --target path prints.\n reportCodexTrust(projectRoot, targets, '1');\n console.log('');\n console.log('Done. Re-run `pnpm wp-install-ai-hooks` anytime to move or uninstall a hook.');\n console.log('(Non-interactive: pnpm wp-install-ai-hooks --target=project|project-personal|global|none)');\n}\n\nif (require.main === module) {\n void main();\n}\n"]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotation threshold, in bytes — 512 KB, the SAME number and the same `.1.log` naming as
|
|
3
|
+
* decision-log.ts / rejection-log.ts / main-sync-log.ts. Deliberately identical rather than merely
|
|
4
|
+
* similar: two log families in one directory with two different retention rules is a trap for whoever
|
|
5
|
+
* later tries to reason about how much history they still have.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SHIM_LOG_MAX_BYTES: number;
|
|
8
|
+
/**
|
|
9
|
+
* One verdict label the shim can record, WITH what it means. Data-only → a class, per CLAUDE.md.
|
|
10
|
+
*
|
|
11
|
+
* The meaning travels with the label because guards/L0-tooling.md renders this table rather than
|
|
12
|
+
* restating it: a bare `string[]` left the meanings in prose, and the prose is what went stale (the
|
|
13
|
+
* hand-written doc documented `DENY-UNDECLARED` for releases while this array did not list it at all).
|
|
14
|
+
*/
|
|
15
|
+
export declare class ShimLogVerdict {
|
|
16
|
+
readonly label: string;
|
|
17
|
+
readonly means: string;
|
|
18
|
+
constructor(label: string, means: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The verdict vocabulary one shim invocation can record, and how each maps to guards/L0-tooling.md.
|
|
22
|
+
*
|
|
23
|
+
* The ALLOW-* and DENY-* labels are the ones this log has always used and are kept verbatim, so
|
|
24
|
+
* anything already grepping them keeps working. `PASS-BIN-*` is the healthy case the log used to be
|
|
25
|
+
* silent about, and `DENY-UNDECLARED` is fault U's — emitted by the shim since U existed, but missing
|
|
26
|
+
* from this array until the generated doc started reading it.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SHIM_LOG_VERDICTS: readonly ShimLogVerdict[];
|
|
29
|
+
/**
|
|
30
|
+
* The sh-side L0 fault codes, IMPORTED from the one codebook (../core/l0-fault-codes) rather than
|
|
31
|
+
* retyped here — the letters in this file and the letters in `L0_FAULTS` have to be the same letters or
|
|
32
|
+
* the log cannot be reconciled against the matrix. `-` means "no sh-side fault": the shim cannot
|
|
33
|
+
* classify S / C / Y, which the BINARY detects and stamps onto its OWN streams with the same `fault=`
|
|
34
|
+
* field, so a `-` here is a statement about this layer only, never a claim that nothing was wrong.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SHIM_LOG_FAULTS: readonly ["D", "X", "U", "K", "-"];
|
|
37
|
+
/**
|
|
38
|
+
* One FIELD of the audit line: how it reads on disk, the sh expression that produces it, and what it
|
|
39
|
+
* answers. Data-only → a class, per CLAUDE.md.
|
|
40
|
+
*/
|
|
41
|
+
export declare class ShimLogField {
|
|
42
|
+
readonly label: string;
|
|
43
|
+
/** The sh word spliced into the printf below — the ONE place this field's value is spelled. */
|
|
44
|
+
readonly shValue: string;
|
|
45
|
+
readonly means: string;
|
|
46
|
+
/**
|
|
47
|
+
* True for a field that is printed only SOMETIMES (`bin=`, and only when it differs from
|
|
48
|
+
* `shim=`). Such a field carries its OWN trailing tab in its sh value and therefore renders
|
|
49
|
+
* with NO separator of its own — `%s%s` glues it to the next field, so an empty value leaves
|
|
50
|
+
* the line one field shorter rather than leaving a stray tab behind.
|
|
51
|
+
*/
|
|
52
|
+
readonly optional: boolean;
|
|
53
|
+
constructor(label: string,
|
|
54
|
+
/** The sh word spliced into the printf below — the ONE place this field's value is spelled. */
|
|
55
|
+
shValue: string, means: string,
|
|
56
|
+
/**
|
|
57
|
+
* True for a field that is printed only SOMETIMES (`bin=`, and only when it differs from
|
|
58
|
+
* `shim=`). Such a field carries its OWN trailing tab in its sh value and therefore renders
|
|
59
|
+
* with NO separator of its own — `%s%s` glues it to the next field, so an empty value leaves
|
|
60
|
+
* the line one field shorter rather than leaving a stray tab behind.
|
|
61
|
+
*/
|
|
62
|
+
optional?: boolean);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* THE LINE, as data. The printf below is BUILT from this array and guards/L0-tooling.md RENDERS it, so
|
|
66
|
+
* a field cannot be added, dropped or reordered without both the shim and the doc changing with it.
|
|
67
|
+
*
|
|
68
|
+
* That is not decoration: `shim=`/`bin=` were inserted mid-line (deliberately breaking positional
|
|
69
|
+
* readers rather than appending where a stale parser keeps working), then `layer=`/`row=` joined them,
|
|
70
|
+
* and the hand-written doc went on describing a 7-field line with no `U` in its fault set the whole time.
|
|
71
|
+
*/
|
|
72
|
+
export declare const SHIM_LOG_FIELDS: readonly ShimLogField[];
|
|
73
|
+
/**
|
|
74
|
+
* The writer's `printf`, assembled from SHIM_LOG_FIELDS — one `%s` per field, in the same order, and a
|
|
75
|
+
* tab after every field EXCEPT an optional one (which carries its own). Retyping either half is what
|
|
76
|
+
* let the format and its documentation disagree, so neither half is retyped anywhere.
|
|
77
|
+
*/
|
|
78
|
+
export declare const SHIM_LOG_PRINTF: string;
|
|
79
|
+
/**
|
|
80
|
+
* Shell fragment: derive WHERE this call's log belongs — the sh TWIN of `DotWebpieces.local()` +
|
|
81
|
+
* `worktreeName()` + `primaryRoot()` in @webpieces/rules-config.
|
|
82
|
+
*
|
|
83
|
+
* sh cannot import TypeScript, so this derivation is duplicated by necessity; the mitigation is
|
|
84
|
+
* `shim-audit-log.spec.ts`, which runs THIS function through a real /bin/sh in real git worktrees and
|
|
85
|
+
* asserts it returns exactly what `dotWebpieces.worktreeName()` returns. If the two ever disagree the
|
|
86
|
+
* lock goes red rather than the logs quietly splitting in half.
|
|
87
|
+
*
|
|
88
|
+
* It asks git the SAME question the TS side asks — `--git-dir` vs `--git-common-dir`, which differ if
|
|
89
|
+
* and only if this is a linked worktree — but in ONE `rev-parse` (it accepts both flags and prints a
|
|
90
|
+
* line each) rather than two, because this runs on the blocking path of every tool call.
|
|
91
|
+
*
|
|
92
|
+
* The tree is derived from the PAYLOAD's `cwd` (Claude Code documents it as the working directory the
|
|
93
|
+
* hook was invoked from), not from `$ROOT`. `$ROOT` is where the shim FILE lives and stays the anchor
|
|
94
|
+
* for what the drift guard MEASURES — this fragment changes only where the log is WRITTEN.
|
|
95
|
+
*
|
|
96
|
+
* Fails soft, exactly like the TS side: when git cannot answer, the log collapses to
|
|
97
|
+
* `<cwd>/.webpieces/logs`, which is the pre-change behaviour.
|
|
98
|
+
*/
|
|
99
|
+
export declare const RESOLVE_LOG_DIR_SH = "wp_resolve_log_dir() {\n _wp_rp=\"$(git -C \"$WP_CWD\" rev-parse --git-dir --git-common-dir 2>/dev/null)\"\n _wp_gd=\"$(printf '%s\\n' \"$_wp_rp\" | sed -n 1p)\"\n _wp_cd=\"$(printf '%s\\n' \"$_wp_rp\" | sed -n 2p)\"\n if [ -z \"$_wp_gd\" ] || [ -z \"$_wp_cd\" ]; then\n WP_TREE=primary; WP_LOG_DIR=\"$WP_CWD/.webpieces/logs\"\n WP_PRIMARY_LOG_DIR=\"$WP_LOG_DIR\"; return 0\n fi\n # git prints a BARE .git from the primary clone and an absolute path from a linked worktree; the TS\n # twin runs path.resolve(cwd, printed), so do the same before comparing or taking a basename.\n case \"$_wp_gd\" in /*) : ;; *) _wp_gd=\"$WP_CWD/$_wp_gd\" ;; esac\n case \"$_wp_cd\" in /*) : ;; *) _wp_cd=\"$WP_CWD/$_wp_cd\" ;; esac\n # The primary clone's root is the parent of the SHARED git dir \u2014 declining any layout whose shared\n # dir is not named .git (a bare repo, --separate-git-dir), same test as primaryRoot().\n _wp_primary=\"$WP_CWD\"\n case \"$_wp_cd\" in\n */.git) [ -d \"${_wp_cd%/*}\" ] && _wp_primary=\"${_wp_cd%/*}\" ;;\n esac\n # The PRIMARY clone's log dir, resolved on both branches. A deny that has to tell a human WHERE the\n # audit trail is (the inverse-drift escalation in shim.ts) must be able to name both the tree it is\n # standing in and the primary \u2014 a subagent has no reach into the second one, so the deny has to quote\n # that path rather than send anyone to go and look.\n WP_PRIMARY_LOG_DIR=\"$_wp_primary/.webpieces/logs\"\n if [ \"$_wp_gd\" = \"$_wp_cd\" ]; then\n WP_TREE=primary\n WP_LOG_DIR=\"$WP_PRIMARY_LOG_DIR\"\n else\n # git's OWN name for the worktree (the basename of <primary>/.git/worktrees/<name>), not the\n # directory's basename \u2014 two worktrees under different parents may share a directory name.\n WP_TREE=\"${_wp_gd##*/}\"\n WP_LOG_DIR=\"$_wp_primary/.webpieces/worktrees/$WP_TREE/logs\"\n fi\n}";
|
|
100
|
+
/**
|
|
101
|
+
* Shell fragment: the audit-log writer itself — `wp_log <fault> <verdict>`, one tab-separated line.
|
|
102
|
+
*
|
|
103
|
+
* FORMAT: SHIM_LOG_FIELDS, tab-separated, append-only — that array IS the format, and SHIM_LOG_PRINTF
|
|
104
|
+
* is built from it, so neither this docblock nor guards/L0-tooling.md can describe a line the shim does
|
|
105
|
+
* not write.
|
|
106
|
+
*
|
|
107
|
+
* `tree=` and `fault=` are the two fields that make the file reconcilable against guards/L0-tooling.md:
|
|
108
|
+
* the first says WHICH checkout produced the line (a shared log across seven worktrees is otherwise
|
|
109
|
+
* unreadable), the second says which of the sh-side faults the shim detected. The verdict
|
|
110
|
+
* keeps its historical spelling and stays adjacent to the command, so `grep 'DENY-STALE\\t'` still
|
|
111
|
+
* finds what it always found.
|
|
112
|
+
*
|
|
113
|
+
* NEVER breaks or blocks the hook: the whole body is wrapped so a failure of any kind — unwritable
|
|
114
|
+
* directory, read-only filesystem, missing `git` — is swallowed, and nothing is ever written to
|
|
115
|
+
* stdout (stdout is the PreToolUse decision channel; a stray byte there corrupts allow/deny).
|
|
116
|
+
*
|
|
117
|
+
* The log dir is resolved LAZILY on first use so a call that never logs never pays for the git probe.
|
|
118
|
+
*/
|
|
119
|
+
export declare const WP_LOG_SH: string;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WP_LOG_SH = exports.RESOLVE_LOG_DIR_SH = exports.SHIM_LOG_PRINTF = exports.SHIM_LOG_FIELDS = exports.ShimLogField = exports.SHIM_LOG_FAULTS = exports.SHIM_LOG_VERDICTS = exports.ShimLogVerdict = exports.SHIM_LOG_MAX_BYTES = void 0;
|
|
4
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
5
|
+
const log_streams_1 = require("../core/log-streams");
|
|
6
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
7
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// THE L0 AUDIT LOG, in POSIX sh — the shim half of
|
|
10
|
+
// `.webpieces/**/logs/L0-shim/<session>-<agent|coordinator>-<binName>.log`. The writer key is
|
|
11
|
+
// the sh twin of agent-workflow-rules' LogStream.writerFile(): wp-ai-guards-hook and wp-ai-rules-hook are run
|
|
12
|
+
// IN PARALLEL by Claude Code on every file edit, so an unsplit name means two writers, one file, and
|
|
13
|
+
// torn appends above PIPE_BUF. A payload with no session_id renders 'unknown', never a bare name —
|
|
14
|
+
// there is no un-prefixed spelling on either side.
|
|
15
|
+
//
|
|
16
|
+
// Split out of ./shim.ts (which renders the shim body) purely so both stay readable; shim.ts splices
|
|
17
|
+
// these fragments in verbatim and re-exports the constants. Like l0-allowlist.ts, this module must
|
|
18
|
+
// stay dependency-light: the shim it renders has to work on a tree too broken to load the rule engine.
|
|
19
|
+
//
|
|
20
|
+
// ─── What changed, and why it is not just a bigger log ─────────────────────────────────────────────
|
|
21
|
+
// This log used to be a FAULT log wearing an audit log's name. `wp_log` fired only on the fail-closed
|
|
22
|
+
// path (ALLOW-READ / ALLOW-CONFIG / ALLOW-CURE / DENY*), so a HEALTHY call — the overwhelming majority
|
|
23
|
+
// — exec'd the bin and recorded nothing at all. You could therefore never answer "what did L0 do to
|
|
24
|
+
// this tool call?", only "what did L0 do on the calls where L0 was already broken". Absence of a line
|
|
25
|
+
// meant either "healthy" or "the shim never ran", and those are the two answers you most need to tell
|
|
26
|
+
// apart. Every path now logs exactly one line, including the pass-through, so the file can be diffed
|
|
27
|
+
// against the documented matrix in guards/L0-tooling.md rather than merely spot-checked.
|
|
28
|
+
//
|
|
29
|
+
// Two more defects went with it:
|
|
30
|
+
// • it wrote to a hardcoded `$ROOT/.webpieces/logs`, so every worktree's lines landed in one flat
|
|
31
|
+
// file (or, worse, in whichever tree happened to hold the shim) instead of the per-tree namespace
|
|
32
|
+
// the L1 binary has used since the state-dir split;
|
|
33
|
+
// • it had NO rotation, on a file now written on EVERY tool call.
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/**
|
|
36
|
+
* Rotation threshold, in bytes — 512 KB, the SAME number and the same `.1.log` naming as
|
|
37
|
+
* decision-log.ts / rejection-log.ts / main-sync-log.ts. Deliberately identical rather than merely
|
|
38
|
+
* similar: two log families in one directory with two different retention rules is a trap for whoever
|
|
39
|
+
* later tries to reason about how much history they still have.
|
|
40
|
+
*/
|
|
41
|
+
exports.SHIM_LOG_MAX_BYTES = 512 * 1024;
|
|
42
|
+
/**
|
|
43
|
+
* One verdict label the shim can record, WITH what it means. Data-only → a class, per CLAUDE.md.
|
|
44
|
+
*
|
|
45
|
+
* The meaning travels with the label because guards/L0-tooling.md renders this table rather than
|
|
46
|
+
* restating it: a bare `string[]` left the meanings in prose, and the prose is what went stale (the
|
|
47
|
+
* hand-written doc documented `DENY-UNDECLARED` for releases while this array did not list it at all).
|
|
48
|
+
*/
|
|
49
|
+
class ShimLogVerdict {
|
|
50
|
+
label;
|
|
51
|
+
means;
|
|
52
|
+
constructor(label, means) {
|
|
53
|
+
this.label = label;
|
|
54
|
+
this.means = means;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ShimLogVerdict = ShimLogVerdict;
|
|
58
|
+
/**
|
|
59
|
+
* The verdict vocabulary one shim invocation can record, and how each maps to guards/L0-tooling.md.
|
|
60
|
+
*
|
|
61
|
+
* The ALLOW-* and DENY-* labels are the ones this log has always used and are kept verbatim, so
|
|
62
|
+
* anything already grepping them keeps working. `PASS-BIN-*` is the healthy case the log used to be
|
|
63
|
+
* silent about, and `DENY-UNDECLARED` is fault U's — emitted by the shim since U existed, but missing
|
|
64
|
+
* from this array until the generated doc started reading it.
|
|
65
|
+
*/
|
|
66
|
+
exports.SHIM_LOG_VERDICTS = [
|
|
67
|
+
new ShimLogVerdict('PASS-BIN-ALLOW', 'no sh-side fault; the bin ran and exited 0 — matrix row 1, handed down to L1'),
|
|
68
|
+
new ShimLogVerdict('PASS-BIN-BLOCK', 'no sh-side fault; the bin ran and exited 2 — matrix row 1, a LATER layer blocked'),
|
|
69
|
+
new ShimLogVerdict('ALLOW-READ', 'allowlist entry 1 (any Read) — PASS, but terminal here (the bin never ran)'),
|
|
70
|
+
new ShimLogVerdict('ALLOW-IGNORED', 'a Codex tool with nothing to judge (L0_IGNORED_TOOLS) — PASS, terminal here'),
|
|
71
|
+
new ShimLogVerdict('ALLOW-CODEX-READ', 'the harness-gated entry: a read-shaped Bash command on CODEX, which has no Read tool — PASS, terminal here. '
|
|
72
|
+
+ 'It cannot appear on a claude-code line; if one ever does, the sh harness test (AI_TYPE_SH) misread the payload'),
|
|
73
|
+
new ShimLogVerdict('ALLOW-CONFIG', 'allowlist entry 2 (a Write/Edit of webpieces.config.json) — PASS, terminal here'),
|
|
74
|
+
new ShimLogVerdict('ALLOW-MANIFEST', 'allowlist entry 3 (a Write/Edit of pnpm-workspace.yaml or package.json) — PASS, terminal here'),
|
|
75
|
+
new ShimLogVerdict('ALLOW-CURE', 'a Bash entry of the allowlist matched — ALLOW'),
|
|
76
|
+
new ShimLogVerdict('DENY', 'fault X, not on the allowlist — BLOCK_AI_CURE'),
|
|
77
|
+
new ShimLogVerdict('DENY-UNDECLARED', 'fault U, not on the allowlist — BLOCK_AI_CURE'),
|
|
78
|
+
new ShimLogVerdict('DENY-STALE', 'fault D, not on the allowlist — BLOCK_AI_CURE'),
|
|
79
|
+
new ShimLogVerdict('DENY-BROKEN', 'fault K, not on the allowlist — BLOCK_AI_CURE'),
|
|
80
|
+
];
|
|
81
|
+
/**
|
|
82
|
+
* The sh-side L0 fault codes, IMPORTED from the one codebook (../core/l0-fault-codes) rather than
|
|
83
|
+
* retyped here — the letters in this file and the letters in `L0_FAULTS` have to be the same letters or
|
|
84
|
+
* the log cannot be reconciled against the matrix. `-` means "no sh-side fault": the shim cannot
|
|
85
|
+
* classify S / C / Y, which the BINARY detects and stamps onto its OWN streams with the same `fault=`
|
|
86
|
+
* field, so a `-` here is a statement about this layer only, never a claim that nothing was wrong.
|
|
87
|
+
*/
|
|
88
|
+
exports.SHIM_LOG_FAULTS = [...rules_config_1.L0_SH_FAULT_CODES, rules_config_1.L0_FAULT_NONE];
|
|
89
|
+
/**
|
|
90
|
+
* One FIELD of the audit line: how it reads on disk, the sh expression that produces it, and what it
|
|
91
|
+
* answers. Data-only → a class, per CLAUDE.md.
|
|
92
|
+
*/
|
|
93
|
+
class ShimLogField {
|
|
94
|
+
label;
|
|
95
|
+
shValue;
|
|
96
|
+
means;
|
|
97
|
+
optional;
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
99
|
+
constructor(label,
|
|
100
|
+
/** The sh word spliced into the printf below — the ONE place this field's value is spelled. */
|
|
101
|
+
shValue, means,
|
|
102
|
+
/**
|
|
103
|
+
* True for a field that is printed only SOMETIMES (`bin=`, and only when it differs from
|
|
104
|
+
* `shim=`). Such a field carries its OWN trailing tab in its sh value and therefore renders
|
|
105
|
+
* with NO separator of its own — `%s%s` glues it to the next field, so an empty value leaves
|
|
106
|
+
* the line one field shorter rather than leaving a stray tab behind.
|
|
107
|
+
*/
|
|
108
|
+
optional = false) {
|
|
109
|
+
this.label = label;
|
|
110
|
+
this.shValue = shValue;
|
|
111
|
+
this.means = means;
|
|
112
|
+
this.optional = optional;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.ShimLogField = ShimLogField;
|
|
116
|
+
/**
|
|
117
|
+
* THE LINE, as data. The printf below is BUILT from this array and guards/L0-tooling.md RENDERS it, so
|
|
118
|
+
* a field cannot be added, dropped or reordered without both the shim and the doc changing with it.
|
|
119
|
+
*
|
|
120
|
+
* That is not decoration: `shim=`/`bin=` were inserted mid-line (deliberately breaking positional
|
|
121
|
+
* readers rather than appending where a stale parser keeps working), then `layer=`/`row=` joined them,
|
|
122
|
+
* and the hand-written doc went on describing a 7-field line with no `U` in its fault set the whole time.
|
|
123
|
+
*/
|
|
124
|
+
exports.SHIM_LOG_FIELDS = [
|
|
125
|
+
new ShimLogField('<iso-ts>', `"$(date '+%Y-%m-%dT%H:%M:%S%z' 2>/dev/null)"`, 'when the shim judged the call, local time with offset'),
|
|
126
|
+
new ShimLogField('<bin-name>', '"$BIN_NAME"', 'WHICH hook ran - wp-ai-guards-hook or wp-ai-rules-hook; Claude Code runs them in parallel'),
|
|
127
|
+
new ShimLogField('<tool>', '"$TOOL"', 'the PreToolUse tool name (Bash, Read, Write, Edit, apply_patch, …)'),
|
|
128
|
+
// WHICH HARNESS. Inserted MID-LINE rather than appended, which is this format's house style and is
|
|
129
|
+
// deliberate: a positional reader that has not been updated fails loudly here instead of silently
|
|
130
|
+
// reading the wrong column forever (see this array's own header). The values are the `AiType`
|
|
131
|
+
// union's, produced by AI_TYPE_SH — one vocabulary across all five streams. A row written before
|
|
132
|
+
// this field existed simply has no `ai=`, which reads as `unknown`; that is a real value, not a
|
|
133
|
+
// compatibility shim.
|
|
134
|
+
new ShimLogField(`ai=<${hook_runtime_1.AI_TYPES.join('|')}>`, '"ai=$AI"', 'WHICH coding agent made the call, from the one turn_id discriminator (adapters/detect-ai.ts)'),
|
|
135
|
+
new ShimLogField('tree=<name|primary>', '"tree=$WP_TREE"', 'git\'s own name for the worktree the CALL was made in, derived from the payload\'s cwd'),
|
|
136
|
+
new ShimLogField(`layer=${rules_config_1.L0_LAYER}`, `"layer=${rules_config_1.L0_LAYER}"`, 'the layer that judged it — constant here, and the first half of the join key a deny cites'),
|
|
137
|
+
new ShimLogField(`row=<${rules_config_1.L0_ROW_HANDED_DOWN}|${rules_config_1.L0_ROW_ALLOWLISTED}|${rules_config_1.L0_ROW_BLOCKED}>`, '"row=$_wp_row"', 'WHICH row of the three-row matrix this call took, read off the verdict (hand-down / allowlisted / blocked)'),
|
|
138
|
+
new ShimLogField('shim=<root>', '"shim=$ROOT"', 'WHICH COPY of ai-hook.sh ran, resolved from $0 — against tree= it is the straddle detector'),
|
|
139
|
+
new ShimLogField('bin=<root>', '"$_wp_bin"', 'WHICH TREE supplied the binary — printed ONLY when it differs from shim=, so its presence IS the borrow', true),
|
|
140
|
+
new ShimLogField(`fault=<${exports.SHIM_LOG_FAULTS.join('|')}>`, '"fault=$1"', 'the sh-side L0 fault, or `-`; S/C/Y are the binary\'s and are stamped on ITS streams'),
|
|
141
|
+
new ShimLogField('<VERDICT>', '"$2"', 'one of the verdict labels below — kept adjacent to the command'),
|
|
142
|
+
new ShimLogField('<command>', '"$CMD_LOG"', 'the command PREFIX (the audit spelling; the DECISION reads $CMD, which fails closed on a quote)'),
|
|
143
|
+
];
|
|
144
|
+
/**
|
|
145
|
+
* The writer's `printf`, assembled from SHIM_LOG_FIELDS — one `%s` per field, in the same order, and a
|
|
146
|
+
* tab after every field EXCEPT an optional one (which carries its own). Retyping either half is what
|
|
147
|
+
* let the format and its documentation disagree, so neither half is retyped anywhere.
|
|
148
|
+
*/
|
|
149
|
+
exports.SHIM_LOG_PRINTF = `printf '${exports.SHIM_LOG_FIELDS.map((f, i) => '%s' + (i === exports.SHIM_LOG_FIELDS.length - 1 ? '' : (f.optional ? '' : '\\t'))).join('')}\\n' `
|
|
150
|
+
+ `${exports.SHIM_LOG_FIELDS.map((f) => f.shValue).join(' ')} >> "$_wp_f"`;
|
|
151
|
+
/**
|
|
152
|
+
* Shell fragment: derive WHERE this call's log belongs — the sh TWIN of `DotWebpieces.local()` +
|
|
153
|
+
* `worktreeName()` + `primaryRoot()` in @webpieces/rules-config.
|
|
154
|
+
*
|
|
155
|
+
* sh cannot import TypeScript, so this derivation is duplicated by necessity; the mitigation is
|
|
156
|
+
* `shim-audit-log.spec.ts`, which runs THIS function through a real /bin/sh in real git worktrees and
|
|
157
|
+
* asserts it returns exactly what `dotWebpieces.worktreeName()` returns. If the two ever disagree the
|
|
158
|
+
* lock goes red rather than the logs quietly splitting in half.
|
|
159
|
+
*
|
|
160
|
+
* It asks git the SAME question the TS side asks — `--git-dir` vs `--git-common-dir`, which differ if
|
|
161
|
+
* and only if this is a linked worktree — but in ONE `rev-parse` (it accepts both flags and prints a
|
|
162
|
+
* line each) rather than two, because this runs on the blocking path of every tool call.
|
|
163
|
+
*
|
|
164
|
+
* The tree is derived from the PAYLOAD's `cwd` (Claude Code documents it as the working directory the
|
|
165
|
+
* hook was invoked from), not from `$ROOT`. `$ROOT` is where the shim FILE lives and stays the anchor
|
|
166
|
+
* for what the drift guard MEASURES — this fragment changes only where the log is WRITTEN.
|
|
167
|
+
*
|
|
168
|
+
* Fails soft, exactly like the TS side: when git cannot answer, the log collapses to
|
|
169
|
+
* `<cwd>/.webpieces/logs`, which is the pre-change behaviour.
|
|
170
|
+
*/
|
|
171
|
+
exports.RESOLVE_LOG_DIR_SH = `wp_resolve_log_dir() {
|
|
172
|
+
_wp_rp="$(git -C "$WP_CWD" rev-parse --git-dir --git-common-dir 2>/dev/null)"
|
|
173
|
+
_wp_gd="$(printf '%s\\n' "$_wp_rp" | sed -n 1p)"
|
|
174
|
+
_wp_cd="$(printf '%s\\n' "$_wp_rp" | sed -n 2p)"
|
|
175
|
+
if [ -z "$_wp_gd" ] || [ -z "$_wp_cd" ]; then
|
|
176
|
+
WP_TREE=primary; WP_LOG_DIR="$WP_CWD/${tooling_common_1.WEBPIECES_TMP_DIR}/${tooling_common_1.LOGS_STATE_DIR}"
|
|
177
|
+
WP_PRIMARY_LOG_DIR="$WP_LOG_DIR"; return 0
|
|
178
|
+
fi
|
|
179
|
+
# git prints a BARE .git from the primary clone and an absolute path from a linked worktree; the TS
|
|
180
|
+
# twin runs path.resolve(cwd, printed), so do the same before comparing or taking a basename.
|
|
181
|
+
case "$_wp_gd" in /*) : ;; *) _wp_gd="$WP_CWD/$_wp_gd" ;; esac
|
|
182
|
+
case "$_wp_cd" in /*) : ;; *) _wp_cd="$WP_CWD/$_wp_cd" ;; esac
|
|
183
|
+
# The primary clone's root is the parent of the SHARED git dir — declining any layout whose shared
|
|
184
|
+
# dir is not named .git (a bare repo, --separate-git-dir), same test as primaryRoot().
|
|
185
|
+
_wp_primary="$WP_CWD"
|
|
186
|
+
case "$_wp_cd" in
|
|
187
|
+
*/.git) [ -d "\${_wp_cd%/*}" ] && _wp_primary="\${_wp_cd%/*}" ;;
|
|
188
|
+
esac
|
|
189
|
+
# The PRIMARY clone's log dir, resolved on both branches. A deny that has to tell a human WHERE the
|
|
190
|
+
# audit trail is (the inverse-drift escalation in shim.ts) must be able to name both the tree it is
|
|
191
|
+
# standing in and the primary — a subagent has no reach into the second one, so the deny has to quote
|
|
192
|
+
# that path rather than send anyone to go and look.
|
|
193
|
+
WP_PRIMARY_LOG_DIR="$_wp_primary/${tooling_common_1.WEBPIECES_TMP_DIR}/${tooling_common_1.LOGS_STATE_DIR}"
|
|
194
|
+
if [ "$_wp_gd" = "$_wp_cd" ]; then
|
|
195
|
+
WP_TREE=primary
|
|
196
|
+
WP_LOG_DIR="$WP_PRIMARY_LOG_DIR"
|
|
197
|
+
else
|
|
198
|
+
# git's OWN name for the worktree (the basename of <primary>/.git/worktrees/<name>), not the
|
|
199
|
+
# directory's basename — two worktrees under different parents may share a directory name.
|
|
200
|
+
WP_TREE="\${_wp_gd##*/}"
|
|
201
|
+
WP_LOG_DIR="$_wp_primary/${tooling_common_1.WEBPIECES_TMP_DIR}/${tooling_common_1.WORKTREE_STATE_DIR}/$WP_TREE/${tooling_common_1.LOGS_STATE_DIR}"
|
|
202
|
+
fi
|
|
203
|
+
}`;
|
|
204
|
+
/**
|
|
205
|
+
* Shell fragment: the audit-log writer itself — `wp_log <fault> <verdict>`, one tab-separated line.
|
|
206
|
+
*
|
|
207
|
+
* FORMAT: SHIM_LOG_FIELDS, tab-separated, append-only — that array IS the format, and SHIM_LOG_PRINTF
|
|
208
|
+
* is built from it, so neither this docblock nor guards/L0-tooling.md can describe a line the shim does
|
|
209
|
+
* not write.
|
|
210
|
+
*
|
|
211
|
+
* `tree=` and `fault=` are the two fields that make the file reconcilable against guards/L0-tooling.md:
|
|
212
|
+
* the first says WHICH checkout produced the line (a shared log across seven worktrees is otherwise
|
|
213
|
+
* unreadable), the second says which of the sh-side faults the shim detected. The verdict
|
|
214
|
+
* keeps its historical spelling and stays adjacent to the command, so `grep 'DENY-STALE\\t'` still
|
|
215
|
+
* finds what it always found.
|
|
216
|
+
*
|
|
217
|
+
* NEVER breaks or blocks the hook: the whole body is wrapped so a failure of any kind — unwritable
|
|
218
|
+
* directory, read-only filesystem, missing `git` — is swallowed, and nothing is ever written to
|
|
219
|
+
* stdout (stdout is the PreToolUse decision channel; a stray byte there corrupts allow/deny).
|
|
220
|
+
*
|
|
221
|
+
* The log dir is resolved LAZILY on first use so a call that never logs never pays for the git probe.
|
|
222
|
+
*/
|
|
223
|
+
exports.WP_LOG_SH = `WP_TREE=""
|
|
224
|
+
WP_LOG_DIR=""
|
|
225
|
+
WP_PRIMARY_LOG_DIR=""
|
|
226
|
+
WP_TAB="$(printf '\\t')" # one real tab, so the OPTIONAL bin= field can carry its own separator
|
|
227
|
+
${exports.RESOLVE_LOG_DIR_SH}
|
|
228
|
+
wp_clean() { # one path segment from an UNTRUSTED payload id — twin of LogStream's segment()
|
|
229
|
+
printf '%s' "$1" | tr -c 'A-Za-z0-9._-' '_' | sed -e 's/\\.\\{2,\\}/_/g' -e 's/^\\.\\{1,\\}/_/' | cut -c1-64
|
|
230
|
+
}
|
|
231
|
+
wp_log() { # $1 = L0 fault code (D|X|K|-), $2 = verdict label
|
|
232
|
+
{
|
|
233
|
+
[ -n "$WP_LOG_DIR" ] || wp_resolve_log_dir
|
|
234
|
+
# The LAYER is the directory and the WRITER is the file — same layout the TS writers use, spelled
|
|
235
|
+
# from the same constant so the two halves cannot drift apart.
|
|
236
|
+
_wp_sd="$WP_LOG_DIR/${log_streams_1.L0_SHIM_STREAM}"
|
|
237
|
+
mkdir -p "$_wp_sd" 2>/dev/null || return 0
|
|
238
|
+
# Same writer key as LogStream.writerFile(): <session>-<agent|coordinator>-<hook>.log. $BIN_NAME
|
|
239
|
+
# IS the hook discriminator here (wp-ai-guards-hook vs wp-ai-rules-hook), and Claude Code runs those
|
|
240
|
+
# two IN PARALLEL on every file edit — without this prefix they append to ONE file and tear above
|
|
241
|
+
# PIPE_BUF. An empty session id renders 'unknown' — this has no bare-name branch, matching
|
|
242
|
+
# LogStream.writerFile(), which has none either.
|
|
243
|
+
# ALWAYS prefixed - a missing session_id renders as 'unknown', never as the shared bare name.
|
|
244
|
+
# Gating this on a non-empty id would drop both parallel hooks back onto one file, which is the
|
|
245
|
+
# torn-append case this exists to remove. Twin of LogStream.writerFile(), which has no bare branch.
|
|
246
|
+
_wp_pfx="$(wp_clean "\${WP_SID:-unknown}")-$(wp_clean "\${WP_AID:-coordinator}")-$BIN_NAME"
|
|
247
|
+
_wp_f="$_wp_sd/\${_wp_pfx}.log"
|
|
248
|
+
# Rotate at the SAME 512 KB into the SAME .1.log sibling as every JS-side webpieces log. This runs
|
|
249
|
+
# on every tool call, so it is one wc and no more; a size we cannot read counts as 0 (no rotation).
|
|
250
|
+
_wp_sz="$(wc -c < "$_wp_f" 2>/dev/null | tr -d ' ')"
|
|
251
|
+
case "$_wp_sz" in ''|*[!0-9]*) _wp_sz=0 ;; esac
|
|
252
|
+
[ "$_wp_sz" -gt ${String(exports.SHIM_LOG_MAX_BYTES)} ] && mv -f "$_wp_f" "$_wp_sd/\${_wp_pfx}.1.log" 2>/dev/null
|
|
253
|
+
# shim= and bin= are the two facts this log could not previously answer, and they are the ones that
|
|
254
|
+
# decide whether a tree was governed by its OWN release or a borrowed one:
|
|
255
|
+
# shim= WHICH COPY OF ai-hook.sh RAN — $ROOT, resolved from $0. The file is TRACKED, so every
|
|
256
|
+
# worktree carries the version at ITS commit; settings.json registers it ABSOLUTE, so the copy
|
|
257
|
+
# that runs is the SESSION ROOT's. Logged rather than assumed, on EVERY line: compared against
|
|
258
|
+
# tree= it is the STRADDLE detector (tree=agent-X shim=<repo> = standing in one tree, judged by
|
|
259
|
+
# another), and that pair varies constantly.
|
|
260
|
+
# bin= WHICH TREE SUPPLIED THE BINARY — $BIN_ROOT, the upward walk's answer.
|
|
261
|
+
#
|
|
262
|
+
# bin= IS PRINTED ONLY WHEN IT DIFFERS FROM shim=, so its mere PRESENCE is the diagnostic ("the binary
|
|
263
|
+
# came from a different tree than the shim") instead of ~50 bytes repeated on every line. Measured
|
|
264
|
+
# across 549 logged lines: it differed on 39, every one a worktree agent's first few calls before it
|
|
265
|
+
# ran pnpm install — after that they matched for the rest of that agent's life. And since the hooks
|
|
266
|
+
# went ABSOLUTE, shim= is always the MAIN tree, so the two can now only differ when the main tree
|
|
267
|
+
# itself has no node_modules (a fresh clone before install). ~7% of lines then, near 0% going forward.
|
|
268
|
+
# A unit test asserts the field appears if and only if the roots differ, so it cannot quietly become
|
|
269
|
+
# unconditional noise again.
|
|
270
|
+
_wp_bin=""
|
|
271
|
+
[ "$BIN_ROOT" != "$ROOT" ] && _wp_bin="bin=$BIN_ROOT$WP_TAB"
|
|
272
|
+
# layer= and row= are the JOIN KEYS, and they are here so the join is REAL rather than promised.
|
|
273
|
+
# Every L0 deny now opens '[<guard>] (layer=L0 fault=<code> row=<n>)' and cites "the same coordinates
|
|
274
|
+
# the audit line carries" — which was true of the JS half (MATRIX_L0_BLOCK, via decision-log) and
|
|
275
|
+
# FALSE of this one, which carried 'fault=' alone. Fixing the message instead of the line would have
|
|
276
|
+
# left 'grep 'layer=L0 row=3'' finding one half of L0 and silently missing the other four faults.
|
|
277
|
+
#
|
|
278
|
+
# 'row=' is NOT a constant: it is the row of the three-row matrix this call actually took, read off
|
|
279
|
+
# the verdict — hand-down, allowlisted, or blocked — exactly as L1 logs 'row=' from L1_ROWS. That is
|
|
280
|
+
# what distinguishes it from the ~50 constant bytes 'bin=' used to spend above.
|
|
281
|
+
_wp_row=${rules_config_1.L0_ROW_HANDED_DOWN}
|
|
282
|
+
case "$2" in ALLOW*) _wp_row=${rules_config_1.L0_ROW_ALLOWLISTED} ;; DENY*) _wp_row=${rules_config_1.L0_ROW_BLOCKED} ;; esac
|
|
283
|
+
${exports.SHIM_LOG_PRINTF}
|
|
284
|
+
} 2>/dev/null || true
|
|
285
|
+
}`;
|
|
286
|
+
//# sourceMappingURL=shim-audit-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shim-audit-log.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/shim-audit-log.ts"],"names":[],"mappings":";;;AAAA,8D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;;;;;;;;;;;;;;;;;;cA6BlC,iCAAkB;mCACG,iCAAkB,sBAAsB,6BAAc;MACnF,uBAAe;;EAEnB,CAAC","sourcesContent":["import { LOGS_STATE_DIR, WORKTREE_STATE_DIR, WEBPIECES_TMP_DIR } from '@webpieces/tooling-common';\nimport { L0_SHIM_STREAM } from '../core/log-streams';\nimport { AI_TYPES } from '@webpieces/hook-runtime';\n\nimport { L0_FAULT_NONE, L0_LAYER, L0_SH_FAULT_CODES, L0_ROW_ALLOWLISTED, L0_ROW_BLOCKED, L0_ROW_HANDED_DOWN } from '@webpieces/rules-config';\n\n// ---------------------------------------------------------------------------\n// THE L0 AUDIT LOG, in POSIX sh — the shim half of\n// `.webpieces/**/logs/L0-shim/<session>-<agent|coordinator>-<binName>.log`. The writer key is\n// the sh twin of agent-workflow-rules' LogStream.writerFile(): wp-ai-guards-hook and wp-ai-rules-hook are run\n// IN PARALLEL by Claude Code on every file edit, so an unsplit name means two writers, one file, and\n// torn appends above PIPE_BUF. A payload with no session_id renders 'unknown', never a bare name —\n// there is no un-prefixed spelling on either side.\n//\n// Split out of ./shim.ts (which renders the shim body) purely so both stay readable; shim.ts splices\n// these fragments in verbatim and re-exports the constants. Like l0-allowlist.ts, this module must\n// stay dependency-light: the shim it renders has to work on a tree too broken to load the rule engine.\n//\n// ─── What changed, and why it is not just a bigger log ─────────────────────────────────────────────\n// This log used to be a FAULT log wearing an audit log's name. `wp_log` fired only on the fail-closed\n// path (ALLOW-READ / ALLOW-CONFIG / ALLOW-CURE / DENY*), so a HEALTHY call — the overwhelming majority\n// — exec'd the bin and recorded nothing at all. You could therefore never answer \"what did L0 do to\n// this tool call?\", only \"what did L0 do on the calls where L0 was already broken\". Absence of a line\n// meant either \"healthy\" or \"the shim never ran\", and those are the two answers you most need to tell\n// apart. Every path now logs exactly one line, including the pass-through, so the file can be diffed\n// against the documented matrix in guards/L0-tooling.md rather than merely spot-checked.\n//\n// Two more defects went with it:\n// • it wrote to a hardcoded `$ROOT/.webpieces/logs`, so every worktree's lines landed in one flat\n// file (or, worse, in whichever tree happened to hold the shim) instead of the per-tree namespace\n// the L1 binary has used since the state-dir split;\n// • it had NO rotation, on a file now written on EVERY tool call.\n// ---------------------------------------------------------------------------\n\n/**\n * Rotation threshold, in bytes — 512 KB, the SAME number and the same `.1.log` naming as\n * decision-log.ts / rejection-log.ts / main-sync-log.ts. Deliberately identical rather than merely\n * similar: two log families in one directory with two different retention rules is a trap for whoever\n * later tries to reason about how much history they still have.\n */\nexport const SHIM_LOG_MAX_BYTES = 512 * 1024;\n\n/**\n * One verdict label the shim can record, WITH what it means. Data-only → a class, per CLAUDE.md.\n *\n * The meaning travels with the label because guards/L0-tooling.md renders this table rather than\n * restating it: a bare `string[]` left the meanings in prose, and the prose is what went stale (the\n * hand-written doc documented `DENY-UNDECLARED` for releases while this array did not list it at all).\n */\nexport class ShimLogVerdict {\n constructor(\n readonly label: string,\n readonly means: string,\n ) {}\n}\n\n/**\n * The verdict vocabulary one shim invocation can record, and how each maps to guards/L0-tooling.md.\n *\n * The ALLOW-* and DENY-* labels are the ones this log has always used and are kept verbatim, so\n * anything already grepping them keeps working. `PASS-BIN-*` is the healthy case the log used to be\n * silent about, and `DENY-UNDECLARED` is fault U's — emitted by the shim since U existed, but missing\n * from this array until the generated doc started reading it.\n */\nexport const SHIM_LOG_VERDICTS: readonly ShimLogVerdict[] = [\n new ShimLogVerdict('PASS-BIN-ALLOW', 'no sh-side fault; the bin ran and exited 0 — matrix row 1, handed down to L1'),\n new ShimLogVerdict('PASS-BIN-BLOCK', 'no sh-side fault; the bin ran and exited 2 — matrix row 1, a LATER layer blocked'),\n new ShimLogVerdict('ALLOW-READ', 'allowlist entry 1 (any Read) — PASS, but terminal here (the bin never ran)'),\n new ShimLogVerdict('ALLOW-IGNORED', 'a Codex tool with nothing to judge (L0_IGNORED_TOOLS) — PASS, terminal here'),\n new ShimLogVerdict('ALLOW-CODEX-READ',\n 'the harness-gated entry: a read-shaped Bash command on CODEX, which has no Read tool — PASS, terminal here. '\n + 'It cannot appear on a claude-code line; if one ever does, the sh harness test (AI_TYPE_SH) misread the payload'),\n new ShimLogVerdict('ALLOW-CONFIG', 'allowlist entry 2 (a Write/Edit of webpieces.config.json) — PASS, terminal here'),\n new ShimLogVerdict('ALLOW-MANIFEST', 'allowlist entry 3 (a Write/Edit of pnpm-workspace.yaml or package.json) — PASS, terminal here'),\n new ShimLogVerdict('ALLOW-CURE', 'a Bash entry of the allowlist matched — ALLOW'),\n new ShimLogVerdict('DENY', 'fault X, not on the allowlist — BLOCK_AI_CURE'),\n new ShimLogVerdict('DENY-UNDECLARED', 'fault U, not on the allowlist — BLOCK_AI_CURE'),\n new ShimLogVerdict('DENY-STALE', 'fault D, not on the allowlist — BLOCK_AI_CURE'),\n new ShimLogVerdict('DENY-BROKEN', 'fault K, not on the allowlist — BLOCK_AI_CURE'),\n];\n\n/**\n * The sh-side L0 fault codes, IMPORTED from the one codebook (../core/l0-fault-codes) rather than\n * retyped here — the letters in this file and the letters in `L0_FAULTS` have to be the same letters or\n * the log cannot be reconciled against the matrix. `-` means \"no sh-side fault\": the shim cannot\n * classify S / C / Y, which the BINARY detects and stamps onto its OWN streams with the same `fault=`\n * field, so a `-` here is a statement about this layer only, never a claim that nothing was wrong.\n */\nexport const SHIM_LOG_FAULTS = [...L0_SH_FAULT_CODES, L0_FAULT_NONE] as const;\n\n/**\n * One FIELD of the audit line: how it reads on disk, the sh expression that produces it, and what it\n * answers. Data-only → a class, per CLAUDE.md.\n */\nexport class ShimLogField {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly label: string,\n /** The sh word spliced into the printf below — the ONE place this field's value is spelled. */\n readonly shValue: string,\n readonly means: string,\n /**\n * True for a field that is printed only SOMETIMES (`bin=`, and only when it differs from\n * `shim=`). Such a field carries its OWN trailing tab in its sh value and therefore renders\n * with NO separator of its own — `%s%s` glues it to the next field, so an empty value leaves\n * the line one field shorter rather than leaving a stray tab behind.\n */\n readonly optional: boolean = false,\n ) {}\n}\n\n/**\n * THE LINE, as data. The printf below is BUILT from this array and guards/L0-tooling.md RENDERS it, so\n * a field cannot be added, dropped or reordered without both the shim and the doc changing with it.\n *\n * That is not decoration: `shim=`/`bin=` were inserted mid-line (deliberately breaking positional\n * readers rather than appending where a stale parser keeps working), then `layer=`/`row=` joined them,\n * and the hand-written doc went on describing a 7-field line with no `U` in its fault set the whole time.\n */\nexport const SHIM_LOG_FIELDS: readonly ShimLogField[] = [\n new ShimLogField('<iso-ts>', `\"$(date '+%Y-%m-%dT%H:%M:%S%z' 2>/dev/null)\"`,\n 'when the shim judged the call, local time with offset'),\n new ShimLogField('<bin-name>', '\"$BIN_NAME\"',\n 'WHICH hook ran - wp-ai-guards-hook or wp-ai-rules-hook; Claude Code runs them in parallel'),\n new ShimLogField('<tool>', '\"$TOOL\"', 'the PreToolUse tool name (Bash, Read, Write, Edit, apply_patch, …)'),\n // WHICH HARNESS. Inserted MID-LINE rather than appended, which is this format's house style and is\n // deliberate: a positional reader that has not been updated fails loudly here instead of silently\n // reading the wrong column forever (see this array's own header). The values are the `AiType`\n // union's, produced by AI_TYPE_SH — one vocabulary across all five streams. A row written before\n // this field existed simply has no `ai=`, which reads as `unknown`; that is a real value, not a\n // compatibility shim.\n new ShimLogField(`ai=<${AI_TYPES.join('|')}>`, '\"ai=$AI\"',\n 'WHICH coding agent made the call, from the one turn_id discriminator (adapters/detect-ai.ts)'),\n new ShimLogField('tree=<name|primary>', '\"tree=$WP_TREE\"',\n 'git\\'s own name for the worktree the CALL was made in, derived from the payload\\'s cwd'),\n new ShimLogField(`layer=${L0_LAYER}`, `\"layer=${L0_LAYER}\"`,\n 'the layer that judged it — constant here, and the first half of the join key a deny cites'),\n new ShimLogField(`row=<${L0_ROW_HANDED_DOWN}|${L0_ROW_ALLOWLISTED}|${L0_ROW_BLOCKED}>`, '\"row=$_wp_row\"',\n 'WHICH row of the three-row matrix this call took, read off the verdict (hand-down / allowlisted / blocked)'),\n new ShimLogField('shim=<root>', '\"shim=$ROOT\"',\n 'WHICH COPY of ai-hook.sh ran, resolved from $0 — against tree= it is the straddle detector'),\n new ShimLogField('bin=<root>', '\"$_wp_bin\"',\n 'WHICH TREE supplied the binary — printed ONLY when it differs from shim=, so its presence IS the borrow',\n true),\n new ShimLogField(`fault=<${SHIM_LOG_FAULTS.join('|')}>`, '\"fault=$1\"',\n 'the sh-side L0 fault, or `-`; S/C/Y are the binary\\'s and are stamped on ITS streams'),\n new ShimLogField('<VERDICT>', '\"$2\"', 'one of the verdict labels below — kept adjacent to the command'),\n new ShimLogField('<command>', '\"$CMD_LOG\"',\n 'the command PREFIX (the audit spelling; the DECISION reads $CMD, which fails closed on a quote)'),\n];\n\n/**\n * The writer's `printf`, assembled from SHIM_LOG_FIELDS — one `%s` per field, in the same order, and a\n * tab after every field EXCEPT an optional one (which carries its own). Retyping either half is what\n * let the format and its documentation disagree, so neither half is retyped anywhere.\n */\nexport const SHIM_LOG_PRINTF =\n `printf '${SHIM_LOG_FIELDS.map(\n (f: ShimLogField, i: number): string => '%s' + (i === SHIM_LOG_FIELDS.length - 1 ? '' : (f.optional ? '' : '\\\\t')),\n ).join('')}\\\\n' `\n + `${SHIM_LOG_FIELDS.map((f: ShimLogField): string => f.shValue).join(' ')} >> \"$_wp_f\"`;\n\n/**\n * Shell fragment: derive WHERE this call's log belongs — the sh TWIN of `DotWebpieces.local()` +\n * `worktreeName()` + `primaryRoot()` in @webpieces/rules-config.\n *\n * sh cannot import TypeScript, so this derivation is duplicated by necessity; the mitigation is\n * `shim-audit-log.spec.ts`, which runs THIS function through a real /bin/sh in real git worktrees and\n * asserts it returns exactly what `dotWebpieces.worktreeName()` returns. If the two ever disagree the\n * lock goes red rather than the logs quietly splitting in half.\n *\n * It asks git the SAME question the TS side asks — `--git-dir` vs `--git-common-dir`, which differ if\n * and only if this is a linked worktree — but in ONE `rev-parse` (it accepts both flags and prints a\n * line each) rather than two, because this runs on the blocking path of every tool call.\n *\n * The tree is derived from the PAYLOAD's `cwd` (Claude Code documents it as the working directory the\n * hook was invoked from), not from `$ROOT`. `$ROOT` is where the shim FILE lives and stays the anchor\n * for what the drift guard MEASURES — this fragment changes only where the log is WRITTEN.\n *\n * Fails soft, exactly like the TS side: when git cannot answer, the log collapses to\n * `<cwd>/.webpieces/logs`, which is the pre-change behaviour.\n */\nexport const RESOLVE_LOG_DIR_SH = `wp_resolve_log_dir() {\n _wp_rp=\"$(git -C \"$WP_CWD\" rev-parse --git-dir --git-common-dir 2>/dev/null)\"\n _wp_gd=\"$(printf '%s\\\\n' \"$_wp_rp\" | sed -n 1p)\"\n _wp_cd=\"$(printf '%s\\\\n' \"$_wp_rp\" | sed -n 2p)\"\n if [ -z \"$_wp_gd\" ] || [ -z \"$_wp_cd\" ]; then\n WP_TREE=primary; WP_LOG_DIR=\"$WP_CWD/${WEBPIECES_TMP_DIR}/${LOGS_STATE_DIR}\"\n WP_PRIMARY_LOG_DIR=\"$WP_LOG_DIR\"; return 0\n fi\n # git prints a BARE .git from the primary clone and an absolute path from a linked worktree; the TS\n # twin runs path.resolve(cwd, printed), so do the same before comparing or taking a basename.\n case \"$_wp_gd\" in /*) : ;; *) _wp_gd=\"$WP_CWD/$_wp_gd\" ;; esac\n case \"$_wp_cd\" in /*) : ;; *) _wp_cd=\"$WP_CWD/$_wp_cd\" ;; esac\n # The primary clone's root is the parent of the SHARED git dir — declining any layout whose shared\n # dir is not named .git (a bare repo, --separate-git-dir), same test as primaryRoot().\n _wp_primary=\"$WP_CWD\"\n case \"$_wp_cd\" in\n */.git) [ -d \"\\${_wp_cd%/*}\" ] && _wp_primary=\"\\${_wp_cd%/*}\" ;;\n esac\n # The PRIMARY clone's log dir, resolved on both branches. A deny that has to tell a human WHERE the\n # audit trail is (the inverse-drift escalation in shim.ts) must be able to name both the tree it is\n # standing in and the primary — a subagent has no reach into the second one, so the deny has to quote\n # that path rather than send anyone to go and look.\n WP_PRIMARY_LOG_DIR=\"$_wp_primary/${WEBPIECES_TMP_DIR}/${LOGS_STATE_DIR}\"\n if [ \"$_wp_gd\" = \"$_wp_cd\" ]; then\n WP_TREE=primary\n WP_LOG_DIR=\"$WP_PRIMARY_LOG_DIR\"\n else\n # git's OWN name for the worktree (the basename of <primary>/.git/worktrees/<name>), not the\n # directory's basename — two worktrees under different parents may share a directory name.\n WP_TREE=\"\\${_wp_gd##*/}\"\n WP_LOG_DIR=\"$_wp_primary/${WEBPIECES_TMP_DIR}/${WORKTREE_STATE_DIR}/$WP_TREE/${LOGS_STATE_DIR}\"\n fi\n}`;\n\n/**\n * Shell fragment: the audit-log writer itself — `wp_log <fault> <verdict>`, one tab-separated line.\n *\n * FORMAT: SHIM_LOG_FIELDS, tab-separated, append-only — that array IS the format, and SHIM_LOG_PRINTF\n * is built from it, so neither this docblock nor guards/L0-tooling.md can describe a line the shim does\n * not write.\n *\n * `tree=` and `fault=` are the two fields that make the file reconcilable against guards/L0-tooling.md:\n * the first says WHICH checkout produced the line (a shared log across seven worktrees is otherwise\n * unreadable), the second says which of the sh-side faults the shim detected. The verdict\n * keeps its historical spelling and stays adjacent to the command, so `grep 'DENY-STALE\\\\t'` still\n * finds what it always found.\n *\n * NEVER breaks or blocks the hook: the whole body is wrapped so a failure of any kind — unwritable\n * directory, read-only filesystem, missing `git` — is swallowed, and nothing is ever written to\n * stdout (stdout is the PreToolUse decision channel; a stray byte there corrupts allow/deny).\n *\n * The log dir is resolved LAZILY on first use so a call that never logs never pays for the git probe.\n */\nexport const WP_LOG_SH = `WP_TREE=\"\"\nWP_LOG_DIR=\"\"\nWP_PRIMARY_LOG_DIR=\"\"\nWP_TAB=\"$(printf '\\\\t')\" # one real tab, so the OPTIONAL bin= field can carry its own separator\n${RESOLVE_LOG_DIR_SH}\nwp_clean() { # one path segment from an UNTRUSTED payload id — twin of LogStream's segment()\n printf '%s' \"$1\" | tr -c 'A-Za-z0-9._-' '_' | sed -e 's/\\\\.\\\\{2,\\\\}/_/g' -e 's/^\\\\.\\\\{1,\\\\}/_/' | cut -c1-64\n}\nwp_log() { # $1 = L0 fault code (D|X|K|-), $2 = verdict label\n {\n [ -n \"$WP_LOG_DIR\" ] || wp_resolve_log_dir\n # The LAYER is the directory and the WRITER is the file — same layout the TS writers use, spelled\n # from the same constant so the two halves cannot drift apart.\n _wp_sd=\"$WP_LOG_DIR/${L0_SHIM_STREAM}\"\n mkdir -p \"$_wp_sd\" 2>/dev/null || return 0\n # Same writer key as LogStream.writerFile(): <session>-<agent|coordinator>-<hook>.log. $BIN_NAME\n # IS the hook discriminator here (wp-ai-guards-hook vs wp-ai-rules-hook), and Claude Code runs those\n # two IN PARALLEL on every file edit — without this prefix they append to ONE file and tear above\n # PIPE_BUF. An empty session id renders 'unknown' — this has no bare-name branch, matching\n # LogStream.writerFile(), which has none either.\n # ALWAYS prefixed - a missing session_id renders as 'unknown', never as the shared bare name.\n # Gating this on a non-empty id would drop both parallel hooks back onto one file, which is the\n # torn-append case this exists to remove. Twin of LogStream.writerFile(), which has no bare branch.\n _wp_pfx=\"$(wp_clean \"\\${WP_SID:-unknown}\")-$(wp_clean \"\\${WP_AID:-coordinator}\")-$BIN_NAME\"\n _wp_f=\"$_wp_sd/\\${_wp_pfx}.log\"\n # Rotate at the SAME 512 KB into the SAME .1.log sibling as every JS-side webpieces log. This runs\n # on every tool call, so it is one wc and no more; a size we cannot read counts as 0 (no rotation).\n _wp_sz=\"$(wc -c < \"$_wp_f\" 2>/dev/null | tr -d ' ')\"\n case \"$_wp_sz\" in ''|*[!0-9]*) _wp_sz=0 ;; esac\n [ \"$_wp_sz\" -gt ${String(SHIM_LOG_MAX_BYTES)} ] && mv -f \"$_wp_f\" \"$_wp_sd/\\${_wp_pfx}.1.log\" 2>/dev/null\n # shim= and bin= are the two facts this log could not previously answer, and they are the ones that\n # decide whether a tree was governed by its OWN release or a borrowed one:\n # shim= WHICH COPY OF ai-hook.sh RAN — $ROOT, resolved from $0. The file is TRACKED, so every\n # worktree carries the version at ITS commit; settings.json registers it ABSOLUTE, so the copy\n # that runs is the SESSION ROOT's. Logged rather than assumed, on EVERY line: compared against\n # tree= it is the STRADDLE detector (tree=agent-X shim=<repo> = standing in one tree, judged by\n # another), and that pair varies constantly.\n # bin= WHICH TREE SUPPLIED THE BINARY — $BIN_ROOT, the upward walk's answer.\n #\n # bin= IS PRINTED ONLY WHEN IT DIFFERS FROM shim=, so its mere PRESENCE is the diagnostic (\"the binary\n # came from a different tree than the shim\") instead of ~50 bytes repeated on every line. Measured\n # across 549 logged lines: it differed on 39, every one a worktree agent's first few calls before it\n # ran pnpm install — after that they matched for the rest of that agent's life. And since the hooks\n # went ABSOLUTE, shim= is always the MAIN tree, so the two can now only differ when the main tree\n # itself has no node_modules (a fresh clone before install). ~7% of lines then, near 0% going forward.\n # A unit test asserts the field appears if and only if the roots differ, so it cannot quietly become\n # unconditional noise again.\n _wp_bin=\"\"\n [ \"$BIN_ROOT\" != \"$ROOT\" ] && _wp_bin=\"bin=$BIN_ROOT$WP_TAB\"\n # layer= and row= are the JOIN KEYS, and they are here so the join is REAL rather than promised.\n # Every L0 deny now opens '[<guard>] (layer=L0 fault=<code> row=<n>)' and cites \"the same coordinates\n # the audit line carries\" — which was true of the JS half (MATRIX_L0_BLOCK, via decision-log) and\n # FALSE of this one, which carried 'fault=' alone. Fixing the message instead of the line would have\n # left 'grep 'layer=L0 row=3'' finding one half of L0 and silently missing the other four faults.\n #\n # 'row=' is NOT a constant: it is the row of the three-row matrix this call actually took, read off\n # the verdict — hand-down, allowlisted, or blocked — exactly as L1 logs 'row=' from L1_ROWS. That is\n # what distinguishes it from the ~50 constant bytes 'bin=' used to spend above.\n _wp_row=${L0_ROW_HANDED_DOWN}\n case \"$2\" in ALLOW*) _wp_row=${L0_ROW_ALLOWLISTED} ;; DENY*) _wp_row=${L0_ROW_BLOCKED} ;; esac\n ${SHIM_LOG_PRINTF}\n } 2>/dev/null || true\n}`;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shimStaleDenyReason(installedVersion: string, root: string, drifted: readonly string[], inSubagent: boolean): string;
|