@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
package/dist/installer.js CHANGED
@@ -8,11 +8,11 @@ import {
8
8
  existsSync as existsSync13,
9
9
  mkdirSync as mkdirSync7,
10
10
  mkdtempSync as mkdtempSync2,
11
- readFileSync as readFileSync15,
11
+ readFileSync as readFileSync16,
12
12
  readSync as readSync4,
13
13
  realpathSync as realpathSync3,
14
14
  rmSync as rmSync4,
15
- writeFileSync as writeFileSync5
15
+ writeFileSync as writeFileSync6
16
16
  } from "fs";
17
17
  import { homedir as homedir13, tmpdir as tmpdir5 } from "os";
18
18
  import { isatty } from "tty";
@@ -2217,11 +2217,11 @@ var PAGE_TAXONOMY = [
2217
2217
  var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
2218
2218
 
2219
2219
  // package.json
2220
- var version = "0.8.1";
2220
+ var version = "0.8.3";
2221
2221
 
2222
2222
  // src/core/util.ts
2223
- import { accessSync, constants } from "fs";
2224
- import { delimiter, join as join6 } from "path";
2223
+ import { accessSync, constants, statSync as statSync2 } from "fs";
2224
+ import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
2225
2225
  function isOurMcpEntry(entry) {
2226
2226
  if (!entry || typeof entry !== "object") return false;
2227
2227
  const candidate = entry;
@@ -2261,7 +2261,7 @@ import { tmpdir } from "os";
2261
2261
  import { dirname as dirname5, join as join8 } from "path";
2262
2262
 
2263
2263
  // src/core/turn-journal.ts
2264
- import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
2264
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
2265
2265
  import { tmpdir as tmpdir2 } from "os";
2266
2266
  import { dirname as dirname6, join as join9 } from "path";
2267
2267
 
@@ -2546,7 +2546,10 @@ function formatUsageReport(usage, path = usageFilePath()) {
2546
2546
 
2547
2547
  // src/core/git.ts
2548
2548
  import { execFileSync as execFileSync2 } from "child_process";
2549
- import { resolve as resolve2 } from "path";
2549
+ import { resolve as resolve3 } from "path";
2550
+ var US = "";
2551
+ var RS = "";
2552
+ var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
2550
2553
 
2551
2554
  // src/core/status.ts
2552
2555
  import { execFileSync as execFileSync4 } from "child_process";
@@ -2554,7 +2557,7 @@ import { execFileSync as execFileSync4 } from "child_process";
2554
2557
  // src/core/survey.ts
2555
2558
  import { execFileSync as execFileSync3, spawn as realSpawn4 } from "child_process";
2556
2559
  import { createHash as createHash4 } from "crypto";
2557
- import { existsSync as existsSync3 } from "fs";
2560
+ import { existsSync as existsSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
2558
2561
  import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2559
2562
  import { dirname as dirname8, join as join13 } from "path";
2560
2563
  import { fileURLToPath as fileURLToPath3 } from "url";
@@ -2569,7 +2572,7 @@ import {
2569
2572
  renameSync as renameSync3,
2570
2573
  rmdirSync,
2571
2574
  rmSync as rmSync2,
2572
- statSync as statSync3,
2575
+ statSync as statSync4,
2573
2576
  unlinkSync,
2574
2577
  utimesSync,
2575
2578
  writeFileSync as writeFileSync2
@@ -2581,10 +2584,10 @@ import { spawn as realSpawn5 } from "child_process";
2581
2584
  import {
2582
2585
  existsSync as existsSync4,
2583
2586
  mkdirSync as mkdirSync5,
2584
- readFileSync as readFileSync7,
2587
+ readFileSync as readFileSync8,
2585
2588
  realpathSync as realpathSync2,
2586
2589
  unlinkSync as unlinkSync2,
2587
- writeFileSync as writeFileSync3
2590
+ writeFileSync as writeFileSync4
2588
2591
  } from "fs";
2589
2592
  import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2590
2593
  import { dirname as dirname9, join as join14 } from "path";
@@ -2595,7 +2598,7 @@ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
2595
2598
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2596
2599
 
2597
2600
  // src/core/skill-sync.ts
2598
- import { cpSync, existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
2601
+ import { cpSync, existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2599
2602
  import { homedir as homedir6 } from "os";
2600
2603
  import { dirname as dirname10, join as join16 } from "path";
2601
2604
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -2654,9 +2657,9 @@ var resolveSkillDirs = (harness, home) => {
2654
2657
  };
2655
2658
 
2656
2659
  // src/core/legacy.ts
2657
- import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
2660
+ import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
2658
2661
  import { homedir as homedir7 } from "os";
2659
- import { join as join17, relative, isAbsolute as isAbsolute2 } from "path";
2662
+ import { join as join17, relative, isAbsolute as isAbsolute3 } from "path";
2660
2663
  var LEGACY_CONFIG_FILES = {
2661
2664
  "claude-code": "claude-code.json",
2662
2665
  codex: "codex.json"
@@ -2680,7 +2683,7 @@ function readOne(harness, home) {
2680
2683
  if (!existsSync7(source)) return void 0;
2681
2684
  let raw;
2682
2685
  try {
2683
- raw = JSON.parse(readFileSync9(source, "utf8"));
2686
+ raw = JSON.parse(readFileSync10(source, "utf8"));
2684
2687
  } catch {
2685
2688
  return void 0;
2686
2689
  }
@@ -2708,9 +2711,9 @@ function readOne(harness, home) {
2708
2711
 
2709
2712
  // src/core/traecode-mcp.ts
2710
2713
  import { execFileSync as execFileSync5 } from "child_process";
2711
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
2714
+ import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync11, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "fs";
2712
2715
  import { homedir as homedir8 } from "os";
2713
- import { dirname as dirname11, isAbsolute as isAbsolute3, join as join18 } from "path";
2716
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18 } from "path";
2714
2717
  import { fileURLToPath as fileURLToPath6 } from "url";
2715
2718
  var MCP_SERVER_NAME = "hindsight";
2716
2719
  var MCP_FILE_REL = join18(".trae", "mcp.json");
@@ -2745,7 +2748,7 @@ function gateStateFile() {
2745
2748
  }
2746
2749
  function readGateState(opts = {}) {
2747
2750
  try {
2748
- return JSON.parse(readFileSync10(opts.stateFile ?? gateStateFile(), "utf8"));
2751
+ return JSON.parse(readFileSync11(opts.stateFile ?? gateStateFile(), "utf8"));
2749
2752
  } catch {
2750
2753
  return {};
2751
2754
  }
@@ -2753,7 +2756,7 @@ function readGateState(opts = {}) {
2753
2756
  function workspaceMcpGateState(settingsPath) {
2754
2757
  let raw;
2755
2758
  try {
2756
- raw = readFileSync10(settingsPath, "utf8");
2759
+ raw = readFileSync11(settingsPath, "utf8");
2757
2760
  } catch {
2758
2761
  return "unknown";
2759
2762
  }
@@ -2769,13 +2772,13 @@ function enableWorkspaceMcpSetting(settingsPath) {
2769
2772
  try {
2770
2773
  let doc = {};
2771
2774
  try {
2772
- doc = JSON.parse(readFileSync10(settingsPath, "utf8"));
2775
+ doc = JSON.parse(readFileSync11(settingsPath, "utf8"));
2773
2776
  } catch {
2774
2777
  if (existsSync8(settingsPath)) return false;
2775
2778
  }
2776
2779
  doc[WORKSPACE_MCP_KEY] = true;
2777
2780
  mkdirSync6(dirname11(settingsPath), { recursive: true });
2778
- writeFileSync4(settingsPath, JSON.stringify(doc, null, 2) + "\n");
2781
+ writeFileSync5(settingsPath, JSON.stringify(doc, null, 2) + "\n");
2779
2782
  return true;
2780
2783
  } catch {
2781
2784
  return false;
@@ -2783,7 +2786,7 @@ function enableWorkspaceMcpSetting(settingsPath) {
2783
2786
  }
2784
2787
  function markWorkspaceMcpEnabled(opts = {}) {
2785
2788
  try {
2786
- writeFileSync4(
2789
+ writeFileSync5(
2787
2790
  opts.stateFile ?? gateStateFile(),
2788
2791
  JSON.stringify({ ...readGateState(opts), workspaceMcpEnabled: true }, null, 2) + "\n"
2789
2792
  );
@@ -2800,7 +2803,7 @@ function workspaceMcpHint(opts = {}) {
2800
2803
  if (typeof state.lastHint === "number" && now - state.lastHint < HINT_MIN_INTERVAL_MS) {
2801
2804
  return void 0;
2802
2805
  }
2803
- writeFileSync4(
2806
+ writeFileSync5(
2804
2807
  opts.stateFile ?? gateStateFile(),
2805
2808
  JSON.stringify({ ...state, lastHint: now }, null, 2) + "\n"
2806
2809
  );
@@ -2818,10 +2821,10 @@ function gitignoreCovers(lines) {
2818
2821
  function ensureGitignored(repo) {
2819
2822
  const gitignore = join18(repo, ".gitignore");
2820
2823
  if (!existsSync8(gitignore)) return;
2821
- const current2 = readFileSync10(gitignore, "utf8");
2824
+ const current2 = readFileSync11(gitignore, "utf8");
2822
2825
  if (gitignoreCovers(current2.split("\n"))) return;
2823
2826
  const addition = (current2.endsWith("\n") || current2 === "" ? "" : "\n") + "# hindsight MCP registration (machine-specific)\n.trae/mcp.json\n";
2824
- writeFileSync4(gitignore, current2 + addition);
2827
+ writeFileSync5(gitignore, current2 + addition);
2825
2828
  }
2826
2829
  function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
2827
2830
  registerTraecodeWorkspaceMcp(cwd, opts);
@@ -2831,7 +2834,7 @@ function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
2831
2834
  function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2832
2835
  try {
2833
2836
  const home = opts.home ?? homedir8();
2834
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
2837
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
2835
2838
  const dist = opts.dist ?? bundledDistDir();
2836
2839
  const script = join18(dist, "mcp-server.js");
2837
2840
  if (!existsSync8(script)) return "skipped";
@@ -2839,7 +2842,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2839
2842
  let doc = {};
2840
2843
  let exists = false;
2841
2844
  try {
2842
- doc = JSON.parse(readFileSync10(file, "utf8"));
2845
+ doc = JSON.parse(readFileSync11(file, "utf8"));
2843
2846
  exists = true;
2844
2847
  } catch {
2845
2848
  if (existsSync8(file)) return "skipped";
@@ -2869,7 +2872,7 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2869
2872
  if (existing !== void 0 && canon(merged) === canon(existing)) return "current";
2870
2873
  servers[MCP_SERVER_NAME] = merged;
2871
2874
  mkdirSync6(dirname11(file), { recursive: true });
2872
- writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
2875
+ writeFileSync5(file, JSON.stringify(doc, null, 2) + "\n");
2873
2876
  if (!exists) ensureGitignored(cwd);
2874
2877
  diag("traecode", "workspace_mcp_registered", { cwd, file });
2875
2878
  return "registered";
@@ -2884,11 +2887,11 @@ function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
2884
2887
  function removeTraecodeWorkspaceMcpEntry(cwd, opts = {}) {
2885
2888
  try {
2886
2889
  const home = opts.home ?? homedir8();
2887
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return false;
2890
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return false;
2888
2891
  const file = join18(cwd, MCP_FILE_REL);
2889
2892
  let doc;
2890
2893
  try {
2891
- doc = JSON.parse(readFileSync10(file, "utf8"));
2894
+ doc = JSON.parse(readFileSync11(file, "utf8"));
2892
2895
  } catch {
2893
2896
  return false;
2894
2897
  }
@@ -2899,7 +2902,7 @@ function removeTraecodeWorkspaceMcpEntry(cwd, opts = {}) {
2899
2902
  delete record[MCP_SERVER_NAME];
2900
2903
  if (Object.keys(record).length === 0) delete doc.mcpServers;
2901
2904
  if (Object.keys(doc).length === 0) rmSync3(file);
2902
- else writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
2905
+ else writeFileSync5(file, JSON.stringify(doc, null, 2) + "\n");
2903
2906
  return true;
2904
2907
  } catch {
2905
2908
  return false;
@@ -2948,7 +2951,7 @@ function findWorkspaceStorageDir(storage, repo) {
2948
2951
  }
2949
2952
  for (const name of entries) {
2950
2953
  try {
2951
- const doc = JSON.parse(readFileSync10(join18(storage, name, "workspace.json"), "utf8"));
2954
+ const doc = JSON.parse(readFileSync11(join18(storage, name, "workspace.json"), "utf8"));
2952
2955
  if (typeof doc.folder !== "string") continue;
2953
2956
  let folder;
2954
2957
  try {
@@ -2966,7 +2969,7 @@ function findWorkspaceStorageDir(storage, repo) {
2966
2969
  function ensureWorkspaceMcpEnabled(cwd, opts = {}) {
2967
2970
  try {
2968
2971
  const home = opts.home ?? homedir8();
2969
- if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
2972
+ if (!cwd || !isAbsolute4(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
2970
2973
  const dir = findWorkspaceStorageDir(traecodeWorkspaceStorageDir(home), cwd);
2971
2974
  if (!dir) return "failed";
2972
2975
  const db = join18(dir, "state.vscdb");
@@ -3001,7 +3004,7 @@ function workspaceEnableHint(opts = {}) {
3001
3004
  if (typeof state.lastEnableHint === "number" && now - state.lastEnableHint < HINT_MIN_INTERVAL_MS) {
3002
3005
  return void 0;
3003
3006
  }
3004
- writeFileSync4(
3007
+ writeFileSync5(
3005
3008
  opts.stateFile ?? gateStateFile(),
3006
3009
  JSON.stringify({ ...state, lastEnableHint: now }, null, 2) + "\n"
3007
3010
  );
@@ -3183,6 +3186,10 @@ function readCursorTranscript(path) {
3183
3186
  }
3184
3187
 
3185
3188
  // src/core/transcript-antigravity.ts
3189
+ function unwrapUserRequest(text) {
3190
+ const request = /<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/.exec(text);
3191
+ return request ? request[1] : text.replace(/<ADDITIONAL_METADATA>[\s\S]*?<\/ADDITIONAL_METADATA>/g, "");
3192
+ }
3186
3193
  function readAntigravityTranscript(path) {
3187
3194
  if (!path) return [];
3188
3195
  const turns = [];
@@ -3192,7 +3199,8 @@ function readAntigravityTranscript(path) {
3192
3199
  const role = event.role ?? event.message?.role ?? event.type;
3193
3200
  const normalizedRole = role === "user" || role === "USER_INPUT" ? "user" : role === "assistant" || role === "model" || role === "PLANNER_RESPONSE" ? "assistant" : void 0;
3194
3201
  const content = event.content ?? event.text ?? event.message?.content ?? event.message?.text;
3195
- const clean = typeof content === "string" ? stripInjectedMemory(content).trim() : "";
3202
+ const text = typeof content === "string" ? stripInjectedMemory(content) : "";
3203
+ const clean = (normalizedRole === "user" ? unwrapUserRequest(text) : text).trim();
3196
3204
  if (normalizedRole && clean) {
3197
3205
  turns.push({
3198
3206
  role: normalizedRole,
@@ -3223,7 +3231,7 @@ function readCopilotTranscript(path) {
3223
3231
  }
3224
3232
 
3225
3233
  // src/core/transcript-grok.ts
3226
- import { existsSync as existsSync9, readFileSync as readFileSync11, readdirSync as readdirSync3 } from "fs";
3234
+ import { existsSync as existsSync9, readFileSync as readFileSync12, readdirSync as readdirSync3 } from "fs";
3227
3235
  import { homedir as homedir9 } from "os";
3228
3236
  import { join as join19 } from "path";
3229
3237
  var CHAT_HISTORY = "chat_history.jsonl";
@@ -3234,7 +3242,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
3234
3242
  try {
3235
3243
  for (const candidate of readdirSync3(sessionsDir)) {
3236
3244
  const directory = join19(sessionsDir, candidate);
3237
- if (readFileSync11(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3245
+ if (readFileSync12(join19(directory, ".cwd"), "utf8").trim() === cwd) {
3238
3246
  return join19(directory, sessionId, CHAT_HISTORY);
3239
3247
  }
3240
3248
  }
@@ -3585,7 +3593,7 @@ function readDroidTranscript(path) {
3585
3593
  }
3586
3594
 
3587
3595
  // src/core/transcript-zcode.ts
3588
- import { readFileSync as readFileSync12 } from "fs";
3596
+ import { readFileSync as readFileSync13 } from "fs";
3589
3597
  function messageText(content) {
3590
3598
  if (typeof content === "string") return content.trim();
3591
3599
  if (!Array.isArray(content)) return "";
@@ -3595,7 +3603,7 @@ function readZcodeTranscript(path) {
3595
3603
  if (!path) return [];
3596
3604
  let body;
3597
3605
  try {
3598
- body = readFileSync12(path, "utf8");
3606
+ body = readFileSync13(path, "utf8");
3599
3607
  } catch {
3600
3608
  return [];
3601
3609
  }
@@ -3816,12 +3824,12 @@ function readWorkbuddyTranscript(path) {
3816
3824
  }
3817
3825
 
3818
3826
  // src/core/transcript-codebuddy-ide.ts
3819
- import { readFileSync as readFileSync13 } from "fs";
3827
+ import { readFileSync as readFileSync14 } from "fs";
3820
3828
  import { basename as basename3, dirname as dirname12, join as join22 } from "path";
3821
3829
  var IDE_CONTEXT_RE = /<(user_info|git_status|additional_data|system_reminder)\b[\s\S]*?<\/\1>/g;
3822
3830
  function readJson(path) {
3823
3831
  try {
3824
- return JSON.parse(readFileSync13(path, "utf8"));
3832
+ return JSON.parse(readFileSync14(path, "utf8"));
3825
3833
  } catch {
3826
3834
  return void 0;
3827
3835
  }
@@ -4035,7 +4043,9 @@ var HOOK_HARNESSES = {
4035
4043
  parse: (ev) => ({
4036
4044
  sessionId: ev.session_id,
4037
4045
  transcriptPath: ev.transcript_path,
4038
- cwd: ev.cwd
4046
+ cwd: ev.cwd,
4047
+ // The transcript may not hold the final reply yet when Stop fires after a tool call (#5790).
4048
+ lastAssistantMessage: ev.last_assistant_message
4039
4049
  })
4040
4050
  }
4041
4051
  },
@@ -4522,9 +4532,9 @@ import {
4522
4532
  existsSync as existsSync12,
4523
4533
  openSync as openSync2,
4524
4534
  readdirSync as readdirSync5,
4525
- readFileSync as readFileSync14,
4535
+ readFileSync as readFileSync15,
4526
4536
  readSync as readSync2,
4527
- statSync as statSync4
4537
+ statSync as statSync5
4528
4538
  } from "fs";
4529
4539
  import { createHash as createHash5 } from "crypto";
4530
4540
  import { homedir as homedir12 } from "os";
@@ -4688,7 +4698,7 @@ function withinRepo(dir, repoDir) {
4688
4698
  }
4689
4699
  function claudeSessionCwd(file) {
4690
4700
  try {
4691
- for (const line of readFileSync14(file, "utf8").split("\n", 400)) {
4701
+ for (const line of readFileSync15(file, "utf8").split("\n", 400)) {
4692
4702
  if (!line.includes('"cwd"')) continue;
4693
4703
  const cwd = JSON.parse(line).cwd;
4694
4704
  if (cwd) return cwd;
@@ -4762,7 +4772,7 @@ function codexHistory(repoDir, home) {
4762
4772
  const walk = (dir) => {
4763
4773
  for (const entry of readdirSync5(dir)) {
4764
4774
  const p = join23(dir, entry);
4765
- if (statSync4(p).isDirectory()) walk(p);
4775
+ if (statSync5(p).isDirectory()) walk(p);
4766
4776
  else if (entry.endsWith(".jsonl")) files.push(p);
4767
4777
  }
4768
4778
  };
@@ -4883,7 +4893,7 @@ function dshHistory(repoDir, home) {
4883
4893
  return { supported: true, sessions, unattributed };
4884
4894
  }
4885
4895
  function readDshLog(file) {
4886
- const bytes = readFileSync14(file);
4896
+ const bytes = readFileSync15(file);
4887
4897
  const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
4888
4898
  return text.split("\n").filter((line) => line.trim());
4889
4899
  }
@@ -5178,7 +5188,7 @@ function isPlainObject(value) {
5178
5188
  }
5179
5189
  function readJson2(path) {
5180
5190
  try {
5181
- const parsed = JSON.parse(readFileSync15(path, "utf8"));
5191
+ const parsed = JSON.parse(readFileSync16(path, "utf8"));
5182
5192
  return isPlainObject(parsed) ? parsed : {};
5183
5193
  } catch {
5184
5194
  return {};
@@ -5196,7 +5206,7 @@ function parseJsonc(text) {
5196
5206
  function writeJson(path, value) {
5197
5207
  mkdirSync7(dirname13(path), { recursive: true });
5198
5208
  backupOnce(path);
5199
- writeFileSync5(path, JSON.stringify(value, null, 2) + "\n");
5209
+ writeFileSync6(path, JSON.stringify(value, null, 2) + "\n");
5200
5210
  }
5201
5211
  function backupOnce(path) {
5202
5212
  if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`)) {
@@ -5204,7 +5214,7 @@ function backupOnce(path) {
5204
5214
  }
5205
5215
  }
5206
5216
  function writeJsonc(path, key, value) {
5207
- const text = existsSync13(path) ? readFileSync15(path, "utf8") : "";
5217
+ const text = existsSync13(path) ? readFileSync16(path, "utf8") : "";
5208
5218
  const edits = modify(text, [key], value, {
5209
5219
  formattingOptions: {
5210
5220
  tabSize: 2,
@@ -5217,7 +5227,7 @@ function writeJsonc(path, key, value) {
5217
5227
  const next = applyEdits(text, edits);
5218
5228
  mkdirSync7(dirname13(path), { recursive: true });
5219
5229
  backupOnce(path);
5220
- writeFileSync5(path, next.endsWith("\n") ? next : `${next}
5230
+ writeFileSync6(path, next.endsWith("\n") ? next : `${next}
5221
5231
  `);
5222
5232
  }
5223
5233
  function mergeHookEvent(existing, entry) {
@@ -5234,6 +5244,7 @@ function setOrDelete(obj, key, arr) {
5234
5244
  var cmdHook = (dist, file, timeout) => ({
5235
5245
  hooks: [{ type: "command", command: `node "${join24(dist, file)}"`, timeout }]
5236
5246
  });
5247
+ var nodeCommand = (script) => script.includes(" ") ? `node "${script}"` : `node ${script}`;
5237
5248
  var processHook = (dist, file, timeoutMs) => ({
5238
5249
  hooks: [{ type: "process", command: "node", args: [join24(dist, file)], timeoutMs }]
5239
5250
  });
@@ -5251,7 +5262,7 @@ function mergeHarnessHooks(hooks, harness, dist) {
5251
5262
  if (installedEvents.has(hook.event)) continue;
5252
5263
  installedEvents.add(hook.event);
5253
5264
  const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : spec.configStyle === "process" ? processHook(dist, hook.entry, hook.timeout) : {
5254
- command: `node "${join24(dist, hook.entry)}"`,
5265
+ command: nodeCommand(join24(dist, hook.entry)),
5255
5266
  ...hook.timeout ? { timeout: hook.timeout } : {}
5256
5267
  };
5257
5268
  hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
@@ -5320,7 +5331,7 @@ function registerOpencodePlugin(c, name) {
5320
5331
  const path = opencodeConfigPath(c);
5321
5332
  let cfg = {};
5322
5333
  if (existsSync13(path)) {
5323
- const parsed = parseJsonc(readFileSync15(path, "utf8"));
5334
+ const parsed = parseJsonc(readFileSync16(path, "utf8"));
5324
5335
  if (!parsed) {
5325
5336
  c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
5326
5337
  return;
@@ -5334,7 +5345,7 @@ function registerOpencodePlugin(c, name) {
5334
5345
  function unregisterOpencodePlugin(c, name) {
5335
5346
  const path = opencodeConfigPath(c);
5336
5347
  if (!existsSync13(path)) return;
5337
- const cfg = parseJsonc(readFileSync15(path, "utf8"));
5348
+ const cfg = parseJsonc(readFileSync16(path, "utf8"));
5338
5349
  if (!cfg || !Array.isArray(cfg.plugin)) return;
5339
5350
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
5340
5351
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -5398,7 +5409,7 @@ var kilo = {
5398
5409
  const path = kiloConfigPath(c);
5399
5410
  let cfg = {};
5400
5411
  if (existsSync13(path)) {
5401
- const parsed = parseJsonc(readFileSync15(path, "utf8"));
5412
+ const parsed = parseJsonc(readFileSync16(path, "utf8"));
5402
5413
  if (!parsed) {
5403
5414
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
5404
5415
  return;
@@ -5413,7 +5424,7 @@ var kilo = {
5413
5424
  uninstall(c) {
5414
5425
  const path = kiloConfigPath(c);
5415
5426
  if (!existsSync13(path)) return;
5416
- const cfg = parseJsonc(readFileSync15(path, "utf8"));
5427
+ const cfg = parseJsonc(readFileSync16(path, "utf8"));
5417
5428
  if (!cfg || !Array.isArray(cfg.plugin)) return;
5418
5429
  const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
5419
5430
  writeJsonc(path, "plugin", kept.length ? kept : void 0);
@@ -5493,7 +5504,7 @@ var codex = {
5493
5504
  writeJson(hooksPath, cfg);
5494
5505
  c.log?.(`codex: hooks merged into ${hooksPath}`);
5495
5506
  const tomlPath = join24(c.home, ".codex", "config.toml");
5496
- const existing = existsSync13(tomlPath) ? readFileSync15(tomlPath, "utf8") : "";
5507
+ const existing = existsSync13(tomlPath) ? readFileSync16(tomlPath, "utf8") : "";
5497
5508
  const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
5498
5509
  const additions = [];
5499
5510
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
@@ -5513,7 +5524,7 @@ var codex = {
5513
5524
  copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
5514
5525
  }
5515
5526
  mkdirSync7(dirname13(tomlPath), { recursive: true });
5516
- writeFileSync5(tomlPath, next);
5527
+ writeFileSync6(tomlPath, next);
5517
5528
  c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
5518
5529
  }
5519
5530
  installSkill(c, "codex");
@@ -5530,9 +5541,9 @@ var codex = {
5530
5541
  uninstallSkill(c, "codex");
5531
5542
  const tomlPath = join24(c.home, ".codex", "config.toml");
5532
5543
  if (existsSync13(tomlPath)) {
5533
- const toml = readFileSync15(tomlPath, "utf8");
5544
+ const toml = readFileSync16(tomlPath, "utf8");
5534
5545
  const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
5535
- if (cleaned !== toml) writeFileSync5(tomlPath, cleaned);
5546
+ if (cleaned !== toml) writeFileSync6(tomlPath, cleaned);
5536
5547
  }
5537
5548
  c.log?.(
5538
5549
  "codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
@@ -5569,14 +5580,14 @@ var antigravity = {
5569
5580
  if (!settings.statusLine) {
5570
5581
  settings.statusLine = {
5571
5582
  type: "command",
5572
- command: `node "${join24(c.dist, "antigravity-statusline.js")}"`
5583
+ command: nodeCommand(join24(c.dist, "antigravity-statusline.js"))
5573
5584
  };
5574
5585
  writeJson(settingsPath, settings);
5575
5586
  c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
5576
5587
  } else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
5577
5588
  settings.statusLine = {
5578
5589
  type: "command",
5579
- command: `node "${join24(c.dist, "antigravity-statusline.js")}"`
5590
+ command: nodeCommand(join24(c.dist, "antigravity-statusline.js"))
5580
5591
  };
5581
5592
  writeJson(settingsPath, settings);
5582
5593
  } else {
@@ -5662,7 +5673,7 @@ function stageRuntime(c) {
5662
5673
  const source = join24(c.pkgRoot, resource);
5663
5674
  if (existsSync13(source)) cpSync2(source, join24(target, resource), { recursive: true });
5664
5675
  }
5665
- writeFileSync5(
5676
+ writeFileSync6(
5666
5677
  join24(target, ORIGIN_FILE),
5667
5678
  JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
5668
5679
  );
@@ -6025,7 +6036,7 @@ var grok = {
6025
6036
  detect: (c) => onPath2("grok") || existsSync13(join24(c.home, ".grok")),
6026
6037
  install(c) {
6027
6038
  const path = join24(c.home, ".grok", "config.toml");
6028
- const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
6039
+ const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
6029
6040
  const stripped = existing.replace(GROK_BLOCK_RE, "\n");
6030
6041
  const withoutOurs = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
6031
6042
  const tomlString = (value) => JSON.stringify(value);
@@ -6047,7 +6058,7 @@ ${GROK_MARKER_END}
6047
6058
  if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
6048
6059
  copyFileSync(path, `${path}.hindsight-backup`);
6049
6060
  mkdirSync7(dirname13(path), { recursive: true });
6050
- writeFileSync5(path, next);
6061
+ writeFileSync6(path, next);
6051
6062
  const hooksPath = grokHooksPath(c);
6052
6063
  const file = readJson2(hooksPath);
6053
6064
  const hooks = isPlainObject(file.hooks) ? file.hooks : {};
@@ -6059,11 +6070,11 @@ ${GROK_MARKER_END}
6059
6070
  uninstall(c) {
6060
6071
  const path = join24(c.home, ".grok", "config.toml");
6061
6072
  if (existsSync13(path)) {
6062
- const existing = readFileSync15(path, "utf8");
6073
+ const existing = readFileSync16(path, "utf8");
6063
6074
  const stripped = existing.replace(GROK_BLOCK_RE, "\n");
6064
6075
  const cleaned = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
6065
6076
  const safe = parseGrokToml(cleaned) !== null || parseGrokToml(existing) === null;
6066
- if (cleaned !== existing && safe) writeFileSync5(path, cleaned);
6077
+ if (cleaned !== existing && safe) writeFileSync6(path, cleaned);
6067
6078
  }
6068
6079
  const hooksPath = grokHooksPath(c);
6069
6080
  if (existsSync13(hooksPath)) {
@@ -6090,7 +6101,7 @@ var kimi = {
6090
6101
  detect: (c) => onPath2("kimi") || existsSync13(kimiHome(c)),
6091
6102
  install(c) {
6092
6103
  const path = join24(kimiHome(c), "config.toml");
6093
- const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
6104
+ const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
6094
6105
  const withoutOurs = existing.replace(KIMI_BLOCK_RE, "\n");
6095
6106
  const spec = HOOK_HARNESSES["kimi-code"];
6096
6107
  const entries = Object.values(spec.install).map(
@@ -6107,7 +6118,7 @@ ${entries}${KIMI_MARKER_END}
6107
6118
  if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
6108
6119
  copyFileSync(path, `${path}.hindsight-backup`);
6109
6120
  mkdirSync7(dirname13(path), { recursive: true });
6110
- writeFileSync5(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
6121
+ writeFileSync6(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
6111
6122
  const mcpPath = join24(kimiHome(c), "mcp.json");
6112
6123
  const mcp = readJson2(mcpPath);
6113
6124
  mcp.mcpServers = { ...mcp.mcpServers ?? {}, hindsight: mcpServerEntry(c.dist, "kimi-code") };
@@ -6118,9 +6129,9 @@ ${entries}${KIMI_MARKER_END}
6118
6129
  uninstall(c) {
6119
6130
  const path = join24(kimiHome(c), "config.toml");
6120
6131
  if (existsSync13(path)) {
6121
- const existing = readFileSync15(path, "utf8");
6132
+ const existing = readFileSync16(path, "utf8");
6122
6133
  const cleaned = existing.replace(KIMI_BLOCK_RE, "\n");
6123
- if (cleaned !== existing) writeFileSync5(path, cleaned);
6134
+ if (cleaned !== existing) writeFileSync6(path, cleaned);
6124
6135
  }
6125
6136
  const mcpPath = join24(kimiHome(c), "mcp.json");
6126
6137
  if (existsSync13(mcpPath)) {
@@ -6141,7 +6152,7 @@ function removeLegacyClineHooks(c) {
6141
6152
  const hooksDir = join24(c.home, "Documents", "Cline", "Hooks");
6142
6153
  for (const event of CLINE_OLD_HOOK_EVENTS) {
6143
6154
  const path = join24(hooksDir, event);
6144
- if (existsSync13(path) && readFileSync15(path, "utf8").includes(CLINE_HOOK_MARKER)) {
6155
+ if (existsSync13(path) && readFileSync16(path, "utf8").includes(CLINE_HOOK_MARKER)) {
6145
6156
  rmSync4(path, { force: true });
6146
6157
  }
6147
6158
  }
@@ -6196,7 +6207,7 @@ function prepareDcodeMarketplace(c) {
6196
6207
  let marketplace = { plugins: [] };
6197
6208
  if (existsSync13(conventionalPath)) {
6198
6209
  try {
6199
- const parsed = JSON.parse(readFileSync15(conventionalPath, "utf8"));
6210
+ const parsed = JSON.parse(readFileSync16(conventionalPath, "utf8"));
6200
6211
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
6201
6212
  path = join24(root, DCODE_FALLBACK_MARKETPLACE);
6202
6213
  } else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
@@ -6210,7 +6221,7 @@ function prepareDcodeMarketplace(c) {
6210
6221
  }
6211
6222
  if (path !== conventionalPath && existsSync13(path)) {
6212
6223
  try {
6213
- const parsed = JSON.parse(readFileSync15(path, "utf8"));
6224
+ const parsed = JSON.parse(readFileSync16(path, "utf8"));
6214
6225
  if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
6215
6226
  c.log?.(`dcode: refusing to replace malformed marketplace file ${path}`);
6216
6227
  return false;
@@ -6287,7 +6298,7 @@ var dsh = {
6287
6298
  detect: (c) => onPath2("dsh") || existsSync13(dshHome(c)),
6288
6299
  install(c) {
6289
6300
  const path = join24(dshHome(c), "cordis.patch.yml");
6290
- const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
6301
+ const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
6291
6302
  const others = dshUserPatches(existing);
6292
6303
  const entry = pathToFileURL(join24(c.dist, "dsh.js")).href;
6293
6304
  const block = `${DSH_MARKER_START}
@@ -6299,7 +6310,7 @@ ${DSH_MARKER_END}
6299
6310
  if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
6300
6311
  copyFileSync(path, `${path}.hindsight-backup`);
6301
6312
  mkdirSync7(dirname13(path), { recursive: true });
6302
- writeFileSync5(path, others ? `${others}
6313
+ writeFileSync6(path, others ? `${others}
6303
6314
 
6304
6315
  ${block}` : block);
6305
6316
  installSkill(c, "dsh");
@@ -6310,10 +6321,10 @@ ${block}` : block);
6310
6321
  uninstall(c) {
6311
6322
  const path = join24(dshHome(c), "cordis.patch.yml");
6312
6323
  if (existsSync13(path)) {
6313
- const existing = readFileSync15(path, "utf8");
6324
+ const existing = readFileSync16(path, "utf8");
6314
6325
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
6315
6326
  if (others !== existing.trim())
6316
- writeFileSync5(path, others ? `${others}
6327
+ writeFileSync6(path, others ? `${others}
6317
6328
  ` : `${DSH_EMPTY_LIST}
6318
6329
  `);
6319
6330
  }
@@ -6718,7 +6729,7 @@ function importConversations(harness, ctx) {
6718
6729
  }
6719
6730
  const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
6720
6731
  const file = join24(mkdtempSync2(join24(tmpdir5(), "hindsight-import-")), "conversations.json");
6721
- writeFileSync5(file, JSON.stringify(found.sessions));
6732
+ writeFileSync6(file, JSON.stringify(found.sessions));
6722
6733
  ctx.log?.(
6723
6734
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
6724
6735
  );
@@ -6837,7 +6848,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
6837
6848
  const pkgRoot = dirname13(dist);
6838
6849
  let version2;
6839
6850
  try {
6840
- version2 = JSON.parse(readFileSync15(join24(pkgRoot, "package.json"), "utf8")).version;
6851
+ version2 = JSON.parse(readFileSync16(join24(pkgRoot, "package.json"), "utf8")).version;
6841
6852
  } catch {
6842
6853
  version2 = void 0;
6843
6854
  }
@@ -6874,6 +6885,7 @@ export {
6874
6885
  ORIGIN_FILE,
6875
6886
  flagValue,
6876
6887
  flagValueArgs,
6888
+ nodeCommand,
6877
6889
  parseJsonc,
6878
6890
  run,
6879
6891
  runtimeDir