@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
package/dist/kilo.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
 
@@ -32180,9 +32180,16 @@ var HindsightClient = class {
32180
32180
  body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
32181
32181
  signal: ctrl.signal
32182
32182
  });
32183
- if (!resp.ok) throw new Error(`reflect ${resp.status}${this.authHint(resp.status)}`);
32183
+ if (!resp.ok)
32184
+ throw new Error(
32185
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
32186
+ );
32184
32187
  const data = await resp.json();
32185
32188
  return (data.text || "").trim();
32189
+ } catch (e) {
32190
+ if (ctrl.signal.aborted)
32191
+ throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
32192
+ throw e;
32186
32193
  } finally {
32187
32194
  clearTimeout(timer);
32188
32195
  }
@@ -32728,7 +32735,7 @@ function resolveHostMemory(harness, directory) {
32728
32735
  // src/core/knowledge-tools.ts
32729
32736
  import { existsSync as existsSync3 } from "fs";
32730
32737
  import { homedir as homedir4 } from "os";
32731
- import { join as join8 } from "path";
32738
+ import { join as join9 } from "path";
32732
32739
 
32733
32740
  // src/core/status.ts
32734
32741
  import { execFileSync as execFileSync2 } from "child_process";
@@ -32769,11 +32776,31 @@ function parsePageList(raw) {
32769
32776
  }
32770
32777
 
32771
32778
  // src/core/survey.ts
32772
- import { spawn as realSpawn2 } from "child_process";
32779
+ import { spawn as realSpawn3 } from "child_process";
32780
+ import { createHash as createHash2 } from "crypto";
32773
32781
  import { existsSync as existsSync2 } from "fs";
32774
- import { homedir as homedir3 } from "os";
32775
- import { dirname as dirname5, join as join7 } from "path";
32782
+ import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
32783
+ import { dirname as dirname5, join as join8 } from "path";
32776
32784
  import { fileURLToPath as fileURLToPath2 } from "url";
32785
+
32786
+ // src/core/survey-lease.ts
32787
+ import { spawn as realSpawn2 } from "child_process";
32788
+ import { randomUUID } from "crypto";
32789
+ import {
32790
+ mkdirSync as mkdirSync2,
32791
+ mkdtempSync,
32792
+ readdirSync,
32793
+ renameSync,
32794
+ rmdirSync,
32795
+ rmSync,
32796
+ statSync,
32797
+ unlinkSync,
32798
+ utimesSync,
32799
+ writeFileSync
32800
+ } from "fs";
32801
+ import { join as join7 } from "path";
32802
+
32803
+ // src/core/survey.ts
32777
32804
  var SURVEY_DOC_IDS = [
32778
32805
  "repository-component-map",
32779
32806
  "repository-core-concepts",
@@ -32891,7 +32918,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
32891
32918
  inputSchema: {},
32892
32919
  annotations: READ_ONLY_ANNOTATIONS,
32893
32920
  handler: async (_args) => {
32894
- const configPath = process.env.HINDSIGHT_CONFIG || join8(homedir4(), ".hindsight", "coding-agent.json");
32921
+ const configPath = process.env.HINDSIGHT_CONFIG || join9(homedir4(), ".hindsight", "coding-agent.json");
32895
32922
  const harness = opts.harness ?? "unknown";
32896
32923
  const cfg = applyBankConfig(
32897
32924
  loadConfig({ harness: opts.harness }),