chat-recall 0.7.15 → 0.7.16

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
@@ -8353,7 +8353,64 @@ var init_opencode = __esm({
8353
8353
  });
8354
8354
 
8355
8355
  // ../engine/dist/core/backends/tail-read.js
8356
- import { openSync as openSync2, readSync as readSync2, closeSync as closeSync2, statSync as statSync4 } from "node:fs";
8356
+ import { openSync as openSync2, readSync as readSync2, closeSync as closeSync2, statSync as statSync4, fstatSync } from "node:fs";
8357
+ function readAt(fd, pos, len) {
8358
+ const buf = Buffer.alloc(len);
8359
+ let got = 0;
8360
+ while (got < len) {
8361
+ const n = readSync2(fd, buf, got, len - got, pos + got);
8362
+ if (n <= 0)
8363
+ break;
8364
+ got += n;
8365
+ }
8366
+ return buf.subarray(0, got);
8367
+ }
8368
+ function linesBeforeOffset(path, offset) {
8369
+ if (offset <= 0)
8370
+ return 0;
8371
+ let fd = null;
8372
+ try {
8373
+ fd = openSync2(path, "r");
8374
+ const ino = fstatSync(fd).ino;
8375
+ const known = lineCounts.get(path);
8376
+ let pos = 0;
8377
+ let lines = 0;
8378
+ if (known && known.ino === ino && known.offset <= offset) {
8379
+ const edgeStart2 = Math.max(0, known.offset - EDGE_BYTES);
8380
+ if (readAt(fd, edgeStart2, known.offset - edgeStart2).equals(known.edge)) {
8381
+ pos = known.offset;
8382
+ lines = known.lines;
8383
+ }
8384
+ }
8385
+ const block = Buffer.allocUnsafe(SKIP_SCAN_BYTES);
8386
+ while (pos < offset) {
8387
+ const n = readSync2(fd, block, 0, Math.min(SKIP_SCAN_BYTES, offset - pos), pos);
8388
+ if (n <= 0)
8389
+ return void 0;
8390
+ for (let i = block.indexOf(10, 0); i >= 0 && i < n; i = block.indexOf(10, i + 1))
8391
+ lines++;
8392
+ pos += n;
8393
+ }
8394
+ const edgeStart = Math.max(0, offset - EDGE_BYTES);
8395
+ const edge = readAt(fd, edgeStart, offset - edgeStart);
8396
+ if (lineCounts.size >= LINE_COUNT_CACHE_MAX && !lineCounts.has(path)) {
8397
+ const oldest = lineCounts.keys().next().value;
8398
+ if (oldest !== void 0)
8399
+ lineCounts.delete(oldest);
8400
+ }
8401
+ lineCounts.set(path, { offset, lines, ino, edge });
8402
+ return lines;
8403
+ } catch {
8404
+ return void 0;
8405
+ } finally {
8406
+ if (fd !== null) {
8407
+ try {
8408
+ closeSync2(fd);
8409
+ } catch {
8410
+ }
8411
+ }
8412
+ }
8413
+ }
8357
8414
  function readTailFromOffset(path, offset, maxBytes = TAIL_READ_MAX_BYTES) {
8358
8415
  let size = 0;
8359
8416
  try {
@@ -8381,7 +8438,7 @@ function readTailFromOffset(path, offset, maxBytes = TAIL_READ_MAX_BYTES) {
8381
8438
  const lastNl = slice.lastIndexOf(10);
8382
8439
  if (lastNl >= 0) {
8383
8440
  const text = slice.subarray(0, lastNl + 1).toString("utf-8");
8384
- return { text, newOffset: offset + lastNl + 1 };
8441
+ return { text, newOffset: offset + lastNl + 1, baseLine: linesBeforeOffset(path, offset) };
8385
8442
  }
8386
8443
  if (offset + got >= size)
8387
8444
  return { text: "", newOffset: offset };
@@ -8414,12 +8471,15 @@ function findNewline(fd, from, size) {
8414
8471
  }
8415
8472
  return -1;
8416
8473
  }
8417
- var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES;
8474
+ var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES, lineCounts, LINE_COUNT_CACHE_MAX, EDGE_BYTES;
8418
8475
  var init_tail_read = __esm({
8419
8476
  "../engine/dist/core/backends/tail-read.js"() {
8420
8477
  "use strict";
8421
8478
  TAIL_READ_MAX_BYTES = 16 * 1024 * 1024;
8422
8479
  SKIP_SCAN_BYTES = 1024 * 1024;
8480
+ lineCounts = /* @__PURE__ */ new Map();
8481
+ LINE_COUNT_CACHE_MAX = 2048;
8482
+ EDGE_BYTES = 64;
8423
8483
  }
8424
8484
  });
8425
8485
 
@@ -18734,6 +18794,7 @@ function persistLedgerData(server, serverData) {
18734
18794
  const data = load();
18735
18795
  data[server] = serverData;
18736
18796
  persist(data);
18797
+ flushLedger();
18737
18798
  }
18738
18799
  function markSynced(server, rows) {
18739
18800
  if (rows.length === 0) return;
@@ -19002,7 +19063,7 @@ var init_http = __esm({
19002
19063
  CLI_VERSION = JSON.parse(readFileSync31(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
19003
19064
  } catch {
19004
19065
  try {
19005
- if (true) CLI_VERSION = "0.7.15";
19066
+ if (true) CLI_VERSION = "0.7.16";
19006
19067
  } catch {
19007
19068
  }
19008
19069
  }
@@ -19500,7 +19561,7 @@ var init_telemetry = __esm({
19500
19561
  init_sync_client();
19501
19562
  cliVersion2 = () => {
19502
19563
  try {
19503
- return true ? "0.7.15" : "dev";
19564
+ return true ? "0.7.16" : "dev";
19504
19565
  } catch {
19505
19566
  return "dev";
19506
19567
  }
@@ -20987,7 +21048,8 @@ async function syncToTargetInScope(cred, opts = {}) {
20987
21048
  clearTimeout(timer);
20988
21049
  }
20989
21050
  };
20990
- const postChunkedHead = async (conv, fileSize) => {
21051
+ const postChunkedHead = async (head, fileSize) => {
21052
+ const conv = { ...head, chunk_head: true };
20991
21053
  const headers = { "content-type": "application/json" };
20992
21054
  if (cred.token) headers.authorization = `Bearer ${cred.token}`;
20993
21055
  const ac = new AbortController();
@@ -21003,9 +21065,10 @@ async function syncToTargetInScope(cred, opts = {}) {
21003
21065
  const body2 = await res.json().catch(() => ({}));
21004
21066
  const id = conv.session_id;
21005
21067
  const guarded = (body2.shrink_guarded ?? []).find((g) => g.session_id === id);
21068
+ const staged = (body2.rebuild_staged ?? []).includes(id);
21006
21069
  const mtime = conv.mtime;
21007
21070
  try {
21008
- if (!guarded) {
21071
+ if (staged || !guarded) {
21009
21072
  markSynced(base4, [{ id, mtime, offset: conv.from_offset, size: conv.from_offset, acked: true }]);
21010
21073
  } else if (typeof guarded.o === "number" && guarded.o > 0 && guarded.o <= fileSize) {
21011
21074
  markSynced(base4, [{ id, mtime, offset: guarded.o, size: guarded.o, acked: true }]);
@@ -21738,8 +21801,13 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
21738
21801
  const backend = getBackendForId(ref.prefixedId);
21739
21802
  if (!backend?.readFromOffset) return null;
21740
21803
  const mapPath = opts.mapPath ?? ((p) => p);
21741
- const { text: tailText, newOffset, skippedBytes } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
21804
+ const { text: tailText, newOffset, skippedBytes, baseLine } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
21742
21805
  if (newOffset <= fromOffset) return null;
21806
+ const fileSize = backend.fileSize?.(ref.prefixedId) ?? 0;
21807
+ const position = {
21808
+ ...typeof baseLine === "number" ? { base_line: baseLine } : {},
21809
+ final: fileSize > 0 && newOffset >= fileSize
21810
+ };
21743
21811
  const messages = skippedBytes ? [] : parseTailMessages(ref.toolId, tailText);
21744
21812
  const textMessages = messages.filter((m) => m.role !== "summary" && m.content?.trim());
21745
21813
  const hasContent = textMessages.length > 0 || messages.some((m) => m.toolCalls?.length);
@@ -21752,6 +21820,7 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
21752
21820
  append: true,
21753
21821
  base_offset: fromOffset,
21754
21822
  from_offset: newOffset,
21823
+ ...position,
21755
21824
  redacted_text: "",
21756
21825
  envelope: { v: TRANSCRIPT_VERSION, messages: [], subagents: [] },
21757
21826
  mtime: Math.floor(ref.mtime) || 0
@@ -21798,6 +21867,7 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
21798
21867
  // equals its stored synced-through offset.
21799
21868
  from_offset: newOffset,
21800
21869
  // where it ends → new synced-through offset.
21870
+ ...position,
21801
21871
  redacted_text: redactedText,
21802
21872
  envelope,
21803
21873
  mtime: Math.floor(ref.mtime) || 0
@@ -21881,7 +21951,7 @@ var init_sync_client = __esm({
21881
21951
  ownVersion = JSON.parse(readFileSync35(join42(dir, "../package.json"), "utf-8")).version || ownVersion;
21882
21952
  } catch {
21883
21953
  try {
21884
- if (true) ownVersion = "0.7.15";
21954
+ if (true) ownVersion = "0.7.16";
21885
21955
  } catch {
21886
21956
  }
21887
21957
  }
@@ -26043,7 +26113,7 @@ var init_intent_drain = __esm({
26043
26113
  ownVersion2 = JSON.parse(readFileSync45(join56(dir, "../package.json"), "utf-8")).version || ownVersion2;
26044
26114
  } catch {
26045
26115
  try {
26046
- if (true) ownVersion2 = "0.7.15";
26116
+ if (true) ownVersion2 = "0.7.16";
26047
26117
  } catch {
26048
26118
  }
26049
26119
  }
package/dist/mcp-relay.js CHANGED
@@ -192,7 +192,7 @@ function bridge(input, output, sock, exit, opts = {}) {
192
192
  }
193
193
 
194
194
  // src/mcp-relay.ts
195
- var VERSION = true ? "0.7.15" : "0.0.0";
195
+ var VERSION = true ? "0.7.16" : "0.0.0";
196
196
  var SERVER_URL = new URL("./mcp.js", import.meta.url);
197
197
  var SERVER_PATH = fileURLToPath(SERVER_URL);
198
198
  var START_TIMEOUT_MS = 15e3;
package/dist/mcp.js CHANGED
@@ -7108,7 +7108,64 @@ var init_opencode = __esm({
7108
7108
  });
7109
7109
 
7110
7110
  // ../engine/dist/core/backends/tail-read.js
7111
- import { openSync, readSync, closeSync, statSync as statSync6 } from "node:fs";
7111
+ import { openSync, readSync, closeSync, statSync as statSync6, fstatSync } from "node:fs";
7112
+ function readAt(fd, pos, len) {
7113
+ const buf = Buffer.alloc(len);
7114
+ let got = 0;
7115
+ while (got < len) {
7116
+ const n = readSync(fd, buf, got, len - got, pos + got);
7117
+ if (n <= 0)
7118
+ break;
7119
+ got += n;
7120
+ }
7121
+ return buf.subarray(0, got);
7122
+ }
7123
+ function linesBeforeOffset(path2, offset) {
7124
+ if (offset <= 0)
7125
+ return 0;
7126
+ let fd = null;
7127
+ try {
7128
+ fd = openSync(path2, "r");
7129
+ const ino = fstatSync(fd).ino;
7130
+ const known = lineCounts.get(path2);
7131
+ let pos = 0;
7132
+ let lines = 0;
7133
+ if (known && known.ino === ino && known.offset <= offset) {
7134
+ const edgeStart2 = Math.max(0, known.offset - EDGE_BYTES);
7135
+ if (readAt(fd, edgeStart2, known.offset - edgeStart2).equals(known.edge)) {
7136
+ pos = known.offset;
7137
+ lines = known.lines;
7138
+ }
7139
+ }
7140
+ const block = Buffer.allocUnsafe(SKIP_SCAN_BYTES);
7141
+ while (pos < offset) {
7142
+ const n = readSync(fd, block, 0, Math.min(SKIP_SCAN_BYTES, offset - pos), pos);
7143
+ if (n <= 0)
7144
+ return void 0;
7145
+ for (let i = block.indexOf(10, 0); i >= 0 && i < n; i = block.indexOf(10, i + 1))
7146
+ lines++;
7147
+ pos += n;
7148
+ }
7149
+ const edgeStart = Math.max(0, offset - EDGE_BYTES);
7150
+ const edge = readAt(fd, edgeStart, offset - edgeStart);
7151
+ if (lineCounts.size >= LINE_COUNT_CACHE_MAX && !lineCounts.has(path2)) {
7152
+ const oldest = lineCounts.keys().next().value;
7153
+ if (oldest !== void 0)
7154
+ lineCounts.delete(oldest);
7155
+ }
7156
+ lineCounts.set(path2, { offset, lines, ino, edge });
7157
+ return lines;
7158
+ } catch {
7159
+ return void 0;
7160
+ } finally {
7161
+ if (fd !== null) {
7162
+ try {
7163
+ closeSync(fd);
7164
+ } catch {
7165
+ }
7166
+ }
7167
+ }
7168
+ }
7112
7169
  function readTailFromOffset(path2, offset, maxBytes = TAIL_READ_MAX_BYTES) {
7113
7170
  let size = 0;
7114
7171
  try {
@@ -7136,7 +7193,7 @@ function readTailFromOffset(path2, offset, maxBytes = TAIL_READ_MAX_BYTES) {
7136
7193
  const lastNl = slice.lastIndexOf(10);
7137
7194
  if (lastNl >= 0) {
7138
7195
  const text = slice.subarray(0, lastNl + 1).toString("utf-8");
7139
- return { text, newOffset: offset + lastNl + 1 };
7196
+ return { text, newOffset: offset + lastNl + 1, baseLine: linesBeforeOffset(path2, offset) };
7140
7197
  }
7141
7198
  if (offset + got >= size)
7142
7199
  return { text: "", newOffset: offset };
@@ -7169,12 +7226,15 @@ function findNewline(fd, from, size) {
7169
7226
  }
7170
7227
  return -1;
7171
7228
  }
7172
- var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES;
7229
+ var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES, lineCounts, LINE_COUNT_CACHE_MAX, EDGE_BYTES;
7173
7230
  var init_tail_read = __esm({
7174
7231
  "../engine/dist/core/backends/tail-read.js"() {
7175
7232
  "use strict";
7176
7233
  TAIL_READ_MAX_BYTES = 16 * 1024 * 1024;
7177
7234
  SKIP_SCAN_BYTES = 1024 * 1024;
7235
+ lineCounts = /* @__PURE__ */ new Map();
7236
+ LINE_COUNT_CACHE_MAX = 2048;
7237
+ EDGE_BYTES = 64;
7178
7238
  }
7179
7239
  });
7180
7240
 
@@ -19648,6 +19708,7 @@ function persistLedgerData(server, serverData) {
19648
19708
  const data = load();
19649
19709
  data[server] = serverData;
19650
19710
  persist(data);
19711
+ flushLedger();
19651
19712
  }
19652
19713
  function markSynced(server, rows) {
19653
19714
  if (rows.length === 0) return;
@@ -19910,7 +19971,7 @@ var init_http = __esm({
19910
19971
  CLI_VERSION = JSON.parse(readFileSync36(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
19911
19972
  } catch {
19912
19973
  try {
19913
- if (true) CLI_VERSION = "0.7.15";
19974
+ if (true) CLI_VERSION = "0.7.16";
19914
19975
  } catch {
19915
19976
  }
19916
19977
  }
@@ -20408,7 +20469,7 @@ var init_telemetry = __esm({
20408
20469
  init_sync_client();
20409
20470
  cliVersion2 = () => {
20410
20471
  try {
20411
- return true ? "0.7.15" : "dev";
20472
+ return true ? "0.7.16" : "dev";
20412
20473
  } catch {
20413
20474
  return "dev";
20414
20475
  }
@@ -21677,7 +21738,8 @@ async function syncToTargetInScope(cred, opts = {}) {
21677
21738
  clearTimeout(timer);
21678
21739
  }
21679
21740
  };
21680
- const postChunkedHead = async (conv, fileSize) => {
21741
+ const postChunkedHead = async (head, fileSize) => {
21742
+ const conv = { ...head, chunk_head: true };
21681
21743
  const headers = { "content-type": "application/json" };
21682
21744
  if (cred.token) headers.authorization = `Bearer ${cred.token}`;
21683
21745
  const ac = new AbortController();
@@ -21693,9 +21755,10 @@ async function syncToTargetInScope(cred, opts = {}) {
21693
21755
  const body2 = await res.json().catch(() => ({}));
21694
21756
  const id = conv.session_id;
21695
21757
  const guarded = (body2.shrink_guarded ?? []).find((g) => g.session_id === id);
21758
+ const staged = (body2.rebuild_staged ?? []).includes(id);
21696
21759
  const mtime = conv.mtime;
21697
21760
  try {
21698
- if (!guarded) {
21761
+ if (staged || !guarded) {
21699
21762
  markSynced(base2, [{ id, mtime, offset: conv.from_offset, size: conv.from_offset, acked: true }]);
21700
21763
  } else if (typeof guarded.o === "number" && guarded.o > 0 && guarded.o <= fileSize) {
21701
21764
  markSynced(base2, [{ id, mtime, offset: guarded.o, size: guarded.o, acked: true }]);
@@ -22428,8 +22491,13 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
22428
22491
  const backend = getBackendForId(ref.prefixedId);
22429
22492
  if (!backend?.readFromOffset) return null;
22430
22493
  const mapPath = opts.mapPath ?? ((p) => p);
22431
- const { text: tailText, newOffset, skippedBytes } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
22494
+ const { text: tailText, newOffset, skippedBytes, baseLine } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
22432
22495
  if (newOffset <= fromOffset) return null;
22496
+ const fileSize = backend.fileSize?.(ref.prefixedId) ?? 0;
22497
+ const position = {
22498
+ ...typeof baseLine === "number" ? { base_line: baseLine } : {},
22499
+ final: fileSize > 0 && newOffset >= fileSize
22500
+ };
22433
22501
  const messages = skippedBytes ? [] : parseTailMessages(ref.toolId, tailText);
22434
22502
  const textMessages = messages.filter((m) => m.role !== "summary" && m.content?.trim());
22435
22503
  const hasContent = textMessages.length > 0 || messages.some((m) => m.toolCalls?.length);
@@ -22442,6 +22510,7 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
22442
22510
  append: true,
22443
22511
  base_offset: fromOffset,
22444
22512
  from_offset: newOffset,
22513
+ ...position,
22445
22514
  redacted_text: "",
22446
22515
  envelope: { v: TRANSCRIPT_VERSION, messages: [], subagents: [] },
22447
22516
  mtime: Math.floor(ref.mtime) || 0
@@ -22488,6 +22557,7 @@ async function buildConversationTail(ref, fromOffset, opts = {}) {
22488
22557
  // equals its stored synced-through offset.
22489
22558
  from_offset: newOffset,
22490
22559
  // where it ends → new synced-through offset.
22560
+ ...position,
22491
22561
  redacted_text: redactedText,
22492
22562
  envelope,
22493
22563
  mtime: Math.floor(ref.mtime) || 0
@@ -22571,7 +22641,7 @@ var init_sync_client = __esm({
22571
22641
  ownVersion = JSON.parse(readFileSync38(join49(dir, "../package.json"), "utf-8")).version || ownVersion;
22572
22642
  } catch {
22573
22643
  try {
22574
- if (true) ownVersion = "0.7.15";
22644
+ if (true) ownVersion = "0.7.16";
22575
22645
  } catch {
22576
22646
  }
22577
22647
  }
@@ -29562,7 +29632,7 @@ function installCrashGuards() {
29562
29632
  reportClientEvent2("mcp_crash", { message: err.stack || err.message });
29563
29633
  });
29564
29634
  }
29565
- var RELAY_VERSION = true ? "0.7.15" : "0.0.0";
29635
+ var RELAY_VERSION = true ? "0.7.16" : "0.0.0";
29566
29636
  function daemonIdleSecs() {
29567
29637
  const raw = process.env.CHAT_RECALL_DAEMON_IDLE_SECS;
29568
29638
  if (raw === void 0) return 900;
@@ -6897,7 +6897,64 @@ var init_opencode = __esm({
6897
6897
  });
6898
6898
 
6899
6899
  // ../engine/dist/core/backends/tail-read.js
6900
- import { openSync, readSync, closeSync, statSync as statSync3 } from "node:fs";
6900
+ import { openSync, readSync, closeSync, statSync as statSync3, fstatSync } from "node:fs";
6901
+ function readAt(fd, pos, len) {
6902
+ const buf = Buffer.alloc(len);
6903
+ let got = 0;
6904
+ while (got < len) {
6905
+ const n = readSync(fd, buf, got, len - got, pos + got);
6906
+ if (n <= 0)
6907
+ break;
6908
+ got += n;
6909
+ }
6910
+ return buf.subarray(0, got);
6911
+ }
6912
+ function linesBeforeOffset(path, offset) {
6913
+ if (offset <= 0)
6914
+ return 0;
6915
+ let fd = null;
6916
+ try {
6917
+ fd = openSync(path, "r");
6918
+ const ino = fstatSync(fd).ino;
6919
+ const known = lineCounts.get(path);
6920
+ let pos = 0;
6921
+ let lines = 0;
6922
+ if (known && known.ino === ino && known.offset <= offset) {
6923
+ const edgeStart2 = Math.max(0, known.offset - EDGE_BYTES);
6924
+ if (readAt(fd, edgeStart2, known.offset - edgeStart2).equals(known.edge)) {
6925
+ pos = known.offset;
6926
+ lines = known.lines;
6927
+ }
6928
+ }
6929
+ const block = Buffer.allocUnsafe(SKIP_SCAN_BYTES);
6930
+ while (pos < offset) {
6931
+ const n = readSync(fd, block, 0, Math.min(SKIP_SCAN_BYTES, offset - pos), pos);
6932
+ if (n <= 0)
6933
+ return void 0;
6934
+ for (let i = block.indexOf(10, 0); i >= 0 && i < n; i = block.indexOf(10, i + 1))
6935
+ lines++;
6936
+ pos += n;
6937
+ }
6938
+ const edgeStart = Math.max(0, offset - EDGE_BYTES);
6939
+ const edge = readAt(fd, edgeStart, offset - edgeStart);
6940
+ if (lineCounts.size >= LINE_COUNT_CACHE_MAX && !lineCounts.has(path)) {
6941
+ const oldest = lineCounts.keys().next().value;
6942
+ if (oldest !== void 0)
6943
+ lineCounts.delete(oldest);
6944
+ }
6945
+ lineCounts.set(path, { offset, lines, ino, edge });
6946
+ return lines;
6947
+ } catch {
6948
+ return void 0;
6949
+ } finally {
6950
+ if (fd !== null) {
6951
+ try {
6952
+ closeSync(fd);
6953
+ } catch {
6954
+ }
6955
+ }
6956
+ }
6957
+ }
6901
6958
  function readTailFromOffset(path, offset, maxBytes = TAIL_READ_MAX_BYTES) {
6902
6959
  let size = 0;
6903
6960
  try {
@@ -6925,7 +6982,7 @@ function readTailFromOffset(path, offset, maxBytes = TAIL_READ_MAX_BYTES) {
6925
6982
  const lastNl = slice.lastIndexOf(10);
6926
6983
  if (lastNl >= 0) {
6927
6984
  const text = slice.subarray(0, lastNl + 1).toString("utf-8");
6928
- return { text, newOffset: offset + lastNl + 1 };
6985
+ return { text, newOffset: offset + lastNl + 1, baseLine: linesBeforeOffset(path, offset) };
6929
6986
  }
6930
6987
  if (offset + got >= size)
6931
6988
  return { text: "", newOffset: offset };
@@ -6958,12 +7015,15 @@ function findNewline(fd, from, size) {
6958
7015
  }
6959
7016
  return -1;
6960
7017
  }
6961
- var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES;
7018
+ var TAIL_READ_MAX_BYTES, SKIP_SCAN_BYTES, lineCounts, LINE_COUNT_CACHE_MAX, EDGE_BYTES;
6962
7019
  var init_tail_read = __esm({
6963
7020
  "../engine/dist/core/backends/tail-read.js"() {
6964
7021
  "use strict";
6965
7022
  TAIL_READ_MAX_BYTES = 16 * 1024 * 1024;
6966
7023
  SKIP_SCAN_BYTES = 1024 * 1024;
7024
+ lineCounts = /* @__PURE__ */ new Map();
7025
+ LINE_COUNT_CACHE_MAX = 2048;
7026
+ EDGE_BYTES = 64;
6967
7027
  }
6968
7028
  });
6969
7029
 
@@ -1 +1 @@
1
- {"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../src/sync-client.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAUrL,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,0CAA0C,CAAC;AA2ExG,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAI7E;AAgBD,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGvD;AAED,MAAM,MAAM,YAAY,GACpB,cAAc,GAAG,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GACpE,KAAK,GA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EAAE,MAAM,CAAA;CAAO,GACjC,OAAO,CAAC,iBAAiB,GAAG,qBAAqB,GAAG,IAAI,CAAC,CA4W3D;AAeD;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,UAAU,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAO,GACnG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyFlJ;AAED;;;;;;GAMG;AACH;;;;;;;;GAQG;AACH;;;;yCAIyC;AACzC,MAAM,WAAW,QAAQ;IAAG,OAAO,EAAE,gBAAgB,GAAG,QAAQ,GAAG,WAAW,CAAA;CAAE;AAEhF,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,CAAC,IAAI,QAAQ,CAElE;AAED,wBAAsB,eAAe,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CA4C/G"}
@@ -1474,7 +1474,10 @@ async function syncToTargetInScope(cred, opts = {}) {
1474
1474
  // records that offset, so the next tick appends from where the server is.
1475
1475
  // Recording the head's end instead makes every append miss the server's
1476
1476
  // offset, answer full_resync_needed, and send the head again, forever.
1477
- const postChunkedHead = async (conv, fileSize) => {
1477
+ const postChunkedHead = async (head, fileSize) => {
1478
+ // The server stages a head it would otherwise refuse as smaller than its
1479
+ // stored copy, and the appends that follow complete the staged rebuild.
1480
+ const conv = { ...head, chunk_head: true };
1478
1481
  const headers = { 'content-type': 'application/json' };
1479
1482
  if (cred.token)
1480
1483
  headers.authorization = `Bearer ${cred.token}`;
@@ -1489,9 +1492,10 @@ async function syncToTargetInScope(cred, opts = {}) {
1489
1492
  const body = await res.json().catch(() => ({}));
1490
1493
  const id = conv.session_id;
1491
1494
  const guarded = (body.shrink_guarded ?? []).find((g) => g.session_id === id);
1495
+ const staged = (body.rebuild_staged ?? []).includes(id);
1492
1496
  const mtime = conv.mtime;
1493
1497
  try {
1494
- if (!guarded) {
1498
+ if (staged || !guarded) {
1495
1499
  markSynced(base, [{ id, mtime, offset: conv.from_offset, size: conv.from_offset, acked: true }]);
1496
1500
  }
1497
1501
  else if (typeof guarded.o === 'number' && guarded.o > 0 && guarded.o <= fileSize) {
@@ -2739,9 +2743,17 @@ export async function buildConversationTail(ref, fromOffset, opts = {}) {
2739
2743
  if (!backend?.readFromOffset)
2740
2744
  return null;
2741
2745
  const mapPath = opts.mapPath ?? ((p) => p);
2742
- const { text: tailText, newOffset, skippedBytes } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
2746
+ const { text: tailText, newOffset, skippedBytes, baseLine } = await backend.readFromOffset(ref.prefixedId, fromOffset, SYNC_CHUNK_BYTES);
2743
2747
  if (newOffset <= fromOffset)
2744
2748
  return null;
2749
+ // The tail's parser numbers its lines from 1. `base_line` turns them into
2750
+ // the file's line numbers on the server; `final` says this tail ends the
2751
+ // file, which completes a rebuild the server staged.
2752
+ const fileSize = backend.fileSize?.(ref.prefixedId) ?? 0;
2753
+ const position = {
2754
+ ...(typeof baseLine === 'number' ? { base_line: baseLine } : {}),
2755
+ final: fileSize > 0 && newOffset >= fileSize,
2756
+ };
2745
2757
  // A window with bytes but nothing to show (tool noise, a skipped line longer
2746
2758
  // than a chunk) still has to move the server's synced-through offset, or the
2747
2759
  // cursor reads the same window on every tick and the rest of a chunked
@@ -2753,7 +2765,7 @@ export async function buildConversationTail(ref, fromOffset, opts = {}) {
2753
2765
  return {
2754
2766
  conv: {
2755
2767
  session_id: ref.prefixedId, tool: ref.toolId, project_path: mapPath(ref.projectPath),
2756
- append: true, base_offset: fromOffset, from_offset: newOffset, redacted_text: '',
2768
+ append: true, base_offset: fromOffset, from_offset: newOffset, ...position, redacted_text: '',
2757
2769
  envelope: { v: TRANSCRIPT_VERSION, messages: [], subagents: [] },
2758
2770
  mtime: Math.floor(ref.mtime) || 0,
2759
2771
  },
@@ -2802,6 +2814,7 @@ export async function buildConversationTail(ref, fromOffset, opts = {}) {
2802
2814
  base_offset: fromOffset, // where this tail STARTS — server validates it
2803
2815
  // equals its stored synced-through offset.
2804
2816
  from_offset: newOffset, // where it ends → new synced-through offset.
2817
+ ...position,
2805
2818
  redacted_text: redactedText,
2806
2819
  envelope,
2807
2820
  mtime: Math.floor(ref.mtime) || 0,