rewound 0.5.0 → 0.5.1

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.
@@ -7,14 +7,42 @@ import path from "node:path";
7
7
  // trailing "\n" yet), the last fragment is torn — leave it unconsumed and
8
8
  // unparsed so the next incremental call re-reads it whole, rather than either
9
9
  // erroring on it or silently skipping past it.
10
- export function consumeCompleteLines(filePath, fromByte) {
10
+ // V8 caps a single string at ~512 MB (ERR_STRING_TOO_LONG), so decoding the
11
+ // whole consumed region in one toString() aborts on transcripts that grew past
12
+ // it even when every individual line is small (#2). Decode in newline-aligned
13
+ // chunks instead: cuts always land after a "\n" byte (0x0a never appears
14
+ // inside a multi-byte UTF-8 sequence), so no record and no character is ever
15
+ // split. A single line longer than the chunk is extended to its terminating
16
+ // newline rather than torn.
17
+ const DECODE_CHUNK_BYTES = 128 * 1024 * 1024;
18
+ export function consumeCompleteLines(filePath, fromByte, chunkBytes = DECODE_CHUNK_BYTES) {
11
19
  const buf = fs.readFileSync(filePath);
12
20
  const slice = buf.subarray(fromByte);
13
21
  const lastNewline = slice.lastIndexOf(0x0a); // "\n"
14
22
  const consumedSlice = lastNewline === -1 ? slice.subarray(0, 0) : slice.subarray(0, lastNewline + 1);
15
23
  const bytesConsumed = fromByte + consumedSlice.length;
16
- const text = consumedSlice.length > 0 ? consumedSlice.toString("utf8") : "";
17
- const lines = text.length > 0 ? text.split("\n") : [];
24
+ const lines = [];
25
+ let offset = 0;
26
+ while (offset < consumedSlice.length) {
27
+ let end = Math.min(offset + chunkBytes, consumedSlice.length);
28
+ if (end < consumedSlice.length) {
29
+ const nl = consumedSlice.lastIndexOf(0x0a, end - 1);
30
+ if (nl >= offset) {
31
+ end = nl + 1;
32
+ }
33
+ else {
34
+ // Single line longer than chunkBytes: consumedSlice always ends on a
35
+ // newline, so the forward scan is guaranteed to find one.
36
+ const next = consumedSlice.indexOf(0x0a, end);
37
+ end = next === -1 ? consumedSlice.length : next + 1;
38
+ }
39
+ }
40
+ for (const line of consumedSlice.subarray(offset, end).toString("utf8").split("\n")) {
41
+ if (line.length > 0)
42
+ lines.push(line); // callers skip blank lines anyway
43
+ }
44
+ offset = end;
45
+ }
18
46
  return { lines, bytesConsumed };
19
47
  }
20
48
  export function walkJsonlFiles(dir, found) {
package/dist/cli.js CHANGED
@@ -52,6 +52,7 @@ export function runIndex(opts, log = defaultLog) {
52
52
  filesUpdated: a.filesUpdated + b.filesUpdated + c.filesUpdated,
53
53
  messagesIndexed: a.messagesIndexed + b.messagesIndexed + c.messagesIndexed,
54
54
  parseErrors: a.parseErrors + b.parseErrors + c.parseErrors,
55
+ skippedFiles: [...a.skippedFiles, ...b.skippedFiles, ...c.skippedFiles],
55
56
  elapsedMs: a.elapsedMs + b.elapsedMs + c.elapsedMs,
56
57
  };
57
58
  if (opts.json) {
@@ -61,6 +62,11 @@ export function runIndex(opts, log = defaultLog) {
61
62
  log(`files scanned: ${stats.filesScanned} new: ${stats.filesNew} updated: ${stats.filesUpdated}`);
62
63
  log(`messages indexed: ${stats.messagesIndexed} parse errors: ${stats.parseErrors}`);
63
64
  log(`elapsed: ${stats.elapsedMs}ms`);
65
+ // A skipped file contributed nothing this run (#2) — name it, loudly, so a
66
+ // pathological transcript reads as "this file was skipped", never as
67
+ // "indexing is broken".
68
+ for (const skipped of stats.skippedFiles)
69
+ log(`skipped (will retry next run): ${skipped}`);
64
70
  if (stats.filesScanned === 0) {
65
71
  log("");
66
72
  log("no transcript files found. roots scanned:");
package/dist/indexer.js CHANGED
@@ -74,8 +74,19 @@ export function indexAll(db, adapter, roots) {
74
74
  let filesUpdated = 0;
75
75
  let messagesIndexed = 0;
76
76
  let parseErrors = 0;
77
+ const skippedFiles = [];
77
78
  for (const filePath of discovered) {
78
- const result = indexOneFile(db, adapter, filePath);
79
+ // #2: one pathological file (oversized single line, unreadable, vanished
80
+ // mid-scan) must not abort the whole run. No file record is written for a
81
+ // skipped file, so a later run retries it instead of skipping forever.
82
+ let result;
83
+ try {
84
+ result = indexOneFile(db, adapter, filePath);
85
+ }
86
+ catch (err) {
87
+ skippedFiles.push(`${filePath}: ${err instanceof Error ? err.message : String(err)}`);
88
+ continue;
89
+ }
79
90
  if (result.status === "new")
80
91
  filesNew++;
81
92
  else if (result.status === "updated")
@@ -95,6 +106,7 @@ export function indexAll(db, adapter, roots) {
95
106
  filesUpdated,
96
107
  messagesIndexed,
97
108
  parseErrors,
109
+ skippedFiles,
98
110
  elapsedMs: Date.now() - start,
99
111
  };
100
112
  }
@@ -112,20 +124,21 @@ export function indexAllWatermark(db, adapter, roots) {
112
124
  let sourcesUpdated = 0;
113
125
  let messagesIndexed = 0;
114
126
  let parseErrors = 0;
127
+ const skippedFiles = [];
115
128
  for (const sourcePath of discovered) {
116
129
  const existing = getSourceCursor(db, sourcePath);
117
130
  const existingCursor = existing?.kind === "watermark" ? { value: existing.value, tieBreakIds: existing.tieBreakIds } : undefined;
118
131
  // A single corrupt, vanished, or lock-timed-out source must not abort the
119
132
  // whole run — the Claude Code/Codex passes ahead of this one in cli.ts's
120
133
  // runIndex already committed, and other sources in `discovered` still
121
- // deserve a chance. Count it as a parse error and move on, leaving its
122
- // cursor untouched (we don't know what, if anything, it actually scanned).
134
+ // deserve a chance. Report it as skipped and move on, leaving its cursor
135
+ // untouched (we don't know what, if anything, it actually scanned).
123
136
  let result;
124
137
  try {
125
138
  result = adapter.parseSince(sourcePath, existingCursor);
126
139
  }
127
- catch {
128
- parseErrors++;
140
+ catch (err) {
141
+ skippedFiles.push(`${sourcePath}: ${err instanceof Error ? err.message : String(err)}`);
129
142
  continue;
130
143
  }
131
144
  const { sessions, cursor } = result;
@@ -153,6 +166,7 @@ export function indexAllWatermark(db, adapter, roots) {
153
166
  filesUpdated: sourcesUpdated,
154
167
  messagesIndexed,
155
168
  parseErrors,
169
+ skippedFiles,
156
170
  elapsedMs: Date.now() - start,
157
171
  };
158
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rewound",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Grep for everything your AI coding agents ever did. Local SQLite/FTS5 search over Claude Code session transcripts: CLI, MCP server, and web UI.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "David Erner",