tuiboard 0.11.0 → 0.12.0
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/.tuiboard/config.example.yaml +29 -9
- package/CHANGELOG.md +71 -0
- package/README.md +63 -30
- package/package.json +3 -2
- package/src/config/loader.ts +32 -7
- package/src/input/handleKey.ts +65 -51
- package/src/input/open-session.ts +403 -0
- package/src/store/agent-adapters/claude-code.ts +348 -0
- package/src/store/agent-adapters/codex.ts +405 -0
- package/src/store/agent-adapters/index.ts +17 -0
- package/src/store/agent-adapters/opencode.ts +195 -0
- package/src/store/agent-adapters/pi.ts +253 -0
- package/src/store/agents.ts +139 -336
- package/src/store/index.ts +45 -7
- package/src/ui/AgentRow.tsx +147 -41
- package/src/ui/AgentsBar.tsx +8 -3
- package/src/ui/Modal.tsx +40 -6
- package/src/ui/agent-line.ts +95 -0
- package/src/views/AgentsOnly.tsx +11 -5
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code adapter for the agents store.
|
|
3
|
+
*
|
|
4
|
+
* Reads:
|
|
5
|
+
* ~/.claude/projects/<slug>/<sessionId>.jsonl — transcripts
|
|
6
|
+
* ~/.claude/sessions/<sessionId>.json — live PID records
|
|
7
|
+
*
|
|
8
|
+
* Eager initial scan (1-2s for ~80 sessions) is acceptable startup cost.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
DORMANT_AFTER_MS,
|
|
17
|
+
cwdShort,
|
|
18
|
+
type AgentAdapter,
|
|
19
|
+
type AgentSession,
|
|
20
|
+
type AgentStatus,
|
|
21
|
+
} from "~/store/agents";
|
|
22
|
+
|
|
23
|
+
const CLAUDE_HOME = join(homedir(), ".claude");
|
|
24
|
+
const PROJECTS_DIR = join(CLAUDE_HOME, "projects");
|
|
25
|
+
const SESSIONS_DIR = join(CLAUDE_HOME, "sessions");
|
|
26
|
+
|
|
27
|
+
/** Threshold: PID record older than this means the Claude process likely crashed. */
|
|
28
|
+
const LIVE_STALE_AFTER_MS = 5 * 60 * 1000;
|
|
29
|
+
|
|
30
|
+
export interface LivePidRecord {
|
|
31
|
+
mtimeMs: number;
|
|
32
|
+
/** "busy" | "idle" | undefined */
|
|
33
|
+
status?: string;
|
|
34
|
+
pid?: number;
|
|
35
|
+
version?: string;
|
|
36
|
+
cwd?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Reverse Claude Code's path-to-slug encoding (lossy on case).
|
|
41
|
+
*
|
|
42
|
+
* Claude Code encodes the cwd by replacing every `:`, `\` and `/` with `-`.
|
|
43
|
+
*
|
|
44
|
+
* Windows "C:\Users\foo" → "C--Users-foo"
|
|
45
|
+
* POSIX "/home/foo" → "-home-foo"
|
|
46
|
+
*
|
|
47
|
+
* We can recognize a Windows-shaped slug by the `<letter>--` prefix
|
|
48
|
+
* (drive letter followed by colon → two leading dashes). Anything else
|
|
49
|
+
* is assumed POSIX. This works regardless of `process.platform`, so
|
|
50
|
+
* decoding remote-shape paths (sessions originated on a different OS)
|
|
51
|
+
* still produces something sensible.
|
|
52
|
+
*/
|
|
53
|
+
export function cwdFromSlug(slug: string): string {
|
|
54
|
+
// Windows drive letter shape: "C--Users-foo" → "C:\Users\foo".
|
|
55
|
+
if (slug.length >= 3 && /^[A-Za-z]--/.test(slug)) {
|
|
56
|
+
return slug[0] + ":\\" + slug.slice(3).replaceAll("-", "\\");
|
|
57
|
+
}
|
|
58
|
+
// POSIX shape: "-home-foo" → "/home/foo".
|
|
59
|
+
if (slug.startsWith("-")) {
|
|
60
|
+
return "/" + slug.slice(1).replaceAll("-", "/");
|
|
61
|
+
}
|
|
62
|
+
// Fallback: bare directory name. Pick the separator from the host OS so
|
|
63
|
+
// the result at least concatenates correctly when the user copies it.
|
|
64
|
+
const sep = process.platform === "win32" ? "\\" : "/";
|
|
65
|
+
return slug.replaceAll("-", sep);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function classifyStatus(
|
|
69
|
+
now: number,
|
|
70
|
+
jsonlMtimeMs: number,
|
|
71
|
+
live: LivePidRecord | undefined,
|
|
72
|
+
): AgentStatus {
|
|
73
|
+
if (live) {
|
|
74
|
+
if (now - live.mtimeMs > LIVE_STALE_AFTER_MS) return "stale";
|
|
75
|
+
return live.status === "busy" ? "live-busy" : "live-idle";
|
|
76
|
+
}
|
|
77
|
+
const age = now - jsonlMtimeMs;
|
|
78
|
+
if (age > DORMANT_AFTER_MS) return "archived";
|
|
79
|
+
return "dormant";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface TranscriptParseResult {
|
|
83
|
+
customTitle?: string;
|
|
84
|
+
aiTitle?: string;
|
|
85
|
+
/**
|
|
86
|
+
* First user message that looks like a real human prompt — skill loaders,
|
|
87
|
+
* system tags, and bare slash-command invocations are filtered. Used as
|
|
88
|
+
* the displayName fallback when there is no custom/ai title.
|
|
89
|
+
*/
|
|
90
|
+
firstHumanUser?: string;
|
|
91
|
+
lastUser?: string;
|
|
92
|
+
lastAssistant?: string;
|
|
93
|
+
messageCount: number;
|
|
94
|
+
toolCount: number;
|
|
95
|
+
gitBranch?: string;
|
|
96
|
+
/** Model of the latest real assistant turn. */
|
|
97
|
+
model?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Heuristic: is this user "message" actually a skill/system bootstrap that
|
|
102
|
+
* Claude Code injected on session start? Used to skip these when picking
|
|
103
|
+
* a fallback displayName — otherwise N sessions opened by the same skill
|
|
104
|
+
* all look identical in the list.
|
|
105
|
+
*/
|
|
106
|
+
function looksSyntheticUser(text: string): boolean {
|
|
107
|
+
const t = text.trimStart();
|
|
108
|
+
if (!t) return true;
|
|
109
|
+
// Skill bootstrap: "Base directory for this skill: ..."
|
|
110
|
+
if (t.startsWith("Base directory for this skill")) return true;
|
|
111
|
+
// System-injected tags: <command-name>, <task-notification>, <system-reminder>, <local-command-stdout>
|
|
112
|
+
if (/^<[a-z][a-z0-9-]*>/i.test(t)) return true;
|
|
113
|
+
// Bare slash-command invocation (the literal "/morning", "/log", etc.)
|
|
114
|
+
if (/^\/[a-z][a-z0-9-]*\s*$/i.test(t)) return true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Lightweight pass over a jsonl transcript. Defensive: malformed lines
|
|
120
|
+
* are skipped silently because the format is internal to Claude Code
|
|
121
|
+
* and may drift between versions.
|
|
122
|
+
*/
|
|
123
|
+
export function parseTranscript(content: string): TranscriptParseResult {
|
|
124
|
+
let customTitle: string | undefined;
|
|
125
|
+
let aiTitle: string | undefined;
|
|
126
|
+
let firstHumanUser: string | undefined;
|
|
127
|
+
let lastUser: string | undefined;
|
|
128
|
+
let lastAssistant: string | undefined;
|
|
129
|
+
let gitBranch: string | undefined;
|
|
130
|
+
let model: string | undefined;
|
|
131
|
+
let messageCount = 0;
|
|
132
|
+
let toolCount = 0;
|
|
133
|
+
|
|
134
|
+
const recordUserText = (text: string) => {
|
|
135
|
+
lastUser = text;
|
|
136
|
+
if (firstHumanUser === undefined && !looksSyntheticUser(text)) {
|
|
137
|
+
firstHumanUser = text;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
for (const line of content.split("\n")) {
|
|
142
|
+
if (!line.trim()) continue;
|
|
143
|
+
let obj: any;
|
|
144
|
+
try {
|
|
145
|
+
obj = JSON.parse(line);
|
|
146
|
+
} catch {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (obj.gitBranch) gitBranch = obj.gitBranch;
|
|
150
|
+
const t = obj.type;
|
|
151
|
+
if (t === "custom-title") {
|
|
152
|
+
customTitle = obj.customTitle ?? obj.title ?? customTitle;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (t === "ai-title") {
|
|
156
|
+
aiTitle = obj.aiTitle ?? obj.title ?? aiTitle;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const msg = obj.message ?? {};
|
|
160
|
+
const role = msg.role;
|
|
161
|
+
if (role === "user") {
|
|
162
|
+
messageCount++;
|
|
163
|
+
const content = msg.content;
|
|
164
|
+
if (typeof content === "string") {
|
|
165
|
+
recordUserText(content);
|
|
166
|
+
} else if (Array.isArray(content)) {
|
|
167
|
+
for (const part of content) {
|
|
168
|
+
if (
|
|
169
|
+
part &&
|
|
170
|
+
typeof part === "object" &&
|
|
171
|
+
part.type === "text" &&
|
|
172
|
+
typeof part.text === "string"
|
|
173
|
+
) {
|
|
174
|
+
recordUserText(part.text);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} else if (role === "assistant") {
|
|
179
|
+
messageCount++;
|
|
180
|
+
if (typeof msg.model === "string" && !msg.model.startsWith("<")) model = msg.model;
|
|
181
|
+
const content = msg.content;
|
|
182
|
+
if (Array.isArray(content)) {
|
|
183
|
+
for (const part of content) {
|
|
184
|
+
if (!part || typeof part !== "object") continue;
|
|
185
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
186
|
+
lastAssistant = part.text;
|
|
187
|
+
} else if (part.type === "tool_use") {
|
|
188
|
+
toolCount++;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
customTitle,
|
|
197
|
+
aiTitle,
|
|
198
|
+
firstHumanUser,
|
|
199
|
+
lastUser,
|
|
200
|
+
lastAssistant,
|
|
201
|
+
messageCount,
|
|
202
|
+
toolCount,
|
|
203
|
+
gitBranch,
|
|
204
|
+
model,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ─── Discovery ──────────────────────────────────────────────────────────────
|
|
209
|
+
|
|
210
|
+
function discoverLivePids(): Map<string, LivePidRecord> {
|
|
211
|
+
const out = new Map<string, LivePidRecord>();
|
|
212
|
+
if (!existsSync(SESSIONS_DIR)) return out;
|
|
213
|
+
let entries: string[];
|
|
214
|
+
try {
|
|
215
|
+
entries = readdirSync(SESSIONS_DIR);
|
|
216
|
+
} catch {
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
for (const f of entries) {
|
|
220
|
+
if (!f.endsWith(".json")) continue;
|
|
221
|
+
const path = join(SESSIONS_DIR, f);
|
|
222
|
+
try {
|
|
223
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
224
|
+
const sid = raw.sessionId;
|
|
225
|
+
if (!sid) continue;
|
|
226
|
+
const stat = statSync(path);
|
|
227
|
+
out.set(sid, {
|
|
228
|
+
mtimeMs: stat.mtimeMs,
|
|
229
|
+
status: raw.status?.toLowerCase(),
|
|
230
|
+
pid: raw.pid,
|
|
231
|
+
version: raw.version,
|
|
232
|
+
cwd: raw.cwd,
|
|
233
|
+
});
|
|
234
|
+
} catch {
|
|
235
|
+
// ignore — malformed PID files happen during writes
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface JsonlEntry {
|
|
242
|
+
slug: string;
|
|
243
|
+
sessionId: string;
|
|
244
|
+
path: string;
|
|
245
|
+
mtimeMs: number;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function discoverJsonlFiles(): JsonlEntry[] {
|
|
249
|
+
const out: JsonlEntry[] = [];
|
|
250
|
+
if (!existsSync(PROJECTS_DIR)) return out;
|
|
251
|
+
let slugs: string[];
|
|
252
|
+
try {
|
|
253
|
+
slugs = readdirSync(PROJECTS_DIR);
|
|
254
|
+
} catch {
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
for (const slug of slugs) {
|
|
258
|
+
const slugDir = join(PROJECTS_DIR, slug);
|
|
259
|
+
let slugStat;
|
|
260
|
+
try {
|
|
261
|
+
slugStat = statSync(slugDir);
|
|
262
|
+
} catch {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (!slugStat.isDirectory()) continue;
|
|
266
|
+
let inner: string[];
|
|
267
|
+
try {
|
|
268
|
+
inner = readdirSync(slugDir);
|
|
269
|
+
} catch {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
for (const f of inner) {
|
|
273
|
+
// Skip subagent transcripts — they're addressed by their parent session.
|
|
274
|
+
if (!f.endsWith(".jsonl")) continue;
|
|
275
|
+
const path = join(slugDir, f);
|
|
276
|
+
try {
|
|
277
|
+
const stat = statSync(path);
|
|
278
|
+
if (!stat.isFile()) continue;
|
|
279
|
+
out.push({
|
|
280
|
+
slug,
|
|
281
|
+
sessionId: f.slice(0, -".jsonl".length),
|
|
282
|
+
path,
|
|
283
|
+
mtimeMs: stat.mtimeMs,
|
|
284
|
+
});
|
|
285
|
+
} catch {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function buildSession(
|
|
294
|
+
jsonl: JsonlEntry,
|
|
295
|
+
live: LivePidRecord | undefined,
|
|
296
|
+
now: number,
|
|
297
|
+
): AgentSession {
|
|
298
|
+
let parsed: TranscriptParseResult;
|
|
299
|
+
try {
|
|
300
|
+
parsed = parseTranscript(readFileSync(jsonl.path, "utf-8"));
|
|
301
|
+
} catch {
|
|
302
|
+
parsed = { messageCount: 0, toolCount: 0 };
|
|
303
|
+
}
|
|
304
|
+
const cwd = live?.cwd ?? cwdFromSlug(jsonl.slug);
|
|
305
|
+
const hasRealTitle = Boolean(parsed.customTitle || parsed.aiTitle);
|
|
306
|
+
const fallbackText =
|
|
307
|
+
parsed.firstHumanUser?.split("\n").find((l) => l.trim().length > 0)?.slice(0, 60) ??
|
|
308
|
+
parsed.lastUser?.split("\n").find((l) => l.trim().length > 0)?.slice(0, 60);
|
|
309
|
+
const uuid8 = jsonl.sessionId.slice(0, 8);
|
|
310
|
+
// When no human-authored title is available, suffix the uuid8 so visually
|
|
311
|
+
// identical fallback titles (e.g. many sessions started by the same /skill)
|
|
312
|
+
// still produce distinct rows.
|
|
313
|
+
const displayName = hasRealTitle
|
|
314
|
+
? (parsed.customTitle ?? parsed.aiTitle)!.slice(0, 60)
|
|
315
|
+
: fallbackText
|
|
316
|
+
? `${fallbackText} · ${uuid8}`
|
|
317
|
+
: uuid8;
|
|
318
|
+
return {
|
|
319
|
+
provider: "claude-code",
|
|
320
|
+
sessionId: jsonl.sessionId,
|
|
321
|
+
sourcePath: jsonl.path,
|
|
322
|
+
cwd,
|
|
323
|
+
cwdShort: cwdShort(cwd),
|
|
324
|
+
status: classifyStatus(now, jsonl.mtimeMs, live),
|
|
325
|
+
lastActivityMs: jsonl.mtimeMs,
|
|
326
|
+
customTitle: parsed.customTitle,
|
|
327
|
+
aiTitle: parsed.aiTitle,
|
|
328
|
+
displayName,
|
|
329
|
+
messageCount: parsed.messageCount,
|
|
330
|
+
toolCount: parsed.toolCount,
|
|
331
|
+
lastUser: parsed.lastUser,
|
|
332
|
+
lastAssistant: parsed.lastAssistant,
|
|
333
|
+
gitBranch: parsed.gitBranch,
|
|
334
|
+
model: parsed.model,
|
|
335
|
+
resumeCommand: `claude --resume ${jsonl.sessionId}`,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export const claudeCodeAdapter: AgentAdapter = {
|
|
340
|
+
provider: "claude-code",
|
|
341
|
+
watchPaths: () => [PROJECTS_DIR, SESSIONS_DIR],
|
|
342
|
+
discover(now) {
|
|
343
|
+
const live = discoverLivePids();
|
|
344
|
+
return discoverJsonlFiles().map((j) =>
|
|
345
|
+
buildSession(j, live.get(j.sessionId), now),
|
|
346
|
+
);
|
|
347
|
+
},
|
|
348
|
+
};
|