@vectorize-io/hindsight-coding-agents 0.4.2 → 0.5.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 (46) hide show
  1. package/README.md +202 -51
  2. package/dist/antigravity-hook.js +637 -199
  3. package/dist/antigravity-statusline.js +219 -84
  4. package/dist/antigravity-stop-hook.js +654 -205
  5. package/dist/claude-hook.js +637 -199
  6. package/dist/claude-sessionstart-hook.js +863 -236
  7. package/dist/claude-stop-hook.js +654 -205
  8. package/dist/cline.js +589 -234
  9. package/dist/codex-hook.js +637 -199
  10. package/dist/codex-sessionstart-hook.js +863 -236
  11. package/dist/codex-stop-hook.js +654 -205
  12. package/dist/copilot-hook.js +637 -199
  13. package/dist/copilot-sessionstart-hook.js +863 -236
  14. package/dist/copilot-stop-hook.js +654 -205
  15. package/dist/cursor-hook.js +637 -199
  16. package/dist/cursor-sessionstart-hook.js +863 -236
  17. package/dist/cursor-stop-hook.js +654 -205
  18. package/dist/daemon-start.js +62 -43
  19. package/dist/dcode-hook.js +2577 -0
  20. package/dist/dcode-sessionstart-hook.js +3194 -0
  21. package/dist/dcode-stop-hook.js +2807 -0
  22. package/dist/deepen.js +361 -204
  23. package/dist/devin-hook.js +637 -199
  24. package/dist/devin-sessionstart-hook.js +863 -236
  25. package/dist/devin-stop-hook.js +654 -205
  26. package/dist/dsh.js +592 -235
  27. package/dist/grok-hook.js +637 -199
  28. package/dist/grok-sessionstart-hook.js +863 -236
  29. package/dist/grok-stop-hook.js +654 -205
  30. package/dist/hindsight-seed.js +222 -83
  31. package/dist/index.js +589 -234
  32. package/dist/installer.js +2343 -302
  33. package/dist/kilo.js +589 -234
  34. package/dist/mcp-server.js +363 -169
  35. package/dist/opencode2.js +30092 -0
  36. package/dist/pi.js +17650 -0
  37. package/dist/prime-agent.js +625 -260
  38. package/dist/qwen-hook.js +2577 -0
  39. package/dist/qwen-sessionstart-hook.js +3194 -0
  40. package/dist/qwen-stop-hook.js +2807 -0
  41. package/dist/status.js +300 -136
  42. package/hooks/hooks.json +37 -0
  43. package/index.js +10 -0
  44. package/package.json +15 -8
  45. package/plugin.json +16 -0
  46. package/skill/SKILL.md +114 -43
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/core/config.ts
4
- import { readFileSync } from "fs";
4
+ import { readFileSync as readFileSync2 } from "fs";
5
5
  import { homedir as homedir2 } from "os";
6
- import { join as join4 } from "path";
6
+ import { join as join6 } from "path";
7
7
 
8
8
  // src/core/seed.ts
9
9
  import { spawn as realSpawn } from "child_process";
@@ -12,71 +12,197 @@ import { fileURLToPath } from "url";
12
12
  var DEFAULT_SEED_LIMIT = 300;
13
13
 
14
14
  // src/core/bank.ts
15
- import { execFileSync } from "child_process";
16
15
  import { existsSync } from "fs";
17
16
  import { homedir } from "os";
18
- import { basename, dirname as dirname2, join as join2, normalize, sep } from "path";
17
+ import { basename, dirname as dirname4, join as join4, normalize, sep } from "path";
18
+
19
+ // src/core/diag.ts
20
+ import { appendFileSync as appendFileSync2 } from "fs";
21
+
22
+ // src/core/log.ts
23
+ import { appendFileSync, mkdirSync } from "fs";
24
+ import { tmpdir } from "os";
25
+ import { dirname as dirname2, join as join2 } from "path";
26
+ var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
27
+ var current = ["debug", "info", "warn", "error"].find(
28
+ (l) => l === process.env.HINDSIGHT_LOG_LEVEL
29
+ ) ?? "info";
30
+ function logFilePath() {
31
+ return process.env.HINDSIGHT_LOG_FILE || join2(tmpdir(), "hindsight-coding-agent", "plugin.log");
32
+ }
33
+ function write(level, scope, msg, extra) {
34
+ if (WEIGHT[level] < WEIGHT[current]) return;
35
+ try {
36
+ const file = logFilePath();
37
+ mkdirSync(dirname2(file), { recursive: true });
38
+ appendFileSync(
39
+ file,
40
+ `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
41
+ );
42
+ } catch {
43
+ }
44
+ }
45
+ var log = {
46
+ debug: (scope, msg, extra) => write("debug", scope, msg, extra),
47
+ info: (scope, msg, extra) => write("info", scope, msg, extra),
48
+ warn: (scope, msg, extra) => write("warn", scope, msg, extra),
49
+ error: (scope, msg, extra) => write("error", scope, msg, extra)
50
+ };
51
+
52
+ // src/core/diag.ts
53
+ function diagFilePath() {
54
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
55
+ }
56
+ function diag(harness, event, extra = {}) {
57
+ log.debug(harness, `diag:${event}`, extra);
58
+ try {
59
+ appendFileSync2(
60
+ diagFilePath(),
61
+ JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
62
+ );
63
+ } catch {
64
+ }
65
+ }
66
+
67
+ // src/core/git-layout.ts
68
+ import { lstatSync, readFileSync, realpathSync } from "fs";
69
+ import { dirname as dirname3, isAbsolute, join as join3, resolve } from "path";
70
+ var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
71
+ var ATTEMPTS = 3;
72
+ var BACKOFF_MS = 20;
73
+ function errorCode(error) {
74
+ return error?.code ?? "";
75
+ }
76
+ function sleepSync(ms) {
77
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
78
+ }
79
+ var TransientProbeError = class extends Error {
80
+ };
81
+ function entryKind(path) {
82
+ try {
83
+ const st = lstatSync(path);
84
+ return st.isDirectory() ? "dir" : "file";
85
+ } catch (error) {
86
+ if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
87
+ return "none";
88
+ }
89
+ }
90
+ function readTextOrNull(path) {
91
+ try {
92
+ return readFileSync(path, "utf8");
93
+ } catch (error) {
94
+ if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
95
+ return null;
96
+ }
97
+ }
98
+ function gitDirFromPointer(text, holder) {
99
+ const match = /^\s*gitdir:\s*(.+?)\s*$/m.exec(text);
100
+ if (!match) return null;
101
+ const target = match[1];
102
+ return isAbsolute(target) ? target : resolve(holder, target);
103
+ }
104
+ function commonDirOf(gitDir) {
105
+ const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
106
+ if (!pointer) return gitDir;
107
+ return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
108
+ }
109
+ function isBare(commonDir) {
110
+ const config = readTextOrNull(join3(commonDir, "config"));
111
+ return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
112
+ }
113
+ function looksLikeBareRepository(directory) {
114
+ return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
115
+ }
116
+ function canonical(path) {
117
+ try {
118
+ return realpathSync(path);
119
+ } catch {
120
+ return path;
121
+ }
122
+ }
123
+ function resolved(commonDir) {
124
+ if (entryKind(commonDir) !== "dir") return null;
125
+ const canonicalDir = canonical(commonDir);
126
+ return { status: "resolved", commonDir: canonicalDir, bare: isBare(canonicalDir) };
127
+ }
128
+ function probeOnce(directory) {
129
+ let current2 = resolve(directory);
130
+ for (; ; ) {
131
+ const dotGit = join3(current2, ".git");
132
+ const kind = entryKind(dotGit);
133
+ if (kind === "dir") {
134
+ const layout = resolved(commonDirOf(dotGit));
135
+ if (layout) return layout;
136
+ } else if (kind === "file") {
137
+ const text = readTextOrNull(dotGit);
138
+ const gitDir = text ? gitDirFromPointer(text, current2) : null;
139
+ const layout = gitDir ? resolved(commonDirOf(gitDir)) : null;
140
+ if (layout) return layout;
141
+ }
142
+ if (looksLikeBareRepository(current2)) {
143
+ const layout = resolved(current2);
144
+ if (layout) return layout;
145
+ }
146
+ const parent = dirname3(current2);
147
+ if (parent === current2) return { status: "absent" };
148
+ current2 = parent;
149
+ }
150
+ }
151
+ function probeGitLayout(directory) {
152
+ if (!directory) return { status: "absent" };
153
+ let last = "";
154
+ for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
155
+ if (attempt) sleepSync(BACKOFF_MS * attempt);
156
+ try {
157
+ return probeOnce(directory);
158
+ } catch (error) {
159
+ last = error instanceof TransientProbeError ? error.message : errorCode(error) || "unknown";
160
+ }
161
+ }
162
+ return { status: "failed", reason: last };
163
+ }
19
164
 
20
165
  // src/core/template.ts
21
166
  var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
22
167
  function applyTemplate(template, resolvers, what) {
23
168
  return template.replace(PLACEHOLDER, (_, name) => {
24
- const resolve = resolvers[name];
25
- if (!resolve) {
169
+ const resolve2 = resolvers[name];
170
+ if (!resolve2) {
26
171
  console.error(
27
172
  `hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
28
173
  );
29
174
  return "unknown";
30
175
  }
31
- return resolve();
176
+ return resolve2();
32
177
  });
33
178
  }
34
179
 
35
180
  // src/core/bank.ts
36
181
  var DEFAULT_BANK_NAME = "coding";
37
182
  var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
38
- function getProjectRootFromGit(directory) {
39
- if (!directory) return null;
40
- try {
41
- const commonDir = execFileSync(
42
- "git",
43
- ["rev-parse", "--path-format=absolute", "--git-common-dir"],
44
- {
45
- cwd: directory,
46
- encoding: "utf-8",
47
- stdio: ["ignore", "pipe", "ignore"],
48
- timeout: 1e3,
49
- windowsHide: true
50
- }
51
- ).trim();
52
- if (!commonDir) return null;
53
- if (basename(commonDir) === ".git") return dirname2(commonDir);
54
- if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
55
- return dirname2(commonDir);
56
- }
57
- return commonDir;
58
- } catch {
59
- return null;
183
+ var BankResolutionError = class extends Error {
184
+ constructor(message) {
185
+ super(message);
186
+ this.name = "BankResolutionError";
60
187
  }
61
- }
62
- function isBareRepository(commonDir) {
63
- try {
64
- return execFileSync("git", ["-C", commonDir, "rev-parse", "--is-bare-repository"], {
65
- encoding: "utf-8",
66
- stdio: ["ignore", "pipe", "ignore"],
67
- timeout: 1e3,
68
- env: { ...process.env, GIT_DIR: void 0, GIT_WORK_TREE: void 0 }
69
- }).trim() === "true";
70
- } catch {
71
- return false;
188
+ };
189
+ function resolveProjectRoot(directory) {
190
+ if (!directory) return { status: "absent" };
191
+ const layout = probeGitLayout(directory);
192
+ if (layout.status !== "resolved") return layout;
193
+ const commonDir = layout.commonDir;
194
+ if (basename(commonDir) === ".git") return { status: "resolved", root: dirname4(commonDir) };
195
+ if (basename(commonDir).startsWith(".") && layout.bare) {
196
+ return { status: "resolved", root: dirname4(commonDir) };
72
197
  }
198
+ return { status: "resolved", root: commonDir };
73
199
  }
74
200
  var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
75
201
  function nearestExistingDir(directory) {
76
202
  let current2 = directory;
77
203
  while (current2) {
78
204
  if (existsSync(current2)) return current2;
79
- const parent = dirname2(current2);
205
+ const parent = dirname4(current2);
80
206
  if (parent === current2) return "";
81
207
  current2 = parent;
82
208
  }
@@ -91,21 +217,29 @@ function mainWorktreeRoot(directory, sessionRoot = "") {
91
217
  sessionRoot,
92
218
  ...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
93
219
  ];
220
+ let failure = null;
94
221
  for (const candidate of candidates) {
95
- const root = candidate ? getProjectRootFromGit(candidate) : null;
96
- if (root) return root;
222
+ if (!candidate) continue;
223
+ const projectRoot = resolveProjectRoot(candidate);
224
+ if (projectRoot.status === "resolved") return projectRoot;
225
+ if (projectRoot.status === "failed") failure = projectRoot;
97
226
  }
98
- return null;
227
+ return failure ?? { status: "absent" };
99
228
  }
100
229
  function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
101
230
  if (resolveWorktrees) {
102
- const root = mainWorktreeRoot(directory, sessionRoot);
103
- if (root) return basename(root);
231
+ const projectRoot = mainWorktreeRoot(directory, sessionRoot);
232
+ if (projectRoot.status === "resolved") return basename(projectRoot.root);
233
+ if (projectRoot.status === "failed") {
234
+ throw new BankResolutionError(
235
+ `git probe failed for ${directory} (${projectRoot.reason}) \u2014 refusing to guess a bank id`
236
+ );
237
+ }
104
238
  }
105
239
  return dirName(sessionRoot || directory);
106
240
  }
107
241
  function configuredDir(dir) {
108
- const expanded = dir === "~" || dir.startsWith("~/") ? join2(homedir(), dir.slice(1)) : dir;
242
+ const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir(), dir.slice(1)) : dir;
109
243
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
110
244
  }
111
245
  function isWithin(directory, configured) {
@@ -125,8 +259,8 @@ function mapLookup(map, directory) {
125
259
  function lookupDirectories(config, directory, sessionRoot = "") {
126
260
  const directories = [normalize(directory)];
127
261
  if (config.resolveWorktrees ?? true) {
128
- const root = mainWorktreeRoot(directory, sessionRoot);
129
- const normalizedRoot = root ? normalize(root) : "";
262
+ const projectRoot = mainWorktreeRoot(directory, sessionRoot);
263
+ const normalizedRoot = projectRoot.status === "resolved" ? normalize(projectRoot.root) : "";
130
264
  if (normalizedRoot && normalizedRoot !== directories[0]) directories.push(normalizedRoot);
131
265
  }
132
266
  return directories;
@@ -159,36 +293,23 @@ function deriveBankId(config, directory, harness = "coding", sessionRoot) {
159
293
  };
160
294
  return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
161
295
  }
162
-
163
- // src/core/log.ts
164
- import { appendFileSync, mkdirSync } from "fs";
165
- import { tmpdir } from "os";
166
- import { dirname as dirname3, join as join3 } from "path";
167
- var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
168
- var current = ["debug", "info", "warn", "error"].find(
169
- (l) => l === process.env.HINDSIGHT_LOG_LEVEL
170
- ) ?? "info";
171
- function logFilePath() {
172
- return process.env.HINDSIGHT_LOG_FILE || join3(tmpdir(), "hindsight-coding-agent", "plugin.log");
173
- }
174
- function write(level, scope, msg, extra) {
175
- if (WEIGHT[level] < WEIGHT[current]) return;
296
+ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot) {
176
297
  try {
177
- const file = logFilePath();
178
- mkdirSync(dirname3(file), { recursive: true });
179
- appendFileSync(
180
- file,
181
- `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
182
- );
183
- } catch {
298
+ return deriveBankId(config, directory, harness, sessionRoot);
299
+ } catch (error) {
300
+ if (!(error instanceof BankResolutionError)) throw error;
301
+ log.warn(harness, "bank unresolved: skipping (repository could not be identified)", {
302
+ directory,
303
+ error: error.message
304
+ });
305
+ diag(harness, "bank_unresolved", { directory, error: error.message });
306
+ return null;
184
307
  }
185
308
  }
186
- var log = {
187
- debug: (scope, msg, extra) => write("debug", scope, msg, extra),
188
- info: (scope, msg, extra) => write("info", scope, msg, extra),
189
- warn: (scope, msg, extra) => write("warn", scope, msg, extra),
190
- error: (scope, msg, extra) => write("error", scope, msg, extra)
191
- };
309
+
310
+ // src/core/util.ts
311
+ import { accessSync, constants } from "fs";
312
+ import { delimiter, join as join5 } from "path";
192
313
 
193
314
  // src/core/hindsight.ts
194
315
  var DEFAULT_OBSERVATION_SCOPES = "shared";
@@ -196,7 +317,7 @@ var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
196
317
  var RETRY_AFTER_CEILING_MS = 60 * 1e3;
197
318
 
198
319
  // src/core/config.ts
199
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join4(homedir2(), ".hindsight", "coding-agent.json");
320
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
200
321
  var DEFAULT_DAEMON_PORT = 9077;
201
322
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
202
323
  function resolvePageTriggerType(raw) {
@@ -220,7 +341,13 @@ function resolveReflectBudget(raw) {
220
341
  log.warn("config", `ignoring reflectBudget=${JSON.stringify(value)} \u2014 expected low|mid|high`);
221
342
  return "high";
222
343
  }
223
- var OBSERVATION_SCOPE_MODES = ["shared", "combined", "per_tag", "all_combinations"];
344
+ var OBSERVATION_SCOPE_MODES = [
345
+ "shared",
346
+ "combined",
347
+ "per_tag",
348
+ "all_combinations",
349
+ "per_source"
350
+ ];
224
351
  function resolveObservationScopes(raw) {
225
352
  const value = raw;
226
353
  if (typeof value === "string")
@@ -258,6 +385,7 @@ function resolveConfig(raw = {}) {
258
385
  disabled: raw.disabled ?? false,
259
386
  retainSessions: raw.retainSessions ?? true,
260
387
  // write sessions back by default, every harness
388
+ manageBankConfig: raw.manageBankConfig ?? true,
261
389
  maxParallelRetains: raw.maxParallelRetains || 10,
262
390
  reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
263
391
  // Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
@@ -284,12 +412,13 @@ function resolveConfig(raw = {}) {
284
412
  ) : {},
285
413
  observationScopes: resolveObservationScopes(raw.observationScopes),
286
414
  banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
287
- logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
415
+ logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
416
+ autoUpdate: raw.autoUpdate ?? true
288
417
  };
289
418
  }
290
419
  function readRaw(path) {
291
420
  try {
292
- return JSON.parse(readFileSync(path, "utf8"));
421
+ return JSON.parse(readFileSync2(path, "utf8"));
293
422
  } catch (e) {
294
423
  if (e?.code !== "ENOENT") {
295
424
  console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
@@ -342,13 +471,15 @@ var ENV_KEYS = {
342
471
  surveyBudgetUsd: "HINDSIGHT_SURVEY_BUDGET_USD",
343
472
  surveyRefreshCommits: "HINDSIGHT_SURVEY_REFRESH_COMMITS",
344
473
  logLevel: "HINDSIGHT_LOG_LEVEL",
474
+ autoUpdate: "HINDSIGHT_AUTO_UPDATE",
345
475
  gitIngest: "HINDSIGHT_GIT_INGEST",
346
476
  // Scalar modes only ("shared", "combined", "per_tag", "all_combinations"). An explicit scope
347
477
  // list is a list OF lists, which does not survive flattening into one variable — file-only.
348
478
  observationScopes: "HINDSIGHT_OBSERVATION_SCOPES",
349
479
  // Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
350
480
  // a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
351
- retainTags: "HINDSIGHT_RETAIN_TAGS"
481
+ retainTags: "HINDSIGHT_RETAIN_TAGS",
482
+ manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
352
483
  };
353
484
  var ENV_BOOLEANS = /* @__PURE__ */ new Set([
354
485
  "dynamicBankId",
@@ -358,7 +489,9 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
358
489
  "retainSessions",
359
490
  "autoReflect",
360
491
  "autoSeed",
361
- "codebaseSurvey"
492
+ "codebaseSurvey",
493
+ "autoUpdate",
494
+ "manageBankConfig"
362
495
  ]);
363
496
  var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
364
497
  var ENV_NUMBERS = /* @__PURE__ */ new Set([
@@ -451,8 +584,10 @@ function brandWord() {
451
584
  function buildAntigravityStatusLine(state, cfg) {
452
585
  const cwd = state.cwd || state.workspace?.current_dir;
453
586
  if (!cwd) return brandWord();
454
- const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, "antigravity-cli"), cwd);
455
- return resolved.cfg.disabled ? "" : `${brandWord()} \xB7 ${resolved.bankId}`;
587
+ const bankId = deriveBankIdOrSkip(cfg, cwd, "antigravity-cli");
588
+ if (bankId === null) return brandWord();
589
+ const resolved2 = applyBankConfig(cfg, bankId, cwd);
590
+ return resolved2.cfg.disabled ? "" : `${brandWord()} \xB7 ${resolved2.bankId}`;
456
591
  }
457
592
  async function main() {
458
593
  const chunks = [];