@rt-tools/agent-kit 0.32.0 → 0.33.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.
@@ -221,6 +221,19 @@ export function pullState(ref, options) {
221
221
  };
222
222
  }
223
223
 
224
+ /**
225
+ * Whether the branch has a merged PR and no open one: `{merged: <number> | null}`. The host deletes
226
+ * the branch of a merged PR, and a push into it recreates the branch with the commit nobody will
227
+ * merge. A branch reopened by a new PR after the merge is lawful work, so an open PR clears it.
228
+ */
229
+ export function pullMerged(branch, options) {
230
+ const pulls = ghJson(['pr', 'list', '--head', `${branch}`, '--state', 'all', '--limit', '20', '--json', 'number,state'], options) ?? [];
231
+ if (pulls.some((pull) => pull.state === 'OPEN')) {
232
+ return { merged: null };
233
+ }
234
+ return { merged: pulls.find((pull) => pull.state === 'MERGED')?.number ?? null };
235
+ }
236
+
224
237
  /**
225
238
  * How many commits the PR branch is behind main. The guard judges the base at the minute of
226
239
  * opening, and a PR stands for days: what was merged in that time is seen neither by it nor by a
@@ -401,6 +414,20 @@ if (isEntryPoint && process.argv[2] === 'pr') {
401
414
  }
402
415
  }
403
416
 
417
+ // The merged PR of a branch as one line of JSON, for the push refusal of the delivery guard.
418
+ if (isEntryPoint && process.argv[2] === 'merged' && process.argv[3]) {
419
+ try {
420
+ process.stdout.write(`${JSON.stringify(pullMerged(process.argv[3], { token: botToken() ?? undefined }))}\n`);
421
+ } catch (error) {
422
+ if (error instanceof OfflineError) {
423
+ process.stdout.write('{"offline":true}\n');
424
+ } else {
425
+ process.stdout.write(`${JSON.stringify({ error: String(error.message ?? error) })}\n`);
426
+ process.exit(1);
427
+ }
428
+ }
429
+ }
430
+
404
431
  // Own conflicting PRs as one line of JSON: `{"conflicting":[{"number":…,"branch":…}]}`.
405
432
  // The delivery guard calls it before letting new work be taken. A tree without a machine account
406
433
  // answers with an empty list: there is nobody to ask about.
@@ -80,6 +80,14 @@ export function assignmentOf(root = ROOT) {
80
80
  return name === null ? null : (assignments(root).find((row) => row.tree === name) ?? null);
81
81
  }
82
82
 
83
+ /**
84
+ * What lifts the refusal, said in the refusal itself. Told only «the owner moves the assignment»,
85
+ * the executor stopped after a direct order and asked the owner a second time: the order already
86
+ * was that move.
87
+ */
88
+ const OWNER_WORD =
89
+ "A message of the owner in this conversation that names this work is that move: write the row with their words and go on; ask only when no message of theirs names it";
90
+
83
91
  /**
84
92
  * What is wrong with taking work under this epic — or an empty string where nothing is.
85
93
  *
@@ -105,15 +113,15 @@ export function assignmentFault(epic, root = ROOT) {
105
113
  const row = assignmentOf(root);
106
114
 
107
115
  if (row === null) {
108
- return `the table ${CONFIG.assignmentsFile} holds no row for the copy «${name}». Ask the owner what this copy leads; work is not taken by guesswork`;
116
+ return `the table ${CONFIG.assignmentsFile} holds no row for the copy «${name}». Ask the owner what this copy leads; work is not taken by guesswork. ${OWNER_WORD}`;
109
117
  }
110
118
 
111
119
  if (row.epic === null) {
112
- return `no epic is assigned to the copy «${name}» — the row in ${CONFIG.assignmentsFile} holds a dash. Ask the owner what to take; an epic chosen by oneself is not an order`;
120
+ return `no epic is assigned to the copy «${name}» — the row in ${CONFIG.assignmentsFile} holds a dash. Ask the owner what to take; an epic chosen by oneself is not an order. ${OWNER_WORD}`;
113
121
  }
114
122
 
115
123
  if (epic !== null && epic !== undefined && String(epic) !== '' && Number(epic) !== row.epic) {
116
- return `the copy «${name}» leads the epic ${key}-${row.epic}, and this work belongs to ${key}-${epic}. Someone else's epic is not taken by one's own decision: the owner moves the assignment`;
124
+ return `the copy «${name}» leads the epic ${key}-${row.epic}, and this work belongs to ${key}-${epic}. Someone else's epic is not taken by one's own decision: the owner moves the assignment. ${OWNER_WORD}`;
117
125
  }
118
126
 
119
127
  return '';
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
2
+ # The push into a branch whose PR is merged, for the delivery guard.
3
+ #
4
+ # NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
5
+ # sources it after `deny` — one tier of its verdict, kept apart because the guard is at its length
6
+ # limit.
7
+ #
8
+ # The owner merged a PR, the host deleted its branch, and minutes later the executor committed an
9
+ # incident analysis into the same branch and pushed it. The host answered `new branch`: the branch
10
+ # came back with one commit over the merged work, and no PR would ever merge it. The pattern of the
11
+ # commit already asked for the PR state before such a push, and only memory held it.
12
+ #
13
+ # What is judged is the branch the push sends: the destination of the last refspec, or the checked
14
+ # out branch when the command names none. The branch has a merged PR and no open one — the push is
15
+ # refused. A branch reopened by a new PR after the merge is lawful work and passes.
16
+ #
17
+ # It expects `$cmd` and `$root` to be set and `deny` to be declared.
18
+ #
19
+ # FAIL-OPEN: no profile function, no network, a dry run, a command that is not a push — silence.
20
+
21
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
22
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
23
+
24
+ # The number of the merged PR of a branch that has no open PR; empty output means "not merged". A
25
+ # tree on another host declares the function in its profile; this default asks the work queue
26
+ # helper. It lives here because the defaults file is at its length limit. No node, no helper, no
27
+ # network — a failing exit code, and the push is not judged.
28
+ command -v rt_pull_merged >/dev/null 2>&1 || rt_pull_merged() {
29
+ local _state
30
+ command -v node >/dev/null 2>&1 || return 1
31
+ [ -f "${RT_BOARD_HELPER:-tools/board.mjs}" ] || return 1
32
+ _state="$(node "${RT_BOARD_HELPER:-tools/board.mjs}" merged "$1" 2>/dev/null)" || return 1
33
+ printf '%s' "$_state" | jq -e 'has("merged")' >/dev/null 2>&1 || return 1
34
+ printf '%s' "$_state" | jq -r '.merged // empty'
35
+ }
36
+
37
+ rt_delivery_merged() {
38
+ local _rest _target _merged
39
+ printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git([[:space:]]|\$)" || return 0
40
+ printf '%s' "$cmd" | grep -q -- '--dry-run' && return 0
41
+ _rest="$(printf '%s' "$cmd" | sed -E 's/git[[:space:]]+stash[[:space:]]+push/git stash/g' \
42
+ | sed -nE 's/.*(^|[[:space:]])push([[:space:]]+(.*))?$/\3/p' | head -1)"
43
+ printf '%s' "$cmd" | sed -E 's/git[[:space:]]+stash[[:space:]]+push/git stash/g' \
44
+ | grep -qE '(^|[[:space:]])push([[:space:]]|$)' || return 0
45
+ # The words after `push` up to the end of the call: options are skipped, the first word is the
46
+ # remote, the second — the refspec, whose destination is the branch.
47
+ _target="$(printf '%s' "$_rest" | sed -E 's/[;&|].*$//' | awk '{
48
+ n = 0
49
+ for (i = 1; i <= NF; i++) {
50
+ if ($i ~ /^-/) continue
51
+ n++
52
+ if (n == 2) { spec = $i }
53
+ }
54
+ sub(/^\+/, "", spec); sub(/^.*:/, "", spec); sub(/^refs\/heads\//, "", spec)
55
+ print spec
56
+ }')"
57
+ [ -n "$_target" ] && [ "$_target" != HEAD ] || _target="$(git -C "$root" branch --show-current 2>/dev/null)"
58
+ [ -n "$_target" ] || return 0
59
+ [ "$_target" = "${main_branch:-main}" ] && return 0
60
+
61
+ _merged="$(cd "$root" && rt_pull_merged "$_target" 2>/dev/null)" || return 0
62
+ [ -n "$_merged" ] || return 0
63
+
64
+ deny "BLOCKED: the PR #${_merged} of the branch «${_target}» is merged, and the branch has no open PR. The host deleted the branch with the merge, and this push recreates it with commits nobody will merge. Take a new branch from the fresh base and move the commits there: git fetch origin && git checkout -b <new branch> origin/<base> && git cherry-pick <commits>."
65
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
- # Requires: hooks/git-guard-delivery-folder.sh, hooks/git-guard-delivery-epic.sh, hooks/git-guard-tree-assignment.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
3
+ # Requires: hooks/git-guard-delivery-merged.sh, hooks/git-guard-delivery-folder.sh,hooks/git-guard-delivery-epic.sh, hooks/git-guard-tree-assignment.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
4
4
  # Delivery guard. PreToolUse on creating a branch, on the push and on opening a PR.
5
5
  #
6
6
  # The delivery law demands three things nothing usually checks: an edit starts from a task visible
@@ -319,6 +319,13 @@ fi
319
319
  && . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
320
320
  command -v rt_delivery_signature >/dev/null 2>&1 && rt_delivery_signature
321
321
 
322
+ # --- the push into a merged branch -----------------------------------------------------------
323
+ # The helper next door — `git-guard-delivery-merged.sh`. No helper — the push is not judged by it.
324
+ # shellcheck disable=SC1090
325
+ [ -f "$rt_hooks_dir/git-guard-delivery-merged.sh" ] \
326
+ && . "$rt_hooks_dir/git-guard-delivery-merged.sh" 2>/dev/null
327
+ command -v rt_delivery_merged >/dev/null 2>&1 && rt_delivery_merged
328
+
322
329
  # --- leaving draft ---------------------------------------------------------------------------
323
330
  # The subject lives in a helper next door — `git-guard-delivery-draft.sh`, by the same technique as
324
331
  # the signature. No helper — leaving draft is not judged, and the work goes on.
@@ -71,7 +71,7 @@ rt_assignment_stale() {
71
71
  # a missing field and for `false`, that is, exactly for the state this refusal is written for.
72
72
  case "$(printf '%s' "$_state" | jq -r 'if .open == false then "false" else "" end' 2>/dev/null)" in
73
73
  false)
74
- fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order."
74
+ fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order. A message of the owner in this conversation that names this work is that new assignment: write the row with their words and go on; ask only when no message of theirs names it."
75
75
  ;;
76
76
  esac
77
77
  }
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env bash
2
+ # A part of the fourth sign of the conversation guard: after a refused menu a list of options in
3
+ # prose is a question too. NOT a guard: it has no `rt-hook:` declaration and hooks into no agent
4
+ # event. The conversation guard sources it — it was moved out when the guard crossed the file
5
+ # length limit.
6
+ #
7
+ # After a refused menu the executor gave the same options as a numbered list with no question mark
8
+ # and ended the turn: the sign knew prose only by «?», and the list went out as an ordinary reply.
9
+ # In a turn where the menu was refused, a numbered list of two or more items under a line ending
10
+ # with a colon is a question too. Outside such a turn a list is not judged: many ordinary reports
11
+ # carry one, and a refusal on each would teach to strip lists from replies.
12
+ #
13
+ # It expects `$transcript` and `$question_text` to be set; it returns zero when the turn ends with
14
+ # such a list after a refused menu, and non-zero otherwise.
15
+ #
16
+ # FAIL-OPEN: no turn record, no parser — the list is not a question.
17
+
18
+ rt_grill_options_asked() {
19
+ local menu_refused options_re
20
+ menu_refused="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
21
+ def is_input:
22
+ .type == "user"
23
+ and ((.isCompactSummary // false) | not)
24
+ and ((.isMeta // false) | not)
25
+ and (((.message.content // []) | if type == "array"
26
+ then ([.[] | select(.type == "tool_result")] | length)
27
+ else 0 end) == 0);
28
+ def asks_menu:
29
+ .type == "assistant" and ((.message.content // []) | any(.[];
30
+ .type == "tool_use" and .name == "AskUserQuestion"));
31
+ def refused:
32
+ .type == "user" and ((.message.content // []) | if type == "array"
33
+ then any(.[]; .type == "tool_result" and (.is_error // false))
34
+ else false end);
35
+ (map(is_input) | rindex(true)) as $i
36
+ | (if $i == null then . else .[$i + 1:] end) as $turn
37
+ | [range(0; ($turn | length) - 1) as $k
38
+ | select(($turn[$k] | asks_menu) and ($turn[$k + 1] | refused))]
39
+ | if length > 0 then "yes" else "no" end
40
+ ' 2>/dev/null)"
41
+ [ "$menu_refused" = "yes" ] || return 1
42
+
43
+ options_re='^[[:space:]]*[0-9]+[.)][[:space:]]'
44
+ printf '%s\n' "$question_text" | awk -v re="$options_re" '
45
+ /:[[:space:]]*$/ { lead = 1; items = 0; next }
46
+ lead && $0 ~ re { items++; if (items >= 2) found = 1; next }
47
+ lead && /^[[:space:]]*$/ { next }
48
+ { lead = 0; items = 0 }
49
+ END { exit found ? 0 : 1 }'
50
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh
2
+ # Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh, hooks/grill-gate-options.sh
3
3
  # rt-hook: Stop
4
4
  # The conversation guard: the owner is not asked a question until the laws and rules have been read
5
5
  # within the same turn. It judges two events, and that is not duplication; the second is declared
@@ -388,11 +388,16 @@ if [ -n "$done_marker" ]; then
388
388
  | join("\n")
389
389
  ' 2>/dev/null)"
390
390
  fi
391
+ # After a refused menu a list of options in prose is a question too: the helper next door.
392
+ # shellcheck disable=SC1090
393
+ [ -f "$rt_hooks_dir/grill-gate-options.sh" ] && . "$rt_hooks_dir/grill-gate-options.sh" 2>/dev/null
391
394
  asks="no"
392
395
  if [ -n "$tool" ]; then
393
396
  asks="yes"
394
397
  elif printf '%s\n' "$question_text" | grep -qE '\?[[:space:]]*$'; then
395
398
  asks="yes"
399
+ elif command -v rt_grill_options_asked >/dev/null 2>&1 && rt_grill_options_asked; then
400
+ asks="yes"
396
401
  fi
397
402
  marked="no"
398
403
  case "$question_text" in
@@ -402,6 +407,9 @@ if [ -n "$done_marker" ]; then
402
407
  reason="BLOCKED by grill-gate: a guard refused in this turn, and the question to the owner carries nothing done without the answer.
403
408
 
404
409
  A refusal removes the step, not the task. Do the mechanical part of the blocker first — what the linter's fix mode repairs, what the refusal names as fixable — then ask only the decision that is left. The question leaves with the line «$done_marker …» naming the working commands of this turn after the last refusal: an edit of a file or a command that changes the tree. A read or a status command does not count."
410
+ [ -n "$tool" ] && reason="${reason}
411
+
412
+ The same question in prose does not walk around this refusal: the menu and prose are judged alike, a list of options included. Fix the menu — add the line and a working command — and send it again."
405
413
 
406
414
  # shellcheck disable=SC1090
407
415
  [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
@@ -31,7 +31,11 @@ stop the install.
31
31
  ## Order
32
32
 
33
33
  1. `package.json` — exact numbers, not a single `^` or `~`.
34
- 2. `pnpm install`; the snapshot goes in the same commit.
34
+ 2. `pnpm install`; the snapshot goes in the same commit. Then `pnpm install --frozen-lockfile`, in
35
+ every repository the edit goes to. Tests, the build and the linter run on modules already
36
+ installed and do not read the snapshot: a range in the declaration against an exact number in
37
+ the snapshot is found only by the strict install, and in a release pipeline that is after the
38
+ merge.
35
39
  3. The styling properties the tree reads from the package are checked against the new version by
36
40
  a command, not by a look: a removed property makes the declaration invalid, not wrong, and
37
41
  every check stays green. Every name from `var(--<prefix>-…)` in the tree is searched for in
@@ -289,3 +289,6 @@ as in `git commit -F -` with the text after it.
289
289
  with a zero exit. The defaults are sourced first, and the line count is compared with the last
290
290
  push before the run.
291
291
  - The owner's edit takes neither the token nor the variables — they are only for machine work.
292
+ - A commit into the branch of a merged PR reaches no one: the host deleted the branch, and a push
293
+ creates it anew with an answer `new branch`. The delivery guard refuses such a push and names the
294
+ merged PR. The commit moves to a new branch from the fresh base by `git cherry-pick`.
@@ -43,6 +43,11 @@ A clone written next to it takes the edits onto itself and diverges from the ori
43
43
  first one. A renamed file and a "similar but own" component are the same departure, only
44
44
  undeclared.
45
45
 
46
+ Before the kit PR is merged, the tree that ordered the edit runs its end-to-end suite against the
47
+ packed build of that branch. The build is unpacked over the installed package without touching the
48
+ declaration. The kit's own tests do not know the screen it stands on — a dialog over a side panel, a
49
+ button whose state the consumer binds — and a defect found after the merge costs a second release.
50
+
46
51
  ## One's own primitive — only with the owner's approval
47
52
 
48
53
  Asked before the first file is written. The same goes for one's own base and one's own inline
@@ -178,7 +178,8 @@ npm run task:new -- --epic --title '<Возможность, которая ра
178
178
  The call puts the epic label on the card, lays a draft of the plan in the tree's directory of plans
179
179
  and writes the path to it into the body: the audit reads the plan by that path, and a card without
180
180
  it points into emptiness. Everything the epic cannot be created without is asked before the card is
181
- made — an administrator alone can take a made one off the board.
181
+ made — an administrator alone can take a made one off the board. What the call does not write — a
182
+ file of epics, an index of plans — the tree lists as hand steps of the same commit as the plan.
182
183
 
183
184
  The draft is filled in by hand, and three things in it are derived from nothing: the opportunity in
184
185
  one phrase, the makeup of the tasks in order, and how the branches of the tasks stand. A set without
@@ -7,6 +7,10 @@ The rule is `task-flow`; the articles that hold the law stand there.
7
7
 
8
8
  ## Pitfalls
9
9
 
10
+ - **A suspicion of a defect put off "until later" is postponed work, and the promise in the reply is
11
+ no record of it.** It goes into the queue as a task, or as a line «not checked» in the record of
12
+ the task where it was noticed. Each turn writes its summary anew: within three tasks the suspicion
13
+ about a menu turned into a remark about its look.
10
14
  - **A task picked into an epic by its body can be closed before the work starts.** Weeks pass
11
15
  between creating a task and taking it, and all that time the tree is edited by neighbouring work:
12
16
  two tasks of one epic had three parts out of four already done — the body described the tree of a
@@ -65,7 +65,9 @@ flowchart TD
65
65
  neither the linter, nor the build, nor the tests read styling properties, and the person at the
66
66
  screen sees the breakage. Gone into a shared update, such a raise is reverted only together with
67
67
  the others, and tying the breakage to it costs a separate investigation; its own branch is
68
- reverted alone.
68
+ reverted alone. A feature that needs a component several releases ahead raises the skipped ones
69
+ first, by that task of its own, and its branch takes only the last step: each skipped release
70
+ brings changes of its own, and in the feature branch they read as the feature's breakage.
69
71
 
70
72
  ## What of the law is not here
71
73
 
@@ -116,6 +116,9 @@ flowchart TD
116
116
  when the tree has no such kind at all. A hardcoded value is refused by neither linter, build nor
117
117
  test: it is syntactically valid and simply does not belong to this tree — that is how a demo
118
118
  value from the vendor's documentation leaves for the production build.
119
+ - **A logo of a foreign service is taken, not drawn.** It is taken from the owner of the mark or
120
+ from an open icon set, in a mockup the same as in code. A drawn mark next to the service name
121
+ reads as that service's logo, and a person at the screen does not recognise it.
119
122
 
120
123
  ## What of the law is not here
121
124
 
@@ -105,6 +105,11 @@ flowchart TD
105
105
  settings — contacts, sender address, keys of external services — the seed does not create
106
106
  either: they are entered in the application. What is needed rarely is switched on by a sign in
107
107
  the environment, not seeded for all.
108
+ - **An edit of a build step or of the pipeline is checked from scratch, and its PR waits for the run
109
+ on itself.** A cached build answers from what an earlier build left, and the edit looks green
110
+ while a clean runner fails on it. So the build runs twice past the cache with its output removed
111
+ between the runs, and its time is compared with the wait limit of whoever calls it. The request to
112
+ merge names the run on the PR itself: a fix of the pipeline merged unrun broke it a second time.
108
113
  - **A created check goes into the push gate or the pipeline, not only into the umbrella target.**
109
114
  The umbrella target is run by hand, and a check that lives only there answers whoever
110
115
  remembered it: such a check's silence reads as its green answer. Three checks stood outside the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rt-tools/agent-kit",
3
- "version": "0.32.0",
3
+ "version": "0.33.1",
4
4
  "description": "Переносимый слой правил для агента: законы, хуки, проверки и агенты, раскладываемые в репозиторий одной командой",
5
5
  "author": "RT Team",
6
6
  "license": "Apache-2.0",