slicekit 0.3.3 → 0.5.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/README.md +20 -9
- package/package.json +1 -1
- package/src/audit.js +234 -0
- package/src/check/rules/sync-release.js +17 -5
- package/src/cli/audit.js +91 -0
- package/src/cli/branch.js +189 -28
- package/src/cli/index.js +76 -0
- package/src/cli/ops.js +78 -0
- package/src/cli/update.js +4 -0
- package/src/config.js +80 -5
- package/src/hooks/subagent-start.js +7 -3
- package/src/init.js +19 -0
- package/src/ops.js +223 -0
- package/src/paths.js +1 -0
- package/src/release-version.js +90 -10
- package/src/reports.js +131 -0
- package/src/state/sync.js +4 -3
- package/templates/claude-code/agents/ops.md +3 -3
- package/templates/instructions/agents/auditor.md +13 -2
- package/templates/instructions/agents/ops.md +30 -9
- package/templates/instructions/commands/audit.md +40 -0
- package/templates/instructions/commands/ops.md +38 -0
- package/templates/instructions/commands/release.md +9 -4
package/README.md
CHANGED
|
@@ -7,16 +7,22 @@ agent finishes a turn and again in CI, not because anyone remembers to update it
|
|
|
7
7
|
|
|
8
8
|
## Status: preview
|
|
9
9
|
|
|
10
|
-
Phases 1 to
|
|
10
|
+
Phases 1 to 5 work. Phases 1 and 2 are intake, specify, the gap scan, plan, the build from red
|
|
11
11
|
tests to green, the review loop, the independent review and `/slicekit build --parallel`. Phase 3
|
|
12
12
|
is the traceability graph (`graph`), its queries (`trace`, `impact`, `history`, `uncovered` and
|
|
13
13
|
`shipped`), its views (`visualize`), and workspaces that let the graph span several repositories;
|
|
14
|
-
a slice is still built in one repository. Phase 4
|
|
15
|
-
|
|
14
|
+
a slice is still built in one repository. Phase 4 is hardening: `check` reads the git host's rules
|
|
15
|
+
on the default branch and `init --protect` sets the missing ones, the guards refuse what they
|
|
16
|
+
cannot judge, commits to the session journal must be signed, the state change after a merge goes
|
|
17
|
+
up as a pull request, and declined should-haves can go to Jira. Phase 5 is `release` (the release
|
|
18
|
+
record of a phase), `ops` (the triage of a symptom), `audit` (the claims of the spec and the
|
|
19
|
+
runbook against the code), observability steps in CI, and two more examples, `examples/fullstack`
|
|
20
|
+
and `examples/data`. [CHANGELOG.md](https://github.com/adityapandya1/agentic-slicekit/blob/main/CHANGELOG.md) lists what each
|
|
16
21
|
version changed.
|
|
17
22
|
|
|
18
|
-
The kit is on npm as a preview from 0.1.1.
|
|
19
|
-
|
|
23
|
+
The kit is on npm as a preview from 0.1.1. Versions from 0.3.0 are published from CI, each with a
|
|
24
|
+
provenance attestation; the versions before it carry none. It needs Node 22 or later and git, and
|
|
25
|
+
it has no dependencies of its own. In your project:
|
|
20
26
|
|
|
21
27
|
```sh
|
|
22
28
|
npm install --save-dev slicekit
|
|
@@ -27,10 +33,6 @@ Each change to the kit ships as the next 0.x version, and a 0.x version may chan
|
|
|
27
33
|
works. After an upgrade, `npx slicekit update` shows what would change in each of the kit's files,
|
|
28
34
|
and `npx slicekit update --yes` writes the changes.
|
|
29
35
|
|
|
30
|
-
The [user guide](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/guide/README.md)
|
|
31
|
-
explains the stages and the slash commands, and gives every command's syntax, options, exit codes
|
|
32
|
-
and an example.
|
|
33
|
-
|
|
34
36
|
The walkthrough below runs from a clone instead, because it copies files only the repository
|
|
35
37
|
holds (`examples/backend` and `examples/walkthrough`):
|
|
36
38
|
|
|
@@ -245,6 +247,15 @@ pip install graphifyy && graphify install
|
|
|
245
247
|
|
|
246
248
|
Then one Claude Code session runs both: `/graphify .` for the code graph, then `/slicekit build`.
|
|
247
249
|
|
|
250
|
+
## User guide
|
|
251
|
+
|
|
252
|
+
The [user guide](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/guide/README.md)
|
|
253
|
+
explains the stages and has a page for every `slicekit` command, every `/slicekit` slash command
|
|
254
|
+
and every check rule. A command's page gives its usage, what it reads and writes, its exit codes
|
|
255
|
+
and an example. A check rule's page says what fails and the failure the rule prevents.
|
|
256
|
+
[docs/adapters.md](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/adapters.md)
|
|
257
|
+
describes the contracts for anyone adding a git host, a tracker or an agent tool.
|
|
258
|
+
|
|
248
259
|
## How the hooks find slicekit
|
|
249
260
|
|
|
250
261
|
`slicekit init` writes the hook command as `node node_modules/slicekit/bin/slicekit.js` when the
|
package/package.json
CHANGED
package/src/audit.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// `slicekit audit` (REQ-2.14, D-58): the claims `/slicekit audit` hands the auditor, each with the
|
|
2
|
+
// files it names and the commits that could have broken it, and the check of the auditor's report.
|
|
3
|
+
// It reads the spec, the runbook, graph.json and git's history; it changes no tracked file.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { readText } from './fs.js';
|
|
7
|
+
import { GitError, git } from './git.js';
|
|
8
|
+
import { slug } from './graph/docs.js';
|
|
9
|
+
import { indexGraph, loadGraph, normalisePath } from './graph/load.js';
|
|
10
|
+
import { GraphError, cmp, keyOf } from './graph/schema.js';
|
|
11
|
+
import { headings, lines, prose } from './markdown.js';
|
|
12
|
+
import { kitPaths } from './paths.js';
|
|
13
|
+
import { footerProblems, lineExists, nextReport, reportSections, sectionTable } from './reports.js';
|
|
14
|
+
import { reqBlocks } from './stage.js';
|
|
15
|
+
|
|
16
|
+
export const STATUSES = ['holds', 'drifted', 'unverifiable'];
|
|
17
|
+
export const COLUMNS = ['Claim', 'Where', 'Evidence', 'Found at', 'Status', 'Commit'];
|
|
18
|
+
|
|
19
|
+
const posix = (p) => p.split(path.sep).join('/');
|
|
20
|
+
const CODE_SPAN = /`([^`\n]+)`/g;
|
|
21
|
+
const LINK = /\[[^\]]*\]\(\s*<?((?:[^()\s<>]|\([^()\s]*\))+)>?(?:\s+(?:"[^"]*"|'[^']*'))?\s*\)/g;
|
|
22
|
+
|
|
23
|
+
// The file paths of the graph and every directory that holds one.
|
|
24
|
+
function graphPaths(index) {
|
|
25
|
+
const files = new Set(index.byKind('file').map((n) => keyOf(n.id)));
|
|
26
|
+
const dirs = new Set();
|
|
27
|
+
for (const f of files) {
|
|
28
|
+
const parts = f.split('/');
|
|
29
|
+
for (let i = 1; i < parts.length; i++) dirs.add(parts.slice(0, i).join('/'));
|
|
30
|
+
}
|
|
31
|
+
return { files, dirs };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The paths a claim's text names that are a file of the graph or a directory holding one: each code
|
|
35
|
+
// span and each link target, read from the root and, for a link, from the claim's own directory.
|
|
36
|
+
function namedFiles(text, docRel, known) {
|
|
37
|
+
const out = new Set();
|
|
38
|
+
const consider = (raw, relative) => {
|
|
39
|
+
const token = raw.trim().replace(/[#?].*$/, '').replace(/:\d+(?:-\d+)?$/, '');
|
|
40
|
+
const tries = [normalisePath(token)];
|
|
41
|
+
if (relative) tries.push(posix(path.posix.normalize(path.posix.join(path.posix.dirname(docRel), token.replace(/\\/g, '/')))).replace(/\/+$/, ''));
|
|
42
|
+
for (const p of tries) {
|
|
43
|
+
if (p !== '' && p !== '.' && !p.startsWith('..') && (known.files.has(p) || known.dirs.has(p))) {
|
|
44
|
+
out.add(p);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
for (const [line] of prose(text)) {
|
|
50
|
+
for (const m of line.matchAll(CODE_SPAN)) consider(m[1], false);
|
|
51
|
+
for (const m of line.replace(/`[^`]*`/g, '').matchAll(LINK)) consider(m[1], true);
|
|
52
|
+
}
|
|
53
|
+
return [...out].sort(cmp);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Every claim, before its history is read: the REQ blocks of the spec in spec order, then the `##`
|
|
57
|
+
// sections of the runbook in runbook order. -> [{id, where, title, files, file, line, kind}]
|
|
58
|
+
function allClaims(root, cfg, index) {
|
|
59
|
+
const known = graphPaths(index);
|
|
60
|
+
const p = kitPaths(root, cfg);
|
|
61
|
+
const out = [];
|
|
62
|
+
const texts = new Map();
|
|
63
|
+
for (const b of reqBlocks(root, cfg)) {
|
|
64
|
+
if (!texts.has(b.file)) texts.set(b.file, lines(readText(path.join(root, b.file))));
|
|
65
|
+
const heading = texts.get(b.file)[b.line - 1] ?? '';
|
|
66
|
+
const title = heading.replace(/^#+\s*/, '').replace(/\s*#*\s*$/, '').slice(b.id.length).trim();
|
|
67
|
+
out.push({ kind: 'spec', id: b.id, where: `${b.file}:${b.line}`, title, files: namedFiles(`${heading}\n${b.block}`, b.file, known), file: b.file, line: b.line });
|
|
68
|
+
}
|
|
69
|
+
if (fs.existsSync(p.runbook)) {
|
|
70
|
+
const rel = posix(path.relative(root, p.runbook));
|
|
71
|
+
const text = readText(p.runbook);
|
|
72
|
+
const all = lines(text);
|
|
73
|
+
const hs = headings(text).filter((h) => h.level <= 2);
|
|
74
|
+
hs.forEach((h, i) => {
|
|
75
|
+
if (h.level !== 2) return;
|
|
76
|
+
const end = hs[i + 1] ? hs[i + 1].line - 1 : all.length;
|
|
77
|
+
const body = all.slice(h.line - 1, end).join('\n');
|
|
78
|
+
out.push({ kind: 'runbook', id: `runbook#${slug(h.text)}`, where: `${rel}:${h.line}`, title: h.text, files: namedFiles(body, rel, known), file: rel, line: h.line });
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The claims an area names (D-58): none for all; `runbook`; a REQ prefix such as `REQ-2`, or one REQ
|
|
85
|
+
// ID; a spec file's stem or path; else a path, naming the claims one of whose files is it, is under
|
|
86
|
+
// it or holds it.
|
|
87
|
+
function inArea(claims, area) {
|
|
88
|
+
if (area === undefined || area === null || String(area).trim() === '') return claims;
|
|
89
|
+
const a = String(area).trim();
|
|
90
|
+
if (a.toLowerCase() === 'runbook') return claims.filter((c) => c.kind === 'runbook');
|
|
91
|
+
if (/^REQ-\d+$/i.test(a)) return claims.filter((c) => c.kind === 'spec' && c.id.toUpperCase().startsWith(`${a.toUpperCase()}.`));
|
|
92
|
+
if (/^REQ-\d+\.\d+$/i.test(a)) return claims.filter((c) => c.kind === 'spec' && c.id.toUpperCase() === a.toUpperCase());
|
|
93
|
+
const p = normalisePath(a);
|
|
94
|
+
const ofDoc = claims.filter((c) => c.file === p || (c.kind === 'spec' && path.posix.basename(c.file, '.md') === p));
|
|
95
|
+
if (ofDoc.length > 0) return ofDoc;
|
|
96
|
+
return claims.filter((c) => c.files.some((f) => f === p || f.startsWith(`${p}/`) || p.startsWith(`${f}/`)));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The commit that last changed each line of a file, read with one `git blame --porcelain`:
|
|
100
|
+
// line number -> {sha, date}; a line not yet committed has no entry.
|
|
101
|
+
function blame(root, file) {
|
|
102
|
+
const out = new Map();
|
|
103
|
+
let text;
|
|
104
|
+
try {
|
|
105
|
+
text = git(root, ['blame', '--porcelain', '--', file]);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e instanceof GitError) return out;
|
|
108
|
+
throw e;
|
|
109
|
+
}
|
|
110
|
+
const dates = new Map();
|
|
111
|
+
let sha = null;
|
|
112
|
+
for (const l of text.split('\n')) {
|
|
113
|
+
const head = /^([0-9a-f]{40,64}) \d+ (\d+)(?: \d+)?$/.exec(l);
|
|
114
|
+
if (head) {
|
|
115
|
+
sha = head[1];
|
|
116
|
+
if (!/^0+$/.test(sha)) out.set(Number(head[2]), { sha, date: null });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const time = /^committer-time (\d+)$/.exec(l);
|
|
120
|
+
if (time && sha) dates.set(sha, new Date(Number(time[1]) * 1000).toISOString());
|
|
121
|
+
}
|
|
122
|
+
for (const entry of out.values()) entry.date = dates.get(entry.sha) ?? null;
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The commits that touched one of `files` and are not reachable from `since`, newest first by
|
|
127
|
+
// ancestry (`git log --topo-order`): a commit's dates are printed and never compared.
|
|
128
|
+
function candidates(root, since, files) {
|
|
129
|
+
if (!since || files.length === 0) return [];
|
|
130
|
+
const text = git(root, ['log', '--topo-order', '--format=%H%x09%cI%x09%s', `${since}..HEAD`, '--', ...files]);
|
|
131
|
+
return text === ''
|
|
132
|
+
? []
|
|
133
|
+
: text.split('\n').map((l) => {
|
|
134
|
+
const [sha, date, ...subject] = l.split('\t');
|
|
135
|
+
return { sha, date, subject: subject.join('\t') };
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// The claims of `area` (D-58), in spec order then runbook order:
|
|
140
|
+
// [{id, where, title, files, since: {sha, date} | null, candidates: [{sha, date, subject}]}].
|
|
141
|
+
// `since` is the commit that last changed the claim's heading line; a candidate touched one of the
|
|
142
|
+
// claim's files and descends from it. An area that names no claim is a usage error.
|
|
143
|
+
export function auditClaims(root, cfg, index, area) {
|
|
144
|
+
const picked = inArea(allClaims(root, cfg, index), area);
|
|
145
|
+
if (picked.length === 0) {
|
|
146
|
+
throw new GraphError(2, area === undefined || area === null || String(area).trim() === '' ? 'the spec and the runbook hold no claim' : `${area} names no claim`);
|
|
147
|
+
}
|
|
148
|
+
const blames = new Map();
|
|
149
|
+
const logs = new Map();
|
|
150
|
+
return picked.map((c) => {
|
|
151
|
+
if (!blames.has(c.file)) blames.set(c.file, blame(root, c.file));
|
|
152
|
+
const since = blames.get(c.file).get(c.line) ?? null;
|
|
153
|
+
const key = `${since?.sha ?? ''}\n${c.files.join('\n')}`;
|
|
154
|
+
if (!logs.has(key)) logs.set(key, candidates(root, since?.sha, c.files));
|
|
155
|
+
return { id: c.id, where: c.where, title: c.title, files: c.files, since, candidates: logs.get(key) };
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// What `/slicekit audit` hands the auditor. The report path is reserved after the claims are read,
|
|
160
|
+
// so an area that names no claim leaves no empty report behind. With `report` false no report is
|
|
161
|
+
// reserved and `report` is null: the context alone, for a second look at an area (issue #157).
|
|
162
|
+
export function auditContext(root, cfg, area, { report = true } = {}) {
|
|
163
|
+
const index = indexGraph(loadGraph(root, cfg));
|
|
164
|
+
const claims = auditClaims(root, cfg, index, area);
|
|
165
|
+
return { report: report ? nextReport(root, cfg, 'audit') : null, claims };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const bare = (cell) => cell.trim().replace(/^`+|`+$/g, '').trim();
|
|
169
|
+
|
|
170
|
+
// What is wrong with an audit report, one `<rel>:<line> <message>` per problem (REQ-2.14): a table
|
|
171
|
+
// under `## Claims` with the six columns; each row a claim of the area, written where the claim is,
|
|
172
|
+
// with a status of the three; a drifted row naming one of its claim's candidate commits; an
|
|
173
|
+
// unverifiable row saying why; a holds or drifted row naming where the evidence was found; no claim
|
|
174
|
+
// with two rows; the two closing lines. With `everyClaim`, each of `claims` has a row: `claims` are
|
|
175
|
+
// the claims of the area, as `auditClaims` reads them from the spec and the runbook.
|
|
176
|
+
export function auditReportProblems(root, rel, text, claims, { everyClaim = false } = {}) {
|
|
177
|
+
const out = [];
|
|
178
|
+
const section = reportSections(text).get('claims');
|
|
179
|
+
const table = sectionTable(text, 'Claims');
|
|
180
|
+
if (!section) out.push(`${rel}:1 no "## Claims" section`);
|
|
181
|
+
else if (!table) out.push(`${rel}:${section.line} the "## Claims" section holds no table`);
|
|
182
|
+
else if (table.header.cells.length !== COLUMNS.length || table.header.cells.some((c, i) => c.toLowerCase() !== COLUMNS[i].toLowerCase())) {
|
|
183
|
+
out.push(`${rel}:${table.header.line} the Claims table's columns are not ${COLUMNS.join(', ')}`);
|
|
184
|
+
} else if (table.rows.length === 0) out.push(`${rel}:${table.header.line} the Claims table holds no row`);
|
|
185
|
+
else {
|
|
186
|
+
const byId = new Map(claims.map((c) => [c.id, c]));
|
|
187
|
+
const rowOf = new Map();
|
|
188
|
+
for (const { cells, line } of table.rows) {
|
|
189
|
+
const at = `${rel}:${line}`;
|
|
190
|
+
if (cells.length !== COLUMNS.length) {
|
|
191
|
+
out.push(`${at} the row holds ${cells.length} cells, not ${COLUMNS.length}`);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const [id, where, status, commit] = [cells[0], cells[1], cells[4], cells[5]].map(bare);
|
|
195
|
+
const evidence = cells[2].trim();
|
|
196
|
+
const foundAt = cells[3].trim();
|
|
197
|
+
const claim = byId.get(id);
|
|
198
|
+
if (!claim) {
|
|
199
|
+
out.push(`${at} ${id === '' ? 'the row names no claim' : `${id} is not a claim of this audit`}`);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (rowOf.has(id)) {
|
|
203
|
+
out.push(`${at} ${id} has a second row; its first is on line ${rowOf.get(id)}`);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
rowOf.set(id, line);
|
|
207
|
+
if (where !== claim.where) out.push(`${at} ${id} is written at ${claim.where}, not ${where === '' ? 'nowhere' : where}`);
|
|
208
|
+
if (!STATUSES.includes(status)) {
|
|
209
|
+
out.push(`${at} the status of ${id} is "${status}", not ${STATUSES.slice(0, 2).join(', ')} or ${STATUSES[2]}`);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (status === 'drifted') {
|
|
213
|
+
const lower = commit.toLowerCase();
|
|
214
|
+
const named = /^[0-9a-f]{7,64}$/.test(lower) && claim.candidates.some((c) => c.sha.toLowerCase().startsWith(lower));
|
|
215
|
+
if (commit === '') out.push(`${at} drifted ${id} names no commit; name one that touched its files after it was written`);
|
|
216
|
+
else if (!named) out.push(`${at} drifted ${id} names ${commit}, which is not a commit that touched its files after it was written`);
|
|
217
|
+
}
|
|
218
|
+
if (status === 'unverifiable') {
|
|
219
|
+
if (evidence === '') out.push(`${at} unverifiable ${id} does not say why in Evidence`);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const cited = /^([^\s`]+):(\d+)$/.exec(bare(foundAt));
|
|
223
|
+
if (cited) {
|
|
224
|
+
if (!lineExists(root, normalisePath(cited[1]), Number(cited[2]))) out.push(`${at} ${cited[1]}:${cited[2]} is not a line of a file in the repository`);
|
|
225
|
+
} else if (!/`[^`]+`/.test(foundAt)) {
|
|
226
|
+
out.push(`${at} Found at of ${id} is neither a <file>:<line> nor a command in backticks`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (everyClaim) {
|
|
230
|
+
for (const c of claims) if (!rowOf.has(c.id)) out.push(`${rel}:${table.header.line} no row for ${c.id}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return [...out, ...footerProblems(rel, text)];
|
|
234
|
+
}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// equal what CI computes for the merge the branch names: a fresh checkout of that merge in a temporary
|
|
4
4
|
// worktree, synced from the git host and given the version, section and render the sync step would
|
|
5
5
|
// write there. So package.json may change only in its version field, CHANGELOG.md only by the one new
|
|
6
|
-
// section, and a rendered file only to its fresh render at that version.
|
|
7
|
-
//
|
|
6
|
+
// section, and a rendered file only to its fresh render at that version. The rendered files of each
|
|
7
|
+
// folder under examples/ that holds them are judged the same way (D-95): the sync step renders each
|
|
8
|
+
// example at that version, so an example file is accepted only where it equals that render. One
|
|
9
|
+
// finding per file that differs, naming it. A sync branch whose merge the checkout cannot resolve is the journal rule's
|
|
8
10
|
// finding. Silent outside CI and on any other branch, and when the config has no release.auto and the
|
|
9
11
|
// branch changes none of those files.
|
|
10
12
|
import { execFileSync } from 'node:child_process';
|
|
@@ -15,7 +17,7 @@ import { getHost } from '../../adapters/githost/index.js';
|
|
|
15
17
|
import { GitHostError } from '../../adapters/githost/errors.js';
|
|
16
18
|
import { ConfigError, loadConfig } from '../../config.js';
|
|
17
19
|
import { git, resolveCommit } from '../../git.js';
|
|
18
|
-
import { PACKAGE, ReleaseError, applyRelease, isKitRoot, isReleasePath } from '../../release-version.js';
|
|
20
|
+
import { EXAMPLES, PACKAGE, ReleaseError, applyRelease, isKitRoot, isReleasePath } from '../../release-version.js';
|
|
19
21
|
import { syncFromHost } from '../../state/sync.js';
|
|
20
22
|
import { SYNC_BRANCH, branchTip } from '../ci-event.js';
|
|
21
23
|
|
|
@@ -32,13 +34,19 @@ export function run(ctx) {
|
|
|
32
34
|
if (at === null || !SYNC_BRANCH.test(at.branch)) return [];
|
|
33
35
|
const merge = resolveCommit(root, at.branch.slice('sync/'.length));
|
|
34
36
|
if (merge === null) return [];
|
|
35
|
-
|
|
37
|
+
// The release paths with the examples this checkout holds; below, those the merge holds are
|
|
38
|
+
// added, so an example the branch adds or removes is judged against the merge's render too.
|
|
39
|
+
const ownsHere = isReleasePath(cfg, root);
|
|
40
|
+
let owns = ownsHere;
|
|
36
41
|
const changed = nul(git(root, ['diff', '--name-only', '--no-renames', '-z', merge, at.tip])).filter(owns);
|
|
37
42
|
if (cfg.release?.auto !== true && changed.length === 0) return [];
|
|
43
|
+
const example = (file) => file.startsWith(`${EXAMPLES}/`);
|
|
38
44
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'slicekit-sync-release-'));
|
|
39
45
|
const wt = path.join(tmp, 'merge');
|
|
40
46
|
try {
|
|
41
47
|
git(root, ['worktree', 'add', '--quiet', '--detach', wt, merge]);
|
|
48
|
+
const ownsMerge = isReleasePath(cfg, wt);
|
|
49
|
+
owns = (f) => ownsHere(f) || ownsMerge(f);
|
|
42
50
|
let expected;
|
|
43
51
|
try {
|
|
44
52
|
expected = expectedFiles(root, ctx, wt, owns);
|
|
@@ -50,7 +58,11 @@ export function run(ctx) {
|
|
|
50
58
|
for (const file of [...new Set([...changed, ...expected.keys()])].sort()) {
|
|
51
59
|
const want = expected.has(file) ? expected.get(file) : read(wt, file);
|
|
52
60
|
const got = blob(root, at.tip, file);
|
|
53
|
-
if (
|
|
61
|
+
if (same(want, got)) continue;
|
|
62
|
+
const how = example(file)
|
|
63
|
+
? 'a sync pull request changes an example file only to its fresh render at the version it sets (slicekit update --yes in that folder)'
|
|
64
|
+
: "a sync pull request changes it only as the sync step does (package.json's version, one new CHANGELOG.md section, the render at that version)";
|
|
65
|
+
out.push({ file, line: 0, message: `${file} differs from what CI computes for the merge ${merge.slice(0, 7)}; ${how}` });
|
|
54
66
|
}
|
|
55
67
|
return out;
|
|
56
68
|
} finally {
|
package/src/cli/audit.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// slicekit audit context [area] [--all] [--no-report] [--json] and
|
|
2
|
+
// slicekit audit check <report> [area] [--every-claim] (REQ-2.14, D-58):
|
|
3
|
+
// the claims `/slicekit audit` hands the auditor, each with the files it names and its candidate
|
|
4
|
+
// commits, and the check of the auditor's report against the claims of the same area, which the
|
|
5
|
+
// check reads from the spec and the runbook as the context does. With --no-report the context is
|
|
6
|
+
// printed alone and no report file is reserved (issue #157). With --every-claim a claim of the
|
|
7
|
+
// area that has no row is a problem. Neither changes a tracked file.
|
|
8
|
+
import { parseArgs } from 'node:util';
|
|
9
|
+
import { auditClaims, auditContext, auditReportProblems } from '../audit.js';
|
|
10
|
+
import { ConfigError, loadConfig } from '../config.js';
|
|
11
|
+
import { GitError } from '../git.js';
|
|
12
|
+
import { indexGraph, loadGraph } from '../graph/load.js';
|
|
13
|
+
import { GraphError } from '../graph/schema.js';
|
|
14
|
+
import { readReport } from '../reports.js';
|
|
15
|
+
|
|
16
|
+
const USAGE = 'audit context [area] [--all] [--no-report] [--json]\n audit check <report> [area] [--every-claim]';
|
|
17
|
+
const SUBCOMMANDS = ['context', 'check'];
|
|
18
|
+
|
|
19
|
+
const usage = (io, why) => {
|
|
20
|
+
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
|
21
|
+
return 2;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// `(none)` is what a procedure prints for no argument.
|
|
25
|
+
const areaOf = (arg) => (arg === undefined || arg === '(none)' ? undefined : arg);
|
|
26
|
+
|
|
27
|
+
// The candidate commits printed for one claim without --all (P5/S-23 review H-7).
|
|
28
|
+
export const SHOWN = 10;
|
|
29
|
+
|
|
30
|
+
// The narrowest area that names `claim`: its REQ ID, or `runbook` for a runbook section.
|
|
31
|
+
const areaFor = (claim) => (claim.id.startsWith('runbook#') ? 'runbook' : claim.id);
|
|
32
|
+
|
|
33
|
+
// The report path when one was reserved, then at most SHOWN candidates per claim, the newest, then
|
|
34
|
+
// one line counting the rest and naming the command that prints them and reserves no report, with
|
|
35
|
+
// the kit's command prefix `cli`; with `all`, each one. --json and the check hold every candidate.
|
|
36
|
+
function contextLines(c, { all = false, cli = 'slicekit' } = {}) {
|
|
37
|
+
const out = c.report === null ? [] : [c.report];
|
|
38
|
+
for (const claim of c.claims) {
|
|
39
|
+
out.push(`${claim.id} ${claim.where} ${claim.title}`.trimEnd());
|
|
40
|
+
out.push(` files: ${claim.files.join(', ')}`.trimEnd());
|
|
41
|
+
const shown = all ? claim.candidates : claim.candidates.slice(0, SHOWN);
|
|
42
|
+
for (const k of shown) out.push(` candidate ${k.sha.slice(0, 7)} ${k.date} ${k.subject}`.trimEnd());
|
|
43
|
+
const more = claim.candidates.length - shown.length;
|
|
44
|
+
if (more > 0) out.push(` ${more} more candidate${more === 1 ? '' : 's'}, each older: ${cli} audit context ${areaFor(claim)} --all --no-report`);
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function run(args, io) {
|
|
50
|
+
let values;
|
|
51
|
+
let positionals;
|
|
52
|
+
try {
|
|
53
|
+
({ values, positionals } = parseArgs({ args, options: { json: { type: 'boolean' }, all: { type: 'boolean' }, 'no-report': { type: 'boolean' }, 'every-claim': { type: 'boolean' } }, allowPositionals: true }));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return usage(io, e.message);
|
|
56
|
+
}
|
|
57
|
+
const [sub, ...rest] = positionals;
|
|
58
|
+
if (!SUBCOMMANDS.includes(sub)) return usage(io, sub === undefined ? 'missing subcommand' : `unknown subcommand '${sub}'`);
|
|
59
|
+
const json = Boolean(values.json);
|
|
60
|
+
const refuse = (message, code) => {
|
|
61
|
+
io.stderr(`slicekit: ${message}\n`);
|
|
62
|
+
if (json) io.stdout(`${JSON.stringify({ error: message }, null, 2)}\n`);
|
|
63
|
+
return code;
|
|
64
|
+
};
|
|
65
|
+
const root = io.cwd;
|
|
66
|
+
try {
|
|
67
|
+
const cfg = loadConfig(root);
|
|
68
|
+
if (sub === 'context') {
|
|
69
|
+
if (rest.length > 1) return usage(io, `unexpected argument ${rest[1]}`);
|
|
70
|
+
const context = auditContext(root, cfg, areaOf(rest[0]), { report: !values['no-report'] });
|
|
71
|
+
io.stdout(json ? `${JSON.stringify(context, null, 2)}\n` : contextLines(context, { all: Boolean(values.all), cli: cfg.cli }).map((l) => `${l}\n`).join(''));
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
if (rest.length === 0) return usage(io, 'missing report');
|
|
75
|
+
if (rest.length > 2) return usage(io, `unexpected argument ${rest[2]}`);
|
|
76
|
+
const { rel, text } = readReport(root, rest[0]);
|
|
77
|
+
if (text === null) return refuse(`${rel} is not a file`, 2);
|
|
78
|
+
const claims = auditClaims(root, cfg, indexGraph(loadGraph(root, cfg)), areaOf(rest[1]));
|
|
79
|
+
const problems = auditReportProblems(root, rel, text, claims, { everyClaim: Boolean(values['every-claim']) });
|
|
80
|
+
if (json) io.stdout(`${JSON.stringify({ report: rel, problems }, null, 2)}\n`);
|
|
81
|
+
else io.stdout(problems.length > 0 ? problems.map((p) => `${p}\n`).join('') : `ok ${rel}\n`);
|
|
82
|
+
return problems.length > 0 ? 1 : 0;
|
|
83
|
+
} catch (e) {
|
|
84
|
+
if (e instanceof GraphError) return refuse(e.message, e.code);
|
|
85
|
+
if (e instanceof ConfigError) return refuse(e.message, 2);
|
|
86
|
+
if (e instanceof GitError) return refuse(e.message, 1);
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const auditCommand = { run, usage: USAGE, subcommands: SUBCOMMANDS };
|