@tangle-network/harness-sessions 1.0.10 → 1.0.11

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.
Files changed (2) hide show
  1. package/dist/source.js +8 -13
  2. package/package.json +1 -1
package/dist/source.js CHANGED
@@ -26,7 +26,6 @@ const NEWLINE = 0x0a;
26
26
  export async function* readJsonlRecords(path, stats, options = {}) {
27
27
  const hash = createHash('sha256');
28
28
  let pending = [];
29
- let pendingBytes = 0;
30
29
  let lineNumber = 0;
31
30
  const parse = (bytes, terminated) => {
32
31
  lineNumber += 1;
@@ -53,6 +52,7 @@ export async function* readJsonlRecords(path, stats, options = {}) {
53
52
  noteUnparsed(stats, lineNumber);
54
53
  return undefined;
55
54
  }
55
+ stats.line = lineNumber;
56
56
  return value;
57
57
  };
58
58
  if (typeof constants.O_NOFOLLOW !== 'number' || typeof constants.O_NONBLOCK !== 'number')
@@ -61,6 +61,8 @@ export async function* readJsonlRecords(path, stats, options = {}) {
61
61
  try {
62
62
  if (!(await file.stat()).isFile())
63
63
  throw new Error(`${path}: native session must be a regular file`);
64
+ // A stream created on an aborted signal emits an 'error' no one listens to, which crashes the process.
65
+ options.signal?.throwIfAborted();
64
66
  const stream = file.createReadStream({ highWaterMark: 1 << 20, signal: options.signal, autoClose: false });
65
67
  for await (const chunk of stream) {
66
68
  hash.update(chunk);
@@ -71,33 +73,26 @@ export async function* readJsonlRecords(path, stats, options = {}) {
71
73
  if (index === -1)
72
74
  break;
73
75
  let line;
74
- if (pendingBytes > 0) {
76
+ if (pending.length > 0) {
75
77
  pending.push(chunk.subarray(start, index));
76
78
  line = Buffer.concat(pending);
77
79
  pending = [];
78
- pendingBytes = 0;
79
80
  }
80
81
  else {
81
82
  line = chunk.subarray(start, index);
82
83
  }
83
84
  const record = parse(line, true);
84
- if (record !== undefined) {
85
- stats.line = lineNumber;
85
+ if (record !== undefined)
86
86
  yield record;
87
- }
88
87
  start = index + 1;
89
88
  }
90
- if (start < chunk.length) {
89
+ if (start < chunk.length)
91
90
  pending.push(chunk.subarray(start));
92
- pendingBytes += chunk.length - start;
93
- }
94
91
  }
95
- if (pendingBytes > 0) {
92
+ if (pending.length > 0) {
96
93
  const record = parse(Buffer.concat(pending), false);
97
- if (record !== undefined) {
98
- stats.line = lineNumber;
94
+ if (record !== undefined)
99
95
  yield record;
100
- }
101
96
  }
102
97
  stats.sha256 = `sha256:${hash.digest('hex')}`;
103
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/harness-sessions",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "One reader for every coding-agent harness's native session (Claude Code, Codex, OpenCode, Pi): store layouts, a normalized session with messages, tool calls, served models, usage and ending errors, and projections to chat messages, OTLP spans and turns",
5
5
  "type": "module",
6
6
  "sideEffects": false,