slicekit 0.1.2 → 0.2.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 +15 -13
- package/package.json +3 -2
- package/src/adapters/githost/fixture.js +24 -1
- package/src/adapters/githost/gh-json.js +69 -2
- package/src/adapters/githost/github.js +16 -1
- package/src/build/commit.js +152 -26
- package/src/build/config.js +50 -0
- package/src/build/pr.js +30 -15
- package/src/build/record.js +8 -2
- package/src/build/red.js +4 -3
- package/src/build/render.js +155 -0
- package/src/build/verdict.js +29 -0
- package/src/build/worktree.js +26 -5
- package/src/check/ci-event.js +17 -0
- package/src/check/rules/citations.js +53 -2
- package/src/check/rules/commands.js +32 -4
- package/src/check/rules/trailer.js +5 -16
- package/src/check/rules/workspace.js +86 -0
- package/src/cli/build.js +34 -8
- package/src/cli/ci.js +150 -0
- package/src/cli/decide.js +4 -3
- package/src/cli/gaps.js +6 -5
- package/src/cli/graph.js +79 -0
- package/src/cli/history.js +17 -0
- package/src/cli/hook.js +1 -1
- package/src/cli/impact.js +17 -0
- package/src/cli/index.js +28 -3
- package/src/cli/instructions.js +1 -1
- package/src/cli/intake.js +3 -3
- package/src/cli/query.js +39 -0
- package/src/cli/shipped.js +32 -0
- package/src/cli/state.js +42 -2
- package/src/cli/trace.js +21 -0
- package/src/cli/uncovered.js +32 -0
- package/src/cli/visualize.js +88 -0
- package/src/cli/workflow.js +6 -2
- package/src/config.js +85 -0
- package/src/graph/build.js +312 -0
- package/src/graph/docs.js +241 -0
- package/src/graph/git-walk.js +91 -0
- package/src/graph/history.js +60 -0
- package/src/graph/impact.js +143 -0
- package/src/graph/kitfiles.js +60 -0
- package/src/graph/load.js +93 -0
- package/src/graph/prs.js +136 -0
- package/src/graph/render.js +28 -0
- package/src/graph/schema.js +108 -0
- package/src/graph/shipped.js +32 -0
- package/src/graph/tests.js +45 -0
- package/src/graph/trace.js +83 -0
- package/src/graph/uncovered.js +16 -0
- package/src/graph/workspace.js +188 -0
- package/src/hook-cli.js +1 -1
- package/src/init.js +2 -0
- package/src/instructions.js +26 -8
- package/src/state/index.js +35 -4
- package/src/verdict.js +14 -2
- package/src/visualize/client.js +489 -0
- package/src/visualize/page.js +100 -0
- package/src/visualize/server.js +46 -0
- package/src/workflow.js +87 -9
- package/templates/instructions/agents/reviewer.md +7 -7
- package/templates/instructions/commands/build.md +34 -4
- package/templates/workflow/pins.json +2 -1
- package/templates/workflow/slicekit.yml +32 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// workspace (04 REQ-4.6's Enforced by, D-47, D-48): a slice file's `repo:` is `.` or names an entry
|
|
2
|
+
// of the workspace file; a contract names at least one producer and one consumer. A party that is a
|
|
3
|
+
// slice is named by its address; one outside the program is named in words, so any text will do.
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { keyedText, partyOf } from '../../graph/docs.js';
|
|
6
|
+
import { GraphError } from '../../graph/schema.js';
|
|
7
|
+
import { readWorkspace, workspaceRel } from '../../graph/workspace.js';
|
|
8
|
+
import { re } from '../../ids.js';
|
|
9
|
+
import { frontMatter } from '../../markdown.js';
|
|
10
|
+
import { findSliceFiles } from '../../slicefile.js';
|
|
11
|
+
|
|
12
|
+
export const id = 'workspace';
|
|
13
|
+
export const blocking = true;
|
|
14
|
+
export const ratchet = false;
|
|
15
|
+
|
|
16
|
+
const toPosix = (p) => p.split(path.sep).join('/');
|
|
17
|
+
const SLICE = new RegExp(`^${re('sliceAddr').source}$`);
|
|
18
|
+
|
|
19
|
+
// The 1-based line of the front-matter key `repo:`, or 1.
|
|
20
|
+
function repoLine(text) {
|
|
21
|
+
const ls = String(text).replace(/\r\n/g, '\n').split('\n');
|
|
22
|
+
if (ls[0]?.replace(/^/, '') !== '---') return 1;
|
|
23
|
+
for (let i = 1; i < ls.length && ls[i] !== '---'; i++) if (/^repo:/.test(ls[i])) return i + 1;
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function slices(ctx) {
|
|
28
|
+
const rel = workspaceRel(ctx.root, ctx.cfg);
|
|
29
|
+
let workspace;
|
|
30
|
+
try {
|
|
31
|
+
workspace = readWorkspace(ctx.root, ctx.cfg);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (!(e instanceof GraphError)) throw e;
|
|
34
|
+
return [{ file: rel, line: 1, message: e.message }];
|
|
35
|
+
}
|
|
36
|
+
const names = new Set((workspace?.repos ?? []).map((r) => r.name));
|
|
37
|
+
const byRel = new Map(ctx.docs.map((d) => [d.rel, d]));
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const f of findSliceFiles(ctx.root, ctx.cfg)) {
|
|
40
|
+
const file = toPosix(path.relative(ctx.root, f.path));
|
|
41
|
+
const text = byRel.get(file)?.text;
|
|
42
|
+
if (text === undefined) continue;
|
|
43
|
+
// Only the two keys are read, so a slice file malformed elsewhere (the citations rule's to report)
|
|
44
|
+
// is still judged on its repo.
|
|
45
|
+
let data;
|
|
46
|
+
try {
|
|
47
|
+
data = frontMatter(text).data ?? {};
|
|
48
|
+
} catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const s = { id: String(data.slice ?? ''), repo: data.repo };
|
|
52
|
+
if (!SLICE.test(s.id) || typeof s.repo !== 'string' || s.repo === '') continue;
|
|
53
|
+
if (s.repo === '.' || names.has(s.repo)) continue;
|
|
54
|
+
const why = workspace ? `, which ${rel} does not list` : '; there is no workspace file';
|
|
55
|
+
out.push({ file, line: repoLine(text), message: `slice ${s.id} names repo ${s.repo}${why}` });
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const CONTRACT = new RegExp(`^(${re('contract').source})-.*\\.md$`);
|
|
61
|
+
// Text that names someone: anything but spaces and punctuation.
|
|
62
|
+
const namesSomeone = (text) => /[\p{L}\p{N}]/u.test(text);
|
|
63
|
+
|
|
64
|
+
function contracts(ctx) {
|
|
65
|
+
const dir = toPosix(path.relative(ctx.root, ctx.paths.contracts));
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const doc of ctx.docs) {
|
|
68
|
+
if (path.posix.dirname(doc.rel) !== dir) continue;
|
|
69
|
+
const m = CONTRACT.exec(path.posix.basename(doc.rel));
|
|
70
|
+
if (!m) continue;
|
|
71
|
+
const said = { produces: false, consumes: false };
|
|
72
|
+
for (const seg of keyedText(doc.text)) {
|
|
73
|
+
const kind = partyOf(seg.key);
|
|
74
|
+
if (kind && namesSomeone(seg.text)) said[kind] = true;
|
|
75
|
+
}
|
|
76
|
+
if (!said.produces) out.push({ file: doc.rel, line: 1, message: `${m[1]} names no producer` });
|
|
77
|
+
if (!said.consumes) out.push({ file: doc.rel, line: 1, message: `${m[1]} names no consumer` });
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function run(ctx) {
|
|
83
|
+
return [...slices(ctx), ...contracts(ctx)];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default { id, blocking, ratchet, run };
|
package/src/cli/build.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// lands with its task; S-15 and S-16 add theirs.
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { ConfigError, loadConfig } from '../config.js';
|
|
5
|
+
import { ConfigError, loadConfig, localNote } from '../config.js';
|
|
6
6
|
import { GitError } from '../git.js';
|
|
7
7
|
import { getHost } from '../adapters/githost/index.js';
|
|
8
8
|
import { GitHostError } from '../adapters/githost/errors.js';
|
|
@@ -13,20 +13,22 @@ import { SliceFileError } from '../slicefile.js';
|
|
|
13
13
|
import { LockError, TransitionError } from '../state/index.js';
|
|
14
14
|
import { runnable, waiting } from '../build/order.js';
|
|
15
15
|
import { amend, commitWork } from '../build/commit.js';
|
|
16
|
+
import { configSlice } from '../build/config.js';
|
|
16
17
|
import { declineFinding } from '../build/decline.js';
|
|
17
18
|
import { finish } from '../build/finish.js';
|
|
18
19
|
import { startParallel } from '../build/parallel.js';
|
|
19
20
|
import { openSlicePr } from '../build/pr.js';
|
|
20
21
|
import { red } from '../build/red.js';
|
|
22
|
+
import { renderSlice } from '../build/render.js';
|
|
21
23
|
import { syncWorktree } from '../build/sync.js';
|
|
22
24
|
import { LOOP_ROUNDS, latestVerdictPath, recordVerdict } from '../build/verdict.js';
|
|
23
25
|
import { BuildError, startSlice } from '../build/worktree.js';
|
|
24
26
|
import { readSlice } from '../state/index.js';
|
|
25
27
|
import { INDEPENDENT_MISSING } from '../state/transitions.js';
|
|
26
28
|
|
|
27
|
-
const SUBCOMMANDS = ['next', 'start', 'red', 'commit', 'amend', 'pr', 'verdict', 'decline', 'finish', 'sync', 'parallel'];
|
|
29
|
+
const SUBCOMMANDS = ['next', 'start', 'red', 'commit', 'render', 'config', 'amend', 'pr', 'verdict', 'decline', 'finish', 'sync', 'parallel'];
|
|
28
30
|
const USAGE =
|
|
29
|
-
'build next | build start <id> [--descr <d>] | build parallel P<n> | build red <id> --tests <a,b> [--worktree <p>] | build commit <id> --message <m> [--require-green] [--worktree <p>] | build amend <id> --test <path> --reason <r> [--worktree <p>] | build pr <id> [--notes <file>] [--worktree <p>] | build verdict <id> <file> [--independent] [--worktree <p>] | build decline <id> <H-n> [--worktree <p>] | build finish <id> [--wait <s>, default 90] [--worktree <p>] | build sync <id> [--worktree <p>]';
|
|
31
|
+
'build next | build start <id> [--descr <d>] | build parallel P<n> | build red <id> --tests <a,b> [--worktree <p>] | build commit <id> --message <m> [--require-green] [--worktree <p>] | build render <id> [--worktree <p>] | build config <id> [--worktree <p>] | build amend <id> --test <path> --reason <r> [--worktree <p>] | build pr <id> [--notes <file>] [--worktree <p>] | build verdict <id> <file> [--independent] [--worktree <p>] | build decline <id> <H-n> [--worktree <p>] | build finish <id> [--wait <s>, default 90] [--worktree <p>] | build sync <id> [--worktree <p>]';
|
|
30
32
|
|
|
31
33
|
const OPTIONS = {
|
|
32
34
|
descr: { type: 'string' },
|
|
@@ -97,7 +99,8 @@ function parallel(root, io, positionals) {
|
|
|
97
99
|
function redStep(root, io, positionals, values) {
|
|
98
100
|
if (positionals.length !== 1 || values.tests === undefined) return usage(io);
|
|
99
101
|
const cfg = loadConfig(root);
|
|
100
|
-
const { commit } = red(root, cfg, positionals[0], { tests: values.tests, worktree: values.worktree });
|
|
102
|
+
const { commit, local } = red(root, cfg, positionals[0], { tests: values.tests, worktree: values.worktree, env: io.env ?? process.env });
|
|
103
|
+
if (local) io.stderr(`${localNote(local)}\n`);
|
|
101
104
|
io.stdout(`${commit}\ntests-red → building\n`);
|
|
102
105
|
return 0;
|
|
103
106
|
}
|
|
@@ -105,15 +108,35 @@ function redStep(root, io, positionals, values) {
|
|
|
105
108
|
function commitStep(root, io, positionals, values) {
|
|
106
109
|
if (positionals.length !== 1 || values.message === undefined) return usage(io);
|
|
107
110
|
const cfg = loadConfig(root);
|
|
108
|
-
const { sha, exit } = commitWork(root, cfg, positionals[0], {
|
|
111
|
+
const { sha, exit, local } = commitWork(root, cfg, positionals[0], {
|
|
109
112
|
message: values.message,
|
|
110
113
|
requireGreen: Boolean(values['require-green']),
|
|
111
114
|
worktree: values.worktree,
|
|
115
|
+
env: io.env ?? process.env,
|
|
112
116
|
});
|
|
117
|
+
if (local) io.stderr(`${localNote(local)}\n`);
|
|
113
118
|
io.stdout(sha === null ? 'nothing to commit\n' : `${sha.slice(0, 7)} exit ${exit}\n`);
|
|
114
119
|
return 0;
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
// Prints the render commit's short SHA, or that the worktree already holds this kit's render.
|
|
123
|
+
function renderStep(root, io, positionals, values) {
|
|
124
|
+
if (positionals.length !== 1) return usage(io);
|
|
125
|
+
const cfg = loadConfig(root);
|
|
126
|
+
const { sha, files } = renderSlice(root, cfg, positionals[0], { worktree: values.worktree });
|
|
127
|
+
io.stdout(sha === null ? 'nothing to render\n' : `${sha.slice(0, 7)} render (${files.length} files)\n`);
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Prints the config commit's short SHA, or that the worktree's config has no change.
|
|
132
|
+
function configStep(root, io, positionals, values) {
|
|
133
|
+
if (positionals.length !== 1) return usage(io);
|
|
134
|
+
const cfg = loadConfig(root);
|
|
135
|
+
const { sha } = configSlice(root, cfg, positionals[0], { worktree: values.worktree });
|
|
136
|
+
io.stdout(sha === null ? 'nothing to commit\n' : `${sha.slice(0, 7)} config\n`);
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
117
140
|
function amendStep(root, io, positionals, values) {
|
|
118
141
|
if (positionals.length !== 1 || values.test === undefined || values.reason === undefined) return usage(io);
|
|
119
142
|
const cfg = loadConfig(root);
|
|
@@ -126,9 +149,12 @@ function prStep(root, io, positionals, values) {
|
|
|
126
149
|
if (positionals.length !== 1) return usage(io);
|
|
127
150
|
const cfg = loadConfig(root);
|
|
128
151
|
const host = getHost(cfg, io.env ?? process.env, root);
|
|
129
|
-
const { number, url, verdictPath } = openSlicePr(root, cfg, host, positionals[0], { notes: values.notes, worktree: values.worktree });
|
|
152
|
+
const { number, url, verdictPath, local, movedHead } = openSlicePr(root, cfg, host, positionals[0], { notes: values.notes, worktree: values.worktree, env: io.env ?? process.env });
|
|
153
|
+
if (local) io.stderr(`${localNote(local)}\n`);
|
|
130
154
|
// Last, the path the next reviewer writes; none once the loop's rounds are used.
|
|
131
|
-
|
|
155
|
+
// A head recorded at draft-pr: the verdict path again, for a review of that head.
|
|
156
|
+
const moved = movedHead ? `head ${movedHead} recorded; the next verdict reviews it\n` : '';
|
|
157
|
+
io.stdout(`#${number} ${url}\n${moved}${verdictPath ? `verdict ${verdictPath}\n` : ''}`);
|
|
132
158
|
return 0;
|
|
133
159
|
}
|
|
134
160
|
|
|
@@ -194,7 +220,7 @@ function syncStep(root, io, positionals, values) {
|
|
|
194
220
|
return 0;
|
|
195
221
|
}
|
|
196
222
|
|
|
197
|
-
const HANDLERS = { next, start, parallel, red: redStep, commit: commitStep, amend: amendStep, pr: prStep, verdict: verdictStep, decline: declineStep, finish: finishStep, sync: syncStep };
|
|
223
|
+
const HANDLERS = { next, start, parallel, red: redStep, commit: commitStep, render: renderStep, config: configStep, amend: amendStep, pr: prStep, verdict: verdictStep, decline: declineStep, finish: finishStep, sync: syncStep };
|
|
198
224
|
|
|
199
225
|
function usage(io) {
|
|
200
226
|
io.stderr(`usage: slicekit ${USAGE}\n`);
|
package/src/cli/ci.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// `slicekit ci bookkeeping` (REQ-3.11, D-49): whether the commits of a pull request push change only
|
|
2
|
+
// the kit's own bookkeeping, by the D-35 rule `build finish` uses (headCovers). It prints one line,
|
|
3
|
+
// `bookkeeping <base>..<head>` or `code <base>..<head>` (or `code (<why>)`), and exits 0 either way:
|
|
4
|
+
// the gate turns the first word into a job output and the team command jobs run unless it is
|
|
5
|
+
// `bookkeeping`. Any doubt is `code`, so the tests run.
|
|
6
|
+
//
|
|
7
|
+
// Without --base the base is found (findGreenBase): the newest commit of the pull request, from the
|
|
8
|
+
// head back over commits not on the base branch, whose newest decided run of THIS workflow ran every
|
|
9
|
+
// team command job to success. A commit's decided run is its newest slicekit pull_request run whose
|
|
10
|
+
// command jobs passed or failed (the hosts' slicekitRun, issue #52): a run still in progress, such as
|
|
11
|
+
// the current run on an `edited` event, and a run whose command jobs were all skipped (a bookkeeping
|
|
12
|
+
// run) or cancelled are passed over, so a head that passed before is its own base. Another
|
|
13
|
+
// workflow's green run never makes a base; a decided run whose command jobs failed ends the walk. The base must also contain the base branch's current tip: the green run tested the head
|
|
14
|
+
// merged with the base branch as it was then, and a base branch that moved since makes a merge no run
|
|
15
|
+
// has tested. github.event.before is never trusted: its run may have failed or been cancelled.
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import { parseArgs } from 'node:util';
|
|
18
|
+
import { getHost } from '../adapters/githost/index.js';
|
|
19
|
+
import { GitHostError } from '../adapters/githost/errors.js';
|
|
20
|
+
import { commandJobsVerdict } from '../adapters/githost/gh-json.js';
|
|
21
|
+
import { loadConfig } from '../config.js';
|
|
22
|
+
import { isSha } from '../evidence.js';
|
|
23
|
+
import { GitError, git, resolveCommit } from '../git.js';
|
|
24
|
+
import { headCovers } from '../state/covers.js';
|
|
25
|
+
|
|
26
|
+
const USAGE = 'ci bookkeeping [--base <sha>] [--head <sha>] [--base-branch <branch>] [--output <file>]';
|
|
27
|
+
// How far back the walk for a green commit goes; each commit is one git host call, and one more for
|
|
28
|
+
// each completed run it judges, newest first, until one is decided.
|
|
29
|
+
export const BASE_WALK_LIMIT = 20;
|
|
30
|
+
const BRANCH = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
|
|
31
|
+
|
|
32
|
+
const short = (sha) => sha.slice(0, 7);
|
|
33
|
+
|
|
34
|
+
function commitOf(root, ref) {
|
|
35
|
+
try {
|
|
36
|
+
return isSha(ref) || ref === 'HEAD' ? resolveCommit(root, ref) : null;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if (e instanceof GitError) return null;
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The base branch's tip in the clone: the remote-tracking ref CI fetched, else the local branch.
|
|
44
|
+
function branchTip(root, branch) {
|
|
45
|
+
if (!BRANCH.test(branch)) return null;
|
|
46
|
+
for (const ref of [`refs/remotes/origin/${branch}`, `refs/heads/${branch}`]) {
|
|
47
|
+
try {
|
|
48
|
+
return git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (!(e instanceof GitError)) throw e;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// { base } for the newest green commit of the pull request, or { why } when there is none.
|
|
57
|
+
export function findGreenBase(root, head, { baseBranch, env = process.env } = {}) {
|
|
58
|
+
let cfg;
|
|
59
|
+
try {
|
|
60
|
+
cfg = loadConfig(root);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return { why: `no config: ${e.message}` };
|
|
63
|
+
}
|
|
64
|
+
const branch = baseBranch || cfg.defaultBranch;
|
|
65
|
+
const tip = branchTip(root, branch);
|
|
66
|
+
if (!tip) return { why: `no base branch ${branch} in the clone` };
|
|
67
|
+
let commits;
|
|
68
|
+
try {
|
|
69
|
+
const out = git(root, ['rev-list', `--max-count=${BASE_WALK_LIMIT}`, head, `^${tip}`]);
|
|
70
|
+
commits = out === '' ? [] : out.split('\n');
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (e instanceof GitError) return { why: 'cannot list the pull request commits' };
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
let base = null;
|
|
76
|
+
try {
|
|
77
|
+
const host = getHost(cfg, env, root);
|
|
78
|
+
for (const sha of commits) {
|
|
79
|
+
const found = host.slicekitRun(sha);
|
|
80
|
+
const verdict = found ? commandJobsVerdict(found.run, found.jobs) : 'other';
|
|
81
|
+
if (verdict === 'failed') return { why: `the team command jobs failed on ${short(sha)}` };
|
|
82
|
+
if (verdict === 'passed') {
|
|
83
|
+
base = sha;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (e instanceof GitHostError || e instanceof GitError) return { why: `git host: ${e.message}` };
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
if (!base) return { why: `no commit of the last ${commits.length} whose team command jobs passed` };
|
|
92
|
+
try {
|
|
93
|
+
git(root, ['merge-base', '--is-ancestor', tip, base]);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
if (e instanceof GitError) return { why: `${branch} moved since ${short(base)} was tested` };
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
return { base };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The decision as { kind, line }.
|
|
102
|
+
export function judgeBookkeeping(root, { base, head = 'HEAD', baseBranch, env = process.env } = {}) {
|
|
103
|
+
const code = (why) => ({ kind: 'code', line: `code (${why})` });
|
|
104
|
+
if (!head) return code('no head');
|
|
105
|
+
const h = commitOf(root, head);
|
|
106
|
+
if (!h) return code(`head ${head} is not a commit in the clone`);
|
|
107
|
+
let b;
|
|
108
|
+
if (base === undefined) {
|
|
109
|
+
const found = findGreenBase(root, h, { baseBranch, env });
|
|
110
|
+
if (!found.base) return code(found.why);
|
|
111
|
+
b = found.base;
|
|
112
|
+
} else {
|
|
113
|
+
if (base === '' || /^0+$/.test(base)) return code('no base');
|
|
114
|
+
b = commitOf(root, base);
|
|
115
|
+
if (!b) return code(`base ${base} is not a commit in the clone`);
|
|
116
|
+
}
|
|
117
|
+
const kind = headCovers(root, b, h) ? 'bookkeeping' : 'code';
|
|
118
|
+
return { kind, line: `${kind} ${short(b)}..${short(h)}` };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function run(args, io) {
|
|
122
|
+
let parsed;
|
|
123
|
+
try {
|
|
124
|
+
parsed = parseArgs({
|
|
125
|
+
args,
|
|
126
|
+
options: { base: { type: 'string' }, head: { type: 'string' }, 'base-branch': { type: 'string' }, output: { type: 'string' } },
|
|
127
|
+
allowPositionals: true,
|
|
128
|
+
});
|
|
129
|
+
} catch (e) {
|
|
130
|
+
io.stderr(`slicekit: ${e.message}\nusage: slicekit ${USAGE}\n`);
|
|
131
|
+
return 2;
|
|
132
|
+
}
|
|
133
|
+
const { values, positionals } = parsed;
|
|
134
|
+
if (positionals.length !== 1 || positionals[0] !== 'bookkeeping') {
|
|
135
|
+
io.stderr(`usage: slicekit ${USAGE}\n`);
|
|
136
|
+
return 2;
|
|
137
|
+
}
|
|
138
|
+
const { kind, line } = judgeBookkeeping(io.cwd, {
|
|
139
|
+
base: values.base,
|
|
140
|
+
head: values.head ?? 'HEAD',
|
|
141
|
+
baseBranch: values['base-branch'],
|
|
142
|
+
env: io.env ?? process.env,
|
|
143
|
+
});
|
|
144
|
+
io.stdout(`${line}\n`);
|
|
145
|
+
// The gate's job output: GitHub's step output file, named by the workflow, never read from env here.
|
|
146
|
+
if (values.output) fs.appendFileSync(values.output, `kind=${kind}\n`);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const ciCommand = { run, usage: USAGE };
|
package/src/cli/decide.js
CHANGED
|
@@ -4,15 +4,16 @@ import { DecisionError, addDecision, settleDecision } from '../decisions.js';
|
|
|
4
4
|
|
|
5
5
|
const USAGE =
|
|
6
6
|
'decide add (--type <T> --question <q> --answer <a> | --open [--type <T>] --question <q> --why <w> --recommendation <r>) [--who <w>] [--replaces D-<n>] [--interface <name> [--source <file>:<line>]]\n' +
|
|
7
|
-
'
|
|
8
|
-
|
|
7
|
+
' decide settle D-<n> --answer <a> [--type <T>] [--who <w>]';
|
|
8
|
+
// Said only on a usage error; the general help gives the same rule under its options.
|
|
9
|
+
const DASH = '(a value that starts with "-" goes as --answer=<text>, and so for every option)';
|
|
9
10
|
|
|
10
11
|
const ADD = ['type', 'question', 'answer', 'why', 'recommendation', 'who', 'replaces', 'interface', 'source', 'open'];
|
|
11
12
|
const SETTLE = ['answer', 'who', 'type'];
|
|
12
13
|
const OPTIONS = { ...Object.fromEntries(ADD.map((k) => [k, { type: 'string' }])), open: { type: 'boolean' } };
|
|
13
14
|
|
|
14
15
|
const usage = (io, why) => {
|
|
15
|
-
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
|
16
|
+
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n ${DASH}\n`);
|
|
16
17
|
return 2;
|
|
17
18
|
};
|
|
18
19
|
|
package/src/cli/gaps.js
CHANGED
|
@@ -4,16 +4,17 @@ import { GapError, addGap, closeGap, scanGaps, verifyGaps } from '../gaps.js';
|
|
|
4
4
|
|
|
5
5
|
const USAGE =
|
|
6
6
|
'gaps scan\n' +
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
|
|
7
|
+
' gaps verify\n' +
|
|
8
|
+
' gaps add --class <c> --where <file>:<line> --what <text>\n' +
|
|
9
|
+
' gaps close G-<n> (--decision D-<n> | --req <REQ>)';
|
|
10
|
+
// Said only on a usage error; the general help gives the same rule under its options.
|
|
11
|
+
const DASH = '(a value that starts with "-" goes as --what=<text>, and so for every option)';
|
|
11
12
|
|
|
12
13
|
const ALLOWED = { scan: [], verify: [], add: ['class', 'where', 'what'], close: ['decision', 'req'] };
|
|
13
14
|
const OPTIONS = Object.fromEntries(Object.values(ALLOWED).flat().map((k) => [k, { type: 'string' }]));
|
|
14
15
|
|
|
15
16
|
const usage = (io, why) => {
|
|
16
|
-
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
|
17
|
+
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n ${DASH}\n`);
|
|
17
18
|
return 2;
|
|
18
19
|
};
|
|
19
20
|
|
package/src/cli/graph.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { getHost } from '../adapters/githost/index.js';
|
|
3
|
+
import { GitHostError } from '../adapters/githost/errors.js';
|
|
4
|
+
import { ConfigError, loadConfig } from '../config.js';
|
|
5
|
+
import { buildGraph, writeGraph } from '../graph/build.js';
|
|
6
|
+
import { GraphError } from '../graph/schema.js';
|
|
7
|
+
import { historyCollision, reachRepos, readWorkspace } from '../graph/workspace.js';
|
|
8
|
+
|
|
9
|
+
const USAGE = 'graph [--full]';
|
|
10
|
+
|
|
11
|
+
// Builds the traceability graph (REQ-4.1 to REQ-4.4): the path first, then what was built and
|
|
12
|
+
// walked, then each workspace repository not reached (REQ-4.6), then each note; warnings go to
|
|
13
|
+
// stderr. The only command that reaches the git host (C-1).
|
|
14
|
+
async function run(args, io) {
|
|
15
|
+
let values;
|
|
16
|
+
try {
|
|
17
|
+
({ values } = parseArgs({ args, options: { full: { type: 'boolean' } }, allowPositionals: false }));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
io.stderr(`slicekit: ${e.message}\nusage: slicekit ${USAGE}\n`);
|
|
20
|
+
return 2;
|
|
21
|
+
}
|
|
22
|
+
const root = io.cwd;
|
|
23
|
+
let cfg;
|
|
24
|
+
try {
|
|
25
|
+
cfg = loadConfig(root);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
28
|
+
io.stderr(`slicekit: ${e.message}\n`);
|
|
29
|
+
return 2;
|
|
30
|
+
}
|
|
31
|
+
const env = io.env ?? process.env;
|
|
32
|
+
let reached;
|
|
33
|
+
let unreached;
|
|
34
|
+
try {
|
|
35
|
+
({ reached, unreached } = reachRepos(root, cfg, readWorkspace(root, cfg), env));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (!(e instanceof GraphError)) throw e;
|
|
38
|
+
io.stderr(`${e.message}\n`);
|
|
39
|
+
return e.code;
|
|
40
|
+
}
|
|
41
|
+
let host = null;
|
|
42
|
+
let skipped = null;
|
|
43
|
+
try {
|
|
44
|
+
host = getHost(cfg, env, root);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (!(e instanceof GitHostError)) throw e;
|
|
47
|
+
skipped = `pull requests skipped: ${e.message}`;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const built = buildGraph(root, cfg, { host, full: Boolean(values.full), skipped, repos: reached });
|
|
51
|
+
try {
|
|
52
|
+
historyCollision(root, cfg, built.graph, reached);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (!(e instanceof GraphError)) throw e;
|
|
55
|
+
io.stderr(`${e.message}\n`);
|
|
56
|
+
return e.code;
|
|
57
|
+
}
|
|
58
|
+
const rel = writeGraph(root, cfg, built);
|
|
59
|
+
const { graph, report } = built;
|
|
60
|
+
const lines = [
|
|
61
|
+
rel,
|
|
62
|
+
`nodes ${graph.nodes.length} edges ${graph.edges.length}`,
|
|
63
|
+
`commits walked ${report.walked} of ${report.commits}`,
|
|
64
|
+
`files read ${report.read} of ${report.files}`,
|
|
65
|
+
`pull requests fetched ${report.fetched}, from the cache ${report.cached}`,
|
|
66
|
+
...unreached.map((u) => `repo ${u.name} not reached: ${u.reason}`),
|
|
67
|
+
...report.notes,
|
|
68
|
+
];
|
|
69
|
+
io.stdout(`${lines.join('\n')}\n`);
|
|
70
|
+
for (const w of report.warnings) io.stderr(`${w}\n`);
|
|
71
|
+
return 0;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (!(e instanceof GraphError)) throw e;
|
|
74
|
+
io.stderr(`${e.message.startsWith('graph: ') ? e.message : `graph: ${e.message}`}\n`);
|
|
75
|
+
return e.code;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const graphCommand = { run, usage: USAGE };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// slicekit history <path> [<path>…] [--json] (REQ-4.5): newest first, the slices and pull requests
|
|
2
|
+
// that touched those paths, each with its verdict and release, from graph.json.
|
|
3
|
+
import { GraphError } from '../graph/schema.js';
|
|
4
|
+
import { history, historyLine } from '../graph/history.js';
|
|
5
|
+
import { queryCommand } from './query.js';
|
|
6
|
+
|
|
7
|
+
const USAGE = 'history <path> [<path>…] [--json]';
|
|
8
|
+
|
|
9
|
+
export const historyCommand = queryCommand({
|
|
10
|
+
name: 'history',
|
|
11
|
+
usage: USAGE,
|
|
12
|
+
answer(index, { positionals }) {
|
|
13
|
+
if (positionals.length === 0) throw new GraphError(2, `give at least one path\nusage: slicekit ${USAGE}`);
|
|
14
|
+
const entries = history(index, positionals);
|
|
15
|
+
return { lines: entries.map(historyLine), json: entries };
|
|
16
|
+
},
|
|
17
|
+
});
|
package/src/cli/hook.js
CHANGED
|
@@ -3,7 +3,7 @@ import { failureOutput, runHook } from '../hooks/io.js';
|
|
|
3
3
|
// `slicekit hook <name>`: read all of stdin, print the hook's JSON decision, exit with its code.
|
|
4
4
|
// Any throw here answers like a failed hook: the refusal for a fail-closed name, {} for a fail-open one.
|
|
5
5
|
export const hookCommand = {
|
|
6
|
-
usage: 'hook <name>
|
|
6
|
+
usage: 'hook <name>',
|
|
7
7
|
async run(args, io) {
|
|
8
8
|
const [name] = args;
|
|
9
9
|
if (!name) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// slicekit impact <REQ, C-n, slice or path> [--json] (REQ-4.5, REQ-4.6): the contracts, slices, files
|
|
2
|
+
// and repositories that share files or contracts with the target, from graph.json.
|
|
3
|
+
import { bookkeeping, impact, impactLines } from '../graph/impact.js';
|
|
4
|
+
import { GraphError } from '../graph/schema.js';
|
|
5
|
+
import { queryCommand } from './query.js';
|
|
6
|
+
|
|
7
|
+
const USAGE = 'impact <REQ-…|C-…|P<n>/S-<nn>|path> [--json]';
|
|
8
|
+
|
|
9
|
+
export const impactCommand = queryCommand({
|
|
10
|
+
name: 'impact',
|
|
11
|
+
usage: USAGE,
|
|
12
|
+
answer(index, { positionals, root, cfg }) {
|
|
13
|
+
if (positionals.length !== 1) throw new GraphError(2, `give one requirement, contract, slice or path\nusage: slicekit ${USAGE}`);
|
|
14
|
+
const r = impact(index, positionals[0], { skip: bookkeeping(root, cfg) });
|
|
15
|
+
return { lines: impactLines(r), json: r };
|
|
16
|
+
},
|
|
17
|
+
});
|
package/src/cli/index.js
CHANGED
|
@@ -3,8 +3,12 @@ import { baselineCommand } from './baseline.js';
|
|
|
3
3
|
import { branchCommand } from './branch.js';
|
|
4
4
|
import { buildCommand } from './build.js';
|
|
5
5
|
import { checkCommand } from './check.js';
|
|
6
|
+
import { ciCommand } from './ci.js';
|
|
6
7
|
import { decideCommand } from './decide.js';
|
|
7
8
|
import { gapsCommand } from './gaps.js';
|
|
9
|
+
import { graphCommand } from './graph.js';
|
|
10
|
+
import { historyCommand } from './history.js';
|
|
11
|
+
import { impactCommand } from './impact.js';
|
|
8
12
|
import { initCommand } from './init.js';
|
|
9
13
|
import { intakeCommand } from './intake.js';
|
|
10
14
|
import { prCommand } from './pr.js';
|
|
@@ -16,9 +20,13 @@ import { readyLabelCommand } from './ready-label.js';
|
|
|
16
20
|
import { reviewCommand } from './review.js';
|
|
17
21
|
import { specCommand } from './spec.js';
|
|
18
22
|
import { stageCommand } from './stage.js';
|
|
23
|
+
import { shippedCommand } from './shipped.js';
|
|
19
24
|
import { stateCommand } from './state.js';
|
|
20
25
|
import { statusCommand } from './status.js';
|
|
26
|
+
import { traceCommand } from './trace.js';
|
|
27
|
+
import { uncoveredCommand } from './uncovered.js';
|
|
21
28
|
import { updateCommand } from './update.js';
|
|
29
|
+
import { visualizeCommand } from './visualize.js';
|
|
22
30
|
import { workflowCommand } from './workflow.js';
|
|
23
31
|
|
|
24
32
|
// Later tasks add entries: { [name]: { run(args, io) -> Promise<number>, usage: string, subcommands?: string[] } }
|
|
@@ -27,8 +35,12 @@ export const COMMANDS = {
|
|
|
27
35
|
branch: branchCommand,
|
|
28
36
|
build: buildCommand,
|
|
29
37
|
check: checkCommand,
|
|
38
|
+
ci: ciCommand,
|
|
30
39
|
decide: decideCommand,
|
|
31
40
|
gaps: gapsCommand,
|
|
41
|
+
graph: graphCommand,
|
|
42
|
+
history: historyCommand,
|
|
43
|
+
impact: impactCommand,
|
|
32
44
|
init: initCommand,
|
|
33
45
|
intake: intakeCommand,
|
|
34
46
|
instructions: instructionsCommand,
|
|
@@ -39,10 +51,14 @@ export const COMMANDS = {
|
|
|
39
51
|
'ready-label': readyLabelCommand,
|
|
40
52
|
review: reviewCommand,
|
|
41
53
|
spec: specCommand,
|
|
54
|
+
shipped: shippedCommand,
|
|
42
55
|
stage: stageCommand,
|
|
43
56
|
state: stateCommand,
|
|
44
57
|
status: statusCommand,
|
|
58
|
+
trace: traceCommand,
|
|
59
|
+
uncovered: uncoveredCommand,
|
|
45
60
|
update: updateCommand,
|
|
61
|
+
visualize: visualizeCommand,
|
|
46
62
|
workflow: workflowCommand,
|
|
47
63
|
};
|
|
48
64
|
|
|
@@ -56,10 +72,18 @@ function usageText() {
|
|
|
56
72
|
const names = Object.keys(COMMANDS).sort();
|
|
57
73
|
if (names.length > 0) {
|
|
58
74
|
lines.push('commands:');
|
|
59
|
-
|
|
75
|
+
// One line per form, each starting with the command's name; a command's own continuation lines
|
|
76
|
+
// are indented for its usage error and set level here.
|
|
77
|
+
for (const name of names) for (const line of COMMANDS[name].usage.split('\n')) lines.push(` ${line.trim()}`);
|
|
60
78
|
lines.push('');
|
|
61
79
|
}
|
|
62
|
-
lines.push(
|
|
80
|
+
lines.push(
|
|
81
|
+
'options:',
|
|
82
|
+
' --help show this text',
|
|
83
|
+
' --version print the version',
|
|
84
|
+
' --<option>=<value> a value that starts with "-", for any option',
|
|
85
|
+
'',
|
|
86
|
+
);
|
|
63
87
|
return lines.join('\n');
|
|
64
88
|
}
|
|
65
89
|
|
|
@@ -69,8 +93,9 @@ export async function main(argv, io) {
|
|
|
69
93
|
io.stdout(`${readVersion()}\n`);
|
|
70
94
|
return 0;
|
|
71
95
|
}
|
|
96
|
+
// The help asked for is the answer, on standard output; the usage after a mistake is an error.
|
|
72
97
|
if (first === '--help') {
|
|
73
|
-
io.
|
|
98
|
+
io.stdout(usageText());
|
|
74
99
|
return 0;
|
|
75
100
|
}
|
|
76
101
|
const command = Object.hasOwn(COMMANDS, first ?? '') ? COMMANDS[first] : undefined;
|
package/src/cli/instructions.js
CHANGED
|
@@ -4,7 +4,7 @@ import { InstructionsError, briefSlice, checkRole, renderBrief, renderProcedure,
|
|
|
4
4
|
|
|
5
5
|
const USAGE =
|
|
6
6
|
'instructions <role> [P<n>/S-<nn>] [--worktree <path> | --summary]\n' +
|
|
7
|
-
'
|
|
7
|
+
' instructions --command <name> [args...]';
|
|
8
8
|
|
|
9
9
|
const usage = (io, why) => {
|
|
10
10
|
io.stderr(`${why ? `slicekit: ${why}\n` : ''}usage: slicekit ${USAGE}\n`);
|
package/src/cli/intake.js
CHANGED
|
@@ -12,9 +12,9 @@ const SUBCOMMANDS = ['snapshot', 'ask', 'answer', 'done'];
|
|
|
12
12
|
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
|
|
13
13
|
const USAGE =
|
|
14
14
|
'intake snapshot <file|url> [--slug <s>] [--who <w>]\n' +
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
15
|
+
' intake ask --pass <product|platform> --topic <t> --question <q>\n' +
|
|
16
|
+
' intake answer (--answer <a> [--type <T>] | --open --why <w> --recommendation <r>) [--who <w>] [--interface <name> [--source <file>:<line>]]\n' +
|
|
17
|
+
' intake done';
|
|
18
18
|
|
|
19
19
|
// The options each subcommand takes, and the positionals it wants after its name.
|
|
20
20
|
const SPEC = {
|