@indigoai-us/hq-cli 5.345.243 → 5.345.244

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.
@@ -189,10 +189,20 @@ export function ingestSpoolLine(line, sessions, lineNo) {
189
189
  entry.lastSeq = seq;
190
190
  sessions[sessionId] = entry;
191
191
  }
192
- /** 64 KiB. Keeps leftover bounded to one jsonl line, never the whole spool. */
192
+ /** 64 KiB. The spool is read in chunks of this size, never as one string. */
193
193
  const SPOOL_READ_CHUNK = 64 * 1024;
194
- /** Drop a truncated leftover bigger than this; liveness events are small JSON. */
194
+ /**
195
+ * A spool line longer than this is skipped whole with a warning. Liveness
196
+ * events are small JSON (well under 1 KiB), so this only bounds memory when a
197
+ * line is corrupt or has no newline.
198
+ */
195
199
  const SPOOL_MAX_LINE = 1_048_576;
200
+ /**
201
+ * Visit each spool line, reading the file in fixed-size chunks. Lines are
202
+ * split on the raw newline byte and decoded only once complete, so a
203
+ * multi-byte UTF-8 character cut by a chunk boundary stays intact. Line
204
+ * numbers match a whole-file `split("\n")`.
205
+ */
196
206
  function ingestSpoolFile(spoolPath, sessions, deps) {
197
207
  const openSync = deps.openSync ?? fs.openSync;
198
208
  const readSync = deps.readSync ?? fs.readSync;
@@ -200,27 +210,47 @@ function ingestSpoolFile(spoolPath, sessions, deps) {
200
210
  const fd = openSync(spoolPath, "r");
201
211
  try {
202
212
  const buf = Buffer.alloc(SPOOL_READ_CHUNK);
203
- let leftover = "";
213
+ let pending = [];
214
+ let pendingBytes = 0;
215
+ let oversized = false;
204
216
  let lineNo = 0;
217
+ const finishLine = (tail) => {
218
+ lineNo += 1;
219
+ if (oversized) {
220
+ process.stderr.write(`lanes liveness: skipping oversized spool line ${lineNo}\n`);
221
+ }
222
+ else {
223
+ const bytes = pending.length > 0 ? Buffer.concat([...pending, tail]) : tail;
224
+ ingestSpoolLine(bytes.toString("utf8"), sessions, lineNo);
225
+ }
226
+ pending = [];
227
+ pendingBytes = 0;
228
+ oversized = false;
229
+ };
205
230
  for (;;) {
206
231
  const n = readSync(fd, buf, 0, buf.length, null);
207
232
  if (n === 0)
208
233
  break;
209
- leftover += buf.toString("utf8", 0, n);
210
- let nl = leftover.indexOf("\n");
211
- while (nl !== -1) {
212
- lineNo += 1;
213
- ingestSpoolLine(leftover.slice(0, nl), sessions, lineNo);
214
- leftover = leftover.slice(nl + 1);
215
- nl = leftover.indexOf("\n");
234
+ const chunk = buf.subarray(0, n);
235
+ let start = 0;
236
+ for (let nl = chunk.indexOf(0x0a, start); nl !== -1; nl = chunk.indexOf(0x0a, start)) {
237
+ finishLine(chunk.subarray(start, nl));
238
+ start = nl + 1;
239
+ }
240
+ if (start < n && !oversized) {
241
+ pendingBytes += n - start;
242
+ if (pendingBytes > SPOOL_MAX_LINE) {
243
+ oversized = true;
244
+ pending = [];
245
+ }
246
+ else {
247
+ // Copy: buf is reused by the next read.
248
+ pending.push(Buffer.from(chunk.subarray(start)));
249
+ }
216
250
  }
217
- if (leftover.length > SPOOL_MAX_LINE)
218
- leftover = "";
219
- }
220
- if (leftover) {
221
- lineNo += 1;
222
- ingestSpoolLine(leftover, sessions, lineNo);
223
251
  }
252
+ if (oversized || pendingBytes > 0)
253
+ finishLine(Buffer.alloc(0));
224
254
  }
225
255
  finally {
226
256
  closeSync(fd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.243",
3
+ "version": "5.345.244",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -63,7 +63,7 @@
63
63
  "@aws-sdk/client-iot-data-plane": "^3.1096.0",
64
64
  "@aws-sdk/client-s3": "^3.1049.0",
65
65
  "@aws-sdk/dsql-signer": "^3.1146.0",
66
- "@indigoai-us/hq-cloud": "6.18.118",
66
+ "@indigoai-us/hq-cloud": "6.18.119",
67
67
  "@indigoai-us/hq-flags-client": "^0.2.0",
68
68
  "@modelcontextprotocol/sdk": "1.32.2",
69
69
  "@sentry/node": "^10.49.0",
@@ -126,11 +126,11 @@
126
126
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
127
127
  },
128
128
  "optionalDependencies": {
129
- "@indigoai-us/hq-hook-win32-x64": "5.345.243",
130
- "@indigoai-us/hq-hook-win32-arm64": "5.345.243",
131
- "@indigoai-us/hq-hook-darwin-x64": "5.345.243",
132
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.243",
133
- "@indigoai-us/hq-hook-linux-x64": "5.345.243",
134
- "@indigoai-us/hq-hook-linux-arm64": "5.345.243"
129
+ "@indigoai-us/hq-hook-win32-x64": "5.345.244",
130
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.244",
131
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.244",
132
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.244",
133
+ "@indigoai-us/hq-hook-linux-x64": "5.345.244",
134
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.244"
135
135
  }
136
136
  }