@vectorize-io/hindsight-coding-agents 0.8.1 → 0.8.3

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 (64) hide show
  1. package/README.md +19 -5
  2. package/dist/antigravity-hook.js +98 -42
  3. package/dist/antigravity-statusline.js +6 -6
  4. package/dist/antigravity-stop-hook.js +135 -51
  5. package/dist/claude-hook.js +98 -42
  6. package/dist/claude-sessionstart-hook.js +386 -99
  7. package/dist/claude-stop-hook.js +135 -51
  8. package/dist/cline.js +433 -118
  9. package/dist/codebuddy-hook.js +98 -42
  10. package/dist/codebuddy-sessionstart-hook.js +386 -99
  11. package/dist/codebuddy-stop-hook.js +135 -51
  12. package/dist/codex-hook.js +98 -42
  13. package/dist/codex-sessionstart-hook.js +386 -99
  14. package/dist/codex-stop-hook.js +135 -51
  15. package/dist/copilot-hook.js +98 -42
  16. package/dist/copilot-sessionstart-hook.js +386 -99
  17. package/dist/copilot-stop-hook.js +135 -51
  18. package/dist/cursor-hook.js +98 -42
  19. package/dist/cursor-sessionstart-hook.js +386 -99
  20. package/dist/cursor-stop-hook.js +135 -51
  21. package/dist/daemon-start.js +10 -10
  22. package/dist/dcode-hook.js +98 -42
  23. package/dist/dcode-sessionstart-hook.js +386 -99
  24. package/dist/dcode-stop-hook.js +135 -51
  25. package/dist/deepen.js +193 -52
  26. package/dist/devin-hook.js +98 -42
  27. package/dist/devin-sessionstart-hook.js +386 -99
  28. package/dist/devin-stop-hook.js +135 -51
  29. package/dist/droid-hook.js +98 -42
  30. package/dist/droid-sessionstart-hook.js +386 -99
  31. package/dist/droid-stop-hook.js +135 -51
  32. package/dist/dsh.js +452 -125
  33. package/dist/grok-hook.js +98 -42
  34. package/dist/grok-sessionstart-hook.js +386 -99
  35. package/dist/grok-stop-hook.js +135 -51
  36. package/dist/hindsight-seed.js +6 -6
  37. package/dist/index.js +457 -137
  38. package/dist/installer.js +92 -80
  39. package/dist/kilo.js +457 -137
  40. package/dist/kimi-hook.js +98 -42
  41. package/dist/kimi-sessionstart-hook.js +386 -99
  42. package/dist/kimi-stop-hook.js +135 -51
  43. package/dist/mcp-server.js +180 -65
  44. package/dist/opencode2.js +613 -131
  45. package/dist/pi.js +433 -125
  46. package/dist/prime-agent.js +433 -125
  47. package/dist/qwen-hook.js +98 -42
  48. package/dist/qwen-sessionstart-hook.js +386 -99
  49. package/dist/qwen-stop-hook.js +135 -51
  50. package/dist/status.js +76 -18
  51. package/dist/survey-supervisor.js +73 -9
  52. package/dist/traecode-hook.js +98 -42
  53. package/dist/traecode-sessionstart-hook.js +386 -99
  54. package/dist/traecode-stop-hook.js +135 -51
  55. package/dist/workbuddy-hook.js +98 -42
  56. package/dist/workbuddy-sessionstart-hook.js +386 -99
  57. package/dist/workbuddy-stop-hook.js +135 -51
  58. package/dist/zcode-hook.js +98 -42
  59. package/dist/zcode-sessionstart-hook.js +386 -99
  60. package/dist/zcode-stop-hook.js +135 -51
  61. package/index.js +4 -1
  62. package/package.json +6 -4
  63. package/plugin.json +1 -1
  64. package/skill/SKILL.md +16 -4
@@ -207,14 +207,14 @@ function probeGitLayout(directory) {
207
207
  var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
208
208
  function applyTemplate(template, resolvers, what) {
209
209
  return template.replace(PLACEHOLDER, (_, name) => {
210
- const resolve3 = resolvers[name];
211
- if (!resolve3) {
210
+ const resolve4 = resolvers[name];
211
+ if (!resolve4) {
212
212
  console.error(
213
213
  `hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
214
214
  );
215
215
  return "unknown";
216
216
  }
217
- return resolve3();
217
+ return resolve4();
218
218
  });
219
219
  }
220
220
 
@@ -673,29 +673,33 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
673
673
  }
674
674
 
675
675
  // package.json
676
- var version = "0.8.1";
676
+ var version = "0.8.3";
677
677
 
678
678
  // src/core/util.ts
679
- import { accessSync, constants } from "fs";
680
- import { delimiter, join as join6 } from "path";
681
- function binOnPath(bin) {
682
- try {
683
- if (bin.includes("/")) {
684
- accessSync(bin, constants.X_OK);
679
+ import { accessSync, constants, statSync as statSync2 } from "fs";
680
+ import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
681
+ function binOnPath(bin, opts = {}) {
682
+ const platform = opts.platform ?? process.platform;
683
+ const env = opts.env ?? process.env;
684
+ const runnable = (file) => {
685
+ try {
686
+ if (!statSync2(file).isFile()) return false;
687
+ if (platform !== "win32") accessSync(file, constants.X_OK);
685
688
  return true;
689
+ } catch {
690
+ return false;
686
691
  }
687
- for (const dir of (process.env.PATH || "").split(delimiter)) {
688
- if (!dir) continue;
689
- try {
690
- accessSync(join6(dir, bin), constants.X_OK);
691
- return true;
692
- } catch {
693
- }
692
+ };
693
+ if (isAbsolute2(bin) || /[\\/]/.test(bin)) return runnable(bin) ? resolve2(bin) : void 0;
694
+ const names = platform !== "win32" || extname(bin) ? [bin] : (opts.exts ?? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")).filter(Boolean).map((ext) => bin + ext.toLowerCase());
695
+ for (const dir of (env.PATH || "").split(delimiter)) {
696
+ if (!dir) continue;
697
+ for (const name of names) {
698
+ const file = join6(dir, name);
699
+ if (runnable(file)) return resolve2(file);
694
700
  }
695
- return false;
696
- } catch {
697
- return false;
698
701
  }
702
+ return void 0;
699
703
  }
700
704
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
701
705
  function semverGte(version2, min) {
@@ -974,15 +978,19 @@ var HindsightClient = class {
974
978
  }
975
979
  /**
976
980
  * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
977
- * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
981
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
978
982
  * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
983
+ * Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
984
+ * of the process after one probe that hit a restarting server (#5735).
979
985
  */
980
986
  async supportsIdempotentRetain() {
981
- if (this.idempotentRetain === void 0) {
982
- this.idempotentRetain = await this.probeIdempotentRetain();
983
- this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
987
+ if (this.idempotentRetain) return true;
988
+ const supported = await this.probeIdempotentRetain();
989
+ if (supported || this.idempotentRetain === void 0) {
990
+ this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
984
991
  }
985
- return this.idempotentRetain;
992
+ this.idempotentRetain = supported;
993
+ return supported;
986
994
  }
987
995
  /** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
988
996
  * hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
@@ -2058,7 +2066,7 @@ function sessionRootDir(harness, sessionId, cwd) {
2058
2066
  }
2059
2067
 
2060
2068
  // src/core/turn-journal.ts
2061
- import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
2069
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
2062
2070
  import { tmpdir as tmpdir2 } from "os";
2063
2071
  import { dirname as dirname6, join as join9 } from "path";
2064
2072
 
@@ -2206,8 +2214,8 @@ async function waitBounded(p, ms) {
2206
2214
  try {
2207
2215
  await Promise.race([
2208
2216
  p,
2209
- new Promise((resolve3) => {
2210
- timer = setTimeout(resolve3, Math.max(ms, 0));
2217
+ new Promise((resolve4) => {
2218
+ timer = setTimeout(resolve4, Math.max(ms, 0));
2211
2219
  })
2212
2220
  ]);
2213
2221
  } finally {
@@ -2299,12 +2307,12 @@ function buildRetainStamp(cfg, ctx) {
2299
2307
  const base = resolversFor(ctx);
2300
2308
  const cache = /* @__PURE__ */ new Map();
2301
2309
  const resolvers = Object.fromEntries(
2302
- Object.entries(base).map(([name, resolve3]) => [
2310
+ Object.entries(base).map(([name, resolve4]) => [
2303
2311
  name,
2304
2312
  () => {
2305
2313
  const hit = cache.get(name);
2306
2314
  if (hit !== void 0) return hit;
2307
- const value = resolve3();
2315
+ const value = resolve4();
2308
2316
  cache.set(name, value);
2309
2317
  return value;
2310
2318
  }
@@ -2363,20 +2371,30 @@ import { join as join11 } from "path";
2363
2371
 
2364
2372
  // src/core/git.ts
2365
2373
  import { execFileSync as execFileSync2 } from "child_process";
2366
- import { resolve as resolve2 } from "path";
2374
+ import { resolve as resolve3 } from "path";
2375
+ var US = "";
2376
+ var RS = "";
2367
2377
  var GITLOG_HEAD = "gitlog-head:";
2368
- function git(repo, ...args) {
2378
+ var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
2379
+ function runGit(repo, args, env) {
2369
2380
  return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
2370
2381
  encoding: "utf8",
2371
2382
  maxBuffer: 1 << 28,
2372
2383
  windowsHide: true,
2384
+ env,
2373
2385
  // execFileSync otherwise forwards failed git stderr into the host's TUI,
2374
2386
  // even when callers catch the error. Keep diagnostics on the error instead.
2375
2387
  stdio: ["ignore", "pipe", "pipe"]
2376
2388
  });
2377
2389
  }
2390
+ function git(repo, ...args) {
2391
+ return runGit(repo, args);
2392
+ }
2393
+ function gitLocal(repo, ...args) {
2394
+ return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
2395
+ }
2378
2396
  function repoNameOf(repo) {
2379
- return projectNameOf(resolve2(repo));
2397
+ return projectNameOf(resolve3(repo));
2380
2398
  }
2381
2399
  function gitHeadSha(dir) {
2382
2400
  try {
@@ -2388,7 +2406,7 @@ function gitHeadSha(dir) {
2388
2406
  function commitsSince(dir, sinceSha) {
2389
2407
  if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
2390
2408
  try {
2391
- const n = Number.parseInt(git(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
2409
+ const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
2392
2410
  return Number.isFinite(n) ? n : null;
2393
2411
  } catch {
2394
2412
  return null;
@@ -2417,11 +2435,197 @@ import { execFileSync as execFileSync4 } from "child_process";
2417
2435
  // src/core/survey.ts
2418
2436
  import { execFileSync as execFileSync3, spawn as realSpawn4 } from "child_process";
2419
2437
  import { createHash as createHash4 } from "crypto";
2420
- import { existsSync as existsSync3 } from "fs";
2438
+ import { existsSync as existsSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
2421
2439
  import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2422
2440
  import { dirname as dirname8, join as join13 } from "path";
2423
2441
  import { fileURLToPath as fileURLToPath3 } from "url";
2424
2442
 
2443
+ // node_modules/smol-toml/dist/stringify.js
2444
+ var BARE_KEY = /^[a-z0-9-_]+$/i;
2445
+ var HAS_WELLFORMED = !!"".isWellFormed;
2446
+ function extendedTypeOf(obj) {
2447
+ let type = typeof obj;
2448
+ if (type === "object") {
2449
+ if (Array.isArray(obj))
2450
+ return "array";
2451
+ if (typeof obj.getUTCDate === "function" && obj instanceof Date)
2452
+ return "date";
2453
+ if (globalThis.Temporal) {
2454
+ if (obj.until) {
2455
+ if (obj instanceof Temporal.ZonedDateTime)
2456
+ return "temporal/tz+uc";
2457
+ if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
2458
+ return "temporal/uc";
2459
+ if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
2460
+ return "temporal";
2461
+ if (obj instanceof Temporal.PlainYearMonth)
2462
+ return "temporal/x";
2463
+ } else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
2464
+ return "temporal/x";
2465
+ }
2466
+ }
2467
+ }
2468
+ return type;
2469
+ }
2470
+ function isArrayOfTables(obj) {
2471
+ for (let i = 0; i < obj.length; i++) {
2472
+ if (extendedTypeOf(obj[i]) !== "object")
2473
+ return false;
2474
+ }
2475
+ return obj.length != 0;
2476
+ }
2477
+ function formatWellFormedStringUnchecked(s) {
2478
+ return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
2479
+ }
2480
+ function formatString(s) {
2481
+ return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
2482
+ }
2483
+ function formatKey(s) {
2484
+ if (BARE_KEY.test(s))
2485
+ return s;
2486
+ if (HAS_WELLFORMED && !s.isWellFormed())
2487
+ throw new RangeError("key contains illegal lone surrogates");
2488
+ return formatWellFormedStringUnchecked(s);
2489
+ }
2490
+ function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
2491
+ if (depth === 0) {
2492
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
2493
+ }
2494
+ switch (type) {
2495
+ // @ts-expect-error -- intentional fallthrough case
2496
+ case "number":
2497
+ if (isNaN(val))
2498
+ return "nan";
2499
+ if (val === Infinity)
2500
+ return "inf";
2501
+ if (val === -Infinity)
2502
+ return "-inf";
2503
+ if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
2504
+ return val.toFixed(1);
2505
+ case "bigint":
2506
+ case "boolean":
2507
+ case "temporal":
2508
+ return val.toString();
2509
+ case "string":
2510
+ return formatString(val);
2511
+ case "date":
2512
+ if (isNaN(val.getTime()))
2513
+ throw new TypeError("cannot serialize invalid date");
2514
+ return val.toISOString();
2515
+ case "object":
2516
+ return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
2517
+ case "array":
2518
+ return stringifyArray(val, depth, numberAsFloat, strictTemporal);
2519
+ // @ts-expect-error -- intentional fallthrough case
2520
+ case "temporal/tz+uc":
2521
+ if (strictTemporal) {
2522
+ let tz = val.timeZoneId;
2523
+ let tzc = tz.charCodeAt(0);
2524
+ if (
2525
+ // Classic offset
2526
+ tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
2527
+ (tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
2528
+ tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && // GMT is a TZ but it's for all intents and purposes equivalent to UTC. Safe to downgrade.
2529
+ !tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
2530
+ !tz.startsWith("Etc/"))
2531
+ ) {
2532
+ throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
2533
+ }
2534
+ }
2535
+ case "temporal/uc":
2536
+ if (strictTemporal && val.calendarId !== "iso8601")
2537
+ throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
2538
+ return val.toString({
2539
+ calendarName: "never",
2540
+ timeZoneName: "never"
2541
+ });
2542
+ case "temporal/x":
2543
+ throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
2544
+ }
2545
+ }
2546
+ function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
2547
+ let keys = Object.keys(obj);
2548
+ if (keys.length === 0)
2549
+ return "{}";
2550
+ let res = "{ ";
2551
+ for (let i = 0; i < keys.length; i++) {
2552
+ let k = keys[i];
2553
+ if (i)
2554
+ res += ", ";
2555
+ res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
2556
+ }
2557
+ return res + " }";
2558
+ }
2559
+ function stringifyArray(array, depth, numberAsFloat, strictTemporal) {
2560
+ if (array.length === 0)
2561
+ return "[]";
2562
+ let res = "[ ";
2563
+ for (let i = 0; i < array.length; i++) {
2564
+ if (i)
2565
+ res += ", ";
2566
+ if (array[i] === null || array[i] === void 0) {
2567
+ throw new TypeError("arrays cannot contain null or undefined values");
2568
+ }
2569
+ res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat, strictTemporal);
2570
+ }
2571
+ return res + " ]";
2572
+ }
2573
+ function stringifyArrayTable(array, key, depth, numberAsFloat, strictTemporal) {
2574
+ if (depth === 0) {
2575
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
2576
+ }
2577
+ let res = "";
2578
+ for (let i = 0; i < array.length; i++) {
2579
+ res += `${res && "\n"}[[${key}]]
2580
+ `;
2581
+ res += stringifyTable(0, array[i], key, depth, numberAsFloat, strictTemporal);
2582
+ }
2583
+ return res;
2584
+ }
2585
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
2586
+ if (depth === 0) {
2587
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
2588
+ }
2589
+ let preamble = "";
2590
+ let tables = "";
2591
+ let keys = Object.keys(obj);
2592
+ for (let i = 0; i < keys.length; i++) {
2593
+ let k = keys[i];
2594
+ if (obj[k] !== null && obj[k] !== void 0) {
2595
+ let type = extendedTypeOf(obj[k]);
2596
+ if (type === "symbol" || type === "function") {
2597
+ throw new TypeError(`cannot serialize values of type '${type}'`);
2598
+ }
2599
+ let key = formatKey(k);
2600
+ if (type === "array" && isArrayOfTables(obj[k])) {
2601
+ tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
2602
+ } else if (type === "object") {
2603
+ let tblKey = prefix ? `${prefix}.${key}` : key;
2604
+ tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
2605
+ } else {
2606
+ preamble += key;
2607
+ preamble += " = ";
2608
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
2609
+ preamble += "\n";
2610
+ }
2611
+ }
2612
+ }
2613
+ if (tableKey && (preamble || !tables))
2614
+ preamble = preamble ? `[${tableKey}]
2615
+ ${preamble}` : `[${tableKey}]`;
2616
+ return preamble && tables ? `${preamble}
2617
+ ${tables}` : preamble || tables;
2618
+ }
2619
+ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
2620
+ if (extendedTypeOf(obj) !== "object") {
2621
+ throw new TypeError("stringify can only be called with an object");
2622
+ }
2623
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
2624
+ if (str[str.length - 1] !== "\n")
2625
+ return str + "\n";
2626
+ return str;
2627
+ }
2628
+
2425
2629
  // src/core/host-client.ts
2426
2630
  function resolveHostConfig(harness, directory) {
2427
2631
  const cfg0 = loadConfig({ harness });
@@ -2443,7 +2647,7 @@ import {
2443
2647
  renameSync as renameSync3,
2444
2648
  rmdirSync,
2445
2649
  rmSync as rmSync2,
2446
- statSync as statSync3,
2650
+ statSync as statSync4,
2447
2651
  unlinkSync,
2448
2652
  utimesSync,
2449
2653
  writeFileSync as writeFileSync2
@@ -2480,7 +2684,7 @@ function reclaimIfStale(directory, staleMs) {
2480
2684
  return true;
2481
2685
  }
2482
2686
  if (owners.length !== 1) return false;
2483
- const age = Date.now() - statSync3(join12(directory, owners[0])).mtimeMs;
2687
+ const age = Date.now() - statSync4(join12(directory, owners[0])).mtimeMs;
2484
2688
  if (Math.abs(age) <= staleMs) return false;
2485
2689
  releaseLease({ directory, owner: owners[0] });
2486
2690
  return true;
@@ -2543,7 +2747,7 @@ function opencodeCanDefineSurveyAgent(bin) {
2543
2747
  windowsHide: true,
2544
2748
  stdio: ["ignore", "pipe", "ignore"]
2545
2749
  });
2546
- return Number(/(\d+)\./.exec(out)?.[1] ?? 0) >= 1;
2750
+ return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
2547
2751
  } catch {
2548
2752
  return false;
2549
2753
  }
@@ -2558,6 +2762,7 @@ var SURVEY_DISALLOWED_TOOLS = [
2558
2762
  "WebSearch",
2559
2763
  "Task"
2560
2764
  ];
2765
+ var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
2561
2766
  function buildSurveyPlan(harness, bin, repoDir, opts) {
2562
2767
  const env = {
2563
2768
  ...process.env,
@@ -2616,9 +2821,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
2616
2821
  "-c",
2617
2822
  `mcp_servers.hindsight.command="node"`,
2618
2823
  "-c",
2619
- `mcp_servers.hindsight.args=["${opts.mcpServerPath}"]`,
2824
+ `mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
2620
2825
  "-c",
2621
- `mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD="${repoDir}"`,
2826
+ `mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
2622
2827
  "-c",
2623
2828
  `mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
2624
2829
  SURVEY_PROMPT
@@ -2642,10 +2847,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
2642
2847
  }
2643
2848
  }
2644
2849
  }
2850
+ var SURVEY_MAX_ATTEMPTS = 3;
2851
+ function surveyAttempts(file, sha) {
2852
+ try {
2853
+ const state = JSON.parse(readFileSync7(file, "utf8"));
2854
+ return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
2855
+ } catch {
2856
+ return 0;
2857
+ }
2858
+ }
2645
2859
  async function startCodebaseSurvey(repoDir, opts = {}) {
2646
2860
  try {
2647
2861
  const spawnFn = opts.spawn ?? realSpawn4;
2648
- const exists = opts.exists ?? binOnPath;
2862
+ const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
2649
2863
  const mcpServerPath = opts.mcpServerPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
2650
2864
  const preferred = opts.harness ?? "claude-code";
2651
2865
  const order = [
@@ -2659,10 +2873,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2659
2873
  for (const harness of order) {
2660
2874
  if (seen.has(harness)) continue;
2661
2875
  seen.add(harness);
2662
- const bin = resolveAgentBin(harness, opts.claudeBin);
2663
- if (!exists(bin)) continue;
2664
- if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin))
2876
+ const name = resolveAgentBin(harness, opts.claudeBin);
2877
+ const bin = resolveBin(name);
2878
+ if (!bin) {
2879
+ log.info("survey", `${harness}: ${name} not found, trying the next agent`);
2880
+ continue;
2881
+ }
2882
+ if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
2883
+ log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
2665
2884
  continue;
2885
+ }
2666
2886
  const plan = buildSurveyPlan(harness, bin, repoDir, {
2667
2887
  model: opts.model,
2668
2888
  budgetUsd: opts.budgetUsd,
@@ -2671,12 +2891,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2671
2891
  const { cfg, bankId } = resolveHostConfig(harness, repoDir);
2672
2892
  if (cfg.disabled) return false;
2673
2893
  const key = createHash4("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
2674
- const lease = acquireLease(
2675
- opts.lease?.dir ?? join13(tmpdir3(), "hindsight-coding-agent", "surveys"),
2676
- key,
2677
- opts.lease?.staleMs ?? LEASE_STALE_MS
2678
- );
2894
+ const leaseDir = opts.lease?.dir ?? join13(tmpdir3(), "hindsight-coding-agent", "surveys");
2895
+ const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
2679
2896
  if (!lease) return false;
2897
+ const attemptsFile = join13(
2898
+ leaseDir,
2899
+ `attempts-${createHash4("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
2900
+ );
2901
+ const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
2902
+ if (attempts >= SURVEY_MAX_ATTEMPTS) {
2903
+ log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
2904
+ releaseLease(lease);
2905
+ return false;
2906
+ }
2680
2907
  const spec = {
2681
2908
  lease,
2682
2909
  bin: plan.bin,
@@ -2684,7 +2911,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2684
2911
  ...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
2685
2912
  };
2686
2913
  const supervisorPath = opts.supervisorPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
2687
- return await new Promise((resolve3) => {
2914
+ return await new Promise((resolve4) => {
2688
2915
  try {
2689
2916
  const child = spawnFn("node", [supervisorPath], {
2690
2917
  cwd: repoDir,
@@ -2694,19 +2921,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
2694
2921
  env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
2695
2922
  });
2696
2923
  let spawned = false;
2697
- child.on("error", () => {
2924
+ child.on("error", (e) => {
2698
2925
  if (spawned) return;
2926
+ log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
2699
2927
  releaseLease(lease);
2700
- resolve3(false);
2928
+ resolve4(false);
2701
2929
  });
2702
2930
  child.once("spawn", () => {
2703
2931
  spawned = true;
2704
2932
  child.unref();
2705
- resolve3(true);
2933
+ if (opts.sha) {
2934
+ try {
2935
+ writeFileSync3(
2936
+ attemptsFile,
2937
+ JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
2938
+ { mode: 384 }
2939
+ );
2940
+ } catch {
2941
+ }
2942
+ }
2943
+ resolve4(true);
2706
2944
  });
2707
- } catch {
2945
+ } catch (e) {
2946
+ log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
2708
2947
  releaseLease(lease);
2709
- resolve3(false);
2948
+ resolve4(false);
2710
2949
  }
2711
2950
  });
2712
2951
  }
@@ -2723,10 +2962,10 @@ import { spawn as realSpawn5 } from "child_process";
2723
2962
  import {
2724
2963
  existsSync as existsSync4,
2725
2964
  mkdirSync as mkdirSync5,
2726
- readFileSync as readFileSync7,
2965
+ readFileSync as readFileSync8,
2727
2966
  realpathSync as realpathSync2,
2728
2967
  unlinkSync as unlinkSync2,
2729
- writeFileSync as writeFileSync3
2968
+ writeFileSync as writeFileSync4
2730
2969
  } from "fs";
2731
2970
  import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2732
2971
  import { dirname as dirname9, join as join14 } from "path";
@@ -2754,22 +2993,22 @@ function sameDir(a, b) {
2754
2993
  }
2755
2994
  function stagedVersion(pkgRoot) {
2756
2995
  try {
2757
- const pkg = JSON.parse(readFileSync7(join14(pkgRoot, "package.json"), "utf8"));
2996
+ const pkg = JSON.parse(readFileSync8(join14(pkgRoot, "package.json"), "utf8"));
2758
2997
  return typeof pkg.version === "string" ? pkg.version : "";
2759
2998
  } catch {
2760
2999
  return "";
2761
3000
  }
2762
3001
  }
2763
3002
  function isNewer(candidate, current2) {
2764
- const parse = (v) => {
3003
+ const parse2 = (v) => {
2765
3004
  const [core = "", ...rest] = v.trim().split("-");
2766
3005
  return {
2767
3006
  nums: core.split(".").map((n) => Number.parseInt(n, 10)),
2768
3007
  pre: rest.length > 0
2769
3008
  };
2770
3009
  };
2771
- const a = parse(candidate);
2772
- const b = parse(current2);
3010
+ const a = parse2(candidate);
3011
+ const b = parse2(current2);
2773
3012
  if (a.nums.length !== 3 || b.nums.length !== 3) return false;
2774
3013
  if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
2775
3014
  for (let i = 0; i < 3; i++) {
@@ -2779,7 +3018,7 @@ function isNewer(candidate, current2) {
2779
3018
  }
2780
3019
  function dueForCheck(file, now) {
2781
3020
  try {
2782
- const state = JSON.parse(readFileSync7(file, "utf8"));
3021
+ const state = JSON.parse(readFileSync8(file, "utf8"));
2783
3022
  return typeof state.lastCheck !== "number" || now - state.lastCheck >= CHECK_INTERVAL_MS;
2784
3023
  } catch {
2785
3024
  return true;
@@ -2788,7 +3027,7 @@ function dueForCheck(file, now) {
2788
3027
  var ORIGIN_FILE = ".install-origin.json";
2789
3028
  function selfUpdatable(runtimeDir) {
2790
3029
  try {
2791
- const origin = JSON.parse(readFileSync7(join14(runtimeDir, ORIGIN_FILE), "utf8"));
3030
+ const origin = JSON.parse(readFileSync8(join14(runtimeDir, ORIGIN_FILE), "utf8"));
2792
3031
  if (typeof origin.source !== "string" || !origin.source) return false;
2793
3032
  return origin.source.split(/[\\/]/).includes("_npx");
2794
3033
  } catch {
@@ -2801,7 +3040,7 @@ function lockFile() {
2801
3040
  }
2802
3041
  function acquireUpdateLock(file, now) {
2803
3042
  try {
2804
- const held = JSON.parse(readFileSync7(file, "utf8"));
3043
+ const held = JSON.parse(readFileSync8(file, "utf8"));
2805
3044
  if (held.ts && now - held.ts < LOCK_STALE_MS) {
2806
3045
  let holderAlive = false;
2807
3046
  if (held.pid) {
@@ -2817,7 +3056,7 @@ function acquireUpdateLock(file, now) {
2817
3056
  }
2818
3057
  try {
2819
3058
  mkdirSync5(dirname9(file), { recursive: true });
2820
- writeFileSync3(file, JSON.stringify({ pid: process.pid, ts: now }));
3059
+ writeFileSync4(file, JSON.stringify({ pid: process.pid, ts: now }));
2821
3060
  return true;
2822
3061
  } catch {
2823
3062
  return false;
@@ -2826,7 +3065,7 @@ function acquireUpdateLock(file, now) {
2826
3065
  function holdLockFor(file, pid, now) {
2827
3066
  try {
2828
3067
  if (pid === void 0) return releaseUpdateLock(file);
2829
- writeFileSync3(file, JSON.stringify({ pid, ts: now }));
3068
+ writeFileSync4(file, JSON.stringify({ pid, ts: now }));
2830
3069
  } catch {
2831
3070
  }
2832
3071
  }
@@ -2838,7 +3077,7 @@ function releaseUpdateLock(file) {
2838
3077
  }
2839
3078
  function stampCheck(file, now, latest) {
2840
3079
  try {
2841
- writeFileSync3(file, JSON.stringify({ lastCheck: now, latest }));
3080
+ writeFileSync4(file, JSON.stringify({ lastCheck: now, latest }));
2842
3081
  } catch {
2843
3082
  }
2844
3083
  }
@@ -2846,7 +3085,7 @@ function spawnNpm(spawnImpl, bin, args, opts) {
2846
3085
  return process.platform === "win32" ? spawnImpl([bin, ...args].join(" "), { ...opts, shell: true }) : spawnImpl(bin, args, opts);
2847
3086
  }
2848
3087
  async function npmViewVersion(pkg, spawnImpl = realSpawn5) {
2849
- return new Promise((resolve3) => {
3088
+ return new Promise((resolve4) => {
2850
3089
  let out = "";
2851
3090
  let settled = false;
2852
3091
  let deadline;
@@ -2855,7 +3094,7 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn5) {
2855
3094
  settled = true;
2856
3095
  if (deadline) clearTimeout(deadline);
2857
3096
  if (reason) log.info("auto-update", `version check failed: ${reason}`);
2858
- resolve3(v);
3097
+ resolve4(v);
2859
3098
  };
2860
3099
  try {
2861
3100
  const child = spawnNpm(spawnImpl, "npm", ["view", pkg, "version", "--json"], {
@@ -2954,7 +3193,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
2954
3193
  }
2955
3194
 
2956
3195
  // src/core/skill-sync.ts
2957
- import { cpSync, existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
3196
+ import { cpSync, existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2958
3197
  import { homedir as homedir6 } from "os";
2959
3198
  import { dirname as dirname10, join as join16 } from "path";
2960
3199
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -3029,7 +3268,7 @@ function syncCompanionSkill(harness, opts = {}) {
3029
3268
  const dstMd = join16(dst, "SKILL.md");
3030
3269
  const installed = existsSync6(dstMd);
3031
3270
  if (!installed && !opts.install) return;
3032
- if (!installed || readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
3271
+ if (!installed || readFileSync9(srcMd, "utf8") !== readFileSync9(dstMd, "utf8")) {
3033
3272
  cpSync(src, dst, { recursive: true });
3034
3273
  }
3035
3274
  } catch {
@@ -3037,9 +3276,9 @@ function syncCompanionSkill(harness, opts = {}) {
3037
3276
  }
3038
3277
 
3039
3278
  // src/core/legacy.ts
3040
- import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
3279
+ import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
3041
3280
  import { homedir as homedir7 } from "os";
3042
- import { join as join17, relative, isAbsolute as isAbsolute2 } from "path";
3281
+ import { join as join17, relative, isAbsolute as isAbsolute3 } from "path";
3043
3282
  var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
3044
3283
  function detectLegacyClaudePlugin(cwd, claudeDir = join17(homedir7(), ".claude")) {
3045
3284
  const registry = readJson(join17(claudeDir, "plugins", "installed_plugins.json"));
@@ -3054,7 +3293,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join17(homedir7(), ".claude")
3054
3293
  if (!i || typeof i !== "object") return false;
3055
3294
  if (typeof i.projectPath !== "string") return true;
3056
3295
  const rel = relative(i.projectPath, cwd);
3057
- return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
3296
+ return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
3058
3297
  });
3059
3298
  if (active) return key;
3060
3299
  }
@@ -3062,7 +3301,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join17(homedir7(), ".claude")
3062
3301
  }
3063
3302
  function readJson(path) {
3064
3303
  try {
3065
- const parsed = JSON.parse(readFileSync9(path, "utf8"));
3304
+ const parsed = JSON.parse(readFileSync10(path, "utf8"));
3066
3305
  return parsed && typeof parsed === "object" ? parsed : void 0;
3067
3306
  } catch {
3068
3307
  return void 0;
@@ -3166,12 +3405,13 @@ async function buildSessionStartContext(args) {
3166
3405
  startSeed(cwd, { limit: cfg.seedLimit, harness });
3167
3406
  if (cold) {
3168
3407
  if (cfg.codebaseSurvey !== false) {
3408
+ const sha = resolveHeadSha(cwd);
3169
3409
  const started = await startSurvey(cwd, {
3170
3410
  harness,
3171
3411
  model: cfg.surveyModel,
3172
- budgetUsd: cfg.surveyBudgetUsd
3412
+ budgetUsd: cfg.surveyBudgetUsd,
3413
+ sha: sha ?? void 0
3173
3414
  });
3174
- const sha = resolveHeadSha(cwd);
3175
3415
  if (started && sha) recordSurveyBaseline(sha);
3176
3416
  }
3177
3417
  diag(harness, "seed_started", { bank: bankId });
@@ -3192,7 +3432,8 @@ async function buildSessionStartContext(args) {
3192
3432
  const started = await startSurvey(cwd, {
3193
3433
  harness,
3194
3434
  model: cfg.surveyModel,
3195
- budgetUsd: cfg.surveyBudgetUsd
3435
+ budgetUsd: cfg.surveyBudgetUsd,
3436
+ sha
3196
3437
  });
3197
3438
  if (started) {
3198
3439
  recordSurveyBaseline(sha);
@@ -3296,9 +3537,9 @@ ${mcpHint}` : mcpHint;
3296
3537
 
3297
3538
  // src/core/traecode-mcp.ts
3298
3539
  import { execFileSync as execFileSync5 } from "child_process";
3299
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
3540
+ import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync11, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "fs";
3300
3541
  import { homedir as homedir8 } from "os";
3301
- import { dirname as dirname11, isAbsolute as isAbsolute3, join as join18 } from "path";
3542
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18 } from "path";
3302
3543
  import { fileURLToPath as fileURLToPath6 } from "url";
3303
3544
  var MCP_SERVER_NAME = "hindsight";
3304
3545
  var MCP_FILE_REL = join18(".trae", "mcp.json");
@@ -3333,7 +3574,7 @@ function gateStateFile() {
3333
3574
  }
3334
3575
  function readGateState(opts = {}) {
3335
3576
  try {
3336
- return JSON.parse(readFileSync10(opts.stateFile ?? gateStateFile(), "utf8"));
3577
+ return JSON.parse(readFileSync11(opts.stateFile ?? gateStateFile(), "utf8"));
3337
3578
  } catch {
3338
3579
  return {};
3339
3580
  }
@@ -3341,7 +3582,7 @@ function readGateState(opts = {}) {
3341
3582
  function workspaceMcpGateState(settingsPath) {
3342
3583
  let raw;
3343
3584
  try {
3344
- raw = readFileSync10(settingsPath, "utf8");
3585
+ raw = readFileSync11(settingsPath, "utf8");
3345
3586
  } catch {
3346
3587
  return "unknown";
3347
3588
  }
@@ -3363,7 +3604,7 @@ function workspaceMcpHint(opts = {}) {
3363
3604
  if (typeof state.lastHint === "number" && now - state.lastHint < HINT_MIN_INTERVAL_MS) {
3364
3605
  return void 0;
3365
3606
  }
3366
- writeFileSync4(
3607
+ writeFileSync5(
3367
3608
  opts.stateFile ?? gateStateFile(),
3368
3609
  JSON.stringify({ ...state, lastHint: now }, null, 2) + "\n"
3369
3610
  );
@@ -3381,10 +3622,10 @@ function gitignoreCovers(lines) {
3381
3622
  function ensureGitignored(repo) {
3382
3623
  const gitignore = join18(repo, ".gitignore");
3383
3624
  if (!existsSync8(gitignore)) return;
3384
- const current2 = readFileSync10(gitignore, "utf8");
3625
+ const current2 = readFileSync11(gitignore, "utf8");
3385
3626
  if (gitignoreCovers(current2.split("\n"))) return;
3386
3627
  const addition = (current2.endsWith("\n") || current2 === "" ? "" : "\n") + "# hindsight MCP registration (machine-specific)\n.trae/mcp.json\n";
3387
- writeFileSync4(gitignore, current2 + addition);
3628
+ writeFileSync5(gitignore, current2 + addition);
3388
3629
  }
3389
3630
  function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
3390
3631
  registerTraecodeWorkspaceMcp(cwd, opts);
@@ -3394,7 +3635,7 @@ function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
3394
3635
  function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
3395
3636
  try {
3396
3637
  const home = opts.home ?? homedir8();
3397
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
3638
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
3398
3639
  const dist = opts.dist ?? bundledDistDir();
3399
3640
  const script = join18(dist, "mcp-server.js");
3400
3641
  if (!existsSync8(script)) return "skipped";
@@ -3402,7 +3643,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
3402
3643
  let doc = {};
3403
3644
  let exists = false;
3404
3645
  try {
3405
- doc = JSON.parse(readFileSync10(file, "utf8"));
3646
+ doc = JSON.parse(readFileSync11(file, "utf8"));
3406
3647
  exists = true;
3407
3648
  } catch {
3408
3649
  if (existsSync8(file)) return "skipped";
@@ -3432,7 +3673,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
3432
3673
  if (existing !== void 0 && canon(merged) === canon(existing)) return "current";
3433
3674
  servers[MCP_SERVER_NAME] = merged;
3434
3675
  mkdirSync6(dirname11(file), { recursive: true });
3435
- writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
3676
+ writeFileSync5(file, JSON.stringify(doc, null, 2) + "\n");
3436
3677
  if (!exists) ensureGitignored(cwd);
3437
3678
  diag("traecode", "workspace_mcp_registered", { cwd, file });
3438
3679
  return "registered";
@@ -3458,7 +3699,7 @@ function findWorkspaceStorageDir(storage, repo) {
3458
3699
  }
3459
3700
  for (const name of entries) {
3460
3701
  try {
3461
- const doc = JSON.parse(readFileSync10(join18(storage, name, "workspace.json"), "utf8"));
3702
+ const doc = JSON.parse(readFileSync11(join18(storage, name, "workspace.json"), "utf8"));
3462
3703
  if (typeof doc.folder !== "string") continue;
3463
3704
  let folder;
3464
3705
  try {
@@ -3476,7 +3717,7 @@ function findWorkspaceStorageDir(storage, repo) {
3476
3717
  function ensureWorkspaceMcpEnabled(cwd, opts = {}) {
3477
3718
  try {
3478
3719
  const home = opts.home ?? homedir8();
3479
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
3720
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
3480
3721
  const dir = findWorkspaceStorageDir(traecodeWorkspaceStorageDir(home), cwd);
3481
3722
  if (!dir) return "failed";
3482
3723
  const db = join18(dir, "state.vscdb");
@@ -3511,7 +3752,7 @@ function workspaceEnableHint(opts = {}) {
3511
3752
  if (typeof state.lastEnableHint === "number" && now - state.lastEnableHint < HINT_MIN_INTERVAL_MS) {
3512
3753
  return void 0;
3513
3754
  }
3514
- writeFileSync4(
3755
+ writeFileSync5(
3515
3756
  opts.stateFile ?? gateStateFile(),
3516
3757
  JSON.stringify({ ...state, lastEnableHint: now }, null, 2) + "\n"
3517
3758
  );
@@ -3693,6 +3934,10 @@ function readCursorTranscript(path) {
3693
3934
  }
3694
3935
 
3695
3936
  // src/core/transcript-antigravity.ts
3937
+ function unwrapUserRequest(text) {
3938
+ const request = /<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/.exec(text);
3939
+ return request ? request[1] : text.replace(/<ADDITIONAL_METADATA>[\s\S]*?<\/ADDITIONAL_METADATA>/g, "");
3940
+ }
3696
3941
  function readAntigravityTranscript(path) {
3697
3942
  if (!path) return [];
3698
3943
  const turns = [];
@@ -3702,7 +3947,8 @@ function readAntigravityTranscript(path) {
3702
3947
  const role = event.role ?? event.message?.role ?? event.type;
3703
3948
  const normalizedRole = role === "user" || role === "USER_INPUT" ? "user" : role === "assistant" || role === "model" || role === "PLANNER_RESPONSE" ? "assistant" : void 0;
3704
3949
  const content = event.content ?? event.text ?? event.message?.content ?? event.message?.text;
3705
- const clean = typeof content === "string" ? stripInjectedMemory(content).trim() : "";
3950
+ const text = typeof content === "string" ? stripInjectedMemory(content) : "";
3951
+ const clean = (normalizedRole === "user" ? unwrapUserRequest(text) : text).trim();
3706
3952
  if (normalizedRole && clean) {
3707
3953
  turns.push({
3708
3954
  role: normalizedRole,
@@ -3733,7 +3979,7 @@ function readCopilotTranscript(path) {
3733
3979
  }
3734
3980
 
3735
3981
  // src/core/transcript-grok.ts
3736
- import { existsSync as existsSync9, readFileSync as readFileSync11, readdirSync as readdirSync3 } from "fs";
3982
+ import { existsSync as existsSync9, readFileSync as readFileSync12, readdirSync as readdirSync3 } from "fs";
3737
3983
  import { homedir as homedir9 } from "os";
3738
3984
  import { join as join19 } from "path";
3739
3985
  var CHAT_HISTORY = "chat_history.jsonl";
@@ -3744,7 +3990,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
3744
3990
  try {
3745
3991
  for (const candidate of readdirSync3(sessionsDir)) {
3746
3992
  const directory = join19(sessionsDir, candidate);
3747
- if (readFileSync11(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3993
+ if (readFileSync12(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3748
3994
  return join19(directory, sessionId, CHAT_HISTORY);
3749
3995
  }
3750
3996
  }
@@ -4095,7 +4341,7 @@ function readDroidTranscript(path) {
4095
4341
  }
4096
4342
 
4097
4343
  // src/core/transcript-zcode.ts
4098
- import { readFileSync as readFileSync12 } from "fs";
4344
+ import { readFileSync as readFileSync13 } from "fs";
4099
4345
  function messageText(content) {
4100
4346
  if (typeof content === "string") return content.trim();
4101
4347
  if (!Array.isArray(content)) return "";
@@ -4105,7 +4351,7 @@ function readZcodeTranscript(path) {
4105
4351
  if (!path) return [];
4106
4352
  let body;
4107
4353
  try {
4108
- body = readFileSync12(path, "utf8");
4354
+ body = readFileSync13(path, "utf8");
4109
4355
  } catch {
4110
4356
  return [];
4111
4357
  }
@@ -4326,12 +4572,12 @@ function readWorkbuddyTranscript(path) {
4326
4572
  }
4327
4573
 
4328
4574
  // src/core/transcript-codebuddy-ide.ts
4329
- import { readFileSync as readFileSync13 } from "fs";
4575
+ import { readFileSync as readFileSync14 } from "fs";
4330
4576
  import { basename as basename3, dirname as dirname12, join as join22 } from "path";
4331
4577
  var IDE_CONTEXT_RE = /<(user_info|git_status|additional_data|system_reminder)\b[\s\S]*?<\/\1>/g;
4332
4578
  function readJson2(path) {
4333
4579
  try {
4334
- return JSON.parse(readFileSync13(path, "utf8"));
4580
+ return JSON.parse(readFileSync14(path, "utf8"));
4335
4581
  } catch {
4336
4582
  return void 0;
4337
4583
  }
@@ -4545,7 +4791,9 @@ var HOOK_HARNESSES = {
4545
4791
  parse: (ev) => ({
4546
4792
  sessionId: ev.session_id,
4547
4793
  transcriptPath: ev.transcript_path,
4548
- cwd: ev.cwd
4794
+ cwd: ev.cwd,
4795
+ // The transcript may not hold the final reply yet when Stop fires after a tool call (#5790).
4796
+ lastAssistantMessage: ev.last_assistant_message
4549
4797
  })
4550
4798
  }
4551
4799
  },
@@ -5028,3 +5276,42 @@ var runHarnessSessionStart = (harness) => runSessionStartHook(HOOK_HARNESSES[har
5028
5276
 
5029
5277
  // src/copilot-sessionstart-hook.ts
5030
5278
  void runHarnessSessionStart("copilot-cli");
5279
+ /*! Bundled license information:
5280
+
5281
+ smol-toml/dist/error.js:
5282
+ smol-toml/dist/primitive.js:
5283
+ smol-toml/dist/date.js:
5284
+ smol-toml/dist/extract.js:
5285
+ smol-toml/dist/util.js:
5286
+ smol-toml/dist/struct.js:
5287
+ smol-toml/dist/parse.js:
5288
+ smol-toml/dist/stringify.js:
5289
+ smol-toml/dist/index.js:
5290
+ (*!
5291
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
5292
+ * SPDX-License-Identifier: BSD-3-Clause
5293
+ *
5294
+ * Redistribution and use in source and binary forms, with or without
5295
+ * modification, are permitted provided that the following conditions are met:
5296
+ *
5297
+ * 1. Redistributions of source code must retain the above copyright notice, this
5298
+ * list of conditions and the following disclaimer.
5299
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
5300
+ * this list of conditions and the following disclaimer in the
5301
+ * documentation and/or other materials provided with the distribution.
5302
+ * 3. Neither the name of the copyright holder nor the names of its contributors
5303
+ * may be used to endorse or promote products derived from this software without
5304
+ * specific prior written permission.
5305
+ *
5306
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
5307
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
5308
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5309
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5310
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5311
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5312
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5313
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5314
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5315
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5316
+ *)
5317
+ */