@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.
Files changed (371) 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 +21432 -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 +135 -0
  14. package/assets/checks/flow-forecast.mjs +334 -0
  15. package/assets/checks/flow-guard-run.mjs +90 -0
  16. package/assets/checks/flow-guard.mjs +496 -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 +495 -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 +227 -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 +437 -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 +318 -0
  32. package/assets/checks/tree-assignment.mjs +26 -7
  33. package/assets/checks/work-result.mjs +362 -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 +23 -22
  40. package/assets/docs/GLOSSARY.md +5 -1
  41. package/assets/hooks/ask-judge.md +67 -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 +374 -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 +44 -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 +39 -6
  77. package/assets/hooks/git-guard-push-marks.sh +262 -13
  78. package/assets/hooks/git-guard-push-tests.sh +58 -52
  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 +40 -12
  88. package/assets/hooks/prose-style-guard.sh +6 -19
  89. package/assets/hooks/pull-merges.sh +76 -0
  90. package/assets/hooks/push-ahead-call-guard.sh +447 -0
  91. package/assets/hooks/push-set.sh +38 -8
  92. package/assets/hooks/qa-dataid-guard.sh +7 -17
  93. package/assets/hooks/record-turn.sh +52 -0
  94. package/assets/hooks/rerun-guard.sh +11 -16
  95. package/assets/hooks/reuse-first-guard.sh +7 -21
  96. package/assets/hooks/role-calls.sh +25 -3
  97. package/assets/hooks/rule-source-guard.sh +54 -21
  98. package/assets/hooks/skill-gate-rearm.sh +18 -5
  99. package/assets/hooks/skill-gate.sh +156 -20
  100. package/assets/hooks/skill-loaded.sh +18 -3
  101. package/assets/hooks/sql-guard-target.sh +2 -2
  102. package/assets/hooks/sql-guard-write.sh +12 -12
  103. package/assets/hooks/sql-guard.sh +58 -16
  104. package/assets/hooks/task-context-load.sh +3 -1
  105. package/assets/hooks/task-flow-context.sh +5 -18
  106. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  107. package/assets/hooks/task-flow-guard.sh +28 -130
  108. package/assets/hooks/tree-assignment-guard.sh +25 -14
  109. package/assets/hooks/turn-entry-load.sh +3 -1
  110. package/assets/hooks/turn-exit-guard.sh +92 -452
  111. package/assets/hooks/turn-exit-role.sh +3 -1
  112. package/assets/hooks/turn-judge.md +113 -0
  113. package/assets/hooks/window-fill-guard.sh +22 -41
  114. package/assets/patterns/doc-style-human.md +36 -76
  115. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  116. package/assets/patterns/git-workflow-commit.github.md +11 -269
  117. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  118. package/assets/patterns/git-workflow-docker.md +8 -231
  119. package/assets/patterns/git-workflow-freshness.md +8 -56
  120. package/assets/patterns/git-workflow-merge.md +6 -176
  121. package/assets/patterns/git-workflow-migration.md +5 -75
  122. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  123. package/assets/patterns/git-workflow-pr-ready.md +9 -70
  124. package/assets/patterns/git-workflow-pr.azure.md +13 -285
  125. package/assets/patterns/git-workflow-pr.github.md +13 -251
  126. package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
  127. package/assets/patterns/git-workflow-restart.md +5 -42
  128. package/assets/patterns/git-workflow-secrets.md +10 -76
  129. package/assets/patterns/git-workflow-stack.md +7 -207
  130. package/assets/patterns/status-report-table.github.md +1 -1
  131. package/assets/patterns/task-flow-archive.md +12 -233
  132. package/assets/patterns/task-flow-close.md +16 -292
  133. package/assets/patterns/task-flow-cycle.md +13 -39
  134. package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
  135. package/assets/patterns/task-flow-handoff.md +13 -161
  136. package/assets/patterns/task-flow-resume.md +18 -218
  137. package/assets/patterns/task-flow-start.md +9 -247
  138. package/assets/patterns/turn-entry-map.md +2 -2
  139. package/assets/pitfalls/agent-kit-extend.md +200 -0
  140. package/assets/pitfalls/agent-kit.2.md +323 -0
  141. package/assets/pitfalls/angular-patterns.md +98 -0
  142. package/assets/pitfalls/browser-verification.md +265 -0
  143. package/assets/pitfalls/component-structure.md +98 -0
  144. package/assets/pitfalls/dependencies.md +92 -0
  145. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  146. package/assets/pitfalls/deploy-flow.github.md +211 -0
  147. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  148. package/assets/pitfalls/doc-style-human.md +112 -0
  149. package/assets/pitfalls/doc-style.2.md +286 -0
  150. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  151. package/assets/pitfalls/entity-models.md +89 -0
  152. package/assets/pitfalls/epic-flow.md +92 -0
  153. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  154. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  155. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  156. package/assets/pitfalls/git-workflow-docker.md +275 -0
  157. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  158. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  159. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  160. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  161. package/assets/pitfalls/git-workflow-merge.md +220 -0
  162. package/assets/pitfalls/git-workflow-migration.md +103 -0
  163. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  164. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  165. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  166. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  167. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  168. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  169. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  170. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  171. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  172. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  173. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  174. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  175. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  176. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  177. package/assets/pitfalls/git-workflow-restart.md +72 -0
  178. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  179. package/assets/pitfalls/git-workflow-stack.md +254 -0
  180. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  181. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  182. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  183. package/assets/pitfalls/lib-layers.md +114 -0
  184. package/assets/pitfalls/lists.md +117 -0
  185. package/assets/pitfalls/mockups.needs-mockups.md +87 -0
  186. package/assets/pitfalls/navigation.md +94 -0
  187. package/assets/pitfalls/observability.needs-app.md +186 -0
  188. package/assets/pitfalls/platform-access.md +94 -0
  189. package/assets/pitfalls/queue-audit.github.md +78 -0
  190. package/assets/pitfalls/reuse-first.md +201 -0
  191. package/assets/pitfalls/spec-driven.2.md +318 -0
  192. package/assets/pitfalls/styling-bem.2.md +125 -0
  193. package/assets/pitfalls/task-flow-archive.md +265 -0
  194. package/assets/pitfalls/task-flow-close.2.md +166 -0
  195. package/assets/pitfalls/task-flow-close.md +167 -0
  196. package/assets/pitfalls/task-flow-cycle.md +73 -0
  197. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  198. package/assets/pitfalls/task-flow-handoff.md +200 -0
  199. package/assets/pitfalls/task-flow-handover.md +30 -0
  200. package/assets/pitfalls/task-flow-owner.md +58 -0
  201. package/assets/pitfalls/task-flow-plan.md +29 -0
  202. package/assets/pitfalls/task-flow-resume.md +257 -0
  203. package/assets/pitfalls/task-flow-start.md +287 -0
  204. package/assets/pitfalls/task-flow.2.md +303 -0
  205. package/assets/pitfalls/task-flow.md +4 -4
  206. package/assets/pitfalls/testing.2.md +279 -0
  207. package/assets/pitfalls/turn-conduct.md +16 -17
  208. package/assets/pitfalls/typescript-conventions.md +161 -0
  209. package/assets/pitfalls/write-a-skill.md +128 -0
  210. package/assets/rules/angular-patterns.md +21 -86
  211. package/assets/rules/autonomous-work.md +2 -2
  212. package/assets/rules/browser-verification.md +28 -256
  213. package/assets/rules/component-structure.md +25 -87
  214. package/assets/rules/dependencies.md +20 -78
  215. package/assets/rules/deploy-flow.azure.md +26 -156
  216. package/assets/rules/deploy-flow.github.md +34 -200
  217. package/assets/rules/deploy-flow.gitlab.md +27 -159
  218. package/assets/rules/doc-style.md +32 -286
  219. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  220. package/assets/rules/entity-models.md +14 -63
  221. package/assets/rules/epic-flow.md +24 -63
  222. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  223. package/assets/rules/git-workflow-hosting.github.md +38 -0
  224. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  225. package/assets/rules/git-workflow-push.azure.md +28 -0
  226. package/assets/rules/git-workflow-push.github.md +28 -0
  227. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  228. package/assets/rules/git-workflow-queue.azure.md +23 -0
  229. package/assets/rules/git-workflow-queue.github.md +30 -0
  230. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  231. package/assets/rules/git-workflow.azure.md +21 -282
  232. package/assets/rules/git-workflow.github.md +24 -284
  233. package/assets/rules/git-workflow.gitlab.md +21 -269
  234. package/assets/rules/lib-layers.md +30 -103
  235. package/assets/rules/lists.md +21 -105
  236. package/assets/rules/mockups.needs-mockups.md +25 -64
  237. package/assets/rules/navigation.md +10 -69
  238. package/assets/rules/observability.needs-app.md +43 -172
  239. package/assets/rules/platform-access.md +28 -75
  240. package/assets/rules/queue-audit.github.md +25 -52
  241. package/assets/rules/reuse-first.md +20 -195
  242. package/assets/rules/spec-driven.md +35 -308
  243. package/assets/rules/styling-bem.md +20 -117
  244. package/assets/rules/task-flow-handover.md +24 -0
  245. package/assets/rules/task-flow-owner.md +34 -0
  246. package/assets/rules/task-flow-plan.md +38 -0
  247. package/assets/rules/task-flow.md +22 -300
  248. package/assets/rules/testing.md +32 -273
  249. package/assets/rules/turn-conduct.md +105 -106
  250. package/assets/rules/turn-entry.md +2 -2
  251. package/assets/rules/typescript-conventions.md +41 -147
  252. package/assets/samples/tasks/_template/plan.md +30 -6
  253. package/assets/samples/tasks/_template/progress.md +0 -1
  254. package/assets/skills/agent-kit-extend.md +25 -168
  255. package/assets/skills/agent-kit.md +27 -299
  256. package/assets/skills/write-a-skill.md +20 -106
  257. package/assets/task-flow/flow.js +184 -0
  258. package/assets/task-flow/flow.md +101 -0
  259. package/assets/task-flow/measure/agreement.mjs +24 -0
  260. package/assets/task-flow/measure/ci.mjs +184 -0
  261. package/assets/task-flow/measure/copy.mjs +22 -0
  262. package/assets/task-flow/measure/epic-of.mjs +50 -0
  263. package/assets/task-flow/measure/epic-text.mjs +35 -0
  264. package/assets/task-flow/measure/epic.mjs +114 -0
  265. package/assets/task-flow/measure/folder.mjs +16 -0
  266. package/assets/task-flow/measure/footprint.mjs +28 -0
  267. package/assets/task-flow/measure/grill.mjs +21 -0
  268. package/assets/task-flow/measure/host.mjs +8 -0
  269. package/assets/task-flow/measure/owner.mjs +27 -0
  270. package/assets/task-flow/measure/plan.mjs +27 -0
  271. package/assets/task-flow/measure/pr.mjs +20 -0
  272. package/assets/task-flow/measure/progress.mjs +50 -0
  273. package/assets/task-flow/measure/session.mjs +252 -0
  274. package/assets/task-flow/measure/task.mjs +23 -0
  275. package/assets/task-flow/measure/text.mjs +77 -0
  276. package/assets/task-flow/source/git.mjs +254 -0
  277. package/assets/task-flow/source/host.mjs +277 -0
  278. package/assets/task-flow/source/marks.mjs +56 -0
  279. package/assets/task-flow/source/owner.mjs +94 -0
  280. package/assets/task-flow/source/records.mjs +116 -0
  281. package/assets/task-flow/source/session.mjs +269 -0
  282. package/assets/task-flow/source/steps.mjs +28 -0
  283. package/assets/task-flow/source/tree.mjs +42 -0
  284. package/bin/agent-kit.d.ts.map +1 -1
  285. package/bin/agent-kit.js +30 -0
  286. package/bin/agent-kit.js.map +1 -1
  287. package/lib/agent-checks.d.ts +55 -0
  288. package/lib/agent-checks.d.ts.map +1 -0
  289. package/lib/agent-checks.js +221 -0
  290. package/lib/agent-checks.js.map +1 -0
  291. package/lib/assets.d.ts.map +1 -1
  292. package/lib/assets.js +7 -2
  293. package/lib/assets.js.map +1 -1
  294. package/lib/cargo.d.ts +29 -0
  295. package/lib/cargo.d.ts.map +1 -1
  296. package/lib/cargo.js +27 -1
  297. package/lib/cargo.js.map +1 -1
  298. package/lib/cascade.d.ts.map +1 -1
  299. package/lib/cascade.js +3 -1
  300. package/lib/cascade.js.map +1 -1
  301. package/lib/commands.d.ts.map +1 -1
  302. package/lib/commands.js +78 -2
  303. package/lib/commands.js.map +1 -1
  304. package/lib/config.d.ts +18 -0
  305. package/lib/config.d.ts.map +1 -1
  306. package/lib/config.js +18 -1
  307. package/lib/config.js.map +1 -1
  308. package/lib/epic-window-send.d.ts +74 -0
  309. package/lib/epic-window-send.d.ts.map +1 -0
  310. package/lib/epic-window-send.js +166 -0
  311. package/lib/epic-window-send.js.map +1 -0
  312. package/lib/hooks-map.d.ts +4 -0
  313. package/lib/hooks-map.d.ts.map +1 -1
  314. package/lib/hooks-map.js +2 -2
  315. package/lib/hooks-map.js.map +1 -1
  316. package/lib/integrity.d.ts +3 -0
  317. package/lib/integrity.d.ts.map +1 -1
  318. package/lib/integrity.js +7 -0
  319. package/lib/integrity.js.map +1 -1
  320. package/lib/metric-lines.d.ts +2 -1
  321. package/lib/metric-lines.d.ts.map +1 -1
  322. package/lib/metric-lines.js +49 -1
  323. package/lib/metric-lines.js.map +1 -1
  324. package/lib/metric-send-mark.d.ts +6 -3
  325. package/lib/metric-send-mark.d.ts.map +1 -1
  326. package/lib/metric-send-mark.js +15 -5
  327. package/lib/metric-send-mark.js.map +1 -1
  328. package/lib/metric-send.d.ts +6 -2
  329. package/lib/metric-send.d.ts.map +1 -1
  330. package/lib/metric-send.js +47 -13
  331. package/lib/metric-send.js.map +1 -1
  332. package/lib/metrics.d.ts +17 -0
  333. package/lib/metrics.d.ts.map +1 -1
  334. package/lib/metrics.js +26 -15
  335. package/lib/metrics.js.map +1 -1
  336. package/lib/observations.js +3 -3
  337. package/lib/observations.js.map +1 -1
  338. package/lib/outcomes.d.ts +5 -2
  339. package/lib/outcomes.d.ts.map +1 -1
  340. package/lib/outcomes.js +5 -4
  341. package/lib/outcomes.js.map +1 -1
  342. package/lib/push-gate.d.ts +13 -0
  343. package/lib/push-gate.d.ts.map +1 -1
  344. package/lib/push-gate.js +11 -7
  345. package/lib/push-gate.js.map +1 -1
  346. package/lib/push-set-usefulness.d.ts +78 -0
  347. package/lib/push-set-usefulness.d.ts.map +1 -0
  348. package/lib/push-set-usefulness.js +225 -0
  349. package/lib/push-set-usefulness.js.map +1 -0
  350. package/lib/sync.d.ts +10 -0
  351. package/lib/sync.d.ts.map +1 -1
  352. package/lib/sync.js +14 -1
  353. package/lib/sync.js.map +1 -1
  354. package/lib/work-result.d.ts +43 -0
  355. package/lib/work-result.d.ts.map +1 -0
  356. package/lib/work-result.js +39 -0
  357. package/lib/work-result.js.map +1 -0
  358. package/package.json +1 -1
  359. package/assets/hooks/claim-guard.sh +0 -212
  360. package/assets/hooks/grill-gate-ask.sh +0 -26
  361. package/assets/hooks/grill-gate-bypass.sh +0 -61
  362. package/assets/hooks/grill-gate-options.sh +0 -50
  363. package/assets/hooks/grill-gate.sh +0 -482
  364. package/assets/hooks/postmortem-guard.sh +0 -124
  365. package/assets/hooks/proposal-guard.sh +0 -154
  366. package/assets/hooks/stand-login-guard.sh +0 -107
  367. package/assets/hooks/turn-exit-epic.sh +0 -173
  368. package/assets/hooks/turn-exit-patterns.sh +0 -123
  369. package/assets/hooks/turn-exit-verdict.sh +0 -149
  370. package/assets/hooks/waiting-turn-guard.sh +0 -320
  371. package/assets/hooks/work-start-guard.sh +0 -175
@@ -5,122 +5,36 @@ description: Creating a new skill — one with no law above it — a showcase, a
5
5
 
6
6
  # How a skill is created
7
7
 
8
- A skill is what the agent loads before work and reads in full. Everything else follows: it is
9
- short, it declares when to load it, and it does not retell what is already written in the
10
- neighbouring one.
8
+ Cold part: `pitfalls.md` — the whole text with samples and reasons.
11
9
 
12
10
  ## When to use
13
11
 
14
- - A skill with no law above it is being created: a showcase, a generator, work with a
15
- third-party service, a technique adopted in this tree.
16
- - A skill has grown, and it is time to split it.
17
- - The skill exists, but nobody loads it — the declaration needs fixing.
18
-
19
- **A rule and a pattern do not go here.** A rule stands under a law, a pattern next to a rule,
20
- and the shape of both is held by the pattern `spec-driven-rule`. A skill without a law is the
21
- third case, and only it is here.
12
+ - A skill with no law above it is created, has grown, or is not loaded. A rule and a pattern —
13
+ pattern `spec-driven-rule`.
22
14
 
23
15
  ## Order
24
16
 
25
- 1. **Ask what is missing.** What work the skill covers, where people stumbled without it,
26
- whether ready-made commands are needed or an order of actions is enough. A skill written
27
- without this retells the tool's documentation — and the agent knows that anyway.
28
- 2. **Write a draft.** One file. Additional ones — only when the first stops being readable in
29
- full.
30
- 3. **Show the owner.** A skill acts on all future sessions, and creating it silently is not
31
- allowed.
32
-
33
- ## When the owner hands over the text
34
-
35
- A text the owner wrote is carried, not rewritten. Before the first split it lands whole in the
36
- task folder: a request cut with `[…]` leaves nothing to compare against. Headings keep their case
37
- and wording, sentences their words, code samples stay whole. What the shape of a skill forces —
38
- the declaration, "When to use", a link in place of "above" — goes into a list of deviations, one
39
- line each. Before the first commit a script compares every heading and paragraph of the source
40
- with the skill files and prints what is missing or changed. A size limit the text does not fit
41
- splits the text into files, never shortens it.
42
-
43
- ## What is in the file
44
-
45
- ```
46
- <skill-name>/
47
- ├── SKILL.md # mandatory, and usually the only one
48
- ├── <SOMETHING>.md # a separate file — when SKILL.md stopped being readable in full
49
- └── scripts/ # ready-made scripts, if the operation is deterministic
50
- ```
51
-
52
- The preamble between `---` is `name` and `description`, then the title and the sections. The
53
- first section is "When to use": the agent decides by it, not by the title.
54
-
55
- ## The declaration decides everything
56
-
57
- `description` is **the only thing the agent sees** when it decides whether to load the skill or
58
- not. It stands in the system prompt next to the descriptions of all the others, and the choice
59
- goes by them.
60
-
61
- It answers two questions: what the skill gives and when to load it. Write in the third person,
62
- up to three hundred characters: the first sentence — what it does, the second — "Load when…", the
63
- third — what is not in it and where to look for that. Where the tree has the descriptions check
64
- laid out, it refuses a longer declaration.
65
-
66
- ```
67
- ✓ Creating a new skill — one with no law above it. Load when asked to create, write or
68
- rewrite a skill. The shape of a rule and a pattern is not here — that is pattern
69
- spec-driven-rule.
17
+ 1. Ask what is missing. 2. Write one file. 3. Show the owner. An owner's text is carried, not
18
+ rewritten: it lands whole in the task folder, deviations are listed, a script compares it.
70
19
 
71
- ✗ Helps with skills.
72
- ```
20
+ ## The file
73
21
 
74
- The second declaration gives the agent no way to tell this skill from the neighbouring one —
75
- and it loads neither.
76
-
77
- The line "what is not here" is not decoration: there are dozens of skills in the tree, and half
78
- of the wrong choices are the neighbour taken instead. Name it by name.
79
-
80
- ## Ready-made commands instead of a description
81
-
82
- A script is put next to the skill when the operation is deterministic — a check, bringing to a
83
- form, parsing output. Such a thing is cheaper to call than to generate anew, and an error in it
84
- is seen once, not in every generation.
85
-
86
- An order of actions that depends on what was found does not become a script: it stays text.
87
-
88
- ## When to split
89
-
90
- Split when:
91
-
92
- - the file stopped being readable in full — by experience, that is around a hundred lines;
93
- - it holds two different subjects, and the second is needed once a month;
94
- - ready-made code took more room than the explanation of what it is for.
95
-
96
- Do not split for beauty: two files instead of one cost one extra hop at every reading, and a
97
- link deeper than one level is not followed at all.
22
+ - **`name` and `description`, then "When to use" first.**
23
+ - **`description` is all the agent sees:** what it gives, "Load when…", which neighbour not to
24
+ load — third person, up to 300 characters.
25
+ - **A deterministic operation becomes a script next to it.**
26
+ - **Split when not readable in full (about a hundred lines); links go one level deep.**
27
+ - **It is named in the gate map or called by another skill or role.**
98
28
 
99
29
  ## How a skill does harm
100
30
 
101
- - **Retelling the tool's documentation.** The agent reads the skill at every piece of work; a
102
- line it knows anyway pushes out the one it does not.
103
- - **Duplicating a neighbour.** Two skills about one thing start to contradict each other, and
104
- the first to notice is whoever has carried out both.
105
- - **What goes stale together with the code.** A skill naming a version, a number or a file name
106
- that is edited more often than once a quarter lies silently.
107
- - **Length.** A skill of three screens stops being read in full and is read up to the first
108
- familiar section.
109
-
110
- ## Before handing it over
111
-
112
- - [ ] the declaration has "Load when…" and names the neighbour not to load;
113
- - [ ] the first section is "When to use";
114
- - [ ] the file is readable in full in one sitting;
115
- - [ ] not one line repeats the neighbouring skill;
116
- - [ ] nothing that goes stale by itself: versions, numbers, dates;
117
- - [ ] at least one ready-made sample, not only an explanation;
118
- - [ ] links go one level deep, no deeper;
119
- - [ ] where the tree has the descriptions check laid out, it is green before the first commit,
120
- not only before the push.
31
+ - **Retelling the tool's documentation.**
32
+ - **Duplicating a neighbour.**
33
+ - **What goes stale together with the code.**
34
+ - **Length.**
121
35
 
122
- ## So that the skill gets loaded
36
+ ## Names and techniques
123
37
 
124
- Writing it is not enough: a skill nobody opens does not act. A new skill is either named in the
125
- gate map of this tree, or called by name by another skill or a role. A skill named nowhere stays
126
- a decoration.
38
+ - An owner's text over a size limit is split into files, never shortened.
39
+ - A skill has at least one ready-made sample, not only an explanation.
40
+ - The descriptions check is green before the first commit, not only before push.
@@ -0,0 +1,184 @@
1
+ // The task flow as an executable scenario: the data language of `flow-syntax.mjs`, nothing here runs.
2
+ // A state is left when its exit is measured; the first state whose exit is unmet is where the work
3
+ // stands. A release case says when a turn may end before the scenario does. A new fact is a new
4
+ // measurer in `measure/`; a new combination of facts is a line here.
5
+ ({
6
+ source: {
7
+ git: { open: {} },
8
+ tree: { open: {} },
9
+ host: { open: {} },
10
+ marks: { open: {} },
11
+ owner: { open: {} },
12
+ session: { open: {} },
13
+ steps: { open: {} },
14
+ records: { open: {} },
15
+ },
16
+
17
+ measure: {
18
+ grill: { written: { git: source.git, tree: source.tree } },
19
+ epic: {
20
+ declared: { git: source.git, host: source.host, tree: source.tree },
21
+ nextTaken: { git: source.git, host: source.host, tree: source.tree },
22
+ mergedMarked: { git: source.git, host: source.host, tree: source.tree },
23
+ finished: { git: source.git, host: source.host, tree: source.tree },
24
+ },
25
+ agreement: { named: { git: source.git, tree: source.tree } },
26
+ task: { taken: { git: source.git, host: source.host } },
27
+ plan: { approved: { git: source.git, marks: source.marks, steps: source.steps, records: source.records } },
28
+ progress: {
29
+ mirrors: { git: source.git, steps: source.steps },
30
+ done: { git: source.git, tree: source.tree, marks: source.marks, steps: source.steps },
31
+ },
32
+ footprint: { touched: { git: source.git } },
33
+ folder: { archived: { git: source.git } },
34
+ pr: { handed: { git: source.git, host: source.host } },
35
+ copy: {
36
+ outsideEpic: { git: source.git, host: source.host, tree: source.tree },
37
+ outOfScenario: { git: source.git, host: source.host, tree: source.tree },
38
+ },
39
+ owner: { interrupted: { owner: source.owner }, nudged: { owner: source.owner } },
40
+ session: {
41
+ wrote: { session: source.session },
42
+ role: { session: source.session },
43
+ menuLost: { session: source.session },
44
+ forbidden: { session: source.session },
45
+ idle: { session: source.session, tree: source.tree },
46
+ unread: { session: source.session },
47
+ waiting: { session: source.session, tree: source.tree },
48
+ hung: { session: source.session, tree: source.tree },
49
+ },
50
+ host: { silent: { host: source.host } },
51
+ // Read by the verdict before the release cases: a CI run nobody watches or a red run nobody read
52
+ // holds the stop, the end of the scenario included.
53
+ ci: { hold: { git: source.git, host: source.host, tree: source.tree, session: source.session, owner: source.owner } },
54
+ },
55
+
56
+ state: {
57
+ request: {
58
+ title: 'просьба-не-разобрана',
59
+ action: 'explore the tree, then ask the questions',
60
+ pattern: 'task-flow-start',
61
+ exit: measure.grill.written,
62
+ },
63
+ epic: {
64
+ title: 'эпик-заведён',
65
+ action: 'take the epic branch from the main branch; the epic card moves with the first task',
66
+ pattern: 'epic-flow-declare',
67
+ exit: measure.epic.declared,
68
+ },
69
+ grill: {
70
+ title: 'разбор-закрыт',
71
+ action: 'write the product agreement, or the reason there is none',
72
+ pattern: 'task-flow-start',
73
+ exit: measure.agreement.named,
74
+ },
75
+ agreement: {
76
+ title: 'договорённость-записана',
77
+ action: 'create the task, the branch from the epic branch, and the folder',
78
+ pattern: 'task-flow-start',
79
+ exit: measure.task.taken,
80
+ },
81
+ taken: {
82
+ title: 'задача-взята',
83
+ action: 'write the plan',
84
+ pattern: 'task-flow-start',
85
+ exit: measure.plan.approved,
86
+ },
87
+ planned: {
88
+ title: 'замысел-записан',
89
+ action: 'do the first stage',
90
+ pattern: 'task-flow-start',
91
+ exit: measure.progress.mirrors,
92
+ },
93
+ stage: {
94
+ title: 'этап-идёт',
95
+ action: 'finish the stage: `step N.M` measures each step and marks it done',
96
+ pattern: 'task-flow-resume',
97
+ exit: measure.progress.done,
98
+ },
99
+ stagesOver: {
100
+ title: 'этапы-кончились',
101
+ action: 'merge the agreement, bring the texts up to date, run the suite',
102
+ pattern: 'task-flow-close',
103
+ exit: measure.footprint.touched,
104
+ },
105
+ reviewOver: {
106
+ title: 'разбор-кончился',
107
+ action: 'take the folder apart by the last commit',
108
+ pattern: 'task-flow-archive',
109
+ exit: measure.folder.archived,
110
+ },
111
+ folderGone: {
112
+ title: 'папка-разобрана',
113
+ action: 'the work queue audit, then open the PR',
114
+ pattern: 'task-flow-close',
115
+ exit: measure.pr.handed,
116
+ },
117
+ handed: {
118
+ title: 'работа-отдана',
119
+ action: 'send the rules review to the background, then take the next task of the epic',
120
+ pattern: 'task-flow-archive',
121
+ exit: measure.epic.nextTaken,
122
+ },
123
+ merged: {
124
+ title: 'влито',
125
+ action: 'merge the PRs of the chain bottom-up, mark the merged tasks by the branch of the next one',
126
+ pattern: 'task-flow-resume',
127
+ exit: measure.epic.mergedMarked,
128
+ },
129
+ epicOver: {
130
+ title: 'задачи-эпика-кончились',
131
+ action: 'open the PR of the epic into the main branch',
132
+ pattern: 'task-flow-close',
133
+ exit: measure.epic.finished,
134
+ end: true,
135
+ },
136
+ },
137
+
138
+ release: {
139
+ scenarioEnd: {
140
+ when: { any: [measure.epic.finished, { all: [measure.copy.outsideEpic, measure.pr.handed] }] },
141
+ order: 1,
142
+ log: 'the end of the scenario',
143
+ },
144
+ // No typed word stops the work; Esc does, and the turns a notice wakes after it are released.
145
+ interrupted: { when: measure.owner.interrupted, order: 2, log: 'the owner interrupted the turn' },
146
+ // The state «работа-отдана» sends work to the background by its own action and goes on: there
147
+ // the wait releases nothing.
148
+ background: {
149
+ when: { all: [measure.session.waiting, { not: measure.pr.handed }] },
150
+ order: 3,
151
+ log: 'a background task of the session runs',
152
+ },
153
+ noWrite: {
154
+ when: {
155
+ any: [
156
+ measure.copy.outOfScenario,
157
+ { all: [{ not: measure.session.wrote }, { not: measure.owner.nudged }] },
158
+ ],
159
+ },
160
+ order: 4,
161
+ log: 'no write to the tree, or a branch outside the scenario',
162
+ },
163
+ role: { when: measure.session.role, order: 5, log: 'a role session' },
164
+ hostSilent: { when: measure.host.silent, order: 6, log: 'the host did not answer twice' },
165
+ menuLost: { when: measure.session.menuLost, order: 8, log: 'the menu did not reach the owner' },
166
+ },
167
+
168
+ words: {
169
+ nudge: '(?<![\\p{L}])(?<!не )(продолжай|доделывай|работай|делай дальше|работаешь)(?![\\p{L}])|почему (ты )?(стоишь|встал|остановил)|что дальше|дальше\\?|^(ну )?(и )?что там|^ну и\\s*[?!.]|какого .*останов',
170
+ write: [
171
+ 'git commit', 'git push', 'git add', 'git merge', 'git rm', 'git mv', 'sed -i', 'perl -pi', 'gh pr', 'npm run task:new', 'pnpm run task:new', 'npm run task:move',
172
+ 'pnpm run task:move', 'npm run agent-kit:sync', 'pnpm run agent-kit:sync',
173
+ ],
174
+ menu: ['отложить RT-N', 'подскажу путь'],
175
+ legacyBranches: ['RT-3276-conversation-checks', 'RT-3329-task-flow-scenario'],
176
+ },
177
+
178
+ expect: {
179
+ exit: { pattern: '^exit (\\d+)$', compare: 'exit' },
180
+ line: { pattern: '^`(.*)`$', compare: 'line' },
181
+ regex: { pattern: '^/(.*)/$', compare: 'regex' },
182
+ number: { pattern: '^(=|>=|<=) ?(-?\\d+)$', compare: 'number' },
183
+ },
184
+ });
@@ -0,0 +1,101 @@
1
+ # The task flow
2
+
3
+ Generated by `flow-sync.mjs` from `flow.js` next to it. `flow-sync.mjs --check` refuses a hand edit:
4
+ the description is edited, and the generator is run.
5
+
6
+ <!-- flow:description -->
7
+ ## States
8
+
9
+ | State | Exit | Mandatory action | Pattern |
10
+ | --- | --- | --- | --- |
11
+ | `просьба-не-разобрана` | `measure.grill.written` | explore the tree, then ask the questions | `task-flow-start` |
12
+ | `эпик-заведён` | `measure.epic.declared` | take the epic branch from the main branch; the epic card moves with the first task | `epic-flow-declare` |
13
+ | `разбор-закрыт` | `measure.agreement.named` | write the product agreement, or the reason there is none | `task-flow-start` |
14
+ | `договорённость-записана` | `measure.task.taken` | create the task, the branch from the epic branch, and the folder | `task-flow-start` |
15
+ | `задача-взята` | `measure.plan.approved` | write the plan | `task-flow-start` |
16
+ | `замысел-записан` | `measure.progress.mirrors` | do the first stage | `task-flow-start` |
17
+ | `этап-идёт` | `measure.progress.done` | finish the stage: `step N.M` measures each step and marks it done | `task-flow-resume` |
18
+ | `этапы-кончились` | `measure.footprint.touched` | merge the agreement, bring the texts up to date, run the suite | `task-flow-close` |
19
+ | `разбор-кончился` | `measure.folder.archived` | take the folder apart by the last commit | `task-flow-archive` |
20
+ | `папка-разобрана` | `measure.pr.handed` | the work queue audit, then open the PR | `task-flow-close` |
21
+ | `работа-отдана` | `measure.epic.nextTaken` | send the rules review to the background, then take the next task of the epic | `task-flow-archive` |
22
+ | `влито` | `measure.epic.mergedMarked` | merge the PRs of the chain bottom-up, mark the merged tasks by the branch of the next one | `task-flow-resume` |
23
+ | `задачи-эпика-кончились` | `measure.epic.finished` | open the PR of the epic into the main branch | `task-flow-close` |
24
+
25
+ ## Release cases
26
+
27
+ The engine asks the cases in this order, and a met case lets the turn end before the scenario does.
28
+
29
+ | Order | Case | When | Log |
30
+ | --- | --- | --- | --- |
31
+ | 1 | `scenarioEnd` | `any(measure.epic.finished, all(measure.copy.outsideEpic, measure.pr.handed))` | the end of the scenario |
32
+ | 2 | `interrupted` | `measure.owner.interrupted` | the owner interrupted the turn |
33
+ | 3 | `background` | `all(measure.session.waiting, not(measure.pr.handed))` | a background task of the session runs |
34
+ | 4 | `noWrite` | `any(measure.copy.outOfScenario, all(not(measure.session.wrote), not(measure.owner.nudged)))` | no write to the tree, or a branch outside the scenario |
35
+ | 5 | `role` | `measure.session.role` | a role session |
36
+ | 6 | `hostSilent` | `measure.host.silent` | the host did not answer twice |
37
+ | 8 | `menuLost` | `measure.session.menuLost` | the menu did not reach the owner |
38
+
39
+ ## Measurers
40
+
41
+ | Measurer | Ports |
42
+ | --- | --- |
43
+ | `measure.grill.written` | `source.git`, `source.tree` |
44
+ | `measure.epic.declared` | `source.git`, `source.host`, `source.tree` |
45
+ | `measure.epic.nextTaken` | `source.git`, `source.host`, `source.tree` |
46
+ | `measure.epic.mergedMarked` | `source.git`, `source.host`, `source.tree` |
47
+ | `measure.epic.finished` | `source.git`, `source.host`, `source.tree` |
48
+ | `measure.agreement.named` | `source.git`, `source.tree` |
49
+ | `measure.task.taken` | `source.git`, `source.host` |
50
+ | `measure.plan.approved` | `source.git`, `source.marks`, `source.steps`, `source.records` |
51
+ | `measure.progress.mirrors` | `source.git`, `source.steps` |
52
+ | `measure.progress.done` | `source.git`, `source.tree`, `source.marks`, `source.steps` |
53
+ | `measure.footprint.touched` | `source.git` |
54
+ | `measure.folder.archived` | `source.git` |
55
+ | `measure.pr.handed` | `source.git`, `source.host` |
56
+ | `measure.copy.outsideEpic` | `source.git`, `source.host`, `source.tree` |
57
+ | `measure.copy.outOfScenario` | `source.git`, `source.host`, `source.tree` |
58
+ | `measure.owner.interrupted` | `source.owner` |
59
+ | `measure.owner.nudged` | `source.owner` |
60
+ | `measure.session.wrote` | `source.session` |
61
+ | `measure.session.role` | `source.session` |
62
+ | `measure.session.menuLost` | `source.session` |
63
+ | `measure.session.forbidden` | `source.session` |
64
+ | `measure.session.idle` | `source.session`, `source.tree` |
65
+ | `measure.session.unread` | `source.session` |
66
+ | `measure.session.waiting` | `source.session`, `source.tree` |
67
+ | `measure.session.hung` | `source.session`, `source.tree` |
68
+ | `measure.host.silent` | `source.host` |
69
+ | `measure.ci.hold` | `source.git`, `source.host`, `source.tree`, `source.session`, `source.owner` |
70
+
71
+ ## Sources
72
+
73
+ | Source | Ports |
74
+ | --- | --- |
75
+ | `source.git.open` | none |
76
+ | `source.tree.open` | none |
77
+ | `source.host.open` | none |
78
+ | `source.marks.open` | none |
79
+ | `source.owner.open` | none |
80
+ | `source.session.open` | none |
81
+ | `source.steps.open` | none |
82
+ | `source.records.open` | none |
83
+
84
+ ## Words
85
+
86
+ | Key | Words |
87
+ | --- | --- |
88
+ | `nudge` | `(?<![\p{L}])(?<!не )(продолжай\|доделывай\|работай\|делай дальше\|работаешь)(?![\p{L}])\|почему (ты )?(стоишь\|встал\|остановил)\|что дальше\|дальше\?\|^(ну )?(и )?что там\|^ну и\s*[?!.]\|какого .*останов` |
89
+ | `write` | git commit, git push, git add, git merge, git rm, git mv, sed -i, perl -pi, gh pr, npm run task:new, pnpm run task:new, npm run task:move, pnpm run task:move, npm run agent-kit:sync, pnpm run agent-kit:sync |
90
+ | `menu` | отложить RT-N, подскажу путь |
91
+ | `legacyBranches` | RT-3276-conversation-checks, RT-3329-task-flow-scenario |
92
+
93
+ ## Expected forms
94
+
95
+ | Form | Expected text | It matches when |
96
+ | --- | --- | --- |
97
+ | `exit` | `^exit (\d+)$` | the command exits with the code of the first group; the output is not compared |
98
+ | `line` | `` ^`(.*)`$ `` | the code is 0 and the last non-empty line of the output equals the first group |
99
+ | `regex` | `^/(.*)/$` | the code is 0 and the last non-empty line matches the first group |
100
+ | `number` | `^(=\|>=\|<=) ?(-?\d+)$` | the code is 0, the last non-empty line is an integer, and its comparison by the first group with the second holds |
101
+ <!-- /flow:description -->
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The measurer «measure.agreement» — exit 3: the grill or the plan of the branch names the directory
3
+ * of the product agreement, found on disk or in the history, or the reason there is none. The forms
4
+ * of the line are those the task folder sample writes: `**Описание фичи:**`, `**Draft:**` and
5
+ * `**Spec:**` with a path, `**Описание фичи:** не нужно — <reason>` and
6
+ * `**Behaviour:** unchanged — <reason>`.
7
+ */
8
+ import { agreementLines, taskFolder } from './text.mjs';
9
+
10
+ export function named({ git, tree }) {
11
+ return () => {
12
+ const branch = git.branch();
13
+ if (!branch) return false;
14
+ for (const file of ['grill.md', 'plan.md']) {
15
+ const path = `${taskFolder(branch)}/${file}`;
16
+ const text = tree.read(path) ?? git.lastVersion(path);
17
+ if (typeof text !== 'string') continue;
18
+ const { paths, reasons } = agreementLines(text);
19
+ if (reasons.length > 0) return true;
20
+ if (paths.some((p) => tree.exists(p) || git.everExisted(p))) return true;
21
+ }
22
+ return false;
23
+ };
24
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * The measurer «measure.ci» — the CI runs the session answers for. The hold is read before the
3
+ * release cases: a turn does not end over a run nobody watches or a red run nobody read.
4
+ *
5
+ * The PRs judged are the open ones whose branch is the current one, the epic branch of the work, or
6
+ * a branch the session pushed in this record — by `git push`, or named by `--head` of `gh pr create`.
7
+ * A task merged into the epic branch moves the head of the epic's PR without any call of the
8
+ * session, so the epic branch is judged too. Only bases the pipeline wakes for are judged: a PR into
9
+ * another base never gets a run, and waiting for one is a dead end.
10
+ *
11
+ * A run on the head of such a PR holds the stop when:
12
+ * - it is running, and no background task of the session that has not ended names its number,
13
+ * the PR number or the head sha — the watch;
14
+ * - it ended red, and no unrefused call after its end names its number or reads the output of a
15
+ * watch of it — the read; a watch call stands before the end and reads nothing;
16
+ * - there is no run yet, and the head was pushed or the PR opened less than `FRESH_MINUTES` ago.
17
+ *
18
+ * No typed word of the owner passes the hold: a running run asks for one background watch, whose
19
+ * notice wakes the session when the run ends, and a red run holds until one call reads it. The
20
+ * owner's Esc does: after it a notice does not put the work back on until the owner writes again.
21
+ */
22
+ import { epicOfWork } from './epic-of.mjs';
23
+ import { interrupted } from './owner.mjs';
24
+
25
+ /** How long a head without a run holds the stop, in minutes: the hosting shows a run within seconds. */
26
+ export const FRESH_MINUTES = 2;
27
+
28
+ /** The conclusions that are no red: the run passed, or did not need to run. */
29
+ const NOT_RED = new Set(['success', 'skipped', 'neutral']);
30
+
31
+ /** A number or a sha as a whole word of a text: «3472» is not found inside «44884034720». */
32
+ const names = (text, value) =>
33
+ value !== null && value !== undefined && value !== '' && new RegExp(`(?<![\\w./-])${String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\w-])`).test(text);
34
+
35
+ /** The text of a call that may name a run: its command, or its whole input. */
36
+ const callText = (event) => (typeof event.input?.command === 'string' ? event.input.command : JSON.stringify(event.input ?? {}));
37
+
38
+ /** The arguments of a command tail, with its redirections cut off: `> /tmp/push.log` names no branch. */
39
+ const argsOf = (tail) =>
40
+ tail
41
+ .replace(/\d*&?>>?\s*\S+/g, ' ')
42
+ .trim()
43
+ .split(/\s+/)
44
+ .filter((arg) => arg && !arg.startsWith('-') && !/[<>]/.test(arg));
45
+
46
+ /**
47
+ * A command as the shell splits it into words: a substitution `$(…)` or `\`…\`` is one word, a line
48
+ * continued by a backslash is one line, and a quoted text with a space or a separator in it is one
49
+ * word. The branch of `git push "https://…$(cat t)@…" X` and of `git -c h='!f() { …; }; f' push o X`
50
+ * is X.
51
+ */
52
+ const QUOTED_WORD = (quoted) => (/[\s;&|]/.test(quoted) ? 'QUOTED' : quoted);
53
+ const flat = (command) => {
54
+ let text = command.replace(/\\\n/g, ' ').replace(/'[^']*'/g, QUOTED_WORD).replace(/`[^`]*`/g, 'SUB');
55
+ for (let before = ''; before !== text; ) [before, text] = [text, text.replace(/\$\([^()]*\)/g, 'SUB')];
56
+ return text.replace(/"[^"]*"/g, QUOTED_WORD);
57
+ };
58
+
59
+ /** An argument without its quotes: `"RT-1-a"` names RT-1-a. */
60
+ const unquote = (arg) => arg.replace(/^(['"])(.*)\1$/, '$2');
61
+
62
+ /** The tail of a command up to its end: `;`, a pipe, `&&` or a lone `&`, not the `&` of `2>&1`. */
63
+ const TAIL = String.raw`((?:[^;&|\n]|>&|&>)*)`;
64
+
65
+ /**
66
+ * The branches the session pushed: { head: the time of the last push }. The time is the result of
67
+ * the call: a push runs the push set for minutes, and the hosting shows the run only after it.
68
+ */
69
+ export function pushedHeads(events) {
70
+ const heads = new Map();
71
+ const put = (head, at) => {
72
+ if (!head || head.includes('$')) return;
73
+ heads.set(head, Math.max(heads.get(head) ?? -Infinity, Number.isFinite(at) ? at : -Infinity));
74
+ };
75
+ // A push sent to the background ends with the notice of its task, not with the result of its call.
76
+ const ended = new Map(events.filter((e) => e.kind === 'backgroundEnd' && e.id).map((e) => [e.id, e.at]));
77
+ for (const event of events) {
78
+ if (event.kind !== 'call' || event.blocked || event.failed || event.name !== 'Bash') continue;
79
+ const command = flat(event.input?.command ?? '');
80
+ const at = event.input?.run_in_background ? ended.get(event.id) : Number.isFinite(event.doneAt) ? event.doneAt : event.at;
81
+ // `git checkout -b X && git push origin HEAD` pushes X, not the branch the call started on.
82
+ const switched = (index) => [...command.slice(0, index).matchAll(/\bgit\s+(?:checkout\s+-[bB]|switch\s+-[cC])\s+(\S+)/g)].pop()?.[1] ?? event.branch;
83
+ const own = (ref, index) => (!ref || ref === 'HEAD' ? switched(index) : ref);
84
+ for (const match of command.matchAll(new RegExp(String.raw`\bgit\s+(?:-[Cc]\s+\S+\s+)*push\b${TAIL}`, 'g'))) {
85
+ const refspecs = argsOf(match[1]).map(unquote).slice(1);
86
+ if (refspecs.length === 0) put(switched(match.index), at);
87
+ for (const refspec of refspecs) put(own(refspec.replace(/^\+/, '').split(':').pop().replace(/^refs\/heads\//, ''), match.index), at);
88
+ }
89
+ for (const match of command.matchAll(new RegExp(String.raw`\bgh\s+pr\s+(?:create|new)\b${TAIL}`, 'g'))) {
90
+ // `--head owner:branch` names the branch of a fork: the PR list names it without the owner.
91
+ put(own(/(?:--head|-H)[=\s]+['"]?([^\s'"]+)/.exec(match[1])?.[1]?.replace(/^[^:]+:/, ''), match.index), at);
92
+ }
93
+ }
94
+ return heads;
95
+ }
96
+
97
+ /** The background tasks of the session that started and have not ended: [{ command, output }]. */
98
+ function openTasks(events) {
99
+ const open = new Map();
100
+ for (const event of events) {
101
+ if (event.kind === 'background') open.set(event.id, event);
102
+ else if (event.kind === 'backgroundEnd') {
103
+ if (event.id) open.delete(event.id);
104
+ else for (const [id, task] of open) if (event.task && task.task === event.task) open.delete(id);
105
+ }
106
+ }
107
+ return [...open.values()];
108
+ }
109
+
110
+ /**
111
+ * A background task watches the run: its command calls the hosting client and names the run, the PR
112
+ * or the head. A log file named after the PR is no watch.
113
+ */
114
+ const watches = (task, run, pr) =>
115
+ typeof task.command === 'string' &&
116
+ /\bgh\b[\s\S]*\bwatch\b/.test(task.command) &&
117
+ (names(task.command, run?.id) ||
118
+ names(task.command, pr.number) ||
119
+ names(task.command, pr.head) ||
120
+ (pr.headRefOid && task.command.includes(pr.headRefOid.slice(0, 7))));
121
+
122
+ /**
123
+ * A command after the end of the run that a hook did not refuse and that did not fail names it, or a
124
+ * read of the output of a watch of it. An edit of a text that names the run reads nothing.
125
+ */
126
+ function wasRead(events, run, pr) {
127
+ const outputs = new Set(events.filter((e) => e.kind === 'background' && e.output && watches(e, run, pr)).map((e) => e.output));
128
+ return events.some(
129
+ (event) =>
130
+ event.kind === 'call' &&
131
+ !event.blocked &&
132
+ !event.failed &&
133
+ Number.isFinite(event.at) &&
134
+ event.at > run.endedAt &&
135
+ ((event.name === 'Bash' && /\bgh\b/.test(callText(event)) && names(callText(event), run.id)) ||
136
+ (event.name === 'Bash' && [...outputs].some((output) => callText(event).includes(output))) ||
137
+ (event.name === 'Read' && outputs.has(event.input?.file_path))),
138
+ );
139
+ }
140
+
141
+ /** A base the pipeline wakes for: a name of the list, or a mask with `*`. */
142
+ const wakes = (bases, base) =>
143
+ bases === null || bases.some((name) => (name.includes('*') ? new RegExp(`^${name.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*+/g, '.*')}$`).test(base) : name === base));
144
+
145
+ /**
146
+ * The hold: { kind: 'running' | 'red' | 'fresh', pr, run, file }, or false. `pr` — { number, head,
147
+ * headRefOid, base }; `run` — { id, attempt, conclusion, endedAt }, null for a fresh head; `file` —
148
+ * the pipeline file.
149
+ */
150
+ export function hold({ git, host, tree, session, owner }) {
151
+ return (data) => {
152
+ if (owner && interrupted({ owner })(data)) return false;
153
+ const events = session.events();
154
+ const pushes = pushedHeads(events);
155
+ const heads = new Set(pushes.keys());
156
+ const branch = git.branch();
157
+ if (branch) heads.add(branch);
158
+ let epic = null;
159
+ try {
160
+ epic = epicOfWork({ git, host, tree })?.branch ?? null;
161
+ } catch (error) {
162
+ if (error?.name !== 'HostSilent') throw error;
163
+ }
164
+ if (epic) heads.add(epic);
165
+ const { bases, file } = host.pipeline();
166
+ if (Array.isArray(bases) && bases.length === 0) return false;
167
+ const pulls = host.openPulls().filter((p) => heads.has(p.head) && wakes(bases, p.base));
168
+ if (pulls.length === 0) return false;
169
+ const now = typeof session.now === 'function' ? session.now() : Date.now();
170
+ const tasks = openTasks(events);
171
+ for (const pr of pulls) {
172
+ const runs = host.runs(pr.headRefOid);
173
+ const red = runs.find((run) => run.status === 'completed' && !NOT_RED.has(run.conclusion) && !wasRead(events, run, pr));
174
+ if (red) return { kind: 'red', pr, run: red, file };
175
+ const running = runs.find((run) => run.status !== 'completed');
176
+ if (running && !tasks.some((task) => watches(task, running, pr))) return { kind: 'running', pr, run: running, file };
177
+ if (runs.length === 0) {
178
+ const since = Math.max(pushes.get(pr.head) ?? -Infinity, Number.isFinite(pr.createdAt) ? pr.createdAt : -Infinity);
179
+ if (now - since < FRESH_MINUTES * 60_000 && !tasks.some((task) => watches(task, null, pr))) return { kind: 'fresh', pr, run: null, file };
180
+ }
181
+ }
182
+ return false;
183
+ };
184
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The measurer «measure.copy» — where the working copy stands against the scenario.
3
+ *
4
+ * outsideEpic — the work has no epic: the task card names none, or the copy of a branch without a
5
+ * task number leads no live epic. Outside an epic the scenario ends at exit 10.
6
+ *
7
+ * outOfScenario — the branch carries no task number, the copy leads no live epic, and no draft folder
8
+ * lies in the working copy: the engine has nothing to name as the next step. A draft keeps the copy
9
+ * in the scenario, measured by states 1–4.
10
+ */
11
+ import { epicOfWork, workTask } from './epic-of.mjs';
12
+
13
+ export function outsideEpic({ git, host, tree }) {
14
+ return () => epicOfWork({ git, host, tree }) === null;
15
+ }
16
+
17
+ export function outOfScenario({ git, host, tree }) {
18
+ return () =>
19
+ workTask({ git, tree }) === null &&
20
+ epicOfWork({ git, host, tree }) === null &&
21
+ !tree.list('docs/tasks').some((name) => name.startsWith('_draft-'));
22
+ }