@vitorcen/context-resume 1.0.5 → 1.0.7

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.
@@ -12,6 +12,37 @@ function createPreview(content, maxLength = 500) {
12
12
  const end = content.slice(content.length - (maxLength / 2));
13
13
  return `${start}\n\n... [${content.length - maxLength} characters omitted] ...\n\n${end}`;
14
14
  }
15
+ function readFirstNonEmptyLine(filePath, maxBytes = 5 * 1024 * 1024) {
16
+ const fd = fs.openSync(filePath, 'r');
17
+ try {
18
+ const buffer = Buffer.alloc(64 * 1024);
19
+ let position = 0;
20
+ let totalBytes = 0;
21
+ let acc = '';
22
+ while (totalBytes < maxBytes) {
23
+ const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, position);
24
+ if (bytesRead <= 0) {
25
+ break;
26
+ }
27
+ position += bytesRead;
28
+ totalBytes += bytesRead;
29
+ acc += buffer.subarray(0, bytesRead).toString('utf-8');
30
+ let newlineIndex = acc.indexOf('\n');
31
+ while (newlineIndex !== -1) {
32
+ const line = acc.slice(0, newlineIndex);
33
+ if (line.trim() !== '') {
34
+ return line;
35
+ }
36
+ acc = acc.slice(newlineIndex + 1);
37
+ newlineIndex = acc.indexOf('\n');
38
+ }
39
+ }
40
+ }
41
+ finally {
42
+ fs.closeSync(fd);
43
+ }
44
+ return null;
45
+ }
15
46
  // --- Claude Adapter ---
16
47
  function normalizeCwd(cwd) {
17
48
  return path.resolve(cwd);
@@ -79,6 +110,11 @@ export async function getClaudeSessions(cwd, limit = 10) {
79
110
  // ignore parse errors
80
111
  }
81
112
  }
113
+ const cleanedPrompts = userPrompts
114
+ .map(p => p.trim())
115
+ .filter(p => p && p.toLowerCase() !== 'warmup' && p.toLowerCase() !== 'new session');
116
+ if (cleanedPrompts.length === 0)
117
+ continue;
82
118
  // Create preview: Start ... End
83
119
  const preview = createPreview(fullContent);
84
120
  const stats = fs.statSync(filePath);
@@ -86,7 +122,7 @@ export async function getClaudeSessions(cwd, limit = 10) {
86
122
  id: path.basename(file, '.jsonl'),
87
123
  title: firstUserMessage.slice(0, 50) + (firstUserMessage.length > 50 ? '...' : ''),
88
124
  preview,
89
- userPrompts,
125
+ userPrompts: cleanedPrompts,
90
126
  timestamp: stats.mtimeMs,
91
127
  source: 'claude',
92
128
  path: filePath
@@ -114,21 +150,17 @@ export async function getCodexSessions(cwd, limit = 10) {
114
150
  // Filter by CWD and sort by time
115
151
  const relevantFiles = [];
116
152
  for (const filePath of files) {
117
- // We need to peek at the first line to check CWD
153
+ // Read the first non-empty line (session_meta can exceed 4KB).
118
154
  try {
119
- const fd = fs.openSync(filePath, 'r');
120
- const buffer = Buffer.alloc(4096); // Read first 4KB
121
- const bytesRead = fs.readSync(fd, buffer, 0, 4096, 0);
122
- fs.closeSync(fd);
123
- const chunk = buffer.toString('utf-8', 0, bytesRead);
124
- const firstLine = chunk.split('\n')[0];
125
- if (firstLine) {
126
- const meta = JSON.parse(firstLine);
127
- const metaCwd = typeof meta.payload?.cwd === 'string' ? normalizeCwd(meta.payload.cwd) : '';
128
- if (meta.type === 'session_meta' && metaCwd === resolvedCwd) {
129
- const stats = fs.statSync(filePath);
130
- relevantFiles.push({ filePath, mtime: stats.mtimeMs });
131
- }
155
+ const firstLine = readFirstNonEmptyLine(filePath);
156
+ if (!firstLine) {
157
+ continue;
158
+ }
159
+ const meta = JSON.parse(firstLine);
160
+ const metaCwd = typeof meta.payload?.cwd === 'string' ? normalizeCwd(meta.payload.cwd) : '';
161
+ if (meta.type === 'session_meta' && metaCwd === resolvedCwd) {
162
+ const stats = fs.statSync(filePath);
163
+ relevantFiles.push({ filePath, mtime: stats.mtimeMs });
132
164
  }
133
165
  }
134
166
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitorcen/context-resume",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Context Resume CLI - Browse and mutually restore the conversation history of Claude Code and Codex",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",