@vectorize-io/hindsight-coding-agents 0.1.1 → 0.2.0

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/installer.js CHANGED
@@ -8,8 +8,8 @@ import {
8
8
  existsSync as existsSync8,
9
9
  mkdirSync as mkdirSync3,
10
10
  mkdtempSync,
11
- readFileSync as readFileSync15,
12
- readSync as readSync3,
11
+ readFileSync as readFileSync10,
12
+ readSync as readSync4,
13
13
  realpathSync,
14
14
  rmSync,
15
15
  writeFileSync as writeFileSync2
@@ -106,7 +106,13 @@ import { tmpdir as tmpdir2 } from "os";
106
106
  import { dirname as dirname4, join as join5 } from "path";
107
107
 
108
108
  // src/core/retain-hook.ts
109
- import { readFileSync as readFileSync5 } from "fs";
109
+ import { readFileSync as readFileSync4 } from "fs";
110
+
111
+ // src/core/retain-cursor.ts
112
+ import { createHash } from "crypto";
113
+
114
+ // src/core/uuid.ts
115
+ import { createHash as createHash2 } from "crypto";
110
116
 
111
117
  // src/core/daemon.ts
112
118
  import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
@@ -162,11 +168,72 @@ function onPath(bin) {
162
168
  }
163
169
  }
164
170
 
165
- // src/core/transcript.ts
166
- import { readFileSync as readFileSync4 } from "fs";
171
+ // src/core/retain-stamp.ts
172
+ import { basename as basename2 } from "path";
173
+
174
+ // src/core/jsonl.ts
175
+ import { closeSync, openSync, readSync, statSync } from "fs";
176
+ import { StringDecoder } from "string_decoder";
177
+ var CHUNK_BYTES = 64 * 1024;
178
+ var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
179
+ function readJsonlTail(path, opts) {
180
+ const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
181
+ let size;
182
+ try {
183
+ size = statSync(path).size;
184
+ } catch {
185
+ return { lines: emptyLines(), skippedBytes: 0 };
186
+ }
187
+ const skippedBytes = size > maxBytes ? size - maxBytes : 0;
188
+ if (skippedBytes > 0) {
189
+ log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
190
+ path,
191
+ sizeBytes: size,
192
+ skippedBytes
193
+ });
194
+ }
195
+ return { lines: streamLines(path, skippedBytes), skippedBytes };
196
+ }
197
+ function* emptyLines() {
198
+ }
199
+ function* streamLines(path, start) {
200
+ let fd;
201
+ try {
202
+ fd = openSync(path, "r");
203
+ } catch {
204
+ return;
205
+ }
206
+ try {
207
+ const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
208
+ const decoder = new StringDecoder("utf8");
209
+ let pending = "";
210
+ let position = start > 0 ? start - 1 : 0;
211
+ let dropPartial = start > 0;
212
+ for (; ; ) {
213
+ const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
214
+ if (bytesRead <= 0) break;
215
+ position += bytesRead;
216
+ pending += decoder.write(buffer.subarray(0, bytesRead));
217
+ let newline;
218
+ while ((newline = pending.indexOf("\n")) !== -1) {
219
+ const line = pending.slice(0, newline);
220
+ pending = pending.slice(newline + 1);
221
+ if (dropPartial) {
222
+ dropPartial = false;
223
+ continue;
224
+ }
225
+ yield line;
226
+ }
227
+ }
228
+ pending += decoder.end();
229
+ if (pending && !dropPartial) yield pending;
230
+ } finally {
231
+ closeSync(fd);
232
+ }
233
+ }
167
234
 
168
235
  // src/core/transcript-util.ts
169
- var MEMORY_TAG_RE = /<(hook_prompt|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
236
+ var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
170
237
  function stripInjectedMemory(s) {
171
238
  return s.replace(MEMORY_TAG_RE, "");
172
239
  }
@@ -225,14 +292,8 @@ function renderLine(content, type) {
225
292
  return out;
226
293
  }
227
294
  function readClaudeTranscript(path) {
228
- let raw;
229
- try {
230
- raw = readFileSync4(path, "utf8");
231
- } catch {
232
- return [];
233
- }
234
295
  const turns = [];
235
- for (const rawLine of raw.split("\n")) {
296
+ for (const rawLine of readJsonlTail(path, { scope: "claude-code" }).lines) {
236
297
  const trimmed = rawLine.trim();
237
298
  if (!trimmed) continue;
238
299
  let parsed;
@@ -257,7 +318,7 @@ function readClaudeTranscript(path) {
257
318
  }
258
319
 
259
320
  // src/core/session-start.ts
260
- import { readFileSync as readFileSync7 } from "fs";
321
+ import { readFileSync as readFileSync6 } from "fs";
261
322
 
262
323
  // src/core/git.ts
263
324
  import { execFileSync as execFileSync3 } from "child_process";
@@ -274,13 +335,12 @@ import { delimiter, dirname as dirname6, join as join7 } from "path";
274
335
  import { fileURLToPath as fileURLToPath3 } from "url";
275
336
 
276
337
  // src/core/skill-sync.ts
277
- import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
338
+ import { cpSync, existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
278
339
  import { homedir as homedir4 } from "os";
279
340
  import { dirname as dirname7, join as join8 } from "path";
280
341
  import { fileURLToPath as fileURLToPath4 } from "url";
281
342
 
282
343
  // src/core/transcript-codex.ts
283
- import { readFileSync as readFileSync8 } from "fs";
284
344
  function isSyntheticUserText(text) {
285
345
  const s = text.trimStart();
286
346
  return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
@@ -289,14 +349,8 @@ function messageText(payload) {
289
349
  return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
290
350
  }
291
351
  function readCodexTranscript(path) {
292
- let raw;
293
- try {
294
- raw = readFileSync8(path, "utf8");
295
- } catch {
296
- return [];
297
- }
298
352
  const turns = [];
299
- for (const rawLine of raw.split("\n")) {
353
+ for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
300
354
  const trimmed = rawLine.trim();
301
355
  if (!trimmed) continue;
302
356
  let parsed;
@@ -330,7 +384,6 @@ function readCodexTranscript(path) {
330
384
  }
331
385
 
332
386
  // src/core/transcript-cursor.ts
333
- import { readFileSync as readFileSync9 } from "fs";
334
387
  function withTimestamp(turn, timestamp) {
335
388
  return timestamp ? { ...turn, timestamp } : turn;
336
389
  }
@@ -340,14 +393,8 @@ function textFrom(content) {
340
393
  return content.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
341
394
  }
342
395
  function readCursorTranscript(path) {
343
- let raw;
344
- try {
345
- raw = readFileSync9(path, "utf8");
346
- } catch {
347
- return [];
348
- }
349
396
  const turns = [];
350
- for (const rawLine of raw.split("\n")) {
397
+ for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
351
398
  let parsed;
352
399
  try {
353
400
  parsed = JSON.parse(rawLine);
@@ -383,17 +430,10 @@ function readCursorTranscript(path) {
383
430
  }
384
431
 
385
432
  // src/core/transcript-antigravity.ts
386
- import { readFileSync as readFileSync10 } from "fs";
387
433
  function readAntigravityTranscript(path) {
388
434
  if (!path) return [];
389
- let raw;
390
- try {
391
- raw = readFileSync10(path, "utf8");
392
- } catch {
393
- return [];
394
- }
395
435
  const turns = [];
396
- for (const line of raw.split("\n")) {
436
+ for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
397
437
  try {
398
438
  const event = JSON.parse(line);
399
439
  const role = event.role ?? event.message?.role ?? event.type;
@@ -414,16 +454,9 @@ function readAntigravityTranscript(path) {
414
454
  }
415
455
 
416
456
  // src/core/transcript-copilot.ts
417
- import { readFileSync as readFileSync11 } from "fs";
418
457
  function readCopilotTranscript(path) {
419
- let raw;
420
- try {
421
- raw = readFileSync11(path, "utf8");
422
- } catch {
423
- return [];
424
- }
425
458
  const turns = [];
426
- for (const rawLine of raw.split("\n")) {
459
+ for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
427
460
  try {
428
461
  const event = JSON.parse(rawLine);
429
462
  const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
@@ -437,7 +470,7 @@ function readCopilotTranscript(path) {
437
470
  }
438
471
 
439
472
  // src/core/transcript-grok.ts
440
- import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
473
+ import { existsSync as existsSync4, readFileSync as readFileSync7, readdirSync } from "fs";
441
474
  import { homedir as homedir5 } from "os";
442
475
  import { join as join9 } from "path";
443
476
  var CHAT_HISTORY = "chat_history.jsonl";
@@ -448,7 +481,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
448
481
  try {
449
482
  for (const candidate of readdirSync(sessionsDir)) {
450
483
  const directory = join9(sessionsDir, candidate);
451
- if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
484
+ if (readFileSync7(join9(directory, ".cwd"), "utf8").trim() === cwd) {
452
485
  return join9(directory, sessionId, CHAT_HISTORY);
453
486
  }
454
487
  }
@@ -457,14 +490,8 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
457
490
  return direct;
458
491
  }
459
492
  function readGrokTranscript(path) {
460
- let raw;
461
- try {
462
- raw = readFileSync12(path, "utf8");
463
- } catch {
464
- return [];
465
- }
466
493
  const turns = [];
467
- for (const rawLine of raw.split("\n")) {
494
+ for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
468
495
  try {
469
496
  const event = JSON.parse(rawLine);
470
497
  if (event.type !== "user" && event.type !== "assistant") continue;
@@ -839,13 +866,13 @@ var HOOK_HARNESSES = {
839
866
 
840
867
  // src/core/history.ts
841
868
  import {
842
- closeSync,
869
+ closeSync as closeSync2,
843
870
  existsSync as existsSync6,
844
- openSync,
871
+ openSync as openSync2,
845
872
  readdirSync as readdirSync2,
846
- readFileSync as readFileSync13,
847
- readSync,
848
- statSync
873
+ readFileSync as readFileSync8,
874
+ readSync as readSync2,
875
+ statSync as statSync2
849
876
  } from "fs";
850
877
  import { homedir as homedir7 } from "os";
851
878
  import { join as join11 } from "path";
@@ -857,7 +884,7 @@ function withinRepo(dir, repoDir) {
857
884
  }
858
885
  function claudeSessionCwd(file) {
859
886
  try {
860
- for (const line of readFileSync13(file, "utf8").split("\n", 400)) {
887
+ for (const line of readFileSync8(file, "utf8").split("\n", 400)) {
861
888
  if (!line.includes('"cwd"')) continue;
862
889
  const cwd = JSON.parse(line).cwd;
863
890
  if (cwd) return cwd;
@@ -875,12 +902,12 @@ function toSession(id, turns) {
875
902
  return prose.length ? { id, turns: prose } : void 0;
876
903
  }
877
904
  function firstLine(path, cap = 1e6) {
878
- const fd = openSync(path, "r");
905
+ const fd = openSync2(path, "r");
879
906
  try {
880
907
  const chunk = Buffer.alloc(64 * 1024);
881
908
  let acc = "";
882
909
  while (acc.length < cap) {
883
- const n = readSync(fd, chunk, 0, chunk.length, null);
910
+ const n = readSync2(fd, chunk, 0, chunk.length, null);
884
911
  if (n <= 0) break;
885
912
  acc += chunk.subarray(0, n).toString("utf8");
886
913
  const nl = acc.indexOf("\n");
@@ -888,7 +915,7 @@ function firstLine(path, cap = 1e6) {
888
915
  }
889
916
  return acc.length && acc.length < cap ? acc : void 0;
890
917
  } finally {
891
- closeSync(fd);
918
+ closeSync2(fd);
892
919
  }
893
920
  }
894
921
  function jsonlFiles(dir) {
@@ -925,7 +952,7 @@ function codexHistory(repoDir, home) {
925
952
  const walk = (dir) => {
926
953
  for (const entry of readdirSync2(dir)) {
927
954
  const p = join11(dir, entry);
928
- if (statSync(p).isDirectory()) walk(p);
955
+ if (statSync2(p).isDirectory()) walk(p);
929
956
  else if (entry.endsWith(".jsonl")) files.push(p);
930
957
  }
931
958
  };
@@ -968,7 +995,7 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
968
995
  }
969
996
 
970
997
  // src/core/legacy.ts
971
- import { existsSync as existsSync7, readFileSync as readFileSync14 } from "fs";
998
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
972
999
  import { homedir as homedir8 } from "os";
973
1000
  import { join as join12 } from "path";
974
1001
  var LEGACY_CONFIG_FILES = {
@@ -994,7 +1021,7 @@ function readOne(harness, home) {
994
1021
  if (!existsSync7(source)) return void 0;
995
1022
  let raw;
996
1023
  try {
997
- raw = JSON.parse(readFileSync14(source, "utf8"));
1024
+ raw = JSON.parse(readFileSync9(source, "utf8"));
998
1025
  } catch {
999
1026
  return void 0;
1000
1027
  }
@@ -1022,7 +1049,7 @@ function readOne(harness, home) {
1022
1049
 
1023
1050
  // src/install-ui.ts
1024
1051
  import { execFileSync as execFileSync5 } from "child_process";
1025
- import { readSync as readSync2 } from "fs";
1052
+ import { readSync as readSync3 } from "fs";
1026
1053
  function fitSelectRow(label, hint, width) {
1027
1054
  const room = Math.max(10, width - 6);
1028
1055
  let hintText = hint ? ` \u2014 ${hint}` : "";
@@ -1148,7 +1175,7 @@ function createInstallerUi(o) {
1148
1175
  for (; ; ) {
1149
1176
  let n;
1150
1177
  try {
1151
- n = readSync2(0, buf, 0, buf.length, null);
1178
+ n = readSync3(0, buf, 0, buf.length, null);
1152
1179
  } catch (e) {
1153
1180
  if (e.code !== "EAGAIN") return null;
1154
1181
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
@@ -1222,7 +1249,7 @@ function createInstallerUi(o) {
1222
1249
  var MARKER = "coding-agents";
1223
1250
  function readJson(path) {
1224
1251
  try {
1225
- return JSON.parse(readFileSync15(path, "utf8"));
1252
+ return JSON.parse(readFileSync10(path, "utf8"));
1226
1253
  } catch {
1227
1254
  return {};
1228
1255
  }
@@ -1341,7 +1368,7 @@ var kilo = {
1341
1368
  const path = kiloConfigPath(c);
1342
1369
  let cfg = {};
1343
1370
  if (existsSync8(path)) {
1344
- const parsed = parseJsonc(readFileSync15(path, "utf8"));
1371
+ const parsed = parseJsonc(readFileSync10(path, "utf8"));
1345
1372
  if (!parsed) {
1346
1373
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
1347
1374
  return;
@@ -1357,7 +1384,7 @@ var kilo = {
1357
1384
  uninstall(c) {
1358
1385
  const path = kiloConfigPath(c);
1359
1386
  if (!existsSync8(path)) return;
1360
- const cfg = parseJsonc(readFileSync15(path, "utf8"));
1387
+ const cfg = parseJsonc(readFileSync10(path, "utf8"));
1361
1388
  if (!cfg || !Array.isArray(cfg.plugin)) return;
1362
1389
  cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
1363
1390
  if (!cfg.plugin.length) delete cfg.plugin;
@@ -1431,7 +1458,7 @@ var codex = {
1431
1458
  writeJson(hooksPath, cfg);
1432
1459
  c.log?.(`codex: hooks merged into ${hooksPath}`);
1433
1460
  const tomlPath = join13(c.home, ".codex", "config.toml");
1434
- let toml = existsSync8(tomlPath) ? readFileSync15(tomlPath, "utf8") : "";
1461
+ let toml = existsSync8(tomlPath) ? readFileSync10(tomlPath, "utf8") : "";
1435
1462
  const additions = [];
1436
1463
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
1437
1464
  if (/^\[features\]/m.test(toml)) {
@@ -1472,7 +1499,7 @@ args = ["${join13(c.dist, "mcp-server.js")}"]`
1472
1499
  uninstallSkill(c, join13(c.home, ".agents", "skills"));
1473
1500
  const tomlPath = join13(c.home, ".codex", "config.toml");
1474
1501
  if (existsSync8(tomlPath)) {
1475
- const toml = readFileSync15(tomlPath, "utf8");
1502
+ const toml = readFileSync10(tomlPath, "utf8");
1476
1503
  const cleaned = toml.replace(
1477
1504
  /\n?\[mcp_servers\.hindsight\]\ncommand = "node"\nargs = \[[^\]]*\]\n?/g,
1478
1505
  "\n"
@@ -1669,7 +1696,7 @@ function readLineSync(c, prompt) {
1669
1696
  const buf = Buffer.alloc(1024);
1670
1697
  for (; ; ) {
1671
1698
  try {
1672
- const n = readSync3(0, buf, 0, buf.length, null);
1699
+ const n = readSync4(0, buf, 0, buf.length, null);
1673
1700
  return buf.subarray(0, n).toString("utf8");
1674
1701
  } catch (e) {
1675
1702
  if (e.code !== "EAGAIN") {
@@ -1916,7 +1943,7 @@ var grok = {
1916
1943
  detect: (c) => onPath2("grok") || existsSync8(join13(c.home, ".grok")),
1917
1944
  install(c) {
1918
1945
  const path = join13(c.home, ".grok", "config.toml");
1919
- const existing = existsSync8(path) ? readFileSync15(path, "utf8") : "";
1946
+ const existing = existsSync8(path) ? readFileSync10(path, "utf8") : "";
1920
1947
  const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
1921
1948
  const command = (entry) => JSON.stringify(`node "${join13(c.dist, entry)}"`);
1922
1949
  const tomlString = (value) => JSON.stringify(value);
@@ -1955,7 +1982,7 @@ ${GROK_MARKER_END}
1955
1982
  uninstall(c) {
1956
1983
  const path = join13(c.home, ".grok", "config.toml");
1957
1984
  if (existsSync8(path)) {
1958
- const existing = readFileSync15(path, "utf8");
1985
+ const existing = readFileSync10(path, "utf8");
1959
1986
  const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
1960
1987
  if (cleaned !== existing) writeFileSync2(path, cleaned);
1961
1988
  }
@@ -1970,7 +1997,7 @@ function removeLegacyClineHooks(c) {
1970
1997
  const hooksDir = join13(c.home, "Documents", "Cline", "Hooks");
1971
1998
  for (const event of CLINE_OLD_HOOK_EVENTS) {
1972
1999
  const path = join13(hooksDir, event);
1973
- if (existsSync8(path) && readFileSync15(path, "utf8").includes(CLINE_HOOK_MARKER)) {
2000
+ if (existsSync8(path) && readFileSync10(path, "utf8").includes(CLINE_HOOK_MARKER)) {
1974
2001
  rmSync(path, { force: true });
1975
2002
  }
1976
2003
  }
@@ -2151,7 +2178,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
2151
2178
  const pkgRoot = dirname8(dist);
2152
2179
  let version;
2153
2180
  try {
2154
- version = JSON.parse(readFileSync15(join13(pkgRoot, "package.json"), "utf8")).version;
2181
+ version = JSON.parse(readFileSync10(join13(pkgRoot, "package.json"), "utf8")).version;
2155
2182
  } catch {
2156
2183
  version = void 0;
2157
2184
  }