@rt-tools/agent-kit 0.37.1 → 0.39.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-runs.github.mjs +40 -5
- package/assets/checks/check-board.github.mjs +38 -7
- 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 +21432 -0
- package/assets/checks/decision-table.mjs +495 -0
- package/assets/checks/epic-window.mjs +98 -0
- package/assets/checks/flow-condition.mjs +64 -0
- package/assets/checks/flow-data.mjs +135 -0
- package/assets/checks/flow-forecast.mjs +334 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +496 -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 +495 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +227 -0
- package/assets/checks/merge-read.mjs +239 -0
- package/assets/checks/owner-nudges.mjs +389 -0
- package/assets/checks/push-inputs.mjs +59 -16
- package/assets/checks/record-count.mjs +437 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/task-flow-script.mjs +318 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +362 -0
- package/assets/checks/work-steps-lib.mjs +205 -0
- package/assets/commands/night.md +6 -6
- package/assets/defaults/gate-map.sh +39 -12
- package/assets/defaults/merges.sh +48 -0
- package/assets/defaults/project.sh +6 -5
- package/assets/defaults/turn-map.md +23 -22
- package/assets/docs/GLOSSARY.md +5 -1
- package/assets/hooks/ask-judge.md +67 -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 -152
- 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 +374 -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 +44 -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 +39 -6
- package/assets/hooks/git-guard-push-marks.sh +262 -13
- package/assets/hooks/git-guard-push-tests.sh +58 -52
- 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 +19 -38
- 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 +40 -12
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-ahead-call-guard.sh +447 -0
- package/assets/hooks/push-set.sh +38 -8
- 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 +5 -18
- package/assets/hooks/task-flow-draft-guard.sh +25 -74
- package/assets/hooks/task-flow-guard.sh +28 -130
- 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 +3 -1
- package/assets/hooks/turn-judge.md +113 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- package/assets/patterns/doc-style-human.md +36 -76
- 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 +8 -56
- package/assets/patterns/git-workflow-merge.md +6 -176
- package/assets/patterns/git-workflow-migration.md +5 -75
- package/assets/patterns/git-workflow-pr-body.github.md +6 -159
- package/assets/patterns/git-workflow-pr-ready.md +9 -70
- package/assets/patterns/git-workflow-pr.azure.md +13 -285
- package/assets/patterns/git-workflow-pr.github.md +13 -251
- package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
- package/assets/patterns/git-workflow-restart.md +5 -42
- package/assets/patterns/git-workflow-secrets.md +10 -76
- package/assets/patterns/git-workflow-stack.md +7 -207
- package/assets/patterns/status-report-table.github.md +1 -1
- package/assets/patterns/task-flow-archive.md +12 -233
- package/assets/patterns/task-flow-close.md +16 -292
- package/assets/patterns/task-flow-cycle.md +13 -39
- package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
- package/assets/patterns/task-flow-handoff.md +13 -161
- package/assets/patterns/task-flow-resume.md +18 -218
- package/assets/patterns/task-flow-start.md +9 -247
- package/assets/patterns/turn-entry-map.md +2 -2
- 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/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-human.md +112 -0
- package/assets/pitfalls/doc-style.2.md +286 -0
- package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
- package/assets/pitfalls/entity-models.md +89 -0
- package/assets/pitfalls/epic-flow.md +92 -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/lib-layers.md +114 -0
- package/assets/pitfalls/lists.md +117 -0
- package/assets/pitfalls/mockups.needs-mockups.md +87 -0
- package/assets/pitfalls/navigation.md +94 -0
- package/assets/pitfalls/observability.needs-app.md +186 -0
- package/assets/pitfalls/platform-access.md +94 -0
- package/assets/pitfalls/queue-audit.github.md +78 -0
- package/assets/pitfalls/reuse-first.md +201 -0
- package/assets/pitfalls/spec-driven.2.md +318 -0
- package/assets/pitfalls/styling-bem.2.md +125 -0
- package/assets/pitfalls/task-flow-archive.md +265 -0
- package/assets/pitfalls/task-flow-close.2.md +166 -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 +58 -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 +4 -4
- package/assets/pitfalls/testing.2.md +279 -0
- package/assets/pitfalls/turn-conduct.md +16 -17
- 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 +2 -2
- package/assets/rules/browser-verification.md +28 -256
- package/assets/rules/component-structure.md +25 -87
- package/assets/rules/dependencies.md +20 -78
- package/assets/rules/deploy-flow.azure.md +26 -156
- package/assets/rules/deploy-flow.github.md +34 -200
- package/assets/rules/deploy-flow.gitlab.md +27 -159
- package/assets/rules/doc-style.md +32 -286
- package/assets/rules/entity-conventions.needs-admin.md +26 -82
- package/assets/rules/entity-models.md +14 -63
- package/assets/rules/epic-flow.md +24 -63
- 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 -282
- package/assets/rules/git-workflow.github.md +24 -284
- package/assets/rules/git-workflow.gitlab.md +21 -269
- package/assets/rules/lib-layers.md +30 -103
- package/assets/rules/lists.md +21 -105
- package/assets/rules/mockups.needs-mockups.md +25 -64
- package/assets/rules/navigation.md +10 -69
- package/assets/rules/observability.needs-app.md +43 -172
- package/assets/rules/platform-access.md +28 -75
- package/assets/rules/queue-audit.github.md +25 -52
- package/assets/rules/reuse-first.md +20 -195
- package/assets/rules/spec-driven.md +35 -308
- 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 -300
- package/assets/rules/testing.md +32 -273
- package/assets/rules/turn-conduct.md +105 -106
- 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 +184 -0
- package/assets/task-flow/flow.md +101 -0
- package/assets/task-flow/measure/agreement.mjs +24 -0
- package/assets/task-flow/measure/ci.mjs +184 -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 +27 -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 +252 -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 +254 -0
- package/assets/task-flow/source/host.mjs +277 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +94 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +269 -0
- package/assets/task-flow/source/steps.mjs +28 -0
- package/assets/task-flow/source/tree.mjs +42 -0
- 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 +221 -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.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/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/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 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +2 -2
- 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.js +3 -3
- package/lib/observations.js.map +1 -1
- package/lib/outcomes.d.ts +5 -2
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +5 -4
- package/lib/outcomes.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/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/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/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,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The count of one turn of a session record, written as observations. The hook at the end of a turn
|
|
4
|
+
* and at the end of a session calls it; so does the recount of a past day.
|
|
5
|
+
*
|
|
6
|
+
* node record-turn.mjs --record <session.jsonl> --observations <dir> --mark <file> --sid <sign>
|
|
7
|
+
* [--patterns <correction patterns>] [--version <v>] [--now <ISO>]
|
|
8
|
+
*
|
|
9
|
+
* It reads the record from the offset its mark keeps, turns the new entries into the events of
|
|
10
|
+
* `record-count.mjs` and appends each as an observation line to the file of the day of its moment:
|
|
11
|
+
* `{"t":<moment>,"ev":"record-<event>",...,"sid":<sign>}`. The words of the owner leave no text: a word
|
|
12
|
+
* carries only its kind and whether the set of correction patterns matched it.
|
|
13
|
+
*
|
|
14
|
+
* An unfinished last line — the harness writes the record while the hook runs — is left for the next
|
|
15
|
+
* count: the mark stays before it. A line in the middle that does not parse is skipped and counted
|
|
16
|
+
* (`record-skip`). A record that cannot be read writes `record-broken` and changes no mark. The count
|
|
17
|
+
* never fails the turn: every path exits with zero.
|
|
18
|
+
*
|
|
19
|
+
* Taking a task is the first moment a session stands on the branch of the task: the first entry of
|
|
20
|
+
* the session with that branch writes `{"ev":"task-taken","task":<key>}`. The mark keeps the tasks
|
|
21
|
+
* the session already took, so a later turn on the same branch writes no second taking.
|
|
22
|
+
*/
|
|
23
|
+
import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, readSync, closeSync, statSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { dirname, join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { eventsOf, ownerWords, taskOf } from './record-count.mjs';
|
|
27
|
+
|
|
28
|
+
const option = (argv, name) => {
|
|
29
|
+
const at = argv.indexOf(name);
|
|
30
|
+
return at >= 0 ? argv[at + 1] : undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** A value fit for an observation: no path, only a name, trimmed. */
|
|
34
|
+
const clean = (value) => (value === undefined || value === null ? '' : String(value).includes('/') ? '' : String(value).replace(/[^A-Za-z0-9._:-]/g, '').slice(0, 48));
|
|
35
|
+
|
|
36
|
+
const readMark = (file) => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
39
|
+
} catch {
|
|
40
|
+
return { offset: 0 };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The whole lines of a record from an offset: the parsed entries, the skipped count and the new offset. */
|
|
45
|
+
export function readFrom(file, offset) {
|
|
46
|
+
const size = statSync(file).size;
|
|
47
|
+
if (size <= offset) return { entries: [], skipped: 0, offset: Math.min(offset, size) };
|
|
48
|
+
const fd = openSync(file, 'r');
|
|
49
|
+
const buffer = Buffer.alloc(size - offset);
|
|
50
|
+
try {
|
|
51
|
+
readSync(fd, buffer, 0, buffer.length, offset);
|
|
52
|
+
} finally {
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
}
|
|
55
|
+
const end = buffer.lastIndexOf(0x0a);
|
|
56
|
+
if (end < 0) return { entries: [], skipped: 0, offset };
|
|
57
|
+
const entries = [];
|
|
58
|
+
let skipped = 0;
|
|
59
|
+
for (const line of buffer.subarray(0, end).toString('utf8').split('\n')) {
|
|
60
|
+
if (!line.trim()) continue;
|
|
61
|
+
try {
|
|
62
|
+
entries.push(JSON.parse(line));
|
|
63
|
+
} catch {
|
|
64
|
+
skipped += 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { entries, skipped, offset: offset + end + 1 };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A task key of a branch: the taking is written only for a branch that names a task. */
|
|
71
|
+
const TASK_KEY = /^[A-Z]+-\d+$/;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The takings of tasks in some entries: the first entry of each task the session stands on, not
|
|
75
|
+
* counting the tasks of `seen`. The set is filled with what is found.
|
|
76
|
+
*/
|
|
77
|
+
export function takingsOf(entries, seen = new Set()) {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
const at = entry?.timestamp;
|
|
81
|
+
const task = taskOf(entry?.gitBranch);
|
|
82
|
+
if (!at || entry?.isSidechain || !task || !TASK_KEY.test(task) || seen.has(task)) continue;
|
|
83
|
+
seen.add(task);
|
|
84
|
+
out.push({ at, task });
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The observation lines of the events of some entries, by the day of their moment. */
|
|
90
|
+
export function observationsOf(entries, { sid, patterns, version, seen = new Set() }) {
|
|
91
|
+
const pattern = patterns ? new RegExp(patterns, 'iu') : null;
|
|
92
|
+
const corrected = new Set(
|
|
93
|
+
pattern ? ownerWords(entries).filter((w) => pattern.test(w.text)).map((w) => `${w.session}|${w.at}|${w.kind}`) : [],
|
|
94
|
+
);
|
|
95
|
+
const byDay = new Map();
|
|
96
|
+
for (const e of eventsOf(entries)) {
|
|
97
|
+
const line = { t: e.at, ev: `record-${e.ev}` };
|
|
98
|
+
const task = clean(taskOf(e.branch));
|
|
99
|
+
if (task) line.task = task;
|
|
100
|
+
for (const key of ['kind', 'check', 'tool']) if (e[key] !== undefined && e[key] !== null) line[key] = clean(e[key]);
|
|
101
|
+
if (e.ev === 'ask' && e.reask) line.reask = '1';
|
|
102
|
+
if (e.ev === 'change' && e.analysis) line.analysis = '1';
|
|
103
|
+
if (e.ev === 'menu' && e.answered) line.answered = clean(e.answered);
|
|
104
|
+
if (e.ev === 'word' && corrected.has(`${e.session}|${e.at}|${e.kind}`)) line.corr = '1';
|
|
105
|
+
line.sid = sid;
|
|
106
|
+
if (version) line.v = version;
|
|
107
|
+
const day = e.at.slice(0, 10);
|
|
108
|
+
if (!byDay.has(day)) byDay.set(day, []);
|
|
109
|
+
byDay.get(day).push(JSON.stringify(line));
|
|
110
|
+
}
|
|
111
|
+
for (const taking of takingsOf(entries, seen)) {
|
|
112
|
+
const day = taking.at.slice(0, 10);
|
|
113
|
+
if (!byDay.has(day)) byDay.set(day, []);
|
|
114
|
+
byDay.get(day).push(JSON.stringify({ t: taking.at, ev: 'task-taken', task: clean(taking.task), sid, ...(version ? { v: version } : {}) }));
|
|
115
|
+
}
|
|
116
|
+
return byDay;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function main(argv) {
|
|
120
|
+
const record = option(argv, '--record');
|
|
121
|
+
const dir = option(argv, '--observations');
|
|
122
|
+
const markFile = option(argv, '--mark');
|
|
123
|
+
const sid = clean(option(argv, '--sid'));
|
|
124
|
+
const version = clean(option(argv, '--version'));
|
|
125
|
+
const now = option(argv, '--now') ?? new Date().toISOString();
|
|
126
|
+
if (!dir || !markFile) return 0;
|
|
127
|
+
const note = (ev, extra = {}) => {
|
|
128
|
+
try {
|
|
129
|
+
mkdirSync(dir, { recursive: true });
|
|
130
|
+
appendFileSync(join(dir, `${now.slice(0, 10)}.jsonl`), `${JSON.stringify({ t: now, ev, ...extra, sid, ...(version ? { v: version } : {}) })}\n`);
|
|
131
|
+
} catch {
|
|
132
|
+
// The count never fails the turn.
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
if (!record || !existsSync(record)) {
|
|
136
|
+
note('record-broken');
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const mark = readMark(markFile);
|
|
141
|
+
const read = readFrom(record, Number(mark.offset) || 0);
|
|
142
|
+
const seen = new Set(Array.isArray(mark.taken) ? mark.taken : []);
|
|
143
|
+
const byDay = observationsOf(read.entries, { sid, patterns: option(argv, '--patterns'), version, seen });
|
|
144
|
+
mkdirSync(dir, { recursive: true });
|
|
145
|
+
for (const [day, lines] of byDay) appendFileSync(join(dir, `${day}.jsonl`), `${lines.join('\n')}\n`);
|
|
146
|
+
if (read.skipped > 0) note('record-skip', { n: String(read.skipped) });
|
|
147
|
+
mkdirSync(dirname(markFile), { recursive: true });
|
|
148
|
+
writeFileSync(markFile, JSON.stringify({ offset: read.offset, taken: [...seen] }));
|
|
149
|
+
} catch {
|
|
150
|
+
note('record-broken');
|
|
151
|
+
}
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) process.exit(main(process.argv.slice(2)));
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The engine of the task flow: reads the description `flow.js` through the model and answers about
|
|
4
|
+
* the scenario. The description lies next to the engine as `task-flow/flow.js` where the engine is
|
|
5
|
+
* laid out, and as `../task-flow/flow.js` in the package; `--flow <path>` names another one.
|
|
6
|
+
*
|
|
7
|
+
* node task-flow-script.mjs states the states of the scenario in their order, a line each:
|
|
8
|
+
* `<n>. <title> — <action> (<pattern>)`
|
|
9
|
+
* node task-flow-script.mjs measure the measured state of the checked-out branch, its action and
|
|
10
|
+
* the exits read up to it; `--json` prints one object with
|
|
11
|
+
* `state`, `index`, `reason`, `exits`, `action`, `pattern`
|
|
12
|
+
* node task-flow-script.mjs step N.M runs the check of that step of the plan, prints
|
|
13
|
+
* `ожидалось … · получено … · совпало|не совпало` and writes the
|
|
14
|
+
* mark of a matched step; exits 0 on a match, 1 otherwise
|
|
15
|
+
* node task-flow-script.mjs step --done the same for every step the progress marks done
|
|
16
|
+
* node task-flow-script.mjs step --done --pr the rerun before a PR opens: a taken-apart folder
|
|
17
|
+
* comes back from the history for the run, a check that
|
|
18
|
+
* changes a tracked file does not match
|
|
19
|
+
* node task-flow-script.mjs plan-check <plan.md> names every check of the plan in no known
|
|
20
|
+
* form or that is a command of the work; exits 1 on any
|
|
21
|
+
* node task-flow-script.mjs plan-red runs every check of the plan of the branch and writes the
|
|
22
|
+
* approval mark when all are red and the owner approved after
|
|
23
|
+
* both roles; the record of the conversation is named by
|
|
24
|
+
* `RT_FLOW_TRANSCRIPT`
|
|
25
|
+
* node task-flow-script.mjs guard reads the input of a hook before Edit, Write, MultiEdit or a
|
|
26
|
+
* shell command from stdin and prints the reason of a refusal,
|
|
27
|
+
* or nothing — the hook `flow-step-guard.sh` calls it
|
|
28
|
+
*
|
|
29
|
+
* The tree override `.claude/rt-kit/overrides/task-flow/flow.js` is merged with the description
|
|
30
|
+
* key by key when it lies in the tree and no `--flow` is named; `--override <path>` names another
|
|
31
|
+
* one. `measure` prints every key the override removed, with its reason.
|
|
32
|
+
*
|
|
33
|
+
* A description that does not build is named with its reason, and the engine exits 1: a scenario
|
|
34
|
+
* read from a broken description would measure what nobody wrote.
|
|
35
|
+
*/
|
|
36
|
+
import { spawnSync } from 'node:child_process';
|
|
37
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
38
|
+
import { homedir } from 'node:os';
|
|
39
|
+
import { dirname, join } from 'node:path';
|
|
40
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
41
|
+
|
|
42
|
+
import { evaluateCondition } from './flow-condition.mjs';
|
|
43
|
+
import { runForecast } from './flow-forecast.mjs';
|
|
44
|
+
import { judgeCall } from './flow-guard.mjs';
|
|
45
|
+
import { callOf, guardContext } from './flow-guard-run.mjs';
|
|
46
|
+
import { isWriteCommand, retiredLines } from './flow-data.mjs';
|
|
47
|
+
import { FlowModelError, buildModel } from './flow-model.mjs';
|
|
48
|
+
import { overridePath, removedLines } from './flow-override.mjs';
|
|
49
|
+
import { planProblems, readRecord, runPlanRed } from './flow-plan.mjs';
|
|
50
|
+
import { runStepCommand } from './flow-step.mjs';
|
|
51
|
+
import { FlowSyntaxError } from './flow-syntax.mjs';
|
|
52
|
+
import { currentStep, decide, holdReason, menuCause, stageStep } from './flow-verdict.mjs';
|
|
53
|
+
|
|
54
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
55
|
+
// The history source puts a taken-apart folder back; it lies next to the laid-out engine, one level up in the package.
|
|
56
|
+
const history = await import(pathToFileURL([join(HERE, 'task-flow/source/git.mjs'), join(HERE, '../task-flow/source/git.mjs')].find((path) => existsSync(path))).href);
|
|
57
|
+
|
|
58
|
+
/** Where the description lies: next to the laid-out engine, or in the package. */
|
|
59
|
+
export function flowPath(given) {
|
|
60
|
+
if (given) return given;
|
|
61
|
+
const laid = join(HERE, 'task-flow', 'flow.js');
|
|
62
|
+
return existsSync(laid) ? laid : join(HERE, '..', 'task-flow', 'flow.js');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The lines of `states`. */
|
|
66
|
+
export function stateLines(model) {
|
|
67
|
+
return model.states.map((s, i) => `${i + 1}. ${s.title} — ${s.action ?? ''} (${s.pattern ?? ''})`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A read the hosting did not answer twice: the error a source throws carries this name. */
|
|
71
|
+
const SILENT = 'HostSilent';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The measured state: the first state whose exit is known to be unmet. An exit the hosting could not
|
|
75
|
+
* answer is unknown and is passed over, and the exits after it are measured. With no unmet exit and
|
|
76
|
+
* an unknown one, the measured state is the first unknown, and the reason is the silent hosting.
|
|
77
|
+
* With every exit met, the scenario is over.
|
|
78
|
+
*
|
|
79
|
+
* `read(name)` answers a measurer result by its reference and may throw `HostSilent`; a result is
|
|
80
|
+
* read once per measurement. Returns `{ state, index, reason, exits }`, `exits` mapping a state key
|
|
81
|
+
* to `true`, `false` or `'unknown'`.
|
|
82
|
+
*/
|
|
83
|
+
export function measureStates(model, read) {
|
|
84
|
+
const cache = new Map();
|
|
85
|
+
const measured = (name) => {
|
|
86
|
+
if (!cache.has(name)) cache.set(name, read(name));
|
|
87
|
+
return cache.get(name);
|
|
88
|
+
};
|
|
89
|
+
const exits = {};
|
|
90
|
+
let firstUnknown = null;
|
|
91
|
+
for (const [index, state] of model.states.entries()) {
|
|
92
|
+
let met;
|
|
93
|
+
try {
|
|
94
|
+
met = evaluateCondition(state.exit, measured);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error?.name !== SILENT) throw error;
|
|
97
|
+
exits[state.key] = 'unknown';
|
|
98
|
+
firstUnknown ??= index;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
exits[state.key] = met;
|
|
102
|
+
if (!met) return { state: state.title, index: index + 1, reason: null, exits };
|
|
103
|
+
}
|
|
104
|
+
if (firstUnknown !== null) {
|
|
105
|
+
return { state: model.states[firstUnknown].title, index: firstUnknown + 1, reason: 'the hosting did not answer twice', exits };
|
|
106
|
+
}
|
|
107
|
+
return { state: null, index: model.states.length + 1, reason: 'the end of the scenario', exits };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The sources of a description by name. Every module is loaded first; a source is opened when it is
|
|
112
|
+
* first asked for, so a source not written yet throws only where it is needed. `given` maps a source
|
|
113
|
+
* name to an opened source and replaces its module.
|
|
114
|
+
*/
|
|
115
|
+
export async function openSources(model, base, given = {}) {
|
|
116
|
+
const modules = {};
|
|
117
|
+
for (const s of model.sources) {
|
|
118
|
+
if (!(s.entry in given)) modules[s.entry] = await import(pathToFileURL(join(base, s.file)).href);
|
|
119
|
+
}
|
|
120
|
+
const opened = { ...given };
|
|
121
|
+
return (name) => {
|
|
122
|
+
if (!(name in opened)) opened[name] = modules[name].open();
|
|
123
|
+
return opened[name];
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The reader of measurer results over the sources of a description. Every module is loaded first,
|
|
129
|
+
* so the measurement itself stays synchronous.
|
|
130
|
+
*/
|
|
131
|
+
export async function openReaders(model, base, given = {}) {
|
|
132
|
+
const source = await openSources(model, base, given);
|
|
133
|
+
const modules = {};
|
|
134
|
+
for (const m of model.measures) modules[m.entry] = await import(pathToFileURL(join(base, m.file)).href);
|
|
135
|
+
const data = { words: model.words, expect: model.expect, rules: { isWriteCommand } };
|
|
136
|
+
const caps = new Map(model.measures.map((m) => [m.entry, m.caps]));
|
|
137
|
+
return (name) => {
|
|
138
|
+
const [, entry, cap] = name.split('.');
|
|
139
|
+
const ports = Object.fromEntries(Object.entries(caps.get(entry)[cap]).map(([port, ref]) => [port, source(ref.path[1])]));
|
|
140
|
+
return modules[entry][cap](ports)(data);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const MARK = { true: 'met', false: 'unmet', unknown: 'unknown' };
|
|
145
|
+
|
|
146
|
+
/** The lines of `measure`: the measured state, what it waits for and the exits read. */
|
|
147
|
+
export function measureLines(model, result) {
|
|
148
|
+
const total = model.states.length;
|
|
149
|
+
const lines = [];
|
|
150
|
+
if (result.state === null) lines.push(`state: the end of the scenario (${total} of ${total} met)`);
|
|
151
|
+
else {
|
|
152
|
+
const state = model.states[result.index - 1];
|
|
153
|
+
lines.push(`state: ${result.state} (${result.index} of ${total})`);
|
|
154
|
+
lines.push(`next: ${state.action ?? ''} (${state.pattern ?? ''})`);
|
|
155
|
+
if (result.reason) lines.push(`reason: ${result.reason}`);
|
|
156
|
+
}
|
|
157
|
+
for (const [i, s] of model.states.entries()) {
|
|
158
|
+
if (!(s.key in result.exits)) break;
|
|
159
|
+
lines.push(` ${i + 1}. ${s.title}: ${MARK[String(result.exits[s.key])]}`);
|
|
160
|
+
}
|
|
161
|
+
return lines;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The JSON of `measure --json`: the measured state with its action and pattern. */
|
|
165
|
+
export function measureJson(model, result) {
|
|
166
|
+
const state = result.state === null ? null : model.states[result.index - 1];
|
|
167
|
+
return { ...result, action: state?.action ?? null, pattern: state?.pattern ?? null };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const USAGE = 'usage: node task-flow-script.mjs states | measure [--json] | step <N.M>|--done [--pr] | plan-check <plan.md> | plan-red | guard | verdict | forecast --days N [--until <date>] [--per-mille] [--guard] [--flow <flow.js>]';
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* What the guard guards: where the task folders and the epic plans lie, the tree override, and the
|
|
174
|
+
* description with its engine — in the package and laid out.
|
|
175
|
+
*/
|
|
176
|
+
export const GUARD_SETTINGS = {
|
|
177
|
+
tasksDir: process.env.RT_FLOW_TASKS_DIR || 'docs/tasks',
|
|
178
|
+
plansDir: process.env.RT_FLOW_PLANS_DIR || 'docs/plans',
|
|
179
|
+
overridePath: '.claude/rt-kit/overrides/task-flow/flow.js',
|
|
180
|
+
protectedPaths: [
|
|
181
|
+
'^projects/agent-kit/assets/task-flow/',
|
|
182
|
+
'^tools/task-flow/',
|
|
183
|
+
'(?:^|/)task-flow-script\\.mjs$',
|
|
184
|
+
'^projects/agent-kit/assets/checks/flow-[\\w-]+\\.mjs$',
|
|
185
|
+
'^tools/flow-[\\w-]+\\.mjs$',
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** The verdict of the guard on the hook input from stdin: the reason of a refusal, or null. */
|
|
190
|
+
async function runGuard(model, base) {
|
|
191
|
+
const input = JSON.parse(readFileSync(0, 'utf8') || '{}');
|
|
192
|
+
const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout?.trim();
|
|
193
|
+
if (!root) return null;
|
|
194
|
+
const call = callOf(input, root);
|
|
195
|
+
if (!call) return null;
|
|
196
|
+
if (input.transcript_path) process.env.RT_FLOW_TRANSCRIPT = input.transcript_path;
|
|
197
|
+
const source = await openSources(model, base);
|
|
198
|
+
const readers = await openReaders(model, base);
|
|
199
|
+
const measure = () => measureStates(model, readers).index;
|
|
200
|
+
const ctx = guardContext({ root, model, marks: source('marks'), owner: source('owner'), measure, settings: GUARD_SETTINGS });
|
|
201
|
+
return judgeCall(call, ctx);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The verdict at the end of a turn on the Stop input from stdin: `{ release: <log> }` or
|
|
206
|
+
* `{ block: <reason> }` as one JSON line.
|
|
207
|
+
*/
|
|
208
|
+
async function runVerdict(model, base) {
|
|
209
|
+
const input = JSON.parse(readFileSync(0, 'utf8') || '{}');
|
|
210
|
+
if (input.transcript_path) process.env.RT_FLOW_TRANSCRIPT = input.transcript_path;
|
|
211
|
+
if (input.agent_type) process.env.RT_FLOW_AGENT = input.agent_type;
|
|
212
|
+
const read = await openReaders(model, base);
|
|
213
|
+
const cache = new Map();
|
|
214
|
+
const measured = (name) => {
|
|
215
|
+
if (!cache.has(name)) cache.set(name, read(name));
|
|
216
|
+
return cache.get(name);
|
|
217
|
+
};
|
|
218
|
+
const result = measureStates(model, measured);
|
|
219
|
+
const decided = decide(model, measured, result);
|
|
220
|
+
if (decided) return decided;
|
|
221
|
+
const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout?.trim();
|
|
222
|
+
const branch = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf8' }).stdout?.trim();
|
|
223
|
+
const progress = join(root ?? '.', GUARD_SETTINGS.tasksDir, branch ?? '', 'progress.md');
|
|
224
|
+
const folder = `${GUARD_SETTINGS.tasksDir}/${branch}`;
|
|
225
|
+
// A folder a live step run put back is not the folder of the branch: its progress is an older one.
|
|
226
|
+
const text = existsSync(progress) && !history.liveRun(folder) ? readFileSync(progress, 'utf8') : null;
|
|
227
|
+
let step = currentStep(text);
|
|
228
|
+
// No current step: the first one of the plan not done or without a matched mark, from the history
|
|
229
|
+
// when the folder is taken apart.
|
|
230
|
+
if (!step && branch && model.states[result.index - 1]?.key === 'stage') {
|
|
231
|
+
const source = await openSources(model, base);
|
|
232
|
+
step = stageStep(source('git'), source('marks'), folder, branch, text);
|
|
233
|
+
}
|
|
234
|
+
const task = branch?.match(/^[A-Z]+-(\d+)-/)?.[1] ?? null;
|
|
235
|
+
return { block: holdReason(model, result, step, { cause: menuCause(measured), task }) };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Cleans the folder a broken step run put back, at a start of the engine, by `cleanBroken` of the
|
|
240
|
+
* history source: `{ verdict, folder }` or null. A folder kept because it was edited after the run is
|
|
241
|
+
* named on stderr, so nobody reads its older progress for the branch's own.
|
|
242
|
+
*/
|
|
243
|
+
export function cleanBrokenRun() {
|
|
244
|
+
const broken = history.cleanBroken();
|
|
245
|
+
if (broken?.verdict === 'kept' && broken.folder) {
|
|
246
|
+
console.error(`task-flow-script: ${broken.folder} is left by a broken step run and was edited after it — not removed; take it away by hand once read`);
|
|
247
|
+
}
|
|
248
|
+
return broken;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const COMMANDS = ['states', 'measure', 'step', 'plan-check', 'plan-red', 'guard', 'verdict', 'forecast'];
|
|
252
|
+
/** The commands the hooks call: they judge by the package description when the override breaks. */
|
|
253
|
+
const HOOK_COMMANDS = ['guard', 'verdict'];
|
|
254
|
+
|
|
255
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
256
|
+
const args = process.argv.slice(2);
|
|
257
|
+
const at = args.indexOf('--flow');
|
|
258
|
+
const given = at >= 0 ? args.splice(at, 2)[1] : undefined;
|
|
259
|
+
const atOverride = args.indexOf('--override');
|
|
260
|
+
const overrideGiven = atOverride >= 0 ? args.splice(atOverride, 2)[1] : undefined;
|
|
261
|
+
const json = args.includes('--json');
|
|
262
|
+
const [command, target] = args.filter((a) => a !== '--json');
|
|
263
|
+
if (!COMMANDS.includes(command) || ((command === 'step' || command === 'plan-check') && !target)) {
|
|
264
|
+
console.error(USAGE);
|
|
265
|
+
process.exit(2);
|
|
266
|
+
}
|
|
267
|
+
// A folder a broken step run put back is cleaned before any command; a live run keeps it.
|
|
268
|
+
cleanBrokenRun();
|
|
269
|
+
try {
|
|
270
|
+
const path = flowPath(given);
|
|
271
|
+
const override = overridePath(overrideGiven, given);
|
|
272
|
+
let model;
|
|
273
|
+
try {
|
|
274
|
+
model = buildModel(path, { override });
|
|
275
|
+
} catch (error) {
|
|
276
|
+
// A broken override does not lift the hooks: the guard protects the override itself, and
|
|
277
|
+
// the exit check must not release a turn because a tree file does not build.
|
|
278
|
+
if (!override || !HOOK_COMMANDS.includes(command)) throw error;
|
|
279
|
+
console.error(`task-flow-script: the override does not build, the hook judges by the package description — ${error.message}`);
|
|
280
|
+
model = buildModel(path);
|
|
281
|
+
}
|
|
282
|
+
if (command === 'states') console.log(stateLines(model).join('\n'));
|
|
283
|
+
else if (command === 'step') {
|
|
284
|
+
const source = await openSources(model, dirname(path));
|
|
285
|
+
const sources = { git: source('git'), steps: source('steps'), marks: source('marks'), owner: source('owner') };
|
|
286
|
+
process.exit(await runStepCommand(sources, model, target, process.argv.includes('--pr') ? '--pr' : ''));
|
|
287
|
+
} else if (command === 'plan-check') {
|
|
288
|
+
const source = await openSources(model, dirname(path));
|
|
289
|
+
const problems = planProblems(readFileSync(target, 'utf8'), source('steps'), model);
|
|
290
|
+
for (const problem of problems) console.log(`plan-check: ${problem}`);
|
|
291
|
+
process.exit(problems.length > 0 ? 1 : 0);
|
|
292
|
+
} else if (command === 'verdict') {
|
|
293
|
+
console.log(JSON.stringify(await runVerdict(model, dirname(path))));
|
|
294
|
+
} else if (command === 'guard') {
|
|
295
|
+
console.log((await runGuard(model, dirname(path))) ?? '');
|
|
296
|
+
} else if (command === 'forecast') {
|
|
297
|
+
const tree = dirname(spawnSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { encoding: 'utf8' }).stdout.trim());
|
|
298
|
+
const root = process.env.RT_FLOW_RECORDS || join(homedir(), '.claude', 'projects');
|
|
299
|
+
const argv = process.argv.slice(3).filter((arg, index, all) => arg !== '--flow' && all[index - 1] !== '--flow');
|
|
300
|
+
console.log(await runForecast({ argv, model, base: dirname(path), openReaders, tree, root, settings: GUARD_SETTINGS }));
|
|
301
|
+
} else if (command === 'plan-red') {
|
|
302
|
+
const source = await openSources(model, dirname(path));
|
|
303
|
+
const sources = { git: source('git'), steps: source('steps'), marks: source('marks') };
|
|
304
|
+
process.exit(runPlanRed(sources, model, readRecord(process.env.RT_FLOW_TRANSCRIPT)));
|
|
305
|
+
} else {
|
|
306
|
+
const result = measureStates(model, await openReaders(model, dirname(path)));
|
|
307
|
+
console.log(json ? JSON.stringify(measureJson(model, result)) : [...measureLines(model, result), ...removedLines(model), ...retiredLines(model)].join('\n'));
|
|
308
|
+
}
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (error instanceof FlowSyntaxError) {
|
|
311
|
+
console.log(`flow syntax: ${error.message}`);
|
|
312
|
+
process.exit(1);
|
|
313
|
+
}
|
|
314
|
+
if (!(error instanceof FlowModelError)) throw error;
|
|
315
|
+
console.log(`flow model: ${error.message}`);
|
|
316
|
+
process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -99,32 +99,40 @@ const OWNER_WORD =
|
|
|
99
99
|
* A tree that declares no assignments is not judged: it has nothing to divide.
|
|
100
100
|
*/
|
|
101
101
|
export function assignmentFault(epic, root = ROOT) {
|
|
102
|
+
return assignmentUnmet(epic, root).text;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The same answer with its kind, as the decision table names the fact `copy_assignment`: `ok`,
|
|
107
|
+
* `unnamed`, `no_row`, `dash` or `foreign`.
|
|
108
|
+
*/
|
|
109
|
+
export function assignmentUnmet(epic, root = ROOT) {
|
|
102
110
|
if (!CONFIG.assignmentsFile) {
|
|
103
|
-
return '';
|
|
111
|
+
return { kind: 'ok', text: '' };
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
const key = CONFIG.board?.taskKey ?? '';
|
|
107
115
|
const name = treeName(root);
|
|
108
116
|
|
|
109
117
|
if (name === null) {
|
|
110
|
-
return `this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}, and the assignment table will find its row
|
|
118
|
+
return { kind: 'unnamed', text: `this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}, and the assignment table will find its row` };
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
const row = assignmentOf(root);
|
|
114
122
|
|
|
115
123
|
if (row === null) {
|
|
116
|
-
return `the table ${CONFIG.assignmentsFile} holds no row for the copy «${name}». Ask the owner what this copy leads; work is not taken by guesswork. ${OWNER_WORD}
|
|
124
|
+
return { kind: 'no_row', text: `the table ${CONFIG.assignmentsFile} holds no row for the copy «${name}». Ask the owner what this copy leads; work is not taken by guesswork. ${OWNER_WORD}` };
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
if (row.epic === null) {
|
|
120
|
-
return `no epic is assigned to the copy «${name}» — the row in ${CONFIG.assignmentsFile} holds a dash. Ask the owner what to take; an epic chosen by oneself is not an order. ${OWNER_WORD}
|
|
128
|
+
return { kind: 'dash', text: `no epic is assigned to the copy «${name}» — the row in ${CONFIG.assignmentsFile} holds a dash. Ask the owner what to take; an epic chosen by oneself is not an order. ${OWNER_WORD}` };
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
if (epic !== null && epic !== undefined && String(epic) !== '' && Number(epic) !== row.epic) {
|
|
124
|
-
return `the copy «${name}» leads the epic ${key}-${row.epic}, and this work belongs to ${key}-${epic}. Someone else's epic is not taken by one's own decision: the owner moves the assignment. ${OWNER_WORD}
|
|
132
|
+
return { kind: 'foreign', text: `the copy «${name}» leads the epic ${key}-${row.epic}, and this work belongs to ${key}-${epic}. Someone else's epic is not taken by one's own decision: the owner moves the assignment. ${OWNER_WORD}` };
|
|
125
133
|
}
|
|
126
134
|
|
|
127
|
-
return '';
|
|
135
|
+
return { kind: 'ok', text: '' };
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
/**
|
|
@@ -141,7 +149,18 @@ if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).
|
|
|
141
149
|
// given, the queue says whether it is still alive.
|
|
142
150
|
const row = assignmentOf();
|
|
143
151
|
|
|
144
|
-
console.log
|
|
152
|
+
// Printed as a string: `console.log` colours a number when FORCE_COLOR is set — the task
|
|
153
|
+
// runner sets it — and the caller then reads escape codes in place of the number.
|
|
154
|
+
console.log(String(row?.epic ?? ''));
|
|
155
|
+
process.exit(0);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const unmet = process.argv.indexOf('--unmet');
|
|
159
|
+
|
|
160
|
+
if (unmet !== -1) {
|
|
161
|
+
// The kind and the text as one line of JSON, for a guard that hands the kind to the decision
|
|
162
|
+
// table as a fact and the text to the refusal.
|
|
163
|
+
console.log(JSON.stringify(assignmentUnmet(process.argv[unmet + 1] ?? '')));
|
|
145
164
|
process.exit(0);
|
|
146
165
|
}
|
|
147
166
|
|