@vectorize-io/hindsight-coding-agents 0.5.1 → 0.5.3

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 +84 -9
  2. package/dist/antigravity-hook.js +424 -81
  3. package/dist/antigravity-statusline.js +56 -11
  4. package/dist/antigravity-stop-hook.js +515 -134
  5. package/dist/claude-hook.js +424 -81
  6. package/dist/claude-sessionstart-hook.js +392 -98
  7. package/dist/claude-stop-hook.js +515 -134
  8. package/dist/cline.js +218 -73
  9. package/dist/codex-hook.js +424 -81
  10. package/dist/codex-sessionstart-hook.js +392 -98
  11. package/dist/codex-stop-hook.js +515 -134
  12. package/dist/copilot-hook.js +424 -81
  13. package/dist/copilot-sessionstart-hook.js +392 -98
  14. package/dist/copilot-stop-hook.js +515 -134
  15. package/dist/cursor-hook.js +424 -81
  16. package/dist/cursor-sessionstart-hook.js +392 -98
  17. package/dist/cursor-stop-hook.js +515 -134
  18. package/dist/daemon-start.js +50 -9
  19. package/dist/dcode-hook.js +424 -81
  20. package/dist/dcode-sessionstart-hook.js +392 -98
  21. package/dist/dcode-stop-hook.js +515 -134
  22. package/dist/deepen.js +164 -27
  23. package/dist/devin-hook.js +424 -81
  24. package/dist/devin-sessionstart-hook.js +392 -98
  25. package/dist/devin-stop-hook.js +515 -134
  26. package/dist/droid-hook.js +2920 -0
  27. package/dist/droid-sessionstart-hook.js +3487 -0
  28. package/dist/droid-stop-hook.js +3188 -0
  29. package/dist/dsh.js +260 -109
  30. package/dist/grok-hook.js +424 -81
  31. package/dist/grok-sessionstart-hook.js +392 -98
  32. package/dist/grok-stop-hook.js +515 -134
  33. package/dist/hindsight-seed.js +56 -11
  34. package/dist/index.js +257 -110
  35. package/dist/installer.js +530 -223
  36. package/dist/kilo.js +257 -110
  37. package/dist/mcp-server.js +537 -146
  38. package/dist/opencode2.js +257 -110
  39. package/dist/pi.js +256 -109
  40. package/dist/prime-agent.js +256 -109
  41. package/dist/qwen-hook.js +424 -81
  42. package/dist/qwen-sessionstart-hook.js +392 -98
  43. package/dist/qwen-stop-hook.js +515 -134
  44. package/dist/status.js +128 -20
  45. package/dist/zcode-hook.js +2920 -0
  46. package/dist/zcode-sessionstart-hook.js +3487 -0
  47. package/dist/zcode-stop-hook.js +3188 -0
  48. package/package.json +11 -5
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +42 -8
package/dist/installer.js CHANGED
@@ -6,17 +6,17 @@ import {
6
6
  copyFileSync,
7
7
  cpSync as cpSync2,
8
8
  existsSync as existsSync10,
9
- mkdirSync as mkdirSync4,
9
+ mkdirSync as mkdirSync5,
10
10
  mkdtempSync,
11
- readFileSync as readFileSync12,
11
+ readFileSync as readFileSync14,
12
12
  readSync as readSync4,
13
13
  realpathSync as realpathSync3,
14
14
  rmSync as rmSync2,
15
15
  writeFileSync as writeFileSync3
16
16
  } from "fs";
17
- import { homedir as homedir10, tmpdir as tmpdir4 } from "os";
17
+ import { homedir as homedir10, tmpdir as tmpdir5 } from "os";
18
18
  import { isatty } from "tty";
19
- import { dirname as dirname10, join as join16 } from "path";
19
+ import { dirname as dirname11, join as join17 } from "path";
20
20
  import { fileURLToPath as fileURLToPath6, pathToFileURL } from "url";
21
21
 
22
22
  // node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -1348,7 +1348,7 @@ function applyEdits(text, edits) {
1348
1348
  }
1349
1349
 
1350
1350
  // src/core/hook.ts
1351
- import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
1351
+ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
1352
1352
 
1353
1353
  // src/core/bank.ts
1354
1354
  import { existsSync } from "fs";
@@ -1417,6 +1417,9 @@ import { spawn as realSpawn } from "child_process";
1417
1417
  import { dirname as dirname4, join as join4 } from "path";
1418
1418
  import { fileURLToPath } from "url";
1419
1419
 
1420
+ // src/core/missions.ts
1421
+ import { createHash } from "crypto";
1422
+
1420
1423
  // src/core/util.ts
1421
1424
  import { accessSync, constants } from "fs";
1422
1425
  import { delimiter, join as join5 } from "path";
@@ -1448,18 +1451,63 @@ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmS
1448
1451
  import { tmpdir as tmpdir2 } from "os";
1449
1452
  import { dirname as dirname5, join as join7 } from "path";
1450
1453
 
1454
+ // src/core/turn-journal.ts
1455
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
1456
+ import { tmpdir as tmpdir3 } from "os";
1457
+ import { dirname as dirname6, join as join8 } from "path";
1458
+
1459
+ // src/core/transcript-util.ts
1460
+ 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;
1461
+ function stripInjectedMemory(s) {
1462
+ return s.replace(MEMORY_TAG_RE, "");
1463
+ }
1464
+ var TARGET_KEYS = [
1465
+ "file_path",
1466
+ "path",
1467
+ "notebook_path",
1468
+ "command",
1469
+ "pattern",
1470
+ "query",
1471
+ "url",
1472
+ "name",
1473
+ "id"
1474
+ ];
1475
+ var ACTION_TARGET_CAP = 100;
1476
+ function actionLine(tool, input) {
1477
+ let target = "";
1478
+ if (input && typeof input === "object") {
1479
+ const rec = input;
1480
+ for (const k of TARGET_KEYS) {
1481
+ const v = rec[k];
1482
+ if (typeof v === "string" && v.trim()) {
1483
+ target = v.trim().split("\n")[0];
1484
+ break;
1485
+ }
1486
+ }
1487
+ } else if (typeof input === "string") {
1488
+ target = input.trim().split("\n")[0];
1489
+ }
1490
+ if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1491
+ return target ? `${tool} ${target}` : tool;
1492
+ }
1493
+
1494
+ // src/core/turn-journal.ts
1495
+ var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
1496
+
1451
1497
  // src/core/retain-hook.ts
1452
- import { readFileSync as readFileSync5 } from "fs";
1498
+ import { readFileSync as readFileSync6 } from "fs";
1453
1499
 
1454
1500
  // src/core/retain-cursor.ts
1455
- import { createHash } from "crypto";
1501
+ import { createHash as createHash2 } from "crypto";
1502
+ var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
1503
+ var PENDING_MAX_BYTES = 256 * 1024;
1456
1504
 
1457
1505
  // src/core/uuid.ts
1458
- import { createHash as createHash2 } from "crypto";
1506
+ import { createHash as createHash3 } from "crypto";
1459
1507
 
1460
1508
  // src/core/daemon.ts
1461
1509
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1462
- import { dirname as dirname6, join as join8 } from "path";
1510
+ import { dirname as dirname7, join as join9 } from "path";
1463
1511
  import { fileURLToPath as fileURLToPath2 } from "url";
1464
1512
  function hasRustToolchain() {
1465
1513
  if (process.platform !== "darwin") return true;
@@ -1527,7 +1575,7 @@ function onPath(bin) {
1527
1575
  import { basename as basename2 } from "path";
1528
1576
 
1529
1577
  // src/core/jsonl.ts
1530
- import { closeSync, openSync, readSync, statSync } from "fs";
1578
+ import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1531
1579
  import { StringDecoder } from "string_decoder";
1532
1580
  var CHUNK_BYTES = 64 * 1024;
1533
1581
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1535,7 +1583,7 @@ function readJsonlTail(path, opts) {
1535
1583
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1536
1584
  let size;
1537
1585
  try {
1538
- size = statSync(path).size;
1586
+ size = statSync2(path).size;
1539
1587
  } catch {
1540
1588
  return { lines: emptyLines(), skippedBytes: 0 };
1541
1589
  }
@@ -1587,41 +1635,6 @@ function* streamLines(path, start) {
1587
1635
  }
1588
1636
  }
1589
1637
 
1590
- // src/core/transcript-util.ts
1591
- 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;
1592
- function stripInjectedMemory(s) {
1593
- return s.replace(MEMORY_TAG_RE, "");
1594
- }
1595
- var TARGET_KEYS = [
1596
- "file_path",
1597
- "path",
1598
- "notebook_path",
1599
- "command",
1600
- "pattern",
1601
- "query",
1602
- "url",
1603
- "name",
1604
- "id"
1605
- ];
1606
- var ACTION_TARGET_CAP = 100;
1607
- function actionLine(tool, input) {
1608
- let target = "";
1609
- if (input && typeof input === "object") {
1610
- const rec = input;
1611
- for (const k of TARGET_KEYS) {
1612
- const v = rec[k];
1613
- if (typeof v === "string" && v.trim()) {
1614
- target = v.trim().split("\n")[0];
1615
- break;
1616
- }
1617
- }
1618
- } else if (typeof input === "string") {
1619
- target = input.trim().split("\n")[0];
1620
- }
1621
- if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1622
- return target ? `${tool} ${target}` : tool;
1623
- }
1624
-
1625
1638
  // src/core/transcript.ts
1626
1639
  function renderLine(content, type) {
1627
1640
  if (typeof content === "string") {
@@ -1674,7 +1687,7 @@ function readClaudeTranscript(path) {
1674
1687
  }
1675
1688
 
1676
1689
  // src/core/session-start.ts
1677
- import { readFileSync as readFileSync8 } from "fs";
1690
+ import { readFileSync as readFileSync9 } from "fs";
1678
1691
 
1679
1692
  // src/core/git.ts
1680
1693
  import { execFileSync as execFileSync2 } from "child_process";
@@ -1687,29 +1700,29 @@ import { execFileSync as execFileSync3 } from "child_process";
1687
1700
  import { spawn as realSpawn3 } from "child_process";
1688
1701
  import { existsSync as existsSync3 } from "fs";
1689
1702
  import { homedir as homedir3 } from "os";
1690
- import { dirname as dirname7, join as join9 } from "path";
1703
+ import { dirname as dirname8, join as join10 } from "path";
1691
1704
  import { fileURLToPath as fileURLToPath3 } from "url";
1692
1705
 
1693
1706
  // src/core/auto-update.ts
1694
1707
  import { spawn as realSpawn4 } from "child_process";
1695
1708
  import {
1696
1709
  existsSync as existsSync4,
1697
- mkdirSync as mkdirSync3,
1698
- readFileSync as readFileSync6,
1710
+ mkdirSync as mkdirSync4,
1711
+ readFileSync as readFileSync7,
1699
1712
  realpathSync as realpathSync2,
1700
1713
  unlinkSync,
1701
1714
  writeFileSync as writeFileSync2
1702
1715
  } from "fs";
1703
- import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
1704
- import { dirname as dirname8, join as join10 } from "path";
1716
+ import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
1717
+ import { dirname as dirname9, join as join11 } from "path";
1705
1718
  import { fileURLToPath as fileURLToPath4 } from "url";
1706
1719
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
1707
1720
  var LOCK_STALE_MS = 10 * 60 * 1e3;
1708
1721
 
1709
1722
  // src/core/skill-sync.ts
1710
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
1723
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
1711
1724
  import { homedir as homedir5 } from "os";
1712
- import { dirname as dirname9, join as join11 } from "path";
1725
+ import { dirname as dirname10, join as join12 } from "path";
1713
1726
  import { fileURLToPath as fileURLToPath5 } from "url";
1714
1727
 
1715
1728
  // src/core/skill-dirs.ts
@@ -1725,6 +1738,13 @@ var SKILL_DIRS = {
1725
1738
  "cline-cli": [".cline", "data", "settings", "skills"],
1726
1739
  "qwen-code": [".qwen", "skills"],
1727
1740
  // Qwen's user-level skills root (Storage.getUserSkillsDirs)
1741
+ "factory-droid": [".factory", "skills"],
1742
+ // Droid's user-level skills root
1743
+ // ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
1744
+ // shared agentskills `~/.agents/skills`. Write its OWN, for the same reason the pi family does —
1745
+ // skill removal is by fixed directory name, so installing into the shared root would make
1746
+ // `uninstall zcode` take Codex's and dsh's copy with it.
1747
+ zcode: [".zcode", "skills"],
1728
1748
  // The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
1729
1749
  // by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
1730
1750
  // and dsh's copy with it.
@@ -1862,19 +1882,19 @@ function readCopilotTranscript(path) {
1862
1882
  }
1863
1883
 
1864
1884
  // src/core/transcript-grok.ts
1865
- import { existsSync as existsSync6, readFileSync as readFileSync9, readdirSync } from "fs";
1885
+ import { existsSync as existsSync6, readFileSync as readFileSync10, readdirSync } from "fs";
1866
1886
  import { homedir as homedir6 } from "os";
1867
- import { join as join12 } from "path";
1887
+ import { join as join13 } from "path";
1868
1888
  var CHAT_HISTORY = "chat_history.jsonl";
1869
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join12(homedir6(), ".grok")) {
1870
- const sessionsDir = join12(grokHome, "sessions");
1871
- const direct = join12(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1889
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join13(homedir6(), ".grok")) {
1890
+ const sessionsDir = join13(grokHome, "sessions");
1891
+ const direct = join13(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1872
1892
  if (existsSync6(direct)) return direct;
1873
1893
  try {
1874
1894
  for (const candidate of readdirSync(sessionsDir)) {
1875
- const directory = join12(sessionsDir, candidate);
1876
- if (readFileSync9(join12(directory, ".cwd"), "utf8").trim() === cwd) {
1877
- return join12(directory, sessionId, CHAT_HISTORY);
1895
+ const directory = join13(sessionsDir, candidate);
1896
+ if (readFileSync10(join13(directory, ".cwd"), "utf8").trim() === cwd) {
1897
+ return join13(directory, sessionId, CHAT_HISTORY);
1878
1898
  }
1879
1899
  }
1880
1900
  } catch {
@@ -1912,9 +1932,9 @@ function readGrokTranscript(path) {
1912
1932
  import { existsSync as existsSync7 } from "fs";
1913
1933
  import { createRequire } from "module";
1914
1934
  import { homedir as homedir7 } from "os";
1915
- import { join as join13 } from "path";
1935
+ import { join as join14 } from "path";
1916
1936
  function devinSessionDb(home = homedir7()) {
1917
- return join13(home, ".local", "share", "devin", "cli", "sessions.db");
1937
+ return join14(home, ".local", "share", "devin", "cli", "sessions.db");
1918
1938
  }
1919
1939
  function parseDevinMessages(nodes) {
1920
1940
  const messages = /* @__PURE__ */ new Map();
@@ -2179,6 +2199,95 @@ function collectQwenTurns(path, turns) {
2179
2199
  }
2180
2200
  }
2181
2201
 
2202
+ // src/core/transcript-droid.ts
2203
+ function renderContent(content, role) {
2204
+ if (!Array.isArray(content)) return [];
2205
+ const texts = [];
2206
+ const actions = [];
2207
+ for (const block of content) {
2208
+ if (!block || typeof block !== "object") continue;
2209
+ const b = block;
2210
+ if (b.type === "text" && typeof b.text === "string") {
2211
+ const text = stripInjectedMemory(b.text).trim();
2212
+ if (text) texts.push(text);
2213
+ } else if (b.type === "tool_use" && typeof b.name === "string") {
2214
+ actions.push({ role: "action", content: actionLine(b.name, b.input) });
2215
+ }
2216
+ }
2217
+ const out = [];
2218
+ const joined = texts.join("\n").trim();
2219
+ if (joined) out.push({ role, content: joined });
2220
+ out.push(...actions);
2221
+ return out;
2222
+ }
2223
+ function readDroidTranscript(path) {
2224
+ const turns = [];
2225
+ for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
2226
+ if (!rawLine.trim()) continue;
2227
+ let parsed;
2228
+ try {
2229
+ parsed = JSON.parse(rawLine);
2230
+ } catch {
2231
+ continue;
2232
+ }
2233
+ if (!parsed || typeof parsed !== "object") continue;
2234
+ const line = parsed;
2235
+ if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
2236
+ const message = line.message;
2237
+ const role = message.role;
2238
+ if (role !== "user" && role !== "assistant") continue;
2239
+ if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
2240
+ const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
2241
+ turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
2242
+ }
2243
+ return turns;
2244
+ }
2245
+
2246
+ // src/core/transcript-zcode.ts
2247
+ import { readFileSync as readFileSync11 } from "fs";
2248
+ function messageText2(content) {
2249
+ if (typeof content === "string") return content.trim();
2250
+ if (!Array.isArray(content)) return "";
2251
+ return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
2252
+ }
2253
+ function readZcodeTranscript(path) {
2254
+ if (!path) return [];
2255
+ let body;
2256
+ try {
2257
+ body = readFileSync11(path, "utf8");
2258
+ } catch {
2259
+ return [];
2260
+ }
2261
+ const turns = [];
2262
+ for (const line of body.split("\n")) {
2263
+ const trimmed = line.trim();
2264
+ if (!trimmed) continue;
2265
+ let parsed;
2266
+ try {
2267
+ parsed = JSON.parse(trimmed);
2268
+ } catch {
2269
+ continue;
2270
+ }
2271
+ if (typeof parsed !== "object" || parsed === null) continue;
2272
+ const record = parsed;
2273
+ const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
2274
+ const role = typeof message?.role === "string" ? message.role : record.type;
2275
+ if (role !== "user" && role !== "assistant") continue;
2276
+ const content = stripInjectedMemory(messageText2(message?.content)).trim();
2277
+ if (!content) continue;
2278
+ turns.push({
2279
+ role,
2280
+ content,
2281
+ ...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
2282
+ });
2283
+ }
2284
+ return turns;
2285
+ }
2286
+ function zcodeAssistantText(path) {
2287
+ if (!path) return "";
2288
+ return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
2289
+ }
2290
+
2182
2291
  // src/harness/hook-lifecycle.ts
2183
2292
  var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
2184
2293
  var claudePrompt = {
@@ -2206,6 +2315,10 @@ var dcodePrompt = {
2206
2315
  ...claudePrompt,
2207
2316
  harness: "dcode"
2208
2317
  };
2318
+ var droidPrompt = {
2319
+ ...claudePrompt,
2320
+ harness: "factory-droid"
2321
+ };
2209
2322
  var qwenPrompt = {
2210
2323
  ...claudePrompt,
2211
2324
  harness: "qwen-code",
@@ -2215,6 +2328,7 @@ var qwenPrompt = {
2215
2328
  sessionId: ev.session_id
2216
2329
  })
2217
2330
  };
2331
+ var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
2218
2332
  var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
2219
2333
  var antigravityPrompt = {
2220
2334
  harness: "antigravity-cli",
@@ -2532,6 +2646,81 @@ var HOOK_HARNESSES = {
2532
2646
  }),
2533
2647
  readTranscript: readQwenTranscript
2534
2648
  }
2649
+ },
2650
+ "factory-droid": {
2651
+ configStyle: "nested",
2652
+ install: {
2653
+ sessionStart: { event: "SessionStart", entry: "droid-sessionstart-hook.js", timeout: 30 },
2654
+ prompt: { event: "UserPromptSubmit", entry: "droid-hook.js", timeout: 30 },
2655
+ stop: { event: "Stop", entry: "droid-stop-hook.js", timeout: 60 }
2656
+ },
2657
+ // Droid emits Notification(idle_prompt), not Stop, after user cancellation. Reusing the
2658
+ // idempotent retain entry point captures that final partial turn; its event gate ignores every
2659
+ // other notification type before config or daemon work begins.
2660
+ additionalHooks: [{ event: "Notification", entry: "droid-stop-hook.js", timeout: 60 }],
2661
+ sessionStart: standardSessionStart("factory-droid"),
2662
+ prompt: droidPrompt,
2663
+ retain: {
2664
+ hostTimeoutSec: 60,
2665
+ harness: "factory-droid",
2666
+ accept: (ev) => ev.hook_event_name === "Stop" || ev.hook_event_name === "Notification" && ev.notification_type === "idle_prompt",
2667
+ parse: (ev) => ({
2668
+ sessionId: ev.session_id,
2669
+ transcriptPath: ev.transcript_path,
2670
+ cwd: ev.cwd
2671
+ }),
2672
+ readTranscript: readDroidTranscript
2673
+ }
2674
+ },
2675
+ /**
2676
+ * ZCode (Z.ai's GLM coding agent) embeds the Claude Code agent runtime, so its hook PROTOCOL is
2677
+ * Claude's — `prompt`/`cwd` in, `hookSpecificOutput.additionalContext` + `systemMessage` out —
2678
+ * with `sessionId` accepted alongside `session_id`, which its Stop payload sends instead.
2679
+ *
2680
+ * What is not Claude's is the TRANSCRIPT, and that is the whole of the difference here. ZCode
2681
+ * keeps no durable session file: `Stop` carries the reply in `responseText` plus a temp,
2682
+ * assistant-only transcript it deletes as soon as the hook returns, and no user prompt at all.
2683
+ * So this is the one harness that retains from the plugin's own journal (core/turn-journal.ts) —
2684
+ * the prompt hook appends the user turn, `journal.assistantText` closes it with the reply — and
2685
+ * everything downstream (cursor, append, stamping) sees the same full conversation as any host
2686
+ * transcript.
2687
+ */
2688
+ zcode: {
2689
+ configStyle: "process",
2690
+ // ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
2691
+ // prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
2692
+ timeoutUnit: "milliseconds",
2693
+ install: {
2694
+ sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
2695
+ prompt: { event: "UserPromptSubmit", entry: "zcode-hook.js", timeout: 3e4 },
2696
+ stop: { event: "Stop", entry: "zcode-stop-hook.js", timeout: 6e4 }
2697
+ },
2698
+ sessionStart: {
2699
+ ...standardSessionStart("zcode"),
2700
+ parse: (ev) => ({ cwd: ev.cwd, sessionId: zcodeSessionId(ev) })
2701
+ },
2702
+ prompt: {
2703
+ ...claudePrompt,
2704
+ harness: "zcode",
2705
+ journalPrompt: true,
2706
+ parse: (ev) => ({
2707
+ prompt: ev.prompt ?? ev.user_prompt,
2708
+ cwd: ev.cwd,
2709
+ sessionId: zcodeSessionId(ev)
2710
+ })
2711
+ },
2712
+ retain: {
2713
+ hostTimeoutSec: 60,
2714
+ harness: "zcode",
2715
+ // No transcriptPath: the journal supplies it (see `journal` below).
2716
+ parse: (ev) => ({ sessionId: zcodeSessionId(ev), cwd: ev.cwd }),
2717
+ journal: {
2718
+ // `responseText` is the full reply and is what ZCode sends in practice. The ephemeral
2719
+ // transcript is the fallback when it is absent, and `responsePreview` — which is
2720
+ // TRUNCATED — is the last resort, preferred only over losing the turn entirely.
2721
+ assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
2722
+ }
2723
+ }
2535
2724
  }
2536
2725
  };
2537
2726
 
@@ -2542,13 +2731,13 @@ import {
2542
2731
  existsSync as existsSync8,
2543
2732
  openSync as openSync2,
2544
2733
  readdirSync as readdirSync2,
2545
- readFileSync as readFileSync10,
2734
+ readFileSync as readFileSync12,
2546
2735
  readSync as readSync2,
2547
- statSync as statSync2
2736
+ statSync as statSync3
2548
2737
  } from "fs";
2549
- import { createHash as createHash3 } from "crypto";
2738
+ import { createHash as createHash4 } from "crypto";
2550
2739
  import { homedir as homedir8 } from "os";
2551
- import { join as join14 } from "path";
2740
+ import { join as join15 } from "path";
2552
2741
  import * as zlib2 from "zlib";
2553
2742
 
2554
2743
  // src/core/transcript-dsh.ts
@@ -2693,7 +2882,7 @@ function zstdDecompressFrames(buffer) {
2693
2882
 
2694
2883
  // src/core/history.ts
2695
2884
  function claudeProjectDir(repoDir, home = homedir8()) {
2696
- return join14(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
2885
+ return join15(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
2697
2886
  }
2698
2887
  function piSessionDir(repoDir) {
2699
2888
  return `--${repoDir.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
@@ -2703,7 +2892,7 @@ function withinRepo(dir, repoDir) {
2703
2892
  }
2704
2893
  function claudeSessionCwd(file) {
2705
2894
  try {
2706
- for (const line of readFileSync10(file, "utf8").split("\n", 400)) {
2895
+ for (const line of readFileSync12(file, "utf8").split("\n", 400)) {
2707
2896
  if (!line.includes('"cwd"')) continue;
2708
2897
  const cwd = JSON.parse(line).cwd;
2709
2898
  if (cwd) return cwd;
@@ -2745,13 +2934,13 @@ function listDir(dir) {
2745
2934
  }
2746
2935
  }
2747
2936
  function jsonlFiles(dir) {
2748
- return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join14(dir, f));
2937
+ return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join15(dir, f));
2749
2938
  }
2750
2939
  function claudeHistory(repoDir, home) {
2751
- const root = join14(home, ".claude", "projects");
2940
+ const root = join15(home, ".claude", "projects");
2752
2941
  const exact = claudeProjectDir(repoDir, home);
2753
2942
  const prefix = exact + "-";
2754
- const dirs = listDir(root).map((d) => join14(root, d)).filter((d) => d === exact || d.startsWith(prefix));
2943
+ const dirs = listDir(root).map((d) => join15(root, d)).filter((d) => d === exact || d.startsWith(prefix));
2755
2944
  const sessions = [];
2756
2945
  let unattributed = 0;
2757
2946
  for (const file of dirs.flatMap(jsonlFiles)) {
@@ -2771,13 +2960,13 @@ function claudeHistory(repoDir, home) {
2771
2960
  return { supported: true, sessions, unattributed };
2772
2961
  }
2773
2962
  function codexHistory(repoDir, home) {
2774
- const root = join14(home, ".codex", "sessions");
2963
+ const root = join15(home, ".codex", "sessions");
2775
2964
  if (!existsSync8(root)) return { supported: true, sessions: [] };
2776
2965
  const files = [];
2777
2966
  const walk = (dir) => {
2778
2967
  for (const entry of readdirSync2(dir)) {
2779
- const p = join14(dir, entry);
2780
- if (statSync2(p).isDirectory()) walk(p);
2968
+ const p = join15(dir, entry);
2969
+ if (statSync3(p).isDirectory()) walk(p);
2781
2970
  else if (entry.endsWith(".jsonl")) files.push(p);
2782
2971
  }
2783
2972
  };
@@ -2802,17 +2991,17 @@ function codexHistory(repoDir, home) {
2802
2991
  }
2803
2992
  var DCODE_THREADS_SCHEMA_VERSION = 1;
2804
2993
  function dcodeTranscriptPath(root, threadId) {
2805
- const digest = createHash3("sha256").update(threadId, "utf8").digest("hex");
2994
+ const digest = createHash4("sha256").update(threadId, "utf8").digest("hex");
2806
2995
  const suffix = `--${digest}.jsonl`;
2807
2996
  try {
2808
2997
  const match = readdirSync2(root).find((entry) => entry.endsWith(suffix));
2809
- return match ? join14(root, match) : void 0;
2998
+ return match ? join15(root, match) : void 0;
2810
2999
  } catch {
2811
3000
  return void 0;
2812
3001
  }
2813
3002
  }
2814
3003
  function dcodeHistory(repoDir, home, runCli) {
2815
- const root = join14(process.env.DEEPAGENTS_HOME || join14(home, ".deepagents"), "transcripts");
3004
+ const root = join15(process.env.DEEPAGENTS_HOME || join15(home, ".deepagents"), "transcripts");
2816
3005
  if (!existsSync8(root)) return { supported: true, sessions: [] };
2817
3006
  let listed;
2818
3007
  try {
@@ -2853,7 +3042,7 @@ function dcodeHistory(repoDir, home, runCli) {
2853
3042
  return { supported: true, sessions, ...unattributed ? { unattributed } : {} };
2854
3043
  }
2855
3044
  function dshHistory(repoDir, home) {
2856
- const root = process.env.DSH_HOME ? join14(process.env.DSH_HOME, "sessions") : join14(home, ".dsh", "sessions");
3045
+ const root = process.env.DSH_HOME ? join15(process.env.DSH_HOME, "sessions") : join15(home, ".dsh", "sessions");
2857
3046
  if (!existsSync8(root)) return { supported: true, sessions: [] };
2858
3047
  if (typeof zlib2.zstdDecompressSync !== "function") {
2859
3048
  return {
@@ -2864,15 +3053,15 @@ function dshHistory(repoDir, home) {
2864
3053
  }
2865
3054
  const sessions = [];
2866
3055
  let unattributed = 0;
2867
- for (const dir of readdirSync2(root).map((project) => join14(root, project))) {
3056
+ for (const dir of readdirSync2(root).map((project) => join15(root, project))) {
2868
3057
  let sessionDirs;
2869
3058
  try {
2870
- sessionDirs = readdirSync2(dir).map((id) => join14(dir, id));
3059
+ sessionDirs = readdirSync2(dir).map((id) => join15(dir, id));
2871
3060
  } catch {
2872
3061
  continue;
2873
3062
  }
2874
3063
  for (const sessionDir of sessionDirs) {
2875
- const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join14(sessionDir, name)).find((candidate) => existsSync8(candidate));
3064
+ const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join15(sessionDir, name)).find((candidate) => existsSync8(candidate));
2876
3065
  if (!file) continue;
2877
3066
  try {
2878
3067
  const lines = readDshLog(file);
@@ -2898,7 +3087,7 @@ function dshHistory(repoDir, home) {
2898
3087
  return { supported: true, sessions, unattributed };
2899
3088
  }
2900
3089
  function readDshLog(file) {
2901
- const bytes = readFileSync10(file);
3090
+ const bytes = readFileSync12(file);
2902
3091
  const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
2903
3092
  return text.split("\n").filter((line) => line.trim());
2904
3093
  }
@@ -2924,18 +3113,18 @@ function piFamilySessions(files, repoDir) {
2924
3113
  return { supported: true, sessions, unattributed };
2925
3114
  }
2926
3115
  function piHistory(repoDir, home) {
2927
- const root = join14(home, ".pi", "agent", "sessions");
3116
+ const root = join15(home, ".pi", "agent", "sessions");
2928
3117
  if (!existsSync8(root)) return { supported: true, sessions: [] };
2929
3118
  const exact = piSessionDir(repoDir);
2930
3119
  const nested = `${exact.slice(0, -2)}-`;
2931
3120
  const files = [];
2932
3121
  for (const dir of listDir(root).filter((d) => d === exact || d.startsWith(nested))) {
2933
- files.push(...jsonlFiles(join14(root, dir)));
3122
+ files.push(...jsonlFiles(join15(root, dir)));
2934
3123
  }
2935
3124
  return piFamilySessions(files, repoDir);
2936
3125
  }
2937
3126
  function primeAgentHistory(repoDir, home) {
2938
- const root = join14(home, ".prime", "agent", "sessions");
3127
+ const root = join15(home, ".prime", "agent", "sessions");
2939
3128
  if (!existsSync8(root)) return { supported: true, sessions: [] };
2940
3129
  return piFamilySessions(jsonlFiles(root), repoDir);
2941
3130
  }
@@ -2967,21 +3156,27 @@ function importLocalHistory(harness, repoDir, home = homedir8(), runDcodeCli) {
2967
3156
  case "copilot-cli":
2968
3157
  case "devin-cli":
2969
3158
  return { supported: false, reason: `${harness} ${SQLITE_HISTORY}`, sessions: [] };
3159
+ case "zcode":
3160
+ return {
3161
+ supported: false,
3162
+ reason: "ZCode keeps no session transcripts on disk to import",
3163
+ sessions: []
3164
+ };
2970
3165
  default:
2971
3166
  return { supported: false, reason: `no local history reader for ${harness}`, sessions: [] };
2972
3167
  }
2973
3168
  }
2974
3169
 
2975
3170
  // src/core/legacy.ts
2976
- import { existsSync as existsSync9, readFileSync as readFileSync11 } from "fs";
3171
+ import { existsSync as existsSync9, readFileSync as readFileSync13 } from "fs";
2977
3172
  import { homedir as homedir9 } from "os";
2978
- import { join as join15 } from "path";
3173
+ import { join as join16 } from "path";
2979
3174
  var LEGACY_CONFIG_FILES = {
2980
3175
  "claude-code": "claude-code.json",
2981
3176
  codex: "codex.json"
2982
3177
  };
2983
3178
  function legacyConfigPath(harness, home = homedir9()) {
2984
- return join15(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
3179
+ return join16(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
2985
3180
  }
2986
3181
  var CLOUD_URL = "https://api.hindsight.vectorize.io";
2987
3182
  function readLegacyEndpoint(home = homedir9(), prefer = []) {
@@ -2999,7 +3194,7 @@ function readOne(harness, home) {
2999
3194
  if (!existsSync9(source)) return void 0;
3000
3195
  let raw;
3001
3196
  try {
3002
- raw = JSON.parse(readFileSync11(source, "utf8"));
3197
+ raw = JSON.parse(readFileSync13(source, "utf8"));
3003
3198
  } catch {
3004
3199
  return void 0;
3005
3200
  }
@@ -3229,9 +3424,11 @@ function createInstallerUi(o) {
3229
3424
 
3230
3425
  // src/installer.ts
3231
3426
  var MARKER = "coding-agents";
3427
+ var ZCODE_MAX_OUTPUT_BYTES = 32768;
3428
+ var zcodeConfigPath = (c) => join17(c.home, ".zcode", "cli", "config.json");
3232
3429
  function readJson(path) {
3233
3430
  try {
3234
- return JSON.parse(readFileSync12(path, "utf8"));
3431
+ return JSON.parse(readFileSync14(path, "utf8"));
3235
3432
  } catch {
3236
3433
  return {};
3237
3434
  }
@@ -3246,7 +3443,7 @@ function parseJsonc(text) {
3246
3443
  }
3247
3444
  }
3248
3445
  function writeJson(path, value) {
3249
- mkdirSync4(dirname10(path), { recursive: true });
3446
+ mkdirSync5(dirname11(path), { recursive: true });
3250
3447
  backupOnce(path);
3251
3448
  writeFileSync3(path, JSON.stringify(value, null, 2) + "\n");
3252
3449
  }
@@ -3256,7 +3453,7 @@ function backupOnce(path) {
3256
3453
  }
3257
3454
  }
3258
3455
  function writeJsonc(path, key, value) {
3259
- const text = existsSync10(path) ? readFileSync12(path, "utf8") : "";
3456
+ const text = existsSync10(path) ? readFileSync14(path, "utf8") : "";
3260
3457
  const edits = modify(text, [key], value, {
3261
3458
  formattingOptions: {
3262
3459
  tabSize: 2,
@@ -3267,7 +3464,7 @@ function writeJsonc(path, key, value) {
3267
3464
  }
3268
3465
  });
3269
3466
  const next = applyEdits(text, edits);
3270
- mkdirSync4(dirname10(path), { recursive: true });
3467
+ mkdirSync5(dirname11(path), { recursive: true });
3271
3468
  backupOnce(path);
3272
3469
  writeFileSync3(path, next.endsWith("\n") ? next : `${next}
3273
3470
  `);
@@ -3284,21 +3481,33 @@ function setOrDelete(obj, key, arr) {
3284
3481
  else delete obj[key];
3285
3482
  }
3286
3483
  var cmdHook = (dist, file, timeout) => ({
3287
- hooks: [{ type: "command", command: `node "${join16(dist, file)}"`, timeout }]
3484
+ hooks: [{ type: "command", command: `node "${join17(dist, file)}"`, timeout }]
3485
+ });
3486
+ var processHook = (dist, file, timeoutMs) => ({
3487
+ hooks: [{ type: "process", command: "node", args: [join17(dist, file)], timeoutMs }]
3288
3488
  });
3289
3489
  var mcpServerEntry = (dist, harness) => ({
3290
3490
  command: "node",
3291
- args: [join16(dist, "mcp-server.js")],
3491
+ args: [join17(dist, "mcp-server.js")],
3292
3492
  env: { HINDSIGHT_MCP_HARNESS: harness }
3293
3493
  });
3494
+ function isOurMcpEntry(entry) {
3495
+ if (!entry || typeof entry !== "object") return false;
3496
+ const candidate = entry;
3497
+ if (candidate.command !== "node" || !Array.isArray(candidate.args)) return false;
3498
+ const script = candidate.args[0];
3499
+ if (typeof script !== "string") return false;
3500
+ const parts = script.replaceAll("\\", "/").split("/").filter(Boolean);
3501
+ return parts.at(-1) === "mcp-server.js" && parts.at(-2) === "dist" && (parts.at(-3) === "coding-agents" || parts.at(-3) === "hindsight-coding-agents");
3502
+ }
3294
3503
  function mergeHarnessHooks(hooks, harness, dist) {
3295
3504
  const spec = HOOK_HARNESSES[harness];
3296
3505
  const installedEvents = /* @__PURE__ */ new Set();
3297
- for (const hook of Object.values(spec.install)) {
3506
+ for (const hook of [...Object.values(spec.install), ...spec.additionalHooks ?? []]) {
3298
3507
  if (installedEvents.has(hook.event)) continue;
3299
3508
  installedEvents.add(hook.event);
3300
- const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
3301
- command: `node "${join16(dist, hook.entry)}"`,
3509
+ const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : spec.configStyle === "process" ? processHook(dist, hook.entry, hook.timeout) : {
3510
+ command: `node "${join17(dist, hook.entry)}"`,
3302
3511
  ...hook.timeout ? { timeout: hook.timeout } : {}
3303
3512
  };
3304
3513
  hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
@@ -3306,7 +3515,8 @@ function mergeHarnessHooks(hooks, harness, dist) {
3306
3515
  }
3307
3516
  function stripHarnessHooks(hooks, harness) {
3308
3517
  const strippedEvents = /* @__PURE__ */ new Set();
3309
- for (const hook of Object.values(HOOK_HARNESSES[harness].install)) {
3518
+ const spec = HOOK_HARNESSES[harness];
3519
+ for (const hook of [...Object.values(spec.install), ...spec.additionalHooks ?? []]) {
3310
3520
  if (strippedEvents.has(hook.event)) continue;
3311
3521
  strippedEvents.add(hook.event);
3312
3522
  setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
@@ -3315,19 +3525,19 @@ function stripHarnessHooks(hooks, harness) {
3315
3525
  function skillsBaseFor(c, harness) {
3316
3526
  const parts = SKILL_DIRS[harness];
3317
3527
  if (!parts) throw new Error(`${harness} installs a skill but names no directory in SKILL_DIRS`);
3318
- return join16(c.home, ...parts);
3528
+ return join17(c.home, ...parts);
3319
3529
  }
3320
3530
  function installSkill(c, harness) {
3321
- const src = join16(c.pkgRoot, "skill");
3322
- if (!existsSync10(join16(src, "SKILL.md"))) return;
3531
+ const src = join17(c.pkgRoot, "skill");
3532
+ if (!existsSync10(join17(src, "SKILL.md"))) return;
3323
3533
  const skillsBase = skillsBaseFor(c, harness);
3324
- const dst = join16(skillsBase, "hindsight-coding-agent");
3325
- mkdirSync4(skillsBase, { recursive: true });
3534
+ const dst = join17(skillsBase, "hindsight-coding-agent");
3535
+ mkdirSync5(skillsBase, { recursive: true });
3326
3536
  cpSync2(src, dst, { recursive: true });
3327
3537
  c.log?.(`${harness}: skill installed at ${dst}`);
3328
3538
  }
3329
3539
  function uninstallSkill(c, harness) {
3330
- rmSync2(join16(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
3540
+ rmSync2(join17(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
3331
3541
  recursive: true,
3332
3542
  force: true
3333
3543
  });
@@ -3350,9 +3560,9 @@ function runClinePlugin(args) {
3350
3560
  }
3351
3561
  var OPENCODE_CONFIG_CANDIDATES = ["opencode.jsonc", "opencode.json"];
3352
3562
  function opencodeConfigPath(c) {
3353
- const dir = join16(c.home, ".config", "opencode");
3354
- const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
3355
- return existing ?? join16(dir, "opencode.json");
3563
+ const dir = join17(c.home, ".config", "opencode");
3564
+ const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join17(dir, f)).find((p) => existsSync10(p));
3565
+ return existing ?? join17(dir, "opencode.json");
3356
3566
  }
3357
3567
  function runDcodePlugin(args) {
3358
3568
  try {
@@ -3366,7 +3576,7 @@ function registerOpencodePlugin(c, name) {
3366
3576
  const path = opencodeConfigPath(c);
3367
3577
  let cfg = {};
3368
3578
  if (existsSync10(path)) {
3369
- const parsed = parseJsonc(readFileSync12(path, "utf8"));
3579
+ const parsed = parseJsonc(readFileSync14(path, "utf8"));
3370
3580
  if (!parsed) {
3371
3581
  c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
3372
3582
  return;
@@ -3380,7 +3590,7 @@ function registerOpencodePlugin(c, name) {
3380
3590
  function unregisterOpencodePlugin(c, name) {
3381
3591
  const path = opencodeConfigPath(c);
3382
3592
  if (!existsSync10(path)) return;
3383
- const cfg = parseJsonc(readFileSync12(path, "utf8"));
3593
+ const cfg = parseJsonc(readFileSync14(path, "utf8"));
3384
3594
  if (!cfg || !Array.isArray(cfg.plugin)) return;
3385
3595
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
3386
3596
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -3388,7 +3598,7 @@ function unregisterOpencodePlugin(c, name) {
3388
3598
  }
3389
3599
  var opencode = {
3390
3600
  name: "opencode",
3391
- detect: (c) => onPath2("opencode") || existsSync10(join16(c.home, ".config", "opencode")),
3601
+ detect: (c) => onPath2("opencode") || existsSync10(join17(c.home, ".config", "opencode")),
3392
3602
  install: (c) => registerOpencodePlugin(c, "opencode"),
3393
3603
  uninstall: (c) => unregisterOpencodePlugin(c, "opencode")
3394
3604
  };
@@ -3399,16 +3609,16 @@ var opencode2 = {
3399
3609
  uninstall: (c) => unregisterOpencodePlugin(c, "opencode2")
3400
3610
  };
3401
3611
  function piFamilyInstaller(harness, configDir) {
3402
- const settings = (c) => join16(c.home, ...configDir, "settings.json");
3612
+ const settings = (c) => join17(c.home, ...configDir, "settings.json");
3403
3613
  return {
3404
3614
  name: harness,
3405
3615
  // Both hosts name their executable exactly as we name the harness, so the harness id doubles
3406
3616
  // as the PATH probe here — unlike, say, antigravity-cli, whose binary is `agy`.
3407
- detect: (c) => onPath2(harness) || existsSync10(join16(c.home, ...configDir)),
3617
+ detect: (c) => onPath2(harness) || existsSync10(join17(c.home, ...configDir)),
3408
3618
  install(c) {
3409
3619
  const path = settings(c);
3410
3620
  const cfg = readJson(path);
3411
- const entry = join16(c.pkgRoot, "dist", `${harness}.js`);
3621
+ const entry = join17(c.pkgRoot, "dist", `${harness}.js`);
3412
3622
  const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
3413
3623
  cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
3414
3624
  writeJson(path, cfg);
@@ -3433,25 +3643,25 @@ var pi = piFamilyInstaller("pi", [".pi", "agent"]);
3433
3643
  var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
3434
3644
  var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
3435
3645
  function kiloConfigPath(c) {
3436
- const dir = join16(c.home, ".config", "kilo");
3437
- const existing = KILO_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
3438
- return existing ?? join16(dir, "kilo.json");
3646
+ const dir = join17(c.home, ".config", "kilo");
3647
+ const existing = KILO_CONFIG_CANDIDATES.map((f) => join17(dir, f)).find((p) => existsSync10(p));
3648
+ return existing ?? join17(dir, "kilo.json");
3439
3649
  }
3440
3650
  var kilo = {
3441
3651
  name: "kilo",
3442
- detect: (c) => onPath2("kilo") || existsSync10(join16(c.home, ".config", "kilo")),
3652
+ detect: (c) => onPath2("kilo") || existsSync10(join17(c.home, ".config", "kilo")),
3443
3653
  install(c) {
3444
3654
  const path = kiloConfigPath(c);
3445
3655
  let cfg = {};
3446
3656
  if (existsSync10(path)) {
3447
- const parsed = parseJsonc(readFileSync12(path, "utf8"));
3657
+ const parsed = parseJsonc(readFileSync14(path, "utf8"));
3448
3658
  if (!parsed) {
3449
3659
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
3450
3660
  return;
3451
3661
  }
3452
3662
  cfg = parsed;
3453
3663
  }
3454
- const entry = pathToFileURL(join16(c.dist, "kilo.js")).href;
3664
+ const entry = pathToFileURL(join17(c.dist, "kilo.js")).href;
3455
3665
  const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
3456
3666
  writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
3457
3667
  c.log?.(`kilo: plugin registered in ${path}`);
@@ -3459,7 +3669,7 @@ var kilo = {
3459
3669
  uninstall(c) {
3460
3670
  const path = kiloConfigPath(c);
3461
3671
  if (!existsSync10(path)) return;
3462
- const cfg = parseJsonc(readFileSync12(path, "utf8"));
3672
+ const cfg = parseJsonc(readFileSync14(path, "utf8"));
3463
3673
  if (!cfg || !Array.isArray(cfg.plugin)) return;
3464
3674
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
3465
3675
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -3468,9 +3678,9 @@ var kilo = {
3468
3678
  };
3469
3679
  var claudeCode = {
3470
3680
  name: "claude-code",
3471
- detect: (c) => onPath2("claude") || existsSync10(join16(c.home, ".claude")),
3681
+ detect: (c) => onPath2("claude") || existsSync10(join17(c.home, ".claude")),
3472
3682
  install(c) {
3473
- const path = join16(c.home, ".claude", "settings.json");
3683
+ const path = join17(c.home, ".claude", "settings.json");
3474
3684
  const settings = readJson(path);
3475
3685
  settings.hooks = settings.hooks ?? {};
3476
3686
  mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
@@ -3489,18 +3699,18 @@ var claudeCode = {
3489
3699
  "HINDSIGHT_MCP_HARNESS=claude-code",
3490
3700
  "--",
3491
3701
  "node",
3492
- join16(c.dist, "mcp-server.js")
3702
+ join17(c.dist, "mcp-server.js")
3493
3703
  ])) {
3494
3704
  c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
3495
3705
  } else {
3496
3706
  c.log?.(
3497
3707
  `claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
3498
- claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join16(c.dist, "mcp-server.js")}"`
3708
+ claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join17(c.dist, "mcp-server.js")}"`
3499
3709
  );
3500
3710
  }
3501
3711
  },
3502
3712
  uninstall(c) {
3503
- const path = join16(c.home, ".claude", "settings.json");
3713
+ const path = join17(c.home, ".claude", "settings.json");
3504
3714
  if (existsSync10(path)) {
3505
3715
  const settings = readJson(path);
3506
3716
  if (settings.hooks) {
@@ -3526,20 +3736,20 @@ function defaultClaudeMcp(args) {
3526
3736
  var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
3527
3737
  var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
3528
3738
  command = "node"
3529
- args = [${JSON.stringify(join16(dist, "mcp-server.js"))}]
3739
+ args = [${JSON.stringify(join17(dist, "mcp-server.js"))}]
3530
3740
  env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
3531
3741
  var codex = {
3532
3742
  name: "codex",
3533
- detect: (c) => onPath2("codex") || existsSync10(join16(c.home, ".codex")),
3743
+ detect: (c) => onPath2("codex") || existsSync10(join17(c.home, ".codex")),
3534
3744
  install(c) {
3535
- const hooksPath = join16(c.home, ".codex", "hooks.json");
3745
+ const hooksPath = join17(c.home, ".codex", "hooks.json");
3536
3746
  const cfg = readJson(hooksPath);
3537
3747
  cfg.hooks = cfg.hooks ?? {};
3538
3748
  mergeHarnessHooks(cfg.hooks, "codex", c.dist);
3539
3749
  writeJson(hooksPath, cfg);
3540
3750
  c.log?.(`codex: hooks merged into ${hooksPath}`);
3541
- const tomlPath = join16(c.home, ".codex", "config.toml");
3542
- const existing = existsSync10(tomlPath) ? readFileSync12(tomlPath, "utf8") : "";
3751
+ const tomlPath = join17(c.home, ".codex", "config.toml");
3752
+ const existing = existsSync10(tomlPath) ? readFileSync14(tomlPath, "utf8") : "";
3543
3753
  const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
3544
3754
  const additions = [];
3545
3755
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
@@ -3558,14 +3768,14 @@ var codex = {
3558
3768
  if (existsSync10(tomlPath) && !existsSync10(`${tomlPath}.hindsight-backup`)) {
3559
3769
  copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
3560
3770
  }
3561
- mkdirSync4(dirname10(tomlPath), { recursive: true });
3771
+ mkdirSync5(dirname11(tomlPath), { recursive: true });
3562
3772
  writeFileSync3(tomlPath, next);
3563
3773
  c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
3564
3774
  }
3565
3775
  installSkill(c, "codex");
3566
3776
  },
3567
3777
  uninstall(c) {
3568
- const hooksPath = join16(c.home, ".codex", "hooks.json");
3778
+ const hooksPath = join17(c.home, ".codex", "hooks.json");
3569
3779
  if (existsSync10(hooksPath)) {
3570
3780
  const cfg = readJson(hooksPath);
3571
3781
  if (cfg.hooks) {
@@ -3574,9 +3784,9 @@ var codex = {
3574
3784
  }
3575
3785
  }
3576
3786
  uninstallSkill(c, "codex");
3577
- const tomlPath = join16(c.home, ".codex", "config.toml");
3787
+ const tomlPath = join17(c.home, ".codex", "config.toml");
3578
3788
  if (existsSync10(tomlPath)) {
3579
- const toml = readFileSync12(tomlPath, "utf8");
3789
+ const toml = readFileSync14(tomlPath, "utf8");
3580
3790
  const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
3581
3791
  if (cleaned !== toml) writeFileSync3(tomlPath, cleaned);
3582
3792
  }
@@ -3592,7 +3802,7 @@ var antigravity = {
3592
3802
  // can consume this integration.
3593
3803
  detect: (c) => onPath2("agy"),
3594
3804
  install(c) {
3595
- const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
3805
+ const hooksPath = join17(c.home, ".gemini", "config", "hooks.json");
3596
3806
  const hooks = readJson(hooksPath);
3597
3807
  for (const key of Object.keys(hooks)) {
3598
3808
  if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
@@ -3603,26 +3813,26 @@ var antigravity = {
3603
3813
  setOrDelete(hooks, event, stripOurs(hooks[event]));
3604
3814
  }
3605
3815
  writeJson(hooksPath, hooks);
3606
- const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
3816
+ const mcpPath = join17(c.home, ".gemini", "config", "mcp_config.json");
3607
3817
  const mcp = readJson(mcpPath);
3608
3818
  mcp.mcpServers = {
3609
3819
  ...mcp.mcpServers ?? {},
3610
3820
  hindsight: mcpServerEntry(c.dist, "antigravity-cli")
3611
3821
  };
3612
3822
  writeJson(mcpPath, mcp);
3613
- const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
3823
+ const settingsPath = join17(c.home, ".gemini", "antigravity-cli", "settings.json");
3614
3824
  const settings = readJson(settingsPath);
3615
3825
  if (!settings.statusLine) {
3616
3826
  settings.statusLine = {
3617
3827
  type: "command",
3618
- command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
3828
+ command: `node "${join17(c.dist, "antigravity-statusline.js")}"`
3619
3829
  };
3620
3830
  writeJson(settingsPath, settings);
3621
3831
  c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
3622
3832
  } else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
3623
3833
  settings.statusLine = {
3624
3834
  type: "command",
3625
- command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
3835
+ command: `node "${join17(c.dist, "antigravity-statusline.js")}"`
3626
3836
  };
3627
3837
  writeJson(settingsPath, settings);
3628
3838
  } else {
@@ -3634,7 +3844,7 @@ var antigravity = {
3634
3844
  installSkill(c, "antigravity-cli");
3635
3845
  },
3636
3846
  uninstall(c) {
3637
- const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
3847
+ const hooksPath = join17(c.home, ".gemini", "config", "hooks.json");
3638
3848
  if (existsSync10(hooksPath)) {
3639
3849
  const hooks = readJson(hooksPath);
3640
3850
  if (hooks[MARKER]) {
@@ -3646,7 +3856,7 @@ var antigravity = {
3646
3856
  }
3647
3857
  writeJson(hooksPath, hooks);
3648
3858
  }
3649
- const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
3859
+ const mcpPath = join17(c.home, ".gemini", "config", "mcp_config.json");
3650
3860
  if (existsSync10(mcpPath)) {
3651
3861
  const mcp = readJson(mcpPath);
3652
3862
  if (mcp.mcpServers?.hindsight) {
@@ -3654,7 +3864,7 @@ var antigravity = {
3654
3864
  writeJson(mcpPath, mcp);
3655
3865
  }
3656
3866
  }
3657
- const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
3867
+ const settingsPath = join17(c.home, ".gemini", "antigravity-cli", "settings.json");
3658
3868
  if (existsSync10(settingsPath)) {
3659
3869
  const settings = readJson(settingsPath);
3660
3870
  if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
@@ -3682,7 +3892,7 @@ function pathNodeVersion() {
3682
3892
  }
3683
3893
  }
3684
3894
  function runtimeDir(home) {
3685
- return join16(home, ".hindsight", "coding-agents");
3895
+ return join17(home, ".hindsight", "coding-agents");
3686
3896
  }
3687
3897
  var ORIGIN_FILE = ".install-origin.json";
3688
3898
  function stageRuntime(c) {
@@ -3695,25 +3905,25 @@ function stageRuntime(c) {
3695
3905
  }
3696
3906
  };
3697
3907
  if (same(c.pkgRoot, target)) return c;
3698
- if (!existsSync10(join16(c.dist, "installer.js"))) return c;
3908
+ if (!existsSync10(join17(c.dist, "installer.js"))) return c;
3699
3909
  try {
3700
- rmSync2(join16(target, "dist"), { recursive: true, force: true });
3701
- mkdirSync4(target, { recursive: true });
3702
- cpSync2(c.dist, join16(target, "dist"), { recursive: true });
3703
- const skill = join16(c.pkgRoot, "skill");
3704
- if (existsSync10(skill)) cpSync2(skill, join16(target, "skill"), { recursive: true });
3705
- const pkgJson = join16(c.pkgRoot, "package.json");
3706
- if (existsSync10(pkgJson)) copyFileSync(pkgJson, join16(target, "package.json"));
3910
+ rmSync2(join17(target, "dist"), { recursive: true, force: true });
3911
+ mkdirSync5(target, { recursive: true });
3912
+ cpSync2(c.dist, join17(target, "dist"), { recursive: true });
3913
+ const skill = join17(c.pkgRoot, "skill");
3914
+ if (existsSync10(skill)) cpSync2(skill, join17(target, "skill"), { recursive: true });
3915
+ const pkgJson = join17(c.pkgRoot, "package.json");
3916
+ if (existsSync10(pkgJson)) copyFileSync(pkgJson, join17(target, "package.json"));
3707
3917
  for (const resource of ["plugin.json", "hooks", "index.js"]) {
3708
- const source = join16(c.pkgRoot, resource);
3709
- if (existsSync10(source)) cpSync2(source, join16(target, resource), { recursive: true });
3918
+ const source = join17(c.pkgRoot, resource);
3919
+ if (existsSync10(source)) cpSync2(source, join17(target, resource), { recursive: true });
3710
3920
  }
3711
3921
  writeFileSync3(
3712
- join16(target, ORIGIN_FILE),
3922
+ join17(target, ORIGIN_FILE),
3713
3923
  JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
3714
3924
  );
3715
3925
  c.log?.(`runtime staged at ${target}`);
3716
- return { ...c, pkgRoot: target, dist: join16(target, "dist") };
3926
+ return { ...c, pkgRoot: target, dist: join17(target, "dist") };
3717
3927
  } catch (error) {
3718
3928
  c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
3719
3929
  return c;
@@ -3791,7 +4001,7 @@ function configureServer(c, args, installing) {
3791
4001
  c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
3792
4002
  return false;
3793
4003
  }
3794
- const configPath = process.env.HINDSIGHT_CONFIG || join16(c.home, ...CONFIG_RELATIVE);
4004
+ const configPath = process.env.HINDSIGHT_CONFIG || join17(c.home, ...CONFIG_RELATIVE);
3795
4005
  const existing = readJson(configPath);
3796
4006
  const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
3797
4007
  let mode = explicit;
@@ -3887,7 +4097,7 @@ function reportDaemonPrereqs(c) {
3887
4097
  }
3888
4098
  var devin = {
3889
4099
  name: "devin-cli",
3890
- detect: (c) => onPath2("devin") || existsSync10(join16(c.home, ".config", "devin")),
4100
+ detect: (c) => onPath2("devin") || existsSync10(join17(c.home, ".config", "devin")),
3891
4101
  // Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
3892
4102
  // nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
3893
4103
  // support a hard prerequisite here — and one worth checking now, because the alternative is an
@@ -3900,12 +4110,12 @@ var devin = {
3900
4110
  Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
3901
4111
  },
3902
4112
  install(c) {
3903
- const configPath = join16(c.home, ".config", "devin", "config.json");
4113
+ const configPath = join17(c.home, ".config", "devin", "config.json");
3904
4114
  const config = readJson(configPath);
3905
4115
  config.hooks = config.hooks ?? {};
3906
4116
  mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
3907
4117
  writeJson(configPath, config);
3908
- const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
4118
+ const mcpPath = join17(c.home, ".config", "devin", "mcp_config.json");
3909
4119
  const mcp = readJson(mcpPath);
3910
4120
  mcp.mcpServers = {
3911
4121
  ...mcp.mcpServers ?? {},
@@ -3915,7 +4125,7 @@ var devin = {
3915
4125
  c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
3916
4126
  },
3917
4127
  uninstall(c) {
3918
- const configPath = join16(c.home, ".config", "devin", "config.json");
4128
+ const configPath = join17(c.home, ".config", "devin", "config.json");
3919
4129
  if (existsSync10(configPath)) {
3920
4130
  const config = readJson(configPath);
3921
4131
  if (config.hooks) {
@@ -3924,7 +4134,7 @@ var devin = {
3924
4134
  writeJson(configPath, config);
3925
4135
  }
3926
4136
  }
3927
- const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
4137
+ const mcpPath = join17(c.home, ".config", "devin", "mcp_config.json");
3928
4138
  if (existsSync10(mcpPath)) {
3929
4139
  const mcp = readJson(mcpPath);
3930
4140
  if (mcp.mcpServers?.hindsight) {
@@ -3937,14 +4147,14 @@ var devin = {
3937
4147
  };
3938
4148
  var cursor = {
3939
4149
  name: "cursor-cli",
3940
- detect: (c) => onPath2("cursor-agent") || existsSync10(join16(c.home, ".cursor")),
4150
+ detect: (c) => onPath2("cursor-agent") || existsSync10(join17(c.home, ".cursor")),
3941
4151
  install(c) {
3942
- const hooksPath = join16(c.home, ".cursor", "hooks.json");
4152
+ const hooksPath = join17(c.home, ".cursor", "hooks.json");
3943
4153
  const cfg = readJson(hooksPath);
3944
4154
  cfg.hooks = cfg.hooks ?? {};
3945
4155
  mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
3946
4156
  writeJson(hooksPath, cfg);
3947
- const mcpPath = join16(c.home, ".cursor", "mcp.json");
4157
+ const mcpPath = join17(c.home, ".cursor", "mcp.json");
3948
4158
  const mcp = readJson(mcpPath);
3949
4159
  mcp.mcpServers = {
3950
4160
  ...mcp.mcpServers ?? {},
@@ -3955,7 +4165,7 @@ var cursor = {
3955
4165
  installSkill(c, "cursor-cli");
3956
4166
  },
3957
4167
  uninstall(c) {
3958
- const hooksPath = join16(c.home, ".cursor", "hooks.json");
4168
+ const hooksPath = join17(c.home, ".cursor", "hooks.json");
3959
4169
  if (existsSync10(hooksPath)) {
3960
4170
  const cfg = readJson(hooksPath);
3961
4171
  if (cfg.hooks) {
@@ -3964,7 +4174,7 @@ var cursor = {
3964
4174
  writeJson(hooksPath, cfg);
3965
4175
  }
3966
4176
  }
3967
- const mcpPath = join16(c.home, ".cursor", "mcp.json");
4177
+ const mcpPath = join17(c.home, ".cursor", "mcp.json");
3968
4178
  if (existsSync10(mcpPath)) {
3969
4179
  const mcp = readJson(mcpPath);
3970
4180
  if (mcp.mcpServers?.hindsight) {
@@ -3978,13 +4188,13 @@ var cursor = {
3978
4188
  };
3979
4189
  var copilot = {
3980
4190
  name: "copilot-cli",
3981
- detect: (c) => onPath2("copilot") || existsSync10(join16(c.home, ".copilot")),
4191
+ detect: (c) => onPath2("copilot") || existsSync10(join17(c.home, ".copilot")),
3982
4192
  install(c) {
3983
- const hooksPath = join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
4193
+ const hooksPath = join17(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
3984
4194
  const hooks = {};
3985
4195
  mergeHarnessHooks(hooks, "copilot-cli", c.dist);
3986
4196
  writeJson(hooksPath, { version: 1, hooks });
3987
- const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
4197
+ const mcpPath = join17(c.home, ".copilot", "mcp-config.json");
3988
4198
  const mcp = readJson(mcpPath);
3989
4199
  mcp.mcpServers = {
3990
4200
  ...mcp.mcpServers ?? {},
@@ -3995,10 +4205,10 @@ var copilot = {
3995
4205
  c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
3996
4206
  },
3997
4207
  uninstall(c) {
3998
- rmSync2(join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
4208
+ rmSync2(join17(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
3999
4209
  force: true
4000
4210
  });
4001
- const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
4211
+ const mcpPath = join17(c.home, ".copilot", "mcp-config.json");
4002
4212
  if (existsSync10(mcpPath)) {
4003
4213
  const mcp = readJson(mcpPath);
4004
4214
  if (mcp.mcpServers?.hindsight) {
@@ -4015,12 +4225,12 @@ var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
4015
4225
  var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
4016
4226
  var grok = {
4017
4227
  name: "grok-build",
4018
- detect: (c) => onPath2("grok") || existsSync10(join16(c.home, ".grok")),
4228
+ detect: (c) => onPath2("grok") || existsSync10(join17(c.home, ".grok")),
4019
4229
  install(c) {
4020
- const path = join16(c.home, ".grok", "config.toml");
4021
- const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
4230
+ const path = join17(c.home, ".grok", "config.toml");
4231
+ const existing = existsSync10(path) ? readFileSync14(path, "utf8") : "";
4022
4232
  const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
4023
- const command = (entry) => JSON.stringify(`node "${join16(c.dist, entry)}"`);
4233
+ const command = (entry) => JSON.stringify(`node "${join17(c.dist, entry)}"`);
4024
4234
  const tomlString = (value) => JSON.stringify(value);
4025
4235
  const block = `
4026
4236
  ${GROK_MARKER_START}
@@ -4044,21 +4254,21 @@ ${GROK_MARKER_START}
4044
4254
 
4045
4255
  [mcp_servers.hindsight]
4046
4256
  command = "node"
4047
- args = [${tomlString(join16(c.dist, "mcp-server.js"))}]
4257
+ args = [${tomlString(join17(c.dist, "mcp-server.js"))}]
4048
4258
  env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
4049
4259
  ${GROK_MARKER_END}
4050
4260
  `;
4051
4261
  if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
4052
4262
  copyFileSync(path, `${path}.hindsight-backup`);
4053
- mkdirSync4(dirname10(path), { recursive: true });
4263
+ mkdirSync5(dirname11(path), { recursive: true });
4054
4264
  writeFileSync3(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
4055
4265
  installSkill(c, "grok-build");
4056
4266
  c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
4057
4267
  },
4058
4268
  uninstall(c) {
4059
- const path = join16(c.home, ".grok", "config.toml");
4269
+ const path = join17(c.home, ".grok", "config.toml");
4060
4270
  if (existsSync10(path)) {
4061
- const existing = readFileSync12(path, "utf8");
4271
+ const existing = readFileSync14(path, "utf8");
4062
4272
  const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
4063
4273
  if (cleaned !== existing) writeFileSync3(path, cleaned);
4064
4274
  }
@@ -4070,17 +4280,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
4070
4280
  var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
4071
4281
  var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
4072
4282
  function removeLegacyClineHooks(c) {
4073
- const hooksDir = join16(c.home, "Documents", "Cline", "Hooks");
4283
+ const hooksDir = join17(c.home, "Documents", "Cline", "Hooks");
4074
4284
  for (const event of CLINE_OLD_HOOK_EVENTS) {
4075
- const path = join16(hooksDir, event);
4076
- if (existsSync10(path) && readFileSync12(path, "utf8").includes(CLINE_HOOK_MARKER)) {
4285
+ const path = join17(hooksDir, event);
4286
+ if (existsSync10(path) && readFileSync14(path, "utf8").includes(CLINE_HOOK_MARKER)) {
4077
4287
  rmSync2(path, { force: true });
4078
4288
  }
4079
4289
  }
4080
4290
  }
4081
4291
  var cline = {
4082
4292
  name: "cline-cli",
4083
- detect: (c) => onPath2("cline") || existsSync10(join16(c.home, ".cline")),
4293
+ detect: (c) => onPath2("cline") || existsSync10(join17(c.home, ".cline")),
4084
4294
  install(c) {
4085
4295
  removeLegacyClineHooks(c);
4086
4296
  const installed = (c.clinePlugin ?? runClinePlugin)([
@@ -4089,7 +4299,7 @@ var cline = {
4089
4299
  "--force",
4090
4300
  c.pkgRoot
4091
4301
  ]);
4092
- const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4302
+ const mcpPath = join17(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4093
4303
  const mcp = readJson(mcpPath);
4094
4304
  mcp.mcpServers = {
4095
4305
  ...mcp.mcpServers ?? {},
@@ -4104,7 +4314,7 @@ var cline = {
4104
4314
  uninstall(c) {
4105
4315
  removeLegacyClineHooks(c);
4106
4316
  (c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
4107
- const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4317
+ const mcpPath = join17(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4108
4318
  if (existsSync10(mcpPath)) {
4109
4319
  const mcp = readJson(mcpPath);
4110
4320
  if (mcp.mcpServers?.hindsight) {
@@ -4118,31 +4328,31 @@ var cline = {
4118
4328
  };
4119
4329
  var DCODE_MARKETPLACE = "hindsight-coding-agents";
4120
4330
  var DCODE_PLUGIN_ID = "hindsight-coding-agents@hindsight-coding-agents";
4121
- var DCODE_MARKETPLACE_RELATIVE_PATH = join16(".agents", "plugins", "marketplace.json");
4331
+ var DCODE_MARKETPLACE_RELATIVE_PATH = join17(".agents", "plugins", "marketplace.json");
4122
4332
  var DCODE_FALLBACK_MARKETPLACE = "hindsight-coding-agents-marketplace.json";
4123
4333
  function prepareDcodeMarketplace(c) {
4124
- const root = join16(c.home, ".hindsight");
4125
- const conventionalPath = join16(root, DCODE_MARKETPLACE_RELATIVE_PATH);
4334
+ const root = join17(c.home, ".hindsight");
4335
+ const conventionalPath = join17(root, DCODE_MARKETPLACE_RELATIVE_PATH);
4126
4336
  let path = conventionalPath;
4127
4337
  let registrationSource = root;
4128
4338
  let marketplace = { plugins: [] };
4129
4339
  if (existsSync10(conventionalPath)) {
4130
4340
  try {
4131
- const parsed = JSON.parse(readFileSync12(conventionalPath, "utf8"));
4341
+ const parsed = JSON.parse(readFileSync14(conventionalPath, "utf8"));
4132
4342
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
4133
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
4343
+ path = join17(root, DCODE_FALLBACK_MARKETPLACE);
4134
4344
  } else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
4135
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
4345
+ path = join17(root, DCODE_FALLBACK_MARKETPLACE);
4136
4346
  } else {
4137
4347
  marketplace = parsed;
4138
4348
  }
4139
4349
  } catch {
4140
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
4350
+ path = join17(root, DCODE_FALLBACK_MARKETPLACE);
4141
4351
  }
4142
4352
  }
4143
4353
  if (path !== conventionalPath && existsSync10(path)) {
4144
4354
  try {
4145
- const parsed = JSON.parse(readFileSync12(path, "utf8"));
4355
+ const parsed = JSON.parse(readFileSync14(path, "utf8"));
4146
4356
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
4147
4357
  c.log?.(`dcode: refusing to replace malformed marketplace file ${path}`);
4148
4358
  return false;
@@ -4170,7 +4380,7 @@ function prepareDcodeMarketplace(c) {
4170
4380
  }
4171
4381
  var dcode = {
4172
4382
  name: "dcode",
4173
- detect: (c) => onPath2("dcode") || existsSync10(join16(c.home, ".deepagents")),
4383
+ detect: (c) => onPath2("dcode") || existsSync10(join17(c.home, ".deepagents")),
4174
4384
  preflight: (c) => c.dcodePlugin || onPath2("dcode") ? void 0 : "the `dcode` CLI is not on PATH",
4175
4385
  install(c) {
4176
4386
  const plugin = c.dcodePlugin ?? runDcodePlugin;
@@ -4179,7 +4389,7 @@ var dcode = {
4179
4389
  if (installed) {
4180
4390
  c.log?.(`dcode: native Agent Plugin installed (${DCODE_PLUGIN_ID})`);
4181
4391
  } else {
4182
- const source = marketplacePath === false ? join16(c.home, ".hindsight") : marketplacePath;
4392
+ const source = marketplacePath === false ? join17(c.home, ".hindsight") : marketplacePath;
4183
4393
  c.log?.(
4184
4394
  `dcode: could not install the native plugin \u2014 run dcode plugin marketplace add "${source}" && dcode plugin install ${DCODE_PLUGIN_ID}`
4185
4395
  );
@@ -4207,16 +4417,16 @@ var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
4207
4417
  var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
4208
4418
  var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
4209
4419
  function dshHome(c) {
4210
- return process.env.DSH_HOME || join16(c.home, ".dsh");
4420
+ return process.env.DSH_HOME || join17(c.home, ".dsh");
4211
4421
  }
4212
4422
  var dsh = {
4213
4423
  name: "dsh",
4214
4424
  detect: (c) => onPath2("dsh") || existsSync10(dshHome(c)),
4215
4425
  install(c) {
4216
- const path = join16(dshHome(c), "cordis.patch.yml");
4217
- const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
4426
+ const path = join17(dshHome(c), "cordis.patch.yml");
4427
+ const existing = existsSync10(path) ? readFileSync14(path, "utf8") : "";
4218
4428
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
4219
- const entry = pathToFileURL(join16(c.dist, "dsh.js")).href;
4429
+ const entry = pathToFileURL(join17(c.dist, "dsh.js")).href;
4220
4430
  const block = `${DSH_MARKER_START}
4221
4431
  - insert:
4222
4432
  - id: hindsight
@@ -4225,7 +4435,7 @@ ${DSH_MARKER_END}
4225
4435
  `;
4226
4436
  if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
4227
4437
  copyFileSync(path, `${path}.hindsight-backup`);
4228
- mkdirSync4(dirname10(path), { recursive: true });
4438
+ mkdirSync5(dirname11(path), { recursive: true });
4229
4439
  writeFileSync3(path, others ? `${others}
4230
4440
 
4231
4441
  ${block}` : block);
@@ -4233,9 +4443,9 @@ ${block}` : block);
4233
4443
  c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
4234
4444
  },
4235
4445
  uninstall(c) {
4236
- const path = join16(dshHome(c), "cordis.patch.yml");
4446
+ const path = join17(dshHome(c), "cordis.patch.yml");
4237
4447
  if (existsSync10(path)) {
4238
- const existing = readFileSync12(path, "utf8");
4448
+ const existing = readFileSync14(path, "utf8");
4239
4449
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
4240
4450
  if (others !== existing.trim()) writeFileSync3(path, others ? `${others}
4241
4451
  ` : "[]\n");
@@ -4246,9 +4456,9 @@ ${block}` : block);
4246
4456
  };
4247
4457
  var qwen = {
4248
4458
  name: "qwen-code",
4249
- detect: (c) => onPath2("qwen") || existsSync10(join16(c.home, ".qwen")),
4459
+ detect: (c) => onPath2("qwen") || existsSync10(join17(c.home, ".qwen")),
4250
4460
  install(c) {
4251
- const path = join16(c.home, ".qwen", "settings.json");
4461
+ const path = join17(c.home, ".qwen", "settings.json");
4252
4462
  const settings = readJson(path);
4253
4463
  settings.hooks = settings.hooks ?? {};
4254
4464
  mergeHarnessHooks(settings.hooks, "qwen-code", c.dist);
@@ -4266,18 +4476,18 @@ var qwen = {
4266
4476
  "HINDSIGHT_MCP_HARNESS=qwen-code",
4267
4477
  "hindsight",
4268
4478
  "node",
4269
- join16(c.dist, "mcp-server.js")
4479
+ join17(c.dist, "mcp-server.js")
4270
4480
  ])) {
4271
4481
  c.log?.("qwen-code: MCP server registered (qwen mcp add, user scope)");
4272
4482
  } else {
4273
4483
  c.log?.(
4274
4484
  `qwen-code: could not run \`qwen mcp add\` \u2014 register the tools manually:
4275
- qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join16(c.dist, "mcp-server.js")}"`
4485
+ qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join17(c.dist, "mcp-server.js")}"`
4276
4486
  );
4277
4487
  }
4278
4488
  },
4279
4489
  uninstall(c) {
4280
- const path = join16(c.home, ".qwen", "settings.json");
4490
+ const path = join17(c.home, ".qwen", "settings.json");
4281
4491
  if (existsSync10(path)) {
4282
4492
  const settings = readJson(path);
4283
4493
  if (settings.hooks) {
@@ -4300,6 +4510,101 @@ function defaultQwenMcp(args) {
4300
4510
  return false;
4301
4511
  }
4302
4512
  }
4513
+ var factoryDroid = {
4514
+ name: "factory-droid",
4515
+ detect: (c) => onPath2("droid") || existsSync10(join17(c.home, ".factory")),
4516
+ preflight(c) {
4517
+ const mcpPath = join17(c.home, ".factory", "mcp.json");
4518
+ const existing = readJson(mcpPath).mcpServers?.hindsight;
4519
+ if (existing && !isOurMcpEntry(existing)) {
4520
+ return `${mcpPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
4521
+ }
4522
+ },
4523
+ install(c) {
4524
+ const hooksPath = join17(c.home, ".factory", "hooks.json");
4525
+ const hooks = readJson(hooksPath);
4526
+ if (!existsSync10(hooksPath)) {
4527
+ const fallback = readJson(join17(c.home, ".factory", "settings.json")).hooks;
4528
+ if (fallback && typeof fallback === "object" && !Array.isArray(fallback)) {
4529
+ Object.assign(hooks, fallback);
4530
+ }
4531
+ }
4532
+ mergeHarnessHooks(hooks, "factory-droid", c.dist);
4533
+ writeJson(hooksPath, hooks);
4534
+ c.log?.(`factory-droid: hooks merged into ${hooksPath}`);
4535
+ installSkill(c, "factory-droid");
4536
+ const mcpPath = join17(c.home, ".factory", "mcp.json");
4537
+ const mcp = readJson(mcpPath);
4538
+ mcp.mcpServers = mcp.mcpServers ?? {};
4539
+ mcp.mcpServers.hindsight = mcpServerEntry(c.dist, "factory-droid");
4540
+ writeJson(mcpPath, mcp);
4541
+ c.log?.(`factory-droid: MCP server registered in ${mcpPath}`);
4542
+ },
4543
+ uninstall(c) {
4544
+ const hooksPath = join17(c.home, ".factory", "hooks.json");
4545
+ if (existsSync10(hooksPath)) {
4546
+ const hooks = readJson(hooksPath);
4547
+ stripHarnessHooks(hooks, "factory-droid");
4548
+ if (Object.keys(hooks).length) writeJson(hooksPath, hooks);
4549
+ else rmSync2(hooksPath);
4550
+ }
4551
+ const mcpPath = join17(c.home, ".factory", "mcp.json");
4552
+ if (existsSync10(mcpPath)) {
4553
+ const mcp = readJson(mcpPath);
4554
+ if (isOurMcpEntry(mcp.mcpServers?.hindsight)) {
4555
+ delete mcp.mcpServers.hindsight;
4556
+ if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
4557
+ else rmSync2(mcpPath);
4558
+ }
4559
+ }
4560
+ uninstallSkill(c, "factory-droid");
4561
+ c.log?.("factory-droid: hooks + MCP registration + skill removed");
4562
+ }
4563
+ };
4564
+ var zcode = {
4565
+ name: "zcode",
4566
+ detect: (c) => onPath2("zcode") || existsSync10(join17(c.home, ".zcode")),
4567
+ preflight(c) {
4568
+ const configPath = zcodeConfigPath(c);
4569
+ const existing = readJson(configPath).mcp?.servers?.hindsight;
4570
+ if (existing && !isOurMcpEntry(existing)) {
4571
+ return `${configPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
4572
+ }
4573
+ },
4574
+ install(c) {
4575
+ const configPath = zcodeConfigPath(c);
4576
+ const config = readJson(configPath);
4577
+ const hooks = config.hooks = config.hooks ?? {};
4578
+ hooks.enabled = true;
4579
+ hooks.maxOutputBytes = hooks.maxOutputBytes ?? ZCODE_MAX_OUTPUT_BYTES;
4580
+ hooks.events = hooks.events ?? {};
4581
+ mergeHarnessHooks(hooks.events, "zcode", c.dist);
4582
+ config.mcp = config.mcp ?? {};
4583
+ config.mcp.servers = config.mcp.servers ?? {};
4584
+ config.mcp.servers.hindsight = mcpServerEntry(c.dist, "zcode");
4585
+ writeJson(configPath, config);
4586
+ c.log?.(`zcode: hooks + MCP server merged into ${configPath}`);
4587
+ installSkill(c, "zcode");
4588
+ },
4589
+ uninstall(c) {
4590
+ const configPath = zcodeConfigPath(c);
4591
+ if (existsSync10(configPath)) {
4592
+ const config = readJson(configPath);
4593
+ if (isOurMcpEntry(config.mcp?.servers?.hindsight)) {
4594
+ delete config.mcp.servers.hindsight;
4595
+ if (!Object.keys(config.mcp.servers).length) delete config.mcp;
4596
+ }
4597
+ const hooks = config.hooks;
4598
+ if (hooks?.events) {
4599
+ stripHarnessHooks(hooks.events, "zcode");
4600
+ if (!Object.keys(hooks.events).length) delete config.hooks;
4601
+ }
4602
+ writeJson(configPath, config);
4603
+ }
4604
+ uninstallSkill(c, "zcode");
4605
+ c.log?.(`zcode: hooks + MCP registration + skill removed`);
4606
+ }
4607
+ };
4303
4608
  var INSTALLERS = [
4304
4609
  opencode,
4305
4610
  opencode2,
@@ -4316,7 +4621,9 @@ var INSTALLERS = [
4316
4621
  qwen,
4317
4622
  cline,
4318
4623
  dcode,
4319
- dsh
4624
+ dsh,
4625
+ factoryDroid,
4626
+ zcode
4320
4627
  ];
4321
4628
  var HARNESS_ALIASES = { agy: "antigravity-cli" };
4322
4629
  function importConversations(harness, ctx) {
@@ -4336,18 +4643,18 @@ function importConversations(harness, ctx) {
4336
4643
  return;
4337
4644
  }
4338
4645
  const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
4339
- const file = join16(mkdtempSync(join16(tmpdir4(), "hindsight-import-")), "conversations.json");
4646
+ const file = join17(mkdtempSync(join17(tmpdir5(), "hindsight-import-")), "conversations.json");
4340
4647
  writeFileSync3(file, JSON.stringify(found.sessions));
4341
4648
  ctx.log?.(
4342
4649
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
4343
4650
  );
4344
4651
  try {
4345
- execFileSync6("node", [join16(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
4652
+ execFileSync6("node", [join17(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
4346
4653
  stdio: "inherit"
4347
4654
  });
4348
4655
  } catch {
4349
4656
  ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
4350
- ctx.log?.(` node "${join16(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
4657
+ ctx.log?.(` node "${join17(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
4351
4658
  }
4352
4659
  }
4353
4660
  function run(argv, ctxIn) {
@@ -4405,12 +4712,6 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
4405
4712
  );
4406
4713
  return 1;
4407
4714
  }
4408
- if (command === "install" && !configureServer(
4409
- ctx,
4410
- rawArgs,
4411
- targets.map((t) => t.name)
4412
- ))
4413
- return 1;
4414
4715
  const blocked = /* @__PURE__ */ new Set();
4415
4716
  if (command === "install") {
4416
4717
  for (const t of targets) {
@@ -4422,6 +4723,12 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
4422
4723
  }
4423
4724
  }
4424
4725
  const runnable = targets.filter((t) => !blocked.has(t.name));
4726
+ if (command === "install" && runnable.length > 0 && !configureServer(
4727
+ ctx,
4728
+ rawArgs,
4729
+ runnable.map((t) => t.name)
4730
+ ))
4731
+ return 1;
4425
4732
  const failed = [];
4426
4733
  for (const t of runnable) {
4427
4734
  if (t[command](ctx) === false) failed.push(t.name);
@@ -4446,11 +4753,11 @@ var mainPath = process.argv[1] ? (() => {
4446
4753
  })() : void 0;
4447
4754
  var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
4448
4755
  if (isMain || mainPath?.endsWith("installer.js")) {
4449
- const dist = dirname10(fileURLToPath6(import.meta.url));
4450
- const pkgRoot = dirname10(dist);
4756
+ const dist = dirname11(fileURLToPath6(import.meta.url));
4757
+ const pkgRoot = dirname11(dist);
4451
4758
  let version;
4452
4759
  try {
4453
- version = JSON.parse(readFileSync12(join16(pkgRoot, "package.json"), "utf8")).version;
4760
+ version = JSON.parse(readFileSync14(join17(pkgRoot, "package.json"), "utf8")).version;
4454
4761
  } catch {
4455
4762
  version = void 0;
4456
4763
  }