@rt-tools/agent-kit 0.30.0 → 0.31.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.
- package/assets/checks/board-runs.github.mjs +7 -2
- package/assets/checks/board.github.mjs +28 -4
- package/assets/checks/task-new-queue.github.mjs +51 -0
- package/assets/checks/task-new.github.mjs +4 -41
- package/assets/defaults/project.sh +3 -0
- package/assets/hooks/epic-stop-guard.sh +6 -1
- package/assets/hooks/git-guard-delivery-body.sh +51 -0
- package/assets/hooks/git-guard-delivery-merge.sh +32 -0
- package/assets/hooks/git-guard-delivery.sh +12 -26
- package/assets/hooks/grill-gate.sh +2 -2
- package/assets/hooks/write-targets.sh +69 -3
- package/assets/patterns/admin-nav-item.md +2 -1
- package/assets/patterns/browser-verification-stand.md +3 -0
- package/assets/patterns/doc-style-human.md +21 -0
- package/assets/patterns/git-workflow-docker.md +4 -2
- package/assets/patterns/git-workflow-merge.md +6 -0
- package/assets/patterns/git-workflow-pr-body.github.md +4 -1
- package/assets/patterns/git-workflow-pr-ready.md +9 -0
- package/assets/patterns/spec-driven-domain.md +12 -0
- package/assets/patterns/testing-e2e.md +16 -2
- package/assets/patterns/testing-unit.md +4 -0
- package/assets/pitfalls/styling-bem.md +11 -0
- package/assets/rules/browser-verification.md +7 -5
- package/assets/rules/component-structure.md +4 -0
- package/assets/rules/deploy-flow.github.md +28 -2
- package/assets/rules/git-workflow.github.md +1 -1
- package/assets/rules/lib-layers.md +2 -2
- package/assets/rules/reuse-first.md +7 -0
- package/assets/rules/shared-code.md +3 -0
- package/assets/rules/spec-driven.md +3 -1
- package/assets/rules/testing.md +3 -1
- package/assets/rules/turn-conduct.md +10 -11
- package/lib/proposals.d.ts.map +1 -1
- package/lib/proposals.js +9 -1
- package/lib/proposals.js.map +1 -1
- package/lib/ship.d.ts +9 -0
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +16 -0
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +30 -29
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.30.0.tgz +0 -0
|
@@ -39,6 +39,11 @@ export function runsOnHead(sha, options) {
|
|
|
39
39
|
* nothing about it: production was 476 commits behind while the check stayed silent. Only a rollout
|
|
40
40
|
* finished with success is judged — one still going may end with anything.
|
|
41
41
|
*
|
|
42
|
+
* The status filter of the hosting is not used: it counts by a separate index that lags, and the same
|
|
43
|
+
* request returned a month-old run and yesterday's one within a minute. The twenty latest runs come
|
|
44
|
+
* without it, and the first successful among them is taken; twenty failed in a row are named by the
|
|
45
|
+
* neighbouring check of the last rollout.
|
|
46
|
+
*
|
|
42
47
|
* Returns `null` if there were no rollouts at all: that is not a discrepancy but nothing to compare.
|
|
43
48
|
*/
|
|
44
49
|
export function deployLag(workflow, mainBranch, options) {
|
|
@@ -46,9 +51,9 @@ export function deployLag(workflow, mainBranch, options) {
|
|
|
46
51
|
[
|
|
47
52
|
'api',
|
|
48
53
|
`repos/${OWNER}/${REPO}/actions/workflows/${encodeURIComponent(workflow)}/runs` +
|
|
49
|
-
'?
|
|
54
|
+
'?per_page=20',
|
|
50
55
|
'--jq',
|
|
51
|
-
'[.workflow_runs[] | {sha: .head_sha, at: .created_at}] | first // empty',
|
|
56
|
+
'[.workflow_runs[] | select(.conclusion == "success") | {sha: .head_sha, at: .created_at}] | first // empty',
|
|
52
57
|
],
|
|
53
58
|
options
|
|
54
59
|
);
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { OfflineError, botToken, gh, ghJson, graphql } from './board-gh.mjs';
|
|
19
19
|
import { declaredEpicOf } from './board-epic-link.mjs';
|
|
20
|
+
import { verdictOnHead } from './board-runs.mjs';
|
|
20
21
|
export { numberFromTaskDir, taskDirs, unstampFolder } from './board-task-dirs.mjs';
|
|
21
22
|
import { CONFIG } from './rt-kit-checks.config.mjs';
|
|
22
23
|
|
|
@@ -101,6 +102,23 @@ export function fetchBoard(options) {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The card of one task on this board, read by a direct request to the task itself — its
|
|
107
|
+
* `projectItems` field — and not out of the list of the whole board. The list took three seconds on
|
|
108
|
+
* two hundred cards, a direct request answered in under one, and it names the column in the same
|
|
109
|
+
* answer. `undefined` — the task stands on no card of this board (yet).
|
|
110
|
+
*/
|
|
111
|
+
export function fetchCard(number, options) {
|
|
112
|
+
const issue = graphql(
|
|
113
|
+
`{ repository(owner: "${OWNER}", name: "${REPO}") { issue(number: ${Number(number)}) { projectItems(first: 20) {
|
|
114
|
+
nodes { id project { id }
|
|
115
|
+
status: fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue { name optionId } } } } } } }`,
|
|
116
|
+
options
|
|
117
|
+
).data?.repository?.issue;
|
|
118
|
+
const card = issue?.projectItems?.nodes?.find((node) => node.project?.id === PROJECT_ID);
|
|
119
|
+
return card ? { itemId: card.id, status: card.status?.name ?? null } : undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
104
122
|
/**
|
|
105
123
|
* Moving a task to another column. The task's state on the board is the only thing the progress
|
|
106
124
|
* is visible by: the board does not read the branch or the open PR itself.
|
|
@@ -169,7 +187,7 @@ export function pullState(ref, options) {
|
|
|
169
187
|
const target = ref === undefined || ref === null || `${ref}`.trim() === '' ? [] : [`${ref}`.trim()];
|
|
170
188
|
let pull;
|
|
171
189
|
try {
|
|
172
|
-
pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName'], options);
|
|
190
|
+
pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName,headRefOid'], options);
|
|
173
191
|
} catch (error) {
|
|
174
192
|
if (error instanceof OfflineError) {
|
|
175
193
|
throw error;
|
|
@@ -197,6 +215,9 @@ export function pullState(ref, options) {
|
|
|
197
215
|
// The head branch: the folder guard judges the branch of the named PR, not the checked-out
|
|
198
216
|
// one — the lower PR of a stack is lifted from the upper branch.
|
|
199
217
|
branch: pull.headRefName ?? null,
|
|
218
|
+
// The run on the tip: `success`, `failure`, `running` or `none`. The merge guard reads it —
|
|
219
|
+
// an epic went into main over a red image build, and the rollout fell after it.
|
|
220
|
+
run: pull.headRefOid ? verdictOnHead(pull.headRefOid, options) : 'none',
|
|
200
221
|
};
|
|
201
222
|
}
|
|
202
223
|
|
|
@@ -284,7 +305,7 @@ export function taskState(number, options) {
|
|
|
284
305
|
if (!issue) {
|
|
285
306
|
return { exists: false, viewer: viewerOf(options) };
|
|
286
307
|
}
|
|
287
|
-
const item =
|
|
308
|
+
const item = fetchCard(issue.number, options);
|
|
288
309
|
return {
|
|
289
310
|
exists: true,
|
|
290
311
|
viewer: viewerOf(options),
|
|
@@ -310,7 +331,7 @@ export function taskState(number, options) {
|
|
|
310
331
|
*
|
|
311
332
|
* `state` — what `taskState` returned, or `{ offline: <reason> }` if asking failed.
|
|
312
333
|
*/
|
|
313
|
-
export function describeTaskState(number, state) {
|
|
334
|
+
export function describeTaskState(number, state, waitedSeconds) {
|
|
314
335
|
if (state?.offline) {
|
|
315
336
|
return {
|
|
316
337
|
ok: false,
|
|
@@ -326,7 +347,10 @@ export function describeTaskState(number, state) {
|
|
|
326
347
|
if (!state.onBoard) {
|
|
327
348
|
return {
|
|
328
349
|
ok: false,
|
|
329
|
-
lines: [
|
|
350
|
+
lines: [
|
|
351
|
+
`in the work queue: NO${waitedSeconds === undefined ? '' : ` — not seen in ${waitedSeconds} s of waiting`}`,
|
|
352
|
+
'a task that is not in the queue is backed by no work — nobody will come for it',
|
|
353
|
+
],
|
|
330
354
|
};
|
|
331
355
|
}
|
|
332
356
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fifth step of creating a task: creation is confirmed by the answer of the work queue, not by
|
|
3
|
+
* the output of the command.
|
|
4
|
+
*
|
|
5
|
+
* All four steps before it answer for their own calls and stay silent about whether the task is
|
|
6
|
+
* visible to whoever comes for it. Sixteen creations in a row printed the number with a link that
|
|
7
|
+
* way, and not one of them landed in the queue: the account was limited by the hosting, and the
|
|
8
|
+
* calls gave no refusal at that.
|
|
9
|
+
*/
|
|
10
|
+
import { OfflineError, describeTaskState, taskState } from './board.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The window of waiting: the pauses between readings, in milliseconds, growing, about thirty seconds
|
|
14
|
+
* in all. The queue hands a new card back after seconds, and the delay sometimes outlasts a window
|
|
15
|
+
* of twelve seconds: one creation in six printed «NO» for a card that stood on the board with its
|
|
16
|
+
* assignee. A false refusal here costs more than a delay — it pushes to create the card a second
|
|
17
|
+
* time, and only an administrator can take it off the board. The list of pauses can be set by
|
|
18
|
+
* `RT_TASK_NEW_PAUSES_MS` — a suite does not wait half a minute for it.
|
|
19
|
+
*/
|
|
20
|
+
export const QUEUE_PAUSES_MS = (process.env.RT_TASK_NEW_PAUSES_MS || '1000,2000,4000,8000,15000')
|
|
21
|
+
.split(',')
|
|
22
|
+
.map((pause) => Number(pause))
|
|
23
|
+
.filter((pause) => Number.isFinite(pause) && pause >= 0);
|
|
24
|
+
|
|
25
|
+
const WAITED_SECONDS = Number((QUEUE_PAUSES_MS.reduce((sum, pause) => sum + pause, 0) / 1000).toFixed(1));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One reading of the queue. `unreachable` — there was nothing to ask with: there is nothing to
|
|
29
|
+
* repeat, the answer is not late, there will be none at all.
|
|
30
|
+
*/
|
|
31
|
+
function askQueue(number, token, waitedSeconds) {
|
|
32
|
+
try {
|
|
33
|
+
return { answer: describeTaskState(number, taskState(number, { token }), waitedSeconds), unreachable: false };
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const reason = error instanceof OfflineError ? error.message : String(error.message ?? error);
|
|
36
|
+
return { answer: describeTaskState(number, { offline: reason }), unreachable: true };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The queue's answer about the created task. «NO» is printed only after the whole window: until then
|
|
42
|
+
* it is the queue's delay, not an answer.
|
|
43
|
+
*/
|
|
44
|
+
export function confirmInQueue(number, token) {
|
|
45
|
+
let reading = askQueue(number, token, 0);
|
|
46
|
+
for (let attempt = 0; !reading.answer.ok && !reading.unreachable && attempt < QUEUE_PAUSES_MS.length; attempt += 1) {
|
|
47
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, QUEUE_PAUSES_MS[attempt]);
|
|
48
|
+
reading = askQueue(number, token, WAITED_SECONDS);
|
|
49
|
+
}
|
|
50
|
+
return reading.answer;
|
|
51
|
+
}
|
|
@@ -50,14 +50,13 @@ import {
|
|
|
50
50
|
STATUS_FIELD_ID,
|
|
51
51
|
TASK_KEY,
|
|
52
52
|
botToken,
|
|
53
|
-
describeTaskState,
|
|
54
53
|
gh,
|
|
55
54
|
ghJson,
|
|
56
55
|
graphql,
|
|
57
56
|
numberFromTitle,
|
|
58
|
-
taskState,
|
|
59
57
|
unstampFolder,
|
|
60
58
|
} from './board.mjs';
|
|
59
|
+
import { confirmInQueue } from './task-new-queue.mjs';
|
|
61
60
|
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
62
61
|
|
|
63
62
|
/**
|
|
@@ -437,45 +436,9 @@ if (args.epic) {
|
|
|
437
436
|
console.log(`[${TASK_KEY}-${number}] ${args.title}`);
|
|
438
437
|
console.log(`https://github.com/${OWNER}/${REPO}/issues/${number}`);
|
|
439
438
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
*
|
|
444
|
-
* All four steps above answer for their own calls and stay silent about whether the task is visible
|
|
445
|
-
* to whoever comes for it. Sixteen creations in a row printed the number with a link that way, and
|
|
446
|
-
* not one of them landed in the queue: the account was limited by the hosting, and the calls gave
|
|
447
|
-
* no refusal at that.
|
|
448
|
-
*/
|
|
449
|
-
/**
|
|
450
|
-
* This is read more than once. The queue does not hand back a new card the same second it was
|
|
451
|
-
* created, and the reading goes as the next call after the adding: two creations in a row printed
|
|
452
|
-
* that the task is not in the queue while the card was in place. A false refusal here costs more
|
|
453
|
-
* than a delay — it pushes to create the card a second time, and only an administrator can take it
|
|
454
|
-
* off the board.
|
|
455
|
-
*/
|
|
456
|
-
let unreachable = false;
|
|
457
|
-
|
|
458
|
-
function askQueue() {
|
|
459
|
-
try {
|
|
460
|
-
return describeTaskState(number, taskState(number, { token }));
|
|
461
|
-
} catch (error) {
|
|
462
|
-
// There was nothing to ask with — there is nothing to repeat: the answer is not late,
|
|
463
|
-
// there will be none at all.
|
|
464
|
-
unreachable = true;
|
|
465
|
-
const reason = error instanceof OfflineError ? error.message : String(error.message ?? error);
|
|
466
|
-
return describeTaskState(number, { offline: reason });
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/** How long to wait between readings and how many times to re-read: the queue delay is seconds. */
|
|
471
|
-
const QUEUE_RETRIES = 3;
|
|
472
|
-
const QUEUE_PAUSE_MS = 1500;
|
|
473
|
-
|
|
474
|
-
let answer = askQueue();
|
|
475
|
-
for (let attempt = 1; !answer.ok && !unreachable && attempt < QUEUE_RETRIES; attempt += 1) {
|
|
476
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, QUEUE_PAUSE_MS);
|
|
477
|
-
answer = askQueue();
|
|
478
|
-
}
|
|
439
|
+
// The fifth step: creation is confirmed by the answer of the work queue, not by the output of this
|
|
440
|
+
// command. How long it waits and why is in the module of the step.
|
|
441
|
+
const answer = confirmInQueue(number, token);
|
|
479
442
|
for (const line of answer.lines) {
|
|
480
443
|
(answer.ok ? console.log : console.error)(`task-new: ${line}`);
|
|
481
444
|
}
|
|
@@ -359,6 +359,9 @@ rt_pull_token_login() { :; }
|
|
|
359
359
|
# foreign words: a section not named by the tree is not judged at all.
|
|
360
360
|
RT_PULL_BODY_SECTION="${RT_PULL_BODY_SECTION:-}"
|
|
361
361
|
|
|
362
|
+
# The PR body line closing the branch's task (`{number}`); the keyword is the hosting's, so silent.
|
|
363
|
+
RT_PULL_CLOSES_LINE="${RT_PULL_CLOSES_LINE:-}"
|
|
364
|
+
|
|
362
365
|
# The command that moves a task between the columns of the work queue, and the name of the first
|
|
363
366
|
# column — the one the task leaves when it is taken into work. The name has no default: the tree
|
|
364
367
|
# names the columns in its own words, and an invented one would match nothing and silently turn off
|
|
@@ -92,7 +92,12 @@ rt_epic_over || exit 0
|
|
|
92
92
|
taken="$(printf '%s' "$cmd" | sed -nE 's/.*(checkout|switch)[[:space:]]+(-[A-Za-z]+[[:space:]]+)*-(b|c)[[:space:]]+[A-Za-z]+-([0-9]+)-.*/\4/p; s/.*(task:move|board\.mjs[[:space:]]+move)[^0-9|;&]*([0-9]+).*/\2/p; s/.*--epic-of[[:space:]=]+([0-9]+).*/\1/p' | head -1)"
|
|
93
93
|
transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
|
|
94
94
|
if [ -n "$taken" ] && [ -n "$transcript" ] && [ -f "$transcript" ]; then
|
|
95
|
+
# A menu answer comes in two forms, «The user answered:» and «Your questions have been answered:»,
|
|
96
|
+
# followed by "question"="answer" pairs. Only the answers count: the question is written by the
|
|
97
|
+
# executor, and a number in «take RT-N?» answered «no» is not the owner's word.
|
|
95
98
|
named="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg n "$taken" '
|
|
99
|
+
def menu_answers: if test("^(The user answered|Your questions have been answered):")
|
|
100
|
+
then ([match("\"=\"([^\"]*)\""; "g") | .captures[0].string] | join("\n")) else "" end;
|
|
96
101
|
[.[] | select(.type == "user")
|
|
97
102
|
| select(((.isMeta // false) or (.isCompactSummary // false)) | not)
|
|
98
103
|
| (.message.content // "")
|
|
@@ -102,7 +107,7 @@ if [ -n "$taken" ] && [ -n "$transcript" ] && [ -f "$transcript" ]; then
|
|
|
102
107
|
elif .type == "tool_result" then ((.content
|
|
103
108
|
| if type == "string" then . elif type == "array"
|
|
104
109
|
then (map(if type == "object" then (.text // "") else "" end) | join(" ")) else "" end)
|
|
105
|
-
|
|
|
110
|
+
| menu_answers)
|
|
106
111
|
else "" end) | join("\n"))
|
|
107
112
|
else "" end]
|
|
108
113
|
| map(test("(^|[^0-9])" + $n + "([^0-9]|$)")) | any
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The body of a PR being opened, for the delivery guard: the section about the remaining step and the
|
|
3
|
+
# line that closes the task.
|
|
4
|
+
#
|
|
5
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
|
|
6
|
+
# sources it — one tier of its verdict, moved out when the guard reached its length limit. It uses
|
|
7
|
+
# the guard's own variables — the command, the task number of the branch, both samples — and the
|
|
8
|
+
# guard's `fault`.
|
|
9
|
+
|
|
10
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
11
|
+
|
|
12
|
+
rt_delivery_pull_body() {
|
|
13
|
+
# The body arrives either as an argument or as a file, both are read here; by the time of the
|
|
14
|
+
# parse the file is already written. Neither one nor the other — there is no requirement: a PR
|
|
15
|
+
# without a body is checked by the guard elsewhere. The flag is recognised only as a separate
|
|
16
|
+
# word: the tail `-b` of a branch name in the base argument read as the body flag, and the next
|
|
17
|
+
# word of the command became the body.
|
|
18
|
+
[ -z "$pull_body_section" ] && [ -z "$pull_closes_line" ] && return 0
|
|
19
|
+
command -v perl >/dev/null 2>&1 || return 0
|
|
20
|
+
|
|
21
|
+
local body body_file closes
|
|
22
|
+
body="$(printf '%s' "$cmd" | perl -0ne '
|
|
23
|
+
if (/(?:^|\s)(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
24
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
25
|
+
}
|
|
26
|
+
' 2>/dev/null)"
|
|
27
|
+
body_file="$(printf '%s' "$cmd" | perl -0ne '
|
|
28
|
+
if (/(?:^|\s)(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
29
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
30
|
+
}
|
|
31
|
+
' 2>/dev/null)"
|
|
32
|
+
[ -z "$body" ] && [ -n "$body_file" ] && [ -f "$body_file" ] && body="$(cat "$body_file" 2>/dev/null)"
|
|
33
|
+
[ -z "$body" ] && return 0
|
|
34
|
+
|
|
35
|
+
# The section about the remaining step: without it the owner merges the PR by the button while
|
|
36
|
+
# the run is still going.
|
|
37
|
+
if [ -n "$pull_body_section" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
|
|
38
|
+
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# The line that closes the task. Without it the merged task stays open on the board, and the
|
|
42
|
+
# work queue audit names that only after the merge — three PRs of one epic went out so, and the
|
|
43
|
+
# owner closed their tasks by hand. The number is the branch's, not the one the executor
|
|
44
|
+
# remembers.
|
|
45
|
+
if [ -n "$pull_closes_line" ] && [ -n "$number" ]; then
|
|
46
|
+
closes="${pull_closes_line//\{number\}/$number}"
|
|
47
|
+
printf '%s' "$body" | grep -qE "$closes" \
|
|
48
|
+
|| fault "the body of the request carries no line that closes the task #${number}. Without it the task stays open after the merge, and the board shows the merged work as not done. Write the line by the sample of the tree: ${closes}"
|
|
49
|
+
fi
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The run on the tip of a PR being 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 and calls it on a merge command. It uses the guard's own variables — the command and
|
|
6
|
+
# the tree root — and the guard's `fault`.
|
|
7
|
+
|
|
8
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
9
|
+
|
|
10
|
+
rt_delivery_merge_run() {
|
|
11
|
+
# An epic went into main while the run on its tip was red on the image build: the rollout fell,
|
|
12
|
+
# and every next PR into main turned red. The red was on the PR page and was not read.
|
|
13
|
+
#
|
|
14
|
+
# A red and an unfinished run refuse. `none` passes: a PR into an epic branch gets no run at
|
|
15
|
+
# all, and refusing it would refuse every task of an epic. The tier is a network one — no answer
|
|
16
|
+
# from the work queue helper, no demand.
|
|
17
|
+
command -v rt_pull_state >/dev/null 2>&1 || return 0
|
|
18
|
+
local ref pull run name
|
|
19
|
+
ref="$(printf '%s' "$cmd" | sed -nE 's/.*(gh[[:space:]]+pr[[:space:]]+merge)[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\2/p' | head -1)"
|
|
20
|
+
pull="$(cd "$root" && rt_pull_state "$ref" 2>/dev/null)" || return 0
|
|
21
|
+
printf '%s' "$pull" | jq -e '.exists' >/dev/null 2>&1 || return 0
|
|
22
|
+
run="$(printf '%s' "$pull" | jq -r '.run // empty' 2>/dev/null)"
|
|
23
|
+
name="$(printf '%s' "$pull" | jq -r '.number // empty' 2>/dev/null)"
|
|
24
|
+
name="${name:-$ref}"
|
|
25
|
+
case "$run" in
|
|
26
|
+
failure)
|
|
27
|
+
fault "the run on the tip of the request${name:+ #${name}} is red. A merge over red carries the breakage into the branch, and every next request into it turns red. Read the run — gh run list --commit <tip> — fix it in the branch and repeat." ;;
|
|
28
|
+
running)
|
|
29
|
+
fault "the run on the tip of the request${name:+ #${name}} has not finished. A merge before its end carries what it has not checked yet. Wait for its end and read the result by a command." ;;
|
|
30
|
+
esac
|
|
31
|
+
return 0
|
|
32
|
+
}
|
|
@@ -117,6 +117,9 @@ pull_token_hint="${RT_PULL_TOKEN_HINT:-}"
|
|
|
117
117
|
# the pattern is named by the tree, not by the package: the package does not know someone else's
|
|
118
118
|
# words, and an invented default would match nothing.
|
|
119
119
|
pull_body_section="${RT_PULL_BODY_SECTION:-}"
|
|
120
|
+
# The line that closes the task on the merge, with `{number}` in place of the task number. Its keyword
|
|
121
|
+
# belongs to the hosting, so the sample is named by the tree, as the section above.
|
|
122
|
+
pull_closes_line="${RT_PULL_CLOSES_LINE:-}"
|
|
120
123
|
commit_email="${RT_COMMIT_EMAIL:-}"
|
|
121
124
|
tasks_dir="${RT_TASKS_DIR:-}"
|
|
122
125
|
archive_dir="${RT_ARCHIVE_DIR:-}"
|
|
@@ -332,6 +335,10 @@ command -v rt_delivery_draft_ready >/dev/null 2>&1 && rt_delivery_draft_ready
|
|
|
332
335
|
# quotes — that is how it fired on an edit of this very text. A quoted substring cannot be cut off
|
|
333
336
|
# entirely this way, but an accidental mention inside a word or a path no longer gets through.
|
|
334
337
|
if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(gh[[:space:]]+pr[[:space:]]+merge|glab[[:space:]]+mr[[:space:]]+merge|az[[:space:]]+repos[[:space:]]+pr[[:space:]]+update)([[:space:]]|\$)"; then
|
|
338
|
+
# The run on the tip goes first: the folder tier below leaves the guard early on many paths.
|
|
339
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-merge.sh" ] && . "$rt_hooks_dir/git-guard-delivery-merge.sh" 2>/dev/null
|
|
340
|
+
command -v rt_delivery_merge_run >/dev/null 2>&1 && rt_delivery_merge_run
|
|
341
|
+
deny_faults
|
|
335
342
|
rt_delivery_merge_folder
|
|
336
343
|
fi
|
|
337
344
|
|
|
@@ -457,32 +464,11 @@ elif [ -n "$pull_token_var" ] \
|
|
|
457
464
|
fault "who will open the request cannot be learned: the hosting was not asked, and the command carries no substitution of «${pull_token_var}». Opened by the logged-in account, the request may come out from the very person named as its reviewer, and that is fixed only by reopening.${pull_token_hint:+ Substitute the token: ${pull_token_hint} …}"
|
|
458
465
|
fi
|
|
459
466
|
|
|
460
|
-
# The
|
|
461
|
-
#
|
|
462
|
-
#
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
# argument read as the body flag, and the next word of the command became the body.
|
|
466
|
-
if [ -n "$pull_body_section" ]; then
|
|
467
|
-
body=''
|
|
468
|
-
if command -v perl >/dev/null 2>&1; then
|
|
469
|
-
body="$(printf '%s' "$cmd" | perl -0ne '
|
|
470
|
-
if (/(?:^|\s)(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
471
|
-
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
472
|
-
}
|
|
473
|
-
' 2>/dev/null)"
|
|
474
|
-
body_file="$(printf '%s' "$cmd" | perl -0ne '
|
|
475
|
-
if (/(?:^|\s)(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
476
|
-
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
477
|
-
}
|
|
478
|
-
' 2>/dev/null)"
|
|
479
|
-
[ -z "$body" ] && [ -n "$body_file" ] && [ -f "$body_file" ] && body="$(cat "$body_file" 2>/dev/null)"
|
|
480
|
-
fi
|
|
481
|
-
|
|
482
|
-
if [ -n "$body" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
|
|
483
|
-
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
484
|
-
fi
|
|
485
|
-
fi
|
|
467
|
+
# The body of the request: the section about the remaining step and the line that closes the task.
|
|
468
|
+
# The subject lives in a helper next door — `git-guard-delivery-body.sh`, by the same technique as
|
|
469
|
+
# the draft above.
|
|
470
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-body.sh" ] && . "$rt_hooks_dir/git-guard-delivery-body.sh" 2>/dev/null
|
|
471
|
+
command -v rt_delivery_pull_body >/dev/null 2>&1 && rt_delivery_pull_body
|
|
486
472
|
|
|
487
473
|
|
|
488
474
|
# The task folder is taken apart before the PR opens, not after the approval: the owner merges as
|
|
@@ -275,7 +275,7 @@ if [ -n "$tool" ]; then
|
|
|
275
275
|
| select(type == "array") | .[] | select(.type == "tool_result") | .content
|
|
276
276
|
| if type == "string" then . elif type == "array"
|
|
277
277
|
then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
|
|
278
|
-
| select(test("^The user answered:"))];
|
|
278
|
+
| select(test("^(The user answered|Your questions have been answered):"))];
|
|
279
279
|
def recommended: ([match("\"=\"[^\"]*\""; "g")] | length) as $all
|
|
280
280
|
| ([match("\\((Recommended|Рекомендую|Рекомендован[^)]*)\\)\"(,|\\.|[[:space:]]|$)"; "g")] | length) as $marked
|
|
281
281
|
| $all > 0 and $all == $marked;
|
|
@@ -436,7 +436,7 @@ fi
|
|
|
436
436
|
# circle: the search was made, the same refusal came back, and the executor stopped asking at all.
|
|
437
437
|
if [ -n "$need_re" ]; then
|
|
438
438
|
named="$(printf '%s' "$need_re" | tr '|' '\n' | sed 's/.*/«&»/' | paste -sd ',' - | sed 's/,/, /g')"
|
|
439
|
-
reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. The turn holds edits, and for them only the rules of their area count: $named. Load them by the tool Skill, or read them in $rules_dir, and answer from what is found; ask only what they do not cover.
|
|
439
|
+
reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. The turn holds edits, and for them only the rules of their area count: $named. A search over the specs or over other rules does not lift this refusal. The area counts every edit since the owner's last message, the stretch before a context compaction included. Load them by the tool Skill, or read them in $rules_dir, and answer from what is found; ask only what they do not cover.
|
|
440
440
|
|
|
441
441
|
A rule loaded before the owner's last message does not count: the guard judges one turn, and the next session is not refused."
|
|
442
442
|
else
|
|
@@ -104,7 +104,7 @@ rt_write_targets() {
|
|
|
104
104
|
# data.
|
|
105
105
|
function emit_calls(s, rest, arg, name) {
|
|
106
106
|
rest = s
|
|
107
|
-
while (match(rest, /(open|writeFileSync|writeFile|appendFileSync|appendFile|
|
|
107
|
+
while (match(rest, /(open|writeFileSync|writeFile|appendFileSync|appendFile|copyfile|copy2|rename|symlink|mkdir|makedirs)[ \t]*\(/)) {
|
|
108
108
|
rest = substr(rest, RSTART + RLENGTH)
|
|
109
109
|
arg = rest
|
|
110
110
|
sub(/[,)].*$/, "", arg)
|
|
@@ -132,6 +132,72 @@ rt_write_targets() {
|
|
|
132
132
|
|| s ~ /(^|[|;&(]|[ \t])(tee|cp|mv|rm|touch|install|truncate)([ \t]|$)/
|
|
133
133
|
}
|
|
134
134
|
function trim(s) { sub(/^[ \t]+/, "", s); sub(/[ \t]+$/, "", s); return s }
|
|
135
|
+
# The index of the bracket that closes the call whose arguments start at `from`: the
|
|
136
|
+
# quotes are skipped, and a bracket inside a string closes nothing.
|
|
137
|
+
function args_end(s, from, i, c, depth, q) {
|
|
138
|
+
depth = 1
|
|
139
|
+
for (i = from; i <= length(s); i++) {
|
|
140
|
+
c = substr(s, i, 1)
|
|
141
|
+
if (q != "") {
|
|
142
|
+
if (c == q && substr(s, i - 1, 1) != "\\") { q = "" }
|
|
143
|
+
} else if (c == "\047" || c == "\"") {
|
|
144
|
+
q = c
|
|
145
|
+
} else if (c == "(") {
|
|
146
|
+
depth++
|
|
147
|
+
} else if (c == ")") {
|
|
148
|
+
depth--
|
|
149
|
+
if (depth == 0) { return i }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return length(s) + 1
|
|
153
|
+
}
|
|
154
|
+
# The first argument of a call: everything up to a comma outside quotes and brackets.
|
|
155
|
+
function first_arg(a, i, c, depth, q) {
|
|
156
|
+
for (i = 1; i <= length(a); i++) {
|
|
157
|
+
c = substr(a, i, 1)
|
|
158
|
+
if (q != "") {
|
|
159
|
+
if (c == q && substr(a, i - 1, 1) != "\\") { q = "" }
|
|
160
|
+
} else if (c == "\047" || c == "\"") {
|
|
161
|
+
q = c
|
|
162
|
+
} else if (c == "(") {
|
|
163
|
+
depth++
|
|
164
|
+
} else if (c == ")") {
|
|
165
|
+
depth--
|
|
166
|
+
} else if (c == "," && depth == 0) {
|
|
167
|
+
return substr(a, 1, i - 1)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return a
|
|
171
|
+
}
|
|
172
|
+
# What the script writes or substitutes is the content of the write, not its target: a
|
|
173
|
+
# path inside the written string belongs to the content of that file. A script that
|
|
174
|
+
# edited a work file and named a laid-out copy in the text of a new line was refused by
|
|
175
|
+
# the name of a copy it never opened. The call stays and its first argument stays where
|
|
176
|
+
# that argument is the address (`writeFileSync(path, data)`); the data and the argument
|
|
177
|
+
# of `.write(`, `.write_text(`, `.write_bytes(` and of a string `.replace(` are cut.
|
|
178
|
+
# `os.replace(source, target)` is a transfer, and its arguments stay.
|
|
179
|
+
function strip_content(s, out, pre, name, from, endp, args) {
|
|
180
|
+
out = ""
|
|
181
|
+
while (match(s, /(\.write|\.write_text|\.write_bytes|\.replace|writeFileSync|appendFileSync|writeFile|appendFile)[ \t]*\(/)) {
|
|
182
|
+
pre = substr(s, 1, RSTART - 1)
|
|
183
|
+
name = substr(s, RSTART, RLENGTH)
|
|
184
|
+
from = RSTART + RLENGTH
|
|
185
|
+
if (name ~ /^\.replace/ && pre ~ /(^|[^A-Za-z0-9_])os$/) {
|
|
186
|
+
out = out pre name
|
|
187
|
+
s = substr(s, from)
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
endp = args_end(s, from)
|
|
191
|
+
if (name ~ /^\./) {
|
|
192
|
+
out = out pre name ")"
|
|
193
|
+
} else {
|
|
194
|
+
args = substr(s, from, endp - from)
|
|
195
|
+
out = out pre name first_arg(args) ")"
|
|
196
|
+
}
|
|
197
|
+
s = substr(s, endp + 1)
|
|
198
|
+
}
|
|
199
|
+
return out s
|
|
200
|
+
}
|
|
135
201
|
# Paths are taken from the write lines, not from the whole body.
|
|
136
202
|
#
|
|
137
203
|
# Before, a body that writes anything at all gave away all its path-like words at once:
|
|
@@ -146,7 +212,7 @@ rt_write_targets() {
|
|
|
146
212
|
if (wrote) {
|
|
147
213
|
for (i = 1; i <= lines; i++) { note_var(line[i]) }
|
|
148
214
|
for (i = 1; i <= lines; i++) {
|
|
149
|
-
if (writes(line[i])) { emit(line[i]); emit_calls(line[i]) }
|
|
215
|
+
if (writes(line[i])) { emit(strip_content(line[i])); emit_calls(line[i]) }
|
|
150
216
|
}
|
|
151
217
|
}
|
|
152
218
|
for (i = 1; i <= lines; i++) { delete line[i] }
|
|
@@ -167,7 +233,7 @@ rt_write_targets() {
|
|
|
167
233
|
if ($0 ~ /(^|[|;&(]|[ \t])(python3?|node|ruby|perl|php|deno|bun)([ \t]|$)/ \
|
|
168
234
|
&& match($0, /[ \t]-[ce][ \t]/)) {
|
|
169
235
|
rest = substr($0, RSTART + RLENGTH)
|
|
170
|
-
if (writes(rest)) { note_var(rest); emit(rest); emit_calls(rest) }
|
|
236
|
+
if (writes(rest)) { note_var(rest); emit(strip_content(rest)); emit_calls(rest) }
|
|
171
237
|
}
|
|
172
238
|
# The heredoc body: the write path of the interpreter stands exactly there.
|
|
173
239
|
if (match($0, /<<-?[ \t]*[\047\"]?[A-Za-z_][A-Za-z0-9_]*/)) {
|
|
@@ -73,4 +73,5 @@ declaration: a domain section is named by the id of its item.
|
|
|
73
73
|
- An address move without editing the end-to-end tests: they walk by addresses, and the run goes
|
|
74
74
|
red.
|
|
75
75
|
- An icon picked as "similar": a missing one is added to the sprite and to
|
|
76
|
-
`<prefix>-icon-names.ts`.
|
|
76
|
+
`<prefix>-icon-names.ts`. The name of a present icon is copied from the kit icon file as is: some
|
|
77
|
+
names carry the `ico-` prefix and most do not.
|
|
@@ -239,6 +239,9 @@ past session, and it answers 200 with old code.
|
|
|
239
239
|
`nx run-many -t build` both the site and the admin go down. Build what you check
|
|
240
240
|
(`npx nx build site`), not the whole tree. If the servers went down, the agent cannot bring them
|
|
241
241
|
back up — the guard is in the way, so the owner is told at once, not at the end of the session.
|
|
242
|
+
The push gate is such a build too: its set runs the build of everything affected. So the
|
|
243
|
+
measurement is taken before the push or on a stand from the production build. The answer of the
|
|
244
|
+
server, not its port, tells whether it survived.
|
|
242
245
|
- Take the rendering port with care: the developer's stand goes by the same name
|
|
243
246
|
`ssr:<rendering port>` through `host-gateway`, and while a foreign process hangs on it, the
|
|
244
247
|
stand serves a foreign build.
|
|
@@ -83,8 +83,29 @@ The owner's language is the one they write in chat and on cards. An owner writin
|
|
|
83
83
|
gets an English task, and that is no miss: the miss is a text in a language the addressee did
|
|
84
84
|
not choose.
|
|
85
85
|
|
|
86
|
+
## A guide for an executor in another tree
|
|
87
|
+
|
|
88
|
+
Its reader has neither the author's memory nor the author's conversation, so the guide is checked
|
|
89
|
+
step by step before it is handed over: each step is done from the text alone. Addresses, access
|
|
90
|
+
and the state of name records are written in. A solution already found and verified goes in as a
|
|
91
|
+
recipe; "decide later" stands only where no way was verified. The ban on naming another tree covers
|
|
92
|
+
its name, not the infrastructure its reader needs.
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
✗ Шаг 1. Подготовьте узел. Адрес и доступ решим позже.
|
|
96
|
+
✓ Шаг 1. Узел — таблица «Где узел»: адрес, порт почты, вход по ключу. Запись DNS ставит владелец
|
|
97
|
+
домена, и в задаче она названа его действием.
|
|
98
|
+
```
|
|
99
|
+
|
|
86
100
|
## Pitfalls
|
|
87
101
|
|
|
102
|
+
- **A promise about the behaviour of an outside service names what backs it.** A host or a bot is
|
|
103
|
+
promised to do something only with a quote of its documentation or a run that did it; where it
|
|
104
|
+
cannot be checked before the merge, the text says exactly that.
|
|
105
|
+
- **What a text says about another record is read from that record in the same turn.** A release
|
|
106
|
+
note names a task by the title read in the tracker at that minute, and a commit without a task
|
|
107
|
+
number does not go into it: a number taken from memory lands on someone else's task.
|
|
108
|
+
|
|
88
109
|
- **An edit made by a shell command is judged by the whole command, the old version inside it
|
|
89
110
|
included.** The style check gets the body of the call, not the text that will end up in the
|
|
90
111
|
file: a rewrite carrying the previous wording inside a heredoc or an interpreter string is
|
|
@@ -89,11 +89,13 @@ for v in $(docker volume ls -q -f dangling=true); do
|
|
|
89
89
|
[ -z "$(docker volume inspect "$v" --format '{{index .Labels "com.docker.compose.project"}}')" ] \
|
|
90
90
|
&& docker volume rm "$v"
|
|
91
91
|
done
|
|
92
|
-
docker builder prune --force --filter until=24h
|
|
92
|
+
docker builder prune --builder <name> --force --filter until=24h # yesterday's cache is nobody's, the fresh one the build needs
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
A threshold on the cache, not a full cleanup: removed whole, it makes the next build go from
|
|
96
|
-
scratch.
|
|
96
|
+
scratch. The cache is pruned with the builder named: without `--builder` the command prunes the
|
|
97
|
+
current builder, and a pipeline running on the same machine changes which one that is, so the cache
|
|
98
|
+
the pipeline builds with goes with it.
|
|
97
99
|
|
|
98
100
|
A pipeline run living on the owner's machine cleans up after itself, and does it in a step that
|
|
99
101
|
runs on failure too: space runs out exactly when the run fails, and a cleanup skipped on failure
|
|
@@ -181,6 +181,12 @@ one's own hand: it is removed by whoever's work it is, in their own branch.
|
|
|
181
181
|
|
|
182
182
|
- "Keep both sides" applied to all files alike: in a spec it is right, in code and in the work
|
|
183
183
|
list it is not.
|
|
184
|
+
- **A merge carries edits of files, not edits of an application.** A function switched on by one
|
|
185
|
+
line in the root of one application stays off in the second application of the tree: nobody
|
|
186
|
+
touched that root, so there is no conflict, and an optional dependency is allowed to be absent, so
|
|
187
|
+
no check turns red. After the merge the diff of the merged-in roots and shared layers is read for
|
|
188
|
+
every application of the tree: each added line is either carried over or named in the report as
|
|
189
|
+
not needed there.
|
|
184
190
|
- The merge command taken without the signature variables: the merge commit is signed by a
|
|
185
191
|
person, and the push set refuses it — at the step where all checks are already green. This is
|
|
186
192
|
fixed by rewriting the branch, not by editing one commit: conflict resolutions usually already
|
|
@@ -21,7 +21,10 @@ Pattern of the rule `git-workflow`. What must be true — the law
|
|
|
21
21
|
|
|
22
22
|
## The PR is attached to the task
|
|
23
23
|
|
|
24
|
-
The body starts with the link line — by it the board fills the linked PRs field
|
|
24
|
+
The body starts with the link line — by it the board fills the linked PRs field, and by it the task
|
|
25
|
+
closes on the merge. The number in it is the branch's, copied rather than recalled; a tree that
|
|
26
|
+
named the sample of the line in its profile, `RT_PULL_CLOSES_LINE`, gets the opening refused by the
|
|
27
|
+
delivery guard without it. Reviewer,
|
|
25
28
|
assignee and labels are set by the same command, and a PR does not open without them:
|
|
26
29
|
|
|
27
30
|
```bash
|
|
@@ -34,6 +34,15 @@ gh pr ready <номер>
|
|
|
34
34
|
Lifting the draft is the last step of handing the work over, not a separate matter. Until it is
|
|
35
35
|
done, the work is not handed over, however many commits lie in the branch.
|
|
36
36
|
|
|
37
|
+
**A merge the executor was told to make goes after the run on the tip is read by a command.** The
|
|
38
|
+
merge command is refused by the delivery guard on a red or unfinished run; a click on the host's
|
|
39
|
+
button no guard sees, so before it the run is read the same way. An epic went into main over a red
|
|
40
|
+
image build, and the rollout fell after it.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
gh run list --commit "$(gh pr view <номер> --json headRefOid --jq .headRefOid)"
|
|
44
|
+
```
|
|
45
|
+
|
|
37
46
|
## Finish the handed-over first, then take new work
|
|
38
47
|
|
|
39
48
|
An open PR is work in flight: its run ages, its branch lags behind main, its body describes the
|