@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.
- package/dist/antigravity-hook.js +15 -1
- package/dist/antigravity-stop-hook.js +35 -11
- package/dist/claude-hook.js +15 -1
- package/dist/claude-sessionstart-hook.js +13 -2
- package/dist/claude-stop-hook.js +35 -11
- package/dist/cline.js +29 -11
- package/dist/codex-hook.js +15 -1
- package/dist/codex-sessionstart-hook.js +13 -2
- package/dist/codex-stop-hook.js +35 -11
- package/dist/copilot-hook.js +15 -1
- package/dist/copilot-sessionstart-hook.js +13 -2
- package/dist/copilot-stop-hook.js +35 -11
- package/dist/cursor-hook.js +15 -1
- package/dist/cursor-sessionstart-hook.js +13 -2
- package/dist/cursor-stop-hook.js +35 -11
- package/dist/daemon-start.js +4 -1
- package/dist/deepen.js +4 -1
- package/dist/devin-hook.js +15 -1
- package/dist/devin-sessionstart-hook.js +13 -2
- package/dist/devin-stop-hook.js +35 -11
- package/dist/grok-hook.js +15 -1
- package/dist/grok-sessionstart-hook.js +13 -2
- package/dist/grok-stop-hook.js +35 -11
- package/dist/index.js +47 -11
- package/dist/installer.js +11 -1
- package/dist/kilo.js +47 -11
- package/dist/prime-agent.js +29 -11
- package/package.json +1 -1
package/dist/cline.js
CHANGED
|
@@ -1010,11 +1010,14 @@ var log = {
|
|
|
1010
1010
|
};
|
|
1011
1011
|
|
|
1012
1012
|
// src/core/diag.ts
|
|
1013
|
+
function diagFilePath() {
|
|
1014
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
1015
|
+
}
|
|
1013
1016
|
function diag(harness, event, extra = {}) {
|
|
1014
1017
|
log.debug(harness, `diag:${event}`, extra);
|
|
1015
1018
|
try {
|
|
1016
1019
|
appendFileSync2(
|
|
1017
|
-
|
|
1020
|
+
diagFilePath(),
|
|
1018
1021
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
1019
1022
|
);
|
|
1020
1023
|
} catch {
|
|
@@ -15641,6 +15644,7 @@ function resolveClaudeBin(explicit) {
|
|
|
15641
15644
|
}
|
|
15642
15645
|
return "claude";
|
|
15643
15646
|
}
|
|
15647
|
+
var SURVEY_AGENT = "hindsight-survey";
|
|
15644
15648
|
function resolveAgentBin(harness, claudeBin) {
|
|
15645
15649
|
switch (harness) {
|
|
15646
15650
|
case "claude-code":
|
|
@@ -15761,7 +15765,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
15761
15765
|
case "opencode": {
|
|
15762
15766
|
return {
|
|
15763
15767
|
bin,
|
|
15764
|
-
args: ["run", "--agent",
|
|
15768
|
+
args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
|
|
15765
15769
|
env
|
|
15766
15770
|
};
|
|
15767
15771
|
}
|
|
@@ -16073,10 +16077,10 @@ async function supportsAppend(client) {
|
|
|
16073
16077
|
return false;
|
|
16074
16078
|
}
|
|
16075
16079
|
}
|
|
16080
|
+
var DEFAULT_RETRY_WINDOW_MS = 6e4;
|
|
16076
16081
|
var RETAIN_RETRY_ATTEMPTS = 2;
|
|
16077
|
-
var
|
|
16078
|
-
async function submitWithRetry(send, isStillNewest) {
|
|
16079
|
-
let spent = 0;
|
|
16082
|
+
var REQUEST_BUDGET_MS = 15e3;
|
|
16083
|
+
async function submitWithRetry(send, isStillNewest, retryUntil) {
|
|
16080
16084
|
for (let attempt = 0; ; attempt++) {
|
|
16081
16085
|
try {
|
|
16082
16086
|
return await send();
|
|
@@ -16084,8 +16088,7 @@ async function submitWithRetry(send, isStillNewest) {
|
|
|
16084
16088
|
const limited = e instanceof RateLimitedError;
|
|
16085
16089
|
if (!limited || attempt >= RETAIN_RETRY_ATTEMPTS || !isStillNewest()) throw e;
|
|
16086
16090
|
const wait = e.retryAfterMs || 1e3;
|
|
16087
|
-
if (wait
|
|
16088
|
-
spent += wait;
|
|
16091
|
+
if (Date.now() + wait + REQUEST_BUDGET_MS > retryUntil) throw e;
|
|
16089
16092
|
await sleep(wait);
|
|
16090
16093
|
}
|
|
16091
16094
|
}
|
|
@@ -16105,14 +16108,24 @@ function serialize(cursors, sessionId2, write2) {
|
|
|
16105
16108
|
}
|
|
16106
16109
|
async function retainLiveSession(client, sessionId2, turns, startTs, harness, opts = {}) {
|
|
16107
16110
|
const cursors = opts.cursors;
|
|
16108
|
-
if (!cursors)
|
|
16111
|
+
if (!cursors)
|
|
16112
|
+
return writeSession(
|
|
16113
|
+
client,
|
|
16114
|
+
sessionId2,
|
|
16115
|
+
turns,
|
|
16116
|
+
startTs,
|
|
16117
|
+
harness,
|
|
16118
|
+
opts.stamp,
|
|
16119
|
+
void 0,
|
|
16120
|
+
opts.retryUntil
|
|
16121
|
+
);
|
|
16109
16122
|
return serialize(
|
|
16110
16123
|
cursors,
|
|
16111
16124
|
sessionId2,
|
|
16112
|
-
() => writeSession(client, sessionId2, turns, startTs, harness, opts.stamp, cursors)
|
|
16125
|
+
() => writeSession(client, sessionId2, turns, startTs, harness, opts.stamp, cursors, opts.retryUntil)
|
|
16113
16126
|
);
|
|
16114
16127
|
}
|
|
16115
|
-
async function writeSession(client, sessionId2, turns, startTs, harness, stamp, cursors) {
|
|
16128
|
+
async function writeSession(client, sessionId2, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16116
16129
|
const refId = `conversation:${sessionId2}`;
|
|
16117
16130
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16118
16131
|
const plan = planRetain(turns, cursors?.read(sessionId2), { appendSupported, bank: client.bank });
|
|
@@ -16164,7 +16177,8 @@ ${content}`),
|
|
|
16164
16177
|
if (!cursors) return true;
|
|
16165
16178
|
const now = cursors.read(sessionId2);
|
|
16166
16179
|
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16167
|
-
}
|
|
16180
|
+
},
|
|
16181
|
+
retryUntil
|
|
16168
16182
|
);
|
|
16169
16183
|
cursors?.write(sessionId2, next);
|
|
16170
16184
|
}
|
|
@@ -16466,6 +16480,7 @@ async function buildHookOutput(args) {
|
|
|
16466
16480
|
const turns = (cached2.turns ?? 0) + 1;
|
|
16467
16481
|
let reflectAnswer = cached2.reflectAnswer;
|
|
16468
16482
|
let reflectRanThisTurn = false;
|
|
16483
|
+
let reflectFailed = false;
|
|
16469
16484
|
const deferInitialReflect = cached2.deferInitialReflect === true;
|
|
16470
16485
|
if (deferInitialReflect) {
|
|
16471
16486
|
diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
|
|
@@ -16490,6 +16505,7 @@ async function buildHookOutput(args) {
|
|
|
16490
16505
|
});
|
|
16491
16506
|
} catch (e) {
|
|
16492
16507
|
reflectAnswer = "";
|
|
16508
|
+
reflectFailed = true;
|
|
16493
16509
|
log.warn(harness, "reflect failed \u2014 session runs without memory", {
|
|
16494
16510
|
error: String(e?.message || e).slice(0, 200)
|
|
16495
16511
|
});
|
|
@@ -16537,6 +16553,8 @@ async function buildHookOutput(args) {
|
|
|
16537
16553
|
const preview = reflectAnswer.replace(/\s+/g, " ").trim();
|
|
16538
16554
|
notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
|
|
16539
16555
|
\u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
|
|
16556
|
+
} else if (reflectFailed) {
|
|
16557
|
+
notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
|
|
16540
16558
|
}
|
|
16541
16559
|
return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
|
|
16542
16560
|
}
|
package/dist/codex-hook.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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",
|
|
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,
|
package/dist/codex-stop-hook.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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)
|
|
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,
|
package/dist/copilot-hook.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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",
|
|
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,
|