jg-agent-hq 5.0.0 → 5.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.1
4
+
5
+ - Index Claude transcripts with less memory. Each record is read once, instead of being copied again for every 64 KiB chunk it spans, and the SQLite worker's young generation is capped at 16 MiB. Indexing a 224 MB transcript held the runtime at about 200 MB instead of about 300 MB. The storage schema is unchanged, so databases and snapshots written by 5.0.0 open as they are.
6
+
3
7
  ## 5.0.0
4
8
 
5
9
  - Read `items` newest first, its only order, with its cursor continuing toward older items; it read oldest first before. `textLimit`, from 1 to 65,536 and 65,536 by default, cuts each item's text on a code-point boundary and marks it `isTruncated`. `nativeItemId` with its `turnId` returns that item alone; Codex finds it by reading that turn's items 128 at a time.
@@ -408,12 +408,19 @@ export class ClaudeHistoryModel {
408
408
  row.updated_at = Math.max(row.updated_at, Math.trunc(stat.mtimeMs));
409
409
  let position = row.byte_offset;
410
410
  let lineStart = position;
411
- let tail = Buffer.alloc(0);
412
411
  const chunk = Buffer.alloc(65_536);
413
412
  // hidden records whose parent comes later in the file, by location and awaited parent
414
413
  const heldBack = [];
414
+ /*
415
+ * A record read again, because it spans chunks or was held back, lands in one buffer that
416
+ * grows to the longest such record. Each read replaces the last one's bytes, which
417
+ * `__record` has decoded by then.
418
+ */
419
+ let spill = Buffer.alloc(0);
415
420
  const reread = (offset, length) => {
416
- const bytes = Buffer.alloc(length);
421
+ if (spill.length < length)
422
+ spill = Buffer.allocUnsafe(length);
423
+ const bytes = spill.subarray(0, length);
417
424
  if (readSync(fd, bytes, 0, length, offset) !== length)
418
425
  this.__unavailable();
419
426
  return bytes;
@@ -441,18 +448,22 @@ export class ClaudeHistoryModel {
441
448
  const count = readSync(fd, chunk, 0, Math.min(chunk.length, stat.size - position, remaining()), position);
442
449
  if (count === 0)
443
450
  break;
451
+ const chunkStart = position;
444
452
  position += count;
445
453
  consume(count);
446
- tail = Buffer.concat([tail, chunk.subarray(0, count)]);
447
- for (let end = tail.indexOf(10); end !== -1; end = tail.indexOf(10)) {
448
- if (end > MAX_RECORD_BYTES)
454
+ // a record that started in an earlier chunk is read again whole, not joined from chunks
455
+ const read = chunk.subarray(0, count);
456
+ for (let end = read.indexOf(10); end !== -1; end = read.indexOf(10, end + 1)) {
457
+ const length = chunkStart + end - lineStart;
458
+ if (length > MAX_RECORD_BYTES)
449
459
  this.__unavailable();
450
- if (end > 0)
451
- indexRecord(tail.subarray(0, end), lineStart);
452
- lineStart += end + 1;
453
- tail = tail.subarray(end + 1);
460
+ if (length > 0)
461
+ indexRecord(lineStart >= chunkStart
462
+ ? read.subarray(lineStart - chunkStart, end)
463
+ : reread(lineStart, length), lineStart);
464
+ lineStart = chunkStart + end + 1;
454
465
  }
455
- if (tail.length > MAX_RECORD_BYTES)
466
+ if (position - lineStart > MAX_RECORD_BYTES)
456
467
  this.__unavailable();
457
468
  }
458
469
  /*
@@ -25,6 +25,8 @@ export const createStore = async (databasePath, runtimeEpoch, actionKey) => {
25
25
  execArgv: process.execArgv.filter((argument, index, arguments_) => argument !== '--input-type' &&
26
26
  !argument.startsWith('--input-type=') &&
27
27
  arguments_[index - 1] !== '--input-type'),
28
+ // indexing a large transcript otherwise grows the young generation to V8's default maximum
29
+ resourceLimits: { maxYoungGenerationSizeMb: 16 },
28
30
  workerData: { databasePath, runtimeEpoch, actionKey },
29
31
  });
30
32
  let hasExited = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jg-agent-hq",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Native coding-agent session control, agent streams and durable collaboration for Node.js apps.",
5
5
  "type": "module",
6
6
  "license": "MIT",