@rt-tools/agent-kit 0.37.0 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/checks/board-pull-state.github.mjs +82 -13
- package/assets/checks/board.github.mjs +1 -1
- package/assets/checks/check-board.github.mjs +20 -12
- package/assets/checks/check-specs.mjs +2 -2
- package/assets/checks/epic-table.github.mjs +4 -3
- package/assets/checks/lib-common.mjs +10 -2
- package/assets/checks/lib-domains.mjs +1 -1
- package/assets/checks/lib-manifests.mjs +34 -2
- package/assets/checks/push-inputs.mjs +401 -0
- package/assets/checks/push-trace.mjs +108 -0
- package/assets/checks/rt-kit-checks.config.mjs +17 -2
- package/assets/checks/spec-anchors.mjs +4 -4
- package/assets/checks/spec-contract.mjs +5 -5
- package/assets/commands/next-session.md +3 -1
- package/assets/commands/night.md +28 -18
- package/assets/defaults/project.sh +37 -8
- package/assets/defaults/push.sh +23 -0
- package/assets/defaults/turn-map.md +10 -6
- package/assets/docs/GLOSSARY.md +1 -1
- package/assets/hooks/epic-stop-guard.sh +62 -15
- package/assets/hooks/git-guard-push-ahead.sh +31 -1
- package/assets/hooks/git-guard-push-marks.sh +173 -29
- package/assets/hooks/git-guard-push-tests.sh +22 -3
- package/assets/hooks/handoff-entry-guard.sh +2 -2
- package/assets/hooks/pre-push.sh +6 -0
- package/assets/hooks/push-set.sh +29 -4
- package/assets/hooks/task-flow-context.sh +15 -4
- package/assets/hooks/task-flow-guard.sh +4 -3
- package/assets/hooks/turn-exit-epic.sh +1 -1
- package/assets/hooks/turn-exit-guard.sh +8 -8
- package/assets/hooks/turn-exit-role.sh +45 -0
- package/assets/laws/work-conduct.md +9 -8
- package/assets/patterns/autonomous-work-run.md +35 -10
- package/assets/patterns/browser-verification-measure.md +10 -20
- package/assets/patterns/browser-verification-stand.md +30 -42
- package/assets/patterns/doc-style-human.md +0 -6
- package/assets/patterns/doc-style-sweep.md +7 -7
- package/assets/patterns/doc-style-trace.md +5 -4
- package/assets/patterns/doc-style-write.md +7 -7
- package/assets/patterns/epic-flow-declare.md +15 -8
- package/assets/patterns/git-workflow-commit.github.md +1 -1
- package/assets/patterns/git-workflow-freshness.md +12 -11
- package/assets/patterns/git-workflow-merge.md +14 -11
- package/assets/patterns/git-workflow-migration.md +4 -2
- package/assets/patterns/git-workflow-pr-body.github.md +1 -1
- package/assets/patterns/git-workflow-pr-ready.md +5 -4
- package/assets/patterns/git-workflow-pr.azure.md +91 -25
- package/assets/patterns/git-workflow-pr.github.md +17 -19
- package/assets/patterns/git-workflow-pr.gitlab.md +75 -29
- package/assets/patterns/git-workflow-restart.md +3 -2
- package/assets/patterns/git-workflow-stack.md +25 -21
- package/assets/patterns/lib-layers-new.md +7 -3
- package/assets/patterns/queue-audit-read.github.md +9 -3
- package/assets/patterns/spec-driven-domain.md +50 -48
- package/assets/patterns/spec-driven-rule.md +18 -19
- package/assets/patterns/status-report-table.github.md +1 -1
- package/assets/patterns/task-flow-archive.md +14 -34
- package/assets/patterns/task-flow-close.md +3 -2
- package/assets/patterns/task-flow-graph.needs-graph.md +4 -0
- package/assets/patterns/task-flow-handoff.md +4 -4
- package/assets/patterns/task-flow-resume.md +56 -20
- package/assets/patterns/task-flow-start.md +3 -4
- package/assets/patterns/testing-e2e.md +14 -18
- package/assets/patterns/testing-unit.md +9 -13
- package/assets/patterns/turn-entry-map.md +13 -3
- package/assets/pitfalls/autonomous-work.md +15 -0
- package/assets/pitfalls/doc-style.md +3 -3
- package/assets/pitfalls/git-workflow.github.md +5 -9
- package/assets/pitfalls/spec-driven.md +9 -7
- package/assets/pitfalls/task-flow.md +14 -25
- package/assets/pitfalls/testing.md +11 -12
- package/assets/pitfalls/turn-conduct.md +6 -6
- package/assets/rules/autonomous-work.md +37 -29
- package/assets/rules/browser-verification.md +27 -22
- package/assets/rules/dependencies.md +3 -3
- package/assets/rules/deploy-flow.azure.md +35 -12
- package/assets/rules/deploy-flow.github.md +10 -6
- package/assets/rules/deploy-flow.gitlab.md +40 -17
- package/assets/rules/doc-style.md +21 -17
- package/assets/rules/epic-flow.md +5 -3
- package/assets/rules/git-workflow.azure.md +140 -122
- package/assets/rules/git-workflow.github.md +7 -8
- package/assets/rules/git-workflow.gitlab.md +128 -117
- package/assets/rules/queue-audit.github.md +5 -3
- package/assets/rules/spec-driven.md +17 -25
- package/assets/rules/status-report.md +5 -3
- package/assets/rules/task-flow.md +26 -15
- package/assets/rules/testing.md +35 -32
- package/assets/rules/turn-conduct.md +26 -24
- package/assets/templates/rule.md +2 -2
- package/lib/cargo-prose.d.ts +2 -1
- package/lib/cargo-prose.d.ts.map +1 -1
- package/lib/cargo-prose.js.map +1 -1
- package/lib/companion.d.ts +0 -5
- package/lib/companion.d.ts.map +1 -1
- package/lib/companion.js +1 -1
- package/lib/companion.js.map +1 -1
- package/lib/cost.d.ts +0 -8
- package/lib/cost.d.ts.map +1 -1
- package/lib/cost.js +4 -4
- package/lib/cost.js.map +1 -1
- package/lib/hooks-map.d.ts +0 -12
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +2 -25
- package/lib/hooks-map.js.map +1 -1
- package/lib/observations-cargo.d.ts +1 -5
- package/lib/observations-cargo.d.ts.map +1 -1
- package/lib/observations-cargo.js +2 -2
- package/lib/observations-cargo.js.map +1 -1
- package/lib/observations.d.ts +0 -2
- package/lib/observations.d.ts.map +1 -1
- package/lib/observations.js.map +1 -1
- package/lib/order.d.ts +0 -2
- package/lib/order.d.ts.map +1 -1
- package/lib/order.js +0 -4
- package/lib/order.js.map +1 -1
- package/lib/outcomes.d.ts +2 -7
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +3 -3
- package/lib/outcomes.js.map +1 -1
- package/lib/proposals.d.ts +0 -1
- package/lib/proposals.d.ts.map +1 -1
- package/lib/proposals.js +1 -1
- package/lib/proposals.js.map +1 -1
- package/lib/shipment.d.ts +2 -11
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +0 -3
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +3 -3
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +2 -2
- package/lib/shipment.js.map +1 -1
- package/lib/traits.d.ts +0 -3
- package/lib/traits.d.ts.map +1 -1
- package/lib/traits.js +2 -2
- package/lib/traits.js.map +1 -1
- package/lib/variants.d.ts +0 -1
- package/lib/variants.d.ts.map +1 -1
- package/lib/variants.js +1 -1
- package/lib/variants.js.map +1 -1
- package/package.json +1 -1
- package/assets/checks/signals/ui-kit.json +0 -11
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Which steps of the push set a change can reach. A step runs when the change touches what it
|
|
4
|
+
* reads; a step the change cannot reach is not started.
|
|
5
|
+
*
|
|
6
|
+
* node tools/push-inputs.mjs record the steps on stdin, or the profile set when stdin is
|
|
7
|
+
* empty: each runs once under `push-trace.mjs`, and the
|
|
8
|
+
* table of what it read is written
|
|
9
|
+
* node tools/push-inputs.mjs select <base> the steps on stdin; the ones to run go to stdout, a
|
|
10
|
+
* line per step with its reason to stderr
|
|
11
|
+
* node tools/push-inputs.mjs verify the table steps are recorded again; a read the table
|
|
12
|
+
* does not cover is a refusal
|
|
13
|
+
*
|
|
14
|
+
* What a step reads is taken from a record of its own calls, not from a list someone wrote: such a
|
|
15
|
+
* list checks itself and goes stale silently. The table is generated and is not edited by hand.
|
|
16
|
+
*
|
|
17
|
+
* A step runs when the change:
|
|
18
|
+
* - edits a file whose content it read, or a file with an extension it read inside a directory it
|
|
19
|
+
* walked;
|
|
20
|
+
* - adds, removes or renames a file inside a directory it walked, or a path whose existence it
|
|
21
|
+
* probed — an existence probe does not depend on what the file holds;
|
|
22
|
+
* - touches the step itself — its file and what that file imports.
|
|
23
|
+
* A step runs always when it reads the history (`git diff`, `git log` and the like): its answer
|
|
24
|
+
* changes without a change of the tree; when it starts a process of another kind, whose reads the
|
|
25
|
+
* recorder does not see; and when it is not in the table at all.
|
|
26
|
+
*
|
|
27
|
+
* FAIL-OPEN: no table, no base, a change list that cannot be read — every step runs, as before.
|
|
28
|
+
*/
|
|
29
|
+
import { spawnSync } from 'node:child_process';
|
|
30
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
31
|
+
import { tmpdir } from 'node:os';
|
|
32
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path';
|
|
33
|
+
import { fileURLToPath } from 'node:url';
|
|
34
|
+
|
|
35
|
+
const ROOT = process.cwd();
|
|
36
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
const TRACER = join(HERE, 'push-trace.mjs');
|
|
38
|
+
const TABLE_DEFAULT = '.claude/rt-kit/push-inputs.json';
|
|
39
|
+
// The agent's observations and their marks are written by the guards on every call, a refusal
|
|
40
|
+
// included: a step that walks the tree reads a new file each time, and the table never matches. A
|
|
41
|
+
// scenario run from a nested directory writes its own observations there, so they are left out at
|
|
42
|
+
// any depth.
|
|
43
|
+
const IGNORED =
|
|
44
|
+
/^(node_modules|\.git|dist|\.nx|\.angular|tmp|coverage)(\/|$)|\/node_modules\/|(^|\/)\.claude\/rt-kit\/observations(\/|$)/;
|
|
45
|
+
const TRACEABLE = /^(node\s+\S+\.m?js|pnpm run [\w:.-]+)(\s|$)/;
|
|
46
|
+
const HEAVY = /(^|\s)nx\s|docker |playwright|e2e|visual-gate|serve:/;
|
|
47
|
+
const LISTING = new Set(['ls-files', 'ls-tree', 'check-ignore', 'check-attr', 'status', 'config', 'hash-object', 'var']);
|
|
48
|
+
const VERIFY = /push-inputs\.mjs verify/;
|
|
49
|
+
|
|
50
|
+
const args = process.argv.slice(2);
|
|
51
|
+
const option = (name) => {
|
|
52
|
+
const at = args.indexOf(name);
|
|
53
|
+
return at >= 0 ? args[at + 1] : undefined;
|
|
54
|
+
};
|
|
55
|
+
const tablePath = resolve(ROOT, option('--table') ?? TABLE_DEFAULT);
|
|
56
|
+
|
|
57
|
+
const rel = (path) => relative(ROOT, path).split(sep).join('/');
|
|
58
|
+
const inside = (path) => {
|
|
59
|
+
const r = rel(path);
|
|
60
|
+
return r !== '' && !r.startsWith('..') && !IGNORED.test(r);
|
|
61
|
+
};
|
|
62
|
+
const extOf = (path) => extname(path) || basename(path);
|
|
63
|
+
const covers = (dir, path) => dir === '.' || path === dir || path.startsWith(`${dir}/`);
|
|
64
|
+
|
|
65
|
+
function readStdin() {
|
|
66
|
+
try {
|
|
67
|
+
return readFileSync(0, 'utf8');
|
|
68
|
+
} catch {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function stepsOf(text) {
|
|
74
|
+
return text.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function profileSteps() {
|
|
78
|
+
const profiles = ['.claude/rt-kit/defaults/project.sh', '.claude/rt-kit/project.sh'].filter((p) => existsSync(join(ROOT, p)));
|
|
79
|
+
const script = `${profiles.map((p) => `. "${p}"`).join('; ')}; rt_push_checks ''`;
|
|
80
|
+
const run = spawnSync('bash', ['-c', script], { cwd: ROOT, encoding: 'utf8' });
|
|
81
|
+
return stepsOf(run.stdout ?? '');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const traceable = (step) => TRACEABLE.test(step) && !HEAVY.test(step);
|
|
85
|
+
|
|
86
|
+
/** The step's own files: the script it starts and what that script imports, by relative paths. */
|
|
87
|
+
function selfOf(step) {
|
|
88
|
+
const own = new Set();
|
|
89
|
+
const script = step.match(/^node\s+(\S+\.m?js)/)?.[1];
|
|
90
|
+
if (script) {
|
|
91
|
+
const queue = [resolve(ROOT, script)];
|
|
92
|
+
while (queue.length) {
|
|
93
|
+
const file = queue.pop();
|
|
94
|
+
if (own.has(rel(file)) || !existsSync(file)) continue;
|
|
95
|
+
own.add(rel(file));
|
|
96
|
+
const text = readFileSync(file, 'utf8');
|
|
97
|
+
for (const m of text.matchAll(/(?:from\s+|import\s*\(\s*|import\s+|require\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g)) {
|
|
98
|
+
queue.push(resolve(dirname(file), m[1]));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (/^pnpm run /.test(step)) own.add('package.json');
|
|
103
|
+
return [...own].sort();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** What a started process means for the step: nothing, a read of the history, or an unseen read. */
|
|
107
|
+
function spawnKind(spawned) {
|
|
108
|
+
const command = Array.isArray(spawned) ? spawned : spawned.command;
|
|
109
|
+
const cwd = Array.isArray(spawned) ? ROOT : spawned.cwd || ROOT;
|
|
110
|
+
const shell = basename(String(command[0] ?? ''));
|
|
111
|
+
let [name, ...rest] = command;
|
|
112
|
+
if ((shell === 'sh' || shell === 'bash') && rest[0] === '-c') {
|
|
113
|
+
[name, ...rest] = String(rest[1] ?? '').trim().split(/\s+/);
|
|
114
|
+
}
|
|
115
|
+
const tool = basename(String(name ?? ''));
|
|
116
|
+
if (tool === 'node' || name === process.execPath) return 'traced';
|
|
117
|
+
if (tool !== 'git') return `untraced:${/^[\w.-]+$/.test(tool) && tool !== '.' ? tool : shell}`;
|
|
118
|
+
const words = [...rest];
|
|
119
|
+
let where = cwd;
|
|
120
|
+
while (words.length && words[0].startsWith('-')) {
|
|
121
|
+
const flag = words.shift();
|
|
122
|
+
if (flag === '-C') where = resolve(where, words.shift() ?? '');
|
|
123
|
+
else if (flag === '-c') words.shift();
|
|
124
|
+
}
|
|
125
|
+
// A scratch repository of the step is not this tree: its history is the step's own.
|
|
126
|
+
if (relative(ROOT, where).startsWith('..')) return 'traced';
|
|
127
|
+
const sub = words[0] ?? '';
|
|
128
|
+
if (LISTING.has(sub)) return 'listing';
|
|
129
|
+
if (sub === 'rev-parse' && words.slice(1).every((w) => /^--(show-toplevel|show-prefix|git-dir|git-common-dir|is-inside-work-tree|show-cdup)$/.test(w))) {
|
|
130
|
+
return 'traced';
|
|
131
|
+
}
|
|
132
|
+
return `history:git ${sub}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** One run of a step under the recorder: the raw reads, walks and process kinds. */
|
|
136
|
+
function trace(step) {
|
|
137
|
+
const out = mkdtempSync(join(tmpdir(), 'rt-push-trace-'));
|
|
138
|
+
const started = Date.now();
|
|
139
|
+
const run = spawnSync('bash', ['-c', step], {
|
|
140
|
+
cwd: ROOT,
|
|
141
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
142
|
+
env: {
|
|
143
|
+
...process.env,
|
|
144
|
+
NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --import ${TRACER}`.trim(),
|
|
145
|
+
RT_PUSH_TRACE_OUT: out,
|
|
146
|
+
NX_DAEMON: 'false',
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const seconds = Math.round((Date.now() - started) / 1000);
|
|
150
|
+
const reads = new Set();
|
|
151
|
+
const probes = new Set();
|
|
152
|
+
const walks = new Set();
|
|
153
|
+
const kinds = new Set();
|
|
154
|
+
for (const name of readdirSync(out)) {
|
|
155
|
+
const record = JSON.parse(readFileSync(join(out, name), 'utf8'));
|
|
156
|
+
for (const p of record.reads) if (inside(p)) reads.add(rel(p));
|
|
157
|
+
for (const p of record.probes ?? []) if (inside(p)) probes.add(rel(p));
|
|
158
|
+
for (const p of record.walks) {
|
|
159
|
+
if (resolve(p) === ROOT) walks.add('.');
|
|
160
|
+
else if (inside(p)) walks.add(rel(p));
|
|
161
|
+
}
|
|
162
|
+
for (const s of record.spawns) kinds.add(spawnKind(s));
|
|
163
|
+
}
|
|
164
|
+
rmSync(out, { recursive: true, force: true });
|
|
165
|
+
if (kinds.has('listing')) walks.add('.');
|
|
166
|
+
for (const set of [reads, probes, walks]) {
|
|
167
|
+
for (const p of outsideHistory([...set])) set.delete(p);
|
|
168
|
+
for (const p of [...set]) if (untracked(p)) set.delete(p);
|
|
169
|
+
}
|
|
170
|
+
return { seconds, exit: run.status ?? 1, reads, probes, walks, kinds, self: selfOf(step) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let untrackedList;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A file that lies in the copy and not in the history, and is not ignored either: a draft, a patch
|
|
177
|
+
* leftover. Like an ignored file it never reaches the change list of a branch, and whether it lies
|
|
178
|
+
* there is a state of the copy. Added to the history, it is an addition in a walked directory and
|
|
179
|
+
* starts the step anyway. Listed once per run: `--directory` names a whole untracked directory
|
|
180
|
+
* once, with a trailing slash.
|
|
181
|
+
*
|
|
182
|
+
* FAIL-OPEN: no git or a fallen call — nothing counts as untracked.
|
|
183
|
+
*/
|
|
184
|
+
function untracked(path) {
|
|
185
|
+
if (!untrackedList) {
|
|
186
|
+
const run = spawnSync('git', ['ls-files', '--others', '--exclude-standard', '--directory', '-z'], {
|
|
187
|
+
cwd: ROOT,
|
|
188
|
+
encoding: 'utf8',
|
|
189
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
190
|
+
});
|
|
191
|
+
untrackedList = run.status === 0 ? (run.stdout ?? '').split('\0').filter(Boolean) : [];
|
|
192
|
+
}
|
|
193
|
+
return untrackedList.some((u) => (u.endsWith('/') ? `${path}/`.startsWith(u) : path === u));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A step with a recorded process kind runs on every change: its reads choose nothing. */
|
|
197
|
+
function runsAlways(entry) {
|
|
198
|
+
return entry.history.length > 0 || entry.untraced.length > 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The paths the repository ignores. A change to such a file never reaches the change list of a
|
|
203
|
+
* branch, so it starts no step, and whether it exists is a state of the machine: a copy with `.env`
|
|
204
|
+
* and a copy without it would record two different tables of one and the same tree.
|
|
205
|
+
*
|
|
206
|
+
* Only the repository's own ignore rules count: a global ignore file differs from machine to
|
|
207
|
+
* machine, and a path it hides would split the table again. Paths go NUL-separated, so a name with
|
|
208
|
+
* a non-ASCII letter or a space is not quoted and is matched as written.
|
|
209
|
+
*
|
|
210
|
+
* FAIL-OPEN: no git — nothing counts as ignored, the table stays as strict as before. One path git
|
|
211
|
+
* refuses (beyond a symbolic link, outside the tree) fails the whole batch, so the paths are then
|
|
212
|
+
* asked one by one, and only the refused one stays in the table.
|
|
213
|
+
*/
|
|
214
|
+
function outsideHistory(paths) {
|
|
215
|
+
if (!paths.length) return [];
|
|
216
|
+
const ask = (list) =>
|
|
217
|
+
spawnSync('git', ['-c', 'core.excludesFile=/dev/null', 'check-ignore', '-z', '--stdin'], {
|
|
218
|
+
cwd: ROOT,
|
|
219
|
+
input: `${list.join('\0')}\0`,
|
|
220
|
+
encoding: 'utf8',
|
|
221
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
222
|
+
});
|
|
223
|
+
const ignored = (run) => (run.status === 0 ? (run.stdout ?? '').split('\0').filter(Boolean) : []);
|
|
224
|
+
const run = ask(paths);
|
|
225
|
+
if (run.status === 0 || run.status === 1) return ignored(run);
|
|
226
|
+
if (run.error || paths.length === 1) return [];
|
|
227
|
+
return paths.flatMap((p) => ignored(ask([p])));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The table entry: only the topmost walked directories, each with the extensions read under it. */
|
|
231
|
+
function entryOf(raw) {
|
|
232
|
+
const dirs = [...raw.walks].sort();
|
|
233
|
+
const top = dirs.filter((d) => !dirs.some((o) => o !== d && covers(o, d)));
|
|
234
|
+
const all = [...raw.reads, ...raw.self];
|
|
235
|
+
const walks = top.map((dir) => ({ dir, exts: [...new Set(all.filter((p) => covers(dir, p)).map(extOf))].sort() }));
|
|
236
|
+
const files = [...raw.reads].filter((p) => !walks.some((w) => covers(w.dir, p) && w.exts.includes(extOf(p)))).sort();
|
|
237
|
+
const probes = [...raw.probes].filter((p) => !raw.reads.has(p) && !raw.self.includes(p) && !walks.some((w) => covers(w.dir, p))).sort();
|
|
238
|
+
const kinds = [...raw.kinds];
|
|
239
|
+
return {
|
|
240
|
+
seconds: raw.seconds,
|
|
241
|
+
history: kinds.filter((k) => k.startsWith('history:')).map((k) => k.slice(8)).sort(),
|
|
242
|
+
untraced: kinds.filter((k) => k.startsWith('untraced:')).map((k) => k.slice(9)).sort(),
|
|
243
|
+
self: raw.self,
|
|
244
|
+
walks,
|
|
245
|
+
files,
|
|
246
|
+
probes,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function loadTable() {
|
|
251
|
+
try {
|
|
252
|
+
return JSON.parse(readFileSync(tablePath, 'utf8'));
|
|
253
|
+
} catch {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Why a change reaches a step; an empty answer — it does not. */
|
|
259
|
+
function reasonOf(entry, changes) {
|
|
260
|
+
if (entry.history.length) return `reads the history (${entry.history.join(', ')})`;
|
|
261
|
+
if (entry.untraced.length) return `starts ${entry.untraced.join(', ')}, whose reads are not seen`;
|
|
262
|
+
for (const { kind, path } of changes) {
|
|
263
|
+
if (entry.self.includes(path)) return `${path} is the step itself`;
|
|
264
|
+
if (entry.files.includes(path)) return `${path} is read by it`;
|
|
265
|
+
const ext = extOf(path);
|
|
266
|
+
if (kind === 'M' && entry.walks.some((w) => covers(w.dir, path) && w.exts.includes(ext))) return `${path} lies where it reads ${ext}`;
|
|
267
|
+
if (kind !== 'M' && entry.walks.some((w) => covers(w.dir, path))) return `${path} is ${kind === 'A' ? 'added to' : 'removed from'} a directory it walks`;
|
|
268
|
+
if (kind !== 'M' && (entry.probes ?? []).some((f) => covers(f, path))) return `${path} is ${kind === 'A' ? 'added at' : 'removed from'} a path it probes`;
|
|
269
|
+
}
|
|
270
|
+
return '';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function changesOf(base) {
|
|
274
|
+
const file = option('--changes');
|
|
275
|
+
const text = file
|
|
276
|
+
? readFileSync(file, 'utf8')
|
|
277
|
+
: spawnSync('git', ['diff', '--name-status', '-M', `${base}...HEAD`], { cwd: ROOT, encoding: 'utf8' }).stdout;
|
|
278
|
+
if (text == null) return null;
|
|
279
|
+
const changes = [];
|
|
280
|
+
for (const line of text.split('\n').filter(Boolean)) {
|
|
281
|
+
const [status, a, b] = line.split('\t');
|
|
282
|
+
if (status.startsWith('R') || status.startsWith('C')) {
|
|
283
|
+
if (status.startsWith('R')) changes.push({ kind: 'D', path: a });
|
|
284
|
+
changes.push({ kind: 'A', path: b });
|
|
285
|
+
} else {
|
|
286
|
+
changes.push({ kind: status === 'A' || status === 'D' ? status : 'M', path: a });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return changes;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function select(base) {
|
|
293
|
+
const steps = stepsOf(readStdin());
|
|
294
|
+
const table = loadTable();
|
|
295
|
+
const changes = base ? changesOf(base) : null;
|
|
296
|
+
if (!table || !changes) {
|
|
297
|
+
process.stdout.write(steps.map((s) => `${s}\n`).join(''));
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
const verifyInputs = new Set([rel(tablePath), rel(TRACER), rel(fileURLToPath(import.meta.url))]);
|
|
301
|
+
// A step with a recorded kind is not traced by the check, so an edit of its script starts no check.
|
|
302
|
+
for (const entry of Object.values(table.steps)) {
|
|
303
|
+
if (!runsAlways(entry)) for (const p of entry.self) verifyInputs.add(p);
|
|
304
|
+
}
|
|
305
|
+
for (const step of steps) {
|
|
306
|
+
let reason;
|
|
307
|
+
if (VERIFY.test(step)) {
|
|
308
|
+
const hit = changes.find((c) => verifyInputs.has(c.path));
|
|
309
|
+
reason = hit ? `${hit.path} is a step or the table` : '';
|
|
310
|
+
} else if (!table.steps[step]) {
|
|
311
|
+
reason = traceable(step) ? 'it is not in the table' : 'its reads are not recorded';
|
|
312
|
+
} else {
|
|
313
|
+
reason = reasonOf(table.steps[step], changes);
|
|
314
|
+
}
|
|
315
|
+
if (reason) {
|
|
316
|
+
process.stdout.write(`${step}\n`);
|
|
317
|
+
process.stderr.write(`→ ${step}: ${reason}\n`);
|
|
318
|
+
} else {
|
|
319
|
+
process.stderr.write(`· not run: ${step} — the change touches nothing it reads\n`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return 0;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function write(table) {
|
|
326
|
+
writeFileSync(tablePath, `${JSON.stringify(table, null, 4)}\n`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The kinds of processes a step was seen to start stay in its entry. Whether a step starts one may
|
|
331
|
+
* hang on the machine — a database address in `.env`, a tool on the path — and a table that dropped
|
|
332
|
+
* the kind on the next machine refused the push of the machine after it. Kept, a kind errs towards
|
|
333
|
+
* an extra run of the step, never towards a skipped one.
|
|
334
|
+
*/
|
|
335
|
+
function keepKinds(entry, old) {
|
|
336
|
+
if (!old) return entry;
|
|
337
|
+
const union = (a, b) => [...new Set([...a, ...(b ?? [])])].sort();
|
|
338
|
+
return { ...entry, history: union(entry.history, old.history), untraced: union(entry.untraced, old.untraced) };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function record() {
|
|
342
|
+
let steps = stepsOf(readStdin());
|
|
343
|
+
if (!steps.length) steps = profileSteps();
|
|
344
|
+
const before = loadTable()?.steps ?? {};
|
|
345
|
+
const table = { note: 'Generated by `node tools/push-inputs.mjs record`; not edited by hand.', steps: {} };
|
|
346
|
+
for (const step of steps.filter(traceable)) {
|
|
347
|
+
if (VERIFY.test(step)) continue;
|
|
348
|
+
table.steps[step] = keepKinds(entryOf(trace(step)), before[step]);
|
|
349
|
+
process.stderr.write(`recorded in ${table.steps[step].seconds}s: ${step}\n`);
|
|
350
|
+
}
|
|
351
|
+
write(table);
|
|
352
|
+
process.stderr.write(`push inputs: ${Object.keys(table.steps).length} steps written to ${rel(tablePath)}\n`);
|
|
353
|
+
return 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function verify() {
|
|
357
|
+
const table = loadTable();
|
|
358
|
+
if (!table) return 0;
|
|
359
|
+
const misses = [];
|
|
360
|
+
let always = 0;
|
|
361
|
+
for (const [step, entry] of Object.entries(table.steps)) {
|
|
362
|
+
// A step with a recorded kind runs on every change already: a new kind changes no selection,
|
|
363
|
+
// and a refusal over it would only name the machine — a platform suffix, a tool on the path.
|
|
364
|
+
if (runsAlways(entry)) {
|
|
365
|
+
always += 1;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const raw = trace(step);
|
|
369
|
+
const now = entryOf(raw);
|
|
370
|
+
for (const h of now.history) misses.push(`${step}: now reads the history (${h})`);
|
|
371
|
+
for (const u of now.untraced) misses.push(`${step}: now starts ${u}`);
|
|
372
|
+
if (now.history.length || now.untraced.length) continue;
|
|
373
|
+
for (const p of [...raw.reads, ...raw.self]) {
|
|
374
|
+
if (!reasonOf(entry, [{ kind: 'M', path: p }])) misses.push(`${step}: reads ${p}`);
|
|
375
|
+
}
|
|
376
|
+
for (const p of raw.probes) {
|
|
377
|
+
if (!reasonOf(entry, [{ kind: 'A', path: p }])) misses.push(`${step}: probes ${p}`);
|
|
378
|
+
}
|
|
379
|
+
for (const d of raw.walks) {
|
|
380
|
+
if (!entry.walks.some((w) => covers(w.dir, d))) misses.push(`${step}: walks ${d}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!misses.length) {
|
|
384
|
+
const total = Object.keys(table.steps).length;
|
|
385
|
+
process.stdout.write(
|
|
386
|
+
`push inputs: the table covers what ${total - always} traced steps read; ${always} run on every change and are not traced\n`,
|
|
387
|
+
);
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
process.stdout.write(
|
|
391
|
+
`push inputs: the table does not cover what the steps read now — a change there would not start them.\n` +
|
|
392
|
+
`${misses.map((m) => ` ${m}`).join('\n')}\n` +
|
|
393
|
+
`Record the table again: node tools/push-inputs.mjs record\n`,
|
|
394
|
+
);
|
|
395
|
+
return 1;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const command = args[0];
|
|
399
|
+
const code = command === 'record' ? record() : command === 'verify' ? verify() : command === 'select' ? select(args[1]) : 2;
|
|
400
|
+
if (code === 2) process.stderr.write('usage: push-inputs.mjs record | select <base> | verify\n');
|
|
401
|
+
process.exit(code);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The read recorder of a push set step. It is loaded into a step by `--import` and writes down what
|
|
4
|
+
* the step really reads: every file whose content it opens, every path whose existence it probes,
|
|
5
|
+
* every directory it walks and every process it starts. The step itself is not changed.
|
|
6
|
+
*
|
|
7
|
+
* The record is the input of `push-inputs.mjs`: from it the set learns which steps a change can
|
|
8
|
+
* reach. A list of inputs written by hand checks itself and goes stale silently; a record taken
|
|
9
|
+
* from the step's own calls does not depend on whoever writes the list.
|
|
10
|
+
*
|
|
11
|
+
* A child `node` inherits `NODE_OPTIONS` and is recorded into a file of its own. A process of
|
|
12
|
+
* another kind is only named: its reads are not seen, and the step that starts it runs always.
|
|
13
|
+
*
|
|
14
|
+
* FAIL-OPEN: without `RT_PUSH_TRACE_OUT` the module does nothing; an error of its own is swallowed,
|
|
15
|
+
* so the step runs as it would without it.
|
|
16
|
+
*/
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import cp from 'node:child_process';
|
|
19
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
20
|
+
import { join, resolve } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const OUT = process.env.RT_PUSH_TRACE_OUT ?? '';
|
|
24
|
+
|
|
25
|
+
if (OUT) {
|
|
26
|
+
const reads = new Set();
|
|
27
|
+
const probes = new Set();
|
|
28
|
+
const walks = new Set();
|
|
29
|
+
const spawns = [];
|
|
30
|
+
const writeFile = fs.writeFileSync;
|
|
31
|
+
const mkdir = fs.mkdirSync;
|
|
32
|
+
|
|
33
|
+
const pathOf = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
if (typeof value === 'string') return resolve(value);
|
|
36
|
+
if (value instanceof URL) return fileURLToPath(value);
|
|
37
|
+
if (Buffer.isBuffer(value)) return resolve(value.toString());
|
|
38
|
+
} catch {
|
|
39
|
+
// An argument that is no path is not recorded.
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
};
|
|
43
|
+
const writing = (flags) => typeof flags === 'string' && /[wa+]/.test(flags);
|
|
44
|
+
|
|
45
|
+
const wrap = (target, name, note) => {
|
|
46
|
+
const original = target[name];
|
|
47
|
+
if (typeof original !== 'function') return;
|
|
48
|
+
target[name] = function traced(...args) {
|
|
49
|
+
try {
|
|
50
|
+
note(args);
|
|
51
|
+
} catch {
|
|
52
|
+
// The recorder never breaks the step.
|
|
53
|
+
}
|
|
54
|
+
return original.apply(this, args);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const read = (args) => {
|
|
58
|
+
const path = pathOf(args[0]);
|
|
59
|
+
if (path) reads.add(path);
|
|
60
|
+
};
|
|
61
|
+
const probe = (args) => {
|
|
62
|
+
const path = pathOf(args[0]);
|
|
63
|
+
if (path) probes.add(path);
|
|
64
|
+
};
|
|
65
|
+
const open = (args) => {
|
|
66
|
+
if (!writing(typeof args[1] === 'object' ? args[1]?.flags : args[1])) read(args);
|
|
67
|
+
};
|
|
68
|
+
const walk = (args) => {
|
|
69
|
+
const path = pathOf(args[0]);
|
|
70
|
+
if (path) walks.add(path);
|
|
71
|
+
};
|
|
72
|
+
// The directory a process starts in is kept: `git` in a scratch repository of the step does not
|
|
73
|
+
// read this tree's history.
|
|
74
|
+
const spawn = (args) => {
|
|
75
|
+
const [command, rest, options] = args;
|
|
76
|
+
if (typeof command !== 'string') return;
|
|
77
|
+
const list = Array.isArray(rest) ? rest.map(String) : [];
|
|
78
|
+
const where = (Array.isArray(rest) ? options : rest)?.cwd;
|
|
79
|
+
spawns.push({ cwd: pathOf(where ?? process.cwd()), command: [command, ...list] });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
for (const name of ['readFileSync', 'readFile', 'createReadStream']) wrap(fs, name, read);
|
|
83
|
+
for (const name of ['existsSync', 'statSync', 'lstatSync', 'accessSync', 'stat', 'lstat', 'access']) wrap(fs, name, probe);
|
|
84
|
+
wrap(fs, 'openSync', open);
|
|
85
|
+
wrap(fs, 'open', open);
|
|
86
|
+
for (const name of ['readdirSync', 'readdir', 'opendirSync', 'opendir']) wrap(fs, name, walk);
|
|
87
|
+
wrap(fs.promises, 'readFile', read);
|
|
88
|
+
for (const name of ['stat', 'lstat', 'access']) wrap(fs.promises, name, probe);
|
|
89
|
+
wrap(fs.promises, 'open', open);
|
|
90
|
+
for (const name of ['readdir', 'opendir']) wrap(fs.promises, name, walk);
|
|
91
|
+
for (const name of ['execFileSync', 'execFile', 'spawnSync', 'spawn']) wrap(cp, name, spawn);
|
|
92
|
+
for (const name of ['execSync', 'exec']) {
|
|
93
|
+
wrap(cp, name, (args) => typeof args[0] === 'string' && spawns.push({ cwd: pathOf(args[1]?.cwd ?? process.cwd()), command: ['sh', '-c', args[0]] }));
|
|
94
|
+
}
|
|
95
|
+
syncBuiltinESMExports();
|
|
96
|
+
|
|
97
|
+
process.on('exit', () => {
|
|
98
|
+
try {
|
|
99
|
+
mkdir(OUT, { recursive: true });
|
|
100
|
+
writeFile(
|
|
101
|
+
join(OUT, `${process.pid}.json`),
|
|
102
|
+
JSON.stringify({ cwd: process.cwd(), argv: process.argv.slice(1), reads: [...reads], probes: [...probes], walks: [...walks], spawns }),
|
|
103
|
+
);
|
|
104
|
+
} catch {
|
|
105
|
+
// A record that could not be written leaves the step without inputs: it runs always.
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -46,8 +46,23 @@ const DEFAULTS = {
|
|
|
46
46
|
* while the width stood at six.
|
|
47
47
|
*/
|
|
48
48
|
scenarioPrefixWidth: [2, 10],
|
|
49
|
-
/**
|
|
50
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Where never to go: the build, the dependencies, the generated. `graphify-out` is the code graph
|
|
51
|
+
* of a tree with the trait `graph`: it lies inside a project and a lib root, and a walk that went
|
|
52
|
+
* in read its page as markup and its cache as a lib without layers.
|
|
53
|
+
*/
|
|
54
|
+
skippedDirs: [
|
|
55
|
+
'node_modules',
|
|
56
|
+
'dist',
|
|
57
|
+
'.git',
|
|
58
|
+
'.nx',
|
|
59
|
+
'tmp',
|
|
60
|
+
'coverage',
|
|
61
|
+
'worktrees',
|
|
62
|
+
'gen',
|
|
63
|
+
'generated',
|
|
64
|
+
'graphify-out',
|
|
65
|
+
],
|
|
51
66
|
/** Where the project texts lie. */
|
|
52
67
|
docsDir: 'docs',
|
|
53
68
|
/** What is set aside: the checks stay silent about it — it describes the past, not the tree. */
|
|
@@ -172,7 +172,7 @@ function checkRuleImplementation(specFile, text, mapFile, heading = ['## Rules',
|
|
|
172
172
|
report(
|
|
173
173
|
mapFile,
|
|
174
174
|
`a statement without a binding: «${head.slice(0, 60)}…» — add a line with \`file:symbol\`, ` +
|
|
175
|
-
'a verdict «Not carried out» with a reason, or move the statement into «Open questions
|
|
175
|
+
'a verdict «Not carried out» with a reason, or move the statement into «Open questions»: Q-<law letters>-<number> in a law, Q-<number> in a spec'
|
|
176
176
|
);
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
@@ -348,9 +348,9 @@ function checkTracedAnchors() {
|
|
|
348
348
|
mapFile,
|
|
349
349
|
others.length > elsewhere
|
|
350
350
|
? `the binding leads into code called by a test alone: \`${symbol}\` is declared in \`${path}\` and outside tests is met nowhere — ` +
|
|
351
|
-
'a test is not a call from the application; either the statement is carried out elsewhere, or its place is in «Open questions
|
|
351
|
+
'a test is not a call from the application; either the statement is carried out elsewhere, or its place is in «Open questions»: Q-<law letters>-<number> in a law, Q-<number> in a spec'
|
|
352
352
|
: `the binding leads into dead code: \`${symbol}\` is declared in \`${path}\` and met nowhere else — ` +
|
|
353
|
-
'either the statement is carried out elsewhere, or its place is in «Open questions
|
|
353
|
+
'either the statement is carried out elsewhere, or its place is in «Open questions»: Q-<law letters>-<number> in a law, Q-<number> in a spec'
|
|
354
354
|
);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
@@ -364,7 +364,7 @@ function checkTracedAnchors() {
|
|
|
364
364
|
* dependencies line and in the middle of the text, and from a law there was no way to learn
|
|
365
365
|
* which domains stand on it — only by grep.
|
|
366
366
|
*
|
|
367
|
-
* Hence the
|
|
367
|
+
* Hence the `**Laws:**` line in the header and an audit of both sides: a law named in the
|
|
368
368
|
* text but not declared, and a declared law that does not exist.
|
|
369
369
|
*/
|
|
370
370
|
const SPEC_LAWS = /^\*\*(?:Laws|Законы):\*\*\s*(.+)$/;
|
|
@@ -102,12 +102,12 @@ function contractRows(text) {
|
|
|
102
102
|
|
|
103
103
|
function checkContract(file, text, roots) {
|
|
104
104
|
if (roots === null) {
|
|
105
|
-
report(file, 'the header carries no line
|
|
105
|
+
report(file, 'the header carries no line `**Procedures:**` — there is nothing to check the table of «Contract» against the decorators with');
|
|
106
106
|
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
if (roots === UNPARSED) {
|
|
110
|
-
report(file, 'the line
|
|
110
|
+
report(file, 'the line `**Procedures:**` names no root in backticks: the roots are written as paths, and the absence of procedures is said by the word «none». As it stands, the table of «Contract» is checked against nothing');
|
|
111
111
|
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -118,7 +118,7 @@ function checkContract(file, text, roots) {
|
|
|
118
118
|
for (const row of rows) {
|
|
119
119
|
const found = declared.get(row.short.toLowerCase());
|
|
120
120
|
if (!found) {
|
|
121
|
-
report(file,
|
|
121
|
+
report(file, `«Contract» carries \`${row.name}\`, and there is no procedure with such a method in ${roots.join(', ')}`);
|
|
122
122
|
continue;
|
|
123
123
|
}
|
|
124
124
|
described.add(row.short.toLowerCase());
|
|
@@ -134,7 +134,7 @@ function checkContract(file, text, roots) {
|
|
|
134
134
|
if (!described.has(key)) {
|
|
135
135
|
report(
|
|
136
136
|
file,
|
|
137
|
-
`the procedure \`${found.service}.${found.method}\` (${found.file}) belongs to the domain, ` + 'and the table of
|
|
137
|
+
`the procedure \`${found.service}.${found.method}\` (${found.file}) belongs to the domain, ` + 'and the table of «Contract» does not carry it'
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -175,7 +175,7 @@ function checkRefusalCodes(file, text, roots) {
|
|
|
175
175
|
for (const bullet of bullets) {
|
|
176
176
|
const code = (bullet.text.match(/`([A-Za-z]\w*)`/) || [])[1];
|
|
177
177
|
if (!code) {
|
|
178
|
-
report(file,
|
|
178
|
+
report(file, `«Refusal codes» carries a line without a code in backticks: «${bullet.text.slice(0, 60)}…»`);
|
|
179
179
|
continue;
|
|
180
180
|
}
|
|
181
181
|
if (!thrown.has(code)) {
|
|
@@ -128,7 +128,9 @@ its own, without retelling.
|
|
|
128
128
|
|
|
129
129
|
## 7. Hand over the result
|
|
130
130
|
|
|
131
|
-
The last line — the path to the handover
|
|
131
|
+
The last line — the path to the handover. The entry hook serves the file to the next session on the
|
|
132
|
+
same branch only while the progress holds no handover section; once it holds one, the hook prints
|
|
133
|
+
the section, and the owner pastes the file path if the file is needed.
|
|
132
134
|
Before it: what became of the main branch, which branches were removed, which stayed unmerged.
|
|
133
135
|
Do not retell the handover content — the owner will read it anyway.
|
|
134
136
|
|