@warren-dean/code-kit 0.31.1 → 0.32.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 +11 -0
- package/README.md +6 -6
- package/bin/code-kit.mjs +4 -3
- package/hooks/guard-agent.mjs +17 -2
- package/hooks/guard-bash.mjs +34 -4
- package/hooks/hooks.json +16 -0
- package/hooks/lib/checkout.mjs +198 -25
- package/hooks/lib/lanetrees.mjs +159 -0
- package/hooks/lib/next.mjs +3 -1
- package/hooks/lib/shell.mjs +71 -1
- package/hooks/lib/worktrees.mjs +91 -31
- package/hooks/mod/board.mjs +38 -61
- package/hooks/mod/decisions.mjs +26 -49
- package/hooks/mod/panes.mjs +151 -164
- package/hooks/mod/register.mjs +124 -163
- package/hooks/mod/view.mjs +4 -70
- package/hooks/worktree-create.mjs +34 -0
- package/hooks/worktree-done.mjs +45 -0
- package/package.json +1 -1
- package/skills/dispatch/SKILL.md +2 -2
- package/templates/agent.md +1 -1
package/hooks/mod/register.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// the lead to review, and merging (`merge --person`). No agent reaches those: they are the mod's own
|
|
9
9
|
// buttons, and the hooks refuse both commands from every agent.
|
|
10
10
|
import {
|
|
11
|
-
|
|
11
|
+
DECIDE_ID,
|
|
12
12
|
APPROVE_ID,
|
|
13
13
|
NOT_CODE_KIT,
|
|
14
14
|
PANE_ID,
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
agentsAtWork,
|
|
20
20
|
shownState,
|
|
21
21
|
attribution,
|
|
22
|
-
answerPane,
|
|
23
22
|
approvalAsidePrompt,
|
|
24
23
|
approvePane,
|
|
25
24
|
questionAsidePrompt,
|
|
@@ -46,7 +45,8 @@ import { axisStart, barCells } from './art.mjs';
|
|
|
46
45
|
import {
|
|
47
46
|
SENDBACK_ID,
|
|
48
47
|
codeTab,
|
|
49
|
-
|
|
48
|
+
cardToDecide,
|
|
49
|
+
decidePane,
|
|
50
50
|
journalTab,
|
|
51
51
|
laneActions,
|
|
52
52
|
liveLevel,
|
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
withoutInFlight,
|
|
101
101
|
} from './loop.mjs';
|
|
102
102
|
import { goalOf, nextText } from './mission.mjs';
|
|
103
|
-
import { contextOf, decisionCards, decisionKey,
|
|
103
|
+
import { contextOf, decisionCards, decisionKey, newDecisions } from './decisions.mjs';
|
|
104
104
|
import { DEFAULT_TEAM_UI, TEAM_ID, teamFrame } from './teamview.mjs';
|
|
105
105
|
import { glowOf, mapStoryOf, touchOf } from './codemap.mjs';
|
|
106
106
|
import { harnessSettings } from '../lib/harness.mjs';
|
|
@@ -139,7 +139,10 @@ const held = new Map(); // tool_use_id → a call held for the person (HOLD-2)
|
|
|
139
139
|
const denied = new Map(); // tool_use_id → a call Claude Code's own permission check refused (PERM-1)
|
|
140
140
|
const briefLater = new Set(); // the brief's questions the person put off this session (ASK-4)
|
|
141
141
|
const worktreesKept = new Set(); // merged worktrees the person chose to keep this session (LEAN-8)
|
|
142
|
-
|
|
142
|
+
// DECIDE-5: the Decide pane's decision, by its card's key, and the person's own words there:
|
|
143
|
+
// { key, at, typing: { text, error, aside } }; null while it's closed.
|
|
144
|
+
let deciding = null;
|
|
145
|
+
const freshTyping = () => ({ text: '', error: null, aside: { thread: [], draft: '' } });
|
|
143
146
|
let where = null; // { cli, cwd, interactive }, from session start
|
|
144
147
|
// The lead loop (spec 05): what it did, and what it waits on.
|
|
145
148
|
const loop = {
|
|
@@ -182,8 +185,7 @@ const LEASE_RENEW_MS = 30000;
|
|
|
182
185
|
// LOOP-11: the lead's last reply, read once before the loop next prompts it: { turnId, text, aborted, sent, read }
|
|
183
186
|
let lastReply = null;
|
|
184
187
|
let turnQuestions = []; // the open questions as the lead's running turn started
|
|
185
|
-
//
|
|
186
|
-
const offered = new Set();
|
|
188
|
+
// LEAN-3: whether Claude Code's question dialog is open on the milestone's compaction.
|
|
187
189
|
let offering = false;
|
|
188
190
|
// NOTIFY-1: the decisions waiting at the last look, by key; null until the first look.
|
|
189
191
|
let notified = null;
|
|
@@ -519,11 +521,11 @@ export function register(on) {
|
|
|
519
521
|
if (teamUi.tab === 'activity' && model.check?.team && !teamSince)
|
|
520
522
|
teamSince = (await json('team', 'since')) ?? { people: {} };
|
|
521
523
|
// JOURNAL-1, DECIDE-2: the lineage, for the Journal tab and the decisions' cards.
|
|
522
|
-
const
|
|
523
|
-
// UI-5: the Log reads it whenever the pane is open.
|
|
524
|
+
const asking = held.size > 0 || (model.requests?.open ?? []).length > 0;
|
|
525
|
+
// UI-5: the Log reads it whenever the pane is open; DECIDE-5: and the Decide pane's lineage.
|
|
524
526
|
if (
|
|
525
527
|
model.check?.docs?.plan &&
|
|
526
|
-
(paneOpen ||
|
|
528
|
+
(paneOpen || paneUi.view === 'journal' || asking || deciding)
|
|
527
529
|
)
|
|
528
530
|
journalData = (await json('journal')) ?? journalData;
|
|
529
531
|
},
|
|
@@ -683,9 +685,16 @@ export function register(on) {
|
|
|
683
685
|
usage: 'usage',
|
|
684
686
|
characters: 'characters',
|
|
685
687
|
};
|
|
688
|
+
// DECIDE-5: /lanes decide opens the Decide pane on the first decision waiting.
|
|
689
|
+
if (asked === 'decide') {
|
|
690
|
+
const [first] = cardsNow(await $.clock.now());
|
|
691
|
+
if (!first) return { text: 'Nothing needs you now.' };
|
|
692
|
+
await act.decide(first.line);
|
|
693
|
+
return {};
|
|
694
|
+
}
|
|
686
695
|
if (asked && !views[asked])
|
|
687
696
|
return {
|
|
688
|
-
text: `/lanes ${asked} isn't a view: try /lanes, or /lanes trail, map, journal, usage or characters.`,
|
|
697
|
+
text: `/lanes ${asked} isn't a view: try /lanes, or /lanes decide, trail, map, journal, usage or characters.`,
|
|
689
698
|
};
|
|
690
699
|
// Asked, not remembered: the person may have closed it with Escape.
|
|
691
700
|
const isOpen = (await $.ui.panes()).some((p) => p.id === PANE_ID);
|
|
@@ -722,25 +731,90 @@ export function register(on) {
|
|
|
722
731
|
return {};
|
|
723
732
|
},
|
|
724
733
|
// DECIDE-3: the Decisions tab, on the decision the person asked about.
|
|
734
|
+
// DECIDE-5: the Decide pane, on the card of the very line chosen (one of several a band line stands
|
|
735
|
+
// for, or the band line itself), else the first of its kind.
|
|
725
736
|
decide: async (line) => {
|
|
726
737
|
const cards = cardsNow(await $.clock.now());
|
|
727
|
-
// UI-3: the card of the very line chosen, else the first of its kind.
|
|
728
738
|
const exact = cards.findIndex(
|
|
729
|
-
(c) =>
|
|
739
|
+
(c) =>
|
|
740
|
+
(c.line?.kind === line?.kind && c.line?.text === line?.text) ||
|
|
741
|
+
(c.source?.kind === line?.kind && c.source?.text === line?.text),
|
|
730
742
|
);
|
|
731
743
|
const at = Math.max(
|
|
732
744
|
0,
|
|
733
745
|
exact >= 0 ? exact : cards.findIndex((c) => c.line.kind === line?.kind),
|
|
734
746
|
);
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (!(await $.ui.panes()).some((p) => p.id === PANE_ID))
|
|
738
|
-
await $.ui.open({ id: PANE_ID, title: 'Lanes', focus: true, closeOnEscape: true });
|
|
747
|
+
deciding = { key: cards[at]?.key ?? null, at, typing: freshTyping() };
|
|
748
|
+
await $.ui.open({ id: DECIDE_ID, title: 'Decide', focus: true, closeOnEscape: true });
|
|
739
749
|
$.ui.invalidate('ui.render');
|
|
740
|
-
|
|
750
|
+
// DECIDE-2: the lineage (what the person asked for, what's settled) is read with the pane open.
|
|
751
|
+
await act.reload();
|
|
741
752
|
$.ui.invalidate('ui.render');
|
|
742
753
|
return {};
|
|
743
754
|
},
|
|
755
|
+
// DECIDE-5: n and p, to the next decision and the one before.
|
|
756
|
+
decideMove: (key, at) => {
|
|
757
|
+
deciding = { key, at, typing: freshTyping() };
|
|
758
|
+
$.ui.invalidate('ui.render');
|
|
759
|
+
},
|
|
760
|
+
// DECIDE-5: an option pressed in the Decide pane. Once it's settled the pane shows the decision now in
|
|
761
|
+
// its place; one that opens a box of its own (Approve…) leaves the pane where it is behind it.
|
|
762
|
+
decideOption: async (option, card) => {
|
|
763
|
+
await act[option.act ?? option.id]?.(option.line ?? card.line);
|
|
764
|
+
if (deciding) deciding = { ...deciding, typing: freshTyping() };
|
|
765
|
+
$.ui.invalidate('ui.render');
|
|
766
|
+
},
|
|
767
|
+
// DECIDE-5: the person's own words, as the answer to the card's question.
|
|
768
|
+
decideTyped: async (card, text) => {
|
|
769
|
+
if (!deciding || !card.typed) return;
|
|
770
|
+
if (!text.trim()) {
|
|
771
|
+
deciding = {
|
|
772
|
+
...deciding,
|
|
773
|
+
typing: { ...deciding.typing, error: 'Type your answer: the lead builds on it.' },
|
|
774
|
+
};
|
|
775
|
+
$.ui.invalidate('ui.render');
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const done = await act.sendAnswer(card.typed, text.trim());
|
|
779
|
+
if (!deciding) return;
|
|
780
|
+
deciding = {
|
|
781
|
+
...deciding,
|
|
782
|
+
typing: done ? freshTyping() : { ...deciding.typing, error: notice },
|
|
783
|
+
};
|
|
784
|
+
$.ui.invalidate('ui.render');
|
|
785
|
+
},
|
|
786
|
+
// ASK-5: a question about the decision, answered in the pane by a side call, before answering it.
|
|
787
|
+
decideAsk: async (card, question) => {
|
|
788
|
+
const q = question.trim();
|
|
789
|
+
if (!deciding || !q || !card.typed) return;
|
|
790
|
+
const key = deciding.key;
|
|
791
|
+
const turn = { question: q, pending: true };
|
|
792
|
+
const thread = deciding.typing.aside.thread;
|
|
793
|
+
deciding = {
|
|
794
|
+
...deciding,
|
|
795
|
+
typing: { ...deciding.typing, aside: { thread: [...thread, turn], draft: '' } },
|
|
796
|
+
};
|
|
797
|
+
$.ui.invalidate('ui.render');
|
|
798
|
+
const reply = await act.sideCall(
|
|
799
|
+
questionAsidePrompt({ q: card.typed, thread, question: q }),
|
|
800
|
+
);
|
|
801
|
+
if (!deciding || deciding.key !== key) return;
|
|
802
|
+
const done = reply.isAnswered
|
|
803
|
+
? { question: q, answer: reply.text }
|
|
804
|
+
: {
|
|
805
|
+
question: q,
|
|
806
|
+
error: `No answer: ${reply.reason}${reply.status ? ` (${reply.status})` : ''}`,
|
|
807
|
+
};
|
|
808
|
+
const aside = deciding.typing.aside;
|
|
809
|
+
deciding = {
|
|
810
|
+
...deciding,
|
|
811
|
+
typing: {
|
|
812
|
+
...deciding.typing,
|
|
813
|
+
aside: { ...aside, thread: aside.thread.map((t) => (t === turn ? done : t)) },
|
|
814
|
+
},
|
|
815
|
+
};
|
|
816
|
+
$.ui.invalidate('ui.render');
|
|
817
|
+
},
|
|
744
818
|
// ASK-2, ASK-4, REPORT-3: a question's Answer… or a report's Read it opens its card.
|
|
745
819
|
openDecision: (line) => act.decide(line),
|
|
746
820
|
// ACT-1: the confirmation, prefilled from the request.
|
|
@@ -809,29 +883,9 @@ export function register(on) {
|
|
|
809
883
|
},
|
|
810
884
|
// ASK-2: the lead's option, pressed: the answer is recorded and sent to the lead.
|
|
811
885
|
answerWith: (line) => act.sendAnswer({ kind: 'question', ...line.question }, line.choice),
|
|
812
|
-
// ASK-2, ASK-4: Answer… opens
|
|
813
|
-
answer:
|
|
814
|
-
|
|
815
|
-
kind: 'question',
|
|
816
|
-
...line.question,
|
|
817
|
-
text: '',
|
|
818
|
-
error: null,
|
|
819
|
-
aside: { thread: [], draft: '' },
|
|
820
|
-
};
|
|
821
|
-
await $.ui.open({ id: ANSWER_ID, title: 'Answer', focus: true, closeOnEscape: true });
|
|
822
|
-
$.ui.invalidate('ui.render');
|
|
823
|
-
},
|
|
824
|
-
answerBrief: async (line) => {
|
|
825
|
-
answering = {
|
|
826
|
-
kind: 'brief',
|
|
827
|
-
...line.brief,
|
|
828
|
-
text: '',
|
|
829
|
-
error: null,
|
|
830
|
-
aside: { thread: [], draft: '' },
|
|
831
|
-
};
|
|
832
|
-
await $.ui.open({ id: ANSWER_ID, title: 'Answer', focus: true, closeOnEscape: true });
|
|
833
|
-
$.ui.invalidate('ui.render');
|
|
834
|
-
},
|
|
886
|
+
// ASK-2, ASK-4, DECIDE-5: Answer… opens the decision in the Decide pane, for the person's own words.
|
|
887
|
+
answer: (line) => act.decide(line),
|
|
888
|
+
answerBrief: (line) => act.decide(line),
|
|
835
889
|
laterBrief: (line) => {
|
|
836
890
|
briefLater.add(line.brief.question);
|
|
837
891
|
model = {
|
|
@@ -840,23 +894,6 @@ export function register(on) {
|
|
|
840
894
|
};
|
|
841
895
|
$.ui.invalidate('ui.render');
|
|
842
896
|
},
|
|
843
|
-
confirmAnswer: async (text) => {
|
|
844
|
-
if (!answering) return;
|
|
845
|
-
if (!text.trim()) {
|
|
846
|
-
answering = { ...answering, error: 'Type your answer: the lead builds on it.' };
|
|
847
|
-
$.ui.invalidate('ui.render');
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
const done = await act.sendAnswer(answering, text.trim());
|
|
851
|
-
if (done) {
|
|
852
|
-
answering = null;
|
|
853
|
-
await $.ui.close({ id: ANSWER_ID });
|
|
854
|
-
}
|
|
855
|
-
},
|
|
856
|
-
cancelAnswer: async () => {
|
|
857
|
-
answering = null;
|
|
858
|
-
await $.ui.close({ id: ANSWER_ID });
|
|
859
|
-
},
|
|
860
897
|
// The answer recorded (a question's, in code-kit) and told to the lead, which carries on with it.
|
|
861
898
|
sendAnswer: async (q, text) => {
|
|
862
899
|
if (q.kind === 'question') {
|
|
@@ -866,7 +903,6 @@ export function register(on) {
|
|
|
866
903
|
);
|
|
867
904
|
if (ran.exitCode !== 0) {
|
|
868
905
|
notice = `Your answer wasn't recorded: ${firstLine(ran)}`;
|
|
869
|
-
if (answering) answering = { ...answering, error: notice };
|
|
870
906
|
$.ui.invalidate('ui.render');
|
|
871
907
|
return false;
|
|
872
908
|
}
|
|
@@ -977,32 +1013,6 @@ export function register(on) {
|
|
|
977
1013
|
if (reply.isAnswered || reply.reason !== 'nothing-to-fork') return reply;
|
|
978
1014
|
return $.model.complete({ model: 'sonnet', prompt, maxTokens: 800 }).catch(failed);
|
|
979
1015
|
},
|
|
980
|
-
// ASK-5: a question about a question, asked in the answer box before answering.
|
|
981
|
-
askAnswer: async (question) => {
|
|
982
|
-
const q = question.trim();
|
|
983
|
-
if (!answering || !q) return;
|
|
984
|
-
const asked = answering;
|
|
985
|
-
const turn = { question: q, pending: true };
|
|
986
|
-
const thread = asked.aside.thread;
|
|
987
|
-
answering = { ...asked, aside: { thread: [...thread, turn], draft: '' } };
|
|
988
|
-
$.ui.invalidate('ui.render');
|
|
989
|
-
const reply = await act.sideCall(questionAsidePrompt({ q: asked, thread, question: q }));
|
|
990
|
-
if (!answering || answering.question !== asked.question) return;
|
|
991
|
-
const done = reply.isAnswered
|
|
992
|
-
? { question: q, answer: reply.text }
|
|
993
|
-
: {
|
|
994
|
-
question: q,
|
|
995
|
-
error: `No answer: ${reply.reason}${reply.status ? ` (${reply.status})` : ''}`,
|
|
996
|
-
};
|
|
997
|
-
answering = {
|
|
998
|
-
...answering,
|
|
999
|
-
aside: {
|
|
1000
|
-
...answering.aside,
|
|
1001
|
-
thread: answering.aside.thread.map((t) => (t === turn ? done : t)),
|
|
1002
|
-
},
|
|
1003
|
-
};
|
|
1004
|
-
$.ui.invalidate('ui.render');
|
|
1005
|
-
},
|
|
1006
1016
|
// ACT-5: a question about the approval, answered in its pane by a side call over the lead's own
|
|
1007
1017
|
// conversation (it shares the prompt cache, and nothing is added to the conversation); before the
|
|
1008
1018
|
// lead's first reply, from code-kit's facts alone.
|
|
@@ -1564,20 +1574,7 @@ export function register(on) {
|
|
|
1564
1574
|
act.sendAnswer({ kind: 'lead', question: line.waiting.question }, line.choice),
|
|
1565
1575
|
answerLeadTyped: (line, text) =>
|
|
1566
1576
|
act.sendAnswer({ kind: 'lead', question: line.waiting.question }, text),
|
|
1567
|
-
answerLeadText:
|
|
1568
|
-
answering = {
|
|
1569
|
-
kind: 'lead',
|
|
1570
|
-
question: line.waiting.question,
|
|
1571
|
-
options: line.waiting.options ?? [],
|
|
1572
|
-
text: '',
|
|
1573
|
-
error: null,
|
|
1574
|
-
aside: { thread: [], draft: '' },
|
|
1575
|
-
};
|
|
1576
|
-
await $.ui.open({ id: ANSWER_ID, title: 'Answer', focus: true, closeOnEscape: true });
|
|
1577
|
-
$.ui.invalidate('ui.render');
|
|
1578
|
-
},
|
|
1579
|
-
// DECIDE-4: a question's answer typed in the dialog, as the person's own words.
|
|
1580
|
-
answerTyped: (line, text) => act.sendAnswer({ kind: 'question', ...line.question }, text),
|
|
1577
|
+
answerLeadText: (line) => act.decide(line),
|
|
1581
1578
|
// LOOP-11, LOOP-12: the person asks the lead again for the step that held the loop.
|
|
1582
1579
|
askAgain: async () => {
|
|
1583
1580
|
const w = loop.waiting;
|
|
@@ -1596,9 +1593,8 @@ export function register(on) {
|
|
|
1596
1593
|
$.ui.invalidate('ui.render');
|
|
1597
1594
|
await act.step('resume');
|
|
1598
1595
|
},
|
|
1599
|
-
// DECIDE-
|
|
1600
|
-
//
|
|
1601
|
-
// Decisions tab. Never in a session another one runs the loop for, nor over what the person types.
|
|
1596
|
+
// DECIDE-5: nothing is asked in Claude Code's own dialog by itself: what needs the person waits in the
|
|
1597
|
+
// band and Needs you, and the Decide pane opens when they ask for it.
|
|
1602
1598
|
// NOTIFY-1: what newly needs the person, as a system notification, from the session that runs the
|
|
1603
1599
|
// loop. What waited before this session looked isn't news. On a Claude Code without $.ui.notify,
|
|
1604
1600
|
// the call fails and nothing is raised.
|
|
@@ -1623,32 +1619,6 @@ export function register(on) {
|
|
|
1623
1619
|
.then(() => $.ui.notify(one.text, { title: one.title }))
|
|
1624
1620
|
.catch(() => {});
|
|
1625
1621
|
},
|
|
1626
|
-
offer: async () => {
|
|
1627
|
-
if (offering || leadTurn || loop.sent || !where.interactive) return;
|
|
1628
|
-
if (standingBy() && role !== 'working') return;
|
|
1629
|
-
const now = await $.clock.now();
|
|
1630
|
-
const choice = cardsNow(now)
|
|
1631
|
-
.map((card) => ({ card, choice: nativeChoice(card) }))
|
|
1632
|
-
.find((c) => c.choice && !offered.has(c.choice.key));
|
|
1633
|
-
if (!choice) return;
|
|
1634
|
-
const box = await $.prompt.read().catch(() => null);
|
|
1635
|
-
if (box?.text?.trim()) return;
|
|
1636
|
-
offered.add(choice.choice.key);
|
|
1637
|
-
offering = true;
|
|
1638
|
-
const { question, header, options, typed } = choice.choice;
|
|
1639
|
-
const answer = await $.ui
|
|
1640
|
-
.ask(question, { options: options.map((o) => o.label), header })
|
|
1641
|
-
.catch(() => null)
|
|
1642
|
-
.finally(() => {
|
|
1643
|
-
offering = false;
|
|
1644
|
-
});
|
|
1645
|
-
if (answer == null) return;
|
|
1646
|
-
const picked = options.find((o) => o.label === answer);
|
|
1647
|
-
if (picked?.act) await act[picked.act](picked.line);
|
|
1648
|
-
else if (!picked && typed && answer.trim())
|
|
1649
|
-
await act[typed](choice.card.line, answer.trim());
|
|
1650
|
-
act.offer().catch(() => {});
|
|
1651
|
-
},
|
|
1652
1622
|
// LOOP-1, LOOP-5, LOOP-7: with the lead idle and no draft, the step `next` reports.
|
|
1653
1623
|
step: async (trigger) => {
|
|
1654
1624
|
const h = harness();
|
|
@@ -2140,7 +2110,7 @@ export function register(on) {
|
|
|
2140
2110
|
if (busy) return;
|
|
2141
2111
|
busy = true;
|
|
2142
2112
|
try {
|
|
2143
|
-
// LOOP-10: the lead session renews its lease
|
|
2113
|
+
// LOOP-10: the lead session renews its lease.
|
|
2144
2114
|
if (lease.mine) await act.lead();
|
|
2145
2115
|
// LOOP-14: the limit has reset; the loop takes its step at once.
|
|
2146
2116
|
if (loop.limited && !loop.limited.over && (await $.clock.now()) >= loop.limited.until) {
|
|
@@ -2148,7 +2118,6 @@ export function register(on) {
|
|
|
2148
2118
|
$.ui.invalidate('ui.render');
|
|
2149
2119
|
await act.step('resume');
|
|
2150
2120
|
}
|
|
2151
|
-
if (!leadTurn) act.offer().catch(() => {});
|
|
2152
2121
|
await act.notifyNew().catch(() => {});
|
|
2153
2122
|
await act.beat().catch(() => {});
|
|
2154
2123
|
await act.stalls();
|
|
@@ -2547,8 +2516,6 @@ export function register(on) {
|
|
|
2547
2516
|
// LEAN-3: a milestone just finished: its compaction comes before the next step.
|
|
2548
2517
|
if (await act?.compactAtMilestone().catch(() => false)) return res;
|
|
2549
2518
|
await act?.step('turn').catch(() => {});
|
|
2550
|
-
// DECIDE-4: a decision waiting, asked in Claude Code's own dialog; not awaited, the person answers.
|
|
2551
|
-
act?.offer().catch(() => {});
|
|
2552
2519
|
}
|
|
2553
2520
|
return res;
|
|
2554
2521
|
});
|
|
@@ -2967,27 +2934,6 @@ export function register(on) {
|
|
|
2967
2934
|
{ onBack: back },
|
|
2968
2935
|
);
|
|
2969
2936
|
}
|
|
2970
|
-
if (paneUi.view === 'decision') {
|
|
2971
|
-
const cards = cardsNow(now);
|
|
2972
|
-
if (cards.length)
|
|
2973
|
-
return viewFrame(
|
|
2974
|
-
'Decision',
|
|
2975
|
-
decisionsTab(cards, paneUi, els, {
|
|
2976
|
-
onDecision: (i) => {
|
|
2977
|
-
paneUi = { ...paneUi, decision: i };
|
|
2978
|
-
$.ui.invalidate('ui.render');
|
|
2979
|
-
},
|
|
2980
|
-
onNeed: (id, line) => act?.[id]?.(line),
|
|
2981
|
-
}),
|
|
2982
|
-
els,
|
|
2983
|
-
{ onBack: back },
|
|
2984
|
-
[
|
|
2985
|
-
{ key: 'j/k', label: 'decision' },
|
|
2986
|
-
{ key: 'esc', label: 'back' },
|
|
2987
|
-
],
|
|
2988
|
-
);
|
|
2989
|
-
paneUi = { ...paneUi, view: null };
|
|
2990
|
-
}
|
|
2991
2937
|
if (paneUi.view === 'characters')
|
|
2992
2938
|
return viewFrame(
|
|
2993
2939
|
'Characters',
|
|
@@ -3095,6 +3041,7 @@ export function register(on) {
|
|
|
3095
3041
|
return;
|
|
3096
3042
|
}
|
|
3097
3043
|
if (e.id === PANE_ID) paneOpen = false;
|
|
3044
|
+
if (e.id === DECIDE_ID) deciding = null;
|
|
3098
3045
|
return next(e);
|
|
3099
3046
|
});
|
|
3100
3047
|
|
|
@@ -3158,21 +3105,35 @@ export function register(on) {
|
|
|
3158
3105
|
});
|
|
3159
3106
|
});
|
|
3160
3107
|
|
|
3161
|
-
//
|
|
3162
|
-
on('ui.render', { component: 'Pane', requestId:
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3108
|
+
// DECIDE-5: the Decide pane: one decision at a time, all of it, beside the conversation.
|
|
3109
|
+
on('ui.render', { component: 'Pane', requestId: DECIDE_ID }, async ($, e) => {
|
|
3110
|
+
const cards = cardsNow(await $.clock.now());
|
|
3111
|
+
const ui = deciding ?? { key: null, at: 0, typing: freshTyping() };
|
|
3112
|
+
// What it shows now, as cards come and go: the one it was opened on, else the one in its place.
|
|
3113
|
+
const at = cardToDecide(cards, ui);
|
|
3114
|
+
if (deciding && at !== null && cards[at].key !== deciding.key)
|
|
3115
|
+
deciding = { key: cards[at].key, at, typing: freshTyping() };
|
|
3116
|
+
return decidePane(cards, deciding ?? ui, $.ui.resolve(e), {
|
|
3117
|
+
onOption: (option, card) => act.decideOption(option, card),
|
|
3118
|
+
onMove: (key, i) => act.decideMove(key, i),
|
|
3119
|
+
onTypedInput: (value) => {
|
|
3120
|
+
if (deciding) deciding = { ...deciding, typing: { ...deciding.typing, text: value } };
|
|
3167
3121
|
$.ui.invalidate('ui.render');
|
|
3168
3122
|
},
|
|
3169
|
-
|
|
3170
|
-
onCancel: () => act.cancelAnswer(),
|
|
3123
|
+
onTyped: (card, value) => act.decideTyped(card, value),
|
|
3171
3124
|
onAskInput: (value) => {
|
|
3172
|
-
|
|
3125
|
+
if (deciding)
|
|
3126
|
+
deciding = {
|
|
3127
|
+
...deciding,
|
|
3128
|
+
typing: { ...deciding.typing, aside: { ...deciding.typing.aside, draft: value } },
|
|
3129
|
+
};
|
|
3173
3130
|
$.ui.invalidate('ui.render');
|
|
3174
3131
|
},
|
|
3175
|
-
onAsk: (value) => act.
|
|
3132
|
+
onAsk: (card, value) => act.decideAsk(card, value),
|
|
3133
|
+
onClose: async () => {
|
|
3134
|
+
deciding = null;
|
|
3135
|
+
await $.ui.close({ id: DECIDE_ID });
|
|
3136
|
+
},
|
|
3176
3137
|
});
|
|
3177
3138
|
});
|
|
3178
3139
|
|
package/hooks/mod/view.mjs
CHANGED
|
@@ -651,7 +651,7 @@ export function approvePane(
|
|
|
651
651
|
* ACT-5: an aside in a pane: each question asked and its answer (or that it's being asked, or why there
|
|
652
652
|
* is none), then the box to ask the next.
|
|
653
653
|
*/
|
|
654
|
-
function asideNodes(aside, { Text, Input, Markdown }, { onAskInput, onAsk }, placeholder) {
|
|
654
|
+
export function asideNodes(aside, { Text, Input, Markdown }, { onAskInput, onAsk }, placeholder) {
|
|
655
655
|
return [
|
|
656
656
|
...aside.thread.flatMap((turn, i) => [
|
|
657
657
|
Text({ key: `aside-q-${i}`, color: 'cyan', children: [`You: ${turn.question}`] }),
|
|
@@ -685,7 +685,7 @@ function asideNodes(aside, { Text, Input, Markdown }, { onAskInput, onAsk }, pla
|
|
|
685
685
|
*/
|
|
686
686
|
export function questionAsidePrompt({ q, thread = [], question }) {
|
|
687
687
|
return [
|
|
688
|
-
"The person is deciding how to answer a question in code-kit's
|
|
688
|
+
"The person is deciding how to answer a question in code-kit's Decide pane, and asks you about it first. Answer in a few short sentences, in plain words: what the question means, why it matters for the build, what the choices are and what each leads to, and what you'd recommend if you know enough to. Use what you know from this conversation, the project's docs you've read, and the facts below. If you don't know, say so; don't guess. This answer goes to that pane, not into the conversation: don't act on it.",
|
|
689
689
|
'',
|
|
690
690
|
q.kind === 'brief'
|
|
691
691
|
? `An open question in ${q.path}:`
|
|
@@ -745,74 +745,8 @@ export function approvalAsidePrompt({ request, story = null, thread = [], questi
|
|
|
745
745
|
].join('\n');
|
|
746
746
|
}
|
|
747
747
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
/** ASK-2, ASK-4: the person's answer to the lead's question, or to one in their brief, typed. */
|
|
751
|
-
export function answerPane(
|
|
752
|
-
answering,
|
|
753
|
-
{ Box, Text, Input, Button, Markdown },
|
|
754
|
-
{ onInput, onSubmit, onCancel, onAskInput, onAsk },
|
|
755
|
-
) {
|
|
756
|
-
const { kind, question, text, error } = answering;
|
|
757
|
-
const aside = answering.aside ?? { thread: [], draft: '' };
|
|
758
|
-
return Box({
|
|
759
|
-
flexDirection: 'column',
|
|
760
|
-
rowGap: 1,
|
|
761
|
-
children: [
|
|
762
|
-
Text({ bold: true, children: [question] }),
|
|
763
|
-
Text({
|
|
764
|
-
dimColor: true,
|
|
765
|
-
children: [
|
|
766
|
-
kind === 'brief'
|
|
767
|
-
? `An open question in ${answering.path}. The lead records your answer in the brief's decisions and builds on it.`
|
|
768
|
-
: kind === 'lead'
|
|
769
|
-
? 'From the lead, which waits on it. Your answer is sent to the lead.'
|
|
770
|
-
: `${answering.id}, from the lead${answering.story ? `, for ${answering.story}` : ''}. Your answer is recorded and sent to the lead.`,
|
|
771
|
-
],
|
|
772
|
-
}),
|
|
773
|
-
...(kind === 'brief' && (answering.owner || answering.blocks)
|
|
774
|
-
? [
|
|
775
|
-
Text({
|
|
776
|
-
dimColor: true,
|
|
777
|
-
children: [
|
|
778
|
-
[
|
|
779
|
-
answering.owner && `Who decides: ${answering.owner}`,
|
|
780
|
-
answering.blocks && `Holds up: ${answering.blocks}`,
|
|
781
|
-
]
|
|
782
|
-
.filter(Boolean)
|
|
783
|
-
.join(' · '),
|
|
784
|
-
],
|
|
785
|
-
}),
|
|
786
|
-
]
|
|
787
|
-
: []),
|
|
788
|
-
// ASK-5: not sure what it means? Ask, here, before answering.
|
|
789
|
-
...asideNodes(
|
|
790
|
-
aside,
|
|
791
|
-
{ Text, Input, Markdown },
|
|
792
|
-
{ onAskInput, onAsk },
|
|
793
|
-
'What does it mean, and what would you suggest?',
|
|
794
|
-
),
|
|
795
|
-
Input({
|
|
796
|
-
key: 'answer-text',
|
|
797
|
-
label: 'Answer',
|
|
798
|
-
value: text,
|
|
799
|
-
submitLabel: 'Answer',
|
|
800
|
-
autoFocus: true,
|
|
801
|
-
onInput,
|
|
802
|
-
onSubmit,
|
|
803
|
-
}),
|
|
804
|
-
...(error ? [Text({ color: 'red', children: [error] })] : []),
|
|
805
|
-
Box({
|
|
806
|
-
flexDirection: 'row',
|
|
807
|
-
columnGap: 2,
|
|
808
|
-
children: [
|
|
809
|
-
Button({ key: 'answer-confirm', label: 'Answer', onPress: () => onSubmit(text) }),
|
|
810
|
-
Button({ key: 'answer-cancel', label: 'Cancel', onPress: onCancel }),
|
|
811
|
-
],
|
|
812
|
-
}),
|
|
813
|
-
],
|
|
814
|
-
});
|
|
815
|
-
}
|
|
748
|
+
/** DECIDE-5: the Decide pane: one decision at a time, beside the conversation. */
|
|
749
|
+
export const DECIDE_ID = 'code-kit-decide';
|
|
816
750
|
|
|
817
751
|
/** What a merge (or another act run through the CLI) reported. */
|
|
818
752
|
export function resultPane(result, { Box, Text }) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// WorktreeCreate (LEAN-10): the worktree Claude Code makes for an agent started with isolation, or for a
|
|
3
|
+
// worktree session. A lane agent gets its lane's worktree, reused with its installs (lib/lanetrees.mjs);
|
|
4
|
+
// everything else gets the worktree Claude Code would have made. The path goes on stdout, nothing else.
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { loadConfig } from './lib/config.mjs';
|
|
7
|
+
import { laneTree, mainCheckout, plainTree, takeNextLane } from './lib/lanetrees.mjs';
|
|
8
|
+
|
|
9
|
+
let input = {};
|
|
10
|
+
try {
|
|
11
|
+
input = JSON.parse(readFileSync(0, 'utf8'));
|
|
12
|
+
} catch {
|
|
13
|
+
// no input: a plain worktree
|
|
14
|
+
}
|
|
15
|
+
const main = mainCheckout(input.cwd || process.cwd());
|
|
16
|
+
if (!main) {
|
|
17
|
+
process.stderr.write('code-kit: not in a git repository, so no worktree was made.\n');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const name = String(input.name || `worktree-${Date.now()}`).replace(/[^\w./-]+/g, '-');
|
|
21
|
+
let dir = null;
|
|
22
|
+
try {
|
|
23
|
+
const { config } = loadConfig(main);
|
|
24
|
+
const next = config ? takeNextLane(main) : null;
|
|
25
|
+
if (next?.lane && config.lanes[next.lane]) dir = laneTree(main, next.lane, config);
|
|
26
|
+
} catch {
|
|
27
|
+
// the lane's worktree couldn't be readied: a plain one
|
|
28
|
+
}
|
|
29
|
+
dir ??= plainTree(main, name);
|
|
30
|
+
if (!dir) {
|
|
31
|
+
process.stderr.write(`code-kit: git couldn't make the worktree ${name}.\n`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
process.stdout.write(`${dir}\n`);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SubagentStop (LEAN-10): with code-kit making the worktrees (worktree-create.mjs), Claude Code no longer
|
|
3
|
+
// takes away an agent's worktree when it changed nothing, nor its branch. This does, as Claude Code would:
|
|
4
|
+
// the plain worktree made for the agent that's stopping, where it holds no change and no commit of its
|
|
5
|
+
// own. A lane's worktree is never taken: its next story reuses it.
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { loadConfig } from './lib/config.mjs';
|
|
10
|
+
import { laneTreePath, mainCheckout } from './lib/lanetrees.mjs';
|
|
11
|
+
import { WORKTREES_DIR } from './lib/worktrees.mjs';
|
|
12
|
+
|
|
13
|
+
let input = {};
|
|
14
|
+
try {
|
|
15
|
+
input = JSON.parse(readFileSync(0, 'utf8'));
|
|
16
|
+
} catch {
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
if (!input.agent_id) process.exit(0);
|
|
20
|
+
const main = mainCheckout(input.cwd || process.cwd());
|
|
21
|
+
if (!main) process.exit(0);
|
|
22
|
+
const name = `agent-${input.agent_id}`;
|
|
23
|
+
const dir = join(main, WORKTREES_DIR, name);
|
|
24
|
+
if (!existsSync(dir)) process.exit(0);
|
|
25
|
+
const { config } = loadConfig(main);
|
|
26
|
+
const lanes = Object.keys(config?.lanes ?? {});
|
|
27
|
+
if (lanes.some((l) => laneTreePath(main, l) === dir)) process.exit(0);
|
|
28
|
+
const git = (...args) => spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8' });
|
|
29
|
+
const branch = `worktree-${name}`;
|
|
30
|
+
if (git('branch', '--show-current').stdout.trim() !== branch) process.exit(0);
|
|
31
|
+
const status = git('status', '--porcelain');
|
|
32
|
+
if (status.status !== 0 || status.stdout.trim()) process.exit(0);
|
|
33
|
+
// Commits only this branch has: none, or it's work that stays.
|
|
34
|
+
const own = git(
|
|
35
|
+
'rev-list',
|
|
36
|
+
'--count',
|
|
37
|
+
branch,
|
|
38
|
+
'--not',
|
|
39
|
+
`--exclude=${branch}`,
|
|
40
|
+
'--branches',
|
|
41
|
+
'--remotes',
|
|
42
|
+
);
|
|
43
|
+
if (own.status !== 0 || Number(own.stdout.trim()) !== 0) process.exit(0);
|
|
44
|
+
spawnSync('git', ['-C', main, 'worktree', 'remove', dir], { encoding: 'utf8' });
|
|
45
|
+
spawnSync('git', ['-C', main, 'branch', '-D', branch], { encoding: 'utf8' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warren-dean/code-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Keeps AI coding agents inside your project's rules: lanes, layer rules, protected paths and proof before finish, enforced by Claude Code hooks and in CI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Warren Langeveldt",
|
package/skills/dispatch/SKILL.md
CHANGED
|
@@ -50,7 +50,7 @@ When the story carries out an intent the team agreed (`code-kit intend`), add `-
|
|
|
50
50
|
|
|
51
51
|
One agent per story: never send a running lane agent a second story, or a send-back. A story that goes on (sent back, or handed back at its context limit) gets a fresh agent: first run `node "${CLAUDE_PLUGIN_ROOT}/bin/code-kit.mjs" worktrees release <branch>`, which keeps the branch's commits and moves its report to the main checkout, then start the agent as below with the brief, "Read your earlier report first: `.claude/state/reports/<branch with / as _>.md` in the main checkout", and what `node "${CLAUDE_PLUGIN_ROOT}/bin/code-kit.mjs" replay <story> --brief` prints: the story's last commit, the tests last run, what changed since, and what was reconciled, from its event log, which holds them even when the stopped agent wrote no report. A long-lived agent rereads its whole context on every step, which is most of what a build costs.
|
|
52
52
|
|
|
53
|
-
Start each story with the Agent tool: `subagent_type` is the lane's agent, `model` the one `code-kit next --json` gives the story in `models` (with the lane model `story`, each story's model follows its `**Size:**`, raised for a security requirement, a fix or a send-back; a story with no size runs on Sonnet, so size it in the plan first if it's plainly small or large), `isolation: "worktree"`, and run them in the background, with a `description` that starts with the story's id ("ST-12 booking form"): the loop reads it to know the story is in flight, and won't ask for it again while the agent works.
|
|
53
|
+
Start each story with the Agent tool: `subagent_type` is the lane's agent, `model` the one `code-kit next --json` gives the story in `models` (with the lane model `story`, each story's model follows its `**Size:**`, raised for a security requirement, a fix or a send-back; a story with no size runs on Sonnet, so size it in the plan first if it's plainly small or large), `isolation: "worktree"`, and run them in the background, with a `description` that starts with the story's id ("ST-12 booking form"): the loop reads it to know the story is in flight, and won't ask for it again while the agent works. Each lane works in its own worktree, `.claude/worktrees/lane-<lane>`, kept from story to story with its installs: code-kit gives it to the lane's agent when it starts, detached at the main checkout's HEAD, so the agent makes or switches to its story's branch as the brief says. So start the agents one per message, each right after the last (they still run in parallel in the background): code-kit tells each agent's worktree whose it is as it starts, and refuses a second agent with a worktree in the same message.
|
|
54
54
|
|
|
55
55
|
The brief is the agent's whole context. Write it so the agent needs nothing else:
|
|
56
56
|
|
|
@@ -69,7 +69,7 @@ Designs: <for a story that builds screens, what `code-kit designs ST-<n>` lists:
|
|
|
69
69
|
Out of scope: <what neighbouring stories or other lanes will do>
|
|
70
70
|
|
|
71
71
|
Steps:
|
|
72
|
-
1. Run the spec-check skill against these requirements and save the report (the path guard requires it).
|
|
72
|
+
1. Run the spec-check skill against these requirements and save the report, with its `| Requirement |` table (the path guard requires it, and reads a report without that table as none).
|
|
73
73
|
If it recommends "blocked on questions", stop and report the questions.
|
|
74
74
|
2. Build it end to end in your lane's paths. No mocks, stubs, placeholder screens or "coming soon".
|
|
75
75
|
3. Write tests that prove each acceptance criterion. Name the requirement ID in each test's title,
|