@rt-tools/agent-kit 0.34.0 → 0.36.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 (123) hide show
  1. package/README.md +6 -6
  2. package/assets/agents/goal-critic.md +9 -0
  3. package/assets/agents/product-strategist.md +5 -0
  4. package/assets/defaults/gate-map.sh +6 -0
  5. package/assets/defaults/project.sh +39 -0
  6. package/assets/defaults/turn-map.md +1 -1
  7. package/assets/hooks/browser-guard-device-id.sh +1 -0
  8. package/assets/hooks/browser-guard-no-asking.sh +1 -0
  9. package/assets/hooks/browser-guard-no-listing.sh +1 -0
  10. package/assets/hooks/browser-guard-no-other-drivers.sh +1 -0
  11. package/assets/hooks/browser-guard-require-select.sh +1 -0
  12. package/assets/hooks/claim-guard.sh +1 -0
  13. package/assets/hooks/dev-server-guard.sh +1 -0
  14. package/assets/hooks/docs-guard.sh +1 -0
  15. package/assets/hooks/end-conversation-guard.sh +1 -0
  16. package/assets/hooks/epic-stop-guard.sh +37 -1
  17. package/assets/hooks/exam-guard.sh +5 -0
  18. package/assets/hooks/git-guard-delivery-draft.sh +23 -0
  19. package/assets/hooks/git-guard-delivery-folder.sh +25 -4
  20. package/assets/hooks/git-guard-delivery-signature.sh +19 -0
  21. package/assets/hooks/git-guard-delivery.sh +7 -18
  22. package/assets/hooks/git-guard-discard.sh +1 -0
  23. package/assets/hooks/git-guard-main.sh +1 -0
  24. package/assets/hooks/git-guard-no-verify.sh +1 -0
  25. package/assets/hooks/git-guard-push-ahead.sh +9 -0
  26. package/assets/hooks/git-guard-push-tests.sh +1 -0
  27. package/assets/hooks/grill-gate.sh +1 -0
  28. package/assets/hooks/guard-note.sh +11 -3
  29. package/assets/hooks/handover-mark.sh +37 -0
  30. package/assets/hooks/metric-marks.sh +233 -0
  31. package/assets/hooks/metric-send-start.sh +38 -0
  32. package/assets/hooks/observe.sh +103 -0
  33. package/assets/hooks/owner-corrections.sh +36 -0
  34. package/assets/hooks/prose-style-guard.sh +1 -0
  35. package/assets/hooks/pull-outcomes.sh +59 -0
  36. package/assets/hooks/push-set.sh +11 -1
  37. package/assets/hooks/qa-dataid-guard.sh +1 -0
  38. package/assets/hooks/rerun-guard.sh +1 -0
  39. package/assets/hooks/reuse-first-guard.sh +1 -0
  40. package/assets/hooks/role-calls.sh +120 -0
  41. package/assets/hooks/rule-source-guard.sh +16 -0
  42. package/assets/hooks/skill-gate.sh +23 -0
  43. package/assets/hooks/task-flow-draft-guard.sh +1 -0
  44. package/assets/hooks/task-flow-guard.sh +1 -0
  45. package/assets/hooks/tree-assignment-guard.sh +1 -0
  46. package/assets/hooks/turn-exit-epic.sh +24 -0
  47. package/assets/hooks/turn-exit-guard.sh +1 -21
  48. package/assets/hooks/waiting-turn-guard.sh +1 -0
  49. package/assets/hooks/window-fill-guard.sh +1 -0
  50. package/assets/hooks/work-start-guard.sh +1 -0
  51. package/assets/patterns/epic-flow-declare.md +71 -0
  52. package/assets/patterns/git-workflow-commit.azure.md +5 -3
  53. package/assets/patterns/git-workflow-commit.github.md +5 -3
  54. package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
  55. package/assets/patterns/spec-driven-rule.md +4 -0
  56. package/assets/patterns/task-flow-close.md +5 -6
  57. package/assets/patterns/task-flow-cycle.md +73 -0
  58. package/assets/patterns/task-flow-start.md +4 -43
  59. package/assets/rules/epic-flow.md +91 -0
  60. package/assets/rules/task-flow.md +14 -41
  61. package/assets/samples/tasks/_template/plan.md +1 -0
  62. package/assets/templates/postmortem.md +2 -0
  63. package/bin/agent-kit.d.ts.map +1 -1
  64. package/bin/agent-kit.js +28 -0
  65. package/bin/agent-kit.js.map +1 -1
  66. package/lib/cargo.d.ts +35 -0
  67. package/lib/cargo.d.ts.map +1 -1
  68. package/lib/cargo.js +76 -0
  69. package/lib/cargo.js.map +1 -1
  70. package/lib/commands.d.ts +9 -0
  71. package/lib/commands.d.ts.map +1 -1
  72. package/lib/commands.js +32 -19
  73. package/lib/commands.js.map +1 -1
  74. package/lib/config.d.ts +5 -0
  75. package/lib/config.d.ts.map +1 -1
  76. package/lib/config.js +1 -0
  77. package/lib/config.js.map +1 -1
  78. package/lib/file-lock.d.ts +4 -0
  79. package/lib/file-lock.d.ts.map +1 -0
  80. package/lib/file-lock.js +23 -0
  81. package/lib/file-lock.js.map +1 -0
  82. package/lib/metric-lines.d.ts +20 -0
  83. package/lib/metric-lines.d.ts.map +1 -0
  84. package/lib/metric-lines.js +117 -0
  85. package/lib/metric-lines.js.map +1 -0
  86. package/lib/metric-send-mark.d.ts +52 -0
  87. package/lib/metric-send-mark.d.ts.map +1 -0
  88. package/lib/metric-send-mark.js +69 -0
  89. package/lib/metric-send-mark.js.map +1 -0
  90. package/lib/metric-send.d.ts +18 -0
  91. package/lib/metric-send.d.ts.map +1 -0
  92. package/lib/metric-send.js +226 -0
  93. package/lib/metric-send.js.map +1 -0
  94. package/lib/metric-usage.d.ts +34 -0
  95. package/lib/metric-usage.d.ts.map +1 -0
  96. package/lib/metric-usage.js +111 -0
  97. package/lib/metric-usage.js.map +1 -0
  98. package/lib/metrics.d.ts +92 -0
  99. package/lib/metrics.d.ts.map +1 -0
  100. package/lib/metrics.js +263 -0
  101. package/lib/metrics.js.map +1 -0
  102. package/lib/observations-cargo.d.ts +2 -0
  103. package/lib/observations-cargo.d.ts.map +1 -1
  104. package/lib/observations-cargo.js +1 -1
  105. package/lib/observations-cargo.js.map +1 -1
  106. package/lib/observations.d.ts +22 -2
  107. package/lib/observations.d.ts.map +1 -1
  108. package/lib/observations.js +40 -13
  109. package/lib/observations.js.map +1 -1
  110. package/lib/outcomes.d.ts +89 -0
  111. package/lib/outcomes.d.ts.map +1 -0
  112. package/lib/outcomes.js +274 -0
  113. package/lib/outcomes.js.map +1 -0
  114. package/lib/ship.js +1 -1
  115. package/lib/ship.js.map +1 -1
  116. package/lib/shipment.d.ts.map +1 -1
  117. package/lib/shipment.js +7 -1
  118. package/lib/shipment.js.map +1 -1
  119. package/lib/snapshot.d.ts +2 -0
  120. package/lib/snapshot.d.ts.map +1 -1
  121. package/lib/snapshot.js +6 -0
  122. package/lib/snapshot.js.map +1 -1
  123. package/package.json +1 -1
package/README.md CHANGED
@@ -27,6 +27,8 @@ npx agent-kit sync # разложить выбранное в docs/constitu
27
27
  npx agent-kit doctor # что разложено, что отстало, чего не хватает
28
28
  npx agent-kit adopt # отдать пакету файлы, лежащие на его путях не от него
29
29
  npx agent-kit stats # чем пользовались, чем ни разу, обо что спотыкались
30
+ npx agent-kit metrics # отказы, повторы, мёртвые правила и вес входа за месяц
31
+ npx agent-kit send # отправить числа по дням: проверки и сессии делают это сами
30
32
  npx agent-kit cost # сколько весит вход в работу, одно правило и весь слой
31
33
  ```
32
34
 
@@ -268,8 +270,7 @@ npx agent-kit init --laws access,delivery,verifiability
268
270
  самого в ней нет — значение со слэшем не пишется вовсе.
269
271
 
270
272
  ```bash
271
- npx agent-kit stats --days 3 # за отрезок; без довода — за три дня
272
- npx agent-kit stats --json # то же машиночитаемо
273
+ npx agent-kit stats --days 3 --json # за отрезок, машиночитаемо; без довода — за три дня
273
274
  ```
274
275
 
275
276
  Самая ценная строка сводки — не «чем пользовались», а **что разложено и не загружено ни разу**:
@@ -352,8 +353,7 @@ npx agent-kit enroll --token <токен> # положить токе
352
353
 
353
354
  ### Что для этого нужно
354
355
 
355
- Наблюдения и сводка живут целиком на машине; в сеть ходит только отправка, и только по команде
356
- человека. Приём — своя служба, а не чужая: она поднимается там, где решит владелец пакета.
356
+ Наблюдения и сводка живут на машине. Текст уходит по команде человека, числа дерево шлёт само (выключает `send: false`).
357
357
 
358
358
  | Где | Что нужно |
359
359
  | --- | --- |
@@ -372,8 +372,8 @@ npx agent-kit enroll --token <токен> # положить токе
372
372
  репозитория: адрес по нему не восстанавливается, а у двух рабочих копий одного репозитория он
373
373
  один. Репозитория нет — признак называется ключом `tree`.
374
374
 
375
- Адреса нет, токена нет, токен отозван — отправка отказывает ненулевым кодом и называет, чего
376
- именно не хватило и где это объявляется. Молчаливая отправка выглядела бы работающей.
375
+ Адреса нет, токена нет, токен отозван — команда человека отказывает ненулевым кодом и называет, чего
376
+ не хватило. Тихий запуск пишет сбой в метку, его называют `agent-kit doctor` и начало сессии.
377
377
 
378
378
  ## Роли и конвейеры
379
379
 
@@ -9,6 +9,11 @@ You judge whether what was built is what the owner asked for. You answer **in th
9
9
  You have neither `Write` nor `Edit`, and you change neither the code nor the texts. `Bash` is for
10
10
  reading and for running what the result claims to do.
11
11
 
12
+ A copy a check needs goes into a directory named after you under the session's scratchpad, and
13
+ nothing is removed — neither by `rm` nor by a cleanup at the end: the scratchpad is shared with the
14
+ session that called you, and a removing command waits in the background for a permission nobody
15
+ answers.
16
+
12
17
  A session writes its own plan, points and signs and then checks itself against them. Everything can
13
18
  turn green while the goal stays unchecked. You are the check that does not stand on what the session
14
19
  wrote.
@@ -43,6 +48,10 @@ own? What does it add that the owner did not ask for?
43
48
  **Result.** For every requirement, what can the owner do now that they could not before, shown from
44
49
  their side? What stands only in a branch, only in a text, or only on this machine?
45
50
 
51
+ **Cycle.** The prompt gives the metric of an edit, its direction, baseline and noise, and the report
52
+ after it. Over the same trees, did the number move past the noise in that direction? If not, the
53
+ verdict is «не сдвинулось», with both numbers. The executor's explanation of why is not evidence.
54
+
46
55
  **PR description.** The prompt gives the description and the replies of the roles. Every "done" and
47
56
  "reached" in the description is tried against the result. A word of a role that differs from its
48
57
  reply is a miss, whatever the session's reason was.
@@ -11,6 +11,11 @@ You have neither `Write` nor `Edit`, and you change neither the code nor the tex
11
11
  reading and for running the sign of a point: `git log`, `ls`, `grep`, `find`, `gh` reads, the tree's
12
12
  read commands and the command a sign names.
13
13
 
14
+ A copy a sign needs goes into a directory named after you under the session's scratchpad, and
15
+ nothing is removed — neither by `rm` nor by a cleanup at the end: the scratchpad is shared with the
16
+ session that called you, and a removing command waits in the background for a permission nobody
17
+ answers.
18
+
14
19
  ## The points
15
20
 
16
21
  - **A** — where the product stands now, by what the tree and the host show today.
@@ -221,6 +221,12 @@ skill_for_default() {
221
221
  rt_gate_invokes "$target" "(gh[[:space:]]+pr|glab[[:space:]]+mr)[[:space:]]+merge" \
222
222
  && printf '%s\n' 'task-flow'
223
223
 
224
+ # Declaring an epic and creating its tasks follow the rule of the epic: the card, the
225
+ # plan and every task at once. Required as the SECOND layer, on top of the delivery rule.
226
+ rt_gate_invokes "$target" "[^[:space:]]*task:new" \
227
+ && printf '%s' "$target" | grep -qE -- '--epic(-of)?([[:space:]=]|$)' \
228
+ && printf '%s\n' 'epic-flow'
229
+
224
230
  # A request to a running application: what lies here is not the code but what answers on
225
231
  # the port. The reply of the previous session's build is indistinguishable from the
226
232
  # reply of the live branch. Both signs are needed — the client call AND the address: the
@@ -361,6 +361,44 @@ rt_conflicting_pulls_default() {
361
361
  printf '%s' "$state" | jq -r '.conflicting[]? | "#\(.number) \(.branch)"'
362
362
  }
363
363
 
364
+ # The requests merged or closed since a day, for the package metrics: one JSON object per line. The
365
+ # default asks GitHub, and another hosting declares the function by the same shape, which is named in
366
+ # `hooks/pull-outcomes.sh`. A failing exit code means «nobody to ask», and such a tree is counted
367
+ # apart. The task comes from the title: the head of a revert request names the request, not the task.
368
+ # An epic is told by the label of its card, as the delivery guard tells it: a request carries none.
369
+ # A request never handed over counts apart, so the hosting is asked no more about it: one call per
370
+ # request made a first read of a busy tree outlive the report.
371
+ rt_pull_outcomes_default() {
372
+ command -v gh >/dev/null 2>&1 || return 3
373
+ command -v jq >/dev/null 2>&1 || return 3
374
+ list="$(gh pr list --state all --limit 1000 --search "closed:>=$1" \
375
+ --json number,state,headRefName,title,closedAt 2>/dev/null)" || return 4
376
+ printf '%s' "$list" | jq -c '.[] | select(.state != "OPEN")' | while IFS= read -r pull; do
377
+ number="$(printf '%s' "$pull" | jq -r '.number')"
378
+ head="$(printf '%s' "$pull" | jq -r '.headRefName')"
379
+ task="$(printf '%s' "$pull" | jq -r '(.title | capture("\\[[A-Za-z]+-(?<n>[0-9]+)\\]").n)? // empty')"
380
+ commits='[]'
381
+ labels='[]'
382
+ if ! command -v rt_handover_known >/dev/null 2>&1 || rt_handover_known "$head"; then
383
+ commits="$(gh api "repos/{owner}/{repo}/pulls/$number/commits?per_page=100" \
384
+ --jq '[.[] | {sha, tree: .commit.tree.sha, parents: (.parents | length)}]' 2>/dev/null)"
385
+ [ -n "$commits" ] || return 4
386
+ [ -z "$task" ] || labels="$(gh api "repos/{owner}/{repo}/issues/$task" --jq '[.labels[].name]' 2>/dev/null)"
387
+ fi
388
+ printf '%s' "$pull" | jq -c --argjson commits "$commits" --argjson labels "${labels:-[]}" \
389
+ --arg task "$task" --arg epic "${RT_BOARD_EPIC_LABEL:-}" '{
390
+ number,
391
+ commits: $commits,
392
+ head: .headRefName,
393
+ merged: (.state == "MERGED"),
394
+ closed: (.closedAt // "" | .[0:10]),
395
+ task: (if $task == "" then null else ($task | tonumber) end),
396
+ revert: (.title | startswith("Revert")),
397
+ epic: ($epic != "" and ($labels | index($epic) != null))
398
+ }'
399
+ done
400
+ }
401
+
364
402
  # What counts as reinvention in this tree. One line per "pattern<tab>replacement". The patterns are
365
403
  # narrow on purpose: the guard checks only NEW text, and a wide pattern would refuse an edit that
366
404
  # creates nothing new.
@@ -408,6 +446,7 @@ rt_docs_pair_for() { rt_docs_pair_for_default "$@"; }
408
446
  rt_lint_for() { rt_lint_for_default "$@"; }
409
447
  rt_task_branch_ok() { rt_task_branch_ok_default "$@"; }
410
448
  rt_task_branch_number() { rt_task_branch_number_default "$@"; }
449
+ rt_pull_outcomes() { rt_pull_outcomes_default "$@"; }
411
450
  rt_reinvented_in() { rt_reinvented_in_default "$@"; }
412
451
  rt_is_app_code() { rt_is_app_code_default "$@"; }
413
452
  # The directory of the rules package sources in this tree, from the root. Empty — the tree does not
@@ -10,7 +10,7 @@ mandatory action is done, the work stays in the same state.
10
10
  ## States and mandatory actions
11
11
 
12
12
  - `просьба-не-разобрана` — explore the tree, then ask; leads `task-flow-start`
13
- - `эпик-заведён` — take the epic branch from the main branch; leads `task-flow-start`
13
+ - `эпик-заведён` — take the epic branch from the main branch; leads `epic-flow-declare`
14
14
  - `разбор-закрыт` — the product agreement or the reason there is none; leads `task-flow-start`
15
15
  - `договорённость-записана` — create the task, the branch from the epic branch, and the folder; leads `task-flow-start`
16
16
  - `задача-взята` — write the plan; leads `task-flow-start`
@@ -27,6 +27,7 @@
27
27
 
28
28
  # The guard's name for the observations: it is written by the shared deny tail.
29
29
  RT_GUARD_NAME=browser-guard-device-id
30
+ RT_GUARD_RULE=browser-verification
30
31
 
31
32
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
32
33
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -21,6 +21,7 @@
21
21
  # Its own name in the observations: the refusal is recorded by the shared deny tail, not by the
22
22
  # guard itself.
23
23
  RT_GUARD_NAME=browser-guard-no-asking
24
+ RT_GUARD_RULE=browser-verification
24
25
 
25
26
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
26
27
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -13,6 +13,7 @@
13
13
  # Its own name in the observations: the refusal is recorded by the shared deny tail, not by the
14
14
  # guard itself.
15
15
  RT_GUARD_NAME=browser-guard-no-listing
16
+ RT_GUARD_RULE=browser-verification
16
17
 
17
18
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
18
19
 
@@ -23,6 +23,7 @@
23
23
  # Own name in the observations: the refusal is written by the shared refusal tail, not by the
24
24
  # guard itself.
25
25
  RT_GUARD_NAME=browser-guard-no-other-drivers
26
+ RT_GUARD_RULE=browser-verification
26
27
 
27
28
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
28
29
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -23,6 +23,7 @@
23
23
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
24
24
  # guard itself.
25
25
  RT_GUARD_NAME=browser-guard-require-select
26
+ RT_GUARD_RULE=browser-verification
26
27
 
27
28
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
28
29
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -35,6 +35,7 @@
35
35
 
36
36
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
37
37
  RT_GUARD_NAME=claim-guard
38
+ RT_GUARD_RULE=turn-conduct
38
39
 
39
40
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
40
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -32,6 +32,7 @@
32
32
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
33
33
  # guard itself.
34
34
  RT_GUARD_NAME=dev-server-guard
35
+ RT_GUARD_RULE=browser-verification
35
36
 
36
37
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
37
38
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -30,6 +30,7 @@
30
30
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
31
31
  # guard itself.
32
32
  RT_GUARD_NAME=docs-guard
33
+ RT_GUARD_RULE=doc-style
33
34
 
34
35
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
35
36
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -18,6 +18,7 @@
18
18
 
19
19
  # Its own name in the observations: the refusal is recorded by the shared deny tail.
20
20
  RT_GUARD_NAME=end-conversation-guard
21
+ RT_GUARD_RULE=turn-conduct
21
22
 
22
23
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
23
24
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -24,6 +24,7 @@
24
24
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
25
25
  # guard itself.
26
26
  RT_GUARD_NAME=epic-stop-guard
27
+ RT_GUARD_RULE=turn-conduct
27
28
 
28
29
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
29
30
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -115,13 +116,48 @@ if [ -n "$taken" ] && [ -n "$transcript" ] && [ -f "$transcript" ]; then
115
116
  [ "$named" = "true" ] && exit 0
116
117
  fi
117
118
 
119
+ # A created task has no number yet, so no menu answer can name it, and the owner's answer to «create
120
+ # a task for these findings?» left the call refused. The word of the owner here is their latest
121
+ # answer to a menu: no message of theirs stands after it, the answer agrees to a task — a word of a
122
+ # task, of creating it, or a plain «yes» — and it is not a refusal. Any answer was too wide: «not
123
+ # now» and an answer about a button colour passed alike. A new epic needs the word of an epic.
124
+ if [ -z "$taken" ] && [ -n "$transcript" ] && [ -f "$transcript" ] \
125
+ && printf '%s' "$cmd" | grep -qE 'task:new|task-new\.mjs' 2>/dev/null; then
126
+ consent='задач|карточ|task|issue|заве|завод|созда|create|^\s*(да|yes|ок|ok)([^[:alpha:]]|$)'
127
+ if printf '%s' "$cmd" | grep -qE -- '--epic([[:space:]=]|$)' 2>/dev/null; then
128
+ consent='эпик|epic'
129
+ fi
130
+ latest="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg consent "$consent" '
131
+ [.[] | select(.type == "user")
132
+ | select(((.isMeta // false) or (.isCompactSummary // false)) | not)
133
+ | (.message.content // "")
134
+ | if type == "string" then {said: .}
135
+ elif type == "array" then (map(
136
+ if .type == "text" then {said: (.text // "")}
137
+ elif .type == "tool_result" then ((.content
138
+ | if type == "string" then . elif type == "array"
139
+ then (map(if type == "object" then (.text // "") else "" end) | join(" ")) else "" end)
140
+ | if test("^(The user answered|Your questions have been answered):")
141
+ then {menu: ([match("\"=\"([^\"]*)\""; "g") | .captures[0].string] | first // "")}
142
+ else empty end)
143
+ else empty end) | .[])
144
+ else empty end]
145
+ | (last // {})
146
+ | if (.menu // "") != ""
147
+ and (.menu | test($consent; "i"))
148
+ and ((.menu | test("^\\s*(нет|не\\s|нельзя|no\\b|стоп|stop|отмен|cancel|подожд|wait|позже|later|пока ничего|ничего|nothing)"; "i")) | not)
149
+ then "yes" else "no" end
150
+ ' 2>/dev/null)"
151
+ [ "$latest" = "yes" ] && exit 0
152
+ fi
153
+
118
154
  root="$(git rev-parse --show-toplevel 2>/dev/null)"
119
155
  checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
120
156
  if [ -z "$checks" ] || [ "$checks" = null ]; then
121
157
  checks=tools
122
158
  fi
123
159
 
124
- reason="Refused: the epic is over — every task of it is merged or handed over by a request, and this call takes new work. The end of an epic is a stop: print the table by «npm run epic:table» (or «node $checks/epic-table.mjs»), tell the owner what was done on each task and what confirms it, and say outright that the session waits for their orders. New work is taken by their word, not by the count of what is left: their message or their answer to a menu that names the number of this work releases the call. A new epic the owner has declared needs the bypass line in the calls that create its card, its tasks and its branch; once the branch of the new epic is taken, the guard reads that epic and stops refusing."
160
+ reason="Refused: the epic is over — every task of it is merged or handed over by a request, and this call takes new work. The end of an epic is a stop: print the table by «npm run epic:table» (or «node $checks/epic-table.mjs»), tell the owner what was done on each task and what confirms it, and say outright that the session waits for their orders. New work is taken by their word, not by the count of what is left: their message or their answer to a menu that names the number of this work releases the call; a task being created has no number yet, and it is released by the latest answer of the owner to a menu when that answer agrees to a task and is not a refusal. A new epic the owner has declared needs the bypass line in the calls that create its card, its tasks and its branch; once the branch of the new epic is taken, the guard reads that epic and stops refusing."
125
161
 
126
162
  # shellcheck disable=SC1090
127
163
  [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
@@ -252,6 +252,11 @@ if [ "$ready" = "1" ]; then
252
252
  esac
253
253
  fi
254
254
 
255
+ # The verdict for the metrics. No mark file — nothing is recorded, and the guard judges as before.
256
+ # shellcheck disable=SC1091
257
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/metric-marks.sh" 2>/dev/null \
258
+ && rt_exam_note "$verdict" "$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)"
259
+
255
260
  case "$verdict" in
256
261
  passed) exit 0 ;;
257
262
  failed)
@@ -16,6 +16,27 @@
16
16
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
17
17
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
18
18
 
19
+ # The handover for the metrics: the call passed every condition here. The next guard in the row may
20
+ # still refuse it, so the branch is only announced: `handover-mark.sh` keeps the sign after the call.
21
+ # No mark file — nothing is kept.
22
+ rt_delivery_handover() {
23
+ local pending
24
+ # shellcheck disable=SC1091
25
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/metric-marks.sh" 2>/dev/null || return 0
26
+ pending="$(rt_handover_pending_file "$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)" "$cmd")"
27
+ [ -z "$pending" ] || printf '%s' "$1" > "$pending" 2>/dev/null
28
+ return 0
29
+ }
30
+
31
+ # A request that opens ready and names a reviewer is handed over at once. A draft is handed over when
32
+ # it leaves draft, and that guard demands a reviewer itself.
33
+ rt_delivery_open_handover() {
34
+ printf '%s' "$1" | grep -qE '[[:space:]](--draft|-d)([[:space:]=]|$)' && return 0
35
+ printf '%s' "$1" | grep -qE '[[:space:]](--reviewer|-r)([[:space:]=])' || return 0
36
+ rt_delivery_handover "$2"
37
+ return 0
38
+ }
39
+
19
40
  rt_delivery_draft_ready() {
20
41
  # --- leaving draft ----------------------------------------------------------------------
21
42
  #
@@ -88,5 +109,7 @@ rt_delivery_draft_ready() {
88
109
  command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder "$pull_head"
89
110
 
90
111
  deny_faults
112
+ # The head comes from the hosting: without its answer the number may name another branch.
113
+ [ -z "$pull_head" ] || rt_delivery_handover "$pull_head"
91
114
  fi
92
115
  }
@@ -71,10 +71,21 @@ rt_delivery_open_folder() {
71
71
  _base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
72
72
  [ -z "$_base" ] && return 0
73
73
 
74
- # SC-AK-1249: the draft the plan named, still lying in the branch, would reach main unmerged.
75
- _draft="$(rt_branch_plan_draft "$_folder" "$_base")"
76
- [ -n "$_draft" ] && [ -n "$(git ls-tree -d --name-only HEAD -- "${_draft%/}" 2>/dev/null)" ] \
77
- && fault "the branch carries the unmerged agreement «${_draft}» its plan named — merge its rules and scenarios into the domain spec, remove the directory by a commit and repeat. If the work is merged in parts, put the comment «# Task-folder-skip: <reason>» into the command."
74
+ # SC-AK-1249: a draft a plan of the branch named, still lying in the branch, would reach main
75
+ # unmerged. SC-AK-1296: a request into an epic or into a lower branch does not reach main, and
76
+ # the draft of an epic lives until its last task. The request of the epic is judged by the plans
77
+ # of all its tasks.
78
+ _into="$(rt_delivery_open_base)"
79
+ if [ "${_into:-$main_branch}" = "$main_branch" ]; then
80
+ while IFS= read -r _plan; do
81
+ [ -n "$_plan" ] || continue
82
+ _draft="$(rt_branch_plan_draft "${_plan%/plan.md}" "$_base")"
83
+ [ -n "$_draft" ] && [ -n "$(git ls-tree -d --name-only HEAD -- "${_draft%/}" 2>/dev/null)" ] \
84
+ && fault "the branch carries the unmerged agreement «${_draft}» its plan named — merge its rules and scenarios into the domain spec, remove the directory by a commit and repeat. If the work is merged in parts, put the comment «# Task-folder-skip: <reason>» into the command."
85
+ done <<EOF
86
+ $(git log --format= --name-only "$_base..HEAD" -- "$tasks_dir/*/plan.md" 2>/dev/null | sort -u)
87
+ EOF
88
+ fi
78
89
 
79
90
  [ -n "$archive_dir" ] || return 0
80
91
  rt_folder_was_in_branch "$_base" "$_folder" || return 0
@@ -84,6 +95,16 @@ rt_delivery_open_folder() {
84
95
  && fault "the task folder was deleted, but the branch added nothing to «${archive_dir}». Deleting is cheaper than taking apart — and together with the folder the analysis of the request is gone, the only record of the words of the owner. Move what explains the decisions taken as one file with a telling name and repeat."
85
96
  }
86
97
 
98
+ # The base the opening command names. Absent — the host takes the default branch: an empty answer.
99
+ rt_delivery_open_base() {
100
+ command -v perl >/dev/null 2>&1 || return 0
101
+ printf '%s' "$cmd" | perl -0ne '
102
+ if (/(?:^|\s)(?:--base|-B)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
103
+ print defined $1 ? $1 : (defined $2 ? $2 : $3);
104
+ }
105
+ ' 2>/dev/null
106
+ }
107
+
87
108
  # The draft agreement the plan of the branch named by the line `**Draft:** \`path\``. The plan is
88
109
  # read from the history: by the time the PR opens the folder is taken apart, and the last commit
89
110
  # touching the plan is the one that removed it — then its parent still holds the plan.
@@ -20,6 +20,25 @@
20
20
  # for a word over the whole line, that is, into a refusal on every mention of the command.
21
21
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
22
22
 
23
+ rt_delivery_branch_signature() {
24
+ # The signature: the address of the machine account is declared by the tree, and the working
25
+ # copy does not know it — which means the very first commit will travel under someone else's
26
+ # signature, and after the push that is fixed only by a force push.
27
+ #
28
+ # A person the tree named in RT_HUMAN_EMAILS signs with their own mail lawfully: the push
29
+ # accepts it, and refusing it here left such a person no way to start a branch at all.
30
+ if [ -n "$commit_email" ]; then
31
+ tree_email="$(git config user.email 2>/dev/null)"
32
+ human_email=''
33
+ for one in ${RT_HUMAN_EMAILS:-}; do
34
+ [ "$tree_email" = "$one" ] && human_email=1 && break
35
+ done
36
+ [ -n "$tree_email" ] && [ "$tree_email" != "$commit_email" ] && [ -z "$human_email" ] \
37
+ && fault "the working copy signs commits as «${tree_email}», while the tree declared the email of the machine account «${commit_email}». The very first commit leaves under a foreign signature: git config user.email \"${commit_email}\"."
38
+ fi
39
+ return 0
40
+ }
41
+
23
42
  rt_delivery_signature() {
24
43
  # --- the signature of a machine commit ----------------------------------------------------
25
44
  #
@@ -40,6 +40,7 @@
40
40
 
41
41
  # Its own name in the observations: the refusal is written by the shared deny tail, not here.
42
42
  RT_GUARD_NAME=git-guard-delivery
43
+ RT_GUARD_RULE=git-workflow
43
44
 
44
45
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
45
46
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -243,6 +244,10 @@ check_task() {
243
244
  return 0
244
245
  }
245
246
 
247
+ # The signature of a new branch and of a push live in one helper, so it is sourced before both.
248
+ # shellcheck disable=SC1090
249
+ [ -f "$rt_hooks_dir/git-guard-delivery-signature.sh" ] && . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
250
+
246
251
  # --- creating a branch -------------------------------------------------------------------
247
252
  branch_arg=''
248
253
  if printf '%s' "$cmd" | grep -qE '(^|[;&|[:space:]])git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]'; then
@@ -296,21 +301,7 @@ if [ -n "$branch_arg" ]; then
296
301
  fault "your ref origin/${main_branch} lags behind the remote one — ${local_head:0:8} against ${remote_head:0:8}. The branch will grow from yesterday tree, and the owner sees that at the opening of the request. Pull and repeat: git fetch origin."
297
302
  fi
298
303
 
299
- # The signature: the address of the machine account is declared by the tree, and the working
300
- # copy does not know it — which means the very first commit will travel under someone else's
301
- # signature, and after the push that is fixed only by a force push.
302
- #
303
- # A person the tree named in RT_HUMAN_EMAILS signs with their own mail lawfully: the push
304
- # accepts it, and refusing it here left such a person no way to start a branch at all.
305
- if [ -n "$commit_email" ]; then
306
- tree_email="$(git config user.email 2>/dev/null)"
307
- human_email=''
308
- for one in ${RT_HUMAN_EMAILS:-}; do
309
- [ "$tree_email" = "$one" ] && human_email=1 && break
310
- done
311
- [ -n "$tree_email" ] && [ "$tree_email" != "$commit_email" ] && [ -z "$human_email" ] \
312
- && fault "the working copy signs commits as «${tree_email}», while the tree declared the email of the machine account «${commit_email}». The very first commit leaves under a foreign signature: git config user.email \"${commit_email}\"."
313
- fi
304
+ command -v rt_delivery_branch_signature >/dev/null 2>&1 && rt_delivery_branch_signature
314
305
 
315
306
  deny_faults
316
307
  fi
@@ -322,8 +313,6 @@ fi
322
313
  # The subject lives in a helper next door — `git-guard-delivery-signature.sh`: the guard grew up to
323
314
  # the length limit, and the signature is the most separate of its subjects. No helper — the
324
315
  # signature is not judged, and the work goes on: the same fail-open as with the other conditions.
325
- # shellcheck disable=SC1090
326
- [ -f "$rt_hooks_dir/git-guard-delivery-signature.sh" ] && . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
327
316
  command -v rt_delivery_signature >/dev/null 2>&1 && rt_delivery_signature
328
317
 
329
318
  # --- the push into a merged branch -----------------------------------------------------------
@@ -484,7 +473,6 @@ fi
484
473
  [ -f "$rt_hooks_dir/git-guard-delivery-body.sh" ] && . "$rt_hooks_dir/git-guard-delivery-body.sh" 2>/dev/null
485
474
  command -v rt_delivery_pull_body >/dev/null 2>&1 && rt_delivery_pull_body
486
475
 
487
-
488
476
  # The task folder is taken apart before the PR opens, not after the approval: the owner merges as
489
477
  # soon as he sees green, and no room is left for a closing commit — three times in a row the folder
490
478
  # travelled into the main branch without being taken apart. After the cleanup the progress guard
@@ -494,5 +482,6 @@ rt_delivery_open_folder
494
482
  # Everything that did not come together is named here, all at once: up to this line the conditions
495
483
  # were being collected, each of which used to refuse the call on its own.
496
484
  deny_faults
485
+ command -v rt_delivery_open_handover >/dev/null 2>&1 && rt_delivery_open_handover "$cmd" "$branch"
497
486
 
498
487
  exit 0
@@ -19,6 +19,7 @@
19
19
  # in the way of work.
20
20
 
21
21
  RT_GUARD_NAME=git-guard-discard
22
+ RT_GUARD_RULE=git-workflow
22
23
 
23
24
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
24
25
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -17,6 +17,7 @@
17
17
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
18
18
  # guard itself.
19
19
  RT_GUARD_NAME=git-guard-main
20
+ RT_GUARD_RULE=git-workflow
20
21
 
21
22
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
22
23
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -26,6 +26,7 @@
26
26
  # in the way of work.
27
27
 
28
28
  RT_GUARD_NAME=git-guard-no-verify
29
+ RT_GUARD_RULE=git-workflow
29
30
 
30
31
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
31
32
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -38,6 +38,11 @@ command -v rt_push_checks >/dev/null 2>&1 || {
38
38
  exit "$not_started"
39
39
  }
40
40
  command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
41
+ # The line of a run for the metrics. No file — the checks run and record nothing.
42
+ # shellcheck disable=SC1091
43
+ [ -f "$rt_hooks_dir/metric-marks.sh" ] && . "$rt_hooks_dir/metric-marks.sh" 2>/dev/null
44
+ command -v rt_run_note >/dev/null 2>&1 || rt_run_note() { return 0; }
45
+ command -v rt_tree_sign >/dev/null 2>&1 || rt_tree_sign() { return 0; }
41
46
 
42
47
  # A mark vouches for the tree of the head, and the checks run over the working copy: with edits
43
48
  # outside the index the run would write marks for content that does not leave.
@@ -49,6 +54,7 @@ rt_push_mark_clean || {
49
54
  base="$(rt_push_base "${RT_MAIN_BRANCH:-main}")"
50
55
  skip_code="${RT_SKIP_CODE:-7}"
51
56
  printf 'push ahead: base %s, tree %s\n' "${base:-none}" "$(git rev-parse --short 'HEAD^{tree}')"
57
+ sign="$(rt_tree_sign .)"
52
58
 
53
59
  red=""
54
60
  while IFS= read -r check; do
@@ -68,11 +74,14 @@ while IFS= read -r check; do
68
74
  status=$?
69
75
  took=$(($(date +%s) - started))
70
76
  if [ "$status" -eq 0 ]; then
77
+ rt_run_note "$sign" "$started" green "$check"
71
78
  rt_push_mark_put "$check" "$base" "$key_before"
72
79
  printf '+ green in %ss: %s\n' "$took" "$check"
73
80
  elif [ "$status" -eq "$skip_code" ]; then
81
+ rt_run_note "$sign" "$started" skipped "$check"
74
82
  printf '~ nothing to look at: %s\n' "$check"
75
83
  else
84
+ rt_run_note "$sign" "$started" red "$check"
76
85
  red="${red}${red:+
77
86
  }${check}"
78
87
  printf '✗ red in %ss: %s\n%s\n' "$took" "$check" "$(printf '%s' "$out" | tail -n 25)"
@@ -35,6 +35,7 @@
35
35
 
36
36
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
37
37
  RT_GUARD_NAME=git-guard-push-tests
38
+ RT_GUARD_RULE=git-workflow
38
39
 
39
40
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
40
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -36,6 +36,7 @@
36
36
 
37
37
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
38
38
  RT_GUARD_NAME=grill-gate
39
+ RT_GUARD_RULE=task-flow
39
40
 
40
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
41
42
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -13,7 +13,10 @@
13
13
  # voluntary and exact: a hook that counts its own refusals by itself — like the rules gate — does
14
14
  # not set it, and the same event is not counted a second time.
15
15
  #
16
- # WHAT IS RECORDED. The guard name and the session id. Cleaning the values and deciding whether to
16
+ # THE RULE. A line `RT_GUARD_RULE=<rule>` next to the name says which rule the guard enforces. A
17
+ # refusal after that rule was loaded in the session counts against the rule: its text taught nothing.
18
+ #
19
+ # WHAT IS RECORDED. The guard name, its rule and the session id. Cleaning the values and deciding whether to
17
20
  # write at all is done by the observation record itself; here only the call is assembled.
18
21
  #
19
22
  # FAIL-OPEN. There may be no record at all — no file, the tree switched observations off, the
@@ -23,7 +26,7 @@
23
26
  # A guard refusal into the observations. The name is taken from `RT_GUARD_NAME`, the session id
24
27
  # from the hook input; without a name nothing is written.
25
28
  rt_guard_note() {
26
- local rt_gn_dir rt_gn_sid rt_gn_name
29
+ local rt_gn_dir rt_gn_sid rt_gn_name rt_gn_empty=''
27
30
  # A default, not a bare read: a guard may be written to abort on an undeclared variable, and a
28
31
  # record that reads it bare brings such a guard down whole — on every call, not on a refusal.
29
32
  rt_gn_name="${RT_GUARD_NAME:-}"
@@ -37,7 +40,12 @@ rt_guard_note() {
37
40
  rt_gn_sid="$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -r '.session_id // empty' 2>/dev/null)"
38
41
 
39
42
  if [ -n "$rt_gn_sid" ]; then
40
- rt_note guard-deny "res=$rt_gn_name" "sid=$rt_gn_sid"
43
+ # shellcheck disable=SC1090
44
+ [ -f "$rt_gn_dir/metric-marks.sh" ] && . "$rt_gn_dir/metric-marks.sh" 2>/dev/null
45
+ command -v rt_refusal_empty >/dev/null 2>&1 \
46
+ && rt_gn_empty="$(rt_refusal_empty "$rt_gn_name" "$rt_gn_sid" \
47
+ "$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -c '.tool_input // empty' 2>/dev/null)")"
48
+ rt_note guard-deny "res=$rt_gn_name" "sid=$rt_gn_sid" "empty=$rt_gn_empty" "rule=${RT_GUARD_RULE:-}"
41
49
  else
42
50
  rt_note guard-deny "res=$rt_gn_name"
43
51
  fi