@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,114 @@
1
+ /**
2
+ * The measurer «measure.epic» — the exits that read the epic of the work: its plan in the plans
3
+ * directory, its branch and its card.
4
+ *
5
+ * declared — exit 2: the epic branch stands on the server or went into the main branch by the PR of
6
+ * the epic, and the epic card left the first column or is closed. Kept for the life of the branch
7
+ * once met.
8
+ *
9
+ * nextTaken — exit 11: every unmerged, unblocked task of the epic other than the current one has a
10
+ * branch, locally or on the server; with no such task the exit is met. A task is blocked when it is
11
+ * deferred. A task with a branch standing
12
+ * before a task without one does not meet the exit: the plan still holds work nobody took.
13
+ *
14
+ * mergedMarked — exit 12: every task not deferred with a merged PR of its branch is marked
15
+ * «влито», except the task merged last, whatever its row, and the task of the last row: the mark is
16
+ * set by the branch of the next task, and these have none. A mark on a task whose merged PR the
17
+ * hosting does not list counts while no branch of it is on the server and no PR of its branches is
18
+ * open or closed unmerged. Until then state 13 would demand the PR of
19
+ * an epic whose tasks are not in its branch.
20
+ *
21
+ * finished — exit 13: the tip of the branch of every task of the epic that is not deferred lies in
22
+ * the epic branch or in the main branch on the server, and the PR of the epic into the main branch
23
+ * exists in any state. The tip is the local branch, the branch on the server, or the head of its
24
+ * merged PR when the server removed the branch.
25
+ */
26
+ import { epicOfWork } from './epic-of.mjs';
27
+ import { taskOfBranch } from './epic-text.mjs';
28
+
29
+ export function declared({ git, host, tree }) {
30
+ return () => {
31
+ const plan = epicOfWork({ git, host, tree });
32
+ if (!plan?.branch) return false;
33
+ const key = `exit2:${plan.epic}`;
34
+ if (host.recalled(key)) return true;
35
+ const onServer = host.remoteBranch(plan.branch) || host.pulls(plan.branch).some((p) => p.base === 'main' && p.state === 'MERGED');
36
+ const card = host.issue(plan.epic);
37
+ const met = onServer && card !== null && (!card.open || (card.status !== null && card.status !== 'backlog'));
38
+ if (met) host.remember(key);
39
+ return met;
40
+ };
41
+ }
42
+
43
+ /** A row the work does not wait for: deferred by the owner's word naming the task. */
44
+ const blocked = (row) => row.deferred;
45
+
46
+ const prefix = (task) => `RT-${task}-`;
47
+
48
+ export function nextTaken({ git, host, tree }) {
49
+ return () => {
50
+ const plan = epicOfWork({ git, host, tree });
51
+ if (!plan) return false;
52
+ const current = taskOfBranch(git.branch());
53
+ // A task with a merged PR is not ahead even unmarked: the hosting removes its branch on merge.
54
+ const merged = new Set(host.mergedPulls().map((p) => taskOfBranch(p.head)).filter((n) => n !== null));
55
+ const ahead = plan.rows.filter((row) => !row.merged && !merged.has(row.task) && row.task !== current && !blocked(row));
56
+ return ahead.every((row) => git.branches(prefix(row.task)).length > 0 || host.remoteBranches(prefix(row.task)).length > 0);
57
+ };
58
+ }
59
+
60
+ export function mergedMarked({ git, host, tree }) {
61
+ return () => {
62
+ const plan = epicOfWork({ git, host, tree });
63
+ if (!plan) return false;
64
+ // The moment of the merge per task: the latest of its merged PRs.
65
+ const mergedAt = new Map();
66
+ for (const p of host.mergedPulls()) {
67
+ const task = taskOfBranch(p.head);
68
+ if (task === null) continue;
69
+ const at = p.mergedAt ?? '';
70
+ if (!mergedAt.has(task) || at > mergedAt.get(task)) mergedAt.set(task, at);
71
+ }
72
+ const live = plan.rows.filter((row) => !row.deferred);
73
+ // The task merged last has no next branch to mark it by: its merged PR counts alone. Tasks
74
+ // merged in the same second are all last.
75
+ const lastAt = [...live].filter((row) => mergedAt.has(row.task)).reduce((at, row) => (mergedAt.get(row.task) > at ? mergedAt.get(row.task) : at), '');
76
+ const isLast = (row) => mergedAt.has(row.task) && mergedAt.get(row.task) === lastAt;
77
+ // The last row has no next task either: a chain merged top-down leaves it merged before the rest.
78
+ const lastRow = live.at(-1) ?? null;
79
+ return live.every((row) => {
80
+ if (mergedAt.has(row.task)) return row.merged || isLast(row) || row === lastRow;
81
+ // A mark with no merged PR in view stands for a merge past the window of the hosting: the
82
+ // hosting removed its branch on merge, so a branch left on the server, or any PR of its
83
+ // branches open or closed unmerged, says the mark is ahead of the work.
84
+ return row.merged && !host.remoteBranches(prefix(row.task)).length && !openPullOrClosedUnmerged({ git, host }, row.task);
85
+ });
86
+ };
87
+ }
88
+
89
+ /** A PR of a branch of the task is open or closed unmerged; the branches are the local and the server ones. */
90
+ const openPullOrClosedUnmerged = ({ git, host }, task) => {
91
+ const names = new Set([...git.branches(prefix(task)), ...host.remoteBranches(prefix(task))].map((b) => b.name));
92
+ return [...names].some((name) => host.pulls(name).some((p) => p.state === 'OPEN' || p.state === 'CLOSED'));
93
+ };
94
+
95
+ /** The tip of the branch of a task: local, on the server, or the head of its merged PR. */
96
+ const tipOf = ({ git, host }, task) =>
97
+ git.branches(prefix(task))[0]?.sha ??
98
+ host.remoteBranches(prefix(task))[0]?.sha ??
99
+ host.mergedPulls().find((p) => taskOfBranch(p.head) === task)?.headRefOid ??
100
+ null;
101
+
102
+ export function finished({ git, host, tree }) {
103
+ return () => {
104
+ const plan = epicOfWork({ git, host, tree });
105
+ if (!plan?.branch) return false;
106
+ const landed = plan.rows
107
+ .filter((row) => !row.deferred)
108
+ .every((row) => {
109
+ const tip = tipOf({ git, host }, row.task);
110
+ return tip !== null && (host.inRemote(tip, plan.branch) || host.inRemote(tip, 'main'));
111
+ });
112
+ return landed && host.pulls(plan.branch).some((p) => p.base === 'main');
113
+ };
114
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The measurer «measure.folder» — exit 9: one commit of the branch removed the task folder and added
3
+ * a record to the description of the past.
4
+ */
5
+ import { taskFolder, under } from './text.mjs';
6
+
7
+ export function archived({ git }) {
8
+ return () => {
9
+ const branch = git.branch();
10
+ if (!branch) return false;
11
+ const folder = taskFolder(branch);
12
+ return git
13
+ .commits()
14
+ .some((c) => c.deleted.some((p) => under(p, folder)) && c.added.some((p) => under(p, 'docs/archive')));
15
+ };
16
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The measurer «measure.footprint» — exit 8: after the commit of the plan the branch changed at least
3
+ * one file under every path of every footprint row marked «(правится)», and the directory of the
4
+ * product agreement the grill or the plan names under `proposed/` is gone from the head. A plan
5
+ * without marked rows is judged by `proposed/` alone.
6
+ */
7
+ import { agreementLines, footprintRows, taskFolder, touches } from './text.mjs';
8
+
9
+ export function touched({ git }) {
10
+ return () => {
11
+ const branch = git.branch();
12
+ if (!branch) return false;
13
+ const folder = taskFolder(branch);
14
+ const sha = git.addedBy(`${folder}/plan.md`);
15
+ if (!sha) return false;
16
+ const plan = git.versionAt(`${folder}/plan.md`, sha) ?? '';
17
+ const commits = git.commits();
18
+ const changed = commits
19
+ .slice(commits.findIndex((c) => c.sha === sha) + 1)
20
+ .flatMap((c) => [...c.added, ...c.deleted, ...c.modified]);
21
+ const rowsMet = footprintRows(plan)
22
+ .filter((row) => row.edited)
23
+ .every((row) => row.paths.every((path) => changed.some((file) => touches(file, path))));
24
+ const texts = [git.lastVersion(`${folder}/grill.md`), plan].filter((t) => typeof t === 'string');
25
+ const proposed = texts.flatMap((t) => agreementLines(t).paths).filter((p) => p.includes('/proposed/'));
26
+ return rowsMet && !proposed.some((p) => git.existsAtHead(p));
27
+ };
28
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The measurer «measure.grill» — exit 1: the grill of the branch, or of a draft in the working copy,
3
+ * holds the owner's request as a quote and an answer. The grill of the branch is read from the
4
+ * working copy, and from the history once the folder is taken apart.
5
+ */
6
+ import { grillAnswered, taskFolder } from './text.mjs';
7
+
8
+ export function written({ git, tree }) {
9
+ return () => {
10
+ const texts = [];
11
+ const branch = git.branch();
12
+ if (branch) {
13
+ const path = `${taskFolder(branch)}/grill.md`;
14
+ texts.push(tree.read(path) ?? git.lastVersion(path));
15
+ }
16
+ for (const name of tree.list('docs/tasks')) {
17
+ if (name.startsWith('_draft-')) texts.push(tree.read(`docs/tasks/${name}/grill.md`));
18
+ }
19
+ return texts.some((text) => typeof text === 'string' && grillAnswered(text));
20
+ };
21
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The measurer «measure.host» — the hosting did not answer: a read failed twice in this measurement.
3
+ * The engine reads it after the states, so it says whether the measured state stands on the silence.
4
+ */
5
+
6
+ export function silent({ host }) {
7
+ return () => host.silent();
8
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The measurer «measure.owner» — what the owner's last word says about the turn: a stop, or a push
3
+ * to go on.
4
+ */
5
+ /** The owner's last word begins with a stop word of `words.stop`, and nothing after it holds the turn. */
6
+ export function saidStop({ owner }) {
7
+ return ({ words, rules }) => {
8
+ const last = owner.last();
9
+ return last !== null && rules.saysStop(last, words);
10
+ };
11
+ }
12
+
13
+ /** The owner's last word pushes the work on by `words.nudge`, or names a task or an epic. */
14
+ export function nudged({ owner }) {
15
+ return ({ words }) => {
16
+ const last = owner.last();
17
+ if (last === null) return false;
18
+ return new RegExp(words.nudge ?? '(?!)', 'iu').test(last) || /(?<![\p{L}\d])[A-Z]+-\d+(?!\d)/u.test(last);
19
+ };
20
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The measurer «measure.plan» — exit 5: a commit of the branch added the plan; every step of the
3
+ * plan as that commit wrote it has a check line whose expected result is a form of `expect`; and
4
+ * the approval mark lies in the common directory of git and names the commit of the plan and the
5
+ * place of the answer, where a session record of this repository holds the owner's «Одобряю …».
6
+ * A plan of a branch of `words.legacyBranches` was approved before the engine and needs no mark.
7
+ */
8
+ import { taskFolder } from './text.mjs';
9
+
10
+ export function approved({ git, marks, steps, records }) {
11
+ return (data) => {
12
+ const words = data?.words ?? {};
13
+ const forms = Object.values(data?.expect ?? {}).map((form) => new RegExp(form.pattern));
14
+ const branch = git.branch();
15
+ if (!branch) return false;
16
+ const path = `${taskFolder(branch)}/plan.md`;
17
+ const sha = git.addedBy(path);
18
+ if (!sha) return false;
19
+ if ((words.legacyBranches ?? []).includes(branch)) return true;
20
+ const checks = steps.checks(git.versionAt(path, sha) ?? '');
21
+ const known = (c) => typeof c.expected === 'string' && forms.some((form) => form.test(c.expected.trim()));
22
+ if (checks.length === 0 || !checks.every(known)) return false;
23
+ // The answer is confirmed at its place in the session records, as the guard confirms it.
24
+ const task = branch.match(/^([A-Z]+-\d+)-/)?.[1] ?? branch;
25
+ return records.approvalFault(marks.approval(branch), sha, task) === null;
26
+ };
27
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The measurer «measure.pr» — exit 10: a branch on the server holds the commit that took the task
3
+ * folder apart; the branch has a PR in any state with a reviewer; the task left the work column.
4
+ */
5
+ import { taskOfBranch } from './epic-text.mjs';
6
+ import { taskFolder, under } from './text.mjs';
7
+
8
+ export function handed({ git, host }) {
9
+ return () => {
10
+ const branch = git.branch();
11
+ const task = taskOfBranch(branch);
12
+ if (task === null) return false;
13
+ const folder = taskFolder(branch);
14
+ const archived = git.commits().find((c) => c.deleted.some((p) => under(p, folder)) && c.added.some((p) => under(p, 'docs/archive')));
15
+ if (!archived || !host.remoteContains(archived.sha)) return false;
16
+ if (!host.pulls(branch).some((p) => p.reviewers.length > 0)) return false;
17
+ const card = host.issue(task);
18
+ return card !== null && (!card.open || card.status !== 'in-progress');
19
+ };
20
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The measurer «measure.progress».
3
+ *
4
+ * mirrors — exit 6: a version of the progress in the commit of the plan or later repeats the steps
5
+ * of the plan, numbers and names, and marks exactly one of them as going on now.
6
+ *
7
+ * done — exit 7: the progress of the working copy, and without the folder the last one in the
8
+ * history, marks every step of the plan done, and every done step has a green mark of its own. A
9
+ * plan without a single check line is judged by the marks of the progress alone.
10
+ */
11
+ import { sameSteps, taskFolder } from './text.mjs';
12
+
13
+ export function mirrors({ git, steps }) {
14
+ return () => {
15
+ const branch = git.branch();
16
+ if (!branch) return false;
17
+ const folder = taskFolder(branch);
18
+ const sha = git.addedBy(`${folder}/plan.md`);
19
+ if (!sha) return false;
20
+ const planned = steps.ofPlan(git.versionAt(`${folder}/plan.md`, sha) ?? '');
21
+ if (planned.length === 0) return false;
22
+ const commits = git.commits();
23
+ return commits.slice(commits.findIndex((c) => c.sha === sha)).some((c) => {
24
+ const text = git.versionAt(`${folder}/progress.md`, c.sha);
25
+ if (text === null) return false;
26
+ const got = steps.ofProgress(text).steps;
27
+ return sameSteps(planned, got) && got.filter((s) => s.mark === '>').length === 1;
28
+ });
29
+ };
30
+ }
31
+
32
+ export function done({ git, tree, marks, steps }) {
33
+ return () => {
34
+ const branch = git.branch();
35
+ if (!branch) return false;
36
+ const folder = taskFolder(branch);
37
+ const plan = tree.read(`${folder}/plan.md`) ?? git.lastVersion(`${folder}/plan.md`);
38
+ const progress = tree.read(`${folder}/progress.md`) ?? git.lastVersion(`${folder}/progress.md`);
39
+ if (plan === null || progress === null) return false;
40
+ const planned = steps.ofPlan(plan);
41
+ if (planned.length === 0) return false;
42
+ const got = steps.ofProgress(progress).steps;
43
+ const unchecked = steps.checks(plan).every((c) => c.command === null);
44
+ return planned.every((p) => {
45
+ const step = got.find((s) => s.number === p.number);
46
+ if (step?.mark !== 'x') return false;
47
+ return unchecked || marks.step(branch, p.number)?.matched === true;
48
+ });
49
+ };
50
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * The measurer «measure.session» — what this session did: a write to the tree, a role it runs as, a
3
+ * menu of a refusal that did not reach the owner, a step another check forbids, a stop after a
4
+ * refusal of a stop with no call in between, and a wait for a background task of its own.
5
+ */
6
+ /** The tools that edit a file. */
7
+ const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
8
+
9
+ /** The session wrote to the tree: an edit of a file, or a command of the work of `words.write`. */
10
+ export function wrote({ session }) {
11
+ return ({ words, rules }) =>
12
+ session.toolUses().some((use) => EDIT_TOOLS.has(use.name) || (use.name === 'Bash' && rules.isWriteCommand(use.input.command ?? '', words)));
13
+ }
14
+
15
+ /** The session runs as a role whose header gives it no edit tool: its report is its work. */
16
+ export function role({ session }) {
17
+ return () => {
18
+ const tools = session.roleTools(session.agent());
19
+ if (!tools || tools.includes('*')) return false;
20
+ return !/(?:^|[^\w])(?:Write|Edit|MultiEdit|NotebookEdit)(?:[^\w]|$)/.test(tools);
21
+ };
22
+ }
23
+
24
+ /**
25
+ * The menu of a refusal did not reach the owner a second time in a row: the last two refusals name
26
+ * the menu of `words.menu`, after each the agent called the menu, and no call was answered.
27
+ */
28
+ export function menuLost({ session }) {
29
+ return ({ words }) => {
30
+ const options = (words.menu ?? []).map((option) => option.replace(/RT-N$/, ''));
31
+ if (options.length === 0) return false;
32
+ let streak = 0;
33
+ let awaiting = false;
34
+ for (const event of session.events()) {
35
+ if (event.kind === 'refusal') {
36
+ // A refusal with a menu the agent never tried to ask breaks the streak, as does any
37
+ // refusal that names no menu.
38
+ if (awaiting) streak = 0;
39
+ awaiting = options.every((option) => event.text.includes(option));
40
+ if (!awaiting) streak = 0;
41
+ } else if (event.kind === 'menu' && awaiting) {
42
+ streak = event.answered ? 0 : streak + 1;
43
+ awaiting = false;
44
+ }
45
+ }
46
+ return streak >= 2;
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Another check forbids the step: the last two refusals of calls come from the same guard for the
52
+ * same reason, and no call wrote to the tree after the first of them. Answers the name of the guard,
53
+ * or false — the exit check then names the owner's menu about that guard.
54
+ */
55
+ /**
56
+ * The last of the refusals of a stop, the calls and the menus is a refusal of a stop: the move it
57
+ * named was not taken. While a background task of the session runs the stop is a wait, not an idle
58
+ * one: the executor has a move, and it is to wait.
59
+ */
60
+ export function idle({ session }) {
61
+ return () => {
62
+ const events = session.events();
63
+ let last = null;
64
+ for (const event of events) if (event.kind === 'refusal' || event.kind === 'call' || event.kind === 'menu') last = event;
65
+ return last?.kind === 'refusal' && running(events, timeOf(session)).tasks.length === 0 && unreadOf(events) === null;
66
+ };
67
+ }
68
+
69
+ /**
70
+ * The background task of the session whose notice has not reached it: { task, output, agent }, or null. A
71
+ * task is unread when its start stands in the record, its notice ended it with a result, and no call
72
+ * or menu followed that notice: the notice reaches the session only when the turn goes on, and a
73
+ * call is the first sign it went on. A task the session stopped itself, or one the harness killed,
74
+ * holds nothing.
75
+ */
76
+ function unreadOf(events) {
77
+ const started = new Map();
78
+ const unread = new Map();
79
+ for (const event of events) {
80
+ if (event.kind === 'background' && event.task) {
81
+ // An agent a message resumed runs again under the same number and sends a notice again.
82
+ started.set(event.task, { ...event, over: false });
83
+ unread.delete(event.task);
84
+ } else if (event.kind === 'backgroundEnd') {
85
+ // A notice that names its call ends that run alone, as in the count of running tasks: a
86
+ // late copy of the notice of a former run does not end the run a message resumed.
87
+ const task = event.id ? [...started.values()].find((one) => one.id === event.id) : started.get(event.task);
88
+ if (!task || task.over) continue;
89
+ task.over = true;
90
+ if (event.stopped || event.status === 'killed' || event.status === 'stopped') continue;
91
+ unread.set(task.task, { task: task.task, output: event.output ?? task.output ?? null, agent: Boolean(task.agent) });
92
+ } else if (event.kind === 'call' || event.kind === 'menu') unread.clear();
93
+ }
94
+ return [...unread.values()].pop() ?? null;
95
+ }
96
+
97
+ /** The measurer «measure.session.unread»: the unread background task of the session, or false. */
98
+ export function unread({ session }) {
99
+ return () => unreadOf(session.events()) ?? false;
100
+ }
101
+
102
+ /** A background task older than this releases nothing and counts as no task, in minutes. */
103
+ export const BACKGROUND_BOUND = 20;
104
+
105
+ const timeOf = (session) => (typeof session.now === 'function' ? session.now() : Date.now());
106
+
107
+ /**
108
+ * The background tasks of the session that have a start, no end, and are younger than the bound at
109
+ * `now`, and how many of the open tasks have released their stop: { tasks, spent }.
110
+ */
111
+ function running(events, now) {
112
+ const open = new Map();
113
+ // The calls whose end stands in the record before their start: a command that finished at once.
114
+ const over = new Set();
115
+ // How many of the open tasks have released their stop: an ended turn takes one, the end of a
116
+ // task gives one back, and a call of a tool gives all back.
117
+ let spent = 0;
118
+ const close = (id) => {
119
+ if (!open.delete(id)) return false;
120
+ spent = Math.max(0, spent - 1);
121
+ return true;
122
+ };
123
+ for (const event of events) {
124
+ if (event.kind === 'background') {
125
+ if (!over.has(event.id)) open.set(event.id, event);
126
+ } else if (event.kind === 'backgroundEnd') {
127
+ // A notice that names its call ends that run alone: an agent a message resumed runs
128
+ // under a new call, and a late copy of the notice of its former run does not end it.
129
+ if (event.id) {
130
+ if (!close(event.id)) over.add(event.id);
131
+ } else for (const [id, task] of open) if (event.task && task.task === event.task) close(id);
132
+ } else if (event.kind === 'ended') spent = Math.min(open.size, spent + 1);
133
+ else if (event.kind === 'call') spent = 0;
134
+ }
135
+ // A start stamped ahead of the clock by more than a minute is no start to wait for.
136
+ const age = (task) => now - task.at;
137
+ const tasks = [...open.values()].filter((task) => Number.isFinite(task.at) && age(task) < BACKGROUND_BOUND * 60_000 && age(task) > -60_000);
138
+ return { tasks, spent };
139
+ }
140
+
141
+ /**
142
+ * The session waits for a background task of its own: more tasks run than turns ended on them with
143
+ * no call since. One task releases one stop — a chain of waits does not keep a turn released, and
144
+ * two tasks release two stops: the notice of the first wakes the session while the second runs.
145
+ */
146
+ export function waiting({ session }) {
147
+ return () => {
148
+ const { tasks, spent } = running(session.events(), timeOf(session));
149
+ return tasks.length > spent;
150
+ };
151
+ }
152
+
153
+ export function forbidden({ session }) {
154
+ return ({ words, rules }) => {
155
+ const writes = (event) =>
156
+ event.kind === 'call' &&
157
+ !event.blocked &&
158
+ (EDIT_TOOLS.has(event.name) || (event.name === 'Bash' && rules.isWriteCommand(event.input.command ?? '', words)));
159
+ let last = null;
160
+ let before = null;
161
+ for (const event of session.events()) {
162
+ if (event.kind === 'blocked') {
163
+ before = last;
164
+ last = event;
165
+ } else if (writes(event)) {
166
+ before = null;
167
+ last = null;
168
+ }
169
+ }
170
+ if (!last || !before) return false;
171
+ // While a background task ended unread, the move is to read it, not the owner's menu.
172
+ if (unreadOf(session.events()) !== null) return false;
173
+ return last.by === before.by && last.reason === before.reason ? last.by : false;
174
+ };
175
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The measurer «measure.task» — exit 4: the task the branch carries is open, or closed by its merge,
3
+ * and left the first column of the work queue; a commit of the branch added the task folder. Kept
4
+ * for the life of the branch once met.
5
+ */
6
+ import { taskOfBranch } from './epic-text.mjs';
7
+ import { taskFolder, under } from './text.mjs';
8
+
9
+ export function taken({ git, host }) {
10
+ return () => {
11
+ const branch = git.branch();
12
+ const task = taskOfBranch(branch);
13
+ if (task === null) return false;
14
+ const key = `exit4:${branch}`;
15
+ if (host.recalled(key)) return true;
16
+ const folder = taskFolder(branch);
17
+ if (!git.commits().some((c) => c.added.some((p) => under(p, folder)))) return false;
18
+ const card = host.issue(task);
19
+ const met = card !== null && card.exists !== false && (!card.open || (card.status !== null && card.status !== 'backlog'));
20
+ if (met) host.remember(key);
21
+ return met;
22
+ };
23
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The reading of the task folder texts shared by the measurers: the sections of the grill, the line
3
+ * of the agreement and the rows of the task footprint. Pure functions of text: the data reaches the
4
+ * measurers through their ports, and this file only reads what they pass.
5
+ */
6
+
7
+ /** The task folder of a branch, from the root of the tree. */
8
+ export function taskFolder(branch) {
9
+ return `docs/tasks/${branch}`;
10
+ }
11
+
12
+ /** The lines of the first `## ` section whose heading is one of the names, or null. */
13
+ export function section(text, names) {
14
+ const lines = text.split('\n');
15
+ const start = lines.findIndex((line) => names.some((name) => line.trim() === `## ${name}`));
16
+ if (start < 0) return null;
17
+ const end = lines.findIndex((line, i) => i > start && /^##\s/.test(line));
18
+ return lines.slice(start + 1, end < 0 ? lines.length : end);
19
+ }
20
+
21
+ const meaningful = (line) => {
22
+ const bare = line.replace(/^>\s*/, '').replace(/\*\*/g, '').trim();
23
+ return bare !== '' && !bare.startsWith('<');
24
+ };
25
+
26
+ /** The grill holds the owner's request as a quote and at least one answer. */
27
+ export function grillAnswered(text) {
28
+ const request = section(text, ['Просьба владельца', 'The owner request']);
29
+ const answers = section(text, ['Вопросы и ответы', 'Questions and answers']);
30
+ if (!request || !answers) return false;
31
+ return request.some((line) => line.startsWith('>') && meaningful(line)) && answers.some(meaningful);
32
+ }
33
+
34
+ const PATH_LINE = /^\*\*(?:Описание фичи|Draft|Spec):\*\*\s+`([^`]+)`/gm;
35
+ const REASON_LINE = /^\*\*(?:Описание фичи:\*\*\s+не нужно|Behaviour:\*\*\s+unchanged)\s+—\s+(.+)$/gm;
36
+
37
+ /** The agreement lines of a text: the paths it names and the reasons there is none. */
38
+ export function agreementLines(text) {
39
+ const paths = [...text.matchAll(PATH_LINE)].map((m) => m[1]).filter((p) => !p.includes('<'));
40
+ const reasons = [...text.matchAll(REASON_LINE)].map((m) => m[1].trim()).filter((r) => r.length >= 3 && !r.startsWith('<'));
41
+ return { paths, reasons };
42
+ }
43
+
44
+ /** The rows of the task footprint: whether the row is marked edited, and the paths it names. */
45
+ export function footprintRows(text) {
46
+ const lines = section(text, ['След задачи', 'Task footprint']) ?? [];
47
+ return lines
48
+ .filter((line) => /^\|/.test(line) && !/^\|\s*-/.test(line))
49
+ .map((line) => line.split('|').map((cell) => cell.trim()))
50
+ .filter((cells) => cells.length >= 4)
51
+ .map((cells) => ({
52
+ edited: /\((?:правится|edited)\)/.test(cells[1]),
53
+ paths: [...cells[2].matchAll(/`([^`\s]+)`/g)].map((m) => m[1]).filter((p) => /[/.]/.test(p) && !p.includes('<')),
54
+ }))
55
+ .filter((row) => row.paths.length > 0);
56
+ }
57
+
58
+ /** A changed file lies under the path: the file itself or a file inside the directory. */
59
+ export function under(file, path) {
60
+ const bare = path.replace(/\/$/, '');
61
+ return file === bare || file.startsWith(`${bare}/`);
62
+ }
63
+
64
+ /**
65
+ * A changed file touches a footprint path: it lies under the path, or the path names its file or
66
+ * its directories anywhere in it (`flow.js`, `source/`, `fixtures/turn-replay/`), as a row writes it
67
+ * after the directory it belongs to.
68
+ */
69
+ export function touches(file, path) {
70
+ const bare = path.replace(/\/$/, '');
71
+ return under(file, path) || `/${file}/`.includes(`/${bare}/`);
72
+ }
73
+
74
+ /** Two lists of steps name the same steps in the same order. */
75
+ export function sameSteps(planned, got) {
76
+ return planned.length === got.length && planned.every((p, i) => p.number === got[i].number && p.name === got[i].name);
77
+ }