@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
@@ -1,478 +1,118 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: Stop
3
- # Requires: hooks/deny-tail.sh, hooks/epic-over.sh, hooks/turn-exit-patterns.sh, hooks/turn-exit-epic.sh, hooks/turn-exit-role.sh
4
- # Turn exit guard: a turn in which nothing was done on the work does not end until the work is
5
- # handed over. Stop.
3
+ # rt-hook-timeout: 90
4
+ # Requires: checks/task-flow-script.mjs, checks/decide.mjs, hooks/decide.sh, hooks/facts.sh, hooks/deny-tail.sh, hooks/turn-exit-role.sh
5
+ # Turn exit guard: a turn does not end before the scenario of the task flow does. Stop.
6
6
  #
7
- # Why exactly this way. The rule lists four lawful exits of a turn — a question the rules do not
8
- # answer, a guard refusal, a filled window, work handed over with the next one started — and all
9
- # of it is held by the executor's memory. Held badly: a turn that ended with a report of what was
10
- # done looks more like work than any other — it is full, it names numbers and states, and the
11
- # emptiness behind it is invisible both to the owner and to the session itself. The owner said it
12
- # outright: stopping in the middle of work is not allowed, and the ban must be held by the machine.
7
+ # The engine measures the branch by the description and answers with a verdict: the turn is released
8
+ # by a release case of the description — the end of the scenario, a stop word of the owner, a session
9
+ # that wrote nothing, a role, the silent hosting, a menu that did not reach the owner — or held with
10
+ # one move named, the next step of the scenario. This file hands the engine the input and turns its
11
+ # verdict into the answer of the hook.
13
12
  #
14
- # What counts as work: an edit of a file and a command that changes the tree or its state. Reading,
15
- # searching and talking do not count as work — a turn that has stalled is filled with exactly
16
- # these. A reading subcommand of `git` and of the hosting client does not count as work either, and
17
- # this is judged by the parts of a compound command: reading joined to an edit through `&&` stays
18
- # work.
13
+ # Three cases the description cannot express live here: a role session with no edit tool ends with
14
+ # its report (`turn-exit-role.sh`), a window past the stop threshold of `window-fill-guard.sh` ends
15
+ # with the handover, and an engine that fails, runs past its limit of 75 seconds or cannot
16
+ # be called releases the turn with the outcome «движок упал» written to the journal; the next turn
17
+ # starts with that line.
19
18
  #
20
- # What releases a turn:
21
- # 1. The work is handed over or merged — the work state says so itself.
22
- # 2. There was work in the turn: an edit of a file or a command that changes the tree.
23
- # 3. A question to the owner through the question tool.
24
- # 4. A guard refusal — it ends the turn by the rule.
25
- # 5. The session handover is written — the window has run out.
26
- # 6. The owner said to stop.
27
- # 7. The session runs as a role with no edit tool: its report is its work, `turn-exit-role.sh`.
28
- #
29
- # Under an open epic the second and the fifth do not release, and a second pass is judged again:
30
- # until the epic is closed the executor does not stop on its own. The tiers lie in `turn-exit-epic.sh`.
31
- #
32
- # Work without a branch and without a task folder is judged by the second sign. It has no state,
33
- # and there is nowhere to take the first sign from — but a turn without a single edit of the tree
34
- # does not end here either: the owner's request "lay it out", "update it", "take a look" lives
35
- # without a task and without a branch, and it was protected least of all. Such a turn is released
36
- # by the same four things: a question, a guard refusal, a written handover and the owner's word
37
- # about stopping.
38
- #
39
- # FAIL-OPEN: on any error, a missing `jq`, a missing turn record, task folder or state line the
40
- # turn is ALLOWED (exit 0). A broken guard has no right to jam the conversation.
19
+ # FAIL-OPEN: no node, no jq, no engine, an engine that fails or runs past its limit → the turn is
20
+ # released, and the failure is written to the journal. A broken guard must not jam the conversation.
41
21
 
42
- # Its own name in the observations: the shared deny tail writes the refusal, not the guard.
43
22
  RT_GUARD_NAME=turn-exit-guard
44
23
  RT_GUARD_RULE=turn-conduct
45
24
 
46
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
47
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
48
-
25
+ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26
+ . "$rt_hooks_dir/utf8.sh" 2>/dev/null || true
27
+ . "$rt_hooks_dir/hook-input.sh" 2>/dev/null || true
28
+ command -v rt_hook_read >/dev/null 2>&1 || exit 0
49
29
  rt_hook_read
50
-
51
- # The refusal is printed in one form: the reason, the shared tail about the two lawful moves and a
52
- # fallback line in case there is no parser. These twelve lines used to stand as eight copies — the
53
- # file grew faster on every new tier than on the requirement itself.
54
- rt_te_deny() {
55
- # The end of an epic releases the turn whatever tier came here: the epic is read only on this road.
56
- command -v rt_te_epic_over >/dev/null 2>&1 && rt_te_epic_over && exit 0
57
- rt_te_reason="$(printf '%s\n\n%s' "$1" 'The owner said to stop — quote their word in the progress: `- **Waiting for the owner:** «<their words>»`. Where the task folder is gone, quote it in « » in the reply: the guard checks the quote against their message.')"
58
- rt_te_short="$2"
59
- # shellcheck disable=SC1090
60
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
61
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
62
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
63
- rt_te_tail="$(rt_deny_tail "")"
64
- [ -n "$rt_te_tail" ] && rt_te_reason="${rt_te_reason}
65
-
66
- ${rt_te_tail}"
67
-
68
- jq -n --arg r "$rt_te_reason" '{decision:"block",reason:$r}' 2>/dev/null \
69
- || printf '{"decision":"block","reason":"turn-exit-guard: %s"}\n' "$rt_te_short"
70
- exit 0
71
- }
72
-
73
30
  input="$RT_HOOK_INPUT"
74
- [ -z "$input" ] && exit 0
75
- command -v jq >/dev/null 2>&1 || exit 0
76
-
77
- active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
78
-
79
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
80
- [ -z "$transcript" ] && exit 0
81
- [ -f "$transcript" ] || exit 0
82
-
83
- workdir="$(rt_hook_cwd)"
84
- [ -z "$workdir" ] && workdir="${CLAUDE_PROJECT_DIR:-.}"
85
- cd "$workdir" 2>/dev/null || exit 0
86
- git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
87
-
88
- root="$(git rev-parse --show-toplevel 2>/dev/null)"
89
- [ -z "$root" ] && exit 0
90
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-role.sh" 2>/dev/null && rt_te_read_only_role && exit 0
91
-
92
- # The tiers of the open epic lie in a neighbouring file. A second pass over the same turn is judged
93
- # only under an open epic: outside it the guard has said its piece once and lets go.
94
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-epic.sh" 2>/dev/null || exit 0
95
- command -v rt_te_epic_open >/dev/null 2>&1 || exit 0
96
- [ "$active" = "true" ] && ! rt_te_epic_open && exit 0
97
-
98
- # The branch, the task folder and the state line are taken while they are there. Empty — the turn
99
- # is judged by the second sign, not released: this is where it used to leave with zero, and work by
100
- # the owner's word ended with an announcement of intent, silently.
101
- branch="$(git branch --show-current 2>/dev/null)"
102
- tasks_dir="${RT_TASKS_DIR:-docs/tasks}"
103
- progress=""
104
- state=""
105
- if [ -n "$branch" ] && [ -f "$root/$tasks_dir/$branch/progress.md" ]; then
106
- progress="$root/$tasks_dir/$branch/progress.md"
107
- state="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(State|Состояние):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$progress" 2>/dev/null | head -1)"
108
- fi
109
-
110
- # Work that has reached these two states has already waited out someone else's step: from here on
111
- # the owner moves it, and a turn closed here drops nothing.
112
- case "$state" in
113
- работа-отдана | влито) exit 0 ;;
114
- esac
115
- rt_te_owner_word_quoted && exit 0 # the owner's standing word quoted in the waiting line
116
-
117
- # A written plan is never the end of a turn at all. The mandatory action of this state is to do the
118
- # first stage, and whoever starts it moves the state by the same edit: a turn left in the previous
119
- # state has not started the first stage by definition. The second sign is no good here — it counts
120
- # creating the task, the branch, the column and the folder as work, and a turn with only the
121
- # preparation done passes straight through it. In one session this happened three times; twice the
122
- # neighbouring guard over the open PR caught it, the third time nothing caught it, and for the
123
- # owner a report about a taken task is indistinguishable from a stop.
124
- if [ "$state" = "замысел-записан" ]; then
125
- plan="$root/$tasks_dir/$branch/plan.md"
126
- first_stage="$(grep -m1 '^### ' "$plan" 2>/dev/null | sed 's/^### //')"
127
- [ -z "$first_stage" ] && first_stage="the first stage of the plan"
128
- reason="BLOCKED by turn-exit-guard: the work stands in the state 'замысел-записан', and the mandatory action of this state — do the first stage — was not begun in the turn.
129
-
130
- Creating the task, the branch, the column and the folder does not count as that step: all of it is preparation for work, not work. To the owner a report about a taken task is indistinguishable from a stop — they see the executor standing still.
131
-
132
- The first stage of the plan: ${first_stage}
133
-
134
- Begin it in this same turn and rewrite the state to '- **State:** \`этап-идёт\`'. The owner said to stop — then write so: the guard reads their word, not a retelling.
135
-
136
- The guard judges one turn: the next session is not refused."
137
-
138
- rt_te_deny "$reason" "the plan is written and the first stage is not begun."
139
- fi
140
-
141
- archived=false
142
- [ -z "$progress" ] && folder_archived && archived=true
143
-
144
- # The next step out of the progress is what the guard names in the refusal: an executor told only
145
- # "the work is not finished" re-reads the same line himself.
146
- next_step=""
147
- [ -n "$progress" ] && next_step="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(Next step|Следующий шаг):\*\*[[:space:]]*(.*)/\2/p' "$progress" 2>/dev/null | head -1)"
148
- [ -z "$next_step" ] && next_step="what stands in the section «Where we stand» of the progress"
149
-
150
- # The patterns of work, of exploration, of waiting and of the handover lie in a neighbouring file:
151
- # the guard outgrew the length limit, and patterns with their reasons read apart from the tiers.
152
- # Without the patterns file the guard stays silent — fail-open, as on any breakage of its own.
153
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-patterns.sh" 2>/dev/null || exit 0
154
- [ -n "${work_re:-}" ] || exit 0
155
-
156
- # The parsing of the turn record lies in a neighbouring file, apart from the tiers that apply its
157
- # answer. Without the file the guard stays silent — fail-open, as on any breakage of its own.
158
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-verdict.sh" 2>/dev/null || exit 0
159
- command -v rt_te_verdict >/dev/null 2>&1 || exit 0
160
- rt_te_verdict
161
-
162
- [ -z "$verdict" ] && exit 0 # also a turn woken while an own background task runs, SC-AK-1247
163
-
164
- # Every sign of the verdict becomes a variable of its own name; the commands go apart, they are text.
165
- eval "$(printf '%s' "$verdict" | jq -r 'del(.ran) | to_entries[] | "\(.key)=\(.value | tostring | @sh)"' 2>/dev/null)"
166
- commands="$(printf '%s' "$verdict" | jq -r '.ran // ""' 2>/dev/null)"
167
-
168
- # A question refused by the conversation guard and asked as prose in the same turn. A guard refusal
169
- # releases the turn — it is the lawful end itself — but there is nothing to release here: the same
170
- # question came back a line later, and the work stalled on what the tree had already answered. The
171
- # tier stands before the lawful exits on purpose: a guard refusal covers exactly this case.
172
- if [ "${asked_in_prose:-false}" = "true" ]; then
173
- rt_te_deny "BLOCKED by turn-exit-guard: in this turn the conversation guard refused a question to the owner, and the reply ends with a question in prose — the same question, asked in another form.
174
-
175
- The refusal of the guard named the reason: the answer lies in the tree or the owner has already given it. Read the place it named and work on; what is asked is what the tree does not hold.
176
-
177
- The guard judges one turn: the next session is not refused." "the question returned in prose after the refusal of the conversation guard."
178
- fi
179
-
180
- # The turn ended with waiting for the owner's word. The guard reads the word about stopping from
181
- # the owner, and here the executor announced it: in this turn the owner said nothing about stopping
182
- # and was asked no question through the tool. The shared tiers refuse such a turn without a name,
183
- # and after one step it ended with the same phrase again — three turns in a row in a consuming
184
- # tree. The tier stands before the lawful exits: a neighbouring guard's refusal releases a turn that
185
- # named a refusal to the owner, not a turn that said "waiting".
186
- # Incident analysis — the record
187
- # "2026-09-04-hod-konchalsya-ozhidaniem-pri-deystvuyushchem-ukazanii" in the intake.
188
- # A promise to do the work in the next turn. The same announcement of intent as a command named and
189
- # not run: the tier stands before the lawful exits, because the promise most often stands next to a
190
- # report about what was done, and by the fullness of the turn it is indistinguishable from a finish.
191
- if [ "$promised" = "true" ] && [ "$released" != "true" ]; then
192
- rt_te_deny "BLOCKED by turn-exit-guard: the reply ends with a promise to do the work in the next turn.
193
-
194
- A promise is the same announcement of intent as a command named and not run, and it only sounds politer. An offer to the owner to object to the announced intent is part of the promise, not a question: a turn ends with a question when the work does not go without the answer.
195
-
196
- Do the promised in this same turn, and the account of it can come after.
197
-
198
- The next step is written in the progress: ${next_step}
199
-
200
- The guard judges one turn: the next session is not refused." "the turn ended with a promise to do the work in the next turn."
201
- fi
202
-
203
- # Taking a task as the last action of the turn. Creating the task, the branch and the move of the
204
- # column is preparation, and the work of the taken task did not begin. Taking it after handed-over
205
- # work is a lawful end: there the taking answers for the handed-over one.
206
- if [ "$only_took" = "true" ] && [ "$released" != "true" ]; then
207
- rt_te_deny "BLOCKED by turn-exit-guard: the last action of the turn is taking a task, and the work of the taken task was not begun.
208
-
209
- Creating the task, the branch and moving the column is preparation for work, not work. To the owner a report about a taken task is indistinguishable from a stop: they see the executor standing still.
210
-
211
- Write the plan and begin its first stage in this same turn.
212
-
213
- The guard judges one turn: the next session is not refused." "the turn ended with taking a task."
214
- fi
215
-
216
- # The owner said to work without stops and did not cancel it. Their word holds until they cancel
217
- # it, and a turn ending with waiting for that same word invents the cancellation. Judged whether or
218
- # not there was work in the turn: the work stood three turns in a row, and each of them was full.
219
- if [ "$standing_work" = "true" ] && [ "$awaits_word" = "true" ]; then
220
- rt_te_deny "BLOCKED by turn-exit-guard: the turn ended with waiting for the word of the owner, and the owner said in this session to work without stops and did not cancel it.
221
-
222
- Their word holds until they cancel it themselves, and a new fact against it is a line about the price in the reply, not waiting. A decision the tree does not hold is needed — then ask the question by the tool.
223
-
224
- The next step is written in the progress: ${next_step}
225
-
226
- The guard judges one turn: the next session is not refused." "the turn ended with waiting under the standing word of the owner to work."
227
- fi
228
-
229
- if [ "$awaits_word" = "true" ]; then
230
- rt_te_deny "BLOCKED by turn-exit-guard: the turn ended with words about waiting for the word of the owner, and the word about stopping the guard reads from the owner: in this turn they announced no stop, and no question was put to them by the tool.
231
-
232
- The phrase «жду твоего слова» is a stop announced by the executor. The instruction of the owner to work holds until they cancel it, and a new fact against it is a line about the price in the reply, not waiting. A decision the tree does not hold is needed — then ask the question by the tool; otherwise do the next step in this same turn.
233
-
234
- The next step is written in the progress: ${next_step}
235
-
236
- The guard judges one turn: the next session is not refused." "the turn ended with waiting for the word of the owner."
237
- fi
238
-
239
- # A question without a single piece of work in a running stage: the parts that do not depend on
240
- # the answer go first, and the question after them.
241
- if [ "${asked:-false}" = "true" ] && [ "$worked" != "true" ] && [ "$state" = "этап-идёт" ]; then
242
- rt_te_question_without_work_deny
243
- fi
244
-
245
- # A handover written by the hand of the executor before the window filled is a stop announced by
246
- # the one it suits: under an open epic it releases nothing. The window guard's refusal releases as
247
- # any refusal, and the handover on compaction is written by the hook, not by a command in the turn.
248
- if [ "${handed_by_hand:-false}" = "true" ] && rt_te_epic_open; then
249
- rt_te_epic_deny handed-by-hand
31
+ root="${CLAUDE_PROJECT_DIR:-$(pwd)}"
32
+
33
+ # The engine measures the copy the session works in: the directory the hook input names. A worktree
34
+ # copy whose branch does not carry the engine is not judged by this scenario, and the turn ends.
35
+ dir="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null)"
36
+ [ -d "$dir" ] || dir="$root"
37
+ copy_top="$(git -C "$dir" rev-parse --show-toplevel 2>/dev/null)"
38
+ root_top="$(git -C "$root" rev-parse --show-toplevel 2>/dev/null)"
39
+ if [ -n "$copy_top" ] && [ "$copy_top" != "$root_top" ] && [ -z "${RT_FLOW_ENGINE:-}" ] && [ ! -f "$copy_top/tools/task-flow-script.mjs" ]; then
40
+ exit 0
250
41
  fi
251
42
 
252
- [ "$released" = "true" ] && exit 0
43
+ # A role with no edit tool: its report is its work.
44
+ . "$rt_hooks_dir/turn-exit-role.sh" 2>/dev/null && rt_te_read_only_role && exit 0
253
45
 
254
- # Work that has reached the handover and has not been handed over. The two states in the `case`
255
- # below declare that the code is written and what remains is to bring the work to a PR: run the
256
- # suite, take the folder apart, open the PR. The second sign does not ask about this — such a turn
257
- # is full of edits and commands, and it releases it whole; between taking the folder apart and
258
- # opening the PR nobody sees the work, and the owner reads the previous state as "nothing was done".
259
- #
260
- # The tier stands after the lawful exits: a question to the owner, a guard refusal, a session
261
- # handover and the owner's word about stopping end the turn by the rule, and locking them behind a
262
- # state is not allowed.
263
- case "$state" in
264
- этапы-кончились | разбор-кончился)
265
- if ! printf '%s' "$commands" | grep -qE "$handover_re"; then
266
- if [ "$state" = "этапы-кончились" ]; then
267
- action="merge the agreement, bring the texts up to what was done and run the suite"
268
- else
269
- action="take the task folder apart by the last commit"
270
- fi
271
- reason="BLOCKED by turn-exit-guard: the work stands in the state '${state}', and no request was opened in the turn.
272
-
273
- The mandatory action of this state is ${action}, and after it the work is brought to a request in the same turn. A report about what was done is never the end of a turn: the edit lies in a branch the owner does not see, and the former state they read as «nothing was done».
274
-
275
- The next step from the progress: ${next_step}
276
-
277
- Bring the work to a request in this same turn and rewrite the state. The owner said to stop — then write so: the guard reads their word, not a retelling.
278
-
279
- The guard judges one turn: the next session is not refused."
280
-
281
- rt_te_deny "$reason" "the work reached handing over and there is no request in the turn."
282
- fi
283
- ;;
46
+ # The journal of the engine failures and of the refusals in a row lies in the common directory of git.
47
+ journal_dir="$(git -C "$root" rev-parse --git-common-dir 2>/dev/null)"
48
+ case "$journal_dir" in
49
+ '') journal_dir="" ;;
50
+ /*) journal_dir="$journal_dir/rt-kit" ;;
51
+ *) journal_dir="$root/$journal_dir/rt-kit" ;;
284
52
  esac
53
+ journal() {
54
+ [ -n "$journal_dir" ] || return 0
55
+ mkdir -p "$journal_dir" 2>/dev/null || return 0
56
+ printf '%s\t%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" >> "$journal_dir/turn-exit.log" 2>/dev/null
57
+ }
285
58
 
286
- # Work taken but not started. A branch by the task number is created, and there is no task
287
- # directory next to it at all — which means the work is declared taken and not started by a single
288
- # line. The turn does not end here, however much work there was in it: creating the branch, moving
289
- # the column and cleaning up neighbouring branches are all commands that change the tree, and the
290
- # second sign releases such a turn whole.
291
- #
292
- # This is exactly how a turn used to stall: the task is taken, the number is named to the owner,
293
- # the report is written — and the next action of the state that means the task is taken, to write
294
- # the plan, is not done. A report looks more like work than any other, and a guard that knows only
295
- # "was there work in the turn" confirms it: there was work.
296
- # Incident analysis — the record "2026-08-25-task-taken-and-turn-ended" in the intake.
297
- #
298
- # A folder taken apart by a branch commit does not get here: `archived` means handed-over work, and
299
- # the previous tier judges it. A branch without a task number is not judged at all — such ones are
300
- # created for a trial too.
301
- # An epic branch is not judged either: it carries no folder by the rule, and the epic plan names it.
302
- if [ "$archived" != "true" ] && [ -z "$progress" ] && [ -n "$branch" ] && [ ! -d "$root/$tasks_dir/$branch" ] && ! rt_te_epic_branch; then
303
- task_key="${RT_TASK_KEY:-}"
304
- if [ -z "$task_key" ] && [ -f "$root/.claude/rt-kit/checks.json" ]; then
305
- task_key="$(jq -r '.board.taskKey // empty' "$root/.claude/rt-kit/checks.json" 2>/dev/null)"
306
- fi
307
- [ -z "$task_key" ] && task_key='[A-Za-z][A-Za-z0-9]*'
308
- if printf '%s' "$branch" | grep -qE "^${task_key}-[0-9]+-" 2>/dev/null; then
309
- reason="BLOCKED by turn-exit-guard: the work is taken and not begun — the branch \`$branch\` is created, and there is no task folder next to it.
310
-
311
- A created branch means the state «задача-взята», and it has one mandatory action — write the plan. A turn ending here leaves the work announced and not begun: the number is named, the column is moved, and on disk there is neither the analysis of the request nor the stages. The commands creating the branch and moving the column do not replace it — such a turn is filled with exactly those.
312
-
313
- npm run task:new -- <number> # if there is no folder at all
314
-
315
- Assemble \`$tasks_dir/$branch/\` and write the plan in this same turn.
316
-
317
- The guard judges one turn: the next session is not refused."
318
-
319
- rt_te_deny "$reason" "the work is taken and not begun — write the plan."
320
- fi
321
- fi
322
-
323
- # The stage contract. The mark "the stage is done" is a statement about the tree, and it is backed
324
- # by the output of a command, not by words: a stage marked from memory is, a session later,
325
- # indistinguishable from a checked one. The guard compares the stage number with what lies in the
326
- # branch history, and on a grown number it demands the commands from the verification line — it
327
- # stands in the plan in backticks. A technique written as prose the guard does not read: there is
328
- # nothing to back it with output, and this is its known limit.
329
- stage_now=""
330
- stage_was=""
331
- if [ -n "$progress" ]; then
332
- stage_now="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(Stage|Этап):\*\*[[:space:]]*([0-9][0-9]*).*/\2/p' "$progress" 2>/dev/null | head -1)"
333
- stage_was="$(git -C "$root" show "HEAD:$tasks_dir/$branch/progress.md" 2>/dev/null | sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(Stage|Этап):\*\*[[:space:]]*([0-9][0-9]*).*/\2/p' | head -1)"
334
- fi
335
-
336
- if [ -n "$progress" ] && [ -n "$stage_now" ] && [ -n "$stage_was" ] && [ "$stage_now" -gt "$stage_was" ] 2>/dev/null; then
337
- plan="$root/$tasks_dir/$branch/plan.md"
338
- # The contract of the closed stage, not of the started one: what is declared done is what is backed.
339
- contract="$(awk -v n="$stage_was" '
340
- $0 ~ "^### " n "\\." { inside = 1; next }
341
- /^### / { inside = 0 }
342
- inside && /\*\*(Verified by|Чем проверяется):\*\*/ { print }
343
- ' "$plan" 2>/dev/null)"
344
- missing=""
345
- while IFS= read -r cmd; do
346
- [ -z "$cmd" ] && continue
347
- printf '%s' "$commands" | grep -qF -- "$cmd" || missing="$missing\n $cmd"
348
- done <<EOF
349
- $(printf '%s' "$contract" | grep -o '`[^`]*`' | tr -d '`')
350
- EOF
351
- if [ -n "$missing" ]; then
352
- reason="BLOCKED by turn-exit-guard: the stage ${stage_was} is declared closed, and the commands it is verified by were not run in this turn:$(printf '%b' "$missing")
353
-
354
- The mark «этап сделан» is a statement about the tree, and it is backed by the output of a command, not by words: a session later what was marked from memory is indistinguishable from what was checked.
355
-
356
- Run them in this same turn or return the former stage number to the progress.
357
-
358
- The guard judges one turn: the next session is not refused."
359
- rt_te_deny "$reason" "a closed stage is not backed by the output of a command."
360
- fi
361
- fi
362
- # The next step rewritten into the progress and not begun: the tier lies next to the epic tiers.
363
- command -v rt_te_next_step_deny >/dev/null 2>&1 && rt_te_next_step_deny
364
-
365
- # The work is handed over and the next one is only named. There is more work in such a turn than in
366
- # any other — and all of it is on the task handed in: the handover finishes the previous work, not
367
- # the turn. Nine incident analyses in a day describe nine different stops, and in all nine the last
368
- # action of the turn was a text to the owner: a report, a summary, an announcement of intent.
369
- # Incident analysis — the record "2026-08-25-handover-turn-ends-on-intent" in the intake.
370
- if [ "$handed_over" = "true" ] && [ "$started_next" != "true" ]; then
371
- reason="BLOCKED by turn-exit-guard: a request is open, and nothing was done about the next work in this turn.
372
-
373
- Handed-over work ends a turn only together with the next one begun — an action about it must be done, not said. «Беру такую-то» is not an exit: the rule calls that an announcement of intent.
374
-
375
- Everything that happened before the request was opened was done on the handed-over task and says nothing about the next one.
376
-
377
- npm run task:new -- <title> # create the next one
378
- git checkout -b <KEY>-<number>-<slug> # take it into work
379
-
380
- Do the first step of the next work in this same turn. The owner said to stop — then write so: the guard reads their word, not a retelling.
381
-
382
- The guard judges one turn: the next session is not refused."
383
-
384
- rt_te_deny "$reason" "the work is handed over and the next one is not begun."
59
+ # A window past its stop threshold: the window guard refuses every next step of work and lets only
60
+ # the closing through — the progress, the handover, a rule, a question. Naming the next step here
61
+ # would name a move that guard denies, so the turn is released, and the reason goes to the journal.
62
+ sid="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
63
+ # shellcheck disable=SC1091
64
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null
65
+ if [ -f "$(rt_fact_window_stop_file "$sid")" ]; then
66
+ journal "окно за порогом: ход отпущен к передаче"
67
+ exit 0
385
68
  fi
386
69
 
387
- # The turn ended with waiting for someone else's step. There was work in it — that is what makes it
388
- # deceptive: it is full, and the emptiness behind it is invisible. The last action is judged, not
389
- # the presence of work.
390
- if [ "$waited" = "true" ]; then
391
- reason="BLOCKED by turn-exit-guard: the last action of the turn was waiting for a step by someone else, and that is never a state of the work.
392
-
393
- The run, the review by the owner and the merge go on without the executor and do not get faster from being watched. There may have been much work in the turn — it stays exactly where it stood, and the owner sees the executor standing still.
394
-
395
- The next step is written in the progress: ${next_step}
396
-
397
- Do it in this same turn or take the next task. Waiting in the middle of a turn is lawful — what is refused is the end.
398
-
399
- The guard judges one turn: the next session is not refused."
400
-
401
- rt_te_deny "$reason" "the turn ended with waiting for a step by someone else."
70
+ engine="${RT_FLOW_ENGINE:-}"
71
+ [ -n "$engine" ] || for candidate in "$rt_hooks_dir/../checks/task-flow-script.mjs" "${copy_top:-$root}/tools/task-flow-script.mjs" "$root/tools/task-flow-script.mjs"; do
72
+ [ -f "$candidate" ] && engine="$candidate" && break
73
+ done
74
+ if [ ! -f "$engine" ] || ! command -v node >/dev/null 2>&1 || ! command -v jq >/dev/null 2>&1; then
75
+ journal "движок упал: the engine cannot be called"
76
+ exit 0
402
77
  fi
403
- command -v rt_te_launch_last_deny >/dev/null 2>&1 && rt_te_launch_last_deny
404
- # The shared line. There was work in the turn — but the last action was not it, it was a text to the
405
- # owner. The particular tiers above name the kind of stop more precisely; what reaches here is what
406
- # they do not know by name.
407
- if [ "$worked" = "true" ] && [ "$ended_working" != "true" ]; then
408
- reason="BLOCKED by turn-exit-guard: there was work in the turn, but the last action of the turn was not it.
409
-
410
- A turn ends with work, not with an account of it. A report, a summary and an announcement of intent are not an exit: the more was done, the more convincingly they look like completion — and the next action takes exactly that place.
411
-
412
- The next step is written in the progress: ${next_step}
413
-
414
- Do it in this same turn, and telling about what was done can come after. The owner said to stop — then write so: the guard reads their word, not a retelling.
415
78
 
416
- The guard judges one turn: the next session is not refused."
417
-
418
- rt_te_deny "$reason" "the last action of the turn was not work."
79
+ limit="${RT_FLOW_VERDICT_LIMIT:-75}"
80
+ verdict="$(cd "$dir" && printf '%s' "$input" | perl -e 'alarm shift; exec @ARGV' "$limit" node "$engine" verdict 2>/dev/null)"
81
+ code=$?
82
+ if [ "$code" -ne 0 ] || [ -z "$verdict" ]; then
83
+ journal "движок упал: exit $code"
84
+ exit 0
419
85
  fi
420
86
 
421
- # Work left in the working tree. The branch has gone ahead of its remote reference, and no PR was
422
- # opened on it in this turn: what was done lies where nobody sees it except the one who did it. The
423
- # sign is read without the network and stays silent where there is no reference at all — such
424
- # branches are created for a trial too.
425
- # Incident analysis — the record "2026-08-25-fifteen-branches-over-one-index" in the intake.
426
- if [ "$worked" = "true" ] && [ "$handed_over" != "true" ] && [ "${unpushed_named:-false}" != "true" ]; then
427
- unpushed="$(git -C "$root" rev-list --count '@{u}..HEAD' 2>/dev/null)"
428
- if [ -n "$unpushed" ] && [ "$unpushed" -gt 0 ] 2>/dev/null; then
429
- reason="BLOCKED by turn-exit-guard: there was work in the turn, but it stayed in the working tree — commits not handed over: ${unpushed}.
430
-
431
- The owner sees the former state and reads it as «nothing was done». Two moves from here: bring the work to the hosting — push the branch and open a request — or remove what was done if it is not needed. What is left in the tree is named with a reason — in the words of the owner, not as a list of leftovers: the line «Не отправлено: <reason>» in the reply releases this tier.
432
-
433
- The guard judges one turn: the next session is not refused."
434
-
435
- rt_te_deny "$reason" "the work stayed in the working tree."
436
- fi
87
+ release="$(printf '%s' "$verdict" | jq -r '.release // empty' 2>/dev/null)"
88
+ if [ -n "$release" ]; then
89
+ rm -f "$journal_dir/refusals-in-row" 2>/dev/null
90
+ # A turn released on a wait is woken only by the notice of its task. The journal keeps the
91
+ # release with the session: the records of that session then show what woke it.
92
+ case "$release" in
93
+ 'a background task of the session runs') journal "ход отпущен на ожидании: $release · сессия $sid" ;;
94
+ esac
95
+ exit 0
437
96
  fi
438
-
439
- rt_te_steps_deny "$progress" # the steps of the plan are not done; the tier lies in the patterns
440
-
441
- # There was work in the turn, and the epic is open: the turn is released outside an epic and under a
442
- # closed one alone. Under an open epic the work stands where it stood, and the next step is named.
443
- [ "$worked" = "true" ] && rt_te_epic_open && rt_te_epic_deny worked
444
- [ "$worked" = "true" ] && exit 0
445
-
446
- if [ "$archived" = "true" ]; then
447
- reason="BLOCKED by turn-exit-guard: the task folder was removed by a commit of the branch, and nothing was done in this turn — neither an edit nor a command changing the tree.
448
-
449
- A removed folder means the middle of handing over, not its end: it is taken away BEFORE the request is opened, and between these two motions nobody but the one who did the work sees it. From this minute there is nothing to declare the state of the work by, so the turn is judged by the second sign — whether there was work in it.
450
-
451
- One step is left: open the request as a draft. The request is already open — then take the next task: waiting for a run by someone else is not work and does not end a turn.
452
-
453
- The guard judges one turn: the next session is not refused."
454
- elif [ -z "$state" ]; then
455
- reason="BLOCKED by turn-exit-guard: nothing was done in this turn — neither an edit nor a command changing the tree. This work has no task folder, and there is nowhere to take the state from, but that does not end the turn.
456
-
457
- A turn ends in four ways: a question to the owner the rules do not answer; a refusal of a guard; a filled session window; work handed over with the next one begun — outside an open epic. The end of the epic is the fifth. A command named and not run is not an exit: the line «сейчас запущу» is an announcement of intent, and that is named outright as a false end of a turn.
458
-
459
- Work by the word of the owner — «разложи», «обнови», «посмотри» — goes without a task and without a branch, and there is nothing to stop it by except this sign.
460
-
461
- Run what is named in this same turn. The owner said to stop — then write so: the guard reads their word, not a retelling.
462
-
463
- The guard judges one turn: the next session is not refused."
464
- else
465
- reason="BLOCKED by turn-exit-guard: the work is in the state '${state}', and nothing was done about it in this turn — neither an edit nor a command changing the tree.
466
-
467
- A turn ends in four ways: a question to the owner the rules do not answer; a refusal of a guard; a filled session window; work handed over with the next one begun — outside an open epic. The end of the epic is the fifth. A report about what was done is not an exit — it looks more like work than any other, and the emptiness behind it is invisible.
468
-
469
- The next step is written in the progress: ${next_step}
470
-
471
- Do it in this same turn. The owner said to stop — then write so: the guard reads their word, not a retelling.
472
-
473
- The guard judges one turn: the next session is not refused."
97
+ reason="$(printf '%s' "$verdict" | jq -r '.block // empty' 2>/dev/null)"
98
+ if [ -z "$reason" ]; then
99
+ journal "движок упал: no verdict"
100
+ exit 0
474
101
  fi
475
102
 
476
- rt_te_deny "$reason" "the work is not finished — the next step stands in the progress."
477
-
103
+ # Claude Code ends the turn itself after eight continuations in a row; the eighth refusal is written.
104
+ row=$(( $(cat "$journal_dir/refusals-in-row" 2>/dev/null || echo 0) + 1 ))
105
+ printf '%s\n' "$row" > "$journal_dir/refusals-in-row" 2>/dev/null
106
+ [ "$row" -ge 8 ] && journal "the eighth refusal in a row: $reason"
107
+
108
+ # The decision and its text come from the decision table. The engine gives the reason; whether the
109
+ # reason names the owner's menu is read from the engine's own fixed sentence for it.
110
+ menu_due=no
111
+ case "$reason" in *"The one move is the owner's menu:"*) menu_due=yes ;; esac
112
+ facts="$(jq -cn --arg m "$menu_due" \
113
+ '{flow_scenario_over:"no", menu_due:$m, read_only_role:"no", window_over_stop:"no"}')"
114
+ params="$(jq -cn --arg r "$reason" '{reason:$r}')"
115
+ # shellcheck disable=SC1091
116
+ . "$rt_hooks_dir/decide.sh" 2>/dev/null
117
+ command -v rt_decide >/dev/null 2>&1 && rt_decide turn-exit-guard.sh end_turn "$facts" "$params" Stop
478
118
  exit 0
@@ -26,7 +26,9 @@ rt_te_read_only_role() {
26
26
  case "$role" in
27
27
  */* | .*) return 1 ;;
28
28
  esac
29
- file="$root/.claude/agents/$role.md"
29
+ # The role is read in the copy the session works in, and in the project when the copy has none.
30
+ file="${dir:-$root}/.claude/agents/$role.md"
31
+ [ -f "$file" ] || file="$root/.claude/agents/$role.md"
30
32
  [ -f "$file" ] || return 1
31
33
 
32
34
  # Only the header is read: the body of a role may quote the line itself.