@litfamily/litclaude 1.0.38 → 1.0.39
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 +26 -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 +18 -17
- 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/rewind/brief.mjs +370 -0
- package/plugins/litclaude/lib/rewind/collect.mjs +39 -13
- package/plugins/litclaude/lib/rewind/gauge.mjs +28 -8
- package/plugins/litclaude/lib/rewind/suggest.mjs +51 -0
- package/plugins/litclaude/lib/rewind/transcripts.mjs +15 -0
- 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-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/readme-studio/SKILL.md +10 -0
- package/plugins/litclaude/skills/readme-studio/references/production-interview.md +2 -0
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
|
|
12
|
+
const WORDS = {
|
|
13
|
+
en: {
|
|
14
|
+
sessions: (n) => `${n} ${n === 1 ? "session" : "sessions"}`,
|
|
15
|
+
waiting: (n) => `${n} ${n === 1 ? "waits" : "wait"} on you`,
|
|
16
|
+
active: (n) => `${n} active`,
|
|
17
|
+
next: "next",
|
|
18
|
+
window: (since, trees) => `last ${since} · ${trees} ${trees === 1 ? "worktree" : "worktrees"}`,
|
|
19
|
+
badge: { "waiting-on-user": "🟠 **WAITING ON YOU**", active: "🟢 **ACTIVE**", ended: "⚪ ended", unknown: "⚫ unknown" },
|
|
20
|
+
reason: { "asked the user": "it asked you something", "paused workflow": "paused workflow", "start-work boundary": "start-work needs approval" },
|
|
21
|
+
ago: (text) => `${text} ago`,
|
|
22
|
+
justNow: "just now",
|
|
23
|
+
goal: "Goal",
|
|
24
|
+
done: "Done",
|
|
25
|
+
nextLabel: "Next",
|
|
26
|
+
noneDone: "no file edits or commits on record",
|
|
27
|
+
toolsUsed: (list) => `no edits yet; used ${list}`,
|
|
28
|
+
doing: (what) => `now: ${what}`,
|
|
29
|
+
endedTitle: (n) => `Ended · ${n}`,
|
|
30
|
+
endedHead: ["id", "where", "goal", "ago", "done"],
|
|
31
|
+
fileCount: (n) => `${n} ${n === 1 ? "file" : "files"}`,
|
|
32
|
+
moreEnded: (n) => `…and ${n} more ended`,
|
|
33
|
+
files: "edited",
|
|
34
|
+
commits: (n) => `${n} ${n === 1 ? "commit" : "commits"}`,
|
|
35
|
+
worked: (d) => `${d} of work`,
|
|
36
|
+
lastAsk: (q) => `last ask: “${q}”`,
|
|
37
|
+
working: "still working in that session",
|
|
38
|
+
self: "this session",
|
|
39
|
+
answer: (q) => `answer its question: “${q}”`,
|
|
40
|
+
resume: (skill, stage, self) => `resume ${skill} at ${stage} (\`lit continue\`${self ? "" : " there"})`,
|
|
41
|
+
approve: "approve or deny the start-work boundary (`lit approve` / `lit deny`)",
|
|
42
|
+
planNow: (plan, item) => `${plan} → ${item}`,
|
|
43
|
+
nothing: "nothing pending on record",
|
|
44
|
+
roadmap: "Roadmap",
|
|
45
|
+
now: "now",
|
|
46
|
+
later: "later",
|
|
47
|
+
milestoneDone: "done",
|
|
48
|
+
noRoadmap: "No open plan, goal or commit in this window.",
|
|
49
|
+
morePlans: (n) => `…and ${n} more open ${n === 1 ? "plan" : "plans"}`,
|
|
50
|
+
recommended: "RECOMMENDED NEXT STEP",
|
|
51
|
+
type: "type",
|
|
52
|
+
stepKind: {
|
|
53
|
+
"resume-frame": ({ skill, stage }) => `Resume the paused ${skill} at ${stage}`,
|
|
54
|
+
"approve-boundary": ({ plan, action, root }) => `start-work (${plan}) waits for ${action} access to ${root}`,
|
|
55
|
+
"continue-work": ({ plan }) => `Keep running ${plan}`,
|
|
56
|
+
"start-plan": ({ plan }) => `Start ${plan} with start-work`,
|
|
57
|
+
none: () => "No next step on record",
|
|
58
|
+
},
|
|
59
|
+
suggest: {
|
|
60
|
+
answer: ({ id8, where, question }) => `Answer ${id8} in ${where}${question ? `: “${question}”` : ""}`,
|
|
61
|
+
resume: ({ id8, skill, stage, where }) => `Resume ${skill} at ${stage} in ${id8} (${where})`,
|
|
62
|
+
plan: ({ plan, item }) => `Next in ${plan}: ${item}`,
|
|
63
|
+
check: ({ id8, goal, where, doing }) => `Check on ${id8} in ${where} (${goal})${doing ? `, now ${doing}` : ""}`,
|
|
64
|
+
pickUp: ({ id8, goal, where }) => `Pick up ${id8} in ${where}: ${goal}`,
|
|
65
|
+
start: () => "No session or plan in this window: say what to start",
|
|
66
|
+
},
|
|
67
|
+
goLine: (say) => `Type **\`${say}\`** to continue.`,
|
|
68
|
+
noGo: "Nothing runs on its own here: open that session, or say what to do.",
|
|
69
|
+
unknownSources: (list) => `Not read: ${list}.`,
|
|
70
|
+
older: "Older sessions were not read (read budget used up).",
|
|
71
|
+
noSessions: "No Claude Code session records in this window.",
|
|
72
|
+
},
|
|
73
|
+
ko: {
|
|
74
|
+
sessions: (n) => `세션 ${n}개`,
|
|
75
|
+
waiting: (n) => `나를 기다리는 것 ${n}`,
|
|
76
|
+
active: (n) => `진행 중 ${n}`,
|
|
77
|
+
next: "다음",
|
|
78
|
+
window: (since, trees) => `최근 ${since} · 워크트리 ${trees}개`,
|
|
79
|
+
badge: { "waiting-on-user": "🟠 **나를 기다림**", active: "🟢 **진행 중**", ended: "⚪ 끝남", unknown: "⚫ 모름" },
|
|
80
|
+
reason: { "asked the user": "질문에 답을 기다림", "paused workflow": "멈춘 워크플로", "start-work boundary": "start-work 승인 대기" },
|
|
81
|
+
ago: (text) => `${text} 전`,
|
|
82
|
+
justNow: "방금",
|
|
83
|
+
goal: "목표",
|
|
84
|
+
done: "한 일",
|
|
85
|
+
nextLabel: "다음",
|
|
86
|
+
noneDone: "기록된 파일 수정·커밋 없음",
|
|
87
|
+
toolsUsed: (list) => `아직 수정 없음, 쓴 도구 ${list}`,
|
|
88
|
+
doing: (what) => `지금: ${what}`,
|
|
89
|
+
endedTitle: (n) => `끝난 세션 · ${n}`,
|
|
90
|
+
endedHead: ["id", "위치", "목표", "끝난 지", "한 일"],
|
|
91
|
+
fileCount: (n) => `파일 ${n}개`,
|
|
92
|
+
moreEnded: (n) => `…끝난 세션 ${n}개 더`,
|
|
93
|
+
files: "수정",
|
|
94
|
+
commits: (n) => `커밋 ${n}개`,
|
|
95
|
+
worked: (d) => `${d} 작업`,
|
|
96
|
+
lastAsk: (q) => `마지막 요청: “${q}”`,
|
|
97
|
+
working: "그 세션에서 작업 중",
|
|
98
|
+
self: "이 세션",
|
|
99
|
+
answer: (q) => `질문에 답하기: “${q}”`,
|
|
100
|
+
resume: (skill, stage, self) => `${skill}(${stage}) 이어가기 (${self ? "" : "그 세션에서 "}\`lit continue\`)`,
|
|
101
|
+
approve: "start-work 경계 승인 또는 거절 (`lit approve` / `lit deny`)",
|
|
102
|
+
planNow: (plan, item) => `${plan} → ${item}`,
|
|
103
|
+
nothing: "기록된 남은 일 없음",
|
|
104
|
+
roadmap: "로드맵",
|
|
105
|
+
now: "지금",
|
|
106
|
+
later: "이후",
|
|
107
|
+
milestoneDone: "완료",
|
|
108
|
+
noRoadmap: "이 기간에 열린 계획·목표·커밋이 없습니다.",
|
|
109
|
+
morePlans: (n) => `…열린 계획 ${n}개 더`,
|
|
110
|
+
recommended: "추천하는 다음 단계",
|
|
111
|
+
type: "입력",
|
|
112
|
+
stepKind: {
|
|
113
|
+
"resume-frame": ({ skill, stage }) => `멈춘 ${skill}(${stage}) 이어가기`,
|
|
114
|
+
"approve-boundary": ({ plan, action, root }) => `start-work(${plan})가 ${root} ${action} 권한을 기다림`,
|
|
115
|
+
"continue-work": ({ plan }) => `${plan} 계속 진행`,
|
|
116
|
+
"start-plan": ({ plan }) => `${plan}을 start-work로 시작`,
|
|
117
|
+
none: () => "기록된 다음 단계 없음",
|
|
118
|
+
},
|
|
119
|
+
suggest: {
|
|
120
|
+
answer: ({ id8, where, question }) => `${where}의 ${id8}에 답하기${question ? `: “${question}”` : ""}`,
|
|
121
|
+
resume: ({ id8, skill, stage, where }) => `${where}의 ${id8}에서 ${skill}(${stage}) 이어가기`,
|
|
122
|
+
plan: ({ plan, item }) => `${plan} 다음 항목: ${item}`,
|
|
123
|
+
check: ({ id8, goal, where, doing }) => `${where}의 ${id8} 확인 (${goal})${doing ? `, 지금 ${doing}` : ""}`,
|
|
124
|
+
pickUp: ({ id8, goal, where }) => `${where}의 ${id8} 이어받기: ${goal}`,
|
|
125
|
+
start: () => "이 기간에 세션·계획이 없습니다. 시작할 일을 말해 주세요",
|
|
126
|
+
},
|
|
127
|
+
goLine: (say) => `**\`${say}\`** 라고 입력하면 이어갑니다.`,
|
|
128
|
+
noGo: "저절로 실행되는 단계는 아닙니다. 그 세션을 열거나 할 일을 말해 주세요.",
|
|
129
|
+
unknownSources: (list) => `읽지 못함: ${list}.`,
|
|
130
|
+
older: "오래된 세션은 읽지 않았습니다(읽기 예산 소진).",
|
|
131
|
+
noSessions: "이 기간의 Claude Code 세션 기록이 없습니다.",
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const duration = (ms) => {
|
|
136
|
+
const minutes = Math.max(0, Math.round(ms / 60_000));
|
|
137
|
+
if (minutes < 60) return `${minutes}m`;
|
|
138
|
+
const hours = Math.floor(minutes / 60);
|
|
139
|
+
if (hours < 48) return minutes % 60 ? `${hours}h ${minutes % 60}m` : `${hours}h`;
|
|
140
|
+
return `${Math.floor(hours / 24)}d`;
|
|
141
|
+
};
|
|
142
|
+
const when = (iso, now, w) => {
|
|
143
|
+
const at = Date.parse(iso);
|
|
144
|
+
if (!Number.isFinite(at)) return null;
|
|
145
|
+
return now - at < 60_000 ? w.justNow : w.ago(duration(now - at));
|
|
146
|
+
};
|
|
147
|
+
// `10-25 14:02`, in the machine's local time: a milestone's date.
|
|
148
|
+
const stamp = (iso) => {
|
|
149
|
+
const at = new Date(iso);
|
|
150
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
151
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
152
|
+
return `${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}`;
|
|
153
|
+
};
|
|
154
|
+
// Inline code that cannot be broken by a backtick inside the data.
|
|
155
|
+
const code = (text) => `\`${String(text).replace(/`/gu, "'")}\``;
|
|
156
|
+
// One line of data as Markdown text: no line breaks, no tags, and its emphasis marks escaped.
|
|
157
|
+
const bare = (text) => String(text).replace(/\s+/gu, " ").trim();
|
|
158
|
+
const plain = (text) => bare(text).replace(/[<>`]/gu, (ch) => ({ "<": "‹", ">": "›", "`": "'" }[ch])).replace(/[*_|[\]\\]/gu, (ch) => `\\${ch}`);
|
|
159
|
+
|
|
160
|
+
// The last question the session asked, from its last assistant words.
|
|
161
|
+
const lastQuestion = (result, escape = plain) => {
|
|
162
|
+
const text = String(result ?? "");
|
|
163
|
+
const found = [...text.matchAll(/[^.!?。?\n]{4,}[??]/gu)].at(-1)?.[0];
|
|
164
|
+
return found ? escape(clipToWidth(bare(found), 90)) : null;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const progressLine = (session, w) => {
|
|
168
|
+
if (session.progress?.gauge) {
|
|
169
|
+
const left = (session.progress.remaining ?? []).filter((name) => name !== "unknown");
|
|
170
|
+
return `${code(session.progress.gauge)}${left.length ? ` · ${w.later}: ${plain(left.slice(0, 2).join(", "))}${left.length > 2 ? ` (+${left.length - 2})` : ""}` : ""}`;
|
|
171
|
+
}
|
|
172
|
+
// A long transcript is read as its head and tail only, so counts of its calls would undercount;
|
|
173
|
+
// its first and last times and its last ask are exact.
|
|
174
|
+
const span = Date.parse(session.last) - Date.parse(session.started);
|
|
175
|
+
const ask = (session.asked ?? []).filter((text) => text && text !== "unknown").at(-1);
|
|
176
|
+
const facts = [
|
|
177
|
+
Number.isFinite(span) && span > 0 ? w.worked(duration(span)) : null,
|
|
178
|
+
ask ? w.lastAsk(plain(clipToWidth(bare(ask), 70))) : null,
|
|
179
|
+
].filter(Boolean);
|
|
180
|
+
return facts.length ? `⏳ ${facts.join(" · ")}` : null;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const doneLine = (session, w) => {
|
|
184
|
+
const files = (session.done?.files ?? []).slice(0, 3).map((file) => code(basename(String(file))));
|
|
185
|
+
const commits = (session.done?.commits ?? []).slice(0, 2).map(({ hash, subject }) => `${code(hash)} ${plain(clipToWidth(subject, 60))}`);
|
|
186
|
+
const parts = [files.length ? `${w.files} ${files.join(", ")}` : null, commits.length ? `${w.commits(session.done.commits.length)}: ${commits.join("; ")}` : null].filter(Boolean);
|
|
187
|
+
if (parts.length) return parts.join(" · ");
|
|
188
|
+
// Head-and-tail reads undercount calls, so tools are named, never counted.
|
|
189
|
+
const tools = Object.entries(session.done?.tools ?? {}).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([name]) => plain(name));
|
|
190
|
+
return tools.length ? w.toolsUsed(tools.join(", ")) : w.noneDone;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// What a session's last tool call was about, as `Bash “Run the gates”`.
|
|
194
|
+
const actionOf = (session, escape = plain) => {
|
|
195
|
+
const action = session.lastAction;
|
|
196
|
+
if (!action?.tool) return null;
|
|
197
|
+
return action.target ? `${escape(action.tool)} “${escape(clipToWidth(bare(action.target), 50))}”` : escape(action.tool);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const nextOf = (session, data, w) => {
|
|
201
|
+
const frames = (data.workflows ?? []).filter((frame) => frame.id8 === session.id8);
|
|
202
|
+
const paused = frames.find((frame) => frame.status === "paused");
|
|
203
|
+
if (paused) return w.resume(paused.skill, paused.stage, session.self);
|
|
204
|
+
if (session.waitingReason === "start-work boundary") return w.approve;
|
|
205
|
+
if (session.status === "waiting-on-user") {
|
|
206
|
+
const question = lastQuestion(session.result);
|
|
207
|
+
if (question) return w.answer(question);
|
|
208
|
+
}
|
|
209
|
+
const work = (data.startWork ?? []).find((item) => item.id8 === session.id8);
|
|
210
|
+
const plan = work ? (data.roadmap?.plans ?? []).find((item) => item.plan === work.plan) : null;
|
|
211
|
+
if (plan && plan.current) return w.planNow(code(plan.plan), plain(plan.current));
|
|
212
|
+
if (session.status === "active") {
|
|
213
|
+
if (frames.length) return `${frames.at(-1).skill} · ${frames.at(-1).stage}`;
|
|
214
|
+
const doing = actionOf(session);
|
|
215
|
+
return doing ? w.doing(doing) : w.working;
|
|
216
|
+
}
|
|
217
|
+
return w.nothing;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const sessionCard = (session, data, now, w) => {
|
|
221
|
+
const reason = session.waitingReason ? ` (${w.reason[session.waitingReason] ?? plain(session.waitingReason)})` : "";
|
|
222
|
+
const ago = when(session.last, now, w);
|
|
223
|
+
const head = `${w.badge[session.status] ?? w.badge.unknown}${reason} · ${code(session.id8)}${ago ? ` · ${ago}` : ""}${session.self ? ` · ${w.self}` : ""}`;
|
|
224
|
+
const goal = session.title && session.title !== "unknown" ? plain(session.title) : plain(session.asked?.[0] ?? "unknown");
|
|
225
|
+
const lines = [head, `**${goal}**`];
|
|
226
|
+
const progress = progressLine(session, w);
|
|
227
|
+
if (progress) lines.push(progress);
|
|
228
|
+
lines.push(`✅ ${w.done}: ${doneLine(session, w)}`);
|
|
229
|
+
lines.push(`▶ ${w.nextLabel}: ${nextOf(session, data, w)}`);
|
|
230
|
+
return lines.map((line) => `> ${line}`).join(" \n");
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const groupKey = (session) => `${session.worktree}\u0000${session.branch}`;
|
|
234
|
+
const placeOf = (session) => (session.worktree && session.worktree !== "unknown" ? basename(String(session.worktree)) : "unknown");
|
|
235
|
+
const goalOf = (session) => (session.title && session.title !== "unknown" ? session.title : session.asked?.[0] ?? "unknown");
|
|
236
|
+
|
|
237
|
+
// Ended sessions, one table row each, newest first: they are history, not something to read now.
|
|
238
|
+
const ENDED_ROWS = 8;
|
|
239
|
+
const endedTable = (sessions, now, w) => {
|
|
240
|
+
const cell = (text) => plain(text) || "·";
|
|
241
|
+
const rows = sessions.slice(0, ENDED_ROWS).map((session) => {
|
|
242
|
+
const commits = session.done?.commits?.length ?? 0;
|
|
243
|
+
const files = session.done?.files?.length ?? 0;
|
|
244
|
+
// Short cells, so a row stays one line in a 120-column terminal: the age to the largest unit.
|
|
245
|
+
const done = commits ? w.commits(commits) : files ? w.fileCount(files) : "·";
|
|
246
|
+
const at = Date.parse(session.last);
|
|
247
|
+
const age = Number.isFinite(at) ? duration(now - at).split(" ")[0] : "·";
|
|
248
|
+
return `| ${code(session.id8)} | ${cell(clipToWidth(placeOf(session), 20))} | ${cell(clipToWidth(goalOf(session), 44))} | ${cell(age)} | ${cell(done)} |`;
|
|
249
|
+
});
|
|
250
|
+
const head = `| ${w.endedHead.join(" | ")} |`;
|
|
251
|
+
const rule = `|${w.endedHead.map(() => "---").join("|")}|`;
|
|
252
|
+
const more = sessions.length > ENDED_ROWS ? ["", `*${w.moreEnded(sessions.length - ENDED_ROWS)}*`] : [];
|
|
253
|
+
return [head, rule, ...rows, ...more];
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// When no step can run on `go`, the brief still recommends one from what it read, in this order:
|
|
257
|
+
// a session that waits on the user, a paused workflow, the next item of an open plan,
|
|
258
|
+
// the most recent other active session, the most recent ended one. It is shown, never recorded.
|
|
259
|
+
const suggestion = (data, w) => {
|
|
260
|
+
// Raw text: the headline escapes it once, the box shows it inside a code block.
|
|
261
|
+
const sessions = data.sessions ?? [];
|
|
262
|
+
const where = (session) => bare(placeOf(session));
|
|
263
|
+
const goal = (session) => clipToWidth(bare(goalOf(session)), 50);
|
|
264
|
+
const waiting = sessions.find((session) => session.status === "waiting-on-user" && !session.self);
|
|
265
|
+
if (waiting) return w.suggest.answer({ id8: waiting.id8, where: where(waiting), question: lastQuestion(waiting.result, bare) });
|
|
266
|
+
const paused = (data.workflows ?? []).find((frame) => frame.status === "paused");
|
|
267
|
+
const owner = paused ? sessions.find((session) => session.id8 === paused.id8) : null;
|
|
268
|
+
if (paused) return w.suggest.resume({ id8: paused.id8, skill: paused.skill, stage: paused.stage, where: owner ? where(owner) : basename(String(paused.worktree)) });
|
|
269
|
+
// A plan in the worktree of a live session comes first, then this worktree's, then the newest.
|
|
270
|
+
const liveTrees = new Set(sessions.filter((session) => session.status !== "ended").map((session) => session.worktree));
|
|
271
|
+
const open = (data.roadmap?.plans ?? []).filter((item) => item.current);
|
|
272
|
+
const plan = open.find((item) => liveTrees.has(item.worktree)) ?? open.find((item) => item.local) ?? open[0];
|
|
273
|
+
if (plan) return w.suggest.plan({ plan: plan.local ? plan.plan : `${basename(String(plan.worktree))}/${plan.plan}`, item: clipToWidth(bare(plan.current), 60) });
|
|
274
|
+
const active = sessions.find((session) => session.status === "active" && !session.self);
|
|
275
|
+
if (active) return w.suggest.check({ id8: active.id8, goal: goal(active), where: where(active), doing: actionOf(active, bare) });
|
|
276
|
+
const ended = sessions.find((session) => session.status === "ended" && !session.self);
|
|
277
|
+
if (ended) return w.suggest.pickUp({ id8: ended.id8, goal: goal(ended), where: where(ended) });
|
|
278
|
+
return w.suggest.start();
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// The roadmap timeline: finished commits with their dates, then the current item and gauge of each
|
|
282
|
+
// open plan of this worktree or one under way elsewhere (an untouched plan of another worktree is
|
|
283
|
+
// only counted), then what comes after it, then litgoal objectives.
|
|
284
|
+
const ROADMAP_PLANS = 4;
|
|
285
|
+
const roadmapLines = (data, w) => {
|
|
286
|
+
const lines = [];
|
|
287
|
+
for (const commit of (data.commits ?? []).slice(0, 5).reverse()) {
|
|
288
|
+
lines.push(`- ✓ ${stamp(commit.at)} · ${code(commit.branch)} ${plain(clipToWidth(commit.subject, 70))}`);
|
|
289
|
+
}
|
|
290
|
+
const plans = data.roadmap?.plans ?? [];
|
|
291
|
+
const shownPlans = plans.slice(0, ROADMAP_PLANS);
|
|
292
|
+
const omitted = plans.length - shownPlans.length + (data.roadmap?.plansOmitted ?? 0);
|
|
293
|
+
for (const plan of shownPlans) {
|
|
294
|
+
const where = plan.local ? "" : `${code(basename(String(plan.worktree)))} `;
|
|
295
|
+
lines.push(`- ▶ **${w.now}** · ${where}${code(plan.plan)} ${plan.progress?.gauge ? code(plan.progress.gauge) : ""} → ${plain(plan.current)}`);
|
|
296
|
+
const later = (plan.progress?.remaining ?? []).filter((name) => name !== "unknown" && name !== plan.current).slice(0, 2);
|
|
297
|
+
for (const item of later) lines.push(` - ○ ${w.later} · ${plain(item)}`);
|
|
298
|
+
}
|
|
299
|
+
if (omitted > 0) lines.push(`- ${w.morePlans(omitted)}`);
|
|
300
|
+
for (const goal of data.roadmap?.litgoal ?? []) {
|
|
301
|
+
const mark = goal.status === "complete" ? "✓" : "▶";
|
|
302
|
+
lines.push(`- ${mark} litgoal ${goal.progress?.gauge ? code(goal.progress.gauge) : ""} ${plain(goal.objective)}`);
|
|
303
|
+
}
|
|
304
|
+
return lines.length ? lines : [w.noRoadmap];
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// A box the width of its longest line, padded by display width so Hangul keeps the right edge.
|
|
308
|
+
const box = (title, body) => {
|
|
309
|
+
const width = Math.max(displayWidth(title) + 2, ...body.map((line) => displayWidth(line))) + 2;
|
|
310
|
+
const pad = (line) => `${line}${" ".repeat(Math.max(0, width - 2 - displayWidth(line)))}`;
|
|
311
|
+
return ["```text", `╭─ ${title} ${"─".repeat(Math.max(1, width - displayWidth(title) - 3))}╮`, ...body.map((line) => `│ ${pad(line)} │`), `╰${"─".repeat(width)}╯`, "```"].join("\n");
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// Wraps a step to the box at word breaks, three lines at most, the last one clipped.
|
|
315
|
+
const wrap = (text, width, lines = 3) => {
|
|
316
|
+
const out = [""];
|
|
317
|
+
for (const word of bare(text).split(" ")) {
|
|
318
|
+
const joined = out.at(-1) ? `${out.at(-1)} ${word}` : word;
|
|
319
|
+
if (displayWidth(joined) <= width || !out.at(-1)) out[out.length - 1] = joined;
|
|
320
|
+
else out.push(word);
|
|
321
|
+
}
|
|
322
|
+
const kept = out.slice(0, lines);
|
|
323
|
+
if (out.length > lines) kept[lines - 1] = `${kept[lines - 1]} ${out.slice(lines).join(" ")}`;
|
|
324
|
+
return kept.map((line) => clipToWidth(line, width));
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const stepText = (next, w) => {
|
|
328
|
+
const target = next?.target ?? {};
|
|
329
|
+
const describe = w.stepKind[next?.kind] ?? w.stepKind.none;
|
|
330
|
+
return bare(describe({ skill: target.skill, stage: target.stage, plan: target.plan, action: target.action, root: target.root }));
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/** The brief as Markdown. `lang` is `ko` or `en`; `now` the clock the relative times use. */
|
|
334
|
+
export const renderBrief = (data, { lang = "en", now = Date.parse(data.generatedAt) || Date.now(), width = 72 } = {}) => {
|
|
335
|
+
const w = WORDS[lang] ?? WORDS.en;
|
|
336
|
+
const sessions = data.sessions ?? [];
|
|
337
|
+
const summary = data.summary ?? { sessions: sessions.length, waitingOnUser: 0, active: 0 };
|
|
338
|
+
const step = data.next?.kind && data.next.kind !== "none" ? stepText(data.next, w) : bare(suggestion(data, w));
|
|
339
|
+
const out = [];
|
|
340
|
+
out.push(`## 🧭 ${[w.sessions(summary.sessions), w.waiting(summary.waitingOnUser), w.active(summary.active)].join(" · ")} · ${w.next}: ${plain(step)}`);
|
|
341
|
+
out.push(`*${w.window(data.scope?.since ?? "7d", (data.scope?.worktrees ?? []).length || 1)}*`);
|
|
342
|
+
if (!sessions.length) out.push("", w.noSessions);
|
|
343
|
+
// Sessions that are live or wait on the user come first, as full cards grouped by worktree.
|
|
344
|
+
const live = sessions.filter((session) => session.status !== "ended");
|
|
345
|
+
const ended = sessions.filter((session) => session.status === "ended");
|
|
346
|
+
const groups = new Map();
|
|
347
|
+
for (const session of live) {
|
|
348
|
+
const key = groupKey(session);
|
|
349
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
350
|
+
groups.get(key).push(session);
|
|
351
|
+
}
|
|
352
|
+
for (const list of groups.values()) {
|
|
353
|
+
const { worktree, branch } = list[0];
|
|
354
|
+
const name = worktree && worktree !== "unknown" ? basename(String(worktree)) : "unknown";
|
|
355
|
+
out.push("", `### 🌿 ${code(branch ?? "unknown")} · ${plain(name)}`);
|
|
356
|
+
for (const session of list) out.push("", sessionCard(session, data, now, w));
|
|
357
|
+
}
|
|
358
|
+
if (ended.length) out.push("", `### ⚪ ${w.endedTitle(ended.length)}`, "", ...endedTable(ended, now, w));
|
|
359
|
+
out.push("", `### 🗺️ ${w.roadmap}${data.roadmap?.progress?.gauge ? ` ${code(data.roadmap.progress.gauge)}` : ""}`, "", ...roadmapLines(data, w));
|
|
360
|
+
const say = data.next?.say ?? null;
|
|
361
|
+
const body = wrap(step, width - 4);
|
|
362
|
+
if (data.next?.command) body.push(clipToWidth(data.next.command, width - 4));
|
|
363
|
+
if (say) body.push(`${w.type}: ${say}`);
|
|
364
|
+
out.push("", box(w.recommended, body));
|
|
365
|
+
out.push("", say ? w.goLine(say) : w.noGo);
|
|
366
|
+
const unknown = Object.entries(data.sources ?? {}).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
367
|
+
const notes = [unknown.length ? w.unknownSources(unknown.join(", ")) : null, data.budget?.exhausted ? w.older : null].filter(Boolean);
|
|
368
|
+
if (notes.length) out.push("", `*${notes.join(" ")}*`);
|
|
369
|
+
return `${out.join("\n")}\n`;
|
|
370
|
+
};
|
|
@@ -11,6 +11,7 @@ import { basename, join, resolve } from "node:path";
|
|
|
11
11
|
|
|
12
12
|
import { parsePlanTaskRows } from "../plan-task-rows.mjs";
|
|
13
13
|
import { resolveProjectStateRoot } from "../project-state-root.mjs";
|
|
14
|
+
import { renderBrief } from "./brief.mjs";
|
|
14
15
|
import { aggregateProgress, clipToWidth, displayWidth, progressOf } from "./gauge.mjs";
|
|
15
16
|
import { chooseNextStep, writeNextStep } from "./next-step.mjs";
|
|
16
17
|
import { makeRedactor } from "./redact.mjs";
|
|
@@ -78,6 +79,16 @@ const worktreesOf = (cwd, exec) => {
|
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
81
|
|
|
82
|
+
// A plan scaffold nobody filled in: a row that is still a `<placeholder>`, or every row the same.
|
|
83
|
+
const isTemplate = (rows) => rows.some((row) => /<[^<>]{1,40}>/u.test(row.text)) || (rows.length > 1 && new Set(rows.map((row) => row.text.trim())).size === 1);
|
|
84
|
+
const mtimeOf = (path) => {
|
|
85
|
+
try {
|
|
86
|
+
return lstatSync(path).mtimeMs;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
81
92
|
const plansIn = (root, budget, redact, local) => {
|
|
82
93
|
const list = entries(join(root, "plans"));
|
|
83
94
|
if (!list) return null;
|
|
@@ -85,7 +96,7 @@ const plansIn = (root, budget, redact, local) => {
|
|
|
85
96
|
const text = readSmallFile(join(root, "plans", entry.name), budget);
|
|
86
97
|
if (text === null) return [];
|
|
87
98
|
const rows = parsePlanTaskRows(text);
|
|
88
|
-
if (!rows.length) return [];
|
|
99
|
+
if (!rows.length || isTemplate(rows)) return [];
|
|
89
100
|
const open = rows.filter((row) => !row.checked);
|
|
90
101
|
if (!open.length) return [];
|
|
91
102
|
const done = rows.length - open.length;
|
|
@@ -93,6 +104,7 @@ const plansIn = (root, budget, redact, local) => {
|
|
|
93
104
|
worktree: redact(root),
|
|
94
105
|
plan: `plans/${entry.name}`,
|
|
95
106
|
local,
|
|
107
|
+
changedMs: mtimeOf(join(root, "plans", entry.name)),
|
|
96
108
|
rows: rows.map((row) => ({ checked: row.checked, title: redact(clipToWidth(row.text, NAME_MAX)) })),
|
|
97
109
|
current: redact(clipToWidth(open[0].text, NAME_MAX)),
|
|
98
110
|
progress: progressOf(done, rows.length, open.map((row) => redact(clipToWidth(row.text, NAME_MAX)))),
|
|
@@ -266,9 +278,12 @@ export const collectRewind = ({
|
|
|
266
278
|
}
|
|
267
279
|
sessions.sort((a, b) => statusRank[a.status] - statusRank[b.status] || (b.lastMs ?? 0) - (a.lastMs ?? 0));
|
|
268
280
|
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
|
|
281
|
+
// This worktree's open plans and the ones another worktree touched inside the window are listed,
|
|
282
|
+
// this one's first, then the most recently changed, up to a short cap; a stale plan elsewhere is
|
|
283
|
+
// left out entirely. The roadmap gauge counts this worktree only, since a sum over unrelated
|
|
284
|
+
// branches measures nothing.
|
|
285
|
+
const recent = (plan) => plan.local || (plan.changedMs !== null && now - plan.changedMs <= sinceMs);
|
|
286
|
+
const orderedPlans = (plans ?? []).filter(recent).sort((a, b) => Number(b.local) - Number(a.local) || (b.changedMs ?? 0) - (a.changedMs ?? 0));
|
|
272
287
|
const shownPlans = orderedPlans.slice(0, PLAN_LIMIT);
|
|
273
288
|
const localGoals = (litgoal ?? []).filter((goal) => goal.local);
|
|
274
289
|
const roadmapItems = [...orderedPlans.filter((plan) => plan.local).map((plan) => plan.progress), ...localGoals.map((goal) => goal.progress)];
|
|
@@ -296,7 +311,8 @@ export const collectRewind = ({
|
|
|
296
311
|
roadmap: {
|
|
297
312
|
plans: shownPlans,
|
|
298
313
|
plansOmitted: orderedPlans.length - shownPlans.length,
|
|
299
|
-
|
|
314
|
+
// Another worktree's finished objective is history, not roadmap.
|
|
315
|
+
litgoal: (litgoal ?? []).filter((goal) => goal.local || goal.status !== "complete"),
|
|
300
316
|
progress: roadmapItems.length ? aggregateProgress(roadmapItems) : progressOf(null, null),
|
|
301
317
|
},
|
|
302
318
|
workflows: (workflows ?? []).map((frame) => ({ ...frame, self: Boolean(sessionId) && frame.sessionId === sessionId })),
|
|
@@ -333,37 +349,45 @@ const remainingLine = (names, width) => {
|
|
|
333
349
|
return out;
|
|
334
350
|
};
|
|
335
351
|
|
|
352
|
+
// A gauge with its leading space, or nothing: an unknown total has no gauge to print.
|
|
353
|
+
const shown = (progress) => (progress?.gauge ? ` ${progress.gauge}` : "");
|
|
354
|
+
|
|
336
355
|
/** Plain-text rendering: every gauge with its remaining names under it, clipped to `width`. */
|
|
337
356
|
export const renderRewind = (data, width = 100) => {
|
|
338
357
|
const out = [];
|
|
339
358
|
const push = (text) => out.push(line(text, width));
|
|
340
359
|
push(`lit-adhd: ${data.summary.sessions} session(s), ${data.summary.waitingOnUser} waiting on you, ${data.summary.active} active`);
|
|
341
|
-
push(`roadmap here
|
|
360
|
+
push(`roadmap here${shown(data.roadmap.progress)}`);
|
|
342
361
|
for (const plan of data.roadmap.plans) {
|
|
343
|
-
push(` ${plan.local ? "" : `${basename(plan.worktree)}: `}${plan.plan}
|
|
362
|
+
push(` ${plan.local ? "" : `${basename(plan.worktree)}: `}${plan.plan}${shown(plan.progress)} now: ${plan.current}`);
|
|
344
363
|
const left = remainingLine(plan.progress.remaining, width);
|
|
345
364
|
if (left) push(` ${left}`);
|
|
346
365
|
}
|
|
347
366
|
if (data.roadmap.plansOmitted) push(` …(+${data.roadmap.plansOmitted} more open plans)`);
|
|
348
|
-
for (const goal of data.roadmap.litgoal) push(` litgoal
|
|
367
|
+
for (const goal of data.roadmap.litgoal) push(` litgoal${shown(goal.progress)} ${goal.objective}`);
|
|
349
368
|
for (const session of data.sessions) {
|
|
350
|
-
push(`${session.id8} ${session.status}
|
|
369
|
+
push(`${session.id8} ${session.status}${shown(session.progress)} ${session.title}`);
|
|
351
370
|
const left = remainingLine(session.progress.remaining, width);
|
|
352
371
|
if (left) push(left);
|
|
353
372
|
}
|
|
354
|
-
for (const frame of data.workflows) push(` ${frame.id8} ${frame.skill} ${frame.stage} ${frame.status}
|
|
373
|
+
for (const frame of data.workflows) push(` ${frame.id8} ${frame.skill} ${frame.stage} ${frame.status}${shown(frame.progress)}`);
|
|
355
374
|
push(`next: ${data.next.kind}${data.next.say ? ` (say "${data.next.say}")` : ""}`);
|
|
356
375
|
const unknown = Object.entries(data.sources).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
357
376
|
if (unknown.length) push(`unknown: ${unknown.join(", ")}`);
|
|
358
377
|
return `${out.join("\n")}\n`;
|
|
359
378
|
};
|
|
360
379
|
|
|
361
|
-
/**
|
|
380
|
+
/**
|
|
381
|
+
* `litclaude-ai rewind [--brief [--lang ko|en] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]`.
|
|
382
|
+
* `--brief` prints the Markdown brief the lit-adhd skill copies; `--json` the data under it.
|
|
383
|
+
*/
|
|
362
384
|
export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr } = {}) => {
|
|
363
385
|
const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: env.CLAUDE_CODE_SESSION_ID || null };
|
|
364
386
|
let json = false;
|
|
387
|
+
let brief = false;
|
|
388
|
+
let lang = "en";
|
|
365
389
|
let width = Number(stdout.columns) || 100;
|
|
366
|
-
const usage = "Usage: litclaude-ai rewind [--json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]";
|
|
390
|
+
const usage = "Usage: litclaude-ai rewind [--brief [--lang ko|en] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]";
|
|
367
391
|
if (args.some((arg) => arg === "--help" || arg === "-h")) {
|
|
368
392
|
stdout.write(`${usage}\n`);
|
|
369
393
|
return 0;
|
|
@@ -371,6 +395,8 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
|
|
|
371
395
|
for (let index = 0; index < args.length; index += 1) {
|
|
372
396
|
const arg = args[index];
|
|
373
397
|
if (arg === "--json") json = true;
|
|
398
|
+
else if (arg === "--brief") brief = true;
|
|
399
|
+
else if (arg === "--lang" && ["ko", "en"].includes(args[index + 1])) lang = args[++index];
|
|
374
400
|
else if (arg === "--here") options.here = true;
|
|
375
401
|
else if (arg === "--since" && parseSince(args[index + 1])) options.since = args[++index];
|
|
376
402
|
else if (arg === "--max" && /^\d{1,2}$/u.test(args[index + 1] ?? "")) options.max = Number(args[++index]);
|
|
@@ -382,6 +408,6 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
|
|
|
382
408
|
}
|
|
383
409
|
}
|
|
384
410
|
const data = collectRewind(options);
|
|
385
|
-
stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : renderRewind(data, width));
|
|
411
|
+
stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : brief ? renderBrief(data, { lang }) : renderRewind(data, width));
|
|
386
412
|
return 0;
|
|
387
413
|
};
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
// Progress gauges for the lit-adhd brief (plans/lit-adhd.md D9). Code draws them so
|
|
2
|
-
// copies them and never invents its own: `[▉▉▉░░] 3/5`, one cell per item up to ten, scaled
|
|
3
|
-
// cells above that
|
|
1
|
+
// Progress gauges for the lit-adhd brief and the LIT card (plans/lit-adhd.md D9). Code draws them so
|
|
2
|
+
// the model copies them and never invents its own: `[▉▉▉░░] 3/5`, one cell per item up to ten, scaled
|
|
3
|
+
// to ten cells above that. A gauge needs two real numbers; with either missing there is no gauge, and
|
|
4
|
+
// the reader gets what is known in words instead (knownFacts).
|
|
4
5
|
|
|
5
6
|
const MAX_CELLS = 10;
|
|
6
7
|
const known = (value) => Number.isInteger(value) && value >= 0;
|
|
7
8
|
|
|
8
|
-
/** `[▉▉▉░░] 3/5
|
|
9
|
+
/** `[▉▉▉░░] 3/5`, or null unless both the count and a total above zero are known. */
|
|
9
10
|
export const gauge = (done, total) => {
|
|
10
|
-
if (!known(total)
|
|
11
|
-
const k =
|
|
11
|
+
if (!known(total) || total === 0 || !known(done)) return null;
|
|
12
|
+
const k = Math.min(done, total);
|
|
12
13
|
const cells = Math.min(total, MAX_CELLS);
|
|
13
14
|
let filled = k;
|
|
14
15
|
if (total > MAX_CELLS) filled = k === total ? MAX_CELLS : k === 0 ? 0 : Math.min(MAX_CELLS - 1, Math.max(1, Math.floor((k * MAX_CELLS) / total)));
|
|
15
16
|
return `[${"▉".repeat(filled)}${"░".repeat(cells - filled)}] ${k}/${total}`;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
const duration = (ms) => {
|
|
20
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
21
|
+
if (seconds < 60) return `${seconds}s`;
|
|
22
|
+
const minutes = Math.floor(seconds / 60);
|
|
23
|
+
if (minutes < 60) return `${minutes}m`;
|
|
24
|
+
const hours = Math.floor(minutes / 60);
|
|
25
|
+
return minutes % 60 ? `${hours}h ${minutes % 60}m` : `${hours}h`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What is known of a thread whose total is not: `12 steps · 4m · last: Edit README.md`, or with no
|
|
30
|
+
* steps `running 4m` (`paused 4m`, …, by `state`), or the state word alone.
|
|
31
|
+
*/
|
|
32
|
+
export const knownFacts = ({ steps = null, elapsedMs = null, last = null, state = "running" } = {}) => {
|
|
33
|
+
const time = Number.isFinite(elapsedMs) && elapsedMs >= 0 ? duration(elapsedMs) : null;
|
|
34
|
+
if (!(known(steps) && steps > 0)) return time ? `${state} ${time}` : state;
|
|
35
|
+
return [`${steps} ${steps === 1 ? "step" : "steps"}`, time, last ? `last: ${last}` : null].filter(Boolean).join(" · ");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** `{done, total, gauge, remaining}`; `gauge` is null without two real numbers, `remaining` as recorded or `["unknown"]`. */
|
|
19
39
|
export const progressOf = (done, total, remaining) => ({
|
|
20
40
|
done: known(done) ? done : null,
|
|
21
41
|
total: known(total) ? total : null,
|
|
@@ -23,7 +43,7 @@ export const progressOf = (done, total, remaining) => ({
|
|
|
23
43
|
remaining: Array.isArray(remaining) && remaining.length ? remaining : known(total) && known(done) && done >= total ? [] : ["unknown"],
|
|
24
44
|
});
|
|
25
45
|
|
|
26
|
-
/** One gauge over several: the sum of known totals, or
|
|
46
|
+
/** One gauge over several: the sum of known totals, or no gauge when any total is unknown. */
|
|
27
47
|
export const aggregateProgress = (items) => {
|
|
28
48
|
const done = items.reduce((sum, item) => sum + (known(item.done) ? item.done : 0), 0);
|
|
29
49
|
const total = items.every((item) => known(item.total)) ? items.reduce((sum, item) => sum + item.total, 0) : null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The SessionStart nudge toward lit-adhd: when this folder has other Claude Code sessions from the
|
|
2
|
+
// last three days, say once a day that `lit adhd` briefs them all on one screen. It looks only at
|
|
3
|
+
// this folder's own transcript folder (no scan of other projects) and stats file times, never
|
|
4
|
+
// contents, so it stays cheap on every session start. A marker under `.litclaude/adhd/` keeps it
|
|
5
|
+
// to one nudge per calendar day per project.
|
|
6
|
+
import { lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
import { projectSlug } from "./transcripts.mjs";
|
|
10
|
+
|
|
11
|
+
export const RECENT_MS = 3 * 24 * 60 * 60 * 1000;
|
|
12
|
+
const SCAN_LIMIT = 400;
|
|
13
|
+
|
|
14
|
+
const dayOf = (now) => new Date(now).toISOString().slice(0, 10);
|
|
15
|
+
|
|
16
|
+
const recentOthers = (folder, sessionId, now) => {
|
|
17
|
+
let names;
|
|
18
|
+
try {
|
|
19
|
+
names = readdirSync(folder).filter((name) => name.endsWith(".jsonl")).slice(0, SCAN_LIMIT);
|
|
20
|
+
} catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return names.filter((name) => {
|
|
24
|
+
if (name === `${sessionId}.jsonl`) return false;
|
|
25
|
+
try {
|
|
26
|
+
const stat = lstatSync(join(folder, name));
|
|
27
|
+
return stat.isFile() && now - stat.mtimeMs < RECENT_MS;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}).length;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The one-line suggestion, or null when there is nothing to suggest or it was already made today.
|
|
36
|
+
* Making it records today's date in `<stateRoot>/.litclaude/adhd/suggested.json`.
|
|
37
|
+
*/
|
|
38
|
+
export const adhdSuggestion = ({ cwd, sessionId, configDir, stateRoot, now = Date.now() }) => {
|
|
39
|
+
const count = recentOthers(join(configDir, "projects", projectSlug(cwd)), sessionId, now);
|
|
40
|
+
if (count === 0) return null;
|
|
41
|
+
const dir = join(stateRoot, ".litclaude", "adhd");
|
|
42
|
+
const marker = join(dir, "suggested.json");
|
|
43
|
+
try {
|
|
44
|
+
if (JSON.parse(readFileSync(marker, "utf8")).day === dayOf(now)) return null;
|
|
45
|
+
} catch {
|
|
46
|
+
// No marker yet, or an unreadable one: suggest and rewrite it.
|
|
47
|
+
}
|
|
48
|
+
mkdirSync(dir, { recursive: true });
|
|
49
|
+
writeFileSync(marker, `${JSON.stringify({ day: dayOf(now) })}\n`);
|
|
50
|
+
return `${count} other recent ${count === 1 ? "session" : "sessions"} here · type \`lit adhd\` for a one-screen brief of where each stands`;
|
|
51
|
+
};
|