@vectorize-io/hindsight-coding-agents 0.3.3 → 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/grok-hook.js CHANGED
@@ -372,6 +372,20 @@ var log = {
372
372
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
373
373
  error: (scope, msg, extra) => write("error", scope, msg, extra)
374
374
  };
375
+ function describeError(value, maxChars = 200) {
376
+ const parts = [];
377
+ const seen = /* @__PURE__ */ new Set();
378
+ let current2 = value;
379
+ while (current2 && !seen.has(current2)) {
380
+ seen.add(current2);
381
+ const error = current2;
382
+ const text = typeof error.message === "string" ? error.message : String(current2);
383
+ const withCode = error.code ? `${text} (${String(error.code)})` : text;
384
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
385
+ current2 = error.cause;
386
+ }
387
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
388
+ }
375
389
 
376
390
  // src/core/diag.ts
377
391
  function diagFilePath() {
@@ -1166,11 +1180,11 @@ async function buildHookOutput(args) {
1166
1180
  reflectAnswer = "";
1167
1181
  reflectFailed = true;
1168
1182
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1169
- error: String(e?.message || e).slice(0, 200)
1183
+ error: describeError(e)
1170
1184
  });
1171
1185
  diag(harness, "reflect_failed", {
1172
1186
  ms: Date.now() - t0,
1173
- error: String(e?.message || e).slice(0, 200),
1187
+ error: describeError(e),
1174
1188
  query: prompt.slice(0, 80)
1175
1189
  });
1176
1190
  }
@@ -1189,7 +1203,7 @@ async function buildHookOutput(args) {
1189
1203
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
1190
1204
  {
1191
1205
  ms: Date.now() - t0,
1192
- error: String(e?.message || e).slice(0, 200)
1206
+ error: describeError(e)
1193
1207
  }
1194
1208
  );
1195
1209
  }
@@ -349,6 +349,20 @@ var log = {
349
349
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
350
350
  error: (scope, msg, extra) => write("error", scope, msg, extra)
351
351
  };
352
+ function describeError(value, maxChars = 200) {
353
+ const parts = [];
354
+ const seen = /* @__PURE__ */ new Set();
355
+ let current2 = value;
356
+ while (current2 && !seen.has(current2)) {
357
+ seen.add(current2);
358
+ const error = current2;
359
+ const text = typeof error.message === "string" ? error.message : String(current2);
360
+ const withCode = error.code ? `${text} (${String(error.code)})` : text;
361
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
362
+ current2 = error.cause;
363
+ }
364
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
365
+ }
352
366
 
353
367
  // src/core/diag.ts
354
368
  function diagFilePath() {
@@ -1525,11 +1539,11 @@ async function buildRetain(args) {
1525
1539
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1526
1540
  } catch (e) {
1527
1541
  log.warn(harness, "session write-back failed", {
1528
- error: String(e?.message || e).slice(0, 200)
1542
+ error: describeError(e)
1529
1543
  });
1530
1544
  diag(harness, "retain_failed", {
1531
1545
  ms: Date.now() - t0,
1532
- error: String(e?.message || e).slice(0, 200),
1546
+ error: describeError(e),
1533
1547
  session: sessionId
1534
1548
  });
1535
1549
  }
package/dist/index.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.";
@@ -15886,7 +15900,7 @@ function ok(value) {
15886
15900
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
15887
15901
  }
15888
15902
  function err(e) {
15889
- const message = String(e?.message ?? e);
15903
+ const message = describeError(e);
15890
15904
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
15891
15905
  }
15892
15906
  function guarded(fn) {
@@ -16519,11 +16533,11 @@ async function buildHookOutput(args) {
16519
16533
  reflectAnswer = "";
16520
16534
  reflectFailed = true;
16521
16535
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
16522
- error: String(e?.message || e).slice(0, 200)
16536
+ error: describeError(e)
16523
16537
  });
16524
16538
  diag(harness, "reflect_failed", {
16525
16539
  ms: Date.now() - t0,
16526
- error: String(e?.message || e).slice(0, 200),
16540
+ error: describeError(e),
16527
16541
  query: prompt.slice(0, 80)
16528
16542
  });
16529
16543
  }
@@ -16542,7 +16556,7 @@ async function buildHookOutput(args) {
16542
16556
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
16543
16557
  {
16544
16558
  ms: Date.now() - t0,
16545
- error: String(e?.message || e).slice(0, 200)
16559
+ error: describeError(e)
16546
16560
  }
16547
16561
  );
16548
16562
  }
@@ -16738,7 +16752,7 @@ var RuntimeCore = class {
16738
16752
  turns = await this.fetchTranscript(sessionId);
16739
16753
  } catch (e) {
16740
16754
  diag(this.harness, "idle_fetch_failed", {
16741
- error: String(e?.message || e).slice(0, 200),
16755
+ error: describeError(e),
16742
16756
  session: sessionId
16743
16757
  });
16744
16758
  return;
@@ -16778,7 +16792,7 @@ var RuntimeCore = class {
16778
16792
  ).catch(
16779
16793
  (e) => diag(this.harness, "retain_failed", {
16780
16794
  ms: Date.now() - t0,
16781
- error: String(e?.message || e).slice(0, 200),
16795
+ error: describeError(e),
16782
16796
  session: sessionId,
16783
16797
  trigger
16784
16798
  })
package/dist/installer.js CHANGED
@@ -892,6 +892,100 @@ import {
892
892
  } from "fs";
893
893
  import { homedir as homedir7 } from "os";
894
894
  import { join as join11 } from "path";
895
+ import * as zlib2 from "zlib";
896
+
897
+ // src/core/transcript-dsh.ts
898
+ function textOf(message) {
899
+ return (message.content || []).filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
900
+ }
901
+ function stampOf(event) {
902
+ return typeof event.time === "number" ? { timestamp: new Date(event.time).toISOString() } : {};
903
+ }
904
+ function readDshEvents(events) {
905
+ const turns = [];
906
+ for (const event of events || []) {
907
+ if (!event || typeof event !== "object") continue;
908
+ const stamp = stampOf(event);
909
+ if (event.type === "user/message") {
910
+ const message = event.data;
911
+ if (!message || message.source?.kind !== "user") continue;
912
+ const text = stripInjectedMemory(textOf(message)).trim();
913
+ if (text) turns.push({ role: "user", content: text, ...stamp });
914
+ } else if (event.type === "assistant/message") {
915
+ const message = event.data?.message;
916
+ if (!message) continue;
917
+ const text = stripInjectedMemory(textOf(message)).trim();
918
+ if (text) turns.push({ role: "assistant", content: text, ...stamp });
919
+ } else if (event.type === "tool/call") {
920
+ const call = event.data;
921
+ if (!call?.name) continue;
922
+ turns.push({
923
+ role: "action",
924
+ content: actionLine(call.name, parseArgs(call.arguments)),
925
+ ...stamp
926
+ });
927
+ }
928
+ }
929
+ return turns;
930
+ }
931
+ function parseArgs(raw) {
932
+ if (!raw) return void 0;
933
+ try {
934
+ return JSON.parse(raw);
935
+ } catch {
936
+ return raw;
937
+ }
938
+ }
939
+
940
+ // src/core/zstd-frames.ts
941
+ import * as zlib from "zlib";
942
+ var ZSTD_MAGIC = 4247762216;
943
+ function scanZstdFrames(buffer) {
944
+ const frames = [];
945
+ let offset = 0;
946
+ while (offset < buffer.length) {
947
+ const start = offset;
948
+ if (buffer.length - offset < 5) return frames;
949
+ if (buffer.readUInt32LE(offset) !== ZSTD_MAGIC) return frames;
950
+ offset += 4;
951
+ const descriptor = buffer.readUInt8(offset);
952
+ offset += 1;
953
+ if ((descriptor & 24) !== 0) return frames;
954
+ const contentSizeFlag = descriptor >>> 6;
955
+ const singleSegment = (descriptor & 32) !== 0;
956
+ const hasChecksum = (descriptor & 4) !== 0;
957
+ const dictionaryFlag = descriptor & 3;
958
+ const dictionaryBytes = dictionaryFlag === 3 ? 4 : dictionaryFlag;
959
+ const contentSizeBytes = contentSizeFlag === 0 ? singleSegment ? 1 : 0 : 1 << contentSizeFlag;
960
+ offset += (singleSegment ? 0 : 1) + dictionaryBytes + contentSizeBytes;
961
+ if (offset > buffer.length) return frames;
962
+ for (; ; ) {
963
+ if (buffer.length - offset < 3) return frames;
964
+ const blockHeader = buffer.readUIntLE(offset, 3);
965
+ offset += 3;
966
+ const lastBlock = (blockHeader & 1) !== 0;
967
+ const blockType = blockHeader >>> 1 & 3;
968
+ if (blockType === 3) return frames;
969
+ const payloadBytes = blockType === 1 ? 1 : blockHeader >>> 3;
970
+ offset += payloadBytes;
971
+ if (offset > buffer.length) return frames;
972
+ if (lastBlock) break;
973
+ }
974
+ if (hasChecksum) {
975
+ if (buffer.length - offset < 4) return frames;
976
+ offset += 4;
977
+ }
978
+ frames.push({ start, end: offset });
979
+ }
980
+ return frames;
981
+ }
982
+ function zstdDecompressFrames(buffer) {
983
+ return scanZstdFrames(buffer).map(
984
+ (frame) => zlib.zstdDecompressSync(buffer.subarray(frame.start, frame.end)).toString("utf8")
985
+ ).join("");
986
+ }
987
+
988
+ // src/core/history.ts
895
989
  function claudeProjectDir(repoDir, home = homedir7()) {
896
990
  return join11(home, ".claude", "projects", repoDir.replace(/[/.]/g, "-"));
897
991
  }
@@ -991,6 +1085,56 @@ function codexHistory(repoDir, home) {
991
1085
  }
992
1086
  return { supported: true, sessions };
993
1087
  }
1088
+ function dshHistory(repoDir, home) {
1089
+ const root = process.env.DSH_HOME ? join11(process.env.DSH_HOME, "sessions") : join11(home, ".dsh", "sessions");
1090
+ if (!existsSync7(root)) return { supported: true, sessions: [] };
1091
+ if (typeof zlib2.zstdDecompressSync !== "function") {
1092
+ return {
1093
+ supported: false,
1094
+ reason: `reading dsh session logs needs Node's built-in Zstandard support (Node 22.15+); this import is running on ${process.version}`,
1095
+ sessions: []
1096
+ };
1097
+ }
1098
+ const sessions = [];
1099
+ let unattributed = 0;
1100
+ for (const dir of readdirSync2(root).map((project) => join11(root, project))) {
1101
+ let sessionDirs;
1102
+ try {
1103
+ sessionDirs = readdirSync2(dir).map((id) => join11(dir, id));
1104
+ } catch {
1105
+ continue;
1106
+ }
1107
+ for (const sessionDir of sessionDirs) {
1108
+ const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join11(sessionDir, name)).find((candidate) => existsSync7(candidate));
1109
+ if (!file) continue;
1110
+ try {
1111
+ const lines = readDshLog(file);
1112
+ const header = JSON.parse(lines[0] ?? "{}");
1113
+ if (!header.cwd) {
1114
+ unattributed++;
1115
+ continue;
1116
+ }
1117
+ if (!withinRepo(header.cwd, repoDir)) continue;
1118
+ const events = lines.slice(1).flatMap((line) => {
1119
+ try {
1120
+ return [JSON.parse(line)];
1121
+ } catch {
1122
+ return [];
1123
+ }
1124
+ });
1125
+ const s = toSession(header.id ?? sessionDir, readDshEvents(events));
1126
+ if (s) sessions.push(s);
1127
+ } catch {
1128
+ }
1129
+ }
1130
+ }
1131
+ return { supported: true, sessions, unattributed };
1132
+ }
1133
+ function readDshLog(file) {
1134
+ const bytes = readFileSync8(file);
1135
+ const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
1136
+ return text.split("\n").filter((line) => line.trim());
1137
+ }
994
1138
  var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
995
1139
  function importLocalHistory(harness, repoDir, home = homedir7()) {
996
1140
  switch (harness) {
@@ -998,6 +1142,8 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
998
1142
  return claudeHistory(repoDir, home);
999
1143
  case "codex":
1000
1144
  return codexHistory(repoDir, home);
1145
+ case "dsh":
1146
+ return dshHistory(repoDir, home);
1001
1147
  case "opencode":
1002
1148
  case "kilo":
1003
1149
  case "cursor-cli":
@@ -2084,6 +2230,47 @@ var cline = {
2084
2230
  c.log?.("cline-cli: native plugin + MCP + skill removed");
2085
2231
  }
2086
2232
  };
2233
+ var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
2234
+ var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
2235
+ var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
2236
+ function dshHome(c) {
2237
+ return process.env.DSH_HOME || join13(c.home, ".dsh");
2238
+ }
2239
+ var dsh = {
2240
+ name: "dsh",
2241
+ detect: (c) => onPath2("dsh") || existsSync9(dshHome(c)),
2242
+ install(c) {
2243
+ const path = join13(dshHome(c), "cordis.patch.yml");
2244
+ const existing = existsSync9(path) ? readFileSync10(path, "utf8") : "";
2245
+ const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
2246
+ const entry = pathToFileURL(join13(c.dist, "dsh.js")).href;
2247
+ const block = `${DSH_MARKER_START}
2248
+ - insert:
2249
+ - id: hindsight
2250
+ name: ${JSON.stringify(entry)}
2251
+ ${DSH_MARKER_END}
2252
+ `;
2253
+ if (existsSync9(path) && !existsSync9(`${path}.hindsight-backup`))
2254
+ copyFileSync(path, `${path}.hindsight-backup`);
2255
+ mkdirSync3(dirname8(path), { recursive: true });
2256
+ writeFileSync2(path, others ? `${others}
2257
+
2258
+ ${block}` : block);
2259
+ installSkill(c, "dsh", join13(c.home, ".agents", "skills"));
2260
+ c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
2261
+ },
2262
+ uninstall(c) {
2263
+ const path = join13(dshHome(c), "cordis.patch.yml");
2264
+ if (existsSync9(path)) {
2265
+ const existing = readFileSync10(path, "utf8");
2266
+ const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
2267
+ if (others !== existing.trim()) writeFileSync2(path, others ? `${others}
2268
+ ` : "[]\n");
2269
+ }
2270
+ uninstallSkill(c, join13(c.home, ".agents", "skills"));
2271
+ c.log?.("dsh: plugin entry + skill removed");
2272
+ }
2273
+ };
2087
2274
  var INSTALLERS = [
2088
2275
  opencode,
2089
2276
  kilo,
@@ -2095,7 +2282,8 @@ var INSTALLERS = [
2095
2282
  cursor,
2096
2283
  copilot,
2097
2284
  grok,
2098
- cline
2285
+ cline,
2286
+ dsh
2099
2287
  ];
2100
2288
  var HARNESS_ALIASES = { agy: "antigravity-cli" };
2101
2289
  function importConversations(harness, ctx) {
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.";
@@ -15886,7 +15900,7 @@ function ok(value) {
15886
15900
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
15887
15901
  }
15888
15902
  function err(e) {
15889
- const message = String(e?.message ?? e);
15903
+ const message = describeError(e);
15890
15904
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
15891
15905
  }
15892
15906
  function guarded(fn) {
@@ -16519,11 +16533,11 @@ async function buildHookOutput(args) {
16519
16533
  reflectAnswer = "";
16520
16534
  reflectFailed = true;
16521
16535
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
16522
- error: String(e?.message || e).slice(0, 200)
16536
+ error: describeError(e)
16523
16537
  });
16524
16538
  diag(harness, "reflect_failed", {
16525
16539
  ms: Date.now() - t0,
16526
- error: String(e?.message || e).slice(0, 200),
16540
+ error: describeError(e),
16527
16541
  query: prompt.slice(0, 80)
16528
16542
  });
16529
16543
  }
@@ -16542,7 +16556,7 @@ async function buildHookOutput(args) {
16542
16556
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
16543
16557
  {
16544
16558
  ms: Date.now() - t0,
16545
- error: String(e?.message || e).slice(0, 200)
16559
+ error: describeError(e)
16546
16560
  }
16547
16561
  );
16548
16562
  }
@@ -16738,7 +16752,7 @@ var RuntimeCore = class {
16738
16752
  turns = await this.fetchTranscript(sessionId);
16739
16753
  } catch (e) {
16740
16754
  diag(this.harness, "idle_fetch_failed", {
16741
- error: String(e?.message || e).slice(0, 200),
16755
+ error: describeError(e),
16742
16756
  session: sessionId
16743
16757
  });
16744
16758
  return;
@@ -16778,7 +16792,7 @@ var RuntimeCore = class {
16778
16792
  ).catch(
16779
16793
  (e) => diag(this.harness, "retain_failed", {
16780
16794
  ms: Date.now() - t0,
16781
- error: String(e?.message || e).slice(0, 200),
16795
+ error: describeError(e),
16782
16796
  session: sessionId,
16783
16797
  trigger
16784
16798
  })
@@ -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,6 +14890,20 @@ 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
14895
14909
  function diagFilePath() {
@@ -15874,7 +15888,7 @@ function ok(value) {
15874
15888
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
15875
15889
  }
15876
15890
  function err(e) {
15877
- const message = String(e?.message ?? e);
15891
+ const message = describeError(e);
15878
15892
  return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
15879
15893
  }
15880
15894
  function guarded(fn) {
@@ -16507,11 +16521,11 @@ async function buildHookOutput(args) {
16507
16521
  reflectAnswer = "";
16508
16522
  reflectFailed = true;
16509
16523
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
16510
- error: String(e?.message || e).slice(0, 200)
16524
+ error: describeError(e)
16511
16525
  });
16512
16526
  diag(harness, "reflect_failed", {
16513
16527
  ms: Date.now() - t0,
16514
- error: String(e?.message || e).slice(0, 200),
16528
+ error: describeError(e),
16515
16529
  query: prompt.slice(0, 80)
16516
16530
  });
16517
16531
  }
@@ -16530,7 +16544,7 @@ async function buildHookOutput(args) {
16530
16544
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
16531
16545
  {
16532
16546
  ms: Date.now() - t0,
16533
- error: String(e?.message || e).slice(0, 200)
16547
+ error: describeError(e)
16534
16548
  }
16535
16549
  );
16536
16550
  }
@@ -16726,7 +16740,7 @@ var RuntimeCore = class {
16726
16740
  turns = await this.fetchTranscript(sessionId);
16727
16741
  } catch (e) {
16728
16742
  diag(this.harness, "idle_fetch_failed", {
16729
- error: String(e?.message || e).slice(0, 200),
16743
+ error: describeError(e),
16730
16744
  session: sessionId
16731
16745
  });
16732
16746
  return;
@@ -16766,7 +16780,7 @@ var RuntimeCore = class {
16766
16780
  ).catch(
16767
16781
  (e) => diag(this.harness, "retain_failed", {
16768
16782
  ms: Date.now() - t0,
16769
- error: String(e?.message || e).slice(0, 200),
16783
+ error: describeError(e),
16770
16784
  session: sessionId,
16771
16785
  trigger
16772
16786
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorize-io/hindsight-coding-agents",
3
- "version": "0.3.3",
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
  {