@warren-dean/code-kit 0.34.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.
package/bin/code-kit.mjs CHANGED
@@ -108,7 +108,7 @@ import {
108
108
  withdrawQuestion,
109
109
  } from '../hooks/lib/questions.mjs';
110
110
  import { traceFile } from '../hooks/lib/trace.mjs';
111
- import { buildStatus, readStories, specCheckRows } from '../hooks/lib/plan.mjs';
111
+ import { buildStatus, readRequirements, readStories, specCheckRows } from '../hooks/lib/plan.mjs';
112
112
  import {
113
113
  atViewport,
114
114
  designsFor,
@@ -224,7 +224,9 @@ import {
224
224
  import { laneClaim, laneClaims, releaseLane, shortSession } from '../hooks/lib/laneclaims.mjs';
225
225
  import { slicesOf } from '../hooks/lib/schedule.mjs';
226
226
  import {
227
+ joinStream,
227
228
  leadSession,
229
+ leadSessions,
228
230
  makeLead,
229
231
  memberOf,
230
232
  readSession,
@@ -234,6 +236,25 @@ import {
234
236
  takeTask,
235
237
  } from '../hooks/lib/sessions.mjs';
236
238
  import { globsOverlap } from '../hooks/lib/teamfacts.mjs';
239
+ import {
240
+ askCore,
241
+ coreRequests,
242
+ decideCore,
243
+ hasStreams,
244
+ platformOf,
245
+ sharedLanes,
246
+ streamOfLane,
247
+ streamsOf,
248
+ } from '../hooks/lib/streams.mjs';
249
+ import {
250
+ cloneCandidate,
251
+ decidePromotion,
252
+ decidedFor,
253
+ promotions,
254
+ raise,
255
+ repeatedRequirements,
256
+ scanForPromotions,
257
+ } from '../hooks/lib/promote.mjs';
237
258
  import {
238
259
  BUSY_MS,
239
260
  agentBusy,
@@ -419,9 +440,11 @@ function whoAmI() {
419
440
  ? `Session ${shortSession(callerSession)}, which code-kit hasn't recorded yet.`
420
441
  : 'Not run from a Claude Code session, so no member of the team.',
421
442
  );
422
- const lead = leadSession(root);
443
+ const lead = leadSession(root, Date.now(), me.stream ?? null);
444
+ // STRM-2: in a project built as streams, which stream the session leads or works in.
445
+ const of = me.stream ? ` of the ${me.stream} stream` : '';
423
446
  out(
424
- `${memberOf(me)}: ${me.role === 'lead' ? 'the lead session' : `a working session${lead ? ` (${memberOf(lead)} leads)` : ' (no session leads now)'}`}${me.task ? `, working on "${me.task.title}"` : ''}.`,
447
+ `${memberOf(me)}: ${me.role === 'lead' ? `the lead session${of}` : `a working session${of}${lead ? ` (${memberOf(lead)} leads)` : ' (no session leads now)'}`}${me.task ? `, working on "${me.task.title}"` : ''}.`,
425
448
  );
426
449
  }
427
450
 
@@ -1653,16 +1676,38 @@ function sessionsCommand() {
1653
1676
  load();
1654
1677
  const root = resolve('.');
1655
1678
  const [sub] = rest;
1656
- if (sub === 'beat' || sub === 'lead') {
1679
+ if (sub === 'beat' || sub === 'lead' || sub === 'stream') {
1657
1680
  if (!callerSession) die(`code-kit sessions ${sub} needs the session: --session <id>.`);
1658
1681
  if (sub === 'beat') return seeSession(root, callerSession) && out('Seen.');
1659
- const was = leadSession(root);
1660
- makeLead(root, callerSession);
1682
+ // STRM-2: the stream it leads, or works in, by name.
1683
+ const { config } = load();
1684
+ const named = rest[1] ?? null;
1685
+ const names = streamsOf(config).map((x) => x.name);
1686
+ if (named && !names.includes(named))
1687
+ die(
1688
+ names.length
1689
+ ? `There's no stream "${named}": the streams are ${names.join(', ')}.`
1690
+ : `This project isn't built as streams, so there's no "${named}": lead it with \`code-kit sessions lead\`.`,
1691
+ );
1692
+ if (sub === 'stream') {
1693
+ if (!named)
1694
+ die(`code-kit sessions stream <name>: one of ${names.join(', ') || 'no streams'}.`);
1695
+ const me = joinStream(root, callerSession, named);
1696
+ return out(
1697
+ `This session (${shortSession(callerSession)}) ${me.role === 'lead' ? 'leads' : 'works in'} the ${named} stream now.`,
1698
+ );
1699
+ }
1700
+ const stream = named ?? readSession(root, callerSession)?.stream ?? null;
1701
+ const was = leadSession(root, Date.now(), stream);
1702
+ makeLead(root, callerSession, Date.now(), stream);
1661
1703
  return out(
1662
- `This session (${shortSession(callerSession)}) leads the project now${was && was.id !== callerSession ? `; ${shortSession(was.id)} is a working session` : ''}.`,
1704
+ `This session (${shortSession(callerSession)}) leads ${stream ? `the ${stream} stream` : 'the project'} now${was && was.id !== callerSession && (was.stream ?? null) === stream ? `; ${shortSession(was.id)} is a working session` : ''}.`,
1663
1705
  );
1664
1706
  }
1665
- if (sub !== undefined) die('code-kit sessions [--json] | sessions lead | sessions beat');
1707
+ if (sub !== undefined)
1708
+ die(
1709
+ 'code-kit sessions [--json] | sessions lead [stream] | sessions stream <name> | sessions beat',
1710
+ );
1666
1711
  const all = sessions(root).filter((s) => s.live || s.task);
1667
1712
  if (flag('--json'))
1668
1713
  return out(
@@ -1675,7 +1720,7 @@ function sessionsCommand() {
1675
1720
  if (!all.length) return out('No session is working this project.');
1676
1721
  for (const s of all)
1677
1722
  out(
1678
- `${pad(memberOf(s), 30)} ${pad(s.live ? s.role : 'ended', 8)} ${s.task ? `${s.task.title}${s.task.paths?.length ? ` (${s.task.paths.join(', ')})` : ''}${s.live ? '' : ', stale'}` : '-'}${s.id === callerSession ? ' ← this session' : ''}`,
1723
+ `${pad(memberOf(s), 30)} ${pad(s.live ? s.role : 'ended', 8)} ${s.stream ? `${pad(s.stream, 10)} ` : ''}${s.task ? `${s.task.title}${s.task.paths?.length ? ` (${s.task.paths.join(', ')})` : ''}${s.live ? '' : ', stale'}` : '-'}${s.id === callerSession ? ' ← this session' : ''}`,
1679
1724
  );
1680
1725
  }
1681
1726
 
@@ -2322,11 +2367,17 @@ function reconcileCommand(id) {
2322
2367
 
2323
2368
  function next() {
2324
2369
  const root = resolve('.');
2325
- let step = nextStep(root, (config) => findBase(config, false));
2326
2370
  // SESS-2: the project's steps are the lead's. A working session that asks is told whose they are,
2327
- // and what's its own, instead of being handed a dispatch or a review it may not do.
2371
+ // and what's its own, instead of being handed a dispatch or a review it may not do. STRM-3: a lead
2372
+ // gets its own stream's steps; the lead in the main checkout also takes the whole project's.
2328
2373
  const me = callerSession ? readSession(root, callerSession) : null;
2329
- const lead = leadSession(root);
2374
+ const leads = leadSessions(root);
2375
+ const projectWide = !me || leads.length < 2 || leads[0].id === me.id;
2376
+ let step = nextStep(root, (config) => findBase(config, false), {
2377
+ stream: me?.stream ?? null,
2378
+ projectWide,
2379
+ });
2380
+ const lead = leadSession(root, Date.now(), me?.stream ?? null);
2330
2381
  if (me && lead && lead.id !== me.id && !['wait', 'done'].includes(step.step))
2331
2382
  step = {
2332
2383
  ...step,
@@ -2404,6 +2455,13 @@ async function approve(given) {
2404
2455
  );
2405
2456
  if (laneName !== undefined && !config.lanes[laneName])
2406
2457
  die(`There is no lane "${laneName}". Lanes: ${Object.keys(config.lanes).join(', ')}.`);
2458
+ // STRM-8: a stream's lead approves for its own stream's lanes; core's, with a platform, is the platform's.
2459
+ const approver = delegated && callerSession ? readSession(resolve('.'), callerSession) : null;
2460
+ const laneStream = laneName ? streamOfLane(config, laneName) : null;
2461
+ if (approver?.stream && laneStream && laneStream !== approver.stream)
2462
+ die(
2463
+ `Nothing was approved: the ${laneName} lane is the ${laneStream} stream's${platformOf(config)?.name === laneStream ? ', which owns core' : ''}, and this session leads ${approver.stream}. Its approvals are its own lead's${platformOf(config)?.name === laneStream ? `; ask it with code-kit core ask "<what>" --story ST-n` : ''}.`,
2464
+ );
2407
2465
  const known = new Set([
2408
2466
  'kit',
2409
2467
  TESTS_APPROVAL,
@@ -3135,7 +3193,7 @@ function loopCommand() {
3135
3193
  die(
3136
3194
  'code-kit loop [--json] | loop pause | loop resume | loop lead --session <id> [--take] | loop release --session <id>',
3137
3195
  );
3138
- const state = readLoop(root);
3196
+ const state = readLoop(root, Date.now(), sessionId);
3139
3197
  // SESS-2: with --session, whether that session leads the project or works in it.
3140
3198
  const role = sessionId ? (readSession(root, sessionId)?.role ?? null) : null;
3141
3199
  out(
@@ -3470,6 +3528,241 @@ function designEvidence(root, config, entries) {
3470
3528
  );
3471
3529
  }
3472
3530
 
3531
+ /**
3532
+ * PROM-1 to PROM-3: module code that belongs in core. `promote` lists the candidates; `promote scan`
3533
+ * looks for them (with --branch, in what the branch changes against the base: a review's findings);
3534
+ * `promote --story ST-n` lists what other streams' specs already require that the story's repeat;
3535
+ * `promote accept|reject` is the platform lead's decision.
3536
+ */
3537
+ function promoteCommand() {
3538
+ const { config } = load();
3539
+ const root = resolve('.');
3540
+ const [sub, id] = rest;
3541
+ const stories = config.docs?.plan ? readStories(root, config.docs.plan) : [];
3542
+ const done = new Set(stories.filter((st) => st.status === 'done').map((st) => st.id));
3543
+ if (!hasStreams(config) && sub !== undefined)
3544
+ die("This project isn't built as streams, so there's no core to promote code into.");
3545
+ if (sub === 'scan') {
3546
+ const base = branchName ? findBase(config, false) : null;
3547
+ const files = branchName
3548
+ ? execFileSync('git', ['-C', root, 'diff', '--name-only', `${base}...${branchName}`], {
3549
+ encoding: 'utf8',
3550
+ })
3551
+ .split('\n')
3552
+ .filter(Boolean)
3553
+ : null;
3554
+ // A review reads the branch as it's committed; its clones of another stream are candidates.
3555
+ const r = scanForPromotions(root, config, { files, ref: branchName ?? null });
3556
+ if (flag('--json')) return out(JSON.stringify(r, null, 2));
3557
+ if (flag('--quiet')) return;
3558
+ if (branchName) {
3559
+ const mine = r.clones.map(cloneCandidate);
3560
+ if (!mine.length)
3561
+ return out(`${branchName} repeats no other stream's code, and no core code.`);
3562
+ for (const c of mine)
3563
+ out(
3564
+ c.signal === 'core-clone'
3565
+ ? `${c.what}: use core's.`
3566
+ : `${c.what}: proposed for core (code-kit promote).`,
3567
+ );
3568
+ return;
3569
+ }
3570
+ return out(
3571
+ r.raised.length
3572
+ ? `${r.raised.length} candidate${r.raised.length === 1 ? '' : 's'} for core raised or added to: ${r.raised.map((c) => c.id).join(', ')}.`
3573
+ : 'Nothing new for core.',
3574
+ );
3575
+ }
3576
+ if (sub === 'accept' || sub === 'reject') {
3577
+ const me = callerSession ? readSession(root, callerSession) : null;
3578
+ const platform = platformOf(config);
3579
+ const candidate = promotions(root).find((x) => x.id === id);
3580
+ const owner = candidate ? decidedFor(config, candidate) : null;
3581
+ if (me?.stream && owner && me.stream !== owner)
3582
+ die(`${id} is the ${owner} lead's to decide${platform ? ': the platform owns core' : ''}.`);
3583
+ const r = decidePromotion(root, id, {
3584
+ how: sub === 'accept' ? 'promoted' : 'rejected',
3585
+ story: storyGiven?.toUpperCase() ?? null,
3586
+ reason: reason ?? null,
3587
+ by: callerSession,
3588
+ });
3589
+ if (!r.ok) die(r.why);
3590
+ return out(
3591
+ sub === 'accept'
3592
+ ? `Promoted ${id}: ${r.promotion.decided.story} moves it into core and switches each stream to it; it closes when that story merges.`
3593
+ : `Rejected ${id}: ${reason.trim()}. It isn't proposed again until its evidence changes.`,
3594
+ );
3595
+ }
3596
+ if (sub !== undefined)
3597
+ die(
3598
+ 'code-kit promote [--json] [--story ST-n] | promote scan [--branch b] [--json|--quiet] | promote accept <id> --story ST-n | promote reject <id> --reason "…"',
3599
+ );
3600
+ if (storyGiven) {
3601
+ const story = stories.find((st) => st.id.toUpperCase() === storyGiven.toUpperCase());
3602
+ if (!story) die(`${config.docs?.plan ?? 'The plan'} has no story ${storyGiven}.`);
3603
+ const found = config.docs?.specs
3604
+ ? repeatedRequirements(config, readRequirements(root, config.docs.specs), story)
3605
+ : [];
3606
+ for (const m of found)
3607
+ raise(root, {
3608
+ key: `requirement:${[m.requirement, m.matches].sort().join('|')}`,
3609
+ signal: 'requirement',
3610
+ what: `${story.id}'s ${m.requirement} repeats ${m.stream}'s ${m.matches} (${m.title})`,
3611
+ where: [m.file],
3612
+ streams: [...new Set([m.stream, streamOfLane(config, story.lane)].filter(Boolean))],
3613
+ evidence: `${Math.round(m.score * 100)}% alike`,
3614
+ });
3615
+ if (flag('--json')) return out(JSON.stringify(found, null, 2));
3616
+ if (!found.length) return out(`No other stream's spec requires what ${story.id} does.`);
3617
+ for (const m of found)
3618
+ out(
3619
+ `${m.requirement} repeats ${m.stream}'s ${m.matches} (${m.title}, ${m.file}): build it once, in core, or reuse ${m.stream}'s through the platform.`,
3620
+ );
3621
+ return;
3622
+ }
3623
+ const all = promotions(root).map((c) => ({
3624
+ ...c,
3625
+ state: c.state === 'promoted' && done.has(c.decided?.story) ? 'done' : c.state,
3626
+ decides: decidedFor(config, c),
3627
+ }));
3628
+ if (flag('--json')) return out(JSON.stringify(all, null, 2));
3629
+ const open = all.filter((c) => c.state === 'open');
3630
+ if (!all.length) return out('No candidates for core.');
3631
+ out(
3632
+ open.length
3633
+ ? `${open.length} candidate${open.length === 1 ? '' : 's'} for core:`
3634
+ : 'No open candidates for core.',
3635
+ );
3636
+ for (const c of open)
3637
+ out(
3638
+ ` ${c.id} (${c.kind}, ${c.streams.join(' and ')}; the ${c.decides} lead decides): ${c.what}`,
3639
+ );
3640
+ for (const c of all.filter((x) => x.state !== 'open').slice(-10))
3641
+ out(
3642
+ ` ${c.id} ${c.state}${c.decided?.story ? ` as ${c.decided.story}` : ''}${c.decided?.reason ? `: ${c.decided.reason}` : ''}`,
3643
+ );
3644
+ }
3645
+
3646
+ /**
3647
+ * STRM-1: the project's streams: each one's lanes, plan, lead session and what its lanes are running; the
3648
+ * core lanes the streams share, and the stream that owns core.
3649
+ */
3650
+ function streamsCommand() {
3651
+ const { config } = load();
3652
+ const root = resolve('.');
3653
+ const all = streamsOf(config);
3654
+ const claims = laneClaims(root);
3655
+ const rows = all.map((st) => {
3656
+ const lead = leadSession(root, Date.now(), st.name);
3657
+ return {
3658
+ ...st,
3659
+ lead: lead
3660
+ ? { session: lead.id, member: memberOf(lead), own: lead.stream === st.name }
3661
+ : null,
3662
+ running: claims
3663
+ .filter((c) => st.lanes.includes(c.lane))
3664
+ .map((c) => ({ lane: c.lane, story: c.story })),
3665
+ };
3666
+ });
3667
+ const shared = sharedLanes(config).map((lane) => ({
3668
+ lane,
3669
+ running: claims.find((c) => c.lane === lane)?.story ?? null,
3670
+ }));
3671
+ if (flag('--json')) return out(JSON.stringify({ streams: rows, shared }, null, 2));
3672
+ if (!all.length)
3673
+ return out(
3674
+ "This project isn't built as streams: one lead runs every lane. docs/specs/31-streams-and-platform.md says how to add them.",
3675
+ );
3676
+ for (const r of rows) {
3677
+ out(
3678
+ `${r.name}${r.platform ? ' (platform: owns core)' : ''}: ${r.lanes.join(', ') || 'no lanes'}; plan ${r.plan}`,
3679
+ );
3680
+ out(
3681
+ ` lead: ${r.lead ? `${r.lead.member}${r.lead.own ? '' : ', leading with no stream of its own'}` : 'none now (/code-kit:lead ' + r.name + ' in a session)'}`,
3682
+ );
3683
+ for (const x of r.running) out(` ${x.lane}: ${x.story ?? 'a story'}`);
3684
+ }
3685
+ if (shared.length)
3686
+ out(
3687
+ `core, shared in turns: ${shared.map((x) => `${x.lane}${x.running ? ` (${x.running})` : ''}`).join(', ')}`,
3688
+ );
3689
+ }
3690
+
3691
+ /**
3692
+ * STRM-7: change requests to core. With a platform stream, a stream's lead asks for what its story needs
3693
+ * from core (`core ask`), the story waits, and the platform's lead accepts it with the story that builds
3694
+ * it, or declines it with why.
3695
+ */
3696
+ function coreCommand() {
3697
+ const { config } = load();
3698
+ const root = resolve('.');
3699
+ const [sub, id] = rest;
3700
+ const platform = platformOf(config);
3701
+ const me = callerSession ? readSession(root, callerSession) : null;
3702
+ if (sub === 'ask') {
3703
+ const what = rest.slice(1).join(' ').trim();
3704
+ if (!platform)
3705
+ die(
3706
+ hasStreams(config)
3707
+ ? "Nothing was asked: there's no platform stream, so core's lanes are the streams' own, shared in turns. Plan the change as a story on a core lane in your stream's plan."
3708
+ : "Nothing was asked: this project isn't built as streams, so core is the lead's.",
3709
+ );
3710
+ if (!storyGiven)
3711
+ die('Name the story that needs it, with --story ST-n: it waits on the decision.');
3712
+ if (me?.stream === platform.name)
3713
+ die('This session leads the platform: core is yours to change.');
3714
+ const r = askCore(root, {
3715
+ stream: me?.stream ?? null,
3716
+ session: callerSession,
3717
+ story: storyGiven.toUpperCase(),
3718
+ what,
3719
+ why: whyGiven ?? null,
3720
+ });
3721
+ if (!r.ok) die(r.why);
3722
+ const lead = leadSession(root, Date.now(), platform.name);
3723
+ return out(
3724
+ r.existed
3725
+ ? `${r.request.id} already asks this; ${r.request.story} waits on it.`
3726
+ : `Asked ${r.request.id} of the platform${lead ? ` (${memberOf(lead)})` : ' (no session leads it now: it waits for one)'}. ${r.request.story} waits on its decision; carry on with other stories.`,
3727
+ );
3728
+ }
3729
+ if (sub === 'accept' || sub === 'decline') {
3730
+ if (!platform) die("There's no platform stream to decide change requests to core.");
3731
+ if (me && me.stream && me.stream !== platform.name)
3732
+ die(
3733
+ `${id ?? 'A change request'} is the platform's to decide, in the ${platform.name} lead's session.`,
3734
+ );
3735
+ const r = decideCore(root, id, {
3736
+ how: sub === 'accept' ? 'accepted' : 'declined',
3737
+ story: storyGiven?.toUpperCase() ?? null,
3738
+ reason: reason ?? null,
3739
+ by: callerSession,
3740
+ });
3741
+ if (!r.ok) die(r.why);
3742
+ return out(
3743
+ sub === 'accept'
3744
+ ? `Accepted ${id}: ${r.request.decided.story} builds it, and ${r.request.story} waits for that story.`
3745
+ : `Declined ${id}: ${reason.trim()}. ${r.request.story} no longer waits on it.`,
3746
+ );
3747
+ }
3748
+ if (sub !== undefined)
3749
+ die(
3750
+ 'code-kit core [--json] | core ask "<what>" --story ST-n [--why "…"] | core accept <id> --story ST-n | core decline <id> --reason "…"',
3751
+ );
3752
+ const all = coreRequests(root);
3753
+ if (flag('--json')) return out(JSON.stringify(all, null, 2));
3754
+ const open = all.filter((r) => r.state === 'open');
3755
+ if (!all.length) return out('No change requests to core.');
3756
+ for (const r of open)
3757
+ out(
3758
+ `${r.id} (${r.stream ?? 'a lead'}, for ${r.story}): ${r.what}${r.why ? `, because ${r.why}` : ''}`,
3759
+ );
3760
+ for (const r of all.filter((x) => x.state !== 'open').slice(-10))
3761
+ out(
3762
+ `${r.id} ${r.state}${r.decided.story ? ` as ${r.decided.story}` : ''}${r.decided.reason ? `: ${r.decided.reason}` : ''} (${r.what})`,
3763
+ );
3764
+ }
3765
+
3473
3766
  const commands = {
3474
3767
  check,
3475
3768
  designs: designsCommand,
@@ -3485,6 +3778,9 @@ const commands = {
3485
3778
  settings,
3486
3779
  lanes: lanesCommand,
3487
3780
  sessions: sessionsCommand,
3781
+ streams: streamsCommand,
3782
+ core: coreCommand,
3783
+ promote: promoteCommand,
3488
3784
  decisions: decisionsCommand,
3489
3785
  task: taskCommand,
3490
3786
  hold: () => (rest.length === 1 ? hold(rest[0]) : usage()),
@@ -3537,7 +3833,9 @@ function usage() {
3537
3833
  ' | report [--json] | report send|discard <id>\n' +
3538
3834
  ' | stops [--session id] [--json] | sent-back <branch> [--reason "…"]\n' +
3539
3835
  ' | settings [--json] | settings set <key> <value> --reason "…" [--via pane]\n' +
3540
- ' | lanes [--json] | lanes release <lane> | sessions [--json] | sessions lead\n' +
3836
+ ' | lanes [--json] | lanes release <lane> | sessions [--json] | sessions lead [stream] | sessions stream <name>\n' +
3837
+ ' | promote [--json] [--story ST-n] | promote scan [--branch b] [--json|--quiet] | promote accept <id> --story ST-n | promote reject <id> --reason "…"\n' +
3838
+ ' | streams [--json] | core [--json] | core ask "<what>" --story ST-n [--why "…"] | core accept <id> --story ST-n | core decline <id> --reason "…"\n' +
3541
3839
  ' | who | task "<what>" --touches globs | task done | task take <session>\n' +
3542
3840
  ' | decisions [--json] [--all]\n' +
3543
3841
  ' | ci check [--json] | ci usage [--days N] [--json] | release <version>\n' +
@@ -14,7 +14,8 @@ import { claimLane, shortSession } from './lib/laneclaims.mjs';
14
14
  import { dropNextLane, mainCheckout, nextLane, noteNextLane } from './lib/lanetrees.mjs';
15
15
  import { readStories, storyBranch } from './lib/plan.mjs';
16
16
  import { agentFileModel } from './lib/schedule.mjs';
17
- import { memberOf, readSession } from './lib/sessions.mjs';
17
+ import { leadSession, memberOf, readSession } from './lib/sessions.mjs';
18
+ import { hasStreams, platformOf, recordTurn, streamOfLane, streamOfStory } from './lib/streams.mjs';
18
19
 
19
20
  const { input, project, config, error } = start();
20
21
  // A broken config is reported by the other hooks; it doesn't stop agents starting.
@@ -38,6 +39,33 @@ if (isolated && !noteNextLane(main, { lane: lane ?? null, story: lane ? story :
38
39
  }
39
40
  if (!lane) process.exit(0);
40
41
  const session = input.session_id ?? null;
42
+ // STRM-2, STRM-6: a stream's lanes are started by its own lead; a shared core lane by any stream's.
43
+ const me = session ? readSession(project, session) : null;
44
+ const laneStream = streamOfLane(config, lane);
45
+ // A lead with no stream of its own leads the streams without a lead of theirs, not the others.
46
+ const theirs = laneStream ? leadSession(project, Date.now(), laneStream) : null;
47
+ const othersLane =
48
+ laneStream &&
49
+ (me?.stream ? laneStream !== me.stream : theirs?.stream === laneStream && theirs.id !== session);
50
+ if (hasStreams(config) && me?.role === 'lead' && othersLane) {
51
+ if (isolated) dropNextLane(main);
52
+ block(
53
+ `Blocked: the ${lane} lane is the ${laneStream} stream's${platformOf(config)?.name === laneStream ? ', which owns core' : ''}, and this session leads ${me.stream ?? 'the streams without a lead of their own'}. A stream's lanes are started by its own lead${theirs ? ` (${memberOf(theirs)})` : ''}.
54
+ ` +
55
+ (platformOf(config)?.name === laneStream
56
+ ? `For a change to core, ask the platform: node "${CLI}" core ask "<what the story needs>" --story <ST-n>`
57
+ : `Hand the ${laneStream} lead what you need, or build it in your own stream's lanes.`),
58
+ );
59
+ }
60
+ const storyStream =
61
+ story && config.docs?.plan
62
+ ? (streamOfStory(
63
+ config,
64
+ readStories(project, config.docs.plan).find((s) => s.id === story),
65
+ ) ??
66
+ me?.stream ??
67
+ null)
68
+ : (me?.stream ?? null);
41
69
  const claimed = claimLane(project, { lane, story, session });
42
70
  if (!claimed.ok) {
43
71
  if (isolated) dropNextLane(main);
@@ -56,6 +84,9 @@ if (!claimed.ok) {
56
84
  );
57
85
  }
58
86
 
87
+ // STRM-6: a shared core lane notes whose turn it ran, so the other streams' stories go next.
88
+ if (!laneStream && hasStreams(config)) recordTurn(project, lane, storyStream);
89
+
59
90
  // SCHED-3: what it runs on. The lead's call wins, then the lane's agent file, then the setting: `story` is
60
91
  // the model the story's size gives, which the mod sets where the call names none (SET-4).
61
92
  try {
@@ -102,7 +102,7 @@ const ALWAYS = [
102
102
  ],
103
103
  [
104
104
  /approval-log\.jsonl/,
105
- "The approval audit log is appended only by the commit hook; nobody edits it. A shell command may name it only to read it: git diff, log, show or blame, or cat, head, tail, grep, wc, jq, cut, sort, uniq, awk or sed -n printing lines, piped only into each other, with no redirect but 2>&1 or into /dev/null, no command's output in its arguments ($(…) or backticks) and no variable set before a command; other commands may come before or after it with ; or &&, if none defines a function or alias, exports a variable or sets one a command reads, such as PATH. Run the read in that form, or read the file with the Read tool, which can't write. To put it back as the last commit has it (after a `git revert --no-commit` or `git cherry-pick --no-commit` took entries out), run `git restore --staged --worktree .claude/approval-log.jsonl` in the same form, and commit in a command after it.",
105
+ "The approval audit log is appended only by the commit hook; nobody edits it. A shell command may name it only to read it: git diff, log, show or blame, or cat, head, tail, grep, wc, jq, cut, sort, uniq, awk or sed -n printing lines, piped only into each other, with no redirect but 2>&1 or into /dev/null, no command's output in its arguments ($(…) or backticks) and no variable set before a command; other commands may come before or after it with ; or &&, if none defines an alias or a function the read calls, exports a variable or sets one a command reads, such as PATH. Run the read in that form, or read the file with the Read tool, which can't write. To put it back as the last commit has it (after a `git revert --no-commit` or `git cherry-pick --no-commit` took entries out), run `git restore --staged --worktree .claude/approval-log.jsonl` in the same form, and commit in a command after it.",
106
106
  unreadNames(cmd, /approval-log\.jsonl/).join('\n'),
107
107
  ],
108
108
  ];
@@ -243,7 +243,7 @@ if (runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+loop\s+(pause|resume)\b`)))
243
243
  // the person's own act.
244
244
  if (
245
245
  runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+loop\s+(lead|release)\b`)) ||
246
- runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+sessions\s+(lead|beat)\b`))
246
+ runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+sessions\s+(lead|beat|stream)\b`))
247
247
  )
248
248
  block(
249
249
  `Blocked: which session leads the project is recorded by code-kit, and choosing it is the person's own act (Lead from here, in the code-kit band, or \`code-kit sessions lead\` in their terminal). Carry on with your work.\nCommand: ${cmd}`,
@@ -841,7 +841,12 @@ const BEFORE_COMMIT = new RegExp(
841
841
  // Setting shell variables (`f=docs/x.md`, `export MSG="…"`) writes no file, unless a value runs a
842
842
  // command. What a later `git add "$f"` stages can't be read, so it counts as every changed file.
843
843
  const ASSIGNS_ONLY = /^(?:export\s+)?[A-Za-z_]\w*=\S*(?:\s+[A-Za-z_]\w*=\S*)*$/;
844
- const assignsOnly = (c) => ASSIGNS_ONLY.test(c.code) && !/`|\$\(|<\(/.test(c.text);
844
+ // Nor does setting the shell's own options (`set -euo pipefail`, `set +x`), or unsetting variables.
845
+ const SHELL_OPTIONS = /^set(?:\s+[-+][a-zA-Z]+(?:\s+[a-z]+)?)+\s*$/;
846
+ const UNSETS = /^unset(?:\s+-[vn])?(?:\s+[A-Za-z_]\w*)+\s*$/;
847
+ const assignsOnly = (c) =>
848
+ (ASSIGNS_ONLY.test(c.code) || SHELL_OPTIONS.test(c.code) || UNSETS.test(c.code)) &&
849
+ !/`|\$\(|<\(|[<>]/.test(c.text);
845
850
  // A tool's command that writes only the tool's own records (an adapter's `shell.records`), which any
846
851
  // actor may write and no check covers, with no redirect of its own.
847
852
  const recordsOnly = (c) =>
@@ -6,11 +6,12 @@ import { existsSync, readFileSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
  import { loadBaseline, newProblems } from './lib/baseline.mjs';
8
8
  import { CONFIG_FILE } from './lib/config.mjs';
9
- import { brokenLayerRule, layerProblems } from './lib/layers.mjs';
9
+ import { brokenLayerRule, layerProblems, targetOf } from './lib/layers.mjs';
10
+ import { recordRefusedImport } from './lib/promote.mjs';
10
11
  import { noteFor } from './lib/standards.mjs';
11
12
  import { block, start } from './lib/hook.mjs';
12
13
  import { teamOf, teamProvider, teamRefusal, whoami } from './lib/team.mjs';
13
- import { sessionWriteProblem } from './lib/sessions.mjs';
14
+ import { sessionWriteProblem, streamWriteProblem } from './lib/sessions.mjs';
14
15
  import { spawnSync } from 'node:child_process';
15
16
  import {
16
17
  actorFor,
@@ -40,6 +41,16 @@ if (error) {
40
41
  const problem = writeProblem(actorFor(input, root, config), rel, root, config);
41
42
  if (problem) block(`Blocked: ${problem}`);
42
43
 
44
+ // STRM-4: a stream's lead writes its own stream's plan and specs, not another stream's.
45
+ const streamed = streamWriteProblem(
46
+ project,
47
+ config,
48
+ actorFor(input, root, config),
49
+ rel,
50
+ input.session_id,
51
+ );
52
+ if (streamed) block(`Blocked: ${streamed}`);
53
+
43
54
  // SESS-4, SESS-5: another session's task leases the path, or a working session writes where it shouldn't.
44
55
  const shared = sessionWriteProblem({
45
56
  project,
@@ -94,6 +105,14 @@ if (after !== null) {
94
105
  const added = newProblems(rel, layerProblems(rel, after, config), loadBaseline(project)).filter(
95
106
  (p) => !existing.has(p),
96
107
  );
108
+ // PROM-1, signal 2: an import of another stream's module asks for a capability core could own.
109
+ for (const p of added) {
110
+ const m = p.match(/^(\S+) \([^()]+\) imports (\S+) \([^()]+\); \S+ is the \S+ stream's module/);
111
+ if (m) {
112
+ const target = targetOf(m[2], rel, config.importAliases);
113
+ if (target) recordRefusedImport(project, config, { file: rel, target, spec: m[2] });
114
+ }
115
+ }
97
116
  if (added.length)
98
117
  block(
99
118
  `Blocked: this edit would break the layer rules (.claude/code-kit.json › layers):\n ${added.join('\n ')}\nDepend only on the layers listed, or ask the lead to change the rule.${noteFor(root, config, added.map(brokenLayerRule))}`,
@@ -3,6 +3,7 @@
3
3
  import { execFileSync } from 'node:child_process';
4
4
  import { existsSync, readFileSync } from 'node:fs';
5
5
  import { VIBE, harnessProblems, harnessSettings } from './harness.mjs';
6
+ import { streamProblems } from './streamconfig.mjs';
6
7
  import { teamProblems } from './team.mjs';
7
8
  import { join } from 'node:path';
8
9
  import { DEFAULT_REGISTER } from './costs.mjs';
@@ -95,6 +96,8 @@ export function withDefaults(c) {
95
96
  .map((e) => ({ glob: e.glob, reviewer: e.reviewer })),
96
97
  protected: [KIT, ...(c.protected ?? []).filter((p) => p.glob !== KIT.glob)],
97
98
  layers: c.layers ?? [],
99
+ // Spec 31: the project's streams; none is one stream holding every lane.
100
+ streams: c.streams ?? null,
98
101
  importAliases: c.importAliases ?? {},
99
102
  shell: { block: c.shell?.block ?? [], restricted: c.shell?.restricted ?? [] },
100
103
  execution: { unrepeatable: c.execution?.unrepeatable ?? [] },
@@ -407,6 +410,7 @@ export function validate(c) {
407
410
  });
408
411
  if (c.designGate !== undefined) validateDesignGate(c.designGate, need);
409
412
  validateLayers(c, need, each);
413
+ p.push(...streamProblems(c));
410
414
  if (c.shell !== undefined) validateShell(c.shell, lanes, need);
411
415
  each('postEdit', (e, at) => {
412
416
  need(
@@ -562,6 +566,10 @@ function validateLayers(c, need, each) {
562
566
  l.denyPackages === undefined || isList(l.denyPackages),
563
567
  `${at}.denyPackages must be a list of globs`,
564
568
  );
569
+ need(
570
+ l.stream === undefined || isStr(l.stream),
571
+ `${at}.stream must name the stream whose module the layer is (leave it out for core)`,
572
+ );
565
573
  need(
566
574
  l.label === undefined || isLabel(l.label),
567
575
  `${at}.label must be a short name for what the layer delivers, such as "Data" or "Service" (one line, at most 60 characters)`,
@@ -106,6 +106,19 @@ export const SETTINGS = {
106
106
  about:
107
107
  "How many slices are in focus at once: a free lane builds an open slice's stories first, and may start the next slice only while fewer are open",
108
108
  },
109
+ 'promote.tokens': {
110
+ default: 60,
111
+ problem: (v) =>
112
+ Number.isInteger(v) && v >= 20 && v <= 1000 ? null : 'must be a whole number from 20 to 1000',
113
+ about:
114
+ 'How many tokens of code alike, names aside, make a clone a candidate for core, in a project built as streams',
115
+ },
116
+ 'promote.coreClones': {
117
+ default: 'note',
118
+ problem: (v) => (['note', 'refuse'].includes(v) ? null : 'must be note or refuse'),
119
+ about:
120
+ "What verify does with a branch whose module code repeats core's: note it for the review, or refuse it",
121
+ },
109
122
  'background.pauseAtPercent': {
110
123
  default: 80,
111
124
  problem: (v) =>
@@ -13,9 +13,10 @@ import {
13
13
  standardsFile,
14
14
  } from './standards.mjs';
15
15
  import { registerFile } from './costs.mjs';
16
+ import { platformOf, sharedLanes, streamsOf } from './streams.mjs';
16
17
 
17
18
  /** The version of code-kit's instructions: raised whenever the templates' rules change. */
18
- export const INSTRUCTIONS_VERSION = 13;
19
+ export const INSTRUCTIONS_VERSION = 15;
19
20
 
20
21
  const TEMPLATES = fileURLToPath(new URL('../../templates/', import.meta.url));
21
22
  const BEGIN = (v) => `<!-- code-kit:begin v${v} -->`;
@@ -69,6 +70,15 @@ function factsOf(root, config, lane = null) {
69
70
  'docs.plan': config.docs?.plan ?? 'the plan',
70
71
  'docs.principles': config.docs?.principles ?? "the project's principles",
71
72
  'docs.standards': standardsFile(config),
73
+ // Spec 31: the streams, and who owns core.
74
+ streams: streamsOf(config)
75
+ .map((st) => `${st.name} (${st.lanes.join(', ') || 'no lanes'})`)
76
+ .join('; '),
77
+ platform: platformOf(config)
78
+ ? `, owned by the ${platformOf(config).name} stream: a stream that needs core changed asks it with \`code-kit core ask "<what>" --story ST-n\`, and its story waits on the decision`
79
+ : sharedLanes(config).length
80
+ ? `, built on core's lanes (${sharedLanes(config).join(', ')}), which the streams take in turns`
81
+ : '',
72
82
  // Spec 29: the running budget and its register.
73
83
  cost: Boolean(config.cost),
74
84
  'docs.costs': registerFile(config),