@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Outside folders a plan's todos name must be granted before the work starts, so a lane never stops
|
|
2
|
+
// to ask the user for them. start-work reads `Scope roots:` lines with SCOPE_LINE; lit-plan's checks
|
|
3
|
+
// use uncoveredScopePaths to name each todo path no such line covers, with the line to paste.
|
|
4
|
+
import { realpathSync, statSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
import { planLinesOutsideFences } from "./plan-task-rows.mjs";
|
|
9
|
+
|
|
10
|
+
// `Scope roots: <path> (<action>, <action>)` lines in the plan widen the grants it starts with.
|
|
11
|
+
// Global, for `matchAll` only: `.test()` or `.exec()` on this shared object would carry `lastIndex`.
|
|
12
|
+
export const SCOPE_LINE = /^Scope roots?:[ \t]*(\S+)[ \t]*\(([a-z, -]+)\)[ \t]*$/gmu;
|
|
13
|
+
|
|
14
|
+
// An absolute path of two or more segments. A command quoted in an inline code span (it holds a
|
|
15
|
+
// space) is data, not a folder the work reaches, so only spans that are one path count.
|
|
16
|
+
const PATH_TOKEN = /(?<![\w.~\/-])\/[\w.@+%,=~-]+(?:\/[\w.@+%,=~-]+)+\/?/gu;
|
|
17
|
+
const pathMentions = (line) => line.replace(/`([^`]*)`/gu, (_, span) => (/\s/u.test(span.trim()) ? " " : ` ${span.trim()} `)).match(PATH_TOKEN) ?? [];
|
|
18
|
+
|
|
19
|
+
const covers = (root, path) => {
|
|
20
|
+
const inside = relative(root, path);
|
|
21
|
+
return inside === "" || (!inside.startsWith("..") && !isAbsolute(inside));
|
|
22
|
+
};
|
|
23
|
+
const real = (path) => {
|
|
24
|
+
try {
|
|
25
|
+
return realpathSync(path);
|
|
26
|
+
} catch {
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const nearestDirectory = (path) => {
|
|
31
|
+
for (let at = path; ; at = dirname(at)) {
|
|
32
|
+
try {
|
|
33
|
+
if (statSync(at).isDirectory()) return at;
|
|
34
|
+
} catch {
|
|
35
|
+
// Not there yet; climb.
|
|
36
|
+
}
|
|
37
|
+
if (dirname(at) === at) return at;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Each absolute path under `## Todos` (before `## Final verification wave`, outside fences) that
|
|
43
|
+
* lies outside the project and outside every `Scope roots:` line, as `{ path, suggestion }` with
|
|
44
|
+
* the line to paste, or `{ path, problem }` when the nearest existing folder is too broad to grant.
|
|
45
|
+
* One entry per folder.
|
|
46
|
+
*/
|
|
47
|
+
export const uncoveredScopePaths = (planText, projectRoot) => {
|
|
48
|
+
const project = real(resolve(projectRoot));
|
|
49
|
+
const scoped = [...planText.matchAll(SCOPE_LINE)].map(([, path]) => real(isAbsolute(path) ? path : resolve(project, path)));
|
|
50
|
+
let inTodos = false;
|
|
51
|
+
const found = new Map();
|
|
52
|
+
for (const { line } of planLinesOutsideFences(planText)) {
|
|
53
|
+
const heading = line.trimEnd();
|
|
54
|
+
if (heading === "## Todos") inTodos = true;
|
|
55
|
+
else if (heading === "## Final verification wave") inTodos = false;
|
|
56
|
+
if (!inTodos) continue;
|
|
57
|
+
for (const mention of pathMentions(line)) {
|
|
58
|
+
const path = mention.replace(/[.,:;)]+$/u, "");
|
|
59
|
+
const directory = real(nearestDirectory(path));
|
|
60
|
+
if ([path, directory].some((candidate) => covers(project, real(candidate)) || scoped.some((root) => covers(root, real(candidate))))) continue;
|
|
61
|
+
if (found.has(directory)) continue;
|
|
62
|
+
// The filesystem root, a top-level folder or the home folder itself is never suggested.
|
|
63
|
+
const parent = dirname(directory);
|
|
64
|
+
const tooBroad = parent === dirname(parent) || directory === real(homedir());
|
|
65
|
+
found.set(directory, tooBroad
|
|
66
|
+
? { path, problem: `${path} is outside the project; name a narrower existing folder on a Scope roots line` }
|
|
67
|
+
: { path, suggestion: `Scope roots: ${directory} (read)` });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return [...found.values()];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const describeScopePath = (entry) => entry.suggestion
|
|
74
|
+
? `${entry.path} is outside the project and no Scope roots line covers it; add: ${entry.suggestion}`
|
|
75
|
+
: entry.problem;
|
|
76
|
+
|
|
@@ -25,8 +25,21 @@ export const planLinesOutsideFences = (text) => {
|
|
|
25
25
|
return visible;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
// A task waits on the user when its line holds `BLOCKED:` outside inline code, or an indented body
|
|
29
|
+
// line under it starts with `BLOCKED:`. A mention such as `BLOCKED:` in backticks is not a marker.
|
|
30
|
+
const blockedLine = (line) => /\bBLOCKED:/u.test(line.replace(/`[^`]*`/gu, ""));
|
|
31
|
+
const blockedBodyLine = (line) => /^[ \t]+(?:[-*][ \t]+)?BLOCKED:/u.test(line);
|
|
32
|
+
|
|
28
33
|
/** Parse the exact column-zero checkbox grammar consumed by start-work. */
|
|
29
|
-
export const parsePlanTaskRows = (text) =>
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
|
|
34
|
+
export const parsePlanTaskRows = (text) => {
|
|
35
|
+
const visible = planLinesOutsideFences(text);
|
|
36
|
+
return visible.flatMap(({ line, index }, at) => {
|
|
37
|
+
const match = /^- \[([ xX])\]\s+(.+?)\s*$/u.exec(line);
|
|
38
|
+
if (!match) return [];
|
|
39
|
+
let blocked = blockedLine(match[2]);
|
|
40
|
+
for (let next = at + 1; !blocked && next < visible.length && /^(?:[ \t]|$)/u.test(visible[next].line); next += 1) {
|
|
41
|
+
blocked = blockedBodyLine(visible[next].line);
|
|
42
|
+
}
|
|
43
|
+
return [{ checked: match[1].toLowerCase() === "x", text: match[2], line, index, ...(blocked ? { blocked } : {}) }];
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -17,7 +17,8 @@ const WORDS = {
|
|
|
17
17
|
active: (n) => `${n} active`,
|
|
18
18
|
next: "next",
|
|
19
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" },
|
|
20
|
+
badge: { "waiting-on-user": "🟠 **WAITING ON YOU**", active: "🟢 **ACTIVE**", idle: "💤 idle", done: "✅ done", ended: "⚪ ended", unknown: "⚫ unknown" },
|
|
21
|
+
runDone: (plan) => `start-work finished ${plan}`,
|
|
21
22
|
reason: { "asked the user": "it asked you something", "paused workflow": "paused workflow", "start-work boundary": "start-work needs approval" },
|
|
22
23
|
ago: (text) => `${text} ago`,
|
|
23
24
|
justNow: "just now",
|
|
@@ -63,13 +64,16 @@ const WORDS = {
|
|
|
63
64
|
plan: ({ plan, item }) => `Next in ${plan}: ${item}`,
|
|
64
65
|
check: ({ id8, goal, where, doing }) => `Check on ${id8} in ${where} (${goal})${doing ? `, now ${doing}` : ""}`,
|
|
65
66
|
pickUp: ({ id8, goal, where }) => `Pick up ${id8} in ${where}: ${goal}`,
|
|
67
|
+
review: ({ id8, where, plan }) => `Review what ${id8} finished in ${where}: ${plan}`,
|
|
66
68
|
start: () => "No session or plan in this window: say what to start",
|
|
67
69
|
},
|
|
68
70
|
goLine: (say) => `Type **\`${say}\`** to continue.`,
|
|
69
71
|
noGo: "Nothing runs on its own here: open that session, or say what to do.",
|
|
70
72
|
unknownSources: (list) => `Not read: ${list}.`,
|
|
71
73
|
older: "Older sessions were not read (read budget used up).",
|
|
74
|
+
plansSkipped: (n) => `${n} ${n === 1 ? "plan was" : "plans were"} not read (read budget used up).`,
|
|
72
75
|
noSessions: "No Claude Code session records in this window.",
|
|
76
|
+
opener: { done: "Done so far", doing: "Doing now", next: "Next", nothingDone: "nothing finished in this window", nothingRunning: "nothing running", type: (say) => `(type ${say})`, finishedRun: (plan) => `${plan} (start-work complete)` },
|
|
73
77
|
},
|
|
74
78
|
ko: {
|
|
75
79
|
sessions: (n) => `세션 ${n}개`,
|
|
@@ -77,7 +81,8 @@ const WORDS = {
|
|
|
77
81
|
active: (n) => `진행 중 ${n}`,
|
|
78
82
|
next: "다음",
|
|
79
83
|
window: (since, trees) => `최근 ${since} · 워크트리 ${trees}개`,
|
|
80
|
-
badge: { "waiting-on-user": "🟠 **나를 기다림**", active: "🟢 **진행 중**", ended: "⚪ 끝남", unknown: "⚫ 모름" },
|
|
84
|
+
badge: { "waiting-on-user": "🟠 **나를 기다림**", active: "🟢 **진행 중**", idle: "💤 쉬는 중", done: "✅ 완료", ended: "⚪ 끝남", unknown: "⚫ 모름" },
|
|
85
|
+
runDone: (plan) => `${plan} start-work 완료`,
|
|
81
86
|
reason: { "asked the user": "질문에 답을 기다림", "paused workflow": "멈춘 워크플로", "start-work boundary": "start-work 승인 대기" },
|
|
82
87
|
ago: (text) => `${text} 전`,
|
|
83
88
|
justNow: "방금",
|
|
@@ -123,12 +128,15 @@ const WORDS = {
|
|
|
123
128
|
plan: ({ plan, item }) => `${plan} 다음 항목: ${item}`,
|
|
124
129
|
check: ({ id8, goal, where, doing }) => `${where}의 ${id8} 확인 (${goal})${doing ? `, 지금 ${doing}` : ""}`,
|
|
125
130
|
pickUp: ({ id8, goal, where }) => `${where}의 ${id8} 이어받기: ${goal}`,
|
|
131
|
+
review: ({ id8, where, plan }) => `${where}의 ${id8}가 끝낸 ${plan} 검토하기`,
|
|
126
132
|
start: () => "이 기간에 세션·계획이 없습니다. 시작할 일을 말해 주세요",
|
|
127
133
|
},
|
|
128
134
|
goLine: (say) => `**\`${say}\`** 라고 입력하면 이어갑니다.`,
|
|
129
135
|
noGo: "저절로 실행되는 단계는 아닙니다. 그 세션을 열거나 할 일을 말해 주세요.",
|
|
130
136
|
unknownSources: (list) => `읽지 못함: ${list}.`,
|
|
131
137
|
older: "오래된 세션은 읽지 않았습니다(읽기 예산 소진).",
|
|
138
|
+
plansSkipped: (n) => `계획 ${n}개는 읽지 못했습니다(읽기 예산 소진).`,
|
|
139
|
+
opener: { done: "지금까지", doing: "지금", next: "다음", nothingDone: "이 기간에 끝낸 일 없음", nothingRunning: "실행 중인 일 없음", type: (say) => `(${say} 입력)`, finishedRun: (plan) => `${plan} (start-work 완료)` },
|
|
132
140
|
noSessions: "이 기간의 Claude Code 세션 기록이 없습니다.",
|
|
133
141
|
},
|
|
134
142
|
};
|
|
@@ -212,6 +220,8 @@ const nextOf = (session, data, w) => {
|
|
|
212
220
|
const work = (data.startWork ?? []).find((item) => item.id8 === session.id8);
|
|
213
221
|
const plan = work ? (data.roadmap?.plans ?? []).find((item) => item.plan === work.plan) : null;
|
|
214
222
|
if (plan && plan.current) return w.planNow(code(plan.plan), plain(plan.current));
|
|
223
|
+
// A finished or idle session's last tool call is history, never its next step.
|
|
224
|
+
if (session.status === "done") return session.finishedPlan ? w.runDone(code(session.finishedPlan)) : w.nothing;
|
|
215
225
|
if (session.status === "active") {
|
|
216
226
|
if (frames.length) return `${frames.at(-1).skill} · ${frames.at(-1).stage}`;
|
|
217
227
|
const doing = actionOf(session);
|
|
@@ -276,8 +286,11 @@ const suggestion = (data, w) => {
|
|
|
276
286
|
if (plan) return w.suggest.plan({ plan: plan.local ? plan.plan : `${basename(String(plan.worktree))}/${plan.plan}`, item: clipToWidth(bare(plan.current), 60) });
|
|
277
287
|
const active = sessions.find((session) => session.status === "active" && !session.self);
|
|
278
288
|
if (active) return w.suggest.check({ id8: active.id8, goal: goal(active), where: where(active), doing: actionOf(active, bare) });
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
// Otherwise the newest listed session that is not running: review what a done one finished, or pick
|
|
290
|
+
// up an idle or ended one. Only an empty window says there is nothing.
|
|
291
|
+
const settled = sessions.find((session) => ["done", "idle", "ended"].includes(session.status) && !session.self);
|
|
292
|
+
if (settled?.status === "done") return w.suggest.review({ id8: settled.id8, where: where(settled), plan: settled.finishedPlan ? bare(settled.finishedPlan) : goal(settled) });
|
|
293
|
+
if (settled) return w.suggest.pickUp({ id8: settled.id8, goal: goal(settled), where: where(settled) });
|
|
281
294
|
return w.suggest.start();
|
|
282
295
|
};
|
|
283
296
|
|
|
@@ -311,7 +324,7 @@ const roadmapLines = (data, w) => {
|
|
|
311
324
|
const box = (title, body) => {
|
|
312
325
|
const width = Math.max(displayWidth(title) + 2, ...body.map((line) => displayWidth(line))) + 2;
|
|
313
326
|
const pad = (line) => `${line}${" ".repeat(Math.max(0, width - 2 - displayWidth(line)))}`;
|
|
314
|
-
return ["```
|
|
327
|
+
return ["```", `╭─ ${title} ${"─".repeat(Math.max(1, width - displayWidth(title) - 3))}╮`, ...body.map((line) => `│ ${pad(line)} │`), `╰${"─".repeat(width)}╯`, "```"].join("\n");
|
|
315
328
|
};
|
|
316
329
|
|
|
317
330
|
// Wraps a step to the box at word breaks, three lines at most, the last one clipped.
|
|
@@ -333,13 +346,50 @@ const stepText = (next, w) => {
|
|
|
333
346
|
return bare(describe({ skill: target.skill, stage: target.stage, plan: target.plan, action: target.action, root: target.root }));
|
|
334
347
|
};
|
|
335
348
|
|
|
349
|
+
// The three lines that open the brief, from records only. Done: this worktree's newest commits in
|
|
350
|
+
// the window (two at most), then its completed start-work runs and its plans with every row ticked
|
|
351
|
+
// (three items at most), else its finished litgoal. Doing: this session's top frame, else its
|
|
352
|
+
// running start-work, else the newest active session's title. Next: the step and the word to type.
|
|
353
|
+
const openerLines = (data, step, w) => {
|
|
354
|
+
const local = data.scope?.worktrees?.[0];
|
|
355
|
+
const subjects = (data.commits ?? []).filter((commit) => commit.worktree === local).slice(0, 2).map((commit) => plain(commit.subject));
|
|
356
|
+
const runs = (data.finished?.runs ?? []).filter((run) => run.worktree === local);
|
|
357
|
+
const runPlans = new Set(runs.map((run) => run.plan));
|
|
358
|
+
const finished = [
|
|
359
|
+
...runs.map((run) => w.opener.finishedRun(code(run.plan))),
|
|
360
|
+
...(data.finished?.plans ?? []).filter((plan) => plan.worktree === local && !runPlans.has(plan.plan)).map((plan) => `${code(plan.plan)}${plan.gauge ? ` ${code(plan.gauge)}` : ""}`),
|
|
361
|
+
];
|
|
362
|
+
const items = [...subjects, ...[...new Set(finished)]].slice(0, 3);
|
|
363
|
+
const finishedGoal = (data.roadmap?.litgoal ?? []).find((goal) => goal.local && goal.status === "complete");
|
|
364
|
+
const done = items.length ? items.join("; ") : finishedGoal ? plain(finishedGoal.objective) : w.opener.nothingDone;
|
|
365
|
+
const sessions = data.sessions ?? [];
|
|
366
|
+
const selfId = sessions.find((session) => session.self)?.id8 ?? null;
|
|
367
|
+
const frame = (data.workflows ?? []).filter((item) => item.self || (selfId && item.id8 === selfId)).at(-1);
|
|
368
|
+
const work = (data.startWork ?? []).find((item) => item.self && item.status === "active");
|
|
369
|
+
const active = sessions.find((session) => session.status === "active");
|
|
370
|
+
const gaugeOf = (progress) => (progress?.gauge ? code(progress.gauge) : null);
|
|
371
|
+
const doing = frame
|
|
372
|
+
? [frame.skill, frame.stage, gaugeOf(frame.progress)].filter((part) => part && part !== "unknown").join(" · ")
|
|
373
|
+
: work
|
|
374
|
+
? ["start-work", work.plan, gaugeOf(work.progress)].filter(Boolean).join(" · ")
|
|
375
|
+
: active ? plain(clipToWidth(goalOf(active), 80)) : w.opener.nothingRunning;
|
|
376
|
+
const say = data.next?.say ?? null;
|
|
377
|
+
return [
|
|
378
|
+
`${w.opener.done}: ${done} `,
|
|
379
|
+
`${w.opener.doing}: ${doing} `,
|
|
380
|
+
`${w.opener.next}: ${plain(step)}${say ? ` ${w.opener.type(say)}` : ""}`,
|
|
381
|
+
];
|
|
382
|
+
};
|
|
383
|
+
|
|
336
384
|
/** The brief as Markdown. `lang` is `ko` or `en`; `now` the clock the relative times use. */
|
|
337
385
|
export const renderBrief = (data, { lang = "en", now = Date.parse(data.generatedAt) || Date.now(), width = 72 } = {}) => {
|
|
338
386
|
const w = WORDS[lang] ?? WORDS.en;
|
|
339
387
|
const sessions = data.sessions ?? [];
|
|
340
388
|
const summary = data.summary ?? { sessions: sessions.length, waitingOnUser: 0, active: 0 };
|
|
341
|
-
|
|
342
|
-
const
|
|
389
|
+
// With no step for `go`, this worktree's HANDOFF.md Next item comes before the generic suggestion.
|
|
390
|
+
const handoffNext = (data.handoffs ?? []).find((handoff) => handoff.local && handoff.next)?.next ?? null;
|
|
391
|
+
const step = data.next?.kind && data.next.kind !== "none" ? stepText(data.next, w) : bare(handoffNext ?? suggestion(data, w));
|
|
392
|
+
const out = [...openerLines(data, step, w), ""];
|
|
343
393
|
out.push(`## 🧭 ${[w.sessions(summary.sessions), w.waiting(summary.waitingOnUser), w.active(summary.active)].join(" · ")} · ${w.next}: ${plain(step)}`);
|
|
344
394
|
out.push(`*${w.window(data.scope?.since ?? "7d", (data.scope?.worktrees ?? []).length || 1)}*`);
|
|
345
395
|
if (!sessions.length) out.push("", w.noSessions);
|
|
@@ -367,7 +417,11 @@ export const renderBrief = (data, { lang = "en", now = Date.parse(data.generated
|
|
|
367
417
|
out.push("", box(w.recommended, body));
|
|
368
418
|
out.push("", say ? w.goLine(say) : w.noGo);
|
|
369
419
|
const unknown = Object.entries(data.sources ?? {}).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
370
|
-
const notes = [
|
|
420
|
+
const notes = [
|
|
421
|
+
unknown.length ? w.unknownSources(unknown.join(", ")) : null,
|
|
422
|
+
data.budget?.exhausted ? w.older : null,
|
|
423
|
+
data.roadmap?.plansSkipped > 0 ? w.plansSkipped(data.roadmap.plansSkipped) : null,
|
|
424
|
+
].filter(Boolean);
|
|
371
425
|
if (notes.length) out.push("", `*${notes.join(" ")}*`);
|
|
372
426
|
return `${out.join("\n")}\n`;
|
|
373
427
|
};
|
|
@@ -89,24 +89,30 @@ const mtimeOf = (path) => {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
// A plan met after the read budget ran out is counted in `skipped.count`, so the brief can say so.
|
|
93
|
+
const plansIn = (root, budget, redact, local, skipped = { count: 0 }) => {
|
|
93
94
|
const list = entries(join(root, "plans"));
|
|
94
95
|
if (!list) return null;
|
|
95
96
|
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".md")).sort((a, b) => a.name.localeCompare(b.name)).flatMap((entry) => {
|
|
97
|
+
if (budget.used >= budget.limit) {
|
|
98
|
+
skipped.count += 1;
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
96
101
|
const text = readSmallFile(join(root, "plans", entry.name), budget);
|
|
97
102
|
if (text === null) return [];
|
|
98
103
|
const rows = parsePlanTaskRows(text);
|
|
99
104
|
if (!rows.length || isTemplate(rows)) return [];
|
|
100
105
|
const open = rows.filter((row) => !row.checked);
|
|
101
|
-
if (!open.length) return [];
|
|
102
106
|
const done = rows.length - open.length;
|
|
107
|
+
// A plan with every row ticked is kept, marked complete: it is finished work, not roadmap.
|
|
103
108
|
return [{
|
|
104
109
|
worktree: redact(root),
|
|
105
110
|
plan: `plans/${entry.name}`,
|
|
106
111
|
local,
|
|
112
|
+
complete: open.length === 0,
|
|
107
113
|
changedMs: mtimeOf(join(root, "plans", entry.name)),
|
|
108
114
|
rows: rows.map((row) => ({ checked: row.checked, title: clipToWidth(redact(row.text), NAME_MAX) })),
|
|
109
|
-
current: clipToWidth(redact(open[0].text), NAME_MAX),
|
|
115
|
+
current: open.length ? clipToWidth(redact(open[0].text), NAME_MAX) : null,
|
|
110
116
|
progress: progressOf(done, rows.length, open.map((row) => clipToWidth(redact(row.text), NAME_MAX))),
|
|
111
117
|
}];
|
|
112
118
|
});
|
|
@@ -125,12 +131,27 @@ const litgoalOf = (root, budget, redact) => {
|
|
|
125
131
|
};
|
|
126
132
|
};
|
|
127
133
|
|
|
128
|
-
|
|
134
|
+
// The first list item or line of text under a `## Next` or `## Next Steps` heading, without its marker.
|
|
135
|
+
const handoffNext = (text) => {
|
|
136
|
+
const lines = text.split("\n");
|
|
137
|
+
const start = lines.findIndex((line) => /^#{1,6}\s+Next(?:\s+Steps)?\s*$/iu.test(line.trim()));
|
|
138
|
+
if (start < 0) return null;
|
|
139
|
+
for (const line of lines.slice(start + 1)) {
|
|
140
|
+
if (/^#{1,6}\s/u.test(line.trim())) return null;
|
|
141
|
+
const item = line.trim().replace(/^(?:[-*+]|\d+[.)])\s+/u, "");
|
|
142
|
+
if (item) return item;
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Only this worktree's own HANDOFF files give a next step (`next`); another worktree's never does.
|
|
148
|
+
const handoffsOf = (root, budget, redact, local = false) => (entries(root) ?? [])
|
|
129
149
|
.filter((entry) => entry.isFile() && /^HANDOFF.*\.md$/u.test(entry.name))
|
|
130
150
|
.map((entry) => {
|
|
131
151
|
const text = readSmallFile(join(root, entry.name), budget) ?? "";
|
|
132
152
|
const headings = text.split("\n").slice(0, 40).filter((line) => /^#{1,3} /u.test(line)).map((line) => clipToWidth(redact(line), 100));
|
|
133
|
-
|
|
153
|
+
const next = local ? handoffNext(text) : null;
|
|
154
|
+
return { worktree: redact(root), file: entry.name, headings, local, next: next ? clipToWidth(redact(next), 120) : null };
|
|
134
155
|
});
|
|
135
156
|
|
|
136
157
|
const commitsOf = (root, sinceMs, now, exec, redact) => {
|
|
@@ -192,6 +213,37 @@ const startWorkOf = (root, budget, redact) => {
|
|
|
192
213
|
}];
|
|
193
214
|
};
|
|
194
215
|
|
|
216
|
+
// start-work runs this lifecycle completed, from its history: which plan, which session, and when.
|
|
217
|
+
const completedRunsOf = (root, budget, redact) => {
|
|
218
|
+
const state = readJson(join(root, ".litclaude", "boulder.json"), budget);
|
|
219
|
+
if (!state || !Array.isArray(state.history)) return null;
|
|
220
|
+
return state.history.filter((entry) => entry?.status === "completed" && typeof entry.plan === "string").map((entry) => ({
|
|
221
|
+
worktree: redact(root),
|
|
222
|
+
plan: `plans/${basename(entry.plan)}`,
|
|
223
|
+
sessionId: state.works?.[entry.work_id]?.root_session_id ?? null,
|
|
224
|
+
atMs: Date.parse(entry.terminal_at),
|
|
225
|
+
})).filter((run) => Number.isFinite(run.atMs));
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// Each session's last hook event (session-liveness.mjs): `alive`, `idle` or `ended`, newest first.
|
|
229
|
+
const LIVENESS_FILES = 24;
|
|
230
|
+
const livenessOf = (root, budget) => {
|
|
231
|
+
const directory = join(root, ".litclaude", "liveness");
|
|
232
|
+
const list = entries(directory);
|
|
233
|
+
if (!list) return null;
|
|
234
|
+
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
235
|
+
.map((entry) => ({ entry, at: mtimeOf(join(directory, entry.name)) ?? 0 }))
|
|
236
|
+
.sort((a, b) => b.at - a.at)
|
|
237
|
+
.slice(0, LIVENESS_FILES)
|
|
238
|
+
.flatMap(({ entry }) => {
|
|
239
|
+
const record = readJson(join(directory, entry.name), budget);
|
|
240
|
+
const atMs = Date.parse(record?.at);
|
|
241
|
+
return typeof record?.sessionId === "string" && ["alive", "idle", "ended"].includes(record.state) && Number.isFinite(atMs)
|
|
242
|
+
? [{ sessionId: record.sessionId, state: record.state, atMs }]
|
|
243
|
+
: [];
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
195
247
|
const herdrOf = (env, exec, redact) => {
|
|
196
248
|
if (env.HERDR_ENV !== "1") return { status: "unknown", agents: [] };
|
|
197
249
|
try {
|
|
@@ -203,7 +255,10 @@ const herdrOf = (env, exec, redact) => {
|
|
|
203
255
|
};
|
|
204
256
|
|
|
205
257
|
const known = (list) => (list === null ? "unknown" : "ok");
|
|
206
|
-
const statusRank = { "waiting-on-user": 0, active: 1,
|
|
258
|
+
const statusRank = { "waiting-on-user": 0, active: 1, idle: 2, done: 2, ended: 3, unknown: 4 };
|
|
259
|
+
// The Stop hook writes `idle` just after the turn's last transcript line, so a record this much older
|
|
260
|
+
// than that line still describes it; anything older predates a newer prompt.
|
|
261
|
+
const LIVENESS_SLACK_MS = 5000;
|
|
207
262
|
|
|
208
263
|
/**
|
|
209
264
|
* Collects the brief. Options: `cwd`, `here` (cwd only), `since` (`7d`), `max` (12), `sessionId`
|
|
@@ -230,6 +285,24 @@ export const collectRewind = ({
|
|
|
230
285
|
const listed = here ? null : worktreesOf(start, exec);
|
|
231
286
|
const roots = [...new Set([start, ...(here ? [] : listed ?? [stateRoot])])];
|
|
232
287
|
|
|
288
|
+
// The small records first: plans, litgoal, handoffs and stacks cost little, and the transcripts
|
|
289
|
+
// after them may use up the read budget.
|
|
290
|
+
const collectEach = (read) => {
|
|
291
|
+
const results = roots.map(read);
|
|
292
|
+
return results.every((value) => value === null) ? null : results.flatMap((value) => value ?? []);
|
|
293
|
+
};
|
|
294
|
+
const plansSkipped = { count: 0 };
|
|
295
|
+
const plans = collectEach((root) => plansIn(root, budget, redact, resolve(root) === stateRoot || resolve(root) === start, plansSkipped));
|
|
296
|
+
const litgoal = collectEach((root) => {
|
|
297
|
+
const goal = litgoalOf(root, budget, redact);
|
|
298
|
+
return goal ? [{ ...goal, local: resolve(root) === stateRoot || resolve(root) === start }] : null;
|
|
299
|
+
});
|
|
300
|
+
const handoffs = roots.flatMap((root) => handoffsOf(root, budget, redact, resolve(root) === start));
|
|
301
|
+
const workflows = collectEach((root) => stacksOf(root, budget, redact));
|
|
302
|
+
const startWork = collectEach((root) => startWorkOf(root, budget, redact));
|
|
303
|
+
const runs = collectEach((root) => completedRunsOf(root, budget, redact));
|
|
304
|
+
const liveness = collectEach((root) => livenessOf(root, budget));
|
|
305
|
+
|
|
233
306
|
const rootSet = new Set(roots.map((root) => resolve(root).normalize("NFC")));
|
|
234
307
|
const transcripts = findTranscripts(env.CLAUDE_CONFIG_DIR || join(home, ".claude"), roots);
|
|
235
308
|
const sessions = [];
|
|
@@ -245,19 +318,7 @@ export const collectRewind = ({
|
|
|
245
318
|
sessions.push(session);
|
|
246
319
|
}
|
|
247
320
|
|
|
248
|
-
const collectEach = (read) => {
|
|
249
|
-
const results = roots.map(read);
|
|
250
|
-
return results.every((value) => value === null) ? null : results.flatMap((value) => value ?? []);
|
|
251
|
-
};
|
|
252
|
-
const plans = collectEach((root) => plansIn(root, budget, redact, resolve(root) === stateRoot || resolve(root) === start));
|
|
253
|
-
const litgoal = collectEach((root) => {
|
|
254
|
-
const goal = litgoalOf(root, budget, redact);
|
|
255
|
-
return goal ? [{ ...goal, local: resolve(root) === stateRoot || resolve(root) === start }] : null;
|
|
256
|
-
});
|
|
257
|
-
const handoffs = roots.flatMap((root) => handoffsOf(root, budget, redact));
|
|
258
321
|
const commits = collectEach((root) => commitsOf(root, sinceMs, now, exec, redact));
|
|
259
|
-
const workflows = collectEach((root) => stacksOf(root, budget, redact));
|
|
260
|
-
const startWork = collectEach((root) => startWorkOf(root, budget, redact));
|
|
261
322
|
const herdr = herdrOf(env, exec, redact);
|
|
262
323
|
|
|
263
324
|
// A session waits on the user when it asked something, or holds a paused frame or boundary.
|
|
@@ -280,14 +341,33 @@ export const collectRewind = ({
|
|
|
280
341
|
.slice(0, 5)
|
|
281
342
|
.map(({ hash, subject }) => ({ hash, subject }));
|
|
282
343
|
}
|
|
344
|
+
// A transcript only says when a session last moved. Its own hook record and its start-work run say
|
|
345
|
+
// more: a run it completed (and did not move past) makes it done; an idle or ended record at least
|
|
346
|
+
// as new as its last transcript line makes it idle or ended. This session is running the brief,
|
|
347
|
+
// whatever its last Stop wrote, and a session that asked the user something still waits.
|
|
348
|
+
const newestLiveness = new Map();
|
|
349
|
+
for (const record of liveness ?? []) {
|
|
350
|
+
if ((newestLiveness.get(record.sessionId)?.atMs ?? -Infinity) < record.atMs) newestLiveness.set(record.sessionId, record);
|
|
351
|
+
}
|
|
352
|
+
const recentRuns = (runs ?? []).filter((run) => now - run.atMs <= sinceMs).sort((a, b) => b.atMs - a.atMs);
|
|
353
|
+
for (const session of sessions) {
|
|
354
|
+
if ((sessionId && session.sessionId === sessionId) || session.status === "waiting-on-user") continue;
|
|
355
|
+
const live = newestLiveness.get(session.sessionId);
|
|
356
|
+
const run = recentRuns.find((item) => item.sessionId === session.sessionId);
|
|
357
|
+
if (run && !(live?.state === "alive" && live.atMs > run.atMs)) {
|
|
358
|
+
session.status = "done";
|
|
359
|
+
session.finishedPlan = run.plan;
|
|
360
|
+
} else if (live && live.state !== "alive" && live.atMs >= (session.lastMs ?? 0) - LIVENESS_SLACK_MS) {
|
|
361
|
+
session.status = live.state === "ended" ? "ended" : "idle";
|
|
362
|
+
}
|
|
363
|
+
}
|
|
283
364
|
sessions.sort((a, b) => statusRank[a.status] - statusRank[b.status] || (b.lastMs ?? 0) - (a.lastMs ?? 0));
|
|
284
365
|
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
const orderedPlans = (plans ?? []).filter(recent).sort((a, b) => Number(b.local) - Number(a.local) || (b.changedMs ?? 0) - (a.changedMs ?? 0));
|
|
366
|
+
// Open plans changed inside the window are listed, this worktree's first, then the most recently
|
|
367
|
+
// changed, up to a short cap; a stale plan is left out, here or elsewhere. The roadmap gauge
|
|
368
|
+
// counts this worktree only, since a sum over unrelated branches measures nothing.
|
|
369
|
+
const recent = (plan) => plan.changedMs !== null && now - plan.changedMs <= sinceMs;
|
|
370
|
+
const orderedPlans = (plans ?? []).filter((plan) => !plan.complete && recent(plan)).sort((a, b) => Number(b.local) - Number(a.local) || (b.changedMs ?? 0) - (a.changedMs ?? 0));
|
|
291
371
|
const shownPlans = orderedPlans.slice(0, PLAN_LIMIT);
|
|
292
372
|
const localGoals = (litgoal ?? []).filter((goal) => goal.local);
|
|
293
373
|
const roadmapItems = [...orderedPlans.filter((plan) => plan.local).map((plan) => plan.progress), ...localGoals.map((goal) => goal.progress)];
|
|
@@ -315,10 +395,16 @@ export const collectRewind = ({
|
|
|
315
395
|
roadmap: {
|
|
316
396
|
plans: shownPlans,
|
|
317
397
|
plansOmitted: orderedPlans.length - shownPlans.length,
|
|
398
|
+
plansSkipped: plansSkipped.count,
|
|
318
399
|
// Another worktree's finished objective is history, not roadmap.
|
|
319
400
|
litgoal: (litgoal ?? []).filter((goal) => goal.local || goal.status !== "complete"),
|
|
320
401
|
progress: roadmapItems.length ? aggregateProgress(roadmapItems) : progressOf(null, null),
|
|
321
402
|
},
|
|
403
|
+
// Finished inside the window: completed start-work runs and plans with every row ticked.
|
|
404
|
+
finished: {
|
|
405
|
+
runs: recentRuns.map(({ worktree, plan, atMs }) => ({ worktree, plan, at: new Date(atMs).toISOString() })),
|
|
406
|
+
plans: (plans ?? []).filter((plan) => plan.complete && recent(plan)).map(({ worktree, plan, local, progress }) => ({ worktree, plan, local, gauge: progress.gauge })),
|
|
407
|
+
},
|
|
322
408
|
workflows: (workflows ?? []).map((frame) => ({ ...frame, self: Boolean(sessionId) && frame.sessionId === sessionId })),
|
|
323
409
|
startWork: startWork ?? [],
|
|
324
410
|
handoffs,
|
|
@@ -337,7 +423,10 @@ export const collectRewind = ({
|
|
|
337
423
|
}
|
|
338
424
|
}
|
|
339
425
|
for (const frame of data.workflows) delete frame.sessionId;
|
|
340
|
-
for (const work of data.startWork)
|
|
426
|
+
for (const work of data.startWork) {
|
|
427
|
+
work.self = Boolean(sessionId) && work.sessionId === sessionId;
|
|
428
|
+
delete work.sessionId;
|
|
429
|
+
}
|
|
341
430
|
return data;
|
|
342
431
|
};
|
|
343
432
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Each session's last hook event as one small record, `.litclaude/liveness/<session>.json`:
|
|
2
|
+
// PostToolUse and PostToolUseFailure say `alive`, Stop says `idle`, SessionEnd says `ended`. The LIT
|
|
3
|
+
// card reads it to tell running, idle and ended sessions apart, and to find herdr lanes of this
|
|
4
|
+
// project by the pane id the hooks ran under. A repeat of the same state is written at most every
|
|
5
|
+
// 30 s, so a busy session costs one small write per half minute.
|
|
6
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
import { ignitionFileName } from "./mod/state.mjs";
|
|
10
|
+
import { requireStateDir, resolveProjectStateRoot, STATE_WRITE_FLAG } from "./project-state-root.mjs";
|
|
11
|
+
|
|
12
|
+
export const LIVENESS_STATES = Object.freeze(["alive", "idle", "ended"]);
|
|
13
|
+
const SAME_STATE_MS = 30_000;
|
|
14
|
+
const HERDR_PANE = /^[A-Za-z0-9:_-]{1,32}$/u;
|
|
15
|
+
|
|
16
|
+
export const livenessPath = (stateRoot, sessionId) => join(stateRoot, ".litclaude", "liveness", ignitionFileName(sessionId));
|
|
17
|
+
|
|
18
|
+
export const markLiveness = (cwd, sessionId, state, { now = Date.now(), env = process.env } = {}) => {
|
|
19
|
+
if (typeof sessionId !== "string" || !sessionId.trim() || !LIVENESS_STATES.includes(state)) return null;
|
|
20
|
+
const stateRoot = resolveProjectStateRoot(cwd);
|
|
21
|
+
// Only a project that already keeps LitClaude state gets the record; a plain repository stays untouched.
|
|
22
|
+
if (!existsSync(join(stateRoot, ".litclaude"))) return null;
|
|
23
|
+
const path = livenessPath(stateRoot, sessionId);
|
|
24
|
+
try {
|
|
25
|
+
const previous = JSON.parse(readFileSync(path, "utf8"));
|
|
26
|
+
if (previous?.state === state && now - Date.parse(previous.at) < SAME_STATE_MS) return null;
|
|
27
|
+
} catch {
|
|
28
|
+
// No record yet, or an unreadable one: write a fresh record.
|
|
29
|
+
}
|
|
30
|
+
const pane = typeof env.HERDR_PANE_ID === "string" && HERDR_PANE.test(env.HERDR_PANE_ID) ? env.HERDR_PANE_ID : null;
|
|
31
|
+
requireStateDir(join(stateRoot, ".litclaude", "liveness"));
|
|
32
|
+
const staging = `${path}.${process.pid}.tmp`;
|
|
33
|
+
writeFileSync(staging, `${JSON.stringify({ version: 1, sessionId, state, at: new Date(now).toISOString(), herdrPane: pane })}\n`, { flag: STATE_WRITE_FLAG });
|
|
34
|
+
renameSync(staging, path);
|
|
35
|
+
return path;
|
|
36
|
+
};
|