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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/installer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/installer.ts
4
- import { execFileSync as execFileSync5 } from "child_process";
4
+ import { execFileSync as execFileSync6 } from "child_process";
5
5
  import {
6
6
  copyFileSync,
7
7
  cpSync as cpSync2,
@@ -9,12 +9,13 @@ import {
9
9
  mkdirSync as mkdirSync3,
10
10
  mkdtempSync,
11
11
  readFileSync as readFileSync15,
12
- readSync as readSync2,
12
+ readSync as readSync3,
13
13
  realpathSync,
14
14
  rmSync,
15
15
  writeFileSync as writeFileSync2
16
16
  } from "fs";
17
17
  import { homedir as homedir9, tmpdir as tmpdir3 } from "os";
18
+ import { isatty } from "tty";
18
19
  import { dirname as dirname8, join as join13 } from "path";
19
20
  import { fileURLToPath as fileURLToPath5, pathToFileURL } from "url";
20
21
 
@@ -85,6 +86,20 @@ function diag(harness, event, extra = {}) {
85
86
  }
86
87
  }
87
88
 
89
+ // src/core/brand.ts
90
+ function brandWord() {
91
+ const start = [0, 116, 217];
92
+ const end = [0, 146, 150];
93
+ const word = "Hindsight";
94
+ let out = "";
95
+ for (let i = 0; i < word.length; i++) {
96
+ const t = i / (word.length - 1);
97
+ const [r, g, b] = start.map((s, k) => Math.round(s + (end[k] - s) * t));
98
+ out += `\x1B[38;2;${r};${g};${b}m${word[i]}`;
99
+ }
100
+ return `${out}\x1B[0m`;
101
+ }
102
+
88
103
  // src/core/session-cache.ts
89
104
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
90
105
  import { tmpdir as tmpdir2 } from "os";
@@ -1005,6 +1020,204 @@ function readOne(harness, home) {
1005
1020
  };
1006
1021
  }
1007
1022
 
1023
+ // src/install-ui.ts
1024
+ import { execFileSync as execFileSync5 } from "child_process";
1025
+ import { readSync as readSync2 } from "fs";
1026
+ function fitSelectRow(label, hint, width) {
1027
+ const room = Math.max(10, width - 6);
1028
+ let hintText = hint ? ` \u2014 ${hint}` : "";
1029
+ if (label.length > room) return { label: `${label.slice(0, room - 1)}\u2026`, hint: "" };
1030
+ if (label.length + hintText.length > room) {
1031
+ hintText = `${hintText.slice(0, room - label.length - 1)}\u2026`;
1032
+ }
1033
+ return { label, hint: hintText };
1034
+ }
1035
+ function splitKeys(chunk) {
1036
+ const keys = [];
1037
+ for (let i = 0; i < chunk.length; ) {
1038
+ if (chunk[i] === "\x1B" && chunk[i + 1] === "[") {
1039
+ let j = i + 2;
1040
+ while (j < chunk.length && !(chunk[j] >= "@" && chunk[j] <= "~")) j++;
1041
+ keys.push(chunk.slice(i, Math.min(j + 1, chunk.length)));
1042
+ i = j + 1;
1043
+ } else {
1044
+ keys.push(chunk[i]);
1045
+ i += 1;
1046
+ }
1047
+ }
1048
+ return keys;
1049
+ }
1050
+ function selectKeyAction(key, index, count) {
1051
+ if (key === "\x1B[A" || key === "k") return { kind: "move", index: (index + count - 1) % count };
1052
+ if (key === "\x1B[B" || key === "j") return { kind: "move", index: (index + 1) % count };
1053
+ if (key === "\r" || key === "\n") return { kind: "submit", index };
1054
+ if (key === "" || key === "\x1B" || key === "q") return { kind: "cancel", index };
1055
+ const digit = Number.parseInt(key, 10);
1056
+ if (digit >= 1 && digit <= count) return { kind: "submit", index: digit - 1 };
1057
+ return { kind: "none", index };
1058
+ }
1059
+ var WARN_RE = /\bskipped\b|could not|manually|preserved|did not finish|unrecognised|add `hooks = true`/i;
1060
+ var ERROR_RE = /unknown harness|no supported coding agents|name a harness/;
1061
+ var INFO_RE = /^usage:|^detected: |\?$/;
1062
+ var EMOJI_KIND = {
1063
+ "\u2705": "ok",
1064
+ "\u26A0\uFE0F": "warn",
1065
+ "\u274C": "error"
1066
+ };
1067
+ function createInstallerUi(o) {
1068
+ const sink = o.write ?? ((line) => console.log(line));
1069
+ let lastLine = "";
1070
+ const write2 = (line) => {
1071
+ lastLine = line;
1072
+ sink(line);
1073
+ };
1074
+ const colors = o.colors ?? (process.stdout.isTTY === true && process.env.NO_COLOR === void 0 && process.env.TERM !== "dumb");
1075
+ const now = o.now ?? Date.now;
1076
+ const paint = (code, s) => colors ? `\x1B[${code}m${s}\x1B[0m` : s;
1077
+ const dim = (s) => paint("2", s);
1078
+ const bold = (s) => paint("1", s);
1079
+ const green = (s) => paint("32", s);
1080
+ const yellow = (s) => paint("33", s);
1081
+ const red = (s) => paint("31", s);
1082
+ const cyan = (s) => paint("36", s);
1083
+ const bar = dim("\u2502");
1084
+ const symbol = { ok: green("\u2713"), warn: yellow("\u25B2"), error: red("\u2716"), info: dim("\u25CB") };
1085
+ const tidy = (s) => s.replaceAll(o.home, "~");
1086
+ const dimPaths = (s) => s.replace(/(?<![:\w/])~?\/[^\s"',)]+/g, (m) => dim(m));
1087
+ const prefixRe = new RegExp(`^(${[...o.harnessNames, ...o.auxNames ?? []].join("|")}): `);
1088
+ const startedAt = now();
1089
+ let group = null;
1090
+ let groups = 0;
1091
+ function classify(line) {
1092
+ if (INFO_RE.test(line)) return "info";
1093
+ if (ERROR_RE.test(line)) return "error";
1094
+ if (WARN_RE.test(line)) return "warn";
1095
+ return "ok";
1096
+ }
1097
+ const spacer = () => {
1098
+ if (lastLine !== bar) write2(bar);
1099
+ };
1100
+ function openGroup(name) {
1101
+ spacer();
1102
+ write2(`${cyan("\u25C7")} ${bold(name)}`);
1103
+ group = name;
1104
+ if (o.harnessNames.includes(name)) groups++;
1105
+ }
1106
+ return {
1107
+ intro() {
1108
+ write2("");
1109
+ write2(
1110
+ `${dim("\u250C")} ${colors ? brandWord() : "Hindsight"} ${bold("coding agents")}` + (o.version ? ` ${dim(`v${o.version}`)}` : "")
1111
+ );
1112
+ write2(bar);
1113
+ },
1114
+ /** Style an interactive question so readline prompts sit on the rail like log lines. */
1115
+ prompt(question) {
1116
+ return `${bar} ${question}`;
1117
+ },
1118
+ select(question, options, defaultIndex) {
1119
+ const stty = (args) => execFileSync5("stty", args, { stdio: ["inherit", "pipe", "pipe"], encoding: "utf8" }).trim();
1120
+ let savedTty;
1121
+ try {
1122
+ savedTty = stty(["-g"]);
1123
+ stty(["raw", "-echo"]);
1124
+ } catch {
1125
+ return void 0;
1126
+ }
1127
+ const render = (index2, redraw) => {
1128
+ const width = process.stdout.columns || 80;
1129
+ const rows = options.map((opt, i) => {
1130
+ const on = i === index2;
1131
+ const pointer = on ? cyan("\u276F") : " ";
1132
+ const fitted = fitSelectRow(opt.label, opt.hint, width);
1133
+ const label = on ? bold(fitted.label) : fitted.label;
1134
+ return `\x1B[2K${bar} ${pointer} ${label}${fitted.hint ? dim(fitted.hint) : ""}`;
1135
+ });
1136
+ if (redraw) process.stdout.write(`\x1B[${options.length}A`);
1137
+ process.stdout.write(rows.map((r) => `\r${r}\r
1138
+ `).join(""));
1139
+ };
1140
+ lastLine = "select";
1141
+ process.stdout.write("\x1B[?7l");
1142
+ process.stdout.write(`${bar} ${symbol.info} ${dim(question)} ${dim("(\u2191/\u2193, Enter)")}\r
1143
+ `);
1144
+ let index = Math.min(Math.max(defaultIndex, 0), options.length - 1);
1145
+ render(index, false);
1146
+ const buf = Buffer.alloc(16);
1147
+ try {
1148
+ for (; ; ) {
1149
+ let n;
1150
+ try {
1151
+ n = readSync2(0, buf, 0, buf.length, null);
1152
+ } catch (e) {
1153
+ if (e.code !== "EAGAIN") return null;
1154
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
1155
+ continue;
1156
+ }
1157
+ if (n === 0) return null;
1158
+ for (const key of splitKeys(buf.subarray(0, n).toString("latin1"))) {
1159
+ const action = selectKeyAction(key, index, options.length);
1160
+ index = action.index;
1161
+ if (action.kind === "move") render(index, true);
1162
+ else if (action.kind === "submit") {
1163
+ render(index, true);
1164
+ return index;
1165
+ } else if (action.kind === "cancel") return null;
1166
+ }
1167
+ }
1168
+ } finally {
1169
+ process.stdout.write("\x1B[?7h");
1170
+ try {
1171
+ stty([savedTty]);
1172
+ } catch {
1173
+ }
1174
+ }
1175
+ },
1176
+ log(message) {
1177
+ const text = tidy(message).replace(/^\n+|\n+$/g, "");
1178
+ if (!text) return;
1179
+ const lines = text.split("\n");
1180
+ if (/^\s/.test(lines[0])) {
1181
+ for (const l of lines) write2(`${bar} ${dim(l.trim())}`);
1182
+ return;
1183
+ }
1184
+ const emoji = lines[0].match(/^(✅|❌|⚠️)\s*/u);
1185
+ if (emoji) lines[0] = lines[0].slice(emoji[0].length);
1186
+ const prefixed = lines[0].match(prefixRe);
1187
+ if (prefixed) {
1188
+ if (prefixed[1] !== group) openGroup(prefixed[1]);
1189
+ lines[0] = lines[0].slice(prefixed[0].length);
1190
+ }
1191
+ const kind = emoji ? EMOJI_KIND[emoji[1]] : classify(lines[0]);
1192
+ write2(`${bar} ${symbol[kind]} ${kind === "info" ? dim(lines[0]) : dimPaths(lines[0])}`);
1193
+ for (const rest of lines.slice(1)) write2(`${bar} ${dim(rest.trim())}`);
1194
+ },
1195
+ outro(exitCode) {
1196
+ spacer();
1197
+ if (exitCode !== 0) {
1198
+ write2(
1199
+ `${dim("\u2514")} ${red("\u2716")} ${groups ? "Completed with errors \u2014 see above." : "Aborted \u2014 nothing was changed."}`
1200
+ );
1201
+ } else if (o.command === "install" || o.command === "uninstall") {
1202
+ const secs = ((now() - startedAt) / 1e3).toFixed(1);
1203
+ const agents = `${groups} agent${groups === 1 ? "" : "s"}`;
1204
+ if (o.command === "install") {
1205
+ const settings = o.configPath ? tidy(o.configPath) : "~/.hindsight/coding-agent.json";
1206
+ write2(`${dim("\u2514")} ${green("\u2713")} Installed ${agents} in ${secs}s`);
1207
+ write2(` ${dim(`Start a session \u2014 settings live in ${settings}.`)}`);
1208
+ } else {
1209
+ write2(
1210
+ `${dim("\u2514")} ${green("\u2713")} Uninstalled ${agents} in ${secs}s \u2014 Hindsight entries removed, *.hindsight-backup files left in place.`
1211
+ );
1212
+ }
1213
+ } else {
1214
+ write2(dim("\u2514"));
1215
+ }
1216
+ write2("");
1217
+ }
1218
+ };
1219
+ }
1220
+
1008
1221
  // src/installer.ts
1009
1222
  var MARKER = "coding-agents";
1010
1223
  function readJson(path) {
@@ -1065,20 +1278,20 @@ function stripHarnessHooks(hooks, harness) {
1065
1278
  setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
1066
1279
  }
1067
1280
  }
1068
- function installSkill(c, skillsBase) {
1281
+ function installSkill(c, harness, skillsBase) {
1069
1282
  const src = join13(c.pkgRoot, "skill");
1070
1283
  if (!existsSync8(join13(src, "SKILL.md"))) return;
1071
1284
  const dst = join13(skillsBase, "hindsight-coding-agent");
1072
1285
  mkdirSync3(skillsBase, { recursive: true });
1073
1286
  cpSync2(src, dst, { recursive: true });
1074
- c.log?.(`skill installed at ${dst}`);
1287
+ c.log?.(`${harness}: skill installed at ${dst}`);
1075
1288
  }
1076
1289
  function uninstallSkill(c, skillsBase) {
1077
1290
  rmSync(join13(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
1078
1291
  }
1079
1292
  function onPath2(bin) {
1080
1293
  try {
1081
- execFileSync5("which", [bin], { stdio: "pipe" });
1294
+ execFileSync6("which", [bin], { stdio: "pipe" });
1082
1295
  return true;
1083
1296
  } catch {
1084
1297
  return false;
@@ -1086,7 +1299,7 @@ function onPath2(bin) {
1086
1299
  }
1087
1300
  function runClinePlugin(args) {
1088
1301
  try {
1089
- execFileSync5("cline", args, { stdio: "pipe" });
1302
+ execFileSync6("cline", args, { stdio: "pipe" });
1090
1303
  return true;
1091
1304
  } catch {
1092
1305
  return false;
@@ -1162,7 +1375,7 @@ var claudeCode = {
1162
1375
  mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
1163
1376
  writeJson(path, settings);
1164
1377
  c.log?.(`claude-code: hooks merged into ${path}`);
1165
- installSkill(c, join13(c.home, ".claude", "skills"));
1378
+ installSkill(c, "claude-code", join13(c.home, ".claude", "skills"));
1166
1379
  const mcp = c.claudeMcp ?? defaultClaudeMcp;
1167
1380
  mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
1168
1381
  if (mcp([
@@ -1201,7 +1414,7 @@ var claudeCode = {
1201
1414
  };
1202
1415
  function defaultClaudeMcp(args) {
1203
1416
  try {
1204
- execFileSync5("claude", args, { stdio: "pipe" });
1417
+ execFileSync6("claude", args, { stdio: "pipe" });
1205
1418
  return true;
1206
1419
  } catch {
1207
1420
  return false;
@@ -1245,7 +1458,7 @@ args = ["${join13(c.dist, "mcp-server.js")}"]`
1245
1458
  `);
1246
1459
  c.log?.(`codex: appended ${additions.length} section(s) to ${tomlPath}`);
1247
1460
  }
1248
- installSkill(c, join13(c.home, ".agents", "skills"));
1461
+ installSkill(c, "codex", join13(c.home, ".agents", "skills"));
1249
1462
  },
1250
1463
  uninstall(c) {
1251
1464
  const hooksPath = join13(c.home, ".codex", "hooks.json");
@@ -1321,7 +1534,7 @@ var antigravity = {
1321
1534
  );
1322
1535
  }
1323
1536
  c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
1324
- installSkill(c, join13(c.home, ".gemini", "config", "skills"));
1537
+ installSkill(c, "antigravity-cli", join13(c.home, ".gemini", "config", "skills"));
1325
1538
  },
1326
1539
  uninstall(c) {
1327
1540
  const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
@@ -1358,7 +1571,7 @@ var antigravity = {
1358
1571
  };
1359
1572
  function pathNodeHasSqlite() {
1360
1573
  try {
1361
- execFileSync5("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
1574
+ execFileSync6("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
1362
1575
  return true;
1363
1576
  } catch {
1364
1577
  return false;
@@ -1366,11 +1579,40 @@ function pathNodeHasSqlite() {
1366
1579
  }
1367
1580
  function pathNodeVersion() {
1368
1581
  try {
1369
- return execFileSync5("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
1582
+ return execFileSync6("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
1370
1583
  } catch {
1371
1584
  return "not found";
1372
1585
  }
1373
1586
  }
1587
+ function runtimeDir(home) {
1588
+ return join13(home, ".hindsight", "coding-agents");
1589
+ }
1590
+ function stageRuntime(c) {
1591
+ const target = runtimeDir(c.home);
1592
+ const same = (a, b) => {
1593
+ try {
1594
+ return realpathSync(a) === realpathSync(b);
1595
+ } catch {
1596
+ return a === b;
1597
+ }
1598
+ };
1599
+ if (same(c.pkgRoot, target)) return c;
1600
+ if (!existsSync8(join13(c.dist, "installer.js"))) return c;
1601
+ try {
1602
+ rmSync(join13(target, "dist"), { recursive: true, force: true });
1603
+ mkdirSync3(target, { recursive: true });
1604
+ cpSync2(c.dist, join13(target, "dist"), { recursive: true });
1605
+ const skill = join13(c.pkgRoot, "skill");
1606
+ if (existsSync8(skill)) cpSync2(skill, join13(target, "skill"), { recursive: true });
1607
+ const pkgJson = join13(c.pkgRoot, "package.json");
1608
+ if (existsSync8(pkgJson)) copyFileSync(pkgJson, join13(target, "package.json"));
1609
+ c.log?.(`runtime staged at ${target}`);
1610
+ return { ...c, pkgRoot: target, dist: join13(target, "dist") };
1611
+ } catch (error) {
1612
+ c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
1613
+ return c;
1614
+ }
1615
+ }
1374
1616
  var SERVER_MODES = ["cloud", "self-hosted", "daemon"];
1375
1617
  function flagValue(args, name) {
1376
1618
  const inline = args.find((a) => a.startsWith(`--${name}=`));
@@ -1387,30 +1629,54 @@ function flagValueArgs(args, names) {
1387
1629
  return taken;
1388
1630
  }
1389
1631
  var CONFIG_RELATIVE = [".hindsight", "coding-agent.json"];
1632
+ var SERVER_CHOICES = [
1633
+ { mode: "cloud", label: "Hindsight Cloud", hint: "hosted, needs an API token" },
1634
+ { mode: "self-hosted", label: "Self-hosted server", hint: "a Hindsight server you already run" },
1635
+ {
1636
+ mode: "daemon",
1637
+ label: "Local daemon (on-device)",
1638
+ hint: "runs hindsight-embed here; no account, needs uv + an LLM key"
1639
+ }
1640
+ ];
1390
1641
  function promptServerMode(c) {
1642
+ if (c.selectPrompt) {
1643
+ const picked = c.selectPrompt(
1644
+ "Where should memory live?",
1645
+ SERVER_CHOICES.map(({ label, hint }) => ({ label, hint })),
1646
+ 0
1647
+ );
1648
+ if (picked === null) {
1649
+ c.log?.("no server chosen \u2014 leaving the server config unchanged");
1650
+ return void 0;
1651
+ }
1652
+ if (picked !== void 0) return SERVER_CHOICES[picked].mode;
1653
+ }
1391
1654
  c.log?.(
1392
1655
  `
1393
1656
  Where should memory live?
1394
- 1) Hindsight Cloud \u2014 hosted, needs an API token
1395
- 2) Self-hosted server \u2014 a Hindsight server you already run
1396
- 3) Local daemon (on-device) \u2014 runs hindsight-embed here; no account, needs uv + an LLM key
1657
+ ` + SERVER_CHOICES.map((o, i) => ` ${i + 1}) ${o.label.padEnd(28)}\u2014 ${o.hint}`).join("\n") + `
1397
1658
  `
1398
1659
  );
1399
- const answer = readLineSync("Choose [1-3] (default 1): ").trim();
1400
- if (answer === "" || answer === "1") return "cloud";
1401
- if (answer === "2") return "self-hosted";
1402
- if (answer === "3") return "daemon";
1660
+ const answer = readLineSync(c, "Choose [1-3] (default 1): ").trim();
1661
+ if (answer === "") return "cloud";
1662
+ const digit = Number.parseInt(answer, 10);
1663
+ if (digit >= 1 && digit <= SERVER_CHOICES.length) return SERVER_CHOICES[digit - 1].mode;
1403
1664
  c.log?.(`unrecognised choice "${answer}" \u2014 leaving the server config unchanged`);
1404
1665
  return void 0;
1405
1666
  }
1406
- function readLineSync(prompt) {
1407
- process.stdout.write(prompt);
1667
+ function readLineSync(c, prompt) {
1668
+ process.stdout.write((c.promptStyle ?? ((s) => s))(prompt));
1408
1669
  const buf = Buffer.alloc(1024);
1409
- try {
1410
- const n = readSync2(0, buf, 0, buf.length, null);
1411
- return buf.subarray(0, n).toString("utf8");
1412
- } catch {
1413
- return "";
1670
+ for (; ; ) {
1671
+ try {
1672
+ const n = readSync3(0, buf, 0, buf.length, null);
1673
+ return buf.subarray(0, n).toString("utf8");
1674
+ } catch (e) {
1675
+ if (e.code !== "EAGAIN") {
1676
+ return "";
1677
+ }
1678
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
1679
+ }
1414
1680
  }
1415
1681
  }
1416
1682
  function configureServer(c, args, installing) {
@@ -1419,7 +1685,7 @@ function configureServer(c, args, installing) {
1419
1685
  c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
1420
1686
  return false;
1421
1687
  }
1422
- const configPath = join13(c.home, ...CONFIG_RELATIVE);
1688
+ const configPath = process.env.HINDSIGHT_CONFIG || join13(c.home, ...CONFIG_RELATIVE);
1423
1689
  const existing = readJson(configPath);
1424
1690
  const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
1425
1691
  let mode = explicit;
@@ -1455,9 +1721,15 @@ server: defaulting to Hindsight Cloud. Re-run with --server self-hosted|daemon t
1455
1721
  if (mode === "cloud") {
1456
1722
  delete next.apiUrl;
1457
1723
  const token = flagValue(args, "api-token") ?? (c.interactive ? askToken(c) : void 0);
1458
- if (token) next.apiToken = token;
1724
+ if (!token) {
1725
+ c.log?.(
1726
+ `\u274C Hindsight Cloud needs an API token \u2014 pass --api-token <token> (or set apiToken in ${configPath}).`
1727
+ );
1728
+ return false;
1729
+ }
1730
+ next.apiToken = token;
1459
1731
  } else if (mode === "self-hosted") {
1460
- const url = flagValue(args, "api-url") ?? (c.interactive ? readLineSync("Server URL (e.g. http://localhost:8888): ").trim() : void 0);
1732
+ const url = flagValue(args, "api-url") ?? (c.interactive ? readLineSync(c, "Server URL (e.g. http://localhost:8888): ").trim() : void 0);
1461
1733
  if (!url) {
1462
1734
  c.log?.(
1463
1735
  `\u274C self-hosted mode needs a server URL \u2014 pass --api-url <url> (or set apiUrl in ${configPath}).`
@@ -1476,9 +1748,12 @@ server: defaulting to Hindsight Cloud. Re-run with --server self-hosted|daemon t
1476
1748
  return true;
1477
1749
  }
1478
1750
  function askToken(c) {
1479
- const token = readLineSync("API token (blank to set later): ").trim();
1480
- if (!token) c.log?.(" no token set \u2014 add apiToken later if the server needs one");
1481
- return token || void 0;
1751
+ for (let attempt = 0; attempt < 3; attempt++) {
1752
+ const token = readLineSync(c, "API token (required for Hindsight Cloud): ").trim();
1753
+ if (token) return token;
1754
+ c.log?.(" a token is required \u2014 find yours in the Hindsight Cloud dashboard");
1755
+ }
1756
+ return void 0;
1482
1757
  }
1483
1758
  function reportDaemonPrereqs(c) {
1484
1759
  if (!(c.hasUvx ?? hasUvx)()) {
@@ -1575,7 +1850,7 @@ var cursor = {
1575
1850
  };
1576
1851
  writeJson(mcpPath, mcp);
1577
1852
  c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
1578
- installSkill(c, join13(c.home, ".cursor", "skills"));
1853
+ installSkill(c, "cursor-cli", join13(c.home, ".cursor", "skills"));
1579
1854
  },
1580
1855
  uninstall(c) {
1581
1856
  const hooksPath = join13(c.home, ".cursor", "hooks.json");
@@ -1614,7 +1889,7 @@ var copilot = {
1614
1889
  hindsight: { command: "node", args: [join13(c.dist, "mcp-server.js")] }
1615
1890
  };
1616
1891
  writeJson(mcpPath, mcp);
1617
- installSkill(c, join13(c.home, ".copilot", "skills"));
1892
+ installSkill(c, "copilot-cli", join13(c.home, ".copilot", "skills"));
1618
1893
  c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
1619
1894
  },
1620
1895
  uninstall(c) {
@@ -1674,7 +1949,7 @@ ${GROK_MARKER_END}
1674
1949
  copyFileSync(path, `${path}.hindsight-backup`);
1675
1950
  mkdirSync3(dirname8(path), { recursive: true });
1676
1951
  writeFileSync2(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
1677
- installSkill(c, join13(c.home, ".grok", "skills"));
1952
+ installSkill(c, "grok-build", join13(c.home, ".grok", "skills"));
1678
1953
  c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
1679
1954
  },
1680
1955
  uninstall(c) {
@@ -1722,7 +1997,7 @@ var cline = {
1722
1997
  }
1723
1998
  };
1724
1999
  writeJson(mcpPath, mcp);
1725
- installSkill(c, join13(c.home, ".cline", "data", "settings", "skills"));
2000
+ installSkill(c, "cline-cli", join13(c.home, ".cline", "data", "settings", "skills"));
1726
2001
  c.log?.(
1727
2002
  installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
1728
2003
  );
@@ -1778,7 +2053,7 @@ function importConversations(harness, ctx) {
1778
2053
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
1779
2054
  );
1780
2055
  try {
1781
- execFileSync5("node", [join13(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
2056
+ execFileSync6("node", [join13(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
1782
2057
  stdio: "inherit"
1783
2058
  });
1784
2059
  } catch {
@@ -1786,24 +2061,21 @@ function importConversations(harness, ctx) {
1786
2061
  ctx.log?.(` node "${join13(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
1787
2062
  }
1788
2063
  }
1789
- function run(argv, ctx) {
2064
+ function run(argv, ctxIn) {
2065
+ let ctx = ctxIn;
1790
2066
  const [command, ...rawArgs] = argv;
1791
2067
  const importHistory = rawArgs.includes("--import-conversations");
1792
2068
  const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
1793
2069
  const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
1794
- if (command === "install" && /\/(_npx|\.npm\/_npx|dlx-)\/|\/_cacache\//.test(ctx.pkgRoot)) {
1795
- ctx.log?.(
1796
- "refusing to install from an npx/dlx cache: the hook wiring would point into a cache npm can evict, silently breaking every session.\nInstall the package permanently, then re-run:\n npm install -g @vectorize-io/hindsight-coding-agents\n hindsight-coding-agents install all"
1797
- );
1798
- return 1;
1799
- }
2070
+ if (command === "install") ctx = stageRuntime(ctx);
1800
2071
  if (command !== "install" && command !== "uninstall") {
1801
2072
  ctx.log?.(
1802
2073
  `usage: hindsight-coding-agents <install|uninstall> <all|harness...>
1803
2074
  [--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
1804
2075
  [--import-conversations]
1805
2076
  all every agent detected on this machine
1806
- harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)`
2077
+ harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
2078
+ agents/CI: without a TTY nothing ever prompts \u2014 pass --server (and --api-url/--api-token) to choose`
1807
2079
  );
1808
2080
  return command ? 1 : 0;
1809
2081
  }
@@ -1864,11 +2136,6 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
1864
2136
  );
1865
2137
  return 1;
1866
2138
  }
1867
- ctx.log?.(
1868
- command === "install" ? `
1869
- \u2705 installed. Start a session \u2014 settings live in ~/.hindsight/coding-agent.json.` : `
1870
- \u2705 uninstalled.`
1871
- );
1872
2139
  return 0;
1873
2140
  }
1874
2141
  var mainPath = process.argv[1] ? (() => {
@@ -1881,16 +2148,37 @@ var mainPath = process.argv[1] ? (() => {
1881
2148
  var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
1882
2149
  if (isMain || mainPath?.endsWith("installer.js")) {
1883
2150
  const dist = dirname8(fileURLToPath5(import.meta.url));
1884
- process.exit(
1885
- run(process.argv.slice(2), {
1886
- home: homedir9(),
1887
- pkgRoot: dirname8(dist),
1888
- dist,
1889
- // Only a real terminal gets prompted; piped/CI installs take the documented default.
1890
- interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
1891
- log: (m) => console.log(m)
1892
- })
1893
- );
2151
+ const pkgRoot = dirname8(dist);
2152
+ let version;
2153
+ try {
2154
+ version = JSON.parse(readFileSync15(join13(pkgRoot, "package.json"), "utf8")).version;
2155
+ } catch {
2156
+ version = void 0;
2157
+ }
2158
+ const ui = createInstallerUi({
2159
+ home: homedir9(),
2160
+ command: process.argv[2],
2161
+ version,
2162
+ harnessNames: INSTALLERS.map((i) => i.name),
2163
+ // configureServer's messages render as their own "server" group, but don't count as an agent.
2164
+ auxNames: ["server"],
2165
+ configPath: process.env.HINDSIGHT_CONFIG || void 0
2166
+ });
2167
+ ui.intro();
2168
+ const code = run(process.argv.slice(2), {
2169
+ home: homedir9(),
2170
+ pkgRoot,
2171
+ dist,
2172
+ // Only a real terminal gets prompted; piped/CI installs take the documented default.
2173
+ // tty.isatty, NOT process.stdin.isTTY: the process.stdin getter initializes the stdin TTY
2174
+ // stream, which puts fd 0 in non-blocking mode and breaks readLineSync (see there).
2175
+ interactive: Boolean(isatty(0) && isatty(1)),
2176
+ log: ui.log,
2177
+ promptStyle: ui.prompt,
2178
+ selectPrompt: ui.select
2179
+ });
2180
+ ui.outro(code);
2181
+ process.exit(code);
1894
2182
  }
1895
2183
  export {
1896
2184
  INSTALLERS,
@@ -1899,5 +2187,6 @@ export {
1899
2187
  flagValue,
1900
2188
  flagValueArgs,
1901
2189
  parseJsonc,
1902
- run
2190
+ run,
2191
+ runtimeDir
1903
2192
  };
package/dist/kilo.js CHANGED
@@ -242,7 +242,9 @@ function readEnvConfig(env = process.env) {
242
242
  function loadConfig(opts = {}) {
243
243
  const o = typeof opts === "string" ? { path: opts } : opts;
244
244
  const withEnv = applyLayer({}, readEnvConfig(), o.harness);
245
- return resolveConfig(applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness));
245
+ const raw = applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness);
246
+ if (!raw.harness && o.harness) raw.harness = o.harness;
247
+ return resolveConfig(raw);
246
248
  }
247
249
  var BANK_OVERRIDE_EXCLUDED = [
248
250
  "bankId",
@@ -311,7 +313,7 @@ var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAG
311
313
  var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Do not invent; capture only what was actually settled.`;
312
314
  var REFLECT_MISSION = "You are a debugging assistant with the project's past decisions in memory (git rationale and developer chats). Given a bug's SYMPTOM, find the past decision whose rationale explains the ROOT CAUSE \u2014 not one that merely shares vocabulary. Answer with the PRECISE fix: state the EXACT rule and the LITERAL values, identifiers, strings, numbers, or set members that were decided \u2014 quote them VERBATIM, never paraphrase, generalize, or omit them (give the actual decided value, not 'the project standard'). If memories CONFLICT on the same rule, the LATEST decision wins \u2014 prefer facts that explicitly amend or supersede an earlier one, state the superseded rule as no longer in effect, and never present it as the fix. Name the function/file to change and cite the REF-ID(s). If NOTHING in memory genuinely explains THIS symptom, say exactly that in one short sentence \u2014 a wrong-but-confident nearest match is worse than an honest miss; never stretch an unrelated decision to fit.";
313
315
  var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
314
- var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details.";
316
+ var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
315
317
  var RETAIN_STRATEGIES = {
316
318
  git: { retain_mission: GIT_MISSION, retain_extraction_mode: "verbose" },
317
319
  // ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
@@ -15943,7 +15945,7 @@ async function buildSessionStartContext(args) {
15943
15945
  cold = docIds !== void 0 ? docIds.size === 0 : void 0;
15944
15946
  gitDocIds = docIds;
15945
15947
  if (docIds !== void 0) {
15946
- startSeed(cwd, { limit: cfg.seedLimit });
15948
+ startSeed(cwd, { limit: cfg.seedLimit, harness });
15947
15949
  if (docIds.size === 0) {
15948
15950
  if (cfg.codebaseSurvey !== false) {
15949
15951
  startSurvey(cwd, {