@warren-dean/code-kit 0.35.0 → 0.36.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.
@@ -22,6 +22,17 @@ import { ciFindings } from './ci.mjs';
22
22
  import { costReport, infraFiles, money } from './costs.mjs';
23
23
  import { storyModels } from './dispatches.mjs';
24
24
  import { pickPerLane } from './schedule.mjs';
25
+ import { leadSessions } from './sessions.mjs';
26
+ import { decidedFor, promotions } from './promote.mjs';
27
+ import {
28
+ coreRequests,
29
+ hasStreams,
30
+ heldByCore,
31
+ lanesToGiveWay,
32
+ platformOf,
33
+ streamOfLane,
34
+ streamOfStory,
35
+ } from './streams.mjs';
25
36
  import { reconcileAll } from './events.mjs';
26
37
  import { readCache, teamOf } from './team.mjs';
27
38
  import { driftHoldWords, driftHolds, driftUnchecked, storyOfBranch } from './teamfacts.mjs';
@@ -133,7 +144,13 @@ const hasMarkdown = (dir) => {
133
144
  * review), `merge` (the head of the merge queue, where the lead merges), `wait` (lanes are
134
145
  * building) or `done`. `base(config)` resolves the branch lanes merge into.
135
146
  */
136
- export function nextStep(root, base) {
147
+ /**
148
+ * The next step for the lead. STRM-3: with `stream`, in a project built as streams, only that stream's
149
+ * stories (a lead with no stream leads every stream without a lead of its own); `projectWide` is whether
150
+ * this lead also takes the steps for the whole project (code-kit's instructions and rules, the merge
151
+ * queue, setup), which belong to the lead in the main checkout.
152
+ */
153
+ export function nextStep(root, base, { stream = null, projectWide = true } = {}) {
137
154
  const attention = [];
138
155
  // ASK-4: the brief's open questions, for the person's Decisions tab.
139
156
  let briefQuestions = [];
@@ -273,7 +290,7 @@ export function nextStep(root, base) {
273
290
  // read and validated above; nothing to add
274
291
  }
275
292
  const [setup] = pendingSetup(raw, root);
276
- if (setup) return result('setup', setup.why, { args: setup.skill });
293
+ if (setup && projectWide) return result('setup', setup.why, { args: setup.skill });
277
294
  // ONB-5: a project set up before setup did all of this is told what re-running init adds; when
278
295
  // ONB-6 finds what it's missing, no new story starts until init has added it.
279
296
  const older = (raw?.setup ?? 1) < SETUP_VERSION;
@@ -304,7 +321,7 @@ export function nextStep(root, base) {
304
321
  } catch {
305
322
  // an unreadable log: recovery falls back to git, as before
306
323
  }
307
- if (unsettled.length) {
324
+ if (unsettled.length && projectWide) {
308
325
  const stories = [...new Set(unsettled.map((u) => u.story))];
309
326
  return result(
310
327
  'reconcile',
@@ -404,6 +421,27 @@ export function nextStep(root, base) {
404
421
  // ONB-2: design stories, designed with the person before any screen that depends on them is built.
405
422
  const forDesign = readyStories.filter((s) => buildable(s) && s.lane === DESIGN).map((s) => s.id);
406
423
  const unbuildable = readyStories.filter((s) => !buildable(s)).map((s) => s.id);
424
+ // STRM-3: a stream's lead gets its own stream's stories; one leading with no stream of its own gets
425
+ // those of every stream that has no lead.
426
+ const streamed = hasStreams(config);
427
+ const streamOf = new Map(status.stories.map((s) => [s.id, streamOfStory(config, s)]));
428
+ const led = new Set(leadSessions(root).flatMap((l) => (l.stream ? [l.stream] : [])));
429
+ const mine = (id) =>
430
+ !streamed || (stream ? streamOf.get(id) === stream : !led.has(streamOf.get(id)));
431
+ // STRM-6: every stream's waiting stories, for whose turn a shared core lane is.
432
+ const othersWaiting = streamed
433
+ ? [...fixes, ...ready].map((id) => ({
434
+ lane: status.stories.find((s) => s.id === id)?.lane,
435
+ stream: streamOf.get(id),
436
+ }))
437
+ : [];
438
+ // STRM-7: a story waiting on a change request to core waits for the platform's decision, or its story.
439
+ const coreHeld = streamed ? heldByCore(root, status.stories) : new Map();
440
+ for (const list of [review, building, blocked, fixes, ready, forLead, forDesign, unbuildable])
441
+ list.splice(0, list.length, ...list.filter(mine));
442
+ for (const list of [fixes, ready, forLead])
443
+ list.splice(0, list.length, ...list.filter((id) => !coreHeld.has(id)));
444
+ for (const [id, why] of coreHeld) if (mine(id)) attention.push(`${why}.`);
407
445
  // ONB-6: work already started finishes; nothing new starts until init has filled the gaps.
408
446
  const held = gaps.length
409
447
  ? [...ready, ...forDesign, ...forLead].sort((a, b) => a.slice(3) - b.slice(3))
@@ -443,7 +481,7 @@ export function nextStep(root, base) {
443
481
  attention.push(
444
482
  `code-kit's instructions in ${ahead.map((f) => f.file).join(', ')} come from a newer code-kit than this session's: don't write them back. Run /plugin marketplace update code-kit and restart Claude Code.`,
445
483
  );
446
- if (behind.length) {
484
+ if (behind.length && projectWide) {
447
485
  const legacy = behind.filter((f) => f.state === 'legacy');
448
486
  return result(
449
487
  'instructions',
@@ -453,7 +491,10 @@ export function nextStep(root, base) {
453
491
  }
454
492
  // HELM-4: a lane waiting on something the lead decides goes first: the lane can't go on without it.
455
493
  const forLeadToDecide = openRequests(root).flatMap((r, i) =>
456
- r.lane && decidedBy(r.names, config, { kind: 'lane', lane: r.lane }) === 'lead'
494
+ r.lane &&
495
+ decidedBy(r.names, config, { kind: 'lane', lane: r.lane }) === 'lead' &&
496
+ // STRM-3: a lane's request is its own stream's lead's; a shared core lane's, any lead's.
497
+ (!streamed || [stream, null].includes(streamOfLane(config, r.lane)) || !stream)
457
498
  ? [{ ...r, n: i + 1 }]
458
499
  : [],
459
500
  );
@@ -463,6 +504,18 @@ export function nextStep(root, base) {
463
504
  `${forLeadToDecide.map((r, i) => `${i ? 'the' : 'The'} ${r.lane} lane asks for ${r.names.map((n) => n.replace(/^dep-/, '').replaceAll('+', '/')).join(', ')}`).join('; ')}: yours to decide, against the story's requirements, the spec and the principles.`,
464
505
  { args: forLeadToDecide.map((r) => r.n).join(' ') },
465
506
  );
507
+ // STRM-7: a stream's story waits on the platform's decision: the platform's lead decides it first.
508
+ const platform = streamed ? platformOf(config) : null;
509
+ const asksOfCore =
510
+ platform && (stream === platform.name || (!stream && !led.has(platform.name)))
511
+ ? coreRequests(root).filter((r) => r.state === 'open')
512
+ : [];
513
+ if (asksOfCore.length)
514
+ return result(
515
+ 'decide',
516
+ `${asksOfCore.map((r) => `${r.stream ?? 'A'} stream's ${r.story} asks core for ${r.what} (${r.id})`).join('; ')}: the platform's to decide. Accept each with the platform story that builds it, or decline it with why.`,
517
+ { args: asksOfCore.map((r) => r.id).join(' ') },
518
+ );
466
519
  // The merge queue (spec 09): branches the lead's review passed. Under autonomy, where the base's
467
520
  // committed rules delegate merges, the lead merges the head first, so dependents see it; otherwise
468
521
  // the person does, and always the first merge, which brings code-kit's rules onto the base.
@@ -470,7 +523,7 @@ export function nextStep(root, base) {
470
523
  const leadMerges = delegation.delegated && actsAlone(config.harness.autonomy);
471
524
  // SETUP-2: a base with no rules committed (a project set up before setup committed them there): the
472
525
  // lead puts the approved rules onto it, and the queue merges under them from then on.
473
- if (queued.length && delegation.first && !queuePaused)
526
+ if (queued.length && delegation.first && !queuePaused && projectWide)
474
527
  return result(
475
528
  'rules',
476
529
  `${queued[0]} passed review and is next to merge, but ${delegation.into} has no code-kit rules committed yet. Put the rules the person approved onto it (code-kit queue rules); then the queue merges under them.`,
@@ -495,7 +548,7 @@ export function nextStep(root, base) {
495
548
  attention.push(
496
549
  `${h.branch} passed review and merges together with ${h.missing.join(', ')}: it waits until ${h.missing.length === 1 ? 'that is' : 'they are'} reviewed and queued.`,
497
550
  );
498
- if (mergeHead && leadMerges && !merging && !queuePaused)
551
+ if (mergeHead && leadMerges && !merging && !queuePaused && projectWide)
499
552
  return result(
500
553
  'merge',
501
554
  `${mergeHead.branch} passed review and is next in the merge queue${queued.length > 1 ? ` (then ${queued.filter((b) => b !== mergeHead.branch).join(', ')})` : ''}.`,
@@ -531,6 +584,16 @@ export function nextStep(root, base) {
531
584
  .map((c) => c.lane),
532
585
  ...status.stories.filter((s) => s.state === 'in progress' && s.lane).map((s) => s.lane),
533
586
  ]);
587
+ // STRM-6: a shared core lane this stream ran last goes to another stream's waiting story first.
588
+ const giveWay = streamed ? lanesToGiveWay(root, config, stream ?? null, othersWaiting) : [];
589
+ for (const lane of giveWay) {
590
+ if (busy.has(lane)) continue;
591
+ busy.add(lane);
592
+ attention.push(
593
+ `The ${lane} lane is core's, shared by the streams, and ran this stream's story last: another stream's story goes first.`,
594
+ );
595
+ }
596
+
534
597
  const sched = pickPerLane(status.stories, {
535
598
  fixes,
536
599
  ready,
@@ -612,8 +675,34 @@ export function nextStep(root, base) {
612
675
  `${forLead.join(', ')} ${forLead.length === 1 ? 'is' : 'are'} the lead's own: build ${forLead.length === 1 ? 'it' : 'them'} on ${forLead.map((id) => `lead/${id.toLowerCase()}`).join(', ')}, then review like any branch.`,
613
676
  { args: forLead.join(' ') },
614
677
  );
678
+ // PROM-2: with nothing of its own to start, a lead decides the candidates for core that are its to
679
+ // decide: the platform's, or, without one, its own stream's.
680
+ const forCore = streamed
681
+ ? promotions(root).filter((c) => {
682
+ if (c.state !== 'open') return false;
683
+ const owner = decidedFor(config, c);
684
+ return stream ? owner === stream : !led.has(owner);
685
+ })
686
+ : [];
687
+ if (forCore.length)
688
+ return result(
689
+ 'promote',
690
+ `${forCore.map((c) => c.id).join(', ')} ${forCore.length === 1 ? 'is' : 'are'} proposed for core: ${forCore
691
+ .slice(0, 3)
692
+ .map((c) => c.what)
693
+ .join(
694
+ '; ',
695
+ )}${forCore.length > 3 ? '; …' : ''}. Decide each: promote it with a platform story, or keep it in its module with why.`,
696
+ { args: forCore.map((c) => c.id).join(' ') },
697
+ );
615
698
  // ONB-6: with nothing in flight, the setup is brought up to date before the next story.
616
- if (gaps.length && !building.length && !queued.length)
699
+ // STRM-3: another stream's lead brings the setup up to date, from the main checkout; this one waits.
700
+ if (gaps.length && !projectWide)
701
+ return result(
702
+ 'wait',
703
+ `${missingWords} The lead in the main checkout brings it up to date with /code-kit:init; this stream's stories start after.`,
704
+ );
705
+ if (gaps.length && !building.length && !queued.length && projectWide)
617
706
  return result(
618
707
  'update',
619
708
  `${missingWords} Re-run /code-kit:init before the next story: it shows the person the difference before anything changes.`,
@@ -670,9 +759,11 @@ export function nextStep(root, base) {
670
759
  'wait',
671
760
  heldOnly ?? `${queued.join(', ')} ${queued.length === 1 ? 'waits' : 'wait'} to be merged.`,
672
761
  );
762
+ // STRM-3: a stream's lead counts its own stream's stories.
763
+ const own = status.stories.filter((x) => mine(x.id));
673
764
  return result(
674
765
  'done',
675
- `All ${status.stories.length} stories are done; spec-design plans the next milestone or feature.`,
766
+ `All ${own.length} ${streamed && stream ? `of the ${stream} stream's ` : ''}stories are done; spec-design plans the next milestone or feature.`,
676
767
  );
677
768
  }
678
769
 
@@ -14,6 +14,7 @@ import { waitingStories } from './questions.mjs';
14
14
  import { sentBack } from './reviews.mjs';
15
15
  import { isTestFile } from './testfiles.mjs';
16
16
  import { WORKTREES_DIR } from './worktrees.mjs';
17
+ import { streamOfLane, streamOfPlanFile } from './streams.mjs';
17
18
 
18
19
  export const REQUIREMENT = /\b(?!ST-)([A-Z][A-Z0-9]*-\d+)\b/g;
19
20
  const STORY_HEADING = /^###\s+(ST-\d+)\b\s*(.*)$/;
@@ -520,7 +521,7 @@ export function storyStates(root, stories, base, { designing = null } = {}) {
520
521
  }
521
522
 
522
523
  /** Gaps between specs, plan and tests, as sentences. */
523
- export function traceProblems(requirements, stories, lanes) {
524
+ export function traceProblems(requirements, stories, lanes, config = null) {
524
525
  const problems = [];
525
526
  const ids = new Set(requirements.map((r) => r.id));
526
527
  const seen = new Set();
@@ -528,10 +529,23 @@ export function traceProblems(requirements, stories, lanes) {
528
529
  if (seen.has(r.id)) problems.push(`${r.id} is defined more than once (${r.file})`);
529
530
  seen.add(r.id);
530
531
  }
531
- const storyIds = new Set();
532
+ const storyIds = new Map();
532
533
  for (const s of stories) {
533
- if (storyIds.has(s.id)) problems.push(`${s.id} is in the plan more than once`);
534
- storyIds.add(s.id);
534
+ // STRM-4: an id is the project's, across every stream's plan.
535
+ if (storyIds.has(s.id))
536
+ problems.push(
537
+ storyIds.get(s.id) === s.file
538
+ ? `${s.id} is in the plan more than once`
539
+ : `${s.id} is in two plans, ${storyIds.get(s.id)} and ${s.file}: a story id is the project's, across every stream`,
540
+ );
541
+ storyIds.set(s.id, s.file);
542
+ // STRM-4: a story on a stream's lane belongs in that stream's plan.
543
+ const byLane = config ? streamOfLane(config, s.lane) : null;
544
+ const byFile = config ? streamOfPlanFile(config, s.file) : null;
545
+ if (byLane && byFile && byLane !== byFile)
546
+ problems.push(
547
+ `${s.id} is in the ${byFile} stream's plan, but its lane, ${s.lane}, is the ${byLane} stream's: move it to that stream's plan, or give it a lane of ${byFile}'s`,
548
+ );
535
549
  if (!s.lane) problems.push(`${s.id} has no **Lane:**`);
536
550
  else if (s.lane !== LEAD && s.lane !== DESIGN && !lanes.includes(s.lane))
537
551
  problems.push(`${s.id} names an unknown lane "${s.lane}"`);
@@ -591,7 +605,7 @@ export function buildStatus(root, config, base, files) {
591
605
  designing: stillDesigning(root, config, requirements),
592
606
  });
593
607
  const tested = testedRequirements(root, files, specs, config);
594
- const problems = traceProblems(requirements, stories, Object.keys(config.lanes));
608
+ const problems = traceProblems(requirements, stories, Object.keys(config.lanes), config);
595
609
  const byRequirement = requirements.map((r) => {
596
610
  const covering = stories.filter((s) => s.state !== DROPPED && s.requirements.includes(r.id));
597
611
  let state = 'no story';