@rt-tools/agent-kit 0.37.0 → 0.38.0
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 +5 -5
- package/assets/checks/action-of.mjs +154 -0
- package/assets/checks/board-pull-state.github.mjs +82 -13
- package/assets/checks/board-runs.github.mjs +40 -5
- package/assets/checks/board.github.mjs +1 -1
- package/assets/checks/check-board.github.mjs +58 -19
- package/assets/checks/check-specs.mjs +2 -2
- package/assets/checks/check-state-next.mjs +22 -10
- package/assets/checks/check-turn-map.mjs +26 -6
- package/assets/checks/check-work-steps.mjs +4 -173
- package/assets/checks/decide.mjs +285 -0
- package/assets/checks/decision-table.json +21365 -0
- package/assets/checks/decision-table.mjs +495 -0
- package/assets/checks/epic-table.github.mjs +4 -3
- package/assets/checks/epic-window.mjs +98 -0
- package/assets/checks/flow-condition.mjs +64 -0
- package/assets/checks/flow-data.mjs +136 -0
- package/assets/checks/flow-forecast.mjs +330 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +294 -0
- package/assets/checks/flow-model.mjs +271 -0
- package/assets/checks/flow-override.mjs +130 -0
- package/assets/checks/flow-plan.mjs +206 -0
- package/assets/checks/flow-scaffold.mjs +224 -0
- package/assets/checks/flow-step.mjs +365 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +112 -0
- package/assets/checks/lib-common.mjs +10 -2
- package/assets/checks/lib-domains.mjs +1 -1
- package/assets/checks/lib-manifests.mjs +34 -2
- package/assets/checks/merge-read.mjs +239 -0
- package/assets/checks/owner-nudges.mjs +389 -0
- package/assets/checks/push-inputs.mjs +444 -0
- package/assets/checks/push-trace.mjs +108 -0
- package/assets/checks/record-count.mjs +410 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/rt-kit-checks.config.mjs +17 -2
- package/assets/checks/spec-anchors.mjs +4 -4
- package/assets/checks/spec-contract.mjs +5 -5
- package/assets/checks/task-flow-script.mjs +292 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +281 -0
- package/assets/checks/work-steps-lib.mjs +205 -0
- package/assets/commands/next-session.md +3 -1
- package/assets/commands/night.md +28 -18
- package/assets/defaults/gate-map.sh +39 -12
- package/assets/defaults/merges.sh +48 -0
- package/assets/defaults/project.sh +43 -13
- package/assets/defaults/push.sh +23 -0
- package/assets/defaults/turn-map.md +24 -21
- package/assets/docs/GLOSSARY.md +6 -2
- package/assets/hooks/ask-judge.md +65 -0
- package/assets/hooks/browser-guard-device-id.sh +11 -9
- package/assets/hooks/browser-guard-no-asking.sh +12 -6
- package/assets/hooks/browser-guard-no-listing.sh +13 -7
- package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
- package/assets/hooks/browser-guard-require-select.sh +15 -15
- package/assets/hooks/commit-msg.sh +13 -3
- package/assets/hooks/conscience-guard.sh +9 -25
- package/assets/hooks/decide.sh +141 -0
- package/assets/hooks/deny-tail.sh +16 -11
- package/assets/hooks/dev-server-guard.sh +27 -20
- package/assets/hooks/dispatch.sh +47 -4
- package/assets/hooks/docs-guard.sh +31 -200
- package/assets/hooks/end-conversation-guard.sh +12 -21
- package/assets/hooks/epic-stop-guard.sh +54 -105
- package/assets/hooks/exam-guard.sh +32 -65
- package/assets/hooks/facts-docs.sh +221 -0
- package/assets/hooks/facts-flow.sh +173 -0
- package/assets/hooks/facts.sh +308 -0
- package/assets/hooks/flow-step-guard.sh +93 -0
- package/assets/hooks/git-guard-delivery-body.sh +4 -4
- package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
- package/assets/hooks/git-guard-delivery-draft.sh +3 -3
- package/assets/hooks/git-guard-delivery-epic.sh +18 -9
- package/assets/hooks/git-guard-delivery-folder.sh +32 -7
- package/assets/hooks/git-guard-delivery-merge.sh +2 -2
- package/assets/hooks/git-guard-delivery-merged.sh +12 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
- package/assets/hooks/git-guard-delivery-rerun.sh +32 -0
- package/assets/hooks/git-guard-delivery-signature.sh +82 -45
- package/assets/hooks/git-guard-delivery-task.sh +47 -0
- package/assets/hooks/git-guard-delivery.sh +112 -101
- package/assets/hooks/git-guard-discard.sh +8 -18
- package/assets/hooks/git-guard-main.sh +13 -19
- package/assets/hooks/git-guard-no-verify.sh +56 -16
- package/assets/hooks/git-guard-push-ahead.sh +46 -5
- package/assets/hooks/git-guard-push-marks.sh +227 -31
- package/assets/hooks/git-guard-push-tests.sh +51 -53
- package/assets/hooks/git-guard-tree-assignment.sh +7 -4
- package/assets/hooks/guard-note.sh +8 -6
- package/assets/hooks/handoff-entry-guard.sh +20 -39
- package/assets/hooks/handoff-write.sh +3 -1
- package/assets/hooks/hook-input.sh +0 -41
- package/assets/hooks/metric-marks.sh +19 -7
- package/assets/hooks/observe.sh +1 -1
- package/assets/hooks/override-write-guard.sh +27 -9
- package/assets/hooks/pre-push.sh +20 -10
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-set.sh +39 -7
- package/assets/hooks/qa-dataid-guard.sh +7 -17
- package/assets/hooks/record-turn.sh +52 -0
- package/assets/hooks/rerun-guard.sh +11 -16
- package/assets/hooks/reuse-first-guard.sh +7 -21
- package/assets/hooks/role-calls.sh +25 -3
- package/assets/hooks/rule-source-guard.sh +54 -21
- package/assets/hooks/skill-gate-rearm.sh +18 -5
- package/assets/hooks/skill-gate.sh +156 -20
- package/assets/hooks/skill-loaded.sh +18 -3
- package/assets/hooks/sql-guard-target.sh +2 -2
- package/assets/hooks/sql-guard-write.sh +12 -12
- package/assets/hooks/sql-guard.sh +58 -16
- package/assets/hooks/task-context-load.sh +3 -1
- package/assets/hooks/task-flow-context.sh +20 -22
- package/assets/hooks/task-flow-draft-guard.sh +25 -74
- package/assets/hooks/task-flow-guard.sh +28 -129
- package/assets/hooks/tree-assignment-guard.sh +25 -14
- package/assets/hooks/turn-entry-load.sh +3 -1
- package/assets/hooks/turn-exit-guard.sh +92 -452
- package/assets/hooks/turn-exit-role.sh +47 -0
- package/assets/hooks/turn-judge.md +103 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- package/assets/laws/work-conduct.md +9 -8
- package/assets/patterns/autonomous-work-run.md +35 -10
- package/assets/patterns/browser-verification-measure.md +10 -20
- package/assets/patterns/browser-verification-stand.md +30 -42
- package/assets/patterns/doc-style-human.md +0 -6
- package/assets/patterns/doc-style-sweep.md +7 -7
- package/assets/patterns/doc-style-trace.md +5 -4
- package/assets/patterns/doc-style-write.md +7 -7
- package/assets/patterns/epic-flow-declare.md +15 -8
- package/assets/patterns/git-workflow-commit.azure.md +9 -155
- package/assets/patterns/git-workflow-commit.github.md +11 -269
- package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
- package/assets/patterns/git-workflow-docker.md +8 -231
- package/assets/patterns/git-workflow-freshness.md +9 -56
- package/assets/patterns/git-workflow-merge.md +7 -174
- package/assets/patterns/git-workflow-migration.md +5 -73
- package/assets/patterns/git-workflow-pr-body.github.md +6 -159
- package/assets/patterns/git-workflow-pr-ready.md +9 -69
- package/assets/patterns/git-workflow-pr.azure.md +14 -220
- package/assets/patterns/git-workflow-pr.github.md +13 -253
- package/assets/patterns/git-workflow-pr.gitlab.md +14 -241
- package/assets/patterns/git-workflow-restart.md +5 -41
- package/assets/patterns/git-workflow-secrets.md +10 -76
- package/assets/patterns/git-workflow-stack.md +9 -205
- package/assets/patterns/lib-layers-new.md +7 -3
- package/assets/patterns/queue-audit-read.github.md +9 -3
- package/assets/patterns/spec-driven-domain.md +50 -48
- package/assets/patterns/spec-driven-rule.md +18 -19
- package/assets/patterns/status-report-table.github.md +2 -2
- package/assets/patterns/task-flow-archive.md +15 -256
- package/assets/patterns/task-flow-close.md +16 -291
- package/assets/patterns/task-flow-cycle.md +13 -39
- package/assets/patterns/task-flow-graph.needs-graph.md +8 -58
- package/assets/patterns/task-flow-handoff.md +13 -161
- package/assets/patterns/task-flow-resume.md +19 -183
- package/assets/patterns/task-flow-start.md +9 -248
- package/assets/patterns/testing-e2e.md +14 -18
- package/assets/patterns/testing-unit.md +9 -13
- package/assets/patterns/turn-entry-map.md +15 -5
- package/assets/pitfalls/agent-kit-extend.md +200 -0
- package/assets/pitfalls/agent-kit.2.md +323 -0
- package/assets/pitfalls/angular-patterns.md +98 -0
- package/assets/pitfalls/autonomous-work.md +15 -0
- package/assets/pitfalls/browser-verification.md +265 -0
- package/assets/pitfalls/component-structure.md +98 -0
- package/assets/pitfalls/dependencies.md +92 -0
- package/assets/pitfalls/deploy-flow.azure.md +171 -0
- package/assets/pitfalls/deploy-flow.github.md +211 -0
- package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
- package/assets/pitfalls/doc-style.2.md +286 -0
- package/assets/pitfalls/doc-style.md +3 -3
- package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
- package/assets/pitfalls/entity-models.md +89 -0
- package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
- package/assets/pitfalls/git-workflow-commit.github.md +307 -0
- package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
- package/assets/pitfalls/git-workflow-docker.md +275 -0
- package/assets/pitfalls/git-workflow-freshness.md +88 -0
- package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
- package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
- package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
- package/assets/pitfalls/git-workflow-merge.md +220 -0
- package/assets/pitfalls/git-workflow-migration.md +103 -0
- package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
- package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
- package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
- package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
- package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
- package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
- package/assets/pitfalls/git-workflow-pr.github.md +107 -0
- package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
- package/assets/pitfalls/git-workflow-push.azure.md +30 -0
- package/assets/pitfalls/git-workflow-push.github.md +30 -0
- package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
- package/assets/pitfalls/git-workflow-queue.github.md +30 -0
- package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-restart.md +72 -0
- package/assets/pitfalls/git-workflow-secrets.md +114 -0
- package/assets/pitfalls/git-workflow-stack.md +254 -0
- package/assets/pitfalls/git-workflow.2.azure.md +291 -0
- package/assets/pitfalls/git-workflow.2.github.md +294 -0
- package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
- package/assets/pitfalls/git-workflow.github.md +5 -9
- package/assets/pitfalls/lib-layers.md +114 -0
- package/assets/pitfalls/lists.md +117 -0
- package/assets/pitfalls/navigation.md +94 -0
- package/assets/pitfalls/reuse-first.md +201 -0
- package/assets/pitfalls/spec-driven.2.md +318 -0
- package/assets/pitfalls/spec-driven.md +9 -7
- package/assets/pitfalls/styling-bem.2.md +125 -0
- package/assets/pitfalls/task-flow-archive.md +264 -0
- package/assets/pitfalls/task-flow-close.2.md +165 -0
- package/assets/pitfalls/task-flow-close.md +167 -0
- package/assets/pitfalls/task-flow-cycle.md +73 -0
- package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
- package/assets/pitfalls/task-flow-handoff.md +200 -0
- package/assets/pitfalls/task-flow-handover.md +30 -0
- package/assets/pitfalls/task-flow-owner.md +29 -0
- package/assets/pitfalls/task-flow-plan.md +29 -0
- package/assets/pitfalls/task-flow-resume.md +257 -0
- package/assets/pitfalls/task-flow-start.md +287 -0
- package/assets/pitfalls/task-flow.2.md +303 -0
- package/assets/pitfalls/task-flow.md +18 -29
- package/assets/pitfalls/testing.2.md +279 -0
- package/assets/pitfalls/testing.md +11 -12
- package/assets/pitfalls/turn-conduct.md +17 -18
- package/assets/pitfalls/typescript-conventions.md +161 -0
- package/assets/pitfalls/write-a-skill.md +128 -0
- package/assets/rules/angular-patterns.md +21 -86
- package/assets/rules/autonomous-work.md +37 -29
- package/assets/rules/browser-verification.md +28 -251
- package/assets/rules/component-structure.md +25 -87
- package/assets/rules/dependencies.md +20 -78
- package/assets/rules/deploy-flow.azure.md +27 -134
- package/assets/rules/deploy-flow.github.md +34 -196
- package/assets/rules/deploy-flow.gitlab.md +28 -137
- package/assets/rules/doc-style.md +32 -282
- package/assets/rules/entity-conventions.needs-admin.md +26 -82
- package/assets/rules/entity-models.md +14 -63
- package/assets/rules/epic-flow.md +5 -3
- package/assets/rules/git-workflow-hosting.azure.md +26 -0
- package/assets/rules/git-workflow-hosting.github.md +38 -0
- package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
- package/assets/rules/git-workflow-push.azure.md +28 -0
- package/assets/rules/git-workflow-push.github.md +28 -0
- package/assets/rules/git-workflow-push.gitlab.md +28 -0
- package/assets/rules/git-workflow-queue.azure.md +23 -0
- package/assets/rules/git-workflow-queue.github.md +30 -0
- package/assets/rules/git-workflow-queue.gitlab.md +23 -0
- package/assets/rules/git-workflow.azure.md +21 -264
- package/assets/rules/git-workflow.github.md +24 -285
- package/assets/rules/git-workflow.gitlab.md +21 -258
- package/assets/rules/lib-layers.md +30 -103
- package/assets/rules/lists.md +21 -105
- package/assets/rules/navigation.md +10 -69
- package/assets/rules/queue-audit.github.md +5 -3
- package/assets/rules/reuse-first.md +20 -195
- package/assets/rules/spec-driven.md +35 -316
- package/assets/rules/status-report.md +5 -3
- package/assets/rules/styling-bem.md +20 -117
- package/assets/rules/task-flow-handover.md +24 -0
- package/assets/rules/task-flow-owner.md +34 -0
- package/assets/rules/task-flow-plan.md +38 -0
- package/assets/rules/task-flow.md +22 -289
- package/assets/rules/testing.md +32 -270
- package/assets/rules/turn-conduct.md +109 -111
- package/assets/rules/turn-entry.md +2 -2
- package/assets/rules/typescript-conventions.md +41 -147
- package/assets/samples/tasks/_template/plan.md +30 -6
- package/assets/samples/tasks/_template/progress.md +0 -1
- package/assets/skills/agent-kit-extend.md +25 -168
- package/assets/skills/agent-kit.md +27 -299
- package/assets/skills/write-a-skill.md +20 -106
- package/assets/task-flow/flow.js +188 -0
- package/assets/task-flow/flow.md +102 -0
- package/assets/task-flow/measure/agreement.mjs +24 -0
- package/assets/task-flow/measure/copy.mjs +22 -0
- package/assets/task-flow/measure/epic-of.mjs +50 -0
- package/assets/task-flow/measure/epic-text.mjs +35 -0
- package/assets/task-flow/measure/epic.mjs +114 -0
- package/assets/task-flow/measure/folder.mjs +16 -0
- package/assets/task-flow/measure/footprint.mjs +28 -0
- package/assets/task-flow/measure/grill.mjs +21 -0
- package/assets/task-flow/measure/host.mjs +8 -0
- package/assets/task-flow/measure/owner.mjs +20 -0
- package/assets/task-flow/measure/plan.mjs +27 -0
- package/assets/task-flow/measure/pr.mjs +20 -0
- package/assets/task-flow/measure/progress.mjs +50 -0
- package/assets/task-flow/measure/session.mjs +175 -0
- package/assets/task-flow/measure/task.mjs +23 -0
- package/assets/task-flow/measure/text.mjs +77 -0
- package/assets/task-flow/source/git.mjs +86 -0
- package/assets/task-flow/source/host.mjs +172 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +74 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +232 -0
- package/assets/task-flow/source/steps.mjs +28 -0
- package/assets/task-flow/source/tree.mjs +42 -0
- package/assets/templates/rule.md +2 -2
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +30 -0
- package/bin/agent-kit.js.map +1 -1
- package/lib/agent-checks.d.ts +55 -0
- package/lib/agent-checks.d.ts.map +1 -0
- package/lib/agent-checks.js +209 -0
- package/lib/agent-checks.js.map +1 -0
- package/lib/assets.d.ts.map +1 -1
- package/lib/assets.js +7 -2
- package/lib/assets.js.map +1 -1
- package/lib/cargo-prose.d.ts +2 -1
- package/lib/cargo-prose.d.ts.map +1 -1
- package/lib/cargo-prose.js.map +1 -1
- package/lib/cargo.d.ts +29 -0
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +27 -1
- package/lib/cargo.js.map +1 -1
- package/lib/cascade.d.ts.map +1 -1
- package/lib/cascade.js +3 -1
- package/lib/cascade.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +78 -2
- package/lib/commands.js.map +1 -1
- package/lib/companion.d.ts +0 -5
- package/lib/companion.d.ts.map +1 -1
- package/lib/companion.js +1 -1
- package/lib/companion.js.map +1 -1
- package/lib/config.d.ts +18 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +18 -1
- package/lib/config.js.map +1 -1
- package/lib/cost.d.ts +0 -8
- package/lib/cost.d.ts.map +1 -1
- package/lib/cost.js +4 -4
- package/lib/cost.js.map +1 -1
- package/lib/epic-window-send.d.ts +74 -0
- package/lib/epic-window-send.d.ts.map +1 -0
- package/lib/epic-window-send.js +166 -0
- package/lib/epic-window-send.js.map +1 -0
- package/lib/hooks-map.d.ts +4 -12
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +4 -27
- package/lib/hooks-map.js.map +1 -1
- package/lib/integrity.d.ts +3 -0
- package/lib/integrity.d.ts.map +1 -1
- package/lib/integrity.js +7 -0
- package/lib/integrity.js.map +1 -1
- package/lib/metric-lines.d.ts +2 -1
- package/lib/metric-lines.d.ts.map +1 -1
- package/lib/metric-lines.js +49 -1
- package/lib/metric-lines.js.map +1 -1
- package/lib/metric-send-mark.d.ts +6 -3
- package/lib/metric-send-mark.d.ts.map +1 -1
- package/lib/metric-send-mark.js +15 -5
- package/lib/metric-send-mark.js.map +1 -1
- package/lib/metric-send.d.ts +6 -2
- package/lib/metric-send.d.ts.map +1 -1
- package/lib/metric-send.js +47 -13
- package/lib/metric-send.js.map +1 -1
- package/lib/metrics.d.ts +17 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +26 -15
- package/lib/metrics.js.map +1 -1
- package/lib/observations-cargo.d.ts +1 -5
- package/lib/observations-cargo.d.ts.map +1 -1
- package/lib/observations-cargo.js +2 -2
- package/lib/observations-cargo.js.map +1 -1
- package/lib/observations.d.ts +0 -2
- package/lib/observations.d.ts.map +1 -1
- package/lib/observations.js +3 -3
- package/lib/observations.js.map +1 -1
- package/lib/order.d.ts +0 -2
- package/lib/order.d.ts.map +1 -1
- package/lib/order.js +0 -4
- package/lib/order.js.map +1 -1
- package/lib/outcomes.d.ts +7 -9
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +8 -7
- package/lib/outcomes.js.map +1 -1
- package/lib/proposals.d.ts +0 -1
- package/lib/proposals.d.ts.map +1 -1
- package/lib/proposals.js +1 -1
- package/lib/proposals.js.map +1 -1
- package/lib/push-gate.d.ts +13 -0
- package/lib/push-gate.d.ts.map +1 -1
- package/lib/push-gate.js +11 -7
- package/lib/push-gate.js.map +1 -1
- package/lib/push-set-usefulness.d.ts +78 -0
- package/lib/push-set-usefulness.d.ts.map +1 -0
- package/lib/push-set-usefulness.js +225 -0
- package/lib/push-set-usefulness.js.map +1 -0
- package/lib/shipment.d.ts +2 -11
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +0 -3
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +3 -3
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +2 -2
- package/lib/shipment.js.map +1 -1
- package/lib/sync.d.ts +10 -0
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +14 -1
- package/lib/sync.js.map +1 -1
- package/lib/traits.d.ts +0 -3
- package/lib/traits.d.ts.map +1 -1
- package/lib/traits.js +2 -2
- package/lib/traits.js.map +1 -1
- package/lib/variants.d.ts +0 -1
- package/lib/variants.d.ts.map +1 -1
- package/lib/variants.js +1 -1
- package/lib/variants.js.map +1 -1
- package/lib/work-result.d.ts +43 -0
- package/lib/work-result.d.ts.map +1 -0
- package/lib/work-result.js +39 -0
- package/lib/work-result.js.map +1 -0
- package/package.json +1 -1
- package/assets/checks/signals/ui-kit.json +0 -11
- package/assets/hooks/claim-guard.sh +0 -212
- package/assets/hooks/grill-gate-ask.sh +0 -26
- package/assets/hooks/grill-gate-bypass.sh +0 -61
- package/assets/hooks/grill-gate-options.sh +0 -50
- package/assets/hooks/grill-gate.sh +0 -482
- package/assets/hooks/postmortem-guard.sh +0 -124
- package/assets/hooks/proposal-guard.sh +0 -154
- package/assets/hooks/stand-login-guard.sh +0 -107
- package/assets/hooks/turn-exit-epic.sh +0 -173
- package/assets/hooks/turn-exit-patterns.sh +0 -123
- package/assets/hooks/turn-exit-verdict.sh +0 -149
- package/assets/hooks/waiting-turn-guard.sh +0 -320
- package/assets/hooks/work-start-guard.sh +0 -175
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The merges of requests and the editions of packages, read from the hosting and the registry and
|
|
4
|
+
* written as observations: what the day line and the epic windows are counted by.
|
|
5
|
+
*
|
|
6
|
+
* node merge-read.mjs --pulls <file> --observations <dir>
|
|
7
|
+
* [--main <branch>] [--packages <dir>,<dir>] [--ignore <pattern>] [--editions <pkg>=<file>]...
|
|
8
|
+
*
|
|
9
|
+
* `--pulls` holds the requests the hosting gave, one JSON object per line: `{number, state,
|
|
10
|
+
* headRefName, baseRefName, mergedAt, title, files}`, open requests included — they tell a task
|
|
11
|
+
* branch from an epic branch before the epic merges. `--editions` holds the answer of the registry
|
|
12
|
+
* for one package: the map of versions to their moments.
|
|
13
|
+
*
|
|
14
|
+
* What is written, by the day of the moment:
|
|
15
|
+
* task-merged a task request merged; `opens: "1"` when its base is an epic branch, `epic` its key
|
|
16
|
+
* epic-merged an epic request merged into the main branch; `pkg` the packages it changed
|
|
17
|
+
* edition a published version of a package of the tree
|
|
18
|
+
*
|
|
19
|
+
* A request and an edition are written once: a second read of the same fact replaces the line of the
|
|
20
|
+
* first, so a read that judged a fact anew corrects it. An answer that does not parse whole writes
|
|
21
|
+
* nothing: a broken read is taken again by the next one.
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { taskOf } from './record-count.mjs';
|
|
27
|
+
|
|
28
|
+
const MINUTE = 60 * 1000;
|
|
29
|
+
|
|
30
|
+
const option = (argv, name) => {
|
|
31
|
+
const at = argv.indexOf(name);
|
|
32
|
+
return at >= 0 ? argv[at + 1] : undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const options = (argv, name) => argv.flatMap((value, at) => (value === name && argv[at + 1] ? [argv[at + 1]] : []));
|
|
36
|
+
|
|
37
|
+
/** A value of an observation: no path, no text, a name of 48 characters at most. */
|
|
38
|
+
const clean = (value) => String(value ?? '').includes('/') ? '' : String(value ?? '').replace(/[^A-Za-z0-9._:-]/g, '').slice(0, 48);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The branches that are task branches: the head of a request whose base is not the main branch. A
|
|
42
|
+
* request merged into such a branch is a stack step, and it opens no window.
|
|
43
|
+
*/
|
|
44
|
+
export function taskBranchesOf(pulls, main = 'main') {
|
|
45
|
+
return new Set(pulls.filter((p) => p.baseRefName && p.baseRefName !== main).map((p) => p.headRefName));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The branches that are epic branches: a base of a request that is no task branch and no main branch. */
|
|
49
|
+
export function epicBranchesOf(pulls, main = 'main') {
|
|
50
|
+
const tasks = taskBranchesOf(pulls, main);
|
|
51
|
+
return new Set(pulls.map((p) => p.baseRefName).filter((base) => base && base !== main && !tasks.has(base)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The packages a request changed: the directories of `packages` that hold one of its files. A file
|
|
56
|
+
* the `ignore` pattern matches is no part of a package: a code graph lies in every package directory
|
|
57
|
+
* and is never published.
|
|
58
|
+
*/
|
|
59
|
+
export const packagesOf = (pull, packages, ignore = null) =>
|
|
60
|
+
packages
|
|
61
|
+
.filter((dir) => (pull.files ?? []).some((file) => (file === dir || file.startsWith(`${dir}/`)) && !(ignore && ignore.test(file))))
|
|
62
|
+
.map((dir) => dir.split('/').pop());
|
|
63
|
+
|
|
64
|
+
/** The observations of the merged requests: one per request, by its merge moment. */
|
|
65
|
+
export function mergesOf(pulls, { main = 'main', packages = [], ignore = null } = {}) {
|
|
66
|
+
const epics = epicBranchesOf(pulls, main);
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const pull of pulls) {
|
|
69
|
+
if (!pull.mergedAt) continue;
|
|
70
|
+
const task = clean(taskOf(pull.headRefName));
|
|
71
|
+
if (pull.baseRefName === main && epics.has(pull.headRefName)) {
|
|
72
|
+
out.push({ number: pull.number, line: { t: pull.mergedAt, ev: 'epic-merged', task, pkg: packagesOf(pull, packages, ignore).map(clean).join(',') } });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const line = { t: pull.mergedAt, ev: 'task-merged', task };
|
|
76
|
+
if (epics.has(pull.baseRefName)) {
|
|
77
|
+
line.opens = '1';
|
|
78
|
+
line.epic = clean(taskOf(pull.baseRefName));
|
|
79
|
+
}
|
|
80
|
+
out.push({ number: pull.number, line });
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The observations of the editions of one package: the registry map without its service keys. */
|
|
86
|
+
export const editionsOf = (pkg, times) =>
|
|
87
|
+
Object.entries(times ?? {})
|
|
88
|
+
.filter(([version, at]) => /^\d+\.\d+\.\d+/.test(version) && typeof at === 'string')
|
|
89
|
+
.map(([version, at]) => ({ key: `${pkg}@${version}`, line: { t: at, ev: 'edition', pkg: clean(pkg), ver: clean(version) } }));
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The merges of a day for the day line: the merged tasks, those with a taking seen on this machine,
|
|
93
|
+
* and their whole minutes from the taking. The taking of a task is its earliest `task-taken`.
|
|
94
|
+
*/
|
|
95
|
+
export function dayMerges(observations, day) {
|
|
96
|
+
const taken = new Map();
|
|
97
|
+
for (const o of observations) {
|
|
98
|
+
if (o.ev !== 'task-taken' || !o.task) continue;
|
|
99
|
+
if (!taken.has(o.task) || o.t < taken.get(o.task)) taken.set(o.task, o.t);
|
|
100
|
+
}
|
|
101
|
+
let tasksMerged = 0;
|
|
102
|
+
let tasksTimed = 0;
|
|
103
|
+
let takenMinutes = 0;
|
|
104
|
+
for (const o of observations) {
|
|
105
|
+
if (o.ev !== 'task-merged' || !String(o.t).startsWith(day)) continue;
|
|
106
|
+
tasksMerged += 1;
|
|
107
|
+
const from = taken.get(o.task);
|
|
108
|
+
if (!from || from > o.t) continue;
|
|
109
|
+
tasksTimed += 1;
|
|
110
|
+
takenMinutes += Math.floor((Date.parse(o.t) - Date.parse(from)) / MINUTE);
|
|
111
|
+
}
|
|
112
|
+
return { tasksMerged, tasksTimed, takenMinutes };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The end of a day of UTC: what was true at it is what the report of the day says. */
|
|
116
|
+
const endOf = (day) => `${day}T23:59:59.999Z`;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The epics of a report day, judged by the end of that day: each epic merged into the main branch
|
|
120
|
+
* by then, and each epic whose window opened by then with no merge yet.
|
|
121
|
+
*
|
|
122
|
+
* status `released` — every package the epic changed has an edition after the merge, or it
|
|
123
|
+
* changed none; `not-released` — a package has no such edition; `merged` — the tree
|
|
124
|
+
* publishes no package; `open` — no merge into the main branch yet
|
|
125
|
+
* minutes whole minutes from the taking to the release, to the merge while not released, and
|
|
126
|
+
* null for an open epic or one with no taking seen; the taking of an epic is the earliest
|
|
127
|
+
* taking of the epic branch or of a task merged into it
|
|
128
|
+
*/
|
|
129
|
+
export function dayEpics(observations, day, { publishes = true } = {}) {
|
|
130
|
+
const end = endOf(day);
|
|
131
|
+
const until = observations.filter((o) => String(o.t) <= end);
|
|
132
|
+
const tasksOf = new Map();
|
|
133
|
+
const opened = new Set();
|
|
134
|
+
for (const o of until) {
|
|
135
|
+
if (o.ev !== 'task-merged' || !o.epic) continue;
|
|
136
|
+
if (!tasksOf.has(o.epic)) tasksOf.set(o.epic, new Set());
|
|
137
|
+
tasksOf.get(o.epic).add(o.task);
|
|
138
|
+
if (o.opens) opened.add(o.epic);
|
|
139
|
+
}
|
|
140
|
+
const takenAt = (epic) =>
|
|
141
|
+
until
|
|
142
|
+
.filter((o) => o.ev === 'task-taken' && (o.task === epic || tasksOf.get(epic)?.has(o.task)))
|
|
143
|
+
.map((o) => o.t)
|
|
144
|
+
.sort()[0] ?? null;
|
|
145
|
+
const minutesBetween = (from, to) => (from && to ? Math.floor((Date.parse(to) - Date.parse(from)) / MINUTE) : null);
|
|
146
|
+
const merged = new Map(until.filter((o) => o.ev === 'epic-merged').map((o) => [o.task, o]));
|
|
147
|
+
const out = [];
|
|
148
|
+
for (const [epic, merge] of merged) {
|
|
149
|
+
const packages = String(merge.pkg ?? '').split(',').filter(Boolean);
|
|
150
|
+
const editions = packages.map((pkg) =>
|
|
151
|
+
until.filter((o) => o.ev === 'edition' && o.pkg === pkg && o.t > merge.t).map((o) => o.t).sort()[0] ?? null,
|
|
152
|
+
);
|
|
153
|
+
let status = 'released';
|
|
154
|
+
let releasedAt = merge.t;
|
|
155
|
+
if (!publishes) {
|
|
156
|
+
status = 'merged';
|
|
157
|
+
releasedAt = null;
|
|
158
|
+
} else if (editions.some((at) => at === null)) {
|
|
159
|
+
status = 'not-released';
|
|
160
|
+
releasedAt = null;
|
|
161
|
+
} else if (editions.length > 0) {
|
|
162
|
+
releasedAt = editions.sort().at(-1);
|
|
163
|
+
}
|
|
164
|
+
out.push({ epic, status, mergedAt: merge.t, releasedAt, minutes: minutesBetween(takenAt(epic), releasedAt ?? merge.t) });
|
|
165
|
+
}
|
|
166
|
+
for (const epic of opened) {
|
|
167
|
+
if (!merged.has(epic)) out.push({ epic, status: 'open', mergedAt: null, releasedAt: null, minutes: null });
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The lines of a file of JSON lines, or null when one of them does not parse. */
|
|
173
|
+
function linesOf(file) {
|
|
174
|
+
const out = [];
|
|
175
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
176
|
+
if (!line.trim()) continue;
|
|
177
|
+
try {
|
|
178
|
+
out.push(JSON.parse(line));
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The key of a merge or an edition line: a second read of the same fact replaces the first. */
|
|
187
|
+
export const factKey = (line) => [line.ev, line.task ?? '', line.pkg && line.ev === 'edition' ? `${line.pkg}@${line.ver}` : '', line.t].join('|');
|
|
188
|
+
|
|
189
|
+
const FACTS = new Set(['task-merged', 'epic-merged', 'edition']);
|
|
190
|
+
|
|
191
|
+
/** Writes the facts into the day files: a line with the key of a new one is replaced, the rest is kept. */
|
|
192
|
+
export function writeFacts(dir, lines) {
|
|
193
|
+
const byDay = new Map();
|
|
194
|
+
for (const line of lines) {
|
|
195
|
+
const day = String(line.t).slice(0, 10);
|
|
196
|
+
if (!byDay.has(day)) byDay.set(day, []);
|
|
197
|
+
byDay.get(day).push(line);
|
|
198
|
+
}
|
|
199
|
+
mkdirSync(dir, { recursive: true });
|
|
200
|
+
for (const [day, fresh] of byDay) {
|
|
201
|
+
const file = join(dir, `${day}.jsonl`);
|
|
202
|
+
const keys = new Set(fresh.map(factKey));
|
|
203
|
+
const kept = existsSync(file)
|
|
204
|
+
? readFileSync(file, 'utf8').split('\n').filter((text) => {
|
|
205
|
+
if (!text.trim()) return false;
|
|
206
|
+
try {
|
|
207
|
+
const old = JSON.parse(text);
|
|
208
|
+
return !(FACTS.has(old.ev) && keys.has(factKey(old)));
|
|
209
|
+
} catch {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
: [];
|
|
214
|
+
writeFileSync(file, [...kept, ...fresh.map((line) => JSON.stringify(line))].join('\n') + '\n');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function main(argv) {
|
|
219
|
+
const dir = option(argv, '--observations');
|
|
220
|
+
const pullsFile = option(argv, '--pulls');
|
|
221
|
+
if (!dir || !pullsFile || !existsSync(pullsFile)) return 0;
|
|
222
|
+
const pulls = linesOf(pullsFile);
|
|
223
|
+
const editions = [];
|
|
224
|
+
for (const pair of options(argv, '--editions')) {
|
|
225
|
+
const [pkg, file] = pair.split('=');
|
|
226
|
+
try {
|
|
227
|
+
editions.push(...editionsOf(pkg, JSON.parse(readFileSync(file, 'utf8'))));
|
|
228
|
+
} catch {
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (pulls === null) return 0;
|
|
233
|
+
const packages = (option(argv, '--packages') ?? '').split(',').filter(Boolean);
|
|
234
|
+
const ignore = option(argv, '--ignore') ? new RegExp(option(argv, '--ignore')) : null;
|
|
235
|
+
writeFacts(dir, [...mergesOf(pulls, { main: option(argv, '--main') ?? 'main', packages, ignore }), ...editions].map((item) => item.line));
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) process.exit(main(process.argv.slice(2)));
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The measures of the guards of the end of a turn, read from the session records of this tree.
|
|
4
|
+
*
|
|
5
|
+
* node owner-nudges.mjs --days 7 --until 2026-11-15 nudges of the owner per 100 calls
|
|
6
|
+
* node owner-nudges.mjs --typed --since 2026-10-13 --until … typed messages of the owner
|
|
7
|
+
* node owner-nudges.mjs --refusals --days 1 --until 2026-11-14 refusals per 100 calls
|
|
8
|
+
* node owner-nudges.mjs --deadlocks --days 7 --until 2026-11-15 series of stop refusals
|
|
9
|
+
* node owner-nudges.mjs --missed --last 200 turns ended with open work
|
|
10
|
+
*
|
|
11
|
+
* The records are the jsonl files of Claude Code under `--root` (by default `~/.claude/projects`),
|
|
12
|
+
* in the directories of every copy of the tree: the main checkout named by `--tree` (by default the
|
|
13
|
+
* checkout that holds the common directory of git) and its worktrees under `.claude/worktrees/`.
|
|
14
|
+
* Only the session files are read, not the records of subagents: an owner message lives only there.
|
|
15
|
+
* An entry copied into a resumed session is counted once, by its id.
|
|
16
|
+
*
|
|
17
|
+
* The window is whole days of UTC: `--until <date>` includes that day, `--days N` goes N days back
|
|
18
|
+
* from its end, `--since <date>` starts at that day. A moment with a time is taken as it is. The
|
|
19
|
+
* moment is always a parameter: the decisions below never read the clock.
|
|
20
|
+
*
|
|
21
|
+
* A nudge is a typed owner message the pattern `words.nudge` of the task flow description matches;
|
|
22
|
+
* a call is a tool use of the agent. A refusal is a mark `BLOCKED by <guard>:` in the feedback of a
|
|
23
|
+
* stop hook or in the hook error a tool call got back. A deadlock is a series of 10 and more stop
|
|
24
|
+
* refusals in a row with one guard and one first line of the reason — the line that names the
|
|
25
|
+
* state and the step; a stop that passed or a refusal with another line ends the series.
|
|
26
|
+
*
|
|
27
|
+
* The missed stops are read in the last `--last` calls after the layout of the engine: the moment
|
|
28
|
+
* of the first commit that added it to the tree, or `--layout <moment>`. A turn that ended there,
|
|
29
|
+
* on a branch that carries the engine, while no release case of the description released it is
|
|
30
|
+
* missed.
|
|
31
|
+
*/
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
34
|
+
import { homedir } from 'node:os';
|
|
35
|
+
import { dirname, join, resolve } from 'node:path';
|
|
36
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
37
|
+
|
|
38
|
+
import { buildModel } from './flow-model.mjs';
|
|
39
|
+
import { readRecord } from './flow-plan.mjs';
|
|
40
|
+
// The owner's words are read by the counter of the record, the same rule the engine reads them by.
|
|
41
|
+
import { typedOf } from './record-count.mjs';
|
|
42
|
+
|
|
43
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
44
|
+
|
|
45
|
+
/** The mark of a refusal: at the start of a line or right after the prefix of the harness. */
|
|
46
|
+
const MARK = /(?:^|\n|: )BLOCKED by ([a-z0-9][a-z0-9-]*):([^\n]*)/g;
|
|
47
|
+
|
|
48
|
+
/** The text the harness gives back to a tool call a hook refused. */
|
|
49
|
+
const HOOK_ERROR = /^\S+ hook error: /;
|
|
50
|
+
|
|
51
|
+
/** The text the harness hands the agent after a stop hook refused. */
|
|
52
|
+
const STOP_FEEDBACK = 'Stop hook feedback:';
|
|
53
|
+
|
|
54
|
+
/** The rewritten exit check. */
|
|
55
|
+
export const EXIT_GUARDS = ['turn-exit-guard'];
|
|
56
|
+
|
|
57
|
+
/** The checks of the executable scenario: the rewritten exit check and the guard of the course of work. */
|
|
58
|
+
export const NEW_GUARDS = ['turn-exit-guard', 'flow-step-guard'];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The seven checks of the base that judged the conversation, and the agent hooks that carry their
|
|
62
|
+
* requirements since they were removed.
|
|
63
|
+
*/
|
|
64
|
+
export const BASE_GUARDS = [
|
|
65
|
+
'grill-gate', 'grill-gate-ask', 'claim-guard', 'waiting-turn-guard', 'postmortem-guard', 'work-start-guard',
|
|
66
|
+
'proposal-guard', 'stand-login-guard', 'turn-judge', 'ask-judge',
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
/** The length from which a series of stop refusals is a deadlock. */
|
|
70
|
+
export const SERIES = 10;
|
|
71
|
+
|
|
72
|
+
/** The directory name Claude Code gives the records of a path. */
|
|
73
|
+
export const recordDirOf = (path) => path.replace(/[^A-Za-z0-9]/g, '-');
|
|
74
|
+
|
|
75
|
+
/** A directory of records belongs to a copy of the tree: the main checkout or one of its worktrees. */
|
|
76
|
+
export function isCopyDir(name, tree) {
|
|
77
|
+
const own = recordDirOf(tree);
|
|
78
|
+
return name === own || name.startsWith(`${own}--claude-worktrees-`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const momentOf = (text, endOfDay) => {
|
|
82
|
+
const day = /^\d{4}-\d{2}-\d{2}$/.test(text);
|
|
83
|
+
const at = Date.parse(day ? `${text}T00:00:00Z` : text);
|
|
84
|
+
if (Number.isNaN(at)) throw new Error(`not a date: ${text}`);
|
|
85
|
+
return day && endOfDay ? at + DAY : at;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** The window `{ from, to }` in ms, the end excluded. */
|
|
89
|
+
export function windowOf({ until, since, days }) {
|
|
90
|
+
if (!until) throw new Error('the window needs --until');
|
|
91
|
+
const to = momentOf(until, true);
|
|
92
|
+
if (since) return { from: momentOf(since, false), to };
|
|
93
|
+
if (!Number.isInteger(days) || days < 1) throw new Error('the window needs --days N or --since <date>');
|
|
94
|
+
return { from: to - days * DAY, to };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const inWindow = (entry, window) => {
|
|
98
|
+
const at = Date.parse(entry?.timestamp ?? '');
|
|
99
|
+
return at >= window.from && at < window.to;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const partsOf = (entry) => (Array.isArray(entry?.message?.content) ? entry.message.content : []);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The text the owner typed in an entry, before a turn or during one, or null: a tool result, a menu
|
|
106
|
+
* answer and a wrapper of the harness are none.
|
|
107
|
+
*/
|
|
108
|
+
export function typedText(entry) {
|
|
109
|
+
if (entry?.isSidechain || entry?.toolUseResult) return null;
|
|
110
|
+
const word = typedOf(entry);
|
|
111
|
+
return word && word.text.trim() !== '' ? word.text : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The ids of the tool calls in an entry of the agent. */
|
|
115
|
+
export function callsOf(entry) {
|
|
116
|
+
if (entry?.type !== 'assistant' || entry.isSidechain) return [];
|
|
117
|
+
return partsOf(entry)
|
|
118
|
+
.map((part, index) => (part?.type === 'tool_use' ? (part.id ?? `${entry.uuid}:${index}`) : null))
|
|
119
|
+
.filter((id) => id !== null);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const textOf = (content) =>
|
|
123
|
+
typeof content === 'string'
|
|
124
|
+
? content
|
|
125
|
+
: Array.isArray(content)
|
|
126
|
+
? content.map((part) => (typeof part === 'string' ? part : (part?.text ?? ''))).join('\n')
|
|
127
|
+
: '';
|
|
128
|
+
|
|
129
|
+
const marksOf = (text, stop) => [...text.matchAll(MARK)].map((match) => ({ guard: match[1], line: match[2].trim(), stop }));
|
|
130
|
+
|
|
131
|
+
/** The refusals an entry carries: `[{ guard, line, stop }]`, `stop` for a refusal of the end of a turn. */
|
|
132
|
+
export function refusalsOf(entry) {
|
|
133
|
+
if (entry?.type !== 'user' || entry.isSidechain) return [];
|
|
134
|
+
const content = entry.message?.content;
|
|
135
|
+
const text = textOf(typeof content === 'string' ? content : partsOf(entry).filter((part) => part?.type === 'text'));
|
|
136
|
+
if (text.startsWith(STOP_FEEDBACK)) return marksOf(text, true);
|
|
137
|
+
return partsOf(entry)
|
|
138
|
+
.filter((part) => part?.type === 'tool_result' && part.is_error)
|
|
139
|
+
.map((part) => textOf(part.content))
|
|
140
|
+
.filter((result) => HOOK_ERROR.test(result))
|
|
141
|
+
.flatMap((result) => marksOf(result, false));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** A stop the hooks let through: the summary of the stop hooks names no refusal. */
|
|
145
|
+
export const stopPassed = (entry) =>
|
|
146
|
+
entry?.type === 'system' && entry.subtype === 'stop_hook_summary' && !(entry.hookErrors ?? []).some((error) => String(error).includes('BLOCKED by'));
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The entries of the copies in the window, each once: `{ copy, session, entry }`. An entry copied
|
|
150
|
+
* into a resumed session carries the same id and is skipped the second time.
|
|
151
|
+
*/
|
|
152
|
+
export function* entriesOf(copies, window) {
|
|
153
|
+
const seen = new Set();
|
|
154
|
+
for (const copy of copies) {
|
|
155
|
+
for (const session of copy.sessions) {
|
|
156
|
+
for (const entry of session.entries) {
|
|
157
|
+
if (!inWindow(entry, window)) continue;
|
|
158
|
+
if (entry.uuid) {
|
|
159
|
+
if (seen.has(entry.uuid)) continue;
|
|
160
|
+
seen.add(entry.uuid);
|
|
161
|
+
}
|
|
162
|
+
yield { copy: copy.name, session: session.id, entry };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const countCalls = (copies, window) => {
|
|
169
|
+
const ids = new Set();
|
|
170
|
+
for (const { entry } of entriesOf(copies, window)) for (const id of callsOf(entry)) ids.add(id);
|
|
171
|
+
return ids.size;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** Nudges and calls in the window: `{ nudges, calls }`. */
|
|
175
|
+
export function measureNudges(copies, window, nudge) {
|
|
176
|
+
const pattern = new RegExp(nudge, 'iu');
|
|
177
|
+
let nudges = 0;
|
|
178
|
+
for (const { entry } of entriesOf(copies, window)) {
|
|
179
|
+
const text = typedText(entry);
|
|
180
|
+
if (text !== null && pattern.test(text)) nudges += 1;
|
|
181
|
+
}
|
|
182
|
+
return { nudges, calls: countCalls(copies, window) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Typed owner messages in the window and the copies that hold them: `{ messages, copies }`. */
|
|
186
|
+
export function measureTyped(copies, window) {
|
|
187
|
+
let messages = 0;
|
|
188
|
+
const holding = new Set();
|
|
189
|
+
for (const { copy, entry } of entriesOf(copies, window)) {
|
|
190
|
+
if (typedText(entry) === null) continue;
|
|
191
|
+
messages += 1;
|
|
192
|
+
holding.add(copy);
|
|
193
|
+
}
|
|
194
|
+
return { messages, copies: holding.size };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Refusals in the window by group and the calls: `{ calls, all, exit, base, fresh }`. */
|
|
198
|
+
export function measureRefusals(copies, window) {
|
|
199
|
+
const counts = { all: 0, exit: 0, base: 0, fresh: 0 };
|
|
200
|
+
for (const { entry } of entriesOf(copies, window)) {
|
|
201
|
+
for (const { guard } of refusalsOf(entry)) {
|
|
202
|
+
counts.all += 1;
|
|
203
|
+
if (EXIT_GUARDS.includes(guard)) counts.exit += 1;
|
|
204
|
+
if (BASE_GUARDS.includes(guard)) counts.base += 1;
|
|
205
|
+
if (NEW_GUARDS.includes(guard)) counts.fresh += 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { calls: countCalls(copies, window), ...counts };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The deadlocks in the window: `[{ session, key, refusals }]`. A series runs over the stop refusals of
|
|
213
|
+
* one session with one key — the guard and the first line of its reason. Calls and owner messages
|
|
214
|
+
* between them do not end it: in a deadlock the agent keeps trying and the owner keeps writing. A
|
|
215
|
+
* stop that passed ends it, unless a refusal of an agent hook follows the summary of that stop.
|
|
216
|
+
*/
|
|
217
|
+
export function findDeadlocks(copies, window) {
|
|
218
|
+
const found = [];
|
|
219
|
+
const sessions = new Map();
|
|
220
|
+
for (const { copy, session, entry } of entriesOf(copies, window)) {
|
|
221
|
+
const id = `${copy}/${session}`;
|
|
222
|
+
if (!sessions.has(id)) sessions.set(id, []);
|
|
223
|
+
sessions.get(id).push(entry);
|
|
224
|
+
}
|
|
225
|
+
for (const [session, entries] of sessions) {
|
|
226
|
+
let run = null;
|
|
227
|
+
let passed = false;
|
|
228
|
+
const close = () => {
|
|
229
|
+
if (run && run.refusals >= SERIES) found.push({ session, ...run });
|
|
230
|
+
run = null;
|
|
231
|
+
passed = false;
|
|
232
|
+
};
|
|
233
|
+
for (const entry of entries) {
|
|
234
|
+
const stops = refusalsOf(entry).filter((refusal) => refusal.stop);
|
|
235
|
+
if (stops.length > 0) {
|
|
236
|
+
passed = false;
|
|
237
|
+
for (const { guard, line } of stops) {
|
|
238
|
+
const key = `${guard}: ${line}`;
|
|
239
|
+
if (run?.key !== key) close();
|
|
240
|
+
run = run ?? { key, refusals: 0 };
|
|
241
|
+
run.refusals += 1;
|
|
242
|
+
}
|
|
243
|
+
} else if (stopPassed(entry)) {
|
|
244
|
+
passed = true;
|
|
245
|
+
} else if (passed && (entry.type === 'assistant' || typedText(entry) !== null)) {
|
|
246
|
+
close();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
close();
|
|
250
|
+
}
|
|
251
|
+
return found;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A count per hundred calls with two decimals. */
|
|
255
|
+
export const per100 = (count, calls) => (calls > 0 ? (count * 100) / calls : 0).toFixed(2);
|
|
256
|
+
|
|
257
|
+
export const nudgesLine = ({ nudges, calls }) => `owner nudges per 100 calls: ${per100(nudges, calls)} (${nudges} nudges, ${calls} calls)`;
|
|
258
|
+
|
|
259
|
+
export const typedLine = ({ messages, copies }) => `owner typed messages: ${messages} in ${copies} copies`;
|
|
260
|
+
|
|
261
|
+
export const refusalsLine = ({ calls, all, exit, base, fresh }) =>
|
|
262
|
+
`refusals per 100 calls: all ${per100(all, calls)}, exit ${per100(exit, calls)}, base ${per100(base, calls)}, new ${per100(fresh, calls)}`;
|
|
263
|
+
|
|
264
|
+
export const deadlocksLine = (series) =>
|
|
265
|
+
`deadlocks: ${series.length} series of ${SERIES}+ stop refusals at one state and step, ${series.reduce((sum, s) => sum + s.refusals, 0)} refusals`;
|
|
266
|
+
|
|
267
|
+
const USAGE =
|
|
268
|
+
'usage: node owner-nudges.mjs [--typed | --refusals | --deadlocks] (--days N | --since <date>) [--until <date>] [--root <dir>] [--tree <path>] [--flow <flow.js>]\n node owner-nudges.mjs --missed --last N [--layout <moment>] [--root <dir>] [--tree <path>] [--flow <flow.js>]';
|
|
269
|
+
|
|
270
|
+
/** The arguments of the command line, or a thrown error naming what is wrong. */
|
|
271
|
+
export function parseArgs(argv) {
|
|
272
|
+
const args = { mode: 'nudges' };
|
|
273
|
+
const modes = { '--typed': 'typed', '--refusals': 'refusals', '--deadlocks': 'deadlocks', '--missed': 'missed' };
|
|
274
|
+
const values = { '--days': 'days', '--since': 'since', '--until': 'until', '--root': 'root', '--tree': 'tree', '--flow': 'flow', '--last': 'last', '--layout': 'layout' };
|
|
275
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
276
|
+
const arg = argv[index];
|
|
277
|
+
if (arg in modes) {
|
|
278
|
+
if (args.mode !== 'nudges') throw new Error('one measure at a time');
|
|
279
|
+
args.mode = modes[arg];
|
|
280
|
+
} else if (arg in values) {
|
|
281
|
+
const value = argv[index + 1];
|
|
282
|
+
if (value === undefined || value.startsWith('--')) throw new Error(`${arg} needs a value`);
|
|
283
|
+
args[values[arg]] = values[arg] === 'days' || values[arg] === 'last' ? Number(value) : value;
|
|
284
|
+
index += 1;
|
|
285
|
+
} else {
|
|
286
|
+
throw new Error(`unknown argument: ${arg}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return args;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The moment of the first of the last `last` calls in the window, or the start of the window when there are fewer. */
|
|
293
|
+
export function lastCallsFrom(copies, window, last) {
|
|
294
|
+
const moments = [];
|
|
295
|
+
for (const { entry } of entriesOf(copies, window)) for (const _ of callsOf(entry)) moments.push(Date.parse(entry.timestamp));
|
|
296
|
+
moments.sort((a, b) => a - b);
|
|
297
|
+
return moments.length > last ? moments[moments.length - last] : window.from;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The moment the engine was laid out: the first commit of any branch that added it, or null. */
|
|
301
|
+
export function layoutMoment(tree) {
|
|
302
|
+
const run = spawnSync('git', ['-C', tree, 'log', '--all', '--diff-filter=A', '--reverse', '--format=%ct', '--', 'tools/task-flow-script.mjs'], { encoding: 'utf8' });
|
|
303
|
+
const first = run.status === 0 ? run.stdout.trim().split('\n')[0] : '';
|
|
304
|
+
return first ? Number(first) * 1000 : null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Whether a branch carries the engine; a branch removed since is taken as one without it. */
|
|
308
|
+
export function branchLaid(tree) {
|
|
309
|
+
const known = new Map();
|
|
310
|
+
return (branch) => {
|
|
311
|
+
if (!branch) return false;
|
|
312
|
+
if (!known.has(branch)) {
|
|
313
|
+
const run = spawnSync('git', ['-C', tree, 'cat-file', '-e', `${branch}:tools/task-flow-script.mjs`], { encoding: 'utf8' });
|
|
314
|
+
known.set(branch, run.status === 0);
|
|
315
|
+
}
|
|
316
|
+
return known.get(branch);
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The copies of the tree with their session records; a file last written before the window is skipped. */
|
|
321
|
+
export function readCopies(root, tree, window) {
|
|
322
|
+
if (!existsSync(root)) return [];
|
|
323
|
+
return readdirSync(root)
|
|
324
|
+
.filter((name) => isCopyDir(name, tree))
|
|
325
|
+
.sort()
|
|
326
|
+
.map((name) => {
|
|
327
|
+
const dir = join(root, name);
|
|
328
|
+
const sessions = readdirSync(dir)
|
|
329
|
+
.filter((file) => file.endsWith('.jsonl'))
|
|
330
|
+
.sort()
|
|
331
|
+
.filter((file) => statSync(join(dir, file)).mtimeMs >= window.from)
|
|
332
|
+
.map((file) => ({ id: file.replace(/\.jsonl$/, ''), entries: readRecord(join(dir, file)) }));
|
|
333
|
+
return { name, sessions };
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The main checkout: the parent of the common directory of git, or the current directory outside git. */
|
|
338
|
+
function treeRoot() {
|
|
339
|
+
const run = spawnSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { encoding: 'utf8' });
|
|
340
|
+
return run.status === 0 ? dirname(run.stdout.trim()) : process.cwd();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function flowPath(named) {
|
|
344
|
+
if (named) return resolve(named);
|
|
345
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
346
|
+
const laid = join(here, 'task-flow', 'flow.js');
|
|
347
|
+
return existsSync(laid) ? laid : join(here, '..', 'task-flow', 'flow.js');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** The command line; it runs after the module is evaluated, so the engine it imports can import this module. */
|
|
351
|
+
async function main() {
|
|
352
|
+
let args;
|
|
353
|
+
let window;
|
|
354
|
+
try {
|
|
355
|
+
args = parseArgs(process.argv.slice(2));
|
|
356
|
+
if (args.mode === 'missed') {
|
|
357
|
+
if (!Number.isInteger(args.last) || args.last < 1) throw new Error('--missed needs --last N');
|
|
358
|
+
} else window = windowOf({ ...args, until: args.until ?? new Date().toISOString().slice(0, 10) });
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error(`owner-nudges: ${error.message}\n${USAGE}`);
|
|
361
|
+
process.exit(2);
|
|
362
|
+
}
|
|
363
|
+
const root = args.root ?? join(homedir(), '.claude', 'projects');
|
|
364
|
+
const tree = args.tree ?? treeRoot();
|
|
365
|
+
if (args.mode === 'missed') {
|
|
366
|
+
const laid = args.layout ? Date.parse(args.layout) : layoutMoment(tree);
|
|
367
|
+
if (laid === null || Number.isNaN(laid)) {
|
|
368
|
+
console.log(`missed stops with open work: 0 of 0 stops in the last ${args.last} calls`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const after = { from: laid, to: Number.POSITIVE_INFINITY };
|
|
372
|
+
const copies = readCopies(root, tree, after);
|
|
373
|
+
const path = flowPath(args.flow);
|
|
374
|
+
const model = buildModel(path);
|
|
375
|
+
const { GUARD_SETTINGS, openReaders } = await import(pathToFileURL(join(dirname(fileURLToPath(import.meta.url)), 'task-flow-script.mjs')).href);
|
|
376
|
+
const { missedLine, runMissed } = await import(pathToFileURL(join(dirname(fileURLToPath(import.meta.url)), 'flow-forecast.mjs')).href);
|
|
377
|
+
const from = lastCallsFrom(copies, after, args.last);
|
|
378
|
+
const result = await runMissed({ copies, from, model, base: dirname(path), openReaders, tree, settings: GUARD_SETTINGS, laid: branchLaid(tree) });
|
|
379
|
+
console.log(missedLine(result, args.last));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const copies = readCopies(root, tree, window);
|
|
383
|
+
if (args.mode === 'typed') console.log(typedLine(measureTyped(copies, window)));
|
|
384
|
+
else if (args.mode === 'refusals') console.log(refusalsLine(measureRefusals(copies, window)));
|
|
385
|
+
else if (args.mode === 'deadlocks') console.log(deadlocksLine(findDeadlocks(copies, window)));
|
|
386
|
+
else console.log(nudgesLine(measureNudges(copies, window, buildModel(flowPath(args.flow)).words.nudge)));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
|