@hype/clod 1.1.0 → 1.3.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/README.md +7 -0
- package/dist/cli.js +28 -0
- package/dist/index.js +13 -3
- package/dist/list.js +15 -6
- package/dist/sessions.js +38 -12
- package/dist/stats.js +1 -1
- package/dist/ui.js +15 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -43,6 +43,13 @@ clod
|
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
45
45
|
|
|
46
|
+
`clod` takes no arguments. Running it launches the session browser. Two flags print and exit:
|
|
47
|
+
|
|
48
|
+
| Flag | Action |
|
|
49
|
+
|------|--------|
|
|
50
|
+
| `-h`, `--help` | Print usage |
|
|
51
|
+
| `-v`, `--version` | Print version |
|
|
52
|
+
|
|
46
53
|
### Keys
|
|
47
54
|
|
|
48
55
|
| Key | Action |
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
// The linked bin runs from anywhere, so resolve relative to this module.
|
|
5
|
+
const PACKAGE_FILE = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
|
|
6
|
+
export function parseArgs(argv) {
|
|
7
|
+
if (argv.includes('-h') || argv.includes('--help'))
|
|
8
|
+
return 'help';
|
|
9
|
+
if (argv.includes('-v') || argv.includes('--version'))
|
|
10
|
+
return 'version';
|
|
11
|
+
return 'launch';
|
|
12
|
+
}
|
|
13
|
+
export async function readPackage(file = PACKAGE_FILE) {
|
|
14
|
+
const pkg = JSON.parse(await readFile(file, 'utf8'));
|
|
15
|
+
return { version: pkg.version, description: pkg.description, homepage: pkg.homepage };
|
|
16
|
+
}
|
|
17
|
+
export function helpText(pkg) {
|
|
18
|
+
return `clod - ${pkg.description}
|
|
19
|
+
|
|
20
|
+
Usage: clod [options]
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
-h, --help Show help
|
|
24
|
+
-v, --version Show version
|
|
25
|
+
|
|
26
|
+
Run with no arguments to launch the session browser.
|
|
27
|
+
Keybindings and usage: ${pkg.homepage}`;
|
|
28
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { helpText, parseArgs, readPackage } from './cli.js';
|
|
3
|
+
import { loadConfig } from './config.js';
|
|
4
|
+
import { listSessionFiles, parseSessions } from './sessions.js';
|
|
5
|
+
const action = parseArgs(process.argv.slice(2));
|
|
6
|
+
if (action === 'help') {
|
|
7
|
+
console.log(helpText(await readPackage()));
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
if (action === 'version') {
|
|
11
|
+
console.log((await readPackage()).version);
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
4
14
|
// Parse enough newest sessions to fill a viewport; stream the rest in later.
|
|
5
15
|
const FIRST_BATCH = 40;
|
|
6
16
|
const files = await listSessionFiles();
|
|
@@ -14,7 +24,7 @@ const loadRest = files.length > FIRST_BATCH ? () => parseSessions(files.slice(FI
|
|
|
14
24
|
const [{ default: React }, { render }, { default: App }, config] = await Promise.all([
|
|
15
25
|
import('react'),
|
|
16
26
|
import('ink'),
|
|
17
|
-
import(
|
|
27
|
+
import('./ui.js'),
|
|
18
28
|
loadConfig()
|
|
19
29
|
]);
|
|
20
30
|
// Object holder: TS narrows a reassigned `let` back to null after the closure,
|
package/dist/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fmtTokens, relativeTime, shortPath } from
|
|
1
|
+
import { fmtTokens, relativeTime, shortPath } from './sessions.js';
|
|
2
2
|
// items[i] is always a session here: callers skip headers before calling.
|
|
3
3
|
const sessionIdAt = (items, i) => items[i].session.sessionId;
|
|
4
4
|
// below these widths a column is hidden rather than truncated into noise
|
|
@@ -18,6 +18,12 @@ export function pad(str, len) {
|
|
|
18
18
|
export function padLeft(str, len) {
|
|
19
19
|
return str.length >= len ? str.slice(0, len) : ' '.repeat(len - str.length) + str;
|
|
20
20
|
}
|
|
21
|
+
export function displayTitle(session) {
|
|
22
|
+
if (session.title)
|
|
23
|
+
return { text: session.title, fallback: false };
|
|
24
|
+
const prompt = session.firstUserMessage?.replace(/\s+/g, ' ').trim();
|
|
25
|
+
return { text: prompt || 'Untitled', fallback: true };
|
|
26
|
+
}
|
|
21
27
|
// subsequence fuzzy match: query chars must appear in order, case-insensitive
|
|
22
28
|
export function fuzzyMatch(query, target) {
|
|
23
29
|
if (!query)
|
|
@@ -34,7 +40,8 @@ export function fuzzyMatch(query, target) {
|
|
|
34
40
|
// Title matches fuzzy (it's short); content matches by substring (fuzzy over a
|
|
35
41
|
// long blob hits everything).
|
|
36
42
|
export function sessionMatches(query, session) {
|
|
37
|
-
|
|
43
|
+
const { text, fallback } = displayTitle(session);
|
|
44
|
+
if ((!fallback || text === 'Untitled') && fuzzyMatch(query, text))
|
|
38
45
|
return true;
|
|
39
46
|
return session.searchText ? session.searchText.includes(query.toLowerCase()) : false;
|
|
40
47
|
}
|
|
@@ -50,9 +57,10 @@ export function computeRowLayout(opts) {
|
|
|
50
57
|
const showDir = sortMode !== 'directory';
|
|
51
58
|
// flex = space for title + branch + dir after the fixed right block
|
|
52
59
|
// (used/ctx/time + three 2-space gaps).
|
|
53
|
-
const fullTitle = session
|
|
60
|
+
const { text: fullTitle, fallback } = displayTitle(session);
|
|
54
61
|
const flex = termWidth - 2 - usedWidth - ctxWidth - timeWidth - 6;
|
|
55
|
-
|
|
62
|
+
const claim = fallback ? Math.min(fullTitle.length, Math.floor(flex / 2)) : fullTitle.length;
|
|
63
|
+
let avail = flex - claim;
|
|
56
64
|
let dirWidth = 0;
|
|
57
65
|
if (showDir && avail >= DIR_MIN + 2) {
|
|
58
66
|
dirWidth = Math.min(pathStr.length, avail - 2);
|
|
@@ -67,6 +75,7 @@ export function computeRowLayout(opts) {
|
|
|
67
75
|
const titleWidth = Math.max(1, flex - (dirWidth ? dirWidth + 2 : 0) - (branchWidth ? branchWidth + 2 : 0));
|
|
68
76
|
return {
|
|
69
77
|
title: pad(truncate(fullTitle, titleWidth), titleWidth),
|
|
78
|
+
titleFallback: fallback,
|
|
70
79
|
branchCol: branchWidth > 0 ? truncate(naturalBranch, branchWidth) : null,
|
|
71
80
|
dirCol: dirWidth > 0 ? truncate(pathStr, dirWidth) : null,
|
|
72
81
|
usedCol: padLeft(usedStr(session), usedWidth),
|
|
@@ -82,8 +91,8 @@ export function buildDisplayItems(sessions, sortMode) {
|
|
|
82
91
|
}
|
|
83
92
|
else if (sortMode === 'lexic') {
|
|
84
93
|
sorted = [...sessions].sort((a, b) => {
|
|
85
|
-
const ta = a.
|
|
86
|
-
const tb = b.
|
|
94
|
+
const ta = displayTitle(a).text;
|
|
95
|
+
const tb = displayTitle(b).text;
|
|
87
96
|
return ta < tb ? -1 : ta > tb ? 1 : b.lastTimestamp - a.lastTimestamp;
|
|
88
97
|
});
|
|
89
98
|
}
|
package/dist/sessions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFile, readdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
-
import { trashPaths } from
|
|
4
|
+
import { trashPaths } from './trash.js';
|
|
5
5
|
// Resolved lazily so tests can point $HOME at a fixture tree; os.homedir()
|
|
6
6
|
// honors $HOME on posix, read afresh each call.
|
|
7
7
|
const claudeDir = () => join(homedir(), '.claude');
|
|
@@ -9,10 +9,31 @@ const projectsDir = () => join(claudeDir(), 'projects');
|
|
|
9
9
|
// Claude Code injects system content as XML-tagged blocks; any message starting
|
|
10
10
|
// with an opening tag is injected content, not a real user message
|
|
11
11
|
const INJECTED = /^<[a-z]/i;
|
|
12
|
-
|
|
12
|
+
// Claude Code writes "[Request interrupted by user]" and the like as user records
|
|
13
|
+
const NOTICE = /^\[[^\]]*\]$/;
|
|
14
|
+
// A slash command arrives as one injected block, with what the user typed inside
|
|
15
|
+
// <command-args>; without this the whole prompt reads as system content.
|
|
16
|
+
const COMMAND = /<command-name>([^<]*)<\/command-name>(?:\s*<command-args>([\s\S]*?)<\/command-args>)?/;
|
|
17
|
+
function rawText(content) {
|
|
18
|
+
if (typeof content === 'string')
|
|
19
|
+
return content;
|
|
20
|
+
if (Array.isArray(content))
|
|
21
|
+
return content.find((b) => b.type === 'text')?.text ?? '';
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
function userText(record) {
|
|
13
25
|
if (record.type !== 'user' || record.isMeta)
|
|
14
|
-
return
|
|
26
|
+
return null;
|
|
15
27
|
const content = record.message?.content;
|
|
28
|
+
if (hasRealText(content))
|
|
29
|
+
return extractText(content);
|
|
30
|
+
const m = COMMAND.exec(rawText(content));
|
|
31
|
+
if (!m)
|
|
32
|
+
return null;
|
|
33
|
+
const args = m[2]?.trim();
|
|
34
|
+
return args ? `${m[1].trim()} ${args}` : m[1].trim();
|
|
35
|
+
}
|
|
36
|
+
function hasRealText(content) {
|
|
16
37
|
if (typeof content === 'string')
|
|
17
38
|
return !INJECTED.test(content);
|
|
18
39
|
if (Array.isArray(content))
|
|
@@ -92,6 +113,7 @@ export async function parseSession(filePath, fileStats) {
|
|
|
92
113
|
let title = null;
|
|
93
114
|
let cwd = null;
|
|
94
115
|
let gitBranch = null;
|
|
116
|
+
let firstUserMessage = null;
|
|
95
117
|
let lastUserMessage = null;
|
|
96
118
|
let lastTimestamp = null;
|
|
97
119
|
let contextTokens = null; // input context of the most recent assistant turn
|
|
@@ -135,9 +157,15 @@ export async function parseSession(filePath, fileStats) {
|
|
|
135
157
|
contextTokens = ctx;
|
|
136
158
|
searchParts.push(textBlocks(r.message?.content));
|
|
137
159
|
}
|
|
138
|
-
else
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
else {
|
|
161
|
+
const text = userText(r);
|
|
162
|
+
if (text !== null) {
|
|
163
|
+
lastUserMessage = text;
|
|
164
|
+
searchParts.push(text);
|
|
165
|
+
const trimmed = text.trim();
|
|
166
|
+
if (!firstUserMessage && trimmed && !NOTICE.test(trimmed))
|
|
167
|
+
firstUserMessage = trimmed;
|
|
168
|
+
}
|
|
141
169
|
}
|
|
142
170
|
}
|
|
143
171
|
catch { }
|
|
@@ -172,6 +200,7 @@ export async function parseSession(filePath, fileStats) {
|
|
|
172
200
|
title,
|
|
173
201
|
cwd,
|
|
174
202
|
gitBranch,
|
|
203
|
+
firstUserMessage,
|
|
175
204
|
lastUserMessage,
|
|
176
205
|
contextTokens,
|
|
177
206
|
models,
|
|
@@ -234,12 +263,9 @@ export async function getSessionMessages(filePath) {
|
|
|
234
263
|
for (const line of raw.split('\n').filter(Boolean)) {
|
|
235
264
|
try {
|
|
236
265
|
const r = JSON.parse(line);
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
text: extractText(r.message?.content),
|
|
241
|
-
timestamp: r.timestamp
|
|
242
|
-
});
|
|
266
|
+
const text = userText(r);
|
|
267
|
+
if (text !== null) {
|
|
268
|
+
messages.push({ role: 'user', text, timestamp: r.timestamp });
|
|
243
269
|
}
|
|
244
270
|
else if (r.type === 'assistant') {
|
|
245
271
|
const content = r.message?.content;
|
package/dist/stats.js
CHANGED
package/dist/ui.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Box, Text, useApp, useInput, useStdout } from 'ink';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { saveConfig } from
|
|
4
|
-
import { buildDisplayItems, computeNavigate, computePage, computeRowLayout, ctxStr, filterItems, findAdjacentSessionId, nextSortMode, pad, termSize, truncate, usedStr } from
|
|
5
|
-
import { deleteSession, fmtTokens, getSessionMessages, MONTHS, relativeTime, renameSession, shortPath } from
|
|
6
|
-
import { bar, computeStats, sparkline } from
|
|
3
|
+
import { saveConfig } from './config.js';
|
|
4
|
+
import { buildDisplayItems, computeNavigate, computePage, computeRowLayout, ctxStr, displayTitle, filterItems, findAdjacentSessionId, nextSortMode, pad, termSize, truncate, usedStr } from './list.js';
|
|
5
|
+
import { deleteSession, fmtTokens, getSessionMessages, MONTHS, relativeTime, renameSession, shortPath } from './sessions.js';
|
|
6
|
+
import { bar, computeStats, sparkline } from './stats.js';
|
|
7
7
|
const h = React.createElement;
|
|
8
8
|
const { useState, useEffect, useMemo, memo } = React;
|
|
9
9
|
const HINT_HEIGHT = 1;
|
|
@@ -11,7 +11,7 @@ const HEADER_HEIGHT = 2;
|
|
|
11
11
|
const SNIPPET_HEIGHT = 3;
|
|
12
12
|
// ─── Row ─────────────────────────────────────────────────────────────────────
|
|
13
13
|
const SessionRow = memo(function SessionRow({ session, selected, termWidth, sortMode, timeWidth, usedWidth, ctxWidth }) {
|
|
14
|
-
const { title, branchCol, dirCol, usedCol, ctxCol, timeCol } = computeRowLayout({
|
|
14
|
+
const { title, titleFallback, branchCol, dirCol, usedCol, ctxCol, timeCol } = computeRowLayout({
|
|
15
15
|
session,
|
|
16
16
|
termWidth,
|
|
17
17
|
sortMode,
|
|
@@ -22,11 +22,11 @@ const SessionRow = memo(function SessionRow({ session, selected, termWidth, sort
|
|
|
22
22
|
if (selected) {
|
|
23
23
|
const branchPart = branchCol ? ` ${branchCol}` : '';
|
|
24
24
|
const dirPart = dirCol ? ` ${dirCol}` : '';
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
return h(Box, {}, h(Text,
|
|
25
|
+
const rest = `${branchPart}${dirPart} ${usedCol} ${ctxCol} ${timeCol}`;
|
|
26
|
+
const hl = { backgroundColor: 'grey', color: 'white', bold: true };
|
|
27
|
+
return h(Box, {}, h(Text, hl, '> '), h(Text, { ...hl, bold: !titleFallback, italic: titleFallback }, title), h(Text, hl, pad(rest, Math.max(0, termWidth - 2 - title.length))));
|
|
28
28
|
}
|
|
29
|
-
return h(Box, { flexDirection: 'row' }, h(Text, {}, ' '), h(Text, {}, title), branchCol ? h(Text, { color: 'yellow', dimColor: true }, ` ${branchCol}`) : null, dirCol ? h(Text, { color: 'cyan', dimColor: true }, ` ${dirCol}`) : null, h(Text, { dimColor: true }, ` ${usedCol}`), h(Text, { color: 'green', dimColor: true }, ` ${ctxCol}`), h(Text, { dimColor: true }, ` ${timeCol}`));
|
|
29
|
+
return h(Box, { flexDirection: 'row' }, h(Text, {}, ' '), h(Text, { dimColor: titleFallback, italic: titleFallback }, title), branchCol ? h(Text, { color: 'yellow', dimColor: true }, ` ${branchCol}`) : null, dirCol ? h(Text, { color: 'cyan', dimColor: true }, ` ${dirCol}`) : null, h(Text, { dimColor: true }, ` ${usedCol}`), h(Text, { color: 'green', dimColor: true }, ` ${ctxCol}`), h(Text, { dimColor: true }, ` ${timeCol}`));
|
|
30
30
|
});
|
|
31
31
|
// ─── Row rename field ────────────────────────────────────────────────────────
|
|
32
32
|
function InputText({ value, cursor, termWidth }) {
|
|
@@ -98,12 +98,15 @@ function PreviewMode({ session, onBack, termWidth, termHeight, loadMessages }) {
|
|
|
98
98
|
}
|
|
99
99
|
if (!messages)
|
|
100
100
|
return;
|
|
101
|
+
// below minScroll the window is already at the top, so further ups only
|
|
102
|
+
// bank presses the next down has to spend getting back
|
|
103
|
+
const minScroll = Math.min(Math.max(0, viewHeight - 2), Math.max(0, messages.length - 1));
|
|
101
104
|
if (key.downArrow)
|
|
102
105
|
setScroll((s) => Math.min(s + 1, Math.max(0, messages.length - 1)));
|
|
103
106
|
if (key.upArrow)
|
|
104
|
-
setScroll((s) => Math.max(
|
|
107
|
+
setScroll((s) => Math.max(minScroll, s - 1));
|
|
105
108
|
});
|
|
106
|
-
const headerTitle = truncate(session.
|
|
109
|
+
const headerTitle = truncate(displayTitle(session).text, termWidth - 10);
|
|
107
110
|
return h(Box, { flexDirection: 'column' }, h(Box, { flexDirection: 'row', paddingX: 1 }, h(Text, { color: 'white', bold: true }, `Preview: ${headerTitle}`)), h(Box, { flexDirection: 'column', height: viewHeight }, messages === null
|
|
108
111
|
? h(Box, { padding: 1 }, h(Text, { dimColor: true }, 'Loading…'))
|
|
109
112
|
: messages.length === 0
|
|
@@ -136,7 +139,7 @@ function DeleteConfirm({ session, onConfirm, onCancel, termWidth, termHeight, lo
|
|
|
136
139
|
});
|
|
137
140
|
const previewHeight = termHeight - 6; // header + id + prompt + status
|
|
138
141
|
const previewMessages = messages?.slice(-previewHeight) ?? [];
|
|
139
|
-
return h(Box, { flexDirection: 'column' }, h(Box, { paddingX: 1 }, h(Text, { color: 'white', bold: true }, `Delete: ${truncate(session.
|
|
142
|
+
return h(Box, { flexDirection: 'column' }, h(Box, { paddingX: 1 }, h(Text, { color: 'white', bold: true }, `Delete: ${truncate(displayTitle(session).text, termWidth - 10)}`)), h(Box, { paddingX: 1 }, h(Text, { dimColor: true }, session.sessionId)), h(Box, { flexDirection: 'column', height: previewHeight, paddingX: 1 }, messages === null
|
|
140
143
|
? h(Text, { dimColor: true }, 'Loading…')
|
|
141
144
|
: previewMessages.length === 0
|
|
142
145
|
? h(Text, { dimColor: true }, 'No messages.')
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hype/clod",
|
|
3
3
|
"description": "Terminal UI for managing Claude Code sessions.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Nate Goldman <ungoldman@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"clod": "./dist/index.js"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@types/node": "^22.20.0",
|
|
18
18
|
"@types/react": "^19.2.17",
|
|
19
19
|
"ink-testing-library": "^4.0.0",
|
|
20
|
-
"typescript": "^
|
|
20
|
+
"typescript": "^7.0.2"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=22"
|