slicekit 0.8.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicekit",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Spec-driven agentic workflow kit",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -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
- function newestPerWorkflow(runs) {
112
- const byId = runs.every(hasId);
113
- if (!byId && !runs.every((r) => r.workflowName && r.event)) return runs;
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 = JSON.stringify(byId ? ['id', r.workflowDatabaseId, r.event ?? null] : ['name', r.workflowName, r.event]);
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
- const failed = runs.find((r) => !OK_CONCLUSIONS.has(r.conclusion));
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
@@ -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 (status.status === 'success' || status.status === 'failure' || waited >= wait) return status;
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
 
@@ -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/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);
@@ -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
- 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:
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>`. The slug is the program name (`name` in
13
- `.slicekit/config.json`) lower-cased, with each run of characters other than `a-z0-9` turned
14
- into one `-`, dashes trimmed from both ends, cut to 60 characters. That is the slug intake used,
15
- so the spec lands on the branch that holds the intake snapshot.
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