slicekit 0.7.5 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/adapters/githost/fixture.js +2 -2
- package/src/adapters/githost/gh-json.js +21 -7
- package/src/adapters/githost/github.js +2 -2
- package/src/brief.js +53 -3
- package/src/build/commit.js +28 -8
- package/src/build/finish.js +7 -3
- package/src/build/verdict.js +20 -2
- package/src/cli/build.js +2 -0
- package/src/hooks/pre-bash.js +35 -5
- package/src/hooks/pre-edit.js +15 -16
- package/src/next.js +12 -1
- package/src/release-version.js +17 -5
- package/src/stage.js +10 -3
- package/templates/instructions/commands/intake.md +1 -1
- package/templates/instructions/commands/specify.md +6 -4
package/package.json
CHANGED
|
@@ -177,9 +177,9 @@ export function fixtureHost(dir) {
|
|
|
177
177
|
const since = assertDate(isoDate);
|
|
178
178
|
return filterMergedSince(readJson(path.join(dir, 'merged-since.json')) ?? [], since);
|
|
179
179
|
},
|
|
180
|
-
ciStatus(sha) {
|
|
180
|
+
ciStatus(sha, { skipCancelled = false } = {}) {
|
|
181
181
|
assertSha(sha);
|
|
182
|
-
return reduceRuns(readJson(path.join(dir, `ci-${sha}.json`)) ?? []);
|
|
182
|
+
return reduceRuns(readJson(path.join(dir, `ci-${sha}.json`)) ?? [], { skipCancelled });
|
|
183
183
|
},
|
|
184
184
|
// As the GitHub host (decidedSlicekitRun): ci-<sha>.json narrowed to the slicekit workflow's
|
|
185
185
|
// pull_request runs, each completed one's jobs read from jobs-<databaseId>.json (none when the file
|
|
@@ -108,25 +108,39 @@ const hasId = (r) => r.workflowDatabaseId !== undefined && r.workflowDatabaseId
|
|
|
108
108
|
// re-run after a newer one is the newer answer (issue #42). createdAt for a run with no startedAt.
|
|
109
109
|
const startOf = (r) => String(r.startedAt || r.createdAt || '');
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
// With `skipCancelled` (issue #225), a cancelled run is no result while its group holds a run that
|
|
112
|
+
// was not cancelled: the workflow's concurrency cancelled it beside a live run on the same head.
|
|
113
|
+
function dropCancelled(runs, keyOf) {
|
|
114
|
+
const live = new Set(runs.filter((r) => r.conclusion !== 'cancelled').map(keyOf));
|
|
115
|
+
return runs.filter((r) => r.conclusion !== 'cancelled' || !live.has(keyOf(r)));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function newestPerWorkflow(all, { skipCancelled = false } = {}) {
|
|
119
|
+
const byId = all.every(hasId);
|
|
120
|
+
const grouped = byId || all.every((r) => r.workflowName && r.event);
|
|
121
|
+
const keyOf = (r) => (!grouped ? 'all' : JSON.stringify(byId ? ['id', r.workflowDatabaseId, r.event ?? null] : ['name', r.workflowName, r.event]));
|
|
122
|
+
const runs = skipCancelled ? dropCancelled(all, keyOf) : all;
|
|
123
|
+
if (!grouped) return runs;
|
|
114
124
|
const newest = new Map();
|
|
115
125
|
for (const r of runs) {
|
|
116
|
-
const key =
|
|
126
|
+
const key = keyOf(r);
|
|
117
127
|
const held = newest.get(key);
|
|
118
128
|
if (!held || startOf(r) > startOf(held)) newest.set(key, r);
|
|
119
129
|
}
|
|
120
130
|
return [...newest.values()];
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
export function reduceRuns(all) {
|
|
133
|
+
export function reduceRuns(all, { skipCancelled = false } = {}) {
|
|
124
134
|
if (!Array.isArray(all) || all.length === 0) return { status: 'unknown', url: null };
|
|
125
|
-
const runs = newestPerWorkflow(all);
|
|
135
|
+
const runs = newestPerWorkflow(all, { skipCancelled });
|
|
126
136
|
const going = runs.find((r) => r.status !== 'completed');
|
|
127
137
|
if (going) return { status: 'pending', url: going.url ?? null };
|
|
128
|
-
|
|
138
|
+
// With `skipCancelled`, a cancelled run left standing (no other run of its workflow on the head,
|
|
139
|
+
// as when it was cancelled by hand) is `cancelled`, not a failure, unless another run failed (D-132).
|
|
140
|
+
const failed = runs.find((r) => !OK_CONCLUSIONS.has(r.conclusion) && !(skipCancelled && r.conclusion === 'cancelled'));
|
|
129
141
|
if (failed) return { status: 'failure', url: failed.url ?? null };
|
|
142
|
+
const cancelled = skipCancelled ? runs.find((r) => r.conclusion === 'cancelled') : undefined;
|
|
143
|
+
if (cancelled) return { status: 'cancelled', url: cancelled.url ?? null };
|
|
130
144
|
return { status: 'success', url: runs[0].url ?? null };
|
|
131
145
|
}
|
|
132
146
|
|
|
@@ -199,9 +199,9 @@ export function githubHost(env = process.env, root = process.cwd(), exec = execF
|
|
|
199
199
|
const args = ['pr', 'list', '--state', 'merged', '--search', `merged:>=${day}`, '--limit', '200', '--json', LIST_FIELDS];
|
|
200
200
|
return filterMergedSince(ghJson(args), since);
|
|
201
201
|
},
|
|
202
|
-
ciStatus(sha) {
|
|
202
|
+
ciStatus(sha, { skipCancelled = false } = {}) {
|
|
203
203
|
assertSha(sha);
|
|
204
|
-
return reduceRuns(ghJson(['run', 'list', '--commit', sha, '--limit', '20', '--json', RUN_FIELDS]));
|
|
204
|
+
return reduceRuns(ghJson(['run', 'list', '--commit', sha, '--limit', '20', '--json', RUN_FIELDS]), { skipCancelled });
|
|
205
205
|
},
|
|
206
206
|
// D-49: the newest pull_request run of the slicekit workflow on a commit whose team command jobs
|
|
207
207
|
// were decided, and its jobs, or null (decidedSlicekitRun). One `gh run list`, then one `gh run
|
package/src/brief.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import crypto from 'node:crypto';
|
|
10
10
|
import fs from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
12
13
|
import { listFiles } from './fs.js';
|
|
13
14
|
import { commitPaths, currentBranch, git } from './git.js';
|
|
14
15
|
import { kitPaths } from './paths.js';
|
|
@@ -63,6 +64,50 @@ export function unlistedEmptySections(text) {
|
|
|
63
64
|
return BRIEF_HEADINGS.filter((h) => h !== OPEN && Object.hasOwn(under, h) && under[h].length === 0 && !open.has(h.toLowerCase()));
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// The kit's blank brief, `templates/brief/blank.md`: the guidance line it holds under each heading.
|
|
68
|
+
// Read once, when first asked.
|
|
69
|
+
const BLANK = fileURLToPath(new URL('../templates/brief/blank.md', import.meta.url));
|
|
70
|
+
let blank = null;
|
|
71
|
+
function blankBrief() {
|
|
72
|
+
if (blank !== null) return blank;
|
|
73
|
+
const lines = fs.readFileSync(BLANK, 'utf8').split(/\r?\n/).map((l) => l.trim());
|
|
74
|
+
const guidance = {};
|
|
75
|
+
let at = null;
|
|
76
|
+
for (const line of lines) {
|
|
77
|
+
if (line.startsWith('## ')) at = line.slice(3).trim();
|
|
78
|
+
else if (at !== null && line !== '') (guidance[at] ??= new Set()).add(line);
|
|
79
|
+
}
|
|
80
|
+
blank = { guidance };
|
|
81
|
+
return blank;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// What of the blank brief a brief still holds unfilled (issue #206): a title that still holds
|
|
85
|
+
// `<name>`, or a section whose only line is the guidance line the blank brief holds
|
|
86
|
+
// under that heading. -> the first such, as a phrase that follows the file's name, or null.
|
|
87
|
+
export function blankLeftover(text) {
|
|
88
|
+
const { guidance } = blankBrief();
|
|
89
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim());
|
|
90
|
+
const first = lines.find((l) => l.startsWith('# '));
|
|
91
|
+
if (first !== undefined && first.includes('<name>')) {
|
|
92
|
+
return `still has the blank brief's title "${first}"; put the brief's name in place of <name>`;
|
|
93
|
+
}
|
|
94
|
+
const under = {};
|
|
95
|
+
let at = null;
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
if (line.startsWith('## ')) {
|
|
98
|
+
at = line.slice(3).trim();
|
|
99
|
+
under[at] ??= [];
|
|
100
|
+
} else if (at !== null && line !== '') under[at].push(line);
|
|
101
|
+
}
|
|
102
|
+
for (const h of BRIEF_HEADINGS) {
|
|
103
|
+
const body = under[h] ?? [];
|
|
104
|
+
if (body.length === 1 && guidance[h]?.has(body[0])) {
|
|
105
|
+
return `has under ## ${h} only the blank brief's guidance line; replace it with the answer${h === OPEN ? ', or remove it when nothing is open' : `, or list ${h} under ## ${OPEN}`}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
66
111
|
function onWorkBranch(root, cfg, what) {
|
|
67
112
|
const branch = currentBranch(root);
|
|
68
113
|
if (branch === null || branch === cfg.defaultBranch || cfg.protectedBranches.includes(branch)) {
|
|
@@ -190,8 +235,10 @@ export function answer(root, cfg, { answer: text, unknown = false } = {}) {
|
|
|
190
235
|
}
|
|
191
236
|
|
|
192
237
|
// Ends the brief: refuses while a question waits, on the default or a protected branch, while a
|
|
193
|
-
// topic was never asked and answered (an unknown answer counts), while a heading is missing from the brief,
|
|
194
|
-
//
|
|
238
|
+
// topic was never asked and answered (an unknown answer counts), while a heading is missing from the brief,
|
|
239
|
+
// while a section's only line is the blank brief's guidance line under that heading (`blankLeftover`),
|
|
240
|
+
// or when a file under the spec directory appeared, changed or went since `brief start`; otherwise
|
|
241
|
+
// commits the brief alone.
|
|
195
242
|
export function done(root, cfg) {
|
|
196
243
|
const session = needSession(root);
|
|
197
244
|
if (session.pending) throw new BriefError(1, `answer the last question first: "${session.pending.question}" has no answer`);
|
|
@@ -204,8 +251,11 @@ export function done(root, cfg) {
|
|
|
204
251
|
const file = briefFile(root, cfg, session.slug);
|
|
205
252
|
const rel = briefRel(root, cfg, session.slug);
|
|
206
253
|
if (!fs.existsSync(file)) throw new BriefError(1, `${rel} is missing; run slicekit brief start ${session.slug} again`);
|
|
207
|
-
const
|
|
254
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
255
|
+
const missing = missingHeadings(text);
|
|
208
256
|
if (missing.length > 0) throw new BriefError(1, `${rel} has no section ## ${missing[0]}`);
|
|
257
|
+
const leftover = blankLeftover(text);
|
|
258
|
+
if (leftover !== null) throw new BriefError(1, `${rel} ${leftover}`);
|
|
209
259
|
const known = session.specFiles ?? {};
|
|
210
260
|
const now = specFilesNow(root, cfg);
|
|
211
261
|
for (const [f, digest] of Object.entries(now)) {
|
package/src/build/commit.js
CHANGED
|
@@ -312,16 +312,20 @@ function bringUntracked(wt, dir) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
// Makes git usable in the run directory (issue #107): a `.git` directory of its own that holds a
|
|
315
|
-
// copy of the worktree's index and HEAD
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
//
|
|
315
|
+
// copy of the worktree's index and HEAD, a copy of the repository's config, `shallow` and
|
|
316
|
+
// `info/exclude`, a copy of every ref the worktree sees, and the repository's objects as alternates.
|
|
317
|
+
// A git command there sees every tracked file as staged and no unstaged change. What it writes stays
|
|
318
|
+
// in that directory: the index, the objects of a commit, the refs, HEAD and their logs, so a test
|
|
319
|
+
// command that commits or moves a branch there (`git commit`, `git branch -f`, `git reset`) moves no
|
|
320
|
+
// ref of the repository and leaves it no object (issue #184). Nothing is registered in the
|
|
321
|
+
// repository, so removing the directory leaves no trace of it.
|
|
319
322
|
function gitIn(wt, dir) {
|
|
320
323
|
const own = path.join(dir, '.git');
|
|
321
324
|
if (fs.existsSync(own)) return;
|
|
322
325
|
const abs = (p) => path.resolve(wt, p);
|
|
326
|
+
const gitPath = (name) => abs(git(wt, ['rev-parse', '--git-path', name]));
|
|
323
327
|
const common = abs(git(wt, ['rev-parse', '--git-common-dir']));
|
|
324
|
-
const
|
|
328
|
+
const forward = (p) => p.split(path.sep).join('/');
|
|
325
329
|
let head;
|
|
326
330
|
try {
|
|
327
331
|
head = `ref: ${git(wt, ['symbolic-ref', '-q', 'HEAD'])}`;
|
|
@@ -329,10 +333,26 @@ function gitIn(wt, dir) {
|
|
|
329
333
|
if (!(e instanceof GitError)) throw e;
|
|
330
334
|
head = git(wt, ['rev-parse', 'HEAD']);
|
|
331
335
|
}
|
|
332
|
-
fs.mkdirSync(own);
|
|
336
|
+
fs.mkdirSync(path.join(own, 'objects', 'info'), { recursive: true });
|
|
337
|
+
fs.mkdirSync(path.join(own, 'refs', 'heads'), { recursive: true });
|
|
338
|
+
fs.mkdirSync(path.join(own, 'refs', 'tags'), { recursive: true });
|
|
339
|
+
fs.mkdirSync(path.join(own, 'info'), { recursive: true });
|
|
333
340
|
fs.writeFileSync(path.join(own, 'HEAD'), `${head}\n`);
|
|
334
|
-
fs.writeFileSync(path.join(own, '
|
|
335
|
-
|
|
341
|
+
fs.writeFileSync(path.join(own, 'objects', 'info', 'alternates'), `${forward(path.join(common, 'objects'))}\n`);
|
|
342
|
+
for (const [from, to] of [[gitPath('config'), 'config'], [gitPath('shallow'), 'shallow'], [gitPath('info/exclude'), path.join('info', 'exclude')], [gitPath('index'), 'index']]) {
|
|
343
|
+
if (fs.existsSync(from)) fs.copyFileSync(from, path.join(own, to));
|
|
344
|
+
}
|
|
345
|
+
// The copied refs are files, so the copy's config must not ask for another ref store; and its
|
|
346
|
+
// work tree is the run directory, wherever the repository's config put its own.
|
|
347
|
+
for (const key of ['extensions.refstorage', 'core.worktree', 'core.bare']) {
|
|
348
|
+
try {
|
|
349
|
+
git(wt, ['config', '--file', path.join(own, 'config'), '--unset-all', key]);
|
|
350
|
+
} catch (e) {
|
|
351
|
+
if (!(e instanceof GitError)) throw e;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const refs = git(wt, ['for-each-ref', '--format=%(objectname) %(refname)']);
|
|
355
|
+
fs.writeFileSync(path.join(own, 'packed-refs'), refs === '' ? '' : `${refs}\n`);
|
|
336
356
|
}
|
|
337
357
|
|
|
338
358
|
// The test command run in a temporary directory holding the index as staged (git checkout-index),
|
package/src/build/finish.js
CHANGED
|
@@ -54,12 +54,13 @@ function setProof(cfg, host, number, ci) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// ciStatus(sha) until it is success or failure, or `wait` seconds are spent, sleeping `interval`
|
|
57
|
-
// seconds (the last nap cut to what is left) between asks.
|
|
57
|
+
// seconds (the last nap cut to what is left) between asks. A cancelled run beside another run of the
|
|
58
|
+
// same workflow on the head is skipped, so the live one is waited on (issue #225).
|
|
58
59
|
function pollCi(host, sha, { wait, interval, sleep }) {
|
|
59
60
|
let waited = 0;
|
|
60
61
|
for (;;) {
|
|
61
|
-
const status = host.ciStatus(sha);
|
|
62
|
-
if (
|
|
62
|
+
const status = host.ciStatus(sha, { skipCancelled: true });
|
|
63
|
+
if (['success', 'failure', 'cancelled'].includes(status.status) || waited >= wait) return status;
|
|
63
64
|
const nap = Math.min(interval, wait - waited);
|
|
64
65
|
sleep(nap);
|
|
65
66
|
waited += nap;
|
|
@@ -123,6 +124,9 @@ export function finish(root, cfg, host, id, { worktree, wait = FINISH_WAIT, inte
|
|
|
123
124
|
|
|
124
125
|
const status = pollCi(host, live, { wait, interval, sleep });
|
|
125
126
|
if (status.status === 'failure') throw new BuildError(`CI failed on ${short(live)}${status.url ? `: ${status.url}` : ''}`);
|
|
127
|
+
if (status.status === 'cancelled') {
|
|
128
|
+
throw new BuildError(`CI run cancelled on ${short(live)}${status.url ? `: ${status.url}` : ''}; re-run it, then run slicekit build finish ${id} again`);
|
|
129
|
+
}
|
|
126
130
|
if (status.status === 'unknown') throw new BuildError(`no CI run found for ${short(live)}; check that the workflow ran`);
|
|
127
131
|
if (status.status !== 'success') throw new BuildError(`CI still running on ${short(live)}; run slicekit build finish ${id} again`);
|
|
128
132
|
|
package/src/build/verdict.js
CHANGED
|
@@ -187,6 +187,20 @@ export function extraRounds(root, cfg, id) {
|
|
|
187
187
|
return readDecisions(text).rows.filter((r) => r.table === 'settled' && names.test(r.answer) && /\bone more round\b/i.test(r.answer)).length;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
// The default branch fetched from origin, as `review start` fetches it, so the decision rows
|
|
191
|
+
// extraRounds counts include one merged on origin since the last fetch (issue #215, D-101). -> null,
|
|
192
|
+
// or the line saying the fetch failed and the local copy is counted.
|
|
193
|
+
export function fetchDefaultBranch(root, cfg) {
|
|
194
|
+
const branch = cfg.defaultBranch;
|
|
195
|
+
try {
|
|
196
|
+
git(root, ['fetch', '-q', 'origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`]);
|
|
197
|
+
return null;
|
|
198
|
+
} catch (e) {
|
|
199
|
+
if (!(e instanceof GitError)) throw e;
|
|
200
|
+
return `could not fetch ${branch} from origin; the decision rows are counted from the local copy, ${defaultRef(root, cfg).replace(/^refs\/(?:remotes|heads)\//, '')}`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
190
204
|
// Whether one more independent round may start after the independent verdicts recorded, given as
|
|
191
205
|
// their blocker counts in round order: the first always; a second only when the first left a blocker;
|
|
192
206
|
// any later one only with a decision row for it (`extra` rows allow `extra` rounds beyond those).
|
|
@@ -498,6 +512,10 @@ export function recordVerdict(root, cfg, host, id, file, { worktree, independent
|
|
|
498
512
|
onFetchFail: resuming ? 'last-fetch' : `could not reach origin to check ${held.branch}; a new verdict needs a fresh fetch`,
|
|
499
513
|
});
|
|
500
514
|
|
|
515
|
+
// An independent round counts the decision rows on the default branch as origin has it now.
|
|
516
|
+
const fetchNote = independent ? fetchDefaultBranch(root, cfg) : null;
|
|
517
|
+
const noted = (r) => (fetchNote ? { ...r, fetchNote } : r);
|
|
518
|
+
|
|
501
519
|
if (resuming) {
|
|
502
520
|
assertBuilt(wt, id, current);
|
|
503
521
|
// The round as committed: a hand edit of the working copy since does not change what it says.
|
|
@@ -508,7 +526,7 @@ export function recordVerdict(root, cfg, host, id, file, { worktree, independent
|
|
|
508
526
|
}
|
|
509
527
|
const v = checked(text, rel, name, independent);
|
|
510
528
|
const result = outcomeOf(root, cfg, id, current.pr.number, k, v, verdicts, independent, rounds);
|
|
511
|
-
return withNextPath(root, id, finish(wt, cfg, host, id, current, result, verdicts, independent), verdicts, independent);
|
|
529
|
+
return noted(withNextPath(root, id, finish(wt, cfg, host, id, current, result, verdicts, independent), verdicts, independent));
|
|
512
530
|
}
|
|
513
531
|
|
|
514
532
|
// D-18: two in-loop rounds, one for a quick slice (D-103); independent verdicts (D-39) do not count against them.
|
|
@@ -547,5 +565,5 @@ export function recordVerdict(root, cfg, host, id, file, { worktree, independent
|
|
|
547
565
|
commitBookkeeping(wt, id, `verdict r${k}`, [rel]);
|
|
548
566
|
const state = recordState(wt, cfg, id, 'in-review', { verdict: { round: k, path: rel, blockers: blockerCount, independent } });
|
|
549
567
|
const result = outcomeOf(root, cfg, id, state.pr.number, k, v, state.verdicts, independent, rounds);
|
|
550
|
-
return withNextPath(root, id, finish(wt, cfg, host, id, state, result, state.verdicts, independent), state.verdicts, independent);
|
|
568
|
+
return noted(withNextPath(root, id, finish(wt, cfg, host, id, state, result, state.verdicts, independent), state.verdicts, independent));
|
|
551
569
|
}
|
package/src/cli/build.js
CHANGED
|
@@ -178,6 +178,8 @@ function verdictStep(root, io, positionals, values) {
|
|
|
178
178
|
if (r.verdictPath) out.push(`verdict ${r.verdictPath}`);
|
|
179
179
|
// D-101: the command of the next independent round, when one is left after a blocker.
|
|
180
180
|
if (r.reviewStart) out.push(`review: ${r.reviewStart}`);
|
|
181
|
+
// Issue #215: the default branch could not be fetched, so its rows were counted from the local copy.
|
|
182
|
+
if (r.fetchNote) io.stderr(`slicekit: ${r.fetchNote}\n`);
|
|
181
183
|
io.stdout(out.map((l) => `${l}\n`).join(''));
|
|
182
184
|
if (r.next === 'stuck') {
|
|
183
185
|
io.stderr(`slicekit: stopped: ${r.blockers.join(', ')} survive round ${r.round}; the pull request stays draft\n${r.stop ? `${r.stop}\n` : ''}`);
|
package/src/hooks/pre-bash.js
CHANGED
|
@@ -564,7 +564,9 @@ GIT_LONG.stage = GIT_LONG.add;
|
|
|
564
564
|
// does not guess, and the caller refuses the command as one it cannot judge (verdict P6-S-52-r2 H-8).
|
|
565
565
|
// A prefix of several options (`--f`) is refused the same way, naming the first: git itself refuses
|
|
566
566
|
// an ambiguous one, so nothing git would run is lost. A word after `--`, and the value of an option
|
|
567
|
-
// that takes one, is not an option.
|
|
567
|
+
// that takes one, is not an option. Git reads a short option that takes a value as taking the rest of
|
|
568
|
+
// its word when anything follows it there (`-oo`, `-bb`), and the next word only when nothing does
|
|
569
|
+
// (issue #180).
|
|
568
570
|
function cutOption(sub, args) {
|
|
569
571
|
const spec = Object.hasOwn(GIT_LONG, sub ?? '') ? GIT_LONG[sub] : null;
|
|
570
572
|
if (spec === null) return null;
|
|
@@ -580,8 +582,9 @@ function cutOption(sub, args) {
|
|
|
580
582
|
}
|
|
581
583
|
const full = all.find((o) => o.startsWith(name));
|
|
582
584
|
if (full !== undefined) return { cut: name, full };
|
|
583
|
-
} else if (/^-[A-Za-z]+$/.test(a)
|
|
584
|
-
|
|
585
|
+
} else if (/^-[A-Za-z]+$/.test(a)) {
|
|
586
|
+
const at = [...a.slice(1)].findIndex((c) => spec.short.includes(c));
|
|
587
|
+
if (at === a.length - 2) k += 1;
|
|
585
588
|
}
|
|
586
589
|
}
|
|
587
590
|
return null;
|
|
@@ -946,6 +949,32 @@ function inPlaceFiles(args) {
|
|
|
946
949
|
return args.slice(k).filter((a) => !a.startsWith('-') || a === '-');
|
|
947
950
|
}
|
|
948
951
|
|
|
952
|
+
// Whether the arguments of `git clean` ask for a dry run (`-n`, `--dry-run`), read as git reads them:
|
|
953
|
+
// `-e` takes the rest of its word when anything follows it there and the next word when nothing does,
|
|
954
|
+
// `--exclude` takes the next word unless written with `=`, and a value is no option. A word after
|
|
955
|
+
// `--` is a path.
|
|
956
|
+
function cleanDryRun(args) {
|
|
957
|
+
let dry = false;
|
|
958
|
+
for (let k = 0; k < args.length; k++) {
|
|
959
|
+
const a = args[k];
|
|
960
|
+
if (a === '--') break;
|
|
961
|
+
if (a.startsWith('--')) {
|
|
962
|
+
const name = a.split('=')[0];
|
|
963
|
+
if (name === '--exclude' && !a.includes('=')) k += 1;
|
|
964
|
+
else if (name === '--dry-run') dry = true;
|
|
965
|
+
} else if (a.startsWith('-') && a.length > 1) {
|
|
966
|
+
for (let j = 1; j < a.length; j++) {
|
|
967
|
+
if (a[j] === 'e') {
|
|
968
|
+
if (j === a.length - 1) k += 1;
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
if (a[j] === 'n') dry = true;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return dry;
|
|
976
|
+
}
|
|
977
|
+
|
|
949
978
|
// `git checkout`, `git restore`, `git rm` and `git mv` (issue #105) -> the paths the command writes in
|
|
950
979
|
// the work tree, each resolved in the directory `-C` names. A path covers what lies under it, and git
|
|
951
980
|
// matches `*` across directories. A pathspec the text does not settle (`:(glob)...`, `:/`,
|
|
@@ -979,8 +1008,9 @@ function gitWrites(w, cwd) {
|
|
|
979
1008
|
return (verb === 'push' || verb === undefined) && sep !== -1 && args.length > sep + 1 ? specs(args.slice(sep + 1)) : every;
|
|
980
1009
|
}
|
|
981
1010
|
if (sub === 'clean') {
|
|
982
|
-
// A dry run removes nothing, with `-f` or without.
|
|
983
|
-
|
|
1011
|
+
// A dry run removes nothing, with `-f` or without. The value of `-e` or `--exclude` is a pattern,
|
|
1012
|
+
// never a dry run: `-e --dry-run`, `-fe --dry-run`, `--exclude --dry-run` and `-fen` (issue #181).
|
|
1013
|
+
if (cleanDryRun(args) && !negates) return [];
|
|
984
1014
|
const named = positionals(args, new Set(['-e', '--exclude']));
|
|
985
1015
|
return named.length ? specs(named) : every;
|
|
986
1016
|
}
|
package/src/hooks/pre-edit.js
CHANGED
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
// file), except the runbook, anything in the slice's own phase directory, and a path the slice file's
|
|
19
19
|
// Expected changes names (D-102).
|
|
20
20
|
//
|
|
21
|
-
// The file's own root is
|
|
22
|
-
//
|
|
23
|
-
//
|
|
21
|
+
// The file's own root is its git top level, judged by the config there (a config in a plain folder of
|
|
22
|
+
// a repository, such as `examples/backend`, makes no root), else the nearest directory above it
|
|
23
|
+
// holding `.slicekit/config.json`, else the session's root: a session in the main checkout editing a
|
|
24
|
+
// nested worktree or clone is judged by its branch, state and config. Paths are canonicalised through the real path of
|
|
24
25
|
// their deepest existing ancestor, so 8.3 short names and links resolve; for rule (4) the path is also
|
|
25
26
|
// judged as named, with a leading link or junction that reaches the root or a directory in it read as
|
|
26
27
|
// that directory, and a relative name against the working directory as given; on win32 a `:` after the drive
|
|
@@ -97,30 +98,28 @@ function kitOwned(abs) {
|
|
|
97
98
|
&& segs.slice(0, i).some((p) => p === '.git' || p.endsWith('.git')));
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
// The file's own root:
|
|
101
|
-
//
|
|
101
|
+
// The file's own root: its git top level (a repository's, a worktree's or a clone's), judged by the
|
|
102
|
+
// config there when it holds `.slicekit/config.json`. A config in a plain folder of a repository,
|
|
103
|
+
// such as an example kept under `examples/`, makes no root, so the repository's config judges the
|
|
104
|
+
// folder's files (issue #203); a config in the main checkout never stands in for a nested worktree
|
|
105
|
+
// or clone. With no git top level, the nearest directory above the file holding a config; null for
|
|
106
|
+
// neither.
|
|
102
107
|
function ownRoot(abs) {
|
|
103
108
|
let start = existingAncestor(abs);
|
|
104
109
|
if (!fs.statSync(start).isDirectory()) start = path.dirname(start);
|
|
105
|
-
let configured = null;
|
|
106
|
-
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
107
|
-
if (fs.existsSync(path.join(dir, CONFIG_PATH))) {
|
|
108
|
-
configured = real(dir);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (path.dirname(dir) === dir) break;
|
|
112
|
-
}
|
|
113
110
|
let top = null;
|
|
114
111
|
try {
|
|
115
112
|
top = real(path.resolve(git(start, ['rev-parse', '--show-toplevel'])));
|
|
116
113
|
} catch (e) {
|
|
117
114
|
if (!(e instanceof GitError)) throw e;
|
|
118
115
|
}
|
|
119
|
-
if (
|
|
120
|
-
|
|
116
|
+
if (top) return { root: top, config: fs.existsSync(path.join(top, CONFIG_PATH)) };
|
|
117
|
+
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
118
|
+
if (fs.existsSync(path.join(dir, CONFIG_PATH))) return { root: real(dir), config: true };
|
|
119
|
+
if (path.dirname(dir) === dir) return null;
|
|
120
|
+
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
123
|
// Whether rel lies inside the slice's own phase directory, `<docs>/phases/P<n>[-name]/`.
|
|
125
124
|
function inOwnPhase(rel, phasesRel, sliceId) {
|
|
126
125
|
if (!under(rel, phasesRel) || same(rel, phasesRel)) return false;
|
package/src/next.js
CHANGED
|
@@ -192,8 +192,19 @@ function sliceStep(root, cfg, slice, rows) {
|
|
|
192
192
|
reviewThen,
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
|
-
case 'in-review':
|
|
195
|
+
case 'in-review': {
|
|
196
|
+
// build verdict leaves an in-loop blocker at in-review while a round is left (issue #230): the
|
|
197
|
+
// fixer answers it, as at changes-requested; build finish would refuse the open blocker.
|
|
198
|
+
const latest = verdicts.at(-1);
|
|
199
|
+
const blockers = latest && !latest.independent ? latestBlockers(root, wt, latest, reviewWt) : [];
|
|
200
|
+
if (blockers.length > 0 && inLoop < rounds) {
|
|
201
|
+
return agent(
|
|
202
|
+
`${id} has open blockers ${blockers.join(', ')} on #${n}: the fixer answers them, then build commit and build pr open the round ${verdicts.length + 1} review (/slicekit build, step 7)`,
|
|
203
|
+
`${cli} instructions fixer ${id} --worktree ${wt}`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
196
206
|
return agent(`${id} is in-review on #${n}: wait for green CI and mark the pull request ready (/slicekit build, step 9)`, `${cli} build finish ${id} --worktree ${wt}`);
|
|
207
|
+
}
|
|
197
208
|
case 'changes-requested': {
|
|
198
209
|
const latest = verdicts.at(-1);
|
|
199
210
|
const blockers = latestBlockers(root, wt, latest, reviewWt);
|
package/src/release-version.js
CHANGED
|
@@ -214,13 +214,25 @@ function namesSlice(sections, id) {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
// Whether a changelog section holds the line of the phase `id` (P1), with or without a name: the
|
|
217
|
-
// phase has had its minor version (D-96). Phase 1's line is not Phase 11's.
|
|
217
|
+
// phase has had its minor version (D-96). Phase 1's line is not Phase 11's. The section counts when
|
|
218
|
+
// one line of it is the phase line on its own, whatever stands above or below it, or when a paragraph
|
|
219
|
+
// is: consecutive lines joined, so a line wrapped over two or more lines, or written by hand without
|
|
220
|
+
// its final full stop, still counts (issue #183). A blank line, a heading line (`#`) and a list line
|
|
221
|
+
// each end a paragraph and are no part of one.
|
|
218
222
|
function namesPhase(sections, id) {
|
|
219
223
|
const number = id.replace(/^P/, '');
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
const shape = new RegExp(`^Phase ${number}(?:: \\S.*?)?\\.?$`);
|
|
225
|
+
const bound = /^(?:#|(?:[-*+]|\d+[.)])\s)/;
|
|
226
|
+
const paragraphs = [];
|
|
227
|
+
let open = null;
|
|
228
|
+
for (const l of sections) {
|
|
229
|
+
const line = l.trim();
|
|
230
|
+
if (shape.test(line)) return true;
|
|
231
|
+
if (line === '' || bound.test(line)) open = null;
|
|
232
|
+
else if (open === null) open = paragraphs.push(line) - 1;
|
|
233
|
+
else paragraphs[open] += ` ${line}`;
|
|
234
|
+
}
|
|
235
|
+
return paragraphs.some((p) => shape.test(p));
|
|
224
236
|
}
|
|
225
237
|
|
|
226
238
|
// Whether the commit `rev` set the version: package.json at it holds a version and CHANGELOG.md at
|
package/src/stage.js
CHANGED
|
@@ -6,7 +6,7 @@ import { GitError, assertRef, git, hasCommits, isRepo } from './git.js';
|
|
|
6
6
|
import { readDecisions } from './decisions.js';
|
|
7
7
|
import { blankCodeSpans, headings, lines, prose, refs, tables } from './markdown.js';
|
|
8
8
|
import { re } from './ids.js';
|
|
9
|
-
import { missingHeadings, unlistedEmptySections } from './brief.js';
|
|
9
|
+
import { blankLeftover, missingHeadings, unlistedEmptySections } from './brief.js';
|
|
10
10
|
import { kitPaths } from './paths.js';
|
|
11
11
|
import { findSliceFiles, parseSliceFile } from './slicefile.js';
|
|
12
12
|
import { listSlices } from './state/index.js';
|
|
@@ -306,8 +306,10 @@ function release(root, cfg) {
|
|
|
306
306
|
|
|
307
307
|
// The optional brief stage (REQ-1.7, D-99), outside STAGES: no stage after it reads the brief folder.
|
|
308
308
|
// Complete when there is a brief and every file under `<docsRoot>/brief/` other than `.keep` has
|
|
309
|
-
// every section of REQ-2.15, each topic section filled or listed under Open questions
|
|
310
|
-
//
|
|
309
|
+
// every section of REQ-2.15, each topic section filled or listed under Open questions, and nothing of
|
|
310
|
+
// the blank brief left unfilled (`blankLeftover`: a title holding `<name>`, a section whose only line
|
|
311
|
+
// is the blank brief's guidance line); the blockers name each file and its first missing section,
|
|
312
|
+
// else what of the blank brief it still holds, else its first empty section not listed there.
|
|
311
313
|
export function briefStage(root, cfg) {
|
|
312
314
|
const dir = kitPaths(root, cfg).brief;
|
|
313
315
|
const files = exists(dir) ? listFiles(dir).filter((f) => path.posix.basename(f) !== '.keep') : [];
|
|
@@ -320,6 +322,11 @@ export function briefStage(root, cfg) {
|
|
|
320
322
|
blockers.push(`${rel(root, path.join(dir, f))} has no section ## ${missing[0]}`);
|
|
321
323
|
continue;
|
|
322
324
|
}
|
|
325
|
+
const leftover = blankLeftover(text);
|
|
326
|
+
if (leftover !== null) {
|
|
327
|
+
blockers.push(`${rel(root, path.join(dir, f))} ${leftover}`);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
323
330
|
const empty = unlistedEmptySections(text);
|
|
324
331
|
if (empty.length > 0) {
|
|
325
332
|
blockers.push(`${rel(root, path.join(dir, f))} has an empty section ## ${empty[0]} that is not listed under ## Open questions`);
|
|
@@ -12,7 +12,7 @@ When a `{{cli}}` step exits with a code other than 0, stop and show the human it
|
|
|
12
12
|
|
|
13
13
|
## 1. The work branch
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
When the source is a brief at `<docsRoot>/brief/<slug>.md`, the branch takes the brief's slug, the `<slug>` of that path, because `/slicekit brief` committed the brief on `spec/<slug>` and the snapshot, the answers and the spec land on that one branch. Otherwise, for any other source, the slug is the program name (`name` in `.slicekit/config.json`) lower-cased, with each run of characters other than `a-z0-9` turned into one `-`, dashes trimmed from both ends, cut to 60 characters, then dashes trimmed again; it is `source` if nothing is left. The snapshot in step 2 names its file by the same rule, applied to the source's base name without its extension. Then run:
|
|
16
16
|
|
|
17
17
|
`{{cli}} branch spec <slug>`
|
|
18
18
|
|
|
@@ -9,10 +9,12 @@ repository's history goes through `{{cli}}`; run no git or gh command yourself.
|
|
|
9
9
|
|
|
10
10
|
## Steps
|
|
11
11
|
|
|
12
|
-
1. Run `{{cli}} branch spec <slug>`.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
1. Run `{{cli}} branch spec <slug>`. Take the slug of the `spec/<slug>` branch that holds the
|
|
13
|
+
newest snapshot under `<docsRoot>/intake/`: intake named it after the brief's slug when its
|
|
14
|
+
source was a brief at `<docsRoot>/brief/<slug>.md`, and after the program name otherwise. The
|
|
15
|
+
program's slug is `name` in `.slicekit/config.json` lower-cased, with each run of characters
|
|
16
|
+
other than `a-z0-9` turned into one `-`, dashes trimmed from both ends, cut to 60 characters. The
|
|
17
|
+
spec then lands on the branch that holds the brief, the intake snapshot and the answers.
|
|
16
18
|
2. Run `{{cli}} stage require clarify`. On exit 1, print what it says and stop: the spec waits for
|
|
17
19
|
intake and clarify.
|
|
18
20
|
3. Read every snapshot under `<docsRoot>/intake/` and every row of `<docsRoot>/decisions.md`. These
|