@warren-dean/code-kit 0.25.0 → 0.26.1
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 +24 -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 +45 -9
- package/hooks/lib/publish.mjs +144 -0
- package/hooks/lib/queue.mjs +36 -0
- package/hooks/lib/snapshot.mjs +33 -3
- package/hooks/lib/storymap.mjs +54 -17
- package/hooks/lib/timeline.mjs +94 -44
- 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 +482 -184
- 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
|
@@ -0,0 +1,1743 @@
|
|
|
1
|
+
// The mod, redesigned (docs/specs/27-the-mod-redesigned.md): one pane of panels, no tabs. Build (is the
|
|
2
|
+
// build moving?), Needs you (what needs me?), Lanes (where is each story? is it what I asked for? is it
|
|
3
|
+
// built right?), Queue and Log, each with a status line first and no room taken when it has nothing to
|
|
4
|
+
// say; the full views opened from a story or a command; three layouts. Pure functions from what the
|
|
5
|
+
// mod already holds to elements, so they're tested with node at every width (UI-13).
|
|
6
|
+
import { charactersOf, characterFrame, characterSvg, POSES, workOf } from './characters.mjs';
|
|
7
|
+
import { BAR, rasterCells, runs, timelineSvg } from './art.mjs';
|
|
8
|
+
import { goalOf } from './mission.mjs';
|
|
9
|
+
import { CELL, cellOf, laneActions, laneStories, storyToOpen } from './panes.mjs';
|
|
10
|
+
import { NOT_CODE_KIT, ago, askWords, shownState, tokens } from './view.mjs';
|
|
11
|
+
|
|
12
|
+
const LEAD = 'lead';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The pane's own state, kept by the mod between draws: the full view open over the panels (null, or
|
|
16
|
+
* story, trail, code, journal, usage, decision, characters), what's selected ({ kind: 'need' | 'lane',
|
|
17
|
+
* id }), the need open in its place, the filter, and the full views' own.
|
|
18
|
+
*/
|
|
19
|
+
export const BOARD_UI = {
|
|
20
|
+
view: null,
|
|
21
|
+
sel: null,
|
|
22
|
+
need: 0,
|
|
23
|
+
search: '',
|
|
24
|
+
filtering: false,
|
|
25
|
+
cell: null,
|
|
26
|
+
file: null,
|
|
27
|
+
mapStory: null,
|
|
28
|
+
mapFile: null,
|
|
29
|
+
decision: 0,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// --- UI-7: one table of words, colours and glyphs ---------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/** Each state's word, colour and glyph, used by every panel and view: the glyph reads without colour. */
|
|
35
|
+
export const STATE = {
|
|
36
|
+
building: { word: 'building', color: 'blue', glyph: '●' },
|
|
37
|
+
working: { word: 'working', color: 'green', glyph: '▶' },
|
|
38
|
+
orchestrating: { word: 'orchestrating', color: 'yellow', glyph: '◆' },
|
|
39
|
+
'in review': { word: 'in review', color: 'yellow', glyph: '◐' },
|
|
40
|
+
queued: { word: 'queued', color: 'cyan', glyph: '◇' },
|
|
41
|
+
waiting: { word: 'waiting', color: 'cyan', glyph: '◇' },
|
|
42
|
+
merging: { word: 'merging', color: 'cyan', glyph: '◈' },
|
|
43
|
+
merged: { word: 'merged', color: 'green', glyph: '✓' },
|
|
44
|
+
'sent back': { word: 'sent back', color: 'magenta', glyph: '↩' },
|
|
45
|
+
'waiting on you': { word: 'waiting on you', color: 'cyan', glyph: '?' },
|
|
46
|
+
blocked: { word: 'blocked', color: 'red', glyph: '■' },
|
|
47
|
+
stalled: { word: 'stalled', color: 'red', glyph: '✗' },
|
|
48
|
+
quiet: { word: 'quiet', color: 'yellow', glyph: '…' },
|
|
49
|
+
ready: { word: 'ready', color: 'green', glyph: '○' },
|
|
50
|
+
todo: { word: 'to do', color: undefined, glyph: '○' },
|
|
51
|
+
idle: { word: 'resting', color: undefined, glyph: '·' },
|
|
52
|
+
dispatched: { word: 'started', color: 'blue', glyph: '→' },
|
|
53
|
+
};
|
|
54
|
+
/** A story's plan state as the table names it: done is merged, review in review, in progress building. */
|
|
55
|
+
const STORY_STATE = { done: 'merged', review: 'in review', 'in progress': 'building' };
|
|
56
|
+
const styleOf = (state) =>
|
|
57
|
+
STATE[state]?.color ? { color: STATE[state].color } : { dimColor: true };
|
|
58
|
+
const wordOf = (state) => STATE[state]?.word ?? state;
|
|
59
|
+
const glyphOf = (state) => STATE[state]?.glyph ?? '·';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* LANES-3: a lane's stories as cards (id and state, title, requirements, and what it waits on or its
|
|
63
|
+
* branch), wrapping, then its agent and the paths it owns. `detail` is { agent, owns, stories }.
|
|
64
|
+
*/
|
|
65
|
+
export function laneDetail(detail, { Box, Text }) {
|
|
66
|
+
const text = (value, style = {}) => Text({ ...style, children: [String(value)] });
|
|
67
|
+
const cards = detail.stories.map((s) => {
|
|
68
|
+
const state = STORY_STATE[s.state] ?? s.state;
|
|
69
|
+
const done = s.state === 'done';
|
|
70
|
+
return Box({
|
|
71
|
+
key: `card-${s.id}`,
|
|
72
|
+
flexDirection: 'column',
|
|
73
|
+
borderStyle: 'round',
|
|
74
|
+
borderColor: STATE[state]?.color ?? 'gray',
|
|
75
|
+
...(done ? { borderDimColor: true } : {}),
|
|
76
|
+
paddingX: 1,
|
|
77
|
+
width: 30,
|
|
78
|
+
flexShrink: 1,
|
|
79
|
+
children: [
|
|
80
|
+
Box({
|
|
81
|
+
flexDirection: 'row',
|
|
82
|
+
justifyContent: 'space-between',
|
|
83
|
+
children: [
|
|
84
|
+
text(s.id, { bold: true, dimColor: done }),
|
|
85
|
+
text(`${glyphOf(state)} ${wordOf(state)}`, styleOf(state)),
|
|
86
|
+
],
|
|
87
|
+
}),
|
|
88
|
+
text(s.title, { wrap: 'truncate-end', dimColor: done }),
|
|
89
|
+
...(s.requirements?.length
|
|
90
|
+
? [text(s.requirements.join(' '), { dimColor: true, wrap: 'truncate-end' })]
|
|
91
|
+
: []),
|
|
92
|
+
...(s.state === 'blocked' && s.waitingOn?.length
|
|
93
|
+
? [text(`waits on ${s.waitingOn.join(', ')}`, { color: 'red', wrap: 'truncate-end' })]
|
|
94
|
+
: s.branch && !done
|
|
95
|
+
? [text(s.branch, { dimColor: true, wrap: 'truncate-end' })]
|
|
96
|
+
: []),
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return [
|
|
101
|
+
Box({
|
|
102
|
+
key: 'lane-cards',
|
|
103
|
+
flexDirection: 'row',
|
|
104
|
+
flexWrap: 'wrap',
|
|
105
|
+
columnGap: 1,
|
|
106
|
+
children: cards.length
|
|
107
|
+
? cards
|
|
108
|
+
: [text('No stories in the plan for this lane.', { dimColor: true })],
|
|
109
|
+
}),
|
|
110
|
+
Box({
|
|
111
|
+
key: 'lane-owns',
|
|
112
|
+
flexDirection: 'row',
|
|
113
|
+
flexWrap: 'wrap',
|
|
114
|
+
columnGap: 2,
|
|
115
|
+
children: [
|
|
116
|
+
...(detail.agent ? [text('agent', { dimColor: true }), text(detail.agent)] : []),
|
|
117
|
+
text('owns', { dimColor: true }),
|
|
118
|
+
...(detail.owns.length
|
|
119
|
+
? detail.owns.map((p) => text(p, { color: 'cyan' }))
|
|
120
|
+
: [text('nothing yet', { dimColor: true })]),
|
|
121
|
+
],
|
|
122
|
+
}),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// --- UI-2: the build counted in requirements tested ------------------------------------------------
|
|
127
|
+
|
|
128
|
+
/** The four kinds of requirement the Build bar counts, in the order it fills. */
|
|
129
|
+
export const PROGRESS = [
|
|
130
|
+
{ id: 'tested', cell: 'tested', word: 'tested' },
|
|
131
|
+
{ id: 'untested', cell: 'done', word: 'untested' },
|
|
132
|
+
{ id: 'moving', cell: 'in progress', word: 'in progress' },
|
|
133
|
+
{ id: 'todo', cell: 'todo', word: 'todo' },
|
|
134
|
+
];
|
|
135
|
+
const kindOfCell = (cell) =>
|
|
136
|
+
cell === 'tested'
|
|
137
|
+
? 'tested'
|
|
138
|
+
: cell === 'done'
|
|
139
|
+
? 'untested'
|
|
140
|
+
: cell === 'in progress'
|
|
141
|
+
? 'moving'
|
|
142
|
+
: 'todo';
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* UI-2: the milestone being built and its requirements by kind, from status's requirements and stories:
|
|
146
|
+
* { name, total, tested, untested, moving, todo, ids }, the milestone's requirements being those its
|
|
147
|
+
* stories cite. With no milestones in the plan, every requirement counts ({ name: null }). Null when
|
|
148
|
+
* the specs name no requirement.
|
|
149
|
+
*/
|
|
150
|
+
export function buildProgress(state, status) {
|
|
151
|
+
const requirements = (status?.requirements ?? []).filter((r) => r.state !== 'removed');
|
|
152
|
+
if (!requirements.length) return null;
|
|
153
|
+
const goal = goalOf(state?.stories ?? []);
|
|
154
|
+
const inMilestone = goal
|
|
155
|
+
? new Set(
|
|
156
|
+
(state.stories ?? [])
|
|
157
|
+
.filter((s) => s.milestone === goal.name)
|
|
158
|
+
.flatMap((s) => s.requirements ?? []),
|
|
159
|
+
)
|
|
160
|
+
: null;
|
|
161
|
+
const mine = inMilestone ? requirements.filter((r) => inMilestone.has(r.id)) : requirements;
|
|
162
|
+
const out = { name: goal?.name ?? null, total: mine.length, ids: {} };
|
|
163
|
+
for (const p of PROGRESS) {
|
|
164
|
+
const ids = mine.filter((r) => kindOfCell(cellOf(r)) === p.id).map((r) => r.id);
|
|
165
|
+
out[p.id] = ids.length;
|
|
166
|
+
out.ids[p.id] = ids;
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The Build bar as runs [{ kind, glyph, color, n }], `width` cells shared by the kinds there are. */
|
|
172
|
+
export function buildBar(progress, width) {
|
|
173
|
+
if (!progress?.total) return [];
|
|
174
|
+
const runs = [];
|
|
175
|
+
let used = 0;
|
|
176
|
+
const kinds = PROGRESS.filter((p) => progress[p.id] > 0);
|
|
177
|
+
kinds.forEach((p, i) => {
|
|
178
|
+
const n =
|
|
179
|
+
i === kinds.length - 1
|
|
180
|
+
? width - used
|
|
181
|
+
: Math.max(1, Math.round((progress[p.id] / progress.total) * width));
|
|
182
|
+
used += n;
|
|
183
|
+
runs.push({ kind: p.id, glyph: CELL[p.cell].glyph, color: CELL[p.cell].color, n });
|
|
184
|
+
});
|
|
185
|
+
return runs.filter((r) => r.n > 0);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The Build panel's words: "Milestone 3: Booking · 9 of 14 tested · 3 untested". */
|
|
189
|
+
export function buildWords(progress) {
|
|
190
|
+
if (!progress) return null;
|
|
191
|
+
const head = progress.name ? `${progress.name} · ` : '';
|
|
192
|
+
return `${head}${progress.tested} of ${progress.total} tested${progress.untested ? ` · ${progress.untested} untested` : ''}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The Build panel's state in a word or two, from the loop and whether anything is at work. */
|
|
196
|
+
export function buildState(loop, { atWork = 0, leadBusy = false } = {}) {
|
|
197
|
+
if (loop?.state === 'paused') return 'paused';
|
|
198
|
+
if (loop?.state === 'done' || loop?.state === 'stopped') return 'milestone done';
|
|
199
|
+
if (loop?.state === 'elsewhere') return 'led elsewhere';
|
|
200
|
+
if (loop?.state === 'unled') return 'no lead';
|
|
201
|
+
if (atWork || leadBusy) return 'moving';
|
|
202
|
+
if (loop?.state === 'off') return 'loop off';
|
|
203
|
+
return 'still';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// --- UI-3: what needs the person, most urgent first -----------------------------------------------
|
|
207
|
+
|
|
208
|
+
/** How urgent each kind of line is (UI-3): a held call first, notes last. */
|
|
209
|
+
const URGENCY = [
|
|
210
|
+
'notice',
|
|
211
|
+
'held',
|
|
212
|
+
'question',
|
|
213
|
+
'waiting',
|
|
214
|
+
'proposal',
|
|
215
|
+
'approvals',
|
|
216
|
+
'queue',
|
|
217
|
+
'review',
|
|
218
|
+
'stalled',
|
|
219
|
+
'stuck',
|
|
220
|
+
'designing',
|
|
221
|
+
'brief',
|
|
222
|
+
'report',
|
|
223
|
+
'worktree',
|
|
224
|
+
];
|
|
225
|
+
const NOTES = new Set(['usage', 'paused', 'finish', 'done', 'teamDown', 'elsewhere', 'loop']);
|
|
226
|
+
|
|
227
|
+
/** What a line is, in a word or two, for the Needs you panel. */
|
|
228
|
+
const NEED_WORD = {
|
|
229
|
+
notice: 'failed',
|
|
230
|
+
held: 'held call',
|
|
231
|
+
question: 'question',
|
|
232
|
+
waiting: 'the lead waits',
|
|
233
|
+
proposal: 'next step',
|
|
234
|
+
approvals: 'approval',
|
|
235
|
+
queue: 'merge',
|
|
236
|
+
review: 'review',
|
|
237
|
+
stalled: 'stalled',
|
|
238
|
+
stuck: 'stuck',
|
|
239
|
+
designing: 'design',
|
|
240
|
+
brief: 'brief',
|
|
241
|
+
report: 'bug report',
|
|
242
|
+
worktree: 'worktree',
|
|
243
|
+
task: 'your task',
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* UI-3, UI-8: the band's lines that need the person or tell them something (the mission rows aside),
|
|
248
|
+
* most urgent first, every action numbered again in that order, so a digit presses the same button in
|
|
249
|
+
* the band and the pane. Team lines (spec 16) sit with the decisions; notes come last.
|
|
250
|
+
*/
|
|
251
|
+
export function needsOf(lines = []) {
|
|
252
|
+
const rank = (l) => {
|
|
253
|
+
if (l.kind === 'task') return -1;
|
|
254
|
+
const at = URGENCY.indexOf(l.kind);
|
|
255
|
+
if (at >= 0) return at;
|
|
256
|
+
return NOTES.has(l.kind) ? URGENCY.length + 1 : URGENCY.length;
|
|
257
|
+
};
|
|
258
|
+
const sorted = lines
|
|
259
|
+
.filter((l) => !l.mission)
|
|
260
|
+
.flatMap(eachOwn)
|
|
261
|
+
.map((l, i) => ({ l, i }))
|
|
262
|
+
.sort((a, b) => rank(a.l) - rank(b.l) || a.i - b.i)
|
|
263
|
+
.map(({ l }) => ({ ...l, actions: l.actions.map((a) => ({ ...a })) }));
|
|
264
|
+
let digit = 0;
|
|
265
|
+
for (const line of sorted)
|
|
266
|
+
for (const a of line.actions) a.hotkey = digit < 9 ? String(++digit) : undefined;
|
|
267
|
+
return sorted;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* UI-3: a line the band counts as several (two approvals, three held calls, two questions) is one
|
|
271
|
+
* line each, so each is chosen, answered and counted on its own.
|
|
272
|
+
*/
|
|
273
|
+
function eachOwn(line) {
|
|
274
|
+
if (line.kind === 'approvals' && line.asks?.length > 1)
|
|
275
|
+
return line.asks.map((ask) => ({
|
|
276
|
+
...line,
|
|
277
|
+
text: `Approve ${askWords(ask.request, ask.files)}`,
|
|
278
|
+
request: ask.request,
|
|
279
|
+
files: ask.files,
|
|
280
|
+
asks: [ask],
|
|
281
|
+
}));
|
|
282
|
+
if (line.kind === 'held' && line.calls?.length > 1)
|
|
283
|
+
return line.calls.map((c) => ({ ...line, text: c.text, held: c.held, calls: [c] }));
|
|
284
|
+
if (line.kind === 'question' && line.questions?.length > 1)
|
|
285
|
+
return line.questions.map((q) => ({
|
|
286
|
+
...line,
|
|
287
|
+
text: `The lead asks: ${q.question}`,
|
|
288
|
+
question: q,
|
|
289
|
+
questions: [q],
|
|
290
|
+
}));
|
|
291
|
+
if (line.kind === 'brief' && line.briefs?.length > 1)
|
|
292
|
+
return line.briefs.map((b) => ({
|
|
293
|
+
...line,
|
|
294
|
+
text: `An open question in your brief: ${b.question}`,
|
|
295
|
+
brief: b,
|
|
296
|
+
briefs: [b],
|
|
297
|
+
}));
|
|
298
|
+
return [line];
|
|
299
|
+
}
|
|
300
|
+
const isNote = (l) => NOTES.has(l.kind);
|
|
301
|
+
const needWord = (l) => (isNote(l) ? 'note' : (NEED_WORD[l.kind] ?? 'team'));
|
|
302
|
+
|
|
303
|
+
// --- UI-4: the lanes, each story with its trail and map -------------------------------------------
|
|
304
|
+
|
|
305
|
+
/** A story's trail in miniature: a cell per requirement it cites, coloured as in the Trail. */
|
|
306
|
+
export function trailCells(story, status) {
|
|
307
|
+
const byId = new Map((status?.requirements ?? []).map((r) => [r.id, r]));
|
|
308
|
+
return (story?.requirements ?? []).map((id) => {
|
|
309
|
+
const r = byId.get(id);
|
|
310
|
+
const cell = r ? cellOf(r) : 'todo';
|
|
311
|
+
return { id, cell, glyph: CELL[cell]?.glyph ?? '○', color: CELL[cell]?.color };
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* A story's map in miniature (UI-4): a chip per layer its changed files are in. Red while the lane has
|
|
317
|
+
* a refusal unresolved there (a layer rule, or a write it may not make), amber where a changed file's
|
|
318
|
+
* card isn't written or is out of date. `map` is `code-kit map <story> --json`; `trouble` is
|
|
319
|
+
* { refused: [{ layer, path }], owed: [path] }.
|
|
320
|
+
*/
|
|
321
|
+
export function mapChips(map, trouble = {}) {
|
|
322
|
+
const files = map?.files ?? [];
|
|
323
|
+
const refused = trouble.refused ?? [];
|
|
324
|
+
const owed = new Set(trouble.owed ?? []);
|
|
325
|
+
const layers = [...(map?.layers ?? [])];
|
|
326
|
+
for (const r of refused) if (r.layer && !layers.includes(r.layer)) layers.push(r.layer);
|
|
327
|
+
const chips = layers.map((layer) => {
|
|
328
|
+
const mine = files.filter((f) => f.layer === layer);
|
|
329
|
+
const red = refused.some((r) => r.layer === layer);
|
|
330
|
+
const amber = mine.some(
|
|
331
|
+
(f) =>
|
|
332
|
+
owed.has(f.path) ||
|
|
333
|
+
Object.values(f.adapters ?? {}).some((a) => a?.card && a.card.state !== 'current'),
|
|
334
|
+
);
|
|
335
|
+
return { layer, tone: red ? 'red' : amber ? 'amber' : null, files: mine.length };
|
|
336
|
+
});
|
|
337
|
+
// A refusal whose layer isn't known (a write to a path no layer names) is still red.
|
|
338
|
+
if (refused.some((r) => !r.layer)) chips.push({ layer: 'refused', tone: 'red', files: 0 });
|
|
339
|
+
return chips;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Where each lane stands: the lanes at work (the lead's first), and the rest, resting. A lane named in
|
|
344
|
+
* `notes` (the loop's note on it: nudged, stalled, a call Claude Code refused; or a move it's playing)
|
|
345
|
+
* is shown as a card, so it's seen.
|
|
346
|
+
*/
|
|
347
|
+
export function lanesAtWork(state, queue = [], notes = {}) {
|
|
348
|
+
const atWork = [];
|
|
349
|
+
const resting = [];
|
|
350
|
+
for (const l of state?.lanes ?? []) {
|
|
351
|
+
const s = shownState(l, queue);
|
|
352
|
+
if (l.active || !['idle', 'blocked'].includes(s) || notes[l.name]) atWork.push(l);
|
|
353
|
+
else resting.push(l);
|
|
354
|
+
}
|
|
355
|
+
return { atWork, resting };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** A lane's character pose (UI-11): the kind of work while its agent works, else its state. */
|
|
359
|
+
export function poseFor(lane, { live = null, waiting = false, stalled = false, queue = [] } = {}) {
|
|
360
|
+
if (stalled || live?.level === 'stalled') return 'stalled';
|
|
361
|
+
if (waiting || shownState(lane, queue) === 'waiting on you') return 'waiting';
|
|
362
|
+
if (live?.level === 'quiet') return 'quiet';
|
|
363
|
+
if (lane.active) return workOf(live?.tool ? String(live.tool).split(' ')[0] : null);
|
|
364
|
+
return 'resting';
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// --- UI-10: the layouts ------------------------------------------------------------------------------
|
|
368
|
+
|
|
369
|
+
/** The layout for the space the pane has: inline above the prompt, docked, or wide. */
|
|
370
|
+
export const layoutOf = (placement, columns) =>
|
|
371
|
+
placement === 'inline' ? 'inline' : columns >= 110 ? 'wide' : 'docked';
|
|
372
|
+
|
|
373
|
+
/** The rows a lane card takes: a character's six, and its border. */
|
|
374
|
+
export const CARD_ROWS = 8;
|
|
375
|
+
/** The columns a lane card takes where cards sit side by side: its character, its words, its frame. */
|
|
376
|
+
export const CARD_COLUMNS = 44;
|
|
377
|
+
/** The fewest columns a card is drawn in. */
|
|
378
|
+
export const CARD_MIN = 40;
|
|
379
|
+
|
|
380
|
+
/** Whether the lanes are drawn as cards, or as swimlanes on the time axis (UI-4). */
|
|
381
|
+
export function lanesAs(cards, { columns, rows }) {
|
|
382
|
+
if (!cards) return 'cards';
|
|
383
|
+
// A card needs its character and a line of words beside it; narrower, a line each.
|
|
384
|
+
if (columns < CARD_MIN) return 'swimlanes';
|
|
385
|
+
const across = Math.max(1, Math.floor(columns / CARD_COLUMNS));
|
|
386
|
+
return Math.ceil(cards / across) * CARD_ROWS <= rows ? 'cards' : 'swimlanes';
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// --- UI-5: the log -----------------------------------------------------------------------------------
|
|
390
|
+
|
|
391
|
+
const LOG_GLYPH = {
|
|
392
|
+
request: '✦',
|
|
393
|
+
decision: '◆',
|
|
394
|
+
spec: '▤',
|
|
395
|
+
setup: '⚙',
|
|
396
|
+
dispatch: '→',
|
|
397
|
+
sentBack: '↩',
|
|
398
|
+
merge: '✓',
|
|
399
|
+
approval: '✔',
|
|
400
|
+
milestone: '★',
|
|
401
|
+
loop: '·',
|
|
402
|
+
};
|
|
403
|
+
const LOG_STATE = { dispatch: 'dispatched', sentBack: 'sent back', merge: 'merged' };
|
|
404
|
+
|
|
405
|
+
/** The time of day, as the Log shows it: 14:02. */
|
|
406
|
+
const clockOf = (at) => new Date(at).toISOString().slice(11, 16);
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* UI-5: the build's latest events, newest last, one line each: { at, time, glyph, color, text, yours }.
|
|
410
|
+
* A story's dispatch, send-back and merge read "ST-4 merged · web"; the rest keep their own words.
|
|
411
|
+
*/
|
|
412
|
+
export function logLines(events = [], stories = [], most = 5) {
|
|
413
|
+
const laneOf = new Map(stories.map((s) => [s.id, s.lane]));
|
|
414
|
+
return events.slice(-most).map((e) => {
|
|
415
|
+
const yours = e.who === 'person' || e.kind === 'request';
|
|
416
|
+
const state = LOG_STATE[e.kind];
|
|
417
|
+
const lane = e.story ? laneOf.get(e.story) : null;
|
|
418
|
+
const text =
|
|
419
|
+
state && e.story
|
|
420
|
+
? `${e.story} ${wordOf(state)}${lane ? ` · ${lane}` : ''}`
|
|
421
|
+
: String(e.text ?? '').replace(/\.$/, '');
|
|
422
|
+
return {
|
|
423
|
+
at: e.at,
|
|
424
|
+
time: clockOf(e.at),
|
|
425
|
+
glyph: LOG_GLYPH[e.kind] ?? '·',
|
|
426
|
+
color: yours ? 'yellow' : state ? STATE[state]?.color : undefined,
|
|
427
|
+
text,
|
|
428
|
+
yours,
|
|
429
|
+
};
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// --- UI-8: the keys -----------------------------------------------------------------------------------
|
|
434
|
+
|
|
435
|
+
/** The letters a story's acts are pressed with, shown on their buttons (UI-8). */
|
|
436
|
+
export const ACT_KEY = {
|
|
437
|
+
approve: 'a',
|
|
438
|
+
review: 'r',
|
|
439
|
+
sendBack: 's',
|
|
440
|
+
merge: 'm',
|
|
441
|
+
watch: 'w',
|
|
442
|
+
nudge: 'n',
|
|
443
|
+
stop: 'x',
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/** UI-6: whether the person's Escape goes back from a full view to the panels, rather than closing. */
|
|
447
|
+
export const escapeGoesBack = (e, paneId, ui) =>
|
|
448
|
+
e.id === paneId && e.origin?.kind === 'person' && Boolean(ui?.view);
|
|
449
|
+
|
|
450
|
+
/** The selection's order: what needs the person, then the lanes at work, then the resting ones. */
|
|
451
|
+
export function selectable(needs, lanes) {
|
|
452
|
+
return [
|
|
453
|
+
...needs.map((_, i) => ({ kind: 'need', id: String(i) })),
|
|
454
|
+
...lanes.map((l) => ({ kind: 'lane', id: l.name })),
|
|
455
|
+
];
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** The selection `step` places on from `sel` (j and k), wrapping. */
|
|
459
|
+
export function moveSelection(order, sel, step) {
|
|
460
|
+
if (!order.length) return null;
|
|
461
|
+
const at = order.findIndex((o) => o.kind === sel?.kind && o.id === sel?.id);
|
|
462
|
+
if (at < 0) return order[step > 0 ? 0 : order.length - 1];
|
|
463
|
+
return order[(at + step + order.length) % order.length];
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* UI-8: the keys that work for what's selected, as the pane's last line lists them:
|
|
468
|
+
* [{ key, label }]. A story's own acts, then the pane's.
|
|
469
|
+
*/
|
|
470
|
+
export function keysFor(sel, { acts = [], view = null, loop = null, story = false } = {}) {
|
|
471
|
+
if (view)
|
|
472
|
+
return [
|
|
473
|
+
...(view === 'trail' ? [{ key: '←→', label: 'requirement' }] : []),
|
|
474
|
+
{ key: 'esc', label: 'back' },
|
|
475
|
+
];
|
|
476
|
+
const keys = [{ key: 'j/k', label: 'move' }];
|
|
477
|
+
if (sel) keys.push({ key: '⏎', label: 'open' });
|
|
478
|
+
if (sel?.kind === 'lane' && story) {
|
|
479
|
+
keys.push({ key: 't', label: 'trail' }, { key: 'c', label: 'map' });
|
|
480
|
+
for (const a of acts) if (ACT_KEY[a.id]) keys.push({ key: ACT_KEY[a.id], label: a.label });
|
|
481
|
+
}
|
|
482
|
+
if (loop && !['off', 'done', 'stopped', 'elsewhere', 'unled'].includes(loop.state))
|
|
483
|
+
keys.push({ key: 'p', label: loop.state === 'paused' ? 'resume' : 'pause' });
|
|
484
|
+
keys.push({ key: 'f', label: 'filter' }, { key: 'l', label: 'journal' });
|
|
485
|
+
keys.push({ key: 'esc', label: 'close' });
|
|
486
|
+
return keys;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// --- drawing ------------------------------------------------------------------------------------------
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The pane (UI-1 to UI-13). `view` holds what to draw: { state, status, loop (with its queue), needs
|
|
493
|
+
* (needsOf's), live, art: { surface, motion, poses, moves, faulted }, maps, trouble, journal, now,
|
|
494
|
+
* placement, columns, rows, ui, held, requests, leadBusy }, and the full views' own data. `on` acts.
|
|
495
|
+
*/
|
|
496
|
+
export function board(view, els, on) {
|
|
497
|
+
const { Box, Text, Button } = els;
|
|
498
|
+
const text = (value, style = {}) => Text({ ...style, children: [String(value)] });
|
|
499
|
+
const { state } = view;
|
|
500
|
+
if (!state || state.kind === 'none') return text(NOT_CODE_KIT, { dimColor: true });
|
|
501
|
+
if (state.kind === 'invalid')
|
|
502
|
+
return text('The config is invalid: run code-kit check.', { color: 'red' });
|
|
503
|
+
const ui = view.ui ?? {};
|
|
504
|
+
const columns = Math.max(20, view.columns ?? 80);
|
|
505
|
+
const layout = layoutOf(view.placement, columns);
|
|
506
|
+
const loop = view.loop ?? null;
|
|
507
|
+
const queue = loop?.queue ?? [];
|
|
508
|
+
const needs = view.needs ?? [];
|
|
509
|
+
const decisions = needs.filter((l) => !isNote(l));
|
|
510
|
+
// A lane playing a move (a cheer at its merge) keeps its card while it plays.
|
|
511
|
+
const { atWork, resting } = lanesAtWork(state, queue, {
|
|
512
|
+
...(loop?.laneNotes ?? {}),
|
|
513
|
+
...(view.art?.moves ?? {}),
|
|
514
|
+
});
|
|
515
|
+
const needle = (ui.search ?? '').trim().toLowerCase();
|
|
516
|
+
const matches = (l) =>
|
|
517
|
+
!needle ||
|
|
518
|
+
[l.name, l.agent, l.story?.id, l.story?.title, l.branch]
|
|
519
|
+
.filter(Boolean)
|
|
520
|
+
.some((s) => s.toLowerCase().includes(needle));
|
|
521
|
+
const progress = buildProgress(state, view.status);
|
|
522
|
+
const looks = charactersOf(state.lanes.map((l) => l.name));
|
|
523
|
+
const motion = view.art?.motion ?? 'while-active';
|
|
524
|
+
const surface = view.art?.surface ?? 'terminal';
|
|
525
|
+
const sel = ui.sel ?? null;
|
|
526
|
+
const selectedLane = sel?.kind === 'lane' ? state.lanes.find((l) => l.name === sel.id) : null;
|
|
527
|
+
|
|
528
|
+
// A status line (UI-1): the panel's name, its state in a word or two, a count at the right.
|
|
529
|
+
const statusLine = (key, name, word, count, color) =>
|
|
530
|
+
Box({
|
|
531
|
+
key: `status-${key}`,
|
|
532
|
+
flexDirection: 'row',
|
|
533
|
+
columnGap: 1,
|
|
534
|
+
children: [
|
|
535
|
+
text(name, { bold: true }),
|
|
536
|
+
text('·', { dimColor: true }),
|
|
537
|
+
Box({
|
|
538
|
+
flexGrow: 1,
|
|
539
|
+
flexShrink: 1,
|
|
540
|
+
children: [text(word, { wrap: 'truncate-end', ...(color ? { color } : {}) })],
|
|
541
|
+
}),
|
|
542
|
+
...(count !== null && count !== undefined ? [text(count, { dimColor: true })] : []),
|
|
543
|
+
],
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// --- the character, on each surface (UI-11, UI-12) ---
|
|
547
|
+
const still = (name, pose) => {
|
|
548
|
+
const grid = characterFrame(pose, 0, looks[name], { motion: 'off' });
|
|
549
|
+
if (surface === 'terminal' && els.Raster)
|
|
550
|
+
return els.Raster({ key: `char-${name}`, columns: 12, rows: 6, cells: rasterCells(grid) });
|
|
551
|
+
if (els.Svg)
|
|
552
|
+
return els.Svg({
|
|
553
|
+
key: `char-${name}`,
|
|
554
|
+
source: characterSvg(pose, looks[name], { motion: 'off' }),
|
|
555
|
+
alt: `${name}: ${POSES[pose]?.words ?? pose}`,
|
|
556
|
+
width: 36,
|
|
557
|
+
height: 36,
|
|
558
|
+
});
|
|
559
|
+
return text(POSES[pose]?.glyph ?? '·');
|
|
560
|
+
};
|
|
561
|
+
const character = (name, pose) => {
|
|
562
|
+
const move = view.art?.moves?.[name] ?? null;
|
|
563
|
+
const faulted = view.art?.faulted?.[surface];
|
|
564
|
+
if (surface === 'terminal' && els.Client && !faulted)
|
|
565
|
+
return els.Client({
|
|
566
|
+
key: `char-${name}`,
|
|
567
|
+
module: './surface/character.mjs',
|
|
568
|
+
props: { look: looks[name], pose, move, motion },
|
|
569
|
+
width: 12,
|
|
570
|
+
height: 6,
|
|
571
|
+
});
|
|
572
|
+
if (surface === 'desktop' && els.Svg && motion !== 'off' && !faulted)
|
|
573
|
+
return els.Svg({
|
|
574
|
+
key: `char-${name}-${move?.key ?? pose}`,
|
|
575
|
+
source: characterSvg(move ? move.kind : pose, looks[name]),
|
|
576
|
+
alt: `${name}: ${POSES[move?.kind ?? pose]?.words ?? pose}`,
|
|
577
|
+
width: 36,
|
|
578
|
+
height: 36,
|
|
579
|
+
});
|
|
580
|
+
return still(name, pose);
|
|
581
|
+
};
|
|
582
|
+
const clock = (name, live, running) => {
|
|
583
|
+
if (!live) return [];
|
|
584
|
+
const ms = Math.max(0, (view.now ?? 0) - (live.at ?? view.now ?? 0));
|
|
585
|
+
const color = live.level === 'stalled' ? 'red' : live.level === 'quiet' ? 'yellow' : null;
|
|
586
|
+
if (['terminal', 'desktop'].includes(surface) && els.Client && !view.art?.faulted?.[surface])
|
|
587
|
+
return [
|
|
588
|
+
els.Client({
|
|
589
|
+
key: `clock-${name}`,
|
|
590
|
+
module: './surface/clock.mjs',
|
|
591
|
+
props: { ms, running, motion, color },
|
|
592
|
+
}),
|
|
593
|
+
];
|
|
594
|
+
return [text(live.ago, color ? { color } : { dimColor: true })];
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// --- Build (UI-2) ---
|
|
598
|
+
const barWidth = Math.max(8, Math.min(40, columns - 30));
|
|
599
|
+
const fresh = new Set(view.art?.fresh ?? []);
|
|
600
|
+
const bar = (width = barWidth) =>
|
|
601
|
+
Box({
|
|
602
|
+
key: 'build-bar',
|
|
603
|
+
flexDirection: 'row',
|
|
604
|
+
flexShrink: 0,
|
|
605
|
+
children: buildBar(progress, width).map((r, i) =>
|
|
606
|
+
text(r.glyph.repeat(r.n), {
|
|
607
|
+
key: `bar-${i}`,
|
|
608
|
+
...(r.color ? { color: r.color } : { dimColor: true }),
|
|
609
|
+
...(r.kind === 'tested' && progress.ids.tested.some((id) => fresh.has(id))
|
|
610
|
+
? { bold: true, inverse: true }
|
|
611
|
+
: {}),
|
|
612
|
+
}),
|
|
613
|
+
),
|
|
614
|
+
});
|
|
615
|
+
const counts = () =>
|
|
616
|
+
PROGRESS.filter((p) => progress?.[p.id])
|
|
617
|
+
.map((p) => `${CELL[p.cell].glyph} ${progress[p.id]} ${p.word}`)
|
|
618
|
+
.join(' ');
|
|
619
|
+
const atWorkCount = atWork.filter((l) => l.active && l.name !== LEAD).length;
|
|
620
|
+
const loopWord = buildState(loop, { atWork: atWorkCount, leadBusy: view.leadBusy });
|
|
621
|
+
const pauseButton =
|
|
622
|
+
loop && ['running', 'paused'].includes(loop.state)
|
|
623
|
+
? [
|
|
624
|
+
Button({
|
|
625
|
+
key: 'loop-toggle',
|
|
626
|
+
label: loop.state === 'paused' ? 'Resume' : 'Pause',
|
|
627
|
+
hotkey: 'p',
|
|
628
|
+
plain: true,
|
|
629
|
+
onPress: () => on.onNeed(loop.state === 'paused' ? 'resume' : 'pause', null),
|
|
630
|
+
}),
|
|
631
|
+
]
|
|
632
|
+
: [];
|
|
633
|
+
const buildPanel = Box({
|
|
634
|
+
key: 'panel-build',
|
|
635
|
+
flexDirection: 'column',
|
|
636
|
+
children: [
|
|
637
|
+
statusLine(
|
|
638
|
+
'build',
|
|
639
|
+
'Build',
|
|
640
|
+
loopWord,
|
|
641
|
+
progress ? `${progress.tested}/${progress.total}` : null,
|
|
642
|
+
loopWord === 'moving' ? 'green' : loopWord === 'paused' ? 'yellow' : undefined,
|
|
643
|
+
),
|
|
644
|
+
...(progress
|
|
645
|
+
? [
|
|
646
|
+
text(buildWords(progress), { wrap: 'truncate-end' }),
|
|
647
|
+
Box({
|
|
648
|
+
key: 'build-progress',
|
|
649
|
+
flexDirection: 'row',
|
|
650
|
+
columnGap: 2,
|
|
651
|
+
children: [
|
|
652
|
+
bar(),
|
|
653
|
+
Box({
|
|
654
|
+
flexShrink: 1,
|
|
655
|
+
children: [text(counts(), { dimColor: true, wrap: 'truncate-end' })],
|
|
656
|
+
}),
|
|
657
|
+
],
|
|
658
|
+
}),
|
|
659
|
+
]
|
|
660
|
+
: [text('No requirements in the specs yet.', { dimColor: true })]),
|
|
661
|
+
...(state.planGaps
|
|
662
|
+
? [
|
|
663
|
+
text(`The plan has ${state.planGaps} gap(s): run code-kit status.`, {
|
|
664
|
+
color: 'yellow',
|
|
665
|
+
wrap: 'truncate-end',
|
|
666
|
+
}),
|
|
667
|
+
]
|
|
668
|
+
: []),
|
|
669
|
+
Box({
|
|
670
|
+
key: 'build-loop',
|
|
671
|
+
flexDirection: 'row',
|
|
672
|
+
columnGap: 1,
|
|
673
|
+
children: [
|
|
674
|
+
text(
|
|
675
|
+
loop?.state === 'off' ? 'loop off' : loop?.state === 'paused' ? 'loop paused' : 'loop',
|
|
676
|
+
{ dimColor: true },
|
|
677
|
+
),
|
|
678
|
+
Box({
|
|
679
|
+
flexGrow: 1,
|
|
680
|
+
flexShrink: 1,
|
|
681
|
+
children: [
|
|
682
|
+
text(loop?.nextText ? `next: ${loop.nextText}` : 'nothing next', {
|
|
683
|
+
wrap: 'truncate-end',
|
|
684
|
+
...(loop?.nextText ? { color: 'cyan' } : { dimColor: true }),
|
|
685
|
+
}),
|
|
686
|
+
],
|
|
687
|
+
}),
|
|
688
|
+
...pauseButton,
|
|
689
|
+
],
|
|
690
|
+
}),
|
|
691
|
+
],
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// --- Needs you (UI-3) ---
|
|
695
|
+
const openAt = Math.min(
|
|
696
|
+
Math.max(0, sel?.kind === 'need' ? Number(sel.id) : (ui.need ?? 0)),
|
|
697
|
+
Math.max(0, needs.length - 1),
|
|
698
|
+
);
|
|
699
|
+
const buttonsOf = (line) =>
|
|
700
|
+
line.actions.map((a) =>
|
|
701
|
+
Button({
|
|
702
|
+
key: `need-${a.id}`,
|
|
703
|
+
label: a.hotkey ? `${a.hotkey} ${a.label}` : a.label,
|
|
704
|
+
...(a.hotkey ? { hotkey: a.hotkey } : {}),
|
|
705
|
+
variant: isNote(line) ? undefined : 'primary',
|
|
706
|
+
onPress: () => on.onNeed(a.id, line),
|
|
707
|
+
}),
|
|
708
|
+
);
|
|
709
|
+
const needsPanel = needs.length
|
|
710
|
+
? Box({
|
|
711
|
+
key: 'panel-needs',
|
|
712
|
+
flexDirection: 'column',
|
|
713
|
+
children: [
|
|
714
|
+
statusLine(
|
|
715
|
+
'needs',
|
|
716
|
+
'Needs you',
|
|
717
|
+
decisions.length ? `${decisions.length} waiting` : 'notes only',
|
|
718
|
+
needs.length,
|
|
719
|
+
decisions.length ? 'yellow' : undefined,
|
|
720
|
+
),
|
|
721
|
+
...needs.map((line, i) => {
|
|
722
|
+
const chosen = sel?.kind === 'need' && Number(sel.id) === i;
|
|
723
|
+
if (i === openAt)
|
|
724
|
+
return Box({
|
|
725
|
+
key: `need-open`,
|
|
726
|
+
flexDirection: 'column',
|
|
727
|
+
borderStyle: 'round',
|
|
728
|
+
borderColor: isNote(line) ? 'gray' : 'yellow',
|
|
729
|
+
paddingX: 1,
|
|
730
|
+
children: [
|
|
731
|
+
Box({
|
|
732
|
+
flexDirection: 'row',
|
|
733
|
+
columnGap: 1,
|
|
734
|
+
children: [
|
|
735
|
+
text(needWord(line), {
|
|
736
|
+
color: isNote(line) ? undefined : 'yellow',
|
|
737
|
+
dimColor: isNote(line),
|
|
738
|
+
}),
|
|
739
|
+
Box({
|
|
740
|
+
flexShrink: 1,
|
|
741
|
+
children: [text(line.text, { bold: true, wrap: 'wrap' })],
|
|
742
|
+
}),
|
|
743
|
+
],
|
|
744
|
+
}),
|
|
745
|
+
...(line.context
|
|
746
|
+
? [text(line.context, { dimColor: true, wrap: 'truncate-end' })]
|
|
747
|
+
: []),
|
|
748
|
+
Box({
|
|
749
|
+
key: 'need-buttons',
|
|
750
|
+
flexDirection: 'row',
|
|
751
|
+
columnGap: 1,
|
|
752
|
+
flexWrap: 'wrap',
|
|
753
|
+
children: [
|
|
754
|
+
...buttonsOf(line),
|
|
755
|
+
...(isNote(line)
|
|
756
|
+
? []
|
|
757
|
+
: [
|
|
758
|
+
Button({
|
|
759
|
+
key: 'need-why',
|
|
760
|
+
label: 'Why…',
|
|
761
|
+
plain: true,
|
|
762
|
+
...(chosen ? { autoFocus: true } : {}),
|
|
763
|
+
onPress: () => on.onDecide(i, line),
|
|
764
|
+
}),
|
|
765
|
+
]),
|
|
766
|
+
],
|
|
767
|
+
}),
|
|
768
|
+
],
|
|
769
|
+
});
|
|
770
|
+
// One line each: what it is (pressed to open it in its place), then its words, cut to fit.
|
|
771
|
+
return Box({
|
|
772
|
+
key: `need-row-${i}`,
|
|
773
|
+
flexDirection: 'row',
|
|
774
|
+
columnGap: 1,
|
|
775
|
+
children: [
|
|
776
|
+
Button({
|
|
777
|
+
key: `need-line-${i}`,
|
|
778
|
+
label: `${chosen ? '›' : ' '} ${needWord(line)}`,
|
|
779
|
+
plain: true,
|
|
780
|
+
...(isNote(line) ? { dimColor: true } : {}),
|
|
781
|
+
onPress: () => on.onSelect({ kind: 'need', id: String(i) }),
|
|
782
|
+
}),
|
|
783
|
+
Box({
|
|
784
|
+
flexShrink: 1,
|
|
785
|
+
children: [
|
|
786
|
+
text(line.text, {
|
|
787
|
+
wrap: 'truncate-end',
|
|
788
|
+
...(isNote(line) ? { dimColor: true } : {}),
|
|
789
|
+
}),
|
|
790
|
+
],
|
|
791
|
+
}),
|
|
792
|
+
],
|
|
793
|
+
});
|
|
794
|
+
}),
|
|
795
|
+
],
|
|
796
|
+
})
|
|
797
|
+
: null;
|
|
798
|
+
|
|
799
|
+
// --- Queue and Log's rows, counted before the Lanes (UI-5) ---
|
|
800
|
+
const open = queue.filter((e) => ['waiting', 'merging'].includes(e.state));
|
|
801
|
+
const settled = queue
|
|
802
|
+
.filter((e) => !['waiting', 'merging'].includes(e.state))
|
|
803
|
+
.slice(-2)
|
|
804
|
+
.reverse();
|
|
805
|
+
const log = logLines(view.journal ?? [], state.stories ?? [], layout === 'wide' ? 8 : 5);
|
|
806
|
+
|
|
807
|
+
// --- Lanes (UI-4) ---
|
|
808
|
+
const asking = new Set([
|
|
809
|
+
...(view.held ?? []).map((c) => c.lane ?? LEAD),
|
|
810
|
+
...(view.requests ?? []).map((r) => r.lane ?? LEAD),
|
|
811
|
+
]);
|
|
812
|
+
const stalledLanes = new Set((loop?.flagged ?? []).map((f) => f.lane));
|
|
813
|
+
const poseOfLane = (l) =>
|
|
814
|
+
view.art?.poses?.[l.name] ??
|
|
815
|
+
poseFor(l, {
|
|
816
|
+
live: view.live?.[l.name],
|
|
817
|
+
waiting: asking.has(l.name),
|
|
818
|
+
stalled: stalledLanes.has(l.name),
|
|
819
|
+
queue,
|
|
820
|
+
});
|
|
821
|
+
const storyOf = (l) => l.story ?? storyToOpen(l, state);
|
|
822
|
+
// A cell per requirement, as many as there's room for, then how many more.
|
|
823
|
+
const cells = (story, room) => {
|
|
824
|
+
const all = trailCells(story, view.status);
|
|
825
|
+
const shown = all.length > room ? all.slice(0, Math.max(1, room - 3)) : all;
|
|
826
|
+
return [
|
|
827
|
+
...shown.map((c, i) =>
|
|
828
|
+
text(c.glyph, { key: `cell-${i}`, ...(c.color ? { color: c.color } : { dimColor: true }) }),
|
|
829
|
+
),
|
|
830
|
+
...(shown.length < all.length
|
|
831
|
+
? [text(`+${all.length - shown.length}`, { dimColor: true })]
|
|
832
|
+
: []),
|
|
833
|
+
];
|
|
834
|
+
};
|
|
835
|
+
const cardRoom = Math.max(4, (layout === 'docked' ? columns : CARD_COLUMNS) - 19);
|
|
836
|
+
const chips = (l, story) =>
|
|
837
|
+
mapChips(view.maps?.[story?.id], view.trouble?.[l.name]).map((c, i) =>
|
|
838
|
+
text(c.layer, {
|
|
839
|
+
key: `chip-${i}`,
|
|
840
|
+
...(c.tone === 'red'
|
|
841
|
+
? { color: 'red', bold: true }
|
|
842
|
+
: c.tone === 'amber'
|
|
843
|
+
? { color: 'yellow' }
|
|
844
|
+
: { dimColor: true }),
|
|
845
|
+
}),
|
|
846
|
+
);
|
|
847
|
+
// What else a card says beside its state: the branch, its background review (REVW-1), the loop's
|
|
848
|
+
// note on the lane (nudged, restarted, stalled, refused by Claude Code; OWN-2) and another tool's
|
|
849
|
+
// facts above zero (JOIN-2).
|
|
850
|
+
const reviewWords = (r) =>
|
|
851
|
+
r.state === 'running'
|
|
852
|
+
? `review running ${ago((view.now ?? 0) - r.startedAt).replace(' ago', '')}`
|
|
853
|
+
: r.state === 'done'
|
|
854
|
+
? `review done · ${r.summary}`
|
|
855
|
+
: r.state === 'skipped'
|
|
856
|
+
? `review skipped: ${r.why}`
|
|
857
|
+
: `review failed: ${r.error}`;
|
|
858
|
+
const notesOf = (l) => {
|
|
859
|
+
const notes = [];
|
|
860
|
+
const review = l.branch ? (loop?.reviews ?? []).find((r) => r.branch === l.branch) : null;
|
|
861
|
+
if (review)
|
|
862
|
+
notes.push({
|
|
863
|
+
text: reviewWords(review),
|
|
864
|
+
color: review.blockers ? 'red' : review.state === 'running' ? 'blue' : undefined,
|
|
865
|
+
});
|
|
866
|
+
const note = loop?.laneNotes?.[l.name];
|
|
867
|
+
if (note) notes.push({ text: note, color: note === 'stalled' ? 'red' : 'yellow' });
|
|
868
|
+
const facts = view.combined?.[l.name];
|
|
869
|
+
if (facts?.without)
|
|
870
|
+
notes.push({ text: `${facts.without} edited without understanding`, color: 'red' });
|
|
871
|
+
if (facts?.owed)
|
|
872
|
+
notes.push({
|
|
873
|
+
text: `${facts.owed} card${facts.owed === 1 ? '' : 's'} owed`,
|
|
874
|
+
color: 'yellow',
|
|
875
|
+
});
|
|
876
|
+
if (!notes.length && (l.branch || l.agent))
|
|
877
|
+
notes.push({ text: [l.branch, l.agent].filter(Boolean).join(' · ') });
|
|
878
|
+
return notes;
|
|
879
|
+
};
|
|
880
|
+
const actsOf = (l) =>
|
|
881
|
+
laneActions(l, { queue, held: view.held ?? [], requests: view.requests ?? [] });
|
|
882
|
+
const card = (l) => {
|
|
883
|
+
const s = shownState(l, queue);
|
|
884
|
+
const chosen = selectedLane?.name === l.name;
|
|
885
|
+
// A lane at work on no story shows none; a selected resting lane shows the story Enter opens.
|
|
886
|
+
const story = l.story ?? (chosen ? storyOf(l) : null);
|
|
887
|
+
const live = view.live?.[l.name];
|
|
888
|
+
const acts = chosen ? actsOf(l) : [];
|
|
889
|
+
const storyText = story
|
|
890
|
+
? `${story.id} ${story.title ?? ''}`.trim()
|
|
891
|
+
: l.name === LEAD
|
|
892
|
+
? 'the main session'
|
|
893
|
+
: 'no story';
|
|
894
|
+
const rows = [
|
|
895
|
+
Box({
|
|
896
|
+
key: 'card-head',
|
|
897
|
+
flexDirection: 'row',
|
|
898
|
+
columnGap: 1,
|
|
899
|
+
children: [
|
|
900
|
+
text(l.name, { bold: true, ...(chosen ? { color: 'cyan' } : {}) }),
|
|
901
|
+
Box({
|
|
902
|
+
flexGrow: 1,
|
|
903
|
+
flexShrink: 1,
|
|
904
|
+
children: [text(storyText, { wrap: 'truncate-end', dimColor: !story })],
|
|
905
|
+
}),
|
|
906
|
+
// USE-1: the lane's tokens this session.
|
|
907
|
+
...(view.usage?.lanes?.[l.name]
|
|
908
|
+
? [text(tokens(view.usage.lanes[l.name]), { dimColor: true })]
|
|
909
|
+
: []),
|
|
910
|
+
],
|
|
911
|
+
}),
|
|
912
|
+
Box({
|
|
913
|
+
key: 'card-state',
|
|
914
|
+
flexDirection: 'row',
|
|
915
|
+
columnGap: 1,
|
|
916
|
+
children: [
|
|
917
|
+
text(`${glyphOf(s)} ${wordOf(s)}`, styleOf(s)),
|
|
918
|
+
...notesOf(l).map((n, i) =>
|
|
919
|
+
Box({
|
|
920
|
+
key: `note-${i}`,
|
|
921
|
+
flexShrink: 1,
|
|
922
|
+
children: [
|
|
923
|
+
text(n.text, {
|
|
924
|
+
wrap: 'truncate-end',
|
|
925
|
+
...(n.color ? { color: n.color } : { dimColor: true }),
|
|
926
|
+
}),
|
|
927
|
+
],
|
|
928
|
+
}),
|
|
929
|
+
),
|
|
930
|
+
],
|
|
931
|
+
}),
|
|
932
|
+
Box({
|
|
933
|
+
key: 'card-live',
|
|
934
|
+
flexDirection: 'row',
|
|
935
|
+
columnGap: 1,
|
|
936
|
+
children: live
|
|
937
|
+
? [
|
|
938
|
+
Box({
|
|
939
|
+
flexShrink: 1,
|
|
940
|
+
children: [
|
|
941
|
+
text(live.tool, {
|
|
942
|
+
wrap: 'truncate-end',
|
|
943
|
+
...(live.level === 'stalled'
|
|
944
|
+
? { color: 'red' }
|
|
945
|
+
: live.level === 'quiet'
|
|
946
|
+
? { color: 'yellow' }
|
|
947
|
+
: { dimColor: true }),
|
|
948
|
+
}),
|
|
949
|
+
],
|
|
950
|
+
}),
|
|
951
|
+
...clock(l.name, live, Boolean(l.active) && live.ago === 'now'),
|
|
952
|
+
]
|
|
953
|
+
: [text(l.active ? 'at work' : ' ', { dimColor: true })],
|
|
954
|
+
}),
|
|
955
|
+
Box({
|
|
956
|
+
key: 'card-trail',
|
|
957
|
+
flexDirection: 'row',
|
|
958
|
+
children: story ? cells(story, cardRoom) : [],
|
|
959
|
+
}),
|
|
960
|
+
Box({
|
|
961
|
+
key: 'card-map',
|
|
962
|
+
flexDirection: 'row',
|
|
963
|
+
columnGap: 1,
|
|
964
|
+
flexWrap: 'wrap',
|
|
965
|
+
children: story ? chips(l, story) : [],
|
|
966
|
+
}),
|
|
967
|
+
];
|
|
968
|
+
// VIEW-2: the selected lane's story on the shared time axis.
|
|
969
|
+
const timeline = view.art?.bars?.[l.name];
|
|
970
|
+
if (chosen && timeline)
|
|
971
|
+
rows.push(
|
|
972
|
+
surface !== 'terminal' && els.Svg
|
|
973
|
+
? els.Svg({
|
|
974
|
+
key: `bar-${l.name}`,
|
|
975
|
+
source: timelineSvg([{ cells: timeline.slice(-cardRoom) }], {
|
|
976
|
+
width: Math.min(timeline.length, cardRoom) * 6,
|
|
977
|
+
}),
|
|
978
|
+
alt: `${l.name}'s timeline`,
|
|
979
|
+
})
|
|
980
|
+
: Box({
|
|
981
|
+
key: `bar-${l.name}`,
|
|
982
|
+
flexDirection: 'row',
|
|
983
|
+
children: runs(timeline.slice(-cardRoom)).map((r, i) =>
|
|
984
|
+
text(BAR[r.kind].glyph.repeat(r.n), {
|
|
985
|
+
key: `run-${i}`,
|
|
986
|
+
...(BAR[r.kind].color ? { color: BAR[r.kind].color } : { dimColor: true }),
|
|
987
|
+
}),
|
|
988
|
+
),
|
|
989
|
+
}),
|
|
990
|
+
);
|
|
991
|
+
// LANES-3: the selected lane's stories as cards, then its agent and what it owns.
|
|
992
|
+
if (chosen)
|
|
993
|
+
rows.push(
|
|
994
|
+
...laneDetail(
|
|
995
|
+
{
|
|
996
|
+
agent: l.agent ?? null,
|
|
997
|
+
owns: view.paths?.[l.name] ?? [],
|
|
998
|
+
stories: laneStories(l, state),
|
|
999
|
+
},
|
|
1000
|
+
els,
|
|
1001
|
+
),
|
|
1002
|
+
);
|
|
1003
|
+
if (chosen)
|
|
1004
|
+
rows.push(
|
|
1005
|
+
Box({
|
|
1006
|
+
key: 'card-acts',
|
|
1007
|
+
flexDirection: 'row',
|
|
1008
|
+
columnGap: 1,
|
|
1009
|
+
flexWrap: 'wrap',
|
|
1010
|
+
children: [
|
|
1011
|
+
...(story
|
|
1012
|
+
? [
|
|
1013
|
+
Button({
|
|
1014
|
+
key: 'open-story',
|
|
1015
|
+
label: 'Open',
|
|
1016
|
+
autoFocus: true,
|
|
1017
|
+
variant: 'primary',
|
|
1018
|
+
onPress: () => on.onOpen({ ...l, story }),
|
|
1019
|
+
}),
|
|
1020
|
+
Button({
|
|
1021
|
+
key: 'open-trail',
|
|
1022
|
+
label: 'Trail t',
|
|
1023
|
+
hotkey: 't',
|
|
1024
|
+
plain: true,
|
|
1025
|
+
onPress: () => on.onView('trail', { lane: l, story }),
|
|
1026
|
+
}),
|
|
1027
|
+
Button({
|
|
1028
|
+
key: 'open-map',
|
|
1029
|
+
label: 'Map c',
|
|
1030
|
+
hotkey: 'c',
|
|
1031
|
+
plain: true,
|
|
1032
|
+
onPress: () => on.onView('code', { lane: l, story }),
|
|
1033
|
+
}),
|
|
1034
|
+
]
|
|
1035
|
+
: []),
|
|
1036
|
+
...acts.map((a) =>
|
|
1037
|
+
Button({
|
|
1038
|
+
key: `act-${a.id}`,
|
|
1039
|
+
label: `${a.label} ${ACT_KEY[a.id] ?? ''}`.trim(),
|
|
1040
|
+
...(ACT_KEY[a.id] ? { hotkey: ACT_KEY[a.id] } : {}),
|
|
1041
|
+
plain: true,
|
|
1042
|
+
onPress: () => on.onLane(a.id, l),
|
|
1043
|
+
}),
|
|
1044
|
+
),
|
|
1045
|
+
],
|
|
1046
|
+
}),
|
|
1047
|
+
);
|
|
1048
|
+
return Box({
|
|
1049
|
+
key: `card-${l.name}`,
|
|
1050
|
+
flexDirection: 'row',
|
|
1051
|
+
columnGap: 1,
|
|
1052
|
+
borderStyle: 'round',
|
|
1053
|
+
borderColor: chosen ? 'cyan' : (STATE[s]?.color ?? 'gray'),
|
|
1054
|
+
...(s === 'idle' && !chosen ? { borderDimColor: true } : {}),
|
|
1055
|
+
paddingX: 1,
|
|
1056
|
+
width: layout === 'docked' ? '100%' : CARD_COLUMNS,
|
|
1057
|
+
flexShrink: 1,
|
|
1058
|
+
children: [
|
|
1059
|
+
character(l.name, poseOfLane(l)),
|
|
1060
|
+
Box({ flexDirection: 'column', flexGrow: 1, flexShrink: 1, children: rows }),
|
|
1061
|
+
],
|
|
1062
|
+
});
|
|
1063
|
+
};
|
|
1064
|
+
const swimlane = (l) => {
|
|
1065
|
+
const s = shownState(l, queue);
|
|
1066
|
+
const chosen = selectedLane?.name === l.name;
|
|
1067
|
+
const story = l.story ?? (chosen ? storyOf(l) : null);
|
|
1068
|
+
const pose = poseOfLane(l);
|
|
1069
|
+
const barCells = view.art?.bars?.[l.name] ?? null;
|
|
1070
|
+
return Box({
|
|
1071
|
+
key: `lane-${l.name}`,
|
|
1072
|
+
flexDirection: 'row',
|
|
1073
|
+
columnGap: 1,
|
|
1074
|
+
children: [
|
|
1075
|
+
text(POSES[pose]?.glyph ?? '·', {
|
|
1076
|
+
color: `#${looks[l.name].tint.toString(16).padStart(6, '0')}`,
|
|
1077
|
+
}),
|
|
1078
|
+
text(l.name, { bold: true, ...(chosen ? { color: 'cyan' } : {}) }),
|
|
1079
|
+
text(columns >= 60 ? `${glyphOf(s)} ${wordOf(s)}` : glyphOf(s), styleOf(s)),
|
|
1080
|
+
Box({
|
|
1081
|
+
flexGrow: 1,
|
|
1082
|
+
flexShrink: 1,
|
|
1083
|
+
children: [
|
|
1084
|
+
text(story ? `${story.id} ${story.title ?? ''}` : wordOf(s), {
|
|
1085
|
+
wrap: 'truncate-end',
|
|
1086
|
+
dimColor: !story,
|
|
1087
|
+
}),
|
|
1088
|
+
],
|
|
1089
|
+
}),
|
|
1090
|
+
...(story ? cells(story, Math.max(1, Math.floor((columns - 40) / 2))) : []),
|
|
1091
|
+
// VIEW-2: the time axis, its latest part, where there's room for it.
|
|
1092
|
+
...(barCells && columns >= 90
|
|
1093
|
+
? runs(barCells.slice(-(columns - 70))).map((r, i) =>
|
|
1094
|
+
text(BAR[r.kind].glyph.repeat(r.n), {
|
|
1095
|
+
key: `run-${i}`,
|
|
1096
|
+
...(BAR[r.kind].color ? { color: BAR[r.kind].color } : { dimColor: true }),
|
|
1097
|
+
}),
|
|
1098
|
+
)
|
|
1099
|
+
: []),
|
|
1100
|
+
],
|
|
1101
|
+
});
|
|
1102
|
+
};
|
|
1103
|
+
const shownLanes = [...atWork, ...resting].filter(matches);
|
|
1104
|
+
const cardLanes = atWork
|
|
1105
|
+
.filter(matches)
|
|
1106
|
+
.concat(selectedLane && !atWork.includes(selectedLane) ? [selectedLane] : []);
|
|
1107
|
+
const restingShown = resting.filter((l) => matches(l) && l !== selectedLane);
|
|
1108
|
+
// The rows the cards have: the pane's, less what the other panels and the keys take, and the
|
|
1109
|
+
// gaps between them; in the wide layout, the Lanes column's, under Build.
|
|
1110
|
+
const buildRows = (progress ? 4 : 3) + (state.planGaps ? 1 : 0);
|
|
1111
|
+
const needsRows = needs.length ? 1 + 4 + (needs[openAt]?.context ? 1 : 0) + needs.length - 1 : 0;
|
|
1112
|
+
const queueRows = open.length ? 1 + open.length + settled.length : 0;
|
|
1113
|
+
const logRows = 1 + log.length;
|
|
1114
|
+
const panels = 3 + (needs.length ? 1 : 0) + (open.length ? 1 : 0);
|
|
1115
|
+
const others =
|
|
1116
|
+
layout === 'wide'
|
|
1117
|
+
? buildRows + 1 + 2
|
|
1118
|
+
: buildRows + needsRows + queueRows + logRows + 1 + panels;
|
|
1119
|
+
const lanesOwn =
|
|
1120
|
+
1 +
|
|
1121
|
+
(restingShown.length ? 1 : 0) +
|
|
1122
|
+
(state.ready.length ? 1 : 0) +
|
|
1123
|
+
(view.leadBusy ? 1 : 0) +
|
|
1124
|
+
(ui.filtering || needle ? 1 : 0);
|
|
1125
|
+
const lanesRoom = (view.rows ?? 40) - others - lanesOwn;
|
|
1126
|
+
const lanesColumns = layout === 'wide' ? Math.floor(columns * 0.6) : columns;
|
|
1127
|
+
const as = lanesAs(cardLanes.length, { columns: lanesColumns, rows: lanesRoom });
|
|
1128
|
+
const lead = state.lanes.find((l) => l.name === LEAD);
|
|
1129
|
+
const dispatched = atWork.filter((l) => l.name !== LEAD && l.active);
|
|
1130
|
+
const rail =
|
|
1131
|
+
view.leadBusy && dispatched.length && as === 'cards'
|
|
1132
|
+
? [
|
|
1133
|
+
Box({
|
|
1134
|
+
key: 'rail',
|
|
1135
|
+
flexDirection: 'row',
|
|
1136
|
+
columnGap: 1,
|
|
1137
|
+
children: [
|
|
1138
|
+
text('lead', { dimColor: true }),
|
|
1139
|
+
...(['terminal', 'desktop'].includes(surface) && els.Client
|
|
1140
|
+
? [
|
|
1141
|
+
els.Client({
|
|
1142
|
+
key: 'rail',
|
|
1143
|
+
module: './surface/rail.mjs',
|
|
1144
|
+
props: { width: 12, running: true, motion },
|
|
1145
|
+
}),
|
|
1146
|
+
]
|
|
1147
|
+
: [text('───────────▸', { color: 'yellow' })]),
|
|
1148
|
+
Box({
|
|
1149
|
+
flexShrink: 1,
|
|
1150
|
+
children: [
|
|
1151
|
+
text(dispatched.map((l) => l.name).join(' · '), { wrap: 'truncate-end' }),
|
|
1152
|
+
],
|
|
1153
|
+
}),
|
|
1154
|
+
],
|
|
1155
|
+
}),
|
|
1156
|
+
]
|
|
1157
|
+
: [];
|
|
1158
|
+
const lanesPanel = Box({
|
|
1159
|
+
key: 'panel-lanes',
|
|
1160
|
+
flexDirection: 'column',
|
|
1161
|
+
children: [
|
|
1162
|
+
statusLine(
|
|
1163
|
+
'lanes',
|
|
1164
|
+
'Lanes',
|
|
1165
|
+
atWork.length
|
|
1166
|
+
? `${atWork.length} at work${needle ? ` · filter "${ui.search}"` : ''}`
|
|
1167
|
+
: 'all resting',
|
|
1168
|
+
state.lanes.length,
|
|
1169
|
+
atWork.length ? 'green' : undefined,
|
|
1170
|
+
),
|
|
1171
|
+
...(ui.filtering || needle
|
|
1172
|
+
? [
|
|
1173
|
+
Box({
|
|
1174
|
+
key: 'filter-row',
|
|
1175
|
+
flexDirection: 'row',
|
|
1176
|
+
columnGap: 1,
|
|
1177
|
+
children: [
|
|
1178
|
+
text('filter', { dimColor: true }),
|
|
1179
|
+
els.Input({
|
|
1180
|
+
key: 'filter',
|
|
1181
|
+
label: '',
|
|
1182
|
+
value: ui.search ?? '',
|
|
1183
|
+
placeholder: 'lane, agent or story',
|
|
1184
|
+
submitLabel: 'Filter',
|
|
1185
|
+
onInput: (v) => on.onSearch(v),
|
|
1186
|
+
onSubmit: (v) => on.onSearch(v),
|
|
1187
|
+
}),
|
|
1188
|
+
],
|
|
1189
|
+
}),
|
|
1190
|
+
]
|
|
1191
|
+
: []),
|
|
1192
|
+
...rail,
|
|
1193
|
+
...(as === 'cards'
|
|
1194
|
+
? [
|
|
1195
|
+
Box({
|
|
1196
|
+
key: 'cards',
|
|
1197
|
+
flexDirection: layout === 'docked' ? 'column' : 'row',
|
|
1198
|
+
flexWrap: 'wrap',
|
|
1199
|
+
columnGap: 1,
|
|
1200
|
+
children: cardLanes.map(card),
|
|
1201
|
+
}),
|
|
1202
|
+
]
|
|
1203
|
+
: [
|
|
1204
|
+
Box({
|
|
1205
|
+
key: 'swimlanes',
|
|
1206
|
+
flexDirection: 'column',
|
|
1207
|
+
children: cardLanes.map(swimlane),
|
|
1208
|
+
}),
|
|
1209
|
+
]),
|
|
1210
|
+
...(restingShown.length
|
|
1211
|
+
? [
|
|
1212
|
+
Box({
|
|
1213
|
+
key: 'resting',
|
|
1214
|
+
flexDirection: 'row',
|
|
1215
|
+
columnGap: 1,
|
|
1216
|
+
children: [
|
|
1217
|
+
text('resting:', { dimColor: true }),
|
|
1218
|
+
Box({
|
|
1219
|
+
flexShrink: 1,
|
|
1220
|
+
children: [
|
|
1221
|
+
text(restingShown.map((l) => l.name).join(', '), {
|
|
1222
|
+
dimColor: true,
|
|
1223
|
+
wrap: 'truncate-end',
|
|
1224
|
+
}),
|
|
1225
|
+
],
|
|
1226
|
+
}),
|
|
1227
|
+
],
|
|
1228
|
+
}),
|
|
1229
|
+
]
|
|
1230
|
+
: []),
|
|
1231
|
+
...(!shownLanes.length ? [text('No lane matches the filter.', { dimColor: true })] : []),
|
|
1232
|
+
// PANE-3: what's ready to start, the lead's own named as such.
|
|
1233
|
+
...(state.ready.length
|
|
1234
|
+
? [
|
|
1235
|
+
text(
|
|
1236
|
+
`ready: ${state.ready.map((r) => `${r.id}${r.lane === LEAD ? " (the lead's own)" : r.lane ? ` (${r.lane})` : ''}`).join(', ')}`,
|
|
1237
|
+
{ dimColor: true, wrap: 'truncate-end' },
|
|
1238
|
+
),
|
|
1239
|
+
]
|
|
1240
|
+
: []),
|
|
1241
|
+
],
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
// --- Queue and Log (UI-5) ---
|
|
1245
|
+
const storyOfBranch = (branch) =>
|
|
1246
|
+
(state.stories ?? []).find((s) => s.branch === branch)?.id ?? '';
|
|
1247
|
+
const queuePanel = open.length
|
|
1248
|
+
? Box({
|
|
1249
|
+
key: 'panel-queue',
|
|
1250
|
+
flexDirection: 'column',
|
|
1251
|
+
children: [
|
|
1252
|
+
statusLine(
|
|
1253
|
+
'queue',
|
|
1254
|
+
'Queue',
|
|
1255
|
+
open.some((e) => e.state === 'merging') ? 'merging' : 'waiting',
|
|
1256
|
+
open.length,
|
|
1257
|
+
'cyan',
|
|
1258
|
+
),
|
|
1259
|
+
...open.map((e, i) =>
|
|
1260
|
+
Box({
|
|
1261
|
+
key: `queue-${e.branch}-${e.state}`,
|
|
1262
|
+
flexDirection: 'row',
|
|
1263
|
+
columnGap: 1,
|
|
1264
|
+
children: [
|
|
1265
|
+
text(`${i + 1}.`, { dimColor: true }),
|
|
1266
|
+
Box({ flexShrink: 1, children: [text(e.branch, { wrap: 'truncate-end' })] }),
|
|
1267
|
+
text(storyOfBranch(e.branch), { dimColor: true }),
|
|
1268
|
+
...(e.commit && columns >= 40
|
|
1269
|
+
? [text(String(e.commit).slice(0, 7), { dimColor: true })]
|
|
1270
|
+
: []),
|
|
1271
|
+
text(`${glyphOf(e.state)} ${wordOf(e.state)}`, styleOf(e.state)),
|
|
1272
|
+
],
|
|
1273
|
+
}),
|
|
1274
|
+
),
|
|
1275
|
+
// MQ-4: what it merged or sent back lately, and why.
|
|
1276
|
+
...settled.map((e) =>
|
|
1277
|
+
Box({
|
|
1278
|
+
key: `queue-${e.branch}-${e.state}`,
|
|
1279
|
+
flexDirection: 'row',
|
|
1280
|
+
columnGap: 1,
|
|
1281
|
+
children: [
|
|
1282
|
+
text('·', { dimColor: true }),
|
|
1283
|
+
Box({
|
|
1284
|
+
flexShrink: 1,
|
|
1285
|
+
children: [text(e.branch, { dimColor: true, wrap: 'truncate-end' })],
|
|
1286
|
+
}),
|
|
1287
|
+
text(`${glyphOf(e.state)} ${wordOf(e.state)}`, styleOf(e.state)),
|
|
1288
|
+
...(e.reason
|
|
1289
|
+
? [
|
|
1290
|
+
Box({
|
|
1291
|
+
flexShrink: 1,
|
|
1292
|
+
children: [text(e.reason, { dimColor: true, wrap: 'truncate-end' })],
|
|
1293
|
+
}),
|
|
1294
|
+
]
|
|
1295
|
+
: []),
|
|
1296
|
+
],
|
|
1297
|
+
}),
|
|
1298
|
+
),
|
|
1299
|
+
],
|
|
1300
|
+
})
|
|
1301
|
+
: null;
|
|
1302
|
+
const logPanel = Box({
|
|
1303
|
+
key: 'panel-log',
|
|
1304
|
+
flexDirection: 'column',
|
|
1305
|
+
children: [
|
|
1306
|
+
statusLine(
|
|
1307
|
+
'log',
|
|
1308
|
+
'Log',
|
|
1309
|
+
log.length ? ago((view.now ?? 0) - log.at(-1).at) : 'nothing yet',
|
|
1310
|
+
(view.journal ?? []).length,
|
|
1311
|
+
),
|
|
1312
|
+
...log.map((e, i) =>
|
|
1313
|
+
Box({
|
|
1314
|
+
key: `log-${i}`,
|
|
1315
|
+
flexDirection: 'row',
|
|
1316
|
+
columnGap: 1,
|
|
1317
|
+
children: [
|
|
1318
|
+
text(e.time, { dimColor: true }),
|
|
1319
|
+
text(e.glyph, e.color ? { color: e.color } : { dimColor: true }),
|
|
1320
|
+
Box({
|
|
1321
|
+
flexShrink: 1,
|
|
1322
|
+
children: [
|
|
1323
|
+
text(e.text, { wrap: 'truncate-end', ...(e.yours ? { color: 'yellow' } : {}) }),
|
|
1324
|
+
],
|
|
1325
|
+
}),
|
|
1326
|
+
],
|
|
1327
|
+
}),
|
|
1328
|
+
),
|
|
1329
|
+
],
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1332
|
+
// --- the keys, on the last line (UI-8) ---
|
|
1333
|
+
const keys = keysFor(sel, {
|
|
1334
|
+
acts: selectedLane ? actsOf(selectedLane) : [],
|
|
1335
|
+
loop,
|
|
1336
|
+
story: Boolean(selectedLane && storyOf(selectedLane)),
|
|
1337
|
+
});
|
|
1338
|
+
const keysLine = Box({
|
|
1339
|
+
key: 'keys',
|
|
1340
|
+
flexDirection: 'row',
|
|
1341
|
+
columnGap: 1,
|
|
1342
|
+
flexWrap: 'wrap',
|
|
1343
|
+
children: [
|
|
1344
|
+
Button({
|
|
1345
|
+
key: 'move-next',
|
|
1346
|
+
label: 'j',
|
|
1347
|
+
hotkey: 'j',
|
|
1348
|
+
plain: true,
|
|
1349
|
+
dimColor: true,
|
|
1350
|
+
onPress: () => on.onMove(1),
|
|
1351
|
+
}),
|
|
1352
|
+
Button({
|
|
1353
|
+
key: 'move-prev',
|
|
1354
|
+
label: 'k',
|
|
1355
|
+
hotkey: 'k',
|
|
1356
|
+
plain: true,
|
|
1357
|
+
dimColor: true,
|
|
1358
|
+
onPress: () => on.onMove(-1),
|
|
1359
|
+
}),
|
|
1360
|
+
Button({
|
|
1361
|
+
key: 'filter-focus',
|
|
1362
|
+
label: 'f',
|
|
1363
|
+
hotkey: 'f',
|
|
1364
|
+
plain: true,
|
|
1365
|
+
dimColor: true,
|
|
1366
|
+
onPress: () => on.onFocusSearch(),
|
|
1367
|
+
}),
|
|
1368
|
+
Button({
|
|
1369
|
+
key: 'open-journal',
|
|
1370
|
+
label: 'l',
|
|
1371
|
+
hotkey: 'l',
|
|
1372
|
+
plain: true,
|
|
1373
|
+
dimColor: true,
|
|
1374
|
+
onPress: () => on.onView('journal'),
|
|
1375
|
+
}),
|
|
1376
|
+
Box({
|
|
1377
|
+
flexShrink: 1,
|
|
1378
|
+
children: [
|
|
1379
|
+
text(keys.map((k) => `${k.key} ${k.label}`).join(' · '), {
|
|
1380
|
+
dimColor: true,
|
|
1381
|
+
wrap: 'truncate-end',
|
|
1382
|
+
}),
|
|
1383
|
+
],
|
|
1384
|
+
}),
|
|
1385
|
+
],
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
// --- the layouts (UI-10) ---
|
|
1389
|
+
if (layout === 'inline') {
|
|
1390
|
+
const first = needs[0];
|
|
1391
|
+
return Box({
|
|
1392
|
+
flexDirection: 'column',
|
|
1393
|
+
children: [
|
|
1394
|
+
Box({
|
|
1395
|
+
key: 'inline-build',
|
|
1396
|
+
flexDirection: 'row',
|
|
1397
|
+
columnGap: 1,
|
|
1398
|
+
children: [
|
|
1399
|
+
...(progress ? [bar(Math.max(6, Math.min(20, columns - 30)))] : []),
|
|
1400
|
+
Box({
|
|
1401
|
+
flexShrink: 1,
|
|
1402
|
+
children: [
|
|
1403
|
+
text(
|
|
1404
|
+
`${progress ? `${progress.tested}/${progress.total} tested · ` : ''}${loopWord}`,
|
|
1405
|
+
{ wrap: 'truncate-end', dimColor: true },
|
|
1406
|
+
),
|
|
1407
|
+
],
|
|
1408
|
+
}),
|
|
1409
|
+
],
|
|
1410
|
+
}),
|
|
1411
|
+
Box({
|
|
1412
|
+
key: 'inline-lanes',
|
|
1413
|
+
flexDirection: 'row',
|
|
1414
|
+
columnGap: 1,
|
|
1415
|
+
// A cell per lane coloured by its state, named where the names fit.
|
|
1416
|
+
children: state.lanes.map((l) => {
|
|
1417
|
+
const s = shownState(l, queue);
|
|
1418
|
+
const named = state.lanes.reduce((n, x) => n + x.name.length + 2, 0) <= columns;
|
|
1419
|
+
return text(named ? `${glyphOf(s)}${l.name}` : glyphOf(s), {
|
|
1420
|
+
key: `inline-${l.name}`,
|
|
1421
|
+
...styleOf(s),
|
|
1422
|
+
});
|
|
1423
|
+
}),
|
|
1424
|
+
}),
|
|
1425
|
+
...(first
|
|
1426
|
+
? [
|
|
1427
|
+
Box({
|
|
1428
|
+
key: 'inline-need',
|
|
1429
|
+
flexDirection: 'row',
|
|
1430
|
+
columnGap: 1,
|
|
1431
|
+
children: [
|
|
1432
|
+
Box({
|
|
1433
|
+
flexShrink: 1,
|
|
1434
|
+
children: [
|
|
1435
|
+
text(
|
|
1436
|
+
`${first.text}${needs.length > 1 ? ` · ${needs.length - 1} more` : ''}`,
|
|
1437
|
+
{
|
|
1438
|
+
wrap: 'truncate-end',
|
|
1439
|
+
bold: !isNote(first),
|
|
1440
|
+
},
|
|
1441
|
+
),
|
|
1442
|
+
],
|
|
1443
|
+
}),
|
|
1444
|
+
...buttonsOf(first),
|
|
1445
|
+
],
|
|
1446
|
+
}),
|
|
1447
|
+
]
|
|
1448
|
+
: []),
|
|
1449
|
+
],
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
if (layout === 'wide')
|
|
1453
|
+
return Box({
|
|
1454
|
+
flexDirection: 'column',
|
|
1455
|
+
rowGap: 1,
|
|
1456
|
+
children: [
|
|
1457
|
+
buildPanel,
|
|
1458
|
+
Box({
|
|
1459
|
+
key: 'wide',
|
|
1460
|
+
flexDirection: 'row',
|
|
1461
|
+
columnGap: 2,
|
|
1462
|
+
children: [
|
|
1463
|
+
Box({ key: 'left', flexDirection: 'column', width: '60%', children: [lanesPanel] }),
|
|
1464
|
+
Box({
|
|
1465
|
+
key: 'right',
|
|
1466
|
+
flexDirection: 'column',
|
|
1467
|
+
flexGrow: 1,
|
|
1468
|
+
flexShrink: 1,
|
|
1469
|
+
rowGap: 1,
|
|
1470
|
+
children: [needsPanel, queuePanel, logPanel].filter(Boolean),
|
|
1471
|
+
}),
|
|
1472
|
+
],
|
|
1473
|
+
}),
|
|
1474
|
+
keysLine,
|
|
1475
|
+
],
|
|
1476
|
+
});
|
|
1477
|
+
return Box({
|
|
1478
|
+
flexDirection: 'column',
|
|
1479
|
+
rowGap: 1,
|
|
1480
|
+
children: [buildPanel, needsPanel, lanesPanel, queuePanel, logPanel, keysLine].filter(Boolean),
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
/**
|
|
1485
|
+
* UI-9: the band above the prompt, at most three lines: the most urgent item with its buttons and how
|
|
1486
|
+
* many more wait; while the build moves and nothing needs the person, one line (the milestone's bar,
|
|
1487
|
+
* the loop and the agents at work); with nothing happening and nothing waiting, nothing (null).
|
|
1488
|
+
*/
|
|
1489
|
+
export function bandOf(view, els, onAction) {
|
|
1490
|
+
const { Box, Text, Button } = els;
|
|
1491
|
+
const text = (value, style = {}) => Text({ ...style, children: [String(value)] });
|
|
1492
|
+
// A working session's own task heads its band (SESS-4); it isn't a decision.
|
|
1493
|
+
const task = (view.needs ?? []).find((l) => l.kind === 'task') ?? null;
|
|
1494
|
+
const needs = (view.needs ?? []).filter((l) => l.kind !== 'task');
|
|
1495
|
+
const decisions = needs.filter((l) => !isNote(l));
|
|
1496
|
+
const columns = Math.max(20, view.columns ?? 80);
|
|
1497
|
+
const taskLine = task
|
|
1498
|
+
? [
|
|
1499
|
+
Box({
|
|
1500
|
+
key: 'band-task',
|
|
1501
|
+
flexDirection: 'row',
|
|
1502
|
+
columnGap: 1,
|
|
1503
|
+
children: [
|
|
1504
|
+
text('task', { dimColor: true }),
|
|
1505
|
+
Box({ flexShrink: 1, children: [text(task.text, { wrap: 'truncate-end' })] }),
|
|
1506
|
+
],
|
|
1507
|
+
}),
|
|
1508
|
+
]
|
|
1509
|
+
: [];
|
|
1510
|
+
if (needs.length) {
|
|
1511
|
+
const [first] = decisions.length ? decisions : needs;
|
|
1512
|
+
const more = (decisions.length ? decisions.length : needs.length) - 1;
|
|
1513
|
+
// At most three lines: the task, the most urgent item, and its buttons with how many more wait.
|
|
1514
|
+
return Box({
|
|
1515
|
+
flexDirection: 'column',
|
|
1516
|
+
children: [
|
|
1517
|
+
...taskLine,
|
|
1518
|
+
Box({
|
|
1519
|
+
key: 'band-first',
|
|
1520
|
+
flexDirection: 'row',
|
|
1521
|
+
columnGap: 1,
|
|
1522
|
+
children: [
|
|
1523
|
+
text(needWord(first), { color: isNote(first) ? undefined : 'yellow' }),
|
|
1524
|
+
Box({
|
|
1525
|
+
flexShrink: 1,
|
|
1526
|
+
children: [text(first.text, { wrap: 'truncate-end', bold: true })],
|
|
1527
|
+
}),
|
|
1528
|
+
...(first.context
|
|
1529
|
+
? [
|
|
1530
|
+
Box({
|
|
1531
|
+
flexShrink: 2,
|
|
1532
|
+
children: [text(first.context, { dimColor: true, wrap: 'truncate-end' })],
|
|
1533
|
+
}),
|
|
1534
|
+
]
|
|
1535
|
+
: []),
|
|
1536
|
+
],
|
|
1537
|
+
}),
|
|
1538
|
+
Box({
|
|
1539
|
+
key: 'band-more',
|
|
1540
|
+
flexDirection: 'row',
|
|
1541
|
+
columnGap: 1,
|
|
1542
|
+
// Narrow, the buttons wrap rather than spill.
|
|
1543
|
+
...(columns < 60 ? { flexWrap: 'wrap' } : {}),
|
|
1544
|
+
children: [
|
|
1545
|
+
...first.actions.map((a) =>
|
|
1546
|
+
Button({
|
|
1547
|
+
key: `band-${a.id}`,
|
|
1548
|
+
label: a.hotkey ? `${a.hotkey} ${a.label}` : a.label,
|
|
1549
|
+
...(a.hotkey ? { hotkey: a.hotkey } : {}),
|
|
1550
|
+
onPress: () => onAction(a.id, first),
|
|
1551
|
+
}),
|
|
1552
|
+
),
|
|
1553
|
+
...(isNote(first)
|
|
1554
|
+
? []
|
|
1555
|
+
: [
|
|
1556
|
+
Button({
|
|
1557
|
+
key: 'band-decide',
|
|
1558
|
+
label: columns < 60 ? 'Why…' : 'Why, and what each choice does',
|
|
1559
|
+
hotkey: 'd',
|
|
1560
|
+
plain: true,
|
|
1561
|
+
onPress: () => onAction('decide', first),
|
|
1562
|
+
}),
|
|
1563
|
+
]),
|
|
1564
|
+
...(more > 0
|
|
1565
|
+
? [
|
|
1566
|
+
Box({
|
|
1567
|
+
flexShrink: 1,
|
|
1568
|
+
children: [
|
|
1569
|
+
text(`${more} more waiting · /lanes`, {
|
|
1570
|
+
dimColor: true,
|
|
1571
|
+
wrap: 'truncate-end',
|
|
1572
|
+
}),
|
|
1573
|
+
],
|
|
1574
|
+
}),
|
|
1575
|
+
]
|
|
1576
|
+
: []),
|
|
1577
|
+
],
|
|
1578
|
+
}),
|
|
1579
|
+
],
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
if (task) return Box({ flexDirection: 'column', children: taskLine });
|
|
1583
|
+
const state = view.state;
|
|
1584
|
+
if (state?.kind !== 'ok') return null;
|
|
1585
|
+
const queue = view.loop?.queue ?? [];
|
|
1586
|
+
const working = state.lanes.filter((l) => l.active && l.name !== LEAD).length;
|
|
1587
|
+
const progress = buildProgress(state, view.status);
|
|
1588
|
+
const word = buildState(view.loop, { atWork: working, leadBusy: view.leadBusy });
|
|
1589
|
+
// A paused loop is said too, with Resume: the build won't move until the person says.
|
|
1590
|
+
if (word !== 'moving' && word !== 'paused') return null;
|
|
1591
|
+
const toggle = ['running', 'paused'].includes(view.loop?.state)
|
|
1592
|
+
? view.loop.state === 'paused'
|
|
1593
|
+
? { id: 'resume', label: 'Resume' }
|
|
1594
|
+
: { id: 'pause', label: 'Pause' }
|
|
1595
|
+
: null;
|
|
1596
|
+
const width = Math.max(6, Math.min(24, columns - 50));
|
|
1597
|
+
const runs = buildBar(progress, width);
|
|
1598
|
+
return Box({
|
|
1599
|
+
key: 'band-line',
|
|
1600
|
+
flexDirection: 'row',
|
|
1601
|
+
columnGap: 1,
|
|
1602
|
+
children: [
|
|
1603
|
+
...(progress?.name ? [text(progress.name, { dimColor: true })] : []),
|
|
1604
|
+
...(runs.length
|
|
1605
|
+
? [
|
|
1606
|
+
Box({
|
|
1607
|
+
key: 'band-bar',
|
|
1608
|
+
flexDirection: 'row',
|
|
1609
|
+
flexShrink: 0,
|
|
1610
|
+
children: runs.map((r, i) =>
|
|
1611
|
+
text(r.glyph.repeat(r.n), {
|
|
1612
|
+
key: `band-bar-${i}`,
|
|
1613
|
+
...(r.color ? { color: r.color } : { dimColor: true }),
|
|
1614
|
+
}),
|
|
1615
|
+
),
|
|
1616
|
+
}),
|
|
1617
|
+
text(`${progress.tested}/${progress.total}`, { dimColor: true }),
|
|
1618
|
+
]
|
|
1619
|
+
: []),
|
|
1620
|
+
Box({
|
|
1621
|
+
flexShrink: 1,
|
|
1622
|
+
children: [
|
|
1623
|
+
text(
|
|
1624
|
+
`${word === 'paused' ? 'loop paused' : word}${working ? ` · ${working} agent${working === 1 ? '' : 's'} at work` : view.leadBusy ? ' · the lead is at work' : ''}`,
|
|
1625
|
+
{ wrap: 'truncate-end', color: word === 'moving' ? 'green' : 'yellow' },
|
|
1626
|
+
),
|
|
1627
|
+
],
|
|
1628
|
+
}),
|
|
1629
|
+
...(toggle
|
|
1630
|
+
? [
|
|
1631
|
+
Button({
|
|
1632
|
+
key: `band-${toggle.id}`,
|
|
1633
|
+
label: toggle.label,
|
|
1634
|
+
plain: true,
|
|
1635
|
+
onPress: () => onAction(toggle.id, null),
|
|
1636
|
+
}),
|
|
1637
|
+
]
|
|
1638
|
+
: []),
|
|
1639
|
+
],
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/** The character sheet (UI-11): every lane of the project in every pose and move. */
|
|
1644
|
+
export function sheetView(lanes, els, { surface = 'terminal', motion = 'while-active' } = {}) {
|
|
1645
|
+
const { Box, Text } = els;
|
|
1646
|
+
const text = (value, style = {}) => Text({ ...style, children: [String(value)] });
|
|
1647
|
+
const names = [LEAD, ...lanes.filter((l) => l !== LEAD)];
|
|
1648
|
+
const looks = charactersOf(names);
|
|
1649
|
+
const poses = Object.keys(POSES);
|
|
1650
|
+
const draw = (name, pose) => {
|
|
1651
|
+
if (surface === 'terminal' && els.Client)
|
|
1652
|
+
return els.Client({
|
|
1653
|
+
key: `sheet-${name}-${pose}`,
|
|
1654
|
+
module: './surface/character.mjs',
|
|
1655
|
+
props: {
|
|
1656
|
+
look: looks[name],
|
|
1657
|
+
pose: POSES[pose].loop || POSES[pose].frames === 1 ? pose : 'resting',
|
|
1658
|
+
move: POSES[pose].loop || POSES[pose].frames === 1 ? null : { kind: pose, key: pose },
|
|
1659
|
+
motion,
|
|
1660
|
+
},
|
|
1661
|
+
width: 12,
|
|
1662
|
+
height: 6,
|
|
1663
|
+
});
|
|
1664
|
+
if (els.Svg)
|
|
1665
|
+
return els.Svg({
|
|
1666
|
+
key: `sheet-${name}-${pose}`,
|
|
1667
|
+
source: characterSvg(pose, looks[name], { motion }),
|
|
1668
|
+
alt: `${name}: ${POSES[pose].words}`,
|
|
1669
|
+
width: 36,
|
|
1670
|
+
height: 36,
|
|
1671
|
+
});
|
|
1672
|
+
return text(POSES[pose].glyph);
|
|
1673
|
+
};
|
|
1674
|
+
return Box({
|
|
1675
|
+
flexDirection: 'column',
|
|
1676
|
+
rowGap: 1,
|
|
1677
|
+
children: [
|
|
1678
|
+
text(
|
|
1679
|
+
"Each lane's character, in every pose and move. A lane's look comes from its name; past six lanes each also wears a mark.",
|
|
1680
|
+
{ dimColor: true, wrap: 'wrap' },
|
|
1681
|
+
),
|
|
1682
|
+
...names.map((name) =>
|
|
1683
|
+
Box({
|
|
1684
|
+
key: `sheet-${name}`,
|
|
1685
|
+
flexDirection: 'column',
|
|
1686
|
+
children: [
|
|
1687
|
+
text(
|
|
1688
|
+
`${name} · ${looks[name].shape}${looks[name].mark ? ` · ${looks[name].mark}` : ''}`,
|
|
1689
|
+
{ bold: true },
|
|
1690
|
+
),
|
|
1691
|
+
Box({
|
|
1692
|
+
flexDirection: 'row',
|
|
1693
|
+
flexWrap: 'wrap',
|
|
1694
|
+
columnGap: 2,
|
|
1695
|
+
children: poses.map((pose) =>
|
|
1696
|
+
Box({
|
|
1697
|
+
key: `sheet-${name}-${pose}-cell`,
|
|
1698
|
+
flexDirection: 'column',
|
|
1699
|
+
children: [draw(name, pose), text(POSES[pose].words, { dimColor: true })],
|
|
1700
|
+
}),
|
|
1701
|
+
),
|
|
1702
|
+
}),
|
|
1703
|
+
],
|
|
1704
|
+
}),
|
|
1705
|
+
),
|
|
1706
|
+
],
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/** A full view over the pane (UI-6): its name and how to go back, the view, and its keys. */
|
|
1711
|
+
export function viewFrame(
|
|
1712
|
+
title,
|
|
1713
|
+
body,
|
|
1714
|
+
els,
|
|
1715
|
+
on,
|
|
1716
|
+
keys = [{ key: 'esc', label: 'back' }],
|
|
1717
|
+
{ head = true } = {},
|
|
1718
|
+
) {
|
|
1719
|
+
const { Box, Text } = els;
|
|
1720
|
+
const text = (value, style = {}) => Text({ ...style, children: [String(value)] });
|
|
1721
|
+
return Box({
|
|
1722
|
+
flexDirection: 'column',
|
|
1723
|
+
rowGap: 1,
|
|
1724
|
+
children: [
|
|
1725
|
+
...(head ? [viewHead(title, els, on)] : []),
|
|
1726
|
+
...(Array.isArray(body) ? body : [body]),
|
|
1727
|
+
text(keys.map((k) => `${k.key} ${k.label}`).join(' · '), { dimColor: true }),
|
|
1728
|
+
],
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/** A full view's first line: Back, and the view's name. */
|
|
1733
|
+
function viewHead(title, { Box, Text, Button }, on) {
|
|
1734
|
+
return Box({
|
|
1735
|
+
key: 'view-head',
|
|
1736
|
+
flexDirection: 'row',
|
|
1737
|
+
columnGap: 1,
|
|
1738
|
+
children: [
|
|
1739
|
+
Button({ key: 'view-back', label: '‹ Back', plain: true, onPress: () => on.onBack() }),
|
|
1740
|
+
Text({ bold: true, children: [String(title)] }),
|
|
1741
|
+
],
|
|
1742
|
+
});
|
|
1743
|
+
}
|