@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.
@@ -372,13 +372,30 @@ 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
391
+ function diagFilePath() {
392
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
393
+ }
377
394
  function diag(harness, event, extra = {}) {
378
395
  log.debug(harness, `diag:${event}`, extra);
379
396
  try {
380
397
  appendFileSync2(
381
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
398
+ diagFilePath(),
382
399
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
383
400
  );
384
401
  } catch {
@@ -1136,6 +1153,7 @@ async function buildHookOutput(args) {
1136
1153
  const turns = (cached.turns ?? 0) + 1;
1137
1154
  let reflectAnswer = cached.reflectAnswer;
1138
1155
  let reflectRanThisTurn = false;
1156
+ let reflectFailed = false;
1139
1157
  const deferInitialReflect = cached.deferInitialReflect === true;
1140
1158
  if (deferInitialReflect) {
1141
1159
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -1160,12 +1178,13 @@ async function buildHookOutput(args) {
1160
1178
  });
1161
1179
  } catch (e) {
1162
1180
  reflectAnswer = "";
1181
+ reflectFailed = true;
1163
1182
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1164
- error: String(e?.message || e).slice(0, 200)
1183
+ error: describeError(e)
1165
1184
  });
1166
1185
  diag(harness, "reflect_failed", {
1167
1186
  ms: Date.now() - t0,
1168
- error: String(e?.message || e).slice(0, 200),
1187
+ error: describeError(e),
1169
1188
  query: prompt.slice(0, 80)
1170
1189
  });
1171
1190
  }
@@ -1184,7 +1203,7 @@ async function buildHookOutput(args) {
1184
1203
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
1185
1204
  {
1186
1205
  ms: Date.now() - t0,
1187
- error: String(e?.message || e).slice(0, 200)
1206
+ error: describeError(e)
1188
1207
  }
1189
1208
  );
1190
1209
  }
@@ -1207,6 +1226,8 @@ async function buildHookOutput(args) {
1207
1226
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
1208
1227
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
1209
1228
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
1229
+ } else if (reflectFailed) {
1230
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
1210
1231
  }
1211
1232
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
1212
1233
  }
@@ -377,11 +377,14 @@ var log = {
377
377
  };
378
378
 
379
379
  // src/core/diag.ts
380
+ function diagFilePath() {
381
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
382
+ }
380
383
  function diag(harness, event, extra = {}) {
381
384
  log.debug(harness, `diag:${event}`, extra);
382
385
  try {
383
386
  appendFileSync2(
384
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
387
+ diagFilePath(),
385
388
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
386
389
  );
387
390
  } catch {
@@ -1423,6 +1426,7 @@ function resolveClaudeBin(explicit) {
1423
1426
  }
1424
1427
  return "claude";
1425
1428
  }
1429
+ var SURVEY_AGENT = "hindsight-survey";
1426
1430
  function resolveAgentBin(harness, claudeBin) {
1427
1431
  switch (harness) {
1428
1432
  case "claude-code":
@@ -1543,7 +1547,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
1543
1547
  case "opencode": {
1544
1548
  return {
1545
1549
  bin,
1546
- args: ["run", "--agent", "plan", SURVEY_PROMPT],
1550
+ args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
1547
1551
  env
1548
1552
  };
1549
1553
  }
@@ -349,13 +349,30 @@ 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
368
+ function diagFilePath() {
369
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
370
+ }
354
371
  function diag(harness, event, extra = {}) {
355
372
  log.debug(harness, `diag:${event}`, extra);
356
373
  try {
357
374
  appendFileSync2(
358
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
375
+ diagFilePath(),
359
376
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
360
377
  );
361
378
  } catch {
@@ -1522,11 +1539,11 @@ async function buildRetain(args) {
1522
1539
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1523
1540
  } catch (e) {
1524
1541
  log.warn(harness, "session write-back failed", {
1525
- error: String(e?.message || e).slice(0, 200)
1542
+ error: describeError(e)
1526
1543
  });
1527
1544
  diag(harness, "retain_failed", {
1528
1545
  ms: Date.now() - t0,
1529
- error: String(e?.message || e).slice(0, 200),
1546
+ error: describeError(e),
1530
1547
  session: sessionId
1531
1548
  });
1532
1549
  }
@@ -372,13 +372,30 @@ 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
391
+ function diagFilePath() {
392
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
393
+ }
377
394
  function diag(harness, event, extra = {}) {
378
395
  log.debug(harness, `diag:${event}`, extra);
379
396
  try {
380
397
  appendFileSync2(
381
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
398
+ diagFilePath(),
382
399
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
383
400
  );
384
401
  } catch {
@@ -1136,6 +1153,7 @@ async function buildHookOutput(args) {
1136
1153
  const turns = (cached.turns ?? 0) + 1;
1137
1154
  let reflectAnswer = cached.reflectAnswer;
1138
1155
  let reflectRanThisTurn = false;
1156
+ let reflectFailed = false;
1139
1157
  const deferInitialReflect = cached.deferInitialReflect === true;
1140
1158
  if (deferInitialReflect) {
1141
1159
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -1160,12 +1178,13 @@ async function buildHookOutput(args) {
1160
1178
  });
1161
1179
  } catch (e) {
1162
1180
  reflectAnswer = "";
1181
+ reflectFailed = true;
1163
1182
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1164
- error: String(e?.message || e).slice(0, 200)
1183
+ error: describeError(e)
1165
1184
  });
1166
1185
  diag(harness, "reflect_failed", {
1167
1186
  ms: Date.now() - t0,
1168
- error: String(e?.message || e).slice(0, 200),
1187
+ error: describeError(e),
1169
1188
  query: prompt.slice(0, 80)
1170
1189
  });
1171
1190
  }
@@ -1184,7 +1203,7 @@ async function buildHookOutput(args) {
1184
1203
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
1185
1204
  {
1186
1205
  ms: Date.now() - t0,
1187
- error: String(e?.message || e).slice(0, 200)
1206
+ error: describeError(e)
1188
1207
  }
1189
1208
  );
1190
1209
  }
@@ -1207,6 +1226,8 @@ async function buildHookOutput(args) {
1207
1226
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
1208
1227
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
1209
1228
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
1229
+ } else if (reflectFailed) {
1230
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
1210
1231
  }
1211
1232
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
1212
1233
  }
@@ -377,11 +377,14 @@ var log = {
377
377
  };
378
378
 
379
379
  // src/core/diag.ts
380
+ function diagFilePath() {
381
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
382
+ }
380
383
  function diag(harness, event, extra = {}) {
381
384
  log.debug(harness, `diag:${event}`, extra);
382
385
  try {
383
386
  appendFileSync2(
384
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
387
+ diagFilePath(),
385
388
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
386
389
  );
387
390
  } catch {
@@ -1423,6 +1426,7 @@ function resolveClaudeBin(explicit) {
1423
1426
  }
1424
1427
  return "claude";
1425
1428
  }
1429
+ var SURVEY_AGENT = "hindsight-survey";
1426
1430
  function resolveAgentBin(harness, claudeBin) {
1427
1431
  switch (harness) {
1428
1432
  case "claude-code":
@@ -1543,7 +1547,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
1543
1547
  case "opencode": {
1544
1548
  return {
1545
1549
  bin,
1546
- args: ["run", "--agent", "plan", SURVEY_PROMPT],
1550
+ args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
1547
1551
  env
1548
1552
  };
1549
1553
  }
@@ -349,13 +349,30 @@ 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
368
+ function diagFilePath() {
369
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
370
+ }
354
371
  function diag(harness, event, extra = {}) {
355
372
  log.debug(harness, `diag:${event}`, extra);
356
373
  try {
357
374
  appendFileSync2(
358
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
375
+ diagFilePath(),
359
376
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
360
377
  );
361
378
  } catch {
@@ -1522,11 +1539,11 @@ async function buildRetain(args) {
1522
1539
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1523
1540
  } catch (e) {
1524
1541
  log.warn(harness, "session write-back failed", {
1525
- error: String(e?.message || e).slice(0, 200)
1542
+ error: describeError(e)
1526
1543
  });
1527
1544
  diag(harness, "retain_failed", {
1528
1545
  ms: Date.now() - t0,
1529
- error: String(e?.message || e).slice(0, 200),
1546
+ error: describeError(e),
1530
1547
  session: sessionId
1531
1548
  });
1532
1549
  }
@@ -511,11 +511,14 @@ var log = {
511
511
  };
512
512
 
513
513
  // src/core/diag.ts
514
+ function diagFilePath() {
515
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
516
+ }
514
517
  function diag(harness, event, extra = {}) {
515
518
  log.debug(harness, `diag:${event}`, extra);
516
519
  try {
517
520
  appendFileSync2(
518
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
521
+ diagFilePath(),
519
522
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
520
523
  );
521
524
  } catch {
package/dist/deepen.js CHANGED
@@ -1191,6 +1191,9 @@ var HARNESS_NAMES = [
1191
1191
  "kilo",
1192
1192
  // Cline CLI loads dist/cline.js through its native plugin manager; file hooks cannot inject.
1193
1193
  "cline-cli",
1194
+ // DeepSeek Harness loads dist/dsh.js as a native Cordis plugin (src/dsh.ts). Its Claude Code /
1195
+ // Codex hook bridges are optional packages, so there is no hook binary to install either.
1196
+ "dsh",
1194
1197
  // Prime Agent loads dist/prime-agent.js as an extension (src/prime-agent.ts); no hook binary.
1195
1198
  "prime-agent",
1196
1199
  "claude-code",
@@ -1211,9 +1214,16 @@ var HOOK_BINS = {
1211
1214
  "grok-build": "hindsight-grok-hook"
1212
1215
  // more hook harnesses: add a HookSpec entry point (see src/cursor-hook.ts) + a registration here.
1213
1216
  };
1217
+ var PLUGIN_ENTRYPOINTS = {
1218
+ opencode: "src/index.ts",
1219
+ kilo: "src/kilo.ts",
1220
+ "cline-cli": "src/cline.ts",
1221
+ "prime-agent": "src/prime-agent.ts",
1222
+ dsh: "src/dsh.ts"
1223
+ };
1214
1224
  async function getHarness(name) {
1215
- if (name === "opencode" || name === "kilo" || name === "cline-cli" || name === "prime-agent") {
1216
- const entry = name === "opencode" ? "src/index.ts" : name === "kilo" ? "src/kilo.ts" : name === "cline-cli" ? "src/cline.ts" : "src/prime-agent.ts";
1225
+ const entry = PLUGIN_ENTRYPOINTS[name];
1226
+ if (entry) {
1217
1227
  return noRuntimeAdapter(
1218
1228
  name,
1219
1229
  `${name}'s runtime is built by ${entry} (the ${name} plugin entrypoint), not via the harness registry`
@@ -1264,13 +1274,30 @@ var log = {
1264
1274
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
1265
1275
  error: (scope, msg, extra) => write("error", scope, msg, extra)
1266
1276
  };
1277
+ function describeError(value, maxChars = 200) {
1278
+ const parts = [];
1279
+ const seen = /* @__PURE__ */ new Set();
1280
+ let current2 = value;
1281
+ while (current2 && !seen.has(current2)) {
1282
+ seen.add(current2);
1283
+ const error = current2;
1284
+ const text = typeof error.message === "string" ? error.message : String(current2);
1285
+ const withCode = error.code ? `${text} (${String(error.code)})` : text;
1286
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
1287
+ current2 = error.cause;
1288
+ }
1289
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
1290
+ }
1267
1291
 
1268
1292
  // src/core/diag.ts
1293
+ function diagFilePath() {
1294
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
1295
+ }
1269
1296
  function diag(harness, event, extra = {}) {
1270
1297
  log.debug(harness, `diag:${event}`, extra);
1271
1298
  try {
1272
1299
  appendFileSync2(
1273
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
1300
+ diagFilePath(),
1274
1301
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
1275
1302
  );
1276
1303
  } catch {
@@ -1540,7 +1567,7 @@ async function main() {
1540
1567
  main().catch((e) => {
1541
1568
  diag("deepen", "deepen_failed", {
1542
1569
  bank: FINAL_BANK,
1543
- error: String(e?.message || e).slice(0, 200)
1570
+ error: describeError(e)
1544
1571
  });
1545
1572
  console.error("deepen failed:", e.message || e);
1546
1573
  try {
@@ -372,13 +372,30 @@ 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
391
+ function diagFilePath() {
392
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
393
+ }
377
394
  function diag(harness, event, extra = {}) {
378
395
  log.debug(harness, `diag:${event}`, extra);
379
396
  try {
380
397
  appendFileSync2(
381
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
398
+ diagFilePath(),
382
399
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
383
400
  );
384
401
  } catch {
@@ -1136,6 +1153,7 @@ async function buildHookOutput(args) {
1136
1153
  const turns = (cached.turns ?? 0) + 1;
1137
1154
  let reflectAnswer = cached.reflectAnswer;
1138
1155
  let reflectRanThisTurn = false;
1156
+ let reflectFailed = false;
1139
1157
  const deferInitialReflect = cached.deferInitialReflect === true;
1140
1158
  if (deferInitialReflect) {
1141
1159
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -1160,12 +1178,13 @@ async function buildHookOutput(args) {
1160
1178
  });
1161
1179
  } catch (e) {
1162
1180
  reflectAnswer = "";
1181
+ reflectFailed = true;
1163
1182
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1164
- error: String(e?.message || e).slice(0, 200)
1183
+ error: describeError(e)
1165
1184
  });
1166
1185
  diag(harness, "reflect_failed", {
1167
1186
  ms: Date.now() - t0,
1168
- error: String(e?.message || e).slice(0, 200),
1187
+ error: describeError(e),
1169
1188
  query: prompt.slice(0, 80)
1170
1189
  });
1171
1190
  }
@@ -1184,7 +1203,7 @@ async function buildHookOutput(args) {
1184
1203
  client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
1185
1204
  {
1186
1205
  ms: Date.now() - t0,
1187
- error: String(e?.message || e).slice(0, 200)
1206
+ error: describeError(e)
1188
1207
  }
1189
1208
  );
1190
1209
  }
@@ -1207,6 +1226,8 @@ async function buildHookOutput(args) {
1207
1226
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
1208
1227
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
1209
1228
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
1229
+ } else if (reflectFailed) {
1230
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
1210
1231
  }
1211
1232
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
1212
1233
  }
@@ -377,11 +377,14 @@ var log = {
377
377
  };
378
378
 
379
379
  // src/core/diag.ts
380
+ function diagFilePath() {
381
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
382
+ }
380
383
  function diag(harness, event, extra = {}) {
381
384
  log.debug(harness, `diag:${event}`, extra);
382
385
  try {
383
386
  appendFileSync2(
384
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
387
+ diagFilePath(),
385
388
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
386
389
  );
387
390
  } catch {
@@ -1423,6 +1426,7 @@ function resolveClaudeBin(explicit) {
1423
1426
  }
1424
1427
  return "claude";
1425
1428
  }
1429
+ var SURVEY_AGENT = "hindsight-survey";
1426
1430
  function resolveAgentBin(harness, claudeBin) {
1427
1431
  switch (harness) {
1428
1432
  case "claude-code":
@@ -1543,7 +1547,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
1543
1547
  case "opencode": {
1544
1548
  return {
1545
1549
  bin,
1546
- args: ["run", "--agent", "plan", SURVEY_PROMPT],
1550
+ args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
1547
1551
  env
1548
1552
  };
1549
1553
  }
@@ -349,13 +349,30 @@ 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
368
+ function diagFilePath() {
369
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
370
+ }
354
371
  function diag(harness, event, extra = {}) {
355
372
  log.debug(harness, `diag:${event}`, extra);
356
373
  try {
357
374
  appendFileSync2(
358
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
375
+ diagFilePath(),
359
376
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
360
377
  );
361
378
  } catch {
@@ -1522,11 +1539,11 @@ async function buildRetain(args) {
1522
1539
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1523
1540
  } catch (e) {
1524
1541
  log.warn(harness, "session write-back failed", {
1525
- error: String(e?.message || e).slice(0, 200)
1542
+ error: describeError(e)
1526
1543
  });
1527
1544
  diag(harness, "retain_failed", {
1528
1545
  ms: Date.now() - t0,
1529
- error: String(e?.message || e).slice(0, 200),
1546
+ error: describeError(e),
1530
1547
  session: sessionId
1531
1548
  });
1532
1549
  }