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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,10 +106,24 @@ function startBackgroundSeed(repoDir, opts = {}) {
106
106
 
107
107
  // src/core/config.ts
108
108
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
109
+ var DEFAULT_DAEMON_PORT = 9077;
110
+ var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
111
+ var DEFAULT_DAEMON_PROFILE = "coding-agent";
109
112
  function resolveConfig(raw = {}) {
113
+ const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
114
+ const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
110
115
  return {
111
- apiUrl: raw.apiUrl ?? "https://api.hindsight.vectorize.io",
116
+ serverMode,
117
+ // Daemon mode resolves the URL HERE rather than at each call site: every entry point already
118
+ // builds its client from cfg.apiUrl, so collapsing the mode into that one field means the
119
+ // daemon needs no plumbing through eight separate constructors.
120
+ apiUrl: serverMode === "daemon" ? `http://127.0.0.1:${apiPort}` : raw.apiUrl ?? "https://api.hindsight.vectorize.io",
112
121
  apiToken: raw.apiToken || void 0,
122
+ apiPort,
123
+ daemonIdleTimeout: raw.daemonIdleTimeout ?? DEFAULT_DAEMON_IDLE_TIMEOUT,
124
+ daemonProfile: raw.daemonProfile || DEFAULT_DAEMON_PROFILE,
125
+ embedVersion: raw.embedVersion || void 0,
126
+ embedPackagePath: raw.embedPackagePath || void 0,
113
127
  bankId: raw.bankId,
114
128
  dynamicBankId: raw.dynamicBankId,
115
129
  bankIdTemplate: raw.bankIdTemplate,
@@ -155,8 +169,16 @@ function applyLayer(raw, layer, harness) {
155
169
  return out;
156
170
  }
157
171
  var ENV_KEYS = {
172
+ serverMode: "HINDSIGHT_SERVER_MODE",
158
173
  apiUrl: "HINDSIGHT_API_URL",
159
174
  apiToken: "HINDSIGHT_API_TOKEN",
175
+ // These four keep the names the old per-agent Claude Code plugin used, so a user migrating from
176
+ // it can carry their existing environment over unchanged.
177
+ apiPort: "HINDSIGHT_API_PORT",
178
+ daemonIdleTimeout: "HINDSIGHT_DAEMON_IDLE_TIMEOUT",
179
+ embedVersion: "HINDSIGHT_EMBED_VERSION",
180
+ embedPackagePath: "HINDSIGHT_EMBED_PACKAGE_PATH",
181
+ daemonProfile: "HINDSIGHT_DAEMON_PROFILE",
160
182
  bankId: "HINDSIGHT_BANK_ID",
161
183
  dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
162
184
  bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
@@ -187,6 +209,8 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
187
209
  "codebaseSurvey"
188
210
  ]);
189
211
  var ENV_NUMBERS = /* @__PURE__ */ new Set([
212
+ "apiPort",
213
+ "daemonIdleTimeout",
190
214
  "retainEveryTurns",
191
215
  "reflectTimeoutMs",
192
216
  "pageRefreshEveryTurns",
@@ -1011,6 +1035,11 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
1011
1035
  // src/core/retain-hook.ts
1012
1036
  import { readFileSync as readFileSync5 } from "fs";
1013
1037
 
1038
+ // src/core/daemon.ts
1039
+ import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
1040
+ import { dirname as dirname5, join as join6 } from "path";
1041
+ import { fileURLToPath as fileURLToPath2 } from "url";
1042
+
1014
1043
  // src/core/transcript.ts
1015
1044
  import { readFileSync as readFileSync4 } from "fs";
1016
1045
 
@@ -1053,24 +1082,24 @@ function actionLine(tool, input) {
1053
1082
  import { readFileSync as readFileSync7 } from "fs";
1054
1083
 
1055
1084
  // src/core/git.ts
1056
- import { execFileSync as execFileSync2 } from "child_process";
1085
+ import { execFileSync as execFileSync3 } from "child_process";
1057
1086
  import { resolve } from "path";
1058
1087
 
1059
1088
  // src/core/status.ts
1060
- import { execFileSync as execFileSync3 } from "child_process";
1089
+ import { execFileSync as execFileSync4 } from "child_process";
1061
1090
 
1062
1091
  // src/core/survey.ts
1063
- import { spawn as realSpawn2 } from "child_process";
1092
+ import { spawn as realSpawn3 } from "child_process";
1064
1093
  import { accessSync, constants, existsSync as existsSync2 } from "fs";
1065
1094
  import { homedir as homedir3 } from "os";
1066
- import { delimiter, dirname as dirname5, join as join6 } from "path";
1067
- import { fileURLToPath as fileURLToPath2 } from "url";
1095
+ import { delimiter, dirname as dirname6, join as join7 } from "path";
1096
+ import { fileURLToPath as fileURLToPath3 } from "url";
1068
1097
 
1069
1098
  // src/core/skill-sync.ts
1070
1099
  import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
1071
1100
  import { homedir as homedir4 } from "os";
1072
- import { dirname as dirname6, join as join7 } from "path";
1073
- import { fileURLToPath as fileURLToPath3 } from "url";
1101
+ import { dirname as dirname7, join as join8 } from "path";
1102
+ import { fileURLToPath as fileURLToPath4 } from "url";
1074
1103
 
1075
1104
  // src/core/transcript-codex.ts
1076
1105
  import { readFileSync as readFileSync8 } from "fs";
@@ -1232,17 +1261,17 @@ function readCopilotTranscript(path) {
1232
1261
  // src/core/transcript-grok.ts
1233
1262
  import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
1234
1263
  import { homedir as homedir5 } from "os";
1235
- import { join as join8 } from "path";
1264
+ import { join as join9 } from "path";
1236
1265
  var CHAT_HISTORY = "chat_history.jsonl";
1237
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join8(homedir5(), ".grok")) {
1238
- const sessionsDir = join8(grokHome, "sessions");
1239
- const direct = join8(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1266
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join9(homedir5(), ".grok")) {
1267
+ const sessionsDir = join9(grokHome, "sessions");
1268
+ const direct = join9(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1240
1269
  if (existsSync4(direct)) return direct;
1241
1270
  try {
1242
1271
  for (const candidate of readdirSync(sessionsDir)) {
1243
- const directory = join8(sessionsDir, candidate);
1244
- if (readFileSync12(join8(directory, ".cwd"), "utf8").trim() === cwd) {
1245
- return join8(directory, sessionId, CHAT_HISTORY);
1272
+ const directory = join9(sessionsDir, candidate);
1273
+ if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
1274
+ return join9(directory, sessionId, CHAT_HISTORY);
1246
1275
  }
1247
1276
  }
1248
1277
  } catch {
@@ -1286,9 +1315,9 @@ function readGrokTranscript(path) {
1286
1315
  import { existsSync as existsSync5 } from "fs";
1287
1316
  import { createRequire } from "module";
1288
1317
  import { homedir as homedir6 } from "os";
1289
- import { join as join9 } from "path";
1318
+ import { join as join10 } from "path";
1290
1319
  function devinSessionDb(home = homedir6()) {
1291
- return join9(home, ".local", "share", "devin", "cli", "sessions.db");
1320
+ return join10(home, ".local", "share", "devin", "cli", "sessions.db");
1292
1321
  }
1293
1322
  function parseDevinMessages(nodes) {
1294
1323
  const messages = /* @__PURE__ */ new Map();
@@ -106,10 +106,24 @@ function startBackgroundSeed(repoDir, opts = {}) {
106
106
 
107
107
  // src/core/config.ts
108
108
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
109
+ var DEFAULT_DAEMON_PORT = 9077;
110
+ var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
111
+ var DEFAULT_DAEMON_PROFILE = "coding-agent";
109
112
  function resolveConfig(raw = {}) {
113
+ const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
114
+ const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
110
115
  return {
111
- apiUrl: raw.apiUrl ?? "https://api.hindsight.vectorize.io",
116
+ serverMode,
117
+ // Daemon mode resolves the URL HERE rather than at each call site: every entry point already
118
+ // builds its client from cfg.apiUrl, so collapsing the mode into that one field means the
119
+ // daemon needs no plumbing through eight separate constructors.
120
+ apiUrl: serverMode === "daemon" ? `http://127.0.0.1:${apiPort}` : raw.apiUrl ?? "https://api.hindsight.vectorize.io",
112
121
  apiToken: raw.apiToken || void 0,
122
+ apiPort,
123
+ daemonIdleTimeout: raw.daemonIdleTimeout ?? DEFAULT_DAEMON_IDLE_TIMEOUT,
124
+ daemonProfile: raw.daemonProfile || DEFAULT_DAEMON_PROFILE,
125
+ embedVersion: raw.embedVersion || void 0,
126
+ embedPackagePath: raw.embedPackagePath || void 0,
113
127
  bankId: raw.bankId,
114
128
  dynamicBankId: raw.dynamicBankId,
115
129
  bankIdTemplate: raw.bankIdTemplate,
@@ -155,8 +169,16 @@ function applyLayer(raw, layer, harness) {
155
169
  return out;
156
170
  }
157
171
  var ENV_KEYS = {
172
+ serverMode: "HINDSIGHT_SERVER_MODE",
158
173
  apiUrl: "HINDSIGHT_API_URL",
159
174
  apiToken: "HINDSIGHT_API_TOKEN",
175
+ // These four keep the names the old per-agent Claude Code plugin used, so a user migrating from
176
+ // it can carry their existing environment over unchanged.
177
+ apiPort: "HINDSIGHT_API_PORT",
178
+ daemonIdleTimeout: "HINDSIGHT_DAEMON_IDLE_TIMEOUT",
179
+ embedVersion: "HINDSIGHT_EMBED_VERSION",
180
+ embedPackagePath: "HINDSIGHT_EMBED_PACKAGE_PATH",
181
+ daemonProfile: "HINDSIGHT_DAEMON_PROFILE",
160
182
  bankId: "HINDSIGHT_BANK_ID",
161
183
  dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
162
184
  bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
@@ -187,6 +209,8 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
187
209
  "codebaseSurvey"
188
210
  ]);
189
211
  var ENV_NUMBERS = /* @__PURE__ */ new Set([
212
+ "apiPort",
213
+ "daemonIdleTimeout",
190
214
  "retainEveryTurns",
191
215
  "reflectTimeoutMs",
192
216
  "pageRefreshEveryTurns",
@@ -860,6 +884,122 @@ function writeSessionCache(cacheFile, cache) {
860
884
  // src/core/retain-hook.ts
861
885
  import { readFileSync as readFileSync5 } from "fs";
862
886
 
887
+ // src/core/daemon.ts
888
+ import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
889
+ import { dirname as dirname5, join as join6 } from "path";
890
+ import { fileURLToPath as fileURLToPath2 } from "url";
891
+ var DAEMON_WAIT_SESSION_START_MS = 12e3;
892
+ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
893
+ try {
894
+ const res = await fetch(`${baseUrl}/health`, { signal: AbortSignal.timeout(timeoutMs) });
895
+ return res.ok;
896
+ } catch {
897
+ return false;
898
+ }
899
+ }
900
+ function hasRustToolchain() {
901
+ if (process.platform !== "darwin") return true;
902
+ try {
903
+ execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
904
+ return true;
905
+ } catch {
906
+ return false;
907
+ }
908
+ }
909
+ function hasUvx() {
910
+ try {
911
+ execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
912
+ return true;
913
+ } catch {
914
+ return false;
915
+ }
916
+ }
917
+ var PROVIDER_PROBES = [
918
+ { provider: "openai", keyEnv: "OPENAI_API_KEY" },
919
+ { provider: "anthropic", keyEnv: "ANTHROPIC_API_KEY" },
920
+ { provider: "gemini", keyEnv: "GEMINI_API_KEY" },
921
+ { provider: "groq", keyEnv: "GROQ_API_KEY" }
922
+ ];
923
+ function detectLlm(env = process.env) {
924
+ const explicit = env.HINDSIGHT_API_LLM_PROVIDER?.trim();
925
+ if (explicit) {
926
+ return {
927
+ provider: explicit,
928
+ apiKey: env.HINDSIGHT_API_LLM_API_KEY?.trim() || void 0,
929
+ source: "HINDSIGHT_API_LLM_PROVIDER"
930
+ };
931
+ }
932
+ for (const probe of PROVIDER_PROBES) {
933
+ const key = env[probe.keyEnv]?.trim();
934
+ if (key) return { provider: probe.provider, apiKey: key, source: probe.keyEnv };
935
+ }
936
+ if (onPath("claude")) {
937
+ return { provider: "claude-code", source: "the Claude Code CLI on PATH (no API key needed)" };
938
+ }
939
+ return void 0;
940
+ }
941
+ function onPath(bin) {
942
+ try {
943
+ execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
944
+ return true;
945
+ } catch {
946
+ return false;
947
+ }
948
+ }
949
+ function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
950
+ try {
951
+ const starter = join6(dirname5(fileURLToPath2(import.meta.url)), "daemon-start.js");
952
+ const child = spawnFn("node", [starter, "--harness", harness], {
953
+ detached: true,
954
+ stdio: "ignore"
955
+ });
956
+ child.on("error", () => {
957
+ });
958
+ child.unref();
959
+ diag(harness, "daemon_start_spawned", { apiUrl: cfg.apiUrl });
960
+ } catch {
961
+ }
962
+ }
963
+ async function ensureDaemon(cfg, harness, opts = {}) {
964
+ if (cfg.serverMode !== "daemon") return;
965
+ if (await isServerHealthy(cfg.apiUrl)) return;
966
+ if (!preflightDaemon(cfg, harness)) return;
967
+ startDaemonDetached(cfg, harness, opts.spawnFn);
968
+ await waitForHealth(cfg.apiUrl, opts.waitMs ?? 0);
969
+ }
970
+ async function waitForHealth(baseUrl, budgetMs, pollMs = 1e3) {
971
+ const deadline = Date.now() + budgetMs;
972
+ while (Date.now() < deadline) {
973
+ await new Promise((r) => setTimeout(r, pollMs));
974
+ if (await isServerHealthy(baseUrl)) return true;
975
+ }
976
+ return false;
977
+ }
978
+ function preflightDaemon(cfg, harness) {
979
+ if (!hasUvx()) {
980
+ diag(harness, "daemon_uvx_missing", { apiUrl: cfg.apiUrl });
981
+ log.warn(harness, "daemon mode needs `uv` on PATH \u2014 see https://docs.astral.sh/uv/");
982
+ return false;
983
+ }
984
+ if (!hasRustToolchain()) {
985
+ diag(harness, "daemon_rust_missing", { platform: process.platform });
986
+ log.warn(
987
+ harness,
988
+ "daemon mode on macOS needs a current Rust toolchain (litellm ships no macOS wheel) \u2014 install from https://rustup.rs, then `rustup default stable && rustup update`"
989
+ );
990
+ return false;
991
+ }
992
+ if (!detectLlm()) {
993
+ diag(harness, "daemon_no_llm", {});
994
+ log.warn(
995
+ harness,
996
+ "daemon mode needs an LLM for fact extraction \u2014 set OPENAI_API_KEY (or ANTHROPIC_API_KEY / GEMINI_API_KEY / HINDSIGHT_API_LLM_PROVIDER), or install the Claude Code CLI"
997
+ );
998
+ return false;
999
+ }
1000
+ return true;
1001
+ }
1002
+
863
1003
  // src/core/transcript.ts
864
1004
  import { readFileSync as readFileSync4 } from "fs";
865
1005
 
@@ -902,10 +1042,10 @@ function actionLine(tool, input) {
902
1042
  import { readFileSync as readFileSync7 } from "fs";
903
1043
 
904
1044
  // src/core/git.ts
905
- import { execFileSync as execFileSync2 } from "child_process";
1045
+ import { execFileSync as execFileSync3 } from "child_process";
906
1046
  import { resolve } from "path";
907
1047
  function git(repo, ...args) {
908
- return execFileSync2("git", ["-C", repo, ...args], { encoding: "utf8", maxBuffer: 1 << 28 });
1048
+ return execFileSync3("git", ["-C", repo, ...args], { encoding: "utf8", maxBuffer: 1 << 28 });
909
1049
  }
910
1050
  function gitHeadSha(dir) {
911
1051
  try {
@@ -931,14 +1071,14 @@ function hasGitHistory(dir) {
931
1071
  }
932
1072
 
933
1073
  // src/core/status.ts
934
- import { execFileSync as execFileSync3 } from "child_process";
1074
+ import { execFileSync as execFileSync4 } from "child_process";
935
1075
 
936
1076
  // src/core/survey.ts
937
- import { spawn as realSpawn2 } from "child_process";
1077
+ import { spawn as realSpawn3 } from "child_process";
938
1078
  import { accessSync, constants, existsSync as existsSync2 } from "fs";
939
1079
  import { homedir as homedir3 } from "os";
940
- import { delimiter, dirname as dirname5, join as join6 } from "path";
941
- import { fileURLToPath as fileURLToPath2 } from "url";
1080
+ import { delimiter, dirname as dirname6, join as join7 } from "path";
1081
+ import { fileURLToPath as fileURLToPath3 } from "url";
942
1082
  var SURVEY_DOC_IDS = [
943
1083
  "repository-component-map",
944
1084
  "repository-core-concepts",
@@ -948,7 +1088,7 @@ var SURVEY_DOC_IDS = [
948
1088
  function resolveClaudeBin(explicit) {
949
1089
  if (explicit) return explicit;
950
1090
  if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
951
- const nativeInstallPath = join6(homedir3(), ".claude", "local", "claude");
1091
+ const nativeInstallPath = join7(homedir3(), ".claude", "local", "claude");
952
1092
  try {
953
1093
  if (existsSync2(nativeInstallPath)) return nativeInstallPath;
954
1094
  } catch {
@@ -976,7 +1116,7 @@ function binExists(bin) {
976
1116
  for (const dir of (process.env.PATH || "").split(delimiter)) {
977
1117
  if (!dir) continue;
978
1118
  try {
979
- accessSync(join6(dir, bin), constants.X_OK);
1119
+ accessSync(join7(dir, bin), constants.X_OK);
980
1120
  return true;
981
1121
  } catch {
982
1122
  }
@@ -1083,9 +1223,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
1083
1223
  }
1084
1224
  function startCodebaseSurvey(repoDir, opts = {}) {
1085
1225
  try {
1086
- const spawnFn = opts.spawn ?? realSpawn2;
1226
+ const spawnFn = opts.spawn ?? realSpawn3;
1087
1227
  const exists = opts.exists ?? binExists;
1088
- const mcpServerPath = opts.mcpServerPath ?? join6(dirname5(fileURLToPath2(import.meta.url)), "mcp-server.js");
1228
+ const mcpServerPath = opts.mcpServerPath ?? join7(dirname6(fileURLToPath3(import.meta.url)), "mcp-server.js");
1089
1229
  const preferred = opts.harness ?? "claude-code";
1090
1230
  const order = [
1091
1231
  preferred,
@@ -1126,8 +1266,8 @@ var DEEPEN_DIFF_TARGET = 300;
1126
1266
  // src/core/skill-sync.ts
1127
1267
  import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
1128
1268
  import { homedir as homedir4 } from "os";
1129
- import { dirname as dirname6, join as join7 } from "path";
1130
- import { fileURLToPath as fileURLToPath3 } from "url";
1269
+ import { dirname as dirname7, join as join8 } from "path";
1270
+ import { fileURLToPath as fileURLToPath4 } from "url";
1131
1271
  var SKILL_DIRS = {
1132
1272
  "claude-code": [".claude", "skills"],
1133
1273
  codex: [".agents", "skills"],
@@ -1136,17 +1276,17 @@ var SKILL_DIRS = {
1136
1276
  "cursor-cli": [".cursor", "skills"]
1137
1277
  };
1138
1278
  function packagedSkillDir() {
1139
- return join7(dirname6(fileURLToPath3(import.meta.url)), "..", "skill");
1279
+ return join8(dirname7(fileURLToPath4(import.meta.url)), "..", "skill");
1140
1280
  }
1141
1281
  function syncCompanionSkill(harness, opts = {}) {
1142
1282
  try {
1143
1283
  const parts = SKILL_DIRS[harness];
1144
1284
  if (!parts) return;
1145
1285
  const src = opts.srcDir ?? packagedSkillDir();
1146
- const srcMd = join7(src, "SKILL.md");
1286
+ const srcMd = join8(src, "SKILL.md");
1147
1287
  if (!existsSync3(srcMd)) return;
1148
- const dst = join7(opts.home ?? homedir4(), ...parts, "hindsight-coding-agent");
1149
- const dstMd = join7(dst, "SKILL.md");
1288
+ const dst = join8(opts.home ?? homedir4(), ...parts, "hindsight-coding-agent");
1289
+ const dstMd = join8(dst, "SKILL.md");
1150
1290
  if (!existsSync3(dstMd)) return;
1151
1291
  if (readFileSync6(srcMd, "utf8") !== readFileSync6(dstMd, "utf8")) {
1152
1292
  cpSync(src, dst, { recursive: true });
@@ -1173,9 +1313,9 @@ async function gitSyncNote(args) {
1173
1313
  const deepened = [...gitIds].filter((id) => id.startsWith("git:")).length;
1174
1314
  let target = DEEPEN_DIFF_TARGET;
1175
1315
  try {
1176
- const { execFileSync: execFileSync4 } = await import("child_process");
1316
+ const { execFileSync: execFileSync5 } = await import("child_process");
1177
1317
  const n = Number(
1178
- execFileSync4("git", ["-C", cwd, "rev-list", "--count", "HEAD"], { encoding: "utf8" }).trim()
1318
+ execFileSync5("git", ["-C", cwd, "rev-list", "--count", "HEAD"], { encoding: "utf8" }).trim()
1179
1319
  );
1180
1320
  if (n > 0) target = Math.min(DEEPEN_DIFF_TARGET, n);
1181
1321
  } catch {
@@ -1317,6 +1457,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
1317
1457
  cfg = resolved.cfg;
1318
1458
  const bankId = resolved.bankId;
1319
1459
  if (cfg.disabled) return;
1460
+ await ensureDaemon(cfg, harness, { waitMs: DAEMON_WAIT_SESSION_START_MS });
1320
1461
  const client = makeClient({ apiUrl: cfg.apiUrl, apiToken: cfg.apiToken, bank: bankId });
1321
1462
  const out = await buildSessionStartContext({ cwd, bankId, cfg, client, harness });
1322
1463
  if (out.deferInitialReflect && sessionId) {
@@ -1490,17 +1631,17 @@ function readCopilotTranscript(path) {
1490
1631
  // src/core/transcript-grok.ts
1491
1632
  import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
1492
1633
  import { homedir as homedir5 } from "os";
1493
- import { join as join8 } from "path";
1634
+ import { join as join9 } from "path";
1494
1635
  var CHAT_HISTORY = "chat_history.jsonl";
1495
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join8(homedir5(), ".grok")) {
1496
- const sessionsDir = join8(grokHome, "sessions");
1497
- const direct = join8(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1636
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join9(homedir5(), ".grok")) {
1637
+ const sessionsDir = join9(grokHome, "sessions");
1638
+ const direct = join9(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
1498
1639
  if (existsSync4(direct)) return direct;
1499
1640
  try {
1500
1641
  for (const candidate of readdirSync(sessionsDir)) {
1501
- const directory = join8(sessionsDir, candidate);
1502
- if (readFileSync12(join8(directory, ".cwd"), "utf8").trim() === cwd) {
1503
- return join8(directory, sessionId, CHAT_HISTORY);
1642
+ const directory = join9(sessionsDir, candidate);
1643
+ if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
1644
+ return join9(directory, sessionId, CHAT_HISTORY);
1504
1645
  }
1505
1646
  }
1506
1647
  } catch {
@@ -1544,9 +1685,9 @@ function readGrokTranscript(path) {
1544
1685
  import { existsSync as existsSync5 } from "fs";
1545
1686
  import { createRequire } from "module";
1546
1687
  import { homedir as homedir6 } from "os";
1547
- import { join as join9 } from "path";
1688
+ import { join as join10 } from "path";
1548
1689
  function devinSessionDb(home = homedir6()) {
1549
- return join9(home, ".local", "share", "devin", "cli", "sessions.db");
1690
+ return join10(home, ".local", "share", "devin", "cli", "sessions.db");
1550
1691
  }
1551
1692
  function parseDevinMessages(nodes) {
1552
1693
  const messages = /* @__PURE__ */ new Map();