@vectorize-io/hindsight-coding-agents 0.5.4 → 0.6.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.
Files changed (50) hide show
  1. package/README.md +24 -7
  2. package/dist/antigravity-hook.js +205 -81
  3. package/dist/antigravity-statusline.js +32 -22
  4. package/dist/antigravity-stop-hook.js +216 -79
  5. package/dist/claude-hook.js +205 -81
  6. package/dist/claude-sessionstart-hook.js +167 -105
  7. package/dist/claude-stop-hook.js +216 -79
  8. package/dist/cline.js +279 -86
  9. package/dist/codex-hook.js +205 -81
  10. package/dist/codex-sessionstart-hook.js +167 -105
  11. package/dist/codex-stop-hook.js +216 -79
  12. package/dist/copilot-hook.js +205 -81
  13. package/dist/copilot-sessionstart-hook.js +167 -105
  14. package/dist/copilot-stop-hook.js +216 -79
  15. package/dist/cursor-hook.js +205 -81
  16. package/dist/cursor-sessionstart-hook.js +167 -105
  17. package/dist/cursor-stop-hook.js +216 -79
  18. package/dist/daemon-start.js +28 -18
  19. package/dist/dcode-hook.js +205 -81
  20. package/dist/dcode-sessionstart-hook.js +167 -105
  21. package/dist/dcode-stop-hook.js +216 -79
  22. package/dist/deepen.js +98 -40
  23. package/dist/devin-hook.js +205 -81
  24. package/dist/devin-sessionstart-hook.js +167 -105
  25. package/dist/devin-stop-hook.js +216 -79
  26. package/dist/droid-hook.js +205 -81
  27. package/dist/droid-sessionstart-hook.js +167 -105
  28. package/dist/droid-stop-hook.js +216 -79
  29. package/dist/dsh.js +277 -85
  30. package/dist/grok-hook.js +205 -81
  31. package/dist/grok-sessionstart-hook.js +167 -105
  32. package/dist/grok-stop-hook.js +216 -79
  33. package/dist/hindsight-seed.js +32 -22
  34. package/dist/index.js +280 -88
  35. package/dist/installer.js +308 -214
  36. package/dist/kilo.js +280 -88
  37. package/dist/mcp-server.js +97 -39
  38. package/dist/opencode2.js +279 -87
  39. package/dist/pi.js +279 -87
  40. package/dist/prime-agent.js +279 -87
  41. package/dist/qwen-hook.js +205 -81
  42. package/dist/qwen-sessionstart-hook.js +167 -105
  43. package/dist/qwen-stop-hook.js +216 -79
  44. package/dist/status.js +94 -36
  45. package/dist/zcode-hook.js +205 -81
  46. package/dist/zcode-sessionstart-hook.js +167 -105
  47. package/dist/zcode-stop-hook.js +216 -79
  48. package/package.json +1 -1
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +24 -7
@@ -5,16 +5,28 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
5
5
 
6
6
  // src/core/bank.ts
7
7
  import { existsSync } from "fs";
8
- import { homedir } from "os";
9
- import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
8
+ import { homedir as homedir2 } from "os";
9
+ import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
10
10
 
11
11
  // src/core/diag.ts
12
- import { appendFileSync as appendFileSync2 } from "fs";
12
+ import { join as join2 } from "path";
13
13
 
14
14
  // src/core/log.ts
15
- import { appendFileSync, mkdirSync } from "fs";
16
- import { tmpdir } from "os";
15
+ import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
16
+ import { homedir } from "os";
17
17
  import { dirname, join } from "path";
18
+ function logsDir() {
19
+ return join(homedir(), ".hindsight", "coding-agents-logs");
20
+ }
21
+ var LOG_MAX_BYTES = 10 * 1024 * 1024;
22
+ function appendLogLine(file, text) {
23
+ mkdirSync(dirname(file), { recursive: true, mode: 448 });
24
+ try {
25
+ if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
26
+ } catch {
27
+ }
28
+ appendFileSync(file, text, { mode: 384 });
29
+ }
18
30
  var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
19
31
  var current = ["debug", "info", "warn", "error"].find(
20
32
  (l) => l === process.env.HINDSIGHT_LOG_LEVEL
@@ -23,15 +35,13 @@ function setLogLevel(level) {
23
35
  if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
24
36
  }
25
37
  function logFilePath() {
26
- return process.env.HINDSIGHT_LOG_FILE || join(tmpdir(), "hindsight-coding-agent", "plugin.log");
38
+ return process.env.HINDSIGHT_LOG_FILE || join(logsDir(), "plugin.log");
27
39
  }
28
40
  function write(level, scope, msg, extra) {
29
41
  if (WEIGHT[level] < WEIGHT[current]) return;
30
42
  try {
31
- const file = logFilePath();
32
- mkdirSync(dirname(file), { recursive: true });
33
- appendFileSync(
34
- file,
43
+ appendLogLine(
44
+ logFilePath(),
35
45
  `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
36
46
  );
37
47
  } catch {
@@ -46,12 +56,12 @@ var log = {
46
56
 
47
57
  // src/core/diag.ts
48
58
  function diagFilePath() {
49
- return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
59
+ return process.env.HINDSIGHT_DIAG_FILE || join2(logsDir(), "diag.jsonl");
50
60
  }
51
61
  function diag(harness, event, extra = {}) {
52
62
  log.debug(harness, `diag:${event}`, extra);
53
63
  try {
54
- appendFileSync2(
64
+ appendLogLine(
55
65
  diagFilePath(),
56
66
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
57
67
  );
@@ -61,7 +71,7 @@ function diag(harness, event, extra = {}) {
61
71
 
62
72
  // src/core/git-layout.ts
63
73
  import { lstatSync, readFileSync, realpathSync } from "fs";
64
- import { dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
74
+ import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
65
75
  var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
66
76
  var ATTEMPTS = 3;
67
77
  var BACKOFF_MS = 20;
@@ -97,16 +107,16 @@ function gitDirFromPointer(text, holder) {
97
107
  return isAbsolute(target) ? target : resolve(holder, target);
98
108
  }
99
109
  function commonDirOf(gitDir) {
100
- const pointer = entryKind(join2(gitDir, "commondir")) === "file" ? readTextOrNull(join2(gitDir, "commondir"))?.trim() : null;
110
+ const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
101
111
  if (!pointer) return gitDir;
102
112
  return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
103
113
  }
104
114
  function isBare(commonDir) {
105
- const config = readTextOrNull(join2(commonDir, "config"));
115
+ const config = readTextOrNull(join3(commonDir, "config"));
106
116
  return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
107
117
  }
108
118
  function looksLikeBareRepository(directory) {
109
- return entryKind(join2(directory, "HEAD")) === "file" && entryKind(join2(directory, "objects")) === "dir" && entryKind(join2(directory, "refs")) === "dir";
119
+ return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
110
120
  }
111
121
  function canonical(path) {
112
122
  try {
@@ -123,7 +133,7 @@ function resolved(commonDir) {
123
133
  function probeOnce(directory) {
124
134
  let current2 = resolve(directory);
125
135
  for (; ; ) {
126
- const dotGit = join2(current2, ".git");
136
+ const dotGit = join3(current2, ".git");
127
137
  const kind = entryKind(dotGit);
128
138
  if (kind === "dir") {
129
139
  const layout = resolved(commonDirOf(dotGit));
@@ -237,7 +247,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
237
247
  return dirName(sessionRoot || directory);
238
248
  }
239
249
  function configuredDir(dir) {
240
- const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir(), dir.slice(1)) : dir;
250
+ const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
241
251
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
242
252
  }
243
253
  function isWithin(directory, configured) {
@@ -311,18 +321,18 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
311
321
 
312
322
  // src/core/config.ts
313
323
  import { readFileSync as readFileSync2 } from "fs";
314
- import { homedir as homedir2 } from "os";
315
- import { join as join6 } from "path";
324
+ import { homedir as homedir3 } from "os";
325
+ import { join as join7 } from "path";
316
326
 
317
327
  // src/core/seed.ts
318
328
  import { spawn as realSpawn } from "child_process";
319
- import { dirname as dirname4, join as join4 } from "path";
329
+ import { dirname as dirname4, join as join5 } from "path";
320
330
  import { fileURLToPath } from "url";
321
331
  var DEFAULT_SEED_LIMIT = 300;
322
332
  function startBackgroundSeed(repoDir, opts = {}) {
323
333
  try {
324
334
  const spawnFn = opts.spawn ?? realSpawn;
325
- const enginePath = opts.enginePath ?? join4(dirname4(fileURLToPath(import.meta.url)), "deepen.js");
335
+ const enginePath = opts.enginePath ?? join5(dirname4(fileURLToPath(import.meta.url)), "deepen.js");
326
336
  const limit = opts.limit ?? DEFAULT_SEED_LIMIT;
327
337
  const child = spawnFn(
328
338
  "node",
@@ -579,7 +589,7 @@ function codingBankManifest(overrides) {
579
589
 
580
590
  // src/core/util.ts
581
591
  import { accessSync, constants } from "fs";
582
- import { delimiter, join as join5 } from "path";
592
+ import { delimiter, join as join6 } from "path";
583
593
  function binOnPath(bin) {
584
594
  try {
585
595
  if (bin.includes("/")) {
@@ -589,7 +599,7 @@ function binOnPath(bin) {
589
599
  for (const dir of (process.env.PATH || "").split(delimiter)) {
590
600
  if (!dir) continue;
591
601
  try {
592
- accessSync(join5(dir, bin), constants.X_OK);
602
+ accessSync(join6(dir, bin), constants.X_OK);
593
603
  return true;
594
604
  } catch {
595
605
  }
@@ -661,6 +671,22 @@ var KnowledgePagesUnavailableError = class extends Error {
661
671
  }
662
672
  };
663
673
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
674
+ var ReflectError = class extends Error {
675
+ constructor(message, status, timedOut, options) {
676
+ super(message, options);
677
+ this.status = status;
678
+ this.timedOut = timedOut;
679
+ this.name = "ReflectError";
680
+ }
681
+ status;
682
+ timedOut;
683
+ /** A timeout or a 5xx means reflect's synthesis (the slow LLM path) broke, while the cheap
684
+ * retrieval endpoints may still answer — worth falling back. A 4xx will fail the same way on
685
+ * every endpoint (auth, missing bank), so it is not. */
686
+ get fallbackEligible() {
687
+ return this.timedOut || this.status !== void 0 && this.status >= 500;
688
+ }
689
+ };
664
690
  var DEFAULT_MAX_PARALLEL_RETAINS = 10;
665
691
  var POLL_CYCLE_MS = 5e3;
666
692
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
@@ -744,11 +770,11 @@ var HindsightClient = class {
744
770
  return `${this.apiUrl}/v1/default/banks/${encodeURIComponent(this.bank)}${suffix}`;
745
771
  }
746
772
  /** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
747
- async req(method, url, body, tolerate = []) {
773
+ async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
748
774
  const r = await this.fetchWithAuth(url, {
749
775
  method,
750
776
  body: body ? JSON.stringify(body) : void 0,
751
- signal: AbortSignal.timeout(15e3)
777
+ signal: AbortSignal.timeout(timeoutMs)
752
778
  });
753
779
  if (r.status === 429 && !tolerate.includes(429))
754
780
  throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
@@ -941,7 +967,7 @@ var HindsightClient = class {
941
967
  /**
942
968
  * Reflect: synthesized, root-cause answer over the bank. Bounded so a slow server never hangs a
943
969
  * caller — but `timeoutMs` is REQUIRED, deliberately: the right deadline differs by an order of
944
- * magnitude between the automatic hook (25s, to fit the host's window) and the agent-invoked
970
+ * magnitude between the automatic hook (20s, to fit the host's window) and the agent-invoked
945
971
  * tool (minutes, on a populated bank). This used to default to 120s, which silently overrode the
946
972
  * tool's configured window and aborted every high-budget synthesis mid-flight (#3590).
947
973
  */
@@ -955,19 +981,45 @@ var HindsightClient = class {
955
981
  signal: ctrl.signal
956
982
  });
957
983
  if (!resp.ok)
958
- throw new Error(
959
- `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
984
+ throw new ReflectError(
985
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`,
986
+ resp.status,
987
+ false
960
988
  );
961
989
  const data = await resp.json();
962
990
  return (data.text || "").trim();
963
991
  } catch (e) {
964
992
  if (ctrl.signal.aborted)
965
- throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
993
+ throw new ReflectError(`reflect timed out after ${opts.timeoutMs}ms`, void 0, true, {
994
+ cause: e
995
+ });
966
996
  throw e;
967
997
  } finally {
968
998
  clearTimeout(timer);
969
999
  }
970
1000
  }
1001
+ /**
1002
+ * Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
1003
+ * when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
1004
+ */
1005
+ async recallObservations(query, opts) {
1006
+ const r = await this.req(
1007
+ "POST",
1008
+ this.bankUrl("/memories/recall"),
1009
+ {
1010
+ query,
1011
+ types: ["observation"],
1012
+ budget: "low",
1013
+ max_tokens: opts.maxTokens,
1014
+ include: { entities: null }
1015
+ },
1016
+ [],
1017
+ opts.timeoutMs
1018
+ );
1019
+ if (r.status === 404) return [];
1020
+ const j = await r.json();
1021
+ return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
1022
+ }
971
1023
  /**
972
1024
  * The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
973
1025
  * queries and staleness but NOT synthesized content, so it is cheap enough to poll.
@@ -1032,10 +1084,16 @@ var HindsightClient = class {
1032
1084
  /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
1033
1085
  * Returns page-level hits with a relevance snippet — the real search behind
1034
1086
  * hindsight_search_knowledge_pages. */
1035
- async searchKnowledgePages(query, limit = 3) {
1087
+ async searchKnowledgePages(query, limit = 3, timeoutMs) {
1036
1088
  if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1037
1089
  const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
1038
- const r = await this.req("GET", this.bankUrl(`/knowledge-base/search${q}`));
1090
+ const r = await this.req(
1091
+ "GET",
1092
+ this.bankUrl(`/knowledge-base/search${q}`),
1093
+ void 0,
1094
+ [],
1095
+ timeoutMs
1096
+ );
1039
1097
  const j = await r.json();
1040
1098
  return (j.results ?? []).map((x) => ({
1041
1099
  id: x.id,
@@ -1222,7 +1280,7 @@ var HindsightClient = class {
1222
1280
  };
1223
1281
 
1224
1282
  // src/core/config.ts
1225
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
1283
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
1226
1284
  var DEFAULT_DAEMON_PORT = 9077;
1227
1285
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1228
1286
  function resolvePageTrigger(raw) {
@@ -1529,18 +1587,18 @@ This tool guide and the page list are re-injected for you periodically as things
1529
1587
  }
1530
1588
 
1531
1589
  // src/core/session-cache.ts
1532
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
1533
- import { tmpdir as tmpdir2 } from "os";
1534
- import { dirname as dirname5, join as join7 } from "path";
1590
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, writeFileSync } from "fs";
1591
+ import { tmpdir } from "os";
1592
+ import { dirname as dirname5, join as join8 } from "path";
1535
1593
  function sessionCacheFile(harness, sessionId) {
1536
- return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.json`);
1594
+ return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.json`);
1537
1595
  }
1538
1596
  function writeFileAtomic(path, body) {
1539
1597
  mkdirSync2(dirname5(path), { recursive: true });
1540
1598
  const tmp = `${path}.${process.pid}.tmp`;
1541
1599
  try {
1542
1600
  writeFileSync(tmp, body);
1543
- renameSync(tmp, path);
1601
+ renameSync2(tmp, path);
1544
1602
  } catch (e) {
1545
1603
  try {
1546
1604
  rmSync(tmp, { force: true });
@@ -1556,7 +1614,7 @@ function writeSessionCache(cacheFile, cache) {
1556
1614
  }
1557
1615
  }
1558
1616
  function sessionRootFile(harness, sessionId) {
1559
- return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.root`);
1617
+ return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.root`);
1560
1618
  }
1561
1619
  function sessionRootDir(harness, sessionId, cwd) {
1562
1620
  if (!sessionId || !cwd) return cwd;
@@ -1574,9 +1632,9 @@ function sessionRootDir(harness, sessionId, cwd) {
1574
1632
  }
1575
1633
 
1576
1634
  // src/core/turn-journal.ts
1577
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
1578
- import { tmpdir as tmpdir3 } from "os";
1579
- import { dirname as dirname6, join as join8 } from "path";
1635
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync as statSync2 } from "fs";
1636
+ import { tmpdir as tmpdir2 } from "os";
1637
+ import { dirname as dirname6, join as join9 } from "path";
1580
1638
 
1581
1639
  // src/core/transcript-util.ts
1582
1640
  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;
@@ -1617,7 +1675,7 @@ function actionLine(tool, input) {
1617
1675
  var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
1618
1676
 
1619
1677
  // src/core/retain-hook.ts
1620
- import { readFileSync as readFileSync6 } from "fs";
1678
+ import { readFileSync as readFileSync7 } from "fs";
1621
1679
 
1622
1680
  // src/core/retain-cursor.ts
1623
1681
  import { createHash as createHash2 } from "crypto";
@@ -1629,7 +1687,7 @@ import { createHash as createHash3 } from "crypto";
1629
1687
 
1630
1688
  // src/core/daemon.ts
1631
1689
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1632
- import { dirname as dirname7, join as join9 } from "path";
1690
+ import { dirname as dirname7, join as join10 } from "path";
1633
1691
  import { fileURLToPath as fileURLToPath2 } from "url";
1634
1692
  var DAEMON_WAIT_SESSION_START_MS = 12e3;
1635
1693
  async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
@@ -1703,7 +1761,7 @@ function onPath(bin) {
1703
1761
  }
1704
1762
  function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
1705
1763
  try {
1706
- const starter = join9(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
1764
+ const starter = join10(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
1707
1765
  const child = spawnFn("node", [starter, "--harness", harness], {
1708
1766
  detached: true,
1709
1767
  stdio: "ignore",
@@ -1804,7 +1862,7 @@ function buildRetainStamp(cfg, ctx) {
1804
1862
  }
1805
1863
 
1806
1864
  // src/core/jsonl.ts
1807
- import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1865
+ import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
1808
1866
  import { StringDecoder } from "string_decoder";
1809
1867
  var CHUNK_BYTES = 64 * 1024;
1810
1868
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1812,7 +1870,7 @@ function readJsonlTail(path, opts) {
1812
1870
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1813
1871
  let size;
1814
1872
  try {
1815
- size = statSync2(path).size;
1873
+ size = statSync3(path).size;
1816
1874
  } catch {
1817
1875
  return { lines: emptyLines(), skippedBytes: 0 };
1818
1876
  }
@@ -1864,8 +1922,12 @@ function* streamLines(path, start) {
1864
1922
  }
1865
1923
  }
1866
1924
 
1925
+ // src/core/usage.ts
1926
+ import { readFileSync as readFileSync6 } from "fs";
1927
+ import { join as join11 } from "path";
1928
+
1867
1929
  // src/core/session-start.ts
1868
- import { readFileSync as readFileSync10 } from "fs";
1930
+ import { readFileSync as readFileSync11 } from "fs";
1869
1931
 
1870
1932
  // src/core/git.ts
1871
1933
  import { execFileSync as execFileSync2 } from "child_process";
@@ -1910,8 +1972,8 @@ import { execFileSync as execFileSync3 } from "child_process";
1910
1972
  import { spawn as realSpawn4 } from "child_process";
1911
1973
  import { createHash as createHash4 } from "crypto";
1912
1974
  import { existsSync as existsSync3 } from "fs";
1913
- import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
1914
- import { dirname as dirname8, join as join11 } from "path";
1975
+ import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
1976
+ import { dirname as dirname8, join as join13 } from "path";
1915
1977
  import { fileURLToPath as fileURLToPath3 } from "url";
1916
1978
 
1917
1979
  // src/core/host-client.ts
@@ -1930,20 +1992,20 @@ import {
1930
1992
  mkdirSync as mkdirSync4,
1931
1993
  mkdtempSync,
1932
1994
  readdirSync,
1933
- renameSync as renameSync2,
1995
+ renameSync as renameSync3,
1934
1996
  rmdirSync,
1935
1997
  rmSync as rmSync2,
1936
- statSync as statSync3,
1998
+ statSync as statSync4,
1937
1999
  unlinkSync,
1938
2000
  utimesSync,
1939
2001
  writeFileSync as writeFileSync2
1940
2002
  } from "fs";
1941
- import { join as join10 } from "path";
2003
+ import { join as join12 } from "path";
1942
2004
  var LEASE_STALE_MS = 3e4;
1943
2005
  var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
1944
2006
  function tryRename(from, to) {
1945
2007
  try {
1946
- renameSync2(from, to);
2008
+ renameSync3(from, to);
1947
2009
  return true;
1948
2010
  } catch {
1949
2011
  return false;
@@ -1951,7 +2013,7 @@ function tryRename(from, to) {
1951
2013
  }
1952
2014
  function releaseLease(lease) {
1953
2015
  try {
1954
- unlinkSync(join10(lease.directory, lease.owner));
2016
+ unlinkSync(join12(lease.directory, lease.owner));
1955
2017
  } catch {
1956
2018
  return;
1957
2019
  }
@@ -1970,7 +2032,7 @@ function reclaimIfStale(directory, staleMs) {
1970
2032
  return true;
1971
2033
  }
1972
2034
  if (owners.length !== 1) return false;
1973
- const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
2035
+ const age = Date.now() - statSync4(join12(directory, owners[0])).mtimeMs;
1974
2036
  if (Math.abs(age) <= staleMs) return false;
1975
2037
  releaseLease({ directory, owner: owners[0] });
1976
2038
  return true;
@@ -1979,10 +2041,10 @@ function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
1979
2041
  let staging;
1980
2042
  try {
1981
2043
  mkdirSync4(root, { recursive: true, mode: 448 });
1982
- staging = mkdtempSync(join10(root, "claim-"));
2044
+ staging = mkdtempSync(join12(root, "claim-"));
1983
2045
  const owner = randomUUID();
1984
- writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
1985
- const directory = join10(root, `survey-${key}.lock`);
2046
+ writeFileSync2(join12(staging, owner), "", { flag: "wx", mode: 384 });
2047
+ const directory = join12(root, `survey-${key}.lock`);
1986
2048
  if (!tryRename(staging, directory)) {
1987
2049
  if (!reclaimIfStale(directory, staleMs)) return void 0;
1988
2050
  if (!tryRename(staging, directory)) return void 0;
@@ -2005,7 +2067,7 @@ var SURVEY_DOC_IDS = [
2005
2067
  function resolveClaudeBin(explicit) {
2006
2068
  if (explicit) return explicit;
2007
2069
  if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
2008
- const nativeInstallPath = join11(homedir3(), ".claude", "local", "claude");
2070
+ const nativeInstallPath = join13(homedir4(), ".claude", "local", "claude");
2009
2071
  try {
2010
2072
  if (existsSync3(nativeInstallPath)) return nativeInstallPath;
2011
2073
  } catch {
@@ -2123,7 +2185,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2123
2185
  try {
2124
2186
  const spawnFn = opts.spawn ?? realSpawn4;
2125
2187
  const exists = opts.exists ?? binOnPath;
2126
- const mcpServerPath = opts.mcpServerPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
2188
+ const mcpServerPath = opts.mcpServerPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
2127
2189
  const preferred = opts.harness ?? "claude-code";
2128
2190
  const order = [
2129
2191
  preferred,
@@ -2147,7 +2209,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2147
2209
  if (cfg.disabled) return false;
2148
2210
  const key = createHash4("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
2149
2211
  const lease = acquireLease(
2150
- opts.lease?.dir ?? join11(tmpdir4(), "hindsight-coding-agent", "surveys"),
2212
+ opts.lease?.dir ?? join13(tmpdir3(), "hindsight-coding-agent", "surveys"),
2151
2213
  key,
2152
2214
  opts.lease?.staleMs ?? LEASE_STALE_MS
2153
2215
  );
@@ -2158,7 +2220,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2158
2220
  args: plan.args,
2159
2221
  ...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
2160
2222
  };
2161
- const supervisorPath = opts.supervisorPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
2223
+ const supervisorPath = opts.supervisorPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
2162
2224
  return await new Promise((resolve3) => {
2163
2225
  try {
2164
2226
  const child = spawnFn("node", [supervisorPath], {
@@ -2198,25 +2260,25 @@ import { spawn as realSpawn5 } from "child_process";
2198
2260
  import {
2199
2261
  existsSync as existsSync4,
2200
2262
  mkdirSync as mkdirSync5,
2201
- readFileSync as readFileSync7,
2263
+ readFileSync as readFileSync8,
2202
2264
  realpathSync as realpathSync2,
2203
2265
  unlinkSync as unlinkSync2,
2204
2266
  writeFileSync as writeFileSync3
2205
2267
  } from "fs";
2206
- import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
2207
- import { dirname as dirname9, join as join12 } from "path";
2268
+ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2269
+ import { dirname as dirname9, join as join14 } from "path";
2208
2270
  import { fileURLToPath as fileURLToPath4 } from "url";
2209
2271
  var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
2210
2272
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2211
2273
  var FETCH_TIMEOUT_MS = 5e3;
2212
2274
  function stateFile(runtimeDir) {
2213
- return join12(runtimeDir, ".update-check.json");
2275
+ return join14(runtimeDir, ".update-check.json");
2214
2276
  }
2215
2277
  function packageRoot() {
2216
- return join12(dirname9(fileURLToPath4(import.meta.url)), "..");
2278
+ return join14(dirname9(fileURLToPath4(import.meta.url)), "..");
2217
2279
  }
2218
2280
  function stagedRuntimeDir() {
2219
- return join12(homedir4(), ".hindsight", "coding-agents");
2281
+ return join14(homedir5(), ".hindsight", "coding-agents");
2220
2282
  }
2221
2283
  function sameDir(a, b) {
2222
2284
  try {
@@ -2227,7 +2289,7 @@ function sameDir(a, b) {
2227
2289
  }
2228
2290
  function stagedVersion(pkgRoot) {
2229
2291
  try {
2230
- const pkg = JSON.parse(readFileSync7(join12(pkgRoot, "package.json"), "utf8"));
2292
+ const pkg = JSON.parse(readFileSync8(join14(pkgRoot, "package.json"), "utf8"));
2231
2293
  return typeof pkg.version === "string" ? pkg.version : "";
2232
2294
  } catch {
2233
2295
  return "";
@@ -2252,7 +2314,7 @@ function isNewer(candidate, current2) {
2252
2314
  }
2253
2315
  function dueForCheck(file, now) {
2254
2316
  try {
2255
- const state = JSON.parse(readFileSync7(file, "utf8"));
2317
+ const state = JSON.parse(readFileSync8(file, "utf8"));
2256
2318
  return typeof state.lastCheck !== "number" || now - state.lastCheck >= CHECK_INTERVAL_MS;
2257
2319
  } catch {
2258
2320
  return true;
@@ -2261,7 +2323,7 @@ function dueForCheck(file, now) {
2261
2323
  var ORIGIN_FILE = ".install-origin.json";
2262
2324
  function selfUpdatable(runtimeDir) {
2263
2325
  try {
2264
- const origin = JSON.parse(readFileSync7(join12(runtimeDir, ORIGIN_FILE), "utf8"));
2326
+ const origin = JSON.parse(readFileSync8(join14(runtimeDir, ORIGIN_FILE), "utf8"));
2265
2327
  if (typeof origin.source !== "string" || !origin.source) return false;
2266
2328
  return origin.source.split(/[\\/]/).includes("_npx");
2267
2329
  } catch {
@@ -2270,11 +2332,11 @@ function selfUpdatable(runtimeDir) {
2270
2332
  }
2271
2333
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2272
2334
  function lockFile() {
2273
- return join12(tmpdir5(), "hindsight-coding-agent", "auto-update.lock");
2335
+ return join14(tmpdir4(), "hindsight-coding-agent", "auto-update.lock");
2274
2336
  }
2275
2337
  function acquireUpdateLock(file, now) {
2276
2338
  try {
2277
- const held = JSON.parse(readFileSync7(file, "utf8"));
2339
+ const held = JSON.parse(readFileSync8(file, "utf8"));
2278
2340
  if (held.ts && now - held.ts < LOCK_STALE_MS) {
2279
2341
  let holderAlive = false;
2280
2342
  if (held.pid) {
@@ -2386,9 +2448,9 @@ async function maybeAutoUpdate(cfg, opts = {}) {
2386
2448
  }
2387
2449
 
2388
2450
  // src/core/skill-sync.ts
2389
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
2390
- import { homedir as homedir5 } from "os";
2391
- import { dirname as dirname10, join as join13 } from "path";
2451
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
2452
+ import { homedir as homedir6 } from "os";
2453
+ import { dirname as dirname10, join as join15 } from "path";
2392
2454
  import { fileURLToPath as fileURLToPath5 } from "url";
2393
2455
 
2394
2456
  // src/core/skill-dirs.ts
@@ -2420,19 +2482,19 @@ var SKILL_DIRS = {
2420
2482
 
2421
2483
  // src/core/skill-sync.ts
2422
2484
  function packagedSkillDir() {
2423
- return join13(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
2485
+ return join15(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
2424
2486
  }
2425
2487
  function syncCompanionSkill(harness, opts = {}) {
2426
2488
  try {
2427
2489
  const parts = SKILL_DIRS[harness];
2428
2490
  if (!parts) return;
2429
2491
  const src = opts.srcDir ?? packagedSkillDir();
2430
- const srcMd = join13(src, "SKILL.md");
2492
+ const srcMd = join15(src, "SKILL.md");
2431
2493
  if (!existsSync5(srcMd)) return;
2432
- const dst = join13(opts.home ?? homedir5(), ...parts, "hindsight-coding-agent");
2433
- const dstMd = join13(dst, "SKILL.md");
2494
+ const dst = join15(opts.home ?? homedir6(), ...parts, "hindsight-coding-agent");
2495
+ const dstMd = join15(dst, "SKILL.md");
2434
2496
  if (!existsSync5(dstMd)) return;
2435
- if (readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
2497
+ if (readFileSync9(srcMd, "utf8") !== readFileSync9(dstMd, "utf8")) {
2436
2498
  cpSync(src, dst, { recursive: true });
2437
2499
  }
2438
2500
  } catch {
@@ -2440,15 +2502,15 @@ function syncCompanionSkill(harness, opts = {}) {
2440
2502
  }
2441
2503
 
2442
2504
  // src/core/legacy.ts
2443
- import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2444
- import { homedir as homedir6 } from "os";
2445
- import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
2505
+ import { existsSync as existsSync6, readFileSync as readFileSync10 } from "fs";
2506
+ import { homedir as homedir7 } from "os";
2507
+ import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
2446
2508
  var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
2447
- function detectLegacyClaudePlugin(cwd, claudeDir = join14(homedir6(), ".claude")) {
2448
- const registry = readJson(join14(claudeDir, "plugins", "installed_plugins.json"));
2509
+ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir7(), ".claude")) {
2510
+ const registry = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
2449
2511
  const plugins = registry?.plugins;
2450
2512
  if (!plugins || typeof plugins !== "object") return void 0;
2451
- const enabled = readJson(join14(claudeDir, "settings.json"))?.enabledPlugins;
2513
+ const enabled = readJson(join16(claudeDir, "settings.json"))?.enabledPlugins;
2452
2514
  for (const [key, raw] of Object.entries(plugins)) {
2453
2515
  if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
2454
2516
  if (enabled && enabled[key] === false) continue;
@@ -2465,7 +2527,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join14(homedir6(), ".claude")
2465
2527
  }
2466
2528
  function readJson(path) {
2467
2529
  try {
2468
- const parsed = JSON.parse(readFileSync9(path, "utf8"));
2530
+ const parsed = JSON.parse(readFileSync10(path, "utf8"));
2469
2531
  return parsed && typeof parsed === "object" ? parsed : void 0;
2470
2532
  } catch {
2471
2533
  return void 0;
@@ -2639,7 +2701,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
2639
2701
  try {
2640
2702
  let ev = {};
2641
2703
  try {
2642
- ev = JSON.parse(readFileSync10(0, "utf8"));
2704
+ ev = JSON.parse(readFileSync11(0, "utf8"));
2643
2705
  } catch {
2644
2706
  return;
2645
2707
  }
@@ -2808,19 +2870,19 @@ function readCopilotTranscript(path) {
2808
2870
  }
2809
2871
 
2810
2872
  // src/core/transcript-grok.ts
2811
- import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
2812
- import { homedir as homedir7 } from "os";
2813
- import { join as join15 } from "path";
2873
+ import { existsSync as existsSync7, readFileSync as readFileSync12, readdirSync as readdirSync2 } from "fs";
2874
+ import { homedir as homedir8 } from "os";
2875
+ import { join as join17 } from "path";
2814
2876
  var CHAT_HISTORY = "chat_history.jsonl";
2815
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
2816
- const sessionsDir = join15(grokHome, "sessions");
2817
- const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2877
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join17(homedir8(), ".grok")) {
2878
+ const sessionsDir = join17(grokHome, "sessions");
2879
+ const direct = join17(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2818
2880
  if (existsSync7(direct)) return direct;
2819
2881
  try {
2820
2882
  for (const candidate of readdirSync2(sessionsDir)) {
2821
- const directory = join15(sessionsDir, candidate);
2822
- if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
2823
- return join15(directory, sessionId, CHAT_HISTORY);
2883
+ const directory = join17(sessionsDir, candidate);
2884
+ if (readFileSync12(join17(directory, ".cwd"), "utf8").trim() === cwd) {
2885
+ return join17(directory, sessionId, CHAT_HISTORY);
2824
2886
  }
2825
2887
  }
2826
2888
  } catch {
@@ -2857,10 +2919,10 @@ function readGrokTranscript(path) {
2857
2919
  // src/core/transcript-devin.ts
2858
2920
  import { existsSync as existsSync8 } from "fs";
2859
2921
  import { createRequire } from "module";
2860
- import { homedir as homedir8 } from "os";
2861
- import { join as join16 } from "path";
2862
- function devinSessionDb(home = homedir8()) {
2863
- return join16(home, ".local", "share", "devin", "cli", "sessions.db");
2922
+ import { homedir as homedir9 } from "os";
2923
+ import { join as join18 } from "path";
2924
+ function devinSessionDb(home = homedir9()) {
2925
+ return join18(home, ".local", "share", "devin", "cli", "sessions.db");
2864
2926
  }
2865
2927
  function parseDevinMessages(nodes) {
2866
2928
  const messages = /* @__PURE__ */ new Map();
@@ -3170,7 +3232,7 @@ function readDroidTranscript(path) {
3170
3232
  }
3171
3233
 
3172
3234
  // src/core/transcript-zcode.ts
3173
- import { readFileSync as readFileSync12 } from "fs";
3235
+ import { readFileSync as readFileSync13 } from "fs";
3174
3236
  function messageText2(content) {
3175
3237
  if (typeof content === "string") return content.trim();
3176
3238
  if (!Array.isArray(content)) return "";
@@ -3180,7 +3242,7 @@ function readZcodeTranscript(path) {
3180
3242
  if (!path) return [];
3181
3243
  let body;
3182
3244
  try {
3183
- body = readFileSync12(path, "utf8");
3245
+ body = readFileSync13(path, "utf8");
3184
3246
  } catch {
3185
3247
  return [];
3186
3248
  }