@hype/clod 1.2.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/dist/list.js +14 -5
- package/dist/sessions.js +37 -11
- package/dist/ui.js +12 -9
- package/package.json +1 -1
package/dist/list.js
CHANGED
|
@@ -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
|
@@ -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/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Box, Text, useApp, useInput, useStdout } from 'ink';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { saveConfig } from './config.js';
|
|
4
|
-
import { buildDisplayItems, computeNavigate, computePage, computeRowLayout, ctxStr, filterItems, findAdjacentSessionId, nextSortMode, pad, termSize, truncate, usedStr } from './list.js';
|
|
4
|
+
import { buildDisplayItems, computeNavigate, computePage, computeRowLayout, ctxStr, displayTitle, filterItems, findAdjacentSessionId, nextSortMode, pad, termSize, truncate, usedStr } from './list.js';
|
|
5
5
|
import { deleteSession, fmtTokens, getSessionMessages, MONTHS, relativeTime, renameSession, shortPath } from './sessions.js';
|
|
6
6
|
import { bar, computeStats, sparkline } from './stats.js';
|
|
7
7
|
const h = React.createElement;
|
|
@@ -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.')
|