@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,444 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Which steps of the push set a change can reach. A step runs when the change touches what it
|
|
4
|
+
* reads; a step the change cannot reach is not started.
|
|
5
|
+
*
|
|
6
|
+
* node tools/push-inputs.mjs record the steps on stdin, or the profile set when stdin is
|
|
7
|
+
* empty: each runs once under `push-trace.mjs`, and the
|
|
8
|
+
* table of what it read is written
|
|
9
|
+
* node tools/push-inputs.mjs subject <base> the steps on stdin; a line per step on stdout —
|
|
10
|
+
* `touched|idle|unknown|not-run<TAB>step`; the paths
|
|
11
|
+
* the tree declares go by `--declared <file>`
|
|
12
|
+
* node tools/push-inputs.mjs select <base> the steps on stdin; the ones to run go to stdout, a
|
|
13
|
+
* line per step with its reason to stderr
|
|
14
|
+
* node tools/push-inputs.mjs verify the table steps are recorded again; a read the table
|
|
15
|
+
* does not cover is a refusal
|
|
16
|
+
*
|
|
17
|
+
* What a step reads is taken from a record of its own calls, not from a list someone wrote: such a
|
|
18
|
+
* list checks itself and goes stale silently. The table is generated and is not edited by hand.
|
|
19
|
+
*
|
|
20
|
+
* A step runs when the change:
|
|
21
|
+
* - edits a file whose content it read, or a file with an extension it read inside a directory it
|
|
22
|
+
* walked;
|
|
23
|
+
* - adds, removes or renames a file inside a directory it walked, or a path whose existence it
|
|
24
|
+
* probed — an existence probe does not depend on what the file holds;
|
|
25
|
+
* - touches the step itself — its file and what that file imports.
|
|
26
|
+
* A step runs always when it reads the history (`git diff`, `git log` and the like): its answer
|
|
27
|
+
* changes without a change of the tree; when it starts a process of another kind, whose reads the
|
|
28
|
+
* recorder does not see; and when it is not in the table at all.
|
|
29
|
+
*
|
|
30
|
+
* FAIL-OPEN: no table, no base, a change list that cannot be read — every step runs, as before.
|
|
31
|
+
*/
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
34
|
+
import { tmpdir } from 'node:os';
|
|
35
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path';
|
|
36
|
+
import { fileURLToPath } from 'node:url';
|
|
37
|
+
|
|
38
|
+
const ROOT = process.cwd();
|
|
39
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
const TRACER = join(HERE, 'push-trace.mjs');
|
|
41
|
+
const TABLE_DEFAULT = '.claude/rt-kit/push-inputs.json';
|
|
42
|
+
// The agent's observations and their marks are written by the guards on every call, a refusal
|
|
43
|
+
// included: a step that walks the tree reads a new file each time, and the table never matches. A
|
|
44
|
+
// scenario run from a nested directory writes its own observations there, so they are left out at
|
|
45
|
+
// any depth.
|
|
46
|
+
const IGNORED =
|
|
47
|
+
/^(node_modules|\.git|dist|\.nx|\.angular|tmp|coverage)(\/|$)|\/node_modules\/|(^|\/)\.claude\/rt-kit\/observations(\/|$)/;
|
|
48
|
+
const TRACEABLE = /^(node\s+\S+\.m?js|pnpm run [\w:.-]+)(\s|$)/;
|
|
49
|
+
const HEAVY = /(^|\s)nx\s|docker |playwright|e2e|visual-gate|serve:/;
|
|
50
|
+
const LISTING = new Set(['ls-files', 'ls-tree', 'check-ignore', 'check-attr', 'status', 'config', 'hash-object', 'var']);
|
|
51
|
+
const VERIFY = /push-inputs\.mjs verify/;
|
|
52
|
+
|
|
53
|
+
const args = process.argv.slice(2);
|
|
54
|
+
const option = (name) => {
|
|
55
|
+
const at = args.indexOf(name);
|
|
56
|
+
return at >= 0 ? args[at + 1] : undefined;
|
|
57
|
+
};
|
|
58
|
+
const tablePath = resolve(ROOT, option('--table') ?? TABLE_DEFAULT);
|
|
59
|
+
|
|
60
|
+
const rel = (path) => relative(ROOT, path).split(sep).join('/');
|
|
61
|
+
const inside = (path) => {
|
|
62
|
+
const r = rel(path);
|
|
63
|
+
return r !== '' && !r.startsWith('..') && !IGNORED.test(r);
|
|
64
|
+
};
|
|
65
|
+
const extOf = (path) => extname(path) || basename(path);
|
|
66
|
+
const covers = (dir, path) => dir === '.' || path === dir || path.startsWith(`${dir}/`);
|
|
67
|
+
|
|
68
|
+
function readStdin() {
|
|
69
|
+
try {
|
|
70
|
+
return readFileSync(0, 'utf8');
|
|
71
|
+
} catch {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function stepsOf(text) {
|
|
77
|
+
return text.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function profileSteps() {
|
|
81
|
+
const profiles = ['.claude/rt-kit/defaults/project.sh', '.claude/rt-kit/project.sh'].filter((p) => existsSync(join(ROOT, p)));
|
|
82
|
+
const script = `${profiles.map((p) => `. "${p}"`).join('; ')}; rt_push_checks ''`;
|
|
83
|
+
const run = spawnSync('bash', ['-c', script], { cwd: ROOT, encoding: 'utf8' });
|
|
84
|
+
return stepsOf(run.stdout ?? '');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const traceable = (step) => TRACEABLE.test(step) && !HEAVY.test(step);
|
|
88
|
+
|
|
89
|
+
/** The step's own files: the script it starts and what that script imports, by relative paths. */
|
|
90
|
+
function selfOf(step) {
|
|
91
|
+
const own = new Set();
|
|
92
|
+
const script = step.match(/^node\s+(\S+\.m?js)/)?.[1];
|
|
93
|
+
if (script) {
|
|
94
|
+
const queue = [resolve(ROOT, script)];
|
|
95
|
+
while (queue.length) {
|
|
96
|
+
const file = queue.pop();
|
|
97
|
+
if (own.has(rel(file)) || !existsSync(file)) continue;
|
|
98
|
+
own.add(rel(file));
|
|
99
|
+
const text = readFileSync(file, 'utf8');
|
|
100
|
+
for (const m of text.matchAll(/(?:from\s+|import\s*\(\s*|import\s+|require\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g)) {
|
|
101
|
+
queue.push(resolve(dirname(file), m[1]));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (/^pnpm run /.test(step)) own.add('package.json');
|
|
106
|
+
return [...own].sort();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What a started process means for the step: nothing, a read of the history, or an unseen read. */
|
|
110
|
+
function spawnKind(spawned) {
|
|
111
|
+
const command = Array.isArray(spawned) ? spawned : spawned.command;
|
|
112
|
+
const cwd = Array.isArray(spawned) ? ROOT : spawned.cwd || ROOT;
|
|
113
|
+
const shell = basename(String(command[0] ?? ''));
|
|
114
|
+
let [name, ...rest] = command;
|
|
115
|
+
if ((shell === 'sh' || shell === 'bash') && rest[0] === '-c') {
|
|
116
|
+
[name, ...rest] = String(rest[1] ?? '').trim().split(/\s+/);
|
|
117
|
+
}
|
|
118
|
+
const tool = basename(String(name ?? ''));
|
|
119
|
+
if (tool === 'node' || name === process.execPath) return 'traced';
|
|
120
|
+
if (tool !== 'git') return `untraced:${/^[\w.-]+$/.test(tool) && tool !== '.' ? tool : shell}`;
|
|
121
|
+
const words = [...rest];
|
|
122
|
+
let where = cwd;
|
|
123
|
+
while (words.length && words[0].startsWith('-')) {
|
|
124
|
+
const flag = words.shift();
|
|
125
|
+
if (flag === '-C') where = resolve(where, words.shift() ?? '');
|
|
126
|
+
else if (flag === '-c') words.shift();
|
|
127
|
+
}
|
|
128
|
+
// A scratch repository of the step is not this tree: its history is the step's own.
|
|
129
|
+
if (relative(ROOT, where).startsWith('..')) return 'traced';
|
|
130
|
+
const sub = words[0] ?? '';
|
|
131
|
+
if (LISTING.has(sub)) return 'listing';
|
|
132
|
+
if (sub === 'rev-parse' && words.slice(1).every((w) => /^--(show-toplevel|show-prefix|git-dir|git-common-dir|is-inside-work-tree|show-cdup)$/.test(w))) {
|
|
133
|
+
return 'traced';
|
|
134
|
+
}
|
|
135
|
+
return `history:git ${sub}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** One run of a step under the recorder: the raw reads, walks and process kinds. */
|
|
139
|
+
function trace(step) {
|
|
140
|
+
const out = mkdtempSync(join(tmpdir(), 'rt-push-trace-'));
|
|
141
|
+
const started = Date.now();
|
|
142
|
+
const run = spawnSync('bash', ['-c', step], {
|
|
143
|
+
cwd: ROOT,
|
|
144
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
145
|
+
env: {
|
|
146
|
+
...process.env,
|
|
147
|
+
NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --import ${TRACER}`.trim(),
|
|
148
|
+
RT_PUSH_TRACE_OUT: out,
|
|
149
|
+
NX_DAEMON: 'false',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
const seconds = Math.round((Date.now() - started) / 1000);
|
|
153
|
+
const reads = new Set();
|
|
154
|
+
const probes = new Set();
|
|
155
|
+
const walks = new Set();
|
|
156
|
+
const kinds = new Set();
|
|
157
|
+
for (const name of readdirSync(out)) {
|
|
158
|
+
const record = JSON.parse(readFileSync(join(out, name), 'utf8'));
|
|
159
|
+
for (const p of record.reads) if (inside(p)) reads.add(rel(p));
|
|
160
|
+
for (const p of record.probes ?? []) if (inside(p)) probes.add(rel(p));
|
|
161
|
+
for (const p of record.walks) {
|
|
162
|
+
if (resolve(p) === ROOT) walks.add('.');
|
|
163
|
+
else if (inside(p)) walks.add(rel(p));
|
|
164
|
+
}
|
|
165
|
+
for (const s of record.spawns) kinds.add(spawnKind(s));
|
|
166
|
+
}
|
|
167
|
+
rmSync(out, { recursive: true, force: true });
|
|
168
|
+
if (kinds.has('listing')) walks.add('.');
|
|
169
|
+
for (const set of [reads, probes, walks]) {
|
|
170
|
+
for (const p of outsideHistory([...set])) set.delete(p);
|
|
171
|
+
for (const p of [...set]) if (untracked(p)) set.delete(p);
|
|
172
|
+
}
|
|
173
|
+
return { seconds, exit: run.status ?? 1, reads, probes, walks, kinds, self: selfOf(step) };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let untrackedList;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* A file that lies in the copy and not in the history, and is not ignored either: a draft, a patch
|
|
180
|
+
* leftover. Like an ignored file it never reaches the change list of a branch, and whether it lies
|
|
181
|
+
* there is a state of the copy. Added to the history, it is an addition in a walked directory and
|
|
182
|
+
* starts the step anyway. Listed once per run: `--directory` names a whole untracked directory
|
|
183
|
+
* once, with a trailing slash.
|
|
184
|
+
*
|
|
185
|
+
* FAIL-OPEN: no git or a fallen call — nothing counts as untracked.
|
|
186
|
+
*/
|
|
187
|
+
function untracked(path) {
|
|
188
|
+
if (!untrackedList) {
|
|
189
|
+
const run = spawnSync('git', ['ls-files', '--others', '--exclude-standard', '--directory', '-z'], {
|
|
190
|
+
cwd: ROOT,
|
|
191
|
+
encoding: 'utf8',
|
|
192
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
193
|
+
});
|
|
194
|
+
untrackedList = run.status === 0 ? (run.stdout ?? '').split('\0').filter(Boolean) : [];
|
|
195
|
+
}
|
|
196
|
+
return untrackedList.some((u) => (u.endsWith('/') ? `${path}/`.startsWith(u) : path === u));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** A step with a recorded process kind runs on every change: its reads choose nothing. */
|
|
200
|
+
function runsAlways(entry) {
|
|
201
|
+
return entry.history.length > 0 || entry.untraced.length > 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The paths the repository ignores. A change to such a file never reaches the change list of a
|
|
206
|
+
* branch, so it starts no step, and whether it exists is a state of the machine: a copy with `.env`
|
|
207
|
+
* and a copy without it would record two different tables of one and the same tree.
|
|
208
|
+
*
|
|
209
|
+
* Only the repository's own ignore rules count: a global ignore file differs from machine to
|
|
210
|
+
* machine, and a path it hides would split the table again. Paths go NUL-separated, so a name with
|
|
211
|
+
* a non-ASCII letter or a space is not quoted and is matched as written.
|
|
212
|
+
*
|
|
213
|
+
* FAIL-OPEN: no git — nothing counts as ignored, the table stays as strict as before. One path git
|
|
214
|
+
* refuses (beyond a symbolic link, outside the tree) fails the whole batch, so the paths are then
|
|
215
|
+
* asked one by one, and only the refused one stays in the table.
|
|
216
|
+
*/
|
|
217
|
+
function outsideHistory(paths) {
|
|
218
|
+
if (!paths.length) return [];
|
|
219
|
+
const ask = (list) =>
|
|
220
|
+
spawnSync('git', ['-c', 'core.excludesFile=/dev/null', 'check-ignore', '-z', '--stdin'], {
|
|
221
|
+
cwd: ROOT,
|
|
222
|
+
input: `${list.join('\0')}\0`,
|
|
223
|
+
encoding: 'utf8',
|
|
224
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
225
|
+
});
|
|
226
|
+
const ignored = (run) => (run.status === 0 ? (run.stdout ?? '').split('\0').filter(Boolean) : []);
|
|
227
|
+
const run = ask(paths);
|
|
228
|
+
if (run.status === 0 || run.status === 1) return ignored(run);
|
|
229
|
+
if (run.error || paths.length === 1) return [];
|
|
230
|
+
return paths.flatMap((p) => ignored(ask([p])));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The table entry: only the topmost walked directories, each with the extensions read under it. */
|
|
234
|
+
function entryOf(raw) {
|
|
235
|
+
const dirs = [...raw.walks].sort();
|
|
236
|
+
const top = dirs.filter((d) => !dirs.some((o) => o !== d && covers(o, d)));
|
|
237
|
+
const all = [...raw.reads, ...raw.self];
|
|
238
|
+
const walks = top.map((dir) => ({ dir, exts: [...new Set(all.filter((p) => covers(dir, p)).map(extOf))].sort() }));
|
|
239
|
+
const files = [...raw.reads].filter((p) => !walks.some((w) => covers(w.dir, p) && w.exts.includes(extOf(p)))).sort();
|
|
240
|
+
const probes = [...raw.probes].filter((p) => !raw.reads.has(p) && !raw.self.includes(p) && !walks.some((w) => covers(w.dir, p))).sort();
|
|
241
|
+
const kinds = [...raw.kinds];
|
|
242
|
+
return {
|
|
243
|
+
seconds: raw.seconds,
|
|
244
|
+
history: kinds.filter((k) => k.startsWith('history:')).map((k) => k.slice(8)).sort(),
|
|
245
|
+
untraced: kinds.filter((k) => k.startsWith('untraced:')).map((k) => k.slice(9)).sort(),
|
|
246
|
+
self: raw.self,
|
|
247
|
+
walks,
|
|
248
|
+
files,
|
|
249
|
+
probes,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function loadTable() {
|
|
254
|
+
try {
|
|
255
|
+
return JSON.parse(readFileSync(tablePath, 'utf8'));
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Why a change reaches a step; an empty answer — it does not. */
|
|
262
|
+
function reasonOf(entry, changes) {
|
|
263
|
+
if (entry.history.length) return `reads the history (${entry.history.join(', ')})`;
|
|
264
|
+
if (entry.untraced.length) return `starts ${entry.untraced.join(', ')}, whose reads are not seen`;
|
|
265
|
+
for (const { kind, path } of changes) {
|
|
266
|
+
if (entry.self.includes(path)) return `${path} is the step itself`;
|
|
267
|
+
if (entry.files.includes(path)) return `${path} is read by it`;
|
|
268
|
+
const ext = extOf(path);
|
|
269
|
+
if (kind === 'M' && entry.walks.some((w) => covers(w.dir, path) && w.exts.includes(ext))) return `${path} lies where it reads ${ext}`;
|
|
270
|
+
if (kind !== 'M' && entry.walks.some((w) => covers(w.dir, path))) return `${path} is ${kind === 'A' ? 'added to' : 'removed from'} a directory it walks`;
|
|
271
|
+
if (kind !== 'M' && (entry.probes ?? []).some((f) => covers(f, path))) return `${path} is ${kind === 'A' ? 'added at' : 'removed from'} a path it probes`;
|
|
272
|
+
}
|
|
273
|
+
return '';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function changesOf(base) {
|
|
277
|
+
const file = option('--changes');
|
|
278
|
+
const text = file
|
|
279
|
+
? readFileSync(file, 'utf8')
|
|
280
|
+
: spawnSync('git', ['diff', '--name-status', '-M', `${base}...HEAD`], { cwd: ROOT, encoding: 'utf8' }).stdout;
|
|
281
|
+
if (text == null) return null;
|
|
282
|
+
const changes = [];
|
|
283
|
+
for (const line of text.split('\n').filter(Boolean)) {
|
|
284
|
+
const [status, a, b] = line.split('\t');
|
|
285
|
+
if (status.startsWith('R') || status.startsWith('C')) {
|
|
286
|
+
if (status.startsWith('R')) changes.push({ kind: 'D', path: a });
|
|
287
|
+
changes.push({ kind: 'A', path: b });
|
|
288
|
+
} else {
|
|
289
|
+
changes.push({ kind: status === 'A' || status === 'D' ? status : 'M', path: a });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return changes;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Why a change reaches a step, by the table; an empty answer — it does not. */
|
|
296
|
+
function reasonsOf(table, changes) {
|
|
297
|
+
const verifyInputs = new Set([rel(tablePath), rel(TRACER), rel(fileURLToPath(import.meta.url))]);
|
|
298
|
+
// A step with a recorded kind is not traced by the check, so an edit of its script starts no check.
|
|
299
|
+
for (const entry of Object.values(table.steps)) {
|
|
300
|
+
if (!runsAlways(entry)) for (const p of entry.self) verifyInputs.add(p);
|
|
301
|
+
}
|
|
302
|
+
return (step) => {
|
|
303
|
+
if (VERIFY.test(step)) {
|
|
304
|
+
const hit = changes.find((c) => verifyInputs.has(c.path));
|
|
305
|
+
return hit ? `${hit.path} is a step or the table` : '';
|
|
306
|
+
}
|
|
307
|
+
if (!table.steps[step]) return traceable(step) ? 'it is not in the table' : 'its reads are not recorded';
|
|
308
|
+
return reasonOf(table.steps[step], changes);
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Whether a change touched the subject of each step: `touched`, `idle`, `unknown` or `not-run`.
|
|
314
|
+
* A step of the table is judged by the rule `select` uses, and one it drops is `not-run`: the set
|
|
315
|
+
* never starts it. A step the table does not record is judged by the paths the tree declares for
|
|
316
|
+
* it — `--declared <file>`, lines `<path>\t<step>`; with no paths declared it is `unknown`. A step
|
|
317
|
+
* that reads the history or starts what the recorder does not see is `unknown` too: its subject is
|
|
318
|
+
* not a list of paths.
|
|
319
|
+
*/
|
|
320
|
+
function subject(base) {
|
|
321
|
+
const steps = stepsOf(readStdin());
|
|
322
|
+
const table = loadTable() ?? { steps: {} };
|
|
323
|
+
const changes = base ? changesOf(base) : null;
|
|
324
|
+
const declared = new Map();
|
|
325
|
+
const file = option('--declared');
|
|
326
|
+
for (const line of (file && existsSync(file) ? readFileSync(file, 'utf8') : '').split('\n').filter(Boolean)) {
|
|
327
|
+
const [path, ...rest] = line.split('\t');
|
|
328
|
+
const step = rest.join('\t');
|
|
329
|
+
declared.set(step, [...(declared.get(step) ?? []), path.replace(/\/+$/, '')]);
|
|
330
|
+
}
|
|
331
|
+
const reason = changes ? reasonsOf(table, changes) : () => 'no base';
|
|
332
|
+
for (const step of steps) {
|
|
333
|
+
let mark = 'unknown';
|
|
334
|
+
const entry = table.steps[step];
|
|
335
|
+
if (changes && declared.has(step)) {
|
|
336
|
+
mark = changes.some((c) => declared.get(step).some((p) => covers(p, c.path))) ? 'touched' : 'idle';
|
|
337
|
+
} else if (changes && (entry || VERIFY.test(step))) {
|
|
338
|
+
const why = reason(step);
|
|
339
|
+
mark = !why ? 'not-run' : entry && (entry.history.length || entry.untraced.length) ? 'unknown' : 'touched';
|
|
340
|
+
}
|
|
341
|
+
process.stdout.write(`${mark}\t${step}\n`);
|
|
342
|
+
}
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function select(base) {
|
|
347
|
+
const steps = stepsOf(readStdin());
|
|
348
|
+
const table = loadTable();
|
|
349
|
+
const changes = base ? changesOf(base) : null;
|
|
350
|
+
if (!table || !changes) {
|
|
351
|
+
process.stdout.write(steps.map((s) => `${s}\n`).join(''));
|
|
352
|
+
return 0;
|
|
353
|
+
}
|
|
354
|
+
const reasonFor = reasonsOf(table, changes);
|
|
355
|
+
for (const step of steps) {
|
|
356
|
+
const reason = reasonFor(step);
|
|
357
|
+
if (reason) {
|
|
358
|
+
process.stdout.write(`${step}\n`);
|
|
359
|
+
process.stderr.write(`→ ${step}: ${reason}\n`);
|
|
360
|
+
} else {
|
|
361
|
+
process.stderr.write(`· not run: ${step} — the change touches nothing it reads\n`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function write(table) {
|
|
368
|
+
writeFileSync(tablePath, `${JSON.stringify(table, null, 4)}\n`);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The kinds of processes a step was seen to start stay in its entry. Whether a step starts one may
|
|
373
|
+
* hang on the machine — a database address in `.env`, a tool on the path — and a table that dropped
|
|
374
|
+
* the kind on the next machine refused the push of the machine after it. Kept, a kind errs towards
|
|
375
|
+
* an extra run of the step, never towards a skipped one.
|
|
376
|
+
*/
|
|
377
|
+
function keepKinds(entry, old) {
|
|
378
|
+
if (!old) return entry;
|
|
379
|
+
const union = (a, b) => [...new Set([...a, ...(b ?? [])])].sort();
|
|
380
|
+
return { ...entry, history: union(entry.history, old.history), untraced: union(entry.untraced, old.untraced) };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function record() {
|
|
384
|
+
let steps = stepsOf(readStdin());
|
|
385
|
+
if (!steps.length) steps = profileSteps();
|
|
386
|
+
const before = loadTable()?.steps ?? {};
|
|
387
|
+
const table = { note: 'Generated by `node tools/push-inputs.mjs record`; not edited by hand.', steps: {} };
|
|
388
|
+
for (const step of steps.filter(traceable)) {
|
|
389
|
+
if (VERIFY.test(step)) continue;
|
|
390
|
+
table.steps[step] = keepKinds(entryOf(trace(step)), before[step]);
|
|
391
|
+
process.stderr.write(`recorded in ${table.steps[step].seconds}s: ${step}\n`);
|
|
392
|
+
}
|
|
393
|
+
write(table);
|
|
394
|
+
process.stderr.write(`push inputs: ${Object.keys(table.steps).length} steps written to ${rel(tablePath)}\n`);
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function verify() {
|
|
399
|
+
const table = loadTable();
|
|
400
|
+
if (!table) return 0;
|
|
401
|
+
const misses = [];
|
|
402
|
+
let always = 0;
|
|
403
|
+
for (const [step, entry] of Object.entries(table.steps)) {
|
|
404
|
+
// A step with a recorded kind runs on every change already: a new kind changes no selection,
|
|
405
|
+
// and a refusal over it would only name the machine — a platform suffix, a tool on the path.
|
|
406
|
+
if (runsAlways(entry)) {
|
|
407
|
+
always += 1;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const raw = trace(step);
|
|
411
|
+
const now = entryOf(raw);
|
|
412
|
+
for (const h of now.history) misses.push(`${step}: now reads the history (${h})`);
|
|
413
|
+
for (const u of now.untraced) misses.push(`${step}: now starts ${u}`);
|
|
414
|
+
if (now.history.length || now.untraced.length) continue;
|
|
415
|
+
for (const p of [...raw.reads, ...raw.self]) {
|
|
416
|
+
if (!reasonOf(entry, [{ kind: 'M', path: p }])) misses.push(`${step}: reads ${p}`);
|
|
417
|
+
}
|
|
418
|
+
for (const p of raw.probes) {
|
|
419
|
+
if (!reasonOf(entry, [{ kind: 'A', path: p }])) misses.push(`${step}: probes ${p}`);
|
|
420
|
+
}
|
|
421
|
+
for (const d of raw.walks) {
|
|
422
|
+
if (!entry.walks.some((w) => covers(w.dir, d))) misses.push(`${step}: walks ${d}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (!misses.length) {
|
|
426
|
+
const total = Object.keys(table.steps).length;
|
|
427
|
+
process.stdout.write(
|
|
428
|
+
`push inputs: the table covers what ${total - always} traced steps read; ${always} run on every change and are not traced\n`,
|
|
429
|
+
);
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
process.stdout.write(
|
|
433
|
+
`push inputs: the table does not cover what the steps read now — a change there would not start them.\n` +
|
|
434
|
+
`${misses.map((m) => ` ${m}`).join('\n')}\n` +
|
|
435
|
+
`Record the table again: node tools/push-inputs.mjs record\n`,
|
|
436
|
+
);
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const command = args[0];
|
|
441
|
+
const code =
|
|
442
|
+
command === 'record' ? record() : command === 'verify' ? verify() : command === 'select' ? select(args[1]) : command === 'subject' ? subject(args[1]) : 2;
|
|
443
|
+
if (code === 2) process.stderr.write('usage: push-inputs.mjs record | select <base> | subject <base> | verify\n');
|
|
444
|
+
process.exit(code);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The read recorder of a push set step. It is loaded into a step by `--import` and writes down what
|
|
4
|
+
* the step really reads: every file whose content it opens, every path whose existence it probes,
|
|
5
|
+
* every directory it walks and every process it starts. The step itself is not changed.
|
|
6
|
+
*
|
|
7
|
+
* The record is the input of `push-inputs.mjs`: from it the set learns which steps a change can
|
|
8
|
+
* reach. A list of inputs written by hand checks itself and goes stale silently; a record taken
|
|
9
|
+
* from the step's own calls does not depend on whoever writes the list.
|
|
10
|
+
*
|
|
11
|
+
* A child `node` inherits `NODE_OPTIONS` and is recorded into a file of its own. A process of
|
|
12
|
+
* another kind is only named: its reads are not seen, and the step that starts it runs always.
|
|
13
|
+
*
|
|
14
|
+
* FAIL-OPEN: without `RT_PUSH_TRACE_OUT` the module does nothing; an error of its own is swallowed,
|
|
15
|
+
* so the step runs as it would without it.
|
|
16
|
+
*/
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import cp from 'node:child_process';
|
|
19
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
20
|
+
import { join, resolve } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const OUT = process.env.RT_PUSH_TRACE_OUT ?? '';
|
|
24
|
+
|
|
25
|
+
if (OUT) {
|
|
26
|
+
const reads = new Set();
|
|
27
|
+
const probes = new Set();
|
|
28
|
+
const walks = new Set();
|
|
29
|
+
const spawns = [];
|
|
30
|
+
const writeFile = fs.writeFileSync;
|
|
31
|
+
const mkdir = fs.mkdirSync;
|
|
32
|
+
|
|
33
|
+
const pathOf = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
if (typeof value === 'string') return resolve(value);
|
|
36
|
+
if (value instanceof URL) return fileURLToPath(value);
|
|
37
|
+
if (Buffer.isBuffer(value)) return resolve(value.toString());
|
|
38
|
+
} catch {
|
|
39
|
+
// An argument that is no path is not recorded.
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
};
|
|
43
|
+
const writing = (flags) => typeof flags === 'string' && /[wa+]/.test(flags);
|
|
44
|
+
|
|
45
|
+
const wrap = (target, name, note) => {
|
|
46
|
+
const original = target[name];
|
|
47
|
+
if (typeof original !== 'function') return;
|
|
48
|
+
target[name] = function traced(...args) {
|
|
49
|
+
try {
|
|
50
|
+
note(args);
|
|
51
|
+
} catch {
|
|
52
|
+
// The recorder never breaks the step.
|
|
53
|
+
}
|
|
54
|
+
return original.apply(this, args);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const read = (args) => {
|
|
58
|
+
const path = pathOf(args[0]);
|
|
59
|
+
if (path) reads.add(path);
|
|
60
|
+
};
|
|
61
|
+
const probe = (args) => {
|
|
62
|
+
const path = pathOf(args[0]);
|
|
63
|
+
if (path) probes.add(path);
|
|
64
|
+
};
|
|
65
|
+
const open = (args) => {
|
|
66
|
+
if (!writing(typeof args[1] === 'object' ? args[1]?.flags : args[1])) read(args);
|
|
67
|
+
};
|
|
68
|
+
const walk = (args) => {
|
|
69
|
+
const path = pathOf(args[0]);
|
|
70
|
+
if (path) walks.add(path);
|
|
71
|
+
};
|
|
72
|
+
// The directory a process starts in is kept: `git` in a scratch repository of the step does not
|
|
73
|
+
// read this tree's history.
|
|
74
|
+
const spawn = (args) => {
|
|
75
|
+
const [command, rest, options] = args;
|
|
76
|
+
if (typeof command !== 'string') return;
|
|
77
|
+
const list = Array.isArray(rest) ? rest.map(String) : [];
|
|
78
|
+
const where = (Array.isArray(rest) ? options : rest)?.cwd;
|
|
79
|
+
spawns.push({ cwd: pathOf(where ?? process.cwd()), command: [command, ...list] });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
for (const name of ['readFileSync', 'readFile', 'createReadStream']) wrap(fs, name, read);
|
|
83
|
+
for (const name of ['existsSync', 'statSync', 'lstatSync', 'accessSync', 'stat', 'lstat', 'access']) wrap(fs, name, probe);
|
|
84
|
+
wrap(fs, 'openSync', open);
|
|
85
|
+
wrap(fs, 'open', open);
|
|
86
|
+
for (const name of ['readdirSync', 'readdir', 'opendirSync', 'opendir']) wrap(fs, name, walk);
|
|
87
|
+
wrap(fs.promises, 'readFile', read);
|
|
88
|
+
for (const name of ['stat', 'lstat', 'access']) wrap(fs.promises, name, probe);
|
|
89
|
+
wrap(fs.promises, 'open', open);
|
|
90
|
+
for (const name of ['readdir', 'opendir']) wrap(fs.promises, name, walk);
|
|
91
|
+
for (const name of ['execFileSync', 'execFile', 'spawnSync', 'spawn']) wrap(cp, name, spawn);
|
|
92
|
+
for (const name of ['execSync', 'exec']) {
|
|
93
|
+
wrap(cp, name, (args) => typeof args[0] === 'string' && spawns.push({ cwd: pathOf(args[1]?.cwd ?? process.cwd()), command: ['sh', '-c', args[0]] }));
|
|
94
|
+
}
|
|
95
|
+
syncBuiltinESMExports();
|
|
96
|
+
|
|
97
|
+
process.on('exit', () => {
|
|
98
|
+
try {
|
|
99
|
+
mkdir(OUT, { recursive: true });
|
|
100
|
+
writeFile(
|
|
101
|
+
join(OUT, `${process.pid}.json`),
|
|
102
|
+
JSON.stringify({ cwd: process.cwd(), argv: process.argv.slice(1), reads: [...reads], probes: [...probes], walks: [...walks], spawns }),
|
|
103
|
+
);
|
|
104
|
+
} catch {
|
|
105
|
+
// A record that could not be written leaves the step without inputs: it runs always.
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|