@webpieces/agent-workflow-rules 0.0.0-stage → 0.0.1
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":"missing-directory.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/missing-directory.ts"],"names":[],"mappings":";;;AA2DA,sDAGC;AA9DD,0DAA+E;AAC/E,0DAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,qBAAqB;IACb,QAAQ,GAAG,IAAI,oCAAqB,EAAE,CAAC;IAExD,yCAAyC;IACzC,KAAK,CAAC,OAAe,EAAE,IAAmB;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACzC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,4FAA4F;IACpF,MAAM,CAAC,OAAe,EAAE,IAAmB;QAC/C,OAAO;YACH,6DAA6D;YAC7D,QAAQ,IAAI,CAAC,YAAY,EAAE;YAC3B,2FAA2F;YAC3F,8FAA8F;YAC9F,EAAE;YACF,oBAAoB,IAAI,CAAC,YAAY,yDAAyD;YAC9F,QAAQ,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE;SACnE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACJ;AArBD,sDAqBC;AAED,oGAAoG;AACpG,sGAAsG;AACtG,4BAA4B;AAC5B,gHAAgH;AAChH,SAAgB,qBAAqB,CAAC,OAAe,EAAE,IAAmB;IACtE,MAAM,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAChE,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,4BAAa,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import { EffectiveTree, EffectiveTreeResolver } from '@webpieces/hook-runtime';\nimport { BlockedResult } from '@webpieces/hook-runtime';\n\n/**\n * L1: the directory this command would run in DOES NOT EXIST.\n *\n * THE INCIDENT (reproduced from a transcript, 0.4.603). A subagent was launched with its cwd inside\n * `<root>/.claude/worktrees/agent-a5931637c5bff6d6d`. Mid-session another agent's cleanup REAPED that\n * worktree. The shell's cwd still named a path that was now gone.\n *\n * `classify()` asked git for the toplevel, got `null` — and `null` meant two completely different\n * things: \"this is not a git directory\" and \"this directory does not exist\". Conflating them classified\n * the dead path as the PRIMARY clone, so force-to-root fired and printed:\n *\n * ❌ Run git/gh commands from the repo root, not a subdirectory.\n * Command runs in: <root>/.claude/worktrees/agent-a5931637c5bff6d6d\n * Judged against: <root>\n * cd '<root>' && cd <root>/.claude/worktrees/agent-… && git fetch …\n *\n * Three things wrong at once: the diagnosis (it is not a subdirectory, it is GONE), the tone (it reads\n * as a scolding for a mistake nobody made), and the remedy (it ends inside the deleted directory, so it\n * cannot satisfy the check — the retry re-fires with the prefix doubled, then tripled). Three rounds\n * were burned before `git worktree list` made the real state visible.\n *\n * So the fix is a DISTINCT tree kind with its own message. Naming the state is most of the cure: an\n * agent that is told the directory is gone stops trying to `cd` into it. The remedy deliberately routes\n * through the governed root and drops the command's own leading `cd`, so it can never point back at the\n * dead path — the same convergence property `remedyAtRoot` gives force-to-root.\n *\n * The lost-work line is not padding. A reaped worktree takes uncommitted changes with it, and an agent\n * that silently retries at the root will otherwise report success on work that no longer exists.\n */\nexport class MissingDirectoryGuard {\n private readonly resolver = new EffectiveTreeResolver();\n\n /** The deny report, or null to allow. */\n block(command: string, tree: EffectiveTree): string | null {\n if (tree.kind !== 'missing') return null;\n return this.report(command, tree);\n }\n\n // Short, on the L0 message diet: name the state, say what it costs, give ONE runnable line.\n private report(command: string, tree: EffectiveTree): string {\n return [\n `❌ The directory this command would run in no longer exists:`,\n ` ${tree.effectiveCwd}`,\n ' Most often it was a linked worktree that has since been reaped (`git worktree list` no',\n ' longer shows it). Nothing can run there, and any UNCOMMITTED work that was in it is gone.',\n '',\n ` Continue from ${tree.governedRoot} — this line does NOT route back through the dead path:`,\n ` ${this.resolver.remedyAtRoot(tree.governedRoot, command)}`,\n ].join('\\n');\n }\n}\n\n// L1 row 7's dispatch entry. It lives HERE rather than beside its two siblings in runner.ts because\n// the guard owns its own report and runner.ts is at its file-size cap — the runner needs only the row\n// lookup and this one call.\n// webpieces-disable no-function-outside-class -- the one-line runner entry point for the class above, beside it\nexport function missingDirectoryBlock(command: string, tree: EffectiveTree): BlockedResult | null {\n const report = new MissingDirectoryGuard().block(command, tree);\n return report === null ? null : new BlockedResult(report);\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CommandScanner } from '@webpieces/hook-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* Is this shell command pure INSPECTION — can it be trusted to change nothing?
|
|
4
|
+
*
|
|
5
|
+
* WHY this exists: when webpieces.config.json cannot be loaded (unparseable, or invalid against the
|
|
6
|
+
* installed validator) every bash command is denied, because with no config there are no guards and
|
|
7
|
+
* fail-closed is the only safe answer. That is right for work — and catastrophic for recovery, because
|
|
8
|
+
* the denial also took out `cat`, `grep` and `sed -n` against webpieces.config.json itself. The guard
|
|
9
|
+
* blocked the exact tools needed to see and fix the problem it was reporting, which is a dead end an
|
|
10
|
+
* agent cannot escape from inside the session. (Reproduced live: mid-merge, the config legitimately
|
|
11
|
+
* held `<<<<<<< HEAD` markers and every attempt to look at it was refused.)
|
|
12
|
+
*
|
|
13
|
+
* The rest of the system already models the escape hatch correctly — reading AND editing
|
|
14
|
+
* webpieces.config.json is always allowed (hook-core's config bypass, the stale-shim recovery
|
|
15
|
+
* carve-out, ContentReadScan's escape-hatch paths). This closes the one place that did not honour it.
|
|
16
|
+
*
|
|
17
|
+
* The bar is deliberately paranoid, because this is a bypass of ALL guards:
|
|
18
|
+
* - every invoked segment's command word must be an allowlisted inspector;
|
|
19
|
+
* - `git`/`gh` are excluded outright, even their read-only subcommands — the guards exist to police
|
|
20
|
+
* git, and "read-only git" is not a line worth drawing while flying blind;
|
|
21
|
+
* - any output redirect to a file (`> x`, `>> x`) makes the command a writer;
|
|
22
|
+
* - the in-place/mutating flags of otherwise-read-only tools (`sed -i`, `find -delete`) are refused.
|
|
23
|
+
* Anything not provably inert stays blocked.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ReadOnlyInspectionScan {
|
|
26
|
+
private readonly scanner;
|
|
27
|
+
private readonly shell;
|
|
28
|
+
constructor(scanner?: CommandScanner);
|
|
29
|
+
/** True only when EVERY segment of the command is provably inert. Empty command → false. */
|
|
30
|
+
isReadOnlyInspection(command: string): boolean;
|
|
31
|
+
private segmentIsInert;
|
|
32
|
+
private redirectsToFile;
|
|
33
|
+
private hasMutatingFlag;
|
|
34
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadOnlyInspectionScan = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
7
|
+
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
8
|
+
/**
|
|
9
|
+
* Is this shell command pure INSPECTION — can it be trusted to change nothing?
|
|
10
|
+
*
|
|
11
|
+
* WHY this exists: when webpieces.config.json cannot be loaded (unparseable, or invalid against the
|
|
12
|
+
* installed validator) every bash command is denied, because with no config there are no guards and
|
|
13
|
+
* fail-closed is the only safe answer. That is right for work — and catastrophic for recovery, because
|
|
14
|
+
* the denial also took out `cat`, `grep` and `sed -n` against webpieces.config.json itself. The guard
|
|
15
|
+
* blocked the exact tools needed to see and fix the problem it was reporting, which is a dead end an
|
|
16
|
+
* agent cannot escape from inside the session. (Reproduced live: mid-merge, the config legitimately
|
|
17
|
+
* held `<<<<<<< HEAD` markers and every attempt to look at it was refused.)
|
|
18
|
+
*
|
|
19
|
+
* The rest of the system already models the escape hatch correctly — reading AND editing
|
|
20
|
+
* webpieces.config.json is always allowed (hook-core's config bypass, the stale-shim recovery
|
|
21
|
+
* carve-out, ContentReadScan's escape-hatch paths). This closes the one place that did not honour it.
|
|
22
|
+
*
|
|
23
|
+
* The bar is deliberately paranoid, because this is a bypass of ALL guards:
|
|
24
|
+
* - every invoked segment's command word must be an allowlisted inspector;
|
|
25
|
+
* - `git`/`gh` are excluded outright, even their read-only subcommands — the guards exist to police
|
|
26
|
+
* git, and "read-only git" is not a line worth drawing while flying blind;
|
|
27
|
+
* - any output redirect to a file (`> x`, `>> x`) makes the command a writer;
|
|
28
|
+
* - the in-place/mutating flags of otherwise-read-only tools (`sed -i`, `find -delete`) are refused.
|
|
29
|
+
* Anything not provably inert stays blocked.
|
|
30
|
+
*/
|
|
31
|
+
class ReadOnlyInspectionScan {
|
|
32
|
+
scanner;
|
|
33
|
+
shell;
|
|
34
|
+
constructor(scanner = new hook_runtime_1.CommandScanner()) {
|
|
35
|
+
this.scanner = scanner;
|
|
36
|
+
this.shell = new hook_runtime_2.ShellSegmentScan(this.scanner);
|
|
37
|
+
}
|
|
38
|
+
/** True only when EVERY segment of the command is provably inert. Empty command → false. */
|
|
39
|
+
isReadOnlyInspection(command) {
|
|
40
|
+
const segments = this.scanner.segmentsWithJoins(command);
|
|
41
|
+
if (segments.length === 0)
|
|
42
|
+
return false;
|
|
43
|
+
return segments.every((segment) => this.segmentIsInert(segment));
|
|
44
|
+
}
|
|
45
|
+
segmentIsInert(segment) {
|
|
46
|
+
const words = this.shell.effectiveWords(segment.text);
|
|
47
|
+
if (words.length === 0)
|
|
48
|
+
return true; // pure shell structure (`done`, `fi`)
|
|
49
|
+
if (this.redirectsToFile(words))
|
|
50
|
+
return false; // `… > file` writes, whatever the command is
|
|
51
|
+
const head = path.basename(words[0]);
|
|
52
|
+
if (!INSPECTORS.has(head))
|
|
53
|
+
return false;
|
|
54
|
+
return !this.hasMutatingFlag(head, words.slice(1));
|
|
55
|
+
}
|
|
56
|
+
// `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which only rewire fds and are the single
|
|
57
|
+
// most common decoration an agent appends to a diagnostic command.
|
|
58
|
+
redirectsToFile(words) {
|
|
59
|
+
return words.some((word) => REDIRECT_TO_FILE.test(word));
|
|
60
|
+
}
|
|
61
|
+
// Read-only tools that grow teeth with one flag: `sed -i` rewrites in place, `find -delete`/`-exec`
|
|
62
|
+
// runs arbitrary commands. Matching is prefix-based so `-i.bak` and `-inplace` are caught too.
|
|
63
|
+
hasMutatingFlag(head, args) {
|
|
64
|
+
const mutating = MUTATING_FLAGS[head];
|
|
65
|
+
if (!mutating)
|
|
66
|
+
return false;
|
|
67
|
+
return args.some((arg) => mutating.some((flag) => arg.startsWith(flag)));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ReadOnlyInspectionScan = ReadOnlyInspectionScan;
|
|
71
|
+
// Commands whose entire job is showing what is already there. Kept to viewers/searchers/formatters:
|
|
72
|
+
// no package managers, no build or test runners, no interpreters, no git.
|
|
73
|
+
const INSPECTORS = new Set([
|
|
74
|
+
'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'tac', 'rev', 'strings', 'xxd', 'od',
|
|
75
|
+
'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',
|
|
76
|
+
'ls', 'find', 'tree', 'wc', 'diff', 'cmp', 'file', 'stat', 'realpath', 'readlink',
|
|
77
|
+
'basename', 'dirname', 'sort', 'uniq', 'cut', 'tr', 'column', 'fold', 'expand',
|
|
78
|
+
'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'which', 'test', '[',
|
|
79
|
+
]);
|
|
80
|
+
// Per-command flags that turn an inspector into a mutator.
|
|
81
|
+
const MUTATING_FLAGS = {
|
|
82
|
+
sed: ['-i', '--in-place'],
|
|
83
|
+
find: ['-delete', '-exec', '-execdir', '-ok', '-okdir', '-fprint', '-fls'],
|
|
84
|
+
awk: ['-i'],
|
|
85
|
+
sort: ['-o', '--output'],
|
|
86
|
+
};
|
|
87
|
+
const REDIRECT_TO_FILE = /^\d*>>?(?!&)/;
|
|
88
|
+
//# sourceMappingURL=read-only-inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-only-inspection.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/read-only-inspection.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAyE;AACzE,0DAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,sBAAsB;IAGF;IAFZ,KAAK,CAAmB;IAEzC,YAA6B,UAA0B,IAAI,6BAAc,EAAE;QAA9C,YAAO,GAAP,OAAO,CAAuC;QACvE,IAAI,CAAC,KAAK,GAAG,IAAI,+BAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,4FAA4F;IAC5F,oBAAoB,CAAC,OAAe;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAuB,EAAW,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,CAAC;IAEO,cAAc,CAAC,OAAuB;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,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AK,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI;IACxF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI;IACrE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IACjF,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ;IAC9E,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG;CAC5E,CAAC,CAAC;AAEH,2DAA2D;AAC3D,MAAM,cAAc,GAAgD;IAChE,GAAG,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC;IACzB,IAAI,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC1E,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEF,MAAM,gBAAgB,GAAG,cAAc,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { CommandScanner, CommandSegment } from '@webpieces/hook-runtime';\nimport { ShellSegmentScan } from '@webpieces/hook-runtime';\n\n/**\n * Is this shell command pure INSPECTION — can it be trusted to change nothing?\n *\n * WHY this exists: when webpieces.config.json cannot be loaded (unparseable, or invalid against the\n * installed validator) every bash command is denied, because with no config there are no guards and\n * fail-closed is the only safe answer. That is right for work — and catastrophic for recovery, because\n * the denial also took out `cat`, `grep` and `sed -n` against webpieces.config.json itself. The guard\n * blocked the exact tools needed to see and fix the problem it was reporting, which is a dead end an\n * agent cannot escape from inside the session. (Reproduced live: mid-merge, the config legitimately\n * held `<<<<<<< HEAD` markers and every attempt to look at it was refused.)\n *\n * The rest of the system already models the escape hatch correctly — reading AND editing\n * webpieces.config.json is always allowed (hook-core's config bypass, the stale-shim recovery\n * carve-out, ContentReadScan's escape-hatch paths). This closes the one place that did not honour it.\n *\n * The bar is deliberately paranoid, because this is a bypass of ALL guards:\n * - every invoked segment's command word must be an allowlisted inspector;\n * - `git`/`gh` are excluded outright, even their read-only subcommands — the guards exist to police\n * git, and \"read-only git\" is not a line worth drawing while flying blind;\n * - any output redirect to a file (`> x`, `>> x`) makes the command a writer;\n * - the in-place/mutating flags of otherwise-read-only tools (`sed -i`, `find -delete`) are refused.\n * Anything not provably inert stays blocked.\n */\nexport class ReadOnlyInspectionScan {\n private readonly shell: ShellSegmentScan;\n\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {\n this.shell = new ShellSegmentScan(this.scanner);\n }\n\n /** True only when EVERY segment of the command is provably inert. Empty command → false. */\n isReadOnlyInspection(command: string): boolean {\n const segments = this.scanner.segmentsWithJoins(command);\n if (segments.length === 0) return false;\n return segments.every((segment: CommandSegment): boolean => this.segmentIsInert(segment));\n }\n\n private segmentIsInert(segment: CommandSegment): boolean {\n const words = this.shell.effectiveWords(segment.text);\n if (words.length === 0) return true; // pure shell structure (`done`, `fi`)\n if (this.redirectsToFile(words)) return false; // `… > file` writes, whatever the command is\n const head = path.basename(words[0]);\n if (!INSPECTORS.has(head)) return false;\n return !this.hasMutatingFlag(head, words.slice(1));\n }\n\n // `>`, `>>`, `>out.txt`, `2>log` — but NOT `2>&1`/`1>&2`, which only rewire fds and are the single\n // most common decoration an agent appends to a diagnostic command.\n private redirectsToFile(words: readonly string[]): boolean {\n return words.some((word: string): boolean => REDIRECT_TO_FILE.test(word));\n }\n\n // Read-only tools that grow teeth with one flag: `sed -i` rewrites in place, `find -delete`/`-exec`\n // runs arbitrary commands. Matching is prefix-based so `-i.bak` and `-inplace` are caught too.\n private hasMutatingFlag(head: string, args: readonly string[]): boolean {\n const mutating = MUTATING_FLAGS[head];\n if (!mutating) return false;\n return args.some((arg: string): boolean => mutating.some((flag: string): boolean => arg.startsWith(flag)));\n }\n}\n\n// Commands whose entire job is showing what is already there. Kept to viewers/searchers/formatters:\n// no package managers, no build or test runners, no interpreters, no git.\nconst INSPECTORS: ReadonlySet<string> = new Set([\n 'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'tac', 'rev', 'strings', 'xxd', 'od',\n 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',\n 'ls', 'find', 'tree', 'wc', 'diff', 'cmp', 'file', 'stat', 'realpath', 'readlink',\n 'basename', 'dirname', 'sort', 'uniq', 'cut', 'tr', 'column', 'fold', 'expand',\n 'echo', 'printf', 'true', 'false', ':', 'cd', 'pwd', 'which', 'test', '[',\n]);\n\n// Per-command flags that turn an inspector into a mutator.\nconst MUTATING_FLAGS: Readonly<Record<string, readonly string[]>> = {\n sed: ['-i', '--in-place'],\n find: ['-delete', '-exec', '-execdir', '-ok', '-okdir', '-fprint', '-fls'],\n awk: ['-i'],\n sort: ['-o', '--output'],\n};\n\nconst REDIRECT_TO_FILE = /^\\d*>>?(?!&)/;\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ToolKind, NormalizedToolInput, BlockedResult } from '@webpieces/hook-runtime';
|
|
2
|
+
export declare function logRejection(toolKind: ToolKind, input: NormalizedToolInput, result: BlockedResult, cwd: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because
|
|
5
|
+
* two audit streams need the same answer from the same regex: this file's rejection index, and the
|
|
6
|
+
* `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be
|
|
7
|
+
* two answers to one question.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractRuleNames(report: string): string[];
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logRejection = logRejection;
|
|
4
|
+
exports.extractRuleNames = extractRuleNames;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
10
|
+
const log_streams_1 = require("./log-streams");
|
|
11
|
+
const log_stream_1 = require("./log-stream");
|
|
12
|
+
const ai_type_context_1 = require("./ai-type-context");
|
|
13
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
14
|
+
/**
|
|
15
|
+
* The rejection index and its detail files, BOTH inside the `rejections/` stream directory, both
|
|
16
|
+
* named by the same writer key:
|
|
17
|
+
*
|
|
18
|
+
* logs/rejections/<sid>-<agent>-<hook>.log ← the index (one line per block)
|
|
19
|
+
* logs/rejections/<sid>-<agent>-<hook>/ ← its detail dir, SAME key
|
|
20
|
+
* writeInfo-<epochMs>.md
|
|
21
|
+
*
|
|
22
|
+
* The detail files used to be `hooks/<YYYY-MM-DD>/writeInfo-<epochMs>.md` — a directory keyed only by
|
|
23
|
+
* the DATE, shared by every writer in the tree, written with a raw `writeFileSync`. Two agents blocked
|
|
24
|
+
* in the same millisecond produced the same path and one silently overwrote the other's evidence. The
|
|
25
|
+
* comment that licensed it claimed a per-worktree log has exactly one writer; LogStream's class
|
|
26
|
+
* comment is the measurement that disproves it (parallel PreToolUse hooks, non-isolated subagents and
|
|
27
|
+
* multiple Claude Code windows all share a tree). Naming the directory after the LOG THAT POINTS AT IT
|
|
28
|
+
* gives it the same one-owner-by-construction property the log itself has, and makes the pointer
|
|
29
|
+
* readable: the index line, the directory and the file are one name.
|
|
30
|
+
*
|
|
31
|
+
* RETENTION is therefore filename-based, not directory-date-based: there is no date level left, so
|
|
32
|
+
* `DetailPruner` parses `<epochMs>` out of each `writeInfo-*.md` (no `stat` call) and removes any
|
|
33
|
+
* stream directory left empty. Every delete is `force: true` and failures are swallowed, so concurrent
|
|
34
|
+
* agents racing the same week-old files is harmless.
|
|
35
|
+
*/
|
|
36
|
+
const DETAIL_PREFIX = 'writeInfo-';
|
|
37
|
+
const DETAIL_SUFFIX = '.md';
|
|
38
|
+
const DETAIL_RE = /^writeInfo-(\d+)\.md$/;
|
|
39
|
+
const MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded
|
|
40
|
+
const MAX_AGE_DAYS = 7;
|
|
41
|
+
const RULE_NAME_RE = /^\[([^\]]+)\] \(/gm;
|
|
42
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
43
|
+
function logRejection(toolKind, input, result, cwd) {
|
|
44
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
45
|
+
try {
|
|
46
|
+
// `.webpieces/` lives at the repo root, NOT the AI's cwd — resolve it so a hook fired while
|
|
47
|
+
// the AI is in a subdirectory never scatters a stray `<subdir>/.webpieces` tree.
|
|
48
|
+
const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
|
|
49
|
+
const now = new Date();
|
|
50
|
+
const timestamp = now.toISOString();
|
|
51
|
+
const epochMs = String(now.getTime());
|
|
52
|
+
// LOCAL scope — a rejection is this worktree's event. WHICH writer's event is answered by the
|
|
53
|
+
// stream prefix, on the index AND on its detail directory, so neither can collide.
|
|
54
|
+
const logsDir = tooling_common_1.dotWebpieces.logsFile(root, log_streams_1.REJECTIONS_STREAM);
|
|
55
|
+
// The detail directory is the writer key with NO extension, sitting beside the `.log` that
|
|
56
|
+
// indexes it — so index and details share one owner, one level down inside the stream dir.
|
|
57
|
+
const detailDirName = log_stream_1.logStream.writerFile('');
|
|
58
|
+
const detailDir = path.join(logsDir, detailDirName);
|
|
59
|
+
fs.mkdirSync(detailDir, { recursive: true });
|
|
60
|
+
const relativePath = computeRelativePath(input.filePath, root);
|
|
61
|
+
const ruleNames = extractRuleNames(result.report);
|
|
62
|
+
const detailFileName = `${DETAIL_PREFIX}${epochMs}${DETAIL_SUFFIX}`;
|
|
63
|
+
// Relative to `rejections/` — the index's own directory — so the pointer resolves from where
|
|
64
|
+
// the reader found the line, and reads as the log's own name plus a file.
|
|
65
|
+
const detailRelPath = `${detailDirName}/${detailFileName}`;
|
|
66
|
+
const detail = buildDetailContent(timestamp, toolKind, relativePath, ruleNames, result.report, input);
|
|
67
|
+
fs.writeFileSync(path.join(detailDir, detailFileName), detail);
|
|
68
|
+
const logPath = path.join(logsDir, log_stream_1.logStream.writerFile('.log'));
|
|
69
|
+
rotateLogFile(logPath, path.join(logsDir, log_stream_1.logStream.writerFile('.1.log')));
|
|
70
|
+
// APPEND-ONLY, and `fault=` is spelled exactly as the L0 sh log spells it. A fault-S storm
|
|
71
|
+
// previously landed here as a couple of lines attributed to whatever rule the report happened
|
|
72
|
+
// to cite, with nothing anywhere identifying L0 as the cause. (WHO made the call is answered by
|
|
73
|
+
// the filename, which logStream prefixes with session/agent/hook — not by a column here.)
|
|
74
|
+
// `ai=` joins the same append-only tail as `fault=`, in the same vocabulary the L0 sh shim and
|
|
75
|
+
// both decision streams use — so `grep ai=codex` spans all five streams. A row from a release
|
|
76
|
+
// that predates the field carries no `ai=` and reads as `unknown`.
|
|
77
|
+
const logLine = `[${timestamp}]\t${toolKind}\t${relativePath}\t[${ruleNames.join(',')}]\t${detailRelPath}\tfault=${result.fault}\tai=${ai_type_context_1.aiTypeContext.forLog()}\n`;
|
|
78
|
+
fs.appendFileSync(logPath, logLine);
|
|
79
|
+
detailPruner.prune(logsDir, MAX_AGE_DAYS);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
//const error = toError(err);
|
|
83
|
+
void err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
87
|
+
function computeRelativePath(filePath, cwd) {
|
|
88
|
+
if (filePath.startsWith(cwd)) {
|
|
89
|
+
const rel = filePath.slice(cwd.length);
|
|
90
|
+
if (rel.startsWith('/'))
|
|
91
|
+
return rel.slice(1);
|
|
92
|
+
return rel;
|
|
93
|
+
}
|
|
94
|
+
return filePath;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because
|
|
98
|
+
* two audit streams need the same answer from the same regex: this file's rejection index, and the
|
|
99
|
+
* `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be
|
|
100
|
+
* two answers to one question.
|
|
101
|
+
*/
|
|
102
|
+
// webpieces-disable no-function-outside-class -- pure regex scraper beside this module's other module-scope helpers; exported so the invocation log and the rejection index scrape rule names with the SAME code.
|
|
103
|
+
function extractRuleNames(report) {
|
|
104
|
+
const names = [];
|
|
105
|
+
let match = RULE_NAME_RE.exec(report);
|
|
106
|
+
while (match !== null) {
|
|
107
|
+
names.push(match[1]);
|
|
108
|
+
match = RULE_NAME_RE.exec(report);
|
|
109
|
+
}
|
|
110
|
+
RULE_NAME_RE.lastIndex = 0;
|
|
111
|
+
return names;
|
|
112
|
+
}
|
|
113
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
114
|
+
function buildDetailContent(timestamp, toolKind, relativePath, ruleNames, report, input) {
|
|
115
|
+
const lines = [];
|
|
116
|
+
lines.push('# Hook Rejection Detail');
|
|
117
|
+
lines.push('');
|
|
118
|
+
lines.push(`- **Timestamp:** ${timestamp}`);
|
|
119
|
+
lines.push(`- **Tool:** ${toolKind}`);
|
|
120
|
+
lines.push(`- **File:** ${relativePath}`);
|
|
121
|
+
lines.push(`- **Rules violated:** ${ruleNames.join(', ')}`);
|
|
122
|
+
lines.push('');
|
|
123
|
+
lines.push('## Report');
|
|
124
|
+
lines.push('');
|
|
125
|
+
lines.push('```');
|
|
126
|
+
lines.push(report.trimEnd());
|
|
127
|
+
lines.push('```');
|
|
128
|
+
lines.push('');
|
|
129
|
+
lines.push('## Content Being Written');
|
|
130
|
+
lines.push('');
|
|
131
|
+
if (toolKind === 'Write') {
|
|
132
|
+
const content = input.edits.length > 0 ? input.edits[0].newString : '';
|
|
133
|
+
lines.push('```typescript');
|
|
134
|
+
lines.push(content.trimEnd());
|
|
135
|
+
lines.push('```');
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
for (let i = 0; i < input.edits.length; i += 1) {
|
|
139
|
+
const edit = input.edits[i];
|
|
140
|
+
lines.push(`### Edit ${String(i + 1)} of ${String(input.edits.length)}`);
|
|
141
|
+
lines.push('');
|
|
142
|
+
lines.push('**old_string:**');
|
|
143
|
+
lines.push('```typescript');
|
|
144
|
+
lines.push(edit.oldString.trimEnd());
|
|
145
|
+
lines.push('```');
|
|
146
|
+
lines.push('');
|
|
147
|
+
lines.push('**new_string:**');
|
|
148
|
+
lines.push('```typescript');
|
|
149
|
+
lines.push(edit.newString.trimEnd());
|
|
150
|
+
lines.push('```');
|
|
151
|
+
lines.push('');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return lines.join('\n') + '\n';
|
|
155
|
+
}
|
|
156
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
157
|
+
function rotateLogFile(logPath, prevPath) {
|
|
158
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
159
|
+
try {
|
|
160
|
+
const stat = fs.statSync(logPath);
|
|
161
|
+
if (stat.size > MAX_LOG_BYTES) {
|
|
162
|
+
if (fs.existsSync(prevPath))
|
|
163
|
+
fs.unlinkSync(prevPath);
|
|
164
|
+
fs.renameSync(logPath, prevPath);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
//const error = toError(err);
|
|
169
|
+
void err;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The 7-day sweep over rejection DETAIL files.
|
|
174
|
+
*
|
|
175
|
+
* A class rather than four module-scope helpers because the four belong together: `prune` is the
|
|
176
|
+
* policy and the other three are the swallow-everything filesystem calls it is built from, none of
|
|
177
|
+
* which means anything on its own.
|
|
178
|
+
*
|
|
179
|
+
* The age comes out of the FILENAME, not out of `stat` — the epoch millis are already in the name, so
|
|
180
|
+
* a sweep costs one `readdir` per stream directory and no syscall per file. (The old scheme could
|
|
181
|
+
* delete a whole `hooks/<YYYY-MM-DD>/` in one recursive `rm` because the date WAS the directory; the
|
|
182
|
+
* directory is now the WRITER, which never expires, so expiry moved down one level.)
|
|
183
|
+
*
|
|
184
|
+
* IDEMPOTENT AND RACE-TOLERANT ON PURPOSE. Several agents sweep the same directory concurrently, so
|
|
185
|
+
* two processes will regularly try to unlink the same week-old file and to rmdir the same emptied
|
|
186
|
+
* directory. `force: true` makes an already-gone target a no-op, an rmdir of a still-populated (or
|
|
187
|
+
* already-removed) directory fails harmlessly, and every error is swallowed: the loser of the race
|
|
188
|
+
* does nothing and reports nothing, which is the correct outcome — the file is gone either way.
|
|
189
|
+
*/
|
|
190
|
+
class DetailPruner {
|
|
191
|
+
prune(logsDir, maxAgeDays) {
|
|
192
|
+
const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;
|
|
193
|
+
for (const dirName of this.readdirOrEmpty(logsDir)) {
|
|
194
|
+
const dir = path.join(logsDir, dirName);
|
|
195
|
+
if (!this.isDirectory(dir))
|
|
196
|
+
continue;
|
|
197
|
+
const names = this.readdirOrEmpty(dir);
|
|
198
|
+
let removed = 0;
|
|
199
|
+
for (const name of names) {
|
|
200
|
+
const match = DETAIL_RE.exec(name);
|
|
201
|
+
if (match === null)
|
|
202
|
+
continue;
|
|
203
|
+
if (Number(match[1]) >= cutoff)
|
|
204
|
+
continue;
|
|
205
|
+
this.removeFile(path.join(dir, name));
|
|
206
|
+
removed += 1;
|
|
207
|
+
}
|
|
208
|
+
// Only a directory we just emptied is a candidate, and the removal is a NON-recursive rmdir
|
|
209
|
+
// on purpose: it fails harmlessly if a concurrent writer dropped a fresh detail in between,
|
|
210
|
+
// so the sweep can never take a file it did not decide was expired.
|
|
211
|
+
if (removed > 0 && removed === names.length)
|
|
212
|
+
this.removeEmptyDir(dir);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
readdirOrEmpty(dir) {
|
|
216
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
217
|
+
try {
|
|
218
|
+
return fs.readdirSync(dir);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
const error = (0, to_error_1.toError)(err);
|
|
222
|
+
void error;
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
isDirectory(target) {
|
|
227
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
228
|
+
try {
|
|
229
|
+
return fs.statSync(target).isDirectory();
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
const error = (0, to_error_1.toError)(err);
|
|
233
|
+
void error;
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// `force: true` is what makes the concurrent sweep harmless: a file another agent already deleted
|
|
238
|
+
// is a no-op rather than an ENOENT.
|
|
239
|
+
removeFile(target) {
|
|
240
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
241
|
+
try {
|
|
242
|
+
fs.rmSync(target, { force: true });
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
const error = (0, to_error_1.toError)(err);
|
|
246
|
+
void error;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// NON-recursive by design — see prune(). This must refuse a directory that is not empty.
|
|
250
|
+
removeEmptyDir(target) {
|
|
251
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
252
|
+
try {
|
|
253
|
+
fs.rmdirSync(target);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
const error = (0, to_error_1.toError)(err);
|
|
257
|
+
void error;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const detailPruner = new DetailPruner();
|
|
262
|
+
//# sourceMappingURL=rejection-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection-log.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/rejection-log.ts"],"names":[],"mappings":";;AA2CA,oCAoDC;AAmBD,4CASC;;AA3HD,+CAAyB;AACzB,mDAA6B;AAE7B,8DAAyD;AACzD,0DAAyD;AACzD,+CAAkD;AAGlD,6CAAyC;AACzC,uDAAkD;AAClD,iEAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,aAAa,GAAG,YAAY,CAAC;AACnC,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAC1C,MAAM,aAAa,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,gCAAgC;AAClE,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAE1C,mKAAmK;AACnK,SAAgB,YAAY,CACxB,QAAkB,EAClB,KAA0B,EAC1B,MAAqB,EACrB,GAAW;IAEX,8DAA8D;IAC9D,IAAI,CAAC;QACD,4FAA4F;QAC5F,iFAAiF;QACjF,MAAM,IAAI,GAAG,IAAI,6BAAc,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAEtC,8FAA8F;QAC9F,mFAAmF;QACnF,MAAM,OAAO,GAAG,6BAAY,CAAC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SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;QACf,CAAC;IACL,CAAC;CACJ;AAED,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\nimport { RepoRootFinder } from '@webpieces/rules-config';\nimport { REJECTIONS_STREAM } from './log-streams';\n\nimport type { ToolKind, NormalizedToolInput, BlockedResult } from '@webpieces/hook-runtime';\nimport { logStream } from './log-stream';\nimport { aiTypeContext } from './ai-type-context';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n/**\n * The rejection index and its detail files, BOTH inside the `rejections/` stream directory, both\n * named by the same writer key:\n *\n * logs/rejections/<sid>-<agent>-<hook>.log ← the index (one line per block)\n * logs/rejections/<sid>-<agent>-<hook>/ ← its detail dir, SAME key\n * writeInfo-<epochMs>.md\n *\n * The detail files used to be `hooks/<YYYY-MM-DD>/writeInfo-<epochMs>.md` — a directory keyed only by\n * the DATE, shared by every writer in the tree, written with a raw `writeFileSync`. Two agents blocked\n * in the same millisecond produced the same path and one silently overwrote the other's evidence. The\n * comment that licensed it claimed a per-worktree log has exactly one writer; LogStream's class\n * comment is the measurement that disproves it (parallel PreToolUse hooks, non-isolated subagents and\n * multiple Claude Code windows all share a tree). Naming the directory after the LOG THAT POINTS AT IT\n * gives it the same one-owner-by-construction property the log itself has, and makes the pointer\n * readable: the index line, the directory and the file are one name.\n *\n * RETENTION is therefore filename-based, not directory-date-based: there is no date level left, so\n * `DetailPruner` parses `<epochMs>` out of each `writeInfo-*.md` (no `stat` call) and removes any\n * stream directory left empty. Every delete is `force: true` and failures are swallowed, so concurrent\n * agents racing the same week-old files is harmless.\n */\nconst DETAIL_PREFIX = 'writeInfo-';\nconst DETAIL_SUFFIX = '.md';\nconst DETAIL_RE = /^writeInfo-(\\d+)\\.md$/;\nconst MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded\nconst MAX_AGE_DAYS = 7;\n\nconst RULE_NAME_RE = /^\\[([^\\]]+)\\] \\(/gm;\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function logRejection(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n result: BlockedResult,\n cwd: string,\n): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // `.webpieces/` lives at the repo root, NOT the AI's cwd — resolve it so a hook fired while\n // the AI is in a subdirectory never scatters a stray `<subdir>/.webpieces` tree.\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n const now = new Date();\n const timestamp = now.toISOString();\n const epochMs = String(now.getTime());\n\n // LOCAL scope — a rejection is this worktree's event. WHICH writer's event is answered by the\n // stream prefix, on the index AND on its detail directory, so neither can collide.\n const logsDir = dotWebpieces.logsFile(root, REJECTIONS_STREAM);\n // The detail directory is the writer key with NO extension, sitting beside the `.log` that\n // indexes it — so index and details share one owner, one level down inside the stream dir.\n const detailDirName = logStream.writerFile('');\n const detailDir = path.join(logsDir, detailDirName);\n fs.mkdirSync(detailDir, { recursive: true });\n\n const relativePath = computeRelativePath(input.filePath, root);\n const ruleNames = extractRuleNames(result.report);\n const detailFileName = `${DETAIL_PREFIX}${epochMs}${DETAIL_SUFFIX}`;\n // Relative to `rejections/` — the index's own directory — so the pointer resolves from where\n // the reader found the line, and reads as the log's own name plus a file.\n const detailRelPath = `${detailDirName}/${detailFileName}`;\n\n const detail = buildDetailContent(timestamp, toolKind, relativePath, ruleNames, result.report, input);\n fs.writeFileSync(path.join(detailDir, detailFileName), detail);\n\n const logPath = path.join(logsDir, logStream.writerFile('.log'));\n rotateLogFile(logPath, path.join(logsDir, logStream.writerFile('.1.log')));\n\n // APPEND-ONLY, and `fault=` is spelled exactly as the L0 sh log spells it. A fault-S storm\n // previously landed here as a couple of lines attributed to whatever rule the report happened\n // to cite, with nothing anywhere identifying L0 as the cause. (WHO made the call is answered by\n // the filename, which logStream prefixes with session/agent/hook — not by a column here.)\n // `ai=` joins the same append-only tail as `fault=`, in the same vocabulary the L0 sh shim and\n // both decision streams use — so `grep ai=codex` spans all five streams. A row from a release\n // that predates the field carries no `ai=` and reads as `unknown`.\n const logLine = `[${timestamp}]\\t${toolKind}\\t${relativePath}\\t[${ruleNames.join(',')}]\\t${detailRelPath}\\tfault=${result.fault}\\tai=${aiTypeContext.forLog()}\\n`;\n fs.appendFileSync(logPath, logLine);\n\n detailPruner.prune(logsDir, MAX_AGE_DAYS);\n } catch (err: unknown) {\n //const error = toError(err);\n void err;\n }\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction computeRelativePath(filePath: string, cwd: string): string {\n if (filePath.startsWith(cwd)) {\n const rel = filePath.slice(cwd.length);\n if (rel.startsWith('/')) return rel.slice(1);\n return rel;\n }\n return filePath;\n}\n\n/**\n * The rule names a block report cites — every `[<rule-name>] (` header it opens with. Exported because\n * two audit streams need the same answer from the same regex: this file's rejection index, and the\n * `rule=` field the `calls/` stream now carries (see InvocationLog.finish). Two scrapers would be\n * two answers to one question.\n */\n// webpieces-disable no-function-outside-class -- pure regex scraper beside this module's other module-scope helpers; exported so the invocation log and the rejection index scrape rule names with the SAME code.\nexport function extractRuleNames(report: string): string[] {\n const names: string[] = [];\n let match = RULE_NAME_RE.exec(report);\n while (match !== null) {\n names.push(match[1]);\n match = RULE_NAME_RE.exec(report);\n }\n RULE_NAME_RE.lastIndex = 0;\n return names;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction buildDetailContent(\n timestamp: string,\n toolKind: ToolKind,\n relativePath: string,\n ruleNames: string[],\n report: string,\n input: NormalizedToolInput,\n): string {\n const lines: string[] = [];\n lines.push('# Hook Rejection Detail');\n lines.push('');\n lines.push(`- **Timestamp:** ${timestamp}`);\n lines.push(`- **Tool:** ${toolKind}`);\n lines.push(`- **File:** ${relativePath}`);\n lines.push(`- **Rules violated:** ${ruleNames.join(', ')}`);\n lines.push('');\n lines.push('## Report');\n lines.push('');\n lines.push('```');\n lines.push(report.trimEnd());\n lines.push('```');\n lines.push('');\n lines.push('## Content Being Written');\n lines.push('');\n\n if (toolKind === 'Write') {\n const content = input.edits.length > 0 ? input.edits[0].newString : '';\n lines.push('```typescript');\n lines.push(content.trimEnd());\n lines.push('```');\n } else {\n for (let i = 0; i < input.edits.length; i += 1) {\n const edit = input.edits[i];\n lines.push(`### Edit ${String(i + 1)} of ${String(input.edits.length)}`);\n lines.push('');\n lines.push('**old_string:**');\n lines.push('```typescript');\n lines.push(edit.oldString.trimEnd());\n lines.push('```');\n lines.push('');\n lines.push('**new_string:**');\n lines.push('```typescript');\n lines.push(edit.newString.trimEnd());\n lines.push('```');\n lines.push('');\n }\n }\n\n return lines.join('\\n') + '\\n';\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction rotateLogFile(logPath: string, prevPath: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const stat = fs.statSync(logPath);\n if (stat.size > MAX_LOG_BYTES) {\n if (fs.existsSync(prevPath)) fs.unlinkSync(prevPath);\n fs.renameSync(logPath, prevPath);\n }\n } catch (err: unknown) {\n //const error = toError(err);\n void err;\n }\n}\n\n/**\n * The 7-day sweep over rejection DETAIL files.\n *\n * A class rather than four module-scope helpers because the four belong together: `prune` is the\n * policy and the other three are the swallow-everything filesystem calls it is built from, none of\n * which means anything on its own.\n *\n * The age comes out of the FILENAME, not out of `stat` — the epoch millis are already in the name, so\n * a sweep costs one `readdir` per stream directory and no syscall per file. (The old scheme could\n * delete a whole `hooks/<YYYY-MM-DD>/` in one recursive `rm` because the date WAS the directory; the\n * directory is now the WRITER, which never expires, so expiry moved down one level.)\n *\n * IDEMPOTENT AND RACE-TOLERANT ON PURPOSE. Several agents sweep the same directory concurrently, so\n * two processes will regularly try to unlink the same week-old file and to rmdir the same emptied\n * directory. `force: true` makes an already-gone target a no-op, an rmdir of a still-populated (or\n * already-removed) directory fails harmlessly, and every error is swallowed: the loser of the race\n * does nothing and reports nothing, which is the correct outcome — the file is gone either way.\n */\nclass DetailPruner {\n prune(logsDir: string, maxAgeDays: number): void {\n const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;\n for (const dirName of this.readdirOrEmpty(logsDir)) {\n const dir = path.join(logsDir, dirName);\n if (!this.isDirectory(dir)) continue;\n const names = this.readdirOrEmpty(dir);\n let removed = 0;\n for (const name of names) {\n const match = DETAIL_RE.exec(name);\n if (match === null) continue;\n if (Number(match[1]) >= cutoff) continue;\n this.removeFile(path.join(dir, name));\n removed += 1;\n }\n // Only a directory we just emptied is a candidate, and the removal is a NON-recursive rmdir\n // on purpose: it fails harmlessly if a concurrent writer dropped a fresh detail in between,\n // so the sweep can never take a file it did not decide was expired.\n if (removed > 0 && removed === names.length) this.removeEmptyDir(dir);\n }\n }\n\n private readdirOrEmpty(dir: string): string[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.readdirSync(dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n private isDirectory(target: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.statSync(target).isDirectory();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // `force: true` is what makes the concurrent sweep harmless: a file another agent already deleted\n // is a no-op rather than an ENOENT.\n private removeFile(target: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmSync(target, { force: true });\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n\n // NON-recursive by design — see prune(). This must refuse a directory that is not empty.\n private removeEmptyDir(target: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmdirSync(target);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n}\n\nconst detailPruner = new DetailPruner();\n"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BranchCreationGuardConfig } from "../../configs/rule-configs";
|
|
2
|
+
import type { BashContext, Violation } from '@webpieces/hook-runtime';
|
|
3
|
+
import { BashRuleBase } from '@webpieces/hook-runtime';
|
|
4
|
+
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
+
export declare class BranchCreationGuardRule extends BashRuleBase<BranchCreationGuardConfig> {
|
|
6
|
+
constructor(config: BranchCreationGuardConfig);
|
|
7
|
+
readonly description: string;
|
|
8
|
+
readonly defaultOptions: {
|
|
9
|
+
branchFormat: string;
|
|
10
|
+
maxLocalBranches: number;
|
|
11
|
+
maxWorktrees: number;
|
|
12
|
+
};
|
|
13
|
+
private readonly worktrees;
|
|
14
|
+
private readonly mergedBranches;
|
|
15
|
+
private readonly branchIdentity;
|
|
16
|
+
private capCache;
|
|
17
|
+
private worktreeCapCache;
|
|
18
|
+
private worktreeAdd;
|
|
19
|
+
private get branchFormat();
|
|
20
|
+
private get subBranchNaming();
|
|
21
|
+
private get maxLocalBranches();
|
|
22
|
+
private get maxWorktrees();
|
|
23
|
+
private freshMainCommand;
|
|
24
|
+
get fixHint(): FixHint;
|
|
25
|
+
/**
|
|
26
|
+
* Strip the parts of a shell command that are DATA rather than executable commands, so the guard
|
|
27
|
+
* stops reading prose as instructions.
|
|
28
|
+
*
|
|
29
|
+
* This guard regex-scans the raw command string and has no notion of quoting, so
|
|
30
|
+
* `git commit -m "... git checkout -b foo ..."` — or any heredoc commit message that mentions a
|
|
31
|
+
* branch command — was parsed as an actual branch creation and blocked. That bit three separate
|
|
32
|
+
* times while building the branch cap, including on the cap's own commit. It matters far more now
|
|
33
|
+
* that the cap check runs BEFORE the origin/main allow: at the cap, a merely-MENTIONED branch
|
|
34
|
+
* command would block your commit.
|
|
35
|
+
*
|
|
36
|
+
* A quoted span whose content has no whitespace is kept verbatim (it is a single token — the name
|
|
37
|
+
* in `git checkout -b "dean/foo"`), so quoting a branch name cannot smuggle a creation past the
|
|
38
|
+
* guard. Anything with whitespace inside quotes is prose, and collapses to a space.
|
|
39
|
+
*/
|
|
40
|
+
check(ctx: BashContext): readonly Violation[];
|
|
41
|
+
/**
|
|
42
|
+
* `git worktree add ../dir <existing-branch>` onto a branch whose PR is ALREADY MERGED.
|
|
43
|
+
*
|
|
44
|
+
* The count caps never catch this: the command creates no branch, and if you are under the
|
|
45
|
+
* worktree cap it sails straight through — materialising a fresh directory full of PRE-MERGE
|
|
46
|
+
* code that the AI will then read, plan from and edit. read-stale-guard blocks the reads and
|
|
47
|
+
* feature-branch-guard blocks the edits once you are in there, but that is a turn wasted per
|
|
48
|
+
* tool call. Refuse at the moment of creation instead, using the SAME merged-PR proof the caps
|
|
49
|
+
* already have precomputed on disk.
|
|
50
|
+
*
|
|
51
|
+
* Fails OPEN exactly like both caps: no cache (fresh clone, no `gh`, refresher hasn't run) or an
|
|
52
|
+
* unparseable command → no opinion.
|
|
53
|
+
*/
|
|
54
|
+
private checkWorktreeOntoDeadBranch;
|
|
55
|
+
private checkReservedSuffix;
|
|
56
|
+
/**
|
|
57
|
+
* Both budgets, in the order that produces the most useful complaint.
|
|
58
|
+
*
|
|
59
|
+
* Called BEFORE the origin/main allow in check() — `... -b <name> origin/main` is the normal,
|
|
60
|
+
* always-permitted path, so a cap checked after it would never once fire.
|
|
61
|
+
*
|
|
62
|
+
* Worktree cap first: a `git worktree add -b` spends BOTH budgets, and when both are full the
|
|
63
|
+
* worktree is the thing the command was actually trying to make, so it is the thing to talk about.
|
|
64
|
+
*/
|
|
65
|
+
private checkCaps;
|
|
66
|
+
/**
|
|
67
|
+
* The cap. Blocks branch #N+1 until already-merged branches are reaped, which is the ONLY thing
|
|
68
|
+
* keeping the local branch list bounded.
|
|
69
|
+
*
|
|
70
|
+
* Fails OPEN when the cache is absent (fresh clone, `gh` unavailable, refresher hasn't run yet):
|
|
71
|
+
* never block on data we don't have. The detached refresher regenerates it within one hook call,
|
|
72
|
+
* so the cap starts enforcing on its own.
|
|
73
|
+
*/
|
|
74
|
+
private checkBranchCap;
|
|
75
|
+
/**
|
|
76
|
+
* The cache, with entries for branches/worktrees that no longer exist dropped.
|
|
77
|
+
*
|
|
78
|
+
* Reconciling is the fix for the phantom count: the file is written by a detached refresher and is
|
|
79
|
+
* DELIBERATELY allowed to go stale, so it keeps naming branches deleted minutes ago and worktrees
|
|
80
|
+
* already removed. Quoting it verbatim is how the guard announced "8 parked local branches … none of
|
|
81
|
+
* them are dead" over a repo that had ONE, and then blocked a legitimate `git worktree add` on that
|
|
82
|
+
* figure. `reconcile` re-checks existence with instant local git reads; it does NOT re-derive any
|
|
83
|
+
* verdict (that needs the network and belongs in the refresher).
|
|
84
|
+
*
|
|
85
|
+
* Its AGE is no longer read here. The cap messages stopped quoting verdict counts entirely, so
|
|
86
|
+
* there is nothing left for a freshness caveat to qualify — `wp-cleanup` recomputes from scratch.
|
|
87
|
+
*/
|
|
88
|
+
private loadReconciledCache;
|
|
89
|
+
/**
|
|
90
|
+
* The branch cap, yielding by ONE when the agent is standing on an already-merged branch.
|
|
91
|
+
*
|
|
92
|
+
* Two individually-correct guards were composing into a trap: merged-branch-bash-guard blocks
|
|
93
|
+
* almost all Bash until you get off a merged branch, and the ONLY way off it that guard advertises
|
|
94
|
+
* is creating a fresh branch — which this cap then refused. Every printed exit led to editing
|
|
95
|
+
* webpieces.config.json, and that is what an unsupervised agent did.
|
|
96
|
+
*
|
|
97
|
+
* One over cap, and only while a merged branch is what is pushing you: the branch about to be
|
|
98
|
+
* created replaces a branch that is already dead, so the steady-state count does not grow. The cap
|
|
99
|
+
* still fires on the NEXT creation, so this defers the cleanup by exactly one branch, never skips it.
|
|
100
|
+
*
|
|
101
|
+
* Fails toward the strict cap: no cache, a cache for another branch, or a clean branch → no yield.
|
|
102
|
+
*/
|
|
103
|
+
private effectiveBranchCap;
|
|
104
|
+
private currentBranchOrNull;
|
|
105
|
+
/**
|
|
106
|
+
* The worktree cap — the second budget. Same gate, same fail-open rule as the branch cap: a
|
|
107
|
+
* worktree list we cannot classify (no cache on disk) blocks nothing.
|
|
108
|
+
*
|
|
109
|
+
* Counts LINKED worktrees only. The primary clone is not a thing anyone can remove, so charging the
|
|
110
|
+
* budget for it would just silently cost you one worktree.
|
|
111
|
+
*/
|
|
112
|
+
private checkWorktreeCap;
|
|
113
|
+
}
|