@vectorize-io/hindsight-coding-agents 0.5.4 → 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 +24 -7
  2. package/dist/antigravity-hook.js +205 -81
  3. package/dist/antigravity-statusline.js +32 -22
  4. package/dist/antigravity-stop-hook.js +216 -79
  5. package/dist/claude-hook.js +205 -81
  6. package/dist/claude-sessionstart-hook.js +167 -105
  7. package/dist/claude-stop-hook.js +216 -79
  8. package/dist/cline.js +279 -86
  9. package/dist/codex-hook.js +205 -81
  10. package/dist/codex-sessionstart-hook.js +167 -105
  11. package/dist/codex-stop-hook.js +216 -79
  12. package/dist/copilot-hook.js +205 -81
  13. package/dist/copilot-sessionstart-hook.js +167 -105
  14. package/dist/copilot-stop-hook.js +216 -79
  15. package/dist/cursor-hook.js +205 -81
  16. package/dist/cursor-sessionstart-hook.js +167 -105
  17. package/dist/cursor-stop-hook.js +216 -79
  18. package/dist/daemon-start.js +28 -18
  19. package/dist/dcode-hook.js +205 -81
  20. package/dist/dcode-sessionstart-hook.js +167 -105
  21. package/dist/dcode-stop-hook.js +216 -79
  22. package/dist/deepen.js +98 -40
  23. package/dist/devin-hook.js +205 -81
  24. package/dist/devin-sessionstart-hook.js +167 -105
  25. package/dist/devin-stop-hook.js +216 -79
  26. package/dist/droid-hook.js +205 -81
  27. package/dist/droid-sessionstart-hook.js +167 -105
  28. package/dist/droid-stop-hook.js +216 -79
  29. package/dist/dsh.js +277 -85
  30. package/dist/grok-hook.js +205 -81
  31. package/dist/grok-sessionstart-hook.js +167 -105
  32. package/dist/grok-stop-hook.js +216 -79
  33. package/dist/hindsight-seed.js +32 -22
  34. package/dist/index.js +280 -88
  35. package/dist/installer.js +308 -214
  36. package/dist/kilo.js +280 -88
  37. package/dist/mcp-server.js +97 -39
  38. package/dist/opencode2.js +279 -87
  39. package/dist/pi.js +279 -87
  40. package/dist/prime-agent.js +279 -87
  41. package/dist/qwen-hook.js +205 -81
  42. package/dist/qwen-sessionstart-hook.js +167 -105
  43. package/dist/qwen-stop-hook.js +216 -79
  44. package/dist/status.js +94 -36
  45. package/dist/zcode-hook.js +205 -81
  46. package/dist/zcode-sessionstart-hook.js +167 -105
  47. package/dist/zcode-stop-hook.js +216 -79
  48. package/package.json +1 -1
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +24 -7
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) => {
@@ -634,6 +644,22 @@ var KnowledgePagesUnavailableError = class extends Error {
634
644
  }
635
645
  };
636
646
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
647
+ var ReflectError = class extends Error {
648
+ constructor(message, status, timedOut, options) {
649
+ super(message, options);
650
+ this.status = status;
651
+ this.timedOut = timedOut;
652
+ this.name = "ReflectError";
653
+ }
654
+ status;
655
+ timedOut;
656
+ /** A timeout or a 5xx means reflect's synthesis (the slow LLM path) broke, while the cheap
657
+ * retrieval endpoints may still answer — worth falling back. A 4xx will fail the same way on
658
+ * every endpoint (auth, missing bank), so it is not. */
659
+ get fallbackEligible() {
660
+ return this.timedOut || this.status !== void 0 && this.status >= 500;
661
+ }
662
+ };
637
663
  var DEFAULT_MAX_PARALLEL_RETAINS = 10;
638
664
  var POLL_CYCLE_MS = 5e3;
639
665
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
@@ -717,11 +743,11 @@ var HindsightClient = class {
717
743
  return `${this.apiUrl}/v1/default/banks/${encodeURIComponent(this.bank)}${suffix}`;
718
744
  }
719
745
  /** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
720
- async req(method, url, body, tolerate = []) {
746
+ async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
721
747
  const r = await this.fetchWithAuth(url, {
722
748
  method,
723
749
  body: body ? JSON.stringify(body) : void 0,
724
- signal: AbortSignal.timeout(15e3)
750
+ signal: AbortSignal.timeout(timeoutMs)
725
751
  });
726
752
  if (r.status === 429 && !tolerate.includes(429))
727
753
  throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
@@ -914,7 +940,7 @@ var HindsightClient = class {
914
940
  /**
915
941
  * Reflect: synthesized, root-cause answer over the bank. Bounded so a slow server never hangs a
916
942
  * caller — but `timeoutMs` is REQUIRED, deliberately: the right deadline differs by an order of
917
- * magnitude between the automatic hook (25s, to fit the host's window) and the agent-invoked
943
+ * magnitude between the automatic hook (20s, to fit the host's window) and the agent-invoked
918
944
  * tool (minutes, on a populated bank). This used to default to 120s, which silently overrode the
919
945
  * tool's configured window and aborted every high-budget synthesis mid-flight (#3590).
920
946
  */
@@ -928,19 +954,45 @@ var HindsightClient = class {
928
954
  signal: ctrl.signal
929
955
  });
930
956
  if (!resp.ok)
931
- throw new Error(
932
- `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
957
+ throw new ReflectError(
958
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`,
959
+ resp.status,
960
+ false
933
961
  );
934
962
  const data = await resp.json();
935
963
  return (data.text || "").trim();
936
964
  } catch (e) {
937
965
  if (ctrl.signal.aborted)
938
- throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
966
+ throw new ReflectError(`reflect timed out after ${opts.timeoutMs}ms`, void 0, true, {
967
+ cause: e
968
+ });
939
969
  throw e;
940
970
  } finally {
941
971
  clearTimeout(timer);
942
972
  }
943
973
  }
974
+ /**
975
+ * Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
976
+ * when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
977
+ */
978
+ async recallObservations(query, opts) {
979
+ const r = await this.req(
980
+ "POST",
981
+ this.bankUrl("/memories/recall"),
982
+ {
983
+ query,
984
+ types: ["observation"],
985
+ budget: "low",
986
+ max_tokens: opts.maxTokens,
987
+ include: { entities: null }
988
+ },
989
+ [],
990
+ opts.timeoutMs
991
+ );
992
+ if (r.status === 404) return [];
993
+ const j = await r.json();
994
+ return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
995
+ }
944
996
  /**
945
997
  * The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
946
998
  * queries and staleness but NOT synthesized content, so it is cheap enough to poll.
@@ -1005,10 +1057,16 @@ var HindsightClient = class {
1005
1057
  /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
1006
1058
  * Returns page-level hits with a relevance snippet — the real search behind
1007
1059
  * hindsight_search_knowledge_pages. */
1008
- async searchKnowledgePages(query, limit = 3) {
1060
+ async searchKnowledgePages(query, limit = 3, timeoutMs) {
1009
1061
  if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1010
1062
  const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
1011
- const r = await this.req("GET", this.bankUrl(`/knowledge-base/search${q}`));
1063
+ const r = await this.req(
1064
+ "GET",
1065
+ this.bankUrl(`/knowledge-base/search${q}`),
1066
+ void 0,
1067
+ [],
1068
+ timeoutMs
1069
+ );
1012
1070
  const j = await r.json();
1013
1071
  return (j.results ?? []).map((x) => ({
1014
1072
  id: x.id,
@@ -1261,17 +1319,17 @@ async function ingestChats(client, sessions, opts = {}) {
1261
1319
 
1262
1320
  // src/core/config.ts
1263
1321
  import { readFileSync as readFileSync2 } from "fs";
1264
- import { homedir as homedir2 } from "os";
1265
- import { join as join6 } from "path";
1322
+ import { homedir as homedir3 } from "os";
1323
+ import { join as join7 } from "path";
1266
1324
 
1267
1325
  // src/core/seed.ts
1268
1326
  import { spawn as realSpawn } from "child_process";
1269
- import { dirname as dirname4, join as join5 } from "path";
1327
+ import { dirname as dirname4, join as join6 } from "path";
1270
1328
  import { fileURLToPath } from "url";
1271
1329
  var DEFAULT_SEED_LIMIT = 300;
1272
1330
 
1273
1331
  // src/core/config.ts
1274
- 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");
1275
1333
  var DEFAULT_DAEMON_PORT = 9077;
1276
1334
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1277
1335
  function resolvePageTrigger(raw) {
@@ -1691,8 +1749,8 @@ async function syncGitLog(client, repo, opts) {
1691
1749
  import { spawn as realSpawn3 } from "child_process";
1692
1750
  import { createHash as createHash4 } from "crypto";
1693
1751
  import { existsSync as existsSync2 } from "fs";
1694
- import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
1695
- 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";
1696
1754
  import { fileURLToPath as fileURLToPath2 } from "url";
1697
1755
 
1698
1756
  // src/core/survey-lease.ts
@@ -1702,15 +1760,15 @@ import {
1702
1760
  mkdirSync as mkdirSync2,
1703
1761
  mkdtempSync,
1704
1762
  readdirSync,
1705
- renameSync,
1763
+ renameSync as renameSync2,
1706
1764
  rmdirSync,
1707
1765
  rmSync,
1708
- statSync,
1766
+ statSync as statSync2,
1709
1767
  unlinkSync,
1710
1768
  utimesSync,
1711
1769
  writeFileSync
1712
1770
  } from "fs";
1713
- import { join as join7 } from "path";
1771
+ import { join as join8 } from "path";
1714
1772
 
1715
1773
  // src/core/survey.ts
1716
1774
  var SURVEY_DOC_IDS = [
@@ -1898,8 +1956,8 @@ var log2 = (m) => {
1898
1956
  console.log(`${(/* @__PURE__ */ new Date()).toISOString()} ${m}`);
1899
1957
  log.info("deepen", m);
1900
1958
  };
1901
- var LOCK_DIR = join9(tmpdir3(), "hindsight-coding-agent");
1902
- 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`);
1903
1961
  function acquireLock() {
1904
1962
  try {
1905
1963
  const held = JSON.parse(readFileSync4(LOCK, "utf8"));