@vectorize-io/hindsight-coding-agents 0.5.5 → 0.6.1

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 (50) hide show
  1. package/README.md +19 -5
  2. package/dist/antigravity-hook.js +87 -83
  3. package/dist/antigravity-statusline.js +32 -22
  4. package/dist/antigravity-stop-hook.js +160 -71
  5. package/dist/claude-hook.js +87 -83
  6. package/dist/claude-sessionstart-hook.js +111 -97
  7. package/dist/claude-stop-hook.js +160 -71
  8. package/dist/cline.js +161 -88
  9. package/dist/codex-hook.js +87 -83
  10. package/dist/codex-sessionstart-hook.js +111 -97
  11. package/dist/codex-stop-hook.js +160 -71
  12. package/dist/copilot-hook.js +87 -83
  13. package/dist/copilot-sessionstart-hook.js +111 -97
  14. package/dist/copilot-stop-hook.js +160 -71
  15. package/dist/cursor-hook.js +87 -83
  16. package/dist/cursor-sessionstart-hook.js +111 -97
  17. package/dist/cursor-stop-hook.js +160 -71
  18. package/dist/daemon-start.js +28 -18
  19. package/dist/dcode-hook.js +87 -83
  20. package/dist/dcode-sessionstart-hook.js +111 -97
  21. package/dist/dcode-stop-hook.js +160 -71
  22. package/dist/deepen.js +42 -32
  23. package/dist/devin-hook.js +87 -83
  24. package/dist/devin-sessionstart-hook.js +111 -97
  25. package/dist/devin-stop-hook.js +160 -71
  26. package/dist/droid-hook.js +87 -83
  27. package/dist/droid-sessionstart-hook.js +111 -97
  28. package/dist/droid-stop-hook.js +160 -71
  29. package/dist/dsh.js +159 -87
  30. package/dist/grok-hook.js +87 -83
  31. package/dist/grok-sessionstart-hook.js +111 -97
  32. package/dist/grok-stop-hook.js +160 -71
  33. package/dist/hindsight-seed.js +32 -22
  34. package/dist/index.js +162 -90
  35. package/dist/installer.js +308 -214
  36. package/dist/kilo.js +162 -90
  37. package/dist/mcp-server.js +41 -31
  38. package/dist/opencode2.js +161 -89
  39. package/dist/pi.js +161 -89
  40. package/dist/prime-agent.js +161 -89
  41. package/dist/qwen-hook.js +87 -83
  42. package/dist/qwen-sessionstart-hook.js +111 -97
  43. package/dist/qwen-stop-hook.js +160 -71
  44. package/dist/status.js +38 -28
  45. package/dist/zcode-hook.js +87 -83
  46. package/dist/zcode-sessionstart-hook.js +111 -97
  47. package/dist/zcode-stop-hook.js +160 -71
  48. package/package.json +1 -1
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +19 -5
package/dist/deepen.js CHANGED
@@ -3,21 +3,33 @@
3
3
  // src/deepen.ts
4
4
  import { execFileSync as execFileSync3 } from "child_process";
5
5
  import { mkdirSync as mkdirSync3, readFileSync as readFileSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
6
- import { tmpdir as tmpdir3 } from "os";
7
- import { join as join9 } from "path";
6
+ import { tmpdir as tmpdir2 } from "os";
7
+ import { join as join10 } from "path";
8
8
 
9
9
  // src/core/bank.ts
10
10
  import { existsSync } from "fs";
11
- import { homedir } from "os";
12
- import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
11
+ import { homedir as homedir2 } from "os";
12
+ import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
13
13
 
14
14
  // src/core/diag.ts
15
- import { appendFileSync as appendFileSync2 } from "fs";
15
+ import { join as join2 } from "path";
16
16
 
17
17
  // src/core/log.ts
18
- import { appendFileSync, mkdirSync } from "fs";
19
- import { tmpdir } from "os";
18
+ import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
19
+ import { homedir } from "os";
20
20
  import { dirname, join } from "path";
21
+ function logsDir() {
22
+ return join(homedir(), ".hindsight", "coding-agents-logs");
23
+ }
24
+ var LOG_MAX_BYTES = 10 * 1024 * 1024;
25
+ function appendLogLine(file, text) {
26
+ mkdirSync(dirname(file), { recursive: true, mode: 448 });
27
+ try {
28
+ if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
29
+ } catch {
30
+ }
31
+ appendFileSync(file, text, { mode: 384 });
32
+ }
21
33
  var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
22
34
  var current = ["debug", "info", "warn", "error"].find(
23
35
  (l) => l === process.env.HINDSIGHT_LOG_LEVEL
@@ -26,15 +38,13 @@ function setLogLevel(level) {
26
38
  if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
27
39
  }
28
40
  function logFilePath() {
29
- return process.env.HINDSIGHT_LOG_FILE || join(tmpdir(), "hindsight-coding-agent", "plugin.log");
41
+ return process.env.HINDSIGHT_LOG_FILE || join(logsDir(), "plugin.log");
30
42
  }
31
43
  function write(level, scope, msg, extra) {
32
44
  if (WEIGHT[level] < WEIGHT[current]) return;
33
45
  try {
34
- const file = logFilePath();
35
- mkdirSync(dirname(file), { recursive: true });
36
- appendFileSync(
37
- file,
46
+ appendLogLine(
47
+ logFilePath(),
38
48
  `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
39
49
  );
40
50
  } catch {
@@ -63,12 +73,12 @@ function describeError(value, maxChars = 200) {
63
73
 
64
74
  // src/core/diag.ts
65
75
  function diagFilePath() {
66
- return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
76
+ return process.env.HINDSIGHT_DIAG_FILE || join2(logsDir(), "diag.jsonl");
67
77
  }
68
78
  function diag(harness, event, extra = {}) {
69
79
  log.debug(harness, `diag:${event}`, extra);
70
80
  try {
71
- appendFileSync2(
81
+ appendLogLine(
72
82
  diagFilePath(),
73
83
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
74
84
  );
@@ -78,7 +88,7 @@ function diag(harness, event, extra = {}) {
78
88
 
79
89
  // src/core/git-layout.ts
80
90
  import { lstatSync, readFileSync, realpathSync } from "fs";
81
- import { dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
91
+ import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
82
92
  var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
83
93
  var ATTEMPTS = 3;
84
94
  var BACKOFF_MS = 20;
@@ -114,16 +124,16 @@ function gitDirFromPointer(text, holder) {
114
124
  return isAbsolute(target) ? target : resolve(holder, target);
115
125
  }
116
126
  function commonDirOf(gitDir) {
117
- const pointer = entryKind(join2(gitDir, "commondir")) === "file" ? readTextOrNull(join2(gitDir, "commondir"))?.trim() : null;
127
+ const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
118
128
  if (!pointer) return gitDir;
119
129
  return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
120
130
  }
121
131
  function isBare(commonDir) {
122
- const config = readTextOrNull(join2(commonDir, "config"));
132
+ const config = readTextOrNull(join3(commonDir, "config"));
123
133
  return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
124
134
  }
125
135
  function looksLikeBareRepository(directory) {
126
- return entryKind(join2(directory, "HEAD")) === "file" && entryKind(join2(directory, "objects")) === "dir" && entryKind(join2(directory, "refs")) === "dir";
136
+ return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
127
137
  }
128
138
  function canonical(path) {
129
139
  try {
@@ -140,7 +150,7 @@ function resolved(commonDir) {
140
150
  function probeOnce(directory) {
141
151
  let current2 = resolve(directory);
142
152
  for (; ; ) {
143
- const dotGit = join2(current2, ".git");
153
+ const dotGit = join3(current2, ".git");
144
154
  const kind = entryKind(dotGit);
145
155
  if (kind === "dir") {
146
156
  const layout = resolved(commonDirOf(dotGit));
@@ -254,7 +264,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
254
264
  return dirName(sessionRoot || directory);
255
265
  }
256
266
  function configuredDir(dir) {
257
- const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir(), dir.slice(1)) : dir;
267
+ const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
258
268
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
259
269
  }
260
270
  function isWithin(directory, configured) {
@@ -571,7 +581,7 @@ function codingBankManifest(overrides) {
571
581
 
572
582
  // src/core/util.ts
573
583
  import { accessSync, constants } from "fs";
574
- import { delimiter, join as join4 } from "path";
584
+ import { delimiter, join as join5 } from "path";
575
585
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
576
586
  function semverGte(version, min) {
577
587
  const parts = (v) => {
@@ -1309,17 +1319,17 @@ async function ingestChats(client, sessions, opts = {}) {
1309
1319
 
1310
1320
  // src/core/config.ts
1311
1321
  import { readFileSync as readFileSync2 } from "fs";
1312
- import { homedir as homedir2 } from "os";
1313
- import { join as join6 } from "path";
1322
+ import { homedir as homedir3 } from "os";
1323
+ import { join as join7 } from "path";
1314
1324
 
1315
1325
  // src/core/seed.ts
1316
1326
  import { spawn as realSpawn } from "child_process";
1317
- import { dirname as dirname4, join as join5 } from "path";
1327
+ import { dirname as dirname4, join as join6 } from "path";
1318
1328
  import { fileURLToPath } from "url";
1319
1329
  var DEFAULT_SEED_LIMIT = 300;
1320
1330
 
1321
1331
  // src/core/config.ts
1322
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
1332
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
1323
1333
  var DEFAULT_DAEMON_PORT = 9077;
1324
1334
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1325
1335
  function resolvePageTrigger(raw) {
@@ -1739,8 +1749,8 @@ async function syncGitLog(client, repo, opts) {
1739
1749
  import { spawn as realSpawn3 } from "child_process";
1740
1750
  import { createHash as createHash4 } from "crypto";
1741
1751
  import { existsSync as existsSync2 } from "fs";
1742
- import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
1743
- import { dirname as dirname5, join as join8 } from "path";
1752
+ import { homedir as homedir4, tmpdir } from "os";
1753
+ import { dirname as dirname5, join as join9 } from "path";
1744
1754
  import { fileURLToPath as fileURLToPath2 } from "url";
1745
1755
 
1746
1756
  // src/core/survey-lease.ts
@@ -1750,15 +1760,15 @@ import {
1750
1760
  mkdirSync as mkdirSync2,
1751
1761
  mkdtempSync,
1752
1762
  readdirSync,
1753
- renameSync,
1763
+ renameSync as renameSync2,
1754
1764
  rmdirSync,
1755
1765
  rmSync,
1756
- statSync,
1766
+ statSync as statSync2,
1757
1767
  unlinkSync,
1758
1768
  utimesSync,
1759
1769
  writeFileSync
1760
1770
  } from "fs";
1761
- import { join as join7 } from "path";
1771
+ import { join as join8 } from "path";
1762
1772
 
1763
1773
  // src/core/survey.ts
1764
1774
  var SURVEY_DOC_IDS = [
@@ -1946,8 +1956,8 @@ var log2 = (m) => {
1946
1956
  console.log(`${(/* @__PURE__ */ new Date()).toISOString()} ${m}`);
1947
1957
  log.info("deepen", m);
1948
1958
  };
1949
- var LOCK_DIR = join9(tmpdir3(), "hindsight-coding-agent");
1950
- var LOCK = join9(LOCK_DIR, `deepen-${encodeURIComponent(FINAL_BANK ?? "")}.lock`);
1959
+ var LOCK_DIR = join10(tmpdir2(), "hindsight-coding-agent");
1960
+ var LOCK = join10(LOCK_DIR, `deepen-${encodeURIComponent(FINAL_BANK ?? "")}.lock`);
1951
1961
  function acquireLock() {
1952
1962
  try {
1953
1963
  const held = JSON.parse(readFileSync4(LOCK, "utf8"));
@@ -5,16 +5,28 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
5
5
 
6
6
  // src/core/bank.ts
7
7
  import { existsSync } from "fs";
8
- import { homedir } from "os";
9
- import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
8
+ import { homedir as homedir2 } from "os";
9
+ import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
10
10
 
11
11
  // src/core/diag.ts
12
- import { appendFileSync as appendFileSync2 } from "fs";
12
+ import { join as join2 } from "path";
13
13
 
14
14
  // src/core/log.ts
15
- import { appendFileSync, mkdirSync } from "fs";
16
- import { tmpdir } from "os";
15
+ import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
16
+ import { homedir } from "os";
17
17
  import { dirname, join } from "path";
18
+ function logsDir() {
19
+ return join(homedir(), ".hindsight", "coding-agents-logs");
20
+ }
21
+ var LOG_MAX_BYTES = 10 * 1024 * 1024;
22
+ function appendLogLine(file, text) {
23
+ mkdirSync(dirname(file), { recursive: true, mode: 448 });
24
+ try {
25
+ if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
26
+ } catch {
27
+ }
28
+ appendFileSync(file, text, { mode: 384 });
29
+ }
18
30
  var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
19
31
  var current = ["debug", "info", "warn", "error"].find(
20
32
  (l) => l === process.env.HINDSIGHT_LOG_LEVEL
@@ -23,15 +35,13 @@ function setLogLevel(level) {
23
35
  if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
24
36
  }
25
37
  function logFilePath() {
26
- return process.env.HINDSIGHT_LOG_FILE || join(tmpdir(), "hindsight-coding-agent", "plugin.log");
38
+ return process.env.HINDSIGHT_LOG_FILE || join(logsDir(), "plugin.log");
27
39
  }
28
40
  function write(level, scope, msg, extra) {
29
41
  if (WEIGHT[level] < WEIGHT[current]) return;
30
42
  try {
31
- const file = logFilePath();
32
- mkdirSync(dirname(file), { recursive: true });
33
- appendFileSync(
34
- file,
43
+ appendLogLine(
44
+ logFilePath(),
35
45
  `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
36
46
  );
37
47
  } catch {
@@ -60,12 +70,12 @@ function describeError(value, maxChars = 200) {
60
70
 
61
71
  // src/core/diag.ts
62
72
  function diagFilePath() {
63
- return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
73
+ return process.env.HINDSIGHT_DIAG_FILE || join2(logsDir(), "diag.jsonl");
64
74
  }
65
75
  function diag(harness, event, extra = {}) {
66
76
  log.debug(harness, `diag:${event}`, extra);
67
77
  try {
68
- appendFileSync2(
78
+ appendLogLine(
69
79
  diagFilePath(),
70
80
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
71
81
  );
@@ -75,7 +85,7 @@ function diag(harness, event, extra = {}) {
75
85
 
76
86
  // src/core/git-layout.ts
77
87
  import { lstatSync, readFileSync, realpathSync } from "fs";
78
- import { dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
88
+ import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
79
89
  var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
80
90
  var ATTEMPTS = 3;
81
91
  var BACKOFF_MS = 20;
@@ -111,16 +121,16 @@ function gitDirFromPointer(text, holder) {
111
121
  return isAbsolute(target) ? target : resolve(holder, target);
112
122
  }
113
123
  function commonDirOf(gitDir) {
114
- const pointer = entryKind(join2(gitDir, "commondir")) === "file" ? readTextOrNull(join2(gitDir, "commondir"))?.trim() : null;
124
+ const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
115
125
  if (!pointer) return gitDir;
116
126
  return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
117
127
  }
118
128
  function isBare(commonDir) {
119
- const config = readTextOrNull(join2(commonDir, "config"));
129
+ const config = readTextOrNull(join3(commonDir, "config"));
120
130
  return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
121
131
  }
122
132
  function looksLikeBareRepository(directory) {
123
- return entryKind(join2(directory, "HEAD")) === "file" && entryKind(join2(directory, "objects")) === "dir" && entryKind(join2(directory, "refs")) === "dir";
133
+ return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
124
134
  }
125
135
  function canonical(path) {
126
136
  try {
@@ -137,7 +147,7 @@ function resolved(commonDir) {
137
147
  function probeOnce(directory) {
138
148
  let current2 = resolve(directory);
139
149
  for (; ; ) {
140
- const dotGit = join2(current2, ".git");
150
+ const dotGit = join3(current2, ".git");
141
151
  const kind = entryKind(dotGit);
142
152
  if (kind === "dir") {
143
153
  const layout = resolved(commonDirOf(dotGit));
@@ -248,7 +258,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
248
258
  return dirName(sessionRoot || directory);
249
259
  }
250
260
  function configuredDir(dir) {
251
- const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir(), dir.slice(1)) : dir;
261
+ const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
252
262
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
253
263
  }
254
264
  function isWithin(directory, configured) {
@@ -322,18 +332,18 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
322
332
 
323
333
  // src/core/config.ts
324
334
  import { readFileSync as readFileSync2 } from "fs";
325
- import { homedir as homedir2 } from "os";
326
- import { join as join6 } from "path";
335
+ import { homedir as homedir3 } from "os";
336
+ import { join as join7 } from "path";
327
337
 
328
338
  // src/core/seed.ts
329
339
  import { spawn as realSpawn } from "child_process";
330
- import { dirname as dirname4, join as join4 } from "path";
340
+ import { dirname as dirname4, join as join5 } from "path";
331
341
  import { fileURLToPath } from "url";
332
342
  var DEFAULT_SEED_LIMIT = 300;
333
343
  function startBackgroundSeed(repoDir, opts = {}) {
334
344
  try {
335
345
  const spawnFn = opts.spawn ?? realSpawn;
336
- const enginePath = opts.enginePath ?? join4(dirname4(fileURLToPath(import.meta.url)), "deepen.js");
346
+ const enginePath = opts.enginePath ?? join5(dirname4(fileURLToPath(import.meta.url)), "deepen.js");
337
347
  const limit = opts.limit ?? DEFAULT_SEED_LIMIT;
338
348
  const child = spawnFn(
339
349
  "node",
@@ -590,7 +600,7 @@ function codingBankManifest(overrides) {
590
600
 
591
601
  // src/core/util.ts
592
602
  import { accessSync, constants } from "fs";
593
- import { delimiter, join as join5 } from "path";
603
+ import { delimiter, join as join6 } from "path";
594
604
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
595
605
  function semverGte(version, min) {
596
606
  const parts = (v) => {
@@ -1262,7 +1272,7 @@ var HindsightClient = class {
1262
1272
  };
1263
1273
 
1264
1274
  // src/core/config.ts
1265
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
1275
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
1266
1276
  var DEFAULT_DAEMON_PORT = 9077;
1267
1277
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1268
1278
  function resolvePageTrigger(raw) {
@@ -1604,11 +1614,11 @@ ${toolGuide(opts)}
1604
1614
  }
1605
1615
 
1606
1616
  // src/core/session-cache.ts
1607
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
1608
- import { tmpdir as tmpdir2 } from "os";
1609
- import { dirname as dirname5, join as join7 } from "path";
1617
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, writeFileSync } from "fs";
1618
+ import { tmpdir } from "os";
1619
+ import { dirname as dirname5, join as join8 } from "path";
1610
1620
  function sessionCacheFile(harness, sessionId) {
1611
- return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.json`);
1621
+ return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.json`);
1612
1622
  }
1613
1623
  function readSessionCache(cacheFile) {
1614
1624
  try {
@@ -1622,7 +1632,7 @@ function writeFileAtomic(path, body) {
1622
1632
  const tmp = `${path}.${process.pid}.tmp`;
1623
1633
  try {
1624
1634
  writeFileSync(tmp, body);
1625
- renameSync(tmp, path);
1635
+ renameSync2(tmp, path);
1626
1636
  } catch (e) {
1627
1637
  try {
1628
1638
  rmSync(tmp, { force: true });
@@ -1638,7 +1648,7 @@ function writeSessionCache(cacheFile, cache) {
1638
1648
  }
1639
1649
  }
1640
1650
  function sessionRootFile(harness, sessionId) {
1641
- return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.root`);
1651
+ return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.root`);
1642
1652
  }
1643
1653
  function sessionRootDir(harness, sessionId, cwd) {
1644
1654
  if (!sessionId || !cwd) return cwd;
@@ -1656,9 +1666,9 @@ function sessionRootDir(harness, sessionId, cwd) {
1656
1666
  }
1657
1667
 
1658
1668
  // src/core/turn-journal.ts
1659
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
1660
- import { tmpdir as tmpdir3 } from "os";
1661
- import { dirname as dirname6, join as join8 } from "path";
1669
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync as statSync2 } from "fs";
1670
+ import { tmpdir as tmpdir2 } from "os";
1671
+ import { dirname as dirname6, join as join9 } from "path";
1662
1672
 
1663
1673
  // src/core/transcript-util.ts
1664
1674
  var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
@@ -1698,20 +1708,20 @@ function actionLine(tool, input) {
1698
1708
  // src/core/turn-journal.ts
1699
1709
  var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
1700
1710
  function journalPath(harness, sessionId) {
1701
- return join8(tmpdir3(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
1711
+ return join9(tmpdir2(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
1702
1712
  }
1703
1713
  function appendJournalTurn(path, turn) {
1704
1714
  const content = stripInjectedMemory(turn.content ?? "").trim();
1705
1715
  if (!content) return;
1706
1716
  try {
1707
- if (statSync(path).size >= JOURNAL_MAX_BYTES) return;
1717
+ if (statSync2(path).size >= JOURNAL_MAX_BYTES) return;
1708
1718
  } catch {
1709
1719
  }
1710
1720
  const last = readJournalTranscript(path).at(-1);
1711
1721
  if (last && last.role === turn.role && last.content === content) return;
1712
1722
  try {
1713
1723
  mkdirSync3(dirname6(path), { recursive: true });
1714
- appendFileSync3(
1724
+ appendFileSync2(
1715
1725
  path,
1716
1726
  JSON.stringify({
1717
1727
  role: turn.role,
@@ -1764,9 +1774,7 @@ async function reflectFallback(harness, prompt, client) {
1764
1774
  try {
1765
1775
  const hits = await client.searchKnowledgePages(query, FALLBACK_PAGE_LIMIT, remaining());
1766
1776
  diag(harness, "reflect_fallback_pages", { ms: Date.now() - t0, count: hits.length });
1767
- if (hits.length) {
1768
- return { memory: formatPageFallback(hits), source: "knowledge_pages", count: hits.length };
1769
- }
1777
+ if (hits.length) return formatPageFallback(hits);
1770
1778
  } catch (e) {
1771
1779
  diag(harness, "reflect_fallback_pages_failed", {
1772
1780
  ms: Date.now() - t0,
@@ -1783,13 +1791,7 @@ async function reflectFallback(harness, prompt, client) {
1783
1791
  ms: Date.now() - t0,
1784
1792
  count: observations.length
1785
1793
  });
1786
- if (observations.length) {
1787
- return {
1788
- memory: formatObservationFallback(observations),
1789
- source: "observations",
1790
- count: observations.length
1791
- };
1792
- }
1794
+ if (observations.length) return formatObservationFallback(observations);
1793
1795
  } catch (e) {
1794
1796
  diag(harness, "reflect_fallback_observations_failed", {
1795
1797
  ms: Date.now() - t0,
@@ -1845,7 +1847,7 @@ async function buildHookOutput(args) {
1845
1847
  });
1846
1848
  if (e instanceof ReflectError && e.fallbackEligible) {
1847
1849
  fallback = await reflectFallback(harness, prompt, client);
1848
- if (fallback) reflectAnswer = fallback.memory;
1850
+ if (fallback) reflectAnswer = fallback;
1849
1851
  }
1850
1852
  }
1851
1853
  }
@@ -1881,8 +1883,6 @@ async function buildHookOutput(args) {
1881
1883
  const kept = blocks.filter(Boolean);
1882
1884
  let notice;
1883
1885
  if (fallback) {
1884
- const what = fallback.source === "knowledge_pages" ? "knowledge page" : "observation";
1885
- notice = `${brandWord()} \xB7 reflect unavailable \u2014 fell back to ${fallback.count} ${what}${fallback.count === 1 ? "" : "s"} (see ${diagFilePath()})`;
1886
1886
  } else if (reflectRanThisTurn && reflectAnswer) {
1887
1887
  const q = prompt.replace(/\s+/g, " ").trim();
1888
1888
  const excerpt = q.length > 48 ? `${q.slice(0, 48)}\u2026` : q;
@@ -1946,7 +1946,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
1946
1946
  }
1947
1947
 
1948
1948
  // src/core/retain-hook.ts
1949
- import { readFileSync as readFileSync6 } from "fs";
1949
+ import { readFileSync as readFileSync7 } from "fs";
1950
1950
 
1951
1951
  // src/core/retain-cursor.ts
1952
1952
  import { createHash as createHash2 } from "crypto";
@@ -1958,14 +1958,14 @@ import { createHash as createHash3 } from "crypto";
1958
1958
 
1959
1959
  // src/core/daemon.ts
1960
1960
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1961
- import { dirname as dirname7, join as join9 } from "path";
1961
+ import { dirname as dirname7, join as join10 } from "path";
1962
1962
  import { fileURLToPath as fileURLToPath2 } from "url";
1963
1963
 
1964
1964
  // src/core/retain-stamp.ts
1965
1965
  import { basename as basename2 } from "path";
1966
1966
 
1967
1967
  // src/core/jsonl.ts
1968
- import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1968
+ import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
1969
1969
  import { StringDecoder } from "string_decoder";
1970
1970
  var CHUNK_BYTES = 64 * 1024;
1971
1971
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1973,7 +1973,7 @@ function readJsonlTail(path, opts) {
1973
1973
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1974
1974
  let size;
1975
1975
  try {
1976
- size = statSync2(path).size;
1976
+ size = statSync3(path).size;
1977
1977
  } catch {
1978
1978
  return { lines: emptyLines(), skippedBytes: 0 };
1979
1979
  }
@@ -2025,8 +2025,12 @@ function* streamLines(path, start) {
2025
2025
  }
2026
2026
  }
2027
2027
 
2028
+ // src/core/usage.ts
2029
+ import { readFileSync as readFileSync6 } from "fs";
2030
+ import { join as join11 } from "path";
2031
+
2028
2032
  // src/core/session-start.ts
2029
- import { readFileSync as readFileSync10 } from "fs";
2033
+ import { readFileSync as readFileSync11 } from "fs";
2030
2034
 
2031
2035
  // src/core/git.ts
2032
2036
  import { execFileSync as execFileSync2 } from "child_process";
@@ -2039,8 +2043,8 @@ import { execFileSync as execFileSync3 } from "child_process";
2039
2043
  import { spawn as realSpawn4 } from "child_process";
2040
2044
  import { createHash as createHash4 } from "crypto";
2041
2045
  import { existsSync as existsSync3 } from "fs";
2042
- import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
2043
- import { dirname as dirname8, join as join11 } from "path";
2046
+ import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2047
+ import { dirname as dirname8, join as join13 } from "path";
2044
2048
  import { fileURLToPath as fileURLToPath3 } from "url";
2045
2049
 
2046
2050
  // src/core/survey-lease.ts
@@ -2050,42 +2054,42 @@ import {
2050
2054
  mkdirSync as mkdirSync4,
2051
2055
  mkdtempSync,
2052
2056
  readdirSync,
2053
- renameSync as renameSync2,
2057
+ renameSync as renameSync3,
2054
2058
  rmdirSync,
2055
2059
  rmSync as rmSync2,
2056
- statSync as statSync3,
2060
+ statSync as statSync4,
2057
2061
  unlinkSync,
2058
2062
  utimesSync,
2059
2063
  writeFileSync as writeFileSync2
2060
2064
  } from "fs";
2061
- import { join as join10 } from "path";
2065
+ import { join as join12 } from "path";
2062
2066
 
2063
2067
  // src/core/auto-update.ts
2064
2068
  import { spawn as realSpawn5 } from "child_process";
2065
2069
  import {
2066
2070
  existsSync as existsSync4,
2067
2071
  mkdirSync as mkdirSync5,
2068
- readFileSync as readFileSync7,
2072
+ readFileSync as readFileSync8,
2069
2073
  realpathSync as realpathSync2,
2070
2074
  unlinkSync as unlinkSync2,
2071
2075
  writeFileSync as writeFileSync3
2072
2076
  } from "fs";
2073
- import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
2074
- import { dirname as dirname9, join as join12 } from "path";
2077
+ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2078
+ import { dirname as dirname9, join as join14 } from "path";
2075
2079
  import { fileURLToPath as fileURLToPath4 } from "url";
2076
2080
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2077
2081
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2078
2082
 
2079
2083
  // src/core/skill-sync.ts
2080
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
2081
- import { homedir as homedir5 } from "os";
2082
- import { dirname as dirname10, join as join13 } from "path";
2084
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
2085
+ import { homedir as homedir6 } from "os";
2086
+ import { dirname as dirname10, join as join15 } from "path";
2083
2087
  import { fileURLToPath as fileURLToPath5 } from "url";
2084
2088
 
2085
2089
  // src/core/legacy.ts
2086
- import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
2087
- import { homedir as homedir6 } from "os";
2088
- import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
2090
+ import { existsSync as existsSync6, readFileSync as readFileSync10 } from "fs";
2091
+ import { homedir as homedir7 } from "os";
2092
+ import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
2089
2093
 
2090
2094
  // src/core/transcript-codex.ts
2091
2095
  function isSyntheticUserText(text) {
@@ -2217,19 +2221,19 @@ function readCopilotTranscript(path) {
2217
2221
  }
2218
2222
 
2219
2223
  // src/core/transcript-grok.ts
2220
- import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
2221
- import { homedir as homedir7 } from "os";
2222
- import { join as join15 } from "path";
2224
+ import { existsSync as existsSync7, readFileSync as readFileSync12, readdirSync as readdirSync2 } from "fs";
2225
+ import { homedir as homedir8 } from "os";
2226
+ import { join as join17 } from "path";
2223
2227
  var CHAT_HISTORY = "chat_history.jsonl";
2224
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
2225
- const sessionsDir = join15(grokHome, "sessions");
2226
- const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2228
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join17(homedir8(), ".grok")) {
2229
+ const sessionsDir = join17(grokHome, "sessions");
2230
+ const direct = join17(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2227
2231
  if (existsSync7(direct)) return direct;
2228
2232
  try {
2229
2233
  for (const candidate of readdirSync2(sessionsDir)) {
2230
- const directory = join15(sessionsDir, candidate);
2231
- if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
2232
- return join15(directory, sessionId, CHAT_HISTORY);
2234
+ const directory = join17(sessionsDir, candidate);
2235
+ if (readFileSync12(join17(directory, ".cwd"), "utf8").trim() === cwd) {
2236
+ return join17(directory, sessionId, CHAT_HISTORY);
2233
2237
  }
2234
2238
  }
2235
2239
  } catch {
@@ -2266,10 +2270,10 @@ function readGrokTranscript(path) {
2266
2270
  // src/core/transcript-devin.ts
2267
2271
  import { existsSync as existsSync8 } from "fs";
2268
2272
  import { createRequire } from "module";
2269
- import { homedir as homedir8 } from "os";
2270
- import { join as join16 } from "path";
2271
- function devinSessionDb(home = homedir8()) {
2272
- return join16(home, ".local", "share", "devin", "cli", "sessions.db");
2273
+ import { homedir as homedir9 } from "os";
2274
+ import { join as join18 } from "path";
2275
+ function devinSessionDb(home = homedir9()) {
2276
+ return join18(home, ".local", "share", "devin", "cli", "sessions.db");
2273
2277
  }
2274
2278
  function parseDevinMessages(nodes) {
2275
2279
  const messages = /* @__PURE__ */ new Map();
@@ -2579,7 +2583,7 @@ function readDroidTranscript(path) {
2579
2583
  }
2580
2584
 
2581
2585
  // src/core/transcript-zcode.ts
2582
- import { readFileSync as readFileSync12 } from "fs";
2586
+ import { readFileSync as readFileSync13 } from "fs";
2583
2587
  function messageText2(content) {
2584
2588
  if (typeof content === "string") return content.trim();
2585
2589
  if (!Array.isArray(content)) return "";
@@ -2589,7 +2593,7 @@ function readZcodeTranscript(path) {
2589
2593
  if (!path) return [];
2590
2594
  let body;
2591
2595
  try {
2592
- body = readFileSync12(path, "utf8");
2596
+ body = readFileSync13(path, "utf8");
2593
2597
  } catch {
2594
2598
  return [];
2595
2599
  }