@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/cline.js
CHANGED
|
@@ -6,8 +6,8 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/core/config.ts
|
|
8
8
|
import { readFileSync as readFileSync2 } from "fs";
|
|
9
|
-
import { homedir as
|
|
10
|
-
import { join as
|
|
9
|
+
import { homedir as homedir3 } from "os";
|
|
10
|
+
import { join as join7 } from "path";
|
|
11
11
|
|
|
12
12
|
// src/core/seed.ts
|
|
13
13
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -44,16 +44,28 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
44
44
|
|
|
45
45
|
// src/core/bank.ts
|
|
46
46
|
import { existsSync } from "fs";
|
|
47
|
-
import { homedir } from "os";
|
|
48
|
-
import { basename, dirname as dirname4, join as
|
|
47
|
+
import { homedir as homedir2 } from "os";
|
|
48
|
+
import { basename, dirname as dirname4, join as join5, normalize, sep } from "path";
|
|
49
49
|
|
|
50
50
|
// src/core/diag.ts
|
|
51
|
-
import {
|
|
51
|
+
import { join as join3 } from "path";
|
|
52
52
|
|
|
53
53
|
// src/core/log.ts
|
|
54
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
55
|
-
import {
|
|
54
|
+
import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
55
|
+
import { homedir } from "os";
|
|
56
56
|
import { dirname as dirname2, join as join2 } from "path";
|
|
57
|
+
function logsDir() {
|
|
58
|
+
return join2(homedir(), ".hindsight", "coding-agents-logs");
|
|
59
|
+
}
|
|
60
|
+
var LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
61
|
+
function appendLogLine(file2, text) {
|
|
62
|
+
mkdirSync(dirname2(file2), { recursive: true, mode: 448 });
|
|
63
|
+
try {
|
|
64
|
+
if (statSync(file2).size >= LOG_MAX_BYTES) renameSync(file2, `${file2}.1`);
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
appendFileSync(file2, text, { mode: 384 });
|
|
68
|
+
}
|
|
57
69
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
58
70
|
var current = ["debug", "info", "warn", "error"].find(
|
|
59
71
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
@@ -62,15 +74,13 @@ function setLogLevel(level) {
|
|
|
62
74
|
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
63
75
|
}
|
|
64
76
|
function logFilePath() {
|
|
65
|
-
return process.env.HINDSIGHT_LOG_FILE || join2(
|
|
77
|
+
return process.env.HINDSIGHT_LOG_FILE || join2(logsDir(), "plugin.log");
|
|
66
78
|
}
|
|
67
79
|
function write(level, scope, msg, extra) {
|
|
68
80
|
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
69
81
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
appendFileSync(
|
|
73
|
-
file2,
|
|
82
|
+
appendLogLine(
|
|
83
|
+
logFilePath(),
|
|
74
84
|
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
75
85
|
);
|
|
76
86
|
} catch {
|
|
@@ -99,12 +109,12 @@ function describeError(value, maxChars = 200) {
|
|
|
99
109
|
|
|
100
110
|
// src/core/diag.ts
|
|
101
111
|
function diagFilePath() {
|
|
102
|
-
return process.env.HINDSIGHT_DIAG_FILE || "
|
|
112
|
+
return process.env.HINDSIGHT_DIAG_FILE || join3(logsDir(), "diag.jsonl");
|
|
103
113
|
}
|
|
104
114
|
function diag(harness, event, extra = {}) {
|
|
105
115
|
log.debug(harness, `diag:${event}`, extra);
|
|
106
116
|
try {
|
|
107
|
-
|
|
117
|
+
appendLogLine(
|
|
108
118
|
diagFilePath(),
|
|
109
119
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
110
120
|
);
|
|
@@ -114,7 +124,7 @@ function diag(harness, event, extra = {}) {
|
|
|
114
124
|
|
|
115
125
|
// src/core/git-layout.ts
|
|
116
126
|
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
117
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
127
|
+
import { dirname as dirname3, isAbsolute, join as join4, resolve } from "path";
|
|
118
128
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
119
129
|
var ATTEMPTS = 3;
|
|
120
130
|
var BACKOFF_MS = 20;
|
|
@@ -150,16 +160,16 @@ function gitDirFromPointer(text, holder) {
|
|
|
150
160
|
return isAbsolute(target) ? target : resolve(holder, target);
|
|
151
161
|
}
|
|
152
162
|
function commonDirOf(gitDir) {
|
|
153
|
-
const pointer = entryKind(
|
|
163
|
+
const pointer = entryKind(join4(gitDir, "commondir")) === "file" ? readTextOrNull(join4(gitDir, "commondir"))?.trim() : null;
|
|
154
164
|
if (!pointer) return gitDir;
|
|
155
165
|
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
156
166
|
}
|
|
157
167
|
function isBare(commonDir) {
|
|
158
|
-
const config2 = readTextOrNull(
|
|
168
|
+
const config2 = readTextOrNull(join4(commonDir, "config"));
|
|
159
169
|
return config2 !== null && /^\s*bare\s*=\s*true\s*$/im.test(config2);
|
|
160
170
|
}
|
|
161
171
|
function looksLikeBareRepository(directory) {
|
|
162
|
-
return entryKind(
|
|
172
|
+
return entryKind(join4(directory, "HEAD")) === "file" && entryKind(join4(directory, "objects")) === "dir" && entryKind(join4(directory, "refs")) === "dir";
|
|
163
173
|
}
|
|
164
174
|
function canonical(path) {
|
|
165
175
|
try {
|
|
@@ -176,7 +186,7 @@ function resolved(commonDir) {
|
|
|
176
186
|
function probeOnce(directory) {
|
|
177
187
|
let current2 = resolve(directory);
|
|
178
188
|
for (; ; ) {
|
|
179
|
-
const dotGit =
|
|
189
|
+
const dotGit = join4(current2, ".git");
|
|
180
190
|
const kind = entryKind(dotGit);
|
|
181
191
|
if (kind === "dir") {
|
|
182
192
|
const layout = resolved(commonDirOf(dotGit));
|
|
@@ -290,7 +300,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
|
290
300
|
return dirName(sessionRoot || directory);
|
|
291
301
|
}
|
|
292
302
|
function configuredDir(dir) {
|
|
293
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
303
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join5(homedir2(), dir.slice(1)) : dir;
|
|
294
304
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
295
305
|
}
|
|
296
306
|
function isWithin(directory, configured) {
|
|
@@ -594,7 +604,7 @@ function codingBankManifest(overrides) {
|
|
|
594
604
|
|
|
595
605
|
// src/core/util.ts
|
|
596
606
|
import { accessSync, constants } from "fs";
|
|
597
|
-
import { delimiter, join as
|
|
607
|
+
import { delimiter, join as join6 } from "path";
|
|
598
608
|
function binOnPath(bin) {
|
|
599
609
|
try {
|
|
600
610
|
if (bin.includes("/")) {
|
|
@@ -604,7 +614,7 @@ function binOnPath(bin) {
|
|
|
604
614
|
for (const dir of (process.env.PATH || "").split(delimiter)) {
|
|
605
615
|
if (!dir) continue;
|
|
606
616
|
try {
|
|
607
|
-
accessSync(
|
|
617
|
+
accessSync(join6(dir, bin), constants.X_OK);
|
|
608
618
|
return true;
|
|
609
619
|
} catch {
|
|
610
620
|
}
|
|
@@ -1285,7 +1295,7 @@ var HindsightClient = class {
|
|
|
1285
1295
|
};
|
|
1286
1296
|
|
|
1287
1297
|
// src/core/config.ts
|
|
1288
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1298
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
|
|
1289
1299
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1290
1300
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1291
1301
|
function resolvePageTrigger(raw) {
|
|
@@ -1579,20 +1589,20 @@ import {
|
|
|
1579
1589
|
unlinkSync,
|
|
1580
1590
|
writeFileSync
|
|
1581
1591
|
} from "fs";
|
|
1582
|
-
import { homedir as
|
|
1583
|
-
import { dirname as dirname5, join as
|
|
1592
|
+
import { homedir as homedir4, tmpdir } from "os";
|
|
1593
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1584
1594
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1585
1595
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1586
1596
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1587
1597
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
1588
1598
|
function stateFile(runtimeDir) {
|
|
1589
|
-
return
|
|
1599
|
+
return join8(runtimeDir, ".update-check.json");
|
|
1590
1600
|
}
|
|
1591
1601
|
function packageRoot() {
|
|
1592
|
-
return
|
|
1602
|
+
return join8(dirname5(fileURLToPath2(import.meta.url)), "..");
|
|
1593
1603
|
}
|
|
1594
1604
|
function stagedRuntimeDir() {
|
|
1595
|
-
return
|
|
1605
|
+
return join8(homedir4(), ".hindsight", "coding-agents");
|
|
1596
1606
|
}
|
|
1597
1607
|
function sameDir(a, b) {
|
|
1598
1608
|
try {
|
|
@@ -1603,7 +1613,7 @@ function sameDir(a, b) {
|
|
|
1603
1613
|
}
|
|
1604
1614
|
function stagedVersion(pkgRoot) {
|
|
1605
1615
|
try {
|
|
1606
|
-
const pkg = JSON.parse(readFileSync3(
|
|
1616
|
+
const pkg = JSON.parse(readFileSync3(join8(pkgRoot, "package.json"), "utf8"));
|
|
1607
1617
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
1608
1618
|
} catch {
|
|
1609
1619
|
return "";
|
|
@@ -1637,7 +1647,7 @@ function dueForCheck(file2, now) {
|
|
|
1637
1647
|
var ORIGIN_FILE = ".install-origin.json";
|
|
1638
1648
|
function selfUpdatable(runtimeDir) {
|
|
1639
1649
|
try {
|
|
1640
|
-
const origin = JSON.parse(readFileSync3(
|
|
1650
|
+
const origin = JSON.parse(readFileSync3(join8(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
1641
1651
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
1642
1652
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
1643
1653
|
} catch {
|
|
@@ -1646,7 +1656,7 @@ function selfUpdatable(runtimeDir) {
|
|
|
1646
1656
|
}
|
|
1647
1657
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1648
1658
|
function lockFile() {
|
|
1649
|
-
return
|
|
1659
|
+
return join8(tmpdir(), "hindsight-coding-agent", "auto-update.lock");
|
|
1650
1660
|
}
|
|
1651
1661
|
function acquireUpdateLock(file2, now) {
|
|
1652
1662
|
try {
|
|
@@ -1763,7 +1773,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
1763
1773
|
|
|
1764
1774
|
// src/core/daemon.ts
|
|
1765
1775
|
import { execFileSync, spawn as realSpawn3 } from "child_process";
|
|
1766
|
-
import { dirname as dirname6, join as
|
|
1776
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1767
1777
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1768
1778
|
var DAEMON_WAIT_SESSION_START_MS = 12e3;
|
|
1769
1779
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
@@ -1838,7 +1848,7 @@ function onPath(bin) {
|
|
|
1838
1848
|
}
|
|
1839
1849
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn3) {
|
|
1840
1850
|
try {
|
|
1841
|
-
const starter =
|
|
1851
|
+
const starter = join9(dirname6(fileURLToPath3(import.meta.url)), "daemon-start.js");
|
|
1842
1852
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1843
1853
|
detached: true,
|
|
1844
1854
|
stdio: "ignore",
|
|
@@ -16407,8 +16417,8 @@ config(en_default());
|
|
|
16407
16417
|
|
|
16408
16418
|
// src/core/knowledge-tools.ts
|
|
16409
16419
|
import { existsSync as existsSync4 } from "fs";
|
|
16410
|
-
import { homedir as
|
|
16411
|
-
import { join as
|
|
16420
|
+
import { homedir as homedir6 } from "os";
|
|
16421
|
+
import { join as join12 } from "path";
|
|
16412
16422
|
|
|
16413
16423
|
// src/core/status.ts
|
|
16414
16424
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -16497,8 +16507,8 @@ ${toolGuide(opts)}
|
|
|
16497
16507
|
import { spawn as realSpawn5 } from "child_process";
|
|
16498
16508
|
import { createHash as createHash2 } from "crypto";
|
|
16499
16509
|
import { existsSync as existsSync3 } from "fs";
|
|
16500
|
-
import { homedir as
|
|
16501
|
-
import { dirname as dirname7, join as
|
|
16510
|
+
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
16511
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
16502
16512
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
16503
16513
|
|
|
16504
16514
|
// src/core/survey-lease.ts
|
|
@@ -16508,20 +16518,20 @@ import {
|
|
|
16508
16518
|
mkdirSync as mkdirSync3,
|
|
16509
16519
|
mkdtempSync,
|
|
16510
16520
|
readdirSync,
|
|
16511
|
-
renameSync,
|
|
16521
|
+
renameSync as renameSync2,
|
|
16512
16522
|
rmdirSync,
|
|
16513
16523
|
rmSync,
|
|
16514
|
-
statSync,
|
|
16524
|
+
statSync as statSync2,
|
|
16515
16525
|
unlinkSync as unlinkSync2,
|
|
16516
16526
|
utimesSync,
|
|
16517
16527
|
writeFileSync as writeFileSync2
|
|
16518
16528
|
} from "fs";
|
|
16519
|
-
import { join as
|
|
16529
|
+
import { join as join10 } from "path";
|
|
16520
16530
|
var LEASE_STALE_MS = 3e4;
|
|
16521
16531
|
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
16522
16532
|
function tryRename(from, to) {
|
|
16523
16533
|
try {
|
|
16524
|
-
|
|
16534
|
+
renameSync2(from, to);
|
|
16525
16535
|
return true;
|
|
16526
16536
|
} catch {
|
|
16527
16537
|
return false;
|
|
@@ -16529,7 +16539,7 @@ function tryRename(from, to) {
|
|
|
16529
16539
|
}
|
|
16530
16540
|
function releaseLease(lease) {
|
|
16531
16541
|
try {
|
|
16532
|
-
unlinkSync2(
|
|
16542
|
+
unlinkSync2(join10(lease.directory, lease.owner));
|
|
16533
16543
|
} catch {
|
|
16534
16544
|
return;
|
|
16535
16545
|
}
|
|
@@ -16548,7 +16558,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
16548
16558
|
return true;
|
|
16549
16559
|
}
|
|
16550
16560
|
if (owners.length !== 1) return false;
|
|
16551
|
-
const age = Date.now() -
|
|
16561
|
+
const age = Date.now() - statSync2(join10(directory, owners[0])).mtimeMs;
|
|
16552
16562
|
if (Math.abs(age) <= staleMs) return false;
|
|
16553
16563
|
releaseLease({ directory, owner: owners[0] });
|
|
16554
16564
|
return true;
|
|
@@ -16557,10 +16567,10 @@ function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
|
16557
16567
|
let staging;
|
|
16558
16568
|
try {
|
|
16559
16569
|
mkdirSync3(root, { recursive: true, mode: 448 });
|
|
16560
|
-
staging = mkdtempSync(
|
|
16570
|
+
staging = mkdtempSync(join10(root, "claim-"));
|
|
16561
16571
|
const owner = randomUUID();
|
|
16562
|
-
writeFileSync2(
|
|
16563
|
-
const directory =
|
|
16572
|
+
writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
|
|
16573
|
+
const directory = join10(root, `survey-${key}.lock`);
|
|
16564
16574
|
if (!tryRename(staging, directory)) {
|
|
16565
16575
|
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
16566
16576
|
if (!tryRename(staging, directory)) return void 0;
|
|
@@ -16583,7 +16593,7 @@ var SURVEY_DOC_IDS = [
|
|
|
16583
16593
|
function resolveClaudeBin(explicit) {
|
|
16584
16594
|
if (explicit) return explicit;
|
|
16585
16595
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
16586
|
-
const nativeInstallPath =
|
|
16596
|
+
const nativeInstallPath = join11(homedir5(), ".claude", "local", "claude");
|
|
16587
16597
|
try {
|
|
16588
16598
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
16589
16599
|
} catch {
|
|
@@ -16701,7 +16711,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16701
16711
|
try {
|
|
16702
16712
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
16703
16713
|
const exists = opts.exists ?? binOnPath;
|
|
16704
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16714
|
+
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16705
16715
|
const preferred = opts.harness ?? "claude-code";
|
|
16706
16716
|
const order = [
|
|
16707
16717
|
preferred,
|
|
@@ -16725,7 +16735,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16725
16735
|
if (cfg.disabled) return false;
|
|
16726
16736
|
const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
16727
16737
|
const lease = acquireLease(
|
|
16728
|
-
opts.lease?.dir ??
|
|
16738
|
+
opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys"),
|
|
16729
16739
|
key,
|
|
16730
16740
|
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
16731
16741
|
);
|
|
@@ -16736,7 +16746,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16736
16746
|
args: plan.args,
|
|
16737
16747
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
16738
16748
|
};
|
|
16739
|
-
const supervisorPath = opts.supervisorPath ??
|
|
16749
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
16740
16750
|
return await new Promise((resolve3) => {
|
|
16741
16751
|
try {
|
|
16742
16752
|
const child = spawnFn("node", [supervisorPath], {
|
|
@@ -16878,7 +16888,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16878
16888
|
inputSchema: {},
|
|
16879
16889
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
16880
16890
|
handler: async (_args) => {
|
|
16881
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16891
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join12(homedir6(), ".hindsight", "coding-agent.json");
|
|
16882
16892
|
const harness = opts.harness ?? "unknown";
|
|
16883
16893
|
const cfg = applyBankConfig(
|
|
16884
16894
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16908,7 +16918,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16908
16918
|
config_override: Boolean(process.env.HINDSIGHT_CONFIG),
|
|
16909
16919
|
hooks_disabled: Boolean(process.env.HINDSIGHT_DISABLE_HOOKS),
|
|
16910
16920
|
log_level: process.env.HINDSIGHT_LOG_LEVEL ?? null,
|
|
16911
|
-
diagnostics_file:
|
|
16921
|
+
diagnostics_file: diagFilePath(),
|
|
16912
16922
|
channel_id_configured: Boolean(process.env.HINDSIGHT_CHANNEL_ID),
|
|
16913
16923
|
user_id_configured: Boolean(process.env.HINDSIGHT_USER_ID)
|
|
16914
16924
|
}
|
|
@@ -17209,6 +17219,64 @@ ${content}`);
|
|
|
17209
17219
|
}
|
|
17210
17220
|
}
|
|
17211
17221
|
|
|
17222
|
+
// src/core/usage.ts
|
|
17223
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
17224
|
+
import { join as join13 } from "path";
|
|
17225
|
+
function usageFilePath() {
|
|
17226
|
+
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
17227
|
+
}
|
|
17228
|
+
var HINDSIGHT_TOOL_RE = /hindsight_(?:[a-z]+_)*[a-z]+$/;
|
|
17229
|
+
var CREDIT_RE = /from hindsight memory/i;
|
|
17230
|
+
var ASSISTANT_ROLES = /* @__PURE__ */ new Set(["assistant", "model"]);
|
|
17231
|
+
function summarizeTurns(turns) {
|
|
17232
|
+
const out = [];
|
|
17233
|
+
for (const t of turns) {
|
|
17234
|
+
if (t.role === "user") {
|
|
17235
|
+
out.push({ turn: out.length + 1, calls: [], credited: false });
|
|
17236
|
+
continue;
|
|
17237
|
+
}
|
|
17238
|
+
const current2 = out.at(-1);
|
|
17239
|
+
if (!current2) continue;
|
|
17240
|
+
if (t.role === "action") {
|
|
17241
|
+
const tool = t.content.split(" ", 1)[0].match(HINDSIGHT_TOOL_RE)?.[0];
|
|
17242
|
+
if (tool) current2.calls.push(tool);
|
|
17243
|
+
} else if (ASSISTANT_ROLES.has(t.role) && CREDIT_RE.test(t.content)) {
|
|
17244
|
+
current2.credited = true;
|
|
17245
|
+
}
|
|
17246
|
+
}
|
|
17247
|
+
return out;
|
|
17248
|
+
}
|
|
17249
|
+
function memoryUsageCursorStore() {
|
|
17250
|
+
const recorded = /* @__PURE__ */ new Map();
|
|
17251
|
+
return {
|
|
17252
|
+
read: (sessionId2) => recorded.get(sessionId2),
|
|
17253
|
+
write: (sessionId2, turns) => void recorded.set(sessionId2, turns)
|
|
17254
|
+
};
|
|
17255
|
+
}
|
|
17256
|
+
function recordUsage(args) {
|
|
17257
|
+
const summary = summarizeTurns(args.turns);
|
|
17258
|
+
const finished = args.lastTurnComplete ? summary : summary.slice(0, -1);
|
|
17259
|
+
const from = args.cursors.read(args.sessionId) ?? 0;
|
|
17260
|
+
if (finished.length <= from) return;
|
|
17261
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
17262
|
+
const lines = finished.slice(from).map(
|
|
17263
|
+
(u) => JSON.stringify({
|
|
17264
|
+
ts,
|
|
17265
|
+
harness: args.harness,
|
|
17266
|
+
session: args.sessionId,
|
|
17267
|
+
bank: args.bankId,
|
|
17268
|
+
turn: u.turn,
|
|
17269
|
+
calls: u.calls,
|
|
17270
|
+
credited: u.credited
|
|
17271
|
+
}) + "\n"
|
|
17272
|
+
).join("");
|
|
17273
|
+
try {
|
|
17274
|
+
appendLogLine(usageFilePath(), lines);
|
|
17275
|
+
args.cursors.write(args.sessionId, finished.length);
|
|
17276
|
+
} catch {
|
|
17277
|
+
}
|
|
17278
|
+
}
|
|
17279
|
+
|
|
17212
17280
|
// src/core/retain-stamp.ts
|
|
17213
17281
|
import { basename as basename2 } from "path";
|
|
17214
17282
|
var RESERVED_TAG_PREFIX = /^(source|harness):/;
|
|
@@ -17257,12 +17325,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17257
17325
|
}
|
|
17258
17326
|
|
|
17259
17327
|
// src/core/session-start.ts
|
|
17260
|
-
import { readFileSync as
|
|
17328
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
17261
17329
|
|
|
17262
17330
|
// src/core/skill-sync.ts
|
|
17263
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
17264
|
-
import { homedir as
|
|
17265
|
-
import { dirname as dirname8, join as
|
|
17331
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
|
|
17332
|
+
import { homedir as homedir7 } from "os";
|
|
17333
|
+
import { dirname as dirname8, join as join14 } from "path";
|
|
17266
17334
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17267
17335
|
|
|
17268
17336
|
// src/core/brand.ts
|
|
@@ -17280,15 +17348,15 @@ function brandWord() {
|
|
|
17280
17348
|
}
|
|
17281
17349
|
|
|
17282
17350
|
// src/core/legacy.ts
|
|
17283
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17284
|
-
import { homedir as
|
|
17285
|
-
import { join as
|
|
17351
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
|
|
17352
|
+
import { homedir as homedir8 } from "os";
|
|
17353
|
+
import { join as join15, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17286
17354
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17287
|
-
function detectLegacyClaudePlugin(cwd, claudeDir =
|
|
17288
|
-
const registry2 = readJson(
|
|
17355
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join15(homedir8(), ".claude")) {
|
|
17356
|
+
const registry2 = readJson(join15(claudeDir, "plugins", "installed_plugins.json"));
|
|
17289
17357
|
const plugins = registry2?.plugins;
|
|
17290
17358
|
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17291
|
-
const enabled = readJson(
|
|
17359
|
+
const enabled = readJson(join15(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17292
17360
|
for (const [key, raw] of Object.entries(plugins)) {
|
|
17293
17361
|
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17294
17362
|
if (enabled && enabled[key] === false) continue;
|
|
@@ -17305,7 +17373,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")
|
|
|
17305
17373
|
}
|
|
17306
17374
|
function readJson(path) {
|
|
17307
17375
|
try {
|
|
17308
|
-
const parsed = JSON.parse(
|
|
17376
|
+
const parsed = JSON.parse(readFileSync6(path, "utf8"));
|
|
17309
17377
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
17310
17378
|
} catch {
|
|
17311
17379
|
return void 0;
|
|
@@ -17317,15 +17385,15 @@ function legacyClaudePluginWarning(key) {
|
|
|
17317
17385
|
}
|
|
17318
17386
|
|
|
17319
17387
|
// src/core/session-cache.ts
|
|
17320
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
17321
|
-
import { tmpdir as
|
|
17322
|
-
import { dirname as dirname9, join as
|
|
17388
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17389
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
17390
|
+
import { dirname as dirname9, join as join16 } from "path";
|
|
17323
17391
|
function sessionCacheFile(harness, sessionId2) {
|
|
17324
|
-
return
|
|
17392
|
+
return join16(tmpdir3(), `hindsight-${harness}`, `${sessionId2}.json`);
|
|
17325
17393
|
}
|
|
17326
17394
|
function readSessionCache(cacheFile) {
|
|
17327
17395
|
try {
|
|
17328
|
-
return JSON.parse(
|
|
17396
|
+
return JSON.parse(readFileSync7(cacheFile, "utf8"));
|
|
17329
17397
|
} catch {
|
|
17330
17398
|
return {};
|
|
17331
17399
|
}
|
|
@@ -17335,7 +17403,7 @@ function writeFileAtomic(path, body) {
|
|
|
17335
17403
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
17336
17404
|
try {
|
|
17337
17405
|
writeFileSync3(tmp, body);
|
|
17338
|
-
|
|
17406
|
+
renameSync3(tmp, path);
|
|
17339
17407
|
} catch (e) {
|
|
17340
17408
|
try {
|
|
17341
17409
|
rmSync2(tmp, { force: true });
|
|
@@ -17511,7 +17579,7 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
|
17511
17579
|
}
|
|
17512
17580
|
|
|
17513
17581
|
// src/core/hook.ts
|
|
17514
|
-
import { existsSync as existsSync7, readFileSync as
|
|
17582
|
+
import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
|
|
17515
17583
|
|
|
17516
17584
|
// src/core/inject.ts
|
|
17517
17585
|
function buildReflectQuery(prompt) {
|
|
@@ -17552,9 +17620,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17552
17620
|
}
|
|
17553
17621
|
|
|
17554
17622
|
// src/core/turn-journal.ts
|
|
17555
|
-
import { appendFileSync as
|
|
17556
|
-
import { tmpdir as
|
|
17557
|
-
import { dirname as dirname10, join as
|
|
17623
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
|
|
17624
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17625
|
+
import { dirname as dirname10, join as join17 } from "path";
|
|
17558
17626
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17559
17627
|
|
|
17560
17628
|
// src/core/hook.ts
|
|
@@ -17570,9 +17638,7 @@ async function reflectFallback(harness, prompt, client) {
|
|
|
17570
17638
|
try {
|
|
17571
17639
|
const hits = await client.searchKnowledgePages(query, FALLBACK_PAGE_LIMIT, remaining());
|
|
17572
17640
|
diag(harness, "reflect_fallback_pages", { ms: Date.now() - t0, count: hits.length });
|
|
17573
|
-
if (hits.length)
|
|
17574
|
-
return { memory: formatPageFallback(hits), source: "knowledge_pages", count: hits.length };
|
|
17575
|
-
}
|
|
17641
|
+
if (hits.length) return formatPageFallback(hits);
|
|
17576
17642
|
} catch (e) {
|
|
17577
17643
|
diag(harness, "reflect_fallback_pages_failed", {
|
|
17578
17644
|
ms: Date.now() - t0,
|
|
@@ -17589,13 +17655,7 @@ async function reflectFallback(harness, prompt, client) {
|
|
|
17589
17655
|
ms: Date.now() - t0,
|
|
17590
17656
|
count: observations.length
|
|
17591
17657
|
});
|
|
17592
|
-
if (observations.length)
|
|
17593
|
-
return {
|
|
17594
|
-
memory: formatObservationFallback(observations),
|
|
17595
|
-
source: "observations",
|
|
17596
|
-
count: observations.length
|
|
17597
|
-
};
|
|
17598
|
-
}
|
|
17658
|
+
if (observations.length) return formatObservationFallback(observations);
|
|
17599
17659
|
} catch (e) {
|
|
17600
17660
|
diag(harness, "reflect_fallback_observations_failed", {
|
|
17601
17661
|
ms: Date.now() - t0,
|
|
@@ -17651,7 +17711,7 @@ async function buildHookOutput(args) {
|
|
|
17651
17711
|
});
|
|
17652
17712
|
if (e instanceof ReflectError && e.fallbackEligible) {
|
|
17653
17713
|
fallback = await reflectFallback(harness, prompt, client);
|
|
17654
|
-
if (fallback) reflectAnswer = fallback
|
|
17714
|
+
if (fallback) reflectAnswer = fallback;
|
|
17655
17715
|
}
|
|
17656
17716
|
}
|
|
17657
17717
|
}
|
|
@@ -17687,8 +17747,6 @@ async function buildHookOutput(args) {
|
|
|
17687
17747
|
const kept = blocks.filter(Boolean);
|
|
17688
17748
|
let notice;
|
|
17689
17749
|
if (fallback) {
|
|
17690
|
-
const what = fallback.source === "knowledge_pages" ? "knowledge page" : "observation";
|
|
17691
|
-
notice = `${brandWord()} \xB7 reflect unavailable \u2014 fell back to ${fallback.count} ${what}${fallback.count === 1 ? "" : "s"} (see ${diagFilePath()})`;
|
|
17692
17750
|
} else if (reflectRanThisTurn && reflectAnswer) {
|
|
17693
17751
|
const q = prompt.replace(/\s+/g, " ").trim();
|
|
17694
17752
|
const excerpt = q.length > 48 ? `${q.slice(0, 48)}\u2026` : q;
|
|
@@ -17725,6 +17783,8 @@ var RuntimeCore = class {
|
|
|
17725
17783
|
sessionState = /* @__PURE__ */ new Map();
|
|
17726
17784
|
/** Live write-back cursors. In memory, unlike the hook harnesses': this host outlives the session. */
|
|
17727
17785
|
cursors = memoryCursorStore();
|
|
17786
|
+
/** Turns already written to the usage log (core/usage.ts), per session. */
|
|
17787
|
+
usageCursors = memoryUsageCursorStore();
|
|
17728
17788
|
/** Pulls a session's CURRENT transcript from the host (set by the adapter); see onSessionIdle. */
|
|
17729
17789
|
fetchTranscript;
|
|
17730
17790
|
lastInjection = "";
|
|
@@ -17847,9 +17907,10 @@ var RuntimeCore = class {
|
|
|
17847
17907
|
* (`engine.retain.fold`), so submitting every turn costs one extraction, not one per turn, and
|
|
17848
17908
|
* nothing is ever held somewhere it can be lost.
|
|
17849
17909
|
*/
|
|
17850
|
-
async onTranscript(sessionId2, turns) {
|
|
17910
|
+
async onTranscript(sessionId2, turns, lastTurnComplete) {
|
|
17851
17911
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
17852
17912
|
if (!this.writeBackEnabled || !sessionId2 || !turns.length) return;
|
|
17913
|
+
this.recordUsage(sessionId2, turns, lastTurnComplete);
|
|
17853
17914
|
const st = this.stateFor(sessionId2);
|
|
17854
17915
|
this.retain(sessionId2, turns, st.startTs);
|
|
17855
17916
|
}
|
|
@@ -17879,11 +17940,22 @@ var RuntimeCore = class {
|
|
|
17879
17940
|
return;
|
|
17880
17941
|
}
|
|
17881
17942
|
if (!turns.length) return;
|
|
17943
|
+
this.recordUsage(sessionId2, turns, true);
|
|
17882
17944
|
const st = this.stateFor(sessionId2);
|
|
17883
17945
|
if (turns.length <= st.retainedTurns) return;
|
|
17884
17946
|
st.retainedTurns = turns.length;
|
|
17885
17947
|
this.retain(sessionId2, turns, st.startTs, "idle");
|
|
17886
17948
|
}
|
|
17949
|
+
recordUsage(sessionId2, turns, lastTurnComplete) {
|
|
17950
|
+
recordUsage({
|
|
17951
|
+
harness: this.harness,
|
|
17952
|
+
sessionId: sessionId2,
|
|
17953
|
+
bankId: this.bankId,
|
|
17954
|
+
turns,
|
|
17955
|
+
cursors: this.usageCursors,
|
|
17956
|
+
lastTurnComplete
|
|
17957
|
+
});
|
|
17958
|
+
}
|
|
17887
17959
|
stateFor(sessionId2) {
|
|
17888
17960
|
let st = this.sessionState.get(sessionId2);
|
|
17889
17961
|
if (!st) {
|
|
@@ -18013,7 +18085,8 @@ function createClineHooks(core, configuredSessionId, sessionStart) {
|
|
|
18013
18085
|
},
|
|
18014
18086
|
async afterRun({ snapshot }) {
|
|
18015
18087
|
const turns = clineTranscript(snapshot.messages);
|
|
18016
|
-
if (turns.length)
|
|
18088
|
+
if (turns.length)
|
|
18089
|
+
await core.onTranscript(sessionId(snapshot, configuredSessionId), turns, true);
|
|
18017
18090
|
}
|
|
18018
18091
|
};
|
|
18019
18092
|
}
|