home-hosted 0.7.16 → 0.7.17

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/dist/cli.js CHANGED
@@ -15090,6 +15090,15 @@ var init_log_files = __esmMin((() => {
15090
15090
  }
15091
15091
  if (fs.existsSync(this.currentPath(serverId))) fs.renameSync(this.currentPath(serverId), this.rotatedPath(serverId, 1));
15092
15092
  }
15093
+ /**
15094
+ * The last `tail` parseable lines of one file.
15095
+ *
15096
+ * Reads backwards, growing the window until it has enough lines. It used to read exactly one
15097
+ * fixed chunk, which silently truncated: a JSONL line here is a couple of hundred bytes, so
15098
+ * one 256 KB chunk holds roughly 1500 of them, while the route accepts `tail=5000`. Asking
15099
+ * for 5000 returned 1464 and dropped 3536 lines with no error — the oldest line handed back
15100
+ * was not the oldest asked for.
15101
+ */
15093
15102
  readTailChunk(file, tail) {
15094
15103
  let handle;
15095
15104
  try {
@@ -15099,15 +15108,24 @@ var init_log_files = __esmMin((() => {
15099
15108
  }
15100
15109
  try {
15101
15110
  const size = fs.fstatSync(handle).size;
15102
- const length = Math.min(size, READ_CHUNK_BYTES);
15103
- const buffer = Buffer$1.alloc(length);
15104
- fs.readSync(handle, buffer, 0, length, size - length);
15105
- const raw = buffer.toString("utf8").split("\n").filter((entry) => entry.trim().length > 0);
15106
- const parsed = [];
15107
- for (const entry of raw.slice(size > length ? 1 : 0)) try {
15108
- parsed.push(JSON.parse(entry));
15109
- } catch {}
15110
- return parsed.slice(-tail);
15111
+ if (size === 0) return [];
15112
+ let start = Math.max(0, size - READ_CHUNK_BYTES);
15113
+ let parsed = [];
15114
+ while (true) {
15115
+ const length = size - start;
15116
+ const buffer = Buffer$1.alloc(length);
15117
+ fs.readSync(handle, buffer, 0, length, start);
15118
+ const raw = buffer.toString("utf8").split("\n");
15119
+ parsed = [];
15120
+ for (const entry of start > 0 ? raw.slice(1) : raw) {
15121
+ if (entry.trim().length === 0) continue;
15122
+ try {
15123
+ parsed.push(JSON.parse(entry));
15124
+ } catch {}
15125
+ }
15126
+ if (parsed.length >= tail || start === 0) return parsed.slice(-tail);
15127
+ start = Math.max(0, start - READ_CHUNK_BYTES);
15128
+ }
15111
15129
  } finally {
15112
15130
  fs.closeSync(handle);
15113
15131
  }