slicekit 0.3.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -9
- package/package.json +1 -1
- package/src/audit.js +4 -3
- package/src/check/rules/sync-release.js +17 -5
- package/src/cli/audit.js +14 -12
- package/src/cli/branch.js +189 -28
- package/src/cli/index.js +72 -0
- package/src/config.js +80 -5
- package/src/release-version.js +90 -10
- package/src/state/sync.js +4 -3
- package/templates/instructions/commands/audit.md +4 -2
- package/templates/instructions/commands/release.md +9 -4
package/README.md
CHANGED
|
@@ -7,16 +7,22 @@ agent finishes a turn and again in CI, not because anyone remembers to update it
|
|
|
7
7
|
|
|
8
8
|
## Status: preview
|
|
9
9
|
|
|
10
|
-
Phases 1 to
|
|
10
|
+
Phases 1 to 5 work. Phases 1 and 2 are intake, specify, the gap scan, plan, the build from red
|
|
11
11
|
tests to green, the review loop, the independent review and `/slicekit build --parallel`. Phase 3
|
|
12
12
|
is the traceability graph (`graph`), its queries (`trace`, `impact`, `history`, `uncovered` and
|
|
13
13
|
`shipped`), its views (`visualize`), and workspaces that let the graph span several repositories;
|
|
14
|
-
a slice is still built in one repository. Phase 4
|
|
15
|
-
|
|
14
|
+
a slice is still built in one repository. Phase 4 is hardening: `check` reads the git host's rules
|
|
15
|
+
on the default branch and `init --protect` sets the missing ones, the guards refuse what they
|
|
16
|
+
cannot judge, commits to the session journal must be signed, the state change after a merge goes
|
|
17
|
+
up as a pull request, and declined should-haves can go to Jira. Phase 5 is `release` (the release
|
|
18
|
+
record of a phase), `ops` (the triage of a symptom), `audit` (the claims of the spec and the
|
|
19
|
+
runbook against the code), observability steps in CI, and two more examples, `examples/fullstack`
|
|
20
|
+
and `examples/data`. [CHANGELOG.md](https://github.com/adityapandya1/agentic-slicekit/blob/main/CHANGELOG.md) lists what each
|
|
16
21
|
version changed.
|
|
17
22
|
|
|
18
|
-
The kit is on npm as a preview from 0.1.1.
|
|
19
|
-
|
|
23
|
+
The kit is on npm as a preview from 0.1.1. Versions from 0.3.0 are published from CI, each with a
|
|
24
|
+
provenance attestation; the versions before it carry none. It needs Node 22 or later and git, and
|
|
25
|
+
it has no dependencies of its own. In your project:
|
|
20
26
|
|
|
21
27
|
```sh
|
|
22
28
|
npm install --save-dev slicekit
|
|
@@ -27,10 +33,6 @@ Each change to the kit ships as the next 0.x version, and a 0.x version may chan
|
|
|
27
33
|
works. After an upgrade, `npx slicekit update` shows what would change in each of the kit's files,
|
|
28
34
|
and `npx slicekit update --yes` writes the changes.
|
|
29
35
|
|
|
30
|
-
The [user guide](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/guide/README.md)
|
|
31
|
-
explains the stages and the slash commands, and gives every command's syntax, options, exit codes
|
|
32
|
-
and an example.
|
|
33
|
-
|
|
34
36
|
The walkthrough below runs from a clone instead, because it copies files only the repository
|
|
35
37
|
holds (`examples/backend` and `examples/walkthrough`):
|
|
36
38
|
|
|
@@ -245,6 +247,15 @@ pip install graphifyy && graphify install
|
|
|
245
247
|
|
|
246
248
|
Then one Claude Code session runs both: `/graphify .` for the code graph, then `/slicekit build`.
|
|
247
249
|
|
|
250
|
+
## User guide
|
|
251
|
+
|
|
252
|
+
The [user guide](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/guide/README.md)
|
|
253
|
+
explains the stages and has a page for every `slicekit` command, every `/slicekit` slash command
|
|
254
|
+
and every check rule. A command's page gives its usage, what it reads and writes, its exit codes
|
|
255
|
+
and an example. A check rule's page says what fails and the failure the rule prevents.
|
|
256
|
+
[docs/adapters.md](https://github.com/adityapandya1/agentic-slicekit/blob/main/docs/adapters.md)
|
|
257
|
+
describes the contracts for anyone adding a git host, a tracker or an agent tool.
|
|
258
|
+
|
|
248
259
|
## How the hooks find slicekit
|
|
249
260
|
|
|
250
261
|
`slicekit init` writes the hook command as `node node_modules/slicekit/bin/slicekit.js` when the
|
package/package.json
CHANGED
package/src/audit.js
CHANGED
|
@@ -157,11 +157,12 @@ export function auditClaims(root, cfg, index, area) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
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
|
-
|
|
160
|
+
// so an area that names no claim leaves no empty report behind. With `report` false no report is
|
|
161
|
+
// reserved and `report` is null: the context alone, for a second look at an area (issue #157).
|
|
162
|
+
export function auditContext(root, cfg, area, { report = true } = {}) {
|
|
162
163
|
const index = indexGraph(loadGraph(root, cfg));
|
|
163
164
|
const claims = auditClaims(root, cfg, index, area);
|
|
164
|
-
return { report: nextReport(root, cfg, 'audit'), claims };
|
|
165
|
+
return { report: report ? nextReport(root, cfg, 'audit') : null, claims };
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
const bare = (cell) => cell.trim().replace(/^`+|`+$/g, '').trim();
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// equal what CI computes for the merge the branch names: a fresh checkout of that merge in a temporary
|
|
4
4
|
// worktree, synced from the git host and given the version, section and render the sync step would
|
|
5
5
|
// write there. So package.json may change only in its version field, CHANGELOG.md only by the one new
|
|
6
|
-
// section, and a rendered file only to its fresh render at that version.
|
|
7
|
-
//
|
|
6
|
+
// section, and a rendered file only to its fresh render at that version. The rendered files of each
|
|
7
|
+
// folder under examples/ that holds them are judged the same way (D-95): the sync step renders each
|
|
8
|
+
// example at that version, so an example file is accepted only where it equals that render. One
|
|
9
|
+
// finding per file that differs, naming it. A sync branch whose merge the checkout cannot resolve is the journal rule's
|
|
8
10
|
// finding. Silent outside CI and on any other branch, and when the config has no release.auto and the
|
|
9
11
|
// branch changes none of those files.
|
|
10
12
|
import { execFileSync } from 'node:child_process';
|
|
@@ -15,7 +17,7 @@ import { getHost } from '../../adapters/githost/index.js';
|
|
|
15
17
|
import { GitHostError } from '../../adapters/githost/errors.js';
|
|
16
18
|
import { ConfigError, loadConfig } from '../../config.js';
|
|
17
19
|
import { git, resolveCommit } from '../../git.js';
|
|
18
|
-
import { PACKAGE, ReleaseError, applyRelease, isKitRoot, isReleasePath } from '../../release-version.js';
|
|
20
|
+
import { EXAMPLES, PACKAGE, ReleaseError, applyRelease, isKitRoot, isReleasePath } from '../../release-version.js';
|
|
19
21
|
import { syncFromHost } from '../../state/sync.js';
|
|
20
22
|
import { SYNC_BRANCH, branchTip } from '../ci-event.js';
|
|
21
23
|
|
|
@@ -32,13 +34,19 @@ export function run(ctx) {
|
|
|
32
34
|
if (at === null || !SYNC_BRANCH.test(at.branch)) return [];
|
|
33
35
|
const merge = resolveCommit(root, at.branch.slice('sync/'.length));
|
|
34
36
|
if (merge === null) return [];
|
|
35
|
-
|
|
37
|
+
// The release paths with the examples this checkout holds; below, those the merge holds are
|
|
38
|
+
// added, so an example the branch adds or removes is judged against the merge's render too.
|
|
39
|
+
const ownsHere = isReleasePath(cfg, root);
|
|
40
|
+
let owns = ownsHere;
|
|
36
41
|
const changed = nul(git(root, ['diff', '--name-only', '--no-renames', '-z', merge, at.tip])).filter(owns);
|
|
37
42
|
if (cfg.release?.auto !== true && changed.length === 0) return [];
|
|
43
|
+
const example = (file) => file.startsWith(`${EXAMPLES}/`);
|
|
38
44
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'slicekit-sync-release-'));
|
|
39
45
|
const wt = path.join(tmp, 'merge');
|
|
40
46
|
try {
|
|
41
47
|
git(root, ['worktree', 'add', '--quiet', '--detach', wt, merge]);
|
|
48
|
+
const ownsMerge = isReleasePath(cfg, wt);
|
|
49
|
+
owns = (f) => ownsHere(f) || ownsMerge(f);
|
|
42
50
|
let expected;
|
|
43
51
|
try {
|
|
44
52
|
expected = expectedFiles(root, ctx, wt, owns);
|
|
@@ -50,7 +58,11 @@ export function run(ctx) {
|
|
|
50
58
|
for (const file of [...new Set([...changed, ...expected.keys()])].sort()) {
|
|
51
59
|
const want = expected.has(file) ? expected.get(file) : read(wt, file);
|
|
52
60
|
const got = blob(root, at.tip, file);
|
|
53
|
-
if (
|
|
61
|
+
if (same(want, got)) continue;
|
|
62
|
+
const how = example(file)
|
|
63
|
+
? 'a sync pull request changes an example file only to its fresh render at the version it sets (slicekit update --yes in that folder)'
|
|
64
|
+
: "a sync pull request changes it only as the sync step does (package.json's version, one new CHANGELOG.md section, the render at that version)";
|
|
65
|
+
out.push({ file, line: 0, message: `${file} differs from what CI computes for the merge ${merge.slice(0, 7)}; ${how}` });
|
|
54
66
|
}
|
|
55
67
|
return out;
|
|
56
68
|
} finally {
|
package/src/cli/audit.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// slicekit audit context [area] [--all] [--
|
|
2
|
-
// (REQ-2.14, D-58):
|
|
1
|
+
// slicekit audit context [area] [--all] [--no-report] [--json] and
|
|
2
|
+
// slicekit audit check <report> [area] [--every-claim] (REQ-2.14, D-58):
|
|
3
3
|
// the claims `/slicekit audit` hands the auditor, each with the files it names and its candidate
|
|
4
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 --
|
|
5
|
+
// check reads from the spec and the runbook as the context does. With --no-report the context is
|
|
6
|
+
// printed alone and no report file is reserved (issue #157). With --every-claim a claim of the
|
|
6
7
|
// area that has no row is a problem. Neither changes a tracked file.
|
|
7
8
|
import { parseArgs } from 'node:util';
|
|
8
9
|
import { auditClaims, auditContext, auditReportProblems } from '../audit.js';
|
|
@@ -12,7 +13,7 @@ import { indexGraph, loadGraph } from '../graph/load.js';
|
|
|
12
13
|
import { GraphError } from '../graph/schema.js';
|
|
13
14
|
import { readReport } from '../reports.js';
|
|
14
15
|
|
|
15
|
-
const USAGE = 'audit context [area] [--all] [--json]\n audit check <report> [area] [--every-claim]';
|
|
16
|
+
const USAGE = 'audit context [area] [--all] [--no-report] [--json]\n audit check <report> [area] [--every-claim]';
|
|
16
17
|
const SUBCOMMANDS = ['context', 'check'];
|
|
17
18
|
|
|
18
19
|
const usage = (io, why) => {
|
|
@@ -29,17 +30,18 @@ export const SHOWN = 10;
|
|
|
29
30
|
// The narrowest area that names `claim`: its REQ ID, or `runbook` for a runbook section.
|
|
30
31
|
const areaFor = (claim) => (claim.id.startsWith('runbook#') ? 'runbook' : claim.id);
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// The report path when one was reserved, then at most SHOWN candidates per claim, the newest, then
|
|
34
|
+
// one line counting the rest and naming the command that prints them and reserves no report, with
|
|
35
|
+
// the kit's command prefix `cli`; with `all`, each one. --json and the check hold every candidate.
|
|
36
|
+
function contextLines(c, { all = false, cli = 'slicekit' } = {}) {
|
|
37
|
+
const out = c.report === null ? [] : [c.report];
|
|
36
38
|
for (const claim of c.claims) {
|
|
37
39
|
out.push(`${claim.id} ${claim.where} ${claim.title}`.trimEnd());
|
|
38
40
|
out.push(` files: ${claim.files.join(', ')}`.trimEnd());
|
|
39
41
|
const shown = all ? claim.candidates : claim.candidates.slice(0, SHOWN);
|
|
40
42
|
for (const k of shown) out.push(` candidate ${k.sha.slice(0, 7)} ${k.date} ${k.subject}`.trimEnd());
|
|
41
43
|
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`);
|
|
44
|
+
if (more > 0) out.push(` ${more} more candidate${more === 1 ? '' : 's'}, each older: ${cli} audit context ${areaFor(claim)} --all --no-report`);
|
|
43
45
|
}
|
|
44
46
|
return out;
|
|
45
47
|
}
|
|
@@ -48,7 +50,7 @@ async function run(args, io) {
|
|
|
48
50
|
let values;
|
|
49
51
|
let positionals;
|
|
50
52
|
try {
|
|
51
|
-
({ values, positionals } = parseArgs({ args, options: { json: { type: 'boolean' }, all: { type: 'boolean' }, 'every-claim': { type: 'boolean' } }, allowPositionals: true }));
|
|
53
|
+
({ values, positionals } = parseArgs({ args, options: { json: { type: 'boolean' }, all: { type: 'boolean' }, 'no-report': { type: 'boolean' }, 'every-claim': { type: 'boolean' } }, allowPositionals: true }));
|
|
52
54
|
} catch (e) {
|
|
53
55
|
return usage(io, e.message);
|
|
54
56
|
}
|
|
@@ -65,8 +67,8 @@ async function run(args, io) {
|
|
|
65
67
|
const cfg = loadConfig(root);
|
|
66
68
|
if (sub === 'context') {
|
|
67
69
|
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
|
+
const context = auditContext(root, cfg, areaOf(rest[0]), { report: !values['no-report'] });
|
|
71
|
+
io.stdout(json ? `${JSON.stringify(context, null, 2)}\n` : contextLines(context, { all: Boolean(values.all), cli: cfg.cli }).map((l) => `${l}\n`).join(''));
|
|
70
72
|
return 0;
|
|
71
73
|
}
|
|
72
74
|
if (rest.length === 0) return usage(io, 'missing report');
|
package/src/cli/branch.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// `slicekit branch <spec|gaps|plan|release> <slug>` (REQ-2.3..REQ-2.5, REQ-2.9, D-54): puts the session on the
|
|
2
2
|
// work branch of a document pull request, cut from the default branch as origin has it. The command owns git
|
|
3
3
|
// (D-19). A change to a tracked file (staged or not) is refused, so no edit is carried across;
|
|
4
|
-
// untracked files go along as git carries them, so a source dropped in for intake survives.
|
|
4
|
+
// untracked files go along as git carries them, so a source dropped in for intake survives. The one
|
|
5
|
+
// change carried is the config as the migration writes it from the committed one (D-94): an earlier
|
|
6
|
+
// command on this branch, such as `release --dry-run`, wrote it, and `pr open` commits it. Where the
|
|
7
|
+
// commit the session is put on holds another config than the one here (an earlier `pr open`
|
|
8
|
+
// committed the migration there), the change is dropped when that config equals it, and refused
|
|
9
|
+
// with one line naming the difference when it does not (issue #162).
|
|
5
10
|
// A `release/<slug>` branch that exists away from the default branch's tip is moved there or refused;
|
|
6
11
|
// one that holds its own commits is refused with its open pull request, read through the git host
|
|
7
|
-
// (C-1 pullRequestForBranch), or with the next free slug when the host says none is open.
|
|
12
|
+
// (C-1 pullRequestForBranch), or with the next free slug when the host says none is open. The host
|
|
13
|
+
// is asked about each `release/<slug>-<n>` branch as well: the phase's open release pull request
|
|
14
|
+
// may be on one of them, taken after `release/<slug>` was closed unmerged (issue #152). A slug
|
|
15
|
+
// given numbered, `<base>-<n>` with <n> 2 or more (the numbers the command itself names), belongs
|
|
16
|
+
// to the family of `release/<base>`: the host is asked about that branch and each
|
|
17
|
+
// `release/<base>-<n>` too, so an open release pull request on any of them refuses.
|
|
8
18
|
import { getHost } from '../adapters/githost/index.js';
|
|
9
19
|
import { GitHostError } from '../adapters/githost/errors.js';
|
|
10
|
-
import
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { CONFIG_PATH, ConfigError, loadConfig, migrateConfig } from '../config.js';
|
|
11
23
|
import { GitError, assertRef, currentBranch, git, hasRemote, switchBranch } from '../git.js';
|
|
12
24
|
|
|
13
25
|
const KINDS = ['spec', 'gaps', 'plan', 'release'];
|
|
@@ -24,6 +36,90 @@ const resolves = (root, ref) => {
|
|
|
24
36
|
}
|
|
25
37
|
};
|
|
26
38
|
|
|
39
|
+
const CONFIG_FILE = CONFIG_PATH.split(path.sep).join('/');
|
|
40
|
+
|
|
41
|
+
// D-94: whether the only uncommitted change to a tracked file is the config, and the file holds
|
|
42
|
+
// exactly what the migration writes from the config the last commit holds. A config staged with
|
|
43
|
+
// one content and holding another in the working directory is not that change.
|
|
44
|
+
function onlyMigratedConfig(root) {
|
|
45
|
+
const names = (args) => git(root, ['diff', '--name-only', '--no-renames', '-z', ...args]).split('\0').filter((f) => f !== '');
|
|
46
|
+
const staged = names(['--cached', 'HEAD']);
|
|
47
|
+
const unstaged = names([]);
|
|
48
|
+
const changed = new Set([...staged, ...unstaged]);
|
|
49
|
+
if (changed.size !== 1 || !changed.has(CONFIG_FILE)) return false;
|
|
50
|
+
if (staged.length > 0 && unstaged.length > 0) return false;
|
|
51
|
+
try {
|
|
52
|
+
const committed = JSON.parse(git(root, ['show', `HEAD:${CONFIG_FILE}`]));
|
|
53
|
+
const { cfg, from } = migrateConfig(committed);
|
|
54
|
+
if (cfg === committed || from === cfg.configVersion) return false;
|
|
55
|
+
return fs.readFileSync(path.join(root, CONFIG_PATH), 'utf8') === `${JSON.stringify(cfg, null, 2)}\n`;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e instanceof GitError || e instanceof ConfigError || e instanceof SyntaxError || e.code !== undefined) return false;
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The text of the config at `ref`, or null when that commit holds none.
|
|
63
|
+
function configAt(root, ref) {
|
|
64
|
+
try {
|
|
65
|
+
return git(root, ['show', `${ref}:${CONFIG_FILE}`]);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (e instanceof GitError) return null;
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const plain = (text) => text.replace(/\r\n/g, '\n').trimEnd();
|
|
73
|
+
const sameText = (a, b) => a !== null && b !== null && plain(a) === plain(b);
|
|
74
|
+
|
|
75
|
+
// Where two configs differ: the top-level fields whose values differ, or, when one of the two is
|
|
76
|
+
// not a JSON object, the first line that differs.
|
|
77
|
+
function configDifference(here, there) {
|
|
78
|
+
const parse = (text) => {
|
|
79
|
+
try {
|
|
80
|
+
const v = JSON.parse(text);
|
|
81
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const a = parse(here);
|
|
87
|
+
const b = parse(there);
|
|
88
|
+
if (a && b) {
|
|
89
|
+
const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => JSON.stringify(a[k]) !== JSON.stringify(b[k]));
|
|
90
|
+
if (keys.length > 0) return `${keys.length === 1 ? 'the field' : 'the fields'} ${keys.join(', ')}`;
|
|
91
|
+
}
|
|
92
|
+
const x = plain(here).split('\n');
|
|
93
|
+
const y = plain(there).split('\n');
|
|
94
|
+
let n = 0;
|
|
95
|
+
while (n < x.length && n < y.length && x[n] === y[n]) n += 1;
|
|
96
|
+
return `line ${n + 1}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// What becomes of the migrated config, the only uncommitted change, when the session moves to the
|
|
100
|
+
// commit `ref` (issue #162, D-94). -> 'carry' when that commit holds the config HEAD holds, so git
|
|
101
|
+
// carries the change; 'drop' when it holds the migrated config already; else the line to refuse with.
|
|
102
|
+
function migratedConfigTo(root, ref, label) {
|
|
103
|
+
const there = configAt(root, ref);
|
|
104
|
+
if (sameText(there, configAt(root, 'HEAD'))) return 'carry';
|
|
105
|
+
const here = fs.readFileSync(path.join(root, CONFIG_PATH), 'utf8');
|
|
106
|
+
if (sameText(there, here)) return 'drop';
|
|
107
|
+
if (there === null) return `${CONFIG_FILE} is migrated here and not committed, and ${label} holds no ${CONFIG_FILE}; the change is left here and no branch is switched to`;
|
|
108
|
+
return `${CONFIG_FILE} is migrated here and not committed, and ${CONFIG_FILE} on ${label} differs from it in ${configDifference(here, there)}; the change is left here and no branch is switched to`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The `release/<slug>-<n>` branches that exist here or on origin, as branch names in the order of <n>.
|
|
112
|
+
function numberedBranches(root, target) {
|
|
113
|
+
const found = new Map();
|
|
114
|
+
const refs = git(root, ['for-each-ref', '--format=%(refname)', `refs/heads/${target}-*`, `refs/remotes/origin/${target}-*`]);
|
|
115
|
+
for (const ref of refs.split('\n').filter((l) => l !== '')) {
|
|
116
|
+
const name = ref.replace(/^refs\/(heads|remotes\/origin)\//, '');
|
|
117
|
+
const m = /^-(\d+)$/.exec(name.slice(target.length));
|
|
118
|
+
if (m) found.set(name, Number(m[1]));
|
|
119
|
+
}
|
|
120
|
+
return [...found.keys()].sort((x, y) => found.get(x) - found.get(y));
|
|
121
|
+
}
|
|
122
|
+
|
|
27
123
|
async function run(args, io) {
|
|
28
124
|
const [kind, slug, ...rest] = args;
|
|
29
125
|
if (!KINDS.includes(kind) || slug === undefined || rest.length > 0) {
|
|
@@ -36,6 +132,9 @@ async function run(args, io) {
|
|
|
36
132
|
}
|
|
37
133
|
const root = io.cwd;
|
|
38
134
|
const target = `${kind}/${slug}`;
|
|
135
|
+
// The first branch of the release family a numbered slug belongs to; else the target itself.
|
|
136
|
+
const numberedSlug = kind === 'release' ? /^(.+)-(\d+)$/.exec(slug) : null;
|
|
137
|
+
const family = numberedSlug && Number(numberedSlug[2]) >= 2 ? `${kind}/${numberedSlug[1]}` : target;
|
|
39
138
|
try {
|
|
40
139
|
const cfg = loadConfig(root);
|
|
41
140
|
const base = assertRef(cfg.defaultBranch);
|
|
@@ -44,7 +143,46 @@ async function run(args, io) {
|
|
|
44
143
|
io.stdout(`${target}\n`);
|
|
45
144
|
return 0;
|
|
46
145
|
}
|
|
47
|
-
const
|
|
146
|
+
const changed = git(root, ['status', '--porcelain', '--untracked-files=no']) !== '';
|
|
147
|
+
const migrated = changed && onlyMigratedConfig(root);
|
|
148
|
+
const dirty = changed && !migrated;
|
|
149
|
+
// Moves the session to the commit `ref` with `go`. The migrated config is carried, dropped
|
|
150
|
+
// first where `ref` holds it already, or the move is refused. -> false when refused, with the
|
|
151
|
+
// line printed. A dropped copy is put back when the move fails. After the move the file holds
|
|
152
|
+
// the bytes the migration wrote: a checkout that converts line endings writes the same config
|
|
153
|
+
// with other ones, which git reads as no change.
|
|
154
|
+
const move = (ref, label, go) => {
|
|
155
|
+
const file = path.join(root, CONFIG_PATH);
|
|
156
|
+
let kept = null;
|
|
157
|
+
if (migrated) {
|
|
158
|
+
const what = migratedConfigTo(root, ref, label);
|
|
159
|
+
if (what !== 'carry' && what !== 'drop') {
|
|
160
|
+
io.stderr(`slicekit: ${what}\n`);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if (what === 'drop') {
|
|
164
|
+
kept = fs.readFileSync(file);
|
|
165
|
+
git(root, ['restore', '-q', '--staged', '--worktree', '--source=HEAD', '--', CONFIG_FILE]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
go();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
if (kept !== null) fs.writeFileSync(file, kept);
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
if (kept !== null) {
|
|
175
|
+
const now = fs.readFileSync(file);
|
|
176
|
+
if (!now.equals(kept) && sameText(now.toString('utf8'), kept.toString('utf8'))) {
|
|
177
|
+
fs.writeFileSync(file, kept);
|
|
178
|
+
// The file's size changed, which git takes for a change until the index entry is read
|
|
179
|
+
// again; the add stages nothing, since the content is the commit's.
|
|
180
|
+
git(root, ['--literal-pathspecs', 'add', '--', CONFIG_FILE]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
};
|
|
185
|
+
const short = (ref) => ref.replace(/^refs\/(heads|remotes)\//, '');
|
|
48
186
|
if (dirty && !onTarget) {
|
|
49
187
|
io.stderr('slicekit: commit or stash your changes first\n');
|
|
50
188
|
return 1;
|
|
@@ -65,6 +203,19 @@ async function run(args, io) {
|
|
|
65
203
|
} catch (e) {
|
|
66
204
|
if (!(e instanceof GitError)) throw e;
|
|
67
205
|
}
|
|
206
|
+
// And, for a release, each numbered branch of the slug another clone pushed.
|
|
207
|
+
if (kind === 'release') {
|
|
208
|
+
const specs = [`+refs/heads/${target}-*:refs/remotes/origin/${target}-*`];
|
|
209
|
+
// And, for a numbered slug, the first branch of its family and that one's numbered branches.
|
|
210
|
+
if (family !== target) specs.push(`+refs/heads/${family}:refs/remotes/origin/${family}`, `+refs/heads/${family}-*:refs/remotes/origin/${family}-*`);
|
|
211
|
+
for (const spec of specs) {
|
|
212
|
+
try {
|
|
213
|
+
git(root, ['fetch', '-q', 'origin', spec]);
|
|
214
|
+
} catch (e) {
|
|
215
|
+
if (!(e instanceof GitError)) throw e;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
68
219
|
} catch (e) {
|
|
69
220
|
if (!(e instanceof GitError)) throw e;
|
|
70
221
|
const lines = e.stderr.split('\n');
|
|
@@ -79,30 +230,37 @@ async function run(args, io) {
|
|
|
79
230
|
// `slicekit release` runs only at the default branch's tip. A release branch that stands
|
|
80
231
|
// elsewhere, here or on origin, is moved to the tip when it holds no commit the default
|
|
81
232
|
// branch lacks; one that does is refused: with its open pull request when the host has one,
|
|
82
|
-
// else with the next free slug.
|
|
233
|
+
// else with the next free slug. A numbered branch of the slug, `release/<slug>-<n>`, that
|
|
234
|
+
// holds commits the default branch lacks is asked about too, whatever `release/<slug>` holds.
|
|
235
|
+
// So are the other branches of a numbered slug's family: `release/<base>` and each
|
|
236
|
+
// `release/<base>-<n>`.
|
|
83
237
|
const tip = git(root, ['rev-parse', '--verify', `${from}^{commit}`]);
|
|
84
238
|
const copies = [`refs/heads/${target}`, remote].filter((ref) => resolves(root, ref));
|
|
85
239
|
const stale = copies.filter((ref) => git(root, ['rev-parse', '--verify', `${ref}^{commit}`]) !== tip);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return 1;
|
|
104
|
-
}
|
|
240
|
+
const ahead = (ref) => git(root, ['rev-list', '--count', `${from}..${ref}`]) !== '0';
|
|
241
|
+
const own = stale.some(ahead);
|
|
242
|
+
// A branch may be that of the phase's open release pull request; a second slug would then
|
|
243
|
+
// open a second one beside it. A pull request needs its branch on origin, so the host is
|
|
244
|
+
// asked unless a fetch that worked found no such branch there.
|
|
245
|
+
const onOrigin = (name) => origin && (!fetched || resolves(root, `refs/remotes/origin/${name}`));
|
|
246
|
+
const holdsOwn = (name) => [`refs/heads/${name}`, `refs/remotes/origin/${name}`].some((ref) => resolves(root, ref) && ahead(ref));
|
|
247
|
+
const numbered = numberedBranches(root, target).filter(holdsOwn);
|
|
248
|
+
const kin = family === target ? [] : [family, ...numberedBranches(root, family)].filter((name) => name !== target && holdsOwn(name));
|
|
249
|
+
for (const name of [...kin, ...(own ? [target] : []), ...numbered].filter(onOrigin)) {
|
|
250
|
+
let open;
|
|
251
|
+
try {
|
|
252
|
+
open = getHost(cfg, io.env ?? process.env, root).pullRequestForBranch(name, { base });
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (!(e instanceof GitHostError)) throw e;
|
|
255
|
+
io.stderr(`slicekit: ${name} holds commits ${base} lacks, and the git host could not be asked for its open pull request (${e.message}); no branch is cut\n`);
|
|
256
|
+
return 1;
|
|
105
257
|
}
|
|
258
|
+
if (open) {
|
|
259
|
+
io.stderr(`slicekit: ${name} is the branch of open pull request #${open.number} (${open.url}); the phase's release is already open\n`);
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (own) {
|
|
106
264
|
let n = 2;
|
|
107
265
|
while (resolves(root, `refs/heads/${target}-${n}`) || resolves(root, `refs/remotes/origin/${target}-${n}`)) n += 1;
|
|
108
266
|
io.stderr(`slicekit: ${target} holds commits ${base} lacks, so no release runs on it; run slicekit branch release ${slug}-${n}\n`);
|
|
@@ -118,15 +276,18 @@ async function run(args, io) {
|
|
|
118
276
|
return 1;
|
|
119
277
|
}
|
|
120
278
|
// -C makes the branch, or moves it, to stand at the tip; it held no commit of its own.
|
|
121
|
-
git(root, ['switch', '-q', '--no-track', '-C', target, from]);
|
|
279
|
+
if (!move(from, short(from), () => git(root, ['switch', '-q', '--no-track', '-C', target, from]))) return 1;
|
|
122
280
|
io.stderr(`slicekit: ${target} was behind ${base}; moved to the tip of ${base}\n`);
|
|
123
281
|
io.stdout(`${target}\n`);
|
|
124
282
|
return 0;
|
|
125
283
|
}
|
|
126
284
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
285
|
+
const local = `refs/heads/${target}`;
|
|
286
|
+
let moved;
|
|
287
|
+
if (resolves(root, local)) moved = move(local, target, () => switchBranch(root, target));
|
|
288
|
+
else if (resolves(root, remote)) moved = move(remote, short(remote), () => switchBranch(root, target, { create: true, from: remote, track: true }));
|
|
289
|
+
else moved = move(from, short(from), () => switchBranch(root, target, { create: true, from }));
|
|
290
|
+
if (!moved) return 1;
|
|
130
291
|
io.stdout(`${target}\n`);
|
|
131
292
|
return 0;
|
|
132
293
|
} catch (e) {
|
package/src/cli/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CONFIG_PATH, ConfigNewerError, loadConfig, migrateConfigFile } from '../config.js';
|
|
4
|
+
import { currentBranch } from '../git.js';
|
|
5
|
+
import { sliceFromBranch } from '../ids.js';
|
|
6
|
+
import { findSliceFiles, parseSliceFile } from '../slicefile.js';
|
|
2
7
|
import { auditCommand } from './audit.js';
|
|
3
8
|
import { baselineCommand } from './baseline.js';
|
|
4
9
|
import { branchCommand } from './branch.js';
|
|
@@ -118,9 +123,76 @@ export async function main(argv, io) {
|
|
|
118
123
|
io.stdout(commandUsage(command));
|
|
119
124
|
return 0;
|
|
120
125
|
}
|
|
126
|
+
// REQ-5.6, D-60, D-93: an older config is migrated before the command reads it. A hook never
|
|
127
|
+
// writes the team's tracked file mid-turn; it reads the config migrated in memory (loadConfig).
|
|
128
|
+
// D-93 names two more cases that read it migrated, write nothing and print one line: a slice
|
|
129
|
+
// branch or a slice's review branch (writesMigration), and `slicekit branch` of every kind, which
|
|
130
|
+
// refuses a changed tracked file; the branch is cut first and the next command writes on it. A
|
|
131
|
+
// migration an earlier command already wrote is carried by `slicekit branch` itself (D-94).
|
|
132
|
+
if (command !== COMMANDS.hook && typeof io.cwd === 'string') {
|
|
133
|
+
try {
|
|
134
|
+
// The branch is asked about only when the config is older, so a current one costs no git call.
|
|
135
|
+
const older = migrateConfigFile(io.cwd, { write: false });
|
|
136
|
+
const here = older !== null && writesMigration(io.cwd);
|
|
137
|
+
const write = here && command !== COMMANDS.branch;
|
|
138
|
+
const migrated = write ? migrateConfigFile(io.cwd) : older;
|
|
139
|
+
if (migrated && !write) {
|
|
140
|
+
const where = here
|
|
141
|
+
? 'slicekit branch writes nothing, and the next command writes it on the branch it runs on'
|
|
142
|
+
: 'it is migrated on the default branch or on a plan branch';
|
|
143
|
+
io.stderr(`config: ${CONFIG_FILE} is at configVersion ${migrated.from} and is read as ${migrated.to} here, unwritten; ${where}
|
|
144
|
+
`);
|
|
145
|
+
} else if (migrated) {
|
|
146
|
+
io.stderr(`config: migrated ${CONFIG_FILE} from configVersion ${migrated.from} to ${migrated.to}
|
|
147
|
+
`);
|
|
148
|
+
for (const change of migrated.changes) io.stderr(` - ${change}
|
|
149
|
+
`);
|
|
150
|
+
}
|
|
151
|
+
} catch (e) {
|
|
152
|
+
if (!(e instanceof ConfigNewerError)) throw e;
|
|
153
|
+
io.stderr(`slicekit: ${e.message}
|
|
154
|
+
`);
|
|
155
|
+
return 2;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
121
158
|
return command.run(rest, io);
|
|
122
159
|
}
|
|
123
160
|
|
|
161
|
+
const CONFIG_FILE = CONFIG_PATH.split(path.sep).join('/');
|
|
162
|
+
|
|
163
|
+
// Whether a command run in `cwd` may write the migrated config (review r1, H-1; D-93). On a slice branch
|
|
164
|
+
// or a slice's review branch no build step commits a changed config (`build commit` refuses a kit
|
|
165
|
+
// file, `build pr` an uncommitted change), so there the config is read migrated and left as it is.
|
|
166
|
+
// The exception is the slice whose Expected changes name the config: its slice branch and its review
|
|
167
|
+
// branch both write, since a review branch's commits go to the slice branch and `build config`
|
|
168
|
+
// commits the file (D-53, D-94). Anything unreadable on the way (no slice file, a config that does
|
|
169
|
+
// not load) is no reason to write.
|
|
170
|
+
function writesMigration(cwd) {
|
|
171
|
+
let branch;
|
|
172
|
+
try {
|
|
173
|
+
branch = currentBranch(cwd);
|
|
174
|
+
} catch {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const id = branch === null ? null : sliceFromBranch(branch);
|
|
178
|
+
if (id === null) return true;
|
|
179
|
+
try {
|
|
180
|
+
const cfg = loadConfig(cwd);
|
|
181
|
+
for (const f of findSliceFiles(cwd, cfg)) {
|
|
182
|
+
let slice;
|
|
183
|
+
try {
|
|
184
|
+
slice = parseSliceFile(fs.readFileSync(f.path, 'utf8'), f.path);
|
|
185
|
+
} catch {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (slice.id === id) return slice.expectedChanges.includes(CONFIG_FILE);
|
|
189
|
+
}
|
|
190
|
+
} catch {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
124
196
|
function commandUsage(command) {
|
|
125
197
|
const lines = command.usage.split('\n').map((line) => ` slicekit ${line.trim()}`);
|
|
126
198
|
return `usage:\n${lines.join('\n')}\n`;
|
package/src/config.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
|
|
6
|
-
export const CONFIG_VERSION =
|
|
6
|
+
export const CONFIG_VERSION = 2;
|
|
7
7
|
export const SHAPES = ['backend', 'fullstack', 'data'];
|
|
8
8
|
export const CONFIG_PATH = path.join('.slicekit', 'config.json');
|
|
9
9
|
|
|
@@ -30,6 +30,49 @@ export class ConfigError extends Error {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// D-33: a config written by a newer kit is refused, never read as this kit's version.
|
|
34
|
+
export class ConfigNewerError extends ConfigError {
|
|
35
|
+
constructor(version) {
|
|
36
|
+
super([`config: configVersion ${version} is newer than this kit's ${CONFIG_VERSION}; upgrade slicekit`]);
|
|
37
|
+
this.name = 'ConfigNewerError';
|
|
38
|
+
this.version = version;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const WORKSPACE_PATH = '.slicekit/workspace.json';
|
|
43
|
+
|
|
44
|
+
// REQ-5.6, D-60: one entry per configVersion, taking a config at that version to the next one. Each
|
|
45
|
+
// changes the config in place and returns one line per change.
|
|
46
|
+
export const MIGRATIONS = {
|
|
47
|
+
// Version 2 removes repos, accepted and unread since D-47: the workspace file is the only list.
|
|
48
|
+
1: (cfg) => {
|
|
49
|
+
const held = Array.isArray(cfg.repos) ? cfg.repos : [];
|
|
50
|
+
delete cfg.repos;
|
|
51
|
+
const changes = ['removed repos, unread since D-47'];
|
|
52
|
+
if (held.length > 0) {
|
|
53
|
+
const names = held.map((r) => (typeof r === 'string' ? r : typeof r?.name === 'string' ? r.name : JSON.stringify(r)));
|
|
54
|
+
changes.push(`repos held ${names.join(', ')}; list them in ${WORKSPACE_PATH}`);
|
|
55
|
+
}
|
|
56
|
+
return changes;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// -> { cfg, from, changes }: a copy of `cfg` at CONFIG_VERSION, the version read, and one line per
|
|
61
|
+
// change (none when it was current). A configVersion that is not an integer of 1 or more is left as
|
|
62
|
+
// it is for validateConfig to name; one above CONFIG_VERSION throws ConfigNewerError.
|
|
63
|
+
export function migrateConfig(cfg) {
|
|
64
|
+
const from = cfg !== null && typeof cfg === 'object' && !Array.isArray(cfg) ? cfg.configVersion : undefined;
|
|
65
|
+
if (!(Number.isInteger(from) && from >= 1)) return { cfg, from, changes: [] };
|
|
66
|
+
if (from > CONFIG_VERSION) throw new ConfigNewerError(from);
|
|
67
|
+
const copy = structuredClone(cfg);
|
|
68
|
+
const changes = [];
|
|
69
|
+
for (let v = from; v < CONFIG_VERSION; v += 1) {
|
|
70
|
+
changes.push(...MIGRATIONS[v](copy));
|
|
71
|
+
copy.configVersion = v + 1;
|
|
72
|
+
}
|
|
73
|
+
return { cfg: copy, from, changes };
|
|
74
|
+
}
|
|
75
|
+
|
|
33
76
|
// The kit's own filler list, before any team extends it.
|
|
34
77
|
export function seedBanned() {
|
|
35
78
|
const file = fileURLToPath(new URL('../templates/style.json', import.meta.url));
|
|
@@ -47,7 +90,6 @@ export function defaultConfig({ name, shape, docsRoot = 'docs', commands = {}, c
|
|
|
47
90
|
cli,
|
|
48
91
|
protectedBranches: [defaultBranch],
|
|
49
92
|
commands: { test: '', lint: '', build: '', e2e: '', ...commands },
|
|
50
|
-
repos: [],
|
|
51
93
|
gitHost: { kind: 'github' },
|
|
52
94
|
tracker: { kind: 'github-issues' },
|
|
53
95
|
review: { independent: 'required' },
|
|
@@ -212,7 +254,9 @@ export function validateConfig(cfg) {
|
|
|
212
254
|
if (!COMMAND_KEYS.includes(key)) errors.push(`commands.${key}: unknown command; use ${COMMAND_KEYS.join(', ')}`);
|
|
213
255
|
}
|
|
214
256
|
}
|
|
215
|
-
if (
|
|
257
|
+
if (cfg.configVersion === CONFIG_VERSION && Object.hasOwn(cfg, 'repos')) {
|
|
258
|
+
errors.push(`repos: removed in configVersion 2; list repositories in ${WORKSPACE_PATH}`);
|
|
259
|
+
}
|
|
216
260
|
for (const key of ['gitHost', 'tracker']) {
|
|
217
261
|
if (!isObject(cfg[key]) || typeof cfg[key].kind !== 'string') errors.push(`${key}.kind: must be a string`);
|
|
218
262
|
}
|
|
@@ -286,6 +330,8 @@ export function compileDestructive(cfg) {
|
|
|
286
330
|
return cfg.destructive.map((src) => new RegExp(src, 'i'));
|
|
287
331
|
}
|
|
288
332
|
|
|
333
|
+
// An older config is read migrated (D-60); the file is never written here, so a hook that loads the
|
|
334
|
+
// config leaves the tracked file as it is.
|
|
289
335
|
export function loadConfig(root) {
|
|
290
336
|
const file = path.join(root, CONFIG_PATH);
|
|
291
337
|
let text;
|
|
@@ -294,17 +340,46 @@ export function loadConfig(root) {
|
|
|
294
340
|
} catch {
|
|
295
341
|
throw new ConfigError([`config: cannot read ${CONFIG_PATH}`]);
|
|
296
342
|
}
|
|
297
|
-
let
|
|
343
|
+
let raw;
|
|
298
344
|
try {
|
|
299
|
-
|
|
345
|
+
raw = JSON.parse(text);
|
|
300
346
|
} catch {
|
|
301
347
|
throw new ConfigError([`config: ${CONFIG_PATH} is not valid JSON`]);
|
|
302
348
|
}
|
|
349
|
+
const { cfg } = migrateConfig(raw);
|
|
303
350
|
const errors = validateConfig(cfg);
|
|
304
351
|
if (errors.length > 0) throw new ConfigError(errors);
|
|
305
352
|
return cfg;
|
|
306
353
|
}
|
|
307
354
|
|
|
355
|
+
// REQ-5.6, D-60: the config file of `root` moved to CONFIG_VERSION when it is older, written through
|
|
356
|
+
// a temporary name and a rename. -> { from, to, changes }, or null when there is no config file, it
|
|
357
|
+
// is not JSON, or it is current. A newer configVersion throws ConfigNewerError and writes nothing.
|
|
358
|
+
// With `write` false the same answer is given and the file is left as it is (D-93: main() asks so
|
|
359
|
+
// on a slice branch or a slice's review branch, and for `slicekit branch`).
|
|
360
|
+
export function migrateConfigFile(root, { write = true } = {}) {
|
|
361
|
+
const file = path.join(root, CONFIG_PATH);
|
|
362
|
+
let raw;
|
|
363
|
+
try {
|
|
364
|
+
raw = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^/, ''));
|
|
365
|
+
} catch {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const { cfg, from, changes } = migrateConfig(raw);
|
|
369
|
+
if (cfg === raw || from === CONFIG_VERSION) return null;
|
|
370
|
+
if (!write) return { from, to: CONFIG_VERSION, changes };
|
|
371
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
372
|
+
try {
|
|
373
|
+
fs.writeFileSync(temporary, `${JSON.stringify(cfg, null, 2)}
|
|
374
|
+
`);
|
|
375
|
+
fs.renameSync(temporary, file);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
fs.rmSync(temporary, { force: true });
|
|
378
|
+
throw e;
|
|
379
|
+
}
|
|
380
|
+
return { from, to: CONFIG_VERSION, changes };
|
|
381
|
+
}
|
|
382
|
+
|
|
308
383
|
// The machine's own settings (D-43): `.slicekit/local.json`, untracked, in the session root (the
|
|
309
384
|
// main checkout). Only `testCommand` is read, by the build steps that run the test command on this
|
|
310
385
|
// machine (`build red`, `build commit --require-green`, `build pr`), and by the `commands` rule
|
package/src/release-version.js
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
// slices this run of the sync moved to `merged`. A sync with no such slice, and a config without
|
|
12
12
|
// `release.auto`, set none. The version counts from package.json at the merge commit, never from
|
|
13
13
|
// one an open sync pull request proposes. The rendered files follow the version (`update --yes`),
|
|
14
|
-
// as `build render` would commit them.
|
|
14
|
+
// as `build render` would commit them. So do the rendered files of each folder under `examples/`
|
|
15
|
+
// that holds a rendered directory (D-95): the sync renders each one at the same version, as
|
|
16
|
+
// `update --yes` would in that folder, and its pull request carries those files.
|
|
15
17
|
//
|
|
16
18
|
// Where a slice begins: the oldest commit of the default branch's first-parent history that brings
|
|
17
19
|
// its state file. For a merge commit or a squash merge that is the merge itself; for a rebase merge
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
import fs from 'node:fs';
|
|
36
38
|
import path from 'node:path';
|
|
37
39
|
import { fileURLToPath } from 'node:url';
|
|
38
|
-
import { CONFIG_PATH, ConfigError, releaseAutoError } from './config.js';
|
|
40
|
+
import { CONFIG_PATH, ConfigError, loadConfig, releaseAutoError } from './config.js';
|
|
39
41
|
import { GitError, git } from './git.js';
|
|
40
42
|
import { readText, writeText } from './fs.js';
|
|
41
43
|
import { ID, stateFileName } from './ids.js';
|
|
@@ -271,15 +273,87 @@ function sliceBegins(root, cfg, merge) {
|
|
|
271
273
|
return begins;
|
|
272
274
|
}
|
|
273
275
|
|
|
274
|
-
// The
|
|
275
|
-
|
|
276
|
-
|
|
276
|
+
// The files `update` renders for a config, and the directory of their reference copies.
|
|
277
|
+
const renderPaths = (cfg) => [...new Set([...entriesForShape(cfg.shape).map((e) => e.dest), SETTINGS]), RENDERED];
|
|
278
|
+
|
|
279
|
+
export const EXAMPLES = 'examples';
|
|
280
|
+
|
|
281
|
+
// The folders under `examples/` that hold rendered files (D-95): each one with a directory of
|
|
282
|
+
// reference copies, `.slicekit/rendered`, and a config. As POSIX paths from the root, sorted. A
|
|
283
|
+
// folder before init, such as one a walkthrough starts from, holds neither and is not one of them.
|
|
284
|
+
export function exampleDirs(root) {
|
|
285
|
+
const dir = path.join(root, EXAMPLES);
|
|
286
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
|
|
287
|
+
const isDir = (p) => fs.existsSync(p) && fs.statSync(p).isDirectory();
|
|
288
|
+
return fs
|
|
289
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
290
|
+
.filter((e) => e.isDirectory() && isDir(path.join(dir, e.name, RENDERED)) && fs.existsSync(path.join(dir, e.name, CONFIG_PATH)))
|
|
291
|
+
.map((e) => `${EXAMPLES}/${e.name}`)
|
|
292
|
+
.sort();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// The paths of the examples the release step may write: for each example, the files `update`
|
|
296
|
+
// renders for that example's own config and its reference copies. An example whose config cannot
|
|
297
|
+
// be read gives the paths every shape renders, so a file of it is still judged.
|
|
298
|
+
function examplePaths(root) {
|
|
299
|
+
const out = [];
|
|
300
|
+
for (const example of exampleDirs(root)) {
|
|
301
|
+
let paths;
|
|
302
|
+
try {
|
|
303
|
+
paths = renderPaths(loadExampleConfig(root, example));
|
|
304
|
+
} catch (e) {
|
|
305
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
306
|
+
paths = [SETTINGS, RENDERED];
|
|
307
|
+
}
|
|
308
|
+
for (const p of paths) out.push(`${example}/${p}`);
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// An example's config, read as it stands and migrated in memory (loadConfig writes nothing): the
|
|
314
|
+
// sync writes an example's rendered files and nothing else of it.
|
|
315
|
+
const loadExampleConfig = (root, example) => loadConfig(path.join(root, ...example.split('/')));
|
|
316
|
+
|
|
317
|
+
// The paths the release step may write: package.json, CHANGELOG.md, the files `update` renders
|
|
318
|
+
// and, given the root, the rendered files of each example under it (D-95).
|
|
319
|
+
export function releasePaths(cfg, root = null) {
|
|
320
|
+
return [PACKAGE, CHANGELOG, ...renderPaths(cfg), ...(root === null ? [] : examplePaths(root))];
|
|
277
321
|
}
|
|
278
|
-
export const isReleasePath = (cfg) => {
|
|
279
|
-
const
|
|
280
|
-
|
|
322
|
+
export const isReleasePath = (cfg, root = null) => {
|
|
323
|
+
const paths = releasePaths(cfg, root);
|
|
324
|
+
const dests = new Set(paths);
|
|
325
|
+
const dirs = paths.filter((p) => p === RENDERED || p.endsWith(`/${RENDERED}`)).map((p) => `${p}/`);
|
|
326
|
+
return (f) => dests.has(f) || dirs.some((d) => f.startsWith(d));
|
|
281
327
|
};
|
|
282
328
|
|
|
329
|
+
// The config of each example, read before the release step writes a file: [{ example, cfg }]. An
|
|
330
|
+
// example whose config does not load stops the step with one line naming its folder and the config
|
|
331
|
+
// problem, so the reader of the sync job's log knows which file to mend.
|
|
332
|
+
function exampleConfigs(root) {
|
|
333
|
+
return exampleDirs(root).map((example) => {
|
|
334
|
+
try {
|
|
335
|
+
return { example, cfg: loadExampleConfig(root, example) };
|
|
336
|
+
} catch (e) {
|
|
337
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
338
|
+
throw new ReleaseError(`${example}: its config does not load (${e.message}); no version is set and no file is written`);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Renders each example at `version`, as `update --yes` would in that folder: the files whose plan
|
|
344
|
+
// is changed or missing are written, an edited one is left, and the reference copies are that
|
|
345
|
+
// version's alone. Every example's config is read before the first one is rendered. Returns the
|
|
346
|
+
// examples rendered.
|
|
347
|
+
export function renderExamples(root, version, configs = exampleConfigs(root)) {
|
|
348
|
+
const out = [];
|
|
349
|
+
for (const { example, cfg } of configs) {
|
|
350
|
+
const dir = path.join(root, ...example.split('/'));
|
|
351
|
+
applyUpdate(dir, cfg, planUpdate(dir, cfg, { version }), { version });
|
|
352
|
+
out.push(example);
|
|
353
|
+
}
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
|
|
283
357
|
function phaseName(phaseDir, phaseId) {
|
|
284
358
|
for (const f of fs.readdirSync(phaseDir).filter((n) => n.endsWith('.md') && !/^S-\d+/.test(n)).sort()) {
|
|
285
359
|
const p = parsePhaseFile(readText(path.join(phaseDir, f)));
|
|
@@ -349,9 +423,12 @@ export function onDefaultTip(root, cfg) {
|
|
|
349
423
|
}
|
|
350
424
|
|
|
351
425
|
// Writes what releaseFor computed: package.json's version, the changelog section, and the render at
|
|
352
|
-
// that version (the kit's own checkout) or at the running kit's version (any other)
|
|
426
|
+
// that version (the kit's own checkout) or at the running kit's version (any other), of the
|
|
427
|
+
// repository's own files and then of each example under `examples/` (D-95). `isKit` says
|
|
353
428
|
// which; it defaults to whether `root` is the kit's checkout. Returns the release, or null when
|
|
354
|
-
// there is none or the files on disk already hold it (a second run on the same commit).
|
|
429
|
+
// there is none or the files on disk already hold it (a second run on the same commit). Every
|
|
430
|
+
// example's config is read first; one that does not load throws a ReleaseError naming the example,
|
|
431
|
+
// and package.json, CHANGELOG.md and every rendered file are left as they were.
|
|
355
432
|
export function applyRelease(root, cfg, { merge = 'HEAD', isKit = isKitRoot(root) } = {}) {
|
|
356
433
|
const release = releaseFor(root, cfg, { merge });
|
|
357
434
|
if (release === null) return null;
|
|
@@ -363,9 +440,12 @@ export function applyRelease(root, cfg, { merge = 'HEAD', isKit = isKitRoot(root
|
|
|
363
440
|
// the version computed and CHANGELOG.md on disk holds its section, an earlier run on this commit
|
|
364
441
|
// wrote them: this run writes nothing and sets no version.
|
|
365
442
|
if (versionOf(pkgText) === release.version && holdsSection(logText, release.version)) return null;
|
|
443
|
+
// Before the first write: an example whose config does not load refuses the release (ReleaseError).
|
|
444
|
+
const examples = exampleConfigs(root);
|
|
366
445
|
writeText(pkg, setVersion(pkgText, release.version));
|
|
367
446
|
writeText(log, prependSection(logText, release.section));
|
|
368
447
|
const version = isKit ? release.version : kitVersion();
|
|
369
448
|
applyUpdate(root, cfg, planUpdate(root, cfg, { version }), { version });
|
|
449
|
+
renderExamples(root, version, examples);
|
|
370
450
|
return release;
|
|
371
451
|
}
|
package/src/state/sync.js
CHANGED
|
@@ -74,7 +74,7 @@ export function syncFromHost(root, cfg, host) {
|
|
|
74
74
|
// `slicekit sync open` (03 REQ-3.11, D-78, D-80): after status --sync --write on the default branch's
|
|
75
75
|
// merge commit, the state change goes up for review instead of onto the default branch. The paths it
|
|
76
76
|
// may carry are the state directory, BUILD.md and the journal heads log, and with release.auto the
|
|
77
|
-
// files the release step writes (syncPaths, D-90); nothing else is staged. When
|
|
77
|
+
// files the release step writes, those of the examples included (syncPaths, D-90, D-95); nothing else is staged. When
|
|
78
78
|
// none of them changed it opens nothing. Otherwise it commits them on `sync/<short sha>` (a new branch
|
|
79
79
|
// from the merge commit), pushes that branch alone, opens `[sync] state after <short sha>` into the
|
|
80
80
|
// default branch through C-1, and starts the kit's workflow on the branch with workflow_dispatch, since
|
|
@@ -98,11 +98,12 @@ export const syncTitle = (short) => `[sync] state after ${short}`;
|
|
|
98
98
|
const posix = (p) => p.split(path.sep).join('/');
|
|
99
99
|
|
|
100
100
|
// The paths a sync commit may carry, relative to the repository root. With release.auto, also the
|
|
101
|
-
// files the release step writes: package.json, CHANGELOG.md
|
|
101
|
+
// files the release step writes: package.json, CHANGELOG.md, the rendered files (D-90) and the
|
|
102
|
+
// rendered files of each example under examples/ (D-95).
|
|
102
103
|
export function syncPaths(root, cfg) {
|
|
103
104
|
const p = kitPaths(root, cfg);
|
|
104
105
|
const state = [p.build, p.state, path.join(p.kit, 'journal-heads.log')].map((f) => posix(path.relative(root, f)));
|
|
105
|
-
return cfg.release?.auto === true ? [...state, ...releasePaths(cfg)] : state;
|
|
106
|
+
return cfg.release?.auto === true ? [...state, ...releasePaths(cfg, root)] : state;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
// git with ALLOW_PROTECTED_COMMIT taken out of the environment (REQ-3.11: the sync never sets it).
|
|
@@ -16,8 +16,10 @@ that reads the repository's history goes through `{{cli}}`; run no git or gh com
|
|
|
16
16
|
of the spec, each `##` section of the runbook), it prints the claim's ID, its `<file>:<line>` and
|
|
17
17
|
its title, the files the claim names, and one `candidate` line for each commit that touched one of
|
|
18
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
|
|
20
|
-
|
|
19
|
+
for a claim, the newest, then one line that counts the older ones and names the command that
|
|
20
|
+
prints them: `{{cli}} audit context <area> --all --no-report`. That form prints the context
|
|
21
|
+
alone, with every candidate and no report path, and reserves no report file, so the report of
|
|
22
|
+
this step stays the one the auditor writes. On exit 2 the area names no claim: print what it says and ask the human
|
|
21
23
|
for another area.
|
|
22
24
|
3. Spawn the auditor in audit mode. Its brief is the output of `{{cli}} instructions auditor`. Give
|
|
23
25
|
it the whole output of step 2 and the report path, and tell it this is an audit, not a gap scan:
|
|
@@ -9,8 +9,8 @@ what merged; it does not deploy (D-12).
|
|
|
9
9
|
|
|
10
10
|
## Steps
|
|
11
11
|
|
|
12
|
-
1. Run `{{cli}} release {{args}} --dry-run`. It writes nothing
|
|
13
|
-
it would write. When it exits 1 it prints one line per reason: a slice that is not merged, a
|
|
12
|
+
1. Run `{{cli}} release {{args}} --dry-run`. It writes nothing but the migration of an older config,
|
|
13
|
+
which step 2 carries to the release branch. When it exits 0 it prints the record it would write. When it exits 1 it prints one line per reason: a slice that is not merged, a
|
|
14
14
|
slice with no recorded pull request, a slice that says `runbook: yes` and neither changed a
|
|
15
15
|
section of the runbook nor gave a Runbook line that begins "no operational change", or a record
|
|
16
16
|
that already exists. Print those lines to the human and stop: the release waits for each one.
|
|
@@ -18,7 +18,9 @@ what merged; it does not deploy (D-12).
|
|
|
18
18
|
puts the session on `release/<slug>` at the tip of the default branch as origin has it; a
|
|
19
19
|
`release/<slug>` left behind that tip with no commit of its own is moved there, and the command
|
|
20
20
|
says so. When `release/<slug>` holds commits the default branch lacks, it asks the git host for
|
|
21
|
-
an open pull request of that branch and exits 1 with one of three lines
|
|
21
|
+
an open pull request of that branch and exits 1 with one of three lines. It asks the same of
|
|
22
|
+
each numbered branch of the slug, `release/<slug>-<n>`, that holds such commits, whatever
|
|
23
|
+
`release/<slug>` holds, and the first two lines then name that branch:
|
|
22
24
|
1. `release/<slug> is the branch of open pull request #<n> (<url>); the phase's release is
|
|
23
25
|
already open`: print the line to the human and stop. Take no other slug: merging or closing
|
|
24
26
|
that pull request is the human's.
|
|
@@ -45,7 +47,10 @@ what merged; it does not deploy (D-12).
|
|
|
45
47
|
**Decisions:** <the lines under "## Decisions" in the record, one per line, or "none">
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
6. Run `{{cli}} pr open --title "[release] {{args}}" --body-file <file> --commit "docs(release): {{args}}" --paths <docsRoot>/releases/{{args}}.md,.slicekit/state,BUILD.md`.
|
|
50
|
+
6. Run `{{cli}} pr open --title "[release] {{args}}" --body-file <file> --commit "docs(release): {{args}}" --paths <docsRoot>/releases/{{args}}.md,.slicekit/state,BUILD.md,.slicekit/config.json`.
|
|
51
|
+
The last path is the config: when an earlier command, such as step 1, wrote the migration of an
|
|
52
|
+
older config, step 2 carried it to the release branch, and this step commits it there (D-94).
|
|
53
|
+
A config with no change adds nothing to the commit.
|
|
49
54
|
7. Print the pull request line `pr open` printed, and tell the human that merging the pull request
|
|
50
55
|
is the release of {{args}} in this repository, and that it deploys nothing: deployment stays the
|
|
51
56
|
team's (D-12).
|