@rt-tools/agent-kit 0.28.0 → 0.29.1

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 (81) hide show
  1. package/assets/checks/board-epic-link.github.mjs +13 -1
  2. package/assets/checks/board-epic-plan.github.mjs +128 -9
  3. package/assets/checks/board-epics.github.mjs +6 -10
  4. package/assets/checks/board-folders.mjs +50 -0
  5. package/assets/checks/board-runs.github.mjs +102 -2
  6. package/assets/checks/check-board.github.mjs +63 -3
  7. package/assets/checks/check-lib-layers.mjs +4 -2
  8. package/assets/checks/check-spec-coverage.mjs +65 -0
  9. package/assets/checks/check-work-steps.mjs +238 -0
  10. package/assets/checks/epic-table.github.mjs +15 -6
  11. package/assets/checks/lib-common.mjs +9 -4
  12. package/assets/checks/lib-domains.mjs +7 -4
  13. package/assets/checks/main-run.github.mjs +69 -0
  14. package/assets/checks/rt-kit-checks.config.mjs +16 -1
  15. package/assets/checks/task-new.github.mjs +6 -6
  16. package/assets/checks/tree-assignment.mjs +169 -0
  17. package/assets/defaults/project.sh +15 -1
  18. package/assets/hooks/end-conversation-guard.sh +59 -0
  19. package/assets/hooks/epic-over.sh +11 -2
  20. package/assets/hooks/git-guard-delivery-epic.sh +15 -1
  21. package/assets/hooks/git-guard-delivery.sh +4 -2
  22. package/assets/hooks/git-guard-push-tests.sh +31 -8
  23. package/assets/hooks/git-guard-tree-assignment.sh +77 -0
  24. package/assets/hooks/grill-gate.sh +63 -2
  25. package/assets/hooks/hook-input.sh +8 -1
  26. package/assets/hooks/main-run-context.sh +45 -0
  27. package/assets/hooks/prose-style-guard.sh +49 -3
  28. package/assets/hooks/tree-assignment-guard.sh +101 -0
  29. package/assets/hooks/turn-exit-epic.sh +149 -0
  30. package/assets/hooks/turn-exit-guard.sh +40 -24
  31. package/assets/hooks/turn-exit-patterns.sh +50 -8
  32. package/assets/hooks/turn-exit-verdict.sh +39 -8
  33. package/assets/hooks/waiting-turn-guard.sh +56 -1
  34. package/assets/hooks/write-targets.sh +23 -1
  35. package/assets/laws/delivery.md +6 -0
  36. package/assets/laws/work-conduct.md +26 -0
  37. package/assets/patterns/doc-style-human.md +6 -0
  38. package/assets/patterns/git-workflow-merge.md +14 -0
  39. package/assets/patterns/git-workflow-pr-body.github.md +161 -0
  40. package/assets/patterns/git-workflow-pr.github.md +6 -104
  41. package/assets/patterns/git-workflow-stack.md +19 -2
  42. package/assets/patterns/spec-driven-domain.md +4 -0
  43. package/assets/patterns/status-report-table.github.md +6 -0
  44. package/assets/patterns/task-flow-close.md +1 -1
  45. package/assets/patterns/task-flow-resume.md +8 -0
  46. package/assets/patterns/task-flow-start.md +26 -22
  47. package/assets/patterns/testing-e2e.md +14 -0
  48. package/assets/pitfalls/git-workflow.github.md +6 -0
  49. package/assets/pitfalls/turn-conduct.md +46 -0
  50. package/assets/rules/doc-style.md +3 -2
  51. package/assets/rules/git-workflow.github.md +37 -38
  52. package/assets/rules/observability.needs-app.md +5 -0
  53. package/assets/rules/reuse-first.md +33 -11
  54. package/assets/rules/task-flow.md +57 -56
  55. package/assets/rules/testing.md +15 -0
  56. package/assets/rules/turn-conduct.md +70 -73
  57. package/assets/rules/typescript-conventions.md +8 -0
  58. package/assets/samples/tasks/_template/plan.md +7 -1
  59. package/assets/samples/tasks/_template/progress.md +14 -1
  60. package/bin/agent-kit.d.ts.map +1 -1
  61. package/bin/agent-kit.js +2 -1
  62. package/bin/agent-kit.js.map +1 -1
  63. package/lib/cargo.d.ts +49 -1
  64. package/lib/cargo.d.ts.map +1 -1
  65. package/lib/cargo.js +9 -2
  66. package/lib/cargo.js.map +1 -1
  67. package/lib/observations-cargo.d.ts +32 -0
  68. package/lib/observations-cargo.d.ts.map +1 -0
  69. package/lib/observations-cargo.js +105 -0
  70. package/lib/observations-cargo.js.map +1 -0
  71. package/lib/shipment.d.ts +8 -20
  72. package/lib/shipment.d.ts.map +1 -1
  73. package/lib/shipment.js +22 -39
  74. package/lib/shipment.js.map +1 -1
  75. package/lib/tree-mark.d.ts +17 -0
  76. package/lib/tree-mark.d.ts.map +1 -0
  77. package/lib/tree-mark.js +41 -0
  78. package/lib/tree-mark.js.map +1 -0
  79. package/package.json +1 -1
  80. package/rt-tools-agent-kit-0.29.1.tgz +0 -0
  81. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
+ # Requires: hooks/deny-tail.sh, checks/tree-assignment.mjs
4
+ # Guard of the assignment of an epic to a working copy. PreToolUse on a call that takes new work
5
+ # past the branch: creating a task under an epic and moving a card into the working column.
6
+ #
7
+ # The branch is judged by the delivery guard — there the epic of the task comes from the queue, and
8
+ # the base is judged along with it. But work is taken by three calls, not one, and the other two go
9
+ # past that guard entirely: a task created under someone else's epic and a card moved into work are
10
+ # both work taken, and both were silent.
11
+ #
12
+ # What this cost. A session found the freshest epic of the open list, decided it was its own and
13
+ # worked the whole day on it: a branch, a task folder, a plan, a written agreement — the owner
14
+ # stopped that, not a check, and said plainly they had never given that epic into work.
15
+ #
16
+ # FAIL-OPEN: no `jq`, no `node`, no reading command, an unreadable table — the call is ALLOWED. A
17
+ # guard that jams the work when a file is missing is switched off on the first day, and the price of
18
+ # a miss here is one turn of the owner's attention.
19
+
20
+ # Its own name in the observations: the refusal is written by the shared deny tail, not by the
21
+ # guard itself.
22
+ RT_GUARD_NAME=tree-assignment-guard
23
+
24
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
25
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
26
+
27
+ rt_hook_read
28
+ input="$RT_HOOK_INPUT"
29
+ [ -z "$input" ] && exit 0
30
+
31
+ command -v jq >/dev/null 2>&1 || exit 0
32
+ command -v node >/dev/null 2>&1 || exit 0
33
+
34
+ tool="$(rt_hook_tool)"
35
+ case "$tool" in
36
+ Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
37
+ *) exit 0 ;;
38
+ esac
39
+
40
+ cmd="$(rt_hook_cmd)"
41
+ [ -z "$cmd" ] && exit 0
42
+
43
+ # The universal executor of the environment passes the real command as a nested string: it is the
44
+ # one to judge, not the wrapper.
45
+ if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
46
+ inner="$(printf '%s' "$cmd" | perl -0ne '
47
+ if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
48
+ print defined $1 ? $1 : (defined $2 ? $2 : $3);
49
+ }
50
+ ' 2>/dev/null)"
51
+ [ -n "$inner" ] && cmd="$inner"
52
+ fi
53
+
54
+ root="$(git rev-parse --show-toplevel 2>/dev/null)"
55
+ [ -n "$root" ] || exit 0
56
+ cd "$root" 2>/dev/null || exit 0
57
+
58
+ checks="$(jq -r '.layout.checks // "tools"' ".claude/rt-kit.json" 2>/dev/null)"
59
+ [ -n "$checks" ] && [ "$checks" != null ] || checks=tools
60
+ reader="${checks}/tree-assignment.mjs"
61
+ [ -f "$reader" ] || exit 0
62
+
63
+ # What is judged, and what the epic of the work is taken from. Creating a task names its epic in the
64
+ # call itself; a card moved into work does not name it at all, and for that the table alone answers:
65
+ # a copy with no assignment takes no work whatever epic it belongs to.
66
+ takes_work() {
67
+ printf '%s' "$cmd" | grep -qE '(task:new|task-new\.mjs)' 2>/dev/null && return 0
68
+ printf '%s' "$cmd" \
69
+ | grep -qE '(task:move|board\.mjs[[:space:]]+move)([^|;&]*)in-progress' 2>/dev/null
70
+ }
71
+
72
+ # Creating an epic is not taking work: it is the owner's order written down, and the assignment for
73
+ # it is given after, by the owner, in the table.
74
+ creates_epic() {
75
+ printf '%s' "$cmd" \
76
+ | grep -qE '(task:new|task-new\.mjs)[^|;&]*--epic([[:space:]]|$)' 2>/dev/null
77
+ }
78
+
79
+ takes_work || exit 0
80
+ creates_epic && exit 0
81
+
82
+ epic="$(printf '%s' "$cmd" | sed -nE 's/.*--epic-of[[:space:]]+([0-9]+).*/\1/p' | head -1)"
83
+
84
+ said="$(node "$reader" --fault "$epic" 2>/dev/null)"
85
+ [ -n "$said" ] || exit 0
86
+
87
+ reason="Refused: this call takes work, and ${said}."
88
+
89
+ # shellcheck disable=SC1090
90
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
91
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
92
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
93
+ deny_tail_text="$(rt_deny_tail "")"
94
+ [ -n "$deny_tail_text" ] && reason="${reason}
95
+
96
+ ${deny_tail_text}"
97
+
98
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
99
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"This copy has no assignment: work is not taken by guesswork."}}\n'
100
+
101
+ exit 0
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env bash
2
+ # The tiers of the open epic for the turn-exit guard. NOT a guard: it has no `rt-hook:` declaration
3
+ # and hooks into no agent event. The guard sources it right after the root of the tree is known.
4
+ #
5
+ # Why they live apart. Under an open epic a turn does not end by itself: the owner said it outright
6
+ # — until the epic is closed the executor does not stop on its own. Two ends the guard used to
7
+ # release are stops all the same: a turn that ended with work, and a second pass over the same turn.
8
+ # The work stands where it stood, and the owner sees the executor standing still with the epic open.
9
+ # The reading of the epic and the refusals about it lie here because the guard reached the file
10
+ # length limit.
11
+ #
12
+ # The state of the epic is asked by the same command that prints the table for the owner, and only
13
+ # on the way to a refusal: the call goes to the hosting and costs seconds. It is asked once per turn.
14
+ #
15
+ # FAIL-OPEN: no epic behind the branch, no table, no way to ask the hosting — the epic reads as not
16
+ # open, and the guard works as it did before these tiers existed.
17
+
18
+ # The unfinished tasks of the epic in one line; empty when the epic is over or cannot be read.
19
+ rt_te_epic_left() {
20
+ if [ -z "${rt_te_epic_asked:-}" ]; then
21
+ rt_te_epic_asked=1
22
+ rt_te_epic_left_cache=""
23
+ rt_te_epic_read=""
24
+ # shellcheck disable=SC1090
25
+ if . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/epic-over.sh" 2>/dev/null \
26
+ && command -v rt_epic_unfinished >/dev/null 2>&1; then
27
+ rt_te_epic_raw="$(rt_epic_unfinished 2>/dev/null)" && rt_te_epic_read=1
28
+ rt_te_epic_left_cache="$(printf '%s' "$rt_te_epic_raw" | tr -s '[:space:]' ' ' | sed 's/^ //; s/ $//')"
29
+ fi
30
+ fi
31
+ printf '%s' "$rt_te_epic_left_cache"
32
+ }
33
+
34
+ # The standing word of the owner about a stop, quoted in « » in the line «Waiting for the owner» of
35
+ # the progress. The guard reads their word, not a retelling: a line without a quote releases
36
+ # nothing, and the quote holds until the owner rewrites the line. Expects `$progress` to be set.
37
+ rt_te_owner_word_quoted() {
38
+ [ -n "${progress:-}" ] || return 1
39
+ local waiting
40
+ # The first waiting line of the progress is read, in either language of the heading.
41
+ waiting="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(Waiting for the owner|Ждём владельца|Ждём от владельца):\*\*[[:space:]]*(.*)/\2/p' "$progress" 2>/dev/null | head -1)"
42
+ # Three characters and more inside « » count as a word.
43
+ printf '%s' "$waiting" | grep -q '«[^»]\{3,\}»' 2>/dev/null
44
+ }
45
+
46
+ # The epic is open: at least one of its tasks is left unfinished.
47
+ rt_te_epic_open() {
48
+ [ -n "$(rt_te_epic_left)" ]
49
+ }
50
+
51
+ # The epic is over: the table was read and printed not a single task. At that point the stop is
52
+ # lawful — waiting for the word of the owner is the work itself — and the refusal releases the turn
53
+ # whatever tier reached it. An epic that cannot be read — no table, the main branch, no way to ask
54
+ # the hosting — is not over, and the turn is judged as before. Reads the same cache: one call per turn.
55
+ rt_te_epic_over() {
56
+ rt_te_epic_left >/dev/null
57
+ [ -n "${rt_te_epic_read:-}" ] && [ -z "${rt_te_epic_left_cache:-}" ]
58
+ }
59
+
60
+ # The epic branch: named by the header line of an epic plan in the plans directory of the tree. It
61
+ # has the shape of a task branch and by the rule carries no task folder, so the tier of the taken
62
+ # task would read every turn on it as work taken and not begun. The plan is written by the command
63
+ # that creates the epic and outlives the merge; the directory is named by the settings, `docs/plans`
64
+ # by default. Expects `$root` and `$branch` to be set. FAIL-OPEN: no directory, no plan — not an
65
+ # epic branch.
66
+ rt_te_epic_branch() {
67
+ [ -n "${root:-}" ] && [ -n "${branch:-}" ] || return 1
68
+ local plans
69
+ plans="$(jq -r ".plansDir // empty" "$root/.claude/rt-kit/checks.json" 2>/dev/null)"
70
+ [ -n "$plans" ] || plans="docs/plans"
71
+ [ -d "$root/$plans" ] || return 1
72
+ grep -lE "^\\*\\*[^|]*\`$branch\`" "$root/$plans"/*.md 2>/dev/null | grep -q .
73
+ }
74
+
75
+ # The refusal of a stop under an open epic. The kind names what the turn ended with.
76
+ rt_te_epic_deny() {
77
+ local kind="$1" ended short
78
+ case "$kind" in
79
+ handed-by-hand)
80
+ ended="the turn ended with a handover written by the hand of the executor, and no window guard refused in it"
81
+ short="a handover by hand under an open epic."
82
+ ;;
83
+ *)
84
+ ended="the turn ended with work, and the work stands where it stood"
85
+ short="the turn ended with work under an open epic."
86
+ ;;
87
+ esac
88
+ rt_te_deny "BLOCKED by turn-exit-guard: the epic is open — its unfinished tasks: $(rt_te_epic_left) — and ${ended}.
89
+
90
+ Until the epic is closed the executor does not stop on its own: the owner said so outright. A turn ends in four ways and no others: a question to the owner through the question tool, when the work does not go without the answer; a refusal of a guard as the last action of the turn; the session handover written by the hook on window fill, or the refusal of the window guard; the word of the owner about stopping, said in this turn. The end of the epic is the fifth: not one task of it is left.
91
+
92
+ The next step is written in the progress: ${next_step}
93
+
94
+ Do it in this same turn. The work of this task is done — take the next task of the epic. The owner said to stop — then write so: the guard reads their word, not a retelling.
95
+
96
+ While the epic is open the guard judges every pass over the turn, not the first one alone." "$short"
97
+ }
98
+
99
+ # A question to the owner at the head of an empty turn in a running stage.
100
+ rt_te_question_without_work_deny() {
101
+ rt_te_deny "BLOCKED by turn-exit-guard: the work stands in the state 'этап-идёт', and the turn asked the owner without doing a single piece of the stage — neither an edit nor a command changing the tree.
102
+
103
+ Waiting for one part of a stage is never a stop of the stage: the parts that do not depend on the answer are done in the same turn, and the question goes after them. A question at the head of an empty turn is a stop with a question attached.
104
+
105
+ The next step is written in the progress: ${next_step}
106
+
107
+ Do what does not depend on the answer in this same turn, then ask by the tool.
108
+
109
+ The guard judges one turn: the next session is not refused." "a question without work in a running stage."
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
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: Stop
3
- # Requires: hooks/deny-tail.sh, hooks/epic-over.sh, hooks/turn-exit-patterns.sh
3
+ # Requires: hooks/deny-tail.sh, hooks/epic-over.sh, hooks/turn-exit-patterns.sh, hooks/turn-exit-epic.sh
4
4
  # Turn exit guard: a turn in which nothing was done on the work does not end until the work is
5
5
  # handed over. Stop.
6
6
  #
@@ -25,6 +25,9 @@
25
25
  # 5. The session handover is written — the window has run out.
26
26
  # 6. The owner said to stop.
27
27
  #
28
+ # Under an open epic the second and the fifth do not release, and a second pass is judged again:
29
+ # until the epic is closed the executor does not stop on its own. The tiers lie in `turn-exit-epic.sh`.
30
+ #
28
31
  # Work without a branch and without a task folder is judged by the second sign. It has no state,
29
32
  # and there is nowhere to take the first sign from — but a turn without a single edit of the tree
30
33
  # does not end here either: the owner's request "lay it out", "update it", "take a look" lives
@@ -48,6 +51,8 @@ rt_hook_read
48
51
  # fallback line in case there is no parser. These twelve lines used to stand as eight copies — the
49
52
  # file grew faster on every new tier than on the requirement itself.
50
53
  rt_te_deny() {
54
+ # The end of an epic releases the turn whatever tier came here: the epic is read only on this road.
55
+ command -v rt_te_epic_over >/dev/null 2>&1 && rt_te_epic_over && exit 0
51
56
  rt_te_reason="$1"
52
57
  rt_te_short="$2"
53
58
  # shellcheck disable=SC1090
@@ -68,9 +73,7 @@ input="$RT_HOOK_INPUT"
68
73
  [ -z "$input" ] && exit 0
69
74
  command -v jq >/dev/null 2>&1 || exit 0
70
75
 
71
- # A second pass over the same turn is not judged: the guard has said its piece once and lets go.
72
76
  active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
73
- [ "$active" = "true" ] && exit 0
74
77
 
75
78
  transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
76
79
  [ -z "$transcript" ] && exit 0
@@ -84,6 +87,12 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
84
87
  root="$(git rev-parse --show-toplevel 2>/dev/null)"
85
88
  [ -z "$root" ] && exit 0
86
89
 
90
+ # The tiers of the open epic lie in a neighbouring file. A second pass over the same turn is judged
91
+ # only under an open epic: outside it the guard has said its piece once and lets go.
92
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/turn-exit-epic.sh" 2>/dev/null || exit 0
93
+ command -v rt_te_epic_open >/dev/null 2>&1 || exit 0
94
+ [ "$active" = "true" ] && ! rt_te_epic_open && exit 0
95
+
87
96
  # The branch, the task folder and the state line are taken while they are there. Empty — the turn
88
97
  # is judged by the second sign, not released: this is where it used to leave with zero, and work by
89
98
  # the owner's word ended with an announcement of intent, silently.
@@ -101,6 +110,7 @@ fi
101
110
  case "$state" in
102
111
  работа-отдана | влито) exit 0 ;;
103
112
  esac
113
+ rt_te_owner_word_quoted && exit 0 # the owner's standing word quoted in the waiting line
104
114
 
105
115
  # A written plan is never the end of a turn at all. The mandatory action of this state is to do the
106
116
  # first stage, and whoever starts it moves the state by the same edit: a turn left in the previous
@@ -171,20 +181,15 @@ rt_te_verdict
171
181
 
172
182
  [ -z "$verdict" ] && exit 0
173
183
 
174
- worked="$(printf '%s' "$verdict" | jq -r '.worked // false' 2>/dev/null)"
175
- waited="$(printf '%s' "$verdict" | jq -r '.waited // false' 2>/dev/null)"
176
- handed_over="$(printf '%s' "$verdict" | jq -r '.handed_over // false' 2>/dev/null)"
177
- started_next="$(printf '%s' "$verdict" | jq -r '.started_next // false' 2>/dev/null)"
178
- ended_working="$(printf '%s' "$verdict" | jq -r '.ended_working // false' 2>/dev/null)"
179
- released="$(printf '%s' "$verdict" | jq -r '.released // false' 2>/dev/null)"
184
+ # Every sign of the verdict becomes a variable of its own name; the commands go apart, they are text.
185
+ eval "$(printf '%s' "$verdict" | jq -r 'del(.ran) | to_entries[] | "\(.key)=\(.value | tostring | @sh)"' 2>/dev/null)"
180
186
  commands="$(printf '%s' "$verdict" | jq -r '.ran // ""' 2>/dev/null)"
181
187
 
182
188
  # A question refused by the conversation guard and asked as prose in the same turn. A guard refusal
183
189
  # releases the turn — it is the lawful end itself — but there is nothing to release here: the same
184
190
  # question came back a line later, and the work stalled on what the tree had already answered. The
185
191
  # tier stands before the lawful exits on purpose: a guard refusal covers exactly this case.
186
- asked_in_prose="$(printf '%s' "$verdict" | jq -r '.asked_in_prose // false' 2>/dev/null)"
187
- if [ "$asked_in_prose" = "true" ]; then
192
+ if [ "${asked_in_prose:-false}" = "true" ]; then
188
193
  rt_te_deny "BLOCKED by turn-exit-guard: in this turn the conversation guard refused a question to the owner, and the reply ends with a question in prose — the same question, asked in another form.
189
194
 
190
195
  The refusal of the guard named the reason: the answer lies in the tree or the owner has already given it. Read the place it named and work on; what is asked is what the tree does not hold.
@@ -200,11 +205,6 @@ fi
200
205
  # named a refusal to the owner, not a turn that said "waiting".
201
206
  # Incident analysis — the record
202
207
  # "2026-09-04-hod-konchalsya-ozhidaniem-pri-deystvuyushchem-ukazanii" in the intake.
203
- awaits_word="$(printf '%s' "$verdict" | jq -r '.awaits_word // false' 2>/dev/null)"
204
- standing_work="$(printf '%s' "$verdict" | jq -r '.standing_work // false' 2>/dev/null)"
205
- promised="$(printf '%s' "$verdict" | jq -r '.promised // false' 2>/dev/null)"
206
- only_took="$(printf '%s' "$verdict" | jq -r '.only_took // false' 2>/dev/null)"
207
-
208
208
  # A promise to do the work in the next turn. The same announcement of intent as a command named and
209
209
  # not run: the tier stands before the lawful exits, because the promise most often stands next to a
210
210
  # report about what was done, and by the fullness of the turn it is indistinguishable from a finish.
@@ -232,9 +232,6 @@ Write the plan and begin its first stage in this same turn.
232
232
 
233
233
  The guard judges one turn: the next session is not refused." "the turn ended with taking a task."
234
234
  fi
235
- # At the end of an epic waiting for the word of the owner is the work itself: the reading of that
236
- # lies with the patterns and is shared with the guard of the stop.
237
- [ "$awaits_word" = "true" ] && rt_te_epic_over && awaits_word=false
238
235
 
239
236
  # The owner said to work without stops and did not cancel it. Their word holds until they cancel
240
237
  # it, and a turn ending with waiting for that same word invents the cancellation. Judged whether or
@@ -259,6 +256,19 @@ The next step is written in the progress: ${next_step}
259
256
  The guard judges one turn: the next session is not refused." "the turn ended with waiting for the word of the owner."
260
257
  fi
261
258
 
259
+ # A question without a single piece of work in a running stage: the parts that do not depend on
260
+ # the answer go first, and the question after them.
261
+ if [ "${asked:-false}" = "true" ] && [ "$worked" != "true" ] && [ "$state" = "этап-идёт" ]; then
262
+ rt_te_question_without_work_deny
263
+ fi
264
+
265
+ # A handover written by the hand of the executor before the window filled is a stop announced by
266
+ # the one it suits: under an open epic it releases nothing. The window guard's refusal releases as
267
+ # any refusal, and the handover on compaction is written by the hook, not by a command in the turn.
268
+ if [ "${handed_by_hand:-false}" = "true" ] && rt_te_epic_open; then
269
+ rt_te_epic_deny handed-by-hand
270
+ fi
271
+
262
272
  [ "$released" = "true" ] && exit 0
263
273
 
264
274
  # Work that has reached the handover and has not been handed over. The two states in the `case`
@@ -308,7 +318,8 @@ esac
308
318
  # A folder taken apart by a branch commit does not get here: `archived` means handed-over work, and
309
319
  # the previous tier judges it. A branch without a task number is not judged at all — such ones are
310
320
  # created for a trial too.
311
- if [ "$archived" != "true" ] && [ -z "$progress" ] && [ -n "$branch" ] && [ ! -d "$root/$tasks_dir/$branch" ]; then
321
+ # An epic branch is not judged either: it carries no folder by the rule, and the epic plan names it.
322
+ if [ "$archived" != "true" ] && [ -z "$progress" ] && [ -n "$branch" ] && [ ! -d "$root/$tasks_dir/$branch" ] && ! rt_te_epic_branch; then
312
323
  task_key="${RT_TASK_KEY:-}"
313
324
  if [ -z "$task_key" ] && [ -f "$root/.claude/rt-kit/checks.json" ]; then
314
325
  task_key="$(jq -r '.board.taskKey // empty' "$root/.claude/rt-kit/checks.json" 2>/dev/null)"
@@ -368,6 +379,8 @@ The guard judges one turn: the next session is not refused."
368
379
  rt_te_deny "$reason" "a closed stage is not backed by the output of a command."
369
380
  fi
370
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
371
384
 
372
385
  # The work is handed over and the next one is only named. There is more work in such a turn than in
373
386
  # any other — and all of it is on the task handed in: the handover finishes the previous work, not
@@ -407,7 +420,7 @@ The guard judges one turn: the next session is not refused."
407
420
 
408
421
  rt_te_deny "$reason" "the turn ended with waiting for a step by someone else."
409
422
  fi
410
-
423
+ command -v rt_te_launch_last_deny >/dev/null 2>&1 && rt_te_launch_last_deny
411
424
  # The shared line. There was work in the turn — but the last action was not it, it was a text to the
412
425
  # owner. The particular tiers above name the kind of stop more precisely; what reaches here is what
413
426
  # they do not know by name.
@@ -435,9 +448,7 @@ if [ "$worked" = "true" ] && [ "$handed_over" != "true" ]; then
435
448
  if [ -n "$unpushed" ] && [ "$unpushed" -gt 0 ] 2>/dev/null; then
436
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}.
437
450
 
438
- 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.
439
-
440
- 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.
441
452
 
442
453
  The guard judges one turn: the next session is not refused."
443
454
 
@@ -445,6 +456,11 @@ The guard judges one turn: the next session is not refused."
445
456
  fi
446
457
  fi
447
458
 
459
+ rt_te_steps_deny "$progress" # the steps of the plan are not done; the tier lies in the patterns
460
+
461
+ # There was work in the turn, and the epic is open: the turn is released outside an epic and under a
462
+ # closed one alone. Under an open epic the work stands where it stood, and the next step is named.
463
+ [ "$worked" = "true" ] && rt_te_epic_open && rt_te_epic_deny worked
448
464
  [ "$worked" = "true" ] && exit 0
449
465
 
450
466
  if [ "$archived" = "true" ]; then
@@ -69,12 +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
- # The end of an epic: there waiting for the word of the owner is the work itself, and the guard of
73
- # the stop refuses taking the next task. The reading lies apart and is shared by the three guards;
74
- # it goes to the hosting, so the guard asks it right before a refusal, not on every turn.
75
- rt_te_epic_over() {
76
- # shellcheck disable=SC1090
77
- . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/epic-over.sh" 2>/dev/null || return 1
78
- command -v rt_epic_over >/dev/null 2>&1 || return 1
79
- rt_epic_over
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."
80
122
  }
@@ -9,9 +9,16 @@
9
9
 
10
10
  rt_te_verdict() {
11
11
  verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re" --arg read "$read_re" --arg part "$part_re" --arg wait "$wait_re" --arg handover "$handover_re" --arg started "$started_re" --arg promise "$promise_re" --arg standing "$standing_work_re" '
12
+ # A service message — a skill load, a compaction summary — carries the user type and is not the word
13
+ # of the owner: it neither starts a turn nor is read as one.
14
+ def is_service:
15
+ ((.isCompactSummary // false) or (.isMeta // false))
16
+ or ((.message.content // "") | if type == "string" then . elif type == "array"
17
+ then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
18
+ | test("^[[:space:]]*Stop hook feedback"));
12
19
  def is_input:
13
20
  .type == "user"
14
- and ((.isCompactSummary // false) | not)
21
+ and (is_service | not)
15
22
  and (((.message.content // []) | if type == "array"
16
23
  then ([.[] | select(.type == "tool_result")] | length)
17
24
  else 0 end) == 0);
@@ -30,6 +37,10 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
30
37
  # however much work there was before: the work stays exactly where it stood.
31
38
  | ([$uses[] | select((.name // "") == "Bash") | ((.input.command // "") + (if (.input.run_in_background // false) then " &" else "" end))] | last // "") as $last
32
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
33
44
  | (($last_name == "Bash") and ($last | test($wait))) as $waited
34
45
  # Handing the work over: the tail of the turn after the PR was opened. Everything before it was
35
46
  # done on the task handed in and says nothing about the next one.
@@ -47,23 +58,28 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
47
58
  | ([$uses[] | (.name // "")] | last // "") as $last_tool
48
59
  | (($last_tool | test("^(Edit|Write|MultiEdit|NotebookEdit)$"))
49
60
  or ([$last | splits($part)] | map(test($work) and (test($read) | not)) | any)) as $ended_working
50
- # A guard refusal and a session handover — both end the turn by the rule.
61
+ # A guard refusal and a session handover — both end the turn by the rule. The refusal is read
62
+ # from the LAST tool result: a refusal in the middle of the turn was answered by the work that
63
+ # followed it, and a turn that went on after it is judged by how it ended.
51
64
  | ([$turn[] | select(.type == "user") | .message.content // [] | select(type == "array") | .[]
52
65
  | select(.type == "tool_result") | .content
53
66
  | if type == "string" then .
54
67
  elif type == "array" then (map(if type == "object" then (.text // "") else tostring end) | join("\n"))
55
- else tostring end] | join("\n")) as $out
56
- | (($out | test("BLOCKED by|Refused by the rules gate|Отбито гейтом")) or ($ran | test("BLOCKED by"))) as $denied
68
+ else tostring end]) as $outs
69
+ | ($outs | join("\n")) as $out
70
+ | ($outs | last // "") as $last_out
71
+ # The refusal of the closing tool is left out: the refused call was itself the stop, not work.
72
+ | ($last_out | test("BLOCKED by (?!end-conversation-guard)|Refused by the rules gate|Отбито гейтом")) as $denied
57
73
  | ($ran | test("handoff")) as $handed
58
74
  # The word of the owner about stopping: the reply itself is judged, not its retelling.
59
- | ([$turn[] | select(.type == "user") | .message.content
75
+ | ([$turn[] | select(.type == "user") | select(is_service | not) | .message.content
60
76
  | if type == "string" then . elif type == "array"
61
77
  then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end] | join("\n")) as $said
62
- | ([.[] | select(.type == "user") | .message.content
78
+ | ([.[] | select(.type == "user") | select(is_service | not) | .message.content
63
79
  | if type == "string" then . elif type == "array"
64
80
  then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end] | join("\n")) as $session_said
65
81
  | ($session_said | test($standing)) as $standing_work
66
- | (($said | test("останов|стоп|хватит|подожди|не надо|прерв|отложи")) and ($said | test($standing) | not)) as $told_stop
82
+ | (($said | test("останов|стоп|хватит|подожди|не надо|прерв|отложи|не двигайся|не продолжай|прекрати")) and ($said | test($standing) | not)) as $told_stop
67
83
  # A question refused by the conversation guard, and a question appended as prose at the end of
68
84
  # the reply. The conversation guard judges the call of the question tool and does not see prose
69
85
  # at all: a refused question came back in the same wording one turn later and passed freely.
@@ -78,7 +94,22 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
78
94
  | (($last_say | test("[Жж]ду (твоего|вашего|его|её) (слова|указани|решени|ответа|команды|отмашки)|[Жж]ду слова владельца|[Жж]ду, что скаж|[Оо]стаюсь ждать|[Бб]уду ждать (твоего|вашего)"))
79
95
  and (($asked or $told_stop or $handed) | not)) as $awaits_word
80
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
81
112
  | (($last_name == "Bash") and ($last | test($started)) and ($handed_over | not)) as $only_took
82
- | { promised: $promised, only_took: $only_took, 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 }
83
114
  ' 2>/dev/null)"
84
115
  }