@rt-tools/agent-kit 0.29.3 → 0.29.4

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.
@@ -82,7 +82,8 @@ what exactly they diverge and what the executor will do wrong by following one o
82
82
 
83
83
  For a **gap**: the name of the resource that lacks it, a quote of the place where it should have
84
84
  stood (or the section name, if there is no place at all), and what happens when the case comes.
85
- A gap has no second quote — do not invent one.
85
+ A gap has no second quote — do not invent one. A gap that asks for new text names the room left
86
+ in that resource: its lines and characters against the prose limits of the size check.
86
87
 
87
88
  No findings — say so. An empty reply is cheaper than an invented one: by an invented one real
88
89
  texts get edited.
@@ -108,6 +108,9 @@ Then for every proposal:
108
108
  - **package, companion or tree** — by the criterion above, and in one word why;
109
109
  - **ready-made text** — exactly what to insert, in the style of the neighbouring rules: in
110
110
  English, as a statement, without padding;
111
+ - **room in the target** — the target file's lines and characters now and after the insertion,
112
+ against the prose limits of the size check; a proposal that takes the file over a limit names
113
+ what in the same file is cut to make room;
111
114
  - **what caused it** — what exactly in this task went wrong without this rule;
112
115
  - whether the gate map needs an edit and which — in the package default or in the tree override.
113
116
 
@@ -169,7 +169,7 @@ export function pullState(ref, options) {
169
169
  const target = ref === undefined || ref === null || `${ref}`.trim() === '' ? [] : [`${ref}`.trim()];
170
170
  let pull;
171
171
  try {
172
- pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable'], options);
172
+ pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName'], options);
173
173
  } catch (error) {
174
174
  if (error instanceof OfflineError) {
175
175
  throw error;
@@ -194,6 +194,9 @@ export function pullState(ref, options) {
194
194
  // author. Only a direct "conflicting" is judged: `UNKNOWN` means the hosting is still
195
195
  // computing, and reading it as a conflict would mean refusing work on every fresh head.
196
196
  conflicting: pull.mergeable === 'CONFLICTING',
197
+ // The head branch: the folder guard judges the branch of the named PR, not the checked-out
198
+ // one — the lower PR of a stack is lifted from the upper branch.
199
+ branch: pull.headRefName ?? null,
197
200
  };
198
201
  }
199
202
 
@@ -37,6 +37,7 @@ rt_delivery_draft_ready() {
37
37
  # the whole demand with a single space. So the first argument is taken, whatever it is —
38
38
  # a number, an address or a branch name — and its absence means "ask about the current
39
39
  # branch".
40
+ pull_head=''
40
41
  pull_ref="$(printf '%s' "$cmd" | sed -nE 's/.*(gh[[:space:]]+pr[[:space:]]+ready|glab[[:space:]]+mr[[:space:]]+update)[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\2/p' | head -1)"
41
42
  if rt_needs rt_pull_state git-guard-delivery; then
42
43
  pull="$(cd "$root" && rt_pull_state "$pull_ref" 2>/dev/null)" || pull=''
@@ -53,6 +54,8 @@ rt_delivery_draft_ready() {
53
54
  *[!0-9]*) pull_name=" «${pull_name}»" ;;
54
55
  *) pull_name=" #${pull_name}" ;;
55
56
  esac
57
+ # The head branch of the PR goes to the folder condition below.
58
+ pull_head="$(printf '%s' "$pull" | jq -r '.branch // empty' 2>/dev/null)"
56
59
  printf '%s' "$pull" | jq -e '.reviewed' >/dev/null 2>&1 \
57
60
  || fault "the request${pull_name} has no review: no reviewer was requested and nobody left a review. A lifted draft reads as «ready to merge», and there is nobody to merge — set a reviewer and repeat."
58
61
 
@@ -82,7 +85,7 @@ rt_delivery_draft_ready() {
82
85
  # The task folder: the same subject as at opening and at the merge, as a third line. The
83
86
  # condition is local — it reads the branch, not the hosting — and therefore stands outside
84
87
  # the network tier above.
85
- command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder
88
+ command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder "$pull_head"
86
89
 
87
90
  deny_faults
88
91
  fi
@@ -20,7 +20,7 @@
20
20
  # into the main branch all the same. The branch name is substituted whole, slash included: for a
21
21
  # branch like `chore/312-slug` the folder lies in a nested directory.
22
22
  rt_folder_in_branch() {
23
- git ls-tree -d --name-only HEAD -- "$1" 2>/dev/null | head -1
23
+ git ls-tree -d --name-only "${2:-HEAD}" -- "$1" 2>/dev/null | head -1
24
24
  }
25
25
 
26
26
  # Was there a task folder in this branch at all. Asked of the branch that deleted it: otherwise the
@@ -29,10 +29,23 @@ rt_folder_was_in_branch() {
29
29
  _base="$1"
30
30
  _folder="$2"
31
31
  _had="$(git ls-tree -d --name-only "$_base" -- "$_folder" 2>/dev/null | head -1)"
32
- [ -z "$_had" ] && _had="$(git log "$_base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$_folder" 2>/dev/null | head -1)"
32
+ [ -z "$_had" ] && _had="$(git log "$_base..${3:-HEAD}" --diff-filter=A --name-only --pretty=format: -- "$_folder" 2>/dev/null | head -1)"
33
33
  [ -n "$_had" ]
34
34
  }
35
35
 
36
+ # The branch and the tree the folder is judged by: sets `_branch` and `_tree`. A command that names
37
+ # a PR is judged by that PR's head: the lower PR of a stack is lifted from the upper branch, and the
38
+ # checked-out branch carries a folder the named PR does not have. The tree of the head is read from
39
+ # the remote ref. Without a head, or without its ref, the checked-out branch is judged, as before.
40
+ rt_delivery_folder_target() {
41
+ _branch="$(git branch --show-current 2>/dev/null)"
42
+ _tree=HEAD
43
+ [ -n "$1" ] && [ "$1" != "$_branch" ] || return 0
44
+ git rev-parse --verify --quiet "refs/remotes/origin/$1" >/dev/null 2>&1 || return 0
45
+ _branch="$1"
46
+ _tree="refs/remotes/origin/$1"
47
+ }
48
+
36
49
  # Condition for opening the PR: the folder is taken apart, and a record from the branch has arrived
37
50
  # in the archive. The refusal accumulates together with the other delivery conditions and is
38
51
  # printed all at once.
@@ -71,16 +84,17 @@ rt_delivery_open_folder() {
71
84
  # pieces of work in a row travelled into the main branch exactly that way, and the body of each PR
72
85
  # carried a promise to remove the folder after approval.
73
86
  #
74
- # The function asks for the branch itself: on this turn the guard has not worked it out yet.
87
+ # The function asks for the branch itself: on this turn the guard has not worked it out yet. The
88
+ # argument is the head branch of the named PR, empty when the PR state did not answer.
75
89
  rt_delivery_ready_folder() {
76
90
  [ -n "$tasks_dir" ] || return 0
77
91
  printf '%s' "$cmd" | grep -qiE "$folder_skip_re" && return 0
78
92
 
79
- _branch="$(git branch --show-current 2>/dev/null)"
93
+ rt_delivery_folder_target "$1"
80
94
  [ -z "$_branch" ] && return 0
81
95
  rt_task_branch_ok "$_branch" || return 0 # no folder stands behind a branch without a task
82
96
 
83
- _lying="$(rt_folder_in_branch "$tasks_dir/$_branch")"
97
+ _lying="$(rt_folder_in_branch "$tasks_dir/$_branch" "$_tree")"
84
98
  [ -n "$_lying" ] \
85
99
  && fault "the branch carries the task folder «${_lying}» — a lifted draft reads as «ready to merge», and merging it there is not allowed. The button is pressed by a person on the hosting, and the folder reaches main before their hand does. Move to «${archive_dir:-archive}» what explains the decisions taken, delete the rest, commit and repeat. If the work is merged in parts, put the comment «# Task-folder-skip: <reason>» into the command."
86
100
  }
@@ -91,33 +105,37 @@ rt_delivery_ready_folder() {
91
105
  rt_delivery_merge_folder() {
92
106
  [ -n "$tasks_dir" ] || exit 0 # the tree keeps no work by a folder
93
107
 
94
- _branch="$(git branch --show-current 2>/dev/null)"
95
- [ -z "$_branch" ] && exit 0
96
- rt_task_branch_ok "$_branch" || exit 0 # no folder stands behind a branch without a task
97
-
98
- _folder="$tasks_dir/$_branch"
99
-
100
108
  # First we look for the bypass in the command itself — that works without a network too. If
101
109
  # only the PR body were read, then without a network the guard would refuse a merge whose
102
110
  # reason is written in that very body.
103
111
  printf '%s' "$cmd" | grep -qiE "$folder_skip_re" && exit 0
104
112
 
105
113
  _number="$(printf '%s' "$cmd" | sed -nE 's/.*(pr|mr)[[:space:]]+(merge|update)[[:space:]]+([0-9]+).*/\3/p' | head -1)"
114
+ _head=''
115
+ if [ -n "$_number" ] && rt_needs rt_pull_state git-guard-delivery; then
116
+ _head="$(cd "$root" && rt_pull_state "$_number" 2>/dev/null | jq -r '.branch // empty' 2>/dev/null)"
117
+ fi
118
+ rt_delivery_folder_target "$_head"
119
+ [ -z "$_branch" ] && exit 0
120
+ rt_task_branch_ok "$_branch" || exit 0 # no folder stands behind a branch without a task
121
+
122
+ _folder="$tasks_dir/$_branch"
123
+
106
124
  if [ -n "$_number" ] && rt_needs rt_report_body git-guard-delivery; then
107
125
  _body="$(cd "$root" && rt_report_body "$_number" 2>/dev/null)"
108
126
  [ -n "$_body" ] && printf '%s' "$_body" | grep -qiE "$folder_skip_re" && exit 0
109
127
  fi
110
128
 
111
- _lying="$(rt_folder_in_branch "$_folder")"
129
+ _lying="$(rt_folder_in_branch "$_folder" "$_tree")"
112
130
  [ -n "$_lying" ] \
113
131
  && deny "BLOCKED: the task folder «${_lying}» is left in the branch — it will travel into main. There will be nobody to take it apart later: the work moves on to the next task, and this request closes. Move to «${archive_dir:-archive}» what explains the decisions taken, delete the rest and repeat. If the work is merged in parts, put the line «Task-folder-skip: <reason>» into the body of the request."
114
132
 
115
133
  [ -n "$archive_dir" ] || exit 0
116
- _base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
134
+ _base="$(git merge-base "$main_branch" "$_tree" 2>/dev/null)"
117
135
  [ -z "$_base" ] && exit 0
118
- rt_folder_was_in_branch "$_base" "$_folder" || exit 0
136
+ rt_folder_was_in_branch "$_base" "$_folder" "$_tree" || exit 0
119
137
 
120
- _gained="$(git diff --name-only --diff-filter=A "$_base" HEAD -- "$archive_dir" 2>/dev/null | head -1)"
138
+ _gained="$(git diff --name-only --diff-filter=A "$_base" "$_tree" -- "$archive_dir" 2>/dev/null | head -1)"
121
139
  [ -z "$_gained" ] \
122
140
  && deny "BLOCKED: 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."
123
141
 
@@ -24,6 +24,7 @@
24
24
  # branch with history; otherwise a non-zero code, and the guard exits silently.
25
25
  #
26
26
  # RT_TF_PATH — the application-code path because of which the guard judges at all
27
+ # RT_TF_CANDIDATES — every path the call writes, one per line, as named in the call
27
28
  # RT_TF_BRANCH — the current branch of the edit's working directory
28
29
  # RT_TF_ROOT — the root of the working tree
29
30
  # RT_TF_TASKS_DIR — the task folders directory, as the tree names it
@@ -174,6 +175,7 @@ rt_task_flow_context() {
174
175
  $rt_tf_candidates
175
176
  EOF
176
177
  [ -z "$RT_TF_PATH" ] && return 1
178
+ RT_TF_CANDIDATES="$rt_tf_candidates"
177
179
 
178
180
  # The branch is looked at where the edit will go: a worktree has one of its own.
179
181
  rt_tf_workdir="$(rt_hook_cwd)"
@@ -52,6 +52,33 @@ plan="$RT_TF_PLAN"
52
52
 
53
53
  deny() { rt_task_flow_deny "$@"; }
54
54
 
55
+ # Resolving a merge conflict is the merge itself, not an edit of the product. Main is merged into
56
+ # the epic branch while the work runs, and that branch carries no task folder by the rule — it holds
57
+ # merges, not edits of its own. Refused here, the conflict has no lawful way out: a folder made up
58
+ # for the epic branch would be the very edit the rule forbids in it. So a call passes while a merge
59
+ # stands and every code path it writes is still unmerged. A file already resolved and added, and
60
+ # any other code file of the same merge, is judged as before: the exception is the conflict, not
61
+ # the branch.
62
+ merge_conflict_only() {
63
+ git -C "$root" rev-parse -q --verify MERGE_HEAD >/dev/null 2>&1 || return 1
64
+ seen=0
65
+ while IFS= read -r candidate; do
66
+ [ -z "$candidate" ] && continue
67
+ case "$candidate" in
68
+ /*) ;;
69
+ *) candidate="${CLAUDE_PROJECT_DIR:-.}/$candidate" ;;
70
+ esac
71
+ rt_is_app_code "$candidate" || rt_tf_laid_out "$candidate" || continue
72
+ [ -n "$(git -C "$root" ls-files -u -- "$candidate" 2>/dev/null | head -1)" ] || return 1
73
+ seen=1
74
+ done <<EOF
75
+ ${RT_TF_CANDIDATES:-$RT_TF_PATH}
76
+ EOF
77
+ [ "$seen" = 1 ]
78
+ }
79
+
80
+ merge_conflict_only && exit 0
81
+
55
82
  if rt_needs rt_task_branch_ok task-flow-guard && ! rt_task_branch_ok "$branch"; then
56
83
  deny "BLOCKED by task-flow: an edit of code goes in a branch for a task, and the current branch is '${branch}'. Create a task (npm run task:new -- --title '…' --slug <slug>) and a branch under its number, then repeat. The rule is task-flow."
57
84
  fi
@@ -174,10 +174,12 @@ flowchart TD
174
174
  the run turned red for something other than the branch's change.
175
175
  <!-- rt-when: *.md -->
176
176
 
177
- - **The removal by expiry is not carried by whichever branch pushed first.** The check stands in the
178
- gate of every branch, so the cleanup lands in the first work to reach a push and travels to the
179
- reviewer inside an edit that has nothing to do with it. Either the cleanup is work of its own with
180
- a task of its own, or the check refuses the run and not the push.
177
+ - **The removal by expiry travels as a commit of its own.** The check stands in the gate of every
178
+ branch and counts age by the calendar, so it refuses whatever branch reaches it first — commits
179
+ too, not only pushes. A task of its own per record is no cure: one record expires every day. The
180
+ prune command makes the cleanup a separate commit with its own subject in the branch it blocked,
181
+ and the PR body names it as unrelated to the work. The lasting cure is moving the check out of the
182
+ commit and push gate into the pipeline of the main branch.
181
183
  <!-- rt-when: *.md -->
182
184
 
183
185
  - **A link to a record of the past in a live text lives exactly until the record's expiry.** The
@@ -240,7 +240,9 @@ A rule loads whole into a session and pays for it every session, whatever the se
240
240
  measurement names where the weight is: 289 440 characters in twenty-nine loaded rules, the articles
241
241
  section is 45% of them, and inside the section statements take 19%, their arguments 81%. So the
242
242
  argument is cut, not the statement: a removed statement changes the rule, a removed argument only
243
- its price.
243
+ its price. Room is measured before an article is added, not after the commit is refused: the size
244
+ check judges lines and characters apart, and a rule near either limit is compressed in the same
245
+ edit. The measurement is two numbers from `wc -lc` against the limits the check prints.
244
246
 
245
247
  A paragraph at an article has three outcomes, chosen by one question: **what is this text needed for
246
248
  — to make a decision, to keep it from being reversed, or to review a miss?**
@@ -258,8 +260,7 @@ A paragraph at an article has three outcomes, chosen by one question: **what is
258
260
  green while it checks something else" is an argument. When it happened, how many times in a row
259
261
  and in which branch is history, and its place is the cold part.
260
262
  - **An incident analysis leaves for the cold part whole, with its numbers and rejected options.**
261
- The cold part loads on demand — for whoever reviews a miss — and grows freely: one session in a
262
- hundred pays for it, not every one.
263
+ The cold part loads on demand and grows freely: one session in a hundred pays for it.
263
264
  - **The cold part holds explanation, not requirement.** A statement absent from the rule never lives
264
265
  there: a rule whose requirement lives in the cold part promises what the session loading it will
265
266
  not see. Tested by the same question reversed — no decision can be made by the cold part that
@@ -268,9 +269,7 @@ A paragraph at an article has three outcomes, chosen by one question: **what is
268
269
  by the same decision: whoever read only it edits the same way as whoever read the former one. They
269
270
  diverged — surplus was removed, and it comes back at the article, not to the cold part.
270
271
  - **A rule without a cold part is legitimate, and the first paragraph that leaves creates one.** An
271
- empty `pitfalls.md` next to it is a promise, not a mechanism: in the measurement of twenty-nine
272
- rules, four of the heaviest have no cold part at all, and their whole incident analysis loads
273
- every session.
272
+ empty `pitfalls.md` next to it is a promise, not a mechanism.
274
273
 
275
274
  ## What of the law is not here
276
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rt-tools/agent-kit",
3
- "version": "0.29.3",
3
+ "version": "0.29.4",
4
4
  "description": "Переносимый слой правил для агента: законы, хуки, проверки и агенты, раскладываемые в репозиторий одной командой",
5
5
  "author": "RT Team",
6
6
  "license": "Apache-2.0",
Binary file
Binary file