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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/antigravity-hook.js +67 -33
  2. package/dist/antigravity-stop-hook.js +61 -31
  3. package/dist/claude-hook.js +67 -33
  4. package/dist/claude-sessionstart-hook.js +239 -71
  5. package/dist/claude-stop-hook.js +61 -31
  6. package/dist/cline.js +213 -50
  7. package/dist/codex-hook.js +67 -33
  8. package/dist/codex-sessionstart-hook.js +239 -71
  9. package/dist/codex-stop-hook.js +61 -31
  10. package/dist/copilot-hook.js +67 -33
  11. package/dist/copilot-sessionstart-hook.js +239 -71
  12. package/dist/copilot-stop-hook.js +61 -31
  13. package/dist/cursor-hook.js +67 -33
  14. package/dist/cursor-sessionstart-hook.js +239 -71
  15. package/dist/cursor-stop-hook.js +61 -31
  16. package/dist/dcode-hook.js +67 -33
  17. package/dist/dcode-sessionstart-hook.js +239 -71
  18. package/dist/dcode-stop-hook.js +61 -31
  19. package/dist/deepen.js +40 -13
  20. package/dist/devin-hook.js +67 -33
  21. package/dist/devin-sessionstart-hook.js +239 -71
  22. package/dist/devin-stop-hook.js +61 -31
  23. package/dist/droid-hook.js +67 -33
  24. package/dist/droid-sessionstart-hook.js +239 -71
  25. package/dist/droid-stop-hook.js +61 -31
  26. package/dist/dsh.js +215 -52
  27. package/dist/grok-hook.js +67 -33
  28. package/dist/grok-sessionstart-hook.js +239 -71
  29. package/dist/grok-stop-hook.js +61 -31
  30. package/dist/index.js +215 -52
  31. package/dist/installer.js +1030 -268
  32. package/dist/kilo.js +215 -52
  33. package/dist/mcp-server.js +33 -6
  34. package/dist/opencode2.js +215 -52
  35. package/dist/pi.js +214 -51
  36. package/dist/prime-agent.js +214 -51
  37. package/dist/qwen-hook.js +67 -33
  38. package/dist/qwen-sessionstart-hook.js +239 -71
  39. package/dist/qwen-stop-hook.js +61 -31
  40. package/dist/status.js +31 -4
  41. package/dist/survey-supervisor.js +81 -0
  42. package/dist/zcode-hook.js +67 -33
  43. package/dist/zcode-sessionstart-hook.js +239 -71
  44. package/dist/zcode-stop-hook.js +61 -31
  45. package/package.json +2 -1
  46. package/plugin.json +1 -1
@@ -922,9 +922,16 @@ var HindsightClient = class {
922
922
  body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
923
923
  signal: ctrl.signal
924
924
  });
925
- if (!resp.ok) throw new Error(`reflect ${resp.status}${this.authHint(resp.status)}`);
925
+ if (!resp.ok)
926
+ throw new Error(
927
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
928
+ );
926
929
  const data = await resp.json();
927
930
  return (data.text || "").trim();
931
+ } catch (e) {
932
+ if (ctrl.signal.aborted)
933
+ throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
934
+ throw e;
928
935
  } finally {
929
936
  clearTimeout(timer);
930
937
  }
@@ -2173,7 +2180,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
2173
2180
  }
2174
2181
 
2175
2182
  // src/core/session-start.ts
2176
- import { readFileSync as readFileSync9 } from "fs";
2183
+ import { readFileSync as readFileSync10 } from "fs";
2177
2184
 
2178
2185
  // src/core/git.ts
2179
2186
  import { execFileSync as execFileSync2 } from "child_process";
@@ -2183,24 +2190,42 @@ import { resolve as resolve2 } from "path";
2183
2190
  import { execFileSync as execFileSync3 } from "child_process";
2184
2191
 
2185
2192
  // src/core/survey.ts
2186
- import { spawn as realSpawn3 } from "child_process";
2193
+ import { spawn as realSpawn4 } from "child_process";
2194
+ import { createHash as createHash4 } from "crypto";
2187
2195
  import { existsSync as existsSync3 } from "fs";
2188
- import { homedir as homedir3 } from "os";
2189
- import { dirname as dirname8, join as join10 } from "path";
2196
+ import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
2197
+ import { dirname as dirname8, join as join11 } from "path";
2190
2198
  import { fileURLToPath as fileURLToPath3 } from "url";
2191
2199
 
2200
+ // src/core/survey-lease.ts
2201
+ import { spawn as realSpawn3 } from "child_process";
2202
+ import { randomUUID } from "crypto";
2203
+ import {
2204
+ mkdirSync as mkdirSync4,
2205
+ mkdtempSync,
2206
+ readdirSync,
2207
+ renameSync as renameSync2,
2208
+ rmdirSync,
2209
+ rmSync as rmSync2,
2210
+ statSync as statSync3,
2211
+ unlinkSync,
2212
+ utimesSync,
2213
+ writeFileSync as writeFileSync2
2214
+ } from "fs";
2215
+ import { join as join10 } from "path";
2216
+
2192
2217
  // src/core/auto-update.ts
2193
- import { spawn as realSpawn4 } from "child_process";
2218
+ import { spawn as realSpawn5 } from "child_process";
2194
2219
  import {
2195
2220
  existsSync as existsSync4,
2196
- mkdirSync as mkdirSync4,
2221
+ mkdirSync as mkdirSync5,
2197
2222
  readFileSync as readFileSync7,
2198
2223
  realpathSync as realpathSync2,
2199
- unlinkSync,
2200
- writeFileSync as writeFileSync2
2224
+ unlinkSync as unlinkSync2,
2225
+ writeFileSync as writeFileSync3
2201
2226
  } from "fs";
2202
- import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
2203
- import { dirname as dirname9, join as join11 } from "path";
2227
+ import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
2228
+ import { dirname as dirname9, join as join12 } from "path";
2204
2229
  import { fileURLToPath as fileURLToPath4 } from "url";
2205
2230
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2206
2231
  var LOCK_STALE_MS = 10 * 60 * 1e3;
@@ -2208,9 +2233,14 @@ var LOCK_STALE_MS = 10 * 60 * 1e3;
2208
2233
  // src/core/skill-sync.ts
2209
2234
  import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
2210
2235
  import { homedir as homedir5 } from "os";
2211
- import { dirname as dirname10, join as join12 } from "path";
2236
+ import { dirname as dirname10, join as join13 } from "path";
2212
2237
  import { fileURLToPath as fileURLToPath5 } from "url";
2213
2238
 
2239
+ // src/core/legacy.ts
2240
+ import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2241
+ import { homedir as homedir6 } from "os";
2242
+ import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
2243
+
2214
2244
  // src/core/transcript-codex.ts
2215
2245
  function isSyntheticUserText(text) {
2216
2246
  const s = text.trimStart();
@@ -2341,19 +2371,19 @@ function readCopilotTranscript(path) {
2341
2371
  }
2342
2372
 
2343
2373
  // src/core/transcript-grok.ts
2344
- import { existsSync as existsSync6, readFileSync as readFileSync10, readdirSync } from "fs";
2345
- import { homedir as homedir6 } from "os";
2346
- import { join as join13 } from "path";
2374
+ import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
2375
+ import { homedir as homedir7 } from "os";
2376
+ import { join as join15 } from "path";
2347
2377
  var CHAT_HISTORY = "chat_history.jsonl";
2348
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join13(homedir6(), ".grok")) {
2349
- const sessionsDir = join13(grokHome, "sessions");
2350
- const direct = join13(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2351
- if (existsSync6(direct)) return direct;
2378
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
2379
+ const sessionsDir = join15(grokHome, "sessions");
2380
+ const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2381
+ if (existsSync7(direct)) return direct;
2352
2382
  try {
2353
- for (const candidate of readdirSync(sessionsDir)) {
2354
- const directory = join13(sessionsDir, candidate);
2355
- if (readFileSync10(join13(directory, ".cwd"), "utf8").trim() === cwd) {
2356
- return join13(directory, sessionId, CHAT_HISTORY);
2383
+ for (const candidate of readdirSync2(sessionsDir)) {
2384
+ const directory = join15(sessionsDir, candidate);
2385
+ if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
2386
+ return join15(directory, sessionId, CHAT_HISTORY);
2357
2387
  }
2358
2388
  }
2359
2389
  } catch {
@@ -2388,12 +2418,12 @@ function readGrokTranscript(path) {
2388
2418
  }
2389
2419
 
2390
2420
  // src/core/transcript-devin.ts
2391
- import { existsSync as existsSync7 } from "fs";
2421
+ import { existsSync as existsSync8 } from "fs";
2392
2422
  import { createRequire } from "module";
2393
- import { homedir as homedir7 } from "os";
2394
- import { join as join14 } from "path";
2395
- function devinSessionDb(home = homedir7()) {
2396
- return join14(home, ".local", "share", "devin", "cli", "sessions.db");
2423
+ import { homedir as homedir8 } from "os";
2424
+ import { join as join16 } from "path";
2425
+ function devinSessionDb(home = homedir8()) {
2426
+ return join16(home, ".local", "share", "devin", "cli", "sessions.db");
2397
2427
  }
2398
2428
  function parseDevinMessages(nodes) {
2399
2429
  const messages = /* @__PURE__ */ new Map();
@@ -2430,7 +2460,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
2430
2460
  diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
2431
2461
  return [];
2432
2462
  }
2433
- if (!existsSync7(dbPath)) {
2463
+ if (!existsSync8(dbPath)) {
2434
2464
  diag("devin-cli", "session_db_missing", { dbPath });
2435
2465
  return [];
2436
2466
  }
@@ -2703,7 +2733,7 @@ function readDroidTranscript(path) {
2703
2733
  }
2704
2734
 
2705
2735
  // src/core/transcript-zcode.ts
2706
- import { readFileSync as readFileSync11 } from "fs";
2736
+ import { readFileSync as readFileSync12 } from "fs";
2707
2737
  function messageText2(content) {
2708
2738
  if (typeof content === "string") return content.trim();
2709
2739
  if (!Array.isArray(content)) return "";
@@ -2713,7 +2743,7 @@ function readZcodeTranscript(path) {
2713
2743
  if (!path) return [];
2714
2744
  let body;
2715
2745
  try {
2716
- body = readFileSync11(path, "utf8");
2746
+ body = readFileSync12(path, "utf8");
2717
2747
  } catch {
2718
2748
  return [];
2719
2749
  }
package/dist/index.js CHANGED
@@ -972,9 +972,16 @@ var HindsightClient = class {
972
972
  body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
973
973
  signal: ctrl.signal
974
974
  });
975
- if (!resp.ok) throw new Error(`reflect ${resp.status}${this.authHint(resp.status)}`);
975
+ if (!resp.ok)
976
+ throw new Error(
977
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
978
+ );
976
979
  const data = await resp.json();
977
980
  return (data.text || "").trim();
981
+ } catch (e) {
982
+ if (ctrl.signal.aborted)
983
+ throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
984
+ throw e;
978
985
  } finally {
979
986
  clearTimeout(timer);
980
987
  }
@@ -16356,7 +16363,7 @@ config(en_default());
16356
16363
  // src/core/knowledge-tools.ts
16357
16364
  import { existsSync as existsSync4 } from "fs";
16358
16365
  import { homedir as homedir5 } from "os";
16359
- import { join as join10 } from "path";
16366
+ import { join as join11 } from "path";
16360
16367
 
16361
16368
  // src/core/status.ts
16362
16369
  import { execFileSync as execFileSync3 } from "child_process";
@@ -16442,11 +16449,86 @@ ${toolGuide(opts)}
16442
16449
  }
16443
16450
 
16444
16451
  // src/core/survey.ts
16445
- import { spawn as realSpawn4 } from "child_process";
16452
+ import { spawn as realSpawn5 } from "child_process";
16453
+ import { createHash as createHash2 } from "crypto";
16446
16454
  import { existsSync as existsSync3 } from "fs";
16447
- import { homedir as homedir4 } from "os";
16448
- import { dirname as dirname7, join as join9 } from "path";
16455
+ import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
16456
+ import { dirname as dirname7, join as join10 } from "path";
16449
16457
  import { fileURLToPath as fileURLToPath4 } from "url";
16458
+
16459
+ // src/core/survey-lease.ts
16460
+ import { spawn as realSpawn4 } from "child_process";
16461
+ import { randomUUID } from "crypto";
16462
+ import {
16463
+ mkdirSync as mkdirSync3,
16464
+ mkdtempSync,
16465
+ readdirSync,
16466
+ renameSync,
16467
+ rmdirSync,
16468
+ rmSync,
16469
+ statSync,
16470
+ unlinkSync as unlinkSync2,
16471
+ utimesSync,
16472
+ writeFileSync as writeFileSync2
16473
+ } from "fs";
16474
+ import { join as join9 } from "path";
16475
+ var LEASE_STALE_MS = 3e4;
16476
+ var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
16477
+ function tryRename(from, to) {
16478
+ try {
16479
+ renameSync(from, to);
16480
+ return true;
16481
+ } catch {
16482
+ return false;
16483
+ }
16484
+ }
16485
+ function releaseLease(lease) {
16486
+ try {
16487
+ unlinkSync2(join9(lease.directory, lease.owner));
16488
+ } catch {
16489
+ return;
16490
+ }
16491
+ try {
16492
+ rmdirSync(lease.directory);
16493
+ } catch {
16494
+ }
16495
+ }
16496
+ function reclaimIfStale(directory, staleMs) {
16497
+ const owners = readdirSync(directory);
16498
+ if (owners.length === 0) {
16499
+ try {
16500
+ rmdirSync(directory);
16501
+ } catch {
16502
+ }
16503
+ return true;
16504
+ }
16505
+ if (owners.length !== 1) return false;
16506
+ const age = Date.now() - statSync(join9(directory, owners[0])).mtimeMs;
16507
+ if (Math.abs(age) <= staleMs) return false;
16508
+ releaseLease({ directory, owner: owners[0] });
16509
+ return true;
16510
+ }
16511
+ function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
16512
+ let staging;
16513
+ try {
16514
+ mkdirSync3(root, { recursive: true, mode: 448 });
16515
+ staging = mkdtempSync(join9(root, "claim-"));
16516
+ const owner = randomUUID();
16517
+ writeFileSync2(join9(staging, owner), "", { flag: "wx", mode: 384 });
16518
+ const directory = join9(root, `survey-${key}.lock`);
16519
+ if (!tryRename(staging, directory)) {
16520
+ if (!reclaimIfStale(directory, staleMs)) return void 0;
16521
+ if (!tryRename(staging, directory)) return void 0;
16522
+ }
16523
+ return { directory, owner };
16524
+ } catch {
16525
+ return void 0;
16526
+ } finally {
16527
+ if (staging) rmSync(staging, { recursive: true, force: true });
16528
+ }
16529
+ }
16530
+
16531
+ // src/core/survey.ts
16450
16532
  var SURVEY_DOC_IDS = [
16451
16533
  "repository-component-map",
16452
16534
  "repository-core-concepts",
@@ -16456,7 +16538,7 @@ var SURVEY_DOC_IDS = [
16456
16538
  function resolveClaudeBin(explicit) {
16457
16539
  if (explicit) return explicit;
16458
16540
  if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
16459
- const nativeInstallPath = join9(homedir4(), ".claude", "local", "claude");
16541
+ const nativeInstallPath = join10(homedir4(), ".claude", "local", "claude");
16460
16542
  try {
16461
16543
  if (existsSync3(nativeInstallPath)) return nativeInstallPath;
16462
16544
  } catch {
@@ -16581,11 +16663,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
16581
16663
  }
16582
16664
  }
16583
16665
  }
16584
- function startCodebaseSurvey(repoDir, opts = {}) {
16666
+ async function startCodebaseSurvey(repoDir, opts = {}) {
16585
16667
  try {
16586
- const spawnFn = opts.spawn ?? realSpawn4;
16668
+ const spawnFn = opts.spawn ?? realSpawn5;
16587
16669
  const exists = opts.exists ?? binOnPath;
16588
- const mcpServerPath = opts.mcpServerPath ?? join9(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
16670
+ const mcpServerPath = opts.mcpServerPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
16589
16671
  const preferred = opts.harness ?? "claude-code";
16590
16672
  const order = [
16591
16673
  preferred,
@@ -16605,20 +16687,51 @@ function startCodebaseSurvey(repoDir, opts = {}) {
16605
16687
  budgetUsd: opts.budgetUsd,
16606
16688
  mcpServerPath
16607
16689
  });
16608
- const child = spawnFn(plan.bin, plan.args, {
16609
- cwd: repoDir,
16610
- detached: true,
16611
- stdio: "ignore",
16612
- windowsHide: true,
16613
- env: plan.env
16614
- });
16615
- child.on("error", () => {
16690
+ const { cfg, bankId } = resolveHostConfig(harness, repoDir);
16691
+ if (cfg.disabled) return false;
16692
+ const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
16693
+ const lease = acquireLease(
16694
+ opts.lease?.dir ?? join10(tmpdir3(), "hindsight-coding-agent", "surveys"),
16695
+ key,
16696
+ opts.lease?.staleMs ?? LEASE_STALE_MS
16697
+ );
16698
+ if (!lease) return false;
16699
+ const spec = {
16700
+ lease,
16701
+ bin: plan.bin,
16702
+ args: plan.args,
16703
+ ...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
16704
+ };
16705
+ const supervisorPath = opts.supervisorPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
16706
+ return await new Promise((resolve3) => {
16707
+ try {
16708
+ const child = spawnFn("node", [supervisorPath], {
16709
+ cwd: repoDir,
16710
+ detached: true,
16711
+ stdio: "ignore",
16712
+ windowsHide: true,
16713
+ env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
16714
+ });
16715
+ let spawned = false;
16716
+ child.on("error", () => {
16717
+ if (spawned) return;
16718
+ releaseLease(lease);
16719
+ resolve3(false);
16720
+ });
16721
+ child.once("spawn", () => {
16722
+ spawned = true;
16723
+ child.unref();
16724
+ resolve3(true);
16725
+ });
16726
+ } catch {
16727
+ releaseLease(lease);
16728
+ resolve3(false);
16729
+ }
16616
16730
  });
16617
- child.unref();
16618
- return;
16619
16731
  }
16620
16732
  } catch {
16621
16733
  }
16734
+ return false;
16622
16735
  }
16623
16736
 
16624
16737
  // src/core/status.ts
@@ -16731,7 +16844,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
16731
16844
  inputSchema: {},
16732
16845
  annotations: READ_ONLY_ANNOTATIONS,
16733
16846
  handler: async (_args) => {
16734
- const configPath = process.env.HINDSIGHT_CONFIG || join10(homedir5(), ".hindsight", "coding-agent.json");
16847
+ const configPath = process.env.HINDSIGHT_CONFIG || join11(homedir5(), ".hindsight", "coding-agent.json");
16735
16848
  const harness = opts.harness ?? "unknown";
16736
16849
  const cfg = applyBankConfig(
16737
16850
  loadConfig({ harness: opts.harness }),
@@ -16867,7 +16980,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
16867
16980
  }
16868
16981
 
16869
16982
  // src/core/retain-cursor.ts
16870
- import { createHash as createHash2 } from "crypto";
16983
+ import { createHash as createHash3 } from "crypto";
16871
16984
  var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
16872
16985
  var PENDING_MAX_BYTES = 256 * 1024;
16873
16986
  function pendingReplayable(cursor, now) {
@@ -16877,7 +16990,7 @@ function pendingReplayable(cursor, now) {
16877
16990
  return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
16878
16991
  }
16879
16992
  function fingerprintTurns(turns, count) {
16880
- const h = createHash2("sha1").update(String(count));
16993
+ const h = createHash3("sha1").update(String(count));
16881
16994
  for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
16882
16995
  return h.digest("hex");
16883
16996
  }
@@ -16900,13 +17013,13 @@ function memoryCursorStore() {
16900
17013
  }
16901
17014
 
16902
17015
  // src/core/uuid.ts
16903
- import { createHash as createHash3 } from "crypto";
17016
+ import { createHash as createHash4 } from "crypto";
16904
17017
  var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
16905
17018
  function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
16906
17019
  const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
16907
17020
  if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
16908
17021
  const bytes = Buffer.from(
16909
- createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
17022
+ createHash4("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
16910
17023
  );
16911
17024
  bytes[6] = bytes[6] & 15 | 80;
16912
17025
  bytes[8] = bytes[8] & 63 | 128;
@@ -17110,12 +17223,12 @@ function buildRetainStamp(cfg, ctx) {
17110
17223
  }
17111
17224
 
17112
17225
  // src/core/session-start.ts
17113
- import { readFileSync as readFileSync6 } from "fs";
17226
+ import { readFileSync as readFileSync7 } from "fs";
17114
17227
 
17115
17228
  // src/core/skill-sync.ts
17116
17229
  import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
17117
17230
  import { homedir as homedir6 } from "os";
17118
- import { dirname as dirname8, join as join11 } from "path";
17231
+ import { dirname as dirname8, join as join12 } from "path";
17119
17232
  import { fileURLToPath as fileURLToPath5 } from "url";
17120
17233
 
17121
17234
  // src/core/brand.ts
@@ -17132,29 +17245,66 @@ function brandWord() {
17132
17245
  return `${out}\x1B[0m`;
17133
17246
  }
17134
17247
 
17248
+ // src/core/legacy.ts
17249
+ import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
17250
+ import { homedir as homedir7 } from "os";
17251
+ import { join as join13, relative, isAbsolute as isAbsolute2 } from "path";
17252
+ var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
17253
+ function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")) {
17254
+ const registry3 = readJson(join13(claudeDir, "plugins", "installed_plugins.json"));
17255
+ const plugins = registry3?.plugins;
17256
+ if (!plugins || typeof plugins !== "object") return void 0;
17257
+ const enabled = readJson(join13(claudeDir, "settings.json"))?.enabledPlugins;
17258
+ for (const [key, raw] of Object.entries(plugins)) {
17259
+ if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
17260
+ if (enabled && enabled[key] === false) continue;
17261
+ const installs = Array.isArray(raw) ? raw : [raw];
17262
+ const active = installs.some((i) => {
17263
+ if (!i || typeof i !== "object") return false;
17264
+ if (typeof i.projectPath !== "string") return true;
17265
+ const rel = relative(i.projectPath, cwd);
17266
+ return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
17267
+ });
17268
+ if (active) return key;
17269
+ }
17270
+ return void 0;
17271
+ }
17272
+ function readJson(path) {
17273
+ try {
17274
+ const parsed = JSON.parse(readFileSync5(path, "utf8"));
17275
+ return parsed && typeof parsed === "object" ? parsed : void 0;
17276
+ } catch {
17277
+ return void 0;
17278
+ }
17279
+ }
17280
+ function legacyClaudePluginWarning(key) {
17281
+ return `\u26A0\uFE0F The old Hindsight Claude Code plugin (${key}) is still installed \u2014 it runs alongside this one, so memory is recalled and retained twice.
17282
+ \u21B3 remove it: claude plugin uninstall ${key}`;
17283
+ }
17284
+
17135
17285
  // src/core/session-cache.ts
17136
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
17137
- import { tmpdir as tmpdir3 } from "os";
17138
- import { dirname as dirname9, join as join12 } from "path";
17286
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
17287
+ import { tmpdir as tmpdir4 } from "os";
17288
+ import { dirname as dirname9, join as join14 } from "path";
17139
17289
  function sessionCacheFile(harness, sessionId) {
17140
- return join12(tmpdir3(), `hindsight-${harness}`, `${sessionId}.json`);
17290
+ return join14(tmpdir4(), `hindsight-${harness}`, `${sessionId}.json`);
17141
17291
  }
17142
17292
  function readSessionCache(cacheFile) {
17143
17293
  try {
17144
- return JSON.parse(readFileSync5(cacheFile, "utf8"));
17294
+ return JSON.parse(readFileSync6(cacheFile, "utf8"));
17145
17295
  } catch {
17146
17296
  return {};
17147
17297
  }
17148
17298
  }
17149
17299
  function writeFileAtomic(path, body) {
17150
- mkdirSync3(dirname9(path), { recursive: true });
17300
+ mkdirSync4(dirname9(path), { recursive: true });
17151
17301
  const tmp = `${path}.${process.pid}.tmp`;
17152
17302
  try {
17153
- writeFileSync2(tmp, body);
17154
- renameSync(tmp, path);
17303
+ writeFileSync3(tmp, body);
17304
+ renameSync2(tmp, path);
17155
17305
  } catch (e) {
17156
17306
  try {
17157
- rmSync(tmp, { force: true });
17307
+ rmSync2(tmp, { force: true });
17158
17308
  } catch {
17159
17309
  }
17160
17310
  throw e;
@@ -17247,13 +17397,13 @@ async function buildSessionStartContext(args) {
17247
17397
  startSeed(cwd, { limit: cfg.seedLimit, harness });
17248
17398
  if (docIds.size === 0) {
17249
17399
  if (cfg.codebaseSurvey !== false) {
17250
- startSurvey(cwd, {
17400
+ const started = await startSurvey(cwd, {
17251
17401
  harness,
17252
17402
  model: cfg.surveyModel,
17253
17403
  budgetUsd: cfg.surveyBudgetUsd
17254
17404
  });
17255
17405
  const sha = resolveHeadSha(cwd);
17256
- if (sha) recordSurveyBaseline(sha);
17406
+ if (started && sha) recordSurveyBaseline(sha);
17257
17407
  }
17258
17408
  diag(harness, "seed_started", { bank: bankId });
17259
17409
  } else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
@@ -17270,17 +17420,19 @@ async function buildSessionStartContext(args) {
17270
17420
  const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
17271
17421
  const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
17272
17422
  if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
17273
- startSurvey(cwd, {
17423
+ const started = await startSurvey(cwd, {
17274
17424
  harness,
17275
17425
  model: cfg.surveyModel,
17276
17426
  budgetUsd: cfg.surveyBudgetUsd
17277
17427
  });
17278
- recordSurveyBaseline(sha);
17279
- diag(harness, "survey_refresh", {
17280
- bank: bankId,
17281
- commits: sinceLast,
17282
- retry: findingsAbsent
17283
- });
17428
+ if (started) {
17429
+ recordSurveyBaseline(sha);
17430
+ diag(harness, "survey_refresh", {
17431
+ bank: bankId,
17432
+ commits: sinceLast,
17433
+ retry: findingsAbsent
17434
+ });
17435
+ }
17284
17436
  } else if (sinceLast === null) {
17285
17437
  recordSurveyBaseline(sha);
17286
17438
  }
@@ -17313,12 +17465,19 @@ async function buildSessionStartContext(args) {
17313
17465
  }).catch(() => void 0);
17314
17466
  }
17315
17467
  systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
17468
+ const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
17469
+ const legacyPlugin = detectLegacy?.(cwd);
17470
+ if (legacyPlugin) {
17471
+ systemMessage += `
17472
+ ${legacyClaudePluginWarning(legacyPlugin)}`;
17473
+ diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
17474
+ }
17316
17475
  diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
17317
17476
  return { systemMessage, additionalContext, deferInitialReflect };
17318
17477
  }
17319
17478
 
17320
17479
  // src/core/hook.ts
17321
- import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
17480
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
17322
17481
 
17323
17482
  // src/core/inject.ts
17324
17483
  function buildReflectQuery(prompt) {
@@ -17350,9 +17509,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
17350
17509
  }
17351
17510
 
17352
17511
  // src/core/turn-journal.ts
17353
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync } from "fs";
17354
- import { tmpdir as tmpdir4 } from "os";
17355
- import { dirname as dirname10, join as join13 } from "path";
17512
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
17513
+ import { tmpdir as tmpdir5 } from "os";
17514
+ import { dirname as dirname10, join as join15 } from "path";
17356
17515
 
17357
17516
  // src/core/transcript-util.ts
17358
17517
  var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
@@ -17407,13 +17566,14 @@ async function buildHookOutput(args) {
17407
17566
  } else if (cfg.autoReflect && reflectAnswer === void 0) {
17408
17567
  reflectRanThisTurn = true;
17409
17568
  const t0 = Date.now();
17569
+ const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
17410
17570
  try {
17411
17571
  reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
17412
17572
  // Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
17413
17573
  // supported default for bounded reflect calls; callers that explicitly invoke the MCP
17414
17574
  // tool still get the deeper high-budget path.
17415
17575
  budget: "low",
17416
- timeoutMs: Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS)
17576
+ timeoutMs
17417
17577
  });
17418
17578
  diag(harness, reflectAnswer ? "reflect_ok" : "reflect_empty", {
17419
17579
  ms: Date.now() - t0,
@@ -17431,7 +17591,10 @@ async function buildHookOutput(args) {
17431
17591
  });
17432
17592
  diag(harness, "reflect_failed", {
17433
17593
  ms: Date.now() - t0,
17434
- error: describeError(e),
17594
+ bank: client.bank,
17595
+ timeoutMs,
17596
+ // Wider than describeError's default: the server's error body is the useful part.
17597
+ error: describeError(e, 1500),
17435
17598
  query: prompt.slice(0, 80)
17436
17599
  });
17437
17600
  }
@@ -30154,12 +30317,12 @@ function tool(input) {
30154
30317
  tool.schema = external_exports2;
30155
30318
 
30156
30319
  // src/harness/registry.ts
30157
- import { readFileSync as readFileSync9 } from "fs";
30320
+ import { readFileSync as readFileSync10 } from "fs";
30158
30321
  var jsonChatReader = (harness) => ({
30159
30322
  describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
30160
30323
  async read(opts) {
30161
30324
  if (!opts.conversations) return [];
30162
- return JSON.parse(readFileSync9(opts.conversations, "utf8"));
30325
+ return JSON.parse(readFileSync10(opts.conversations, "utf8"));
30163
30326
  }
30164
30327
  });
30165
30328