@rt-tools/agent-kit 0.37.0 → 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 (436) hide show
  1. package/README.md +5 -5
  2. package/assets/checks/action-of.mjs +154 -0
  3. package/assets/checks/board-pull-state.github.mjs +82 -13
  4. package/assets/checks/board-runs.github.mjs +40 -5
  5. package/assets/checks/board.github.mjs +1 -1
  6. package/assets/checks/check-board.github.mjs +58 -19
  7. package/assets/checks/check-specs.mjs +2 -2
  8. package/assets/checks/check-state-next.mjs +22 -10
  9. package/assets/checks/check-turn-map.mjs +26 -6
  10. package/assets/checks/check-work-steps.mjs +4 -173
  11. package/assets/checks/decide.mjs +285 -0
  12. package/assets/checks/decision-table.json +21365 -0
  13. package/assets/checks/decision-table.mjs +495 -0
  14. package/assets/checks/epic-table.github.mjs +4 -3
  15. package/assets/checks/epic-window.mjs +98 -0
  16. package/assets/checks/flow-condition.mjs +64 -0
  17. package/assets/checks/flow-data.mjs +136 -0
  18. package/assets/checks/flow-forecast.mjs +330 -0
  19. package/assets/checks/flow-guard-run.mjs +90 -0
  20. package/assets/checks/flow-guard.mjs +294 -0
  21. package/assets/checks/flow-model.mjs +271 -0
  22. package/assets/checks/flow-override.mjs +130 -0
  23. package/assets/checks/flow-plan.mjs +206 -0
  24. package/assets/checks/flow-scaffold.mjs +224 -0
  25. package/assets/checks/flow-step.mjs +365 -0
  26. package/assets/checks/flow-sync.mjs +296 -0
  27. package/assets/checks/flow-syntax.mjs +292 -0
  28. package/assets/checks/flow-verdict.mjs +112 -0
  29. package/assets/checks/lib-common.mjs +10 -2
  30. package/assets/checks/lib-domains.mjs +1 -1
  31. package/assets/checks/lib-manifests.mjs +34 -2
  32. package/assets/checks/merge-read.mjs +239 -0
  33. package/assets/checks/owner-nudges.mjs +389 -0
  34. package/assets/checks/push-inputs.mjs +444 -0
  35. package/assets/checks/push-trace.mjs +108 -0
  36. package/assets/checks/record-count.mjs +410 -0
  37. package/assets/checks/record-recount.mjs +187 -0
  38. package/assets/checks/record-turn.mjs +155 -0
  39. package/assets/checks/rt-kit-checks.config.mjs +17 -2
  40. package/assets/checks/spec-anchors.mjs +4 -4
  41. package/assets/checks/spec-contract.mjs +5 -5
  42. package/assets/checks/task-flow-script.mjs +292 -0
  43. package/assets/checks/tree-assignment.mjs +26 -7
  44. package/assets/checks/work-result.mjs +281 -0
  45. package/assets/checks/work-steps-lib.mjs +205 -0
  46. package/assets/commands/next-session.md +3 -1
  47. package/assets/commands/night.md +28 -18
  48. package/assets/defaults/gate-map.sh +39 -12
  49. package/assets/defaults/merges.sh +48 -0
  50. package/assets/defaults/project.sh +43 -13
  51. package/assets/defaults/push.sh +23 -0
  52. package/assets/defaults/turn-map.md +24 -21
  53. package/assets/docs/GLOSSARY.md +6 -2
  54. package/assets/hooks/ask-judge.md +65 -0
  55. package/assets/hooks/browser-guard-device-id.sh +11 -9
  56. package/assets/hooks/browser-guard-no-asking.sh +12 -6
  57. package/assets/hooks/browser-guard-no-listing.sh +13 -7
  58. package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
  59. package/assets/hooks/browser-guard-require-select.sh +15 -15
  60. package/assets/hooks/commit-msg.sh +13 -3
  61. package/assets/hooks/conscience-guard.sh +9 -25
  62. package/assets/hooks/decide.sh +141 -0
  63. package/assets/hooks/deny-tail.sh +16 -11
  64. package/assets/hooks/dev-server-guard.sh +27 -20
  65. package/assets/hooks/dispatch.sh +47 -4
  66. package/assets/hooks/docs-guard.sh +31 -200
  67. package/assets/hooks/end-conversation-guard.sh +12 -21
  68. package/assets/hooks/epic-stop-guard.sh +54 -105
  69. package/assets/hooks/exam-guard.sh +32 -65
  70. package/assets/hooks/facts-docs.sh +221 -0
  71. package/assets/hooks/facts-flow.sh +173 -0
  72. package/assets/hooks/facts.sh +308 -0
  73. package/assets/hooks/flow-step-guard.sh +93 -0
  74. package/assets/hooks/git-guard-delivery-body.sh +4 -4
  75. package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
  76. package/assets/hooks/git-guard-delivery-draft.sh +3 -3
  77. package/assets/hooks/git-guard-delivery-epic.sh +18 -9
  78. package/assets/hooks/git-guard-delivery-folder.sh +32 -7
  79. package/assets/hooks/git-guard-delivery-merge.sh +2 -2
  80. package/assets/hooks/git-guard-delivery-merged.sh +12 -1
  81. package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
  82. package/assets/hooks/git-guard-delivery-rerun.sh +32 -0
  83. package/assets/hooks/git-guard-delivery-signature.sh +82 -45
  84. package/assets/hooks/git-guard-delivery-task.sh +47 -0
  85. package/assets/hooks/git-guard-delivery.sh +112 -101
  86. package/assets/hooks/git-guard-discard.sh +8 -18
  87. package/assets/hooks/git-guard-main.sh +13 -19
  88. package/assets/hooks/git-guard-no-verify.sh +56 -16
  89. package/assets/hooks/git-guard-push-ahead.sh +46 -5
  90. package/assets/hooks/git-guard-push-marks.sh +227 -31
  91. package/assets/hooks/git-guard-push-tests.sh +51 -53
  92. package/assets/hooks/git-guard-tree-assignment.sh +7 -4
  93. package/assets/hooks/guard-note.sh +8 -6
  94. package/assets/hooks/handoff-entry-guard.sh +20 -39
  95. package/assets/hooks/handoff-write.sh +3 -1
  96. package/assets/hooks/hook-input.sh +0 -41
  97. package/assets/hooks/metric-marks.sh +19 -7
  98. package/assets/hooks/observe.sh +1 -1
  99. package/assets/hooks/override-write-guard.sh +27 -9
  100. package/assets/hooks/pre-push.sh +20 -10
  101. package/assets/hooks/prose-style-guard.sh +6 -19
  102. package/assets/hooks/pull-merges.sh +76 -0
  103. package/assets/hooks/push-set.sh +39 -7
  104. package/assets/hooks/qa-dataid-guard.sh +7 -17
  105. package/assets/hooks/record-turn.sh +52 -0
  106. package/assets/hooks/rerun-guard.sh +11 -16
  107. package/assets/hooks/reuse-first-guard.sh +7 -21
  108. package/assets/hooks/role-calls.sh +25 -3
  109. package/assets/hooks/rule-source-guard.sh +54 -21
  110. package/assets/hooks/skill-gate-rearm.sh +18 -5
  111. package/assets/hooks/skill-gate.sh +156 -20
  112. package/assets/hooks/skill-loaded.sh +18 -3
  113. package/assets/hooks/sql-guard-target.sh +2 -2
  114. package/assets/hooks/sql-guard-write.sh +12 -12
  115. package/assets/hooks/sql-guard.sh +58 -16
  116. package/assets/hooks/task-context-load.sh +3 -1
  117. package/assets/hooks/task-flow-context.sh +20 -22
  118. package/assets/hooks/task-flow-draft-guard.sh +25 -74
  119. package/assets/hooks/task-flow-guard.sh +28 -129
  120. package/assets/hooks/tree-assignment-guard.sh +25 -14
  121. package/assets/hooks/turn-entry-load.sh +3 -1
  122. package/assets/hooks/turn-exit-guard.sh +92 -452
  123. package/assets/hooks/turn-exit-role.sh +47 -0
  124. package/assets/hooks/turn-judge.md +103 -0
  125. package/assets/hooks/window-fill-guard.sh +22 -41
  126. package/assets/laws/work-conduct.md +9 -8
  127. package/assets/patterns/autonomous-work-run.md +35 -10
  128. package/assets/patterns/browser-verification-measure.md +10 -20
  129. package/assets/patterns/browser-verification-stand.md +30 -42
  130. package/assets/patterns/doc-style-human.md +0 -6
  131. package/assets/patterns/doc-style-sweep.md +7 -7
  132. package/assets/patterns/doc-style-trace.md +5 -4
  133. package/assets/patterns/doc-style-write.md +7 -7
  134. package/assets/patterns/epic-flow-declare.md +15 -8
  135. package/assets/patterns/git-workflow-commit.azure.md +9 -155
  136. package/assets/patterns/git-workflow-commit.github.md +11 -269
  137. package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
  138. package/assets/patterns/git-workflow-docker.md +8 -231
  139. package/assets/patterns/git-workflow-freshness.md +9 -56
  140. package/assets/patterns/git-workflow-merge.md +7 -174
  141. package/assets/patterns/git-workflow-migration.md +5 -73
  142. package/assets/patterns/git-workflow-pr-body.github.md +6 -159
  143. package/assets/patterns/git-workflow-pr-ready.md +9 -69
  144. package/assets/patterns/git-workflow-pr.azure.md +14 -220
  145. package/assets/patterns/git-workflow-pr.github.md +13 -253
  146. package/assets/patterns/git-workflow-pr.gitlab.md +14 -241
  147. package/assets/patterns/git-workflow-restart.md +5 -41
  148. package/assets/patterns/git-workflow-secrets.md +10 -76
  149. package/assets/patterns/git-workflow-stack.md +9 -205
  150. package/assets/patterns/lib-layers-new.md +7 -3
  151. package/assets/patterns/queue-audit-read.github.md +9 -3
  152. package/assets/patterns/spec-driven-domain.md +50 -48
  153. package/assets/patterns/spec-driven-rule.md +18 -19
  154. package/assets/patterns/status-report-table.github.md +2 -2
  155. package/assets/patterns/task-flow-archive.md +15 -256
  156. package/assets/patterns/task-flow-close.md +16 -291
  157. package/assets/patterns/task-flow-cycle.md +13 -39
  158. package/assets/patterns/task-flow-graph.needs-graph.md +8 -58
  159. package/assets/patterns/task-flow-handoff.md +13 -161
  160. package/assets/patterns/task-flow-resume.md +19 -183
  161. package/assets/patterns/task-flow-start.md +9 -248
  162. package/assets/patterns/testing-e2e.md +14 -18
  163. package/assets/patterns/testing-unit.md +9 -13
  164. package/assets/patterns/turn-entry-map.md +15 -5
  165. package/assets/pitfalls/agent-kit-extend.md +200 -0
  166. package/assets/pitfalls/agent-kit.2.md +323 -0
  167. package/assets/pitfalls/angular-patterns.md +98 -0
  168. package/assets/pitfalls/autonomous-work.md +15 -0
  169. package/assets/pitfalls/browser-verification.md +265 -0
  170. package/assets/pitfalls/component-structure.md +98 -0
  171. package/assets/pitfalls/dependencies.md +92 -0
  172. package/assets/pitfalls/deploy-flow.azure.md +171 -0
  173. package/assets/pitfalls/deploy-flow.github.md +211 -0
  174. package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
  175. package/assets/pitfalls/doc-style.2.md +286 -0
  176. package/assets/pitfalls/doc-style.md +3 -3
  177. package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
  178. package/assets/pitfalls/entity-models.md +89 -0
  179. package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
  180. package/assets/pitfalls/git-workflow-commit.github.md +307 -0
  181. package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
  182. package/assets/pitfalls/git-workflow-docker.md +275 -0
  183. package/assets/pitfalls/git-workflow-freshness.md +88 -0
  184. package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
  185. package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
  186. package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
  187. package/assets/pitfalls/git-workflow-merge.md +220 -0
  188. package/assets/pitfalls/git-workflow-migration.md +103 -0
  189. package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
  190. package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
  191. package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
  192. package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
  193. package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
  194. package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
  195. package/assets/pitfalls/git-workflow-pr.github.md +107 -0
  196. package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
  197. package/assets/pitfalls/git-workflow-push.azure.md +30 -0
  198. package/assets/pitfalls/git-workflow-push.github.md +30 -0
  199. package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
  200. package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
  201. package/assets/pitfalls/git-workflow-queue.github.md +30 -0
  202. package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
  203. package/assets/pitfalls/git-workflow-restart.md +72 -0
  204. package/assets/pitfalls/git-workflow-secrets.md +114 -0
  205. package/assets/pitfalls/git-workflow-stack.md +254 -0
  206. package/assets/pitfalls/git-workflow.2.azure.md +291 -0
  207. package/assets/pitfalls/git-workflow.2.github.md +294 -0
  208. package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
  209. package/assets/pitfalls/git-workflow.github.md +5 -9
  210. package/assets/pitfalls/lib-layers.md +114 -0
  211. package/assets/pitfalls/lists.md +117 -0
  212. package/assets/pitfalls/navigation.md +94 -0
  213. package/assets/pitfalls/reuse-first.md +201 -0
  214. package/assets/pitfalls/spec-driven.2.md +318 -0
  215. package/assets/pitfalls/spec-driven.md +9 -7
  216. package/assets/pitfalls/styling-bem.2.md +125 -0
  217. package/assets/pitfalls/task-flow-archive.md +264 -0
  218. package/assets/pitfalls/task-flow-close.2.md +165 -0
  219. package/assets/pitfalls/task-flow-close.md +167 -0
  220. package/assets/pitfalls/task-flow-cycle.md +73 -0
  221. package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
  222. package/assets/pitfalls/task-flow-handoff.md +200 -0
  223. package/assets/pitfalls/task-flow-handover.md +30 -0
  224. package/assets/pitfalls/task-flow-owner.md +29 -0
  225. package/assets/pitfalls/task-flow-plan.md +29 -0
  226. package/assets/pitfalls/task-flow-resume.md +257 -0
  227. package/assets/pitfalls/task-flow-start.md +287 -0
  228. package/assets/pitfalls/task-flow.2.md +303 -0
  229. package/assets/pitfalls/task-flow.md +18 -29
  230. package/assets/pitfalls/testing.2.md +279 -0
  231. package/assets/pitfalls/testing.md +11 -12
  232. package/assets/pitfalls/turn-conduct.md +17 -18
  233. package/assets/pitfalls/typescript-conventions.md +161 -0
  234. package/assets/pitfalls/write-a-skill.md +128 -0
  235. package/assets/rules/angular-patterns.md +21 -86
  236. package/assets/rules/autonomous-work.md +37 -29
  237. package/assets/rules/browser-verification.md +28 -251
  238. package/assets/rules/component-structure.md +25 -87
  239. package/assets/rules/dependencies.md +20 -78
  240. package/assets/rules/deploy-flow.azure.md +27 -134
  241. package/assets/rules/deploy-flow.github.md +34 -196
  242. package/assets/rules/deploy-flow.gitlab.md +28 -137
  243. package/assets/rules/doc-style.md +32 -282
  244. package/assets/rules/entity-conventions.needs-admin.md +26 -82
  245. package/assets/rules/entity-models.md +14 -63
  246. package/assets/rules/epic-flow.md +5 -3
  247. package/assets/rules/git-workflow-hosting.azure.md +26 -0
  248. package/assets/rules/git-workflow-hosting.github.md +38 -0
  249. package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
  250. package/assets/rules/git-workflow-push.azure.md +28 -0
  251. package/assets/rules/git-workflow-push.github.md +28 -0
  252. package/assets/rules/git-workflow-push.gitlab.md +28 -0
  253. package/assets/rules/git-workflow-queue.azure.md +23 -0
  254. package/assets/rules/git-workflow-queue.github.md +30 -0
  255. package/assets/rules/git-workflow-queue.gitlab.md +23 -0
  256. package/assets/rules/git-workflow.azure.md +21 -264
  257. package/assets/rules/git-workflow.github.md +24 -285
  258. package/assets/rules/git-workflow.gitlab.md +21 -258
  259. package/assets/rules/lib-layers.md +30 -103
  260. package/assets/rules/lists.md +21 -105
  261. package/assets/rules/navigation.md +10 -69
  262. package/assets/rules/queue-audit.github.md +5 -3
  263. package/assets/rules/reuse-first.md +20 -195
  264. package/assets/rules/spec-driven.md +35 -316
  265. package/assets/rules/status-report.md +5 -3
  266. package/assets/rules/styling-bem.md +20 -117
  267. package/assets/rules/task-flow-handover.md +24 -0
  268. package/assets/rules/task-flow-owner.md +34 -0
  269. package/assets/rules/task-flow-plan.md +38 -0
  270. package/assets/rules/task-flow.md +22 -289
  271. package/assets/rules/testing.md +32 -270
  272. package/assets/rules/turn-conduct.md +109 -111
  273. package/assets/rules/turn-entry.md +2 -2
  274. package/assets/rules/typescript-conventions.md +41 -147
  275. package/assets/samples/tasks/_template/plan.md +30 -6
  276. package/assets/samples/tasks/_template/progress.md +0 -1
  277. package/assets/skills/agent-kit-extend.md +25 -168
  278. package/assets/skills/agent-kit.md +27 -299
  279. package/assets/skills/write-a-skill.md +20 -106
  280. package/assets/task-flow/flow.js +188 -0
  281. package/assets/task-flow/flow.md +102 -0
  282. package/assets/task-flow/measure/agreement.mjs +24 -0
  283. package/assets/task-flow/measure/copy.mjs +22 -0
  284. package/assets/task-flow/measure/epic-of.mjs +50 -0
  285. package/assets/task-flow/measure/epic-text.mjs +35 -0
  286. package/assets/task-flow/measure/epic.mjs +114 -0
  287. package/assets/task-flow/measure/folder.mjs +16 -0
  288. package/assets/task-flow/measure/footprint.mjs +28 -0
  289. package/assets/task-flow/measure/grill.mjs +21 -0
  290. package/assets/task-flow/measure/host.mjs +8 -0
  291. package/assets/task-flow/measure/owner.mjs +20 -0
  292. package/assets/task-flow/measure/plan.mjs +27 -0
  293. package/assets/task-flow/measure/pr.mjs +20 -0
  294. package/assets/task-flow/measure/progress.mjs +50 -0
  295. package/assets/task-flow/measure/session.mjs +175 -0
  296. package/assets/task-flow/measure/task.mjs +23 -0
  297. package/assets/task-flow/measure/text.mjs +77 -0
  298. package/assets/task-flow/source/git.mjs +86 -0
  299. package/assets/task-flow/source/host.mjs +172 -0
  300. package/assets/task-flow/source/marks.mjs +56 -0
  301. package/assets/task-flow/source/owner.mjs +74 -0
  302. package/assets/task-flow/source/records.mjs +116 -0
  303. package/assets/task-flow/source/session.mjs +232 -0
  304. package/assets/task-flow/source/steps.mjs +28 -0
  305. package/assets/task-flow/source/tree.mjs +42 -0
  306. package/assets/templates/rule.md +2 -2
  307. package/bin/agent-kit.d.ts.map +1 -1
  308. package/bin/agent-kit.js +30 -0
  309. package/bin/agent-kit.js.map +1 -1
  310. package/lib/agent-checks.d.ts +55 -0
  311. package/lib/agent-checks.d.ts.map +1 -0
  312. package/lib/agent-checks.js +209 -0
  313. package/lib/agent-checks.js.map +1 -0
  314. package/lib/assets.d.ts.map +1 -1
  315. package/lib/assets.js +7 -2
  316. package/lib/assets.js.map +1 -1
  317. package/lib/cargo-prose.d.ts +2 -1
  318. package/lib/cargo-prose.d.ts.map +1 -1
  319. package/lib/cargo-prose.js.map +1 -1
  320. package/lib/cargo.d.ts +29 -0
  321. package/lib/cargo.d.ts.map +1 -1
  322. package/lib/cargo.js +27 -1
  323. package/lib/cargo.js.map +1 -1
  324. package/lib/cascade.d.ts.map +1 -1
  325. package/lib/cascade.js +3 -1
  326. package/lib/cascade.js.map +1 -1
  327. package/lib/commands.d.ts.map +1 -1
  328. package/lib/commands.js +78 -2
  329. package/lib/commands.js.map +1 -1
  330. package/lib/companion.d.ts +0 -5
  331. package/lib/companion.d.ts.map +1 -1
  332. package/lib/companion.js +1 -1
  333. package/lib/companion.js.map +1 -1
  334. package/lib/config.d.ts +18 -0
  335. package/lib/config.d.ts.map +1 -1
  336. package/lib/config.js +18 -1
  337. package/lib/config.js.map +1 -1
  338. package/lib/cost.d.ts +0 -8
  339. package/lib/cost.d.ts.map +1 -1
  340. package/lib/cost.js +4 -4
  341. package/lib/cost.js.map +1 -1
  342. package/lib/epic-window-send.d.ts +74 -0
  343. package/lib/epic-window-send.d.ts.map +1 -0
  344. package/lib/epic-window-send.js +166 -0
  345. package/lib/epic-window-send.js.map +1 -0
  346. package/lib/hooks-map.d.ts +4 -12
  347. package/lib/hooks-map.d.ts.map +1 -1
  348. package/lib/hooks-map.js +4 -27
  349. package/lib/hooks-map.js.map +1 -1
  350. package/lib/integrity.d.ts +3 -0
  351. package/lib/integrity.d.ts.map +1 -1
  352. package/lib/integrity.js +7 -0
  353. package/lib/integrity.js.map +1 -1
  354. package/lib/metric-lines.d.ts +2 -1
  355. package/lib/metric-lines.d.ts.map +1 -1
  356. package/lib/metric-lines.js +49 -1
  357. package/lib/metric-lines.js.map +1 -1
  358. package/lib/metric-send-mark.d.ts +6 -3
  359. package/lib/metric-send-mark.d.ts.map +1 -1
  360. package/lib/metric-send-mark.js +15 -5
  361. package/lib/metric-send-mark.js.map +1 -1
  362. package/lib/metric-send.d.ts +6 -2
  363. package/lib/metric-send.d.ts.map +1 -1
  364. package/lib/metric-send.js +47 -13
  365. package/lib/metric-send.js.map +1 -1
  366. package/lib/metrics.d.ts +17 -0
  367. package/lib/metrics.d.ts.map +1 -1
  368. package/lib/metrics.js +26 -15
  369. package/lib/metrics.js.map +1 -1
  370. package/lib/observations-cargo.d.ts +1 -5
  371. package/lib/observations-cargo.d.ts.map +1 -1
  372. package/lib/observations-cargo.js +2 -2
  373. package/lib/observations-cargo.js.map +1 -1
  374. package/lib/observations.d.ts +0 -2
  375. package/lib/observations.d.ts.map +1 -1
  376. package/lib/observations.js +3 -3
  377. package/lib/observations.js.map +1 -1
  378. package/lib/order.d.ts +0 -2
  379. package/lib/order.d.ts.map +1 -1
  380. package/lib/order.js +0 -4
  381. package/lib/order.js.map +1 -1
  382. package/lib/outcomes.d.ts +7 -9
  383. package/lib/outcomes.d.ts.map +1 -1
  384. package/lib/outcomes.js +8 -7
  385. package/lib/outcomes.js.map +1 -1
  386. package/lib/proposals.d.ts +0 -1
  387. package/lib/proposals.d.ts.map +1 -1
  388. package/lib/proposals.js +1 -1
  389. package/lib/proposals.js.map +1 -1
  390. package/lib/push-gate.d.ts +13 -0
  391. package/lib/push-gate.d.ts.map +1 -1
  392. package/lib/push-gate.js +11 -7
  393. package/lib/push-gate.js.map +1 -1
  394. package/lib/push-set-usefulness.d.ts +78 -0
  395. package/lib/push-set-usefulness.d.ts.map +1 -0
  396. package/lib/push-set-usefulness.js +225 -0
  397. package/lib/push-set-usefulness.js.map +1 -0
  398. package/lib/shipment.d.ts +2 -11
  399. package/lib/shipment.d.ts.map +1 -1
  400. package/lib/shipment.fixture.d.ts +0 -3
  401. package/lib/shipment.fixture.d.ts.map +1 -1
  402. package/lib/shipment.fixture.js +3 -3
  403. package/lib/shipment.fixture.js.map +1 -1
  404. package/lib/shipment.js +2 -2
  405. package/lib/shipment.js.map +1 -1
  406. package/lib/sync.d.ts +10 -0
  407. package/lib/sync.d.ts.map +1 -1
  408. package/lib/sync.js +14 -1
  409. package/lib/sync.js.map +1 -1
  410. package/lib/traits.d.ts +0 -3
  411. package/lib/traits.d.ts.map +1 -1
  412. package/lib/traits.js +2 -2
  413. package/lib/traits.js.map +1 -1
  414. package/lib/variants.d.ts +0 -1
  415. package/lib/variants.d.ts.map +1 -1
  416. package/lib/variants.js +1 -1
  417. package/lib/variants.js.map +1 -1
  418. package/lib/work-result.d.ts +43 -0
  419. package/lib/work-result.d.ts.map +1 -0
  420. package/lib/work-result.js +39 -0
  421. package/lib/work-result.js.map +1 -0
  422. package/package.json +1 -1
  423. package/assets/checks/signals/ui-kit.json +0 -11
  424. package/assets/hooks/claim-guard.sh +0 -212
  425. package/assets/hooks/grill-gate-ask.sh +0 -26
  426. package/assets/hooks/grill-gate-bypass.sh +0 -61
  427. package/assets/hooks/grill-gate-options.sh +0 -50
  428. package/assets/hooks/grill-gate.sh +0 -482
  429. package/assets/hooks/postmortem-guard.sh +0 -124
  430. package/assets/hooks/proposal-guard.sh +0 -154
  431. package/assets/hooks/stand-login-guard.sh +0 -107
  432. package/assets/hooks/turn-exit-epic.sh +0 -173
  433. package/assets/hooks/turn-exit-patterns.sh +0 -123
  434. package/assets/hooks/turn-exit-verdict.sh +0 -149
  435. package/assets/hooks/waiting-turn-guard.sh +0 -320
  436. package/assets/hooks/work-start-guard.sh +0 -175
@@ -1,482 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh, hooks/grill-gate-options.sh
3
- # rt-hook: Stop
4
- # The conversation guard: the owner is not asked a question until the laws and rules have been read
5
- # within the same turn. It judges two events, and that is not duplication; the second is declared
6
- # by the neighbouring resource `hooks/grill-gate-ask.sh`, which hands the call over here.
7
- #
8
- # Why exactly this way. The requirement "the rules are read before the conversation" is enforceable
9
- # right up to the moment the question is sent. A check at the turn end refuses after the fact: by
10
- # the time of the refusal the question is already with the owner, and the owner sees it together
11
- # with the refused turn — the requirement fires, but it does not save the work. So a turn with a
12
- # question is judged on the question tool, before sending.
13
- #
14
- # This one interception does not close the hole: a question is more often asked in prose, and that
15
- # is exactly how the one that brought this guard about was asked. A prose question is not a tool,
16
- # and it can be caught only at the turn end — the event gets the path to the turn record and sees
17
- # the turn whole. Hence two events: the menu is caught before sending, prose after. They are
18
- # declared by different resources so that a tree whose question tool is already taken by a guard of
19
- # its own can take one half instead of dropping the requirement whole.
20
- #
21
- # Reading the rules counts as any of three paths: loading a rule, reading a file of the laws or the
22
- # rules, searching through them. To demand loading exactly would drive the executor to it where one
23
- # search was enough — the guard would hinder the work instead of straightening it.
24
- #
25
- # But reading anything at all from the rules layer does not close the question: an incident
26
- # analysis someone else read and a search over the catalog counted on a par with the rule this work
27
- # actually needs — and the answer to the question put to the owner lay exactly in that rule. So,
28
- # when the area of this turn's work is known, only the rule of that area counts as reading. The
29
- # area is taken from where the rules gate takes it: from the paths edited in the turn.
30
- #
31
- # FAIL-OPEN here too: there are no edits in the turn, there is no gate map, the area did not come
32
- # out — any reading counts, as before.
33
- #
34
- # FAIL-OPEN: on any error, with no turn record and on a repeat pass the turn is ALLOWED (exit 0).
35
- # A broken guard has no right to jam the conversation.
36
-
37
- # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
38
- RT_GUARD_NAME=grill-gate
39
- RT_GUARD_RULE=task-flow
40
-
41
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
42
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
43
-
44
- rt_hook_read
45
- input="$RT_HOOK_INPUT"
46
- [ -z "$input" ] && exit 0
47
-
48
- command -v jq >/dev/null 2>&1 || exit 0
49
-
50
- # Which event arrived. A tool call has its name, the turn end does not.
51
- tool="$(rt_hook_tool)"
52
-
53
- # A repeat pass over the same turn is not judged: otherwise the turn would never end — the guard
54
- # said its piece once and lets go. This does not apply to a tool call: there the call itself is
55
- # judged.
56
- active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
57
- [ -z "$tool" ] && [ "$active" = "true" ] && exit 0
58
-
59
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
60
- [ -z "$transcript" ] && exit 0
61
- [ -f "$transcript" ] || exit 0
62
-
63
- # The tree profile: the directories of laws, rules and specs differ from tree to tree, and they are
64
- # needed both for the sign of reading and for the hint in the refusal.
65
- rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
- for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
67
- # shellcheck disable=SC1090
68
- [ -f "$profile" ] && . "$profile" 2>/dev/null
69
- done
70
-
71
- # Substitution without a colon is deliberate: set to empty means the tree drops the requirement,
72
- # and that must not be replaced by a default. The default goes only to the one who did not set the
73
- # variable at all.
74
- laws_dir="${RT_LAWS_DIR-docs/constitution}"
75
- rules_dir="${RT_RULES_DIR-.claude/skills}"
76
- specs_dir="${RT_SPECS_DIR-docs/specs}"
77
- # The plan of an epic and the archive are read on a par with the laws: the decision that ties the
78
- # tasks of an epic together lies exactly there. Whoever had read the plan was refused on a par with
79
- # whoever had read nothing, and that refusal was lifted by a search over three directories among
80
- # which the needed one was not.
81
- plans_dir="${RT_PLANS_DIR-docs/plans}"
82
- archive_dir="${RT_ARCHIVE_DIR-docs/archive}"
83
-
84
- # A tree that has neither laws nor rules gets no requirement: there is nothing to read.
85
- [ -z "$laws_dir" ] && [ -z "$rules_dir" ] && exit 0
86
-
87
- # The gate map: by it the rule name is got from the edit path. There is none — the area does not
88
- # come out, and everything stays as before.
89
- rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
90
- for map in "$rt_hooks_dir/../rt-kit/defaults/gate-map.sh" "$rt_hooks_dir/../defaults/gate-map.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/gate-map.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/gate-map.sh"; do
91
- # shellcheck disable=SC1090
92
- [ -f "$map" ] && . "$map" 2>/dev/null
93
- done
94
-
95
- # The pattern by which a tool call counts as reading the rules. The directories go into it as they
96
- # are: the dot in `.claude` matches any character and brings nothing extra here.
97
- read_re="$(printf '%s' "$laws_dir|$rules_dir|$specs_dir|$plans_dir|$archive_dir" | sed 's/^|*//; s/|*$//; s/||*/|/g')"
98
- [ -z "$read_re" ] && exit 0
99
-
100
- # The area of this turn's work: the rules the gate demands of the paths edited in the turn. The
101
- # paths are got by the same parse of the turn as below — by a call of its own, so that the reading
102
- # pattern is ready for the main parse.
103
- need_re=''
104
- if command -v skill_for >/dev/null 2>&1 && [ -n "$rules_dir" ]; then
105
- edited="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
106
- def is_input:
107
- .type == "user"
108
- and ((.isCompactSummary // false) | not)
109
- and ((.isMeta // false) | not)
110
- and (((.message.content // []) | if type == "array"
111
- then ([.[] | select(.type == "tool_result")] | length)
112
- else 0 end) == 0);
113
- (map(is_input) | rindex(true)) as $i
114
- | (if $i == null then . else .[$i + 1:] end)
115
- | [.[] | select(.type == "assistant") | (.message.content // [])[]
116
- | select(.type == "tool_use") | select(.name == "Edit" or .name == "Write" or .name == "NotebookEdit")
117
- | (.input.file_path // .input.notebook_path // "")]
118
- | map(select(. != "")) | unique | .[]
119
- ' 2>/dev/null)"
120
- for path in $edited; do
121
- # Only this tree's paths make up the area: a draft in the session scratch directory is not
122
- # work of this tree, and the rule its kind maps to answers no question put to the owner. The
123
- # rules gate stops at the same root check; a relative path is a path of the tree.
124
- case "$path" in
125
- /*)
126
- case "$path" in
127
- "${CLAUDE_PROJECT_DIR:-$PWD}"/*) ;;
128
- *) continue ;;
129
- esac
130
- ;;
131
- esac
132
- for rule in $(skill_for edit "$path" '' 2>/dev/null); do
133
- case "|$need_re|" in
134
- *"|$rule|"*) ;;
135
- *) need_re="${need_re}${need_re:+|}${rule}" ;;
136
- esac
137
- done
138
- done
139
- fi
140
-
141
- # A turn is everything recorded after the last real input from the owner. A tool answer comes in
142
- # under the same `user` role, so lines with `tool_result` do not count as input: otherwise the turn
143
- # would be the piece after the last tool call, and reading the rules at its start would be lost.
144
- # The text of a loaded rule and the report of a subagent come in under that role too, marked
145
- # `isMeta`. Taken for input, a rule loaded right before a question cut the turn after its own
146
- # loading, and its text stood as the owner's last reply.
147
- #
148
- # A tail of 400 lines: the turn record grows all session, and only the last turn is judged.
149
- # On the tool call event the question is already known — it is the call; only whether the rules
150
- # were read within this turn is judged. At the turn end the question is looked for in the text of
151
- # the replies: the menu has by then already been refused earlier.
152
- verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re" --arg tool "$tool" --arg need "$need_re" --arg rules "$rules_dir" '
153
- def is_input:
154
- .type == "user"
155
- and ((.isCompactSummary // false) | not)
156
- and ((.isMeta // false) | not)
157
- and (((.message.content // []) | if type == "array"
158
- then ([.[] | select(.type == "tool_result")] | length)
159
- else 0 end) == 0);
160
-
161
- (map(is_input) | rindex(true)) as $i
162
- | (if $i == null then . else .[$i + 1:] end) as $turn
163
- | [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text] as $texts
164
- | [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")] as $uses
165
- | (if $need == "" then
166
- $uses | map(
167
- (.name == "Skill")
168
- or ((.name // "") | test("^(Read|Grep|Glob)$")) and ((.input | tostring) | test($re))
169
- or ((.name == "Bash") and ((.input.command // "") | test($re)))
170
- ) | any
171
- else
172
- # The area of the work is known — only the rule of that area counts: an incident
173
- # analysis someone else read does not answer the question that was asked.
174
- ($need | split("|")) as $rules_needed
175
- | $uses | map(
176
- ((.name == "Skill") and (((.input.skill // "") | tostring) as $s | $rules_needed | index($s) != null))
177
- or (((.name // "") | test("^(Read|Grep|Glob|Bash)$"))
178
- and ((.input | tostring) as $text
179
- | $rules_needed | map(. as $rule | $text | test($rules + "/" + $rule + "(/|\\b)")) | any))
180
- ) | any
181
- end) as $read
182
- | (($texts | join("\n")) | test("\\?[[:space:]]*$"; "m")) as $asked_prose
183
- | ($tool != "") as $asking_now
184
- | if ($asked_prose or $asking_now) and ($read | not) then "ask" else "pass" end
185
- ' 2>/dev/null)"
186
-
187
- # The second sign of the same guard: the owner has already answered this question.
188
- #
189
- # The first sign judges whether the rules were read, and stays silent on work that is allowed. But
190
- # the miss can be another one: the owner gave an instruction in a direct reply, the executor found
191
- # a fact that changes the price of the instruction but not its meaning — and instead of a line
192
- # about the price asked a menu where two options out of three offered to cancel the owner's
193
- # decision. The work stopped until an answer, having been allowed a minute earlier.
194
- #
195
- # What is judged is the overlap of words: the question going out now against the owner's last reply
196
- # — and only where the record already holds a call of the question tool, that is, the owner has
197
- # answered a question. There is no understanding of the text here and none is needed: three shared
198
- # significant words mean the same subject, while a grill of six questions runs over different
199
- # subjects and does not reach the threshold.
200
- #
201
- # FAIL-OPEN: no question in the call, no reply from the owner, no earlier question — the sign stays
202
- # silent.
203
- if [ -n "$tool" ]; then
204
- # The words are taken from what the owner reads — the question, the options and their
205
- # descriptions — and not from the serialised menu: its keys `question`, `label` and
206
- # `description` stand in every call and matched any English text by two words of the three.
207
- asked_text="$(printf '%s' "$input" | jq -r '[(.tool_input.questions // [])[]
208
- | (.question // ""), ((.options // [])[] | (.label // ""), (.description // ""))] | join(" ")' 2>/dev/null)"
209
- seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_text" '
210
- def is_input:
211
- .type == "user"
212
- and ((.isCompactSummary // false) | not)
213
- and ((.isMeta // false) | not)
214
- and (((.message.content // []) | if type == "array"
215
- then ([.[] | select(.type == "tool_result")] | length)
216
- else 0 end) == 0);
217
-
218
- def words: [splits("[^\\p{L}\\p{N}]+")] | map(select(length >= 5)) | unique;
219
-
220
- (map(is_input) | rindex(true)) as $i
221
- | if $i == null then "no" else
222
- (.[$i] | (.message.content // []) | if type == "array"
223
- then ([.[] | select(.type == "text") | .text] | join(" "))
224
- else (. // "") end) as $said
225
- | ([.[:$i][] | select(.type == "assistant") | (.message.content // [])[]
226
- | select(.type == "tool_use") | select(.name == "AskUserQuestion")] | length) as $before
227
- # A reply of fewer than five significant words is a command, not a decision: «take task
228
- # N» shares the number and the words of the subject with any next question about it.
229
- | if $before == 0 or (($said | words) | length) < 5 then "no" else
230
- (($now | words) - (($now | words) - ($said | words))) as $common
231
- | if ($common | length) >= 3 then "answered" else "no" end
232
- end
233
- end
234
- ' 2>/dev/null)"
235
-
236
- if [ "$seen" = "answered" ]; then
237
- reason="BLOCKED by grill-gate: the owner has already answered this question in this conversation — go on with the work instead of asking again.
238
-
239
- An instruction of the owner holds until they cancel it. A new fact against a standing instruction is a line in the reply about the price, not a new question: what is asked again is only what the instruction does not cover. The miss here is not in the form of the question but in stopping work that is already allowed.
240
-
241
- The question really is about another matter — then name in it what the former answer of the owner lacks: the sign judges the shared words of the question and of the last message of the owner, not the meaning."
242
-
243
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the
244
- # refusal has one.
245
- # shellcheck disable=SC1090
246
- [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
247
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
248
- deny_tail_text="$(rt_deny_tail "")"
249
- [ -n "$deny_tail_text" ] && reason="${reason}
250
-
251
- ${deny_tail_text}"
252
-
253
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
254
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: this question has already been answered."}}\n'
255
- exit 0
256
- fi
257
- fi
258
-
259
- # The third sign of the same guard: the owner answered the recommended option twice in a row.
260
- #
261
- # Every menu carries a recommended option, and an owner who takes it twice running has shown that
262
- # the decisions are not theirs: the questions are answered by the tree, and the menu only asks them
263
- # to confirm it. A grill went on to a fifth menu after four such answers, and the owner closed it
264
- # with the name of a ready-made module that answered all five. From the second answer on, the
265
- # remaining questions are closed by an assumption written into the grill, and the owner gets the
266
- # list in one line — not a menu.
267
- #
268
- # What is judged is the record of the question tool: the last two of its answers, each with every
269
- # option taken marked as recommended. Any other answer breaks the streak, and a menu after it goes
270
- # out as usual. The mark is the word the menu itself carries, in either language of the tree.
271
- #
272
- # FAIL-OPEN: fewer than two answers in the record, no record, no parser — the sign stays silent.
273
- if [ -n "$tool" ]; then
274
- streak="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
275
- def answer_texts: [.[] | select(.type == "user") | (.message.content // [])
276
- | select(type == "array") | .[] | select(.type == "tool_result") | .content
277
- | if type == "string" then . elif type == "array"
278
- then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
279
- | select(test("^(The user answered|Your questions have been answered):"))];
280
- def recommended: ([match("\"=\"[^\"]*\""; "g")] | length) as $all
281
- | ([match("\\((Recommended|Рекомендую|Рекомендован[^)]*)\\)\"(,|\\.|[[:space:]]|$)"; "g")] | length) as $marked
282
- | $all > 0 and $all == $marked;
283
- (answer_texts) as $answers
284
- | if ($answers | length) < 2 then "no"
285
- elif ($answers[-1] | recommended) and ($answers[-2] | recommended) then "streak"
286
- else "no" end
287
- ' 2>/dev/null)"
288
-
289
- if [ "$streak" = "streak" ]; then
290
- reason="BLOCKED by grill-gate: the owner took the recommended option on the last two menus in a row — the remaining questions are closed by assumption, not by a menu.
291
-
292
- Two answers «recommended» running say the decisions are not the owner's: the tree answers these questions, and the menu only asks them to confirm it. Write what is taken into the grill as decisions, name the list to the owner in one line, and go on with the work. Before that, look for a ready-made module of the same kind — in this tree and in the trees recorded as samples: one grill of five menus was closed by the owner naming such a module.
293
-
294
- A menu goes out again only for a question no assumption closes, and it says so in its first line."
295
-
296
- # shellcheck disable=SC1090
297
- [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
298
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
299
- deny_tail_text="$(rt_deny_tail "")"
300
- [ -n "$deny_tail_text" ] && reason="${reason}
301
-
302
- ${deny_tail_text}"
303
-
304
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
305
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: two recommended answers in a row close the remaining questions by assumption."}}\n'
306
- exit 0
307
- fi
308
- fi
309
-
310
- # The fifth sign of the same guard: a question that offers to walk around a check does not leave.
311
- #
312
- # A red set was explained by a "foreign" cause, and the owner was asked whether to send it past the
313
- # check. Such a question is a miss by itself, even when the owner answers "yes": a check is fixed at
314
- # its cause or fixed itself, and a third option is not named. The sign reads the text the owner
315
- # reads — the menu with its options, or the last reply when it ends with a question — and looks for
316
- # the forms of a bypass: past the check, a bypass line, a disabled rule, a hook switched off.
317
- #
318
- # The sign lies in a file of its own next to the guard; without it the sign stays silent.
319
- # shellcheck disable=SC1090
320
- [ -f "$rt_hooks_dir/grill-gate-bypass.sh" ] && . "$rt_hooks_dir/grill-gate-bypass.sh" 2>/dev/null
321
- command -v rt_grill_bypass >/dev/null 2>&1 && rt_grill_bypass && exit 0
322
-
323
- # The fourth sign of the same guard: a question after a refusal carries what was done without the
324
- # answer.
325
- #
326
- # A guard refused, the executor ran not one edit and brought the owner a choice "fix or wait". A
327
- # question is a lawful exit of a turn, so no guard held it, and the owner asked why the work stopped.
328
- # A refusal removes the step, not the task: the mechanical part of the blocker is done first. So a
329
- # question after a refusal leaves only with the line the tree names, and with at least one working
330
- # command after the last refusal — an edit of a file or a command by the work pattern of the exit
331
- # guard. A read or a status command does not count: it looks like work and moves nothing.
332
- #
333
- # The menu and a question in prose are judged alike: one change of form would otherwise walk around
334
- # the requirement. A turn without a refusal is not judged by this sign.
335
- #
336
- # The line is written in the language the tree speaks to its owner: the tree names it by
337
- # `RT_DONE_WITHOUT_ANSWER` in its profile, and set empty it drops the sign.
338
- #
339
- # FAIL-OPEN: no turn record, no parser, no refusal in the turn — the sign stays silent.
340
- done_marker="${RT_DONE_WITHOUT_ANSWER-Без ответа сделано:}"
341
- work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
342
- # shellcheck disable=SC1090
343
- [ -f "$rt_hooks_dir/turn-exit-patterns.sh" ] && . "$rt_hooks_dir/turn-exit-patterns.sh" 2>/dev/null
344
- if [ -n "$done_marker" ]; then
345
- after_refusal="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re" '
346
- def is_input:
347
- .type == "user"
348
- and ((.isCompactSummary // false) | not)
349
- and ((.isMeta // false) | not)
350
- and (((.message.content // []) | if type == "array"
351
- then ([.[] | select(.type == "tool_result")] | length)
352
- else 0 end) == 0);
353
- def refusal:
354
- .type == "user" and ((.message.content // []) | if type == "array"
355
- then any(.[]; .type == "tool_result" and (.is_error // false)
356
- and ((.content | if type == "string" then . elif type == "array"
357
- then (map(if type == "object" then (.text // "") else "" end) | join(" "))
358
- else "" end) | test("BLOCKED|Refused|denied")))
359
- else false end);
360
- def working:
361
- .type == "assistant" and ((.message.content // []) | any(.[];
362
- .type == "tool_use" and (
363
- ((.name // "") | test("^(Edit|Write|NotebookEdit)$"))
364
- or ((.name == "Bash") and ((.input.command // "") | test($work))))));
365
-
366
- (map(is_input) | rindex(true)) as $i
367
- | (if $i == null then . else .[$i + 1:] end) as $turn
368
- | ($turn | map(refusal) | rindex(true)) as $r
369
- | if $r == null then "none"
370
- elif ($turn[$r + 1:] | map(working) | any) then "worked"
371
- else "idle" end
372
- ' 2>/dev/null)"
373
-
374
- if [ "$after_refusal" = "worked" ] || [ "$after_refusal" = "idle" ]; then
375
- if [ -n "$tool" ]; then
376
- question_text="$asked_text"
377
- else
378
- question_text="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
379
- def is_input:
380
- .type == "user"
381
- and ((.isCompactSummary // false) | not)
382
- and ((.isMeta // false) | not)
383
- and (((.message.content // []) | if type == "array"
384
- then ([.[] | select(.type == "tool_result")] | length)
385
- else 0 end) == 0);
386
- (map(is_input) | rindex(true)) as $i
387
- | (if $i == null then . else .[$i + 1:] end)
388
- | [.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text]
389
- | join("\n")
390
- ' 2>/dev/null)"
391
- fi
392
- # After a refused menu a list of options in prose is a question too: the helper next door.
393
- # shellcheck disable=SC1090
394
- [ -f "$rt_hooks_dir/grill-gate-options.sh" ] && . "$rt_hooks_dir/grill-gate-options.sh" 2>/dev/null
395
- asks="no"
396
- if [ -n "$tool" ]; then
397
- asks="yes"
398
- elif printf '%s\n' "$question_text" | grep -qE '\?[[:space:]]*$'; then
399
- asks="yes"
400
- elif command -v rt_grill_options_asked >/dev/null 2>&1 && rt_grill_options_asked; then
401
- asks="yes"
402
- fi
403
- marked="no"
404
- case "$question_text" in
405
- *"$done_marker"*) marked="yes" ;;
406
- esac
407
- if [ "$asks" = "yes" ] && { [ "$marked" = "no" ] || [ "$after_refusal" = "idle" ]; }; then
408
- reason="BLOCKED by grill-gate: a guard refused in this turn, and the question to the owner carries nothing done without the answer.
409
-
410
- A refusal removes the step, not the task. Do the mechanical part of the blocker first — what the linter's fix mode repairs, what the refusal names as fixable — then ask only the decision that is left. The question leaves with the line «$done_marker …» naming the working commands of this turn after the last refusal: an edit of a file or a command that changes the tree. A read or a status command does not count."
411
- [ -n "$tool" ] && reason="${reason}
412
-
413
- The same question in prose does not walk around this refusal: the menu and prose are judged alike, a list of options included. Fix the menu — add the line and a working command — and send it again."
414
-
415
- # shellcheck disable=SC1090
416
- [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
417
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
418
- deny_tail_text="$(rt_deny_tail "")"
419
- [ -n "$deny_tail_text" ] && reason="${reason}
420
-
421
- ${deny_tail_text}"
422
-
423
- if [ -n "$tool" ]; then
424
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
425
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: a question after a refusal carries what was done without the answer."}}\n'
426
- else
427
- jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
428
- || printf '{"decision":"block","reason":"grill-gate: a question after a refusal carries what was done without the answer."}\n'
429
- fi
430
- exit 0
431
- fi
432
- fi
433
- fi
434
-
435
- [ "$verdict" = "ask" ] || exit 0
436
-
437
- if [ -n "$tool" ]; then
438
- head="BLOCKED by grill-gate: the question to the owner has not left yet, and this is the only moment when the requirement can be met."
439
- else
440
- head="BLOCKED by grill-gate: the reply carries a question to the owner, and the laws and rules were not read in this turn."
441
- fi
442
-
443
- # The refusal names the action its own condition accepts. When the turn holds edits, only the rules
444
- # of their area count, and the advice to search the directories sent the executor round in a
445
- # circle: the search was made, the same refusal came back, and the executor stopped asking at all.
446
- if [ -n "$need_re" ]; then
447
- named="$(printf '%s' "$need_re" | tr '|' '\n' | sed 's/.*/«&»/' | paste -sd ',' - | sed 's/,/, /g')"
448
- reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. The turn holds edits, and for them only the rules of their area count: $named. A search over the specs or over other rules does not lift this refusal. The area counts every edit since the owner's last message, the stretch before a context compaction included. Load them by the tool Skill, or read them in $rules_dir, and answer from what is found; ask only what they do not cover.
449
-
450
- A rule loaded before the owner's last message does not count: the guard judges one turn, and the next session is not refused."
451
- else
452
- reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. Run a search by the words of the subject and answer from what is found; ask only what the documents do not cover:
453
-
454
- grep -rn -i \"<a word of the subject>\" $laws_dir $rules_dir $specs_dir $plans_dir $archive_dir
455
-
456
- The guard judges one turn: the next session is not refused."
457
- fi
458
-
459
- # The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
460
- # The file may not be laid out — then there is no tail, and the reason for the refusal stays as it
461
- # was.
462
- # shellcheck disable=SC1090
463
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
464
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
465
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
466
- deny_tail_text="$(rt_deny_tail "")"
467
- [ -n "$deny_tail_text" ] && reason="${reason}
468
-
469
- ${deny_tail_text}"
470
-
471
- # The form of the refusal differs between the two events: a tool call is refused by a decision
472
- # about access, and the turn end by a decision about the turn. One form for both events silently
473
- # does not fire.
474
- if [ -n "$tool" ]; then
475
- jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
476
- || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: read the laws and rules on the subject before asking the owner."}}\n'
477
- else
478
- jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
479
- || printf '{"decision":"block","reason":"grill-gate: read the laws and rules on the subject before asking the owner."}\n'
480
- fi
481
-
482
- exit 0
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env bash
2
- # rt-hook: Stop
3
- # Requires: hooks/deny-tail.sh
4
- # Incident guard: a turn in which the executor admitted a miss does not end while there is no
5
- # incident record. Stop.
6
- #
7
- # Why exactly so. An incident — a session in which the executor did the wrong thing and the rules
8
- # layer did not refuse it — leaves no code behind that could be fixed. Such a session ends with an
9
- # apology in the chat: the next day the mechanism of the miss is retold already smoothed over,
10
- # conclusions remain, and no rule follows from conclusions. An analysis happened only when the
11
- # owner demanded it out loud.
12
- #
13
- # The admission is caught by patterns, not by understanding the meaning: the verdict "that was a
14
- # miss" would be given by the one it inconveniences, and the threshold would drift. The pattern
15
- # set is visible, is extended by an edit and misses noticeably — a session that admitted a miss
16
- # in words outside the set is passed by the guard, and this is said out loud in the agreement
17
- # rather than counted as closed.
18
- #
19
- # It is caught at the end of the turn, not on sending the reply: by the moment of the admission
20
- # the miss has already happened, and there is nothing to catch earlier. This sets it apart from
21
- # the conversation guard, which has a tool of its own — a question to the owner.
22
- #
23
- # FAIL-OPEN: on any error, with no turn record and on a repeat pass the turn is ALLOWED (exit 0).
24
- # A broken guard has no right to jam the conversation.
25
-
26
- # Own name in the observations: the refusal is written by the shared refusal tail, not by the
27
- # guard itself.
28
- RT_GUARD_NAME=postmortem-guard
29
-
30
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
31
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
32
-
33
- rt_hook_read
34
- input="$RT_HOOK_INPUT"
35
- [ -z "$input" ] && exit 0
36
-
37
- command -v jq >/dev/null 2>&1 || exit 0
38
-
39
- # A repeat pass over the same turn is not judged: the guard has said its word once and lets go.
40
- active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
41
- [ "$active" = "true" ] && exit 0
42
-
43
- transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
44
- [ -z "$transcript" ] && exit 0
45
- [ -f "$transcript" ] || exit 0
46
-
47
- root="${CLAUDE_PROJECT_DIR:-.}"
48
-
49
- # The records directory is the tree's own, and the tree settings name it — by the same key the
50
- # cargo dispatch reads it with. One name for both sides: a tree that moved the directory out of
51
- # history would otherwise get a guard looking for records at the old address — and it would stay
52
- # silent forever. The variable remains a bypass for one launch, and an empty string in either of
53
- # the two is the tree's refusal of the demand: a tree that keeps no records is not forced to.
54
- if [ -n "${RT_POSTMORTEMS_DIR+set}" ]; then
55
- notes_dir="$RT_POSTMORTEMS_DIR"
56
- elif [ -f "$root/.claude/rt-kit.json" ]; then
57
- notes_dir="$(jq -r '.postmortems // "docs/postmortems"' "$root/.claude/rt-kit.json" 2>/dev/null)"
58
- else
59
- notes_dir="docs/postmortems"
60
- fi
61
- [ -z "$notes_dir" ] && exit 0
62
- [ -d "$root/$notes_dir" ] || exit 0
63
-
64
- # Patterns of admitting a miss. The set is open and is extended by an edit: its completeness is
65
- # an open question of the agreement, not a promise.
66
- admitted_re='был неправ|был не прав|ошибс|моя ошибк|мой промах|промахнул|проглядел|не проверил|соврал|виноват|извин|прошу прощения|неверно утверждал|утверждение было ложн|принял на веру'
67
-
68
- # The turn is everything recorded after the owner's last real input. A tool result arrives under
69
- # the same role, so lines with `tool_result` do not count as input.
70
- #
71
- # A tail of 400 lines: the turn record grows all session long, and only the last turn is judged.
72
- verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$admitted_re" '
73
- def is_input:
74
- .type == "user"
75
- and ((.isCompactSummary // false) | not)
76
- and (((.message.content // []) | if type == "array"
77
- then ([.[] | select(.type == "tool_result")] | length)
78
- else 0 end) == 0);
79
-
80
- (map(is_input) | rindex(true)) as $i
81
- | (if $i == null then . else .[$i + 1:] end) as $turn
82
- | [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text] as $texts
83
- | [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")] as $uses
84
- # The sign is case-insensitive by a flag, not by lowercasing: lowercasing knows only Latin
85
- # letters, and a capitalised "Был неправ" would slip past the pattern set silently.
86
- | (($texts | join("\n")) | test($re; "i")) as $admitted
87
- | ($uses | map(
88
- ((.name // "") | test("^(Write|Edit|MultiEdit)$"))
89
- and ((.input.file_path // "") | test("postmortem"))
90
- ) | any) as $wrote
91
- | if $admitted and ($wrote | not) then "admit" else "pass" end
92
- ' 2>/dev/null)"
93
-
94
- [ "$verdict" = "admit" ] || exit 0
95
-
96
- # A record made during this session lifts the demand even without an edit in this same turn: the
97
- # analysis may have landed as a file a turn earlier — the one in which the miss was admitted.
98
- if [ -n "$(find "$root/$notes_dir" -name '*.md' -newermt '-1 day' 2>/dev/null | head -1)" ]; then
99
- exit 0
100
- fi
101
-
102
- reason="BLOCKED by postmortem-guard: a miss is admitted in the reply, and there is no record of the incident in \`$notes_dir/\` for today. An incident — a session in which the executor did the wrong thing and the rules layer did not refuse it — is written down in that same session: by the next day the mechanism of the miss is retold already smoothed over, and no rule comes out of it.
103
-
104
- The record names: the mechanism of the miss step by step, what was available before it, what caught it and what of this went into the rules layer. Without the last line it is a complaint, not an analysis.
105
-
106
- $notes_dir/<year>-<month>-<day>-<short name>.md
107
-
108
- The guard judges one turn: the next session is not refused."
109
-
110
- # The shared refusal tail: two lawful moves. The file may not be laid out — then there is no
111
- # tail, and the reason for the refusal stays as it was.
112
- # shellcheck disable=SC1090
113
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
114
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
115
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
116
- deny_tail_text="$(rt_deny_tail "")"
117
- [ -n "$deny_tail_text" ] && reason="${reason}
118
-
119
- ${deny_tail_text}"
120
-
121
- jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
122
- || printf '{"decision":"block","reason":"postmortem-guard: a miss is admitted — write the analysis of the incident."}\n'
123
-
124
- exit 0