@rt-tools/agent-kit 0.29.0 → 0.29.2

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 (53) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +128 -9
  2. package/assets/checks/board-epics.github.mjs +6 -10
  3. package/assets/checks/board-folders.mjs +50 -0
  4. package/assets/checks/check-lib-layers.mjs +4 -2
  5. package/assets/checks/check-spec-coverage.mjs +65 -0
  6. package/assets/checks/check-work-steps.mjs +238 -0
  7. package/assets/checks/epic-table.github.mjs +15 -6
  8. package/assets/checks/lib-common.mjs +9 -4
  9. package/assets/checks/lib-domains.mjs +7 -4
  10. package/assets/checks/rt-kit-checks.config.mjs +1 -1
  11. package/assets/checks/task-new.github.mjs +6 -6
  12. package/assets/defaults/project.sh +15 -1
  13. package/assets/hooks/git-guard-delivery-epic.sh +8 -1
  14. package/assets/hooks/git-guard-delivery-tree.sh +63 -16
  15. package/assets/hooks/git-guard-delivery.sh +12 -11
  16. package/assets/hooks/git-guard-no-verify.sh +142 -0
  17. package/assets/hooks/git-guard-push-tests.sh +39 -8
  18. package/assets/hooks/grill-gate.sh +63 -2
  19. package/assets/hooks/prose-style-guard.sh +49 -3
  20. package/assets/hooks/turn-exit-epic.sh +39 -0
  21. package/assets/hooks/turn-exit-guard.sh +6 -4
  22. package/assets/hooks/turn-exit-patterns.sh +51 -0
  23. package/assets/hooks/turn-exit-verdict.sh +20 -1
  24. package/assets/hooks/waiting-turn-guard.sh +56 -1
  25. package/assets/hooks/write-targets.sh +23 -1
  26. package/assets/laws/work-conduct.md +22 -0
  27. package/assets/patterns/doc-style-human.md +6 -0
  28. package/assets/patterns/git-workflow-commit.github.md +4 -0
  29. package/assets/patterns/git-workflow-merge.md +1 -0
  30. package/assets/patterns/git-workflow-pr-body.github.md +10 -5
  31. package/assets/patterns/spec-driven-domain.md +4 -0
  32. package/assets/patterns/status-report-table.github.md +6 -0
  33. package/assets/patterns/task-flow-start.md +27 -23
  34. package/assets/patterns/testing-e2e.md +25 -0
  35. package/assets/pitfalls/turn-conduct.md +28 -0
  36. package/assets/rules/doc-style.md +1 -1
  37. package/assets/rules/git-workflow.github.md +2 -1
  38. package/assets/rules/observability.needs-app.md +5 -0
  39. package/assets/rules/reuse-first.md +33 -11
  40. package/assets/rules/spec-driven.md +3 -1
  41. package/assets/rules/task-flow.md +30 -29
  42. package/assets/rules/testing.md +15 -0
  43. package/assets/rules/turn-conduct.md +44 -46
  44. package/assets/rules/typescript-conventions.md +8 -0
  45. package/assets/samples/tasks/_template/plan.md +7 -1
  46. package/assets/samples/tasks/_template/progress.md +13 -0
  47. package/lib/observations-cargo.d.ts +12 -0
  48. package/lib/observations-cargo.d.ts.map +1 -1
  49. package/lib/observations-cargo.js +18 -1
  50. package/lib/observations-cargo.js.map +1 -1
  51. package/package.json +1 -1
  52. package/rt-tools-agent-kit-0.29.2.tgz +0 -0
  53. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
@@ -105,6 +105,7 @@ if command -v skill_for >/dev/null 2>&1 && [ -n "$rules_dir" ]; then
105
105
  def is_input:
106
106
  .type == "user"
107
107
  and ((.isCompactSummary // false) | not)
108
+ and ((.isMeta // false) | not)
108
109
  and (((.message.content // []) | if type == "array"
109
110
  then ([.[] | select(.type == "tool_result")] | length)
110
111
  else 0 end) == 0);
@@ -128,6 +129,9 @@ fi
128
129
  # A turn is everything recorded after the last real input from the owner. A tool answer comes in
129
130
  # under the same `user` role, so lines with `tool_result` do not count as input: otherwise the turn
130
131
  # would be the piece after the last tool call, and reading the rules at its start would be lost.
132
+ # The text of a loaded rule and the report of a subagent come in under that role too, marked
133
+ # `isMeta`. Taken for input, a rule loaded right before a question cut the turn after its own
134
+ # loading, and its text stood as the owner's last reply.
131
135
  #
132
136
  # A tail of 400 lines: the turn record grows all session, and only the last turn is judged.
133
137
  # On the tool call event the question is already known — it is the call; only whether the rules
@@ -137,6 +141,7 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re"
137
141
  def is_input:
138
142
  .type == "user"
139
143
  and ((.isCompactSummary // false) | not)
144
+ and ((.isMeta // false) | not)
140
145
  and (((.message.content // []) | if type == "array"
141
146
  then ([.[] | select(.type == "tool_result")] | length)
142
147
  else 0 end) == 0);
@@ -184,11 +189,16 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re"
184
189
  # FAIL-OPEN: no question in the call, no reply from the owner, no earlier question — the sign stays
185
190
  # silent.
186
191
  if [ -n "$tool" ]; then
187
- asked_json="$(printf '%s' "$input" | jq -r '(.tool_input.questions // []) | tostring' 2>/dev/null)"
188
- seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_json" '
192
+ # The words are taken from what the owner reads — the question, the options and their
193
+ # descriptions — and not from the serialised menu: its keys `question`, `label` and
194
+ # `description` stand in every call and matched any English text by two words of the three.
195
+ asked_text="$(printf '%s' "$input" | jq -r '[(.tool_input.questions // [])[]
196
+ | (.question // ""), ((.options // [])[] | (.label // ""), (.description // ""))] | join(" ")' 2>/dev/null)"
197
+ seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_text" '
189
198
  def is_input:
190
199
  .type == "user"
191
200
  and ((.isCompactSummary // false) | not)
201
+ and ((.isMeta // false) | not)
192
202
  and (((.message.content // []) | if type == "array"
193
203
  then ([.[] | select(.type == "tool_result")] | length)
194
204
  else 0 end) == 0);
@@ -232,6 +242,57 @@ ${deny_tail_text}"
232
242
  fi
233
243
  fi
234
244
 
245
+ # The third sign of the same guard: the owner answered the recommended option twice in a row.
246
+ #
247
+ # Every menu carries a recommended option, and an owner who takes it twice running has shown that
248
+ # the decisions are not theirs: the questions are answered by the tree, and the menu only asks them
249
+ # to confirm it. A grill went on to a fifth menu after four such answers, and the owner closed it
250
+ # with the name of a ready-made module that answered all five. From the second answer on, the
251
+ # remaining questions are closed by an assumption written into the grill, and the owner gets the
252
+ # list in one line — not a menu.
253
+ #
254
+ # What is judged is the record of the question tool: the last two of its answers, each with every
255
+ # option taken marked as recommended. Any other answer breaks the streak, and a menu after it goes
256
+ # out as usual. The mark is the word the menu itself carries, in either language of the tree.
257
+ #
258
+ # FAIL-OPEN: fewer than two answers in the record, no record, no parser — the sign stays silent.
259
+ if [ -n "$tool" ]; then
260
+ streak="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
261
+ def answer_texts: [.[] | select(.type == "user") | (.message.content // [])
262
+ | select(type == "array") | .[] | select(.type == "tool_result") | .content
263
+ | if type == "string" then . elif type == "array"
264
+ then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
265
+ | select(test("^The user answered:"))];
266
+ def recommended: ([match("\"=\"[^\"]*\""; "g")] | length) as $all
267
+ | ([match("\\((Recommended|Рекомендую|Рекомендован[^)]*)\\)\"(,|\\.|[[:space:]]|$)"; "g")] | length) as $marked
268
+ | $all > 0 and $all == $marked;
269
+ (answer_texts) as $answers
270
+ | if ($answers | length) < 2 then "no"
271
+ elif ($answers[-1] | recommended) and ($answers[-2] | recommended) then "streak"
272
+ else "no" end
273
+ ' 2>/dev/null)"
274
+
275
+ if [ "$streak" = "streak" ]; then
276
+ 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.
277
+
278
+ 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.
279
+
280
+ A menu goes out again only for a question no assumption closes, and it says so in its first line."
281
+
282
+ # shellcheck disable=SC1090
283
+ [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
284
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
285
+ deny_tail_text="$(rt_deny_tail "")"
286
+ [ -n "$deny_tail_text" ] && reason="${reason}
287
+
288
+ ${deny_tail_text}"
289
+
290
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
291
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: two recommended answers in a row close the remaining questions by assumption."}}\n'
292
+ exit 0
293
+ fi
294
+ fi
295
+
235
296
  [ "$verdict" = "ask" ] || exit 0
236
297
 
237
298
  if [ -n "$tool" ]; then
@@ -40,6 +40,30 @@ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
40
40
  [ -f "$rt_hooks_dir/write-targets.sh" ] && . "$rt_hooks_dir/write-targets.sh" 2>/dev/null
41
41
  command -v rt_write_targets >/dev/null 2>&1 || rt_write_targets() { cat >/dev/null; }
42
42
 
43
+ # The bodies of the heredocs of a command, one after another. The delimiter is taken as the shell
44
+ # takes it — quoted or bare — and everything up to the closing line is the written text.
45
+ rt_prose_heredoc_bodies() {
46
+ awk -v q="'" '
47
+ inside {
48
+ if ($0 == tag) { inside = 0 } else { print }
49
+ next
50
+ }
51
+ {
52
+ s = $0
53
+ re = "<<-?[ \t]*(\"[^\"]+\"|" q "[^" q "]+" q "|[A-Za-z_][A-Za-z0-9_]*)"
54
+ while (match(s, re)) {
55
+ t = substr(s, RSTART, RLENGTH)
56
+ s = substr(s, RSTART + RLENGTH)
57
+ sub(/^<<-?[ \t]*/, "", t)
58
+ gsub(/\"/, "", t)
59
+ gsub(q, "", t)
60
+ tag = t
61
+ inside = 1
62
+ }
63
+ }
64
+ '
65
+ }
66
+
43
67
  tool="$(rt_hook_tool)"
44
68
  case "$tool" in
45
69
  Edit | Write | MultiEdit)
@@ -52,9 +76,13 @@ case "$tool" in
52
76
  # The first document among the write targets. A command writing several is judged by one of
53
77
  # them: the text is one for the whole command, and a second refusal would repeat the first.
54
78
  path="$(printf '%s' "$cmd" | rt_write_targets | grep -m1 '\.md$')"
55
- # The new text is the body of the command: the written text stands inside it, and the
56
- # findings of the check name the very lines that go into the file.
57
- added="$cmd"
79
+ # The new text is taken from the heredoc bodies of the command, not from the whole call.
80
+ # A rewrite carrying the previous wording inside the call would otherwise be refused by
81
+ # the words of that previous wording, and the refusal repeats at the second attempt. No
82
+ # heredoc in the command — the whole text is judged, as before: a redirect of a printf
83
+ # holds the written text and nothing else.
84
+ added="$(printf '%s' "$cmd" | rt_prose_heredoc_bodies)"
85
+ [ -z "$added" ] && added="$cmd"
58
86
  ;;
59
87
  *) exit 0 ;;
60
88
  esac
@@ -64,6 +92,24 @@ case "$path" in
64
92
  *) exit 0 ;;
65
93
  esac
66
94
 
95
+ # The judgement's boundary is the project root. A scratch document written outside it belongs to no
96
+ # repository, and the wording conventions of this tree are nobody's convention there: a fixture in
97
+ # the system temporary directory was refused over a word in it.
98
+ if [ -n "${CLAUDE_PROJECT_DIR:-}" ]; then
99
+ case "$path" in
100
+ /*)
101
+ rt_root="$(cd "$CLAUDE_PROJECT_DIR" 2>/dev/null && pwd)"
102
+ # A root that cannot be entered is taken as it was declared: the directory may be
103
+ # absent on this machine, and that says nothing about where the document lies.
104
+ [ -n "$rt_root" ] || rt_root="$CLAUDE_PROJECT_DIR"
105
+ case "$path" in
106
+ "$rt_root"/*) ;;
107
+ *) exit 0 ;;
108
+ esac
109
+ ;;
110
+ esac
111
+ fi
112
+
67
113
  # The archive and the task folders are not judged: the archive is not edited at all, and the
68
114
  # progress is written in haste and lives until the merge.
69
115
  case "$path" in
@@ -108,3 +108,42 @@ Do what does not depend on the answer in this same turn, then ask by the tool.
108
108
 
109
109
  The guard judges one turn: the next session is not refused." "a question without work in a running stage."
110
110
  }
111
+
112
+ # The next step rewritten into the progress and not begun. The turn rewrote the progress, and after
113
+ # that edit did nothing but commit and push it: the stage number moved, the report is full, and the
114
+ # step the line names is untouched. Judged in a running stage alone; handed-in work has a tier of
115
+ # its own. Expects the verdict signs and `$state` to be set.
116
+ rt_te_next_step_deny() {
117
+ [ "${progress_edited:-false}" = "true" ] || return 0
118
+ [ "${after_progress:-false}" = "true" ] && return 0
119
+ [ "${state:-}" = "этап-идёт" ] || return 0
120
+ [ "${handed_over:-false}" = "true" ] && return 0
121
+ rt_te_deny "BLOCKED by turn-exit-guard: the progress was rewritten in this turn, and after that edit the turn did nothing but commit and push it — the next step it names is not begun.
122
+
123
+ The volume done before the line does not replace the step: a closed stage, a full report and a moved stage number are the shape of four stops in a row. A rewritten progress is a promise about the next action, and the turn that wrote it keeps it.
124
+
125
+ The next step is written in the progress: ${next_step}
126
+
127
+ Begin it in this same turn: an edit outside the task folder or a command changing the tree. The owner said to stop — then write so: the guard reads their word, not a retelling.
128
+
129
+ The guard judges one turn: the next session is not refused." "the next step named by the progress is not begun."
130
+ }
131
+
132
+ # A launch in the background as the last action of the turn. A role sent to review, an exploration
133
+ # sent to a subagent, a command sent behind the turn: none of them asks anything while it runs and
134
+ # none goes faster for being waited on. A turn that ended on the launch stands exactly as long as an
135
+ # empty one — the owner sees the executor standing still with the role working. The tier lives here
136
+ # next to the state tiers because the guard file is at its length limit; it is not gated by the
137
+ # epic. Expects the verdict signs to be set.
138
+ rt_te_launch_last_deny() {
139
+ [ "${launched_last:-false}" = "true" ] || return 0
140
+ rt_te_deny "BLOCKED by turn-exit-guard: the last action of the turn was a launch in the background — a role or a command — and the turn ended on it.
141
+
142
+ A launch is an announcement of intent, not work: what was sent goes on without the executor and asks nothing on the way. While it runs, what does not depend on it is done — the epic, the tasks, the branch, the next stage — and its findings are taken when they come back.
143
+
144
+ The next step is written in the progress: ${next_step}
145
+
146
+ Do it in this same turn; the launch may stand anywhere in the turn but last.
147
+
148
+ The guard judges one turn: the next session is not refused." "the turn ended on a launch in the background."
149
+ }
@@ -379,6 +379,8 @@ The guard judges one turn: the next session is not refused."
379
379
  rt_te_deny "$reason" "a closed stage is not backed by the output of a command."
380
380
  fi
381
381
  fi
382
+ # The next step rewritten into the progress and not begun: the tier lies next to the epic tiers.
383
+ command -v rt_te_next_step_deny >/dev/null 2>&1 && rt_te_next_step_deny
382
384
 
383
385
  # The work is handed over and the next one is only named. There is more work in such a turn than in
384
386
  # any other — and all of it is on the task handed in: the handover finishes the previous work, not
@@ -418,7 +420,7 @@ The guard judges one turn: the next session is not refused."
418
420
 
419
421
  rt_te_deny "$reason" "the turn ended with waiting for a step by someone else."
420
422
  fi
421
-
423
+ command -v rt_te_launch_last_deny >/dev/null 2>&1 && rt_te_launch_last_deny
422
424
  # The shared line. There was work in the turn — but the last action was not it, it was a text to the
423
425
  # owner. The particular tiers above name the kind of stop more precisely; what reaches here is what
424
426
  # they do not know by name.
@@ -446,9 +448,7 @@ if [ "$worked" = "true" ] && [ "$handed_over" != "true" ]; then
446
448
  if [ -n "$unpushed" ] && [ "$unpushed" -gt 0 ] 2>/dev/null; then
447
449
  reason="BLOCKED by turn-exit-guard: there was work in the turn, but it stayed in the working tree — commits not handed over: ${unpushed}.
448
450
 
449
- 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.
450
-
451
- What is left in the tree is named with a reason — in the words of the owner, not as a list of leftovers.
451
+ 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.
452
452
 
453
453
  The guard judges one turn: the next session is not refused."
454
454
 
@@ -456,6 +456,8 @@ The guard judges one turn: the next session is not refused."
456
456
  fi
457
457
  fi
458
458
 
459
+ rt_te_steps_deny "$progress" # the steps of the plan are not done; the tier lies in the patterns
460
+
459
461
  # There was work in the turn, and the epic is open: the turn is released outside an epic and under a
460
462
  # closed one alone. Under an open epic the work stands where it stood, and the next step is named.
461
463
  [ "$worked" = "true" ] && rt_te_epic_open && rt_te_epic_deny worked
@@ -69,3 +69,54 @@ standing_work_re='работай[^.]{0,40}(без остановок|без па
69
69
  handover_re='gh[[:space:]]+pr[[:space:]]+create'
70
70
  started_re='task:new|task:move|board\.mjs[[:space:]]+move|git[[:space:]]+checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|git[[:space:]]+switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c'
71
71
 
72
+ # How many steps of the plan are not done yet. The progress mirrors the steps of the plan with a
73
+ # mark each — `[x]` done, `[>]` going on right now, `[ ]` not begun — and a check keeps the two
74
+ # lists matched. The reading is a local file, not a call to the hosting: it costs nothing and is
75
+ # asked on every turn, unlike the state of the epic.
76
+ #
77
+ # Prints the number and answers non-zero when there is nothing to read: no progress, or a progress
78
+ # with no list of steps. A tier that REFUSES a turn must tell "the work goes on" from "there is
79
+ # nothing to ask with" — the same reason the count of the epic's tasks is printed rather than folded
80
+ # into an exit code.
81
+ rt_te_steps_left() {
82
+ [ -f "$1" ] || return 1
83
+ grep -qE '^-[[:space:]]+\[[x> ]\][[:space:]]+[0-9]+\.[0-9]+[[:space:]]' "$1" 2>/dev/null || return 1
84
+ printf '%s' "$(grep -cE '^-[[:space:]]+\[[> ]\][[:space:]]+[0-9]+\.[0-9]+[[:space:]]' "$1" 2>/dev/null || printf '0')"
85
+ return 0
86
+ }
87
+
88
+ # The step going on right now: its number and its name, as the progress writes them. Empty when no
89
+ # step carries the mark — the refusal then names the count alone.
90
+ rt_te_step_now() {
91
+ [ -f "$1" ] || return 0
92
+ sed -nE 's/^-[[:space:]]+\[>\][[:space:]]+([0-9]+\.[0-9]+[[:space:]]+.*)$/\1/p' "$1" 2>/dev/null | head -1
93
+ }
94
+
95
+ # The refusal about a step that is not done. The text lies here and not in the guard for the same
96
+ # reason as the one about the epic: the guard stands at its length limit.
97
+ #
98
+ # Why the tier exists. The tier about the epic judges the whole: while the epic holds tasks, a turn
99
+ # does not end. It says nothing about a turn inside one task — the epic may hold a single task, and
100
+ # the work inside it breaks off in the middle all the same. The stage tier next to it reads the
101
+ # «Verified by» command of a stage declared closed, and a stage nobody declared closed it does not
102
+ # touch either.
103
+ rt_te_steps_reason() {
104
+ printf '%s' "BLOCKED by turn-exit-guard: ${1} steps of the plan are not done, and the turn ends without the word of the owner about stopping.
105
+
106
+ The step going on right now: ${2:-none is marked as going on}
107
+
108
+ Work is not finished while the plan holds steps that are not done. A turn that did work and then reported is no exception: the report ends the account, not the work.
109
+
110
+ The steps are listed in the progress and counted by «npm run check:work-steps»; the plan holds the same list and is not edited.
111
+
112
+ Do them in this same turn. Lawful exits stay as they were: a question to the owner through the tool, a refusal of another guard, a session handover, and the owner's own word about stopping — the guard reads that word from them, not from a retelling."
113
+ }
114
+
115
+ # The tier itself: the steps of the plan are not done. It lies here and not in the guard for the
116
+ # same reason as the text above — the guard stands at its length limit. The tier judges the
117
+ # progress of the current task and says nothing about the epic: the tier next to it does that.
118
+ rt_te_steps_deny() {
119
+ _steps_left="$(rt_te_steps_left "$1" 2>/dev/null)" || return 0
120
+ [ "${_steps_left:-0}" -gt 0 ] 2>/dev/null || return 0
121
+ rt_te_deny "$(rt_te_steps_reason "$_steps_left" "$(rt_te_step_now "$1")")" "${_steps_left} steps of the plan are not done."
122
+ }
@@ -37,6 +37,10 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
37
37
  # however much work there was before: the work stays exactly where it stood.
38
38
  | ([$uses[] | select((.name // "") == "Bash") | ((.input.command // "") + (if (.input.run_in_background // false) then " &" else "" end))] | last // "") as $last
39
39
  | ([$uses[] | (.name // "")] | last // "") as $last_name
40
+ # A launch in the background as the last action: a role sent to work by the agent tool, or a
41
+ # command sent behind the turn. The launch is an announcement of intent, and what does not
42
+ # depend on it is done while it runs — the turn does not end on the launch itself.
43
+ | (($last_name | test("^(Agent|Task)$")) or (($last_name == "Bash") and ($last | test("&[[:space:]]*$")))) as $launched_last
40
44
  | (($last_name == "Bash") and ($last | test($wait))) as $waited
41
45
  # Handing the work over: the tail of the turn after the PR was opened. Everything before it was
42
46
  # done on the task handed in and says nothing about the next one.
@@ -90,7 +94,22 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
90
94
  | (($last_say | test("[Жж]ду (твоего|вашего|его|её) (слова|указани|решени|ответа|команды|отмашки)|[Жж]ду слова владельца|[Жж]ду, что скаж|[Оо]стаюсь ждать|[Бб]уду ждать (твоего|вашего)"))
91
95
  and (($asked or $told_stop or $handed) | not)) as $awaits_word
92
96
  | ($last_say | test($promise)) as $promised
97
+ # The next step rewritten into the progress and not begun. The last edit of the progress in the
98
+ # turn is found — by the editing tool or by a writing command naming the file — and after it the
99
+ # turn must hold work other than the commit and the push of it: an edit outside the task folder
100
+ # or a command changing the tree. Four stops of one shape ended with a full report, a moved
101
+ # stage number and an untouched next step; the volume before the line is not the step.
102
+ | ($uses | map(
103
+ (((.name // "") | test("^(Edit|Write|MultiEdit|NotebookEdit)$")) and ((.input.file_path // "") | test("(^|/)progress\\.md$")))
104
+ or (((.name // "") == "Bash") and ((.input.command // "") | test("progress\\.md")) and ((.input.command // "") | test("sed -i|tee |>|python3|cat ")))
105
+ ) | rindex(true)) as $progress_at
106
+ | ($progress_at != null) as $progress_edited
107
+ | (if $progress_at == null then [] else $uses[($progress_at + 1):] end) as $after
108
+ | ($after | map(
109
+ (((.name // "") | test("^(Edit|Write|MultiEdit|NotebookEdit)$")) and ((.input.file_path // "") | test("/tasks/") | not))
110
+ or (((.name // "") == "Bash") and ([(.input.command // "") | splits($part)] | map(test($work) and (test($read) | not) and (test("^[[:space:]]*([^[:space:]]*/)?git[[:space:]]+(add|commit|push)") | not)) | any))
111
+ ) | any) as $after_progress
93
112
  | (($last_name == "Bash") and ($last | test($started)) and ($handed_over | not)) as $only_took
94
- | { promised: $promised, only_took: $only_took, asked: $asked, handed_by_hand: ($handed and (($asked or $denied or $told_stop) | not)), standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, ran: $ran }
113
+ | { promised: $promised, only_took: $only_took, asked: $asked, handed_by_hand: ($handed and (($asked or $denied or $told_stop) | not)), standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, progress_edited: $progress_edited, after_progress: $after_progress, launched_last: $launched_last, ran: $ran }
95
114
  ' 2>/dev/null)"
96
115
  }
@@ -86,6 +86,23 @@ taken_path_re='/tasks/'
86
86
  # because the next task was taken instead of this, not on top of it.
87
87
  ready_re='pr[[:space:]]+ready|run[[:space:]]+(list|view|watch)|pr[[:space:]]+checks|check-runs|check:board|board\.mjs'
88
88
 
89
+ # A run started or rerun in the turn. Its outcome does not call by itself: a rerun went through in
90
+ # one line between other things, its state was read once — «queued» — and the turn ended by a lawful
91
+ # exit while the request stayed without watching; the owner found the green run before the
92
+ # executor. The sign is the pair: a starting command in the turn and no command that waits for the
93
+ # end in the same turn. A wait is a watching command of the hosting client, a loop until the end or
94
+ # the watching tool — in the background or blocking; a single read of the state is not a wait.
95
+ # Incident analysis — the record "2026-09-15-turn-idle-after-green-run" in the intake.
96
+ started_run_re='run[[:space:]]+rerun|workflow[[:space:]]+run|ci[[:space:]]+(retry|run)|pipeline[[:space:]]+(run|retry)|pipelines[[:space:]]+run'
97
+
98
+ # A run nobody started by hand: the pipeline wakes on an opened request by itself, and the tier
99
+ # above stays silent — there is no starting command in the turn at all. The sign is taken from the
100
+ # output rather than from the base of the request: which bases wake the pipeline the guard cannot
101
+ # know, and a demand by the bare fact of opening would refuse every request into an epic branch.
102
+ # So the pair is "the request is opened in the turn" and "its run is read as going".
103
+ going_run_re='queued|in_progress|"status"[[:space:]]*:[[:space:]]*"(queued|in_progress)"|status:[[:space:]]*(queued|in_progress)'
104
+ watched_run_re='run[[:space:]]+watch|pr[[:space:]]+checks[^|;&]*--watch|until[[:space:]][^\n]*sleep|while[[:space:]][^\n]*sleep|ci[[:space:]]+status[^|;&]*--live|pipelines[[:space:]]+runs[[:space:]]+show'
105
+
89
106
  # One's own named action. An empty turn that declared what it will do next gives itself away by
90
107
  # nothing: it opened no PR, read no run, and both earlier signs are silent. It is caught by form —
91
108
  # a set of future-tense patterns about one's own step — not by understanding the meaning; and no
@@ -99,7 +116,9 @@ vow_re='дальше беру|дальше возьму|дальше иду|сл
99
116
  # A 400-line tail: the turn record grows all session, and only the last turn is judged.
100
117
  verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r \
101
118
  --arg opened "$opened_re" --arg taken "$taken_re" --arg taken_path "$taken_path_re" \
102
- --arg read "$read_re" --arg red "$red_re" --arg ready "$ready_re" --arg vow "$vow_re" '
119
+ --arg read "$read_re" --arg red "$red_re" --arg ready "$ready_re" --arg vow "$vow_re" \
120
+ --arg started_run "$started_run_re" --arg watched_run "$watched_run_re" \
121
+ --arg going_run "$going_run_re" '
103
122
  def is_input:
104
123
  .type == "user"
105
124
  and ((.isCompactSummary // false) | not)
@@ -127,6 +146,11 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r \
127
146
  | (($ran | test($read; "i")) and ($out | test($red; "i"))) as $red_run
128
147
  | (($ran | test($taken; "i")) or ($wrote | test($taken_path; "i"))) as $went_on
129
148
  | ($ran | test($ready; "i")) as $checked
149
+ # The run started in the turn and the wait for its end: the watching tool counts as a wait too.
150
+ | ($ran | test($started_run; "i")) as $reran
151
+ # The run of the request opened in this turn: read as going and left without a wait.
152
+ | ($opened_pr and ($out | test($going_run; "i"))) as $own_run_going
153
+ | (($ran | test($watched_run; "i")) or ($uses | map(.name // "") | any(. == "Monitor"))) as $watched_run
130
154
  | ([$turn[] | select(.type == "assistant") | (.message.content // [])[]
131
155
  | select(.type == "text") | .text] | join("\n")) as $said
132
156
  | ($said | test($vow; "i")) as $announced
@@ -134,6 +158,7 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r \
134
158
  | if $opened_pr and ($went_on | not) and ($checked | not) then "owe:both"
135
159
  elif $opened_pr and ($went_on | not) then "owe:pr"
136
160
  elif $opened_pr and ($checked | not) then "owe:draft"
161
+ elif ($reran or $own_run_going) and ($watched_run | not) then "owe:watch"
137
162
  elif $went_on then "pass"
138
163
  elif $red_run then "owe:run"
139
164
  elif $announced and $tools == 0 then "owe:vow"
@@ -190,6 +215,36 @@ ${deny_tail_text}"
190
215
  exit 0
191
216
  fi
192
217
 
218
+ # A run started or rerun in the turn without a wait for its end. The next task taken does not lift
219
+ # this: the request stays without watching either way, and its outcome reaches the owner first.
220
+ if [ "$verdict" = "owe:watch" ]; then
221
+ reason="BLOCKED by waiting-turn-guard: a run of this turn was left without a wait for its end — started by hand, or started by the request opened here and read as going.
222
+
223
+ The outcome of a run does not call by itself: a state read once — «queued», «in_progress» — is a moment, not a result. Without a wait the request stays without watching, the draft is not lifted and the merge is not asked, and the owner finds the green run before the executor.
224
+
225
+ Put the wait in this same turn, in the background or blocking:
226
+
227
+ gh run watch <id> --exit-status & # returns the session to the request at the end
228
+ gh pr checks <number> --watch
229
+
230
+ The end of a run is learned from the return of such a command, not from a look at the page.
231
+
232
+ The guard judges one turn: the next session is not refused."
233
+
234
+ # shellcheck disable=SC1090
235
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
236
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
237
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
238
+ deny_tail_text="$(rt_deny_tail "")"
239
+ [ -n "$deny_tail_text" ] && reason="${reason}
240
+
241
+ ${deny_tail_text}"
242
+
243
+ jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
244
+ || printf '{"decision":"block","reason":"waiting-turn-guard: a run was started in the turn, and nothing waits for its end."}\n'
245
+ exit 0
246
+ fi
247
+
193
248
  # A draft left while the next task is taken is a separate refusal: there the demand is not about
194
249
  # the next task but about carrying the handed-in one to the end.
195
250
  if [ "$verdict" = "owe:draft" ]; then
@@ -42,8 +42,30 @@ rt_write_targets() {
42
42
  rt_wt_text="$(printf '%s' "$rt_wt_text" \
43
43
  | sed -E 's#(&|[0-9]*)>>?[[:space:]]*/dev/(null|stderr)##g; s#[0-9]*>&[0-9-]##g')"
44
44
 
45
+ # The bodies of the heredocs are cut out of the shell parse: they are data of the command, not
46
+ # the command. A markdown quote line inside a body — a caret and a path — read as a redirection,
47
+ # and an edit that wrote nothing into the tree was refused by the path standing in that quote.
48
+ # The bodies are parsed separately, by the interpreter branch below.
49
+ rt_wt_shell="$(printf '%s' "$rt_wt_text" | awk -v q="'" '
50
+ function trim(s) { sub(/^[ \t]+/, "", s); sub(/[ \t]+$/, "", s); return s }
51
+ tag != "" { if (trim($0) == tag) { tag = "" } ; next }
52
+ {
53
+ print
54
+ s = $0
55
+ re = "<<-?[ \t]*(\"[^\"]+\"|" q "[^" q "]+" q "|[A-Za-z_][A-Za-z0-9_]*)"
56
+ while (match(s, re)) {
57
+ t = substr(s, RSTART, RLENGTH)
58
+ s = substr(s, RSTART + RLENGTH)
59
+ sub(/^<<-?[ \t]*/, "", t)
60
+ gsub(/\"/, "", t)
61
+ gsub(q, "", t)
62
+ tag = t
63
+ }
64
+ }
65
+ ')"
66
+
45
67
  {
46
- printf '%s' "$rt_wt_text" \
68
+ printf '%s' "$rt_wt_shell" \
47
69
  | tr "\"'\`" ' ' \
48
70
  | sed -E 's/>>?/\n>/g' \
49
71
  | sed -nE '
@@ -90,6 +90,16 @@ one session and keeps its whole context and state when it passes to the next.
90
90
  check.
91
91
  - **Done work is marked in one place.** Two records of the same thing drift apart silently, and then
92
92
  neither shows what remains.
93
+ - **The steps of the work are written out in full before it starts, and each of them can be called
94
+ done or not done.** A plan of prose alone cannot say how much is left: whoever reads it counts by
95
+ eye and counts differently every time, so the work reads as nearly finished from the first step
96
+ onwards.
97
+ - **The step going on right now is marked at every minute of the work, and there is only ever one.**
98
+ A record that names the whole stage and not the step inside it says nothing about where the work
99
+ broke off, and the session that picks it up starts by guessing.
100
+ - **Work with a step that is not done is not finished, and a report about the done does not finish
101
+ it either.** A report ends the account, not the work: it looks like completeness better than
102
+ anything else, and the emptiness behind it is invisible to whoever wrote it.
93
103
  - **A decision made along the way is written down together with its reason.** Without a reason it
94
104
  reads as accidental and is revoked by the next session, and brought back by the third.
95
105
  - **The boundary of the work is named before it starts.** A boundary not named aloud does not exist:
@@ -190,6 +200,18 @@ one session and keeps its whole context and state when it passes to the next.
190
200
  being watched. While it runs, the next task is taken, and the check is returned to in the turn
191
201
  that reads its end. A session spent waiting costs as much as one with a task done, and yields
192
202
  nothing.
203
+ - **A check the work started is watched to its end, and watching goes beside the next task.** Not
204
+ waiting and not watching are different things: the first frees the executor, the second abandons
205
+ the work. The return is arranged in the turn that started the check, by something that comes back
206
+ by itself; a state read once is a moment, not an outcome.
207
+ - **A check is started by the work, not only by the command that names it.** Handing the work over
208
+ starts a check by itself where the machine is set up for that, and the executor answers for it as
209
+ for one started by hand.
210
+ - **A check that came back green is carried to the end by the one who handed the work over.** What
211
+ is left after it — a lock to lift, a mark to set — is the executor's step: the owner sees the lock
212
+ and reads it as work still going. A red one is fixed by the same executor, in the same work.
213
+ - **A check left with nobody watching is a miss and is analysed as one.** The work is finished and
214
+ nobody knows it; every minute until the owner asks is paid by them.
193
215
  - **A wait that does stop the work is named to the owner separately and directly.** Sometimes there
194
216
  is no way forward: the next task stands on one not yet reviewed, or the change waits for a
195
217
  decision only the owner has. Then the executor says three things — what stands still, what it
@@ -85,6 +85,12 @@ not choose.
85
85
 
86
86
  ## Pitfalls
87
87
 
88
+ - **An edit made by a shell command is judged by the whole command, the old version inside it
89
+ included.** The style check gets the body of the call, not the text that will end up in the
90
+ file: a rewrite carrying the previous wording inside a heredoc or an interpreter string is
91
+ refused by the words of that previous wording. The refusal repeats at the second attempt,
92
+ because the old text is still there. The new text is written by the edit tool — there only the
93
+ new text is judged — or inserted by line number, and the command is given the path.
88
94
  - **Shorter does not mean clearer.** A text in the layer's words comes out a third shorter and
89
95
  is useless to whoever decides whether the work is urgent.
90
96
  - **"Not X but Y" looks like an explanation and explains nothing.** The owner learns what was
@@ -231,6 +231,10 @@ Docs-skip: правка только в тестах хука, зеркала у
231
231
 
232
232
  ## Common misses
233
233
 
234
+ - **An amend goes through the same hooks as a commit.** The flag that skips the commit hooks is not
235
+ used for any edit, a one-letter typo in the subject included. The gate before a push does not
236
+ read commit messages, so a message the hook never saw reaches the host unchecked. A commit that
237
+ skipped the hooks is redone without the flag before the push.
234
238
  - **An audit right after adding answers "no" when the card already stands.** The work queue gives
235
239
  out a new item not in the same second it was created, and the last step reads it by the next
236
240
  call. The answer to this is to reread the whole queue, not to create the card a second time: two
@@ -47,6 +47,7 @@ technique, and different files of one merge are resolved differently.
47
47
  | a build from a description | rebuilt from the description after the description is resolved: a generator writes the lines of such a file, and sides joined by hand give a file it would never output |
48
48
  | a spec in `docs/specs/` | by keeping both sides, if both appended; a section removed by one side stays removed — rule `spec-driven`; after — `npm run check:specs` |
49
49
  | a rule's companion next to the rule | by keeping both sides — the same two additions to one table; after — `npm run check:specs` |
50
+ | the table of working-copy assignments | by the base's side whole. The owner fills it in the main branch, and a session does not write it: the branch's side can only be an older copy. After — the reading the session start prints |
50
51
  | the work list (`docs/BACKLOG.md`) | by the selection sign — pattern `doc-style-sweep` |
51
52
 
52
53
  ## A commit is carried over by a cherry-pick
@@ -25,13 +25,18 @@ The body starts with the link line — by it the board fills the linked PRs fiel
25
25
  assignee and labels are set by the same command, and a PR does not open without them:
26
26
 
27
27
  ```bash
28
- GH_TOKEN="$TOKEN" gh pr create --base <ветка эпика> --title '[<КЛЮЧ>-86] Письмо владельцу с незаполненным адресом попадает в логи' \
29
- --reviewer <владелец> --assignee <бот> --label bug --label area:api \
30
- --body 'Closes #86
31
-
32
- …'
28
+ GH_TOKEN="$TOKEN" gh pr create --title '[<КЛЮЧ>-86] Письмо владельцу с незаполненным адресом попадает в логи' \
29
+ --base <ветка эпика> --body-file <файл с телом> \
30
+ --reviewer <владелец> --assignee <бот> --label bug --label area:api
33
31
  ```
34
32
 
33
+ **The title stands first in the call, and the body comes in by a file.** The delivery guard reads
34
+ the title out of the command text and takes the first match of the short key: a body passed as a
35
+ line in the same call may itself hold a word after that key — a quoted command, a label, a run
36
+ line — and it becomes the title in the guard's eyes. The refusal then says the title does not
37
+ start with the task number while the real title is right, and the mistake is looked for where
38
+ there is none. A body in a file leaves the call one title and nothing else to match.
39
+
35
40
  The reviewer is always the owner: without a review request the PR does not show in their queue.
36
41
  The assignee is the same account the machine work goes from. Labels are taken from the task
37
42
  whole — both the kind of edit and all its areas; they are read from the task, not picked from
@@ -162,6 +162,10 @@ statement.
162
162
 
163
163
  ## Common misses
164
164
 
165
+ - A second table under the contract section: the audit reads every table there as the list of
166
+ procedures, and a set of refusal codes standing next to them comes back as that many
167
+ discrepancies at once — thirty-six on a spec that was right. Under the contract stands the table
168
+ of procedures alone; a set of codes goes into the data section.
165
169
  - A grown domain is split into new domains instead of subdomains: a new domain has to be entered
166
170
  in the index, audited against the code separately and explained as to why it is not a subdomain
167
171
  of its neighbour — while a subdomain stays in its domain and inherits its contract. A
@@ -71,6 +71,12 @@ into an interactive sign-in instead of an answer.
71
71
 
72
72
  ## Common misses
73
73
 
74
+ - **On the epic's own branch the number is asked as an argument.** Without an argument the
75
+ command takes the number from the branch and looks in that card's body for the line declaring
76
+ an epic. On a task branch that line is there; on the epic branch the card is the epic itself
77
+ and declares no other. The answer — "the task declares no epic" — then reads as a broken card
78
+ rather than as a question asked the wrong way.
79
+
74
80
  - **The task on the board is read by a request, not by the view subcommand.** The subcommand
75
81
  drags in boards of the old kind, the host answers with a refusal about them, and the call turns
76
82
  red whole, showing nothing. A direct request is taken.