@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/kilo.js
CHANGED
|
@@ -9,8 +9,8 @@ import { posix, win32 } from "path";
|
|
|
9
9
|
|
|
10
10
|
// src/core/config.ts
|
|
11
11
|
import { readFileSync as readFileSync2 } from "fs";
|
|
12
|
-
import { homedir as
|
|
13
|
-
import { join as
|
|
12
|
+
import { homedir as homedir3 } from "os";
|
|
13
|
+
import { join as join7 } from "path";
|
|
14
14
|
|
|
15
15
|
// src/core/seed.ts
|
|
16
16
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -47,16 +47,28 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
47
47
|
|
|
48
48
|
// src/core/bank.ts
|
|
49
49
|
import { existsSync } from "fs";
|
|
50
|
-
import { homedir } from "os";
|
|
51
|
-
import { basename, dirname as dirname4, join as
|
|
50
|
+
import { homedir as homedir2 } from "os";
|
|
51
|
+
import { basename, dirname as dirname4, join as join5, normalize, sep } from "path";
|
|
52
52
|
|
|
53
53
|
// src/core/diag.ts
|
|
54
|
-
import {
|
|
54
|
+
import { join as join3 } from "path";
|
|
55
55
|
|
|
56
56
|
// src/core/log.ts
|
|
57
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
58
|
-
import {
|
|
57
|
+
import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
58
|
+
import { homedir } from "os";
|
|
59
59
|
import { dirname as dirname2, join as join2 } from "path";
|
|
60
|
+
function logsDir() {
|
|
61
|
+
return join2(homedir(), ".hindsight", "coding-agents-logs");
|
|
62
|
+
}
|
|
63
|
+
var LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
64
|
+
function appendLogLine(file3, text) {
|
|
65
|
+
mkdirSync(dirname2(file3), { recursive: true, mode: 448 });
|
|
66
|
+
try {
|
|
67
|
+
if (statSync(file3).size >= LOG_MAX_BYTES) renameSync(file3, `${file3}.1`);
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
appendFileSync(file3, text, { mode: 384 });
|
|
71
|
+
}
|
|
60
72
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
61
73
|
var current = ["debug", "info", "warn", "error"].find(
|
|
62
74
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
@@ -65,15 +77,13 @@ function setLogLevel(level) {
|
|
|
65
77
|
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
66
78
|
}
|
|
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
|
-
file3,
|
|
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 {
|
|
@@ -102,12 +112,12 @@ function describeError(value, maxChars = 200) {
|
|
|
102
112
|
|
|
103
113
|
// src/core/diag.ts
|
|
104
114
|
function diagFilePath() {
|
|
105
|
-
return process.env.HINDSIGHT_DIAG_FILE || "
|
|
115
|
+
return process.env.HINDSIGHT_DIAG_FILE || join3(logsDir(), "diag.jsonl");
|
|
106
116
|
}
|
|
107
117
|
function diag(harness, event, extra = {}) {
|
|
108
118
|
log.debug(harness, `diag:${event}`, extra);
|
|
109
119
|
try {
|
|
110
|
-
|
|
120
|
+
appendLogLine(
|
|
111
121
|
diagFilePath(),
|
|
112
122
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
113
123
|
);
|
|
@@ -117,7 +127,7 @@ function diag(harness, event, extra = {}) {
|
|
|
117
127
|
|
|
118
128
|
// src/core/git-layout.ts
|
|
119
129
|
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
120
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
130
|
+
import { dirname as dirname3, isAbsolute, join as join4, resolve } from "path";
|
|
121
131
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
122
132
|
var ATTEMPTS = 3;
|
|
123
133
|
var BACKOFF_MS = 20;
|
|
@@ -153,16 +163,16 @@ function gitDirFromPointer(text, holder) {
|
|
|
153
163
|
return isAbsolute(target) ? target : resolve(holder, target);
|
|
154
164
|
}
|
|
155
165
|
function commonDirOf(gitDir) {
|
|
156
|
-
const pointer = entryKind(
|
|
166
|
+
const pointer = entryKind(join4(gitDir, "commondir")) === "file" ? readTextOrNull(join4(gitDir, "commondir"))?.trim() : null;
|
|
157
167
|
if (!pointer) return gitDir;
|
|
158
168
|
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
159
169
|
}
|
|
160
170
|
function isBare(commonDir) {
|
|
161
|
-
const config3 = readTextOrNull(
|
|
171
|
+
const config3 = readTextOrNull(join4(commonDir, "config"));
|
|
162
172
|
return config3 !== null && /^\s*bare\s*=\s*true\s*$/im.test(config3);
|
|
163
173
|
}
|
|
164
174
|
function looksLikeBareRepository(directory) {
|
|
165
|
-
return entryKind(
|
|
175
|
+
return entryKind(join4(directory, "HEAD")) === "file" && entryKind(join4(directory, "objects")) === "dir" && entryKind(join4(directory, "refs")) === "dir";
|
|
166
176
|
}
|
|
167
177
|
function canonical(path) {
|
|
168
178
|
try {
|
|
@@ -179,7 +189,7 @@ function resolved(commonDir) {
|
|
|
179
189
|
function probeOnce(directory) {
|
|
180
190
|
let current2 = resolve(directory);
|
|
181
191
|
for (; ; ) {
|
|
182
|
-
const dotGit =
|
|
192
|
+
const dotGit = join4(current2, ".git");
|
|
183
193
|
const kind = entryKind(dotGit);
|
|
184
194
|
if (kind === "dir") {
|
|
185
195
|
const layout = resolved(commonDirOf(dotGit));
|
|
@@ -293,7 +303,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
|
293
303
|
return dirName(sessionRoot || directory);
|
|
294
304
|
}
|
|
295
305
|
function configuredDir(dir) {
|
|
296
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
306
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join5(homedir2(), dir.slice(1)) : dir;
|
|
297
307
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
298
308
|
}
|
|
299
309
|
function isWithin(directory, configured) {
|
|
@@ -597,7 +607,7 @@ function codingBankManifest(overrides) {
|
|
|
597
607
|
|
|
598
608
|
// src/core/util.ts
|
|
599
609
|
import { accessSync, constants } from "fs";
|
|
600
|
-
import { delimiter, join as
|
|
610
|
+
import { delimiter, join as join6 } from "path";
|
|
601
611
|
function binOnPath(bin) {
|
|
602
612
|
try {
|
|
603
613
|
if (bin.includes("/")) {
|
|
@@ -607,7 +617,7 @@ function binOnPath(bin) {
|
|
|
607
617
|
for (const dir of (process.env.PATH || "").split(delimiter)) {
|
|
608
618
|
if (!dir) continue;
|
|
609
619
|
try {
|
|
610
|
-
accessSync(
|
|
620
|
+
accessSync(join6(dir, bin), constants.X_OK);
|
|
611
621
|
return true;
|
|
612
622
|
} catch {
|
|
613
623
|
}
|
|
@@ -1288,7 +1298,7 @@ var HindsightClient = class {
|
|
|
1288
1298
|
};
|
|
1289
1299
|
|
|
1290
1300
|
// src/core/config.ts
|
|
1291
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1301
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
|
|
1292
1302
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1293
1303
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1294
1304
|
function resolvePageTrigger(raw) {
|
|
@@ -1582,20 +1592,20 @@ import {
|
|
|
1582
1592
|
unlinkSync,
|
|
1583
1593
|
writeFileSync
|
|
1584
1594
|
} from "fs";
|
|
1585
|
-
import { homedir as
|
|
1586
|
-
import { dirname as dirname5, join as
|
|
1595
|
+
import { homedir as homedir4, tmpdir } from "os";
|
|
1596
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1587
1597
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1588
1598
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1589
1599
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1590
1600
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
1591
1601
|
function stateFile(runtimeDir) {
|
|
1592
|
-
return
|
|
1602
|
+
return join8(runtimeDir, ".update-check.json");
|
|
1593
1603
|
}
|
|
1594
1604
|
function packageRoot() {
|
|
1595
|
-
return
|
|
1605
|
+
return join8(dirname5(fileURLToPath2(import.meta.url)), "..");
|
|
1596
1606
|
}
|
|
1597
1607
|
function stagedRuntimeDir() {
|
|
1598
|
-
return
|
|
1608
|
+
return join8(homedir4(), ".hindsight", "coding-agents");
|
|
1599
1609
|
}
|
|
1600
1610
|
function sameDir(a, b) {
|
|
1601
1611
|
try {
|
|
@@ -1606,7 +1616,7 @@ function sameDir(a, b) {
|
|
|
1606
1616
|
}
|
|
1607
1617
|
function stagedVersion(pkgRoot) {
|
|
1608
1618
|
try {
|
|
1609
|
-
const pkg = JSON.parse(readFileSync3(
|
|
1619
|
+
const pkg = JSON.parse(readFileSync3(join8(pkgRoot, "package.json"), "utf8"));
|
|
1610
1620
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
1611
1621
|
} catch {
|
|
1612
1622
|
return "";
|
|
@@ -1640,7 +1650,7 @@ function dueForCheck(file3, now) {
|
|
|
1640
1650
|
var ORIGIN_FILE = ".install-origin.json";
|
|
1641
1651
|
function selfUpdatable(runtimeDir) {
|
|
1642
1652
|
try {
|
|
1643
|
-
const origin = JSON.parse(readFileSync3(
|
|
1653
|
+
const origin = JSON.parse(readFileSync3(join8(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
1644
1654
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
1645
1655
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
1646
1656
|
} catch {
|
|
@@ -1649,7 +1659,7 @@ function selfUpdatable(runtimeDir) {
|
|
|
1649
1659
|
}
|
|
1650
1660
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1651
1661
|
function lockFile() {
|
|
1652
|
-
return
|
|
1662
|
+
return join8(tmpdir(), "hindsight-coding-agent", "auto-update.lock");
|
|
1653
1663
|
}
|
|
1654
1664
|
function acquireUpdateLock(file3, now) {
|
|
1655
1665
|
try {
|
|
@@ -1766,7 +1776,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
1766
1776
|
|
|
1767
1777
|
// src/core/daemon.ts
|
|
1768
1778
|
import { execFileSync, spawn as realSpawn3 } from "child_process";
|
|
1769
|
-
import { dirname as dirname6, join as
|
|
1779
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1770
1780
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1771
1781
|
var DAEMON_WAIT_SESSION_START_MS = 12e3;
|
|
1772
1782
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
@@ -1841,7 +1851,7 @@ function onPath(bin) {
|
|
|
1841
1851
|
}
|
|
1842
1852
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn3) {
|
|
1843
1853
|
try {
|
|
1844
|
-
const starter =
|
|
1854
|
+
const starter = join9(dirname6(fileURLToPath3(import.meta.url)), "daemon-start.js");
|
|
1845
1855
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1846
1856
|
detached: true,
|
|
1847
1857
|
stdio: "ignore",
|
|
@@ -16410,8 +16420,8 @@ config(en_default());
|
|
|
16410
16420
|
|
|
16411
16421
|
// src/core/knowledge-tools.ts
|
|
16412
16422
|
import { existsSync as existsSync4 } from "fs";
|
|
16413
|
-
import { homedir as
|
|
16414
|
-
import { join as
|
|
16423
|
+
import { homedir as homedir6 } from "os";
|
|
16424
|
+
import { join as join12 } from "path";
|
|
16415
16425
|
|
|
16416
16426
|
// src/core/status.ts
|
|
16417
16427
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -16500,8 +16510,8 @@ ${toolGuide(opts)}
|
|
|
16500
16510
|
import { spawn as realSpawn5 } from "child_process";
|
|
16501
16511
|
import { createHash as createHash2 } from "crypto";
|
|
16502
16512
|
import { existsSync as existsSync3 } from "fs";
|
|
16503
|
-
import { homedir as
|
|
16504
|
-
import { dirname as dirname7, join as
|
|
16513
|
+
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
16514
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
16505
16515
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
16506
16516
|
|
|
16507
16517
|
// src/core/survey-lease.ts
|
|
@@ -16511,20 +16521,20 @@ import {
|
|
|
16511
16521
|
mkdirSync as mkdirSync3,
|
|
16512
16522
|
mkdtempSync,
|
|
16513
16523
|
readdirSync,
|
|
16514
|
-
renameSync,
|
|
16524
|
+
renameSync as renameSync2,
|
|
16515
16525
|
rmdirSync,
|
|
16516
16526
|
rmSync,
|
|
16517
|
-
statSync,
|
|
16527
|
+
statSync as statSync2,
|
|
16518
16528
|
unlinkSync as unlinkSync2,
|
|
16519
16529
|
utimesSync,
|
|
16520
16530
|
writeFileSync as writeFileSync2
|
|
16521
16531
|
} from "fs";
|
|
16522
|
-
import { join as
|
|
16532
|
+
import { join as join10 } from "path";
|
|
16523
16533
|
var LEASE_STALE_MS = 3e4;
|
|
16524
16534
|
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
16525
16535
|
function tryRename(from, to) {
|
|
16526
16536
|
try {
|
|
16527
|
-
|
|
16537
|
+
renameSync2(from, to);
|
|
16528
16538
|
return true;
|
|
16529
16539
|
} catch {
|
|
16530
16540
|
return false;
|
|
@@ -16532,7 +16542,7 @@ function tryRename(from, to) {
|
|
|
16532
16542
|
}
|
|
16533
16543
|
function releaseLease(lease) {
|
|
16534
16544
|
try {
|
|
16535
|
-
unlinkSync2(
|
|
16545
|
+
unlinkSync2(join10(lease.directory, lease.owner));
|
|
16536
16546
|
} catch {
|
|
16537
16547
|
return;
|
|
16538
16548
|
}
|
|
@@ -16551,7 +16561,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
16551
16561
|
return true;
|
|
16552
16562
|
}
|
|
16553
16563
|
if (owners.length !== 1) return false;
|
|
16554
|
-
const age = Date.now() -
|
|
16564
|
+
const age = Date.now() - statSync2(join10(directory, owners[0])).mtimeMs;
|
|
16555
16565
|
if (Math.abs(age) <= staleMs) return false;
|
|
16556
16566
|
releaseLease({ directory, owner: owners[0] });
|
|
16557
16567
|
return true;
|
|
@@ -16560,10 +16570,10 @@ function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
|
16560
16570
|
let staging;
|
|
16561
16571
|
try {
|
|
16562
16572
|
mkdirSync3(root, { recursive: true, mode: 448 });
|
|
16563
|
-
staging = mkdtempSync(
|
|
16573
|
+
staging = mkdtempSync(join10(root, "claim-"));
|
|
16564
16574
|
const owner = randomUUID();
|
|
16565
|
-
writeFileSync2(
|
|
16566
|
-
const directory =
|
|
16575
|
+
writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
|
|
16576
|
+
const directory = join10(root, `survey-${key}.lock`);
|
|
16567
16577
|
if (!tryRename(staging, directory)) {
|
|
16568
16578
|
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
16569
16579
|
if (!tryRename(staging, directory)) return void 0;
|
|
@@ -16586,7 +16596,7 @@ var SURVEY_DOC_IDS = [
|
|
|
16586
16596
|
function resolveClaudeBin(explicit) {
|
|
16587
16597
|
if (explicit) return explicit;
|
|
16588
16598
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
16589
|
-
const nativeInstallPath =
|
|
16599
|
+
const nativeInstallPath = join11(homedir5(), ".claude", "local", "claude");
|
|
16590
16600
|
try {
|
|
16591
16601
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
16592
16602
|
} catch {
|
|
@@ -16715,7 +16725,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16715
16725
|
try {
|
|
16716
16726
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
16717
16727
|
const exists = opts.exists ?? binOnPath;
|
|
16718
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16728
|
+
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16719
16729
|
const preferred = opts.harness ?? "claude-code";
|
|
16720
16730
|
const order = [
|
|
16721
16731
|
preferred,
|
|
@@ -16739,7 +16749,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16739
16749
|
if (cfg.disabled) return false;
|
|
16740
16750
|
const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
16741
16751
|
const lease = acquireLease(
|
|
16742
|
-
opts.lease?.dir ??
|
|
16752
|
+
opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys"),
|
|
16743
16753
|
key,
|
|
16744
16754
|
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
16745
16755
|
);
|
|
@@ -16750,7 +16760,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16750
16760
|
args: plan.args,
|
|
16751
16761
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
16752
16762
|
};
|
|
16753
|
-
const supervisorPath = opts.supervisorPath ??
|
|
16763
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
16754
16764
|
return await new Promise((resolve3) => {
|
|
16755
16765
|
try {
|
|
16756
16766
|
const child = spawnFn("node", [supervisorPath], {
|
|
@@ -16892,7 +16902,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16892
16902
|
inputSchema: {},
|
|
16893
16903
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
16894
16904
|
handler: async (_args) => {
|
|
16895
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16905
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join12(homedir6(), ".hindsight", "coding-agent.json");
|
|
16896
16906
|
const harness = opts.harness ?? "unknown";
|
|
16897
16907
|
const cfg = applyBankConfig(
|
|
16898
16908
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16922,7 +16932,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16922
16932
|
config_override: Boolean(process.env.HINDSIGHT_CONFIG),
|
|
16923
16933
|
hooks_disabled: Boolean(process.env.HINDSIGHT_DISABLE_HOOKS),
|
|
16924
16934
|
log_level: process.env.HINDSIGHT_LOG_LEVEL ?? null,
|
|
16925
|
-
diagnostics_file:
|
|
16935
|
+
diagnostics_file: diagFilePath(),
|
|
16926
16936
|
channel_id_configured: Boolean(process.env.HINDSIGHT_CHANNEL_ID),
|
|
16927
16937
|
user_id_configured: Boolean(process.env.HINDSIGHT_USER_ID)
|
|
16928
16938
|
}
|
|
@@ -17223,6 +17233,64 @@ ${content}`);
|
|
|
17223
17233
|
}
|
|
17224
17234
|
}
|
|
17225
17235
|
|
|
17236
|
+
// src/core/usage.ts
|
|
17237
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
17238
|
+
import { join as join13 } from "path";
|
|
17239
|
+
function usageFilePath() {
|
|
17240
|
+
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
17241
|
+
}
|
|
17242
|
+
var HINDSIGHT_TOOL_RE = /hindsight_(?:[a-z]+_)*[a-z]+$/;
|
|
17243
|
+
var CREDIT_RE = /from hindsight memory/i;
|
|
17244
|
+
var ASSISTANT_ROLES = /* @__PURE__ */ new Set(["assistant", "model"]);
|
|
17245
|
+
function summarizeTurns(turns) {
|
|
17246
|
+
const out = [];
|
|
17247
|
+
for (const t of turns) {
|
|
17248
|
+
if (t.role === "user") {
|
|
17249
|
+
out.push({ turn: out.length + 1, calls: [], credited: false });
|
|
17250
|
+
continue;
|
|
17251
|
+
}
|
|
17252
|
+
const current2 = out.at(-1);
|
|
17253
|
+
if (!current2) continue;
|
|
17254
|
+
if (t.role === "action") {
|
|
17255
|
+
const tool2 = t.content.split(" ", 1)[0].match(HINDSIGHT_TOOL_RE)?.[0];
|
|
17256
|
+
if (tool2) current2.calls.push(tool2);
|
|
17257
|
+
} else if (ASSISTANT_ROLES.has(t.role) && CREDIT_RE.test(t.content)) {
|
|
17258
|
+
current2.credited = true;
|
|
17259
|
+
}
|
|
17260
|
+
}
|
|
17261
|
+
return out;
|
|
17262
|
+
}
|
|
17263
|
+
function memoryUsageCursorStore() {
|
|
17264
|
+
const recorded = /* @__PURE__ */ new Map();
|
|
17265
|
+
return {
|
|
17266
|
+
read: (sessionId) => recorded.get(sessionId),
|
|
17267
|
+
write: (sessionId, turns) => void recorded.set(sessionId, turns)
|
|
17268
|
+
};
|
|
17269
|
+
}
|
|
17270
|
+
function recordUsage(args) {
|
|
17271
|
+
const summary = summarizeTurns(args.turns);
|
|
17272
|
+
const finished = args.lastTurnComplete ? summary : summary.slice(0, -1);
|
|
17273
|
+
const from = args.cursors.read(args.sessionId) ?? 0;
|
|
17274
|
+
if (finished.length <= from) return;
|
|
17275
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
17276
|
+
const lines = finished.slice(from).map(
|
|
17277
|
+
(u) => JSON.stringify({
|
|
17278
|
+
ts,
|
|
17279
|
+
harness: args.harness,
|
|
17280
|
+
session: args.sessionId,
|
|
17281
|
+
bank: args.bankId,
|
|
17282
|
+
turn: u.turn,
|
|
17283
|
+
calls: u.calls,
|
|
17284
|
+
credited: u.credited
|
|
17285
|
+
}) + "\n"
|
|
17286
|
+
).join("");
|
|
17287
|
+
try {
|
|
17288
|
+
appendLogLine(usageFilePath(), lines);
|
|
17289
|
+
args.cursors.write(args.sessionId, finished.length);
|
|
17290
|
+
} catch {
|
|
17291
|
+
}
|
|
17292
|
+
}
|
|
17293
|
+
|
|
17226
17294
|
// src/core/retain-stamp.ts
|
|
17227
17295
|
import { basename as basename2 } from "path";
|
|
17228
17296
|
var RESERVED_TAG_PREFIX = /^(source|harness):/;
|
|
@@ -17271,12 +17339,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17271
17339
|
}
|
|
17272
17340
|
|
|
17273
17341
|
// src/core/session-start.ts
|
|
17274
|
-
import { readFileSync as
|
|
17342
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
17275
17343
|
|
|
17276
17344
|
// src/core/skill-sync.ts
|
|
17277
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
17278
|
-
import { homedir as
|
|
17279
|
-
import { dirname as dirname8, join as
|
|
17345
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
|
|
17346
|
+
import { homedir as homedir7 } from "os";
|
|
17347
|
+
import { dirname as dirname8, join as join14 } from "path";
|
|
17280
17348
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17281
17349
|
|
|
17282
17350
|
// src/core/brand.ts
|
|
@@ -17294,15 +17362,15 @@ function brandWord() {
|
|
|
17294
17362
|
}
|
|
17295
17363
|
|
|
17296
17364
|
// src/core/legacy.ts
|
|
17297
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17298
|
-
import { homedir as
|
|
17299
|
-
import { join as
|
|
17365
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
|
|
17366
|
+
import { homedir as homedir8 } from "os";
|
|
17367
|
+
import { join as join15, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17300
17368
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17301
|
-
function detectLegacyClaudePlugin(cwd, claudeDir =
|
|
17302
|
-
const registry3 = readJson(
|
|
17369
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join15(homedir8(), ".claude")) {
|
|
17370
|
+
const registry3 = readJson(join15(claudeDir, "plugins", "installed_plugins.json"));
|
|
17303
17371
|
const plugins = registry3?.plugins;
|
|
17304
17372
|
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17305
|
-
const enabled = readJson(
|
|
17373
|
+
const enabled = readJson(join15(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17306
17374
|
for (const [key, raw] of Object.entries(plugins)) {
|
|
17307
17375
|
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17308
17376
|
if (enabled && enabled[key] === false) continue;
|
|
@@ -17319,7 +17387,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")
|
|
|
17319
17387
|
}
|
|
17320
17388
|
function readJson(path) {
|
|
17321
17389
|
try {
|
|
17322
|
-
const parsed = JSON.parse(
|
|
17390
|
+
const parsed = JSON.parse(readFileSync6(path, "utf8"));
|
|
17323
17391
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
17324
17392
|
} catch {
|
|
17325
17393
|
return void 0;
|
|
@@ -17331,15 +17399,15 @@ function legacyClaudePluginWarning(key) {
|
|
|
17331
17399
|
}
|
|
17332
17400
|
|
|
17333
17401
|
// src/core/session-cache.ts
|
|
17334
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
17335
|
-
import { tmpdir as
|
|
17336
|
-
import { dirname as dirname9, join as
|
|
17402
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17403
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
17404
|
+
import { dirname as dirname9, join as join16 } from "path";
|
|
17337
17405
|
function sessionCacheFile(harness, sessionId) {
|
|
17338
|
-
return
|
|
17406
|
+
return join16(tmpdir3(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
17339
17407
|
}
|
|
17340
17408
|
function readSessionCache(cacheFile) {
|
|
17341
17409
|
try {
|
|
17342
|
-
return JSON.parse(
|
|
17410
|
+
return JSON.parse(readFileSync7(cacheFile, "utf8"));
|
|
17343
17411
|
} catch {
|
|
17344
17412
|
return {};
|
|
17345
17413
|
}
|
|
@@ -17349,7 +17417,7 @@ function writeFileAtomic(path, body) {
|
|
|
17349
17417
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
17350
17418
|
try {
|
|
17351
17419
|
writeFileSync3(tmp, body);
|
|
17352
|
-
|
|
17420
|
+
renameSync3(tmp, path);
|
|
17353
17421
|
} catch (e) {
|
|
17354
17422
|
try {
|
|
17355
17423
|
rmSync2(tmp, { force: true });
|
|
@@ -17525,7 +17593,7 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
|
17525
17593
|
}
|
|
17526
17594
|
|
|
17527
17595
|
// src/core/hook.ts
|
|
17528
|
-
import { existsSync as existsSync7, readFileSync as
|
|
17596
|
+
import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
|
|
17529
17597
|
|
|
17530
17598
|
// src/core/inject.ts
|
|
17531
17599
|
function buildReflectQuery(prompt) {
|
|
@@ -17566,9 +17634,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17566
17634
|
}
|
|
17567
17635
|
|
|
17568
17636
|
// src/core/turn-journal.ts
|
|
17569
|
-
import { appendFileSync as
|
|
17570
|
-
import { tmpdir as
|
|
17571
|
-
import { dirname as dirname10, join as
|
|
17637
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
|
|
17638
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17639
|
+
import { dirname as dirname10, join as join17 } from "path";
|
|
17572
17640
|
|
|
17573
17641
|
// src/core/transcript-util.ts
|
|
17574
17642
|
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;
|
|
@@ -17621,9 +17689,7 @@ async function reflectFallback(harness, prompt, client) {
|
|
|
17621
17689
|
try {
|
|
17622
17690
|
const hits = await client.searchKnowledgePages(query, FALLBACK_PAGE_LIMIT, remaining());
|
|
17623
17691
|
diag(harness, "reflect_fallback_pages", { ms: Date.now() - t0, count: hits.length });
|
|
17624
|
-
if (hits.length)
|
|
17625
|
-
return { memory: formatPageFallback(hits), source: "knowledge_pages", count: hits.length };
|
|
17626
|
-
}
|
|
17692
|
+
if (hits.length) return formatPageFallback(hits);
|
|
17627
17693
|
} catch (e) {
|
|
17628
17694
|
diag(harness, "reflect_fallback_pages_failed", {
|
|
17629
17695
|
ms: Date.now() - t0,
|
|
@@ -17640,13 +17706,7 @@ async function reflectFallback(harness, prompt, client) {
|
|
|
17640
17706
|
ms: Date.now() - t0,
|
|
17641
17707
|
count: observations.length
|
|
17642
17708
|
});
|
|
17643
|
-
if (observations.length)
|
|
17644
|
-
return {
|
|
17645
|
-
memory: formatObservationFallback(observations),
|
|
17646
|
-
source: "observations",
|
|
17647
|
-
count: observations.length
|
|
17648
|
-
};
|
|
17649
|
-
}
|
|
17709
|
+
if (observations.length) return formatObservationFallback(observations);
|
|
17650
17710
|
} catch (e) {
|
|
17651
17711
|
diag(harness, "reflect_fallback_observations_failed", {
|
|
17652
17712
|
ms: Date.now() - t0,
|
|
@@ -17702,7 +17762,7 @@ async function buildHookOutput(args) {
|
|
|
17702
17762
|
});
|
|
17703
17763
|
if (e instanceof ReflectError && e.fallbackEligible) {
|
|
17704
17764
|
fallback = await reflectFallback(harness, prompt, client);
|
|
17705
|
-
if (fallback) reflectAnswer = fallback
|
|
17765
|
+
if (fallback) reflectAnswer = fallback;
|
|
17706
17766
|
}
|
|
17707
17767
|
}
|
|
17708
17768
|
}
|
|
@@ -17738,8 +17798,6 @@ async function buildHookOutput(args) {
|
|
|
17738
17798
|
const kept = blocks.filter(Boolean);
|
|
17739
17799
|
let notice;
|
|
17740
17800
|
if (fallback) {
|
|
17741
|
-
const what = fallback.source === "knowledge_pages" ? "knowledge page" : "observation";
|
|
17742
|
-
notice = `${brandWord()} \xB7 reflect unavailable \u2014 fell back to ${fallback.count} ${what}${fallback.count === 1 ? "" : "s"} (see ${diagFilePath()})`;
|
|
17743
17801
|
} else if (reflectRanThisTurn && reflectAnswer) {
|
|
17744
17802
|
const q = prompt.replace(/\s+/g, " ").trim();
|
|
17745
17803
|
const excerpt = q.length > 48 ? `${q.slice(0, 48)}\u2026` : q;
|
|
@@ -17776,6 +17834,8 @@ var RuntimeCore = class {
|
|
|
17776
17834
|
sessionState = /* @__PURE__ */ new Map();
|
|
17777
17835
|
/** Live write-back cursors. In memory, unlike the hook harnesses': this host outlives the session. */
|
|
17778
17836
|
cursors = memoryCursorStore();
|
|
17837
|
+
/** Turns already written to the usage log (core/usage.ts), per session. */
|
|
17838
|
+
usageCursors = memoryUsageCursorStore();
|
|
17779
17839
|
/** Pulls a session's CURRENT transcript from the host (set by the adapter); see onSessionIdle. */
|
|
17780
17840
|
fetchTranscript;
|
|
17781
17841
|
lastInjection = "";
|
|
@@ -17898,9 +17958,10 @@ var RuntimeCore = class {
|
|
|
17898
17958
|
* (`engine.retain.fold`), so submitting every turn costs one extraction, not one per turn, and
|
|
17899
17959
|
* nothing is ever held somewhere it can be lost.
|
|
17900
17960
|
*/
|
|
17901
|
-
async onTranscript(sessionId, turns) {
|
|
17961
|
+
async onTranscript(sessionId, turns, lastTurnComplete) {
|
|
17902
17962
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
17903
17963
|
if (!this.writeBackEnabled || !sessionId || !turns.length) return;
|
|
17964
|
+
this.recordUsage(sessionId, turns, lastTurnComplete);
|
|
17904
17965
|
const st = this.stateFor(sessionId);
|
|
17905
17966
|
this.retain(sessionId, turns, st.startTs);
|
|
17906
17967
|
}
|
|
@@ -17930,11 +17991,22 @@ var RuntimeCore = class {
|
|
|
17930
17991
|
return;
|
|
17931
17992
|
}
|
|
17932
17993
|
if (!turns.length) return;
|
|
17994
|
+
this.recordUsage(sessionId, turns, true);
|
|
17933
17995
|
const st = this.stateFor(sessionId);
|
|
17934
17996
|
if (turns.length <= st.retainedTurns) return;
|
|
17935
17997
|
st.retainedTurns = turns.length;
|
|
17936
17998
|
this.retain(sessionId, turns, st.startTs, "idle");
|
|
17937
17999
|
}
|
|
18000
|
+
recordUsage(sessionId, turns, lastTurnComplete) {
|
|
18001
|
+
recordUsage({
|
|
18002
|
+
harness: this.harness,
|
|
18003
|
+
sessionId,
|
|
18004
|
+
bankId: this.bankId,
|
|
18005
|
+
turns,
|
|
18006
|
+
cursors: this.usageCursors,
|
|
18007
|
+
lastTurnComplete
|
|
18008
|
+
});
|
|
18009
|
+
}
|
|
17938
18010
|
stateFor(sessionId) {
|
|
17939
18011
|
let st = this.sessionState.get(sessionId);
|
|
17940
18012
|
if (!st) {
|
|
@@ -30427,12 +30499,12 @@ function tool(input) {
|
|
|
30427
30499
|
tool.schema = external_exports2;
|
|
30428
30500
|
|
|
30429
30501
|
// src/harness/registry.ts
|
|
30430
|
-
import { readFileSync as
|
|
30502
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
30431
30503
|
var jsonChatReader = (harness) => ({
|
|
30432
30504
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
30433
30505
|
async read(opts) {
|
|
30434
30506
|
if (!opts.conversations) return [];
|
|
30435
|
-
return JSON.parse(
|
|
30507
|
+
return JSON.parse(readFileSync11(opts.conversations, "utf8"));
|
|
30436
30508
|
}
|
|
30437
30509
|
});
|
|
30438
30510
|
|
|
@@ -30492,7 +30564,7 @@ function createRuntime(core) {
|
|
|
30492
30564
|
const msgs = output.messages || [];
|
|
30493
30565
|
const sid = opencodeSessionId(msgs);
|
|
30494
30566
|
if (!sid) return;
|
|
30495
|
-
await core.onTranscript(sid, readOpencodeMessages(msgs));
|
|
30567
|
+
await core.onTranscript(sid, readOpencodeMessages(msgs), false);
|
|
30496
30568
|
},
|
|
30497
30569
|
// The Stop-equivalent these hosts otherwise lack: `session.idle` fires once the assistant has
|
|
30498
30570
|
// finished, which is the only moment the completed exchange is readable. Without it a session's
|