slicekit 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/audit.js +233 -0
- package/src/cli/audit.js +89 -0
- package/src/cli/index.js +4 -0
- package/src/cli/ops.js +78 -0
- package/src/cli/update.js +4 -0
- 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/reports.js +131 -0
- 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 +38 -0
- package/templates/instructions/commands/ops.md +38 -0
package/package.json
CHANGED
package/src/audit.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
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.
|
|
161
|
+
export function auditContext(root, cfg, area) {
|
|
162
|
+
const index = indexGraph(loadGraph(root, cfg));
|
|
163
|
+
const claims = auditClaims(root, cfg, index, area);
|
|
164
|
+
return { report: nextReport(root, cfg, 'audit'), claims };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const bare = (cell) => cell.trim().replace(/^`+|`+$/g, '').trim();
|
|
168
|
+
|
|
169
|
+
// What is wrong with an audit report, one `<rel>:<line> <message>` per problem (REQ-2.14): a table
|
|
170
|
+
// under `## Claims` with the six columns; each row a claim of the area, written where the claim is,
|
|
171
|
+
// with a status of the three; a drifted row naming one of its claim's candidate commits; an
|
|
172
|
+
// unverifiable row saying why; a holds or drifted row naming where the evidence was found; no claim
|
|
173
|
+
// with two rows; the two closing lines. With `everyClaim`, each of `claims` has a row: `claims` are
|
|
174
|
+
// the claims of the area, as `auditClaims` reads them from the spec and the runbook.
|
|
175
|
+
export function auditReportProblems(root, rel, text, claims, { everyClaim = false } = {}) {
|
|
176
|
+
const out = [];
|
|
177
|
+
const section = reportSections(text).get('claims');
|
|
178
|
+
const table = sectionTable(text, 'Claims');
|
|
179
|
+
if (!section) out.push(`${rel}:1 no "## Claims" section`);
|
|
180
|
+
else if (!table) out.push(`${rel}:${section.line} the "## Claims" section holds no table`);
|
|
181
|
+
else if (table.header.cells.length !== COLUMNS.length || table.header.cells.some((c, i) => c.toLowerCase() !== COLUMNS[i].toLowerCase())) {
|
|
182
|
+
out.push(`${rel}:${table.header.line} the Claims table's columns are not ${COLUMNS.join(', ')}`);
|
|
183
|
+
} else if (table.rows.length === 0) out.push(`${rel}:${table.header.line} the Claims table holds no row`);
|
|
184
|
+
else {
|
|
185
|
+
const byId = new Map(claims.map((c) => [c.id, c]));
|
|
186
|
+
const rowOf = new Map();
|
|
187
|
+
for (const { cells, line } of table.rows) {
|
|
188
|
+
const at = `${rel}:${line}`;
|
|
189
|
+
if (cells.length !== COLUMNS.length) {
|
|
190
|
+
out.push(`${at} the row holds ${cells.length} cells, not ${COLUMNS.length}`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const [id, where, status, commit] = [cells[0], cells[1], cells[4], cells[5]].map(bare);
|
|
194
|
+
const evidence = cells[2].trim();
|
|
195
|
+
const foundAt = cells[3].trim();
|
|
196
|
+
const claim = byId.get(id);
|
|
197
|
+
if (!claim) {
|
|
198
|
+
out.push(`${at} ${id === '' ? 'the row names no claim' : `${id} is not a claim of this audit`}`);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (rowOf.has(id)) {
|
|
202
|
+
out.push(`${at} ${id} has a second row; its first is on line ${rowOf.get(id)}`);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
rowOf.set(id, line);
|
|
206
|
+
if (where !== claim.where) out.push(`${at} ${id} is written at ${claim.where}, not ${where === '' ? 'nowhere' : where}`);
|
|
207
|
+
if (!STATUSES.includes(status)) {
|
|
208
|
+
out.push(`${at} the status of ${id} is "${status}", not ${STATUSES.slice(0, 2).join(', ')} or ${STATUSES[2]}`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (status === 'drifted') {
|
|
212
|
+
const lower = commit.toLowerCase();
|
|
213
|
+
const named = /^[0-9a-f]{7,64}$/.test(lower) && claim.candidates.some((c) => c.sha.toLowerCase().startsWith(lower));
|
|
214
|
+
if (commit === '') out.push(`${at} drifted ${id} names no commit; name one that touched its files after it was written`);
|
|
215
|
+
else if (!named) out.push(`${at} drifted ${id} names ${commit}, which is not a commit that touched its files after it was written`);
|
|
216
|
+
}
|
|
217
|
+
if (status === 'unverifiable') {
|
|
218
|
+
if (evidence === '') out.push(`${at} unverifiable ${id} does not say why in Evidence`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const cited = /^([^\s`]+):(\d+)$/.exec(bare(foundAt));
|
|
222
|
+
if (cited) {
|
|
223
|
+
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`);
|
|
224
|
+
} else if (!/`[^`]+`/.test(foundAt)) {
|
|
225
|
+
out.push(`${at} Found at of ${id} is neither a <file>:<line> nor a command in backticks`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (everyClaim) {
|
|
229
|
+
for (const c of claims) if (!rowOf.has(c.id)) out.push(`${rel}:${table.header.line} no row for ${c.id}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return [...out, ...footerProblems(rel, text)];
|
|
233
|
+
}
|
package/src/cli/audit.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// slicekit audit context [area] [--all] [--json] and slicekit audit check <report> [area] [--every-claim]
|
|
2
|
+
// (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 --every-claim a claim of the
|
|
6
|
+
// area that has no row is a problem. Neither changes a tracked file.
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import { auditClaims, auditContext, auditReportProblems } from '../audit.js';
|
|
9
|
+
import { ConfigError, loadConfig } from '../config.js';
|
|
10
|
+
import { GitError } from '../git.js';
|
|
11
|
+
import { indexGraph, loadGraph } from '../graph/load.js';
|
|
12
|
+
import { GraphError } from '../graph/schema.js';
|
|
13
|
+
import { readReport } from '../reports.js';
|
|
14
|
+
|
|
15
|
+
const USAGE = 'audit context [area] [--all] [--json]\n audit check <report> [area] [--every-claim]';
|
|
16
|
+
const SUBCOMMANDS = ['context', 'check'];
|
|
17
|
+
|
|
18
|
+
const usage = (io, why) => {
|
|
19
|
+
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
|
20
|
+
return 2;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// `(none)` is what a procedure prints for no argument.
|
|
24
|
+
const areaOf = (arg) => (arg === undefined || arg === '(none)' ? undefined : arg);
|
|
25
|
+
|
|
26
|
+
// The candidate commits printed for one claim without --all (P5/S-23 review H-7).
|
|
27
|
+
export const SHOWN = 10;
|
|
28
|
+
|
|
29
|
+
// The narrowest area that names `claim`: its REQ ID, or `runbook` for a runbook section.
|
|
30
|
+
const areaFor = (claim) => (claim.id.startsWith('runbook#') ? 'runbook' : claim.id);
|
|
31
|
+
|
|
32
|
+
// At most SHOWN candidates per claim, the newest, then one line counting the rest and naming the
|
|
33
|
+
// command that prints them; with `all`, each one. --json and the check hold every candidate.
|
|
34
|
+
function contextLines(c, { all = false } = {}) {
|
|
35
|
+
const out = [c.report];
|
|
36
|
+
for (const claim of c.claims) {
|
|
37
|
+
out.push(`${claim.id} ${claim.where} ${claim.title}`.trimEnd());
|
|
38
|
+
out.push(` files: ${claim.files.join(', ')}`.trimEnd());
|
|
39
|
+
const shown = all ? claim.candidates : claim.candidates.slice(0, SHOWN);
|
|
40
|
+
for (const k of shown) out.push(` candidate ${k.sha.slice(0, 7)} ${k.date} ${k.subject}`.trimEnd());
|
|
41
|
+
const more = claim.candidates.length - shown.length;
|
|
42
|
+
if (more > 0) out.push(` ${more} more candidate${more === 1 ? '' : 's'}, each older: audit context ${areaFor(claim)} --all`);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function run(args, io) {
|
|
48
|
+
let values;
|
|
49
|
+
let positionals;
|
|
50
|
+
try {
|
|
51
|
+
({ values, positionals } = parseArgs({ args, options: { json: { type: 'boolean' }, all: { type: 'boolean' }, 'every-claim': { type: 'boolean' } }, allowPositionals: true }));
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return usage(io, e.message);
|
|
54
|
+
}
|
|
55
|
+
const [sub, ...rest] = positionals;
|
|
56
|
+
if (!SUBCOMMANDS.includes(sub)) return usage(io, sub === undefined ? 'missing subcommand' : `unknown subcommand '${sub}'`);
|
|
57
|
+
const json = Boolean(values.json);
|
|
58
|
+
const refuse = (message, code) => {
|
|
59
|
+
io.stderr(`slicekit: ${message}\n`);
|
|
60
|
+
if (json) io.stdout(`${JSON.stringify({ error: message }, null, 2)}\n`);
|
|
61
|
+
return code;
|
|
62
|
+
};
|
|
63
|
+
const root = io.cwd;
|
|
64
|
+
try {
|
|
65
|
+
const cfg = loadConfig(root);
|
|
66
|
+
if (sub === 'context') {
|
|
67
|
+
if (rest.length > 1) return usage(io, `unexpected argument ${rest[1]}`);
|
|
68
|
+
const context = auditContext(root, cfg, areaOf(rest[0]));
|
|
69
|
+
io.stdout(json ? `${JSON.stringify(context, null, 2)}\n` : contextLines(context, { all: Boolean(values.all) }).map((l) => `${l}\n`).join(''));
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (rest.length === 0) return usage(io, 'missing report');
|
|
73
|
+
if (rest.length > 2) return usage(io, `unexpected argument ${rest[2]}`);
|
|
74
|
+
const { rel, text } = readReport(root, rest[0]);
|
|
75
|
+
if (text === null) return refuse(`${rel} is not a file`, 2);
|
|
76
|
+
const claims = auditClaims(root, cfg, indexGraph(loadGraph(root, cfg)), areaOf(rest[1]));
|
|
77
|
+
const problems = auditReportProblems(root, rel, text, claims, { everyClaim: Boolean(values['every-claim']) });
|
|
78
|
+
if (json) io.stdout(`${JSON.stringify({ report: rel, problems }, null, 2)}\n`);
|
|
79
|
+
else io.stdout(problems.length > 0 ? problems.map((p) => `${p}\n`).join('') : `ok ${rel}\n`);
|
|
80
|
+
return problems.length > 0 ? 1 : 0;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e instanceof GraphError) return refuse(e.message, e.code);
|
|
83
|
+
if (e instanceof ConfigError) return refuse(e.message, 2);
|
|
84
|
+
if (e instanceof GitError) return refuse(e.message, 1);
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const auditCommand = { run, usage: USAGE, subcommands: SUBCOMMANDS };
|
package/src/cli/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { auditCommand } from './audit.js';
|
|
2
3
|
import { baselineCommand } from './baseline.js';
|
|
3
4
|
import { branchCommand } from './branch.js';
|
|
4
5
|
import { buildCommand } from './build.js';
|
|
@@ -14,6 +15,7 @@ import { intakeCommand } from './intake.js';
|
|
|
14
15
|
import { prCommand } from './pr.js';
|
|
15
16
|
import { instructionsCommand } from './instructions.js';
|
|
16
17
|
import { journalCommand } from './journal.js';
|
|
18
|
+
import { opsCommand } from './ops.js';
|
|
17
19
|
import { planCommand } from './plan.js';
|
|
18
20
|
import { hookCommand } from './hook.js';
|
|
19
21
|
import { readyLabelCommand } from './ready-label.js';
|
|
@@ -33,6 +35,7 @@ import { workflowCommand } from './workflow.js';
|
|
|
33
35
|
|
|
34
36
|
// Later tasks add entries: { [name]: { run(args, io) -> Promise<number>, usage: string, subcommands?: string[] } }
|
|
35
37
|
export const COMMANDS = {
|
|
38
|
+
audit: auditCommand,
|
|
36
39
|
baseline: baselineCommand,
|
|
37
40
|
branch: branchCommand,
|
|
38
41
|
build: buildCommand,
|
|
@@ -48,6 +51,7 @@ export const COMMANDS = {
|
|
|
48
51
|
instructions: instructionsCommand,
|
|
49
52
|
hook: hookCommand,
|
|
50
53
|
journal: journalCommand,
|
|
54
|
+
ops: opsCommand,
|
|
51
55
|
plan: planCommand,
|
|
52
56
|
pr: prCommand,
|
|
53
57
|
'ready-label': readyLabelCommand,
|
package/src/cli/ops.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// slicekit ops context <symptom> [--path <p>]… [--json] and slicekit ops check <report> (REQ-2.13,
|
|
2
|
+
// D-57): what `/slicekit ops` hands the ops agent, and the check of the report it replies with.
|
|
3
|
+
// Neither runs git, calls the host or takes an action.
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
import { ConfigError, loadConfig } from '../config.js';
|
|
6
|
+
import { historyLine } from '../graph/history.js';
|
|
7
|
+
import { indexGraph, loadGraph } from '../graph/load.js';
|
|
8
|
+
import { GraphError } from '../graph/schema.js';
|
|
9
|
+
import { opsContext, opsReportProblems } from '../ops.js';
|
|
10
|
+
import { readReport } from '../reports.js';
|
|
11
|
+
|
|
12
|
+
const USAGE = 'ops context <symptom> [--path <p>]… [--json]\n ops check <report>';
|
|
13
|
+
const SUBCOMMANDS = ['context', 'check'];
|
|
14
|
+
|
|
15
|
+
const usage = (io, why) => {
|
|
16
|
+
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
|
17
|
+
return 2;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function contextLines(c) {
|
|
21
|
+
return [
|
|
22
|
+
c.report,
|
|
23
|
+
`symptom: ${c.symptom}`,
|
|
24
|
+
...c.files.map((f) => `file: ${f}`),
|
|
25
|
+
...c.broad.map((b) => `too broad: ${b.word} (${b.count} files)`),
|
|
26
|
+
...(c.unmatched.length > 0 ? [`no file: ${c.unmatched.join(', ')}`] : []),
|
|
27
|
+
'history:',
|
|
28
|
+
...c.history.map(historyLine),
|
|
29
|
+
`runbook: ${c.runbook}${c.missing.includes(c.runbook) ? ' (missing)' : ''}`,
|
|
30
|
+
`observability: ${c.observability}${c.missing.includes(c.observability) ? ' (missing)' : ''}`,
|
|
31
|
+
`last release: ${c.lastRelease ?? 'none'}`,
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function run(args, io) {
|
|
36
|
+
let values;
|
|
37
|
+
let positionals;
|
|
38
|
+
try {
|
|
39
|
+
({ values, positionals } = parseArgs({ args, options: { path: { type: 'string', multiple: true }, json: { type: 'boolean' } }, allowPositionals: true }));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return usage(io, e.message);
|
|
42
|
+
}
|
|
43
|
+
const [sub, ...rest] = positionals;
|
|
44
|
+
if (!SUBCOMMANDS.includes(sub)) return usage(io, sub === undefined ? 'missing subcommand' : `unknown subcommand '${sub}'`);
|
|
45
|
+
const json = Boolean(values.json);
|
|
46
|
+
const refuse = (message, code) => {
|
|
47
|
+
io.stderr(`slicekit: ${message}\n`);
|
|
48
|
+
if (json) io.stdout(`${JSON.stringify({ error: message }, null, 2)}\n`);
|
|
49
|
+
return code;
|
|
50
|
+
};
|
|
51
|
+
const root = io.cwd;
|
|
52
|
+
try {
|
|
53
|
+
const cfg = loadConfig(root);
|
|
54
|
+
if (sub === 'context') {
|
|
55
|
+
// The words of a symptom typed without quotes are one symptom.
|
|
56
|
+
const symptom = rest.join(' ').trim();
|
|
57
|
+
const paths = values.path ?? [];
|
|
58
|
+
if (symptom === '' && paths.length === 0) return usage(io, 'missing symptom');
|
|
59
|
+
const context = opsContext(root, cfg, symptom, { paths });
|
|
60
|
+
io.stdout(json ? `${JSON.stringify(context, null, 2)}\n` : contextLines(context).map((l) => `${l}\n`).join(''));
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
if (rest.length !== 1) return usage(io, rest.length === 0 ? 'missing report' : `unexpected argument ${rest[1]}`);
|
|
64
|
+
if (values.path) return usage(io, 'ops check takes no --path');
|
|
65
|
+
const { rel, text } = readReport(root, rest[0]);
|
|
66
|
+
if (text === null) return refuse(`${rel} is not a file`, 2);
|
|
67
|
+
const problems = opsReportProblems(root, indexGraph(loadGraph(root, cfg)), rel, text);
|
|
68
|
+
if (json) io.stdout(`${JSON.stringify({ report: rel, problems }, null, 2)}\n`);
|
|
69
|
+
else io.stdout(problems.length > 0 ? problems.map((p) => `${p}\n`).join('') : `ok ${rel}\n`);
|
|
70
|
+
return problems.length > 0 ? 1 : 0;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (e instanceof GraphError) return refuse(e.message, e.code);
|
|
73
|
+
if (e instanceof ConfigError) return refuse(e.message, 2);
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const opsCommand = { run, usage: USAGE, subcommands: SUBCOMMANDS };
|
package/src/cli/update.js
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import { ConfigError, loadConfig } from '../config.js';
|
|
4
4
|
import { exists } from '../fs.js';
|
|
5
|
+
import { missingReportsRule } from '../init.js';
|
|
5
6
|
import { checkCli } from '../hook-cli.js';
|
|
6
7
|
import { kitVersion, RENDERED } from '../render/index.js';
|
|
7
8
|
import { applyUpdate, planUpdate } from '../render/update.js';
|
|
@@ -40,6 +41,9 @@ async function run(args, io) {
|
|
|
40
41
|
io.stdout(`${status} ${dest}\n`);
|
|
41
42
|
if (diff !== '') io.stdout(diff);
|
|
42
43
|
}
|
|
44
|
+
// update never writes the ignore file (REQ-5.6): a project that lacks the rule is told the line.
|
|
45
|
+
const rule = missingReportsRule(root, cfg);
|
|
46
|
+
if (rule) io.stdout(`.gitignore has no rule for ${rule}, where /slicekit ops and /slicekit audit write their reports; add the line ${rule}\n`);
|
|
43
47
|
if (values.check) {
|
|
44
48
|
if (!exists(path.join(root, RENDERED))) io.stdout(`${RENDERED}/ is missing; commit it so drift can be told from kit changes\n`);
|
|
45
49
|
return pending.some((p) => p.status === 'drifted' || p.status === 'missing') ? 1 : 0;
|
|
@@ -15,6 +15,10 @@ import { addAgent, usableId } from './subagent-marker.js';
|
|
|
15
15
|
export { roleOf };
|
|
16
16
|
export const BRIEF_MAX = 8000;
|
|
17
17
|
export const NO_GIT = 'You never run a git command that commits, pushes or moves a branch; report and the command commits.';
|
|
18
|
+
// The ops agent holds no tool that runs a command or writes a file, and nothing of its work is
|
|
19
|
+
// committed (D-57): it is told what becomes of its reply instead.
|
|
20
|
+
export const OPS_REPLY = 'You run no command and write no file. Your reply is the report: the main session writes it under .slicekit/reports/ and checks it, and it is never committed.';
|
|
21
|
+
const closing = (role) => (role === 'ops' ? OPS_REPLY : NO_GIT);
|
|
18
22
|
const SKILL = path.join('.claude', 'skills', 'slicekit-writing', 'SKILL.md');
|
|
19
23
|
const KIT_SKILL = fileURLToPath(new URL('../../templates/claude-code/skills/slicekit-writing/SKILL.md', import.meta.url));
|
|
20
24
|
|
|
@@ -74,11 +78,11 @@ function withoutRules(text) {
|
|
|
74
78
|
return out.join('\n').trim();
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
// The brief, the rules and the no-git sentence
|
|
78
|
-
// sentence always last and whole. A brief that does not fit is cut from its end and followed by a
|
|
81
|
+
// The brief, the rules and the role's closing sentence (the no-git sentence; for ops, OPS_REPLY) in
|
|
82
|
+
// at most BRIEF_MAX characters, the rules and the sentence always last and whole. A brief that does not fit is cut from its end and followed by a
|
|
79
83
|
// line naming where the full text is. Only when the rules alone do not fit are they cut too.
|
|
80
84
|
function assemble(brief, rules, role, cli) {
|
|
81
|
-
const tail = `\n\n${
|
|
85
|
+
const tail = `\n\n${closing(role)}`;
|
|
82
86
|
const end = rules.text === '' ? tail : `\n\n${rules.text}${tail}`;
|
|
83
87
|
if (brief.length + end.length <= BRIEF_MAX) return brief + end;
|
|
84
88
|
const note = `\n(brief truncated; full text in ${cli} instructions ${role})`;
|
package/src/init.js
CHANGED
|
@@ -23,6 +23,8 @@ const IGNORE_RULES = [
|
|
|
23
23
|
{ rule: '.slicekit/.subagent-*', forms: new Set(['.slicekit/.subagent-*', '/.slicekit/.subagent-*']) },
|
|
24
24
|
// The machine's own settings (D-43), such as a local test command: never part of the project.
|
|
25
25
|
{ rule: '.slicekit/local.json', forms: new Set(['.slicekit/local.json', '/.slicekit/local.json']) },
|
|
26
|
+
// The reports of `/slicekit ops` and `/slicekit audit` (D-57, D-58): written on one machine, never committed.
|
|
27
|
+
{ rule: '.slicekit/reports/', forms: new Set(['.slicekit/reports/', '/.slicekit/reports/', '.slicekit/reports', '/.slicekit/reports']) },
|
|
26
28
|
{ rule: '!.slicekit/journal/', forms: new Set(['!.slicekit/journal/', '!/.slicekit/journal/']) },
|
|
27
29
|
{ rule: '!.slicekit/journal/*.log', forms: new Set(['!.slicekit/journal/*.log', '!/.slicekit/journal/*.log']) },
|
|
28
30
|
{ rule: '.slicekit/journal/*.lock', forms: new Set(['.slicekit/journal/*.lock', '/.slicekit/journal/*.lock']) },
|
|
@@ -40,6 +42,8 @@ const IGNORE_RULES = [
|
|
|
40
42
|
const UNIGNORE_RULES = ['!.slicekit/journal/', '!.slicekit/journal/*.log', '.slicekit/journal/*.lock', '!.slicekit/journal-heads.log'];
|
|
41
43
|
const UNIGNORE_PROBES = ['.slicekit/journal-heads.log', '.slicekit/journal/main--00000000.log'];
|
|
42
44
|
|
|
45
|
+
const REPORTS_RULE = '.slicekit/reports/';
|
|
46
|
+
|
|
43
47
|
function ignoredByGit(root, rel) {
|
|
44
48
|
try {
|
|
45
49
|
git(root, ['check-ignore', '--quiet', '--no-index', rel]);
|
|
@@ -94,6 +98,21 @@ function reassertUnignores(root, file) {
|
|
|
94
98
|
return { appended, note };
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
// The ignore rule for the reports directory when the project lacks it, else null. `update` never
|
|
102
|
+
// writes the ignore file (REQ-5.6: managed blocks only), so it prints this line for a project
|
|
103
|
+
// initialised before the rule existed (P5/S-23 review H-4). In a git repository git decides whether
|
|
104
|
+
// a report is ignored; outside one, a line in any spelling init accepts counts.
|
|
105
|
+
export function missingReportsRule(root, cfg) {
|
|
106
|
+
const paths = kitPaths(root, cfg);
|
|
107
|
+
if (isRepo(root)) {
|
|
108
|
+
const report = path.relative(root, path.join(paths.reports, 'ops-1.md')).split(path.sep).join('/');
|
|
109
|
+
return ignoredByGit(root, report) ? null : REPORTS_RULE;
|
|
110
|
+
}
|
|
111
|
+
const { forms } = IGNORE_RULES.find((r) => r.rule === REPORTS_RULE);
|
|
112
|
+
const present = exists(paths.gitignore) ? fs.readFileSync(paths.gitignore, 'utf8').split(/\r?\n/).map((l) => l.trim()) : [];
|
|
113
|
+
return present.some((l) => forms.has(l)) ? null : REPORTS_RULE;
|
|
114
|
+
}
|
|
115
|
+
|
|
97
116
|
// Hooks checked out with CRLF break sh (REQ-3.9).
|
|
98
117
|
// Intake snapshots (S-10) are stored byte for byte, so git must not convert their line endings. The
|
|
99
118
|
// pattern comes from kitPaths as S-10 builds it, so `./docs` and `docs` write the same line.
|
package/src/ops.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// `slicekit ops` (REQ-2.13, D-57): what `/slicekit ops` hands the ops agent for a symptom, and the
|
|
2
|
+
// check of the report the agent replies with. Both read graph.json and files; neither runs git, calls
|
|
3
|
+
// the host or takes an action.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { history } from './graph/history.js';
|
|
7
|
+
import { indexGraph, loadGraph, normalisePath } from './graph/load.js';
|
|
8
|
+
import { GraphError, cmp, keyOf } from './graph/schema.js';
|
|
9
|
+
import { re } from './ids.js';
|
|
10
|
+
import { kitPaths } from './paths.js';
|
|
11
|
+
import { cellsOf, footerProblems, isDivider, isRow, lineExists, nextReport, reportSections } from './reports.js';
|
|
12
|
+
|
|
13
|
+
// A word naming more files than this is too broad to expand.
|
|
14
|
+
export const BROAD = 50;
|
|
15
|
+
|
|
16
|
+
const posix = (p) => p.split(path.sep).join('/');
|
|
17
|
+
const segmentsOf = (file) => file.toLowerCase().split(/[/._-]/).filter((s) => s !== '');
|
|
18
|
+
|
|
19
|
+
// The files a symptom names (D-57). Words are the runs of letters and digits of three or more
|
|
20
|
+
// characters, lower-cased, unique, in order; a word names each file one of whose path segments
|
|
21
|
+
// (split on `/`, `.`, `-`, `_`) equals it. A word naming more than BROAD files names none and is
|
|
22
|
+
// reported; so is a word naming no file. Each of `paths` names the files `slicekit history` would
|
|
23
|
+
// match for it. -> {files, words: [{word, files}], broad: [{word, count}], unmatched}
|
|
24
|
+
export function symptomFiles(index, symptom, paths = []) {
|
|
25
|
+
const all = index.byKind('file').map((n) => keyOf(n.id));
|
|
26
|
+
const bySegment = new Map();
|
|
27
|
+
for (const file of all) {
|
|
28
|
+
for (const s of new Set(segmentsOf(file))) {
|
|
29
|
+
if (!bySegment.has(s)) bySegment.set(s, []);
|
|
30
|
+
bySegment.get(s).push(file);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const found = new Set();
|
|
34
|
+
const words = [];
|
|
35
|
+
const broad = [];
|
|
36
|
+
const unmatched = [];
|
|
37
|
+
for (const word of new Set((String(symptom ?? '').match(/[A-Za-z0-9]{3,}/g) ?? []).map((w) => w.toLowerCase()))) {
|
|
38
|
+
const named = bySegment.get(word) ?? [];
|
|
39
|
+
if (named.length === 0) unmatched.push(word);
|
|
40
|
+
else if (named.length > BROAD) broad.push({ word, count: named.length });
|
|
41
|
+
else {
|
|
42
|
+
words.push({ word, files: [...named].sort(cmp) });
|
|
43
|
+
for (const f of named) found.add(f);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const p of paths) {
|
|
47
|
+
const want = normalisePath(p);
|
|
48
|
+
const dir = `${want}/`;
|
|
49
|
+
const named = want === '' || want === '.' ? all : all.filter((f) => f === want || f.startsWith(dir));
|
|
50
|
+
if (named.length === 0) throw new GraphError(2, `${p} is not in the graph`);
|
|
51
|
+
for (const f of named) found.add(f);
|
|
52
|
+
}
|
|
53
|
+
return { files: [...found].sort(cmp), words, broad, unmatched };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The release record of the highest phase, as its repository-relative path; null when there is none.
|
|
57
|
+
function lastRelease(index) {
|
|
58
|
+
const phaseOf = (n) => Number(/^P(\d+)$/.exec(keyOf(n.id))?.[1] ?? -1);
|
|
59
|
+
const newest = [...index.byKind('release')].sort((a, b) => phaseOf(b) - phaseOf(a) || cmp(a.id, b.id))[0];
|
|
60
|
+
return newest ? String(newest.from ?? '').replace(/:\d+$/, '') || null : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Everything the ops agent is handed for `symptom`. The report path is reserved last, so a symptom
|
|
64
|
+
// that names no file leaves no empty report behind. Paths are repository-relative.
|
|
65
|
+
export function opsContext(root, cfg, symptom, { paths = [] } = {}) {
|
|
66
|
+
const index = indexGraph(loadGraph(root, cfg));
|
|
67
|
+
const { files, broad, unmatched } = symptomFiles(index, symptom, paths);
|
|
68
|
+
if (files.length === 0) throw new GraphError(1, 'the symptom names no file in the graph; name one with --path <path>');
|
|
69
|
+
const p = kitPaths(root, cfg);
|
|
70
|
+
const rel = (file) => posix(path.relative(root, file));
|
|
71
|
+
const entries = history(index, files);
|
|
72
|
+
return {
|
|
73
|
+
report: nextReport(root, cfg, 'ops'),
|
|
74
|
+
symptom,
|
|
75
|
+
files,
|
|
76
|
+
broad,
|
|
77
|
+
unmatched,
|
|
78
|
+
history: entries,
|
|
79
|
+
runbook: rel(p.runbook),
|
|
80
|
+
observability: rel(p.observability),
|
|
81
|
+
missing: [p.runbook, p.observability].filter((f) => !fs.existsSync(f)).map(rel),
|
|
82
|
+
lastRelease: lastRelease(index),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const OPS_SECTIONS = ['Likely slices and pull requests', 'First checks', 'Proposed actions'];
|
|
87
|
+
|
|
88
|
+
const FOOTER = /^(?:Skipped|Not checked):/;
|
|
89
|
+
const ITEM = /^\s*(?:[-*+]|\d+[.)])\s+/;
|
|
90
|
+
const MARKED = /\((?:anyone|on-call|owner: [^()]*[^()\s][^()]*)\)[.\s]*$/;
|
|
91
|
+
const PR_REF = /(?<![\w&/#.-])([A-Za-z0-9._-]+)?#(\d+)\b/g;
|
|
92
|
+
const CITATION = /(?<![\w./-])([A-Za-z0-9_.][\w./-]*):(\d+)\b/g;
|
|
93
|
+
|
|
94
|
+
// The file extensions a path can end in without naming a file of the graph: the cited file may be
|
|
95
|
+
// missing, and its extension still says it was meant as a file.
|
|
96
|
+
const EXTENSIONS = new Set(
|
|
97
|
+
'c cc cfg cjs conf cpp cs css csv env go gradle h hpp html ini java js json jsx kt lock log lua md mjs php properties proto ps1 py rb rs scss sh sql svelte swift tf toml ts tsx txt vue xml yaml yml'.split(' '),
|
|
98
|
+
);
|
|
99
|
+
const extensionOf = (file) => /\.([A-Za-z0-9]+)$/.exec(file.split('/').at(-1))?.[1].toLowerCase() ?? null;
|
|
100
|
+
|
|
101
|
+
// Whether the text before the colon of a `<path>:<line>` token in First checks makes it a citation
|
|
102
|
+
// (P5/S-23 review H-6), with a slash in it or without. It is one when the path is a file in the
|
|
103
|
+
// repository or a file of the graph, and when its last segment ends in a file extension: one of
|
|
104
|
+
// EXTENSIONS, or the extension of a file of the graph. A token that names no file and ends in no file
|
|
105
|
+
// extension, such as `localhost:8080`, `svc.internal/health:8080` or `registry/app:2`, is none.
|
|
106
|
+
function isCitation(root, index, file) {
|
|
107
|
+
if (file === '' || file === '.') return false;
|
|
108
|
+
if (index.node(`file:${file}`)) return true;
|
|
109
|
+
try {
|
|
110
|
+
if (fs.statSync(path.join(root, file)).isFile()) return true;
|
|
111
|
+
} catch {
|
|
112
|
+
// Not a file on disk: the extension decides.
|
|
113
|
+
}
|
|
114
|
+
const ext = extensionOf(file);
|
|
115
|
+
return ext !== null && (EXTENSIONS.has(ext) || index.byKind('file').some((n) => extensionOf(keyOf(n.id)) === ext));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const FENCE = /^\s*(```|~~~)/;
|
|
119
|
+
const SUBHEADING = /^\s{0,3}#{3,6}\s/;
|
|
120
|
+
const NO_MARK = 'who may take it: (anyone), (on-call) or (owner: <name>)';
|
|
121
|
+
|
|
122
|
+
// The actions of the Proposed actions section, in each form the section can hold one, as
|
|
123
|
+
// {first, marked, message}: `first` the action's first line number. A list item, with the lines that
|
|
124
|
+
// continue it (indented, or right under it), and a paragraph of plain lines are each one action,
|
|
125
|
+
// marked when the joined text ends with the mark. A table row is one action, marked when one of its
|
|
126
|
+
// cells ends with the mark; the header row and the divider are none. A sub-heading and a fenced
|
|
127
|
+
// block are no action. `ls` holds the section's lines that are not blank.
|
|
128
|
+
function actions(ls) {
|
|
129
|
+
const out = [];
|
|
130
|
+
let open = null;
|
|
131
|
+
let last = 0;
|
|
132
|
+
let fenced = false;
|
|
133
|
+
const start = (first, t) => {
|
|
134
|
+
open = { first, text: t.trimEnd(), item: ITEM.test(t) };
|
|
135
|
+
out.push(open);
|
|
136
|
+
};
|
|
137
|
+
ls.forEach(({ text: t, line }, i) => {
|
|
138
|
+
const adjacent = line === last + 1;
|
|
139
|
+
last = line;
|
|
140
|
+
if (FENCE.test(t)) {
|
|
141
|
+
fenced = !fenced;
|
|
142
|
+
open = null;
|
|
143
|
+
} else if (fenced || SUBHEADING.test(t)) {
|
|
144
|
+
open = null;
|
|
145
|
+
} else if (isRow(t)) {
|
|
146
|
+
open = null;
|
|
147
|
+
const header = ls[i + 1] && ls[i + 1].line === line + 1 && isDivider(ls[i + 1].text);
|
|
148
|
+
if (!header && !isDivider(t)) out.push({ first: line, row: cellsOf(t) });
|
|
149
|
+
} else if (ITEM.test(t)) {
|
|
150
|
+
start(line, t);
|
|
151
|
+
} else if (open && (adjacent || (open.item && /^\s+\S/.test(t)))) {
|
|
152
|
+
open.text += ` ${t.trim()}`;
|
|
153
|
+
} else {
|
|
154
|
+
start(line, t);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return out.map((a) =>
|
|
158
|
+
a.row
|
|
159
|
+
? { first: a.first, marked: a.row.some((cell) => MARKED.test(cell)), message: `the action names in no cell ${NO_MARK}` }
|
|
160
|
+
: { first: a.first, marked: MARKED.test(a.text), message: `the action does not end with ${NO_MARK}` },
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// A Proposed actions section that proposes no action is this one line.
|
|
165
|
+
const NONE = 'None.';
|
|
166
|
+
|
|
167
|
+
// The lines of a section above its first closing line, `Skipped:` or `Not checked:`, outside a fenced
|
|
168
|
+
// block. The closing lines end the section: a closing line that wraps, or a list under it, is no action.
|
|
169
|
+
function beforeFooter(ls) {
|
|
170
|
+
let fenced = false;
|
|
171
|
+
for (let i = 0; i < ls.length; i++) {
|
|
172
|
+
if (FENCE.test(ls[i].text)) fenced = !fenced;
|
|
173
|
+
else if (!fenced && FOOTER.test(ls[i].text)) return ls.slice(0, i);
|
|
174
|
+
}
|
|
175
|
+
return ls;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// What is wrong with an ops report, one `<rel>:<line> <message>` per problem (REQ-2.13): each of the
|
|
179
|
+
// three sections present and holding a line; every slice and pull request named in the first one in
|
|
180
|
+
// the graph; every `<file>:<line>` cited in First checks a line that exists; every proposed action,
|
|
181
|
+
// whether a list item, a plain line or a table row, marked by who may take it, up to the first closing
|
|
182
|
+
// line, or the one line `None.` for no action; the two closing lines.
|
|
183
|
+
export function opsReportProblems(root, index, rel, text) {
|
|
184
|
+
const out = [];
|
|
185
|
+
const sections = reportSections(text);
|
|
186
|
+
const content = (name, closed = false) => {
|
|
187
|
+
const section = sections.get(name.toLowerCase());
|
|
188
|
+
if (!section) {
|
|
189
|
+
out.push(`${rel}:1 no "## ${name}" section`);
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
const upTo = closed ? beforeFooter(section.lines) : section.lines;
|
|
193
|
+
const held = upTo.filter((l) => l.text.trim() !== '' && !FOOTER.test(l.text));
|
|
194
|
+
if (held.length === 0) out.push(`${rel}:${section.line} the "## ${name}" section is empty`);
|
|
195
|
+
return held;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
for (const { text: l, line } of content(OPS_SECTIONS[0])) {
|
|
199
|
+
for (const addr of new Set(l.match(new RegExp(`\\b${re('sliceAddr').source}\\b`, 'g')) ?? [])) {
|
|
200
|
+
if (!index.node(`slice:${addr}`)) out.push(`${rel}:${line} ${addr} is not a slice in the graph`);
|
|
201
|
+
}
|
|
202
|
+
for (const ref of new Set([...l.matchAll(PR_REF)].map((m) => `${m[1] ?? ''}#${m[2]}`))) {
|
|
203
|
+
if (!index.find(ref)) out.push(`${rel}:${line} ${ref} is not a pull request in the graph`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const { text: l, line } of content(OPS_SECTIONS[1])) {
|
|
208
|
+
for (const m of l.matchAll(CITATION)) {
|
|
209
|
+
const file = normalisePath(m[1]);
|
|
210
|
+
if (!isCitation(root, index, file)) continue;
|
|
211
|
+
if (!lineExists(root, file, Number(m[2]))) out.push(`${rel}:${line} ${m[1]}:${m[2]} is not a line of a file in the repository`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const proposed = content(OPS_SECTIONS[2], true);
|
|
216
|
+
if (!(proposed.length === 1 && proposed[0].text.trim() === NONE)) {
|
|
217
|
+
for (const action of actions(proposed)) {
|
|
218
|
+
if (!action.marked) out.push(`${rel}:${action.first} ${action.message}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return [...out, ...footerProblems(rel, text)];
|
|
223
|
+
}
|
package/src/paths.js
CHANGED
|
@@ -11,6 +11,7 @@ export function kitPaths(root, cfg) {
|
|
|
11
11
|
baselines: path.join(kit, 'baselines'),
|
|
12
12
|
journalDir: path.join(kit, 'journal'),
|
|
13
13
|
graph: path.join(kit, 'graph'),
|
|
14
|
+
reports: path.join(kit, 'reports'),
|
|
14
15
|
workspace: path.join(kit, 'workspace.json'),
|
|
15
16
|
docs,
|
|
16
17
|
intake: path.join(docs, 'intake'),
|
package/src/reports.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The reports of `/slicekit ops` and `/slicekit audit` (REQ-2.13, REQ-2.14, D-57, D-58): where the
|
|
2
|
+
// next one goes, and how a check reads one. A report lives under .slicekit/reports, which init's
|
|
3
|
+
// ignore rules cover, so writing one changes no tracked file.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { lines } from './markdown.js';
|
|
7
|
+
import { kitPaths } from './paths.js';
|
|
8
|
+
|
|
9
|
+
const posix = (p) => p.split(path.sep).join('/');
|
|
10
|
+
const FENCE = /^\s*(```|~~~)/;
|
|
11
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
12
|
+
|
|
13
|
+
// The next free report of `kind`, relative to the root with forward slashes:
|
|
14
|
+
// `.slicekit/reports/<kind>-<k>.md`, `k` one above the highest of that kind there, else 1. The path
|
|
15
|
+
// is reserved by creating the empty file with the exclusive flag, moving to the next `k` while
|
|
16
|
+
// another run holds it, so two runs at once never get one path. Nothing else is written.
|
|
17
|
+
export function nextReport(root, cfg, kind) {
|
|
18
|
+
const dir = kitPaths(root, cfg).reports;
|
|
19
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
20
|
+
const name = new RegExp(`^${escapeRe(kind)}-(\\d+)\\.md$`);
|
|
21
|
+
let k = 1;
|
|
22
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
23
|
+
const m = name.exec(entry);
|
|
24
|
+
if (m && Number(m[1]) >= k) k = Number(m[1]) + 1;
|
|
25
|
+
}
|
|
26
|
+
for (;;) {
|
|
27
|
+
const file = path.join(dir, `${kind}-${k}.md`);
|
|
28
|
+
try {
|
|
29
|
+
fs.closeSync(fs.openSync(file, 'wx'));
|
|
30
|
+
return posix(path.relative(root, file));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e.code !== 'EEXIST') throw e;
|
|
33
|
+
k++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The `##` sections of a report outside fenced blocks: lower-case heading -> {line, lines}, `line`
|
|
39
|
+
// the heading's 1-based line and `lines` every line after it, as {text, line}, up to the next `#` or
|
|
40
|
+
// `##` heading. The first section of a name wins.
|
|
41
|
+
export function reportSections(text) {
|
|
42
|
+
const out = new Map();
|
|
43
|
+
let fenced = false;
|
|
44
|
+
let current = null;
|
|
45
|
+
lines(text).forEach((raw, i) => {
|
|
46
|
+
if (FENCE.test(raw)) {
|
|
47
|
+
fenced = !fenced;
|
|
48
|
+
} else if (!fenced) {
|
|
49
|
+
const m = /^(#{1,2})\s+(.*?)\s*#*\s*$/.exec(raw);
|
|
50
|
+
if (m) {
|
|
51
|
+
current = null;
|
|
52
|
+
const key = m[2].toLowerCase();
|
|
53
|
+
if (m[1].length === 2 && !out.has(key)) {
|
|
54
|
+
current = { line: i + 1, lines: [] };
|
|
55
|
+
out.set(key, current);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (current) current.lines.push({ text: raw, line: i + 1 });
|
|
61
|
+
});
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const isRow = (l) => /^\s*\|.*\|\s*$/.test(l);
|
|
66
|
+
export const isDivider = (l) => /^\s*\|(\s*:?-+:?\s*\|)+\s*$/.test(l);
|
|
67
|
+
// A row's cells; a `\|` is a pipe inside its cell.
|
|
68
|
+
export const cellsOf = (row) =>
|
|
69
|
+
row
|
|
70
|
+
.replace(/^\s*\|/, '')
|
|
71
|
+
.replace(/(?<!\\)\|\s*$/, '')
|
|
72
|
+
.split(/(?<!\\)\|/)
|
|
73
|
+
.map((c) => c.trim().replace(/\\\|/g, '|'));
|
|
74
|
+
|
|
75
|
+
// The first table of the section `heading`: {header: {cells, line}, rows: [{cells, line}]}, or null
|
|
76
|
+
// when the section is missing or holds no table.
|
|
77
|
+
export function sectionTable(text, heading) {
|
|
78
|
+
const section = reportSections(text).get(heading.toLowerCase());
|
|
79
|
+
if (!section) return null;
|
|
80
|
+
const ls = section.lines;
|
|
81
|
+
for (let i = 0; i + 1 < ls.length; i++) {
|
|
82
|
+
if (!isRow(ls[i].text) || !isDivider(ls[i + 1].text)) continue;
|
|
83
|
+
const rows = [];
|
|
84
|
+
for (let j = i + 2; j < ls.length && isRow(ls[j].text); j++) rows.push({ cells: cellsOf(ls[j].text), line: ls[j].line });
|
|
85
|
+
return { header: { cells: cellsOf(ls[i].text), line: ls[i].line }, rows };
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The rows of the first table of the section `heading`, the header row dropped: [{cells, line}].
|
|
91
|
+
export function reportTable(text, heading) {
|
|
92
|
+
return sectionTable(text, heading)?.rows ?? [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Whether `<file>:<line>` names a line that exists: a file under the root with at least that many lines.
|
|
96
|
+
export function lineExists(root, file, line) {
|
|
97
|
+
const abs = path.resolve(root, file);
|
|
98
|
+
const rel = path.relative(root, abs);
|
|
99
|
+
if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) return false;
|
|
100
|
+
let text;
|
|
101
|
+
try {
|
|
102
|
+
if (!fs.statSync(abs).isFile()) return false;
|
|
103
|
+
text = fs.readFileSync(abs, 'utf8');
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const all = text.split('\n');
|
|
108
|
+
const count = all.at(-1) === '' ? all.length - 1 : all.length;
|
|
109
|
+
return Number.isInteger(line) && line >= 1 && line <= count;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// One `<rel>:<line> <message>` per closing line the report lacks: `Skipped:` and `Not checked:`, each
|
|
113
|
+
// at the start of its own line.
|
|
114
|
+
export function footerProblems(rel, text) {
|
|
115
|
+
const all = lines(text);
|
|
116
|
+
const last = Math.max(1, all.at(-1) === '' ? all.length - 1 : all.length);
|
|
117
|
+
return ['Skipped:', 'Not checked:'].filter((label) => !all.some((l) => l.startsWith(label))).map((label) => `${rel}:${last} no "${label}" line`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The text of a report named on the command line, with its path as the messages print it. A path
|
|
121
|
+
// that is no file is `null` text.
|
|
122
|
+
export function readReport(root, given) {
|
|
123
|
+
const abs = path.resolve(root, given);
|
|
124
|
+
const rel = posix(path.relative(root, abs));
|
|
125
|
+
try {
|
|
126
|
+
return { rel, text: fs.readFileSync(abs, 'utf8').replace(/^/, '') };
|
|
127
|
+
} catch (e) {
|
|
128
|
+
if (e.code === 'ENOENT' || e.code === 'EISDIR') return { rel, text: null };
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ops
|
|
3
|
-
description: Reads the runbook and history for a symptom and
|
|
4
|
-
tools: Read, Grep, Glob
|
|
3
|
+
description: Reads the runbook and history for a symptom and replies with a proposed-actions report; changes nothing.
|
|
4
|
+
tools: Read, Grep, Glob
|
|
5
5
|
model: inherit
|
|
6
6
|
---
|
|
7
|
-
Brief: run `{{cli}} instructions ops` and follow it.
|
|
7
|
+
Brief: run `{{cli}} instructions ops` and follow it. The start hook gives you that brief, since you hold no tool that runs a command or writes a file. Your reply is the report; you take no action you propose. End every reply with "Skipped:" and "Not checked:" lines.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Brief: auditor
|
|
2
2
|
|
|
3
|
-
You compare what the documents claim with what the code, the tests and the CI history show, or, in gap mode, what the spec claims with what the intake and the decisions support. Every finding carries a citation on both sides: the claim's file and line, and the evidence's file and line, command or CI run.
|
|
3
|
+
You compare what the documents claim with what the code, the tests and the CI history show, or, in gap mode, what the spec claims with what the intake and the decisions support. Every finding carries a citation on both sides: the claim's file and line, and the evidence's file and line, command or CI run. In gap mode the command commits what you record; an audit report is never committed.
|
|
4
4
|
|
|
5
5
|
## You write
|
|
6
6
|
|
|
7
7
|
- In an audit, a report at the path the command gives you, with one row per claim: the claim, where it is written, the evidence, where it was found, and its status.
|
|
8
|
-
- The status is one of three words. `holds`: the evidence agrees with the claim. `drifted`: the evidence contradicts it; name the commit that broke it,
|
|
8
|
+
- The status is one of three words. `holds`: the evidence agrees with the claim. `drifted`: the evidence contradicts it; name the commit that broke it, one of the claim's candidate commits. `unverifiable`: you found no evidence either way; say why.
|
|
9
9
|
- In gap mode, nothing but the rows you record with `{{cli}} gaps add` (see Gaps below). You write no file of your own.
|
|
10
10
|
|
|
11
11
|
## You never
|
|
@@ -14,6 +14,17 @@ You compare what the documents claim with what the code, the tests and the CI hi
|
|
|
14
14
|
- Change the documents you audit. In an audit the gap goes in your report; in gap mode it goes in through `{{cli}} gaps add`.
|
|
15
15
|
- Run git, except the read-only `git diff`, `git log`, `git show` and `git status`. You never commit or push; the command does that.
|
|
16
16
|
|
|
17
|
+
## Audit
|
|
18
|
+
|
|
19
|
+
In an audit the command gives you the report path and the claims, each with its ID, its `<file>:<line>`, the files it names and its candidate commits: those that touched one of those files after the claim was written. The report holds one table under `## Claims`, one row per claim:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
| Claim | Where | Evidence | Found at | Status | Commit |
|
|
23
|
+
|---|---|---|---|---|---|
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Claim and Where are as the command printed them. Found at is the evidence's `<file>:<line>` or a command in backticks; an `unverifiable` row may leave it empty. Commit is empty unless the row is `drifted`: a `drifted` row names one of its claim's candidate commits, by seven or more characters of its SHA. When no candidate explains the contradiction, the row is `unverifiable`. The report ends with the same two closing lines as your reply.
|
|
27
|
+
|
|
17
28
|
## Gaps
|
|
18
29
|
|
|
19
30
|
When `/slicekit gaps` spawns you, you are in gap mode: the claims are the spec under `<docsRoot>/spec/` and the evidence is the intake snapshots under `<docsRoot>/intake/` and `<docsRoot>/decisions.md`. You look for gaps between them. Each gap is one of five classes:
|
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
# Brief: ops
|
|
2
2
|
|
|
3
|
-
You triage one symptom.
|
|
3
|
+
You triage one symptom. The command gives you the symptom and its context: the files the symptom names, the history of those files (the slices and pull requests that touched them, each with its verdict and release), and the paths of the runbook, `observability.md` and the last release record. You read those three files and return proposed actions. You change nothing: you hold no tool that writes a file or runs a command.
|
|
4
4
|
|
|
5
5
|
## You write
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
No file. Your reply is the report, and the command saves it as you wrote it. It holds these three sections, under these headings:
|
|
8
8
|
|
|
9
|
-
1.
|
|
10
|
-
2.
|
|
11
|
-
3.
|
|
9
|
+
1. `## Likely slices and pull requests`: one line per slice, with its address, its pull request as `#<n>` and the files that tie it to the symptom. Name only slices and pull requests the history you were given lists.
|
|
10
|
+
2. `## First checks`: the runbook's first checks for this symptom, each quoted with its `<file>:<line>`. A check from `observability.md` or the release record carries its `<file>:<line>` the same way. When the runbook holds no check for the symptom, say so in one line.
|
|
11
|
+
3. `## Proposed actions`: one list item per action, each ending with a mark of who may take it: `(anyone)`, `(on-call)`, or `(owner: <name>)` with the owner the runbook names. When you propose no action, the section holds the one line `None.` and nothing else.
|
|
12
|
+
|
|
13
|
+
A reply in this shape passes the check:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
## Likely slices and pull requests
|
|
17
|
+
|
|
18
|
+
- P1/S-01, #1: src/billing/charge.js, src/billing/refund.js
|
|
19
|
+
|
|
20
|
+
## First checks
|
|
21
|
+
|
|
22
|
+
- docs/runbook.md:14 When billing returns 500, read the charge and refund code first.
|
|
23
|
+
|
|
24
|
+
## Proposed actions
|
|
25
|
+
|
|
26
|
+
- Read the service's log for the failing request (anyone)
|
|
27
|
+
- Revert pull request #1 on the host (on-call)
|
|
28
|
+
- Ask whether the charge limits changed (owner: Dana)
|
|
29
|
+
|
|
30
|
+
Skipped: the release record
|
|
31
|
+
Not checked: the service's log
|
|
32
|
+
```
|
|
12
33
|
|
|
13
34
|
## You never
|
|
14
35
|
|
|
15
|
-
- Change infrastructure, configuration, data or
|
|
16
|
-
- Take an action you propose, even one marked `anyone`.
|
|
17
|
-
- Run git
|
|
36
|
+
- Change infrastructure, configuration, data, code or any document.
|
|
37
|
+
- Take an action you propose, even one marked `(anyone)`.
|
|
38
|
+
- Run git or any other command. You never commit, push or revert.
|
|
18
39
|
|
|
19
40
|
## Your report
|
|
20
41
|
|
|
21
|
-
Your reply
|
|
42
|
+
Your reply holds the report and nothing before it. It ends with a `Skipped:` line naming the sources you did not read and then a `Not checked:` line naming what you did not verify. Each of these lines starts at the beginning of its line, with no list marker, bold or backticks. The two lines end the Proposed actions section: nothing from the `Skipped:` line on is read as an action, so write every action above it. A reply without both lines is refused when you stop.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# /slicekit audit
|
|
2
|
+
|
|
3
|
+
Compare what the spec and the runbook claim with what the code, the tests and the CI history show,
|
|
4
|
+
and list each claim as `holds`, `drifted` or `unverifiable` (REQ-2.14). The area: {{args}}.
|
|
5
|
+
|
|
6
|
+
The area is a spec file's name without `.md`, a REQ prefix such as `REQ-2`, the word `runbook`, or
|
|
7
|
+
a path; `(none)` means every claim. This command changes no tracked file. Its report goes under
|
|
8
|
+
`.slicekit/reports/`, which the project's ignore rules cover, and is never committed. Every step
|
|
9
|
+
that reads the repository's history goes through `{{cli}}`; run no git or gh command yourself.
|
|
10
|
+
|
|
11
|
+
## Steps
|
|
12
|
+
|
|
13
|
+
1. Run `{{cli}} graph`, so the files the claims name are read from the latest history.
|
|
14
|
+
2. Run `{{cli}} audit context {{args}}`; when the area is `(none)`, leave it out and run the command
|
|
15
|
+
with no area. Its first line is the report path. Then, for each claim in the area (each REQ block
|
|
16
|
+
of the spec, each `##` section of the runbook), it prints the claim's ID, its `<file>:<line>` and
|
|
17
|
+
its title, the files the claim names, and one `candidate` line for each commit that touched one of
|
|
18
|
+
those files after the claim's heading was last changed. It prints at most ten `candidate` lines
|
|
19
|
+
for a claim, the newest, then one line that counts the older ones and names the area to run with
|
|
20
|
+
`--all` to print them. On exit 2 the area names no claim: print what it says and ask the human
|
|
21
|
+
for another area.
|
|
22
|
+
3. Spawn the auditor in audit mode. Its brief is the output of `{{cli}} instructions auditor`. Give
|
|
23
|
+
it the whole output of step 2 and the report path, and tell it this is an audit, not a gap scan:
|
|
24
|
+
the claims are the ones listed, and the evidence is the code, the tests and the CI history. The
|
|
25
|
+
auditor writes the report at that path. Step 2 created that path as an empty file, so tell the
|
|
26
|
+
auditor to read it with the Read tool before the first write, or the Write tool refuses to
|
|
27
|
+
overwrite it.
|
|
28
|
+
4. Run `{{cli}} audit check <report> {{args}} --every-claim`, with the same area as step 2 or none.
|
|
29
|
+
The check reads the area's claims from the spec and the runbook, as step 2 did. It prints
|
|
30
|
+
`ok <report>`, or one `<report>:<line> <message>` line per problem: a missing `## Claims` table,
|
|
31
|
+
a row for a claim that is not in the area, a claim of the area with no row, a claim with two
|
|
32
|
+
rows, a status that is not one of the three words, a
|
|
33
|
+
`drifted` row whose commit is not one of its claim's candidates. On findings, send them to the
|
|
34
|
+
auditor once and run the check again. When the check still finds a problem, print the findings
|
|
35
|
+
with the report path and go on to step 5.
|
|
36
|
+
5. Print the report path and the count of rows for each status. Tell the human that the audit
|
|
37
|
+
changed nothing: each `drifted` row becomes a slice or a decision, by their hand, and each
|
|
38
|
+
`unverifiable` row is a claim with no test or check behind it.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# /slicekit ops
|
|
2
|
+
|
|
3
|
+
Triage one symptom: find the slices and pull requests that touched the files it names, the
|
|
4
|
+
runbook's first checks for it, and the actions someone could take, each marked by who may take it
|
|
5
|
+
(REQ-2.13). The symptom: {{args}}.
|
|
6
|
+
|
|
7
|
+
This command takes no action and changes no tracked file. Its report goes under
|
|
8
|
+
`.slicekit/reports/`, which the project's ignore rules cover, and is never committed. Every step
|
|
9
|
+
that reads the repository's history goes through `{{cli}}`; run no git or gh command yourself.
|
|
10
|
+
|
|
11
|
+
When the symptom is `(none)`, ask the human for it and stop until they answer.
|
|
12
|
+
|
|
13
|
+
## Steps
|
|
14
|
+
|
|
15
|
+
1. Run `{{cli}} graph`, so the history the next step reads holds the latest merged pull requests.
|
|
16
|
+
2. Run `{{cli}} ops context "{{args}}"`, with the symptom in one pair of double quotes and any
|
|
17
|
+
double quote, backquote or dollar sign inside it removed. Its first line is the report path.
|
|
18
|
+
The rest names the files the symptom's words match, the history of those files, the runbook,
|
|
19
|
+
`observability.md` and the last release record.
|
|
20
|
+
- On exit 1 the symptom names no file in the graph. Ask the human which file, directory or
|
|
21
|
+
service is meant, then run the command again with `--path <path>` for each one they name.
|
|
22
|
+
- A `too broad:` line names a word that matches more than fifty files and was not expanded. Tell
|
|
23
|
+
the human; when that word is the one they meant, ask for a narrower path and add it with
|
|
24
|
+
`--path`.
|
|
25
|
+
3. Spawn the ops agent. Its brief is the output of `{{cli}} instructions ops`. Give it the symptom
|
|
26
|
+
and the whole output of step 2, and tell it to read the runbook, `observability.md` and the
|
|
27
|
+
release record that output names. The agent holds no tool that writes a file or runs a command:
|
|
28
|
+
its reply is the report.
|
|
29
|
+
4. Write the agent's reply, as it is, to the report path from step 2 with the Write tool. Change no
|
|
30
|
+
word of it. Step 2 created that path as an empty file, so read it with the Read tool before the
|
|
31
|
+
first write, or the Write tool refuses to overwrite it.
|
|
32
|
+
5. Run `{{cli}} ops check <report>`. It prints `ok <report>`, or one `<report>:<line> <message>`
|
|
33
|
+
line per problem: a missing section, a slice or pull request the graph does not hold, a cited
|
|
34
|
+
`<file>:<line>` that does not exist, an action marked by no one. On findings, send them to the
|
|
35
|
+
agent once, write its new reply to the same path and run the check again. When the check still
|
|
36
|
+
finds a problem, print the findings with the report path and go on to step 6.
|
|
37
|
+
6. Print the report path and the report's `## Proposed actions` section. Tell the human that no
|
|
38
|
+
action was taken: each proposed action is theirs, or the named owner's, to take.
|