@litfamily/litclaude 1.0.38 → 1.0.40
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 +41 -0
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/hooks.md +11 -6
- package/package.json +1 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/bin/litclaude-hook.js +31 -13
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/lit-adhd.md +12 -8
- package/plugins/litclaude/commands/lit-rewind.md +12 -8
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +26 -25
- package/plugins/litclaude/lib/interface-probe-gate.mjs +4 -5
- package/plugins/litclaude/lib/lit-plan-persistence.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/autoloop.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/cli.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/ledger.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/state.mjs +4 -6
- package/plugins/litclaude/lib/mod/frame.mjs +87 -20
- package/plugins/litclaude/lib/mod/svg-card.mjs +64 -22
- package/plugins/litclaude/lib/mod/timeline.mjs +4 -3
- package/plugins/litclaude/lib/mod/view.mjs +53 -13
- package/plugins/litclaude/lib/motion-render-gate.mjs +4 -5
- package/plugins/litclaude/lib/project-state-root.mjs +44 -2
- package/plugins/litclaude/lib/rewind/brief.mjs +373 -0
- package/plugins/litclaude/lib/rewind/collect.mjs +55 -25
- package/plugins/litclaude/lib/rewind/gauge.mjs +28 -8
- package/plugins/litclaude/lib/rewind/next-step.mjs +4 -5
- package/plugins/litclaude/lib/rewind/redact.mjs +28 -8
- package/plugins/litclaude/lib/rewind/suggest.mjs +56 -0
- package/plugins/litclaude/lib/rewind/transcripts.mjs +18 -3
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +6 -9
- package/plugins/litclaude/lib/workflow-stack.mjs +4 -5
- package/plugins/litclaude/skills/frontend-ui-ux/SKILL.md +8 -1
- package/plugins/litclaude/skills/frontend-ui-ux/references/production-interview.md +1 -1
- package/plugins/litclaude/skills/lit-adhd/SKILL.md +45 -28
- package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +114 -58
- package/plugins/litclaude/skills/lit-adhd/scripts/rewind.mjs +1 -1
- package/plugins/litclaude/skills/lit-diagram-drawer/SKILL.md +12 -1
- package/plugins/litclaude/skills/lit-docx/SKILL.md +6 -1
- package/plugins/litclaude/skills/lit-docx/references/direction-step.md +8 -4
- package/plugins/litclaude/skills/lit-handoff/SKILL.md +1 -0
- package/plugins/litclaude/skills/lit-hijack/references/capture-and-provenance.md +7 -0
- package/plugins/litclaude/skills/lit-hijack/references/distil-and-licence.md +5 -0
- package/plugins/litclaude/skills/lit-hijack/scripts/hijack.mjs +87 -15
- package/plugins/litclaude/skills/lit-pptx/SKILL.md +6 -1
- package/plugins/litclaude/skills/lit-pptx/references/direction-step.md +4 -2
- package/plugins/litclaude/skills/lit-recap/SKILL.md +1 -0
- package/plugins/litclaude/skills/lit-schematic/SKILL.md +12 -1
- package/plugins/litclaude/skills/lit-typographic-motion/SKILL.md +10 -6
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/assets.mjs +80 -13
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-serve.mjs +13 -3
- package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +9 -7
- package/plugins/litclaude/skills/readme-studio/SKILL.md +10 -0
- package/plugins/litclaude/skills/readme-studio/references/production-interview.md +2 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// (skills.mjs) and what Claude Code reports live (subagents, context and rate-limit usage). Pure: the mod calls these on each refresh and hands the result to the
|
|
3
3
|
// band's surface module, which only draws and animates it.
|
|
4
4
|
|
|
5
|
+
import { lookOf } from "./motion.mjs";
|
|
5
6
|
import { AUTOLOOP_LIMITS, GATE_LIMITS } from "./state.mjs";
|
|
6
7
|
import { buildWorkflow } from "./workflow.mjs";
|
|
7
8
|
|
|
@@ -13,6 +14,13 @@ export const AGENT_STALE_MS = 30 * 60 * 1000;
|
|
|
13
14
|
// The context warning starts this many points before the auto-handoff percent.
|
|
14
15
|
export const CONTEXT_LEAD = 5;
|
|
15
16
|
|
|
17
|
+
// How long the rewind look stays after `lit adhd` was sent. The ignition keeps naming lit-adhd
|
|
18
|
+
// until the next prompt, so the look lasts while the user reads the brief, but no longer than this.
|
|
19
|
+
export const REWIND_LINGER_MS = 15 * 60 * 1000;
|
|
20
|
+
|
|
21
|
+
// How long the card must have sat idle since its newest skill before it offers `lit adhd`.
|
|
22
|
+
export const BREAK_MS = 30 * 60 * 1000;
|
|
23
|
+
|
|
16
24
|
const LIVE_AGENT = new Set(["running", "pending", "waiting", "idle"]);
|
|
17
25
|
const ENDED_AGENT = new Set(["completed", "failed", "killed"]);
|
|
18
26
|
const NONTERMINAL_GOAL = new Set(["active", "blocked", "review_blocked", "needs_user_decision"]);
|
|
@@ -97,14 +105,24 @@ const countOrNull = (value) => (Number.isInteger(value) && value >= 0 ? value :
|
|
|
97
105
|
|
|
98
106
|
// `lists` maps a loop (`main`, or a subagent's id) to what its tool calls say of its progress:
|
|
99
107
|
// `steps`, the tool calls it finished; `todos`, the counts of its last TodoWrite; `tasks`, the
|
|
100
|
-
// status of each task it created with TaskCreate (TaskUpdate moves them
|
|
101
|
-
// lists it touched last
|
|
108
|
+
// status of each task it created with TaskCreate (TaskUpdate moves them, and may give one to a lane
|
|
109
|
+
// by `owner`); `latest`, which of the two lists it touched last; `last`, its last finished step as a
|
|
110
|
+
// tool name and at most a file's base name. Only statuses are kept, never a todo's or a task's text.
|
|
102
111
|
export const EMPTY_LISTS = Object.freeze({});
|
|
103
112
|
const LIST_CAP = 200;
|
|
104
113
|
const LOOP_CAP = 40;
|
|
105
114
|
const TASK_STATUS = new Set(["pending", "in_progress", "completed"]);
|
|
106
115
|
|
|
107
|
-
const loopEntry = (lists, loop) => lists[loop] ?? { steps: 0, todos: null, tasks: {}, latest: null };
|
|
116
|
+
const loopEntry = (lists, loop) => lists[loop] ?? { steps: 0, todos: null, tasks: {}, latest: null, last: null };
|
|
117
|
+
const OWNER = /^[\w .:-]{1,40}$/u;
|
|
118
|
+
// `Edit README.md`: the tool and the base name of the file it touched, nothing of its arguments.
|
|
119
|
+
const lastStepOf = (call) => {
|
|
120
|
+
const tool = stepName(call?.tool);
|
|
121
|
+
if (!tool) return null;
|
|
122
|
+
const path = typeof call.file_path === "string" ? call.file_path : typeof call.notebook_path === "string" ? call.notebook_path : null;
|
|
123
|
+
const base = path ? path.split(/[\\/]/u).pop().replace(/[^\w .@+-]/gu, "").slice(0, 28) : "";
|
|
124
|
+
return base ? `${tool} ${base}` : tool;
|
|
125
|
+
};
|
|
108
126
|
|
|
109
127
|
/**
|
|
110
128
|
* Folds one finished tool call of `loop` into `lists`: every call counts a step, a TodoWrite
|
|
@@ -116,6 +134,7 @@ export const noteLoopCall = (lists, loop, call, result) => {
|
|
|
116
134
|
const next = { ...lists };
|
|
117
135
|
const entry = { ...loopEntry(lists, loop) };
|
|
118
136
|
entry.steps += 1;
|
|
137
|
+
entry.last = lastStepOf(call) ?? entry.last ?? null;
|
|
119
138
|
if (call?.tool === "TodoWrite" && Array.isArray(call.todos)) {
|
|
120
139
|
const todos = call.todos.slice(0, LIST_CAP);
|
|
121
140
|
entry.todos = { done: todos.filter((todo) => todo?.status === "completed").length, total: todos.length };
|
|
@@ -123,13 +142,16 @@ export const noteLoopCall = (lists, loop, call, result) => {
|
|
|
123
142
|
} else if (call?.tool === "TaskCreate" && typeof result?.task?.id === "string") {
|
|
124
143
|
entry.tasks = { ...entry.tasks, [result.task.id.slice(0, 64)]: { status: "pending", seen: true } };
|
|
125
144
|
entry.latest = "tasks";
|
|
126
|
-
} else if (call?.tool === "TaskUpdate" && typeof call.taskId === "string" && (TASK_STATUS.has(call.status) || call.status === "deleted")) {
|
|
145
|
+
} else if (call?.tool === "TaskUpdate" && typeof call.taskId === "string" && (TASK_STATUS.has(call.status) || call.status === "deleted" || typeof call.owner === "string")) {
|
|
127
146
|
const id = call.taskId.slice(0, 64);
|
|
128
147
|
const owner = Object.keys(next).find((key) => key !== loop && next[key].tasks?.[id]);
|
|
129
148
|
const target = owner ? { ...next[owner] } : entry;
|
|
130
149
|
const tasks = { ...target.tasks };
|
|
131
150
|
if (call.status === "deleted") delete tasks[id];
|
|
132
|
-
else
|
|
151
|
+
else if (TASK_STATUS.has(call.status) || tasks[id]) {
|
|
152
|
+
const assignee = typeof call.owner === "string" && OWNER.test(call.owner.trim()) ? call.owner.trim() : tasks[id]?.owner;
|
|
153
|
+
tasks[id] = { status: TASK_STATUS.has(call.status) ? call.status : tasks[id].status, seen: tasks[id]?.seen ?? false, ...(assignee ? { owner: assignee } : {}) };
|
|
154
|
+
}
|
|
133
155
|
target.tasks = Object.fromEntries(Object.entries(tasks).slice(-LIST_CAP));
|
|
134
156
|
target.latest = "tasks";
|
|
135
157
|
if (owner) next[owner] = target;
|
|
@@ -151,6 +173,13 @@ export const listProgress = (entry) => {
|
|
|
151
173
|
return entry.todos ?? fromTasks;
|
|
152
174
|
};
|
|
153
175
|
|
|
176
|
+
// The tasks any loop's list gave to `owner` by name, as `{ done, total }`, or null when none did.
|
|
177
|
+
const ownedProgress = (lists, owner) => {
|
|
178
|
+
if (!owner) return null;
|
|
179
|
+
const owned = Object.values(lists).flatMap((entry) => Object.values(entry?.tasks ?? {})).filter((task) => task.owner === owner);
|
|
180
|
+
return owned.length ? { done: owned.filter(({ status }) => status === "completed").length, total: owned.length } : null;
|
|
181
|
+
};
|
|
182
|
+
|
|
154
183
|
// `tasks` maps a background task's id to `{ id, kind, name, at, until }`: a shell a Bash call left
|
|
155
184
|
// running (its own `backgroundTaskId`) or a monitor, named by the call's description, never its
|
|
156
185
|
// command. `until` is a monitor's deadline. A task ends with its notification, a TaskStop, its
|
|
@@ -207,8 +236,11 @@ const frameCount = (frame, snapshot, mainList) => {
|
|
|
207
236
|
return mainList ?? { done: countOrNull(record?.n), total: null };
|
|
208
237
|
};
|
|
209
238
|
|
|
210
|
-
|
|
239
|
+
// A thread with no total carries what is known instead: its finished steps, how long it has run
|
|
240
|
+
// and its last step (knownFacts in rewind/gauge.mjs words them).
|
|
241
|
+
const frameThread = (frame, index, snapshot, active, mainList = null, now = null, mainEntry = null) => {
|
|
211
242
|
const { done, total } = frameCount(frame, snapshot, active ? mainList : null);
|
|
243
|
+
const started = Number.isFinite(frame.at) ? frame.at : frame.record?.at;
|
|
212
244
|
return {
|
|
213
245
|
key: `frame-${index}`,
|
|
214
246
|
name: frame.skill ?? frame.record?.family ?? "work",
|
|
@@ -217,11 +249,15 @@ const frameThread = (frame, index, snapshot, active, mainList = null) => {
|
|
|
217
249
|
total,
|
|
218
250
|
state: frame.record?.done ? "done" : frame.status === "paused" ? "paused" : frame.skill === "start-work" && snapshot.work?.status === "paused" ? "blocked" : "running",
|
|
219
251
|
active,
|
|
252
|
+
steps: active && mainEntry ? mainEntry.steps : null,
|
|
253
|
+
last: active && mainEntry ? mainEntry.last ?? null : null,
|
|
254
|
+
elapsedMs: Number.isFinite(now) && Number.isFinite(started) ? Math.max(0, now - started) : null,
|
|
220
255
|
};
|
|
221
256
|
};
|
|
222
257
|
|
|
223
|
-
// A lane's k/n: its own todo or task list,
|
|
224
|
-
|
|
258
|
+
// A lane's k/n: its own todo or task list, then the tasks a loop gave it by name; else no total,
|
|
259
|
+
// with the steps it has finished and its last one.
|
|
260
|
+
const laneCount = (entry, lists, name) => listProgress(entry) ?? ownedProgress(lists, name) ?? { done: null, total: null, steps: entry?.steps ?? 0, last: entry?.last ?? null };
|
|
225
261
|
|
|
226
262
|
/**
|
|
227
263
|
* The live threads, or null while there is at most one: `{ chain, lanes, others, laneCount,
|
|
@@ -235,20 +271,21 @@ const laneCount = (entry) => listProgress(entry) ?? { done: entry?.steps ?? 0, t
|
|
|
235
271
|
const threadsOf = ({ snapshot, lanes, tasks, lists, now, threadReserve }) => {
|
|
236
272
|
const frames = snapshot.workflow?.stack?.frames ?? [];
|
|
237
273
|
const mainList = listProgress(lists.main);
|
|
238
|
-
const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList));
|
|
274
|
+
const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList, now, lists.main));
|
|
239
275
|
const laneThreads = lanes.map((lane, index) => ({
|
|
240
276
|
key: `lane-${lane.id ?? index}`,
|
|
241
277
|
name: lane.name,
|
|
242
278
|
stage: null,
|
|
243
|
-
...laneCount(lane.id ? lists[lane.id] : null),
|
|
279
|
+
...laneCount(lane.id ? lists[lane.id] : null, lists, lane.name),
|
|
244
280
|
state: lane.status === "stalled" ? "blocked" : lane.status === "idle" ? "idle" : "running",
|
|
245
281
|
active: false,
|
|
282
|
+
elapsedMs: Number.isFinite(lane.elapsedMs) ? lane.elapsedMs : null,
|
|
246
283
|
}));
|
|
247
|
-
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 }));
|
|
284
|
+
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 }));
|
|
248
285
|
const parallel = [...laneThreads, ...taskThreads];
|
|
249
286
|
const others = (snapshot.workflow?.others ?? [])
|
|
250
287
|
.filter((other) => Number.isFinite(other.at) && now - other.at <= OTHER_SESSION_MS && other.frames?.length)
|
|
251
|
-
.map((other) => ({ ...frameThread(other.frames.at(-1), 0, {}, false), key: `session-${other.id8}`, session: other.id8 }));
|
|
288
|
+
.map((other) => ({ ...frameThread(other.frames.at(-1), 0, {}, false, null, now), key: `session-${other.id8}`, session: other.id8 }));
|
|
252
289
|
const total = chain.length + parallel.length + others.length;
|
|
253
290
|
if (total < 2) return null;
|
|
254
291
|
const room = Math.max(PARALLEL_ROWS, THREAD_ROWS - chain.length);
|
|
@@ -382,10 +419,13 @@ export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVIT
|
|
|
382
419
|
const lit = skills.some(({ state }) => state === "current");
|
|
383
420
|
const workflow = buildWorkflow({ snapshot, skills, completion, now });
|
|
384
421
|
const title = discipline ?? skills.find(({ state }) => state === "current")?.id ?? lastDiscipline;
|
|
385
|
-
const
|
|
422
|
+
const rewind = lookOf(discipline) === "rewind" && Number.isFinite(snapshot.ignition?.at) && now - snapshot.ignition.at < REWIND_LINGER_MS;
|
|
423
|
+
const visible = band === "off" ? false : band === "always" || active || lit || rewind || notice !== null || completion !== null || warnings.length > 0;
|
|
386
424
|
return {
|
|
387
425
|
visible,
|
|
388
426
|
idle: !active && !lit,
|
|
427
|
+
rewind,
|
|
428
|
+
away: !active && !lit && !rewind && skills.length > 0 && now - Math.max(...skills.map(({ at }) => (Number.isFinite(at) ? at : now))) >= BREAK_MS,
|
|
389
429
|
discipline,
|
|
390
430
|
title: workflow?.paused ? crumbOf(workflow.paused) : title,
|
|
391
431
|
phases,
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
// once more to tell the model to say, in the reply, that the film is not done and why; a blocked
|
|
11
11
|
// environment (exit 10-12, 14, 15, 21, 22) goes straight to that notice. A done film with a downgrade, open
|
|
12
12
|
// look items or no image tool blocks once so the reply says so.
|
|
13
|
-
import { existsSync,
|
|
13
|
+
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { requireStateDir, resolveProjectStateRoot, STATE_WRITE_FLAG } from "./project-state-root.mjs";
|
|
17
17
|
|
|
18
18
|
export const MOTION_MAX_BLOCKS = 2;
|
|
19
19
|
export const MOTION_DISCIPLINE = "lit-typographic-motion";
|
|
@@ -43,10 +43,9 @@ const readTurn = (cwd) => {
|
|
|
43
43
|
|
|
44
44
|
const writeTurn = (cwd, state) => {
|
|
45
45
|
const target = motionTurnPath(cwd);
|
|
46
|
-
|
|
47
|
-
ensureStateDirIgnored(target);
|
|
46
|
+
requireStateDir(join(target, ".."));
|
|
48
47
|
const tmp = `${target}.tmp`;
|
|
49
|
-
writeFileSync(tmp, JSON.stringify(state));
|
|
48
|
+
writeFileSync(tmp, JSON.stringify(state), { flag: STATE_WRITE_FLAG });
|
|
50
49
|
renameSync(tmp, target);
|
|
51
50
|
return state;
|
|
52
51
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { closeSync, constants, existsSync, lstatSync, openSync, writeSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
1
|
+
import { closeSync, constants, existsSync, lstatSync, mkdirSync, openSync, writeSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
3
3
|
|
|
4
4
|
import { findProjectRoot } from "./rules/discovery.mjs";
|
|
5
5
|
|
|
@@ -52,3 +52,45 @@ export const ensureStateDirIgnored = (pathInsideState) => {
|
|
|
52
52
|
if (fd !== undefined) closeSync(fd);
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
+
|
|
56
|
+
// Creates `dir` inside a project's state folder one level at a time and returns false, creating
|
|
57
|
+
// nothing more, when `.litclaude` or any folder below it is a symlink or not a folder: a cloned
|
|
58
|
+
// repository can carry such a link, and following it would write LitClaude state anywhere the user
|
|
59
|
+
// can write. Every state writer calls this before writing and gives up on false.
|
|
60
|
+
export const prepareStateDir = (dir) => {
|
|
61
|
+
const target = resolve(dir);
|
|
62
|
+
const parts = target.split(sep);
|
|
63
|
+
const at = parts.indexOf(PROJECT_STATE_DIR);
|
|
64
|
+
if (at <= 0) return false;
|
|
65
|
+
try {
|
|
66
|
+
mkdirSync(parts.slice(0, at).join(sep) || sep, { recursive: true });
|
|
67
|
+
let current = parts.slice(0, at).join(sep) || sep;
|
|
68
|
+
for (const part of parts.slice(at)) {
|
|
69
|
+
current = join(current, part);
|
|
70
|
+
try {
|
|
71
|
+
mkdirSync(current);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error?.code !== "EEXIST") return false;
|
|
74
|
+
}
|
|
75
|
+
const stats = lstatSync(current);
|
|
76
|
+
if (stats.isSymbolicLink() || !stats.isDirectory()) return false;
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
ensureStateDirIgnored(target);
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Open flags for a state file write that fails on a symlink at the file itself instead of following it.
|
|
86
|
+
export const STATE_WRITE_FLAG = constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC | (constants.O_NOFOLLOW ?? 0);
|
|
87
|
+
export const STATE_APPEND_FLAG = constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | (constants.O_NOFOLLOW ?? 0);
|
|
88
|
+
|
|
89
|
+
/** `prepareStateDir` for writers that must stop: throws on a refused state folder. */
|
|
90
|
+
export const requireStateDir = (dir) => {
|
|
91
|
+
if (!resolve(dir).split(sep).includes(PROJECT_STATE_DIR)) {
|
|
92
|
+
mkdirSync(dir, { recursive: true });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!prepareStateDir(dir)) throw new Error("the LitClaude state folder is a symlink or not a folder; refusing to write");
|
|
96
|
+
};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// The lit-adhd brief as Markdown, drawn by code from the collector's data (collect.mjs) so a tired
|
|
2
|
+
// reader gets the same shape every time and the model only copies it: a one-line headline, one card
|
|
3
|
+
// per session grouped by worktree and branch (status badge, goal, a real gauge or the known facts,
|
|
4
|
+
// done, next), a roadmap timeline (done ✓ / now ▶ / later ○ with dates), one recommended next step
|
|
5
|
+
// in a box, and the word to type. Every string in `data` is already redacted and clipped; this file
|
|
6
|
+
// adds layout and words only, never a number the data does not hold.
|
|
7
|
+
|
|
8
|
+
import { basename } from "node:path";
|
|
9
|
+
|
|
10
|
+
import { clipToWidth, displayWidth } from "./gauge.mjs";
|
|
11
|
+
import { stripControls } from "./redact.mjs";
|
|
12
|
+
|
|
13
|
+
const WORDS = {
|
|
14
|
+
en: {
|
|
15
|
+
sessions: (n) => `${n} ${n === 1 ? "session" : "sessions"}`,
|
|
16
|
+
waiting: (n) => `${n} ${n === 1 ? "waits" : "wait"} on you`,
|
|
17
|
+
active: (n) => `${n} active`,
|
|
18
|
+
next: "next",
|
|
19
|
+
window: (since, trees) => `last ${since} · ${trees} ${trees === 1 ? "worktree" : "worktrees"}`,
|
|
20
|
+
badge: { "waiting-on-user": "🟠 **WAITING ON YOU**", active: "🟢 **ACTIVE**", ended: "⚪ ended", unknown: "⚫ unknown" },
|
|
21
|
+
reason: { "asked the user": "it asked you something", "paused workflow": "paused workflow", "start-work boundary": "start-work needs approval" },
|
|
22
|
+
ago: (text) => `${text} ago`,
|
|
23
|
+
justNow: "just now",
|
|
24
|
+
goal: "Goal",
|
|
25
|
+
done: "Done",
|
|
26
|
+
nextLabel: "Next",
|
|
27
|
+
noneDone: "no file edits or commits on record",
|
|
28
|
+
toolsUsed: (list) => `no edits yet; used ${list}`,
|
|
29
|
+
doing: (what) => `now: ${what}`,
|
|
30
|
+
endedTitle: (n) => `Ended · ${n}`,
|
|
31
|
+
endedHead: ["id", "where", "goal", "ago", "done"],
|
|
32
|
+
fileCount: (n) => `${n} ${n === 1 ? "file" : "files"}`,
|
|
33
|
+
moreEnded: (n) => `…and ${n} more ended`,
|
|
34
|
+
files: "edited",
|
|
35
|
+
commits: (n) => `${n} ${n === 1 ? "commit" : "commits"}`,
|
|
36
|
+
worked: (d) => `${d} of work`,
|
|
37
|
+
lastAsk: (q) => `last ask: “${q}”`,
|
|
38
|
+
working: "still working in that session",
|
|
39
|
+
self: "this session",
|
|
40
|
+
answer: (q) => `answer its question: “${q}”`,
|
|
41
|
+
resume: (skill, stage, self) => `resume ${skill} at ${stage} (\`lit continue\`${self ? "" : " there"})`,
|
|
42
|
+
approve: "approve or deny the start-work boundary (`lit approve` / `lit deny`)",
|
|
43
|
+
planNow: (plan, item) => `${plan} → ${item}`,
|
|
44
|
+
nothing: "nothing pending on record",
|
|
45
|
+
roadmap: "Roadmap",
|
|
46
|
+
now: "now",
|
|
47
|
+
later: "later",
|
|
48
|
+
milestoneDone: "done",
|
|
49
|
+
noRoadmap: "No open plan, goal or commit in this window.",
|
|
50
|
+
morePlans: (n) => `…and ${n} more open ${n === 1 ? "plan" : "plans"}`,
|
|
51
|
+
recommended: "RECOMMENDED NEXT STEP",
|
|
52
|
+
type: "type",
|
|
53
|
+
stepKind: {
|
|
54
|
+
"resume-frame": ({ skill, stage }) => `Resume the paused ${skill} at ${stage}`,
|
|
55
|
+
"approve-boundary": ({ plan, action, root }) => `start-work (${plan}) waits for ${action} access to ${root}`,
|
|
56
|
+
"continue-work": ({ plan }) => `Keep running ${plan}`,
|
|
57
|
+
"start-plan": ({ plan }) => `Start ${plan} with start-work`,
|
|
58
|
+
none: () => "No next step on record",
|
|
59
|
+
},
|
|
60
|
+
suggest: {
|
|
61
|
+
answer: ({ id8, where, question }) => `Answer ${id8} in ${where}${question ? `: “${question}”` : ""}`,
|
|
62
|
+
resume: ({ id8, skill, stage, where }) => `Resume ${skill} at ${stage} in ${id8} (${where})`,
|
|
63
|
+
plan: ({ plan, item }) => `Next in ${plan}: ${item}`,
|
|
64
|
+
check: ({ id8, goal, where, doing }) => `Check on ${id8} in ${where} (${goal})${doing ? `, now ${doing}` : ""}`,
|
|
65
|
+
pickUp: ({ id8, goal, where }) => `Pick up ${id8} in ${where}: ${goal}`,
|
|
66
|
+
start: () => "No session or plan in this window: say what to start",
|
|
67
|
+
},
|
|
68
|
+
goLine: (say) => `Type **\`${say}\`** to continue.`,
|
|
69
|
+
noGo: "Nothing runs on its own here: open that session, or say what to do.",
|
|
70
|
+
unknownSources: (list) => `Not read: ${list}.`,
|
|
71
|
+
older: "Older sessions were not read (read budget used up).",
|
|
72
|
+
noSessions: "No Claude Code session records in this window.",
|
|
73
|
+
},
|
|
74
|
+
ko: {
|
|
75
|
+
sessions: (n) => `세션 ${n}개`,
|
|
76
|
+
waiting: (n) => `나를 기다리는 것 ${n}`,
|
|
77
|
+
active: (n) => `진행 중 ${n}`,
|
|
78
|
+
next: "다음",
|
|
79
|
+
window: (since, trees) => `최근 ${since} · 워크트리 ${trees}개`,
|
|
80
|
+
badge: { "waiting-on-user": "🟠 **나를 기다림**", active: "🟢 **진행 중**", ended: "⚪ 끝남", unknown: "⚫ 모름" },
|
|
81
|
+
reason: { "asked the user": "질문에 답을 기다림", "paused workflow": "멈춘 워크플로", "start-work boundary": "start-work 승인 대기" },
|
|
82
|
+
ago: (text) => `${text} 전`,
|
|
83
|
+
justNow: "방금",
|
|
84
|
+
goal: "목표",
|
|
85
|
+
done: "한 일",
|
|
86
|
+
nextLabel: "다음",
|
|
87
|
+
noneDone: "기록된 파일 수정·커밋 없음",
|
|
88
|
+
toolsUsed: (list) => `아직 수정 없음, 쓴 도구 ${list}`,
|
|
89
|
+
doing: (what) => `지금: ${what}`,
|
|
90
|
+
endedTitle: (n) => `끝난 세션 · ${n}`,
|
|
91
|
+
endedHead: ["id", "위치", "목표", "끝난 지", "한 일"],
|
|
92
|
+
fileCount: (n) => `파일 ${n}개`,
|
|
93
|
+
moreEnded: (n) => `…끝난 세션 ${n}개 더`,
|
|
94
|
+
files: "수정",
|
|
95
|
+
commits: (n) => `커밋 ${n}개`,
|
|
96
|
+
worked: (d) => `${d} 작업`,
|
|
97
|
+
lastAsk: (q) => `마지막 요청: “${q}”`,
|
|
98
|
+
working: "그 세션에서 작업 중",
|
|
99
|
+
self: "이 세션",
|
|
100
|
+
answer: (q) => `질문에 답하기: “${q}”`,
|
|
101
|
+
resume: (skill, stage, self) => `${skill}(${stage}) 이어가기 (${self ? "" : "그 세션에서 "}\`lit continue\`)`,
|
|
102
|
+
approve: "start-work 경계 승인 또는 거절 (`lit approve` / `lit deny`)",
|
|
103
|
+
planNow: (plan, item) => `${plan} → ${item}`,
|
|
104
|
+
nothing: "기록된 남은 일 없음",
|
|
105
|
+
roadmap: "로드맵",
|
|
106
|
+
now: "지금",
|
|
107
|
+
later: "이후",
|
|
108
|
+
milestoneDone: "완료",
|
|
109
|
+
noRoadmap: "이 기간에 열린 계획·목표·커밋이 없습니다.",
|
|
110
|
+
morePlans: (n) => `…열린 계획 ${n}개 더`,
|
|
111
|
+
recommended: "추천하는 다음 단계",
|
|
112
|
+
type: "입력",
|
|
113
|
+
stepKind: {
|
|
114
|
+
"resume-frame": ({ skill, stage }) => `멈춘 ${skill}(${stage}) 이어가기`,
|
|
115
|
+
"approve-boundary": ({ plan, action, root }) => `start-work(${plan})가 ${root} ${action} 권한을 기다림`,
|
|
116
|
+
"continue-work": ({ plan }) => `${plan} 계속 진행`,
|
|
117
|
+
"start-plan": ({ plan }) => `${plan}을 start-work로 시작`,
|
|
118
|
+
none: () => "기록된 다음 단계 없음",
|
|
119
|
+
},
|
|
120
|
+
suggest: {
|
|
121
|
+
answer: ({ id8, where, question }) => `${where}의 ${id8}에 답하기${question ? `: “${question}”` : ""}`,
|
|
122
|
+
resume: ({ id8, skill, stage, where }) => `${where}의 ${id8}에서 ${skill}(${stage}) 이어가기`,
|
|
123
|
+
plan: ({ plan, item }) => `${plan} 다음 항목: ${item}`,
|
|
124
|
+
check: ({ id8, goal, where, doing }) => `${where}의 ${id8} 확인 (${goal})${doing ? `, 지금 ${doing}` : ""}`,
|
|
125
|
+
pickUp: ({ id8, goal, where }) => `${where}의 ${id8} 이어받기: ${goal}`,
|
|
126
|
+
start: () => "이 기간에 세션·계획이 없습니다. 시작할 일을 말해 주세요",
|
|
127
|
+
},
|
|
128
|
+
goLine: (say) => `**\`${say}\`** 라고 입력하면 이어갑니다.`,
|
|
129
|
+
noGo: "저절로 실행되는 단계는 아닙니다. 그 세션을 열거나 할 일을 말해 주세요.",
|
|
130
|
+
unknownSources: (list) => `읽지 못함: ${list}.`,
|
|
131
|
+
older: "오래된 세션은 읽지 않았습니다(읽기 예산 소진).",
|
|
132
|
+
noSessions: "이 기간의 Claude Code 세션 기록이 없습니다.",
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const duration = (ms) => {
|
|
137
|
+
const minutes = Math.max(0, Math.round(ms / 60_000));
|
|
138
|
+
if (minutes < 60) return `${minutes}m`;
|
|
139
|
+
const hours = Math.floor(minutes / 60);
|
|
140
|
+
if (hours < 48) return minutes % 60 ? `${hours}h ${minutes % 60}m` : `${hours}h`;
|
|
141
|
+
return `${Math.floor(hours / 24)}d`;
|
|
142
|
+
};
|
|
143
|
+
const when = (iso, now, w) => {
|
|
144
|
+
const at = Date.parse(iso);
|
|
145
|
+
if (!Number.isFinite(at)) return null;
|
|
146
|
+
return now - at < 60_000 ? w.justNow : w.ago(duration(now - at));
|
|
147
|
+
};
|
|
148
|
+
// `10-25 14:02`, in the machine's local time: a milestone's date.
|
|
149
|
+
const stamp = (iso) => {
|
|
150
|
+
const at = new Date(iso);
|
|
151
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
152
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
153
|
+
return `${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}`;
|
|
154
|
+
};
|
|
155
|
+
// Inline code that cannot be broken by a backtick inside the data.
|
|
156
|
+
const code = (text) => `\`${stripControls(text).replace(/`/gu, "'")}\``;
|
|
157
|
+
// One line of data as Markdown text: no line breaks, no tags, and its emphasis marks escaped.
|
|
158
|
+
// Every value printed passes through here or `code`, so a control sequence the collector missed
|
|
159
|
+
// (an older record, a hand-made fixture) still cannot reach the terminal.
|
|
160
|
+
const bare = (text) => stripControls(text).replace(/\s+/gu, " ").trim();
|
|
161
|
+
const plain = (text) => bare(text).replace(/[<>`]/gu, (ch) => ({ "<": "‹", ">": "›", "`": "'" }[ch])).replace(/[*_|[\]\\]/gu, (ch) => `\\${ch}`);
|
|
162
|
+
|
|
163
|
+
// The last question the session asked, from its last assistant words.
|
|
164
|
+
const lastQuestion = (result, escape = plain) => {
|
|
165
|
+
const text = String(result ?? "");
|
|
166
|
+
const found = [...text.matchAll(/[^.!?。?\n]{4,}[??]/gu)].at(-1)?.[0];
|
|
167
|
+
return found ? escape(clipToWidth(bare(found), 90)) : null;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const progressLine = (session, w) => {
|
|
171
|
+
if (session.progress?.gauge) {
|
|
172
|
+
const left = (session.progress.remaining ?? []).filter((name) => name !== "unknown");
|
|
173
|
+
return `${code(session.progress.gauge)}${left.length ? ` · ${w.later}: ${plain(left.slice(0, 2).join(", "))}${left.length > 2 ? ` (+${left.length - 2})` : ""}` : ""}`;
|
|
174
|
+
}
|
|
175
|
+
// A long transcript is read as its head and tail only, so counts of its calls would undercount;
|
|
176
|
+
// its first and last times and its last ask are exact.
|
|
177
|
+
const span = Date.parse(session.last) - Date.parse(session.started);
|
|
178
|
+
const ask = (session.asked ?? []).filter((text) => text && text !== "unknown").at(-1);
|
|
179
|
+
const facts = [
|
|
180
|
+
Number.isFinite(span) && span > 0 ? w.worked(duration(span)) : null,
|
|
181
|
+
ask ? w.lastAsk(plain(clipToWidth(bare(ask), 70))) : null,
|
|
182
|
+
].filter(Boolean);
|
|
183
|
+
return facts.length ? `⏳ ${facts.join(" · ")}` : null;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const doneLine = (session, w) => {
|
|
187
|
+
const files = (session.done?.files ?? []).slice(0, 3).map((file) => code(basename(String(file))));
|
|
188
|
+
const commits = (session.done?.commits ?? []).slice(0, 2).map(({ hash, subject }) => `${code(hash)} ${plain(clipToWidth(subject, 60))}`);
|
|
189
|
+
const parts = [files.length ? `${w.files} ${files.join(", ")}` : null, commits.length ? `${w.commits(session.done.commits.length)}: ${commits.join("; ")}` : null].filter(Boolean);
|
|
190
|
+
if (parts.length) return parts.join(" · ");
|
|
191
|
+
// Head-and-tail reads undercount calls, so tools are named, never counted.
|
|
192
|
+
const tools = Object.entries(session.done?.tools ?? {}).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([name]) => plain(name));
|
|
193
|
+
return tools.length ? w.toolsUsed(tools.join(", ")) : w.noneDone;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// What a session's last tool call was about, as `Bash “Run the gates”`.
|
|
197
|
+
const actionOf = (session, escape = plain) => {
|
|
198
|
+
const action = session.lastAction;
|
|
199
|
+
if (!action?.tool) return null;
|
|
200
|
+
return action.target ? `${escape(action.tool)} “${escape(clipToWidth(bare(action.target), 50))}”` : escape(action.tool);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const nextOf = (session, data, w) => {
|
|
204
|
+
const frames = (data.workflows ?? []).filter((frame) => frame.id8 === session.id8);
|
|
205
|
+
const paused = frames.find((frame) => frame.status === "paused");
|
|
206
|
+
if (paused) return w.resume(paused.skill, paused.stage, session.self);
|
|
207
|
+
if (session.waitingReason === "start-work boundary") return w.approve;
|
|
208
|
+
if (session.status === "waiting-on-user") {
|
|
209
|
+
const question = lastQuestion(session.result);
|
|
210
|
+
if (question) return w.answer(question);
|
|
211
|
+
}
|
|
212
|
+
const work = (data.startWork ?? []).find((item) => item.id8 === session.id8);
|
|
213
|
+
const plan = work ? (data.roadmap?.plans ?? []).find((item) => item.plan === work.plan) : null;
|
|
214
|
+
if (plan && plan.current) return w.planNow(code(plan.plan), plain(plan.current));
|
|
215
|
+
if (session.status === "active") {
|
|
216
|
+
if (frames.length) return `${frames.at(-1).skill} · ${frames.at(-1).stage}`;
|
|
217
|
+
const doing = actionOf(session);
|
|
218
|
+
return doing ? w.doing(doing) : w.working;
|
|
219
|
+
}
|
|
220
|
+
return w.nothing;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const sessionCard = (session, data, now, w) => {
|
|
224
|
+
const reason = session.waitingReason ? ` (${w.reason[session.waitingReason] ?? plain(session.waitingReason)})` : "";
|
|
225
|
+
const ago = when(session.last, now, w);
|
|
226
|
+
const head = `${w.badge[session.status] ?? w.badge.unknown}${reason} · ${code(session.id8)}${ago ? ` · ${ago}` : ""}${session.self ? ` · ${w.self}` : ""}`;
|
|
227
|
+
const goal = session.title && session.title !== "unknown" ? plain(session.title) : plain(session.asked?.[0] ?? "unknown");
|
|
228
|
+
const lines = [head, `**${goal}**`];
|
|
229
|
+
const progress = progressLine(session, w);
|
|
230
|
+
if (progress) lines.push(progress);
|
|
231
|
+
lines.push(`✅ ${w.done}: ${doneLine(session, w)}`);
|
|
232
|
+
lines.push(`▶ ${w.nextLabel}: ${nextOf(session, data, w)}`);
|
|
233
|
+
return lines.map((line) => `> ${line}`).join(" \n");
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const groupKey = (session) => `${session.worktree}\u0000${session.branch}`;
|
|
237
|
+
const placeOf = (session) => (session.worktree && session.worktree !== "unknown" ? basename(String(session.worktree)) : "unknown");
|
|
238
|
+
const goalOf = (session) => (session.title && session.title !== "unknown" ? session.title : session.asked?.[0] ?? "unknown");
|
|
239
|
+
|
|
240
|
+
// Ended sessions, one table row each, newest first: they are history, not something to read now.
|
|
241
|
+
const ENDED_ROWS = 8;
|
|
242
|
+
const endedTable = (sessions, now, w) => {
|
|
243
|
+
const cell = (text) => plain(text) || "·";
|
|
244
|
+
const rows = sessions.slice(0, ENDED_ROWS).map((session) => {
|
|
245
|
+
const commits = session.done?.commits?.length ?? 0;
|
|
246
|
+
const files = session.done?.files?.length ?? 0;
|
|
247
|
+
// Short cells, so a row stays one line in a 120-column terminal: the age to the largest unit.
|
|
248
|
+
const done = commits ? w.commits(commits) : files ? w.fileCount(files) : "·";
|
|
249
|
+
const at = Date.parse(session.last);
|
|
250
|
+
const age = Number.isFinite(at) ? duration(now - at).split(" ")[0] : "·";
|
|
251
|
+
return `| ${code(session.id8)} | ${cell(clipToWidth(placeOf(session), 20))} | ${cell(clipToWidth(goalOf(session), 44))} | ${cell(age)} | ${cell(done)} |`;
|
|
252
|
+
});
|
|
253
|
+
const head = `| ${w.endedHead.join(" | ")} |`;
|
|
254
|
+
const rule = `|${w.endedHead.map(() => "---").join("|")}|`;
|
|
255
|
+
const more = sessions.length > ENDED_ROWS ? ["", `*${w.moreEnded(sessions.length - ENDED_ROWS)}*`] : [];
|
|
256
|
+
return [head, rule, ...rows, ...more];
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// When no step can run on `go`, the brief still recommends one from what it read, in this order:
|
|
260
|
+
// a session that waits on the user, a paused workflow, the next item of an open plan,
|
|
261
|
+
// the most recent other active session, the most recent ended one. It is shown, never recorded.
|
|
262
|
+
const suggestion = (data, w) => {
|
|
263
|
+
// Raw text: the headline escapes it once, the box shows it inside a code block.
|
|
264
|
+
const sessions = data.sessions ?? [];
|
|
265
|
+
const where = (session) => bare(placeOf(session));
|
|
266
|
+
const goal = (session) => clipToWidth(bare(goalOf(session)), 50);
|
|
267
|
+
const waiting = sessions.find((session) => session.status === "waiting-on-user" && !session.self);
|
|
268
|
+
if (waiting) return w.suggest.answer({ id8: waiting.id8, where: where(waiting), question: lastQuestion(waiting.result, bare) });
|
|
269
|
+
const paused = (data.workflows ?? []).find((frame) => frame.status === "paused");
|
|
270
|
+
const owner = paused ? sessions.find((session) => session.id8 === paused.id8) : null;
|
|
271
|
+
if (paused) return w.suggest.resume({ id8: paused.id8, skill: paused.skill, stage: paused.stage, where: owner ? where(owner) : basename(String(paused.worktree)) });
|
|
272
|
+
// A plan in the worktree of a live session comes first, then this worktree's, then the newest.
|
|
273
|
+
const liveTrees = new Set(sessions.filter((session) => session.status !== "ended").map((session) => session.worktree));
|
|
274
|
+
const open = (data.roadmap?.plans ?? []).filter((item) => item.current);
|
|
275
|
+
const plan = open.find((item) => liveTrees.has(item.worktree)) ?? open.find((item) => item.local) ?? open[0];
|
|
276
|
+
if (plan) return w.suggest.plan({ plan: plan.local ? plan.plan : `${basename(String(plan.worktree))}/${plan.plan}`, item: clipToWidth(bare(plan.current), 60) });
|
|
277
|
+
const active = sessions.find((session) => session.status === "active" && !session.self);
|
|
278
|
+
if (active) return w.suggest.check({ id8: active.id8, goal: goal(active), where: where(active), doing: actionOf(active, bare) });
|
|
279
|
+
const ended = sessions.find((session) => session.status === "ended" && !session.self);
|
|
280
|
+
if (ended) return w.suggest.pickUp({ id8: ended.id8, goal: goal(ended), where: where(ended) });
|
|
281
|
+
return w.suggest.start();
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// The roadmap timeline: finished commits with their dates, then the current item and gauge of each
|
|
285
|
+
// open plan of this worktree or one under way elsewhere (an untouched plan of another worktree is
|
|
286
|
+
// only counted), then what comes after it, then litgoal objectives.
|
|
287
|
+
const ROADMAP_PLANS = 4;
|
|
288
|
+
const roadmapLines = (data, w) => {
|
|
289
|
+
const lines = [];
|
|
290
|
+
for (const commit of (data.commits ?? []).slice(0, 5).reverse()) {
|
|
291
|
+
lines.push(`- ✓ ${stamp(commit.at)} · ${code(commit.branch)} ${plain(clipToWidth(commit.subject, 70))}`);
|
|
292
|
+
}
|
|
293
|
+
const plans = data.roadmap?.plans ?? [];
|
|
294
|
+
const shownPlans = plans.slice(0, ROADMAP_PLANS);
|
|
295
|
+
const omitted = plans.length - shownPlans.length + (data.roadmap?.plansOmitted ?? 0);
|
|
296
|
+
for (const plan of shownPlans) {
|
|
297
|
+
const where = plan.local ? "" : `${code(basename(String(plan.worktree)))} `;
|
|
298
|
+
lines.push(`- ▶ **${w.now}** · ${where}${code(plan.plan)} ${plan.progress?.gauge ? code(plan.progress.gauge) : ""} → ${plain(plan.current)}`);
|
|
299
|
+
const later = (plan.progress?.remaining ?? []).filter((name) => name !== "unknown" && name !== plan.current).slice(0, 2);
|
|
300
|
+
for (const item of later) lines.push(` - ○ ${w.later} · ${plain(item)}`);
|
|
301
|
+
}
|
|
302
|
+
if (omitted > 0) lines.push(`- ${w.morePlans(omitted)}`);
|
|
303
|
+
for (const goal of data.roadmap?.litgoal ?? []) {
|
|
304
|
+
const mark = goal.status === "complete" ? "✓" : "▶";
|
|
305
|
+
lines.push(`- ${mark} litgoal ${goal.progress?.gauge ? code(goal.progress.gauge) : ""} ${plain(goal.objective)}`);
|
|
306
|
+
}
|
|
307
|
+
return lines.length ? lines : [w.noRoadmap];
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// A box the width of its longest line, padded by display width so Hangul keeps the right edge.
|
|
311
|
+
const box = (title, body) => {
|
|
312
|
+
const width = Math.max(displayWidth(title) + 2, ...body.map((line) => displayWidth(line))) + 2;
|
|
313
|
+
const pad = (line) => `${line}${" ".repeat(Math.max(0, width - 2 - displayWidth(line)))}`;
|
|
314
|
+
return ["```text", `╭─ ${title} ${"─".repeat(Math.max(1, width - displayWidth(title) - 3))}╮`, ...body.map((line) => `│ ${pad(line)} │`), `╰${"─".repeat(width)}╯`, "```"].join("\n");
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// Wraps a step to the box at word breaks, three lines at most, the last one clipped.
|
|
318
|
+
const wrap = (text, width, lines = 3) => {
|
|
319
|
+
const out = [""];
|
|
320
|
+
for (const word of bare(text).split(" ")) {
|
|
321
|
+
const joined = out.at(-1) ? `${out.at(-1)} ${word}` : word;
|
|
322
|
+
if (displayWidth(joined) <= width || !out.at(-1)) out[out.length - 1] = joined;
|
|
323
|
+
else out.push(word);
|
|
324
|
+
}
|
|
325
|
+
const kept = out.slice(0, lines);
|
|
326
|
+
if (out.length > lines) kept[lines - 1] = `${kept[lines - 1]} ${out.slice(lines).join(" ")}`;
|
|
327
|
+
return kept.map((line) => clipToWidth(line, width));
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const stepText = (next, w) => {
|
|
331
|
+
const target = next?.target ?? {};
|
|
332
|
+
const describe = w.stepKind[next?.kind] ?? w.stepKind.none;
|
|
333
|
+
return bare(describe({ skill: target.skill, stage: target.stage, plan: target.plan, action: target.action, root: target.root }));
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/** The brief as Markdown. `lang` is `ko` or `en`; `now` the clock the relative times use. */
|
|
337
|
+
export const renderBrief = (data, { lang = "en", now = Date.parse(data.generatedAt) || Date.now(), width = 72 } = {}) => {
|
|
338
|
+
const w = WORDS[lang] ?? WORDS.en;
|
|
339
|
+
const sessions = data.sessions ?? [];
|
|
340
|
+
const summary = data.summary ?? { sessions: sessions.length, waitingOnUser: 0, active: 0 };
|
|
341
|
+
const step = data.next?.kind && data.next.kind !== "none" ? stepText(data.next, w) : bare(suggestion(data, w));
|
|
342
|
+
const out = [];
|
|
343
|
+
out.push(`## 🧭 ${[w.sessions(summary.sessions), w.waiting(summary.waitingOnUser), w.active(summary.active)].join(" · ")} · ${w.next}: ${plain(step)}`);
|
|
344
|
+
out.push(`*${w.window(data.scope?.since ?? "7d", (data.scope?.worktrees ?? []).length || 1)}*`);
|
|
345
|
+
if (!sessions.length) out.push("", w.noSessions);
|
|
346
|
+
// Sessions that are live or wait on the user come first, as full cards grouped by worktree.
|
|
347
|
+
const live = sessions.filter((session) => session.status !== "ended");
|
|
348
|
+
const ended = sessions.filter((session) => session.status === "ended");
|
|
349
|
+
const groups = new Map();
|
|
350
|
+
for (const session of live) {
|
|
351
|
+
const key = groupKey(session);
|
|
352
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
353
|
+
groups.get(key).push(session);
|
|
354
|
+
}
|
|
355
|
+
for (const list of groups.values()) {
|
|
356
|
+
const { worktree, branch } = list[0];
|
|
357
|
+
const name = worktree && worktree !== "unknown" ? basename(String(worktree)) : "unknown";
|
|
358
|
+
out.push("", `### 🌿 ${code(branch ?? "unknown")} · ${plain(name)}`);
|
|
359
|
+
for (const session of list) out.push("", sessionCard(session, data, now, w));
|
|
360
|
+
}
|
|
361
|
+
if (ended.length) out.push("", `### ⚪ ${w.endedTitle(ended.length)}`, "", ...endedTable(ended, now, w));
|
|
362
|
+
out.push("", `### 🗺️ ${w.roadmap}${data.roadmap?.progress?.gauge ? ` ${code(data.roadmap.progress.gauge)}` : ""}`, "", ...roadmapLines(data, w));
|
|
363
|
+
const say = data.next?.say ?? null;
|
|
364
|
+
const body = wrap(step, width - 4);
|
|
365
|
+
if (data.next?.command) body.push(clipToWidth(data.next.command, width - 4));
|
|
366
|
+
if (say) body.push(`${w.type}: ${say}`);
|
|
367
|
+
out.push("", box(w.recommended, body));
|
|
368
|
+
out.push("", say ? w.goLine(say) : w.noGo);
|
|
369
|
+
const unknown = Object.entries(data.sources ?? {}).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
370
|
+
const notes = [unknown.length ? w.unknownSources(unknown.join(", ")) : null, data.budget?.exhausted ? w.older : null].filter(Boolean);
|
|
371
|
+
if (notes.length) out.push("", `*${notes.join(" ")}*`);
|
|
372
|
+
return `${out.join("\n")}\n`;
|
|
373
|
+
};
|