@vectorize-io/hindsight-coding-agents 0.5.2 → 0.5.4

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 (51) hide show
  1. package/README.md +42 -8
  2. package/dist/antigravity-hook.js +335 -91
  3. package/dist/antigravity-statusline.js +17 -10
  4. package/dist/antigravity-stop-hook.js +340 -92
  5. package/dist/claude-hook.js +335 -91
  6. package/dist/claude-sessionstart-hook.js +459 -132
  7. package/dist/claude-stop-hook.js +340 -92
  8. package/dist/cline.js +283 -64
  9. package/dist/codex-hook.js +335 -91
  10. package/dist/codex-sessionstart-hook.js +459 -132
  11. package/dist/codex-stop-hook.js +340 -92
  12. package/dist/copilot-hook.js +335 -91
  13. package/dist/copilot-sessionstart-hook.js +459 -132
  14. package/dist/copilot-stop-hook.js +340 -92
  15. package/dist/cursor-hook.js +335 -91
  16. package/dist/cursor-sessionstart-hook.js +459 -132
  17. package/dist/cursor-stop-hook.js +340 -92
  18. package/dist/daemon-start.js +17 -10
  19. package/dist/dcode-hook.js +335 -91
  20. package/dist/dcode-sessionstart-hook.js +459 -132
  21. package/dist/dcode-stop-hook.js +340 -92
  22. package/dist/deepen.js +113 -32
  23. package/dist/devin-hook.js +335 -91
  24. package/dist/devin-sessionstart-hook.js +459 -132
  25. package/dist/devin-stop-hook.js +340 -92
  26. package/dist/droid-hook.js +335 -91
  27. package/dist/droid-sessionstart-hook.js +459 -132
  28. package/dist/droid-stop-hook.js +340 -92
  29. package/dist/dsh.js +322 -101
  30. package/dist/grok-hook.js +335 -91
  31. package/dist/grok-sessionstart-hook.js +459 -132
  32. package/dist/grok-stop-hook.js +340 -92
  33. package/dist/hindsight-seed.js +17 -10
  34. package/dist/index.js +322 -101
  35. package/dist/installer.js +1252 -325
  36. package/dist/kilo.js +322 -101
  37. package/dist/mcp-server.js +100 -23
  38. package/dist/opencode2.js +322 -101
  39. package/dist/pi.js +321 -100
  40. package/dist/prime-agent.js +321 -100
  41. package/dist/qwen-hook.js +335 -91
  42. package/dist/qwen-sessionstart-hook.js +459 -132
  43. package/dist/qwen-stop-hook.js +340 -92
  44. package/dist/status.js +98 -21
  45. package/dist/survey-supervisor.js +81 -0
  46. package/dist/zcode-hook.js +2954 -0
  47. package/dist/zcode-sessionstart-hook.js +3655 -0
  48. package/dist/zcode-stop-hook.js +3218 -0
  49. package/package.json +7 -3
  50. package/plugin.json +1 -1
  51. package/skill/SKILL.md +17 -7
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,
10
- mkdtempSync,
11
- readFileSync as readFileSync12,
9
+ mkdirSync as mkdirSync6,
10
+ mkdtempSync as mkdtempSync2,
11
+ readFileSync as readFileSync14,
12
12
  readSync as readSync4,
13
13
  realpathSync as realpathSync3,
14
- rmSync as rmSync2,
15
- writeFileSync as writeFileSync3
14
+ rmSync as rmSync3,
15
+ writeFileSync as writeFileSync4
16
16
  } from "fs";
17
- import { homedir as homedir10, tmpdir as tmpdir4 } from "os";
17
+ import { homedir as homedir10, tmpdir as tmpdir6 } 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 join18 } from "path";
20
20
  import { fileURLToPath as fileURLToPath6, pathToFileURL } from "url";
21
21
 
22
22
  // node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -910,22 +910,22 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
910
910
  }
911
911
  }
912
912
  }
913
- function handleError(error, skipUntilAfter = [], skipUntil = []) {
913
+ function handleError(error, skipUntilAfter = [], skipUntil2 = []) {
914
914
  onError(error);
915
- if (skipUntilAfter.length + skipUntil.length > 0) {
915
+ if (skipUntilAfter.length + skipUntil2.length > 0) {
916
916
  let token = _scanner.getToken();
917
917
  while (token !== 17) {
918
918
  if (skipUntilAfter.indexOf(token) !== -1) {
919
919
  scanNext();
920
920
  break;
921
- } else if (skipUntil.indexOf(token) !== -1) {
921
+ } else if (skipUntil2.indexOf(token) !== -1) {
922
922
  break;
923
923
  }
924
924
  token = scanNext();
925
925
  }
926
926
  }
927
927
  }
928
- function parseString(isValue) {
928
+ function parseString2(isValue) {
929
929
  const value = _scanner.getTokenValue();
930
930
  if (isValue) {
931
931
  onLiteralValue(value);
@@ -974,11 +974,11 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
974
974
  ]);
975
975
  return false;
976
976
  }
977
- parseString(false);
977
+ parseString2(false);
978
978
  if (_scanner.getToken() === 6) {
979
979
  onSeparator(":");
980
980
  scanNext();
981
- if (!parseValue()) {
981
+ if (!parseValue2()) {
982
982
  handleError(4, [], [
983
983
  2,
984
984
  5
@@ -1032,7 +1032,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
1032
1032
  }
1033
1033
  return true;
1034
1034
  }
1035
- function parseArray() {
1035
+ function parseArray2() {
1036
1036
  onArrayBegin();
1037
1037
  scanNext();
1038
1038
  let isFirstElement = true;
@@ -1056,7 +1056,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
1056
1056
  } else {
1057
1057
  _jsonPath[_jsonPath.length - 1]++;
1058
1058
  }
1059
- if (!parseValue()) {
1059
+ if (!parseValue2()) {
1060
1060
  handleError(4, [], [
1061
1061
  4,
1062
1062
  5
@@ -1079,14 +1079,14 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
1079
1079
  }
1080
1080
  return true;
1081
1081
  }
1082
- function parseValue() {
1082
+ function parseValue2() {
1083
1083
  switch (_scanner.getToken()) {
1084
1084
  case 3:
1085
- return parseArray();
1085
+ return parseArray2();
1086
1086
  case 1:
1087
1087
  return parseObject();
1088
1088
  case 10:
1089
- return parseString(true);
1089
+ return parseString2(true);
1090
1090
  default:
1091
1091
  return parseLiteral();
1092
1092
  }
@@ -1099,7 +1099,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
1099
1099
  handleError(4, [], []);
1100
1100
  return false;
1101
1101
  }
1102
- if (!parseValue()) {
1102
+ if (!parseValue2()) {
1103
1103
  handleError(4, [], []);
1104
1104
  return false;
1105
1105
  }
@@ -1347,8 +1347,653 @@ function applyEdits(text, edits) {
1347
1347
  return text;
1348
1348
  }
1349
1349
 
1350
+ // node_modules/smol-toml/dist/date.js
1351
+ var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
1352
+ var TomlDate = class _TomlDate extends Date {
1353
+ #hasDate = false;
1354
+ #hasTime = false;
1355
+ #offset = null;
1356
+ constructor(date) {
1357
+ let hasDate = true;
1358
+ let hasTime = true;
1359
+ let offset = "Z";
1360
+ if (typeof date === "string") {
1361
+ let match = date.match(DATE_TIME_RE);
1362
+ if (match) {
1363
+ if (!match[1]) {
1364
+ hasDate = false;
1365
+ date = `0000-01-01T${date}`;
1366
+ }
1367
+ hasTime = !!match[2];
1368
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
1369
+ if (match[2] && +match[2] > 23) {
1370
+ date = "";
1371
+ } else {
1372
+ offset = match[3] || null;
1373
+ date = date.toUpperCase();
1374
+ if (!offset && hasTime)
1375
+ date += "Z";
1376
+ }
1377
+ } else {
1378
+ date = "";
1379
+ }
1380
+ }
1381
+ super(date);
1382
+ if (!isNaN(this.getTime())) {
1383
+ this.#hasDate = hasDate;
1384
+ this.#hasTime = hasTime;
1385
+ this.#offset = offset;
1386
+ }
1387
+ }
1388
+ isDateTime() {
1389
+ return this.#hasDate && this.#hasTime;
1390
+ }
1391
+ isLocal() {
1392
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
1393
+ }
1394
+ isDate() {
1395
+ return this.#hasDate && !this.#hasTime;
1396
+ }
1397
+ isTime() {
1398
+ return this.#hasTime && !this.#hasDate;
1399
+ }
1400
+ isValid() {
1401
+ return this.#hasDate || this.#hasTime;
1402
+ }
1403
+ toISOString() {
1404
+ let iso = super.toISOString();
1405
+ if (this.isDate())
1406
+ return iso.slice(0, 10);
1407
+ if (this.isTime())
1408
+ return iso.slice(11, 23);
1409
+ if (this.#offset === null)
1410
+ return iso.slice(0, -1);
1411
+ if (this.#offset === "Z")
1412
+ return iso;
1413
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
1414
+ offset = this.#offset[0] === "-" ? offset : -offset;
1415
+ let offsetDate = new Date(this.getTime() - offset * 6e4);
1416
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
1417
+ }
1418
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
1419
+ let date = new _TomlDate(jsDate);
1420
+ date.#offset = offset;
1421
+ return date;
1422
+ }
1423
+ static wrapAsLocalDateTime(jsDate) {
1424
+ let date = new _TomlDate(jsDate);
1425
+ date.#offset = null;
1426
+ return date;
1427
+ }
1428
+ static wrapAsLocalDate(jsDate) {
1429
+ let date = new _TomlDate(jsDate);
1430
+ date.#hasTime = false;
1431
+ date.#offset = null;
1432
+ return date;
1433
+ }
1434
+ static wrapAsLocalTime(jsDate) {
1435
+ let date = new _TomlDate(jsDate);
1436
+ date.#hasDate = false;
1437
+ date.#offset = null;
1438
+ return date;
1439
+ }
1440
+ };
1441
+
1442
+ // node_modules/smol-toml/dist/error.js
1443
+ function getLineColFromPtr(string, ptr) {
1444
+ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
1445
+ return [lines.length, lines.pop().length + 1];
1446
+ }
1447
+ function makeCodeBlock(string, line, column) {
1448
+ let lines = string.split(/\r\n|\n|\r/g);
1449
+ let codeblock = "";
1450
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
1451
+ for (let i = line - 1; i <= line + 1; i++) {
1452
+ let l = lines[i - 1];
1453
+ if (!l)
1454
+ continue;
1455
+ codeblock += i.toString().padEnd(numberLen, " ");
1456
+ codeblock += ": ";
1457
+ codeblock += l;
1458
+ codeblock += "\n";
1459
+ if (i === line) {
1460
+ codeblock += " ".repeat(numberLen + column + 2);
1461
+ codeblock += "^\n";
1462
+ }
1463
+ }
1464
+ return codeblock;
1465
+ }
1466
+ var TomlError = class extends Error {
1467
+ line;
1468
+ column;
1469
+ codeblock;
1470
+ constructor(message, options) {
1471
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
1472
+ const codeblock = makeCodeBlock(options.toml, line, column);
1473
+ super(`Invalid TOML document: ${message}
1474
+
1475
+ ${codeblock}`, options);
1476
+ this.line = line;
1477
+ this.column = column;
1478
+ this.codeblock = codeblock;
1479
+ }
1480
+ };
1481
+
1482
+ // node_modules/smol-toml/dist/util.js
1483
+ function indexOfNewline(str, start = 0) {
1484
+ let idx = str.indexOf("\n", start);
1485
+ if (str.charCodeAt(idx - 1) === 13)
1486
+ idx--;
1487
+ return idx;
1488
+ }
1489
+ function skipComment(ctx) {
1490
+ for (; ctx.p < ctx.s.length; ctx.p++) {
1491
+ let c = ctx.s.charCodeAt(ctx.p);
1492
+ if (c === 10)
1493
+ break;
1494
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
1495
+ ctx.p++;
1496
+ break;
1497
+ }
1498
+ if (c < 32 && c !== 9 || c === 127) {
1499
+ throw new TomlError("control characters are not allowed in comments", {
1500
+ toml: ctx.s,
1501
+ ptr: ctx.p
1502
+ });
1503
+ }
1504
+ }
1505
+ }
1506
+ function skipVoid(ctx, banNewLines, banComments) {
1507
+ let c;
1508
+ while (1) {
1509
+ while ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))
1510
+ ctx.p++;
1511
+ if (banComments || c !== 35)
1512
+ break;
1513
+ skipComment(ctx);
1514
+ }
1515
+ }
1516
+ function skipUntil(ctx, sep2, end) {
1517
+ let ptr = ctx.p;
1518
+ if (!end) {
1519
+ ptr = indexOfNewline(ctx.s, ptr);
1520
+ ctx.p = ptr < 0 ? ctx.s.length : ptr;
1521
+ return;
1522
+ }
1523
+ for (; ctx.p < ctx.s.length; ctx.p++) {
1524
+ let c = ctx.s.charCodeAt(ctx.p);
1525
+ if (c === 35) {
1526
+ skipComment(ctx);
1527
+ } else if (c === end || c === sep2) {
1528
+ return;
1529
+ }
1530
+ }
1531
+ throw new TomlError("cannot find end of structure", {
1532
+ toml: ctx.s,
1533
+ ptr
1534
+ });
1535
+ }
1536
+
1537
+ // node_modules/smol-toml/dist/primitive.js
1538
+ var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
1539
+ var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
1540
+ var LEADING_ZERO = /^[+-]?0[0-9_]/;
1541
+ function parseString(ctx) {
1542
+ let start = ctx.p;
1543
+ let c = ctx.s.charCodeAt(ctx.p++);
1544
+ let first = c;
1545
+ let isLiteral = c === 39;
1546
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
1547
+ if (isMultiline) {
1548
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
1549
+ ctx.p++;
1550
+ else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
1551
+ ctx.p += 2;
1552
+ }
1553
+ let parsed = "";
1554
+ let sliceStart = ctx.p;
1555
+ let state = 0;
1556
+ for (; ctx.p < ctx.s.length; ctx.p++) {
1557
+ c = ctx.s.charCodeAt(ctx.p);
1558
+ if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
1559
+ state = state && 3;
1560
+ } else if (c < 32 && c !== 9 || c === 127) {
1561
+ throw new TomlError("control characters are not allowed in strings", {
1562
+ toml: ctx.s,
1563
+ ptr: ctx.p
1564
+ });
1565
+ } else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
1566
+ if (isMultiline) {
1567
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
1568
+ ctx.p++;
1569
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
1570
+ ctx.p++;
1571
+ }
1572
+ if (!state)
1573
+ parsed += ctx.s.slice(sliceStart, ctx.p);
1574
+ ctx.p += isMultiline ? 3 : 1;
1575
+ return parsed;
1576
+ } else if (!state) {
1577
+ if (!isLiteral && c === 92) {
1578
+ parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
1579
+ state = 1;
1580
+ }
1581
+ } else if (state === 1) {
1582
+ if (c === 120 || c === 117 || c === 85) {
1583
+ let value = 0;
1584
+ let len = c === 120 ? 2 : c === 117 ? 4 : 8;
1585
+ for (let j = 0; j < len; j++, ctx.p++) {
1586
+ let hex = ctx.s.charCodeAt(ctx.p + 1);
1587
+ let digit = (
1588
+ /* 0-9 */
1589
+ hex >= 48 && hex <= 57 ? hex - 48 : (
1590
+ /* A-F */
1591
+ hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
1592
+ /* a-f */
1593
+ hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
1594
+ )
1595
+ )
1596
+ );
1597
+ if (digit < 0)
1598
+ throw new TomlError("invalid non-hex character in unicode escape", { toml: ctx.s, ptr: ctx.p + 1 });
1599
+ value = value << 4 | digit;
1600
+ }
1601
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
1602
+ throw new TomlError("invalid unicode escape", { toml: ctx.s, ptr: ctx.p });
1603
+ }
1604
+ parsed += String.fromCodePoint(value);
1605
+ sliceStart = ctx.p + 1;
1606
+ state = 0;
1607
+ } else if (c === 32 || c === 9) {
1608
+ state = 2;
1609
+ } else {
1610
+ if (c === 98)
1611
+ parsed += "\b";
1612
+ else if (c === 116)
1613
+ parsed += " ";
1614
+ else if (c === 110)
1615
+ parsed += "\n";
1616
+ else if (c === 102)
1617
+ parsed += "\f";
1618
+ else if (c === 114)
1619
+ parsed += "\r";
1620
+ else if (c === 101)
1621
+ parsed += "\x1B";
1622
+ else if (c === 34)
1623
+ parsed += '"';
1624
+ else if (c === 92)
1625
+ parsed += "\\";
1626
+ else
1627
+ throw new TomlError("unrecognized escape sequence", { toml: ctx.s, ptr: ctx.p });
1628
+ sliceStart = ctx.p + 1;
1629
+ state = 0;
1630
+ }
1631
+ } else if (c !== 32 && c !== 9) {
1632
+ if (state === 2) {
1633
+ throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
1634
+ toml: ctx.s,
1635
+ ptr: sliceStart
1636
+ });
1637
+ }
1638
+ state = !isLiteral && c === 92 ? 1 : 0;
1639
+ sliceStart = ctx.p;
1640
+ }
1641
+ }
1642
+ throw new TomlError("unfinished string", { toml: ctx.s, ptr: start });
1643
+ }
1644
+ function sliceAndTrimEndOf(ctx, start, end) {
1645
+ let value = ctx.s.slice(start, end);
1646
+ let commentIdx = value.indexOf("#");
1647
+ if (commentIdx > 0) {
1648
+ skipComment({ s: value, p: commentIdx, d: 0 });
1649
+ value = value.slice(0, commentIdx);
1650
+ }
1651
+ return value.trimEnd();
1652
+ }
1653
+ function parseValue(ctx, integersAsBigInt, end) {
1654
+ let ptr = ctx.p;
1655
+ let err = { toml: ctx.s, ptr };
1656
+ skipUntil(ctx, 44, end);
1657
+ let value = sliceAndTrimEndOf(ctx, ptr, ctx.p);
1658
+ if (!value)
1659
+ throw new TomlError("incomplete declaration: value expected", err);
1660
+ if (value === "-inf")
1661
+ return -Infinity;
1662
+ if (value === "inf" || value === "+inf")
1663
+ return Infinity;
1664
+ if (value === "nan" || value === "+nan" || value === "-nan")
1665
+ return NaN;
1666
+ if (value === "-0")
1667
+ return integersAsBigInt ? 0n : 0;
1668
+ let isInt = INT_REGEX.test(value);
1669
+ if (isInt || FLOAT_REGEX.test(value)) {
1670
+ if (LEADING_ZERO.test(value)) {
1671
+ throw new TomlError("leading zeroes are not allowed", err);
1672
+ }
1673
+ value = value.replace(/_/g, "");
1674
+ let numeric = +value;
1675
+ if (isNaN(numeric)) {
1676
+ throw new TomlError("invalid number", err);
1677
+ }
1678
+ if (isInt) {
1679
+ if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
1680
+ throw new TomlError("integer value cannot be represented losslessly", err);
1681
+ }
1682
+ if (isInt || integersAsBigInt === true)
1683
+ numeric = BigInt(value);
1684
+ }
1685
+ return numeric;
1686
+ }
1687
+ const date = new TomlDate(value);
1688
+ if (!date.isValid())
1689
+ throw new TomlError("invalid value", err);
1690
+ return date;
1691
+ }
1692
+
1693
+ // node_modules/smol-toml/dist/extract.js
1694
+ function extractValue(ctx, end, integersAsBigInt) {
1695
+ let ptr = ctx.p;
1696
+ let c = ctx.s.charCodeAt(ptr);
1697
+ if (c === 91 || c === 123) {
1698
+ if (!ctx.d--) {
1699
+ throw new TomlError("document contains excessively nested structures. aborting.", {
1700
+ toml: ctx.s,
1701
+ ptr
1702
+ });
1703
+ }
1704
+ let value = c === 91 ? parseArray(ctx, integersAsBigInt) : parseInlineTable(ctx, integersAsBigInt);
1705
+ ctx.d++;
1706
+ return value;
1707
+ }
1708
+ if (c === 34 || c === 39) {
1709
+ return parseString(ctx);
1710
+ }
1711
+ if (c === 116) {
1712
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
1713
+ throw new TomlError("invalid value", { toml: ctx.s, ptr });
1714
+ ctx.p++;
1715
+ return true;
1716
+ }
1717
+ if (c === 102) {
1718
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
1719
+ throw new TomlError("invalid value", { toml: ctx.s, ptr });
1720
+ ctx.p++;
1721
+ return false;
1722
+ }
1723
+ return parseValue(ctx, integersAsBigInt, end);
1724
+ }
1725
+
1726
+ // node_modules/smol-toml/dist/struct.js
1727
+ var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
1728
+ function parseKey(ctx, end = "=") {
1729
+ let start = ctx.p;
1730
+ let dot = start - 1;
1731
+ let parsed = [];
1732
+ let endPtr = ctx.s.indexOf(end, start);
1733
+ if (endPtr < 0) {
1734
+ throw new TomlError("incomplete key-value: cannot find end of key", {
1735
+ toml: ctx.s,
1736
+ ptr: start
1737
+ });
1738
+ }
1739
+ do {
1740
+ let c = ctx.s.charCodeAt(ctx.p = ++dot);
1741
+ if (c !== 32 && c !== 9) {
1742
+ if (c === 34 || c === 39) {
1743
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) {
1744
+ throw new TomlError("multiline strings are not allowed in keys", {
1745
+ toml: ctx.s,
1746
+ ptr: ctx.p
1747
+ });
1748
+ }
1749
+ let part = parseString(ctx);
1750
+ dot = ctx.s.indexOf(".", ctx.p);
1751
+ let strEnd = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
1752
+ let newLine = indexOfNewline(strEnd);
1753
+ if (newLine > -1) {
1754
+ throw new TomlError("newlines are not allowed in keys", {
1755
+ toml: ctx.s,
1756
+ ptr: newLine
1757
+ });
1758
+ }
1759
+ if (strEnd.trimStart()) {
1760
+ throw new TomlError("found extra tokens after the string part", {
1761
+ toml: ctx.s,
1762
+ ptr: ctx.p
1763
+ });
1764
+ }
1765
+ if (endPtr < ctx.p) {
1766
+ endPtr = ctx.s.indexOf(end, ctx.p);
1767
+ if (endPtr < 0) {
1768
+ throw new TomlError("incomplete key-value: cannot find end of key", {
1769
+ toml: ctx.s,
1770
+ ptr: start
1771
+ });
1772
+ }
1773
+ }
1774
+ parsed.push(part);
1775
+ } else {
1776
+ dot = ctx.s.indexOf(".", ctx.p);
1777
+ let part = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
1778
+ if (!KEY_PART_RE.test(part)) {
1779
+ throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
1780
+ toml: ctx.s,
1781
+ ptr: ctx.p
1782
+ });
1783
+ }
1784
+ parsed.push(part.trimEnd());
1785
+ }
1786
+ }
1787
+ } while (dot + 1 && dot < endPtr);
1788
+ ctx.p = endPtr + 1;
1789
+ skipVoid(ctx, true, true);
1790
+ return parsed;
1791
+ }
1792
+ function parseInlineTable(ctx, integersAsBigInt) {
1793
+ let res = {};
1794
+ let seen = /* @__PURE__ */ new Set();
1795
+ let c;
1796
+ ctx.p++;
1797
+ while (ctx.p < ctx.s.length) {
1798
+ skipVoid(ctx);
1799
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
1800
+ ctx.p++;
1801
+ return res;
1802
+ }
1803
+ let k;
1804
+ let t = res;
1805
+ let hasOwn = false;
1806
+ let p = ctx.p;
1807
+ let key = parseKey(ctx);
1808
+ for (let i = 0; i < key.length; i++) {
1809
+ if (i)
1810
+ t = hasOwn ? t[k] : t[k] = {};
1811
+ k = key[i];
1812
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
1813
+ throw new TomlError("trying to redefine an already defined value", {
1814
+ toml: ctx.s,
1815
+ ptr: p
1816
+ });
1817
+ }
1818
+ if (!hasOwn && k === "__proto__") {
1819
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
1820
+ }
1821
+ }
1822
+ if (hasOwn) {
1823
+ throw new TomlError("trying to redefine an already defined value", {
1824
+ toml: ctx.s,
1825
+ ptr: ctx.p
1826
+ });
1827
+ }
1828
+ let value = extractValue(ctx, 125, integersAsBigInt);
1829
+ seen.add(t[k] = value);
1830
+ skipVoid(ctx);
1831
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
1832
+ return res;
1833
+ }
1834
+ if (c !== 44) {
1835
+ throw new TomlError("expected comma or end of structure", { toml: ctx.s, ptr: ctx.p - 1 });
1836
+ }
1837
+ }
1838
+ throw new TomlError("unfinished table encountered", {
1839
+ toml: ctx.s,
1840
+ ptr: ctx.p
1841
+ });
1842
+ }
1843
+ function parseArray(ctx, integersAsBigInt) {
1844
+ let res = [];
1845
+ let c;
1846
+ ctx.p++;
1847
+ while (ctx.p < ctx.s.length) {
1848
+ skipVoid(ctx);
1849
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
1850
+ ctx.p++;
1851
+ return res;
1852
+ }
1853
+ res.push(extractValue(ctx, 93, integersAsBigInt));
1854
+ skipVoid(ctx);
1855
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
1856
+ return res;
1857
+ }
1858
+ if (c !== 44) {
1859
+ throw new TomlError("expected comma or end of structure", { toml: ctx.s, ptr: ctx.p - 1 });
1860
+ }
1861
+ }
1862
+ throw new TomlError("unfinished array encountered", {
1863
+ toml: ctx.s,
1864
+ ptr: ctx.p
1865
+ });
1866
+ }
1867
+
1868
+ // node_modules/smol-toml/dist/parse.js
1869
+ function peekTable(key, table, meta, type) {
1870
+ let t = table;
1871
+ let m = meta;
1872
+ let k;
1873
+ let hasOwn = false;
1874
+ let state;
1875
+ for (let i = 0; i < key.length; i++) {
1876
+ if (i) {
1877
+ t = hasOwn ? t[k] : t[k] = {};
1878
+ m = (state = m[k]).c;
1879
+ if (type === 0 && (state.t === 1 || state.t === 2)) {
1880
+ return null;
1881
+ }
1882
+ if (state.t === 2) {
1883
+ let l = t.length - 1;
1884
+ t = t[l];
1885
+ m = m[l].c;
1886
+ }
1887
+ }
1888
+ k = key[i];
1889
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
1890
+ return null;
1891
+ }
1892
+ if (!hasOwn) {
1893
+ if (k === "__proto__") {
1894
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
1895
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
1896
+ }
1897
+ m[k] = {
1898
+ t: i < key.length - 1 && type === 2 ? 3 : type,
1899
+ d: false,
1900
+ i: 0,
1901
+ c: {}
1902
+ };
1903
+ }
1904
+ }
1905
+ state = m[k];
1906
+ if (state.t !== type && !(type === 1 && state.t === 3)) {
1907
+ return null;
1908
+ }
1909
+ if (type === 2) {
1910
+ if (!state.d) {
1911
+ state.d = true;
1912
+ t[k] = [];
1913
+ }
1914
+ t[k].push(t = {});
1915
+ state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
1916
+ }
1917
+ if (state.d) {
1918
+ return null;
1919
+ }
1920
+ state.d = true;
1921
+ if (type === 1) {
1922
+ t = hasOwn ? t[k] : t[k] = {};
1923
+ } else if (type === 0 && hasOwn) {
1924
+ return null;
1925
+ }
1926
+ return [k, t, state.c];
1927
+ }
1928
+ function parse2(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
1929
+ let ctx = { s: toml, p: 0, d: maxDepth };
1930
+ let res = {};
1931
+ let meta = {};
1932
+ let tmp;
1933
+ let tbl = res;
1934
+ let m = meta;
1935
+ skipVoid(ctx);
1936
+ while (ctx.p < toml.length) {
1937
+ if (toml.charCodeAt(ctx.p) === 91) {
1938
+ let isTableArray = toml.charCodeAt(++ctx.p) === 91;
1939
+ tmp = ctx.p += +isTableArray;
1940
+ let k = parseKey(ctx, "]");
1941
+ if (isTableArray) {
1942
+ if (toml.charCodeAt(ctx.p - 1) !== 93) {
1943
+ throw new TomlError("expected end of table declaration", {
1944
+ toml,
1945
+ ptr: ctx.p - 1
1946
+ });
1947
+ }
1948
+ ctx.p++;
1949
+ }
1950
+ let p = peekTable(
1951
+ k,
1952
+ res,
1953
+ meta,
1954
+ isTableArray ? 2 : 1
1955
+ /* Type.EXPLICIT */
1956
+ );
1957
+ if (!p) {
1958
+ throw new TomlError("trying to redefine an already defined table or value", {
1959
+ toml,
1960
+ ptr: tmp
1961
+ });
1962
+ }
1963
+ m = p[2];
1964
+ tbl = p[1];
1965
+ } else {
1966
+ tmp = ctx.p;
1967
+ let k = parseKey(ctx);
1968
+ let p = peekTable(
1969
+ k,
1970
+ tbl,
1971
+ m,
1972
+ 0
1973
+ /* Type.DOTTED */
1974
+ );
1975
+ if (!p) {
1976
+ throw new TomlError("trying to redefine an already defined table or value", {
1977
+ toml,
1978
+ ptr: tmp
1979
+ });
1980
+ }
1981
+ p[1][p[0]] = extractValue(ctx, void 0, integersAsBigInt);
1982
+ }
1983
+ skipVoid(ctx, true);
1984
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && tmp !== 13) {
1985
+ throw new TomlError("each key-value declaration must be followed by an end-of-line", {
1986
+ toml,
1987
+ ptr: ctx.p
1988
+ });
1989
+ }
1990
+ skipVoid(ctx);
1991
+ }
1992
+ return res;
1993
+ }
1994
+
1350
1995
  // src/core/hook.ts
1351
- import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
1996
+ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
1352
1997
 
1353
1998
  // src/core/bank.ts
1354
1999
  import { existsSync } from "fs";
@@ -1451,8 +2096,51 @@ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmS
1451
2096
  import { tmpdir as tmpdir2 } from "os";
1452
2097
  import { dirname as dirname5, join as join7 } from "path";
1453
2098
 
2099
+ // src/core/turn-journal.ts
2100
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
2101
+ import { tmpdir as tmpdir3 } from "os";
2102
+ import { dirname as dirname6, join as join8 } from "path";
2103
+
2104
+ // src/core/transcript-util.ts
2105
+ 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;
2106
+ function stripInjectedMemory(s) {
2107
+ return s.replace(MEMORY_TAG_RE, "");
2108
+ }
2109
+ var TARGET_KEYS = [
2110
+ "file_path",
2111
+ "path",
2112
+ "notebook_path",
2113
+ "command",
2114
+ "pattern",
2115
+ "query",
2116
+ "url",
2117
+ "name",
2118
+ "id"
2119
+ ];
2120
+ var ACTION_TARGET_CAP = 100;
2121
+ function actionLine(tool, input) {
2122
+ let target = "";
2123
+ if (input && typeof input === "object") {
2124
+ const rec = input;
2125
+ for (const k of TARGET_KEYS) {
2126
+ const v = rec[k];
2127
+ if (typeof v === "string" && v.trim()) {
2128
+ target = v.trim().split("\n")[0];
2129
+ break;
2130
+ }
2131
+ }
2132
+ } else if (typeof input === "string") {
2133
+ target = input.trim().split("\n")[0];
2134
+ }
2135
+ if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
2136
+ return target ? `${tool} ${target}` : tool;
2137
+ }
2138
+
2139
+ // src/core/turn-journal.ts
2140
+ var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
2141
+
1454
2142
  // src/core/retain-hook.ts
1455
- import { readFileSync as readFileSync5 } from "fs";
2143
+ import { readFileSync as readFileSync6 } from "fs";
1456
2144
 
1457
2145
  // src/core/retain-cursor.ts
1458
2146
  import { createHash as createHash2 } from "crypto";
@@ -1464,7 +2152,7 @@ import { createHash as createHash3 } from "crypto";
1464
2152
 
1465
2153
  // src/core/daemon.ts
1466
2154
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1467
- import { dirname as dirname6, join as join8 } from "path";
2155
+ import { dirname as dirname7, join as join9 } from "path";
1468
2156
  import { fileURLToPath as fileURLToPath2 } from "url";
1469
2157
  function hasRustToolchain() {
1470
2158
  if (process.platform !== "darwin") return true;
@@ -1532,7 +2220,7 @@ function onPath(bin) {
1532
2220
  import { basename as basename2 } from "path";
1533
2221
 
1534
2222
  // src/core/jsonl.ts
1535
- import { closeSync, openSync, readSync, statSync } from "fs";
2223
+ import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1536
2224
  import { StringDecoder } from "string_decoder";
1537
2225
  var CHUNK_BYTES = 64 * 1024;
1538
2226
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1540,7 +2228,7 @@ function readJsonlTail(path, opts) {
1540
2228
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1541
2229
  let size;
1542
2230
  try {
1543
- size = statSync(path).size;
2231
+ size = statSync2(path).size;
1544
2232
  } catch {
1545
2233
  return { lines: emptyLines(), skippedBytes: 0 };
1546
2234
  }
@@ -1592,41 +2280,6 @@ function* streamLines(path, start) {
1592
2280
  }
1593
2281
  }
1594
2282
 
1595
- // src/core/transcript-util.ts
1596
- 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;
1597
- function stripInjectedMemory(s) {
1598
- return s.replace(MEMORY_TAG_RE, "");
1599
- }
1600
- var TARGET_KEYS = [
1601
- "file_path",
1602
- "path",
1603
- "notebook_path",
1604
- "command",
1605
- "pattern",
1606
- "query",
1607
- "url",
1608
- "name",
1609
- "id"
1610
- ];
1611
- var ACTION_TARGET_CAP = 100;
1612
- function actionLine(tool, input) {
1613
- let target = "";
1614
- if (input && typeof input === "object") {
1615
- const rec = input;
1616
- for (const k of TARGET_KEYS) {
1617
- const v = rec[k];
1618
- if (typeof v === "string" && v.trim()) {
1619
- target = v.trim().split("\n")[0];
1620
- break;
1621
- }
1622
- }
1623
- } else if (typeof input === "string") {
1624
- target = input.trim().split("\n")[0];
1625
- }
1626
- if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1627
- return target ? `${tool} ${target}` : tool;
1628
- }
1629
-
1630
2283
  // src/core/transcript.ts
1631
2284
  function renderLine(content, type) {
1632
2285
  if (typeof content === "string") {
@@ -1679,7 +2332,7 @@ function readClaudeTranscript(path) {
1679
2332
  }
1680
2333
 
1681
2334
  // src/core/session-start.ts
1682
- import { readFileSync as readFileSync8 } from "fs";
2335
+ import { readFileSync as readFileSync10 } from "fs";
1683
2336
 
1684
2337
  // src/core/git.ts
1685
2338
  import { execFileSync as execFileSync2 } from "child_process";
@@ -1689,32 +2342,50 @@ import { resolve as resolve2 } from "path";
1689
2342
  import { execFileSync as execFileSync3 } from "child_process";
1690
2343
 
1691
2344
  // src/core/survey.ts
1692
- import { spawn as realSpawn3 } from "child_process";
2345
+ import { spawn as realSpawn4 } from "child_process";
2346
+ import { createHash as createHash4 } from "crypto";
1693
2347
  import { existsSync as existsSync3 } from "fs";
1694
- import { homedir as homedir3 } from "os";
1695
- import { dirname as dirname7, join as join9 } from "path";
2348
+ import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
2349
+ import { dirname as dirname8, join as join11 } from "path";
1696
2350
  import { fileURLToPath as fileURLToPath3 } from "url";
1697
2351
 
2352
+ // src/core/survey-lease.ts
2353
+ import { spawn as realSpawn3 } from "child_process";
2354
+ import { randomUUID } from "crypto";
2355
+ import {
2356
+ mkdirSync as mkdirSync4,
2357
+ mkdtempSync,
2358
+ readdirSync,
2359
+ renameSync as renameSync2,
2360
+ rmdirSync,
2361
+ rmSync as rmSync2,
2362
+ statSync as statSync3,
2363
+ unlinkSync,
2364
+ utimesSync,
2365
+ writeFileSync as writeFileSync2
2366
+ } from "fs";
2367
+ import { join as join10 } from "path";
2368
+
1698
2369
  // src/core/auto-update.ts
1699
- import { spawn as realSpawn4 } from "child_process";
2370
+ import { spawn as realSpawn5 } from "child_process";
1700
2371
  import {
1701
2372
  existsSync as existsSync4,
1702
- mkdirSync as mkdirSync3,
1703
- readFileSync as readFileSync6,
2373
+ mkdirSync as mkdirSync5,
2374
+ readFileSync as readFileSync7,
1704
2375
  realpathSync as realpathSync2,
1705
- unlinkSync,
1706
- writeFileSync as writeFileSync2
2376
+ unlinkSync as unlinkSync2,
2377
+ writeFileSync as writeFileSync3
1707
2378
  } from "fs";
1708
- import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
1709
- import { dirname as dirname8, join as join10 } from "path";
2379
+ import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
2380
+ import { dirname as dirname9, join as join12 } from "path";
1710
2381
  import { fileURLToPath as fileURLToPath4 } from "url";
1711
2382
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
1712
2383
  var LOCK_STALE_MS = 10 * 60 * 1e3;
1713
2384
 
1714
2385
  // src/core/skill-sync.ts
1715
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
2386
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
1716
2387
  import { homedir as homedir5 } from "os";
1717
- import { dirname as dirname9, join as join11 } from "path";
2388
+ import { dirname as dirname10, join as join13 } from "path";
1718
2389
  import { fileURLToPath as fileURLToPath5 } from "url";
1719
2390
 
1720
2391
  // src/core/skill-dirs.ts
@@ -1732,6 +2403,11 @@ var SKILL_DIRS = {
1732
2403
  // Qwen's user-level skills root (Storage.getUserSkillsDirs)
1733
2404
  "factory-droid": [".factory", "skills"],
1734
2405
  // Droid's user-level skills root
2406
+ // ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
2407
+ // shared agentskills `~/.agents/skills`. Write its OWN, for the same reason the pi family does —
2408
+ // skill removal is by fixed directory name, so installing into the shared root would make
2409
+ // `uninstall zcode` take Codex's and dsh's copy with it.
2410
+ zcode: [".zcode", "skills"],
1735
2411
  // The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
1736
2412
  // by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
1737
2413
  // and dsh's copy with it.
@@ -1739,6 +2415,59 @@ var SKILL_DIRS = {
1739
2415
  "prime-agent": [".prime", "agent", "skills"]
1740
2416
  };
1741
2417
 
2418
+ // src/core/legacy.ts
2419
+ import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2420
+ import { homedir as homedir6 } from "os";
2421
+ import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
2422
+ var LEGACY_CONFIG_FILES = {
2423
+ "claude-code": "claude-code.json",
2424
+ codex: "codex.json"
2425
+ };
2426
+ function legacyConfigPath(harness, home = homedir6()) {
2427
+ return join14(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
2428
+ }
2429
+ var CLOUD_URL = "https://api.hindsight.vectorize.io";
2430
+ function readLegacyEndpoint(home = homedir6(), prefer = []) {
2431
+ const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
2432
+ (h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
2433
+ );
2434
+ for (const harness of order) {
2435
+ const found = readOne(harness, home);
2436
+ if (found) return found;
2437
+ }
2438
+ return void 0;
2439
+ }
2440
+ function readOne(harness, home) {
2441
+ const source = legacyConfigPath(harness, home);
2442
+ if (!existsSync6(source)) return void 0;
2443
+ let raw;
2444
+ try {
2445
+ raw = JSON.parse(readFileSync9(source, "utf8"));
2446
+ } catch {
2447
+ return void 0;
2448
+ }
2449
+ if (!raw || typeof raw !== "object") return void 0;
2450
+ const apiToken = typeof raw.hindsightApiToken === "string" ? raw.hindsightApiToken : void 0;
2451
+ const url = typeof raw.hindsightApiUrl === "string" ? raw.hindsightApiUrl.trim() : "";
2452
+ if (url) {
2453
+ return {
2454
+ harness,
2455
+ serverMode: url.replace(/\/+$/, "") === CLOUD_URL ? "cloud" : "self-hosted",
2456
+ apiUrl: url,
2457
+ ...apiToken ? { apiToken } : {},
2458
+ source
2459
+ };
2460
+ }
2461
+ const port = typeof raw.apiPort === "number" ? raw.apiPort : void 0;
2462
+ return {
2463
+ harness,
2464
+ serverMode: "daemon",
2465
+ ...apiToken ? { apiToken } : {},
2466
+ ...port && port !== DEFAULT_DAEMON_PORT ? { apiPort: port } : {},
2467
+ source
2468
+ };
2469
+ }
2470
+
1742
2471
  // src/core/transcript-codex.ts
1743
2472
  function isSyntheticUserText(text) {
1744
2473
  const s = text.trimStart();
@@ -1869,19 +2598,19 @@ function readCopilotTranscript(path) {
1869
2598
  }
1870
2599
 
1871
2600
  // src/core/transcript-grok.ts
1872
- import { existsSync as existsSync6, readFileSync as readFileSync9, readdirSync } from "fs";
1873
- import { homedir as homedir6 } from "os";
1874
- import { join as join12 } from "path";
2601
+ import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
2602
+ import { homedir as homedir7 } from "os";
2603
+ import { join as join15 } from "path";
1875
2604
  var CHAT_HISTORY = "chat_history.jsonl";
1876
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join12(homedir6(), ".grok")) {
1877
- const sessionsDir = join12(grokHome, "sessions");
1878
- const direct = join12(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1879
- if (existsSync6(direct)) return direct;
2605
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
2606
+ const sessionsDir = join15(grokHome, "sessions");
2607
+ const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2608
+ if (existsSync7(direct)) return direct;
1880
2609
  try {
1881
- for (const candidate of readdirSync(sessionsDir)) {
1882
- const directory = join12(sessionsDir, candidate);
1883
- if (readFileSync9(join12(directory, ".cwd"), "utf8").trim() === cwd) {
1884
- return join12(directory, sessionId, CHAT_HISTORY);
2610
+ for (const candidate of readdirSync2(sessionsDir)) {
2611
+ const directory = join15(sessionsDir, candidate);
2612
+ if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
2613
+ return join15(directory, sessionId, CHAT_HISTORY);
1885
2614
  }
1886
2615
  }
1887
2616
  } catch {
@@ -1916,12 +2645,12 @@ function readGrokTranscript(path) {
1916
2645
  }
1917
2646
 
1918
2647
  // src/core/transcript-devin.ts
1919
- import { existsSync as existsSync7 } from "fs";
2648
+ import { existsSync as existsSync8 } from "fs";
1920
2649
  import { createRequire } from "module";
1921
- import { homedir as homedir7 } from "os";
1922
- import { join as join13 } from "path";
1923
- function devinSessionDb(home = homedir7()) {
1924
- return join13(home, ".local", "share", "devin", "cli", "sessions.db");
2650
+ import { homedir as homedir8 } from "os";
2651
+ import { join as join16 } from "path";
2652
+ function devinSessionDb(home = homedir8()) {
2653
+ return join16(home, ".local", "share", "devin", "cli", "sessions.db");
1925
2654
  }
1926
2655
  function parseDevinMessages(nodes) {
1927
2656
  const messages = /* @__PURE__ */ new Map();
@@ -1958,7 +2687,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
1958
2687
  diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
1959
2688
  return [];
1960
2689
  }
1961
- if (!existsSync7(dbPath)) {
2690
+ if (!existsSync8(dbPath)) {
1962
2691
  diag("devin-cli", "session_db_missing", { dbPath });
1963
2692
  return [];
1964
2693
  }
@@ -2230,6 +2959,51 @@ function readDroidTranscript(path) {
2230
2959
  return turns;
2231
2960
  }
2232
2961
 
2962
+ // src/core/transcript-zcode.ts
2963
+ import { readFileSync as readFileSync12 } from "fs";
2964
+ function messageText2(content) {
2965
+ if (typeof content === "string") return content.trim();
2966
+ if (!Array.isArray(content)) return "";
2967
+ return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
2968
+ }
2969
+ function readZcodeTranscript(path) {
2970
+ if (!path) return [];
2971
+ let body;
2972
+ try {
2973
+ body = readFileSync12(path, "utf8");
2974
+ } catch {
2975
+ return [];
2976
+ }
2977
+ const turns = [];
2978
+ for (const line of body.split("\n")) {
2979
+ const trimmed = line.trim();
2980
+ if (!trimmed) continue;
2981
+ let parsed;
2982
+ try {
2983
+ parsed = JSON.parse(trimmed);
2984
+ } catch {
2985
+ continue;
2986
+ }
2987
+ if (typeof parsed !== "object" || parsed === null) continue;
2988
+ const record = parsed;
2989
+ const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
2990
+ const role = typeof message?.role === "string" ? message.role : record.type;
2991
+ if (role !== "user" && role !== "assistant") continue;
2992
+ const content = stripInjectedMemory(messageText2(message?.content)).trim();
2993
+ if (!content) continue;
2994
+ turns.push({
2995
+ role,
2996
+ content,
2997
+ ...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
2998
+ });
2999
+ }
3000
+ return turns;
3001
+ }
3002
+ function zcodeAssistantText(path) {
3003
+ if (!path) return "";
3004
+ return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
3005
+ }
3006
+
2233
3007
  // src/harness/hook-lifecycle.ts
2234
3008
  var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
2235
3009
  var claudePrompt = {
@@ -2270,6 +3044,7 @@ var qwenPrompt = {
2270
3044
  sessionId: ev.session_id
2271
3045
  })
2272
3046
  };
3047
+ var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
2273
3048
  var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
2274
3049
  var antigravityPrompt = {
2275
3050
  harness: "antigravity-cli",
@@ -2612,6 +3387,56 @@ var HOOK_HARNESSES = {
2612
3387
  }),
2613
3388
  readTranscript: readDroidTranscript
2614
3389
  }
3390
+ },
3391
+ /**
3392
+ * ZCode (Z.ai's GLM coding agent) embeds the Claude Code agent runtime, so its hook PROTOCOL is
3393
+ * Claude's — `prompt`/`cwd` in, `hookSpecificOutput.additionalContext` + `systemMessage` out —
3394
+ * with `sessionId` accepted alongside `session_id`, which its Stop payload sends instead.
3395
+ *
3396
+ * What is not Claude's is the TRANSCRIPT, and that is the whole of the difference here. ZCode
3397
+ * keeps no durable session file: `Stop` carries the reply in `responseText` plus a temp,
3398
+ * assistant-only transcript it deletes as soon as the hook returns, and no user prompt at all.
3399
+ * So this is the one harness that retains from the plugin's own journal (core/turn-journal.ts) —
3400
+ * the prompt hook appends the user turn, `journal.assistantText` closes it with the reply — and
3401
+ * everything downstream (cursor, append, stamping) sees the same full conversation as any host
3402
+ * transcript.
3403
+ */
3404
+ zcode: {
3405
+ configStyle: "process",
3406
+ // ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
3407
+ // prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3408
+ timeoutUnit: "milliseconds",
3409
+ install: {
3410
+ sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
3411
+ prompt: { event: "UserPromptSubmit", entry: "zcode-hook.js", timeout: 3e4 },
3412
+ stop: { event: "Stop", entry: "zcode-stop-hook.js", timeout: 6e4 }
3413
+ },
3414
+ sessionStart: {
3415
+ ...standardSessionStart("zcode"),
3416
+ parse: (ev) => ({ cwd: ev.cwd, sessionId: zcodeSessionId(ev) })
3417
+ },
3418
+ prompt: {
3419
+ ...claudePrompt,
3420
+ harness: "zcode",
3421
+ journalPrompt: true,
3422
+ parse: (ev) => ({
3423
+ prompt: ev.prompt ?? ev.user_prompt,
3424
+ cwd: ev.cwd,
3425
+ sessionId: zcodeSessionId(ev)
3426
+ })
3427
+ },
3428
+ retain: {
3429
+ hostTimeoutSec: 60,
3430
+ harness: "zcode",
3431
+ // No transcriptPath: the journal supplies it (see `journal` below).
3432
+ parse: (ev) => ({ sessionId: zcodeSessionId(ev), cwd: ev.cwd }),
3433
+ journal: {
3434
+ // `responseText` is the full reply and is what ZCode sends in practice. The ephemeral
3435
+ // transcript is the fallback when it is absent, and `responsePreview` — which is
3436
+ // TRUNCATED — is the last resort, preferred only over losing the turn entirely.
3437
+ assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
3438
+ }
3439
+ }
2615
3440
  }
2616
3441
  };
2617
3442
 
@@ -2619,16 +3444,16 @@ var HOOK_HARNESSES = {
2619
3444
  import { execFileSync as execFileSync4 } from "child_process";
2620
3445
  import {
2621
3446
  closeSync as closeSync2,
2622
- existsSync as existsSync8,
3447
+ existsSync as existsSync9,
2623
3448
  openSync as openSync2,
2624
- readdirSync as readdirSync2,
2625
- readFileSync as readFileSync10,
3449
+ readdirSync as readdirSync3,
3450
+ readFileSync as readFileSync13,
2626
3451
  readSync as readSync2,
2627
- statSync as statSync2
3452
+ statSync as statSync4
2628
3453
  } from "fs";
2629
- import { createHash as createHash4 } from "crypto";
2630
- import { homedir as homedir8 } from "os";
2631
- import { join as join14 } from "path";
3454
+ import { createHash as createHash5 } from "crypto";
3455
+ import { homedir as homedir9 } from "os";
3456
+ import { join as join17 } from "path";
2632
3457
  import * as zlib2 from "zlib";
2633
3458
 
2634
3459
  // src/core/transcript-dsh.ts
@@ -2772,8 +3597,8 @@ function zstdDecompressFrames(buffer) {
2772
3597
  }
2773
3598
 
2774
3599
  // src/core/history.ts
2775
- function claudeProjectDir(repoDir, home = homedir8()) {
2776
- return join14(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
3600
+ function claudeProjectDir(repoDir, home = homedir9()) {
3601
+ return join17(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
2777
3602
  }
2778
3603
  function piSessionDir(repoDir) {
2779
3604
  return `--${repoDir.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
@@ -2783,7 +3608,7 @@ function withinRepo(dir, repoDir) {
2783
3608
  }
2784
3609
  function claudeSessionCwd(file) {
2785
3610
  try {
2786
- for (const line of readFileSync10(file, "utf8").split("\n", 400)) {
3611
+ for (const line of readFileSync13(file, "utf8").split("\n", 400)) {
2787
3612
  if (!line.includes('"cwd"')) continue;
2788
3613
  const cwd = JSON.parse(line).cwd;
2789
3614
  if (cwd) return cwd;
@@ -2819,19 +3644,19 @@ function firstLine(path, cap = 1e6) {
2819
3644
  }
2820
3645
  function listDir(dir) {
2821
3646
  try {
2822
- return readdirSync2(dir);
3647
+ return readdirSync3(dir);
2823
3648
  } catch {
2824
3649
  return [];
2825
3650
  }
2826
3651
  }
2827
3652
  function jsonlFiles(dir) {
2828
- return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join14(dir, f));
3653
+ return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join17(dir, f));
2829
3654
  }
2830
3655
  function claudeHistory(repoDir, home) {
2831
- const root = join14(home, ".claude", "projects");
3656
+ const root = join17(home, ".claude", "projects");
2832
3657
  const exact = claudeProjectDir(repoDir, home);
2833
3658
  const prefix = exact + "-";
2834
- const dirs = listDir(root).map((d) => join14(root, d)).filter((d) => d === exact || d.startsWith(prefix));
3659
+ const dirs = listDir(root).map((d) => join17(root, d)).filter((d) => d === exact || d.startsWith(prefix));
2835
3660
  const sessions = [];
2836
3661
  let unattributed = 0;
2837
3662
  for (const file of dirs.flatMap(jsonlFiles)) {
@@ -2851,13 +3676,13 @@ function claudeHistory(repoDir, home) {
2851
3676
  return { supported: true, sessions, unattributed };
2852
3677
  }
2853
3678
  function codexHistory(repoDir, home) {
2854
- const root = join14(home, ".codex", "sessions");
2855
- if (!existsSync8(root)) return { supported: true, sessions: [] };
3679
+ const root = join17(home, ".codex", "sessions");
3680
+ if (!existsSync9(root)) return { supported: true, sessions: [] };
2856
3681
  const files = [];
2857
3682
  const walk = (dir) => {
2858
- for (const entry of readdirSync2(dir)) {
2859
- const p = join14(dir, entry);
2860
- if (statSync2(p).isDirectory()) walk(p);
3683
+ for (const entry of readdirSync3(dir)) {
3684
+ const p = join17(dir, entry);
3685
+ if (statSync4(p).isDirectory()) walk(p);
2861
3686
  else if (entry.endsWith(".jsonl")) files.push(p);
2862
3687
  }
2863
3688
  };
@@ -2882,18 +3707,18 @@ function codexHistory(repoDir, home) {
2882
3707
  }
2883
3708
  var DCODE_THREADS_SCHEMA_VERSION = 1;
2884
3709
  function dcodeTranscriptPath(root, threadId) {
2885
- const digest = createHash4("sha256").update(threadId, "utf8").digest("hex");
3710
+ const digest = createHash5("sha256").update(threadId, "utf8").digest("hex");
2886
3711
  const suffix = `--${digest}.jsonl`;
2887
3712
  try {
2888
- const match = readdirSync2(root).find((entry) => entry.endsWith(suffix));
2889
- return match ? join14(root, match) : void 0;
3713
+ const match = readdirSync3(root).find((entry) => entry.endsWith(suffix));
3714
+ return match ? join17(root, match) : void 0;
2890
3715
  } catch {
2891
3716
  return void 0;
2892
3717
  }
2893
3718
  }
2894
3719
  function dcodeHistory(repoDir, home, runCli) {
2895
- const root = join14(process.env.DEEPAGENTS_HOME || join14(home, ".deepagents"), "transcripts");
2896
- if (!existsSync8(root)) return { supported: true, sessions: [] };
3720
+ const root = join17(process.env.DEEPAGENTS_HOME || join17(home, ".deepagents"), "transcripts");
3721
+ if (!existsSync9(root)) return { supported: true, sessions: [] };
2897
3722
  let listed;
2898
3723
  try {
2899
3724
  listed = JSON.parse(runCli(["threads", "list", "--json"]));
@@ -2933,8 +3758,8 @@ function dcodeHistory(repoDir, home, runCli) {
2933
3758
  return { supported: true, sessions, ...unattributed ? { unattributed } : {} };
2934
3759
  }
2935
3760
  function dshHistory(repoDir, home) {
2936
- const root = process.env.DSH_HOME ? join14(process.env.DSH_HOME, "sessions") : join14(home, ".dsh", "sessions");
2937
- if (!existsSync8(root)) return { supported: true, sessions: [] };
3761
+ const root = process.env.DSH_HOME ? join17(process.env.DSH_HOME, "sessions") : join17(home, ".dsh", "sessions");
3762
+ if (!existsSync9(root)) return { supported: true, sessions: [] };
2938
3763
  if (typeof zlib2.zstdDecompressSync !== "function") {
2939
3764
  return {
2940
3765
  supported: false,
@@ -2944,15 +3769,15 @@ function dshHistory(repoDir, home) {
2944
3769
  }
2945
3770
  const sessions = [];
2946
3771
  let unattributed = 0;
2947
- for (const dir of readdirSync2(root).map((project) => join14(root, project))) {
3772
+ for (const dir of readdirSync3(root).map((project) => join17(root, project))) {
2948
3773
  let sessionDirs;
2949
3774
  try {
2950
- sessionDirs = readdirSync2(dir).map((id) => join14(dir, id));
3775
+ sessionDirs = readdirSync3(dir).map((id) => join17(dir, id));
2951
3776
  } catch {
2952
3777
  continue;
2953
3778
  }
2954
3779
  for (const sessionDir of sessionDirs) {
2955
- const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join14(sessionDir, name)).find((candidate) => existsSync8(candidate));
3780
+ const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join17(sessionDir, name)).find((candidate) => existsSync9(candidate));
2956
3781
  if (!file) continue;
2957
3782
  try {
2958
3783
  const lines = readDshLog(file);
@@ -2978,7 +3803,7 @@ function dshHistory(repoDir, home) {
2978
3803
  return { supported: true, sessions, unattributed };
2979
3804
  }
2980
3805
  function readDshLog(file) {
2981
- const bytes = readFileSync10(file);
3806
+ const bytes = readFileSync13(file);
2982
3807
  const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
2983
3808
  return text.split("\n").filter((line) => line.trim());
2984
3809
  }
@@ -3004,23 +3829,23 @@ function piFamilySessions(files, repoDir) {
3004
3829
  return { supported: true, sessions, unattributed };
3005
3830
  }
3006
3831
  function piHistory(repoDir, home) {
3007
- const root = join14(home, ".pi", "agent", "sessions");
3008
- if (!existsSync8(root)) return { supported: true, sessions: [] };
3832
+ const root = join17(home, ".pi", "agent", "sessions");
3833
+ if (!existsSync9(root)) return { supported: true, sessions: [] };
3009
3834
  const exact = piSessionDir(repoDir);
3010
3835
  const nested = `${exact.slice(0, -2)}-`;
3011
3836
  const files = [];
3012
3837
  for (const dir of listDir(root).filter((d) => d === exact || d.startsWith(nested))) {
3013
- files.push(...jsonlFiles(join14(root, dir)));
3838
+ files.push(...jsonlFiles(join17(root, dir)));
3014
3839
  }
3015
3840
  return piFamilySessions(files, repoDir);
3016
3841
  }
3017
3842
  function primeAgentHistory(repoDir, home) {
3018
- const root = join14(home, ".prime", "agent", "sessions");
3019
- if (!existsSync8(root)) return { supported: true, sessions: [] };
3843
+ const root = join17(home, ".prime", "agent", "sessions");
3844
+ if (!existsSync9(root)) return { supported: true, sessions: [] };
3020
3845
  return piFamilySessions(jsonlFiles(root), repoDir);
3021
3846
  }
3022
3847
  var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
3023
- function importLocalHistory(harness, repoDir, home = homedir8(), runDcodeCli) {
3848
+ function importLocalHistory(harness, repoDir, home = homedir9(), runDcodeCli) {
3024
3849
  switch (harness) {
3025
3850
  case "claude-code":
3026
3851
  return claudeHistory(repoDir, home);
@@ -3047,64 +3872,17 @@ function importLocalHistory(harness, repoDir, home = homedir8(), runDcodeCli) {
3047
3872
  case "copilot-cli":
3048
3873
  case "devin-cli":
3049
3874
  return { supported: false, reason: `${harness} ${SQLITE_HISTORY}`, sessions: [] };
3875
+ case "zcode":
3876
+ return {
3877
+ supported: false,
3878
+ reason: "ZCode keeps no session transcripts on disk to import",
3879
+ sessions: []
3880
+ };
3050
3881
  default:
3051
3882
  return { supported: false, reason: `no local history reader for ${harness}`, sessions: [] };
3052
3883
  }
3053
3884
  }
3054
3885
 
3055
- // src/core/legacy.ts
3056
- import { existsSync as existsSync9, readFileSync as readFileSync11 } from "fs";
3057
- import { homedir as homedir9 } from "os";
3058
- import { join as join15 } from "path";
3059
- var LEGACY_CONFIG_FILES = {
3060
- "claude-code": "claude-code.json",
3061
- codex: "codex.json"
3062
- };
3063
- function legacyConfigPath(harness, home = homedir9()) {
3064
- return join15(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
3065
- }
3066
- var CLOUD_URL = "https://api.hindsight.vectorize.io";
3067
- function readLegacyEndpoint(home = homedir9(), prefer = []) {
3068
- const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
3069
- (h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
3070
- );
3071
- for (const harness of order) {
3072
- const found = readOne(harness, home);
3073
- if (found) return found;
3074
- }
3075
- return void 0;
3076
- }
3077
- function readOne(harness, home) {
3078
- const source = legacyConfigPath(harness, home);
3079
- if (!existsSync9(source)) return void 0;
3080
- let raw;
3081
- try {
3082
- raw = JSON.parse(readFileSync11(source, "utf8"));
3083
- } catch {
3084
- return void 0;
3085
- }
3086
- if (!raw || typeof raw !== "object") return void 0;
3087
- const apiToken = typeof raw.hindsightApiToken === "string" ? raw.hindsightApiToken : void 0;
3088
- const url = typeof raw.hindsightApiUrl === "string" ? raw.hindsightApiUrl.trim() : "";
3089
- if (url) {
3090
- return {
3091
- harness,
3092
- serverMode: url.replace(/\/+$/, "") === CLOUD_URL ? "cloud" : "self-hosted",
3093
- apiUrl: url,
3094
- ...apiToken ? { apiToken } : {},
3095
- source
3096
- };
3097
- }
3098
- const port = typeof raw.apiPort === "number" ? raw.apiPort : void 0;
3099
- return {
3100
- harness,
3101
- serverMode: "daemon",
3102
- ...apiToken ? { apiToken } : {},
3103
- ...port && port !== DEFAULT_DAEMON_PORT ? { apiPort: port } : {},
3104
- source
3105
- };
3106
- }
3107
-
3108
3886
  // src/install-ui.ts
3109
3887
  import { execFileSync as execFileSync5 } from "child_process";
3110
3888
  import { readSync as readSync3 } from "fs";
@@ -3309,9 +4087,11 @@ function createInstallerUi(o) {
3309
4087
 
3310
4088
  // src/installer.ts
3311
4089
  var MARKER = "coding-agents";
4090
+ var ZCODE_MAX_OUTPUT_BYTES = 32768;
4091
+ var zcodeConfigPath = (c) => join18(c.home, ".zcode", "cli", "config.json");
3312
4092
  function readJson(path) {
3313
4093
  try {
3314
- return JSON.parse(readFileSync12(path, "utf8"));
4094
+ return JSON.parse(readFileSync14(path, "utf8"));
3315
4095
  } catch {
3316
4096
  return {};
3317
4097
  }
@@ -3326,9 +4106,9 @@ function parseJsonc(text) {
3326
4106
  }
3327
4107
  }
3328
4108
  function writeJson(path, value) {
3329
- mkdirSync4(dirname10(path), { recursive: true });
4109
+ mkdirSync6(dirname11(path), { recursive: true });
3330
4110
  backupOnce(path);
3331
- writeFileSync3(path, JSON.stringify(value, null, 2) + "\n");
4111
+ writeFileSync4(path, JSON.stringify(value, null, 2) + "\n");
3332
4112
  }
3333
4113
  function backupOnce(path) {
3334
4114
  if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`)) {
@@ -3336,7 +4116,7 @@ function backupOnce(path) {
3336
4116
  }
3337
4117
  }
3338
4118
  function writeJsonc(path, key, value) {
3339
- const text = existsSync10(path) ? readFileSync12(path, "utf8") : "";
4119
+ const text = existsSync10(path) ? readFileSync14(path, "utf8") : "";
3340
4120
  const edits = modify(text, [key], value, {
3341
4121
  formattingOptions: {
3342
4122
  tabSize: 2,
@@ -3347,9 +4127,9 @@ function writeJsonc(path, key, value) {
3347
4127
  }
3348
4128
  });
3349
4129
  const next = applyEdits(text, edits);
3350
- mkdirSync4(dirname10(path), { recursive: true });
4130
+ mkdirSync6(dirname11(path), { recursive: true });
3351
4131
  backupOnce(path);
3352
- writeFileSync3(path, next.endsWith("\n") ? next : `${next}
4132
+ writeFileSync4(path, next.endsWith("\n") ? next : `${next}
3353
4133
  `);
3354
4134
  }
3355
4135
  function mergeHookEvent(existing, entry) {
@@ -3364,11 +4144,14 @@ function setOrDelete(obj, key, arr) {
3364
4144
  else delete obj[key];
3365
4145
  }
3366
4146
  var cmdHook = (dist, file, timeout) => ({
3367
- hooks: [{ type: "command", command: `node "${join16(dist, file)}"`, timeout }]
4147
+ hooks: [{ type: "command", command: `node "${join18(dist, file)}"`, timeout }]
4148
+ });
4149
+ var processHook = (dist, file, timeoutMs) => ({
4150
+ hooks: [{ type: "process", command: "node", args: [join18(dist, file)], timeoutMs }]
3368
4151
  });
3369
4152
  var mcpServerEntry = (dist, harness) => ({
3370
4153
  command: "node",
3371
- args: [join16(dist, "mcp-server.js")],
4154
+ args: [join18(dist, "mcp-server.js")],
3372
4155
  env: { HINDSIGHT_MCP_HARNESS: harness }
3373
4156
  });
3374
4157
  function isOurMcpEntry(entry) {
@@ -3386,8 +4169,8 @@ function mergeHarnessHooks(hooks, harness, dist) {
3386
4169
  for (const hook of [...Object.values(spec.install), ...spec.additionalHooks ?? []]) {
3387
4170
  if (installedEvents.has(hook.event)) continue;
3388
4171
  installedEvents.add(hook.event);
3389
- const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
3390
- command: `node "${join16(dist, hook.entry)}"`,
4172
+ const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : spec.configStyle === "process" ? processHook(dist, hook.entry, hook.timeout) : {
4173
+ command: `node "${join18(dist, hook.entry)}"`,
3391
4174
  ...hook.timeout ? { timeout: hook.timeout } : {}
3392
4175
  };
3393
4176
  hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
@@ -3405,19 +4188,19 @@ function stripHarnessHooks(hooks, harness) {
3405
4188
  function skillsBaseFor(c, harness) {
3406
4189
  const parts = SKILL_DIRS[harness];
3407
4190
  if (!parts) throw new Error(`${harness} installs a skill but names no directory in SKILL_DIRS`);
3408
- return join16(c.home, ...parts);
4191
+ return join18(c.home, ...parts);
3409
4192
  }
3410
4193
  function installSkill(c, harness) {
3411
- const src = join16(c.pkgRoot, "skill");
3412
- if (!existsSync10(join16(src, "SKILL.md"))) return;
4194
+ const src = join18(c.pkgRoot, "skill");
4195
+ if (!existsSync10(join18(src, "SKILL.md"))) return;
3413
4196
  const skillsBase = skillsBaseFor(c, harness);
3414
- const dst = join16(skillsBase, "hindsight-coding-agent");
3415
- mkdirSync4(skillsBase, { recursive: true });
4197
+ const dst = join18(skillsBase, "hindsight-coding-agent");
4198
+ mkdirSync6(skillsBase, { recursive: true });
3416
4199
  cpSync2(src, dst, { recursive: true });
3417
4200
  c.log?.(`${harness}: skill installed at ${dst}`);
3418
4201
  }
3419
4202
  function uninstallSkill(c, harness) {
3420
- rmSync2(join16(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
4203
+ rmSync3(join18(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
3421
4204
  recursive: true,
3422
4205
  force: true
3423
4206
  });
@@ -3440,9 +4223,9 @@ function runClinePlugin(args) {
3440
4223
  }
3441
4224
  var OPENCODE_CONFIG_CANDIDATES = ["opencode.jsonc", "opencode.json"];
3442
4225
  function opencodeConfigPath(c) {
3443
- const dir = join16(c.home, ".config", "opencode");
3444
- const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
3445
- return existing ?? join16(dir, "opencode.json");
4226
+ const dir = join18(c.home, ".config", "opencode");
4227
+ const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join18(dir, f)).find((p) => existsSync10(p));
4228
+ return existing ?? join18(dir, "opencode.json");
3446
4229
  }
3447
4230
  function runDcodePlugin(args) {
3448
4231
  try {
@@ -3456,7 +4239,7 @@ function registerOpencodePlugin(c, name) {
3456
4239
  const path = opencodeConfigPath(c);
3457
4240
  let cfg = {};
3458
4241
  if (existsSync10(path)) {
3459
- const parsed = parseJsonc(readFileSync12(path, "utf8"));
4242
+ const parsed = parseJsonc(readFileSync14(path, "utf8"));
3460
4243
  if (!parsed) {
3461
4244
  c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
3462
4245
  return;
@@ -3470,7 +4253,7 @@ function registerOpencodePlugin(c, name) {
3470
4253
  function unregisterOpencodePlugin(c, name) {
3471
4254
  const path = opencodeConfigPath(c);
3472
4255
  if (!existsSync10(path)) return;
3473
- const cfg = parseJsonc(readFileSync12(path, "utf8"));
4256
+ const cfg = parseJsonc(readFileSync14(path, "utf8"));
3474
4257
  if (!cfg || !Array.isArray(cfg.plugin)) return;
3475
4258
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
3476
4259
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -3478,7 +4261,7 @@ function unregisterOpencodePlugin(c, name) {
3478
4261
  }
3479
4262
  var opencode = {
3480
4263
  name: "opencode",
3481
- detect: (c) => onPath2("opencode") || existsSync10(join16(c.home, ".config", "opencode")),
4264
+ detect: (c) => onPath2("opencode") || existsSync10(join18(c.home, ".config", "opencode")),
3482
4265
  install: (c) => registerOpencodePlugin(c, "opencode"),
3483
4266
  uninstall: (c) => unregisterOpencodePlugin(c, "opencode")
3484
4267
  };
@@ -3489,16 +4272,16 @@ var opencode2 = {
3489
4272
  uninstall: (c) => unregisterOpencodePlugin(c, "opencode2")
3490
4273
  };
3491
4274
  function piFamilyInstaller(harness, configDir) {
3492
- const settings = (c) => join16(c.home, ...configDir, "settings.json");
4275
+ const settings = (c) => join18(c.home, ...configDir, "settings.json");
3493
4276
  return {
3494
4277
  name: harness,
3495
4278
  // Both hosts name their executable exactly as we name the harness, so the harness id doubles
3496
4279
  // as the PATH probe here — unlike, say, antigravity-cli, whose binary is `agy`.
3497
- detect: (c) => onPath2(harness) || existsSync10(join16(c.home, ...configDir)),
4280
+ detect: (c) => onPath2(harness) || existsSync10(join18(c.home, ...configDir)),
3498
4281
  install(c) {
3499
4282
  const path = settings(c);
3500
4283
  const cfg = readJson(path);
3501
- const entry = join16(c.pkgRoot, "dist", `${harness}.js`);
4284
+ const entry = join18(c.pkgRoot, "dist", `${harness}.js`);
3502
4285
  const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
3503
4286
  cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
3504
4287
  writeJson(path, cfg);
@@ -3523,25 +4306,25 @@ var pi = piFamilyInstaller("pi", [".pi", "agent"]);
3523
4306
  var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
3524
4307
  var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
3525
4308
  function kiloConfigPath(c) {
3526
- const dir = join16(c.home, ".config", "kilo");
3527
- const existing = KILO_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
3528
- return existing ?? join16(dir, "kilo.json");
4309
+ const dir = join18(c.home, ".config", "kilo");
4310
+ const existing = KILO_CONFIG_CANDIDATES.map((f) => join18(dir, f)).find((p) => existsSync10(p));
4311
+ return existing ?? join18(dir, "kilo.json");
3529
4312
  }
3530
4313
  var kilo = {
3531
4314
  name: "kilo",
3532
- detect: (c) => onPath2("kilo") || existsSync10(join16(c.home, ".config", "kilo")),
4315
+ detect: (c) => onPath2("kilo") || existsSync10(join18(c.home, ".config", "kilo")),
3533
4316
  install(c) {
3534
4317
  const path = kiloConfigPath(c);
3535
4318
  let cfg = {};
3536
4319
  if (existsSync10(path)) {
3537
- const parsed = parseJsonc(readFileSync12(path, "utf8"));
4320
+ const parsed = parseJsonc(readFileSync14(path, "utf8"));
3538
4321
  if (!parsed) {
3539
4322
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
3540
4323
  return;
3541
4324
  }
3542
4325
  cfg = parsed;
3543
4326
  }
3544
- const entry = pathToFileURL(join16(c.dist, "kilo.js")).href;
4327
+ const entry = pathToFileURL(join18(c.dist, "kilo.js")).href;
3545
4328
  const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
3546
4329
  writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
3547
4330
  c.log?.(`kilo: plugin registered in ${path}`);
@@ -3549,7 +4332,7 @@ var kilo = {
3549
4332
  uninstall(c) {
3550
4333
  const path = kiloConfigPath(c);
3551
4334
  if (!existsSync10(path)) return;
3552
- const cfg = parseJsonc(readFileSync12(path, "utf8"));
4335
+ const cfg = parseJsonc(readFileSync14(path, "utf8"));
3553
4336
  if (!cfg || !Array.isArray(cfg.plugin)) return;
3554
4337
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
3555
4338
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -3558,9 +4341,9 @@ var kilo = {
3558
4341
  };
3559
4342
  var claudeCode = {
3560
4343
  name: "claude-code",
3561
- detect: (c) => onPath2("claude") || existsSync10(join16(c.home, ".claude")),
4344
+ detect: (c) => onPath2("claude") || existsSync10(join18(c.home, ".claude")),
3562
4345
  install(c) {
3563
- const path = join16(c.home, ".claude", "settings.json");
4346
+ const path = join18(c.home, ".claude", "settings.json");
3564
4347
  const settings = readJson(path);
3565
4348
  settings.hooks = settings.hooks ?? {};
3566
4349
  mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
@@ -3579,18 +4362,18 @@ var claudeCode = {
3579
4362
  "HINDSIGHT_MCP_HARNESS=claude-code",
3580
4363
  "--",
3581
4364
  "node",
3582
- join16(c.dist, "mcp-server.js")
4365
+ join18(c.dist, "mcp-server.js")
3583
4366
  ])) {
3584
4367
  c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
3585
4368
  } else {
3586
4369
  c.log?.(
3587
4370
  `claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
3588
- claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join16(c.dist, "mcp-server.js")}"`
4371
+ claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join18(c.dist, "mcp-server.js")}"`
3589
4372
  );
3590
4373
  }
3591
4374
  },
3592
4375
  uninstall(c) {
3593
- const path = join16(c.home, ".claude", "settings.json");
4376
+ const path = join18(c.home, ".claude", "settings.json");
3594
4377
  if (existsSync10(path)) {
3595
4378
  const settings = readJson(path);
3596
4379
  if (settings.hooks) {
@@ -3616,20 +4399,20 @@ function defaultClaudeMcp(args) {
3616
4399
  var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
3617
4400
  var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
3618
4401
  command = "node"
3619
- args = [${JSON.stringify(join16(dist, "mcp-server.js"))}]
4402
+ args = [${JSON.stringify(join18(dist, "mcp-server.js"))}]
3620
4403
  env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
3621
4404
  var codex = {
3622
4405
  name: "codex",
3623
- detect: (c) => onPath2("codex") || existsSync10(join16(c.home, ".codex")),
4406
+ detect: (c) => onPath2("codex") || existsSync10(join18(c.home, ".codex")),
3624
4407
  install(c) {
3625
- const hooksPath = join16(c.home, ".codex", "hooks.json");
4408
+ const hooksPath = join18(c.home, ".codex", "hooks.json");
3626
4409
  const cfg = readJson(hooksPath);
3627
4410
  cfg.hooks = cfg.hooks ?? {};
3628
4411
  mergeHarnessHooks(cfg.hooks, "codex", c.dist);
3629
4412
  writeJson(hooksPath, cfg);
3630
4413
  c.log?.(`codex: hooks merged into ${hooksPath}`);
3631
- const tomlPath = join16(c.home, ".codex", "config.toml");
3632
- const existing = existsSync10(tomlPath) ? readFileSync12(tomlPath, "utf8") : "";
4414
+ const tomlPath = join18(c.home, ".codex", "config.toml");
4415
+ const existing = existsSync10(tomlPath) ? readFileSync14(tomlPath, "utf8") : "";
3633
4416
  const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
3634
4417
  const additions = [];
3635
4418
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
@@ -3648,14 +4431,14 @@ var codex = {
3648
4431
  if (existsSync10(tomlPath) && !existsSync10(`${tomlPath}.hindsight-backup`)) {
3649
4432
  copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
3650
4433
  }
3651
- mkdirSync4(dirname10(tomlPath), { recursive: true });
3652
- writeFileSync3(tomlPath, next);
4434
+ mkdirSync6(dirname11(tomlPath), { recursive: true });
4435
+ writeFileSync4(tomlPath, next);
3653
4436
  c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
3654
4437
  }
3655
4438
  installSkill(c, "codex");
3656
4439
  },
3657
4440
  uninstall(c) {
3658
- const hooksPath = join16(c.home, ".codex", "hooks.json");
4441
+ const hooksPath = join18(c.home, ".codex", "hooks.json");
3659
4442
  if (existsSync10(hooksPath)) {
3660
4443
  const cfg = readJson(hooksPath);
3661
4444
  if (cfg.hooks) {
@@ -3664,11 +4447,11 @@ var codex = {
3664
4447
  }
3665
4448
  }
3666
4449
  uninstallSkill(c, "codex");
3667
- const tomlPath = join16(c.home, ".codex", "config.toml");
4450
+ const tomlPath = join18(c.home, ".codex", "config.toml");
3668
4451
  if (existsSync10(tomlPath)) {
3669
- const toml = readFileSync12(tomlPath, "utf8");
4452
+ const toml = readFileSync14(tomlPath, "utf8");
3670
4453
  const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
3671
- if (cleaned !== toml) writeFileSync3(tomlPath, cleaned);
4454
+ if (cleaned !== toml) writeFileSync4(tomlPath, cleaned);
3672
4455
  }
3673
4456
  c.log?.(
3674
4457
  "codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
@@ -3682,7 +4465,7 @@ var antigravity = {
3682
4465
  // can consume this integration.
3683
4466
  detect: (c) => onPath2("agy"),
3684
4467
  install(c) {
3685
- const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
4468
+ const hooksPath = join18(c.home, ".gemini", "config", "hooks.json");
3686
4469
  const hooks = readJson(hooksPath);
3687
4470
  for (const key of Object.keys(hooks)) {
3688
4471
  if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
@@ -3693,26 +4476,26 @@ var antigravity = {
3693
4476
  setOrDelete(hooks, event, stripOurs(hooks[event]));
3694
4477
  }
3695
4478
  writeJson(hooksPath, hooks);
3696
- const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
4479
+ const mcpPath = join18(c.home, ".gemini", "config", "mcp_config.json");
3697
4480
  const mcp = readJson(mcpPath);
3698
4481
  mcp.mcpServers = {
3699
4482
  ...mcp.mcpServers ?? {},
3700
4483
  hindsight: mcpServerEntry(c.dist, "antigravity-cli")
3701
4484
  };
3702
4485
  writeJson(mcpPath, mcp);
3703
- const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
4486
+ const settingsPath = join18(c.home, ".gemini", "antigravity-cli", "settings.json");
3704
4487
  const settings = readJson(settingsPath);
3705
4488
  if (!settings.statusLine) {
3706
4489
  settings.statusLine = {
3707
4490
  type: "command",
3708
- command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
4491
+ command: `node "${join18(c.dist, "antigravity-statusline.js")}"`
3709
4492
  };
3710
4493
  writeJson(settingsPath, settings);
3711
4494
  c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
3712
4495
  } else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
3713
4496
  settings.statusLine = {
3714
4497
  type: "command",
3715
- command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
4498
+ command: `node "${join18(c.dist, "antigravity-statusline.js")}"`
3716
4499
  };
3717
4500
  writeJson(settingsPath, settings);
3718
4501
  } else {
@@ -3724,7 +4507,7 @@ var antigravity = {
3724
4507
  installSkill(c, "antigravity-cli");
3725
4508
  },
3726
4509
  uninstall(c) {
3727
- const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
4510
+ const hooksPath = join18(c.home, ".gemini", "config", "hooks.json");
3728
4511
  if (existsSync10(hooksPath)) {
3729
4512
  const hooks = readJson(hooksPath);
3730
4513
  if (hooks[MARKER]) {
@@ -3736,7 +4519,7 @@ var antigravity = {
3736
4519
  }
3737
4520
  writeJson(hooksPath, hooks);
3738
4521
  }
3739
- const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
4522
+ const mcpPath = join18(c.home, ".gemini", "config", "mcp_config.json");
3740
4523
  if (existsSync10(mcpPath)) {
3741
4524
  const mcp = readJson(mcpPath);
3742
4525
  if (mcp.mcpServers?.hindsight) {
@@ -3744,7 +4527,7 @@ var antigravity = {
3744
4527
  writeJson(mcpPath, mcp);
3745
4528
  }
3746
4529
  }
3747
- const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
4530
+ const settingsPath = join18(c.home, ".gemini", "antigravity-cli", "settings.json");
3748
4531
  if (existsSync10(settingsPath)) {
3749
4532
  const settings = readJson(settingsPath);
3750
4533
  if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
@@ -3772,7 +4555,7 @@ function pathNodeVersion() {
3772
4555
  }
3773
4556
  }
3774
4557
  function runtimeDir(home) {
3775
- return join16(home, ".hindsight", "coding-agents");
4558
+ return join18(home, ".hindsight", "coding-agents");
3776
4559
  }
3777
4560
  var ORIGIN_FILE = ".install-origin.json";
3778
4561
  function stageRuntime(c) {
@@ -3785,25 +4568,25 @@ function stageRuntime(c) {
3785
4568
  }
3786
4569
  };
3787
4570
  if (same(c.pkgRoot, target)) return c;
3788
- if (!existsSync10(join16(c.dist, "installer.js"))) return c;
4571
+ if (!existsSync10(join18(c.dist, "installer.js"))) return c;
3789
4572
  try {
3790
- rmSync2(join16(target, "dist"), { recursive: true, force: true });
3791
- mkdirSync4(target, { recursive: true });
3792
- cpSync2(c.dist, join16(target, "dist"), { recursive: true });
3793
- const skill = join16(c.pkgRoot, "skill");
3794
- if (existsSync10(skill)) cpSync2(skill, join16(target, "skill"), { recursive: true });
3795
- const pkgJson = join16(c.pkgRoot, "package.json");
3796
- if (existsSync10(pkgJson)) copyFileSync(pkgJson, join16(target, "package.json"));
4573
+ rmSync3(join18(target, "dist"), { recursive: true, force: true });
4574
+ mkdirSync6(target, { recursive: true });
4575
+ cpSync2(c.dist, join18(target, "dist"), { recursive: true });
4576
+ const skill = join18(c.pkgRoot, "skill");
4577
+ if (existsSync10(skill)) cpSync2(skill, join18(target, "skill"), { recursive: true });
4578
+ const pkgJson = join18(c.pkgRoot, "package.json");
4579
+ if (existsSync10(pkgJson)) copyFileSync(pkgJson, join18(target, "package.json"));
3797
4580
  for (const resource of ["plugin.json", "hooks", "index.js"]) {
3798
- const source = join16(c.pkgRoot, resource);
3799
- if (existsSync10(source)) cpSync2(source, join16(target, resource), { recursive: true });
4581
+ const source = join18(c.pkgRoot, resource);
4582
+ if (existsSync10(source)) cpSync2(source, join18(target, resource), { recursive: true });
3800
4583
  }
3801
- writeFileSync3(
3802
- join16(target, ORIGIN_FILE),
4584
+ writeFileSync4(
4585
+ join18(target, ORIGIN_FILE),
3803
4586
  JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
3804
4587
  );
3805
4588
  c.log?.(`runtime staged at ${target}`);
3806
- return { ...c, pkgRoot: target, dist: join16(target, "dist") };
4589
+ return { ...c, pkgRoot: target, dist: join18(target, "dist") };
3807
4590
  } catch (error) {
3808
4591
  c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
3809
4592
  return c;
@@ -3881,7 +4664,7 @@ function configureServer(c, args, installing) {
3881
4664
  c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
3882
4665
  return false;
3883
4666
  }
3884
- const configPath = process.env.HINDSIGHT_CONFIG || join16(c.home, ...CONFIG_RELATIVE);
4667
+ const configPath = process.env.HINDSIGHT_CONFIG || join18(c.home, ...CONFIG_RELATIVE);
3885
4668
  const existing = readJson(configPath);
3886
4669
  const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
3887
4670
  let mode = explicit;
@@ -3977,7 +4760,7 @@ function reportDaemonPrereqs(c) {
3977
4760
  }
3978
4761
  var devin = {
3979
4762
  name: "devin-cli",
3980
- detect: (c) => onPath2("devin") || existsSync10(join16(c.home, ".config", "devin")),
4763
+ detect: (c) => onPath2("devin") || existsSync10(join18(c.home, ".config", "devin")),
3981
4764
  // Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
3982
4765
  // nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
3983
4766
  // support a hard prerequisite here — and one worth checking now, because the alternative is an
@@ -3990,12 +4773,12 @@ var devin = {
3990
4773
  Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
3991
4774
  },
3992
4775
  install(c) {
3993
- const configPath = join16(c.home, ".config", "devin", "config.json");
4776
+ const configPath = join18(c.home, ".config", "devin", "config.json");
3994
4777
  const config = readJson(configPath);
3995
4778
  config.hooks = config.hooks ?? {};
3996
4779
  mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
3997
4780
  writeJson(configPath, config);
3998
- const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
4781
+ const mcpPath = join18(c.home, ".config", "devin", "mcp_config.json");
3999
4782
  const mcp = readJson(mcpPath);
4000
4783
  mcp.mcpServers = {
4001
4784
  ...mcp.mcpServers ?? {},
@@ -4005,7 +4788,7 @@ var devin = {
4005
4788
  c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
4006
4789
  },
4007
4790
  uninstall(c) {
4008
- const configPath = join16(c.home, ".config", "devin", "config.json");
4791
+ const configPath = join18(c.home, ".config", "devin", "config.json");
4009
4792
  if (existsSync10(configPath)) {
4010
4793
  const config = readJson(configPath);
4011
4794
  if (config.hooks) {
@@ -4014,7 +4797,7 @@ var devin = {
4014
4797
  writeJson(configPath, config);
4015
4798
  }
4016
4799
  }
4017
- const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
4800
+ const mcpPath = join18(c.home, ".config", "devin", "mcp_config.json");
4018
4801
  if (existsSync10(mcpPath)) {
4019
4802
  const mcp = readJson(mcpPath);
4020
4803
  if (mcp.mcpServers?.hindsight) {
@@ -4027,14 +4810,14 @@ var devin = {
4027
4810
  };
4028
4811
  var cursor = {
4029
4812
  name: "cursor-cli",
4030
- detect: (c) => onPath2("cursor-agent") || existsSync10(join16(c.home, ".cursor")),
4813
+ detect: (c) => onPath2("cursor-agent") || existsSync10(join18(c.home, ".cursor")),
4031
4814
  install(c) {
4032
- const hooksPath = join16(c.home, ".cursor", "hooks.json");
4815
+ const hooksPath = join18(c.home, ".cursor", "hooks.json");
4033
4816
  const cfg = readJson(hooksPath);
4034
4817
  cfg.hooks = cfg.hooks ?? {};
4035
4818
  mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
4036
4819
  writeJson(hooksPath, cfg);
4037
- const mcpPath = join16(c.home, ".cursor", "mcp.json");
4820
+ const mcpPath = join18(c.home, ".cursor", "mcp.json");
4038
4821
  const mcp = readJson(mcpPath);
4039
4822
  mcp.mcpServers = {
4040
4823
  ...mcp.mcpServers ?? {},
@@ -4045,7 +4828,7 @@ var cursor = {
4045
4828
  installSkill(c, "cursor-cli");
4046
4829
  },
4047
4830
  uninstall(c) {
4048
- const hooksPath = join16(c.home, ".cursor", "hooks.json");
4831
+ const hooksPath = join18(c.home, ".cursor", "hooks.json");
4049
4832
  if (existsSync10(hooksPath)) {
4050
4833
  const cfg = readJson(hooksPath);
4051
4834
  if (cfg.hooks) {
@@ -4054,7 +4837,7 @@ var cursor = {
4054
4837
  writeJson(hooksPath, cfg);
4055
4838
  }
4056
4839
  }
4057
- const mcpPath = join16(c.home, ".cursor", "mcp.json");
4840
+ const mcpPath = join18(c.home, ".cursor", "mcp.json");
4058
4841
  if (existsSync10(mcpPath)) {
4059
4842
  const mcp = readJson(mcpPath);
4060
4843
  if (mcp.mcpServers?.hindsight) {
@@ -4068,13 +4851,13 @@ var cursor = {
4068
4851
  };
4069
4852
  var copilot = {
4070
4853
  name: "copilot-cli",
4071
- detect: (c) => onPath2("copilot") || existsSync10(join16(c.home, ".copilot")),
4854
+ detect: (c) => onPath2("copilot") || existsSync10(join18(c.home, ".copilot")),
4072
4855
  install(c) {
4073
- const hooksPath = join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
4856
+ const hooksPath = join18(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
4074
4857
  const hooks = {};
4075
4858
  mergeHarnessHooks(hooks, "copilot-cli", c.dist);
4076
4859
  writeJson(hooksPath, { version: 1, hooks });
4077
- const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
4860
+ const mcpPath = join18(c.home, ".copilot", "mcp-config.json");
4078
4861
  const mcp = readJson(mcpPath);
4079
4862
  mcp.mcpServers = {
4080
4863
  ...mcp.mcpServers ?? {},
@@ -4085,10 +4868,10 @@ var copilot = {
4085
4868
  c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
4086
4869
  },
4087
4870
  uninstall(c) {
4088
- rmSync2(join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
4871
+ rmSync3(join18(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
4089
4872
  force: true
4090
4873
  });
4091
- const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
4874
+ const mcpPath = join18(c.home, ".copilot", "mcp-config.json");
4092
4875
  if (existsSync10(mcpPath)) {
4093
4876
  const mcp = readJson(mcpPath);
4094
4877
  if (mcp.mcpServers?.hindsight) {
@@ -4102,15 +4885,66 @@ var copilot = {
4102
4885
  };
4103
4886
  var GROK_MARKER_START = "# HINDSIGHT_CODING_AGENTS_GROK_START";
4104
4887
  var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
4105
- var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
4888
+ var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`, "g");
4889
+ var GROK_HOOK_SCRIPT_RE = /(grok-(?:sessionstart-|stop-)?hook\.js|hindsight-coding-agents)/;
4890
+ function parseGrokToml(text) {
4891
+ try {
4892
+ return parse2(text);
4893
+ } catch {
4894
+ return null;
4895
+ }
4896
+ }
4897
+ function hasUnmarkedGrokEntries(text) {
4898
+ const cfg = parseGrokToml(text);
4899
+ if (!cfg)
4900
+ return /\[\s*mcp_servers\s*\.\s*hindsight\s*[.\]]/.test(text) || GROK_HOOK_SCRIPT_RE.test(text);
4901
+ if (cfg.mcp_servers && "hindsight" in cfg.mcp_servers) return true;
4902
+ return Object.values(cfg.hooks ?? {}).some(
4903
+ (entries) => (entries ?? []).some(
4904
+ (entry) => (entry?.hooks ?? []).some(
4905
+ (h) => typeof h?.command === "string" && GROK_HOOK_SCRIPT_RE.test(h.command)
4906
+ )
4907
+ )
4908
+ );
4909
+ }
4910
+ function stripUnmarkedGrokEntries(toml) {
4911
+ const lines = toml.split("\n");
4912
+ const sections = [{ header: "", lines: [] }];
4913
+ for (const line of lines) {
4914
+ if (/^\s*\[/.test(line)) sections.push({ header: line.trim(), lines: [line] });
4915
+ else sections[sections.length - 1].lines.push(line);
4916
+ }
4917
+ const isOurs = (s) => s.lines.some((l) => /^\s*(command|args)\s*=/.test(l) && GROK_HOOK_SCRIPT_RE.test(l));
4918
+ const hasKeys = (s) => s.lines.slice(1).some((l) => /^\s*[^#\s]/.test(l));
4919
+ const drop = sections.map((s) => {
4920
+ if (/^\[mcp_servers\.hindsight(\.|\])/.test(s.header)) return true;
4921
+ if (/^\[\[hooks\..+\.hooks\]\]$/.test(s.header)) return isOurs(s);
4922
+ return false;
4923
+ });
4924
+ for (let i = 0; i < sections.length; i++) {
4925
+ if (!/^\[\[hooks\.[^.\]]+\]\]$/.test(sections[i].header) || hasKeys(sections[i])) continue;
4926
+ let j = i + 1;
4927
+ let sawChild = false;
4928
+ while (j < sections.length && /^\[\[hooks\..+\.hooks\]\]$/.test(sections[j].header)) {
4929
+ if (!drop[j]) break;
4930
+ sawChild = true;
4931
+ j++;
4932
+ }
4933
+ const childrenAllDropped = sawChild && (j >= sections.length || !/^\[\[hooks\..+\.hooks\]\]$/.test(sections[j].header));
4934
+ if (childrenAllDropped) drop[i] = true;
4935
+ }
4936
+ if (!drop.some(Boolean)) return toml;
4937
+ return sections.filter((_, i) => !drop[i]).map((s) => s.lines.join("\n")).join("\n").replace(/\n{3,}/g, "\n\n");
4938
+ }
4106
4939
  var grok = {
4107
4940
  name: "grok-build",
4108
- detect: (c) => onPath2("grok") || existsSync10(join16(c.home, ".grok")),
4941
+ detect: (c) => onPath2("grok") || existsSync10(join18(c.home, ".grok")),
4109
4942
  install(c) {
4110
- const path = join16(c.home, ".grok", "config.toml");
4111
- const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
4112
- const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
4113
- const command = (entry) => JSON.stringify(`node "${join16(c.dist, entry)}"`);
4943
+ const path = join18(c.home, ".grok", "config.toml");
4944
+ const existing = existsSync10(path) ? readFileSync14(path, "utf8") : "";
4945
+ const stripped = existing.replace(GROK_BLOCK_RE, "\n");
4946
+ const withoutOurs = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
4947
+ const command = (entry) => JSON.stringify(`node "${join18(c.dist, entry)}"`);
4114
4948
  const tomlString = (value) => JSON.stringify(value);
4115
4949
  const block = `
4116
4950
  ${GROK_MARKER_START}
@@ -4134,23 +4968,32 @@ ${GROK_MARKER_START}
4134
4968
 
4135
4969
  [mcp_servers.hindsight]
4136
4970
  command = "node"
4137
- args = [${tomlString(join16(c.dist, "mcp-server.js"))}]
4971
+ args = [${tomlString(join18(c.dist, "mcp-server.js"))}]
4138
4972
  env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
4139
4973
  ${GROK_MARKER_END}
4140
4974
  `;
4975
+ const next = `${withoutOurs.replace(/\n*$/, "\n")}${block}`;
4976
+ if (parseGrokToml(next) === null) {
4977
+ c.log?.(
4978
+ `grok-build: refusing to write ${path} \u2014 the result would not be valid TOML. Remove the Hindsight hooks and [mcp_servers.hindsight] from it by hand, then re-run install.`
4979
+ );
4980
+ return false;
4981
+ }
4141
4982
  if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
4142
4983
  copyFileSync(path, `${path}.hindsight-backup`);
4143
- mkdirSync4(dirname10(path), { recursive: true });
4144
- writeFileSync3(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
4984
+ mkdirSync6(dirname11(path), { recursive: true });
4985
+ writeFileSync4(path, next);
4145
4986
  installSkill(c, "grok-build");
4146
4987
  c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
4147
4988
  },
4148
4989
  uninstall(c) {
4149
- const path = join16(c.home, ".grok", "config.toml");
4990
+ const path = join18(c.home, ".grok", "config.toml");
4150
4991
  if (existsSync10(path)) {
4151
- const existing = readFileSync12(path, "utf8");
4152
- const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
4153
- if (cleaned !== existing) writeFileSync3(path, cleaned);
4992
+ const existing = readFileSync14(path, "utf8");
4993
+ const stripped = existing.replace(GROK_BLOCK_RE, "\n");
4994
+ const cleaned = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
4995
+ const safe = parseGrokToml(cleaned) !== null || parseGrokToml(existing) === null;
4996
+ if (cleaned !== existing && safe) writeFileSync4(path, cleaned);
4154
4997
  }
4155
4998
  uninstallSkill(c, "grok-build");
4156
4999
  c.log?.("grok-build: native hooks + MCP + skill removed");
@@ -4160,17 +5003,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
4160
5003
  var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
4161
5004
  var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
4162
5005
  function removeLegacyClineHooks(c) {
4163
- const hooksDir = join16(c.home, "Documents", "Cline", "Hooks");
5006
+ const hooksDir = join18(c.home, "Documents", "Cline", "Hooks");
4164
5007
  for (const event of CLINE_OLD_HOOK_EVENTS) {
4165
- const path = join16(hooksDir, event);
4166
- if (existsSync10(path) && readFileSync12(path, "utf8").includes(CLINE_HOOK_MARKER)) {
4167
- rmSync2(path, { force: true });
5008
+ const path = join18(hooksDir, event);
5009
+ if (existsSync10(path) && readFileSync14(path, "utf8").includes(CLINE_HOOK_MARKER)) {
5010
+ rmSync3(path, { force: true });
4168
5011
  }
4169
5012
  }
4170
5013
  }
4171
5014
  var cline = {
4172
5015
  name: "cline-cli",
4173
- detect: (c) => onPath2("cline") || existsSync10(join16(c.home, ".cline")),
5016
+ detect: (c) => onPath2("cline") || existsSync10(join18(c.home, ".cline")),
4174
5017
  install(c) {
4175
5018
  removeLegacyClineHooks(c);
4176
5019
  const installed = (c.clinePlugin ?? runClinePlugin)([
@@ -4179,7 +5022,7 @@ var cline = {
4179
5022
  "--force",
4180
5023
  c.pkgRoot
4181
5024
  ]);
4182
- const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
5025
+ const mcpPath = join18(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4183
5026
  const mcp = readJson(mcpPath);
4184
5027
  mcp.mcpServers = {
4185
5028
  ...mcp.mcpServers ?? {},
@@ -4194,7 +5037,7 @@ var cline = {
4194
5037
  uninstall(c) {
4195
5038
  removeLegacyClineHooks(c);
4196
5039
  (c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
4197
- const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
5040
+ const mcpPath = join18(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4198
5041
  if (existsSync10(mcpPath)) {
4199
5042
  const mcp = readJson(mcpPath);
4200
5043
  if (mcp.mcpServers?.hindsight) {
@@ -4208,31 +5051,31 @@ var cline = {
4208
5051
  };
4209
5052
  var DCODE_MARKETPLACE = "hindsight-coding-agents";
4210
5053
  var DCODE_PLUGIN_ID = "hindsight-coding-agents@hindsight-coding-agents";
4211
- var DCODE_MARKETPLACE_RELATIVE_PATH = join16(".agents", "plugins", "marketplace.json");
5054
+ var DCODE_MARKETPLACE_RELATIVE_PATH = join18(".agents", "plugins", "marketplace.json");
4212
5055
  var DCODE_FALLBACK_MARKETPLACE = "hindsight-coding-agents-marketplace.json";
4213
5056
  function prepareDcodeMarketplace(c) {
4214
- const root = join16(c.home, ".hindsight");
4215
- const conventionalPath = join16(root, DCODE_MARKETPLACE_RELATIVE_PATH);
5057
+ const root = join18(c.home, ".hindsight");
5058
+ const conventionalPath = join18(root, DCODE_MARKETPLACE_RELATIVE_PATH);
4216
5059
  let path = conventionalPath;
4217
5060
  let registrationSource = root;
4218
5061
  let marketplace = { plugins: [] };
4219
5062
  if (existsSync10(conventionalPath)) {
4220
5063
  try {
4221
- const parsed = JSON.parse(readFileSync12(conventionalPath, "utf8"));
5064
+ const parsed = JSON.parse(readFileSync14(conventionalPath, "utf8"));
4222
5065
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
4223
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
5066
+ path = join18(root, DCODE_FALLBACK_MARKETPLACE);
4224
5067
  } else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
4225
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
5068
+ path = join18(root, DCODE_FALLBACK_MARKETPLACE);
4226
5069
  } else {
4227
5070
  marketplace = parsed;
4228
5071
  }
4229
5072
  } catch {
4230
- path = join16(root, DCODE_FALLBACK_MARKETPLACE);
5073
+ path = join18(root, DCODE_FALLBACK_MARKETPLACE);
4231
5074
  }
4232
5075
  }
4233
5076
  if (path !== conventionalPath && existsSync10(path)) {
4234
5077
  try {
4235
- const parsed = JSON.parse(readFileSync12(path, "utf8"));
5078
+ const parsed = JSON.parse(readFileSync14(path, "utf8"));
4236
5079
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
4237
5080
  c.log?.(`dcode: refusing to replace malformed marketplace file ${path}`);
4238
5081
  return false;
@@ -4260,7 +5103,7 @@ function prepareDcodeMarketplace(c) {
4260
5103
  }
4261
5104
  var dcode = {
4262
5105
  name: "dcode",
4263
- detect: (c) => onPath2("dcode") || existsSync10(join16(c.home, ".deepagents")),
5106
+ detect: (c) => onPath2("dcode") || existsSync10(join18(c.home, ".deepagents")),
4264
5107
  preflight: (c) => c.dcodePlugin || onPath2("dcode") ? void 0 : "the `dcode` CLI is not on PATH",
4265
5108
  install(c) {
4266
5109
  const plugin = c.dcodePlugin ?? runDcodePlugin;
@@ -4269,7 +5112,7 @@ var dcode = {
4269
5112
  if (installed) {
4270
5113
  c.log?.(`dcode: native Agent Plugin installed (${DCODE_PLUGIN_ID})`);
4271
5114
  } else {
4272
- const source = marketplacePath === false ? join16(c.home, ".hindsight") : marketplacePath;
5115
+ const source = marketplacePath === false ? join18(c.home, ".hindsight") : marketplacePath;
4273
5116
  c.log?.(
4274
5117
  `dcode: could not install the native plugin \u2014 run dcode plugin marketplace add "${source}" && dcode plugin install ${DCODE_PLUGIN_ID}`
4275
5118
  );
@@ -4297,16 +5140,16 @@ var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
4297
5140
  var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
4298
5141
  var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
4299
5142
  function dshHome(c) {
4300
- return process.env.DSH_HOME || join16(c.home, ".dsh");
5143
+ return process.env.DSH_HOME || join18(c.home, ".dsh");
4301
5144
  }
4302
5145
  var dsh = {
4303
5146
  name: "dsh",
4304
5147
  detect: (c) => onPath2("dsh") || existsSync10(dshHome(c)),
4305
5148
  install(c) {
4306
- const path = join16(dshHome(c), "cordis.patch.yml");
4307
- const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
5149
+ const path = join18(dshHome(c), "cordis.patch.yml");
5150
+ const existing = existsSync10(path) ? readFileSync14(path, "utf8") : "";
4308
5151
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
4309
- const entry = pathToFileURL(join16(c.dist, "dsh.js")).href;
5152
+ const entry = pathToFileURL(join18(c.dist, "dsh.js")).href;
4310
5153
  const block = `${DSH_MARKER_START}
4311
5154
  - insert:
4312
5155
  - id: hindsight
@@ -4315,19 +5158,19 @@ ${DSH_MARKER_END}
4315
5158
  `;
4316
5159
  if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
4317
5160
  copyFileSync(path, `${path}.hindsight-backup`);
4318
- mkdirSync4(dirname10(path), { recursive: true });
4319
- writeFileSync3(path, others ? `${others}
5161
+ mkdirSync6(dirname11(path), { recursive: true });
5162
+ writeFileSync4(path, others ? `${others}
4320
5163
 
4321
5164
  ${block}` : block);
4322
5165
  installSkill(c, "dsh");
4323
5166
  c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
4324
5167
  },
4325
5168
  uninstall(c) {
4326
- const path = join16(dshHome(c), "cordis.patch.yml");
5169
+ const path = join18(dshHome(c), "cordis.patch.yml");
4327
5170
  if (existsSync10(path)) {
4328
- const existing = readFileSync12(path, "utf8");
5171
+ const existing = readFileSync14(path, "utf8");
4329
5172
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
4330
- if (others !== existing.trim()) writeFileSync3(path, others ? `${others}
5173
+ if (others !== existing.trim()) writeFileSync4(path, others ? `${others}
4331
5174
  ` : "[]\n");
4332
5175
  }
4333
5176
  uninstallSkill(c, "dsh");
@@ -4336,9 +5179,9 @@ ${block}` : block);
4336
5179
  };
4337
5180
  var qwen = {
4338
5181
  name: "qwen-code",
4339
- detect: (c) => onPath2("qwen") || existsSync10(join16(c.home, ".qwen")),
5182
+ detect: (c) => onPath2("qwen") || existsSync10(join18(c.home, ".qwen")),
4340
5183
  install(c) {
4341
- const path = join16(c.home, ".qwen", "settings.json");
5184
+ const path = join18(c.home, ".qwen", "settings.json");
4342
5185
  const settings = readJson(path);
4343
5186
  settings.hooks = settings.hooks ?? {};
4344
5187
  mergeHarnessHooks(settings.hooks, "qwen-code", c.dist);
@@ -4356,18 +5199,18 @@ var qwen = {
4356
5199
  "HINDSIGHT_MCP_HARNESS=qwen-code",
4357
5200
  "hindsight",
4358
5201
  "node",
4359
- join16(c.dist, "mcp-server.js")
5202
+ join18(c.dist, "mcp-server.js")
4360
5203
  ])) {
4361
5204
  c.log?.("qwen-code: MCP server registered (qwen mcp add, user scope)");
4362
5205
  } else {
4363
5206
  c.log?.(
4364
5207
  `qwen-code: could not run \`qwen mcp add\` \u2014 register the tools manually:
4365
- qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join16(c.dist, "mcp-server.js")}"`
5208
+ qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join18(c.dist, "mcp-server.js")}"`
4366
5209
  );
4367
5210
  }
4368
5211
  },
4369
5212
  uninstall(c) {
4370
- const path = join16(c.home, ".qwen", "settings.json");
5213
+ const path = join18(c.home, ".qwen", "settings.json");
4371
5214
  if (existsSync10(path)) {
4372
5215
  const settings = readJson(path);
4373
5216
  if (settings.hooks) {
@@ -4392,19 +5235,19 @@ function defaultQwenMcp(args) {
4392
5235
  }
4393
5236
  var factoryDroid = {
4394
5237
  name: "factory-droid",
4395
- detect: (c) => onPath2("droid") || existsSync10(join16(c.home, ".factory")),
5238
+ detect: (c) => onPath2("droid") || existsSync10(join18(c.home, ".factory")),
4396
5239
  preflight(c) {
4397
- const mcpPath = join16(c.home, ".factory", "mcp.json");
5240
+ const mcpPath = join18(c.home, ".factory", "mcp.json");
4398
5241
  const existing = readJson(mcpPath).mcpServers?.hindsight;
4399
5242
  if (existing && !isOurMcpEntry(existing)) {
4400
5243
  return `${mcpPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
4401
5244
  }
4402
5245
  },
4403
5246
  install(c) {
4404
- const hooksPath = join16(c.home, ".factory", "hooks.json");
5247
+ const hooksPath = join18(c.home, ".factory", "hooks.json");
4405
5248
  const hooks = readJson(hooksPath);
4406
5249
  if (!existsSync10(hooksPath)) {
4407
- const fallback = readJson(join16(c.home, ".factory", "settings.json")).hooks;
5250
+ const fallback = readJson(join18(c.home, ".factory", "settings.json")).hooks;
4408
5251
  if (fallback && typeof fallback === "object" && !Array.isArray(fallback)) {
4409
5252
  Object.assign(hooks, fallback);
4410
5253
  }
@@ -4413,7 +5256,7 @@ var factoryDroid = {
4413
5256
  writeJson(hooksPath, hooks);
4414
5257
  c.log?.(`factory-droid: hooks merged into ${hooksPath}`);
4415
5258
  installSkill(c, "factory-droid");
4416
- const mcpPath = join16(c.home, ".factory", "mcp.json");
5259
+ const mcpPath = join18(c.home, ".factory", "mcp.json");
4417
5260
  const mcp = readJson(mcpPath);
4418
5261
  mcp.mcpServers = mcp.mcpServers ?? {};
4419
5262
  mcp.mcpServers.hindsight = mcpServerEntry(c.dist, "factory-droid");
@@ -4421,26 +5264,70 @@ var factoryDroid = {
4421
5264
  c.log?.(`factory-droid: MCP server registered in ${mcpPath}`);
4422
5265
  },
4423
5266
  uninstall(c) {
4424
- const hooksPath = join16(c.home, ".factory", "hooks.json");
5267
+ const hooksPath = join18(c.home, ".factory", "hooks.json");
4425
5268
  if (existsSync10(hooksPath)) {
4426
5269
  const hooks = readJson(hooksPath);
4427
5270
  stripHarnessHooks(hooks, "factory-droid");
4428
5271
  if (Object.keys(hooks).length) writeJson(hooksPath, hooks);
4429
- else rmSync2(hooksPath);
5272
+ else rmSync3(hooksPath);
4430
5273
  }
4431
- const mcpPath = join16(c.home, ".factory", "mcp.json");
5274
+ const mcpPath = join18(c.home, ".factory", "mcp.json");
4432
5275
  if (existsSync10(mcpPath)) {
4433
5276
  const mcp = readJson(mcpPath);
4434
5277
  if (isOurMcpEntry(mcp.mcpServers?.hindsight)) {
4435
5278
  delete mcp.mcpServers.hindsight;
4436
5279
  if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
4437
- else rmSync2(mcpPath);
5280
+ else rmSync3(mcpPath);
4438
5281
  }
4439
5282
  }
4440
5283
  uninstallSkill(c, "factory-droid");
4441
5284
  c.log?.("factory-droid: hooks + MCP registration + skill removed");
4442
5285
  }
4443
5286
  };
5287
+ var zcode = {
5288
+ name: "zcode",
5289
+ detect: (c) => onPath2("zcode") || existsSync10(join18(c.home, ".zcode")),
5290
+ preflight(c) {
5291
+ const configPath = zcodeConfigPath(c);
5292
+ const existing = readJson(configPath).mcp?.servers?.hindsight;
5293
+ if (existing && !isOurMcpEntry(existing)) {
5294
+ return `${configPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
5295
+ }
5296
+ },
5297
+ install(c) {
5298
+ const configPath = zcodeConfigPath(c);
5299
+ const config = readJson(configPath);
5300
+ const hooks = config.hooks = config.hooks ?? {};
5301
+ hooks.enabled = true;
5302
+ hooks.maxOutputBytes = hooks.maxOutputBytes ?? ZCODE_MAX_OUTPUT_BYTES;
5303
+ hooks.events = hooks.events ?? {};
5304
+ mergeHarnessHooks(hooks.events, "zcode", c.dist);
5305
+ config.mcp = config.mcp ?? {};
5306
+ config.mcp.servers = config.mcp.servers ?? {};
5307
+ config.mcp.servers.hindsight = mcpServerEntry(c.dist, "zcode");
5308
+ writeJson(configPath, config);
5309
+ c.log?.(`zcode: hooks + MCP server merged into ${configPath}`);
5310
+ installSkill(c, "zcode");
5311
+ },
5312
+ uninstall(c) {
5313
+ const configPath = zcodeConfigPath(c);
5314
+ if (existsSync10(configPath)) {
5315
+ const config = readJson(configPath);
5316
+ if (isOurMcpEntry(config.mcp?.servers?.hindsight)) {
5317
+ delete config.mcp.servers.hindsight;
5318
+ if (!Object.keys(config.mcp.servers).length) delete config.mcp;
5319
+ }
5320
+ const hooks = config.hooks;
5321
+ if (hooks?.events) {
5322
+ stripHarnessHooks(hooks.events, "zcode");
5323
+ if (!Object.keys(hooks.events).length) delete config.hooks;
5324
+ }
5325
+ writeJson(configPath, config);
5326
+ }
5327
+ uninstallSkill(c, "zcode");
5328
+ c.log?.(`zcode: hooks + MCP registration + skill removed`);
5329
+ }
5330
+ };
4444
5331
  var INSTALLERS = [
4445
5332
  opencode,
4446
5333
  opencode2,
@@ -4458,7 +5345,8 @@ var INSTALLERS = [
4458
5345
  cline,
4459
5346
  dcode,
4460
5347
  dsh,
4461
- factoryDroid
5348
+ factoryDroid,
5349
+ zcode
4462
5350
  ];
4463
5351
  var HARNESS_ALIASES = { agy: "antigravity-cli" };
4464
5352
  function importConversations(harness, ctx) {
@@ -4478,18 +5366,18 @@ function importConversations(harness, ctx) {
4478
5366
  return;
4479
5367
  }
4480
5368
  const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
4481
- const file = join16(mkdtempSync(join16(tmpdir4(), "hindsight-import-")), "conversations.json");
4482
- writeFileSync3(file, JSON.stringify(found.sessions));
5369
+ const file = join18(mkdtempSync2(join18(tmpdir6(), "hindsight-import-")), "conversations.json");
5370
+ writeFileSync4(file, JSON.stringify(found.sessions));
4483
5371
  ctx.log?.(
4484
5372
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
4485
5373
  );
4486
5374
  try {
4487
- execFileSync6("node", [join16(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
5375
+ execFileSync6("node", [join18(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
4488
5376
  stdio: "inherit"
4489
5377
  });
4490
5378
  } catch {
4491
5379
  ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
4492
- ctx.log?.(` node "${join16(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
5380
+ ctx.log?.(` node "${join18(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
4493
5381
  }
4494
5382
  }
4495
5383
  function run(argv, ctxIn) {
@@ -4588,11 +5476,11 @@ var mainPath = process.argv[1] ? (() => {
4588
5476
  })() : void 0;
4589
5477
  var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
4590
5478
  if (isMain || mainPath?.endsWith("installer.js")) {
4591
- const dist = dirname10(fileURLToPath6(import.meta.url));
4592
- const pkgRoot = dirname10(dist);
5479
+ const dist = dirname11(fileURLToPath6(import.meta.url));
5480
+ const pkgRoot = dirname11(dist);
4593
5481
  let version;
4594
5482
  try {
4595
- version = JSON.parse(readFileSync12(join16(pkgRoot, "package.json"), "utf8")).version;
5483
+ version = JSON.parse(readFileSync14(join18(pkgRoot, "package.json"), "utf8")).version;
4596
5484
  } catch {
4597
5485
  version = void 0;
4598
5486
  }
@@ -4633,3 +5521,42 @@ export {
4633
5521
  run,
4634
5522
  runtimeDir
4635
5523
  };
5524
+ /*! Bundled license information:
5525
+
5526
+ smol-toml/dist/date.js:
5527
+ smol-toml/dist/error.js:
5528
+ smol-toml/dist/util.js:
5529
+ smol-toml/dist/primitive.js:
5530
+ smol-toml/dist/extract.js:
5531
+ smol-toml/dist/struct.js:
5532
+ smol-toml/dist/parse.js:
5533
+ smol-toml/dist/stringify.js:
5534
+ smol-toml/dist/index.js:
5535
+ (*!
5536
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
5537
+ * SPDX-License-Identifier: BSD-3-Clause
5538
+ *
5539
+ * Redistribution and use in source and binary forms, with or without
5540
+ * modification, are permitted provided that the following conditions are met:
5541
+ *
5542
+ * 1. Redistributions of source code must retain the above copyright notice, this
5543
+ * list of conditions and the following disclaimer.
5544
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
5545
+ * this list of conditions and the following disclaimer in the
5546
+ * documentation and/or other materials provided with the distribution.
5547
+ * 3. Neither the name of the copyright holder nor the names of its contributors
5548
+ * may be used to endorse or promote products derived from this software without
5549
+ * specific prior written permission.
5550
+ *
5551
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
5552
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
5553
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5554
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5555
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5556
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5557
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5558
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5559
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5560
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5561
+ *)
5562
+ */