@rt-tools/agent-kit 0.28.0 → 0.29.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-epic-link.github.mjs +13 -1
- package/assets/checks/board-runs.github.mjs +102 -2
- package/assets/checks/check-board.github.mjs +63 -3
- package/assets/checks/main-run.github.mjs +69 -0
- package/assets/checks/rt-kit-checks.config.mjs +15 -0
- package/assets/checks/tree-assignment.mjs +169 -0
- package/assets/hooks/end-conversation-guard.sh +59 -0
- package/assets/hooks/epic-over.sh +11 -2
- package/assets/hooks/git-guard-delivery-epic.sh +7 -0
- package/assets/hooks/git-guard-delivery.sh +2 -1
- package/assets/hooks/git-guard-tree-assignment.sh +77 -0
- package/assets/hooks/hook-input.sh +8 -1
- package/assets/hooks/main-run-context.sh +45 -0
- package/assets/hooks/tree-assignment-guard.sh +101 -0
- package/assets/hooks/turn-exit-epic.sh +110 -0
- package/assets/hooks/turn-exit-guard.sh +34 -20
- package/assets/hooks/turn-exit-patterns.sh +0 -9
- package/assets/hooks/turn-exit-verdict.sh +20 -8
- package/assets/laws/delivery.md +6 -0
- package/assets/laws/work-conduct.md +4 -0
- package/assets/patterns/git-workflow-merge.md +13 -0
- package/assets/patterns/git-workflow-pr-body.github.md +156 -0
- package/assets/patterns/git-workflow-pr.github.md +6 -104
- package/assets/patterns/git-workflow-stack.md +19 -2
- package/assets/patterns/task-flow-close.md +1 -1
- package/assets/patterns/task-flow-resume.md +8 -0
- package/assets/pitfalls/git-workflow.github.md +6 -0
- package/assets/pitfalls/turn-conduct.md +18 -0
- package/assets/rules/doc-style.md +3 -2
- package/assets/rules/git-workflow.github.md +35 -37
- package/assets/rules/task-flow.md +33 -33
- package/assets/rules/turn-conduct.md +31 -32
- package/assets/samples/tasks/_template/progress.md +1 -1
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +2 -1
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo.d.ts +49 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +9 -2
- package/lib/cargo.js.map +1 -1
- package/lib/observations-cargo.d.ts +20 -0
- package/lib/observations-cargo.d.ts.map +1 -0
- package/lib/observations-cargo.js +88 -0
- package/lib/observations-cargo.js.map +1 -0
- package/lib/shipment.d.ts +8 -20
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +22 -39
- package/lib/shipment.js.map +1 -1
- package/lib/tree-mark.d.ts +17 -0
- package/lib/tree-mark.d.ts.map +1 -0
- package/lib/tree-mark.js +41 -0
- package/lib/tree-mark.js.map +1 -0
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.29.0.tgz +0 -0
- package/rt-tools-agent-kit-0.28.0.tgz +0 -0
|
@@ -24,6 +24,18 @@ const TASK_KEY = CONFIG.board?.taskKey ?? '';
|
|
|
24
24
|
* kinship of cards.
|
|
25
25
|
*/
|
|
26
26
|
export function declaredEpicOf(body, number = null) {
|
|
27
|
-
const named = String(body ?? '').match(
|
|
27
|
+
const named = String(body ?? '').match(DECLARATION)?.[1];
|
|
28
28
|
return number === null ? named : named !== undefined && Number(named) === number;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The declaration opens its line: the creating command writes it as a line of its own, and a
|
|
33
|
+
* hand-written one carries at most an ordinal before it — «Первая задачи эпика #7». A list marker
|
|
34
|
+
* is allowed for the same reason: in a plan the declaration lies among items.
|
|
35
|
+
*
|
|
36
|
+
* Read anywhere in the line, it caught the same words inside a sentence: a task whose description
|
|
37
|
+
* said «семь задач эпика #1870» was read as belonging to that epic, and the delivery check refused
|
|
38
|
+
* its branch from the main one. The words alone cannot tell a declaration from prose about an
|
|
39
|
+
* epic — the place in the line can.
|
|
40
|
+
*/
|
|
41
|
+
const DECLARATION = new RegExp(`^\\s*(?:[-*]\\s+)?(?:\\S+\\s+)?задач[аи]\\s+эпика?\\s+(?:#|${TASK_KEY}-)(\\d+)`, 'im');
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* No network or no token — the calls throw `OfflineError`, like the rest of the work with the
|
|
11
11
|
* hosting: an inability to ask does not count as a discrepancy.
|
|
12
12
|
*/
|
|
13
|
-
import { existsSync } from 'node:fs';
|
|
14
|
-
import { join } from 'node:path';
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { basename, join } from 'node:path';
|
|
15
15
|
|
|
16
16
|
import { OWNER, REPO, gh } from './board.mjs';
|
|
17
17
|
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
@@ -169,6 +169,106 @@ export function evictedOnHead(sha, options) {
|
|
|
169
169
|
.map((run) => run.id);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Whether the pipeline wakes on a push to the main branch.
|
|
174
|
+
*
|
|
175
|
+
* A pipeline that listens to requests alone never runs on the main branch, and the absence of a
|
|
176
|
+
* run there says nothing: a tree like that gets no finding about the main run, and the audit says
|
|
177
|
+
* so out loud. The trigger is read from the pipeline file by its `on` block: a `push` key without
|
|
178
|
+
* a list of branches wakes on every branch, one with a list — on the branches named.
|
|
179
|
+
*/
|
|
180
|
+
export function pipelineWakesOnPush(pipelineText, mainBranch) {
|
|
181
|
+
const lines = pipelineText.split('\n');
|
|
182
|
+
const indentOf = (line) => line.length - line.trimStart().length;
|
|
183
|
+
// The lines of a block: those below its key and indented deeper than it, blank ones included.
|
|
184
|
+
const blockAfter = (index) => {
|
|
185
|
+
const depth = indentOf(lines[index]);
|
|
186
|
+
const body = [];
|
|
187
|
+
for (let i = index + 1; i < lines.length; i += 1) {
|
|
188
|
+
if (lines[i].trim() !== '' && indentOf(lines[i]) <= depth) {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
body.push(lines[i]);
|
|
192
|
+
}
|
|
193
|
+
return body;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const onIndex = lines.findIndex((line) => /^on:\s*(#.*)?$/.test(line));
|
|
197
|
+
if (onIndex === -1) {
|
|
198
|
+
// The short form: `on: push` or `on: [push, pull_request]` — a push without a list of
|
|
199
|
+
// branches wakes on every branch.
|
|
200
|
+
return lines.some((line) => /^on:\s*(\[.*\bpush\b.*\]|push)\s*(#.*)?$/.test(line));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const on = blockAfter(onIndex);
|
|
204
|
+
const pushIndex = on.findIndex((line) => /^\s+push:\s*(#.*)?$/.test(line));
|
|
205
|
+
if (pushIndex === -1) {
|
|
206
|
+
return on.some((line) => /^\s+push:\s*\S/.test(line));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const pushLines = on.slice(pushIndex);
|
|
210
|
+
const pushDepth = indentOf(pushLines[0]);
|
|
211
|
+
const push = pushLines.slice(1).filter((line) => line.trim() === '' || indentOf(line) > pushDepth);
|
|
212
|
+
const branchesIndex = push.findIndex((line) => /^\s+branches:/.test(line));
|
|
213
|
+
if (branchesIndex === -1) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const inline = /^\s+branches:\s*\[(.*)\]/.exec(push[branchesIndex]);
|
|
218
|
+
const names = inline
|
|
219
|
+
? inline[1].split(',')
|
|
220
|
+
: push
|
|
221
|
+
.slice(branchesIndex + 1)
|
|
222
|
+
.filter((line) => /^\s+-\s/.test(line))
|
|
223
|
+
.map((line) => line.replace(/^\s+-\s*/, ''));
|
|
224
|
+
return names.map((name) => name.trim().replace(/^['"]|['"]$/g, '')).includes(mainBranch);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* How the last run of the pipeline on the main branch ended: `success`, `failure`, `running`,
|
|
229
|
+
* `evicted` if it was pushed out of the queue and never started, or `none` if there was no run.
|
|
230
|
+
*
|
|
231
|
+
* The main branch is asked about apart from the rollout and apart from the tips of open requests.
|
|
232
|
+
* A merge is read as the end of the work, and the run it starts is read by nobody: a red run of the
|
|
233
|
+
* main branch stood for a day and a half, the rollout behind it did not go, and the owner said so.
|
|
234
|
+
* A cancelled run is told from a fallen one by its step count, the same way as on a request tip:
|
|
235
|
+
* zero steps means the queue pushed it out for the next merge, and the merge was checked by nothing.
|
|
236
|
+
*/
|
|
237
|
+
export function lastMainRun(mainBranch, options) {
|
|
238
|
+
const runs = gh(
|
|
239
|
+
[
|
|
240
|
+
'api',
|
|
241
|
+
`repos/${OWNER}/${REPO}/actions/workflows/${encodeURIComponent(basename(PIPELINE))}/runs` +
|
|
242
|
+
`?branch=${encodeURIComponent(mainBranch)}&per_page=1`,
|
|
243
|
+
'--jq',
|
|
244
|
+
'[.workflow_runs[] | {id, status, conclusion, sha: .head_sha, at: .created_at, url: .html_url}] | first // empty',
|
|
245
|
+
],
|
|
246
|
+
options
|
|
247
|
+
);
|
|
248
|
+
const last = String(runs).trim();
|
|
249
|
+
if (!last) {
|
|
250
|
+
return { verdict: 'none' };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const run = JSON.parse(last);
|
|
254
|
+
if (run.status !== 'completed') {
|
|
255
|
+
return { verdict: 'running', ...run };
|
|
256
|
+
}
|
|
257
|
+
if (run.conclusion === 'success') {
|
|
258
|
+
return { verdict: 'success', ...run };
|
|
259
|
+
}
|
|
260
|
+
if (run.conclusion === 'cancelled' && jobCount(run.id, options) === 0) {
|
|
261
|
+
return { verdict: 'evicted', ...run };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return { verdict: 'failure', ...run };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The text of the pipeline file; an empty string where the tree has none. */
|
|
268
|
+
export function pipelineText() {
|
|
269
|
+
return HAS_PIPELINE ? readFileSync(join(ROOT, PIPELINE), 'utf8') : '';
|
|
270
|
+
}
|
|
271
|
+
|
|
172
272
|
/** How many steps a run has started. Zero means it never started at all. */
|
|
173
273
|
function jobCount(id, options) {
|
|
174
274
|
const answer = gh(['api', `repos/${OWNER}/${REPO}/actions/runs/${id}/jobs?per_page=1`, '--jq', '.total_count'], options);
|
|
@@ -51,12 +51,17 @@ import {
|
|
|
51
51
|
import { checkBranchFolders } from './board-folders.mjs';
|
|
52
52
|
import { checkConflicting, checkHeadRun } from './board-pull-state.mjs';
|
|
53
53
|
import { checkLongWork } from './board-long-work.mjs';
|
|
54
|
-
import { HAS_PIPELINE, deployLag, lastDeploy } from './board-runs.mjs';
|
|
54
|
+
import { HAS_PIPELINE, deployLag, lastDeploy, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
|
|
55
55
|
import { checkEpicLinks, checkEpicPullBase, checkEpicState, checkEpicSubIssues } from './board-epics.mjs';
|
|
56
56
|
import { similarTitles } from './board-titles.mjs';
|
|
57
57
|
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
58
58
|
|
|
59
59
|
const IN_REVIEW = STATUS_OPTIONS[IN_REVIEW_STATUS].name;
|
|
60
|
+
/**
|
|
61
|
+
* The columns a card reaches only after its task is closed: the merge closes the task, and the
|
|
62
|
+
* board's own rule moves the card. A tree that names neither gets no such audit.
|
|
63
|
+
*/
|
|
64
|
+
const CLOSING_STATUSES = [STATUS_OPTIONS.done?.name, STATUS_OPTIONS.deployed?.name].filter((name) => typeof name === 'string' && name !== '');
|
|
60
65
|
const TASKS_DIR = join(ROOT, CONFIG.tasksDir);
|
|
61
66
|
/** Age of an abandoned draft after which it stops looking like one started today. */
|
|
62
67
|
const DRAFT_DAYS = 7;
|
|
@@ -157,7 +162,7 @@ function folderInBranch(branch, options) {
|
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
let checked = { issues: 0, pulls: 0, cargo: 0 };
|
|
165
|
+
let checked = { issues: 0, pulls: 0, cargo: 0, offBase: 0 };
|
|
161
166
|
|
|
162
167
|
// Drafts are judged by the disk and so are checked always: no connection is needed for that.
|
|
163
168
|
checkDrafts();
|
|
@@ -175,7 +180,7 @@ try {
|
|
|
175
180
|
// such a record, whatever labels it wears.
|
|
176
181
|
const open = CARGO_LABELS.size === 0 ? allOpen : allOpen.filter((issue) => !isCargo(issue));
|
|
177
182
|
const pulls = fetchOpenPulls(options);
|
|
178
|
-
checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length };
|
|
183
|
+
checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length, offBase: 0 };
|
|
179
184
|
|
|
180
185
|
for (const item of board.foreign) {
|
|
181
186
|
report(`the board: ${item} — the board holds tasks, not PRs about them`);
|
|
@@ -230,6 +235,9 @@ try {
|
|
|
230
235
|
if (HAS_PIPELINE && pull.headRefOid) {
|
|
231
236
|
checkHeadRun(pull, report, MAIN_BRANCH, options);
|
|
232
237
|
}
|
|
238
|
+
if (pull.baseRefName && pull.baseRefName !== MAIN_BRANCH) {
|
|
239
|
+
checked.offBase += 1;
|
|
240
|
+
}
|
|
233
241
|
|
|
234
242
|
checkConflicting(pull, report);
|
|
235
243
|
|
|
@@ -268,6 +276,16 @@ try {
|
|
|
268
276
|
if (pull === undefined && status === IN_REVIEW) {
|
|
269
277
|
report(`#${issue.number}: the task awaits review, and there is no open PR behind it — the column lags the work`);
|
|
270
278
|
}
|
|
279
|
+
// A closing column is reached by a card whose task the merge has closed: the board moves
|
|
280
|
+
// it by its own rule on a closed item. An open task standing there says the opposite of
|
|
281
|
+
// what the owner reads from the column — and nobody notices: the mover to the last column
|
|
282
|
+
// skips such a card in silence, and the closing of a task merged into an epic branch is
|
|
283
|
+
// done by a pipeline that any tree may lack, may add later, or may see fail.
|
|
284
|
+
if (status !== null && CLOSING_STATUSES.includes(status)) {
|
|
285
|
+
report(
|
|
286
|
+
`#${issue.number}: the task is open, and its card stands at «${status}» — a closing column means the work is merged. Close the task, or move the card back by npm run task:move -- ${issue.number} <column>`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
271
289
|
}
|
|
272
290
|
|
|
273
291
|
// The task folder dies with the task: what explains a settled decision moves to
|
|
@@ -328,11 +346,53 @@ if (!offline && DEPLOY_WORKFLOW) {
|
|
|
328
346
|
}
|
|
329
347
|
}
|
|
330
348
|
|
|
349
|
+
// The main branch is audited by the last run of the pipeline on it. A PR is checked before the
|
|
350
|
+
// merge, but the merge itself nobody watches: a red main run stood for a day and a half without a
|
|
351
|
+
// line about it, and a run pushed out of the queue by the next merge looked like a passed one.
|
|
352
|
+
if (!offline && HAS_PIPELINE) {
|
|
353
|
+
if (pipelineWakesOnPush(pipelineText(), MAIN_BRANCH)) {
|
|
354
|
+
try {
|
|
355
|
+
const run = lastMainRun(MAIN_BRANCH, { token: botToken() ?? undefined });
|
|
356
|
+
if (run.verdict === 'failure') {
|
|
357
|
+
report(
|
|
358
|
+
`the last run of «${MAIN_BRANCH}» is red on ${String(run.sha).slice(0, 8)} of ${String(run.at).slice(0, 10)}: ` +
|
|
359
|
+
`merges on top go out unchecked — ${run.url}`
|
|
360
|
+
);
|
|
361
|
+
} else if (run.verdict === 'evicted') {
|
|
362
|
+
report(
|
|
363
|
+
`the run of «${MAIN_BRANCH}» on ${String(run.sha).slice(0, 8)} was pushed out of the queue and never checked the merge — ${run.url}`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
} catch (error) {
|
|
367
|
+
if (error instanceof OfflineError) {
|
|
368
|
+
console.log(`check-board: the main branch run was not checked — ${error.message}`);
|
|
369
|
+
} else {
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
// Silence here would read as «main is green»: the tree whose pipeline sleeps on a push is told so.
|
|
375
|
+
console.log(`check-board: the main branch run was not checked — the pipeline does not wake on a push to «${MAIN_BRANCH}»`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
331
379
|
// What was not checked is named out loud: silence about runs would read as "the runs are there".
|
|
332
380
|
if (!offline && !DEPLOY_WORKFLOW) {
|
|
333
381
|
console.log('check-board: production was not checked against the main branch — the rollout workflow is not named in the tree config');
|
|
334
382
|
}
|
|
335
383
|
|
|
384
|
+
// A base other than the main branch has two consequences, and they are read from one line: the
|
|
385
|
+
// pipeline wakes for no such PR, and the host closes no task on its merge. Named apart, the
|
|
386
|
+
// second was read by nobody — the executor took the line about the run as the whole of it, and
|
|
387
|
+
// the tasks of a chain stayed open after their merges. Per PR the audit is silent: that is the
|
|
388
|
+
// order of handing in of every task of an epic, and a line on each would teach to skip the audit.
|
|
389
|
+
if (!offline && checked.offBase > 0) {
|
|
390
|
+
console.log(
|
|
391
|
+
`check-board: open PRs with a base other than «${MAIN_BRANCH}» — ${checked.offBase}: the pipeline gives them no run, ` +
|
|
392
|
+
`and the host closes no task on their merge — the tree closes those by a pipeline of its own or by the hand after the merge`
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
336
396
|
// What was filtered out is named by number: silent filtering is indistinguishable from a broken
|
|
337
397
|
// audit — a label named with a typo would switch the check off entirely and say nothing about it.
|
|
338
398
|
if (!offline && checked.cargo > 0) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The last run of the main branch in one line.
|
|
4
|
+
*
|
|
5
|
+
* node tools/main-run.mjs
|
|
6
|
+
*
|
|
7
|
+
* Two readers call it: the session start prints the line into the context, and the executor
|
|
8
|
+
* calls it after every known merge. The queue audit reads the same run and names the same two
|
|
9
|
+
* findings; this command exists because the audit waits to be called, while a merge made
|
|
10
|
+
* mid-session moves the main branch without anybody asking the audit.
|
|
11
|
+
*
|
|
12
|
+
* Silence here is never «green»: where the run could not be read — no pipeline file, a pipeline
|
|
13
|
+
* asleep on a push to the main branch, no network — the line says so. The exit code is 1 on a red
|
|
14
|
+
* or a pushed-out run and 0 in every other case, so that a chain after a merge stops on it.
|
|
15
|
+
*/
|
|
16
|
+
import { OfflineError, botToken } from './board.mjs';
|
|
17
|
+
import { HAS_PIPELINE, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
|
|
18
|
+
import { CONFIG } from './rt-kit-checks.config.mjs';
|
|
19
|
+
|
|
20
|
+
const MAIN_BRANCH = CONFIG.deploy?.mainBranch ?? 'main';
|
|
21
|
+
|
|
22
|
+
/** The line for one reading of the run; exported so the suite can read it without the hosting. */
|
|
23
|
+
export function mainRunLine(run, mainBranch = MAIN_BRANCH) {
|
|
24
|
+
const sha = String(run.sha ?? '').slice(0, 8);
|
|
25
|
+
const day = String(run.at ?? '').slice(0, 10);
|
|
26
|
+
switch (run.verdict) {
|
|
27
|
+
case 'none':
|
|
28
|
+
return `main-run: «${mainBranch}» has no run yet`;
|
|
29
|
+
case 'running':
|
|
30
|
+
return `main-run: «${mainBranch}» is being checked on ${sha} — ${run.url}`;
|
|
31
|
+
case 'success':
|
|
32
|
+
return `main-run: «${mainBranch}» is green on ${sha} of ${day}`;
|
|
33
|
+
case 'evicted':
|
|
34
|
+
return `main-run: the run of «${mainBranch}» on ${sha} was pushed out of the queue and never checked the merge — ${run.url}`;
|
|
35
|
+
default:
|
|
36
|
+
return `main-run: «${mainBranch}» is RED on ${sha} of ${day}: merges on top go out unchecked — ${run.url}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function main() {
|
|
41
|
+
if (!HAS_PIPELINE) {
|
|
42
|
+
console.log('main-run: the main branch run was not read — the tree has no pipeline file');
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
if (!pipelineWakesOnPush(pipelineText(), MAIN_BRANCH)) {
|
|
46
|
+
console.log(`main-run: the main branch run was not read — the pipeline does not wake on a push to «${MAIN_BRANCH}»`);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let run;
|
|
51
|
+
try {
|
|
52
|
+
run = lastMainRun(MAIN_BRANCH, { token: botToken() ?? undefined });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof OfflineError) {
|
|
55
|
+
console.log(`main-run: the main branch run was not read — ${error.message}`);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log(mainRunLine(run, MAIN_BRANCH));
|
|
62
|
+
return run.verdict === 'failure' || run.verdict === 'evicted' ? 1 : 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The suite imports the line without running the reading; the hosting is asked only when called.
|
|
66
|
+
const isEntryPoint = process.argv[1] && import.meta.url === `file://${process.argv[1]}`;
|
|
67
|
+
if (isEntryPoint) {
|
|
68
|
+
process.exit(main());
|
|
69
|
+
}
|
|
@@ -97,6 +97,21 @@ const DEFAULTS = {
|
|
|
97
97
|
* Empty — the tree has no such directory, and an epic is not created by the command.
|
|
98
98
|
*/
|
|
99
99
|
plansDir: '',
|
|
100
|
+
/**
|
|
101
|
+
* Where the assignment of an epic to a working copy is declared, and where a copy holds its own
|
|
102
|
+
* name.
|
|
103
|
+
*
|
|
104
|
+
* Two files, and they lie apart on purpose. The assignment belongs to the working copy and is
|
|
105
|
+
* declared in the main branch: written into the branch of a task, it is in force only there,
|
|
106
|
+
* and at the first branch switch the executor works by one order while the check reads another.
|
|
107
|
+
* The name of the copy is the state of the machine — the path to it belongs in nobody's
|
|
108
|
+
* history, so the copy names itself by a short word in a file outside the index.
|
|
109
|
+
*
|
|
110
|
+
* Empty — the tree declares no assignments, and nothing about them is judged: a tree with one
|
|
111
|
+
* working copy has nothing to divide.
|
|
112
|
+
*/
|
|
113
|
+
assignmentsFile: '',
|
|
114
|
+
treeNameFile: '.claude/rt-kit/tree-name',
|
|
100
115
|
/** Where the lists of accepted debts are put. */
|
|
101
116
|
allowlistDir: 'tools',
|
|
102
117
|
/**
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The epic assigned to this working copy.
|
|
3
|
+
*
|
|
4
|
+
* A machine holds several working copies of one tree, and a session in each of them asks the same
|
|
5
|
+
* question — which work is mine. The queue answers only what is open: it holds no owner of a card,
|
|
6
|
+
* and by topic one epic cannot be told from another. So the assignment is declared apart, and it
|
|
7
|
+
* is read from here by everyone who needs it — the startup hook, the delivery guard, the audit.
|
|
8
|
+
*
|
|
9
|
+
* Two files, and they lie apart. The assignment belongs to the working copy and is declared in the
|
|
10
|
+
* main branch — a record written into the branch of a task is in force only there. The name of the
|
|
11
|
+
* copy is the state of the machine: the path to it belongs in nobody's history, so the copy names
|
|
12
|
+
* itself by a short word in a file outside the index.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
|
|
17
|
+
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
18
|
+
|
|
19
|
+
/** The name this working copy calls itself by, or `null` where it names itself in no way. */
|
|
20
|
+
export function treeName(root = ROOT) {
|
|
21
|
+
const path = join(root, CONFIG.treeNameFile || '');
|
|
22
|
+
|
|
23
|
+
if (!CONFIG.treeNameFile || !existsSync(path)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const said = readFileSync(path, 'utf8').trim();
|
|
28
|
+
|
|
29
|
+
return said === '' ? null : said.split('\n')[0].trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The rows of the assignment table: the name of the copy, the epic, the plan of works and the day
|
|
34
|
+
* the assignment was given.
|
|
35
|
+
*
|
|
36
|
+
* The table is read by the shape of its row, not by the header: a header is translated, reordered
|
|
37
|
+
* and renamed, and every such edit would silently empty the answer. A row that does not hold a
|
|
38
|
+
* task key with a number is not an assignment — the heading row of the table and the line of dashes
|
|
39
|
+
* under it look exactly like a row to any reader that counts cells.
|
|
40
|
+
*
|
|
41
|
+
* A row whose epic cell holds a dash is a row all the same, and its epic is empty: «no work has
|
|
42
|
+
* been assigned to this copy» and «this copy is not in the table» are two different states, and
|
|
43
|
+
* whoever reads them needs to tell one from the other — the first is the owner's answer, the
|
|
44
|
+
* second is their silence.
|
|
45
|
+
*/
|
|
46
|
+
export function assignments(root = ROOT) {
|
|
47
|
+
const path = join(root, CONFIG.assignmentsFile || '');
|
|
48
|
+
|
|
49
|
+
if (!CONFIG.assignmentsFile || !existsSync(path)) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const key = CONFIG.board?.taskKey ?? '';
|
|
54
|
+
const epicRe = new RegExp(`^(?:#|${key}-)?(\\d+)$`);
|
|
55
|
+
const DASH = /^[-—–]$/;
|
|
56
|
+
|
|
57
|
+
return readFileSync(path, 'utf8')
|
|
58
|
+
.split('\n')
|
|
59
|
+
.filter((line) => line.trim().startsWith('|'))
|
|
60
|
+
.map((line) =>
|
|
61
|
+
line
|
|
62
|
+
.trim()
|
|
63
|
+
.replace(/^\||\|$/g, '')
|
|
64
|
+
.split('|')
|
|
65
|
+
.map((cell) => cell.trim().replace(/^`|`$/g, ''))
|
|
66
|
+
)
|
|
67
|
+
.filter((cells) => cells.length >= 2 && (epicRe.test(cells[1]) || DASH.test(cells[1])))
|
|
68
|
+
.map((cells) => ({
|
|
69
|
+
tree: cells[0],
|
|
70
|
+
epic: epicRe.test(cells[1]) ? Number(cells[1].match(epicRe)[1]) : null,
|
|
71
|
+
plan: cells[2] ?? '',
|
|
72
|
+
given: cells[3] ?? '',
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The assignment of this working copy, or `null` where the table names no such copy. */
|
|
77
|
+
export function assignmentOf(root = ROOT) {
|
|
78
|
+
const name = treeName(root);
|
|
79
|
+
|
|
80
|
+
return name === null ? null : (assignments(root).find((row) => row.tree === name) ?? null);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* What is wrong with taking work under this epic — or an empty string where nothing is.
|
|
85
|
+
*
|
|
86
|
+
* Three answers, and they are different states, not degrees of one: the table names no such copy,
|
|
87
|
+
* the copy has no epic assigned, the epic is someone else's. The first two are cured by the owner's
|
|
88
|
+
* word and by nothing else; the third names both epics, so that the executor sees what they took
|
|
89
|
+
* and what they were given.
|
|
90
|
+
*
|
|
91
|
+
* A tree that declares no assignments is not judged: it has nothing to divide.
|
|
92
|
+
*/
|
|
93
|
+
export function assignmentFault(epic, root = ROOT) {
|
|
94
|
+
if (!CONFIG.assignmentsFile) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const key = CONFIG.board?.taskKey ?? '';
|
|
99
|
+
const name = treeName(root);
|
|
100
|
+
|
|
101
|
+
if (name === null) {
|
|
102
|
+
return `this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}, and the assignment table will find its row`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const row = assignmentOf(root);
|
|
106
|
+
|
|
107
|
+
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`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
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`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
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`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Called by hand and by the startup hook: it says what this copy answers for. The word about the
|
|
124
|
+
* absence is printed just as loudly as the assignment itself — a copy without a row is exactly the
|
|
125
|
+
* case in which work gets taken by guesswork.
|
|
126
|
+
*/
|
|
127
|
+
if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) {
|
|
128
|
+
const assigned = process.argv.indexOf('--assigned');
|
|
129
|
+
|
|
130
|
+
if (assigned !== -1) {
|
|
131
|
+
// The number alone, for a caller that asks the queue about the state of that epic: the
|
|
132
|
+
// staleness of an assignment is not readable from the table — the table says what was
|
|
133
|
+
// given, the queue says whether it is still alive.
|
|
134
|
+
const row = assignmentOf();
|
|
135
|
+
|
|
136
|
+
console.log(row?.epic ?? '');
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const asked = process.argv.indexOf('--fault');
|
|
141
|
+
|
|
142
|
+
if (asked !== -1) {
|
|
143
|
+
// The refusal text alone, and an empty answer where nothing is wrong: the caller is a guard,
|
|
144
|
+
// and it prints what it got. The exit code stays zero — the refusal is the guard's to make.
|
|
145
|
+
console.log(assignmentFault(process.argv[asked + 1] ?? ''));
|
|
146
|
+
process.exit(0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const name = treeName();
|
|
150
|
+
const row = assignmentOf();
|
|
151
|
+
|
|
152
|
+
if (!CONFIG.assignmentsFile) {
|
|
153
|
+
console.log('tree-assignment: the tree declares no assignments — the key `assignmentsFile` is empty');
|
|
154
|
+
} else if (name === null) {
|
|
155
|
+
console.log(`tree-assignment: this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}`);
|
|
156
|
+
} else if (row === null) {
|
|
157
|
+
console.log(
|
|
158
|
+
`tree-assignment: «${name}» — the table ${CONFIG.assignmentsFile} holds no row for this copy. Ask the owner about it; work is not taken by guesswork`
|
|
159
|
+
);
|
|
160
|
+
} else if (row.epic === null) {
|
|
161
|
+
console.log(
|
|
162
|
+
`tree-assignment: «${name}» — no epic is assigned to this copy. Ask the owner about it; work is not taken by guesswork`
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
console.log(
|
|
166
|
+
`tree-assignment: «${name}» — epic ${CONFIG.board?.taskKey ?? ''}-${row.epic}, the plan of works ${row.plan}, given ${row.given}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# rt-hook: PreToolUse .*EndConversation.*
|
|
3
|
+
# Requires: hooks/deny-tail.sh
|
|
4
|
+
# The guard of the end of the conversation: the executor does not end the session. PreToolUse on
|
|
5
|
+
# the tool that closes the conversation — refused always.
|
|
6
|
+
#
|
|
7
|
+
# Why. The session is ended by the owner and by nobody else. On 17 September 2026 the executor
|
|
8
|
+
# closed the session by that tool with the work open and tasks assigned, and the owner named it
|
|
9
|
+
# unlawful. A ban in the settings of one machine holds one machine; this guard travels with the
|
|
10
|
+
# package. There is no lawful form of bypass: no state of the work, no word in the turn and no
|
|
11
|
+
# insult from the owner cancels it — a session that must close is closed by the owner.
|
|
12
|
+
#
|
|
13
|
+
# The name of the tool is read by jq, and without jq by grep over the raw input: a missing parser
|
|
14
|
+
# must not turn into silence here. A tool name with a vendor prefix is matched by its tail.
|
|
15
|
+
#
|
|
16
|
+
# FAIL-OPEN only where there is nothing to judge: an empty input or a name that is not the closing
|
|
17
|
+
# tool passes. A readable call of the closing tool is refused with or without a JSON parser.
|
|
18
|
+
|
|
19
|
+
# Its own name in the observations: the refusal is recorded by the shared deny tail.
|
|
20
|
+
RT_GUARD_NAME=end-conversation-guard
|
|
21
|
+
|
|
22
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
23
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
24
|
+
|
|
25
|
+
if command -v rt_hook_read >/dev/null 2>&1; then
|
|
26
|
+
rt_hook_read
|
|
27
|
+
input="$RT_HOOK_INPUT"
|
|
28
|
+
else
|
|
29
|
+
input="$(cat)"
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
tool="$(printf '%s' "$input" | jq -r '.tool_name // ""' 2>/dev/null)"
|
|
33
|
+
if [ -z "$tool" ] && printf '%s' "$input" | grep -q '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*EndConversation'; then
|
|
34
|
+
tool=EndConversation
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# Called by the dispatcher for the closing tool alone; a foreign name still passes, so a direct
|
|
38
|
+
# call with another tool costs nothing.
|
|
39
|
+
case "$tool" in
|
|
40
|
+
*EndConversation*) ;;
|
|
41
|
+
*) exit 0 ;;
|
|
42
|
+
esac
|
|
43
|
+
|
|
44
|
+
# shellcheck disable=SC1090
|
|
45
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
46
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
47
|
+
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
48
|
+
|
|
49
|
+
reason="BLOCKED by end-conversation-guard: the executor does not end the conversation. The session is ended by the owner and by nobody else.
|
|
50
|
+
|
|
51
|
+
An assignment stands until the owner cancels it, and an insult cancels nothing: do what was assigned, and where the work stands on the owner's word, wait for the word. A session that must close is closed by the owner — say so in words and go on working. There is no lawful form of bypass for this refusal."
|
|
52
|
+
tail_text="$(rt_deny_tail "")"
|
|
53
|
+
[ -n "$tail_text" ] && reason="${reason}
|
|
54
|
+
|
|
55
|
+
${tail_text}"
|
|
56
|
+
|
|
57
|
+
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
58
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"BLOCKED by end-conversation-guard: the session is ended by the owner and by nobody else."}}\n'
|
|
59
|
+
exit 0
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
# work, no epic behind the branch, no way to ask the hosting — is not zero, and the caller works as
|
|
17
17
|
# it did before this reading existed.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# The unfinished tasks of the epic as the table prints them. A non-zero code means the epic could
|
|
20
|
+
# not be read — no table, no epic behind the branch, no way to ask the hosting — and the caller
|
|
21
|
+
# tells that apart from an empty answer, which means the epic is over.
|
|
22
|
+
rt_epic_unfinished() {
|
|
20
23
|
command -v jq >/dev/null 2>&1 || return 1
|
|
21
24
|
command -v node >/dev/null 2>&1 || return 1
|
|
22
25
|
|
|
@@ -43,7 +46,13 @@ rt_epic_over() {
|
|
|
43
46
|
[ -f "$table" ] || return 1
|
|
44
47
|
|
|
45
48
|
left="$(cd "$root" && node "$table" --unfinished 2>/dev/null)" || return 1
|
|
46
|
-
|
|
49
|
+
printf '%s' "$left"
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
47
52
|
|
|
53
|
+
rt_epic_over() {
|
|
54
|
+
local left
|
|
55
|
+
left="$(rt_epic_unfinished)" || return 1
|
|
56
|
+
[ -n "$left" ] && return 1
|
|
48
57
|
return 0
|
|
49
58
|
}
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
#
|
|
11
11
|
# WHAT IS HERE. Two calls, both called from the delivery guard, where `fault`, `main_branch` and
|
|
12
12
|
# the profile calls are already declared. The helper reads neither the input nor the settings.
|
|
13
|
+
#
|
|
14
|
+
# The assignment of an epic to this working copy is read next to this: it judges the same subject
|
|
15
|
+
# one step earlier — whether this copy leads the epic at all — so its helper is sourced here. The
|
|
16
|
+
# guard calls it in the branch block before the base: a fresh base does not cure a branch of
|
|
17
|
+
# someone else's epic, and a refusal about the base would send the executor to fix what is in order.
|
|
18
|
+
# shellcheck disable=SC1090
|
|
19
|
+
[ -f "$rt_hooks_dir/git-guard-tree-assignment.sh" ] && . "$rt_hooks_dir/git-guard-tree-assignment.sh" 2>/dev/null
|
|
13
20
|
|
|
14
21
|
# The branch of an epic by its number: the same form as a task branch — the profile pulls the
|
|
15
22
|
# number out of a name, and the epic branch is the one whose number is the epic's.
|
|
@@ -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-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
|
|
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
|
|
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
|
|
@@ -274,6 +274,7 @@ if [ -n "$branch_arg" ]; then
|
|
|
274
274
|
# base fresh — `git checkout -b <branch> origin/<main>` — would be forbidden.
|
|
275
275
|
base_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]+[^[:space:];&|]+[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\4/p' | head -1)"
|
|
276
276
|
base_ref="${base_arg:-HEAD}"
|
|
277
|
+
command -v rt_assignment_fault >/dev/null 2>&1 && rt_assignment_fault "$epic_arg" "the branch «${branch_arg}»"
|
|
277
278
|
if [ -n "$epic_arg" ] && command -v rt_epic_base >/dev/null 2>&1; then
|
|
278
279
|
rt_epic_base "$epic_arg" "$base_ref" "$branch_arg"
|
|
279
280
|
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|