@vectorize-io/hindsight-coding-agents 0.5.4 → 0.6.0
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/README.md +24 -7
- package/dist/antigravity-hook.js +205 -81
- package/dist/antigravity-statusline.js +32 -22
- package/dist/antigravity-stop-hook.js +216 -79
- package/dist/claude-hook.js +205 -81
- package/dist/claude-sessionstart-hook.js +167 -105
- package/dist/claude-stop-hook.js +216 -79
- package/dist/cline.js +279 -86
- package/dist/codex-hook.js +205 -81
- package/dist/codex-sessionstart-hook.js +167 -105
- package/dist/codex-stop-hook.js +216 -79
- package/dist/copilot-hook.js +205 -81
- package/dist/copilot-sessionstart-hook.js +167 -105
- package/dist/copilot-stop-hook.js +216 -79
- package/dist/cursor-hook.js +205 -81
- package/dist/cursor-sessionstart-hook.js +167 -105
- package/dist/cursor-stop-hook.js +216 -79
- package/dist/daemon-start.js +28 -18
- package/dist/dcode-hook.js +205 -81
- package/dist/dcode-sessionstart-hook.js +167 -105
- package/dist/dcode-stop-hook.js +216 -79
- package/dist/deepen.js +98 -40
- package/dist/devin-hook.js +205 -81
- package/dist/devin-sessionstart-hook.js +167 -105
- package/dist/devin-stop-hook.js +216 -79
- package/dist/droid-hook.js +205 -81
- package/dist/droid-sessionstart-hook.js +167 -105
- package/dist/droid-stop-hook.js +216 -79
- package/dist/dsh.js +277 -85
- package/dist/grok-hook.js +205 -81
- package/dist/grok-sessionstart-hook.js +167 -105
- package/dist/grok-stop-hook.js +216 -79
- package/dist/hindsight-seed.js +32 -22
- package/dist/index.js +280 -88
- package/dist/installer.js +308 -214
- package/dist/kilo.js +280 -88
- package/dist/mcp-server.js +97 -39
- package/dist/opencode2.js +279 -87
- package/dist/pi.js +279 -87
- package/dist/prime-agent.js +279 -87
- package/dist/qwen-hook.js +205 -81
- package/dist/qwen-sessionstart-hook.js +167 -105
- package/dist/qwen-stop-hook.js +216 -79
- package/dist/status.js +94 -36
- package/dist/zcode-hook.js +205 -81
- package/dist/zcode-sessionstart-hook.js +167 -105
- package/dist/zcode-stop-hook.js +216 -79
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +24 -7
|
@@ -5,16 +5,28 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
|
5
5
|
|
|
6
6
|
// src/core/bank.ts
|
|
7
7
|
import { existsSync } from "fs";
|
|
8
|
-
import { homedir } from "os";
|
|
9
|
-
import { basename, dirname as dirname3, join as
|
|
8
|
+
import { homedir as homedir2 } from "os";
|
|
9
|
+
import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
|
|
10
10
|
|
|
11
11
|
// src/core/diag.ts
|
|
12
|
-
import {
|
|
12
|
+
import { join as join2 } from "path";
|
|
13
13
|
|
|
14
14
|
// src/core/log.ts
|
|
15
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
16
|
-
import {
|
|
15
|
+
import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
16
|
+
import { homedir } from "os";
|
|
17
17
|
import { dirname, join } from "path";
|
|
18
|
+
function logsDir() {
|
|
19
|
+
return join(homedir(), ".hindsight", "coding-agents-logs");
|
|
20
|
+
}
|
|
21
|
+
var LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
22
|
+
function appendLogLine(file, text) {
|
|
23
|
+
mkdirSync(dirname(file), { recursive: true, mode: 448 });
|
|
24
|
+
try {
|
|
25
|
+
if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
appendFileSync(file, text, { mode: 384 });
|
|
29
|
+
}
|
|
18
30
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
19
31
|
var current = ["debug", "info", "warn", "error"].find(
|
|
20
32
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
@@ -23,15 +35,13 @@ function setLogLevel(level) {
|
|
|
23
35
|
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
24
36
|
}
|
|
25
37
|
function logFilePath() {
|
|
26
|
-
return process.env.HINDSIGHT_LOG_FILE || join(
|
|
38
|
+
return process.env.HINDSIGHT_LOG_FILE || join(logsDir(), "plugin.log");
|
|
27
39
|
}
|
|
28
40
|
function write(level, scope, msg, extra) {
|
|
29
41
|
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
30
42
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
appendFileSync(
|
|
34
|
-
file,
|
|
43
|
+
appendLogLine(
|
|
44
|
+
logFilePath(),
|
|
35
45
|
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
36
46
|
);
|
|
37
47
|
} catch {
|
|
@@ -60,12 +70,12 @@ function describeError(value, maxChars = 200) {
|
|
|
60
70
|
|
|
61
71
|
// src/core/diag.ts
|
|
62
72
|
function diagFilePath() {
|
|
63
|
-
return process.env.HINDSIGHT_DIAG_FILE || "
|
|
73
|
+
return process.env.HINDSIGHT_DIAG_FILE || join2(logsDir(), "diag.jsonl");
|
|
64
74
|
}
|
|
65
75
|
function diag(harness, event, extra = {}) {
|
|
66
76
|
log.debug(harness, `diag:${event}`, extra);
|
|
67
77
|
try {
|
|
68
|
-
|
|
78
|
+
appendLogLine(
|
|
69
79
|
diagFilePath(),
|
|
70
80
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
71
81
|
);
|
|
@@ -75,7 +85,7 @@ function diag(harness, event, extra = {}) {
|
|
|
75
85
|
|
|
76
86
|
// src/core/git-layout.ts
|
|
77
87
|
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
78
|
-
import { dirname as dirname2, isAbsolute, join as
|
|
88
|
+
import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
|
|
79
89
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
80
90
|
var ATTEMPTS = 3;
|
|
81
91
|
var BACKOFF_MS = 20;
|
|
@@ -111,16 +121,16 @@ function gitDirFromPointer(text, holder) {
|
|
|
111
121
|
return isAbsolute(target) ? target : resolve(holder, target);
|
|
112
122
|
}
|
|
113
123
|
function commonDirOf(gitDir) {
|
|
114
|
-
const pointer = entryKind(
|
|
124
|
+
const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
|
|
115
125
|
if (!pointer) return gitDir;
|
|
116
126
|
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
117
127
|
}
|
|
118
128
|
function isBare(commonDir) {
|
|
119
|
-
const config = readTextOrNull(
|
|
129
|
+
const config = readTextOrNull(join3(commonDir, "config"));
|
|
120
130
|
return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
|
|
121
131
|
}
|
|
122
132
|
function looksLikeBareRepository(directory) {
|
|
123
|
-
return entryKind(
|
|
133
|
+
return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
|
|
124
134
|
}
|
|
125
135
|
function canonical(path) {
|
|
126
136
|
try {
|
|
@@ -137,7 +147,7 @@ function resolved(commonDir) {
|
|
|
137
147
|
function probeOnce(directory) {
|
|
138
148
|
let current2 = resolve(directory);
|
|
139
149
|
for (; ; ) {
|
|
140
|
-
const dotGit =
|
|
150
|
+
const dotGit = join3(current2, ".git");
|
|
141
151
|
const kind = entryKind(dotGit);
|
|
142
152
|
if (kind === "dir") {
|
|
143
153
|
const layout = resolved(commonDirOf(dotGit));
|
|
@@ -251,7 +261,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
|
251
261
|
return dirName(sessionRoot || directory);
|
|
252
262
|
}
|
|
253
263
|
function configuredDir(dir) {
|
|
254
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
264
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
|
|
255
265
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
256
266
|
}
|
|
257
267
|
function isWithin(directory, configured) {
|
|
@@ -325,12 +335,12 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
|
|
|
325
335
|
|
|
326
336
|
// src/core/config.ts
|
|
327
337
|
import { readFileSync as readFileSync2 } from "fs";
|
|
328
|
-
import { homedir as
|
|
329
|
-
import { join as
|
|
338
|
+
import { homedir as homedir3 } from "os";
|
|
339
|
+
import { join as join7 } from "path";
|
|
330
340
|
|
|
331
341
|
// src/core/seed.ts
|
|
332
342
|
import { spawn as realSpawn } from "child_process";
|
|
333
|
-
import { dirname as dirname4, join as
|
|
343
|
+
import { dirname as dirname4, join as join5 } from "path";
|
|
334
344
|
import { fileURLToPath } from "url";
|
|
335
345
|
var DEFAULT_SEED_LIMIT = 300;
|
|
336
346
|
|
|
@@ -566,7 +576,7 @@ function codingBankManifest(overrides) {
|
|
|
566
576
|
|
|
567
577
|
// src/core/util.ts
|
|
568
578
|
import { accessSync, constants } from "fs";
|
|
569
|
-
import { delimiter, join as
|
|
579
|
+
import { delimiter, join as join6 } from "path";
|
|
570
580
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
571
581
|
function semverGte(version, min) {
|
|
572
582
|
const parts = (v) => {
|
|
@@ -629,6 +639,22 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
629
639
|
}
|
|
630
640
|
};
|
|
631
641
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
642
|
+
var ReflectError = class extends Error {
|
|
643
|
+
constructor(message, status, timedOut, options) {
|
|
644
|
+
super(message, options);
|
|
645
|
+
this.status = status;
|
|
646
|
+
this.timedOut = timedOut;
|
|
647
|
+
this.name = "ReflectError";
|
|
648
|
+
}
|
|
649
|
+
status;
|
|
650
|
+
timedOut;
|
|
651
|
+
/** A timeout or a 5xx means reflect's synthesis (the slow LLM path) broke, while the cheap
|
|
652
|
+
* retrieval endpoints may still answer — worth falling back. A 4xx will fail the same way on
|
|
653
|
+
* every endpoint (auth, missing bank), so it is not. */
|
|
654
|
+
get fallbackEligible() {
|
|
655
|
+
return this.timedOut || this.status !== void 0 && this.status >= 500;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
632
658
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
633
659
|
var POLL_CYCLE_MS = 5e3;
|
|
634
660
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
@@ -712,11 +738,11 @@ var HindsightClient = class {
|
|
|
712
738
|
return `${this.apiUrl}/v1/default/banks/${encodeURIComponent(this.bank)}${suffix}`;
|
|
713
739
|
}
|
|
714
740
|
/** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
|
|
715
|
-
async req(method, url, body, tolerate = []) {
|
|
741
|
+
async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
|
|
716
742
|
const r = await this.fetchWithAuth(url, {
|
|
717
743
|
method,
|
|
718
744
|
body: body ? JSON.stringify(body) : void 0,
|
|
719
|
-
signal: AbortSignal.timeout(
|
|
745
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
720
746
|
});
|
|
721
747
|
if (r.status === 429 && !tolerate.includes(429))
|
|
722
748
|
throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
|
|
@@ -909,7 +935,7 @@ var HindsightClient = class {
|
|
|
909
935
|
/**
|
|
910
936
|
* Reflect: synthesized, root-cause answer over the bank. Bounded so a slow server never hangs a
|
|
911
937
|
* caller — but `timeoutMs` is REQUIRED, deliberately: the right deadline differs by an order of
|
|
912
|
-
* magnitude between the automatic hook (
|
|
938
|
+
* magnitude between the automatic hook (20s, to fit the host's window) and the agent-invoked
|
|
913
939
|
* tool (minutes, on a populated bank). This used to default to 120s, which silently overrode the
|
|
914
940
|
* tool's configured window and aborted every high-budget synthesis mid-flight (#3590).
|
|
915
941
|
*/
|
|
@@ -923,19 +949,45 @@ var HindsightClient = class {
|
|
|
923
949
|
signal: ctrl.signal
|
|
924
950
|
});
|
|
925
951
|
if (!resp.ok)
|
|
926
|
-
throw new
|
|
927
|
-
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}
|
|
952
|
+
throw new ReflectError(
|
|
953
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`,
|
|
954
|
+
resp.status,
|
|
955
|
+
false
|
|
928
956
|
);
|
|
929
957
|
const data = await resp.json();
|
|
930
958
|
return (data.text || "").trim();
|
|
931
959
|
} catch (e) {
|
|
932
960
|
if (ctrl.signal.aborted)
|
|
933
|
-
throw new
|
|
961
|
+
throw new ReflectError(`reflect timed out after ${opts.timeoutMs}ms`, void 0, true, {
|
|
962
|
+
cause: e
|
|
963
|
+
});
|
|
934
964
|
throw e;
|
|
935
965
|
} finally {
|
|
936
966
|
clearTimeout(timer);
|
|
937
967
|
}
|
|
938
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
|
|
971
|
+
* when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
|
|
972
|
+
*/
|
|
973
|
+
async recallObservations(query, opts) {
|
|
974
|
+
const r = await this.req(
|
|
975
|
+
"POST",
|
|
976
|
+
this.bankUrl("/memories/recall"),
|
|
977
|
+
{
|
|
978
|
+
query,
|
|
979
|
+
types: ["observation"],
|
|
980
|
+
budget: "low",
|
|
981
|
+
max_tokens: opts.maxTokens,
|
|
982
|
+
include: { entities: null }
|
|
983
|
+
},
|
|
984
|
+
[],
|
|
985
|
+
opts.timeoutMs
|
|
986
|
+
);
|
|
987
|
+
if (r.status === 404) return [];
|
|
988
|
+
const j = await r.json();
|
|
989
|
+
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
990
|
+
}
|
|
939
991
|
/**
|
|
940
992
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
941
993
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -1000,10 +1052,16 @@ var HindsightClient = class {
|
|
|
1000
1052
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1001
1053
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1002
1054
|
* hindsight_search_knowledge_pages. */
|
|
1003
|
-
async searchKnowledgePages(query, limit = 3) {
|
|
1055
|
+
async searchKnowledgePages(query, limit = 3, timeoutMs) {
|
|
1004
1056
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1005
1057
|
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1006
|
-
const r = await this.req(
|
|
1058
|
+
const r = await this.req(
|
|
1059
|
+
"GET",
|
|
1060
|
+
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1061
|
+
void 0,
|
|
1062
|
+
[],
|
|
1063
|
+
timeoutMs
|
|
1064
|
+
);
|
|
1007
1065
|
const j = await r.json();
|
|
1008
1066
|
return (j.results ?? []).map((x) => ({
|
|
1009
1067
|
id: x.id,
|
|
@@ -1190,7 +1248,7 @@ var HindsightClient = class {
|
|
|
1190
1248
|
};
|
|
1191
1249
|
|
|
1192
1250
|
// src/core/config.ts
|
|
1193
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1251
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
|
|
1194
1252
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1195
1253
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1196
1254
|
function resolvePageTrigger(raw) {
|
|
@@ -1447,15 +1505,15 @@ function resolvePartial(cfg, patch) {
|
|
|
1447
1505
|
}
|
|
1448
1506
|
|
|
1449
1507
|
// src/core/session-cache.ts
|
|
1450
|
-
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
|
|
1451
|
-
import { tmpdir
|
|
1452
|
-
import { dirname as dirname5, join as
|
|
1508
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, writeFileSync } from "fs";
|
|
1509
|
+
import { tmpdir } from "os";
|
|
1510
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1453
1511
|
function writeFileAtomic(path, body) {
|
|
1454
1512
|
mkdirSync2(dirname5(path), { recursive: true });
|
|
1455
1513
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
1456
1514
|
try {
|
|
1457
1515
|
writeFileSync(tmp, body);
|
|
1458
|
-
|
|
1516
|
+
renameSync2(tmp, path);
|
|
1459
1517
|
} catch (e) {
|
|
1460
1518
|
try {
|
|
1461
1519
|
rmSync(tmp, { force: true });
|
|
@@ -1465,7 +1523,7 @@ function writeFileAtomic(path, body) {
|
|
|
1465
1523
|
}
|
|
1466
1524
|
}
|
|
1467
1525
|
function sessionRootFile(harness, sessionId) {
|
|
1468
|
-
return
|
|
1526
|
+
return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.root`);
|
|
1469
1527
|
}
|
|
1470
1528
|
function sessionRootDir(harness, sessionId, cwd) {
|
|
1471
1529
|
if (!sessionId || !cwd) return cwd;
|
|
@@ -1481,8 +1539,27 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1481
1539
|
}
|
|
1482
1540
|
return cwd;
|
|
1483
1541
|
}
|
|
1542
|
+
function fileUsageCursorStore(harness) {
|
|
1543
|
+
const file = (sessionId) => join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.usage.json`);
|
|
1544
|
+
return {
|
|
1545
|
+
read: (sessionId) => {
|
|
1546
|
+
try {
|
|
1547
|
+
const turns = JSON.parse(readFileSync3(file(sessionId), "utf8")).turns;
|
|
1548
|
+
return typeof turns === "number" ? turns : void 0;
|
|
1549
|
+
} catch {
|
|
1550
|
+
return void 0;
|
|
1551
|
+
}
|
|
1552
|
+
},
|
|
1553
|
+
write: (sessionId, turns) => {
|
|
1554
|
+
try {
|
|
1555
|
+
writeFileAtomic(file(sessionId), JSON.stringify({ turns }));
|
|
1556
|
+
} catch {
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1484
1561
|
function cursorFile(harness, sessionId) {
|
|
1485
|
-
return
|
|
1562
|
+
return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.retain.json`);
|
|
1486
1563
|
}
|
|
1487
1564
|
function fileCursorStore(harness) {
|
|
1488
1565
|
return {
|
|
@@ -1503,9 +1580,9 @@ function fileCursorStore(harness) {
|
|
|
1503
1580
|
}
|
|
1504
1581
|
|
|
1505
1582
|
// src/core/turn-journal.ts
|
|
1506
|
-
import { appendFileSync as
|
|
1507
|
-
import { tmpdir as
|
|
1508
|
-
import { dirname as dirname6, join as
|
|
1583
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync as statSync2 } from "fs";
|
|
1584
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
1585
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1509
1586
|
|
|
1510
1587
|
// src/core/transcript-util.ts
|
|
1511
1588
|
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
@@ -1545,20 +1622,20 @@ function actionLine(tool, input) {
|
|
|
1545
1622
|
// src/core/turn-journal.ts
|
|
1546
1623
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
1547
1624
|
function journalPath(harness, sessionId) {
|
|
1548
|
-
return
|
|
1625
|
+
return join9(tmpdir2(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
|
|
1549
1626
|
}
|
|
1550
1627
|
function appendJournalTurn(path, turn) {
|
|
1551
1628
|
const content = stripInjectedMemory(turn.content ?? "").trim();
|
|
1552
1629
|
if (!content) return;
|
|
1553
1630
|
try {
|
|
1554
|
-
if (
|
|
1631
|
+
if (statSync2(path).size >= JOURNAL_MAX_BYTES) return;
|
|
1555
1632
|
} catch {
|
|
1556
1633
|
}
|
|
1557
1634
|
const last = readJournalTranscript(path).at(-1);
|
|
1558
1635
|
if (last && last.role === turn.role && last.content === content) return;
|
|
1559
1636
|
try {
|
|
1560
1637
|
mkdirSync3(dirname6(path), { recursive: true });
|
|
1561
|
-
|
|
1638
|
+
appendFileSync2(
|
|
1562
1639
|
path,
|
|
1563
1640
|
JSON.stringify({
|
|
1564
1641
|
role: turn.role,
|
|
@@ -1599,7 +1676,7 @@ function readJournalTranscript(path) {
|
|
|
1599
1676
|
}
|
|
1600
1677
|
|
|
1601
1678
|
// src/core/retain-hook.ts
|
|
1602
|
-
import { readFileSync as
|
|
1679
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
1603
1680
|
|
|
1604
1681
|
// src/core/retain-cursor.ts
|
|
1605
1682
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -1792,7 +1869,7 @@ ${content}`);
|
|
|
1792
1869
|
|
|
1793
1870
|
// src/core/daemon.ts
|
|
1794
1871
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1795
|
-
import { dirname as dirname7, join as
|
|
1872
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
1796
1873
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1797
1874
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
1798
1875
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1866,7 +1943,7 @@ function onPath(bin) {
|
|
|
1866
1943
|
}
|
|
1867
1944
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
|
|
1868
1945
|
try {
|
|
1869
|
-
const starter =
|
|
1946
|
+
const starter = join10(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
|
|
1870
1947
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1871
1948
|
detached: true,
|
|
1872
1949
|
stdio: "ignore",
|
|
@@ -1967,7 +2044,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
1967
2044
|
}
|
|
1968
2045
|
|
|
1969
2046
|
// src/core/jsonl.ts
|
|
1970
|
-
import { closeSync, openSync, readSync, statSync as
|
|
2047
|
+
import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
|
|
1971
2048
|
import { StringDecoder } from "string_decoder";
|
|
1972
2049
|
var CHUNK_BYTES = 64 * 1024;
|
|
1973
2050
|
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
@@ -1975,7 +2052,7 @@ function readJsonlTail(path, opts) {
|
|
|
1975
2052
|
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1976
2053
|
let size;
|
|
1977
2054
|
try {
|
|
1978
|
-
size =
|
|
2055
|
+
size = statSync3(path).size;
|
|
1979
2056
|
} catch {
|
|
1980
2057
|
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1981
2058
|
}
|
|
@@ -2078,6 +2155,57 @@ function readClaudeTranscript(path) {
|
|
|
2078
2155
|
return turns;
|
|
2079
2156
|
}
|
|
2080
2157
|
|
|
2158
|
+
// src/core/usage.ts
|
|
2159
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
2160
|
+
import { join as join11 } from "path";
|
|
2161
|
+
function usageFilePath() {
|
|
2162
|
+
return process.env.HINDSIGHT_USAGE_FILE || join11(logsDir(), "usage.jsonl");
|
|
2163
|
+
}
|
|
2164
|
+
var HINDSIGHT_TOOL_RE = /hindsight_(?:[a-z]+_)*[a-z]+$/;
|
|
2165
|
+
var CREDIT_RE = /from hindsight memory/i;
|
|
2166
|
+
var ASSISTANT_ROLES = /* @__PURE__ */ new Set(["assistant", "model"]);
|
|
2167
|
+
function summarizeTurns(turns) {
|
|
2168
|
+
const out = [];
|
|
2169
|
+
for (const t of turns) {
|
|
2170
|
+
if (t.role === "user") {
|
|
2171
|
+
out.push({ turn: out.length + 1, calls: [], credited: false });
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
const current2 = out.at(-1);
|
|
2175
|
+
if (!current2) continue;
|
|
2176
|
+
if (t.role === "action") {
|
|
2177
|
+
const tool = t.content.split(" ", 1)[0].match(HINDSIGHT_TOOL_RE)?.[0];
|
|
2178
|
+
if (tool) current2.calls.push(tool);
|
|
2179
|
+
} else if (ASSISTANT_ROLES.has(t.role) && CREDIT_RE.test(t.content)) {
|
|
2180
|
+
current2.credited = true;
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
return out;
|
|
2184
|
+
}
|
|
2185
|
+
function recordUsage(args) {
|
|
2186
|
+
const summary = summarizeTurns(args.turns);
|
|
2187
|
+
const finished = args.lastTurnComplete ? summary : summary.slice(0, -1);
|
|
2188
|
+
const from = args.cursors.read(args.sessionId) ?? 0;
|
|
2189
|
+
if (finished.length <= from) return;
|
|
2190
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
2191
|
+
const lines = finished.slice(from).map(
|
|
2192
|
+
(u) => JSON.stringify({
|
|
2193
|
+
ts,
|
|
2194
|
+
harness: args.harness,
|
|
2195
|
+
session: args.sessionId,
|
|
2196
|
+
bank: args.bankId,
|
|
2197
|
+
turn: u.turn,
|
|
2198
|
+
calls: u.calls,
|
|
2199
|
+
credited: u.credited
|
|
2200
|
+
}) + "\n"
|
|
2201
|
+
).join("");
|
|
2202
|
+
try {
|
|
2203
|
+
appendLogLine(usageFilePath(), lines);
|
|
2204
|
+
args.cursors.write(args.sessionId, finished.length);
|
|
2205
|
+
} catch {
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2081
2209
|
// src/core/retain-hook.ts
|
|
2082
2210
|
var HOST_DEADLINE_MARGIN_MS = 2e3;
|
|
2083
2211
|
async function buildRetain(args) {
|
|
@@ -2094,6 +2222,14 @@ async function buildRetain(args) {
|
|
|
2094
2222
|
});
|
|
2095
2223
|
}
|
|
2096
2224
|
if (turns.length === 0) return;
|
|
2225
|
+
recordUsage({
|
|
2226
|
+
harness,
|
|
2227
|
+
sessionId,
|
|
2228
|
+
bankId: args.bankId ?? "",
|
|
2229
|
+
turns,
|
|
2230
|
+
cursors: args.usageCursors ?? fileUsageCursorStore(harness),
|
|
2231
|
+
lastTurnComplete: true
|
|
2232
|
+
});
|
|
2097
2233
|
const startTs = turns[0]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
2098
2234
|
const t0 = Date.now();
|
|
2099
2235
|
try {
|
|
@@ -2119,7 +2255,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2119
2255
|
const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
|
|
2120
2256
|
let ev = {};
|
|
2121
2257
|
try {
|
|
2122
|
-
ev = JSON.parse(
|
|
2258
|
+
ev = JSON.parse(readFileSync7(0, "utf8"));
|
|
2123
2259
|
} catch {
|
|
2124
2260
|
return;
|
|
2125
2261
|
}
|
|
@@ -2169,6 +2305,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2169
2305
|
lastAssistantMessage,
|
|
2170
2306
|
readLastMessage: spec.readLastMessage,
|
|
2171
2307
|
retryUntil: hostDeadline,
|
|
2308
|
+
bankId,
|
|
2172
2309
|
stamp: buildRetainStamp(cfg, {
|
|
2173
2310
|
directory: cwd,
|
|
2174
2311
|
sessionRoot,
|
|
@@ -2180,7 +2317,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2180
2317
|
}
|
|
2181
2318
|
|
|
2182
2319
|
// src/core/session-start.ts
|
|
2183
|
-
import { readFileSync as
|
|
2320
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
2184
2321
|
|
|
2185
2322
|
// src/core/git.ts
|
|
2186
2323
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -2193,8 +2330,8 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
2193
2330
|
import { spawn as realSpawn4 } from "child_process";
|
|
2194
2331
|
import { createHash as createHash4 } from "crypto";
|
|
2195
2332
|
import { existsSync as existsSync3 } from "fs";
|
|
2196
|
-
import { homedir as
|
|
2197
|
-
import { dirname as dirname8, join as
|
|
2333
|
+
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
2334
|
+
import { dirname as dirname8, join as join13 } from "path";
|
|
2198
2335
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2199
2336
|
|
|
2200
2337
|
// src/core/survey-lease.ts
|
|
@@ -2204,42 +2341,42 @@ import {
|
|
|
2204
2341
|
mkdirSync as mkdirSync4,
|
|
2205
2342
|
mkdtempSync,
|
|
2206
2343
|
readdirSync,
|
|
2207
|
-
renameSync as
|
|
2344
|
+
renameSync as renameSync3,
|
|
2208
2345
|
rmdirSync,
|
|
2209
2346
|
rmSync as rmSync2,
|
|
2210
|
-
statSync as
|
|
2347
|
+
statSync as statSync4,
|
|
2211
2348
|
unlinkSync,
|
|
2212
2349
|
utimesSync,
|
|
2213
2350
|
writeFileSync as writeFileSync2
|
|
2214
2351
|
} from "fs";
|
|
2215
|
-
import { join as
|
|
2352
|
+
import { join as join12 } from "path";
|
|
2216
2353
|
|
|
2217
2354
|
// src/core/auto-update.ts
|
|
2218
2355
|
import { spawn as realSpawn5 } from "child_process";
|
|
2219
2356
|
import {
|
|
2220
2357
|
existsSync as existsSync4,
|
|
2221
2358
|
mkdirSync as mkdirSync5,
|
|
2222
|
-
readFileSync as
|
|
2359
|
+
readFileSync as readFileSync8,
|
|
2223
2360
|
realpathSync as realpathSync2,
|
|
2224
2361
|
unlinkSync as unlinkSync2,
|
|
2225
2362
|
writeFileSync as writeFileSync3
|
|
2226
2363
|
} from "fs";
|
|
2227
|
-
import { homedir as
|
|
2228
|
-
import { dirname as dirname9, join as
|
|
2364
|
+
import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
|
|
2365
|
+
import { dirname as dirname9, join as join14 } from "path";
|
|
2229
2366
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2230
2367
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2231
2368
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2232
2369
|
|
|
2233
2370
|
// src/core/skill-sync.ts
|
|
2234
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
2235
|
-
import { homedir as
|
|
2236
|
-
import { dirname as dirname10, join as
|
|
2371
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
|
|
2372
|
+
import { homedir as homedir6 } from "os";
|
|
2373
|
+
import { dirname as dirname10, join as join15 } from "path";
|
|
2237
2374
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2238
2375
|
|
|
2239
2376
|
// src/core/legacy.ts
|
|
2240
|
-
import { existsSync as existsSync6, readFileSync as
|
|
2241
|
-
import { homedir as
|
|
2242
|
-
import { join as
|
|
2377
|
+
import { existsSync as existsSync6, readFileSync as readFileSync10 } from "fs";
|
|
2378
|
+
import { homedir as homedir7 } from "os";
|
|
2379
|
+
import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2243
2380
|
|
|
2244
2381
|
// src/core/transcript-codex.ts
|
|
2245
2382
|
function isSyntheticUserText(text) {
|
|
@@ -2371,19 +2508,19 @@ function readCopilotTranscript(path) {
|
|
|
2371
2508
|
}
|
|
2372
2509
|
|
|
2373
2510
|
// src/core/transcript-grok.ts
|
|
2374
|
-
import { existsSync as existsSync7, readFileSync as
|
|
2375
|
-
import { homedir as
|
|
2376
|
-
import { join as
|
|
2511
|
+
import { existsSync as existsSync7, readFileSync as readFileSync12, readdirSync as readdirSync2 } from "fs";
|
|
2512
|
+
import { homedir as homedir8 } from "os";
|
|
2513
|
+
import { join as join17 } from "path";
|
|
2377
2514
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2378
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2379
|
-
const sessionsDir =
|
|
2380
|
-
const direct =
|
|
2515
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join17(homedir8(), ".grok")) {
|
|
2516
|
+
const sessionsDir = join17(grokHome, "sessions");
|
|
2517
|
+
const direct = join17(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2381
2518
|
if (existsSync7(direct)) return direct;
|
|
2382
2519
|
try {
|
|
2383
2520
|
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2384
|
-
const directory =
|
|
2385
|
-
if (
|
|
2386
|
-
return
|
|
2521
|
+
const directory = join17(sessionsDir, candidate);
|
|
2522
|
+
if (readFileSync12(join17(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2523
|
+
return join17(directory, sessionId, CHAT_HISTORY);
|
|
2387
2524
|
}
|
|
2388
2525
|
}
|
|
2389
2526
|
} catch {
|
|
@@ -2420,10 +2557,10 @@ function readGrokTranscript(path) {
|
|
|
2420
2557
|
// src/core/transcript-devin.ts
|
|
2421
2558
|
import { existsSync as existsSync8 } from "fs";
|
|
2422
2559
|
import { createRequire } from "module";
|
|
2423
|
-
import { homedir as
|
|
2424
|
-
import { join as
|
|
2425
|
-
function devinSessionDb(home =
|
|
2426
|
-
return
|
|
2560
|
+
import { homedir as homedir9 } from "os";
|
|
2561
|
+
import { join as join18 } from "path";
|
|
2562
|
+
function devinSessionDb(home = homedir9()) {
|
|
2563
|
+
return join18(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2427
2564
|
}
|
|
2428
2565
|
function parseDevinMessages(nodes) {
|
|
2429
2566
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2733,7 +2870,7 @@ function readDroidTranscript(path) {
|
|
|
2733
2870
|
}
|
|
2734
2871
|
|
|
2735
2872
|
// src/core/transcript-zcode.ts
|
|
2736
|
-
import { readFileSync as
|
|
2873
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
2737
2874
|
function messageText2(content) {
|
|
2738
2875
|
if (typeof content === "string") return content.trim();
|
|
2739
2876
|
if (!Array.isArray(content)) return "";
|
|
@@ -2743,7 +2880,7 @@ function readZcodeTranscript(path) {
|
|
|
2743
2880
|
if (!path) return [];
|
|
2744
2881
|
let body;
|
|
2745
2882
|
try {
|
|
2746
|
-
body =
|
|
2883
|
+
body = readFileSync13(path, "utf8");
|
|
2747
2884
|
} catch {
|
|
2748
2885
|
return [];
|
|
2749
2886
|
}
|