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

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 +84 -70
  3. package/dist/antigravity-statusline.js +32 -22
  4. package/dist/antigravity-stop-hook.js +160 -71
  5. package/dist/claude-hook.js +84 -70
  6. package/dist/claude-sessionstart-hook.js +111 -97
  7. package/dist/claude-stop-hook.js +160 -71
  8. package/dist/cline.js +158 -75
  9. package/dist/codex-hook.js +84 -70
  10. package/dist/codex-sessionstart-hook.js +111 -97
  11. package/dist/codex-stop-hook.js +160 -71
  12. package/dist/copilot-hook.js +84 -70
  13. package/dist/copilot-sessionstart-hook.js +111 -97
  14. package/dist/copilot-stop-hook.js +160 -71
  15. package/dist/cursor-hook.js +84 -70
  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 +84 -70
  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 +84 -70
  24. package/dist/devin-sessionstart-hook.js +111 -97
  25. package/dist/devin-stop-hook.js +160 -71
  26. package/dist/droid-hook.js +84 -70
  27. package/dist/droid-sessionstart-hook.js +111 -97
  28. package/dist/droid-stop-hook.js +160 -71
  29. package/dist/dsh.js +156 -74
  30. package/dist/grok-hook.js +84 -70
  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 +159 -77
  35. package/dist/installer.js +308 -214
  36. package/dist/kilo.js +159 -77
  37. package/dist/mcp-server.js +41 -31
  38. package/dist/opencode2.js +158 -76
  39. package/dist/pi.js +158 -76
  40. package/dist/prime-agent.js +158 -76
  41. package/dist/qwen-hook.js +84 -70
  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 +84 -70
  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/README.md CHANGED
@@ -23,6 +23,7 @@ npx @vectorize-io/hindsight-coding-agents install all # every detected
23
23
  npx @vectorize-io/hindsight-coding-agents install claude-code # or just one
24
24
  npx @vectorize-io/hindsight-coding-agents uninstall all # removes exactly what install added
25
25
  npx @vectorize-io/hindsight-coding-agents update # refresh the runtime only, no rewiring
26
+ npx @vectorize-io/hindsight-coding-agents stats # how often each agent uses Hindsight
26
27
  ```
27
28
 
28
29
  `install` takes an explicit target — `all`, or one or more harness names. A bare
@@ -439,8 +440,8 @@ as `HINDSIGHT_MAX_PARALLEL_RETAINS` for containers and CI.
439
440
 
440
441
  `HINDSIGHT_CONFIG` moves the file itself — point it at another path for a container or a test
441
442
  harness where `$HOME` is not the right anchor. It is still exactly one file; only its location
442
- changes. (The other variables that are not settings are `HINDSIGHT_LOG_FILE`, `HINDSIGHT_DIAG_FILE`
443
- and `HINDSIGHT_LOG_LEVEL` — see [Diagnostics & logging](#diagnostics--logging).)
443
+ changes. (The other variables that are not settings are `HINDSIGHT_LOG_FILE`, `HINDSIGHT_DIAG_FILE`,
444
+ `HINDSIGHT_USAGE_FILE` and `HINDSIGHT_LOG_LEVEL` — see [Diagnostics & logging](#diagnostics--logging).)
444
445
 
445
446
  ### When a change takes effect
446
447
 
@@ -822,16 +823,18 @@ drops the markers along with the contributor-only sections.
822
823
 
823
824
  ## Diagnostics & logging
824
825
 
825
- Two files, two audiences:
826
+ All logs live in `~/.hindsight/coding-agents-logs/` (owner-only). Each file rotates to `<file>.1`
827
+ at 10 MB.
826
828
 
827
- **Leveled plugin log** (humans debugging): `$TMPDIR/hindsight-coding-agent/plugin.log` (override
829
+ **Leveled plugin log** (humans debugging): `~/.hindsight/coding-agents-logs/plugin.log` (override
828
830
  `HINDSIGHT_LOG_FILE`) — timestamped `LEVEL [scope] message` lines from every component, including
829
831
  the ingestion engine. Level defaults to `info`; set `"logLevel": "debug"` in config or
830
832
  `HINDSIGHT_LOG_LEVEL=debug` for ad-hoc debugging (at `debug`, every diag event below is mirrored
831
833
  here too, so one file tells the whole story).
832
834
 
833
835
  **Structured diag events** (machines/harnesses): every reflect and page-fetch outcome is appended
834
- as a JSON line to `/tmp/hindsight-plugin.log` (override with `HINDSIGHT_DIAG_FILE`):
836
+ as a JSON line to `~/.hindsight/coding-agents-logs/diag.jsonl` (override with
837
+ `HINDSIGHT_DIAG_FILE`):
835
838
 
836
839
  ```json
837
840
  {
@@ -851,6 +854,17 @@ bank's observations: `reflect_fallback_pages` / `reflect_fallback_observations`
851
854
  step returned (`*_failed` when it errored). Seed starts are logged as
852
855
  `seed_started`.
853
856
 
857
+ **Tool usage** (is the agent using Hindsight?): one JSON line per finished user turn in
858
+ `~/.hindsight/coding-agents-logs/usage.jsonl` (override `HINDSIGHT_USAGE_FILE`) — the `hindsight_*`
859
+ tools the agent called during that turn, and whether its reply credited Hindsight memory ("From
860
+ Hindsight memory"). The credit rate counts only turns that called a retrieval tool (search, list,
861
+ read, reflect); saving a document is not expected to be credited. Recorded when the session is written back, so a scope with
862
+ `retainSessions: false` records none. It never leaves your machine. Summarize it per agent with:
863
+
864
+ ```bash
865
+ npx @vectorize-io/hindsight-coding-agents stats
866
+ ```
867
+
854
868
  ### Is the memory ready yet?
855
869
 
856
870
  `hindsight_sync_status` — the agent-facing tool, `dist/status.js` for scripts — answers exactly
@@ -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,
@@ -1946,7 +1956,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
1946
1956
  }
1947
1957
 
1948
1958
  // src/core/retain-hook.ts
1949
- import { readFileSync as readFileSync6 } from "fs";
1959
+ import { readFileSync as readFileSync7 } from "fs";
1950
1960
 
1951
1961
  // src/core/retain-cursor.ts
1952
1962
  import { createHash as createHash2 } from "crypto";
@@ -1958,14 +1968,14 @@ import { createHash as createHash3 } from "crypto";
1958
1968
 
1959
1969
  // src/core/daemon.ts
1960
1970
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1961
- import { dirname as dirname7, join as join9 } from "path";
1971
+ import { dirname as dirname7, join as join10 } from "path";
1962
1972
  import { fileURLToPath as fileURLToPath2 } from "url";
1963
1973
 
1964
1974
  // src/core/retain-stamp.ts
1965
1975
  import { basename as basename2 } from "path";
1966
1976
 
1967
1977
  // src/core/jsonl.ts
1968
- import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1978
+ import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
1969
1979
  import { StringDecoder } from "string_decoder";
1970
1980
  var CHUNK_BYTES = 64 * 1024;
1971
1981
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1973,7 +1983,7 @@ function readJsonlTail(path, opts) {
1973
1983
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1974
1984
  let size;
1975
1985
  try {
1976
- size = statSync2(path).size;
1986
+ size = statSync3(path).size;
1977
1987
  } catch {
1978
1988
  return { lines: emptyLines(), skippedBytes: 0 };
1979
1989
  }
@@ -2025,8 +2035,12 @@ function* streamLines(path, start) {
2025
2035
  }
2026
2036
  }
2027
2037
 
2038
+ // src/core/usage.ts
2039
+ import { readFileSync as readFileSync6 } from "fs";
2040
+ import { join as join11 } from "path";
2041
+
2028
2042
  // src/core/session-start.ts
2029
- import { readFileSync as readFileSync10 } from "fs";
2043
+ import { readFileSync as readFileSync11 } from "fs";
2030
2044
 
2031
2045
  // src/core/git.ts
2032
2046
  import { execFileSync as execFileSync2 } from "child_process";
@@ -2039,8 +2053,8 @@ import { execFileSync as execFileSync3 } from "child_process";
2039
2053
  import { spawn as realSpawn4 } from "child_process";
2040
2054
  import { createHash as createHash4 } from "crypto";
2041
2055
  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";
2056
+ import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2057
+ import { dirname as dirname8, join as join13 } from "path";
2044
2058
  import { fileURLToPath as fileURLToPath3 } from "url";
2045
2059
 
2046
2060
  // src/core/survey-lease.ts
@@ -2050,42 +2064,42 @@ import {
2050
2064
  mkdirSync as mkdirSync4,
2051
2065
  mkdtempSync,
2052
2066
  readdirSync,
2053
- renameSync as renameSync2,
2067
+ renameSync as renameSync3,
2054
2068
  rmdirSync,
2055
2069
  rmSync as rmSync2,
2056
- statSync as statSync3,
2070
+ statSync as statSync4,
2057
2071
  unlinkSync,
2058
2072
  utimesSync,
2059
2073
  writeFileSync as writeFileSync2
2060
2074
  } from "fs";
2061
- import { join as join10 } from "path";
2075
+ import { join as join12 } from "path";
2062
2076
 
2063
2077
  // src/core/auto-update.ts
2064
2078
  import { spawn as realSpawn5 } from "child_process";
2065
2079
  import {
2066
2080
  existsSync as existsSync4,
2067
2081
  mkdirSync as mkdirSync5,
2068
- readFileSync as readFileSync7,
2082
+ readFileSync as readFileSync8,
2069
2083
  realpathSync as realpathSync2,
2070
2084
  unlinkSync as unlinkSync2,
2071
2085
  writeFileSync as writeFileSync3
2072
2086
  } from "fs";
2073
- import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
2074
- import { dirname as dirname9, join as join12 } from "path";
2087
+ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2088
+ import { dirname as dirname9, join as join14 } from "path";
2075
2089
  import { fileURLToPath as fileURLToPath4 } from "url";
2076
2090
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2077
2091
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2078
2092
 
2079
2093
  // 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";
2094
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
2095
+ import { homedir as homedir6 } from "os";
2096
+ import { dirname as dirname10, join as join15 } from "path";
2083
2097
  import { fileURLToPath as fileURLToPath5 } from "url";
2084
2098
 
2085
2099
  // 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";
2100
+ import { existsSync as existsSync6, readFileSync as readFileSync10 } from "fs";
2101
+ import { homedir as homedir7 } from "os";
2102
+ import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
2089
2103
 
2090
2104
  // src/core/transcript-codex.ts
2091
2105
  function isSyntheticUserText(text) {
@@ -2217,19 +2231,19 @@ function readCopilotTranscript(path) {
2217
2231
  }
2218
2232
 
2219
2233
  // 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";
2234
+ import { existsSync as existsSync7, readFileSync as readFileSync12, readdirSync as readdirSync2 } from "fs";
2235
+ import { homedir as homedir8 } from "os";
2236
+ import { join as join17 } from "path";
2223
2237
  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);
2238
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join17(homedir8(), ".grok")) {
2239
+ const sessionsDir = join17(grokHome, "sessions");
2240
+ const direct = join17(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2227
2241
  if (existsSync7(direct)) return direct;
2228
2242
  try {
2229
2243
  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);
2244
+ const directory = join17(sessionsDir, candidate);
2245
+ if (readFileSync12(join17(directory, ".cwd"), "utf8").trim() === cwd) {
2246
+ return join17(directory, sessionId, CHAT_HISTORY);
2233
2247
  }
2234
2248
  }
2235
2249
  } catch {
@@ -2266,10 +2280,10 @@ function readGrokTranscript(path) {
2266
2280
  // src/core/transcript-devin.ts
2267
2281
  import { existsSync as existsSync8 } from "fs";
2268
2282
  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");
2283
+ import { homedir as homedir9 } from "os";
2284
+ import { join as join18 } from "path";
2285
+ function devinSessionDb(home = homedir9()) {
2286
+ return join18(home, ".local", "share", "devin", "cli", "sessions.db");
2273
2287
  }
2274
2288
  function parseDevinMessages(nodes) {
2275
2289
  const messages = /* @__PURE__ */ new Map();
@@ -2579,7 +2593,7 @@ function readDroidTranscript(path) {
2579
2593
  }
2580
2594
 
2581
2595
  // src/core/transcript-zcode.ts
2582
- import { readFileSync as readFileSync12 } from "fs";
2596
+ import { readFileSync as readFileSync13 } from "fs";
2583
2597
  function messageText2(content) {
2584
2598
  if (typeof content === "string") return content.trim();
2585
2599
  if (!Array.isArray(content)) return "";
@@ -2589,7 +2603,7 @@ function readZcodeTranscript(path) {
2589
2603
  if (!path) return [];
2590
2604
  let body;
2591
2605
  try {
2592
- body = readFileSync12(path, "utf8");
2606
+ body = readFileSync13(path, "utf8");
2593
2607
  } catch {
2594
2608
  return [];
2595
2609
  }
@@ -2,8 +2,8 @@
2
2
 
3
3
  // src/core/config.ts
4
4
  import { readFileSync as readFileSync2 } from "fs";
5
- import { homedir as homedir2 } from "os";
6
- import { join as join6 } from "path";
5
+ import { homedir as homedir3 } from "os";
6
+ import { join as join7 } from "path";
7
7
 
8
8
  // src/core/seed.ts
9
9
  import { spawn as realSpawn } from "child_process";
@@ -13,30 +13,40 @@ var DEFAULT_SEED_LIMIT = 300;
13
13
 
14
14
  // src/core/bank.ts
15
15
  import { existsSync } from "fs";
16
- import { homedir } from "os";
17
- import { basename, dirname as dirname4, join as join4, normalize, sep } from "path";
16
+ import { homedir as homedir2 } from "os";
17
+ import { basename, dirname as dirname4, join as join5, normalize, sep } from "path";
18
18
 
19
19
  // src/core/diag.ts
20
- import { appendFileSync as appendFileSync2 } from "fs";
20
+ import { join as join3 } from "path";
21
21
 
22
22
  // src/core/log.ts
23
- import { appendFileSync, mkdirSync } from "fs";
24
- import { tmpdir } from "os";
23
+ import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
24
+ import { homedir } from "os";
25
25
  import { dirname as dirname2, join as join2 } from "path";
26
+ function logsDir() {
27
+ return join2(homedir(), ".hindsight", "coding-agents-logs");
28
+ }
29
+ var LOG_MAX_BYTES = 10 * 1024 * 1024;
30
+ function appendLogLine(file, text) {
31
+ mkdirSync(dirname2(file), { recursive: true, mode: 448 });
32
+ try {
33
+ if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
34
+ } catch {
35
+ }
36
+ appendFileSync(file, text, { mode: 384 });
37
+ }
26
38
  var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
27
39
  var current = ["debug", "info", "warn", "error"].find(
28
40
  (l) => l === process.env.HINDSIGHT_LOG_LEVEL
29
41
  ) ?? "info";
30
42
  function logFilePath() {
31
- return process.env.HINDSIGHT_LOG_FILE || join2(tmpdir(), "hindsight-coding-agent", "plugin.log");
43
+ return process.env.HINDSIGHT_LOG_FILE || join2(logsDir(), "plugin.log");
32
44
  }
33
45
  function write(level, scope, msg, extra) {
34
46
  if (WEIGHT[level] < WEIGHT[current]) return;
35
47
  try {
36
- const file = logFilePath();
37
- mkdirSync(dirname2(file), { recursive: true });
38
- appendFileSync(
39
- file,
48
+ appendLogLine(
49
+ logFilePath(),
40
50
  `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
41
51
  );
42
52
  } catch {
@@ -51,12 +61,12 @@ var log = {
51
61
 
52
62
  // src/core/diag.ts
53
63
  function diagFilePath() {
54
- return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
64
+ return process.env.HINDSIGHT_DIAG_FILE || join3(logsDir(), "diag.jsonl");
55
65
  }
56
66
  function diag(harness, event, extra = {}) {
57
67
  log.debug(harness, `diag:${event}`, extra);
58
68
  try {
59
- appendFileSync2(
69
+ appendLogLine(
60
70
  diagFilePath(),
61
71
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
62
72
  );
@@ -66,7 +76,7 @@ function diag(harness, event, extra = {}) {
66
76
 
67
77
  // src/core/git-layout.ts
68
78
  import { lstatSync, readFileSync, realpathSync } from "fs";
69
- import { dirname as dirname3, isAbsolute, join as join3, resolve } from "path";
79
+ import { dirname as dirname3, isAbsolute, join as join4, resolve } from "path";
70
80
  var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
71
81
  var ATTEMPTS = 3;
72
82
  var BACKOFF_MS = 20;
@@ -102,16 +112,16 @@ function gitDirFromPointer(text, holder) {
102
112
  return isAbsolute(target) ? target : resolve(holder, target);
103
113
  }
104
114
  function commonDirOf(gitDir) {
105
- const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
115
+ const pointer = entryKind(join4(gitDir, "commondir")) === "file" ? readTextOrNull(join4(gitDir, "commondir"))?.trim() : null;
106
116
  if (!pointer) return gitDir;
107
117
  return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
108
118
  }
109
119
  function isBare(commonDir) {
110
- const config = readTextOrNull(join3(commonDir, "config"));
120
+ const config = readTextOrNull(join4(commonDir, "config"));
111
121
  return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
112
122
  }
113
123
  function looksLikeBareRepository(directory) {
114
- return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
124
+ return entryKind(join4(directory, "HEAD")) === "file" && entryKind(join4(directory, "objects")) === "dir" && entryKind(join4(directory, "refs")) === "dir";
115
125
  }
116
126
  function canonical(path) {
117
127
  try {
@@ -128,7 +138,7 @@ function resolved(commonDir) {
128
138
  function probeOnce(directory) {
129
139
  let current2 = resolve(directory);
130
140
  for (; ; ) {
131
- const dotGit = join3(current2, ".git");
141
+ const dotGit = join4(current2, ".git");
132
142
  const kind = entryKind(dotGit);
133
143
  if (kind === "dir") {
134
144
  const layout = resolved(commonDirOf(dotGit));
@@ -239,7 +249,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
239
249
  return dirName(sessionRoot || directory);
240
250
  }
241
251
  function configuredDir(dir) {
242
- const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir(), dir.slice(1)) : dir;
252
+ const expanded = dir === "~" || dir.startsWith("~/") ? join5(homedir2(), dir.slice(1)) : dir;
243
253
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
244
254
  }
245
255
  function isWithin(directory, configured) {
@@ -347,7 +357,7 @@ function parseHashedCron(cron) {
347
357
 
348
358
  // src/core/util.ts
349
359
  import { accessSync, constants } from "fs";
350
- import { delimiter, join as join5 } from "path";
360
+ import { delimiter, join as join6 } from "path";
351
361
 
352
362
  // src/core/hindsight.ts
353
363
  var DEFAULT_OBSERVATION_SCOPES = "shared";
@@ -355,7 +365,7 @@ var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
355
365
  var RETRY_AFTER_CEILING_MS = 60 * 1e3;
356
366
 
357
367
  // src/core/config.ts
358
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
368
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
359
369
  var DEFAULT_DAEMON_PORT = 9077;
360
370
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
361
371
  function resolvePageTrigger(raw) {