@warren-dean/code-kit 0.24.0 → 0.26.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.
Files changed (41) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +25 -0
  4. package/README.md +74 -60
  5. package/bin/code-kit.mjs +188 -3
  6. package/hooks/act.mjs +96 -0
  7. package/hooks/guard-bash.mjs +27 -1
  8. package/hooks/hooks.json +42 -1
  9. package/hooks/lib/ci.mjs +407 -0
  10. package/hooks/lib/config.mjs +26 -2
  11. package/hooks/lib/events.mjs +626 -0
  12. package/hooks/lib/harness.mjs +8 -0
  13. package/hooks/lib/instructions.mjs +1 -1
  14. package/hooks/lib/next.mjs +31 -0
  15. package/hooks/lib/plan.mjs +17 -2
  16. package/hooks/lib/publish.mjs +144 -0
  17. package/hooks/lib/queue.mjs +36 -0
  18. package/hooks/lib/snapshot.mjs +33 -3
  19. package/hooks/lib/worktrees.mjs +19 -11
  20. package/hooks/mod/art.mjs +0 -81
  21. package/hooks/mod/board.mjs +1743 -0
  22. package/hooks/mod/characters.mjs +516 -0
  23. package/hooks/mod/loop.mjs +17 -3
  24. package/hooks/mod/mission.mjs +2 -93
  25. package/hooks/mod/panes.mjs +111 -422
  26. package/hooks/mod/register.mjs +473 -182
  27. package/hooks/mod/surface/character.mjs +79 -0
  28. package/hooks/mod/surface/clock.mjs +37 -0
  29. package/hooks/mod/surface/rail.mjs +33 -0
  30. package/hooks/mod/view.mjs +30 -602
  31. package/hooks/session.mjs +14 -11
  32. package/package.json +2 -1
  33. package/skills/decide/SKILL.md +1 -1
  34. package/skills/dispatch/SKILL.md +1 -1
  35. package/skills/init/SKILL.md +4 -3
  36. package/skills/next/SKILL.md +1 -1
  37. package/skills/review/SKILL.md +1 -1
  38. package/templates/agent.md +1 -1
  39. package/templates/claude-md.md +3 -1
  40. package/templates/github-workflow.yml +10 -3
  41. package/hooks/mod/register.test.ts +0 -4932
package/bin/code-kit.mjs CHANGED
@@ -19,6 +19,11 @@
19
19
  // approve <name>... --reason "…" [--lane name]
20
20
  // merge <branch> --delegated|--person [--into branch] merge a branch that passes verify: the lead
21
21
  // (approvals.delegate.merge) or the person (the code-kit pane)
22
+ // publish --delegated|--person put what's merged into the base onto the remote's, as
23
+ // branches.publish says: pushed, or as a pull request
24
+ // replay <story> [--json|--brief] a story's state rebuilt from its event log (spec 26), reading only
25
+ // reconcile [--json] | reconcile <story> --act <id> --found done|not-done --how "…"
26
+ // check acts a stopped agent left open against git; record a finding
22
27
  // requests [--json] open approval requests and approvals in force
23
28
  // requests drop <n>|all [--reason …] [--via pane] drop requests nobody needs answered any more
24
29
  // ask "<question>" [--story ST-n] [--blocks] [--why …] [--option "Label: what it does"]...
@@ -41,6 +46,9 @@
41
46
  // a working session's ad hoc task and the paths it leases
42
47
  // lanes [--json] | lanes release <lane>
43
48
  // the lanes running a story now, one each across sessions (spec 23)
49
+ // ci check [--json] | ci usage [--days N] [--json]
50
+ // what the project's CI spends and what multiplies it (spec 25)
51
+ // release <version> cut release/<version> from the base and push it: the full CI runs there
44
52
  // --config <file> reads a draft (.claude/code-kit.draft.json) instead of .claude/code-kit.json.
45
53
  import { execFileSync, spawnSync } from 'node:child_process';
46
54
  import {
@@ -50,6 +58,7 @@ import {
50
58
  readdirSync,
51
59
  readFileSync,
52
60
  rmSync,
61
+ statSync,
53
62
  writeFileSync,
54
63
  } from 'node:fs';
55
64
  import { tmpdir } from 'node:os';
@@ -109,6 +118,14 @@ import {
109
118
  writeInstructions,
110
119
  } from '../hooks/lib/instructions.mjs';
111
120
  import { dequeue, enqueue, lastMerged, readQueue, settle, waiting } from '../hooks/lib/queue.mjs';
121
+ import { publishBase } from '../hooks/lib/publish.mjs';
122
+ import {
123
+ briefOf,
124
+ readEvents,
125
+ reconcileAll,
126
+ recordFinding,
127
+ replay as replayEvents,
128
+ } from '../hooks/lib/events.mjs';
112
129
  import { SETTINGS, parseSetting, settingOf, withSetting } from '../hooks/lib/harness.mjs';
113
130
  import { claimLead, readLoop, releaseLead, writeLoop } from '../hooks/lib/loop-state.mjs';
114
131
  import {
@@ -169,6 +186,7 @@ import {
169
186
  worktrees,
170
187
  } from '../hooks/lib/worktrees.mjs';
171
188
  import { decisionsFor, openDecisions } from '../hooks/lib/decisionstore.mjs';
189
+ import { WORKFLOWS_DIR, ciFindings, ciUsage, releaseBranch } from '../hooks/lib/ci.mjs';
172
190
  import {
173
191
  appliesTo,
174
192
  projectStandards,
@@ -207,7 +225,11 @@ const callerSession = sessionId ?? process.env.CLAUDE_CODE_SESSION_ID ?? null;
207
225
  // A provider's command hears which session is calling, for that session's own live link.
208
226
  if (callerSession) process.env.CODE_KIT_SESSION = callerSession;
209
227
  const minutesGiven = option('--minutes');
228
+ const daysGiven = option('--days');
210
229
  const answerGiven = option('--answer');
230
+ const actGiven = option('--act');
231
+ const foundGiven = option('--found');
232
+ const howGiven = option('--how');
211
233
  const leaseGiven = option('--lease');
212
234
  const touchesGiven = option('--touches');
213
235
  const techLeadGiven = option('--tech-lead');
@@ -228,6 +250,7 @@ const FLAGS = [
228
250
  '--write',
229
251
  '--no-checks',
230
252
  '--json',
253
+ '--brief',
231
254
  '--delegated',
232
255
  '--person',
233
256
  '--fresh',
@@ -624,11 +647,37 @@ function mergeMode() {
624
647
  return byPerson;
625
648
  }
626
649
 
650
+ /**
651
+ * MQ-6: what's merged into the base, put onto the remote's as the base's rules say (`branches.publish`):
652
+ * pushed, or as a pull request. Moving the remote's base is the person's, or the lead's where pushing it
653
+ * is delegated; otherwise a pull request waits for the person. '' where the base doesn't publish.
654
+ */
655
+ function publishAfter(config, byPerson) {
656
+ const into = intoName ?? config.branches.protected[0];
657
+ const target = configAt(into) ?? config;
658
+ const mode = target.branches.publish;
659
+ if (!mode) return '';
660
+ const mayMove = byPerson || target.approvals.delegate?.push === true;
661
+ return ` ${publishBase(resolve('.'), into, { mode, mayMove }).message}`;
662
+ }
663
+
664
+ /** `publish --delegated|--person`: publishes what's merged and not yet on the remote, as a merge does. */
665
+ function publish() {
666
+ const { config } = load();
667
+ const byPerson = mergeMode();
668
+ const into = intoName ?? config.branches.protected[0];
669
+ if (!(configAt(into) ?? config).branches.publish)
670
+ return out(
671
+ `${into}'s rules don't say how merges reach the remote ("branches.publish" isn't set), so code-kit leaves pushing ${into} to you.`,
672
+ );
673
+ out(publishAfter(config, byPerson).trim());
674
+ }
675
+
627
676
  function merge(branch) {
628
677
  const { config } = load();
629
678
  const byPerson = mergeMode();
630
679
  try {
631
- out(mergeOne(branch, config, byPerson).message);
680
+ out(`${mergeOne(branch, config, byPerson).message}${publishAfter(config, byPerson)}`);
632
681
  } catch (e) {
633
682
  if (e instanceof MergeStop) die(e.message);
634
683
  throw e;
@@ -818,9 +867,10 @@ function queue() {
818
867
  try {
819
868
  const { message } = mergeOne(head.branch, config, byPerson, head.commit ?? null);
820
869
  settle(root, head.branch, 'merged');
870
+ const published = publishAfter(config, byPerson);
821
871
  const left = waiting(readQueue(root));
822
872
  return out(
823
- `${message}${left.length ? ` Next in the queue: ${left[0].branch}.` : ' The queue is empty.'}`,
873
+ `${message}${published}${left.length ? ` Next in the queue: ${left[0].branch}.` : ' The queue is empty.'}`,
824
874
  );
825
875
  } catch (e) {
826
876
  if (!(e instanceof MergeStop)) throw e;
@@ -1329,6 +1379,73 @@ function settings() {
1329
1379
  );
1330
1380
  }
1331
1381
 
1382
+ /**
1383
+ * CIC-2, CIC-4: `ci check` lists what in the project's workflows multiplies their cost with a story per
1384
+ * branch; `ci usage` sums the Actions runs of the last days, by workflow and trigger.
1385
+ */
1386
+ function ciCommand() {
1387
+ const { config } = load();
1388
+ const root = resolve('.');
1389
+ const [sub] = rest;
1390
+ if (sub === 'check') {
1391
+ const found = ciFindings(root, config.branches.protected[0]);
1392
+ if (flag('--json')) return out(JSON.stringify(found, null, 2));
1393
+ if (!found.length)
1394
+ return out(
1395
+ existsSync(join(root, WORKFLOWS_DIR))
1396
+ ? "Nothing in the project's workflows multiplies their cost: no full run per merge or pull request, every job has a time limit."
1397
+ : `No workflows in ${WORKFLOWS_DIR}.`,
1398
+ );
1399
+ let last = null;
1400
+ for (const f of found) {
1401
+ if (f.file !== last) out(`${last ? '\n' : ''}${f.file}`);
1402
+ last = f.file;
1403
+ out(` ${f.kind}: ${f.what}.\n Fix: ${f.fix}.`);
1404
+ }
1405
+ out(
1406
+ "\nChanging CI is the person's to approve (approval ci). A release then runs the full suite once: code-kit release <version>.",
1407
+ );
1408
+ return;
1409
+ }
1410
+ if (sub === 'usage') {
1411
+ const days = Number(daysGiven ?? 7);
1412
+ if (!Number.isFinite(days) || days <= 0) die('--days takes a number of days, such as 7.');
1413
+ const u = ciUsage(root, { days });
1414
+ if (u.error) die(u.error);
1415
+ if (flag('--json')) return out(JSON.stringify(u, null, 2));
1416
+ out(
1417
+ `${u.repo}, the last ${days} day${days === 1 ? '' : 's'}: ${u.runs} run${u.runs === 1 ? '' : 's'}, about ${u.minutes} minutes of wall-clock time (GitHub bills each job, rounded up to the minute, so the bill is at least this).`,
1418
+ );
1419
+ for (const r of u.rows)
1420
+ out(
1421
+ ` ${String(r.minutes).padStart(6)} min ${String(r.runs).padStart(4)} runs ${r.workflow} (${r.event})${r.cancelled ? `, ${r.cancelled} cancelled` : ''}${r.failed ? `, ${r.failed} failed` : ''}`,
1422
+ );
1423
+ if (u.refused)
1424
+ out(
1425
+ `\nGitHub isn't starting this project's jobs: ${u.refused} The project's CI isn't running at all until that's resolved in the account's Billing settings.`,
1426
+ );
1427
+ return;
1428
+ }
1429
+ usage();
1430
+ }
1431
+
1432
+ /** CIC-3: the release branch, cut from the base as committed and pushed, where the full CI runs once. */
1433
+ function releaseCommand(version) {
1434
+ const { config } = load();
1435
+ const from = base(config, false);
1436
+ const r = releaseBranch(resolve('.'), version, { base: from });
1437
+ if (!r.ok) die(`Not released: ${r.why}`);
1438
+ if (flag('--json')) return out(JSON.stringify(r, null, 2));
1439
+ out(
1440
+ `Cut ${r.branch} from ${from} at ${r.commit.slice(0, 7)} and pushed it: the project's full CI runs on it now.`,
1441
+ );
1442
+ out(
1443
+ r.stories.length
1444
+ ? `Stories in it since ${r.since ?? 'the start'}: ${r.stories.join(', ')}.`
1445
+ : `No story ids in its commits since ${r.since ?? 'the start'}.`,
1446
+ );
1447
+ }
1448
+
1332
1449
  /** Records the review's send-back of `branch` at its current commit (lib/reviews.mjs). */
1333
1450
  function sentBackCommand(branch) {
1334
1451
  load();
@@ -1571,6 +1688,66 @@ function status() {
1571
1688
  }
1572
1689
  }
1573
1690
 
1691
+ /**
1692
+ * DUR-3, DUR-5: `replay <story>` rebuilds a story's state from its event log, reading only; `--json`
1693
+ * for the mod and the skills, `--brief` for the brief of the agent that carries the story on.
1694
+ */
1695
+ function replayCommand(id) {
1696
+ const story = id.toUpperCase();
1697
+ const events = readEvents('.', story);
1698
+ const state = replayEvents(events);
1699
+ if (flag('--json'))
1700
+ return out(JSON.stringify({ story, events: events.length, ...state }, null, 2));
1701
+ if (!events.length)
1702
+ return out(
1703
+ `${story} has no event log (it started before code-kit kept one): read its state from git, its report and \`code-kit status\`.`,
1704
+ );
1705
+ const report = state.branch
1706
+ ? join('.claude/state/reports', `${state.branch.replace(/[^\w.-]+/g, '_')}.md`)
1707
+ : null;
1708
+ let reportAt = null;
1709
+ try {
1710
+ reportAt = report ? statSync(report).mtime.toISOString() : null;
1711
+ } catch {
1712
+ // no report written
1713
+ }
1714
+ if (flag('--brief')) return out(briefOf(story, state, { reportAt }));
1715
+ out(`${story}: ${state.phase ?? 'not started'}${state.branch ? ` on ${state.branch}` : ''}`);
1716
+ out(briefOf(story, state, { reportAt }).split('\n').slice(1).join('\n'));
1717
+ }
1718
+
1719
+ /**
1720
+ * DUR-4: `reconcile` checks every act a stopped agent left open against git, as `next` does, and lists
1721
+ * what it settled and what it couldn't; `reconcile <story> --act <id> --found done|not-done --how "…"`
1722
+ * records the lead's own finding for an act git couldn't settle.
1723
+ */
1724
+ function reconcileCommand(id) {
1725
+ const { config } = load();
1726
+ if (id) {
1727
+ if (!actGiven || !['done', 'not-done'].includes(foundGiven) || !howGiven)
1728
+ die('code-kit reconcile <story> --act <id> --found done|not-done --how "<how you know>"');
1729
+ const recorded = recordFinding(
1730
+ '.',
1731
+ id.toUpperCase(),
1732
+ actGiven,
1733
+ foundGiven === 'done' ? 'done' : 'not done',
1734
+ howGiven,
1735
+ );
1736
+ if (!recorded) die(`${id.toUpperCase()} has no act ${actGiven} left open.`);
1737
+ return out(`Recorded act ${actGiven} of ${id.toUpperCase()} as ${recorded.result.found}.`);
1738
+ }
1739
+ const result = reconcileAll('.', config, { base: findBase(config, false) });
1740
+ if (flag('--json')) return out(JSON.stringify(result, null, 2));
1741
+ if (!result.reconciled.length && !result.unknowns.length)
1742
+ return out('Nothing is left open by an agent that stopped.');
1743
+ for (const r of result.reconciled)
1744
+ out(`${r.story}: ${r.kind} \`${r.target}\` was ${r.found} (${r.how}); ${r.next}.`);
1745
+ for (const u of result.unknowns)
1746
+ out(
1747
+ `${u.story}: ${u.kind} \`${u.target}\` (act ${u.act}) is unknown: ${u.how}. The lead finds out and records it.`,
1748
+ );
1749
+ }
1750
+
1574
1751
  function next() {
1575
1752
  const step = nextStep(resolve('.'), (config) => findBase(config, false));
1576
1753
  if (flag('--json')) return out(JSON.stringify(step, null, 2));
@@ -2515,6 +2692,7 @@ const commands = {
2515
2692
  loop: loopCommand,
2516
2693
  approve: () => (rest.length ? approve(rest) : usage()),
2517
2694
  merge: () => (rest.length === 1 ? merge(rest[0]) : usage()),
2695
+ publish: () => (rest.length === 0 ? publish() : usage()),
2518
2696
  requests,
2519
2697
  stops,
2520
2698
  settings,
@@ -2534,6 +2712,10 @@ const commands = {
2534
2712
  journal: journalCommand,
2535
2713
  timeline,
2536
2714
  'sent-back': () => (rest.length === 1 ? sentBackCommand(rest[0]) : usage()),
2715
+ ci: ciCommand,
2716
+ release: () => (rest.length === 1 ? releaseCommand(rest[0]) : usage()),
2717
+ replay: () => (rest.length === 1 ? replayCommand(rest[0]) : usage()),
2718
+ reconcile: () => (rest.length <= 1 ? reconcileCommand(rest[0]) : usage()),
2537
2719
  trace: () => (rest.length ? trace(rest) : usage()),
2538
2720
  adapters,
2539
2721
  next,
@@ -2556,7 +2738,9 @@ function usage() {
2556
2738
  ' | standards [--json] [--for <path>...]\n' +
2557
2739
  ' | worktrees [--json] | worktrees release|discard <branch> | worktrees prune [--quiet]\n' +
2558
2740
  ' | approve <name>... --reason "…" [--lane name] [--config file]\n' +
2559
- ' | merge <branch> --delegated|--person [--into branch] | requests [--json] | requests drop <n>|all\n' +
2741
+ ' | merge <branch> --delegated|--person [--into branch] | publish --delegated|--person\n' +
2742
+ ' | replay <story> [--json|--brief] | reconcile [--json] | reconcile <story> --act <id> --found done|not-done --how "…"\n' +
2743
+ ' | requests [--json] | requests drop <n>|all\n' +
2560
2744
  ' | ask "<question>" [--story ST-n] [--blocks] [--why "…"] [--option "Label: effect"]... | ask [--json]\n' +
2561
2745
  ' | ask answer <id> "<answer>" | ask withdraw <id> --reason "…"\n' +
2562
2746
  ' | report "<title>" --what "…" [--expected …] [--command …] [--refusal …] [--rule …]\n' +
@@ -2566,6 +2750,7 @@ function usage() {
2566
2750
  ' | lanes [--json] | lanes release <lane> | sessions [--json] | sessions lead\n' +
2567
2751
  ' | who | task "<what>" --touches globs | task done | task take <session>\n' +
2568
2752
  ' | decisions [--json] [--all]\n' +
2753
+ ' | ci check [--json] | ci usage [--days N] [--json] | release <version>\n' +
2569
2754
  ' | hold <id> [--minutes N] | hold <id> --answer approved|refused\n' +
2570
2755
  ' | queue [--json] | queue add|drop <branch> | queue rules | queue merge --delegated|--person\n' +
2571
2756
  ' | loop [--json] | loop pause|resume | loop lead|release --session id [--take]\n' +
package/hooks/act.mjs ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ // Durable lanes (spec 26): the event log's writer. PreToolUse records each act's start, PostToolUse
3
+ // its end and PostToolUseFailure its failure, and SubagentStop a lane agent handing back. It never
4
+ // blocks a call (DUR-2): it runs in the background (`async` in hooks.json), so no call waits for it,
5
+ // and a write that fails is said once in the session while the work goes on.
6
+ import { existsSync, realpathSync, writeFileSync } from 'node:fs';
7
+ import { tmpdir } from 'node:os';
8
+ import { basename, dirname, isAbsolute, join, relative } from 'node:path';
9
+ import { start } from './lib/hook.mjs';
10
+ import { actorFor, currentBranch, sessionRoot } from './lib/rules.mjs';
11
+ import {
12
+ classify,
13
+ headOf,
14
+ recordEnd,
15
+ recordNote,
16
+ recordStart,
17
+ resultOf,
18
+ storyOf,
19
+ } from './lib/events.mjs';
20
+
21
+ const mode = process.argv[2];
22
+
23
+ /** A path as the repository names it, when it's inside it: real paths compared, so /tmp and /private/tmp agree. */
24
+ function inRoot(root, path) {
25
+ if (!path || !isAbsolute(path)) return path;
26
+ const real = (p) => {
27
+ try {
28
+ return realpathSync(p);
29
+ } catch {
30
+ try {
31
+ return join(realpathSync(dirname(p)), basename(p));
32
+ } catch {
33
+ return p;
34
+ }
35
+ }
36
+ };
37
+ const rel = relative(real(root), real(path));
38
+ return rel && !rel.startsWith('..') && !isAbsolute(rel) ? rel : path;
39
+ }
40
+ let input = {};
41
+ try {
42
+ const begun = start();
43
+ input = begun.input;
44
+ if (begun.error) process.exit(0);
45
+ const { project, config } = begun;
46
+ const root = sessionRoot(input, project) ?? project;
47
+ const actor = actorFor(input, root, config);
48
+ let branch = null;
49
+ try {
50
+ branch = currentBranch(root);
51
+ } catch {
52
+ // not a git repository yet
53
+ }
54
+ const who = actor.kind === 'lane' ? actor.lane : actor.kind === 'lead' ? 'lead' : actor.label;
55
+ const ctx = { session: input.session_id ?? null, agent: input.agent_id ?? null, actor: who };
56
+ if (mode === 'handback') {
57
+ const story = storyOf({ kind: 'handback', target: '', branch }).story;
58
+ if (actor.kind === 'lane' && story)
59
+ recordNote(root, { ...ctx, story, branch, kind: 'handback', head: headOf(root) });
60
+ process.exit(0);
61
+ }
62
+ const { kind, target } = classify(input.tool_name, input.tool_input, config);
63
+ const shown = kind === 'edit' || kind === 'read' ? inRoot(root, target) : target;
64
+ const { story, branch: storyBranch } = storyOf({ kind, target: shown, branch, root });
65
+ const act = {
66
+ ...ctx,
67
+ act: input.tool_use_id ?? null,
68
+ story,
69
+ kind,
70
+ target: shown,
71
+ branch: storyBranch ?? branch,
72
+ head: headOf(root),
73
+ };
74
+ if (mode === 'start') recordStart(root, act);
75
+ else if (mode === 'end') recordEnd(root, act, resultOf(kind, null, root));
76
+ else if (mode === 'fail') recordEnd(root, act, resultOf(kind, input.error ?? 'failed', root));
77
+ } catch (e) {
78
+ // DUR-2: once per session, the person hears the log isn't being kept; the call goes on.
79
+ const marker = join(
80
+ tmpdir(),
81
+ `code-kit-events-${String(input.session_id ?? 'session').replace(/[^\w-]/g, '')}`,
82
+ );
83
+ if (!existsSync(marker)) {
84
+ try {
85
+ writeFileSync(marker, String(e?.message ?? e));
86
+ } catch {
87
+ // nowhere to note it
88
+ }
89
+ process.stdout.write(
90
+ JSON.stringify({
91
+ systemMessage: `code-kit couldn't write its event log (${String(e?.message ?? e).split('\n')[0]}), so recovery after a crash falls back to git. Work goes on as before.`,
92
+ }),
93
+ );
94
+ }
95
+ }
96
+ process.exit(0);
@@ -20,6 +20,7 @@ import { CONFIG_FILE, committedConfig } from './lib/config.mjs';
20
20
  import { laneOfBranch, storyOfBranch, teamOf, teamProvider, whoami } from './lib/team.mjs';
21
21
  import { globToRegExp, matchesAny } from './lib/glob.mjs';
22
22
  import { noteBefore } from './lane-audit.mjs';
23
+ import { storyMerges } from './lib/queue.mjs';
23
24
  import { TESTS_APPROVAL, commitWeakenings } from './lib/regression.mjs';
24
25
  import {
25
26
  STANDARDS_APPROVAL,
@@ -105,7 +106,11 @@ for (const [re, why, text] of ALWAYS) {
105
106
  }
106
107
  const packages = addedPackages(cmd);
107
108
  const approves = runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+approve\b`));
108
- const delegatedMerge = runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+(?:queue\s+)?merge\b`));
109
+ // Merging into a protected branch, and publishing what's merged to the remote's (MQ-6), are alike.
110
+ const delegatedMerge = runs(
111
+ cmd,
112
+ new RegExp(String.raw`^${CODE_KIT}\s+(?:(?:queue\s+)?merge|publish)\b`),
113
+ );
109
114
  const queues = runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+queue\s+(?:add|drop)\b`));
110
115
  const rulesOntoBase = runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+queue\s+rules\b`));
111
116
  const asks = runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+ask\b\s+(?!--json\b)\S`));
@@ -272,6 +277,14 @@ if (runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+settings\s+set\b`)))
272
277
  block(
273
278
  `Blocked: changing the harness settings is the person's own act, from the code-kit pane (/harness) or their terminal. Tell them what you'd change and why, and stop.\nCommand: ${cmd}`,
274
279
  );
280
+ // DUR-4: what an interrupted act came to is the lead's to record, which found out.
281
+ if (
282
+ runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+reconcile\s+\S+.*\s--act\b`)) &&
283
+ actor.kind !== 'lead'
284
+ )
285
+ block(
286
+ `Blocked: recording what an interrupted act came to is the lead's, which checks what happened. Tell the lead what you know, and carry on.\nCommand: ${cmd}`,
287
+ );
275
288
  // LEAN-6: releasing or pruning worktrees is the lead's, which knows which stories are still at work.
276
289
  if (
277
290
  runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+worktrees\s+(?:release|prune)\b`)) &&
@@ -388,6 +401,19 @@ if (writesHistory && config.branches.protected.includes(branch) && !settingUp) {
388
401
  `Blocked: never commit or merge on ${branch}. Work on a branch; the lead merges it after review (or the person, where merges aren't delegated).`,
389
402
  );
390
403
  }
404
+ // MQ-5: a story's branch merges only into the base, through the merge queue. Merged with git into any
405
+ // other branch (an integration branch such as lead/next), it looks unmerged to the queue, the trail and
406
+ // worktree cleanup, and that branch becomes a second base. A lane merging another story into its own
407
+ // story's branch, or its base into it (MQ-3), is still its own work.
408
+ const elsewhere = storyMerges(cmd, branch).find(
409
+ ({ into }) => !storyOfBranch(into) && !config.branches.protected.includes(into),
410
+ );
411
+ if (elsewhere) {
412
+ const base = config.branches.protected[0];
413
+ block(
414
+ `Blocked: ${elsewhere.story} is a story's branch, and a story merges only into ${base}, through the merge queue: queue it once its review passes (\`code-kit queue add ${elsewhere.story}\`), then ${config.approvals.delegate?.merge ? `merge it with \`code-kit merge ${elsewhere.story} --delegated\`` : 'the person merges it from the code-kit pane'}. Merged into ${elsewhere.into}, it would look unmerged to the queue, the trail and worktree cleanup, and ${elsewhere.into} would become a second ${base}. ${config.branches.publish ? `The merge then reaches the remote's ${base} as "branches.publish" says (${config.branches.publish}).` : `Where the remote's ${base} only moves through pull requests, a person sets "branches.publish": "pull-request" and code-kit opens them.`}\nCommand: ${cmd}`,
415
+ );
416
+ }
391
417
 
392
418
  // TEAM-1, TEAM-4: in a team, making a story's branch claims the story (the dispatch), refused when the
393
419
  // lane is someone else's or the story is already claimed; a commit on it grows the claim's lease with
package/hooks/hooks.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "description": "code-kit: lanes, protected paths with an approval log, spec-check and design gates, layer rules and the project's checks, from .claude/code-kit.json",
2
+ "description": "code-kit: lanes, protected paths with an approval log, spec-check and design gates, layer rules and the project's checks, and a log of every act for recovery after a crash, from .claude/code-kit.json",
3
3
  "modules": ["./mod/register.mjs"],
4
4
  "hooks": {
5
5
  "PreToolUse": [
@@ -32,6 +32,17 @@
32
32
  "timeout": 10
33
33
  }
34
34
  ]
35
+ },
36
+ {
37
+ "matcher": "*",
38
+ "hooks": [
39
+ {
40
+ "type": "command",
41
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/act.mjs\" start",
42
+ "timeout": 5,
43
+ "async": true
44
+ }
45
+ ]
35
46
  }
36
47
  ],
37
48
  "PostToolUse": [
@@ -54,6 +65,17 @@
54
65
  "timeout": 30
55
66
  }
56
67
  ]
68
+ },
69
+ {
70
+ "matcher": "*",
71
+ "hooks": [
72
+ {
73
+ "type": "command",
74
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/act.mjs\" end",
75
+ "timeout": 5,
76
+ "async": true
77
+ }
78
+ ]
57
79
  }
58
80
  ],
59
81
  "SessionStart": [
@@ -106,6 +128,25 @@
106
128
  "type": "command",
107
129
  "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/stop-check.mjs\"",
108
130
  "timeout": 600
131
+ },
132
+ {
133
+ "type": "command",
134
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/act.mjs\" handback",
135
+ "timeout": 5,
136
+ "async": true
137
+ }
138
+ ]
139
+ }
140
+ ],
141
+ "PostToolUseFailure": [
142
+ {
143
+ "matcher": "*",
144
+ "hooks": [
145
+ {
146
+ "type": "command",
147
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/act.mjs\" fail",
148
+ "timeout": 5,
149
+ "async": true
109
150
  }
110
151
  ]
111
152
  }