@vectorize-io/hindsight-coding-agents 0.5.5 → 0.6.1
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 +19 -5
- package/dist/antigravity-hook.js +87 -83
- package/dist/antigravity-statusline.js +32 -22
- package/dist/antigravity-stop-hook.js +160 -71
- package/dist/claude-hook.js +87 -83
- package/dist/claude-sessionstart-hook.js +111 -97
- package/dist/claude-stop-hook.js +160 -71
- package/dist/cline.js +161 -88
- package/dist/codex-hook.js +87 -83
- package/dist/codex-sessionstart-hook.js +111 -97
- package/dist/codex-stop-hook.js +160 -71
- package/dist/copilot-hook.js +87 -83
- package/dist/copilot-sessionstart-hook.js +111 -97
- package/dist/copilot-stop-hook.js +160 -71
- package/dist/cursor-hook.js +87 -83
- package/dist/cursor-sessionstart-hook.js +111 -97
- package/dist/cursor-stop-hook.js +160 -71
- package/dist/daemon-start.js +28 -18
- package/dist/dcode-hook.js +87 -83
- package/dist/dcode-sessionstart-hook.js +111 -97
- package/dist/dcode-stop-hook.js +160 -71
- package/dist/deepen.js +42 -32
- package/dist/devin-hook.js +87 -83
- package/dist/devin-sessionstart-hook.js +111 -97
- package/dist/devin-stop-hook.js +160 -71
- package/dist/droid-hook.js +87 -83
- package/dist/droid-sessionstart-hook.js +111 -97
- package/dist/droid-stop-hook.js +160 -71
- package/dist/dsh.js +159 -87
- package/dist/grok-hook.js +87 -83
- package/dist/grok-sessionstart-hook.js +111 -97
- package/dist/grok-stop-hook.js +160 -71
- package/dist/hindsight-seed.js +32 -22
- package/dist/index.js +162 -90
- package/dist/installer.js +308 -214
- package/dist/kilo.js +162 -90
- package/dist/mcp-server.js +41 -31
- package/dist/opencode2.js +161 -89
- package/dist/pi.js +161 -89
- package/dist/prime-agent.js +161 -89
- package/dist/qwen-hook.js +87 -83
- package/dist/qwen-sessionstart-hook.js +111 -97
- package/dist/qwen-stop-hook.js +160 -71
- package/dist/status.js +38 -28
- package/dist/zcode-hook.js +87 -83
- package/dist/zcode-sessionstart-hook.js +111 -97
- package/dist/zcode-stop-hook.js +160 -71
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +19 -5
package/dist/grok-stop-hook.js
CHANGED
|
@@ -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) => {
|
|
@@ -1238,7 +1248,7 @@ var HindsightClient = class {
|
|
|
1238
1248
|
};
|
|
1239
1249
|
|
|
1240
1250
|
// src/core/config.ts
|
|
1241
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1251
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
|
|
1242
1252
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1243
1253
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1244
1254
|
function resolvePageTrigger(raw) {
|
|
@@ -1495,15 +1505,15 @@ function resolvePartial(cfg, patch) {
|
|
|
1495
1505
|
}
|
|
1496
1506
|
|
|
1497
1507
|
// src/core/session-cache.ts
|
|
1498
|
-
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
|
|
1499
|
-
import { tmpdir
|
|
1500
|
-
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";
|
|
1501
1511
|
function writeFileAtomic(path, body) {
|
|
1502
1512
|
mkdirSync2(dirname5(path), { recursive: true });
|
|
1503
1513
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
1504
1514
|
try {
|
|
1505
1515
|
writeFileSync(tmp, body);
|
|
1506
|
-
|
|
1516
|
+
renameSync2(tmp, path);
|
|
1507
1517
|
} catch (e) {
|
|
1508
1518
|
try {
|
|
1509
1519
|
rmSync(tmp, { force: true });
|
|
@@ -1513,7 +1523,7 @@ function writeFileAtomic(path, body) {
|
|
|
1513
1523
|
}
|
|
1514
1524
|
}
|
|
1515
1525
|
function sessionRootFile(harness, sessionId) {
|
|
1516
|
-
return
|
|
1526
|
+
return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.root`);
|
|
1517
1527
|
}
|
|
1518
1528
|
function sessionRootDir(harness, sessionId, cwd) {
|
|
1519
1529
|
if (!sessionId || !cwd) return cwd;
|
|
@@ -1529,8 +1539,27 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1529
1539
|
}
|
|
1530
1540
|
return cwd;
|
|
1531
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
|
+
}
|
|
1532
1561
|
function cursorFile(harness, sessionId) {
|
|
1533
|
-
return
|
|
1562
|
+
return join8(tmpdir(), `hindsight-${harness}`, `${sessionId}.retain.json`);
|
|
1534
1563
|
}
|
|
1535
1564
|
function fileCursorStore(harness) {
|
|
1536
1565
|
return {
|
|
@@ -1551,9 +1580,9 @@ function fileCursorStore(harness) {
|
|
|
1551
1580
|
}
|
|
1552
1581
|
|
|
1553
1582
|
// src/core/turn-journal.ts
|
|
1554
|
-
import { appendFileSync as
|
|
1555
|
-
import { tmpdir as
|
|
1556
|
-
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";
|
|
1557
1586
|
|
|
1558
1587
|
// src/core/transcript-util.ts
|
|
1559
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;
|
|
@@ -1593,20 +1622,20 @@ function actionLine(tool, input) {
|
|
|
1593
1622
|
// src/core/turn-journal.ts
|
|
1594
1623
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
1595
1624
|
function journalPath(harness, sessionId) {
|
|
1596
|
-
return
|
|
1625
|
+
return join9(tmpdir2(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
|
|
1597
1626
|
}
|
|
1598
1627
|
function appendJournalTurn(path, turn) {
|
|
1599
1628
|
const content = stripInjectedMemory(turn.content ?? "").trim();
|
|
1600
1629
|
if (!content) return;
|
|
1601
1630
|
try {
|
|
1602
|
-
if (
|
|
1631
|
+
if (statSync2(path).size >= JOURNAL_MAX_BYTES) return;
|
|
1603
1632
|
} catch {
|
|
1604
1633
|
}
|
|
1605
1634
|
const last = readJournalTranscript(path).at(-1);
|
|
1606
1635
|
if (last && last.role === turn.role && last.content === content) return;
|
|
1607
1636
|
try {
|
|
1608
1637
|
mkdirSync3(dirname6(path), { recursive: true });
|
|
1609
|
-
|
|
1638
|
+
appendFileSync2(
|
|
1610
1639
|
path,
|
|
1611
1640
|
JSON.stringify({
|
|
1612
1641
|
role: turn.role,
|
|
@@ -1647,7 +1676,7 @@ function readJournalTranscript(path) {
|
|
|
1647
1676
|
}
|
|
1648
1677
|
|
|
1649
1678
|
// src/core/retain-hook.ts
|
|
1650
|
-
import { readFileSync as
|
|
1679
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
1651
1680
|
|
|
1652
1681
|
// src/core/retain-cursor.ts
|
|
1653
1682
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -1840,7 +1869,7 @@ ${content}`);
|
|
|
1840
1869
|
|
|
1841
1870
|
// src/core/daemon.ts
|
|
1842
1871
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1843
|
-
import { dirname as dirname7, join as
|
|
1872
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
1844
1873
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1845
1874
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
1846
1875
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1914,7 +1943,7 @@ function onPath(bin) {
|
|
|
1914
1943
|
}
|
|
1915
1944
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
|
|
1916
1945
|
try {
|
|
1917
|
-
const starter =
|
|
1946
|
+
const starter = join10(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
|
|
1918
1947
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1919
1948
|
detached: true,
|
|
1920
1949
|
stdio: "ignore",
|
|
@@ -2015,7 +2044,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
2015
2044
|
}
|
|
2016
2045
|
|
|
2017
2046
|
// src/core/jsonl.ts
|
|
2018
|
-
import { closeSync, openSync, readSync, statSync as
|
|
2047
|
+
import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
|
|
2019
2048
|
import { StringDecoder } from "string_decoder";
|
|
2020
2049
|
var CHUNK_BYTES = 64 * 1024;
|
|
2021
2050
|
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
@@ -2023,7 +2052,7 @@ function readJsonlTail(path, opts) {
|
|
|
2023
2052
|
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
2024
2053
|
let size;
|
|
2025
2054
|
try {
|
|
2026
|
-
size =
|
|
2055
|
+
size = statSync3(path).size;
|
|
2027
2056
|
} catch {
|
|
2028
2057
|
return { lines: emptyLines(), skippedBytes: 0 };
|
|
2029
2058
|
}
|
|
@@ -2126,6 +2155,57 @@ function readClaudeTranscript(path) {
|
|
|
2126
2155
|
return turns;
|
|
2127
2156
|
}
|
|
2128
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
|
+
|
|
2129
2209
|
// src/core/retain-hook.ts
|
|
2130
2210
|
var HOST_DEADLINE_MARGIN_MS = 2e3;
|
|
2131
2211
|
async function buildRetain(args) {
|
|
@@ -2142,6 +2222,14 @@ async function buildRetain(args) {
|
|
|
2142
2222
|
});
|
|
2143
2223
|
}
|
|
2144
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
|
+
});
|
|
2145
2233
|
const startTs = turns[0]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
2146
2234
|
const t0 = Date.now();
|
|
2147
2235
|
try {
|
|
@@ -2167,7 +2255,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2167
2255
|
const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
|
|
2168
2256
|
let ev = {};
|
|
2169
2257
|
try {
|
|
2170
|
-
ev = JSON.parse(
|
|
2258
|
+
ev = JSON.parse(readFileSync7(0, "utf8"));
|
|
2171
2259
|
} catch {
|
|
2172
2260
|
return;
|
|
2173
2261
|
}
|
|
@@ -2217,6 +2305,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2217
2305
|
lastAssistantMessage,
|
|
2218
2306
|
readLastMessage: spec.readLastMessage,
|
|
2219
2307
|
retryUntil: hostDeadline,
|
|
2308
|
+
bankId,
|
|
2220
2309
|
stamp: buildRetainStamp(cfg, {
|
|
2221
2310
|
directory: cwd,
|
|
2222
2311
|
sessionRoot,
|
|
@@ -2228,7 +2317,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2228
2317
|
}
|
|
2229
2318
|
|
|
2230
2319
|
// src/core/session-start.ts
|
|
2231
|
-
import { readFileSync as
|
|
2320
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
2232
2321
|
|
|
2233
2322
|
// src/core/git.ts
|
|
2234
2323
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -2241,8 +2330,8 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
2241
2330
|
import { spawn as realSpawn4 } from "child_process";
|
|
2242
2331
|
import { createHash as createHash4 } from "crypto";
|
|
2243
2332
|
import { existsSync as existsSync3 } from "fs";
|
|
2244
|
-
import { homedir as
|
|
2245
|
-
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";
|
|
2246
2335
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2247
2336
|
|
|
2248
2337
|
// src/core/survey-lease.ts
|
|
@@ -2252,42 +2341,42 @@ import {
|
|
|
2252
2341
|
mkdirSync as mkdirSync4,
|
|
2253
2342
|
mkdtempSync,
|
|
2254
2343
|
readdirSync,
|
|
2255
|
-
renameSync as
|
|
2344
|
+
renameSync as renameSync3,
|
|
2256
2345
|
rmdirSync,
|
|
2257
2346
|
rmSync as rmSync2,
|
|
2258
|
-
statSync as
|
|
2347
|
+
statSync as statSync4,
|
|
2259
2348
|
unlinkSync,
|
|
2260
2349
|
utimesSync,
|
|
2261
2350
|
writeFileSync as writeFileSync2
|
|
2262
2351
|
} from "fs";
|
|
2263
|
-
import { join as
|
|
2352
|
+
import { join as join12 } from "path";
|
|
2264
2353
|
|
|
2265
2354
|
// src/core/auto-update.ts
|
|
2266
2355
|
import { spawn as realSpawn5 } from "child_process";
|
|
2267
2356
|
import {
|
|
2268
2357
|
existsSync as existsSync4,
|
|
2269
2358
|
mkdirSync as mkdirSync5,
|
|
2270
|
-
readFileSync as
|
|
2359
|
+
readFileSync as readFileSync8,
|
|
2271
2360
|
realpathSync as realpathSync2,
|
|
2272
2361
|
unlinkSync as unlinkSync2,
|
|
2273
2362
|
writeFileSync as writeFileSync3
|
|
2274
2363
|
} from "fs";
|
|
2275
|
-
import { homedir as
|
|
2276
|
-
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";
|
|
2277
2366
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2278
2367
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2279
2368
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2280
2369
|
|
|
2281
2370
|
// src/core/skill-sync.ts
|
|
2282
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
2283
|
-
import { homedir as
|
|
2284
|
-
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";
|
|
2285
2374
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2286
2375
|
|
|
2287
2376
|
// src/core/legacy.ts
|
|
2288
|
-
import { existsSync as existsSync6, readFileSync as
|
|
2289
|
-
import { homedir as
|
|
2290
|
-
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";
|
|
2291
2380
|
|
|
2292
2381
|
// src/core/transcript-codex.ts
|
|
2293
2382
|
function isSyntheticUserText(text) {
|
|
@@ -2419,19 +2508,19 @@ function readCopilotTranscript(path) {
|
|
|
2419
2508
|
}
|
|
2420
2509
|
|
|
2421
2510
|
// src/core/transcript-grok.ts
|
|
2422
|
-
import { existsSync as existsSync7, readFileSync as
|
|
2423
|
-
import { homedir as
|
|
2424
|
-
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";
|
|
2425
2514
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2426
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2427
|
-
const sessionsDir =
|
|
2428
|
-
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);
|
|
2429
2518
|
if (existsSync7(direct)) return direct;
|
|
2430
2519
|
try {
|
|
2431
2520
|
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2432
|
-
const directory =
|
|
2433
|
-
if (
|
|
2434
|
-
return
|
|
2521
|
+
const directory = join17(sessionsDir, candidate);
|
|
2522
|
+
if (readFileSync12(join17(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2523
|
+
return join17(directory, sessionId, CHAT_HISTORY);
|
|
2435
2524
|
}
|
|
2436
2525
|
}
|
|
2437
2526
|
} catch {
|
|
@@ -2468,10 +2557,10 @@ function readGrokTranscript(path) {
|
|
|
2468
2557
|
// src/core/transcript-devin.ts
|
|
2469
2558
|
import { existsSync as existsSync8 } from "fs";
|
|
2470
2559
|
import { createRequire } from "module";
|
|
2471
|
-
import { homedir as
|
|
2472
|
-
import { join as
|
|
2473
|
-
function devinSessionDb(home =
|
|
2474
|
-
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");
|
|
2475
2564
|
}
|
|
2476
2565
|
function parseDevinMessages(nodes) {
|
|
2477
2566
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2781,7 +2870,7 @@ function readDroidTranscript(path) {
|
|
|
2781
2870
|
}
|
|
2782
2871
|
|
|
2783
2872
|
// src/core/transcript-zcode.ts
|
|
2784
|
-
import { readFileSync as
|
|
2873
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
2785
2874
|
function messageText2(content) {
|
|
2786
2875
|
if (typeof content === "string") return content.trim();
|
|
2787
2876
|
if (!Array.isArray(content)) return "";
|
|
@@ -2791,7 +2880,7 @@ function readZcodeTranscript(path) {
|
|
|
2791
2880
|
if (!path) return [];
|
|
2792
2881
|
let body;
|
|
2793
2882
|
try {
|
|
2794
|
-
body =
|
|
2883
|
+
body = readFileSync13(path, "utf8");
|
|
2795
2884
|
} catch {
|
|
2796
2885
|
return [];
|
|
2797
2886
|
}
|
package/dist/hindsight-seed.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// src/core/config.ts
|
|
4
4
|
import { readFileSync as readFileSync2 } from "fs";
|
|
5
|
-
import { homedir as
|
|
6
|
-
import { join as
|
|
5
|
+
import { homedir as homedir3 } from "os";
|
|
6
|
+
import { join as join7 } from "path";
|
|
7
7
|
|
|
8
8
|
// src/core/seed.ts
|
|
9
9
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -50,30 +50,40 @@ function seedControl(command2, args) {
|
|
|
50
50
|
|
|
51
51
|
// src/core/bank.ts
|
|
52
52
|
import { existsSync } from "fs";
|
|
53
|
-
import { homedir } from "os";
|
|
54
|
-
import { basename, dirname as dirname4, join as
|
|
53
|
+
import { homedir as homedir2 } from "os";
|
|
54
|
+
import { basename, dirname as dirname4, join as join5, normalize, sep } from "path";
|
|
55
55
|
|
|
56
56
|
// src/core/diag.ts
|
|
57
|
-
import {
|
|
57
|
+
import { join as join3 } from "path";
|
|
58
58
|
|
|
59
59
|
// src/core/log.ts
|
|
60
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
61
|
-
import {
|
|
60
|
+
import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
61
|
+
import { homedir } from "os";
|
|
62
62
|
import { dirname as dirname2, join as join2 } from "path";
|
|
63
|
+
function logsDir() {
|
|
64
|
+
return join2(homedir(), ".hindsight", "coding-agents-logs");
|
|
65
|
+
}
|
|
66
|
+
var LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
67
|
+
function appendLogLine(file, text) {
|
|
68
|
+
mkdirSync(dirname2(file), { recursive: true, mode: 448 });
|
|
69
|
+
try {
|
|
70
|
+
if (statSync(file).size >= LOG_MAX_BYTES) renameSync(file, `${file}.1`);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
appendFileSync(file, text, { mode: 384 });
|
|
74
|
+
}
|
|
63
75
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
64
76
|
var current = ["debug", "info", "warn", "error"].find(
|
|
65
77
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
66
78
|
) ?? "info";
|
|
67
79
|
function logFilePath() {
|
|
68
|
-
return process.env.HINDSIGHT_LOG_FILE || join2(
|
|
80
|
+
return process.env.HINDSIGHT_LOG_FILE || join2(logsDir(), "plugin.log");
|
|
69
81
|
}
|
|
70
82
|
function write(level, scope, msg, extra) {
|
|
71
83
|
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
72
84
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
appendFileSync(
|
|
76
|
-
file,
|
|
85
|
+
appendLogLine(
|
|
86
|
+
logFilePath(),
|
|
77
87
|
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
78
88
|
);
|
|
79
89
|
} catch {
|
|
@@ -88,12 +98,12 @@ var log = {
|
|
|
88
98
|
|
|
89
99
|
// src/core/diag.ts
|
|
90
100
|
function diagFilePath() {
|
|
91
|
-
return process.env.HINDSIGHT_DIAG_FILE || "
|
|
101
|
+
return process.env.HINDSIGHT_DIAG_FILE || join3(logsDir(), "diag.jsonl");
|
|
92
102
|
}
|
|
93
103
|
function diag(harness, event, extra = {}) {
|
|
94
104
|
log.debug(harness, `diag:${event}`, extra);
|
|
95
105
|
try {
|
|
96
|
-
|
|
106
|
+
appendLogLine(
|
|
97
107
|
diagFilePath(),
|
|
98
108
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
99
109
|
);
|
|
@@ -103,7 +113,7 @@ function diag(harness, event, extra = {}) {
|
|
|
103
113
|
|
|
104
114
|
// src/core/git-layout.ts
|
|
105
115
|
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
106
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
116
|
+
import { dirname as dirname3, isAbsolute, join as join4, resolve } from "path";
|
|
107
117
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
108
118
|
var ATTEMPTS = 3;
|
|
109
119
|
var BACKOFF_MS = 20;
|
|
@@ -139,16 +149,16 @@ function gitDirFromPointer(text, holder) {
|
|
|
139
149
|
return isAbsolute(target) ? target : resolve(holder, target);
|
|
140
150
|
}
|
|
141
151
|
function commonDirOf(gitDir) {
|
|
142
|
-
const pointer = entryKind(
|
|
152
|
+
const pointer = entryKind(join4(gitDir, "commondir")) === "file" ? readTextOrNull(join4(gitDir, "commondir"))?.trim() : null;
|
|
143
153
|
if (!pointer) return gitDir;
|
|
144
154
|
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
145
155
|
}
|
|
146
156
|
function isBare(commonDir) {
|
|
147
|
-
const config = readTextOrNull(
|
|
157
|
+
const config = readTextOrNull(join4(commonDir, "config"));
|
|
148
158
|
return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
|
|
149
159
|
}
|
|
150
160
|
function looksLikeBareRepository(directory) {
|
|
151
|
-
return entryKind(
|
|
161
|
+
return entryKind(join4(directory, "HEAD")) === "file" && entryKind(join4(directory, "objects")) === "dir" && entryKind(join4(directory, "refs")) === "dir";
|
|
152
162
|
}
|
|
153
163
|
function canonical(path) {
|
|
154
164
|
try {
|
|
@@ -165,7 +175,7 @@ function resolved(commonDir) {
|
|
|
165
175
|
function probeOnce(directory) {
|
|
166
176
|
let current2 = resolve(directory);
|
|
167
177
|
for (; ; ) {
|
|
168
|
-
const dotGit =
|
|
178
|
+
const dotGit = join4(current2, ".git");
|
|
169
179
|
const kind = entryKind(dotGit);
|
|
170
180
|
if (kind === "dir") {
|
|
171
181
|
const layout = resolved(commonDirOf(dotGit));
|
|
@@ -276,7 +286,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
|
276
286
|
return dirName(sessionRoot || directory);
|
|
277
287
|
}
|
|
278
288
|
function configuredDir(dir) {
|
|
279
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
289
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join5(homedir2(), dir.slice(1)) : dir;
|
|
280
290
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
281
291
|
}
|
|
282
292
|
function isWithin(directory, configured) {
|
|
@@ -371,7 +381,7 @@ function parseHashedCron(cron) {
|
|
|
371
381
|
|
|
372
382
|
// src/core/util.ts
|
|
373
383
|
import { accessSync, constants } from "fs";
|
|
374
|
-
import { delimiter, join as
|
|
384
|
+
import { delimiter, join as join6 } from "path";
|
|
375
385
|
|
|
376
386
|
// src/core/hindsight.ts
|
|
377
387
|
var DEFAULT_OBSERVATION_SCOPES = "shared";
|
|
@@ -379,7 +389,7 @@ var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
|
379
389
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
380
390
|
|
|
381
391
|
// src/core/config.ts
|
|
382
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
392
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
|
|
383
393
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
384
394
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
385
395
|
function resolvePageTrigger(raw) {
|