@vectorize-io/hindsight-coding-agents 0.3.2 → 0.3.4

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.
package/dist/kilo.js CHANGED
@@ -376,6 +376,20 @@ var log = {
376
376
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
377
377
  error: (scope, msg, extra) => write("error", scope, msg, extra)
378
378
  };
379
+ function describeError(value, maxChars = 200) {
380
+ const parts = [];
381
+ const seen = /* @__PURE__ */ new Set();
382
+ let current2 = value;
383
+ while (current2 && !seen.has(current2)) {
384
+ seen.add(current2);
385
+ const error95 = current2;
386
+ const text = typeof error95.message === "string" ? error95.message : String(current2);
387
+ const withCode = error95.code ? `${text} (${String(error95.code)})` : text;
388
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
389
+ current2 = error95.cause;
390
+ }
391
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
392
+ }
379
393
 
380
394
  // src/core/missions.ts
381
395
  var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
@@ -1011,11 +1025,14 @@ var HindsightClient = class {
1011
1025
 
1012
1026
  // src/core/diag.ts
1013
1027
  import { appendFileSync as appendFileSync2 } from "fs";
1028
+ function diagFilePath() {
1029
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
1030
+ }
1014
1031
  function diag(harness, event, extra = {}) {
1015
1032
  log.debug(harness, `diag:${event}`, extra);
1016
1033
  try {
1017
1034
  appendFileSync2(
1018
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
1035
+ diagFilePath(),
1019
1036
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
1020
1037
  );
1021
1038
  } catch {
@@ -15642,6 +15659,18 @@ function resolveClaudeBin(explicit) {
15642
15659
  }
15643
15660
  return "claude";
15644
15661
  }
15662
+ var SURVEY_AGENT = "hindsight-survey";
15663
+ var SURVEY_AGENT_CONFIG = {
15664
+ description: "One-time read-only structural survey that seeds this repository's Hindsight memory.",
15665
+ mode: "primary",
15666
+ permission: {
15667
+ "*": "deny",
15668
+ read: "allow",
15669
+ grep: "allow",
15670
+ glob: "allow",
15671
+ hindsight_ingest_document: "allow"
15672
+ }
15673
+ };
15645
15674
  function resolveAgentBin(harness, claudeBin) {
15646
15675
  switch (harness) {
15647
15676
  case "claude-code":
@@ -15762,7 +15791,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
15762
15791
  case "opencode": {
15763
15792
  return {
15764
15793
  bin,
15765
- args: ["run", "--agent", "plan", SURVEY_PROMPT],
15794
+ args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
15766
15795
  env
15767
15796
  };
15768
15797
  }
@@ -15871,7 +15900,7 @@ function ok(value) {
15871
15900
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
15872
15901
  }
15873
15902
  function err(e) {
15874
- const message = String(e?.message ?? e);
15903
+ const message = describeError(e);
15875
15904
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
15876
15905
  }
15877
15906
  function guarded(fn) {
@@ -16477,6 +16506,7 @@ async function buildHookOutput(args) {
16477
16506
  const turns = (cached3.turns ?? 0) + 1;
16478
16507
  let reflectAnswer = cached3.reflectAnswer;
16479
16508
  let reflectRanThisTurn = false;
16509
+ let reflectFailed = false;
16480
16510
  const deferInitialReflect = cached3.deferInitialReflect === true;
16481
16511
  if (deferInitialReflect) {
16482
16512
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -16501,12 +16531,13 @@ async function buildHookOutput(args) {
16501
16531
  });
16502
16532
  } catch (e) {
16503
16533
  reflectAnswer = "";
16534
+ reflectFailed = true;
16504
16535
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
16505
- error: String(e?.message || e).slice(0, 200)
16536
+ error: describeError(e)
16506
16537
  });
16507
16538
  diag(harness, "reflect_failed", {
16508
16539
  ms: Date.now() - t0,
16509
- error: String(e?.message || e).slice(0, 200),
16540
+ error: describeError(e),
16510
16541
  query: prompt.slice(0, 80)
16511
16542
  });
16512
16543
  }
@@ -16525,7 +16556,7 @@ async function buildHookOutput(args) {
16525
16556
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
16526
16557
  {
16527
16558
  ms: Date.now() - t0,
16528
- error: String(e?.message || e).slice(0, 200)
16559
+ error: describeError(e)
16529
16560
  }
16530
16561
  );
16531
16562
  }
@@ -16548,6 +16579,8 @@ async function buildHookOutput(args) {
16548
16579
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
16549
16580
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
16550
16581
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
16582
+ } else if (reflectFailed) {
16583
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
16551
16584
  }
16552
16585
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
16553
16586
  }
@@ -16719,7 +16752,7 @@ var RuntimeCore = class {
16719
16752
  turns = await this.fetchTranscript(sessionId);
16720
16753
  } catch (e) {
16721
16754
  diag(this.harness, "idle_fetch_failed", {
16722
- error: String(e?.message || e).slice(0, 200),
16755
+ error: describeError(e),
16723
16756
  session: sessionId
16724
16757
  });
16725
16758
  return;
@@ -16759,7 +16792,7 @@ var RuntimeCore = class {
16759
16792
  ).catch(
16760
16793
  (e) => diag(this.harness, "retain_failed", {
16761
16794
  ms: Date.now() - t0,
16762
- error: String(e?.message || e).slice(0, 200),
16795
+ error: describeError(e),
16763
16796
  session: sessionId,
16764
16797
  trigger
16765
16798
  })
@@ -29265,6 +29298,12 @@ var jsonChatReader = (harness) => ({
29265
29298
  });
29266
29299
 
29267
29300
  // src/harness/opencode.ts
29301
+ var surveyAgentHook = {
29302
+ config: async (cfg) => {
29303
+ cfg.agent ??= {};
29304
+ cfg.agent[SURVEY_AGENT] ??= SURVEY_AGENT_CONFIG;
29305
+ }
29306
+ };
29268
29307
  var textOf = (parts) => (parts || []).filter((p) => p?.type === "text" && p.text).map((p) => p.text).join("\n").trim();
29269
29308
  var chatReader = jsonChatReader("opencode");
29270
29309
  function toOpencodeTool(spec) {
@@ -29285,6 +29324,7 @@ function createRuntime(core) {
29285
29324
  const tools = {};
29286
29325
  for (const spec of core.toolSpecs()) tools[spec.name] = toOpencodeTool(spec);
29287
29326
  return {
29327
+ ...surveyAgentHook,
29288
29328
  tool: tools,
29289
29329
  // Each user turn: recall on the prompt; the injection it builds is pushed by system.transform.
29290
29330
  "chat.message": async (input, output) => {
@@ -31903,7 +31903,7 @@ var HindsightClient = class {
31903
31903
  // src/core/knowledge-tools.ts
31904
31904
  import { existsSync as existsSync3 } from "fs";
31905
31905
  import { homedir as homedir4 } from "os";
31906
- import { join as join5 } from "path";
31906
+ import { join as join6 } from "path";
31907
31907
 
31908
31908
  // src/core/status.ts
31909
31909
  import { execFileSync as execFileSync3 } from "child_process";
@@ -32011,12 +32011,56 @@ async function syncStatus(client, bank, repoDir) {
32011
32011
  };
32012
32012
  }
32013
32013
 
32014
+ // src/core/log.ts
32015
+ import { appendFileSync, mkdirSync } from "fs";
32016
+ import { tmpdir } from "os";
32017
+ import { dirname as dirname4, join as join5 } from "path";
32018
+ var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
32019
+ var current = ["debug", "info", "warn", "error"].find(
32020
+ (l) => l === process.env.HINDSIGHT_LOG_LEVEL
32021
+ ) ?? "info";
32022
+ function logFilePath() {
32023
+ return process.env.HINDSIGHT_LOG_FILE || join5(tmpdir(), "hindsight-coding-agent", "plugin.log");
32024
+ }
32025
+ function write(level, scope, msg, extra) {
32026
+ if (WEIGHT[level] < WEIGHT[current]) return;
32027
+ try {
32028
+ const file2 = logFilePath();
32029
+ mkdirSync(dirname4(file2), { recursive: true });
32030
+ appendFileSync(
32031
+ file2,
32032
+ `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
32033
+ );
32034
+ } catch {
32035
+ }
32036
+ }
32037
+ var log = {
32038
+ debug: (scope, msg, extra) => write("debug", scope, msg, extra),
32039
+ info: (scope, msg, extra) => write("info", scope, msg, extra),
32040
+ warn: (scope, msg, extra) => write("warn", scope, msg, extra),
32041
+ error: (scope, msg, extra) => write("error", scope, msg, extra)
32042
+ };
32043
+ function describeError(value, maxChars = 200) {
32044
+ const parts = [];
32045
+ const seen = /* @__PURE__ */ new Set();
32046
+ let current2 = value;
32047
+ while (current2 && !seen.has(current2)) {
32048
+ seen.add(current2);
32049
+ const error51 = current2;
32050
+ const text = typeof error51.message === "string" ? error51.message : String(current2);
32051
+ const withCode = error51.code ? `${text} (${String(error51.code)})` : text;
32052
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
32053
+ current2 = error51.cause;
32054
+ }
32055
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
32056
+ }
32057
+
32014
32058
  // src/core/knowledge-tools.ts
32015
32059
  function ok(value) {
32016
32060
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
32017
32061
  }
32018
32062
  function err(e) {
32019
- const message = String(e?.message ?? e);
32063
+ const message = describeError(e);
32020
32064
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
32021
32065
  }
32022
32066
  function guarded(fn) {
@@ -32047,7 +32091,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
32047
32091
  description: "Report safe Hindsight runtime diagnostics for this coding-agent session: resolved bank, workspace, harness, config location, API endpoint, and non-secret environment overrides. Use this when memory, hooks, MCP tools, or configuration appear not to work. Tokens and other secret values are never returned.",
32048
32092
  inputSchema: {},
32049
32093
  handler: async (_args) => {
32050
- const configPath = process.env.HINDSIGHT_CONFIG || join5(homedir4(), ".hindsight", "coding-agent.json");
32094
+ const configPath = process.env.HINDSIGHT_CONFIG || join6(homedir4(), ".hindsight", "coding-agent.json");
32051
32095
  const harness = opts.harness ?? "unknown";
32052
32096
  const cfg = loadConfig({ harness: opts.harness });
32053
32097
  return ok({
@@ -32160,36 +32204,6 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
32160
32204
  ];
32161
32205
  }
32162
32206
 
32163
- // src/core/log.ts
32164
- import { appendFileSync, mkdirSync } from "fs";
32165
- import { tmpdir } from "os";
32166
- import { dirname as dirname4, join as join6 } from "path";
32167
- var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
32168
- var current = ["debug", "info", "warn", "error"].find(
32169
- (l) => l === process.env.HINDSIGHT_LOG_LEVEL
32170
- ) ?? "info";
32171
- function logFilePath() {
32172
- return process.env.HINDSIGHT_LOG_FILE || join6(tmpdir(), "hindsight-coding-agent", "plugin.log");
32173
- }
32174
- function write(level, scope, msg, extra) {
32175
- if (WEIGHT[level] < WEIGHT[current]) return;
32176
- try {
32177
- const file2 = logFilePath();
32178
- mkdirSync(dirname4(file2), { recursive: true });
32179
- appendFileSync(
32180
- file2,
32181
- `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
32182
- );
32183
- } catch {
32184
- }
32185
- }
32186
- var log = {
32187
- debug: (scope, msg, extra) => write("debug", scope, msg, extra),
32188
- info: (scope, msg, extra) => write("info", scope, msg, extra),
32189
- warn: (scope, msg, extra) => write("warn", scope, msg, extra),
32190
- error: (scope, msg, extra) => write("error", scope, msg, extra)
32191
- };
32192
-
32193
32207
  // src/core/retain-stamp.ts
32194
32208
  import { basename as basename2 } from "path";
32195
32209
  var RESERVED_TAG_PREFIX = /^(source|harness):/;
@@ -14890,13 +14890,30 @@ var log = {
14890
14890
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
14891
14891
  error: (scope, msg, extra) => write("error", scope, msg, extra)
14892
14892
  };
14893
+ function describeError(value, maxChars = 200) {
14894
+ const parts = [];
14895
+ const seen = /* @__PURE__ */ new Set();
14896
+ let current2 = value;
14897
+ while (current2 && !seen.has(current2)) {
14898
+ seen.add(current2);
14899
+ const error51 = current2;
14900
+ const text = typeof error51.message === "string" ? error51.message : String(current2);
14901
+ const withCode = error51.code ? `${text} (${String(error51.code)})` : text;
14902
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
14903
+ current2 = error51.cause;
14904
+ }
14905
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
14906
+ }
14893
14907
 
14894
14908
  // src/core/diag.ts
14909
+ function diagFilePath() {
14910
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
14911
+ }
14895
14912
  function diag(harness, event, extra = {}) {
14896
14913
  log.debug(harness, `diag:${event}`, extra);
14897
14914
  try {
14898
14915
  appendFileSync2(
14899
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
14916
+ diagFilePath(),
14900
14917
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
14901
14918
  );
14902
14919
  } catch {
@@ -15641,6 +15658,7 @@ function resolveClaudeBin(explicit) {
15641
15658
  }
15642
15659
  return "claude";
15643
15660
  }
15661
+ var SURVEY_AGENT = "hindsight-survey";
15644
15662
  function resolveAgentBin(harness, claudeBin) {
15645
15663
  switch (harness) {
15646
15664
  case "claude-code":
@@ -15761,7 +15779,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
15761
15779
  case "opencode": {
15762
15780
  return {
15763
15781
  bin,
15764
- args: ["run", "--agent", "plan", SURVEY_PROMPT],
15782
+ args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
15765
15783
  env
15766
15784
  };
15767
15785
  }
@@ -15870,7 +15888,7 @@ function ok(value) {
15870
15888
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
15871
15889
  }
15872
15890
  function err(e) {
15873
- const message = String(e?.message ?? e);
15891
+ const message = describeError(e);
15874
15892
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
15875
15893
  }
15876
15894
  function guarded(fn) {
@@ -16476,6 +16494,7 @@ async function buildHookOutput(args) {
16476
16494
  const turns = (cached2.turns ?? 0) + 1;
16477
16495
  let reflectAnswer = cached2.reflectAnswer;
16478
16496
  let reflectRanThisTurn = false;
16497
+ let reflectFailed = false;
16479
16498
  const deferInitialReflect = cached2.deferInitialReflect === true;
16480
16499
  if (deferInitialReflect) {
16481
16500
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -16500,12 +16519,13 @@ async function buildHookOutput(args) {
16500
16519
  });
16501
16520
  } catch (e) {
16502
16521
  reflectAnswer = "";
16522
+ reflectFailed = true;
16503
16523
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
16504
- error: String(e?.message || e).slice(0, 200)
16524
+ error: describeError(e)
16505
16525
  });
16506
16526
  diag(harness, "reflect_failed", {
16507
16527
  ms: Date.now() - t0,
16508
- error: String(e?.message || e).slice(0, 200),
16528
+ error: describeError(e),
16509
16529
  query: prompt.slice(0, 80)
16510
16530
  });
16511
16531
  }
@@ -16524,7 +16544,7 @@ async function buildHookOutput(args) {
16524
16544
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
16525
16545
  {
16526
16546
  ms: Date.now() - t0,
16527
- error: String(e?.message || e).slice(0, 200)
16547
+ error: describeError(e)
16528
16548
  }
16529
16549
  );
16530
16550
  }
@@ -16547,6 +16567,8 @@ async function buildHookOutput(args) {
16547
16567
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
16548
16568
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
16549
16569
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
16570
+ } else if (reflectFailed) {
16571
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
16550
16572
  }
16551
16573
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
16552
16574
  }
@@ -16718,7 +16740,7 @@ var RuntimeCore = class {
16718
16740
  turns = await this.fetchTranscript(sessionId);
16719
16741
  } catch (e) {
16720
16742
  diag(this.harness, "idle_fetch_failed", {
16721
- error: String(e?.message || e).slice(0, 200),
16743
+ error: describeError(e),
16722
16744
  session: sessionId
16723
16745
  });
16724
16746
  return;
@@ -16758,7 +16780,7 @@ var RuntimeCore = class {
16758
16780
  ).catch(
16759
16781
  (e) => diag(this.harness, "retain_failed", {
16760
16782
  ms: Date.now() - t0,
16761
- error: String(e?.message || e).slice(0, 200),
16783
+ error: describeError(e),
16762
16784
  session: sessionId,
16763
16785
  trigger
16764
16786
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorize-io/hindsight-coding-agents",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/vectorize-io/hindsight.git",
@@ -27,10 +27,26 @@
27
27
  "hindsight-antigravity-statusline": "dist/antigravity-statusline.js",
28
28
  "hindsight-devin-hook": "dist/devin-hook.js"
29
29
  },
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./dsh": "./dist/dsh.js",
36
+ "./cordis.patch.yml": "./cordis.patch.yml",
37
+ "./package.json": "./package.json",
38
+ "./dist/*": "./dist/*"
39
+ },
30
40
  "files": [
31
41
  "skill",
32
- "dist"
42
+ "dist",
43
+ "cordis.patch.yml"
33
44
  ],
45
+ "dsh": {
46
+ "bundle": {
47
+ "patch": "./cordis.patch.yml"
48
+ }
49
+ },
34
50
  "cline": {
35
51
  "plugins": [
36
52
  {