@vectorize-io/hindsight-coding-agents 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antigravity-hook.js +67 -33
- package/dist/antigravity-stop-hook.js +61 -31
- package/dist/claude-hook.js +67 -33
- package/dist/claude-sessionstart-hook.js +239 -71
- package/dist/claude-stop-hook.js +61 -31
- package/dist/cline.js +213 -50
- package/dist/codex-hook.js +67 -33
- package/dist/codex-sessionstart-hook.js +239 -71
- package/dist/codex-stop-hook.js +61 -31
- package/dist/copilot-hook.js +67 -33
- package/dist/copilot-sessionstart-hook.js +239 -71
- package/dist/copilot-stop-hook.js +61 -31
- package/dist/cursor-hook.js +67 -33
- package/dist/cursor-sessionstart-hook.js +239 -71
- package/dist/cursor-stop-hook.js +61 -31
- package/dist/dcode-hook.js +67 -33
- package/dist/dcode-sessionstart-hook.js +239 -71
- package/dist/dcode-stop-hook.js +61 -31
- package/dist/deepen.js +40 -13
- package/dist/devin-hook.js +67 -33
- package/dist/devin-sessionstart-hook.js +239 -71
- package/dist/devin-stop-hook.js +61 -31
- package/dist/droid-hook.js +67 -33
- package/dist/droid-sessionstart-hook.js +239 -71
- package/dist/droid-stop-hook.js +61 -31
- package/dist/dsh.js +215 -52
- package/dist/grok-hook.js +67 -33
- package/dist/grok-sessionstart-hook.js +239 -71
- package/dist/grok-stop-hook.js +61 -31
- package/dist/index.js +215 -52
- package/dist/installer.js +1030 -268
- package/dist/kilo.js +215 -52
- package/dist/mcp-server.js +33 -6
- package/dist/opencode2.js +215 -52
- package/dist/pi.js +214 -51
- package/dist/prime-agent.js +214 -51
- package/dist/qwen-hook.js +67 -33
- package/dist/qwen-sessionstart-hook.js +239 -71
- package/dist/qwen-stop-hook.js +61 -31
- package/dist/status.js +31 -4
- package/dist/survey-supervisor.js +81 -0
- package/dist/zcode-hook.js +67 -33
- package/dist/zcode-sessionstart-hook.js +239 -71
- package/dist/zcode-stop-hook.js +61 -31
- package/package.json +2 -1
- package/plugin.json +1 -1
package/dist/claude-stop-hook.js
CHANGED
|
@@ -922,9 +922,16 @@ var HindsightClient = class {
|
|
|
922
922
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
923
923
|
signal: ctrl.signal
|
|
924
924
|
});
|
|
925
|
-
if (!resp.ok)
|
|
925
|
+
if (!resp.ok)
|
|
926
|
+
throw new Error(
|
|
927
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
928
|
+
);
|
|
926
929
|
const data = await resp.json();
|
|
927
930
|
return (data.text || "").trim();
|
|
931
|
+
} catch (e) {
|
|
932
|
+
if (ctrl.signal.aborted)
|
|
933
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
934
|
+
throw e;
|
|
928
935
|
} finally {
|
|
929
936
|
clearTimeout(timer);
|
|
930
937
|
}
|
|
@@ -2173,7 +2180,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
2173
2180
|
}
|
|
2174
2181
|
|
|
2175
2182
|
// src/core/session-start.ts
|
|
2176
|
-
import { readFileSync as
|
|
2183
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
2177
2184
|
|
|
2178
2185
|
// src/core/git.ts
|
|
2179
2186
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -2183,24 +2190,42 @@ import { resolve as resolve2 } from "path";
|
|
|
2183
2190
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
2184
2191
|
|
|
2185
2192
|
// src/core/survey.ts
|
|
2186
|
-
import { spawn as
|
|
2193
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
2194
|
+
import { createHash as createHash4 } from "crypto";
|
|
2187
2195
|
import { existsSync as existsSync3 } from "fs";
|
|
2188
|
-
import { homedir as homedir3 } from "os";
|
|
2189
|
-
import { dirname as dirname8, join as
|
|
2196
|
+
import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
|
|
2197
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
2190
2198
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2191
2199
|
|
|
2200
|
+
// src/core/survey-lease.ts
|
|
2201
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
2202
|
+
import { randomUUID } from "crypto";
|
|
2203
|
+
import {
|
|
2204
|
+
mkdirSync as mkdirSync4,
|
|
2205
|
+
mkdtempSync,
|
|
2206
|
+
readdirSync,
|
|
2207
|
+
renameSync as renameSync2,
|
|
2208
|
+
rmdirSync,
|
|
2209
|
+
rmSync as rmSync2,
|
|
2210
|
+
statSync as statSync3,
|
|
2211
|
+
unlinkSync,
|
|
2212
|
+
utimesSync,
|
|
2213
|
+
writeFileSync as writeFileSync2
|
|
2214
|
+
} from "fs";
|
|
2215
|
+
import { join as join10 } from "path";
|
|
2216
|
+
|
|
2192
2217
|
// src/core/auto-update.ts
|
|
2193
|
-
import { spawn as
|
|
2218
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
2194
2219
|
import {
|
|
2195
2220
|
existsSync as existsSync4,
|
|
2196
|
-
mkdirSync as
|
|
2221
|
+
mkdirSync as mkdirSync5,
|
|
2197
2222
|
readFileSync as readFileSync7,
|
|
2198
2223
|
realpathSync as realpathSync2,
|
|
2199
|
-
unlinkSync,
|
|
2200
|
-
writeFileSync as
|
|
2224
|
+
unlinkSync as unlinkSync2,
|
|
2225
|
+
writeFileSync as writeFileSync3
|
|
2201
2226
|
} from "fs";
|
|
2202
|
-
import { homedir as homedir4, tmpdir as
|
|
2203
|
-
import { dirname as dirname9, join as
|
|
2227
|
+
import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
|
|
2228
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
2204
2229
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2205
2230
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2206
2231
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
@@ -2208,9 +2233,14 @@ var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
|
2208
2233
|
// src/core/skill-sync.ts
|
|
2209
2234
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
2210
2235
|
import { homedir as homedir5 } from "os";
|
|
2211
|
-
import { dirname as dirname10, join as
|
|
2236
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
2212
2237
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2213
2238
|
|
|
2239
|
+
// src/core/legacy.ts
|
|
2240
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
2241
|
+
import { homedir as homedir6 } from "os";
|
|
2242
|
+
import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2243
|
+
|
|
2214
2244
|
// src/core/transcript-codex.ts
|
|
2215
2245
|
function isSyntheticUserText(text) {
|
|
2216
2246
|
const s = text.trimStart();
|
|
@@ -2341,19 +2371,19 @@ function readCopilotTranscript(path) {
|
|
|
2341
2371
|
}
|
|
2342
2372
|
|
|
2343
2373
|
// src/core/transcript-grok.ts
|
|
2344
|
-
import { existsSync as
|
|
2345
|
-
import { homedir as
|
|
2346
|
-
import { join as
|
|
2374
|
+
import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
|
|
2375
|
+
import { homedir as homedir7 } from "os";
|
|
2376
|
+
import { join as join15 } from "path";
|
|
2347
2377
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2348
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2349
|
-
const sessionsDir =
|
|
2350
|
-
const direct =
|
|
2351
|
-
if (
|
|
2378
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
|
|
2379
|
+
const sessionsDir = join15(grokHome, "sessions");
|
|
2380
|
+
const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2381
|
+
if (existsSync7(direct)) return direct;
|
|
2352
2382
|
try {
|
|
2353
|
-
for (const candidate of
|
|
2354
|
-
const directory =
|
|
2355
|
-
if (
|
|
2356
|
-
return
|
|
2383
|
+
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2384
|
+
const directory = join15(sessionsDir, candidate);
|
|
2385
|
+
if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2386
|
+
return join15(directory, sessionId, CHAT_HISTORY);
|
|
2357
2387
|
}
|
|
2358
2388
|
}
|
|
2359
2389
|
} catch {
|
|
@@ -2388,12 +2418,12 @@ function readGrokTranscript(path) {
|
|
|
2388
2418
|
}
|
|
2389
2419
|
|
|
2390
2420
|
// src/core/transcript-devin.ts
|
|
2391
|
-
import { existsSync as
|
|
2421
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2392
2422
|
import { createRequire } from "module";
|
|
2393
|
-
import { homedir as
|
|
2394
|
-
import { join as
|
|
2395
|
-
function devinSessionDb(home =
|
|
2396
|
-
return
|
|
2423
|
+
import { homedir as homedir8 } from "os";
|
|
2424
|
+
import { join as join16 } from "path";
|
|
2425
|
+
function devinSessionDb(home = homedir8()) {
|
|
2426
|
+
return join16(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2397
2427
|
}
|
|
2398
2428
|
function parseDevinMessages(nodes) {
|
|
2399
2429
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2430,7 +2460,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2430
2460
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2431
2461
|
return [];
|
|
2432
2462
|
}
|
|
2433
|
-
if (!
|
|
2463
|
+
if (!existsSync8(dbPath)) {
|
|
2434
2464
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2435
2465
|
return [];
|
|
2436
2466
|
}
|
|
@@ -2703,7 +2733,7 @@ function readDroidTranscript(path) {
|
|
|
2703
2733
|
}
|
|
2704
2734
|
|
|
2705
2735
|
// src/core/transcript-zcode.ts
|
|
2706
|
-
import { readFileSync as
|
|
2736
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
2707
2737
|
function messageText2(content) {
|
|
2708
2738
|
if (typeof content === "string") return content.trim();
|
|
2709
2739
|
if (!Array.isArray(content)) return "";
|
|
@@ -2713,7 +2743,7 @@ function readZcodeTranscript(path) {
|
|
|
2713
2743
|
if (!path) return [];
|
|
2714
2744
|
let body;
|
|
2715
2745
|
try {
|
|
2716
|
-
body =
|
|
2746
|
+
body = readFileSync12(path, "utf8");
|
|
2717
2747
|
} catch {
|
|
2718
2748
|
return [];
|
|
2719
2749
|
}
|
package/dist/cline.js
CHANGED
|
@@ -969,9 +969,16 @@ var HindsightClient = class {
|
|
|
969
969
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
970
970
|
signal: ctrl.signal
|
|
971
971
|
});
|
|
972
|
-
if (!resp.ok)
|
|
972
|
+
if (!resp.ok)
|
|
973
|
+
throw new Error(
|
|
974
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
975
|
+
);
|
|
973
976
|
const data = await resp.json();
|
|
974
977
|
return (data.text || "").trim();
|
|
978
|
+
} catch (e) {
|
|
979
|
+
if (ctrl.signal.aborted)
|
|
980
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
981
|
+
throw e;
|
|
975
982
|
} finally {
|
|
976
983
|
clearTimeout(timer);
|
|
977
984
|
}
|
|
@@ -16353,7 +16360,7 @@ config(en_default());
|
|
|
16353
16360
|
// src/core/knowledge-tools.ts
|
|
16354
16361
|
import { existsSync as existsSync4 } from "fs";
|
|
16355
16362
|
import { homedir as homedir5 } from "os";
|
|
16356
|
-
import { join as
|
|
16363
|
+
import { join as join11 } from "path";
|
|
16357
16364
|
|
|
16358
16365
|
// src/core/status.ts
|
|
16359
16366
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -16439,11 +16446,86 @@ ${toolGuide(opts)}
|
|
|
16439
16446
|
}
|
|
16440
16447
|
|
|
16441
16448
|
// src/core/survey.ts
|
|
16442
|
-
import { spawn as
|
|
16449
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
16450
|
+
import { createHash as createHash2 } from "crypto";
|
|
16443
16451
|
import { existsSync as existsSync3 } from "fs";
|
|
16444
|
-
import { homedir as homedir4 } from "os";
|
|
16445
|
-
import { dirname as dirname7, join as
|
|
16452
|
+
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
16453
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
16446
16454
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
16455
|
+
|
|
16456
|
+
// src/core/survey-lease.ts
|
|
16457
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
16458
|
+
import { randomUUID } from "crypto";
|
|
16459
|
+
import {
|
|
16460
|
+
mkdirSync as mkdirSync3,
|
|
16461
|
+
mkdtempSync,
|
|
16462
|
+
readdirSync,
|
|
16463
|
+
renameSync,
|
|
16464
|
+
rmdirSync,
|
|
16465
|
+
rmSync,
|
|
16466
|
+
statSync,
|
|
16467
|
+
unlinkSync as unlinkSync2,
|
|
16468
|
+
utimesSync,
|
|
16469
|
+
writeFileSync as writeFileSync2
|
|
16470
|
+
} from "fs";
|
|
16471
|
+
import { join as join9 } from "path";
|
|
16472
|
+
var LEASE_STALE_MS = 3e4;
|
|
16473
|
+
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
16474
|
+
function tryRename(from, to) {
|
|
16475
|
+
try {
|
|
16476
|
+
renameSync(from, to);
|
|
16477
|
+
return true;
|
|
16478
|
+
} catch {
|
|
16479
|
+
return false;
|
|
16480
|
+
}
|
|
16481
|
+
}
|
|
16482
|
+
function releaseLease(lease) {
|
|
16483
|
+
try {
|
|
16484
|
+
unlinkSync2(join9(lease.directory, lease.owner));
|
|
16485
|
+
} catch {
|
|
16486
|
+
return;
|
|
16487
|
+
}
|
|
16488
|
+
try {
|
|
16489
|
+
rmdirSync(lease.directory);
|
|
16490
|
+
} catch {
|
|
16491
|
+
}
|
|
16492
|
+
}
|
|
16493
|
+
function reclaimIfStale(directory, staleMs) {
|
|
16494
|
+
const owners = readdirSync(directory);
|
|
16495
|
+
if (owners.length === 0) {
|
|
16496
|
+
try {
|
|
16497
|
+
rmdirSync(directory);
|
|
16498
|
+
} catch {
|
|
16499
|
+
}
|
|
16500
|
+
return true;
|
|
16501
|
+
}
|
|
16502
|
+
if (owners.length !== 1) return false;
|
|
16503
|
+
const age = Date.now() - statSync(join9(directory, owners[0])).mtimeMs;
|
|
16504
|
+
if (Math.abs(age) <= staleMs) return false;
|
|
16505
|
+
releaseLease({ directory, owner: owners[0] });
|
|
16506
|
+
return true;
|
|
16507
|
+
}
|
|
16508
|
+
function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
16509
|
+
let staging;
|
|
16510
|
+
try {
|
|
16511
|
+
mkdirSync3(root, { recursive: true, mode: 448 });
|
|
16512
|
+
staging = mkdtempSync(join9(root, "claim-"));
|
|
16513
|
+
const owner = randomUUID();
|
|
16514
|
+
writeFileSync2(join9(staging, owner), "", { flag: "wx", mode: 384 });
|
|
16515
|
+
const directory = join9(root, `survey-${key}.lock`);
|
|
16516
|
+
if (!tryRename(staging, directory)) {
|
|
16517
|
+
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
16518
|
+
if (!tryRename(staging, directory)) return void 0;
|
|
16519
|
+
}
|
|
16520
|
+
return { directory, owner };
|
|
16521
|
+
} catch {
|
|
16522
|
+
return void 0;
|
|
16523
|
+
} finally {
|
|
16524
|
+
if (staging) rmSync(staging, { recursive: true, force: true });
|
|
16525
|
+
}
|
|
16526
|
+
}
|
|
16527
|
+
|
|
16528
|
+
// src/core/survey.ts
|
|
16447
16529
|
var SURVEY_DOC_IDS = [
|
|
16448
16530
|
"repository-component-map",
|
|
16449
16531
|
"repository-core-concepts",
|
|
@@ -16453,7 +16535,7 @@ var SURVEY_DOC_IDS = [
|
|
|
16453
16535
|
function resolveClaudeBin(explicit) {
|
|
16454
16536
|
if (explicit) return explicit;
|
|
16455
16537
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
16456
|
-
const nativeInstallPath =
|
|
16538
|
+
const nativeInstallPath = join10(homedir4(), ".claude", "local", "claude");
|
|
16457
16539
|
try {
|
|
16458
16540
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
16459
16541
|
} catch {
|
|
@@ -16567,11 +16649,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
16567
16649
|
}
|
|
16568
16650
|
}
|
|
16569
16651
|
}
|
|
16570
|
-
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16652
|
+
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16571
16653
|
try {
|
|
16572
|
-
const spawnFn = opts.spawn ??
|
|
16654
|
+
const spawnFn = opts.spawn ?? realSpawn5;
|
|
16573
16655
|
const exists = opts.exists ?? binOnPath;
|
|
16574
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16656
|
+
const mcpServerPath = opts.mcpServerPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16575
16657
|
const preferred = opts.harness ?? "claude-code";
|
|
16576
16658
|
const order = [
|
|
16577
16659
|
preferred,
|
|
@@ -16591,20 +16673,51 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16591
16673
|
budgetUsd: opts.budgetUsd,
|
|
16592
16674
|
mcpServerPath
|
|
16593
16675
|
});
|
|
16594
|
-
const
|
|
16595
|
-
|
|
16596
|
-
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
|
|
16676
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
16677
|
+
if (cfg.disabled) return false;
|
|
16678
|
+
const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
16679
|
+
const lease = acquireLease(
|
|
16680
|
+
opts.lease?.dir ?? join10(tmpdir3(), "hindsight-coding-agent", "surveys"),
|
|
16681
|
+
key,
|
|
16682
|
+
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
16683
|
+
);
|
|
16684
|
+
if (!lease) return false;
|
|
16685
|
+
const spec = {
|
|
16686
|
+
lease,
|
|
16687
|
+
bin: plan.bin,
|
|
16688
|
+
args: plan.args,
|
|
16689
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
16690
|
+
};
|
|
16691
|
+
const supervisorPath = opts.supervisorPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
16692
|
+
return await new Promise((resolve3) => {
|
|
16693
|
+
try {
|
|
16694
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
16695
|
+
cwd: repoDir,
|
|
16696
|
+
detached: true,
|
|
16697
|
+
stdio: "ignore",
|
|
16698
|
+
windowsHide: true,
|
|
16699
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
16700
|
+
});
|
|
16701
|
+
let spawned = false;
|
|
16702
|
+
child.on("error", () => {
|
|
16703
|
+
if (spawned) return;
|
|
16704
|
+
releaseLease(lease);
|
|
16705
|
+
resolve3(false);
|
|
16706
|
+
});
|
|
16707
|
+
child.once("spawn", () => {
|
|
16708
|
+
spawned = true;
|
|
16709
|
+
child.unref();
|
|
16710
|
+
resolve3(true);
|
|
16711
|
+
});
|
|
16712
|
+
} catch {
|
|
16713
|
+
releaseLease(lease);
|
|
16714
|
+
resolve3(false);
|
|
16715
|
+
}
|
|
16602
16716
|
});
|
|
16603
|
-
child.unref();
|
|
16604
|
-
return;
|
|
16605
16717
|
}
|
|
16606
16718
|
} catch {
|
|
16607
16719
|
}
|
|
16720
|
+
return false;
|
|
16608
16721
|
}
|
|
16609
16722
|
|
|
16610
16723
|
// src/core/status.ts
|
|
@@ -16717,7 +16830,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16717
16830
|
inputSchema: {},
|
|
16718
16831
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
16719
16832
|
handler: async (_args) => {
|
|
16720
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16833
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join11(homedir5(), ".hindsight", "coding-agent.json");
|
|
16721
16834
|
const harness = opts.harness ?? "unknown";
|
|
16722
16835
|
const cfg = applyBankConfig(
|
|
16723
16836
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16853,7 +16966,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16853
16966
|
}
|
|
16854
16967
|
|
|
16855
16968
|
// src/core/retain-cursor.ts
|
|
16856
|
-
import { createHash as
|
|
16969
|
+
import { createHash as createHash3 } from "crypto";
|
|
16857
16970
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16858
16971
|
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16859
16972
|
function pendingReplayable(cursor, now) {
|
|
@@ -16863,7 +16976,7 @@ function pendingReplayable(cursor, now) {
|
|
|
16863
16976
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16864
16977
|
}
|
|
16865
16978
|
function fingerprintTurns(turns, count) {
|
|
16866
|
-
const h =
|
|
16979
|
+
const h = createHash3("sha1").update(String(count));
|
|
16867
16980
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16868
16981
|
return h.digest("hex");
|
|
16869
16982
|
}
|
|
@@ -16886,13 +16999,13 @@ function memoryCursorStore() {
|
|
|
16886
16999
|
}
|
|
16887
17000
|
|
|
16888
17001
|
// src/core/uuid.ts
|
|
16889
|
-
import { createHash as
|
|
17002
|
+
import { createHash as createHash4 } from "crypto";
|
|
16890
17003
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16891
17004
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16892
17005
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16893
17006
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16894
17007
|
const bytes = Buffer.from(
|
|
16895
|
-
|
|
17008
|
+
createHash4("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16896
17009
|
);
|
|
16897
17010
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16898
17011
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -17096,12 +17209,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17096
17209
|
}
|
|
17097
17210
|
|
|
17098
17211
|
// src/core/session-start.ts
|
|
17099
|
-
import { readFileSync as
|
|
17212
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
17100
17213
|
|
|
17101
17214
|
// src/core/skill-sync.ts
|
|
17102
17215
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
17103
17216
|
import { homedir as homedir6 } from "os";
|
|
17104
|
-
import { dirname as dirname8, join as
|
|
17217
|
+
import { dirname as dirname8, join as join12 } from "path";
|
|
17105
17218
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17106
17219
|
|
|
17107
17220
|
// src/core/brand.ts
|
|
@@ -17118,29 +17231,66 @@ function brandWord() {
|
|
|
17118
17231
|
return `${out}\x1B[0m`;
|
|
17119
17232
|
}
|
|
17120
17233
|
|
|
17234
|
+
// src/core/legacy.ts
|
|
17235
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
17236
|
+
import { homedir as homedir7 } from "os";
|
|
17237
|
+
import { join as join13, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17238
|
+
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17239
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")) {
|
|
17240
|
+
const registry2 = readJson(join13(claudeDir, "plugins", "installed_plugins.json"));
|
|
17241
|
+
const plugins = registry2?.plugins;
|
|
17242
|
+
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17243
|
+
const enabled = readJson(join13(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17244
|
+
for (const [key, raw] of Object.entries(plugins)) {
|
|
17245
|
+
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17246
|
+
if (enabled && enabled[key] === false) continue;
|
|
17247
|
+
const installs = Array.isArray(raw) ? raw : [raw];
|
|
17248
|
+
const active = installs.some((i) => {
|
|
17249
|
+
if (!i || typeof i !== "object") return false;
|
|
17250
|
+
if (typeof i.projectPath !== "string") return true;
|
|
17251
|
+
const rel = relative(i.projectPath, cwd);
|
|
17252
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
17253
|
+
});
|
|
17254
|
+
if (active) return key;
|
|
17255
|
+
}
|
|
17256
|
+
return void 0;
|
|
17257
|
+
}
|
|
17258
|
+
function readJson(path) {
|
|
17259
|
+
try {
|
|
17260
|
+
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
17261
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
17262
|
+
} catch {
|
|
17263
|
+
return void 0;
|
|
17264
|
+
}
|
|
17265
|
+
}
|
|
17266
|
+
function legacyClaudePluginWarning(key) {
|
|
17267
|
+
return `\u26A0\uFE0F The old Hindsight Claude Code plugin (${key}) is still installed \u2014 it runs alongside this one, so memory is recalled and retained twice.
|
|
17268
|
+
\u21B3 remove it: claude plugin uninstall ${key}`;
|
|
17269
|
+
}
|
|
17270
|
+
|
|
17121
17271
|
// src/core/session-cache.ts
|
|
17122
|
-
import { mkdirSync as
|
|
17123
|
-
import { tmpdir as
|
|
17124
|
-
import { dirname as dirname9, join as
|
|
17272
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17273
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17274
|
+
import { dirname as dirname9, join as join14 } from "path";
|
|
17125
17275
|
function sessionCacheFile(harness, sessionId2) {
|
|
17126
|
-
return
|
|
17276
|
+
return join14(tmpdir4(), `hindsight-${harness}`, `${sessionId2}.json`);
|
|
17127
17277
|
}
|
|
17128
17278
|
function readSessionCache(cacheFile) {
|
|
17129
17279
|
try {
|
|
17130
|
-
return JSON.parse(
|
|
17280
|
+
return JSON.parse(readFileSync6(cacheFile, "utf8"));
|
|
17131
17281
|
} catch {
|
|
17132
17282
|
return {};
|
|
17133
17283
|
}
|
|
17134
17284
|
}
|
|
17135
17285
|
function writeFileAtomic(path, body) {
|
|
17136
|
-
|
|
17286
|
+
mkdirSync4(dirname9(path), { recursive: true });
|
|
17137
17287
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
17138
17288
|
try {
|
|
17139
|
-
|
|
17140
|
-
|
|
17289
|
+
writeFileSync3(tmp, body);
|
|
17290
|
+
renameSync2(tmp, path);
|
|
17141
17291
|
} catch (e) {
|
|
17142
17292
|
try {
|
|
17143
|
-
|
|
17293
|
+
rmSync2(tmp, { force: true });
|
|
17144
17294
|
} catch {
|
|
17145
17295
|
}
|
|
17146
17296
|
throw e;
|
|
@@ -17233,13 +17383,13 @@ async function buildSessionStartContext(args) {
|
|
|
17233
17383
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
17234
17384
|
if (docIds.size === 0) {
|
|
17235
17385
|
if (cfg.codebaseSurvey !== false) {
|
|
17236
|
-
startSurvey(cwd, {
|
|
17386
|
+
const started = await startSurvey(cwd, {
|
|
17237
17387
|
harness,
|
|
17238
17388
|
model: cfg.surveyModel,
|
|
17239
17389
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17240
17390
|
});
|
|
17241
17391
|
const sha = resolveHeadSha(cwd);
|
|
17242
|
-
if (sha) recordSurveyBaseline(sha);
|
|
17392
|
+
if (started && sha) recordSurveyBaseline(sha);
|
|
17243
17393
|
}
|
|
17244
17394
|
diag(harness, "seed_started", { bank: bankId });
|
|
17245
17395
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
@@ -17256,17 +17406,19 @@ async function buildSessionStartContext(args) {
|
|
|
17256
17406
|
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
17257
17407
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
17258
17408
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
17259
|
-
startSurvey(cwd, {
|
|
17409
|
+
const started = await startSurvey(cwd, {
|
|
17260
17410
|
harness,
|
|
17261
17411
|
model: cfg.surveyModel,
|
|
17262
17412
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17263
17413
|
});
|
|
17264
|
-
|
|
17265
|
-
|
|
17266
|
-
|
|
17267
|
-
|
|
17268
|
-
|
|
17269
|
-
|
|
17414
|
+
if (started) {
|
|
17415
|
+
recordSurveyBaseline(sha);
|
|
17416
|
+
diag(harness, "survey_refresh", {
|
|
17417
|
+
bank: bankId,
|
|
17418
|
+
commits: sinceLast,
|
|
17419
|
+
retry: findingsAbsent
|
|
17420
|
+
});
|
|
17421
|
+
}
|
|
17270
17422
|
} else if (sinceLast === null) {
|
|
17271
17423
|
recordSurveyBaseline(sha);
|
|
17272
17424
|
}
|
|
@@ -17299,12 +17451,19 @@ async function buildSessionStartContext(args) {
|
|
|
17299
17451
|
}).catch(() => void 0);
|
|
17300
17452
|
}
|
|
17301
17453
|
systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
|
|
17454
|
+
const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
|
|
17455
|
+
const legacyPlugin = detectLegacy?.(cwd);
|
|
17456
|
+
if (legacyPlugin) {
|
|
17457
|
+
systemMessage += `
|
|
17458
|
+
${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
17459
|
+
diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
|
|
17460
|
+
}
|
|
17302
17461
|
diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
|
|
17303
17462
|
return { systemMessage, additionalContext, deferInitialReflect };
|
|
17304
17463
|
}
|
|
17305
17464
|
|
|
17306
17465
|
// src/core/hook.ts
|
|
17307
|
-
import { existsSync as
|
|
17466
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
17308
17467
|
|
|
17309
17468
|
// src/core/inject.ts
|
|
17310
17469
|
function buildReflectQuery(prompt) {
|
|
@@ -17336,9 +17495,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17336
17495
|
}
|
|
17337
17496
|
|
|
17338
17497
|
// src/core/turn-journal.ts
|
|
17339
|
-
import { appendFileSync as appendFileSync3, mkdirSync as
|
|
17340
|
-
import { tmpdir as
|
|
17341
|
-
import { dirname as dirname10, join as
|
|
17498
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
|
|
17499
|
+
import { tmpdir as tmpdir5 } from "os";
|
|
17500
|
+
import { dirname as dirname10, join as join15 } from "path";
|
|
17342
17501
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17343
17502
|
|
|
17344
17503
|
// src/core/hook.ts
|
|
@@ -17356,13 +17515,14 @@ async function buildHookOutput(args) {
|
|
|
17356
17515
|
} else if (cfg.autoReflect && reflectAnswer === void 0) {
|
|
17357
17516
|
reflectRanThisTurn = true;
|
|
17358
17517
|
const t0 = Date.now();
|
|
17518
|
+
const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
|
|
17359
17519
|
try {
|
|
17360
17520
|
reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
|
|
17361
17521
|
// Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
|
|
17362
17522
|
// supported default for bounded reflect calls; callers that explicitly invoke the MCP
|
|
17363
17523
|
// tool still get the deeper high-budget path.
|
|
17364
17524
|
budget: "low",
|
|
17365
|
-
timeoutMs
|
|
17525
|
+
timeoutMs
|
|
17366
17526
|
});
|
|
17367
17527
|
diag(harness, reflectAnswer ? "reflect_ok" : "reflect_empty", {
|
|
17368
17528
|
ms: Date.now() - t0,
|
|
@@ -17380,7 +17540,10 @@ async function buildHookOutput(args) {
|
|
|
17380
17540
|
});
|
|
17381
17541
|
diag(harness, "reflect_failed", {
|
|
17382
17542
|
ms: Date.now() - t0,
|
|
17383
|
-
|
|
17543
|
+
bank: client.bank,
|
|
17544
|
+
timeoutMs,
|
|
17545
|
+
// Wider than describeError's default: the server's error body is the useful part.
|
|
17546
|
+
error: describeError(e, 1500),
|
|
17384
17547
|
query: prompt.slice(0, 80)
|
|
17385
17548
|
});
|
|
17386
17549
|
}
|