@litfamily/litclaude 1.0.41 → 1.0.43
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/CHANGELOG.md +50 -0
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/TRADEMARK.md +12 -0
- package/bin/litclaude-ai.js +29 -3
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/hooks.md +35 -6
- package/package.json +2 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +7 -1
- package/plugins/litclaude/bin/litclaude-hook.js +52 -6
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/lit-plan.md +5 -2
- package/plugins/litclaude/commands/start-work.md +8 -0
- package/plugins/litclaude/hooks/lit-band-client.mjs +9 -4
- package/plugins/litclaude/hooks/lit-mod.mjs +31 -1
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +8 -8
- package/plugins/litclaude/lib/invite.mjs +131 -0
- package/plugins/litclaude/lib/lit-plan-persistence.mjs +15 -4
- package/plugins/litclaude/lib/mod/frame.mjs +97 -21
- package/plugins/litclaude/lib/mod/looks.mjs +13 -0
- package/plugins/litclaude/lib/mod/motion.mjs +5 -0
- package/plugins/litclaude/lib/mod/settings.mjs +5 -2
- package/plugins/litclaude/lib/mod/state.mjs +85 -5
- package/plugins/litclaude/lib/mod/svg-card.mjs +66 -16
- package/plugins/litclaude/lib/mod/timeline.mjs +32 -0
- package/plugins/litclaude/lib/mod/view.mjs +84 -12
- package/plugins/litclaude/lib/owner-lock.mjs +11 -1
- package/plugins/litclaude/lib/plan-scope-roots.mjs +76 -0
- package/plugins/litclaude/lib/plan-task-rows.mjs +17 -4
- package/plugins/litclaude/lib/rewind/brief.mjs +62 -8
- package/plugins/litclaude/lib/rewind/collect.mjs +114 -25
- package/plugins/litclaude/lib/session-liveness.mjs +36 -0
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +200 -12
- package/plugins/litclaude/scripts/scaffold-plan.mjs +8 -2
- package/plugins/litclaude/skills/lit-adhd/SKILL.md +18 -11
- package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +2 -2
- package/plugins/litclaude/skills/lit-adhd/references/status-taxonomy.md +8 -3
- package/plugins/litclaude/skills/lit-plan/SKILL.md +10 -3
- package/plugins/litclaude/skills/start-work/SKILL.md +5 -0
|
@@ -384,11 +384,18 @@ export const countPlanTasks = (text) => {
|
|
|
384
384
|
return rows.length ? { done: rows.filter(({ checked }) => checked).length, total: rows.length } : null;
|
|
385
385
|
};
|
|
386
386
|
|
|
387
|
-
// Each frame that names a plan gets that plan's checkbox counts, read once per plan under the cap
|
|
387
|
+
// Each frame that names a plan gets that plan's checkbox counts, read once per plan under the cap,
|
|
388
|
+
// and `planAt`, the plan file's last change (when a finished plan's row was checked off).
|
|
388
389
|
const withPlanCounts = async (io, stateRoot, frames) => {
|
|
389
390
|
const refs = [...new Set(frames.map(({ planRef }) => planRef).filter(Boolean))];
|
|
390
|
-
const
|
|
391
|
-
|
|
391
|
+
const read = new Map(await Promise.all(refs.map(async (ref) => [ref, {
|
|
392
|
+
counts: countPlanTasks(await readGuarded(io, stateRoot, ref, STATE_CAPS.goals)),
|
|
393
|
+
at: num((await statOf(io, joinPath(stateRoot, ref)))?.mtimeMs),
|
|
394
|
+
}])));
|
|
395
|
+
for (const frame of frames) {
|
|
396
|
+
frame.plan = frame.planRef ? read.get(frame.planRef)?.counts ?? null : null;
|
|
397
|
+
frame.planAt = frame.planRef ? read.get(frame.planRef)?.at ?? null : null;
|
|
398
|
+
}
|
|
392
399
|
return frames;
|
|
393
400
|
};
|
|
394
401
|
|
|
@@ -409,11 +416,32 @@ const readOtherStacks = async (io, stateRoot, sessionId) => {
|
|
|
409
416
|
const id = typeof raw?.sessionId === "string" ? raw.sessionId : null;
|
|
410
417
|
const parsed = id ? parseWorkflowStack(raw, id) : null;
|
|
411
418
|
if (parsed) await withPlanCounts(io, stateRoot, parsed.frames.slice(-1));
|
|
412
|
-
return parsed ? { id8: id.replace(/[^A-Za-z0-9]/gu, "").slice(0, 8), at: entry.mtimeMs, ended: typeof raw.endedAt === "string", frames: parsed.frames } : null;
|
|
419
|
+
return parsed ? { sessionId: id, id8: id.replace(/[^A-Za-z0-9]/gu, "").slice(0, 8), at: entry.mtimeMs, ended: typeof raw.endedAt === "string", frames: parsed.frames } : null;
|
|
413
420
|
}));
|
|
414
421
|
return read.filter(Boolean);
|
|
415
422
|
};
|
|
416
423
|
|
|
424
|
+
const LIVENESS_FILES = 12;
|
|
425
|
+
const LIVENESS_STATES = new Set(["alive", "idle", "ended"]);
|
|
426
|
+
|
|
427
|
+
// The newest liveness records the hooks wrote (session-liveness.mjs), keyed by full session id:
|
|
428
|
+
// `{ state, at, herdrPane }`. Links and malformed records are skipped.
|
|
429
|
+
const readLiveness = async (io, stateRoot) => {
|
|
430
|
+
const files = (await listOf(io, joinPath(stateRoot, ".litclaude", "liveness")))
|
|
431
|
+
.filter((entry) => entry?.kind === "file" && !entry.isLink && /^[A-Za-z0-9._-]+\.json$/u.test(entry.name))
|
|
432
|
+
.sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
433
|
+
.slice(0, LIVENESS_FILES);
|
|
434
|
+
const records = await Promise.all(files.map((entry) => readGuardedJson(io, stateRoot, joinPath(".litclaude", "liveness", entry.name), STATE_CAPS.small)));
|
|
435
|
+
const liveness = {};
|
|
436
|
+
for (const record of records) {
|
|
437
|
+
const id = str(record?.sessionId, 160);
|
|
438
|
+
if (!id || !LIVENESS_STATES.has(record.state) || time(record.at) === null || Object.hasOwn(liveness, id)) continue;
|
|
439
|
+
const pane = typeof record.herdrPane === "string" && /^[A-Za-z0-9:_-]{1,32}$/u.test(record.herdrPane) ? record.herdrPane : null;
|
|
440
|
+
liveness[id] = { state: record.state, at: time(record.at), herdrPane: pane };
|
|
441
|
+
}
|
|
442
|
+
return liveness;
|
|
443
|
+
};
|
|
444
|
+
|
|
417
445
|
const readWorkflowSources = async (io, stateRoot, sessionId) => {
|
|
418
446
|
const dir = (name) => joinPath(stateRoot, ".litclaude", name);
|
|
419
447
|
const [interviews, drafts, researches, ownStack, unknownStack] = await Promise.all([
|
|
@@ -428,7 +456,8 @@ const readWorkflowSources = async (io, stateRoot, sessionId) => {
|
|
|
428
456
|
await withPlanCounts(io, stateRoot, stack.frames);
|
|
429
457
|
if (stack.record) stack.record.plan = stack.frames[stack.owner].plan;
|
|
430
458
|
}
|
|
431
|
-
const
|
|
459
|
+
const [stacks, liveness] = await Promise.all([readOtherStacks(io, stateRoot, sessionId), readLiveness(io, stateRoot)]);
|
|
460
|
+
const others = stacks.map((other) => ({ ...other, liveness: liveness[other.sessionId] ?? null }));
|
|
432
461
|
// A record written before the stack existed, read only while this session has no stack.
|
|
433
462
|
const legacy = stack ? null : await readGuardedJson(io, stateRoot, ".litclaude/workflow-stage.json", STATE_CAPS.small);
|
|
434
463
|
const interviewFile = newestFile(interviews, /^[A-Za-z0-9._-]+-state\.json$/u);
|
|
@@ -448,6 +477,8 @@ const readWorkflowSources = async (io, stateRoot, sessionId) => {
|
|
|
448
477
|
record: stack?.record ?? parseStageRecord(legacy, sessionId),
|
|
449
478
|
stack,
|
|
450
479
|
others,
|
|
480
|
+
liveness,
|
|
481
|
+
sessionId: typeof sessionId === "string" ? sessionId : null,
|
|
451
482
|
interview: interview ? parseInterviewState(interview, interviewFile.mtimeMs) : null,
|
|
452
483
|
draft: draft === null ? null : parseDraftStatus(draft, draftFile.name.replace(/\.md$/u, ""), draftFile.mtimeMs),
|
|
453
484
|
research,
|
|
@@ -488,6 +519,55 @@ export const readLitSnapshot = async (io, { cwd, sessionId, env = {} }) => {
|
|
|
488
519
|
};
|
|
489
520
|
};
|
|
490
521
|
|
|
522
|
+
// Where `lit invite` keeps its record (lib/invite.mjs inviteHome): LITCLAUDE_HOME, else ~/.litclaude.
|
|
523
|
+
export const inviteRoot = (env) => {
|
|
524
|
+
// Untrimmed, like lib/invite.mjs and resolveHome, so the card reads the file the CLI wrote.
|
|
525
|
+
const home = env?.LITCLAUDE_HOME;
|
|
526
|
+
if (home) return normalizePath(home);
|
|
527
|
+
return env?.HOME?.trim() ? joinPath(env.HOME.trim(), ".litclaude") : null;
|
|
528
|
+
};
|
|
529
|
+
// lib/invite.mjs's id rule; the band cannot import that module, which writes.
|
|
530
|
+
const INVITE_ID = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/u;
|
|
531
|
+
|
|
532
|
+
/** The recorded inviter's id from a real, well-formed invite.json under inviteRoot (read guarded), or null. */
|
|
533
|
+
export const readInvited = async (io, env) => {
|
|
534
|
+
const root = inviteRoot(env);
|
|
535
|
+
if (!root) return null;
|
|
536
|
+
const record = await readGuardedJson(io, root, "invite.json", 4096);
|
|
537
|
+
return record?.version === 1 && typeof record.invitedBy === "string" && INVITE_ID.test(record.invitedBy) ? record.invitedBy : null;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* The LitClaude version Claude Code installed, from its `installed_plugins.json` record: the
|
|
542
|
+
* `litclaude@…` entry, user scope first. Anything unreadable or malformed gives null.
|
|
543
|
+
*/
|
|
544
|
+
export const installedVersionOf = (record) => {
|
|
545
|
+
const plugins = record?.plugins;
|
|
546
|
+
if (!plugins || typeof plugins !== "object" || Array.isArray(plugins)) return null;
|
|
547
|
+
const entries = Object.entries(plugins)
|
|
548
|
+
.filter(([key, list]) => key.startsWith("litclaude@") && Array.isArray(list))
|
|
549
|
+
.flatMap(([, list]) => list)
|
|
550
|
+
.filter((entry) => entry && typeof entry === "object" && typeof entry.version === "string");
|
|
551
|
+
return str((entries.find(({ scope }) => scope === "user") ?? entries[0])?.version, 40);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
const readJsonAt = async (io, path, cap) => {
|
|
555
|
+
if (typeof path !== "string" || !path) return null;
|
|
556
|
+
try {
|
|
557
|
+
const text = await readSmall(io, path, cap);
|
|
558
|
+
const value = text === null ? null : JSON.parse(text);
|
|
559
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
560
|
+
} catch {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/** `{ loaded, installed }`: this plugin's own manifest version and the one installed, or null each. */
|
|
566
|
+
export const readPluginVersions = async (io, { pluginJson, installedFile }) => {
|
|
567
|
+
const [plugin, installed] = await Promise.all([readJsonAt(io, pluginJson, STATE_CAPS.small), readJsonAt(io, installedFile, STATE_CAPS.goals)]);
|
|
568
|
+
return { loaded: str(plugin?.version, 40), installed: installedVersionOf(installed) };
|
|
569
|
+
};
|
|
570
|
+
|
|
491
571
|
const readSmall = async (io, path, cap) => {
|
|
492
572
|
const stat = await statOf(io, path);
|
|
493
573
|
if (!stat || stat.kind !== "file" || !(stat.size <= cap)) return null;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
import { gauge, knownFacts } from "../rewind/gauge.mjs";
|
|
24
24
|
import { textWidth, truncateToWidth } from "./layout.mjs";
|
|
25
|
-
import { LOOKS, lookOf } from "./looks.mjs";
|
|
25
|
+
import { CLUB_GLINT, CLUB_GOLD, CLUB_PILL, CLUB_STOPS, LOOKS, lookOf } from "./looks.mjs";
|
|
26
26
|
import { TIMINGS, barCells, gradientAt, rainbowAt } from "./motion.mjs";
|
|
27
27
|
|
|
28
28
|
const C = Object.freeze({
|
|
@@ -105,6 +105,7 @@ const indicatorOf = (model, accent) => {
|
|
|
105
105
|
if (model.completion) return { label: "DONE ✓", fill: C.green };
|
|
106
106
|
if (model.look === "turn") return { label: LOOKS.turn.label, fill: C.amber };
|
|
107
107
|
if (model.look === "review") return { label: `${LOOKS.review.label} ${model.workflow.verdicts.filter(({ state }) => state === "pass" || state === "fail").length}/${model.workflow.verdicts.length}`, fill: accent };
|
|
108
|
+
if (model.look === "club") return { label: `${LOOKS.club.label} ✦`, fill: CLUB_GOLD };
|
|
108
109
|
if (model.idle) return { label: "idle", fill: C.dim, plain: true };
|
|
109
110
|
const flow = model.workflow;
|
|
110
111
|
if (flow?.paused && flow.current >= 0) return { label: `${flow.stages[flow.current].id.toUpperCase()} ||`, fill: C.dim };
|
|
@@ -116,19 +117,32 @@ const indicatorOf = (model, accent) => {
|
|
|
116
117
|
return { label: "LIVE ●", fill: accent };
|
|
117
118
|
};
|
|
118
119
|
|
|
119
|
-
// The rewind look draws the LIT pill and a `REWIND <<` indicator in the turning rainbow
|
|
120
|
+
// The rewind look draws the LIT pill and a `REWIND <<` indicator in the turning rainbow; the club
|
|
121
|
+
// look a gold pill after a `✧`, a rose title closed by a `✦`, and `CLUB ✦` on its gold-gradient pill.
|
|
120
122
|
const topRow = (model, accent, animate, rewind = false) => {
|
|
121
123
|
const { width, pad } = SVG_CARD;
|
|
122
124
|
const y = ROW_Y[0];
|
|
125
|
+
const club = model.look === "club";
|
|
126
|
+
const lead = club ? text(pad, y, "✧", { fill: CLUB_STOPS[1] }) : "";
|
|
127
|
+
const from = club ? pad + widthOf("✧ ") : pad;
|
|
123
128
|
const brand = rewind
|
|
124
|
-
? pill(
|
|
125
|
-
: pill(
|
|
129
|
+
? pill(from, y, "🔥 LIT", { fill: "url(#lit-rainbow)", ink: C.ink, veil: true })
|
|
130
|
+
: pill(from, y, "🔥 LIT", { fill: club ? CLUB_GOLD : C.pink, ink: C.ink, breath: animate.breath ? C.orange : null });
|
|
126
131
|
const indicator = rewind && !model.completion ? { label: "REWIND <<", fill: "url(#lit-rainbow)" } : indicatorOf(model, accent);
|
|
127
|
-
|
|
128
|
-
const
|
|
132
|
+
// The club pill is 16 wider than the bare indicator text; it ends where the text would.
|
|
133
|
+
const pillWide = club ? 16 : 0;
|
|
134
|
+
// A newer LitClaude installed than the one loaded: `restart to <version>` left of the indicator.
|
|
135
|
+
const chip = model.restart ? `restart to ${model.restart}` : null;
|
|
136
|
+
const chipEnd = width - pad - widthOf(indicator.label) - 16 - pillWide;
|
|
137
|
+
const label = club
|
|
138
|
+
? pill(width - pad - widthOf(indicator.label) - 16, y, indicator.label, { fill: "url(#lit-club-pill)", ink: C.ink }).markup
|
|
139
|
+
: text(width - pad, y, indicator.label, { fill: indicator.fill, bold: !indicator.plain, anchor: "end" });
|
|
140
|
+
const right = label + (chip ? text(chipEnd, y, chip, { fill: C.amber, anchor: "end" }) : "");
|
|
141
|
+
const tail = club ? " ✦" : "";
|
|
142
|
+
const room = width - pad - widthOf(indicator.label) - 16 - pillWide - (chip ? widthOf(chip) + 16 : 0) - brand.end - widthOf(" · ") - widthOf(tail);
|
|
129
143
|
const name = truncateToWidth(model.title ?? "ready", Math.max(4, Math.floor(room / SVG_CARD.cell)));
|
|
130
|
-
const title = run(brand.end + 4, y, [[" · ", { fill: C.dim }], [name, model.idle && !rewind ? { fill: C.dim } : { fill: accent, bold: true }]]);
|
|
131
|
-
return brand.markup + title.markup + right;
|
|
144
|
+
const title = run(brand.end + 4, y, [[" · ", { fill: C.dim }], [name, club ? { fill: CLUB_STOPS[1] } : model.idle && !rewind ? { fill: C.dim } : { fill: accent, bold: true }], ...(club ? [[tail, { fill: CLUB_GOLD }]] : [])]);
|
|
145
|
+
return lead + brand.markup + title.markup + right;
|
|
132
146
|
};
|
|
133
147
|
|
|
134
148
|
const rightOfPhases = (model, withProgress = true) => {
|
|
@@ -306,6 +320,18 @@ const detailRowSvg = (model, accent, animate) => {
|
|
|
306
320
|
const TONES = Object.freeze({ pink: [C.pink, "#ff6fae", "🔥"], amber: [C.amber, C.amber, "⚠"], red: [C.red, C.red, "✗"] });
|
|
307
321
|
|
|
308
322
|
// Skill chips, or the notice or the finish while one is up, or the hint while nothing has fired.
|
|
323
|
+
// The club card's quiet `invited by @<id>` chip on the muted pill, ending at the card's right pad;
|
|
324
|
+
// drawn only when it clears whatever the row already holds (ending at `after`) by 16.
|
|
325
|
+
const inviteChipSvg = (model, y, after) => {
|
|
326
|
+
if (!model.invitedBy || after === null) return "";
|
|
327
|
+
const handle = `@${model.invitedBy}`;
|
|
328
|
+
const w = widthOf(`invited by ${handle}`) + 16;
|
|
329
|
+
const x = SVG_CARD.width - SVG_CARD.pad - w;
|
|
330
|
+
if (x < after + 16) return "";
|
|
331
|
+
return `<rect x="${x.toFixed(1)}" y="${y - PILL_H + 6}" width="${w.toFixed(1)}" height="${PILL_H}" rx="${PILL_H / 2}" fill="${C.muted}"/>`
|
|
332
|
+
+ run(x + 8, y, [["invited by ", { fill: C.mutedText }], [handle, { fill: CLUB_STOPS[1], bold: true }]]).markup;
|
|
333
|
+
};
|
|
334
|
+
|
|
309
335
|
const middleRow = (model, accent, animate, shift = 0, rewind = false) => {
|
|
310
336
|
const { width, pad } = SVG_CARD;
|
|
311
337
|
const y = ROW_Y[3] + shift;
|
|
@@ -321,7 +347,8 @@ const middleRow = (model, accent, animate, shift = 0, rewind = false) => {
|
|
|
321
347
|
if (model.skills.length === 0) {
|
|
322
348
|
if (!model.idle && model.next && !model.workflow?.next) return run(pad, y, [["▸ ", { fill: accent }], [truncateToWidth(model.next, Math.floor((room - pad) / SVG_CARD.cell) - 2), { fill: C.white }]]).markup;
|
|
323
349
|
if (!model.idle) return text(pad, y, "no LitFamily skill yet in this request", { fill: C.dim });
|
|
324
|
-
|
|
350
|
+
const hint = run(pad, y, [["no LitFamily skill yet · type ", { fill: C.dim }], ["lit <task>", { fill: accent }], [" to start one", { fill: C.dim }]]);
|
|
351
|
+
return hint.markup + inviteChipSvg(model, y, hint.end);
|
|
325
352
|
}
|
|
326
353
|
const out = [text(pad, y, "skills", { fill: C.dim })];
|
|
327
354
|
let x = pad + widthOf("skills") + 10;
|
|
@@ -345,6 +372,7 @@ const middleRow = (model, accent, animate, shift = 0, rewind = false) => {
|
|
|
345
372
|
});
|
|
346
373
|
if (rewind && animate.sweep && x !== null) out.push(sparksSvg(x, width - pad, y));
|
|
347
374
|
if (model.away && x !== null && x + widthOf("back? type lit adhd to catch up") <= room) out.push(run(x, y, [["back? type ", { fill: C.dim }], ["lit adhd", { fill: accent }], [" to catch up", { fill: C.dim }]]).markup);
|
|
375
|
+
else out.push(inviteChipSvg(model, y, x));
|
|
348
376
|
return out.join("");
|
|
349
377
|
};
|
|
350
378
|
|
|
@@ -423,7 +451,7 @@ const pulseSvg = (x, y, animate, fill) => {
|
|
|
423
451
|
*/
|
|
424
452
|
const threadRowsSvg = (model, { animate = false, rewind = false } = {}) => {
|
|
425
453
|
const { width, pad } = SVG_CARD;
|
|
426
|
-
const { chain, lanes, others, laneCount = 0, taskCount = 0, more } = model.threads;
|
|
454
|
+
const { chain, lanes, herdrLanes = [], others, laneCount = 0, taskCount = 0, more } = model.threads;
|
|
427
455
|
const lines = [];
|
|
428
456
|
chain.forEach((thread, index) => lines.push({ thread, lead: index === 0 ? "" : `${" ".repeat(index - 1)}└─ ` }));
|
|
429
457
|
const under = " ".repeat(Math.max(0, chain.length - 1));
|
|
@@ -434,6 +462,7 @@ const threadRowsSvg = (model, { animate = false, rewind = false } = {}) => {
|
|
|
434
462
|
} else {
|
|
435
463
|
lanes.forEach((thread) => lines.push({ thread, lead: chain.length ? `${under}└─ ` : "" }));
|
|
436
464
|
}
|
|
465
|
+
herdrLanes.forEach((thread) => lines.push({ thread, lead: "" }));
|
|
437
466
|
others.forEach((thread) => lines.push({ thread, lead: "" }));
|
|
438
467
|
const threads = lines.filter(({ thread }) => thread).map(({ thread }) => thread);
|
|
439
468
|
const nameCells = Math.min(28, Math.max(...threads.map(({ name }) => textWidth(name))));
|
|
@@ -504,6 +533,25 @@ const rainbowDefs = (animate) => {
|
|
|
504
533
|
return `<defs><linearGradient id="lit-rainbow" x1="0" x2="1" y1="0" y2="1">${stops.join("")}</linearGradient></defs>`;
|
|
505
534
|
};
|
|
506
535
|
|
|
536
|
+
// The club look's ring: gold on the left side through rose to violet on the right, so the top edge
|
|
537
|
+
// and the bottom edge each carry the whole velvet and the ring closes gold on gold at the left, as
|
|
538
|
+
// the terminal card lays it clockwise. The pill gradient fills `CLUB ✦`.
|
|
539
|
+
const gradientStops = (stops) => stops.map((color, i) => `<stop offset="${(i / (stops.length - 1)).toFixed(3)}" stop-color="${color}"/>`).join("");
|
|
540
|
+
const clubDefs = () => `<defs><linearGradient id="lit-club" x1="0" x2="1" y1="0" y2="0">${gradientStops(CLUB_STOPS.slice(0, 3))}</linearGradient>`
|
|
541
|
+
+ `<linearGradient id="lit-club-pill" x1="0" x2="1" y1="0" y2="0">${gradientStops(CLUB_PILL)}</linearGradient></defs>`;
|
|
542
|
+
|
|
543
|
+
// The club glint (full motion only): a warm light crossing the top edge left to right in
|
|
544
|
+
// TIMINGS.clubGlint, then off the card until the next pass, TIMINGS.clubGlintPeriod apart. The first
|
|
545
|
+
// pass waits TIMINGS.clubGlintRest, as on the terminal card.
|
|
546
|
+
const clubGlintSvg = (width) => {
|
|
547
|
+
const reach = 120;
|
|
548
|
+
const pass = (TIMINGS.clubGlint / TIMINGS.clubGlintPeriod).toFixed(3);
|
|
549
|
+
return `<defs><linearGradient id="lit-club-glint" gradientUnits="userSpaceOnUse" x1="${-reach}" x2="0" y1="0" y2="0">`
|
|
550
|
+
+ `<stop offset="0" stop-color="${CLUB_GLINT}" stop-opacity="0"/><stop offset="0.5" stop-color="${CLUB_GLINT}" stop-opacity="0.95"/><stop offset="1" stop-color="${CLUB_GLINT}" stop-opacity="0"/>`
|
|
551
|
+
+ `<animateTransform attributeName="gradientTransform" type="translate" values="0 0;${width + reach} 0;${width + reach} 0" keyTimes="0;${pass};1" dur="${TIMINGS.clubGlintPeriod}ms" begin="${TIMINGS.clubGlintRest}ms" repeatCount="indefinite"/>`
|
|
552
|
+
+ `</linearGradient></defs><line x1="15" y1="1.25" x2="${width - 15}" y2="1.25" stroke="url(#lit-club-glint)" stroke-width="2.5" stroke-linecap="round"/>`;
|
|
553
|
+
};
|
|
554
|
+
|
|
507
555
|
/** What the card says, for a reader that cannot see the drawing. */
|
|
508
556
|
export const svgCardAlt = (model) => {
|
|
509
557
|
const parts = [`LIT ${model.rewind ? "rewind" : model.idle ? "idle" : "working"}`];
|
|
@@ -518,7 +566,7 @@ export const svgCardAlt = (model) => {
|
|
|
518
566
|
parts.push(`phase ${LABELS[current]}`);
|
|
519
567
|
}
|
|
520
568
|
if (model.step) parts.push(`running ${model.step.name}`);
|
|
521
|
-
const threads = model.threads ? [...model.threads.chain, ...model.threads.lanes, ...model.threads.others] : [];
|
|
569
|
+
const threads = model.threads ? [...model.threads.chain, ...model.threads.lanes, ...(model.threads.herdrLanes ?? []), ...model.threads.others] : [];
|
|
522
570
|
if (threads.length) parts.push(`threads ${threads.map((thread) => `${thread.name} ${gauge(thread.done, thread.total) ? `${gauge(thread.done, thread.total)} ${thread.state}` : threadFacts(thread)}`).join(", ")}${model.threads.more ? `, ${model.threads.more} more` : ""}`);
|
|
523
571
|
if (model.skills.length) parts.push(`skills ${model.skills.map(({ id }) => id).join(", ")}`);
|
|
524
572
|
const { context, rates } = model.figures;
|
|
@@ -539,12 +587,13 @@ export const composeSvgCard = (model, { motion = "full", accent = "#5fd7ff" } =
|
|
|
539
587
|
const rewind = (model.rewind === true || (!model.idle && lookOf(model.discipline) === "rewind")) && model.warnings.length === 0;
|
|
540
588
|
const working = (!model.idle || rewind) && motion !== "off";
|
|
541
589
|
const animate = { breath: working, sweep: working && motion === "full", comet: working && motion === "full" };
|
|
542
|
-
const
|
|
590
|
+
const club = model.look === "club" && model.warnings.length === 0;
|
|
591
|
+
const edge = rewind ? "url(#lit-rainbow)" : club ? "url(#lit-club)" : borderColor(model, accent);
|
|
543
592
|
const perimeter = 1000;
|
|
544
|
-
const defs = (rewind ? rainbowDefs(animate.breath) : "") + (animate.sweep
|
|
593
|
+
const defs = (rewind ? rainbowDefs(animate.breath) : club ? clubDefs() : "") + (animate.sweep
|
|
545
594
|
? `<defs><linearGradient id="lit-sweep" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0"/><stop offset="0.5" stop-color="#fff" stop-opacity="0.55"/><stop offset="1" stop-color="#fff" stop-opacity="0"/><animateTransform attributeName="gradientTransform" type="translate" values="-1.2 0;1.2 0" ${loop(TIMINGS.sweep, 0.5)}/></linearGradient></defs>`
|
|
546
595
|
: "");
|
|
547
|
-
const frame = `<rect x="1" y="1" width="${width - 2}" height="${height - 2}" rx="14" fill="${C.bg}" stroke="${edge}" stroke-width="${model.idle && !rewind ? "1.5" : "2.5"}"${model.idle && !rewind ? ' stroke-opacity="0.8"' : ""}>`
|
|
596
|
+
const frame = `<rect x="1" y="1" width="${width - 2}" height="${height - 2}" rx="14" fill="${C.bg}" stroke="${edge}" stroke-width="${model.idle && !rewind && !club ? "1.5" : "2.5"}"${model.idle && !rewind && !club ? ' stroke-opacity="0.8"' : ""}>`
|
|
548
597
|
+ (animate.breath && !model.warnings.length ? `<animate attributeName="stroke-opacity" values="0.85;1;0.85" ${loop(TIMINGS.breath, BREATH_PHASE)}/>` : "")
|
|
549
598
|
+ "</rect>";
|
|
550
599
|
const comet = animate.comet
|
|
@@ -559,6 +608,7 @@ export const composeSvgCard = (model, { motion = "full", accent = "#5fd7ff" } =
|
|
|
559
608
|
middleRow(model, accent, animate, shift, rewind),
|
|
560
609
|
bottomRow(model, accent, shift),
|
|
561
610
|
].join("");
|
|
562
|
-
const
|
|
563
|
-
|
|
611
|
+
const glint = club && motion === "full" ? clubGlintSvg(width) : "";
|
|
612
|
+
const source = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" font-family="${FONT}" font-size="${SVG_CARD.font}">${defs}${frame}${comet}${glint}${body}</svg>`;
|
|
613
|
+
return { source, alt: svgCardAlt(model), animated: working || glint !== "" };
|
|
564
614
|
};
|
|
@@ -45,10 +45,18 @@ const ambientOf = (model, now, profile, previous = null) => {
|
|
|
45
45
|
return { on, at: on && previous?.on ? previous.at : now };
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
// The club look's glint runs on the idle card, so it keeps its own clock apart from the ambient
|
|
49
|
+
// loop: between passes nothing moves and the surface waits for the next one (glintWait).
|
|
50
|
+
const glintOf = (model, now, profile, previous = null) => {
|
|
51
|
+
const on = Boolean(profile.ambient?.sweep) && model.visible && model.look === "club";
|
|
52
|
+
return { on, at: on && previous?.on ? previous.at : now };
|
|
53
|
+
};
|
|
54
|
+
|
|
48
55
|
export const createTimeline = (model, now, profile) => {
|
|
49
56
|
const restAt = now + entryEnd(profile);
|
|
50
57
|
return {
|
|
51
58
|
ambient: ambientOf(model, now, profile),
|
|
59
|
+
glint: glintOf(model, now, profile),
|
|
52
60
|
enterAt: now,
|
|
53
61
|
exitAt: null,
|
|
54
62
|
fill: { from: 0, to: fractionOf(model), at: restAt, dur: profile.duration(TIMINGS.fill) },
|
|
@@ -90,6 +98,7 @@ export const advanceTimeline = (timeline, model, now, profile) => {
|
|
|
90
98
|
}
|
|
91
99
|
next.chips = chipsOf(model, now, timeline.chips);
|
|
92
100
|
next.ambient = ambientOf(model, now, profile, timeline.ambient);
|
|
101
|
+
next.glint = glintOf(model, now, profile, timeline.glint);
|
|
93
102
|
next.step = stepOf(model, now);
|
|
94
103
|
next.lanes = lanesOf(model, now);
|
|
95
104
|
return next;
|
|
@@ -101,6 +110,28 @@ export const clockShown = (timeline) => timeline.exitAt === null && Boolean(time
|
|
|
101
110
|
/** True while the ambient loop runs; the surface module then keeps a slower frame timer going. */
|
|
102
111
|
export const ambientActive = (timeline, profile) => Boolean(profile.ambient) && timeline.exitAt === null && timeline.ambient.on;
|
|
103
112
|
|
|
113
|
+
// Where the club glint stands: 0 to 1 across the current pass, or null between passes, before the
|
|
114
|
+
// first one and while the glint is off.
|
|
115
|
+
const glintAt = (timeline, now) => {
|
|
116
|
+
if (!timeline.glint?.on || timeline.exitAt !== null) return null;
|
|
117
|
+
const elapsed = now - timeline.glint.at - TIMINGS.clubGlintRest;
|
|
118
|
+
if (elapsed < 0) return null;
|
|
119
|
+
const into = elapsed % TIMINGS.clubGlintPeriod;
|
|
120
|
+
return into < TIMINGS.clubGlint ? into / TIMINGS.clubGlint : null;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* How long the surface may wait before its next frame for the club glint: a frame interval while a
|
|
125
|
+
* pass runs, the time left until the next pass otherwise, and null when the glint is off.
|
|
126
|
+
*/
|
|
127
|
+
export const glintWait = (timeline, now, profile) => {
|
|
128
|
+
if (!profile.ambient?.sweep || !timeline.glint?.on || timeline.exitAt !== null) return null;
|
|
129
|
+
const elapsed = now - timeline.glint.at - TIMINGS.clubGlintRest;
|
|
130
|
+
if (elapsed < 0) return -elapsed;
|
|
131
|
+
const into = elapsed % TIMINGS.clubGlintPeriod;
|
|
132
|
+
return into < TIMINGS.clubGlint ? TIMINGS.ambientFrame : TIMINGS.clubGlintPeriod - into;
|
|
133
|
+
};
|
|
134
|
+
|
|
104
135
|
// The rewind look's sparks: fixed seeds (a small LCG, so every surface draws the same sky), each a
|
|
105
136
|
// starting place, a drift speed and a twinkle offset.
|
|
106
137
|
const SPARK_SEEDS = (() => {
|
|
@@ -217,6 +248,7 @@ export const sampleTimeline = (timeline, now, profile) => {
|
|
|
217
248
|
completion,
|
|
218
249
|
chips,
|
|
219
250
|
ambient: ambientSample(timeline, now, profile),
|
|
251
|
+
glint: glintAt(timeline, now),
|
|
220
252
|
step: timeline.step ? { name: timeline.step.name, elapsedMs: timeline.step.base + Math.max(0, now - timeline.step.at) } : null,
|
|
221
253
|
lanes: timeline.lanes ? { elapsedMs: timeline.lanes.base + Math.max(0, now - timeline.lanes.at) } : null,
|
|
222
254
|
spin: Math.floor(Math.max(0, now) / TIMINGS.spin) % 4,
|
|
@@ -103,6 +103,9 @@ const PARALLEL_ROWS = 3;
|
|
|
103
103
|
// Another session of this project counts as live while its stack was written this recently and
|
|
104
104
|
// SessionEnd has not marked it ended.
|
|
105
105
|
export const OTHER_SESSION_MS = 15 * 60 * 1000;
|
|
106
|
+
// A finished start-work (or any thread marked done) keeps its check mark this long after it
|
|
107
|
+
// finished, then leaves the card.
|
|
108
|
+
export const DONE_LINGER_MS = 60_000;
|
|
106
109
|
|
|
107
110
|
const countOrNull = (value) => (Number.isInteger(value) && value >= 0 ? value : null);
|
|
108
111
|
|
|
@@ -241,22 +244,59 @@ const frameCount = (frame, snapshot, mainList) => {
|
|
|
241
244
|
|
|
242
245
|
// A thread with no total carries what is known instead: its finished steps, how long it has run
|
|
243
246
|
// and its last step (knownFacts in rewind/gauge.mjs words them).
|
|
247
|
+
// A frame is finished when its record says so, or when it is a start-work, not paused, whose plan has
|
|
248
|
+
// every row checked; a paused one at k/k still waits (for a review to hand back, say). `doneAt` is
|
|
249
|
+
// when: the plan file's last change, else the record's or the frame's time.
|
|
244
250
|
const frameThread = (frame, index, snapshot, active, mainList = null, now = null, mainEntry = null) => {
|
|
245
251
|
const { done, total } = frameCount(frame, snapshot, active ? mainList : null);
|
|
246
252
|
const started = Number.isFinite(frame.at) ? frame.at : frame.record?.at;
|
|
253
|
+
const finished = Boolean(frame.record?.done) || (frame.skill === "start-work" && frame.status !== "paused" && total > 0 && done === total);
|
|
254
|
+
const doneAt = [frame.planAt, frame.record?.at, started].find(Number.isFinite) ?? null;
|
|
247
255
|
return {
|
|
248
256
|
key: `frame-${index}`,
|
|
249
257
|
name: frame.skill ?? frame.record?.family ?? "work",
|
|
250
258
|
stage: frame.record?.step ?? frame.record?.stage ?? null,
|
|
251
259
|
done,
|
|
252
260
|
total,
|
|
253
|
-
state:
|
|
261
|
+
state: finished ? "done" : frame.status === "paused" ? "paused" : frame.skill === "start-work" && snapshot.work?.status === "paused" ? "blocked" : "running",
|
|
262
|
+
doneAt: finished ? doneAt : null,
|
|
254
263
|
active,
|
|
255
264
|
steps: active && mainEntry ? mainEntry.steps : null,
|
|
256
265
|
last: active && mainEntry ? mainEntry.last ?? null : null,
|
|
257
266
|
elapsedMs: Number.isFinite(now) && Number.isFinite(started) ? Math.max(0, now - started) : null,
|
|
258
267
|
};
|
|
259
268
|
};
|
|
269
|
+
const lingering = (thread, now) => thread.state !== "done" || !Number.isFinite(thread.doneAt) || now - thread.doneAt <= DONE_LINGER_MS;
|
|
270
|
+
|
|
271
|
+
// Another session's row: its liveness record says running (`alive`), `idle` or `ended` (hidden);
|
|
272
|
+
// without one, a stack written within OTHER_SESSION_MS and not marked ended counts as running.
|
|
273
|
+
// A stack that moved after the record (a resumed session's first tool call) outranks it.
|
|
274
|
+
const otherState = (thread, liveness) => (liveness?.state === "idle" && thread.state === "running" ? "idle" : thread.state);
|
|
275
|
+
const currentLiveness = (liveness, stackAt) => (liveness && !(Number.isFinite(stackAt) && stackAt > liveness.at) ? liveness : null);
|
|
276
|
+
const seenAt = (other) => Math.max(Number.isFinite(other.at) ? other.at : -Infinity, Number.isFinite(other.liveness?.at) ? other.liveness.at : -Infinity);
|
|
277
|
+
// Running first, then idle, then the rest (paused, done), each newest first.
|
|
278
|
+
const STATE_ORDER = { running: 0, idle: 1 };
|
|
279
|
+
const runningFirst = (a, b) => (STATE_ORDER[a.state] ?? 2) - (STATE_ORDER[b.state] ?? 2) || b.seenAt - a.seenAt;
|
|
280
|
+
|
|
281
|
+
// herdr lanes of this project: sessions whose hooks ran in a herdr pane (their liveness record keeps
|
|
282
|
+
// the pane id), drawn as lanes named `<top skill or claude> · <pane>`. This session, and any session
|
|
283
|
+
// in this session's own pane, are never listed.
|
|
284
|
+
const herdrLanesOf = (snapshot, others, now) => {
|
|
285
|
+
const liveness = snapshot.workflow?.liveness ?? {};
|
|
286
|
+
const self = snapshot.workflow?.sessionId ?? null;
|
|
287
|
+
const ownPane = self ? liveness[self]?.herdrPane ?? null : null;
|
|
288
|
+
return Object.entries(liveness)
|
|
289
|
+
.filter(([id, entry]) => id !== self && entry.herdrPane && entry.herdrPane !== ownPane)
|
|
290
|
+
.map(([id, entry]) => {
|
|
291
|
+
const other = others.find((candidate) => candidate.sessionId === id);
|
|
292
|
+
const live = currentLiveness(entry, other?.at);
|
|
293
|
+
if (live?.state === "ended" || (!live && other?.ended) || now - Math.max(entry.at, other?.at ?? -Infinity) > OTHER_SESSION_MS) return null;
|
|
294
|
+
const top = other?.frames?.length ? frameThread(other.frames.at(-1), 0, {}, false, null, now) : { name: "claude", stage: null, done: null, total: null, state: "running", doneAt: null, active: false, elapsedMs: null };
|
|
295
|
+
return { ...top, key: `herdr-${entry.herdrPane}`, sessionId: id, name: `${top.name} · ${entry.herdrPane}`, state: otherState(top, live), seenAt: Math.max(entry.at, other?.at ?? -Infinity) };
|
|
296
|
+
})
|
|
297
|
+
.filter((thread) => thread && lingering(thread, now))
|
|
298
|
+
.sort(runningFirst);
|
|
299
|
+
};
|
|
260
300
|
|
|
261
301
|
// A lane's k/n: its own todo or task list, then the tasks a loop gave it by name; else no total,
|
|
262
302
|
// with the steps it has finished and its last one.
|
|
@@ -274,7 +314,8 @@ const laneCount = (entry, lists, name) => listProgress(entry) ?? ownedProgress(l
|
|
|
274
314
|
const threadsOf = ({ snapshot, lanes, tasks, lists, now, threadReserve }) => {
|
|
275
315
|
const frames = snapshot.workflow?.stack?.frames ?? [];
|
|
276
316
|
const mainList = listProgress(lists.main);
|
|
277
|
-
const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList, now, lists.main))
|
|
317
|
+
const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList, now, lists.main))
|
|
318
|
+
.filter((thread) => lingering(thread, now));
|
|
278
319
|
const laneThreads = lanes.map((lane, index) => ({
|
|
279
320
|
key: `lane-${lane.id ?? index}`,
|
|
280
321
|
name: lane.name,
|
|
@@ -286,23 +327,36 @@ const threadsOf = ({ snapshot, lanes, tasks, lists, now, threadReserve }) => {
|
|
|
286
327
|
}));
|
|
287
328
|
const taskThreads = tasks.map((task) => ({ key: `task-${task.id}`, name: task.name, stage: task.kind, done: null, total: null, state: "running", active: false, task: task.kind, elapsedMs: Number.isFinite(task.at) ? Math.max(0, now - task.at) : null }));
|
|
288
329
|
const parallel = [...laneThreads, ...taskThreads];
|
|
330
|
+
const herdrLanes = herdrLanesOf(snapshot, snapshot.workflow?.others ?? [], now);
|
|
331
|
+
const inHerdr = new Set(herdrLanes.map(({ sessionId }) => sessionId));
|
|
289
332
|
const others = (snapshot.workflow?.others ?? [])
|
|
290
|
-
.filter((other) =>
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
333
|
+
.filter((other) => {
|
|
334
|
+
const live = currentLiveness(other.liveness, other.at);
|
|
335
|
+
return (live ? live.state !== "ended" : !other.ended) && !inHerdr.has(other.sessionId) && now - seenAt(other) <= OTHER_SESSION_MS && other.frames?.length;
|
|
336
|
+
})
|
|
337
|
+
.map((other) => {
|
|
338
|
+
const thread = frameThread(other.frames.at(-1), 0, {}, false, null, now);
|
|
339
|
+
return { ...thread, key: `session-${other.id8}`, session: other.id8, state: otherState(thread, currentLiveness(other.liveness, other.at)), seenAt: seenAt(other) };
|
|
340
|
+
})
|
|
341
|
+
.filter((thread) => lingering(thread, now))
|
|
342
|
+
.sort(runningFirst);
|
|
343
|
+
const total = chain.length + parallel.length + herdrLanes.length + others.length;
|
|
344
|
+
// A lone own thread keeps the plain card; a herdr lane or another session always gets its row.
|
|
345
|
+
if (total < 2 && herdrLanes.length + others.length === 0) return null;
|
|
294
346
|
const room = Math.max(PARALLEL_ROWS, THREAD_ROWS - chain.length);
|
|
295
347
|
const keptLanes = parallel.slice(0, room);
|
|
296
|
-
const
|
|
348
|
+
const keptHerdr = herdrLanes.slice(0, Math.max(0, room - keptLanes.length));
|
|
349
|
+
const keptOthers = others.slice(0, Math.max(0, room - keptLanes.length - keptHerdr.length));
|
|
297
350
|
const fork = parallel.length >= 2 ? 1 : 0;
|
|
298
|
-
const needed = chain.length + keptLanes.length + keptOthers.length + fork;
|
|
351
|
+
const needed = chain.length + keptLanes.length + keptHerdr.length + keptOthers.length + fork;
|
|
299
352
|
return {
|
|
300
353
|
chain,
|
|
301
354
|
lanes: keptLanes,
|
|
355
|
+
herdrLanes: keptHerdr,
|
|
302
356
|
others: keptOthers,
|
|
303
357
|
laneCount: laneThreads.length,
|
|
304
358
|
taskCount: taskThreads.length,
|
|
305
|
-
more: total - chain.length - keptLanes.length - keptOthers.length,
|
|
359
|
+
more: total - chain.length - keptLanes.length - keptHerdr.length - keptOthers.length,
|
|
306
360
|
reserve: Math.max(needed, Number.isInteger(threadReserve) ? threadReserve : 0),
|
|
307
361
|
};
|
|
308
362
|
};
|
|
@@ -394,7 +448,19 @@ export const stepName = (tool) => {
|
|
|
394
448
|
* (noteBackgroundTask). `turnStartedAt` is when the main loop's current turn began, `waiting`
|
|
395
449
|
* what the session waits on the user for (`{ reason }`, null while it does not).
|
|
396
450
|
*/
|
|
397
|
-
|
|
451
|
+
const versionParts = (version) => {
|
|
452
|
+
const match = typeof version === "string" ? /^(\d+)\.(\d+)\.(\d+)/u.exec(version) : null;
|
|
453
|
+
return match ? match.slice(1, 4).map(Number) : null;
|
|
454
|
+
};
|
|
455
|
+
/** The installed version when it is newer than the loaded one by `major.minor.patch`, else null. */
|
|
456
|
+
export const restartVersion = ({ loaded = null, installed = null } = {}) => {
|
|
457
|
+
const [have, want] = [versionParts(loaded), versionParts(installed)];
|
|
458
|
+
if (!have || !want) return null;
|
|
459
|
+
const order = want.map((part, i) => part - have[i]).find((diff) => diff !== 0) ?? 0;
|
|
460
|
+
return order > 0 ? installed.slice(0, 40) : null;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVITY, usage = null, now, band = "always", isWorking = false, notice = null, completion = null, skills = [], lastDiscipline = null, git = null, step = null, threadReserve = 0, lists = EMPTY_LISTS, tasks = EMPTY_TASKS, turnStartedAt = null, waiting = null, versions = null, club = false, invitedBy = null }) => {
|
|
398
464
|
const discipline = snapshot.ignition?.discipline ?? null;
|
|
399
465
|
const progress = progressOf(snapshot);
|
|
400
466
|
const completing = completion !== null;
|
|
@@ -424,14 +490,20 @@ export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVIT
|
|
|
424
490
|
const lit = skills.some(({ state }) => state === "current");
|
|
425
491
|
const workflow = buildWorkflow({ snapshot, skills, completion, now });
|
|
426
492
|
const title = discipline ?? skills.find(({ state }) => state === "current")?.id ?? lastDiscipline;
|
|
427
|
-
const
|
|
493
|
+
const chosen = selectLook({ snapshot, discipline, skills, workflow, completion, waiting, now, turnStartedAt });
|
|
494
|
+
// `club` (an inviter recorded and the club option on) dresses only the idle card, and never
|
|
495
|
+
// shows a band that `band: auto` would hide.
|
|
496
|
+
const look = chosen ?? (club === true && !active && !lit ? "club" : null);
|
|
428
497
|
const rewind = look === "rewind";
|
|
429
|
-
const visible = band === "off" ? false : band === "always" || active || lit ||
|
|
498
|
+
const visible = band === "off" ? false : band === "always" || active || lit || chosen !== null || notice !== null || completion !== null || warnings.length > 0;
|
|
430
499
|
return {
|
|
431
500
|
visible,
|
|
432
501
|
idle: !active && !lit,
|
|
502
|
+
restart: restartVersion(versions ?? undefined),
|
|
433
503
|
look,
|
|
434
504
|
rewind,
|
|
505
|
+
// Who invited this machine, for the club card's chip; null on every other look.
|
|
506
|
+
invitedBy: look === "club" && typeof invitedBy === "string" ? invitedBy : null,
|
|
435
507
|
waiting: waiting?.reason ?? null,
|
|
436
508
|
away: !active && !lit && !rewind && skills.length > 0 && now - Math.max(...skills.map(({ at }) => (Number.isFinite(at) ? at : now))) >= BREAK_MS,
|
|
437
509
|
discipline,
|
|
@@ -50,6 +50,15 @@ const assertLockDirectory = (lockDir, expected) => {
|
|
|
50
50
|
return identity;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
// A contender that loses a stale takeover finds the lock removed or replaced by the winner's
|
|
54
|
+
// fresh directory. That is a lost race to retry, not a failure; a symlink still fails closed.
|
|
55
|
+
const lockWasReplaced = (lockDir, expected) => {
|
|
56
|
+
const details = lstatSync(lockDir, { throwIfNoEntry: false });
|
|
57
|
+
if (!details) return true;
|
|
58
|
+
if (details.isSymbolicLink() || !details.isDirectory()) return false;
|
|
59
|
+
return !sameDirectory(directoryIdentity(details), expected);
|
|
60
|
+
};
|
|
61
|
+
|
|
53
62
|
// Destructive cleanup is commit-by-rename: once the checked path is moved to a private
|
|
54
63
|
// quarantine, a pathname replacement cannot make us remove the replacement. Re-checking the
|
|
55
64
|
// moved entry catches Linux inode reuse (ctime/birthtime differ even when dev+ino are forged).
|
|
@@ -304,7 +313,8 @@ export const acquireOwnerLock = (lockDir, { timeoutMs = 500, staleMs = 30_000 }
|
|
|
304
313
|
}
|
|
305
314
|
}
|
|
306
315
|
} catch (takeoverError) {
|
|
307
|
-
if (!["ENOENT", "EEXIST", "ENOTEMPTY"].includes(takeoverError?.code)
|
|
316
|
+
if (!["ENOENT", "EEXIST", "ENOTEMPTY"].includes(takeoverError?.code)
|
|
317
|
+
&& !lockWasReplaced(lockDir, lockDirectory)) {
|
|
308
318
|
throw new OwnerLockError("stale lock takeover failed", 65);
|
|
309
319
|
}
|
|
310
320
|
}
|