@warren-dean/code-kit 0.25.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +16 -0
- package/README.md +70 -59
- package/bin/code-kit.mjs +113 -3
- package/hooks/act.mjs +96 -0
- package/hooks/guard-bash.mjs +27 -1
- package/hooks/hooks.json +42 -1
- package/hooks/lib/config.mjs +26 -2
- package/hooks/lib/events.mjs +626 -0
- package/hooks/lib/harness.mjs +8 -0
- package/hooks/lib/instructions.mjs +1 -1
- package/hooks/lib/next.mjs +22 -0
- package/hooks/lib/plan.mjs +17 -2
- package/hooks/lib/publish.mjs +144 -0
- package/hooks/lib/queue.mjs +36 -0
- package/hooks/lib/snapshot.mjs +33 -3
- package/hooks/lib/worktrees.mjs +19 -11
- package/hooks/mod/art.mjs +0 -81
- package/hooks/mod/board.mjs +1743 -0
- package/hooks/mod/characters.mjs +516 -0
- package/hooks/mod/loop.mjs +17 -3
- package/hooks/mod/mission.mjs +2 -93
- package/hooks/mod/panes.mjs +111 -422
- package/hooks/mod/register.mjs +473 -182
- package/hooks/mod/surface/character.mjs +79 -0
- package/hooks/mod/surface/clock.mjs +37 -0
- package/hooks/mod/surface/rail.mjs +33 -0
- package/hooks/mod/view.mjs +30 -602
- package/hooks/session.mjs +14 -11
- package/package.json +2 -1
- package/skills/decide/SKILL.md +1 -1
- package/skills/dispatch/SKILL.md +1 -1
- package/skills/init/SKILL.md +1 -1
- package/skills/next/SKILL.md +1 -1
- package/skills/review/SKILL.md +1 -1
- package/templates/agent.md +1 -1
- package/templates/claude-md.md +2 -2
- 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"]...
|
|
@@ -53,6 +58,7 @@ import {
|
|
|
53
58
|
readdirSync,
|
|
54
59
|
readFileSync,
|
|
55
60
|
rmSync,
|
|
61
|
+
statSync,
|
|
56
62
|
writeFileSync,
|
|
57
63
|
} from 'node:fs';
|
|
58
64
|
import { tmpdir } from 'node:os';
|
|
@@ -112,6 +118,14 @@ import {
|
|
|
112
118
|
writeInstructions,
|
|
113
119
|
} from '../hooks/lib/instructions.mjs';
|
|
114
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';
|
|
115
129
|
import { SETTINGS, parseSetting, settingOf, withSetting } from '../hooks/lib/harness.mjs';
|
|
116
130
|
import { claimLead, readLoop, releaseLead, writeLoop } from '../hooks/lib/loop-state.mjs';
|
|
117
131
|
import {
|
|
@@ -213,6 +227,9 @@ if (callerSession) process.env.CODE_KIT_SESSION = callerSession;
|
|
|
213
227
|
const minutesGiven = option('--minutes');
|
|
214
228
|
const daysGiven = option('--days');
|
|
215
229
|
const answerGiven = option('--answer');
|
|
230
|
+
const actGiven = option('--act');
|
|
231
|
+
const foundGiven = option('--found');
|
|
232
|
+
const howGiven = option('--how');
|
|
216
233
|
const leaseGiven = option('--lease');
|
|
217
234
|
const touchesGiven = option('--touches');
|
|
218
235
|
const techLeadGiven = option('--tech-lead');
|
|
@@ -233,6 +250,7 @@ const FLAGS = [
|
|
|
233
250
|
'--write',
|
|
234
251
|
'--no-checks',
|
|
235
252
|
'--json',
|
|
253
|
+
'--brief',
|
|
236
254
|
'--delegated',
|
|
237
255
|
'--person',
|
|
238
256
|
'--fresh',
|
|
@@ -629,11 +647,37 @@ function mergeMode() {
|
|
|
629
647
|
return byPerson;
|
|
630
648
|
}
|
|
631
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
|
+
|
|
632
676
|
function merge(branch) {
|
|
633
677
|
const { config } = load();
|
|
634
678
|
const byPerson = mergeMode();
|
|
635
679
|
try {
|
|
636
|
-
out(mergeOne(branch, config, byPerson).message);
|
|
680
|
+
out(`${mergeOne(branch, config, byPerson).message}${publishAfter(config, byPerson)}`);
|
|
637
681
|
} catch (e) {
|
|
638
682
|
if (e instanceof MergeStop) die(e.message);
|
|
639
683
|
throw e;
|
|
@@ -823,9 +867,10 @@ function queue() {
|
|
|
823
867
|
try {
|
|
824
868
|
const { message } = mergeOne(head.branch, config, byPerson, head.commit ?? null);
|
|
825
869
|
settle(root, head.branch, 'merged');
|
|
870
|
+
const published = publishAfter(config, byPerson);
|
|
826
871
|
const left = waiting(readQueue(root));
|
|
827
872
|
return out(
|
|
828
|
-
`${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.'}`,
|
|
829
874
|
);
|
|
830
875
|
} catch (e) {
|
|
831
876
|
if (!(e instanceof MergeStop)) throw e;
|
|
@@ -1643,6 +1688,66 @@ function status() {
|
|
|
1643
1688
|
}
|
|
1644
1689
|
}
|
|
1645
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
|
+
|
|
1646
1751
|
function next() {
|
|
1647
1752
|
const step = nextStep(resolve('.'), (config) => findBase(config, false));
|
|
1648
1753
|
if (flag('--json')) return out(JSON.stringify(step, null, 2));
|
|
@@ -2587,6 +2692,7 @@ const commands = {
|
|
|
2587
2692
|
loop: loopCommand,
|
|
2588
2693
|
approve: () => (rest.length ? approve(rest) : usage()),
|
|
2589
2694
|
merge: () => (rest.length === 1 ? merge(rest[0]) : usage()),
|
|
2695
|
+
publish: () => (rest.length === 0 ? publish() : usage()),
|
|
2590
2696
|
requests,
|
|
2591
2697
|
stops,
|
|
2592
2698
|
settings,
|
|
@@ -2608,6 +2714,8 @@ const commands = {
|
|
|
2608
2714
|
'sent-back': () => (rest.length === 1 ? sentBackCommand(rest[0]) : usage()),
|
|
2609
2715
|
ci: ciCommand,
|
|
2610
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()),
|
|
2611
2719
|
trace: () => (rest.length ? trace(rest) : usage()),
|
|
2612
2720
|
adapters,
|
|
2613
2721
|
next,
|
|
@@ -2630,7 +2738,9 @@ function usage() {
|
|
|
2630
2738
|
' | standards [--json] [--for <path>...]\n' +
|
|
2631
2739
|
' | worktrees [--json] | worktrees release|discard <branch> | worktrees prune [--quiet]\n' +
|
|
2632
2740
|
' | approve <name>... --reason "…" [--lane name] [--config file]\n' +
|
|
2633
|
-
' | merge <branch> --delegated|--person [--into branch] |
|
|
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' +
|
|
2634
2744
|
' | ask "<question>" [--story ST-n] [--blocks] [--why "…"] [--option "Label: effect"]... | ask [--json]\n' +
|
|
2635
2745
|
' | ask answer <id> "<answer>" | ask withdraw <id> --reason "…"\n' +
|
|
2636
2746
|
' | report "<title>" --what "…" [--expected …] [--command …] [--refusal …] [--rule …]\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);
|
package/hooks/guard-bash.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/hooks/lib/config.mjs
CHANGED
|
@@ -91,11 +91,15 @@ export function withDefaults(c) {
|
|
|
91
91
|
layers: c.layers ?? [],
|
|
92
92
|
importAliases: c.importAliases ?? {},
|
|
93
93
|
shell: { block: c.shell?.block ?? [], restricted: c.shell?.restricted ?? [] },
|
|
94
|
+
execution: { unrepeatable: c.execution?.unrepeatable ?? [] },
|
|
94
95
|
postEdit: c.postEdit ?? [],
|
|
95
96
|
checks: c.checks ?? [],
|
|
96
97
|
tests: c.tests ?? [],
|
|
97
98
|
regression: { prepare: c.regression?.prepare ?? null },
|
|
98
|
-
branches: {
|
|
99
|
+
branches: {
|
|
100
|
+
protected: c.branches?.protected ?? ['main', 'master'],
|
|
101
|
+
publish: c.branches?.publish ?? null,
|
|
102
|
+
},
|
|
99
103
|
approvals: {
|
|
100
104
|
lead: c.approvals?.lead === true,
|
|
101
105
|
delegate: delegateRules(c.approvals?.delegate, c.protected ?? []),
|
|
@@ -404,9 +408,29 @@ export function validate(c) {
|
|
|
404
408
|
'"approvals.delegate" must be false, or { protected?: [approval names], merge?: true|false, push?: true|false, tests?: true|false, dependencies?: { licences?, minWeeklyDownloads?, maxMonthsSinceRelease?, allowInstallScripts?: true|false|["binary","build","other"] } }',
|
|
405
409
|
);
|
|
406
410
|
need(
|
|
407
|
-
c.branches === undefined || isList(c.branches
|
|
411
|
+
c.branches === undefined || c.branches.protected === undefined || isList(c.branches.protected),
|
|
408
412
|
'"branches.protected" must be a list of branch names',
|
|
409
413
|
);
|
|
414
|
+
need(
|
|
415
|
+
c.execution === undefined ||
|
|
416
|
+
(c.execution &&
|
|
417
|
+
typeof c.execution === 'object' &&
|
|
418
|
+
(c.execution.unrepeatable === undefined ||
|
|
419
|
+
(isList(c.execution.unrepeatable) &&
|
|
420
|
+
c.execution.unrepeatable.every((r) => {
|
|
421
|
+
try {
|
|
422
|
+
new RegExp(r);
|
|
423
|
+
return true;
|
|
424
|
+
} catch {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
})))),
|
|
428
|
+
'"execution.unrepeatable" must be a list of patterns (regular expressions) for commands that can\'t safely run twice',
|
|
429
|
+
);
|
|
430
|
+
need(
|
|
431
|
+
[undefined, 'push', 'pull-request'].includes(c.branches?.publish),
|
|
432
|
+
'"branches.publish" must be "push" or "pull-request": how merges reach the remote\'s base',
|
|
433
|
+
);
|
|
410
434
|
p.push(...harnessProblems(c.harness));
|
|
411
435
|
p.push(...teamProblems(c));
|
|
412
436
|
return p;
|