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

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,21 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/installer.ts
4
- import { execFileSync as execFileSync4 } from "child_process";
4
+ import { execFileSync as execFileSync5 } from "child_process";
5
5
  import {
6
6
  copyFileSync,
7
7
  cpSync as cpSync2,
8
- existsSync as existsSync7,
8
+ existsSync as existsSync8,
9
9
  mkdirSync as mkdirSync3,
10
10
  mkdtempSync,
11
- readFileSync as readFileSync14,
11
+ readFileSync as readFileSync15,
12
+ readSync as readSync2,
12
13
  realpathSync,
13
14
  rmSync,
14
15
  writeFileSync as writeFileSync2
15
16
  } from "fs";
16
- import { homedir as homedir8, tmpdir as tmpdir3 } from "os";
17
- import { dirname as dirname7, join as join11 } from "path";
18
- import { fileURLToPath as fileURLToPath4, pathToFileURL } from "url";
17
+ import { homedir as homedir9, tmpdir as tmpdir3 } from "os";
18
+ import { dirname as dirname8, join as join13 } from "path";
19
+ import { fileURLToPath as fileURLToPath5, pathToFileURL } from "url";
19
20
 
20
21
  // src/core/hook.ts
21
22
  import { existsSync, readFileSync as readFileSync3 } from "fs";
@@ -37,6 +38,7 @@ import { fileURLToPath } from "url";
37
38
 
38
39
  // src/core/config.ts
39
40
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
41
+ var DEFAULT_DAEMON_PORT = 9077;
40
42
 
41
43
  // src/core/diag.ts
42
44
  import { appendFileSync as appendFileSync2 } from "fs";
@@ -91,6 +93,60 @@ import { dirname as dirname4, join as join5 } from "path";
91
93
  // src/core/retain-hook.ts
92
94
  import { readFileSync as readFileSync5 } from "fs";
93
95
 
96
+ // src/core/daemon.ts
97
+ import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
98
+ import { dirname as dirname5, join as join6 } from "path";
99
+ import { fileURLToPath as fileURLToPath2 } from "url";
100
+ function hasRustToolchain() {
101
+ if (process.platform !== "darwin") return true;
102
+ try {
103
+ execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
104
+ return true;
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+ function hasUvx() {
110
+ try {
111
+ execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
112
+ return true;
113
+ } catch {
114
+ return false;
115
+ }
116
+ }
117
+ var PROVIDER_PROBES = [
118
+ { provider: "openai", keyEnv: "OPENAI_API_KEY" },
119
+ { provider: "anthropic", keyEnv: "ANTHROPIC_API_KEY" },
120
+ { provider: "gemini", keyEnv: "GEMINI_API_KEY" },
121
+ { provider: "groq", keyEnv: "GROQ_API_KEY" }
122
+ ];
123
+ function detectLlm(env = process.env) {
124
+ const explicit = env.HINDSIGHT_API_LLM_PROVIDER?.trim();
125
+ if (explicit) {
126
+ return {
127
+ provider: explicit,
128
+ apiKey: env.HINDSIGHT_API_LLM_API_KEY?.trim() || void 0,
129
+ source: "HINDSIGHT_API_LLM_PROVIDER"
130
+ };
131
+ }
132
+ for (const probe of PROVIDER_PROBES) {
133
+ const key = env[probe.keyEnv]?.trim();
134
+ if (key) return { provider: probe.provider, apiKey: key, source: probe.keyEnv };
135
+ }
136
+ if (onPath("claude")) {
137
+ return { provider: "claude-code", source: "the Claude Code CLI on PATH (no API key needed)" };
138
+ }
139
+ return void 0;
140
+ }
141
+ function onPath(bin) {
142
+ try {
143
+ execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
144
+ return true;
145
+ } catch {
146
+ return false;
147
+ }
148
+ }
149
+
94
150
  // src/core/transcript.ts
95
151
  import { readFileSync as readFileSync4 } from "fs";
96
152
 
@@ -189,24 +245,24 @@ function readClaudeTranscript(path) {
189
245
  import { readFileSync as readFileSync7 } from "fs";
190
246
 
191
247
  // src/core/git.ts
192
- import { execFileSync as execFileSync2 } from "child_process";
248
+ import { execFileSync as execFileSync3 } from "child_process";
193
249
  import { resolve } from "path";
194
250
 
195
251
  // src/core/status.ts
196
- import { execFileSync as execFileSync3 } from "child_process";
252
+ import { execFileSync as execFileSync4 } from "child_process";
197
253
 
198
254
  // src/core/survey.ts
199
- import { spawn as realSpawn2 } from "child_process";
255
+ import { spawn as realSpawn3 } from "child_process";
200
256
  import { accessSync, constants, existsSync as existsSync2 } from "fs";
201
257
  import { homedir as homedir3 } from "os";
202
- import { delimiter, dirname as dirname5, join as join6 } from "path";
203
- import { fileURLToPath as fileURLToPath2 } from "url";
258
+ import { delimiter, dirname as dirname6, join as join7 } from "path";
259
+ import { fileURLToPath as fileURLToPath3 } from "url";
204
260
 
205
261
  // src/core/skill-sync.ts
206
262
  import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
207
263
  import { homedir as homedir4 } from "os";
208
- import { dirname as dirname6, join as join7 } from "path";
209
- import { fileURLToPath as fileURLToPath3 } from "url";
264
+ import { dirname as dirname7, join as join8 } from "path";
265
+ import { fileURLToPath as fileURLToPath4 } from "url";
210
266
 
211
267
  // src/core/transcript-codex.ts
212
268
  import { readFileSync as readFileSync8 } from "fs";
@@ -368,17 +424,17 @@ function readCopilotTranscript(path) {
368
424
  // src/core/transcript-grok.ts
369
425
  import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
370
426
  import { homedir as homedir5 } from "os";
371
- import { join as join8 } from "path";
427
+ import { join as join9 } from "path";
372
428
  var CHAT_HISTORY = "chat_history.jsonl";
373
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join8(homedir5(), ".grok")) {
374
- const sessionsDir = join8(grokHome, "sessions");
375
- const direct = join8(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
429
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join9(homedir5(), ".grok")) {
430
+ const sessionsDir = join9(grokHome, "sessions");
431
+ const direct = join9(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
376
432
  if (existsSync4(direct)) return direct;
377
433
  try {
378
434
  for (const candidate of readdirSync(sessionsDir)) {
379
- const directory = join8(sessionsDir, candidate);
380
- if (readFileSync12(join8(directory, ".cwd"), "utf8").trim() === cwd) {
381
- return join8(directory, sessionId, CHAT_HISTORY);
435
+ const directory = join9(sessionsDir, candidate);
436
+ if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
437
+ return join9(directory, sessionId, CHAT_HISTORY);
382
438
  }
383
439
  }
384
440
  } catch {
@@ -422,9 +478,9 @@ function readGrokTranscript(path) {
422
478
  import { existsSync as existsSync5 } from "fs";
423
479
  import { createRequire } from "module";
424
480
  import { homedir as homedir6 } from "os";
425
- import { join as join9 } from "path";
481
+ import { join as join10 } from "path";
426
482
  function devinSessionDb(home = homedir6()) {
427
- return join9(home, ".local", "share", "devin", "cli", "sessions.db");
483
+ return join10(home, ".local", "share", "devin", "cli", "sessions.db");
428
484
  }
429
485
  function parseDevinMessages(nodes) {
430
486
  const messages = /* @__PURE__ */ new Map();
@@ -777,9 +833,9 @@ import {
777
833
  statSync
778
834
  } from "fs";
779
835
  import { homedir as homedir7 } from "os";
780
- import { join as join10 } from "path";
836
+ import { join as join11 } from "path";
781
837
  function claudeProjectDir(repoDir, home = homedir7()) {
782
- return join10(home, ".claude", "projects", repoDir.replace(/[/.]/g, "-"));
838
+ return join11(home, ".claude", "projects", repoDir.replace(/[/.]/g, "-"));
783
839
  }
784
840
  function withinRepo(dir, repoDir) {
785
841
  return !!dir && (dir === repoDir || dir.startsWith(repoDir.endsWith("/") ? repoDir : repoDir + "/"));
@@ -822,13 +878,13 @@ function firstLine(path, cap = 1e6) {
822
878
  }
823
879
  function jsonlFiles(dir) {
824
880
  if (!existsSync6(dir)) return [];
825
- return readdirSync2(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join10(dir, f));
881
+ return readdirSync2(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join11(dir, f));
826
882
  }
827
883
  function claudeHistory(repoDir, home) {
828
- const root = join10(home, ".claude", "projects");
884
+ const root = join11(home, ".claude", "projects");
829
885
  const exact = claudeProjectDir(repoDir, home);
830
886
  const prefix = exact + "-";
831
- const dirs = existsSync6(root) ? readdirSync2(root).map((d) => join10(root, d)).filter((d) => d === exact || d.startsWith(prefix)) : [];
887
+ const dirs = existsSync6(root) ? readdirSync2(root).map((d) => join11(root, d)).filter((d) => d === exact || d.startsWith(prefix)) : [];
832
888
  const sessions = [];
833
889
  let unattributed = 0;
834
890
  for (const file of dirs.flatMap(jsonlFiles)) {
@@ -848,12 +904,12 @@ function claudeHistory(repoDir, home) {
848
904
  return { supported: true, sessions, unattributed };
849
905
  }
850
906
  function codexHistory(repoDir, home) {
851
- const root = join10(home, ".codex", "sessions");
907
+ const root = join11(home, ".codex", "sessions");
852
908
  if (!existsSync6(root)) return { supported: true, sessions: [] };
853
909
  const files = [];
854
910
  const walk = (dir) => {
855
911
  for (const entry of readdirSync2(dir)) {
856
- const p = join10(dir, entry);
912
+ const p = join11(dir, entry);
857
913
  if (statSync(p).isDirectory()) walk(p);
858
914
  else if (entry.endsWith(".jsonl")) files.push(p);
859
915
  }
@@ -896,11 +952,64 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
896
952
  }
897
953
  }
898
954
 
955
+ // src/core/legacy.ts
956
+ import { existsSync as existsSync7, readFileSync as readFileSync14 } from "fs";
957
+ import { homedir as homedir8 } from "os";
958
+ import { join as join12 } from "path";
959
+ var LEGACY_CONFIG_FILES = {
960
+ "claude-code": "claude-code.json",
961
+ codex: "codex.json"
962
+ };
963
+ function legacyConfigPath(harness, home = homedir8()) {
964
+ return join12(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
965
+ }
966
+ var CLOUD_URL = "https://api.hindsight.vectorize.io";
967
+ function readLegacyEndpoint(home = homedir8(), prefer = []) {
968
+ const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
969
+ (h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
970
+ );
971
+ for (const harness of order) {
972
+ const found = readOne(harness, home);
973
+ if (found) return found;
974
+ }
975
+ return void 0;
976
+ }
977
+ function readOne(harness, home) {
978
+ const source = legacyConfigPath(harness, home);
979
+ if (!existsSync7(source)) return void 0;
980
+ let raw;
981
+ try {
982
+ raw = JSON.parse(readFileSync14(source, "utf8"));
983
+ } catch {
984
+ return void 0;
985
+ }
986
+ if (!raw || typeof raw !== "object") return void 0;
987
+ const apiToken = typeof raw.hindsightApiToken === "string" ? raw.hindsightApiToken : void 0;
988
+ const url = typeof raw.hindsightApiUrl === "string" ? raw.hindsightApiUrl.trim() : "";
989
+ if (url) {
990
+ return {
991
+ harness,
992
+ serverMode: url.replace(/\/+$/, "") === CLOUD_URL ? "cloud" : "self-hosted",
993
+ apiUrl: url,
994
+ ...apiToken ? { apiToken } : {},
995
+ source
996
+ };
997
+ }
998
+ const port = typeof raw.apiPort === "number" ? raw.apiPort : void 0;
999
+ return {
1000
+ harness,
1001
+ serverMode: "daemon",
1002
+ ...apiToken ? { apiToken } : {},
1003
+ ...port && port !== DEFAULT_DAEMON_PORT ? { apiPort: port } : {},
1004
+ source
1005
+ };
1006
+ }
1007
+
899
1008
  // src/installer.ts
900
1009
  var MARKER = "coding-agents";
901
1010
  function readJson(path) {
902
1011
  try {
903
- return JSON.parse(readFileSync14(path, "utf8"));
1012
+ return JSON.parse(readFileSync15(path, "utf8"));
904
1013
  } catch {
905
1014
  return {};
906
1015
  }
@@ -915,8 +1024,8 @@ function parseJsonc(text) {
915
1024
  }
916
1025
  }
917
1026
  function writeJson(path, value) {
918
- mkdirSync3(dirname7(path), { recursive: true });
919
- if (existsSync7(path) && !existsSync7(`${path}.hindsight-backup`)) {
1027
+ mkdirSync3(dirname8(path), { recursive: true });
1028
+ if (existsSync8(path) && !existsSync8(`${path}.hindsight-backup`)) {
920
1029
  copyFileSync(path, `${path}.hindsight-backup`);
921
1030
  }
922
1031
  writeFileSync2(path, JSON.stringify(value, null, 2) + "\n");
@@ -933,7 +1042,7 @@ function setOrDelete(obj, key, arr) {
933
1042
  else delete obj[key];
934
1043
  }
935
1044
  var cmdHook = (dist, file, timeout) => ({
936
- hooks: [{ type: "command", command: `node "${join11(dist, file)}"`, timeout }]
1045
+ hooks: [{ type: "command", command: `node "${join13(dist, file)}"`, timeout }]
937
1046
  });
938
1047
  function mergeHarnessHooks(hooks, harness, dist) {
939
1048
  const spec = HOOK_HARNESSES[harness];
@@ -942,7 +1051,7 @@ function mergeHarnessHooks(hooks, harness, dist) {
942
1051
  if (installedEvents.has(hook.event)) continue;
943
1052
  installedEvents.add(hook.event);
944
1053
  const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
945
- command: `node "${join11(dist, hook.entry)}"`,
1054
+ command: `node "${join13(dist, hook.entry)}"`,
946
1055
  ...hook.timeout ? { timeout: hook.timeout } : {}
947
1056
  };
948
1057
  hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
@@ -957,19 +1066,19 @@ function stripHarnessHooks(hooks, harness) {
957
1066
  }
958
1067
  }
959
1068
  function installSkill(c, skillsBase) {
960
- const src = join11(c.pkgRoot, "skill");
961
- if (!existsSync7(join11(src, "SKILL.md"))) return;
962
- const dst = join11(skillsBase, "hindsight-coding-agent");
1069
+ const src = join13(c.pkgRoot, "skill");
1070
+ if (!existsSync8(join13(src, "SKILL.md"))) return;
1071
+ const dst = join13(skillsBase, "hindsight-coding-agent");
963
1072
  mkdirSync3(skillsBase, { recursive: true });
964
1073
  cpSync2(src, dst, { recursive: true });
965
1074
  c.log?.(`skill installed at ${dst}`);
966
1075
  }
967
1076
  function uninstallSkill(c, skillsBase) {
968
- rmSync(join11(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
1077
+ rmSync(join13(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
969
1078
  }
970
- function onPath(bin) {
1079
+ function onPath2(bin) {
971
1080
  try {
972
- execFileSync4("which", [bin], { stdio: "pipe" });
1081
+ execFileSync5("which", [bin], { stdio: "pipe" });
973
1082
  return true;
974
1083
  } catch {
975
1084
  return false;
@@ -977,7 +1086,7 @@ function onPath(bin) {
977
1086
  }
978
1087
  function runClinePlugin(args) {
979
1088
  try {
980
- execFileSync4("cline", args, { stdio: "pipe" });
1089
+ execFileSync5("cline", args, { stdio: "pipe" });
981
1090
  return true;
982
1091
  } catch {
983
1092
  return false;
@@ -985,9 +1094,9 @@ function runClinePlugin(args) {
985
1094
  }
986
1095
  var opencode = {
987
1096
  name: "opencode",
988
- detect: (c) => onPath("opencode") || existsSync7(join11(c.home, ".config", "opencode")),
1097
+ detect: (c) => onPath2("opencode") || existsSync8(join13(c.home, ".config", "opencode")),
989
1098
  install(c) {
990
- const path = join11(c.home, ".config", "opencode", "opencode.json");
1099
+ const path = join13(c.home, ".config", "opencode", "opencode.json");
991
1100
  const cfg = readJson(path);
992
1101
  const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
993
1102
  cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), c.pkgRoot];
@@ -995,8 +1104,8 @@ var opencode = {
995
1104
  c.log?.(`opencode: plugin registered in ${path}`);
996
1105
  },
997
1106
  uninstall(c) {
998
- const path = join11(c.home, ".config", "opencode", "opencode.json");
999
- if (!existsSync7(path)) return;
1107
+ const path = join13(c.home, ".config", "opencode", "opencode.json");
1108
+ if (!existsSync8(path)) return;
1000
1109
  const cfg = readJson(path);
1001
1110
  if (Array.isArray(cfg.plugin)) {
1002
1111
  cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
@@ -1008,25 +1117,25 @@ var opencode = {
1008
1117
  };
1009
1118
  var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
1010
1119
  function kiloConfigPath(c) {
1011
- const dir = join11(c.home, ".config", "kilo");
1012
- const existing = KILO_CONFIG_CANDIDATES.map((f) => join11(dir, f)).find((p) => existsSync7(p));
1013
- return existing ?? join11(dir, "kilo.json");
1120
+ const dir = join13(c.home, ".config", "kilo");
1121
+ const existing = KILO_CONFIG_CANDIDATES.map((f) => join13(dir, f)).find((p) => existsSync8(p));
1122
+ return existing ?? join13(dir, "kilo.json");
1014
1123
  }
1015
1124
  var kilo = {
1016
1125
  name: "kilo",
1017
- detect: (c) => onPath("kilo") || existsSync7(join11(c.home, ".config", "kilo")),
1126
+ detect: (c) => onPath2("kilo") || existsSync8(join13(c.home, ".config", "kilo")),
1018
1127
  install(c) {
1019
1128
  const path = kiloConfigPath(c);
1020
1129
  let cfg = {};
1021
- if (existsSync7(path)) {
1022
- const parsed = parseJsonc(readFileSync14(path, "utf8"));
1130
+ if (existsSync8(path)) {
1131
+ const parsed = parseJsonc(readFileSync15(path, "utf8"));
1023
1132
  if (!parsed) {
1024
1133
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
1025
1134
  return;
1026
1135
  }
1027
1136
  cfg = parsed;
1028
1137
  }
1029
- const entry = pathToFileURL(join11(c.dist, "kilo.js")).href;
1138
+ const entry = pathToFileURL(join13(c.dist, "kilo.js")).href;
1030
1139
  const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
1031
1140
  cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), entry];
1032
1141
  writeJson(path, cfg);
@@ -1034,8 +1143,8 @@ var kilo = {
1034
1143
  },
1035
1144
  uninstall(c) {
1036
1145
  const path = kiloConfigPath(c);
1037
- if (!existsSync7(path)) return;
1038
- const cfg = parseJsonc(readFileSync14(path, "utf8"));
1146
+ if (!existsSync8(path)) return;
1147
+ const cfg = parseJsonc(readFileSync15(path, "utf8"));
1039
1148
  if (!cfg || !Array.isArray(cfg.plugin)) return;
1040
1149
  cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
1041
1150
  if (!cfg.plugin.length) delete cfg.plugin;
@@ -1045,15 +1154,15 @@ var kilo = {
1045
1154
  };
1046
1155
  var claudeCode = {
1047
1156
  name: "claude-code",
1048
- detect: (c) => onPath("claude") || existsSync7(join11(c.home, ".claude")),
1157
+ detect: (c) => onPath2("claude") || existsSync8(join13(c.home, ".claude")),
1049
1158
  install(c) {
1050
- const path = join11(c.home, ".claude", "settings.json");
1159
+ const path = join13(c.home, ".claude", "settings.json");
1051
1160
  const settings = readJson(path);
1052
1161
  settings.hooks = settings.hooks ?? {};
1053
1162
  mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
1054
1163
  writeJson(path, settings);
1055
1164
  c.log?.(`claude-code: hooks merged into ${path}`);
1056
- installSkill(c, join11(c.home, ".claude", "skills"));
1165
+ installSkill(c, join13(c.home, ".claude", "skills"));
1057
1166
  const mcp = c.claudeMcp ?? defaultClaudeMcp;
1058
1167
  mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
1059
1168
  if (mcp([
@@ -1064,19 +1173,19 @@ var claudeCode = {
1064
1173
  "hindsight",
1065
1174
  "--",
1066
1175
  "node",
1067
- join11(c.dist, "mcp-server.js")
1176
+ join13(c.dist, "mcp-server.js")
1068
1177
  ])) {
1069
1178
  c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
1070
1179
  } else {
1071
1180
  c.log?.(
1072
1181
  `claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
1073
- claude mcp add --scope user hindsight -- node "${join11(c.dist, "mcp-server.js")}"`
1182
+ claude mcp add --scope user hindsight -- node "${join13(c.dist, "mcp-server.js")}"`
1074
1183
  );
1075
1184
  }
1076
1185
  },
1077
1186
  uninstall(c) {
1078
- const path = join11(c.home, ".claude", "settings.json");
1079
- if (existsSync7(path)) {
1187
+ const path = join13(c.home, ".claude", "settings.json");
1188
+ if (existsSync8(path)) {
1080
1189
  const settings = readJson(path);
1081
1190
  if (settings.hooks) {
1082
1191
  stripHarnessHooks(settings.hooks, "claude-code");
@@ -1086,13 +1195,13 @@ var claudeCode = {
1086
1195
  }
1087
1196
  const mcp = c.claudeMcp ?? defaultClaudeMcp;
1088
1197
  mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
1089
- uninstallSkill(c, join11(c.home, ".claude", "skills"));
1198
+ uninstallSkill(c, join13(c.home, ".claude", "skills"));
1090
1199
  c.log?.("claude-code: hooks + MCP registration + skill removed");
1091
1200
  }
1092
1201
  };
1093
1202
  function defaultClaudeMcp(args) {
1094
1203
  try {
1095
- execFileSync4("claude", args, { stdio: "pipe" });
1204
+ execFileSync5("claude", args, { stdio: "pipe" });
1096
1205
  return true;
1097
1206
  } catch {
1098
1207
  return false;
@@ -1100,16 +1209,16 @@ function defaultClaudeMcp(args) {
1100
1209
  }
1101
1210
  var codex = {
1102
1211
  name: "codex",
1103
- detect: (c) => onPath("codex") || existsSync7(join11(c.home, ".codex")),
1212
+ detect: (c) => onPath2("codex") || existsSync8(join13(c.home, ".codex")),
1104
1213
  install(c) {
1105
- const hooksPath = join11(c.home, ".codex", "hooks.json");
1214
+ const hooksPath = join13(c.home, ".codex", "hooks.json");
1106
1215
  const cfg = readJson(hooksPath);
1107
1216
  cfg.hooks = cfg.hooks ?? {};
1108
1217
  mergeHarnessHooks(cfg.hooks, "codex", c.dist);
1109
1218
  writeJson(hooksPath, cfg);
1110
1219
  c.log?.(`codex: hooks merged into ${hooksPath}`);
1111
- const tomlPath = join11(c.home, ".codex", "config.toml");
1112
- let toml = existsSync7(tomlPath) ? readFileSync14(tomlPath, "utf8") : "";
1220
+ const tomlPath = join13(c.home, ".codex", "config.toml");
1221
+ let toml = existsSync8(tomlPath) ? readFileSync15(tomlPath, "utf8") : "";
1113
1222
  const additions = [];
1114
1223
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
1115
1224
  if (/^\[features\]/m.test(toml)) {
@@ -1124,33 +1233,33 @@ var codex = {
1124
1233
  additions.push(
1125
1234
  `[mcp_servers.hindsight]
1126
1235
  command = "node"
1127
- args = ["${join11(c.dist, "mcp-server.js")}"]`
1236
+ args = ["${join13(c.dist, "mcp-server.js")}"]`
1128
1237
  );
1129
1238
  }
1130
1239
  if (additions.length) {
1131
- if (existsSync7(tomlPath) && !existsSync7(`${tomlPath}.hindsight-backup`)) {
1240
+ if (existsSync8(tomlPath) && !existsSync8(`${tomlPath}.hindsight-backup`)) {
1132
1241
  copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
1133
1242
  }
1134
- mkdirSync3(dirname7(tomlPath), { recursive: true });
1243
+ mkdirSync3(dirname8(tomlPath), { recursive: true });
1135
1244
  writeFileSync2(tomlPath, `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
1136
1245
  `);
1137
1246
  c.log?.(`codex: appended ${additions.length} section(s) to ${tomlPath}`);
1138
1247
  }
1139
- installSkill(c, join11(c.home, ".agents", "skills"));
1248
+ installSkill(c, join13(c.home, ".agents", "skills"));
1140
1249
  },
1141
1250
  uninstall(c) {
1142
- const hooksPath = join11(c.home, ".codex", "hooks.json");
1143
- if (existsSync7(hooksPath)) {
1251
+ const hooksPath = join13(c.home, ".codex", "hooks.json");
1252
+ if (existsSync8(hooksPath)) {
1144
1253
  const cfg = readJson(hooksPath);
1145
1254
  if (cfg.hooks) {
1146
1255
  stripHarnessHooks(cfg.hooks, "codex");
1147
1256
  writeJson(hooksPath, cfg);
1148
1257
  }
1149
1258
  }
1150
- uninstallSkill(c, join11(c.home, ".agents", "skills"));
1151
- const tomlPath = join11(c.home, ".codex", "config.toml");
1152
- if (existsSync7(tomlPath)) {
1153
- const toml = readFileSync14(tomlPath, "utf8");
1259
+ uninstallSkill(c, join13(c.home, ".agents", "skills"));
1260
+ const tomlPath = join13(c.home, ".codex", "config.toml");
1261
+ if (existsSync8(tomlPath)) {
1262
+ const toml = readFileSync15(tomlPath, "utf8");
1154
1263
  const cleaned = toml.replace(
1155
1264
  /\n?\[mcp_servers\.hindsight\]\ncommand = "node"\nargs = \[[^\]]*\]\n?/g,
1156
1265
  "\n"
@@ -1167,9 +1276,9 @@ var antigravity = {
1167
1276
  // `agy` is the supported Antigravity CLI executable. Do not infer support from the
1168
1277
  // legacy Gemini CLI's ~/.gemini state: both clients may leave files there, but only agy
1169
1278
  // can consume this integration.
1170
- detect: (c) => onPath("agy"),
1279
+ detect: (c) => onPath2("agy"),
1171
1280
  install(c) {
1172
- const hooksPath = join11(c.home, ".gemini", "config", "hooks.json");
1281
+ const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
1173
1282
  const hooks = readJson(hooksPath);
1174
1283
  for (const key of Object.keys(hooks)) {
1175
1284
  if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
@@ -1180,30 +1289,30 @@ var antigravity = {
1180
1289
  setOrDelete(hooks, event, stripOurs(hooks[event]));
1181
1290
  }
1182
1291
  writeJson(hooksPath, hooks);
1183
- const mcpPath = join11(c.home, ".gemini", "config", "mcp_config.json");
1292
+ const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
1184
1293
  const mcp = readJson(mcpPath);
1185
1294
  mcp.mcpServers = {
1186
1295
  ...mcp.mcpServers ?? {},
1187
1296
  hindsight: {
1188
1297
  command: "node",
1189
- args: [join11(c.dist, "mcp-server.js")],
1298
+ args: [join13(c.dist, "mcp-server.js")],
1190
1299
  env: { HINDSIGHT_MCP_HARNESS: "antigravity-cli" }
1191
1300
  }
1192
1301
  };
1193
1302
  writeJson(mcpPath, mcp);
1194
- const settingsPath = join11(c.home, ".gemini", "antigravity-cli", "settings.json");
1303
+ const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
1195
1304
  const settings = readJson(settingsPath);
1196
1305
  if (!settings.statusLine) {
1197
1306
  settings.statusLine = {
1198
1307
  type: "command",
1199
- command: `node "${join11(c.dist, "antigravity-statusline.js")}"`
1308
+ command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
1200
1309
  };
1201
1310
  writeJson(settingsPath, settings);
1202
1311
  c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
1203
1312
  } else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
1204
1313
  settings.statusLine = {
1205
1314
  type: "command",
1206
- command: `node "${join11(c.dist, "antigravity-statusline.js")}"`
1315
+ command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
1207
1316
  };
1208
1317
  writeJson(settingsPath, settings);
1209
1318
  } else {
@@ -1212,11 +1321,11 @@ var antigravity = {
1212
1321
  );
1213
1322
  }
1214
1323
  c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
1215
- installSkill(c, join11(c.home, ".gemini", "config", "skills"));
1324
+ installSkill(c, join13(c.home, ".gemini", "config", "skills"));
1216
1325
  },
1217
1326
  uninstall(c) {
1218
- const hooksPath = join11(c.home, ".gemini", "config", "hooks.json");
1219
- if (existsSync7(hooksPath)) {
1327
+ const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
1328
+ if (existsSync8(hooksPath)) {
1220
1329
  const hooks = readJson(hooksPath);
1221
1330
  if (hooks[MARKER]) {
1222
1331
  stripHarnessHooks(hooks[MARKER], "antigravity-cli");
@@ -1227,29 +1336,29 @@ var antigravity = {
1227
1336
  }
1228
1337
  writeJson(hooksPath, hooks);
1229
1338
  }
1230
- const mcpPath = join11(c.home, ".gemini", "config", "mcp_config.json");
1231
- if (existsSync7(mcpPath)) {
1339
+ const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
1340
+ if (existsSync8(mcpPath)) {
1232
1341
  const mcp = readJson(mcpPath);
1233
1342
  if (mcp.mcpServers?.hindsight) {
1234
1343
  delete mcp.mcpServers.hindsight;
1235
1344
  writeJson(mcpPath, mcp);
1236
1345
  }
1237
1346
  }
1238
- const settingsPath = join11(c.home, ".gemini", "antigravity-cli", "settings.json");
1239
- if (existsSync7(settingsPath)) {
1347
+ const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
1348
+ if (existsSync8(settingsPath)) {
1240
1349
  const settings = readJson(settingsPath);
1241
1350
  if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
1242
1351
  delete settings.statusLine;
1243
1352
  writeJson(settingsPath, settings);
1244
1353
  }
1245
1354
  }
1246
- uninstallSkill(c, join11(c.home, ".gemini", "config", "skills"));
1355
+ uninstallSkill(c, join13(c.home, ".gemini", "config", "skills"));
1247
1356
  c.log?.("antigravity-cli: hooks + MCP entry + status line + skill removed");
1248
1357
  }
1249
1358
  };
1250
1359
  function pathNodeHasSqlite() {
1251
1360
  try {
1252
- execFileSync4("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
1361
+ execFileSync5("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
1253
1362
  return true;
1254
1363
  } catch {
1255
1364
  return false;
@@ -1257,14 +1366,147 @@ function pathNodeHasSqlite() {
1257
1366
  }
1258
1367
  function pathNodeVersion() {
1259
1368
  try {
1260
- return execFileSync4("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
1369
+ return execFileSync5("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
1261
1370
  } catch {
1262
1371
  return "not found";
1263
1372
  }
1264
1373
  }
1374
+ var SERVER_MODES = ["cloud", "self-hosted", "daemon"];
1375
+ function flagValue(args, name) {
1376
+ const inline = args.find((a) => a.startsWith(`--${name}=`));
1377
+ if (inline) return inline.slice(name.length + 3);
1378
+ const i = args.indexOf(`--${name}`);
1379
+ return i >= 0 ? args[i + 1] : void 0;
1380
+ }
1381
+ function flagValueArgs(args, names) {
1382
+ const taken = /* @__PURE__ */ new Set();
1383
+ for (const name of names) {
1384
+ const i = args.indexOf(`--${name}`);
1385
+ if (i >= 0 && args[i + 1] && !args[i + 1].startsWith("--")) taken.add(args[i + 1]);
1386
+ }
1387
+ return taken;
1388
+ }
1389
+ var CONFIG_RELATIVE = [".hindsight", "coding-agent.json"];
1390
+ function promptServerMode(c) {
1391
+ c.log?.(
1392
+ `
1393
+ 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
1397
+ `
1398
+ );
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";
1403
+ c.log?.(`unrecognised choice "${answer}" \u2014 leaving the server config unchanged`);
1404
+ return void 0;
1405
+ }
1406
+ function readLineSync(prompt) {
1407
+ process.stdout.write(prompt);
1408
+ 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 "";
1414
+ }
1415
+ }
1416
+ function configureServer(c, args, installing) {
1417
+ const explicit = flagValue(args, "server");
1418
+ if (explicit && !SERVER_MODES.includes(explicit)) {
1419
+ c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
1420
+ return false;
1421
+ }
1422
+ const configPath = join13(c.home, ...CONFIG_RELATIVE);
1423
+ const existing = readJson(configPath);
1424
+ const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
1425
+ let mode = explicit;
1426
+ if (!mode) {
1427
+ if (alreadyConfigured) return true;
1428
+ const legacy = (c.readLegacy ?? readLegacyEndpoint)(c.home, installing);
1429
+ if (legacy) {
1430
+ const carried = { ...existing, serverMode: legacy.serverMode };
1431
+ if (legacy.apiUrl) carried.apiUrl = legacy.apiUrl;
1432
+ if (legacy.apiToken) carried.apiToken = legacy.apiToken;
1433
+ if (legacy.apiPort) carried.apiPort = legacy.apiPort;
1434
+ writeJson(configPath, carried);
1435
+ c.log?.(
1436
+ `server: ${legacy.serverMode}${legacy.apiUrl ? ` (${legacy.apiUrl})` : ""} \u2014 carried over from the ${legacy.harness} plugin (${legacy.source})
1437
+ Only the endpoint moves; conversations do not. To bring this repo's history
1438
+ across, re-run here with --import-conversations.`
1439
+ );
1440
+ if (legacy.serverMode === "daemon") reportDaemonPrereqs(c);
1441
+ return true;
1442
+ }
1443
+ if (!c.interactive) {
1444
+ c.log?.(
1445
+ `
1446
+ server: defaulting to Hindsight Cloud. Re-run with --server self-hosted|daemon to change,
1447
+ or edit ${configPath}.`
1448
+ );
1449
+ return true;
1450
+ }
1451
+ mode = promptServerMode(c);
1452
+ if (!mode) return true;
1453
+ }
1454
+ const next = { ...existing, serverMode: mode };
1455
+ if (mode === "cloud") {
1456
+ delete next.apiUrl;
1457
+ const token = flagValue(args, "api-token") ?? (c.interactive ? askToken(c) : void 0);
1458
+ if (token) next.apiToken = token;
1459
+ } 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);
1461
+ if (!url) {
1462
+ c.log?.(
1463
+ `\u274C self-hosted mode needs a server URL \u2014 pass --api-url <url> (or set apiUrl in ${configPath}).`
1464
+ );
1465
+ return false;
1466
+ }
1467
+ next.apiUrl = url;
1468
+ const token = flagValue(args, "api-token");
1469
+ if (token) next.apiToken = token;
1470
+ } else {
1471
+ delete next.apiUrl;
1472
+ reportDaemonPrereqs(c);
1473
+ }
1474
+ writeJson(configPath, next);
1475
+ c.log?.(`server: ${mode} (${configPath})`);
1476
+ return true;
1477
+ }
1478
+ 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;
1482
+ }
1483
+ function reportDaemonPrereqs(c) {
1484
+ if (!(c.hasUvx ?? hasUvx)()) {
1485
+ c.log?.(
1486
+ `\u26A0\uFE0F \`uv\` is not on PATH. The daemon is fetched and run with it, so memory stays inert
1487
+ until you install it: https://docs.astral.sh/uv/`
1488
+ );
1489
+ }
1490
+ if (!(c.hasRust ?? hasRustToolchain)()) {
1491
+ c.log?.(
1492
+ `\u26A0\uFE0F macOS needs a current Rust toolchain to build the daemon's dependencies (litellm
1493
+ publishes no macOS wheel). Install from https://rustup.rs, then
1494
+ \`rustup default stable && rustup update\` \u2014 an OUT-OF-DATE toolchain fails too.`
1495
+ );
1496
+ }
1497
+ const llm = (c.detectLlm ?? detectLlm)();
1498
+ if (llm) {
1499
+ c.log?.(` local extraction will use ${llm.provider} (from ${llm.source})`);
1500
+ } else {
1501
+ c.log?.(
1502
+ `\u26A0\uFE0F No LLM available for local fact extraction. Set OPENAI_API_KEY, ANTHROPIC_API_KEY or
1503
+ GEMINI_API_KEY (or install the Claude Code CLI, which needs no key).`
1504
+ );
1505
+ }
1506
+ }
1265
1507
  var devin = {
1266
1508
  name: "devin-cli",
1267
- detect: (c) => onPath("devin") || existsSync7(join11(c.home, ".config", "devin")),
1509
+ detect: (c) => onPath2("devin") || existsSync8(join13(c.home, ".config", "devin")),
1268
1510
  // Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
1269
1511
  // nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
1270
1512
  // support a hard prerequisite here — and one worth checking now, because the alternative is an
@@ -1277,18 +1519,18 @@ var devin = {
1277
1519
  Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
1278
1520
  },
1279
1521
  install(c) {
1280
- const configPath = join11(c.home, ".config", "devin", "config.json");
1522
+ const configPath = join13(c.home, ".config", "devin", "config.json");
1281
1523
  const config = readJson(configPath);
1282
1524
  config.hooks = config.hooks ?? {};
1283
1525
  mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
1284
1526
  writeJson(configPath, config);
1285
- const mcpPath = join11(c.home, ".config", "devin", "mcp_config.json");
1527
+ const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
1286
1528
  const mcp = readJson(mcpPath);
1287
1529
  mcp.mcpServers = {
1288
1530
  ...mcp.mcpServers ?? {},
1289
1531
  hindsight: {
1290
1532
  command: "node",
1291
- args: [join11(c.dist, "mcp-server.js")],
1533
+ args: [join13(c.dist, "mcp-server.js")],
1292
1534
  env: { HINDSIGHT_MCP_HARNESS: "devin-cli" }
1293
1535
  }
1294
1536
  };
@@ -1296,8 +1538,8 @@ var devin = {
1296
1538
  c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
1297
1539
  },
1298
1540
  uninstall(c) {
1299
- const configPath = join11(c.home, ".config", "devin", "config.json");
1300
- if (existsSync7(configPath)) {
1541
+ const configPath = join13(c.home, ".config", "devin", "config.json");
1542
+ if (existsSync8(configPath)) {
1301
1543
  const config = readJson(configPath);
1302
1544
  if (config.hooks) {
1303
1545
  stripHarnessHooks(config.hooks, "devin-cli");
@@ -1305,8 +1547,8 @@ var devin = {
1305
1547
  writeJson(configPath, config);
1306
1548
  }
1307
1549
  }
1308
- const mcpPath = join11(c.home, ".config", "devin", "mcp_config.json");
1309
- if (existsSync7(mcpPath)) {
1550
+ const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
1551
+ if (existsSync8(mcpPath)) {
1310
1552
  const mcp = readJson(mcpPath);
1311
1553
  if (mcp.mcpServers?.hindsight) {
1312
1554
  delete mcp.mcpServers.hindsight;
@@ -1318,26 +1560,26 @@ var devin = {
1318
1560
  };
1319
1561
  var cursor = {
1320
1562
  name: "cursor-cli",
1321
- detect: (c) => onPath("cursor-agent") || existsSync7(join11(c.home, ".cursor")),
1563
+ detect: (c) => onPath2("cursor-agent") || existsSync8(join13(c.home, ".cursor")),
1322
1564
  install(c) {
1323
- const hooksPath = join11(c.home, ".cursor", "hooks.json");
1565
+ const hooksPath = join13(c.home, ".cursor", "hooks.json");
1324
1566
  const cfg = readJson(hooksPath);
1325
1567
  cfg.hooks = cfg.hooks ?? {};
1326
1568
  mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
1327
1569
  writeJson(hooksPath, cfg);
1328
- const mcpPath = join11(c.home, ".cursor", "mcp.json");
1570
+ const mcpPath = join13(c.home, ".cursor", "mcp.json");
1329
1571
  const mcp = readJson(mcpPath);
1330
1572
  mcp.mcpServers = {
1331
1573
  ...mcp.mcpServers ?? {},
1332
- hindsight: { command: "node", args: [join11(c.dist, "mcp-server.js")] }
1574
+ hindsight: { command: "node", args: [join13(c.dist, "mcp-server.js")] }
1333
1575
  };
1334
1576
  writeJson(mcpPath, mcp);
1335
1577
  c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
1336
- installSkill(c, join11(c.home, ".cursor", "skills"));
1578
+ installSkill(c, join13(c.home, ".cursor", "skills"));
1337
1579
  },
1338
1580
  uninstall(c) {
1339
- const hooksPath = join11(c.home, ".cursor", "hooks.json");
1340
- if (existsSync7(hooksPath)) {
1581
+ const hooksPath = join13(c.home, ".cursor", "hooks.json");
1582
+ if (existsSync8(hooksPath)) {
1341
1583
  const cfg = readJson(hooksPath);
1342
1584
  if (cfg.hooks) {
1343
1585
  stripHarnessHooks(cfg.hooks, "cursor-cli");
@@ -1345,49 +1587,49 @@ var cursor = {
1345
1587
  writeJson(hooksPath, cfg);
1346
1588
  }
1347
1589
  }
1348
- const mcpPath = join11(c.home, ".cursor", "mcp.json");
1349
- if (existsSync7(mcpPath)) {
1590
+ const mcpPath = join13(c.home, ".cursor", "mcp.json");
1591
+ if (existsSync8(mcpPath)) {
1350
1592
  const mcp = readJson(mcpPath);
1351
1593
  if (mcp.mcpServers?.hindsight) {
1352
1594
  delete mcp.mcpServers.hindsight;
1353
1595
  writeJson(mcpPath, mcp);
1354
1596
  }
1355
1597
  }
1356
- uninstallSkill(c, join11(c.home, ".cursor", "skills"));
1598
+ uninstallSkill(c, join13(c.home, ".cursor", "skills"));
1357
1599
  c.log?.("cursor-cli: hooks + MCP entry + skill removed");
1358
1600
  }
1359
1601
  };
1360
1602
  var copilot = {
1361
1603
  name: "copilot-cli",
1362
- detect: (c) => onPath("copilot") || existsSync7(join11(c.home, ".copilot")),
1604
+ detect: (c) => onPath2("copilot") || existsSync8(join13(c.home, ".copilot")),
1363
1605
  install(c) {
1364
- const hooksPath = join11(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
1606
+ const hooksPath = join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
1365
1607
  const hooks = {};
1366
1608
  mergeHarnessHooks(hooks, "copilot-cli", c.dist);
1367
1609
  writeJson(hooksPath, { version: 1, hooks });
1368
- const mcpPath = join11(c.home, ".copilot", "mcp-config.json");
1610
+ const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
1369
1611
  const mcp = readJson(mcpPath);
1370
1612
  mcp.mcpServers = {
1371
1613
  ...mcp.mcpServers ?? {},
1372
- hindsight: { command: "node", args: [join11(c.dist, "mcp-server.js")] }
1614
+ hindsight: { command: "node", args: [join13(c.dist, "mcp-server.js")] }
1373
1615
  };
1374
1616
  writeJson(mcpPath, mcp);
1375
- installSkill(c, join11(c.home, ".copilot", "skills"));
1617
+ installSkill(c, join13(c.home, ".copilot", "skills"));
1376
1618
  c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
1377
1619
  },
1378
1620
  uninstall(c) {
1379
- rmSync(join11(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
1621
+ rmSync(join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
1380
1622
  force: true
1381
1623
  });
1382
- const mcpPath = join11(c.home, ".copilot", "mcp-config.json");
1383
- if (existsSync7(mcpPath)) {
1624
+ const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
1625
+ if (existsSync8(mcpPath)) {
1384
1626
  const mcp = readJson(mcpPath);
1385
1627
  if (mcp.mcpServers?.hindsight) {
1386
1628
  delete mcp.mcpServers.hindsight;
1387
1629
  writeJson(mcpPath, mcp);
1388
1630
  }
1389
1631
  }
1390
- uninstallSkill(c, join11(c.home, ".copilot", "skills"));
1632
+ uninstallSkill(c, join13(c.home, ".copilot", "skills"));
1391
1633
  c.log?.("copilot-cli: hooks + MCP entry + skill removed");
1392
1634
  }
1393
1635
  };
@@ -1396,12 +1638,12 @@ var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
1396
1638
  var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
1397
1639
  var grok = {
1398
1640
  name: "grok-build",
1399
- detect: (c) => onPath("grok") || existsSync7(join11(c.home, ".grok")),
1641
+ detect: (c) => onPath2("grok") || existsSync8(join13(c.home, ".grok")),
1400
1642
  install(c) {
1401
- const path = join11(c.home, ".grok", "config.toml");
1402
- const existing = existsSync7(path) ? readFileSync14(path, "utf8") : "";
1643
+ const path = join13(c.home, ".grok", "config.toml");
1644
+ const existing = existsSync8(path) ? readFileSync15(path, "utf8") : "";
1403
1645
  const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
1404
- const command = (entry) => JSON.stringify(`node "${join11(c.dist, entry)}"`);
1646
+ const command = (entry) => JSON.stringify(`node "${join13(c.dist, entry)}"`);
1405
1647
  const tomlString = (value) => JSON.stringify(value);
1406
1648
  const block = `
1407
1649
  ${GROK_MARKER_START}
@@ -1425,24 +1667,24 @@ ${GROK_MARKER_START}
1425
1667
 
1426
1668
  [mcp_servers.hindsight]
1427
1669
  command = "node"
1428
- args = [${tomlString(join11(c.dist, "mcp-server.js"))}]
1670
+ args = [${tomlString(join13(c.dist, "mcp-server.js"))}]
1429
1671
  ${GROK_MARKER_END}
1430
1672
  `;
1431
- if (existsSync7(path) && !existsSync7(`${path}.hindsight-backup`))
1673
+ if (existsSync8(path) && !existsSync8(`${path}.hindsight-backup`))
1432
1674
  copyFileSync(path, `${path}.hindsight-backup`);
1433
- mkdirSync3(dirname7(path), { recursive: true });
1675
+ mkdirSync3(dirname8(path), { recursive: true });
1434
1676
  writeFileSync2(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
1435
- installSkill(c, join11(c.home, ".grok", "skills"));
1677
+ installSkill(c, join13(c.home, ".grok", "skills"));
1436
1678
  c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
1437
1679
  },
1438
1680
  uninstall(c) {
1439
- const path = join11(c.home, ".grok", "config.toml");
1440
- if (existsSync7(path)) {
1441
- const existing = readFileSync14(path, "utf8");
1681
+ const path = join13(c.home, ".grok", "config.toml");
1682
+ if (existsSync8(path)) {
1683
+ const existing = readFileSync15(path, "utf8");
1442
1684
  const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
1443
1685
  if (cleaned !== existing) writeFileSync2(path, cleaned);
1444
1686
  }
1445
- uninstallSkill(c, join11(c.home, ".grok", "skills"));
1687
+ uninstallSkill(c, join13(c.home, ".grok", "skills"));
1446
1688
  c.log?.("grok-build: native hooks + MCP + skill removed");
1447
1689
  }
1448
1690
  };
@@ -1450,17 +1692,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
1450
1692
  var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
1451
1693
  var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
1452
1694
  function removeLegacyClineHooks(c) {
1453
- const hooksDir = join11(c.home, "Documents", "Cline", "Hooks");
1695
+ const hooksDir = join13(c.home, "Documents", "Cline", "Hooks");
1454
1696
  for (const event of CLINE_OLD_HOOK_EVENTS) {
1455
- const path = join11(hooksDir, event);
1456
- if (existsSync7(path) && readFileSync14(path, "utf8").includes(CLINE_HOOK_MARKER)) {
1697
+ const path = join13(hooksDir, event);
1698
+ if (existsSync8(path) && readFileSync15(path, "utf8").includes(CLINE_HOOK_MARKER)) {
1457
1699
  rmSync(path, { force: true });
1458
1700
  }
1459
1701
  }
1460
1702
  }
1461
1703
  var cline = {
1462
1704
  name: "cline-cli",
1463
- detect: (c) => onPath("cline") || existsSync7(join11(c.home, ".cline")),
1705
+ detect: (c) => onPath2("cline") || existsSync8(join13(c.home, ".cline")),
1464
1706
  install(c) {
1465
1707
  removeLegacyClineHooks(c);
1466
1708
  const installed = (c.clinePlugin ?? runClinePlugin)([
@@ -1469,18 +1711,18 @@ var cline = {
1469
1711
  "--force",
1470
1712
  c.pkgRoot
1471
1713
  ]);
1472
- const mcpPath = join11(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
1714
+ const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
1473
1715
  const mcp = readJson(mcpPath);
1474
1716
  mcp.mcpServers = {
1475
1717
  ...mcp.mcpServers ?? {},
1476
1718
  hindsight: {
1477
1719
  command: "node",
1478
- args: [join11(c.dist, "mcp-server.js")],
1720
+ args: [join13(c.dist, "mcp-server.js")],
1479
1721
  env: { HINDSIGHT_MCP_HARNESS: "cline-cli" }
1480
1722
  }
1481
1723
  };
1482
1724
  writeJson(mcpPath, mcp);
1483
- installSkill(c, join11(c.home, ".cline", "data", "settings", "skills"));
1725
+ installSkill(c, join13(c.home, ".cline", "data", "settings", "skills"));
1484
1726
  c.log?.(
1485
1727
  installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
1486
1728
  );
@@ -1488,15 +1730,15 @@ var cline = {
1488
1730
  uninstall(c) {
1489
1731
  removeLegacyClineHooks(c);
1490
1732
  (c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
1491
- const mcpPath = join11(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
1492
- if (existsSync7(mcpPath)) {
1733
+ const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
1734
+ if (existsSync8(mcpPath)) {
1493
1735
  const mcp = readJson(mcpPath);
1494
1736
  if (mcp.mcpServers?.hindsight) {
1495
1737
  delete mcp.mcpServers.hindsight;
1496
1738
  writeJson(mcpPath, mcp);
1497
1739
  }
1498
1740
  }
1499
- uninstallSkill(c, join11(c.home, ".cline", "data", "settings", "skills"));
1741
+ uninstallSkill(c, join13(c.home, ".cline", "data", "settings", "skills"));
1500
1742
  c.log?.("cline-cli: native plugin + MCP + skill removed");
1501
1743
  }
1502
1744
  };
@@ -1530,24 +1772,25 @@ function importConversations(harness, ctx) {
1530
1772
  return;
1531
1773
  }
1532
1774
  const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
1533
- const file = join11(mkdtempSync(join11(tmpdir3(), "hindsight-import-")), "conversations.json");
1775
+ const file = join13(mkdtempSync(join13(tmpdir3(), "hindsight-import-")), "conversations.json");
1534
1776
  writeFileSync2(file, JSON.stringify(found.sessions));
1535
1777
  ctx.log?.(
1536
1778
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
1537
1779
  );
1538
1780
  try {
1539
- execFileSync4("node", [join11(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
1781
+ execFileSync5("node", [join13(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
1540
1782
  stdio: "inherit"
1541
1783
  });
1542
1784
  } catch {
1543
1785
  ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
1544
- ctx.log?.(` node "${join11(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
1786
+ ctx.log?.(` node "${join13(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
1545
1787
  }
1546
1788
  }
1547
1789
  function run(argv, ctx) {
1548
1790
  const [command, ...rawArgs] = argv;
1549
1791
  const importHistory = rawArgs.includes("--import-conversations");
1550
- const names = rawArgs.filter((a) => !a.startsWith("--"));
1792
+ const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
1793
+ const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
1551
1794
  if (command === "install" && /\/(_npx|\.npm\/_npx|dlx-)\/|\/_cacache\//.test(ctx.pkgRoot)) {
1552
1795
  ctx.log?.(
1553
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"
@@ -1556,7 +1799,9 @@ function run(argv, ctx) {
1556
1799
  }
1557
1800
  if (command !== "install" && command !== "uninstall") {
1558
1801
  ctx.log?.(
1559
- `usage: hindsight-coding-agents <install|uninstall> <all|harness...> [--import-conversations]
1802
+ `usage: hindsight-coding-agents <install|uninstall> <all|harness...>
1803
+ [--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
1804
+ [--import-conversations]
1560
1805
  all every agent detected on this machine
1561
1806
  harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)`
1562
1807
  );
@@ -1591,6 +1836,12 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
1591
1836
  );
1592
1837
  return 1;
1593
1838
  }
1839
+ if (command === "install" && !configureServer(
1840
+ ctx,
1841
+ rawArgs,
1842
+ targets.map((t) => t.name)
1843
+ ))
1844
+ return 1;
1594
1845
  const blocked = /* @__PURE__ */ new Set();
1595
1846
  if (command === "install") {
1596
1847
  for (const t of targets) {
@@ -1615,7 +1866,7 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
1615
1866
  }
1616
1867
  ctx.log?.(
1617
1868
  command === "install" ? `
1618
- \u2705 installed. Configure the server in ~/.hindsight/coding-agent.json (apiUrl/apiToken) and start a session.` : `
1869
+ \u2705 installed. Start a session \u2014 settings live in ~/.hindsight/coding-agent.json.` : `
1619
1870
  \u2705 uninstalled.`
1620
1871
  );
1621
1872
  return 0;
@@ -1629,12 +1880,14 @@ var mainPath = process.argv[1] ? (() => {
1629
1880
  })() : void 0;
1630
1881
  var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
1631
1882
  if (isMain || mainPath?.endsWith("installer.js")) {
1632
- const dist = dirname7(fileURLToPath4(import.meta.url));
1883
+ const dist = dirname8(fileURLToPath5(import.meta.url));
1633
1884
  process.exit(
1634
1885
  run(process.argv.slice(2), {
1635
- home: homedir8(),
1636
- pkgRoot: dirname7(dist),
1886
+ home: homedir9(),
1887
+ pkgRoot: dirname8(dist),
1637
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),
1638
1891
  log: (m) => console.log(m)
1639
1892
  })
1640
1893
  );
@@ -1643,6 +1896,8 @@ export {
1643
1896
  INSTALLERS,
1644
1897
  KILO_CONFIG_CANDIDATES,
1645
1898
  MARKER,
1899
+ flagValue,
1900
+ flagValueArgs,
1646
1901
  parseJsonc,
1647
1902
  run
1648
1903
  };