@vectorize-io/hindsight-coding-agents 0.3.1 → 0.3.3

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.
@@ -351,11 +351,14 @@ var log = {
351
351
  };
352
352
 
353
353
  // src/core/diag.ts
354
+ function diagFilePath() {
355
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
356
+ }
354
357
  function diag(harness, event, extra = {}) {
355
358
  log.debug(harness, `diag:${event}`, extra);
356
359
  try {
357
360
  appendFileSync2(
358
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
361
+ diagFilePath(),
359
362
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
360
363
  );
361
364
  } catch {
@@ -1088,10 +1091,10 @@ async function supportsAppend(client) {
1088
1091
  return false;
1089
1092
  }
1090
1093
  }
1094
+ var DEFAULT_RETRY_WINDOW_MS = 6e4;
1091
1095
  var RETAIN_RETRY_ATTEMPTS = 2;
1092
- var RETAIN_RETRY_BUDGET_MS = 6e3;
1093
- async function submitWithRetry(send, isStillNewest) {
1094
- let spent = 0;
1096
+ var REQUEST_BUDGET_MS = 15e3;
1097
+ async function submitWithRetry(send, isStillNewest, retryUntil) {
1095
1098
  for (let attempt = 0; ; attempt++) {
1096
1099
  try {
1097
1100
  return await send();
@@ -1099,8 +1102,7 @@ async function submitWithRetry(send, isStillNewest) {
1099
1102
  const limited = e instanceof RateLimitedError;
1100
1103
  if (!limited || attempt >= RETAIN_RETRY_ATTEMPTS || !isStillNewest()) throw e;
1101
1104
  const wait = e.retryAfterMs || 1e3;
1102
- if (wait > RETAIN_RETRY_BUDGET_MS - spent) throw e;
1103
- spent += wait;
1105
+ if (Date.now() + wait + REQUEST_BUDGET_MS > retryUntil) throw e;
1104
1106
  await sleep(wait);
1105
1107
  }
1106
1108
  }
@@ -1120,14 +1122,24 @@ function serialize(cursors, sessionId, write2) {
1120
1122
  }
1121
1123
  async function retainLiveSession(client, sessionId, turns, startTs, harness, opts = {}) {
1122
1124
  const cursors = opts.cursors;
1123
- if (!cursors) return writeSession(client, sessionId, turns, startTs, harness, opts.stamp);
1125
+ if (!cursors)
1126
+ return writeSession(
1127
+ client,
1128
+ sessionId,
1129
+ turns,
1130
+ startTs,
1131
+ harness,
1132
+ opts.stamp,
1133
+ void 0,
1134
+ opts.retryUntil
1135
+ );
1124
1136
  return serialize(
1125
1137
  cursors,
1126
1138
  sessionId,
1127
- () => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors)
1139
+ () => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors, opts.retryUntil)
1128
1140
  );
1129
1141
  }
1130
- async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors) {
1142
+ async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
1131
1143
  const refId = `conversation:${sessionId}`;
1132
1144
  const appendSupported = Boolean(cursors) && await supportsAppend(client);
1133
1145
  const plan = planRetain(turns, cursors?.read(sessionId), { appendSupported, bank: client.bank });
@@ -1179,7 +1191,8 @@ ${content}`),
1179
1191
  if (!cursors) return true;
1180
1192
  const now = cursors.read(sessionId);
1181
1193
  return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
1182
- }
1194
+ },
1195
+ retryUntil
1183
1196
  );
1184
1197
  cursors?.write(sessionId, next);
1185
1198
  }
@@ -1495,6 +1508,7 @@ function readClaudeTranscript(path) {
1495
1508
  }
1496
1509
 
1497
1510
  // src/core/retain-hook.ts
1511
+ var HOST_DEADLINE_MARGIN_MS = 2e3;
1498
1512
  async function buildRetain(args) {
1499
1513
  const { harness, sessionId, transcriptPath, client } = args;
1500
1514
  const readTranscript = args.readTranscript ?? readClaudeTranscript;
@@ -1505,7 +1519,8 @@ async function buildRetain(args) {
1505
1519
  try {
1506
1520
  await retainLiveSession(client, sessionId, turns, startTs, harness, {
1507
1521
  cursors: args.cursors ?? fileCursorStore(harness),
1508
- stamp: args.stamp
1522
+ stamp: args.stamp,
1523
+ retryUntil: args.retryUntil
1509
1524
  });
1510
1525
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1511
1526
  } catch (e) {
@@ -1521,6 +1536,7 @@ async function buildRetain(args) {
1521
1536
  }
1522
1537
  async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
1523
1538
  if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
1539
+ const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
1524
1540
  let ev = {};
1525
1541
  try {
1526
1542
  ev = JSON.parse(readFileSync4(0, "utf8"));
@@ -1550,6 +1566,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
1550
1566
  transcriptPath,
1551
1567
  client,
1552
1568
  readTranscript: spec.readTranscript,
1569
+ retryUntil: hostDeadline,
1553
1570
  stamp: buildRetainStamp(cfg, {
1554
1571
  directory: cwd,
1555
1572
  harness: spec.harness,
@@ -1921,6 +1938,7 @@ var HOOK_HARNESSES = {
1921
1938
  sessionStart: standardSessionStart("claude-code"),
1922
1939
  prompt: claudePrompt,
1923
1940
  retain: {
1941
+ hostTimeoutSec: 60,
1924
1942
  harness: "claude-code",
1925
1943
  parse: (ev) => ({
1926
1944
  sessionId: ev.session_id,
@@ -1939,6 +1957,7 @@ var HOOK_HARNESSES = {
1939
1957
  sessionStart: standardSessionStart("codex"),
1940
1958
  prompt: codexPrompt,
1941
1959
  retain: {
1960
+ hostTimeoutSec: 60,
1942
1961
  harness: "codex",
1943
1962
  parse: (ev) => ({
1944
1963
  sessionId: ev.session_id,
@@ -1967,6 +1986,7 @@ var HOOK_HARNESSES = {
1967
1986
  },
1968
1987
  prompt: antigravityPrompt,
1969
1988
  retain: {
1989
+ hostTimeoutSec: 30,
1970
1990
  harness: "antigravity-cli",
1971
1991
  parse: (ev) => ({
1972
1992
  sessionId: ev.conversationId,
@@ -1995,6 +2015,7 @@ var HOOK_HARNESSES = {
1995
2015
  },
1996
2016
  prompt: cursorPrompt,
1997
2017
  retain: {
2018
+ hostTimeoutSec: 30,
1998
2019
  harness: "cursor-cli",
1999
2020
  parse: (ev) => ({
2000
2021
  sessionId: ev.conversation_id ?? ev.session_id,
@@ -2028,6 +2049,7 @@ var HOOK_HARNESSES = {
2028
2049
  },
2029
2050
  prompt: copilotPrompt,
2030
2051
  retain: {
2052
+ hostTimeoutSec: 60,
2031
2053
  harness: "copilot-cli",
2032
2054
  parse: (ev) => ({
2033
2055
  sessionId: ev.sessionId,
@@ -2056,6 +2078,7 @@ var HOOK_HARNESSES = {
2056
2078
  },
2057
2079
  prompt: devinPrompt,
2058
2080
  retain: {
2081
+ hostTimeoutSec: 60,
2059
2082
  harness: "devin-cli",
2060
2083
  parse: (ev) => {
2061
2084
  const sessionId = ev.session_id;
@@ -2095,6 +2118,7 @@ var HOOK_HARNESSES = {
2095
2118
  })
2096
2119
  },
2097
2120
  retain: {
2121
+ hostTimeoutSec: 60,
2098
2122
  harness: "grok-build",
2099
2123
  parse: (ev) => ({
2100
2124
  sessionId: ev.sessionId,
@@ -374,11 +374,14 @@ var log = {
374
374
  };
375
375
 
376
376
  // src/core/diag.ts
377
+ function diagFilePath() {
378
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
379
+ }
377
380
  function diag(harness, event, extra = {}) {
378
381
  log.debug(harness, `diag:${event}`, extra);
379
382
  try {
380
383
  appendFileSync2(
381
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
384
+ diagFilePath(),
382
385
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
383
386
  );
384
387
  } catch {
@@ -1136,6 +1139,7 @@ async function buildHookOutput(args) {
1136
1139
  const turns = (cached.turns ?? 0) + 1;
1137
1140
  let reflectAnswer = cached.reflectAnswer;
1138
1141
  let reflectRanThisTurn = false;
1142
+ let reflectFailed = false;
1139
1143
  const deferInitialReflect = cached.deferInitialReflect === true;
1140
1144
  if (deferInitialReflect) {
1141
1145
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -1160,6 +1164,7 @@ async function buildHookOutput(args) {
1160
1164
  });
1161
1165
  } catch (e) {
1162
1166
  reflectAnswer = "";
1167
+ reflectFailed = true;
1163
1168
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1164
1169
  error: String(e?.message || e).slice(0, 200)
1165
1170
  });
@@ -1207,6 +1212,8 @@ async function buildHookOutput(args) {
1207
1212
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
1208
1213
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
1209
1214
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
1215
+ } else if (reflectFailed) {
1216
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
1210
1217
  }
1211
1218
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
1212
1219
  }
@@ -1729,6 +1736,7 @@ var HOOK_HARNESSES = {
1729
1736
  sessionStart: standardSessionStart("claude-code"),
1730
1737
  prompt: claudePrompt,
1731
1738
  retain: {
1739
+ hostTimeoutSec: 60,
1732
1740
  harness: "claude-code",
1733
1741
  parse: (ev) => ({
1734
1742
  sessionId: ev.session_id,
@@ -1747,6 +1755,7 @@ var HOOK_HARNESSES = {
1747
1755
  sessionStart: standardSessionStart("codex"),
1748
1756
  prompt: codexPrompt,
1749
1757
  retain: {
1758
+ hostTimeoutSec: 60,
1750
1759
  harness: "codex",
1751
1760
  parse: (ev) => ({
1752
1761
  sessionId: ev.session_id,
@@ -1775,6 +1784,7 @@ var HOOK_HARNESSES = {
1775
1784
  },
1776
1785
  prompt: antigravityPrompt,
1777
1786
  retain: {
1787
+ hostTimeoutSec: 30,
1778
1788
  harness: "antigravity-cli",
1779
1789
  parse: (ev) => ({
1780
1790
  sessionId: ev.conversationId,
@@ -1803,6 +1813,7 @@ var HOOK_HARNESSES = {
1803
1813
  },
1804
1814
  prompt: cursorPrompt,
1805
1815
  retain: {
1816
+ hostTimeoutSec: 30,
1806
1817
  harness: "cursor-cli",
1807
1818
  parse: (ev) => ({
1808
1819
  sessionId: ev.conversation_id ?? ev.session_id,
@@ -1836,6 +1847,7 @@ var HOOK_HARNESSES = {
1836
1847
  },
1837
1848
  prompt: copilotPrompt,
1838
1849
  retain: {
1850
+ hostTimeoutSec: 60,
1839
1851
  harness: "copilot-cli",
1840
1852
  parse: (ev) => ({
1841
1853
  sessionId: ev.sessionId,
@@ -1864,6 +1876,7 @@ var HOOK_HARNESSES = {
1864
1876
  },
1865
1877
  prompt: devinPrompt,
1866
1878
  retain: {
1879
+ hostTimeoutSec: 60,
1867
1880
  harness: "devin-cli",
1868
1881
  parse: (ev) => {
1869
1882
  const sessionId = ev.session_id;
@@ -1903,6 +1916,7 @@ var HOOK_HARNESSES = {
1903
1916
  })
1904
1917
  },
1905
1918
  retain: {
1919
+ hostTimeoutSec: 60,
1906
1920
  harness: "grok-build",
1907
1921
  parse: (ev) => ({
1908
1922
  sessionId: ev.sessionId,
@@ -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
  }
@@ -2147,6 +2151,7 @@ var HOOK_HARNESSES = {
2147
2151
  sessionStart: standardSessionStart("claude-code"),
2148
2152
  prompt: claudePrompt,
2149
2153
  retain: {
2154
+ hostTimeoutSec: 60,
2150
2155
  harness: "claude-code",
2151
2156
  parse: (ev) => ({
2152
2157
  sessionId: ev.session_id,
@@ -2165,6 +2170,7 @@ var HOOK_HARNESSES = {
2165
2170
  sessionStart: standardSessionStart("codex"),
2166
2171
  prompt: codexPrompt,
2167
2172
  retain: {
2173
+ hostTimeoutSec: 60,
2168
2174
  harness: "codex",
2169
2175
  parse: (ev) => ({
2170
2176
  sessionId: ev.session_id,
@@ -2193,6 +2199,7 @@ var HOOK_HARNESSES = {
2193
2199
  },
2194
2200
  prompt: antigravityPrompt,
2195
2201
  retain: {
2202
+ hostTimeoutSec: 30,
2196
2203
  harness: "antigravity-cli",
2197
2204
  parse: (ev) => ({
2198
2205
  sessionId: ev.conversationId,
@@ -2221,6 +2228,7 @@ var HOOK_HARNESSES = {
2221
2228
  },
2222
2229
  prompt: cursorPrompt,
2223
2230
  retain: {
2231
+ hostTimeoutSec: 30,
2224
2232
  harness: "cursor-cli",
2225
2233
  parse: (ev) => ({
2226
2234
  sessionId: ev.conversation_id ?? ev.session_id,
@@ -2254,6 +2262,7 @@ var HOOK_HARNESSES = {
2254
2262
  },
2255
2263
  prompt: copilotPrompt,
2256
2264
  retain: {
2265
+ hostTimeoutSec: 60,
2257
2266
  harness: "copilot-cli",
2258
2267
  parse: (ev) => ({
2259
2268
  sessionId: ev.sessionId,
@@ -2282,6 +2291,7 @@ var HOOK_HARNESSES = {
2282
2291
  },
2283
2292
  prompt: devinPrompt,
2284
2293
  retain: {
2294
+ hostTimeoutSec: 60,
2285
2295
  harness: "devin-cli",
2286
2296
  parse: (ev) => {
2287
2297
  const sessionId = ev.session_id;
@@ -2321,6 +2331,7 @@ var HOOK_HARNESSES = {
2321
2331
  })
2322
2332
  },
2323
2333
  retain: {
2334
+ hostTimeoutSec: 60,
2324
2335
  harness: "grok-build",
2325
2336
  parse: (ev) => ({
2326
2337
  sessionId: ev.sessionId,
@@ -351,11 +351,14 @@ var log = {
351
351
  };
352
352
 
353
353
  // src/core/diag.ts
354
+ function diagFilePath() {
355
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
356
+ }
354
357
  function diag(harness, event, extra = {}) {
355
358
  log.debug(harness, `diag:${event}`, extra);
356
359
  try {
357
360
  appendFileSync2(
358
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
361
+ diagFilePath(),
359
362
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
360
363
  );
361
364
  } catch {
@@ -1088,10 +1091,10 @@ async function supportsAppend(client) {
1088
1091
  return false;
1089
1092
  }
1090
1093
  }
1094
+ var DEFAULT_RETRY_WINDOW_MS = 6e4;
1091
1095
  var RETAIN_RETRY_ATTEMPTS = 2;
1092
- var RETAIN_RETRY_BUDGET_MS = 6e3;
1093
- async function submitWithRetry(send, isStillNewest) {
1094
- let spent = 0;
1096
+ var REQUEST_BUDGET_MS = 15e3;
1097
+ async function submitWithRetry(send, isStillNewest, retryUntil) {
1095
1098
  for (let attempt = 0; ; attempt++) {
1096
1099
  try {
1097
1100
  return await send();
@@ -1099,8 +1102,7 @@ async function submitWithRetry(send, isStillNewest) {
1099
1102
  const limited = e instanceof RateLimitedError;
1100
1103
  if (!limited || attempt >= RETAIN_RETRY_ATTEMPTS || !isStillNewest()) throw e;
1101
1104
  const wait = e.retryAfterMs || 1e3;
1102
- if (wait > RETAIN_RETRY_BUDGET_MS - spent) throw e;
1103
- spent += wait;
1105
+ if (Date.now() + wait + REQUEST_BUDGET_MS > retryUntil) throw e;
1104
1106
  await sleep(wait);
1105
1107
  }
1106
1108
  }
@@ -1120,14 +1122,24 @@ function serialize(cursors, sessionId, write2) {
1120
1122
  }
1121
1123
  async function retainLiveSession(client, sessionId, turns, startTs, harness, opts = {}) {
1122
1124
  const cursors = opts.cursors;
1123
- if (!cursors) return writeSession(client, sessionId, turns, startTs, harness, opts.stamp);
1125
+ if (!cursors)
1126
+ return writeSession(
1127
+ client,
1128
+ sessionId,
1129
+ turns,
1130
+ startTs,
1131
+ harness,
1132
+ opts.stamp,
1133
+ void 0,
1134
+ opts.retryUntil
1135
+ );
1124
1136
  return serialize(
1125
1137
  cursors,
1126
1138
  sessionId,
1127
- () => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors)
1139
+ () => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors, opts.retryUntil)
1128
1140
  );
1129
1141
  }
1130
- async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors) {
1142
+ async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
1131
1143
  const refId = `conversation:${sessionId}`;
1132
1144
  const appendSupported = Boolean(cursors) && await supportsAppend(client);
1133
1145
  const plan = planRetain(turns, cursors?.read(sessionId), { appendSupported, bank: client.bank });
@@ -1179,7 +1191,8 @@ ${content}`),
1179
1191
  if (!cursors) return true;
1180
1192
  const now = cursors.read(sessionId);
1181
1193
  return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
1182
- }
1194
+ },
1195
+ retryUntil
1183
1196
  );
1184
1197
  cursors?.write(sessionId, next);
1185
1198
  }
@@ -1495,6 +1508,7 @@ function readClaudeTranscript(path) {
1495
1508
  }
1496
1509
 
1497
1510
  // src/core/retain-hook.ts
1511
+ var HOST_DEADLINE_MARGIN_MS = 2e3;
1498
1512
  async function buildRetain(args) {
1499
1513
  const { harness, sessionId, transcriptPath, client } = args;
1500
1514
  const readTranscript = args.readTranscript ?? readClaudeTranscript;
@@ -1505,7 +1519,8 @@ async function buildRetain(args) {
1505
1519
  try {
1506
1520
  await retainLiveSession(client, sessionId, turns, startTs, harness, {
1507
1521
  cursors: args.cursors ?? fileCursorStore(harness),
1508
- stamp: args.stamp
1522
+ stamp: args.stamp,
1523
+ retryUntil: args.retryUntil
1509
1524
  });
1510
1525
  diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
1511
1526
  } catch (e) {
@@ -1521,6 +1536,7 @@ async function buildRetain(args) {
1521
1536
  }
1522
1537
  async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
1523
1538
  if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
1539
+ const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
1524
1540
  let ev = {};
1525
1541
  try {
1526
1542
  ev = JSON.parse(readFileSync4(0, "utf8"));
@@ -1550,6 +1566,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
1550
1566
  transcriptPath,
1551
1567
  client,
1552
1568
  readTranscript: spec.readTranscript,
1569
+ retryUntil: hostDeadline,
1553
1570
  stamp: buildRetainStamp(cfg, {
1554
1571
  directory: cwd,
1555
1572
  harness: spec.harness,
@@ -1921,6 +1938,7 @@ var HOOK_HARNESSES = {
1921
1938
  sessionStart: standardSessionStart("claude-code"),
1922
1939
  prompt: claudePrompt,
1923
1940
  retain: {
1941
+ hostTimeoutSec: 60,
1924
1942
  harness: "claude-code",
1925
1943
  parse: (ev) => ({
1926
1944
  sessionId: ev.session_id,
@@ -1939,6 +1957,7 @@ var HOOK_HARNESSES = {
1939
1957
  sessionStart: standardSessionStart("codex"),
1940
1958
  prompt: codexPrompt,
1941
1959
  retain: {
1960
+ hostTimeoutSec: 60,
1942
1961
  harness: "codex",
1943
1962
  parse: (ev) => ({
1944
1963
  sessionId: ev.session_id,
@@ -1967,6 +1986,7 @@ var HOOK_HARNESSES = {
1967
1986
  },
1968
1987
  prompt: antigravityPrompt,
1969
1988
  retain: {
1989
+ hostTimeoutSec: 30,
1970
1990
  harness: "antigravity-cli",
1971
1991
  parse: (ev) => ({
1972
1992
  sessionId: ev.conversationId,
@@ -1995,6 +2015,7 @@ var HOOK_HARNESSES = {
1995
2015
  },
1996
2016
  prompt: cursorPrompt,
1997
2017
  retain: {
2018
+ hostTimeoutSec: 30,
1998
2019
  harness: "cursor-cli",
1999
2020
  parse: (ev) => ({
2000
2021
  sessionId: ev.conversation_id ?? ev.session_id,
@@ -2028,6 +2049,7 @@ var HOOK_HARNESSES = {
2028
2049
  },
2029
2050
  prompt: copilotPrompt,
2030
2051
  retain: {
2052
+ hostTimeoutSec: 60,
2031
2053
  harness: "copilot-cli",
2032
2054
  parse: (ev) => ({
2033
2055
  sessionId: ev.sessionId,
@@ -2056,6 +2078,7 @@ var HOOK_HARNESSES = {
2056
2078
  },
2057
2079
  prompt: devinPrompt,
2058
2080
  retain: {
2081
+ hostTimeoutSec: 60,
2059
2082
  harness: "devin-cli",
2060
2083
  parse: (ev) => {
2061
2084
  const sessionId = ev.session_id;
@@ -2095,6 +2118,7 @@ var HOOK_HARNESSES = {
2095
2118
  })
2096
2119
  },
2097
2120
  retain: {
2121
+ hostTimeoutSec: 60,
2098
2122
  harness: "grok-build",
2099
2123
  parse: (ev) => ({
2100
2124
  sessionId: ev.sessionId,
@@ -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
@@ -1266,11 +1266,14 @@ var log = {
1266
1266
  };
1267
1267
 
1268
1268
  // src/core/diag.ts
1269
+ function diagFilePath() {
1270
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
1271
+ }
1269
1272
  function diag(harness, event, extra = {}) {
1270
1273
  log.debug(harness, `diag:${event}`, extra);
1271
1274
  try {
1272
1275
  appendFileSync2(
1273
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
1276
+ diagFilePath(),
1274
1277
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
1275
1278
  );
1276
1279
  } catch {
@@ -374,11 +374,14 @@ var log = {
374
374
  };
375
375
 
376
376
  // src/core/diag.ts
377
+ function diagFilePath() {
378
+ return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
379
+ }
377
380
  function diag(harness, event, extra = {}) {
378
381
  log.debug(harness, `diag:${event}`, extra);
379
382
  try {
380
383
  appendFileSync2(
381
- process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log",
384
+ diagFilePath(),
382
385
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
383
386
  );
384
387
  } catch {
@@ -1136,6 +1139,7 @@ async function buildHookOutput(args) {
1136
1139
  const turns = (cached.turns ?? 0) + 1;
1137
1140
  let reflectAnswer = cached.reflectAnswer;
1138
1141
  let reflectRanThisTurn = false;
1142
+ let reflectFailed = false;
1139
1143
  const deferInitialReflect = cached.deferInitialReflect === true;
1140
1144
  if (deferInitialReflect) {
1141
1145
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -1160,6 +1164,7 @@ async function buildHookOutput(args) {
1160
1164
  });
1161
1165
  } catch (e) {
1162
1166
  reflectAnswer = "";
1167
+ reflectFailed = true;
1163
1168
  log.warn(harness, "reflect failed \u2014 session runs without memory", {
1164
1169
  error: String(e?.message || e).slice(0, 200)
1165
1170
  });
@@ -1207,6 +1212,8 @@ async function buildHookOutput(args) {
1207
1212
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
1208
1213
  notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
1209
1214
  \u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
1215
+ } else if (reflectFailed) {
1216
+ notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
1210
1217
  }
1211
1218
  return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
1212
1219
  }
@@ -1729,6 +1736,7 @@ var HOOK_HARNESSES = {
1729
1736
  sessionStart: standardSessionStart("claude-code"),
1730
1737
  prompt: claudePrompt,
1731
1738
  retain: {
1739
+ hostTimeoutSec: 60,
1732
1740
  harness: "claude-code",
1733
1741
  parse: (ev) => ({
1734
1742
  sessionId: ev.session_id,
@@ -1747,6 +1755,7 @@ var HOOK_HARNESSES = {
1747
1755
  sessionStart: standardSessionStart("codex"),
1748
1756
  prompt: codexPrompt,
1749
1757
  retain: {
1758
+ hostTimeoutSec: 60,
1750
1759
  harness: "codex",
1751
1760
  parse: (ev) => ({
1752
1761
  sessionId: ev.session_id,
@@ -1775,6 +1784,7 @@ var HOOK_HARNESSES = {
1775
1784
  },
1776
1785
  prompt: antigravityPrompt,
1777
1786
  retain: {
1787
+ hostTimeoutSec: 30,
1778
1788
  harness: "antigravity-cli",
1779
1789
  parse: (ev) => ({
1780
1790
  sessionId: ev.conversationId,
@@ -1803,6 +1813,7 @@ var HOOK_HARNESSES = {
1803
1813
  },
1804
1814
  prompt: cursorPrompt,
1805
1815
  retain: {
1816
+ hostTimeoutSec: 30,
1806
1817
  harness: "cursor-cli",
1807
1818
  parse: (ev) => ({
1808
1819
  sessionId: ev.conversation_id ?? ev.session_id,
@@ -1836,6 +1847,7 @@ var HOOK_HARNESSES = {
1836
1847
  },
1837
1848
  prompt: copilotPrompt,
1838
1849
  retain: {
1850
+ hostTimeoutSec: 60,
1839
1851
  harness: "copilot-cli",
1840
1852
  parse: (ev) => ({
1841
1853
  sessionId: ev.sessionId,
@@ -1864,6 +1876,7 @@ var HOOK_HARNESSES = {
1864
1876
  },
1865
1877
  prompt: devinPrompt,
1866
1878
  retain: {
1879
+ hostTimeoutSec: 60,
1867
1880
  harness: "devin-cli",
1868
1881
  parse: (ev) => {
1869
1882
  const sessionId = ev.session_id;
@@ -1903,6 +1916,7 @@ var HOOK_HARNESSES = {
1903
1916
  })
1904
1917
  },
1905
1918
  retain: {
1919
+ hostTimeoutSec: 60,
1906
1920
  harness: "grok-build",
1907
1921
  parse: (ev) => ({
1908
1922
  sessionId: ev.sessionId,