@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
 
@@ -633,11 +633,11 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
633
633
  }
634
634
 
635
635
  // package.json
636
- var version = "0.8.1";
636
+ var version = "0.8.3";
637
637
 
638
638
  // src/core/util.ts
639
- import { accessSync, constants } from "fs";
640
- import { delimiter, join as join6 } from "path";
639
+ import { accessSync, constants, statSync as statSync2 } from "fs";
640
+ import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
641
641
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
642
642
  function semverGte(version2, min) {
643
643
  const parts = (v) => {
@@ -915,15 +915,19 @@ var HindsightClient = class {
915
915
  }
916
916
  /**
917
917
  * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
918
- * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
918
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
919
919
  * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
920
+ * Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
921
+ * of the process after one probe that hit a restarting server (#5735).
920
922
  */
921
923
  async supportsIdempotentRetain() {
922
- if (this.idempotentRetain === void 0) {
923
- this.idempotentRetain = await this.probeIdempotentRetain();
924
- this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
924
+ if (this.idempotentRetain) return true;
925
+ const supported = await this.probeIdempotentRetain();
926
+ if (supported || this.idempotentRetain === void 0) {
927
+ this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
925
928
  }
926
- return this.idempotentRetain;
929
+ this.idempotentRetain = supported;
930
+ return supported;
927
931
  }
928
932
  /** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
929
933
  * hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
@@ -1951,7 +1955,7 @@ function fileCursorStore(harness) {
1951
1955
  }
1952
1956
 
1953
1957
  // src/core/turn-journal.ts
1954
- import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
1958
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
1955
1959
  import { tmpdir as tmpdir2 } from "os";
1956
1960
  import { dirname as dirname6, join as join9 } from "path";
1957
1961
 
@@ -1999,7 +2003,7 @@ function appendJournalTurn(path, turn) {
1999
2003
  const content = stripInjectedMemory(turn.content ?? "").trim();
2000
2004
  if (!content) return;
2001
2005
  try {
2002
- if (statSync2(path).size >= JOURNAL_MAX_BYTES) return;
2006
+ if (statSync3(path).size >= JOURNAL_MAX_BYTES) return;
2003
2007
  } catch {
2004
2008
  }
2005
2009
  const last = readJournalTranscript(path).at(-1);
@@ -2061,6 +2065,18 @@ function pendingReplayable(cursor, now) {
2061
2065
  if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
2062
2066
  return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
2063
2067
  }
2068
+ function advanceSegments(cursor, bank) {
2069
+ if (!cursor || cursor.bank === bank) return cursor?.segments;
2070
+ return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
2071
+ }
2072
+ function bankTurns(turns, segments, bank) {
2073
+ if (!segments) return turns;
2074
+ return turns.filter((_, i) => {
2075
+ let owner;
2076
+ for (const s of segments) if (s.from <= i) owner = s.bank;
2077
+ return owner === bank;
2078
+ });
2079
+ }
2064
2080
  var MAX_CURSOR_OPS = 8;
2065
2081
  function fingerprintTurns(turns, count) {
2066
2082
  const h = createHash2("sha1").update(String(count));
@@ -2071,7 +2087,8 @@ function planRetain(turns, cursor, opts) {
2071
2087
  if (!turns.length) return { mode: "skip" };
2072
2088
  if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
2073
2089
  if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
2074
- if (cursor.bank !== opts.bank) return { mode: "replace" };
2090
+ if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
2091
+ return { mode: "replace" };
2075
2092
  const seen = cursor.paths ?? [];
2076
2093
  const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
2077
2094
  const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
@@ -2206,8 +2223,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
2206
2223
  let cursor = cursors?.read(sessionId);
2207
2224
  const probed = Boolean(cursors) && cursor?.appendSupported !== true;
2208
2225
  const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
2226
+ const moved = Boolean(cursor && cursor.bank !== client.bank);
2227
+ if (moved)
2228
+ log.warn(harness ?? "", "session moved to another bank mid-session", {
2229
+ session: sessionId,
2230
+ from: cursor?.bank,
2231
+ to: client.bank,
2232
+ atTurn: cursor?.turns
2233
+ });
2234
+ const segments = advanceSegments(cursor, client.bank);
2209
2235
  let ops = [];
2210
- if (appendSupported && cursor?.ops?.length && !cursor.dirty)
2236
+ if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
2211
2237
  ({ cursor, ops } = await settleOps(client, cursor));
2212
2238
  const plan = planRetain(turns, cursor, {
2213
2239
  appendSupported,
@@ -2216,7 +2242,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
2216
2242
  });
2217
2243
  if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
2218
2244
  const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
2219
- const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
2245
+ const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
2220
2246
  if (plan.mode === "skip" && !outbox.length) return;
2221
2247
  const opId = (mode, content) => uuidV5(`${client.bank}
2222
2248
  ${refId}
@@ -2258,6 +2284,7 @@ ${content}`);
2258
2284
  fingerprint: fingerprintTurns(turns, turns.length),
2259
2285
  bank: client.bank,
2260
2286
  ...paths ? { paths } : {},
2287
+ ...segments ? { segments } : {},
2261
2288
  ...appendSupported ? { appendSupported: true } : {}
2262
2289
  };
2263
2290
  const accepted = (id) => {
@@ -2270,9 +2297,14 @@ ${content}`);
2270
2297
  return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
2271
2298
  };
2272
2299
  if (plan.mode === "replace") {
2273
- const content = renderSessionJsonl(refId, turns, startTs);
2300
+ const share = bankTurns(turns, segments, client.bank);
2301
+ if (!share.length) return;
2302
+ const content = renderSessionJsonl(refId, share, startTs);
2303
+ const base = cursor ? `${cursor.turns}
2304
+ ${cursor.fingerprint}` : "";
2274
2305
  cursors?.write(sessionId, { ...next, dirty: true });
2275
- const operationId = opId("replace", content);
2306
+ const operationId = opId("replace", `${base}
2307
+ ${content}`);
2276
2308
  await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
2277
2309
  ops = [];
2278
2310
  cursors?.write(sessionId, accepted(operationId));
@@ -2396,8 +2428,8 @@ async function waitBounded(p, ms) {
2396
2428
  try {
2397
2429
  await Promise.race([
2398
2430
  p,
2399
- new Promise((resolve3) => {
2400
- timer = setTimeout(resolve3, Math.max(ms, 0));
2431
+ new Promise((resolve4) => {
2432
+ timer = setTimeout(resolve4, Math.max(ms, 0));
2401
2433
  })
2402
2434
  ]);
2403
2435
  } finally {
@@ -2489,12 +2521,12 @@ function buildRetainStamp(cfg, ctx) {
2489
2521
  const base = resolversFor(ctx);
2490
2522
  const cache = /* @__PURE__ */ new Map();
2491
2523
  const resolvers = Object.fromEntries(
2492
- Object.entries(base).map(([name, resolve3]) => [
2524
+ Object.entries(base).map(([name, resolve4]) => [
2493
2525
  name,
2494
2526
  () => {
2495
2527
  const hit = cache.get(name);
2496
2528
  if (hit !== void 0) return hit;
2497
- const value = resolve3();
2529
+ const value = resolve4();
2498
2530
  cache.set(name, value);
2499
2531
  return value;
2500
2532
  }
@@ -2765,7 +2797,10 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
2765
2797
 
2766
2798
  // src/core/git.ts
2767
2799
  import { execFileSync as execFileSync2 } from "child_process";
2768
- import { resolve as resolve2 } from "path";
2800
+ import { resolve as resolve3 } from "path";
2801
+ var US = "";
2802
+ var RS = "";
2803
+ var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
2769
2804
 
2770
2805
  // src/core/status.ts
2771
2806
  import { execFileSync as execFileSync4 } from "child_process";
@@ -2773,11 +2808,14 @@ import { execFileSync as execFileSync4 } from "child_process";
2773
2808
  // src/core/survey.ts
2774
2809
  import { execFileSync as execFileSync3, spawn as realSpawn4 } from "child_process";
2775
2810
  import { createHash as createHash4 } from "crypto";
2776
- import { existsSync as existsSync3 } from "fs";
2811
+ import { existsSync as existsSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
2777
2812
  import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2778
2813
  import { dirname as dirname8, join as join13 } from "path";
2779
2814
  import { fileURLToPath as fileURLToPath3 } from "url";
2780
2815
 
2816
+ // node_modules/smol-toml/dist/stringify.js
2817
+ var HAS_WELLFORMED = !!"".isWellFormed;
2818
+
2781
2819
  // src/core/survey-lease.ts
2782
2820
  import { spawn as realSpawn3 } from "child_process";
2783
2821
  import { randomUUID } from "crypto";
@@ -2788,7 +2826,7 @@ import {
2788
2826
  renameSync as renameSync3,
2789
2827
  rmdirSync,
2790
2828
  rmSync as rmSync2,
2791
- statSync as statSync3,
2829
+ statSync as statSync4,
2792
2830
  unlinkSync,
2793
2831
  utimesSync,
2794
2832
  writeFileSync as writeFileSync2
@@ -2800,10 +2838,10 @@ import { spawn as realSpawn5 } from "child_process";
2800
2838
  import {
2801
2839
  existsSync as existsSync4,
2802
2840
  mkdirSync as mkdirSync5,
2803
- readFileSync as readFileSync7,
2841
+ readFileSync as readFileSync8,
2804
2842
  realpathSync as realpathSync2,
2805
2843
  unlinkSync as unlinkSync2,
2806
- writeFileSync as writeFileSync3
2844
+ writeFileSync as writeFileSync4
2807
2845
  } from "fs";
2808
2846
  import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2809
2847
  import { dirname as dirname9, join as join14 } from "path";
@@ -2814,7 +2852,7 @@ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
2814
2852
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2815
2853
 
2816
2854
  // src/core/skill-sync.ts
2817
- import { cpSync, existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
2855
+ import { cpSync, existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2818
2856
  import { homedir as homedir6 } from "os";
2819
2857
  import { dirname as dirname10, join as join16 } from "path";
2820
2858
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -2824,15 +2862,15 @@ import { existsSync as existsSync5 } from "fs";
2824
2862
  import { join as join15 } from "path";
2825
2863
 
2826
2864
  // src/core/legacy.ts
2827
- import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
2865
+ import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
2828
2866
  import { homedir as homedir7 } from "os";
2829
- import { join as join17, relative, isAbsolute as isAbsolute2 } from "path";
2867
+ import { join as join17, relative, isAbsolute as isAbsolute3 } from "path";
2830
2868
 
2831
2869
  // src/core/traecode-mcp.ts
2832
2870
  import { execFileSync as execFileSync5 } from "child_process";
2833
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
2871
+ import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync11, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "fs";
2834
2872
  import { homedir as homedir8 } from "os";
2835
- import { dirname as dirname11, isAbsolute as isAbsolute3, join as join18 } from "path";
2873
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18 } from "path";
2836
2874
  import { fileURLToPath as fileURLToPath6 } from "url";
2837
2875
  var MCP_SERVER_NAME = "hindsight";
2838
2876
  var MCP_FILE_REL = join18(".trae", "mcp.json");
@@ -2867,7 +2905,7 @@ function gateStateFile() {
2867
2905
  }
2868
2906
  function readGateState(opts = {}) {
2869
2907
  try {
2870
- return JSON.parse(readFileSync10(opts.stateFile ?? gateStateFile(), "utf8"));
2908
+ return JSON.parse(readFileSync11(opts.stateFile ?? gateStateFile(), "utf8"));
2871
2909
  } catch {
2872
2910
  return {};
2873
2911
  }
@@ -2875,7 +2913,7 @@ function readGateState(opts = {}) {
2875
2913
  function workspaceMcpGateState(settingsPath) {
2876
2914
  let raw;
2877
2915
  try {
2878
- raw = readFileSync10(settingsPath, "utf8");
2916
+ raw = readFileSync11(settingsPath, "utf8");
2879
2917
  } catch {
2880
2918
  return "unknown";
2881
2919
  }
@@ -2897,7 +2935,7 @@ function workspaceMcpHint(opts = {}) {
2897
2935
  if (typeof state.lastHint === "number" && now - state.lastHint < HINT_MIN_INTERVAL_MS) {
2898
2936
  return void 0;
2899
2937
  }
2900
- writeFileSync4(
2938
+ writeFileSync5(
2901
2939
  opts.stateFile ?? gateStateFile(),
2902
2940
  JSON.stringify({ ...state, lastHint: now }, null, 2) + "\n"
2903
2941
  );
@@ -2915,10 +2953,10 @@ function gitignoreCovers(lines) {
2915
2953
  function ensureGitignored(repo) {
2916
2954
  const gitignore = join18(repo, ".gitignore");
2917
2955
  if (!existsSync8(gitignore)) return;
2918
- const current2 = readFileSync10(gitignore, "utf8");
2956
+ const current2 = readFileSync11(gitignore, "utf8");
2919
2957
  if (gitignoreCovers(current2.split("\n"))) return;
2920
2958
  const addition = (current2.endsWith("\n") || current2 === "" ? "" : "\n") + "# hindsight MCP registration (machine-specific)\n.trae/mcp.json\n";
2921
- writeFileSync4(gitignore, current2 + addition);
2959
+ writeFileSync5(gitignore, current2 + addition);
2922
2960
  }
2923
2961
  function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
2924
2962
  registerTraecodeWorkspaceMcp(cwd, opts);
@@ -2928,7 +2966,7 @@ function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
2928
2966
  function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2929
2967
  try {
2930
2968
  const home = opts.home ?? homedir8();
2931
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
2969
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
2932
2970
  const dist = opts.dist ?? bundledDistDir();
2933
2971
  const script = join18(dist, "mcp-server.js");
2934
2972
  if (!existsSync8(script)) return "skipped";
@@ -2936,7 +2974,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2936
2974
  let doc = {};
2937
2975
  let exists = false;
2938
2976
  try {
2939
- doc = JSON.parse(readFileSync10(file, "utf8"));
2977
+ doc = JSON.parse(readFileSync11(file, "utf8"));
2940
2978
  exists = true;
2941
2979
  } catch {
2942
2980
  if (existsSync8(file)) return "skipped";
@@ -2966,7 +3004,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2966
3004
  if (existing !== void 0 && canon(merged) === canon(existing)) return "current";
2967
3005
  servers[MCP_SERVER_NAME] = merged;
2968
3006
  mkdirSync6(dirname11(file), { recursive: true });
2969
- writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
3007
+ writeFileSync5(file, JSON.stringify(doc, null, 2) + "\n");
2970
3008
  if (!exists) ensureGitignored(cwd);
2971
3009
  diag("traecode", "workspace_mcp_registered", { cwd, file });
2972
3010
  return "registered";
@@ -2992,7 +3030,7 @@ function findWorkspaceStorageDir(storage, repo) {
2992
3030
  }
2993
3031
  for (const name of entries) {
2994
3032
  try {
2995
- const doc = JSON.parse(readFileSync10(join18(storage, name, "workspace.json"), "utf8"));
3033
+ const doc = JSON.parse(readFileSync11(join18(storage, name, "workspace.json"), "utf8"));
2996
3034
  if (typeof doc.folder !== "string") continue;
2997
3035
  let folder;
2998
3036
  try {
@@ -3010,7 +3048,7 @@ function findWorkspaceStorageDir(storage, repo) {
3010
3048
  function ensureWorkspaceMcpEnabled(cwd, opts = {}) {
3011
3049
  try {
3012
3050
  const home = opts.home ?? homedir8();
3013
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
3051
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
3014
3052
  const dir = findWorkspaceStorageDir(traecodeWorkspaceStorageDir(home), cwd);
3015
3053
  if (!dir) return "failed";
3016
3054
  const db = join18(dir, "state.vscdb");
@@ -3045,7 +3083,7 @@ function workspaceEnableHint(opts = {}) {
3045
3083
  if (typeof state.lastEnableHint === "number" && now - state.lastEnableHint < HINT_MIN_INTERVAL_MS) {
3046
3084
  return void 0;
3047
3085
  }
3048
- writeFileSync4(
3086
+ writeFileSync5(
3049
3087
  opts.stateFile ?? gateStateFile(),
3050
3088
  JSON.stringify({ ...state, lastEnableHint: now }, null, 2) + "\n"
3051
3089
  );
@@ -3227,6 +3265,10 @@ function readCursorTranscript(path) {
3227
3265
  }
3228
3266
 
3229
3267
  // src/core/transcript-antigravity.ts
3268
+ function unwrapUserRequest(text) {
3269
+ const request = /<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/.exec(text);
3270
+ return request ? request[1] : text.replace(/<ADDITIONAL_METADATA>[\s\S]*?<\/ADDITIONAL_METADATA>/g, "");
3271
+ }
3230
3272
  function readAntigravityTranscript(path) {
3231
3273
  if (!path) return [];
3232
3274
  const turns = [];
@@ -3236,7 +3278,8 @@ function readAntigravityTranscript(path) {
3236
3278
  const role = event.role ?? event.message?.role ?? event.type;
3237
3279
  const normalizedRole = role === "user" || role === "USER_INPUT" ? "user" : role === "assistant" || role === "model" || role === "PLANNER_RESPONSE" ? "assistant" : void 0;
3238
3280
  const content = event.content ?? event.text ?? event.message?.content ?? event.message?.text;
3239
- const clean = typeof content === "string" ? stripInjectedMemory(content).trim() : "";
3281
+ const text = typeof content === "string" ? stripInjectedMemory(content) : "";
3282
+ const clean = (normalizedRole === "user" ? unwrapUserRequest(text) : text).trim();
3240
3283
  if (normalizedRole && clean) {
3241
3284
  turns.push({
3242
3285
  role: normalizedRole,
@@ -3267,7 +3310,7 @@ function readCopilotTranscript(path) {
3267
3310
  }
3268
3311
 
3269
3312
  // src/core/transcript-grok.ts
3270
- import { existsSync as existsSync9, readFileSync as readFileSync11, readdirSync as readdirSync3 } from "fs";
3313
+ import { existsSync as existsSync9, readFileSync as readFileSync12, readdirSync as readdirSync3 } from "fs";
3271
3314
  import { homedir as homedir9 } from "os";
3272
3315
  import { join as join19 } from "path";
3273
3316
  var CHAT_HISTORY = "chat_history.jsonl";
@@ -3278,7 +3321,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
3278
3321
  try {
3279
3322
  for (const candidate of readdirSync3(sessionsDir)) {
3280
3323
  const directory = join19(sessionsDir, candidate);
3281
- if (readFileSync11(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3324
+ if (readFileSync12(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3282
3325
  return join19(directory, sessionId, CHAT_HISTORY);
3283
3326
  }
3284
3327
  }
@@ -3629,7 +3672,7 @@ function readDroidTranscript(path) {
3629
3672
  }
3630
3673
 
3631
3674
  // src/core/transcript-zcode.ts
3632
- import { readFileSync as readFileSync12 } from "fs";
3675
+ import { readFileSync as readFileSync13 } from "fs";
3633
3676
  function messageText(content) {
3634
3677
  if (typeof content === "string") return content.trim();
3635
3678
  if (!Array.isArray(content)) return "";
@@ -3639,7 +3682,7 @@ function readZcodeTranscript(path) {
3639
3682
  if (!path) return [];
3640
3683
  let body;
3641
3684
  try {
3642
- body = readFileSync12(path, "utf8");
3685
+ body = readFileSync13(path, "utf8");
3643
3686
  } catch {
3644
3687
  return [];
3645
3688
  }
@@ -3860,12 +3903,12 @@ function readWorkbuddyTranscript(path) {
3860
3903
  }
3861
3904
 
3862
3905
  // src/core/transcript-codebuddy-ide.ts
3863
- import { readFileSync as readFileSync13 } from "fs";
3906
+ import { readFileSync as readFileSync14 } from "fs";
3864
3907
  import { basename as basename3, dirname as dirname12, join as join22 } from "path";
3865
3908
  var IDE_CONTEXT_RE = /<(user_info|git_status|additional_data|system_reminder)\b[\s\S]*?<\/\1>/g;
3866
3909
  function readJson(path) {
3867
3910
  try {
3868
- return JSON.parse(readFileSync13(path, "utf8"));
3911
+ return JSON.parse(readFileSync14(path, "utf8"));
3869
3912
  } catch {
3870
3913
  return void 0;
3871
3914
  }
@@ -4079,7 +4122,9 @@ var HOOK_HARNESSES = {
4079
4122
  parse: (ev) => ({
4080
4123
  sessionId: ev.session_id,
4081
4124
  transcriptPath: ev.transcript_path,
4082
- cwd: ev.cwd
4125
+ cwd: ev.cwd,
4126
+ // The transcript may not hold the final reply yet when Stop fires after a tool call (#5790).
4127
+ lastAssistantMessage: ev.last_assistant_message
4083
4128
  })
4084
4129
  }
4085
4130
  },
@@ -4562,3 +4607,42 @@ var runHarnessRetain = (harness) => runRetainHook(HOOK_HARNESSES[harness].retain
4562
4607
 
4563
4608
  // src/traecode-stop-hook.ts
4564
4609
  void runHarnessRetain("traecode");
4610
+ /*! Bundled license information:
4611
+
4612
+ smol-toml/dist/error.js:
4613
+ smol-toml/dist/primitive.js:
4614
+ smol-toml/dist/date.js:
4615
+ smol-toml/dist/extract.js:
4616
+ smol-toml/dist/util.js:
4617
+ smol-toml/dist/struct.js:
4618
+ smol-toml/dist/parse.js:
4619
+ smol-toml/dist/stringify.js:
4620
+ smol-toml/dist/index.js:
4621
+ (*!
4622
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
4623
+ * SPDX-License-Identifier: BSD-3-Clause
4624
+ *
4625
+ * Redistribution and use in source and binary forms, with or without
4626
+ * modification, are permitted provided that the following conditions are met:
4627
+ *
4628
+ * 1. Redistributions of source code must retain the above copyright notice, this
4629
+ * list of conditions and the following disclaimer.
4630
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
4631
+ * this list of conditions and the following disclaimer in the
4632
+ * documentation and/or other materials provided with the distribution.
4633
+ * 3. Neither the name of the copyright holder nor the names of its contributors
4634
+ * may be used to endorse or promote products derived from this software without
4635
+ * specific prior written permission.
4636
+ *
4637
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
4638
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4639
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4640
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
4641
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4642
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
4643
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
4644
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
4645
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4646
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4647
+ *)
4648
+ */