@rt-tools/agent-kit 0.37.1 → 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.
Files changed (357) hide show
  1. package/README.md +5 -5
  2. package/assets/checks/action-of.mjs +154 -0
  3. package/assets/checks/board-runs.github.mjs +40 -5
  4. package/assets/checks/check-board.github.mjs +38 -7
  5. package/assets/checks/check-state-next.mjs +22 -10
  6. package/assets/checks/check-turn-map.mjs +26 -6
  7. package/assets/checks/check-work-steps.mjs +4 -173
  8. package/assets/checks/decide.mjs +285 -0
  9. package/assets/checks/decision-table.json +21365 -0
  10. package/assets/checks/decision-table.mjs +495 -0
  11. package/assets/checks/epic-window.mjs +98 -0
  12. package/assets/checks/flow-condition.mjs +64 -0
  13. package/assets/checks/flow-data.mjs +136 -0
  14. package/assets/checks/flow-forecast.mjs +330 -0
  15. package/assets/checks/flow-guard-run.mjs +90 -0
  16. package/assets/checks/flow-guard.mjs +294 -0
  17. package/assets/checks/flow-model.mjs +271 -0
  18. package/assets/checks/flow-override.mjs +130 -0
  19. package/assets/checks/flow-plan.mjs +206 -0
  20. package/assets/checks/flow-scaffold.mjs +224 -0
  21. package/assets/checks/flow-step.mjs +365 -0
  22. package/assets/checks/flow-sync.mjs +296 -0
  23. package/assets/checks/flow-syntax.mjs +292 -0
  24. package/assets/checks/flow-verdict.mjs +112 -0
  25. package/assets/checks/merge-read.mjs +239 -0
  26. package/assets/checks/owner-nudges.mjs +389 -0
  27. package/assets/checks/push-inputs.mjs +59 -16
  28. package/assets/checks/record-count.mjs +410 -0
  29. package/assets/checks/record-recount.mjs +187 -0
  30. package/assets/checks/record-turn.mjs +155 -0
  31. package/assets/checks/task-flow-script.mjs +292 -0
  32. package/assets/checks/tree-assignment.mjs +26 -7
  33. package/assets/checks/work-result.mjs +281 -0
  34. package/assets/checks/work-steps-lib.mjs +205 -0
  35. package/assets/commands/night.md +6 -6
  36. package/assets/defaults/gate-map.sh +39 -12
  37. package/assets/defaults/merges.sh +48 -0
  38. package/assets/defaults/project.sh +6 -5
  39. package/assets/defaults/turn-map.md +21 -22
  40. package/assets/docs/GLOSSARY.md +5 -1
  41. package/assets/hooks/ask-judge.md +65 -0
  42. package/assets/hooks/browser-guard-device-id.sh +11 -9
  43. package/assets/hooks/browser-guard-no-asking.sh +12 -6
  44. package/assets/hooks/browser-guard-no-listing.sh +13 -7
  45. package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
  46. package/assets/hooks/browser-guard-require-select.sh +15 -15
  47. package/assets/hooks/commit-msg.sh +13 -3
  48. package/assets/hooks/conscience-guard.sh +9 -25
  49. package/assets/hooks/decide.sh +141 -0
  50. package/assets/hooks/deny-tail.sh +16 -11
  51. package/assets/hooks/dev-server-guard.sh +27 -20
  52. package/assets/hooks/dispatch.sh +47 -4
  53. package/assets/hooks/docs-guard.sh +31 -200
  54. package/assets/hooks/end-conversation-guard.sh +12 -21
  55. package/assets/hooks/epic-stop-guard.sh +54 -152
  56. package/assets/hooks/exam-guard.sh +32 -65
  57. package/assets/hooks/facts-docs.sh +221 -0
  58. package/assets/hooks/facts-flow.sh +173 -0
  59. package/assets/hooks/facts.sh +308 -0
  60. package/assets/hooks/flow-step-guard.sh +93 -0
  61. package/assets/hooks/git-guard-delivery-body.sh +4 -4
  62. package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
  63. package/assets/hooks/git-guard-delivery-draft.sh +3 -3
  64. package/assets/hooks/git-guard-delivery-epic.sh +18 -9
  65. package/assets/hooks/git-guard-delivery-folder.sh +32 -7
  66. package/assets/hooks/git-guard-delivery-merge.sh +2 -2
  67. package/assets/hooks/git-guard-delivery-merged.sh +12 -1
  68. package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
  69. package/assets/hooks/git-guard-delivery-rerun.sh +32 -0
  70. package/assets/hooks/git-guard-delivery-signature.sh +82 -45
  71. package/assets/hooks/git-guard-delivery-task.sh +47 -0
  72. package/assets/hooks/git-guard-delivery.sh +112 -101
  73. package/assets/hooks/git-guard-discard.sh +8 -18
  74. package/assets/hooks/git-guard-main.sh +13 -19
  75. package/assets/hooks/git-guard-no-verify.sh +56 -16
  76. package/assets/hooks/git-guard-push-ahead.sh +15 -4
  77. package/assets/hooks/git-guard-push-marks.sh +53 -1
  78. package/assets/hooks/git-guard-push-tests.sh +30 -51
  79. package/assets/hooks/git-guard-tree-assignment.sh +7 -4
  80. package/assets/hooks/guard-note.sh +8 -6
  81. package/assets/hooks/handoff-entry-guard.sh +19 -38
  82. package/assets/hooks/handoff-write.sh +3 -1
  83. package/assets/hooks/hook-input.sh +0 -41
  84. package/assets/hooks/metric-marks.sh +19 -7
  85. package/assets/hooks/observe.sh +1 -1
  86. package/assets/hooks/override-write-guard.sh +27 -9
  87. package/assets/hooks/pre-push.sh +14 -10
  88. package/assets/hooks/prose-style-guard.sh +6 -19
  89. package/assets/hooks/pull-merges.sh +76 -0
  90. package/assets/hooks/push-set.sh +11 -4
  91. package/assets/hooks/qa-dataid-guard.sh +7 -17
  92. package/assets/hooks/record-turn.sh +52 -0
  93. package/assets/hooks/rerun-guard.sh +11 -16
  94. package/assets/hooks/reuse-first-guard.sh +7 -21
  95. package/assets/hooks/role-calls.sh +25 -3
  96. package/assets/hooks/rule-source-guard.sh +54 -21
  97. package/assets/hooks/skill-gate-rearm.sh +18 -5
  98. package/assets/hooks/skill-gate.sh +156 -20
  99. package/assets/hooks/skill-loaded.sh +18 -3
  100. package/assets/hooks/sql-guard-target.sh +2 -2
  101. package/assets/hooks/sql-guard-write.sh +12 -12
  102. package/assets/hooks/sql-guard.sh +58 -16
  103. package/assets/hooks/task-context-load.sh +3 -1
  104. package/assets/hooks/task-flow-context.sh +5 -18
  105. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  106. package/assets/hooks/task-flow-guard.sh +28 -130
  107. package/assets/hooks/tree-assignment-guard.sh +25 -14
  108. package/assets/hooks/turn-entry-load.sh +3 -1
  109. package/assets/hooks/turn-exit-guard.sh +92 -452
  110. package/assets/hooks/turn-exit-role.sh +3 -1
  111. package/assets/hooks/turn-judge.md +103 -0
  112. package/assets/hooks/window-fill-guard.sh +22 -41
  113. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  114. package/assets/patterns/git-workflow-commit.github.md +11 -269
  115. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  116. package/assets/patterns/git-workflow-docker.md +8 -231
  117. package/assets/patterns/git-workflow-freshness.md +8 -56
  118. package/assets/patterns/git-workflow-merge.md +6 -176
  119. package/assets/patterns/git-workflow-migration.md +5 -75
  120. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  121. package/assets/patterns/git-workflow-pr-ready.md +9 -70
  122. package/assets/patterns/git-workflow-pr.azure.md +13 -285
  123. package/assets/patterns/git-workflow-pr.github.md +13 -251
  124. package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
  125. package/assets/patterns/git-workflow-restart.md +5 -42
  126. package/assets/patterns/git-workflow-secrets.md +10 -76
  127. package/assets/patterns/git-workflow-stack.md +7 -207
  128. package/assets/patterns/status-report-table.github.md +1 -1
  129. package/assets/patterns/task-flow-archive.md +12 -233
  130. package/assets/patterns/task-flow-close.md +16 -292
  131. package/assets/patterns/task-flow-cycle.md +13 -39
  132. package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
  133. package/assets/patterns/task-flow-handoff.md +13 -161
  134. package/assets/patterns/task-flow-resume.md +18 -218
  135. package/assets/patterns/task-flow-start.md +9 -247
  136. package/assets/patterns/turn-entry-map.md +2 -2
  137. package/assets/pitfalls/agent-kit-extend.md +200 -0
  138. package/assets/pitfalls/agent-kit.2.md +323 -0
  139. package/assets/pitfalls/angular-patterns.md +98 -0
  140. package/assets/pitfalls/browser-verification.md +265 -0
  141. package/assets/pitfalls/component-structure.md +98 -0
  142. package/assets/pitfalls/dependencies.md +92 -0
  143. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  144. package/assets/pitfalls/deploy-flow.github.md +211 -0
  145. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  146. package/assets/pitfalls/doc-style.2.md +286 -0
  147. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  148. package/assets/pitfalls/entity-models.md +89 -0
  149. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  150. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  151. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  152. package/assets/pitfalls/git-workflow-docker.md +275 -0
  153. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  154. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  155. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  156. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  157. package/assets/pitfalls/git-workflow-merge.md +220 -0
  158. package/assets/pitfalls/git-workflow-migration.md +103 -0
  159. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  160. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  161. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  162. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  163. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  164. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  165. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  166. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  167. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  168. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  169. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  170. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  171. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  172. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  173. package/assets/pitfalls/git-workflow-restart.md +72 -0
  174. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  175. package/assets/pitfalls/git-workflow-stack.md +254 -0
  176. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  177. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  178. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  179. package/assets/pitfalls/lib-layers.md +114 -0
  180. package/assets/pitfalls/lists.md +117 -0
  181. package/assets/pitfalls/navigation.md +94 -0
  182. package/assets/pitfalls/reuse-first.md +201 -0
  183. package/assets/pitfalls/spec-driven.2.md +318 -0
  184. package/assets/pitfalls/styling-bem.2.md +125 -0
  185. package/assets/pitfalls/task-flow-archive.md +264 -0
  186. package/assets/pitfalls/task-flow-close.2.md +165 -0
  187. package/assets/pitfalls/task-flow-close.md +167 -0
  188. package/assets/pitfalls/task-flow-cycle.md +73 -0
  189. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  190. package/assets/pitfalls/task-flow-handoff.md +200 -0
  191. package/assets/pitfalls/task-flow-handover.md +30 -0
  192. package/assets/pitfalls/task-flow-owner.md +29 -0
  193. package/assets/pitfalls/task-flow-plan.md +29 -0
  194. package/assets/pitfalls/task-flow-resume.md +257 -0
  195. package/assets/pitfalls/task-flow-start.md +287 -0
  196. package/assets/pitfalls/task-flow.2.md +303 -0
  197. package/assets/pitfalls/task-flow.md +4 -4
  198. package/assets/pitfalls/testing.2.md +279 -0
  199. package/assets/pitfalls/turn-conduct.md +16 -17
  200. package/assets/pitfalls/typescript-conventions.md +161 -0
  201. package/assets/pitfalls/write-a-skill.md +128 -0
  202. package/assets/rules/angular-patterns.md +21 -86
  203. package/assets/rules/autonomous-work.md +2 -2
  204. package/assets/rules/browser-verification.md +28 -256
  205. package/assets/rules/component-structure.md +25 -87
  206. package/assets/rules/dependencies.md +20 -78
  207. package/assets/rules/deploy-flow.azure.md +26 -156
  208. package/assets/rules/deploy-flow.github.md +34 -200
  209. package/assets/rules/deploy-flow.gitlab.md +27 -159
  210. package/assets/rules/doc-style.md +32 -286
  211. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  212. package/assets/rules/entity-models.md +14 -63
  213. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  214. package/assets/rules/git-workflow-hosting.github.md +38 -0
  215. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  216. package/assets/rules/git-workflow-push.azure.md +28 -0
  217. package/assets/rules/git-workflow-push.github.md +28 -0
  218. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  219. package/assets/rules/git-workflow-queue.azure.md +23 -0
  220. package/assets/rules/git-workflow-queue.github.md +30 -0
  221. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  222. package/assets/rules/git-workflow.azure.md +21 -282
  223. package/assets/rules/git-workflow.github.md +24 -284
  224. package/assets/rules/git-workflow.gitlab.md +21 -269
  225. package/assets/rules/lib-layers.md +30 -103
  226. package/assets/rules/lists.md +21 -105
  227. package/assets/rules/navigation.md +10 -69
  228. package/assets/rules/reuse-first.md +20 -195
  229. package/assets/rules/spec-driven.md +35 -308
  230. package/assets/rules/styling-bem.md +20 -117
  231. package/assets/rules/task-flow-handover.md +24 -0
  232. package/assets/rules/task-flow-owner.md +34 -0
  233. package/assets/rules/task-flow-plan.md +38 -0
  234. package/assets/rules/task-flow.md +22 -300
  235. package/assets/rules/testing.md +32 -273
  236. package/assets/rules/turn-conduct.md +100 -104
  237. package/assets/rules/turn-entry.md +2 -2
  238. package/assets/rules/typescript-conventions.md +41 -147
  239. package/assets/samples/tasks/_template/plan.md +30 -6
  240. package/assets/samples/tasks/_template/progress.md +0 -1
  241. package/assets/skills/agent-kit-extend.md +25 -168
  242. package/assets/skills/agent-kit.md +27 -299
  243. package/assets/skills/write-a-skill.md +20 -106
  244. package/assets/task-flow/flow.js +188 -0
  245. package/assets/task-flow/flow.md +102 -0
  246. package/assets/task-flow/measure/agreement.mjs +24 -0
  247. package/assets/task-flow/measure/copy.mjs +22 -0
  248. package/assets/task-flow/measure/epic-of.mjs +50 -0
  249. package/assets/task-flow/measure/epic-text.mjs +35 -0
  250. package/assets/task-flow/measure/epic.mjs +114 -0
  251. package/assets/task-flow/measure/folder.mjs +16 -0
  252. package/assets/task-flow/measure/footprint.mjs +28 -0
  253. package/assets/task-flow/measure/grill.mjs +21 -0
  254. package/assets/task-flow/measure/host.mjs +8 -0
  255. package/assets/task-flow/measure/owner.mjs +20 -0
  256. package/assets/task-flow/measure/plan.mjs +27 -0
  257. package/assets/task-flow/measure/pr.mjs +20 -0
  258. package/assets/task-flow/measure/progress.mjs +50 -0
  259. package/assets/task-flow/measure/session.mjs +175 -0
  260. package/assets/task-flow/measure/task.mjs +23 -0
  261. package/assets/task-flow/measure/text.mjs +77 -0
  262. package/assets/task-flow/source/git.mjs +86 -0
  263. package/assets/task-flow/source/host.mjs +172 -0
  264. package/assets/task-flow/source/marks.mjs +56 -0
  265. package/assets/task-flow/source/owner.mjs +74 -0
  266. package/assets/task-flow/source/records.mjs +116 -0
  267. package/assets/task-flow/source/session.mjs +232 -0
  268. package/assets/task-flow/source/steps.mjs +28 -0
  269. package/assets/task-flow/source/tree.mjs +42 -0
  270. package/bin/agent-kit.d.ts.map +1 -1
  271. package/bin/agent-kit.js +30 -0
  272. package/bin/agent-kit.js.map +1 -1
  273. package/lib/agent-checks.d.ts +55 -0
  274. package/lib/agent-checks.d.ts.map +1 -0
  275. package/lib/agent-checks.js +209 -0
  276. package/lib/agent-checks.js.map +1 -0
  277. package/lib/assets.d.ts.map +1 -1
  278. package/lib/assets.js +7 -2
  279. package/lib/assets.js.map +1 -1
  280. package/lib/cargo.d.ts +29 -0
  281. package/lib/cargo.d.ts.map +1 -1
  282. package/lib/cargo.js +27 -1
  283. package/lib/cargo.js.map +1 -1
  284. package/lib/cascade.d.ts.map +1 -1
  285. package/lib/cascade.js +3 -1
  286. package/lib/cascade.js.map +1 -1
  287. package/lib/commands.d.ts.map +1 -1
  288. package/lib/commands.js +78 -2
  289. package/lib/commands.js.map +1 -1
  290. package/lib/config.d.ts +18 -0
  291. package/lib/config.d.ts.map +1 -1
  292. package/lib/config.js +18 -1
  293. package/lib/config.js.map +1 -1
  294. package/lib/epic-window-send.d.ts +74 -0
  295. package/lib/epic-window-send.d.ts.map +1 -0
  296. package/lib/epic-window-send.js +166 -0
  297. package/lib/epic-window-send.js.map +1 -0
  298. package/lib/hooks-map.d.ts +4 -0
  299. package/lib/hooks-map.d.ts.map +1 -1
  300. package/lib/hooks-map.js +2 -2
  301. package/lib/hooks-map.js.map +1 -1
  302. package/lib/integrity.d.ts +3 -0
  303. package/lib/integrity.d.ts.map +1 -1
  304. package/lib/integrity.js +7 -0
  305. package/lib/integrity.js.map +1 -1
  306. package/lib/metric-lines.d.ts +2 -1
  307. package/lib/metric-lines.d.ts.map +1 -1
  308. package/lib/metric-lines.js +49 -1
  309. package/lib/metric-lines.js.map +1 -1
  310. package/lib/metric-send-mark.d.ts +6 -3
  311. package/lib/metric-send-mark.d.ts.map +1 -1
  312. package/lib/metric-send-mark.js +15 -5
  313. package/lib/metric-send-mark.js.map +1 -1
  314. package/lib/metric-send.d.ts +6 -2
  315. package/lib/metric-send.d.ts.map +1 -1
  316. package/lib/metric-send.js +47 -13
  317. package/lib/metric-send.js.map +1 -1
  318. package/lib/metrics.d.ts +17 -0
  319. package/lib/metrics.d.ts.map +1 -1
  320. package/lib/metrics.js +26 -15
  321. package/lib/metrics.js.map +1 -1
  322. package/lib/observations.js +3 -3
  323. package/lib/observations.js.map +1 -1
  324. package/lib/outcomes.d.ts +5 -2
  325. package/lib/outcomes.d.ts.map +1 -1
  326. package/lib/outcomes.js +5 -4
  327. package/lib/outcomes.js.map +1 -1
  328. package/lib/push-gate.d.ts +13 -0
  329. package/lib/push-gate.d.ts.map +1 -1
  330. package/lib/push-gate.js +11 -7
  331. package/lib/push-gate.js.map +1 -1
  332. package/lib/push-set-usefulness.d.ts +78 -0
  333. package/lib/push-set-usefulness.d.ts.map +1 -0
  334. package/lib/push-set-usefulness.js +225 -0
  335. package/lib/push-set-usefulness.js.map +1 -0
  336. package/lib/sync.d.ts +10 -0
  337. package/lib/sync.d.ts.map +1 -1
  338. package/lib/sync.js +14 -1
  339. package/lib/sync.js.map +1 -1
  340. package/lib/work-result.d.ts +43 -0
  341. package/lib/work-result.d.ts.map +1 -0
  342. package/lib/work-result.js +39 -0
  343. package/lib/work-result.js.map +1 -0
  344. package/package.json +1 -1
  345. package/assets/hooks/claim-guard.sh +0 -212
  346. package/assets/hooks/grill-gate-ask.sh +0 -26
  347. package/assets/hooks/grill-gate-bypass.sh +0 -61
  348. package/assets/hooks/grill-gate-options.sh +0 -50
  349. package/assets/hooks/grill-gate.sh +0 -482
  350. package/assets/hooks/postmortem-guard.sh +0 -124
  351. package/assets/hooks/proposal-guard.sh +0 -154
  352. package/assets/hooks/stand-login-guard.sh +0 -107
  353. package/assets/hooks/turn-exit-epic.sh +0 -173
  354. package/assets/hooks/turn-exit-patterns.sh +0 -123
  355. package/assets/hooks/turn-exit-verdict.sh +0 -149
  356. package/assets/hooks/waiting-turn-guard.sh +0 -320
  357. 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,292 @@
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, saysStop } 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, holdReason, menuCause, releaseCase } from './flow-verdict.mjs';
53
+
54
+ const HERE = dirname(fileURLToPath(import.meta.url));
55
+
56
+ /** Where the description lies: next to the laid-out engine, or in the package. */
57
+ export function flowPath(given) {
58
+ if (given) return given;
59
+ const laid = join(HERE, 'task-flow', 'flow.js');
60
+ return existsSync(laid) ? laid : join(HERE, '..', 'task-flow', 'flow.js');
61
+ }
62
+
63
+ /** The lines of `states`. */
64
+ export function stateLines(model) {
65
+ return model.states.map((s, i) => `${i + 1}. ${s.title} — ${s.action ?? ''} (${s.pattern ?? ''})`);
66
+ }
67
+
68
+ /** A read the hosting did not answer twice: the error a source throws carries this name. */
69
+ const SILENT = 'HostSilent';
70
+
71
+ /**
72
+ * The measured state: the first state whose exit is known to be unmet. An exit the hosting could not
73
+ * answer is unknown and is passed over, and the exits after it are measured. With no unmet exit and
74
+ * an unknown one, the measured state is the first unknown, and the reason is the silent hosting.
75
+ * With every exit met, the scenario is over.
76
+ *
77
+ * `read(name)` answers a measurer result by its reference and may throw `HostSilent`; a result is
78
+ * read once per measurement. Returns `{ state, index, reason, exits }`, `exits` mapping a state key
79
+ * to `true`, `false` or `'unknown'`.
80
+ */
81
+ export function measureStates(model, read) {
82
+ const cache = new Map();
83
+ const measured = (name) => {
84
+ if (!cache.has(name)) cache.set(name, read(name));
85
+ return cache.get(name);
86
+ };
87
+ const exits = {};
88
+ let firstUnknown = null;
89
+ for (const [index, state] of model.states.entries()) {
90
+ let met;
91
+ try {
92
+ met = evaluateCondition(state.exit, measured);
93
+ } catch (error) {
94
+ if (error?.name !== SILENT) throw error;
95
+ exits[state.key] = 'unknown';
96
+ firstUnknown ??= index;
97
+ continue;
98
+ }
99
+ exits[state.key] = met;
100
+ if (!met) return { state: state.title, index: index + 1, reason: null, exits };
101
+ }
102
+ if (firstUnknown !== null) {
103
+ return { state: model.states[firstUnknown].title, index: firstUnknown + 1, reason: 'the hosting did not answer twice', exits };
104
+ }
105
+ return { state: null, index: model.states.length + 1, reason: 'the end of the scenario', exits };
106
+ }
107
+
108
+ /**
109
+ * The sources of a description by name. Every module is loaded first; a source is opened when it is
110
+ * first asked for, so a source not written yet throws only where it is needed. `given` maps a source
111
+ * name to an opened source and replaces its module.
112
+ */
113
+ export async function openSources(model, base, given = {}) {
114
+ const modules = {};
115
+ for (const s of model.sources) {
116
+ if (!(s.entry in given)) modules[s.entry] = await import(pathToFileURL(join(base, s.file)).href);
117
+ }
118
+ const opened = { ...given };
119
+ return (name) => {
120
+ if (!(name in opened)) opened[name] = modules[name].open();
121
+ return opened[name];
122
+ };
123
+ }
124
+
125
+ /**
126
+ * The reader of measurer results over the sources of a description. Every module is loaded first,
127
+ * so the measurement itself stays synchronous.
128
+ */
129
+ export async function openReaders(model, base, given = {}) {
130
+ const source = await openSources(model, base, given);
131
+ const modules = {};
132
+ for (const m of model.measures) modules[m.entry] = await import(pathToFileURL(join(base, m.file)).href);
133
+ const data = { words: model.words, expect: model.expect, rules: { saysStop, isWriteCommand } };
134
+ const caps = new Map(model.measures.map((m) => [m.entry, m.caps]));
135
+ return (name) => {
136
+ const [, entry, cap] = name.split('.');
137
+ const ports = Object.fromEntries(Object.entries(caps.get(entry)[cap]).map(([port, ref]) => [port, source(ref.path[1])]));
138
+ return modules[entry][cap](ports)(data);
139
+ };
140
+ }
141
+
142
+ const MARK = { true: 'met', false: 'unmet', unknown: 'unknown' };
143
+
144
+ /** The lines of `measure`: the measured state, what it waits for and the exits read. */
145
+ export function measureLines(model, result) {
146
+ const total = model.states.length;
147
+ const lines = [];
148
+ if (result.state === null) lines.push(`state: the end of the scenario (${total} of ${total} met)`);
149
+ else {
150
+ const state = model.states[result.index - 1];
151
+ lines.push(`state: ${result.state} (${result.index} of ${total})`);
152
+ lines.push(`next: ${state.action ?? ''} (${state.pattern ?? ''})`);
153
+ if (result.reason) lines.push(`reason: ${result.reason}`);
154
+ }
155
+ for (const [i, s] of model.states.entries()) {
156
+ if (!(s.key in result.exits)) break;
157
+ lines.push(` ${i + 1}. ${s.title}: ${MARK[String(result.exits[s.key])]}`);
158
+ }
159
+ return lines;
160
+ }
161
+
162
+ /** The JSON of `measure --json`: the measured state with its action and pattern. */
163
+ export function measureJson(model, result) {
164
+ const state = result.state === null ? null : model.states[result.index - 1];
165
+ return { ...result, action: state?.action ?? null, pattern: state?.pattern ?? null };
166
+ }
167
+
168
+ 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>]';
169
+
170
+ /**
171
+ * What the guard guards: where the task folders and the epic plans lie, the tree override, and the
172
+ * description with its engine — in the package and laid out.
173
+ */
174
+ export const GUARD_SETTINGS = {
175
+ tasksDir: process.env.RT_FLOW_TASKS_DIR || 'docs/tasks',
176
+ plansDir: process.env.RT_FLOW_PLANS_DIR || 'docs/plans',
177
+ overridePath: '.claude/rt-kit/overrides/task-flow/flow.js',
178
+ protectedPaths: [
179
+ '^projects/agent-kit/assets/task-flow/',
180
+ '^tools/task-flow/',
181
+ '(?:^|/)task-flow-script\\.mjs$',
182
+ '^projects/agent-kit/assets/checks/flow-[\\w-]+\\.mjs$',
183
+ '^tools/flow-[\\w-]+\\.mjs$',
184
+ ],
185
+ };
186
+
187
+ /** The verdict of the guard on the hook input from stdin: the reason of a refusal, or null. */
188
+ async function runGuard(model, base) {
189
+ const input = JSON.parse(readFileSync(0, 'utf8') || '{}');
190
+ const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout?.trim();
191
+ if (!root) return null;
192
+ const call = callOf(input, root);
193
+ if (!call) return null;
194
+ if (input.transcript_path) process.env.RT_FLOW_TRANSCRIPT = input.transcript_path;
195
+ const source = await openSources(model, base);
196
+ const readers = await openReaders(model, base);
197
+ const measure = () => measureStates(model, readers).index;
198
+ const ctx = guardContext({ root, model, marks: source('marks'), owner: source('owner'), measure, settings: GUARD_SETTINGS });
199
+ return judgeCall(call, ctx);
200
+ }
201
+
202
+ /**
203
+ * The verdict at the end of a turn on the Stop input from stdin: `{ release: <log> }` or
204
+ * `{ block: <reason> }` as one JSON line.
205
+ */
206
+ async function runVerdict(model, base) {
207
+ const input = JSON.parse(readFileSync(0, 'utf8') || '{}');
208
+ if (input.transcript_path) process.env.RT_FLOW_TRANSCRIPT = input.transcript_path;
209
+ if (input.agent_type) process.env.RT_FLOW_AGENT = input.agent_type;
210
+ const read = await openReaders(model, base);
211
+ const cache = new Map();
212
+ const measured = (name) => {
213
+ if (!cache.has(name)) cache.set(name, read(name));
214
+ return cache.get(name);
215
+ };
216
+ const result = measureStates(model, measured);
217
+ const released = releaseCase(model, measured, result);
218
+ if (released) return { release: released.log ?? released.key };
219
+ const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout?.trim();
220
+ const branch = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf8' }).stdout?.trim();
221
+ const progress = join(root ?? '.', GUARD_SETTINGS.tasksDir, branch ?? '', 'progress.md');
222
+ const step = currentStep(existsSync(progress) ? readFileSync(progress, 'utf8') : null);
223
+ const task = branch?.match(/^[A-Z]+-(\d+)-/)?.[1] ?? null;
224
+ return { block: holdReason(model, result, step, { cause: menuCause(measured), task }) };
225
+ }
226
+
227
+ const COMMANDS = ['states', 'measure', 'step', 'plan-check', 'plan-red', 'guard', 'verdict', 'forecast'];
228
+ /** The commands the hooks call: they judge by the package description when the override breaks. */
229
+ const HOOK_COMMANDS = ['guard', 'verdict'];
230
+
231
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
232
+ const args = process.argv.slice(2);
233
+ const at = args.indexOf('--flow');
234
+ const given = at >= 0 ? args.splice(at, 2)[1] : undefined;
235
+ const atOverride = args.indexOf('--override');
236
+ const overrideGiven = atOverride >= 0 ? args.splice(atOverride, 2)[1] : undefined;
237
+ const json = args.includes('--json');
238
+ const [command, target] = args.filter((a) => a !== '--json');
239
+ if (!COMMANDS.includes(command) || ((command === 'step' || command === 'plan-check') && !target)) {
240
+ console.error(USAGE);
241
+ process.exit(2);
242
+ }
243
+ try {
244
+ const path = flowPath(given);
245
+ const override = overridePath(overrideGiven, given);
246
+ let model;
247
+ try {
248
+ model = buildModel(path, { override });
249
+ } catch (error) {
250
+ // A broken override does not lift the hooks: the guard protects the override itself, and
251
+ // the exit check must not release a turn because a tree file does not build.
252
+ if (!override || !HOOK_COMMANDS.includes(command)) throw error;
253
+ console.error(`task-flow-script: the override does not build, the hook judges by the package description — ${error.message}`);
254
+ model = buildModel(path);
255
+ }
256
+ if (command === 'states') console.log(stateLines(model).join('\n'));
257
+ else if (command === 'step') {
258
+ const source = await openSources(model, dirname(path));
259
+ const sources = { git: source('git'), steps: source('steps'), marks: source('marks'), owner: source('owner') };
260
+ process.exit(await runStepCommand(sources, model, target, process.argv.includes('--pr') ? '--pr' : ''));
261
+ } else if (command === 'plan-check') {
262
+ const source = await openSources(model, dirname(path));
263
+ const problems = planProblems(readFileSync(target, 'utf8'), source('steps'), model);
264
+ for (const problem of problems) console.log(`plan-check: ${problem}`);
265
+ process.exit(problems.length > 0 ? 1 : 0);
266
+ } else if (command === 'verdict') {
267
+ console.log(JSON.stringify(await runVerdict(model, dirname(path))));
268
+ } else if (command === 'guard') {
269
+ console.log((await runGuard(model, dirname(path))) ?? '');
270
+ } else if (command === 'forecast') {
271
+ const tree = dirname(spawnSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { encoding: 'utf8' }).stdout.trim());
272
+ const root = process.env.RT_FLOW_RECORDS || join(homedir(), '.claude', 'projects');
273
+ const argv = process.argv.slice(3).filter((arg, index, all) => arg !== '--flow' && all[index - 1] !== '--flow');
274
+ console.log(await runForecast({ argv, model, base: dirname(path), openReaders, tree, root, settings: GUARD_SETTINGS }));
275
+ } else if (command === 'plan-red') {
276
+ const source = await openSources(model, dirname(path));
277
+ const sources = { git: source('git'), steps: source('steps'), marks: source('marks') };
278
+ process.exit(runPlanRed(sources, model, readRecord(process.env.RT_FLOW_TRANSCRIPT)));
279
+ } else {
280
+ const result = measureStates(model, await openReaders(model, dirname(path)));
281
+ console.log(json ? JSON.stringify(measureJson(model, result)) : [...measureLines(model, result), ...removedLines(model)].join('\n'));
282
+ }
283
+ } catch (error) {
284
+ if (error instanceof FlowSyntaxError) {
285
+ console.log(`flow syntax: ${error.message}`);
286
+ process.exit(1);
287
+ }
288
+ if (!(error instanceof FlowModelError)) throw error;
289
+ console.log(`flow model: ${error.message}`);
290
+ process.exit(1);
291
+ }
292
+ }
@@ -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(row?.epic ?? '');
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