@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/droid-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/dsh.js
CHANGED
|
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/dsh.ts
|
|
8
|
-
import { randomUUID } from "crypto";
|
|
8
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
9
9
|
|
|
10
10
|
// src/core/config.ts
|
|
11
11
|
import { readFileSync as readFileSync2 } from "fs";
|
|
@@ -972,9 +972,16 @@ var HindsightClient = class {
|
|
|
972
972
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
973
973
|
signal: ctrl.signal
|
|
974
974
|
});
|
|
975
|
-
if (!resp.ok)
|
|
975
|
+
if (!resp.ok)
|
|
976
|
+
throw new Error(
|
|
977
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
978
|
+
);
|
|
976
979
|
const data = await resp.json();
|
|
977
980
|
return (data.text || "").trim();
|
|
981
|
+
} catch (e) {
|
|
982
|
+
if (ctrl.signal.aborted)
|
|
983
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
984
|
+
throw e;
|
|
978
985
|
} finally {
|
|
979
986
|
clearTimeout(timer);
|
|
980
987
|
}
|
|
@@ -16356,7 +16363,7 @@ config(en_default());
|
|
|
16356
16363
|
// src/core/knowledge-tools.ts
|
|
16357
16364
|
import { existsSync as existsSync4 } from "fs";
|
|
16358
16365
|
import { homedir as homedir5 } from "os";
|
|
16359
|
-
import { join as
|
|
16366
|
+
import { join as join11 } from "path";
|
|
16360
16367
|
|
|
16361
16368
|
// src/core/status.ts
|
|
16362
16369
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -16442,11 +16449,86 @@ ${toolGuide(opts)}
|
|
|
16442
16449
|
}
|
|
16443
16450
|
|
|
16444
16451
|
// src/core/survey.ts
|
|
16445
|
-
import { spawn as
|
|
16452
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
16453
|
+
import { createHash as createHash2 } from "crypto";
|
|
16446
16454
|
import { existsSync as existsSync3 } from "fs";
|
|
16447
|
-
import { homedir as homedir4 } from "os";
|
|
16448
|
-
import { dirname as dirname7, join as
|
|
16455
|
+
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
16456
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
16449
16457
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
16458
|
+
|
|
16459
|
+
// src/core/survey-lease.ts
|
|
16460
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
16461
|
+
import { randomUUID } from "crypto";
|
|
16462
|
+
import {
|
|
16463
|
+
mkdirSync as mkdirSync3,
|
|
16464
|
+
mkdtempSync,
|
|
16465
|
+
readdirSync,
|
|
16466
|
+
renameSync,
|
|
16467
|
+
rmdirSync,
|
|
16468
|
+
rmSync,
|
|
16469
|
+
statSync,
|
|
16470
|
+
unlinkSync as unlinkSync2,
|
|
16471
|
+
utimesSync,
|
|
16472
|
+
writeFileSync as writeFileSync2
|
|
16473
|
+
} from "fs";
|
|
16474
|
+
import { join as join9 } from "path";
|
|
16475
|
+
var LEASE_STALE_MS = 3e4;
|
|
16476
|
+
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
16477
|
+
function tryRename(from, to) {
|
|
16478
|
+
try {
|
|
16479
|
+
renameSync(from, to);
|
|
16480
|
+
return true;
|
|
16481
|
+
} catch {
|
|
16482
|
+
return false;
|
|
16483
|
+
}
|
|
16484
|
+
}
|
|
16485
|
+
function releaseLease(lease) {
|
|
16486
|
+
try {
|
|
16487
|
+
unlinkSync2(join9(lease.directory, lease.owner));
|
|
16488
|
+
} catch {
|
|
16489
|
+
return;
|
|
16490
|
+
}
|
|
16491
|
+
try {
|
|
16492
|
+
rmdirSync(lease.directory);
|
|
16493
|
+
} catch {
|
|
16494
|
+
}
|
|
16495
|
+
}
|
|
16496
|
+
function reclaimIfStale(directory, staleMs) {
|
|
16497
|
+
const owners = readdirSync(directory);
|
|
16498
|
+
if (owners.length === 0) {
|
|
16499
|
+
try {
|
|
16500
|
+
rmdirSync(directory);
|
|
16501
|
+
} catch {
|
|
16502
|
+
}
|
|
16503
|
+
return true;
|
|
16504
|
+
}
|
|
16505
|
+
if (owners.length !== 1) return false;
|
|
16506
|
+
const age = Date.now() - statSync(join9(directory, owners[0])).mtimeMs;
|
|
16507
|
+
if (Math.abs(age) <= staleMs) return false;
|
|
16508
|
+
releaseLease({ directory, owner: owners[0] });
|
|
16509
|
+
return true;
|
|
16510
|
+
}
|
|
16511
|
+
function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
16512
|
+
let staging;
|
|
16513
|
+
try {
|
|
16514
|
+
mkdirSync3(root, { recursive: true, mode: 448 });
|
|
16515
|
+
staging = mkdtempSync(join9(root, "claim-"));
|
|
16516
|
+
const owner = randomUUID();
|
|
16517
|
+
writeFileSync2(join9(staging, owner), "", { flag: "wx", mode: 384 });
|
|
16518
|
+
const directory = join9(root, `survey-${key}.lock`);
|
|
16519
|
+
if (!tryRename(staging, directory)) {
|
|
16520
|
+
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
16521
|
+
if (!tryRename(staging, directory)) return void 0;
|
|
16522
|
+
}
|
|
16523
|
+
return { directory, owner };
|
|
16524
|
+
} catch {
|
|
16525
|
+
return void 0;
|
|
16526
|
+
} finally {
|
|
16527
|
+
if (staging) rmSync(staging, { recursive: true, force: true });
|
|
16528
|
+
}
|
|
16529
|
+
}
|
|
16530
|
+
|
|
16531
|
+
// src/core/survey.ts
|
|
16450
16532
|
var SURVEY_DOC_IDS = [
|
|
16451
16533
|
"repository-component-map",
|
|
16452
16534
|
"repository-core-concepts",
|
|
@@ -16456,7 +16538,7 @@ var SURVEY_DOC_IDS = [
|
|
|
16456
16538
|
function resolveClaudeBin(explicit) {
|
|
16457
16539
|
if (explicit) return explicit;
|
|
16458
16540
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
16459
|
-
const nativeInstallPath =
|
|
16541
|
+
const nativeInstallPath = join10(homedir4(), ".claude", "local", "claude");
|
|
16460
16542
|
try {
|
|
16461
16543
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
16462
16544
|
} catch {
|
|
@@ -16570,11 +16652,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
16570
16652
|
}
|
|
16571
16653
|
}
|
|
16572
16654
|
}
|
|
16573
|
-
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16655
|
+
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16574
16656
|
try {
|
|
16575
|
-
const spawnFn = opts.spawn ??
|
|
16657
|
+
const spawnFn = opts.spawn ?? realSpawn5;
|
|
16576
16658
|
const exists = opts.exists ?? binOnPath;
|
|
16577
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16659
|
+
const mcpServerPath = opts.mcpServerPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16578
16660
|
const preferred = opts.harness ?? "claude-code";
|
|
16579
16661
|
const order = [
|
|
16580
16662
|
preferred,
|
|
@@ -16594,20 +16676,51 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16594
16676
|
budgetUsd: opts.budgetUsd,
|
|
16595
16677
|
mcpServerPath
|
|
16596
16678
|
});
|
|
16597
|
-
const
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
|
|
16602
|
-
|
|
16603
|
-
|
|
16604
|
-
|
|
16679
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
16680
|
+
if (cfg.disabled) return false;
|
|
16681
|
+
const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
16682
|
+
const lease = acquireLease(
|
|
16683
|
+
opts.lease?.dir ?? join10(tmpdir3(), "hindsight-coding-agent", "surveys"),
|
|
16684
|
+
key,
|
|
16685
|
+
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
16686
|
+
);
|
|
16687
|
+
if (!lease) return false;
|
|
16688
|
+
const spec = {
|
|
16689
|
+
lease,
|
|
16690
|
+
bin: plan.bin,
|
|
16691
|
+
args: plan.args,
|
|
16692
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
16693
|
+
};
|
|
16694
|
+
const supervisorPath = opts.supervisorPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
16695
|
+
return await new Promise((resolve3) => {
|
|
16696
|
+
try {
|
|
16697
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
16698
|
+
cwd: repoDir,
|
|
16699
|
+
detached: true,
|
|
16700
|
+
stdio: "ignore",
|
|
16701
|
+
windowsHide: true,
|
|
16702
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
16703
|
+
});
|
|
16704
|
+
let spawned = false;
|
|
16705
|
+
child.on("error", () => {
|
|
16706
|
+
if (spawned) return;
|
|
16707
|
+
releaseLease(lease);
|
|
16708
|
+
resolve3(false);
|
|
16709
|
+
});
|
|
16710
|
+
child.once("spawn", () => {
|
|
16711
|
+
spawned = true;
|
|
16712
|
+
child.unref();
|
|
16713
|
+
resolve3(true);
|
|
16714
|
+
});
|
|
16715
|
+
} catch {
|
|
16716
|
+
releaseLease(lease);
|
|
16717
|
+
resolve3(false);
|
|
16718
|
+
}
|
|
16605
16719
|
});
|
|
16606
|
-
child.unref();
|
|
16607
|
-
return;
|
|
16608
16720
|
}
|
|
16609
16721
|
} catch {
|
|
16610
16722
|
}
|
|
16723
|
+
return false;
|
|
16611
16724
|
}
|
|
16612
16725
|
|
|
16613
16726
|
// src/core/status.ts
|
|
@@ -16720,7 +16833,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16720
16833
|
inputSchema: {},
|
|
16721
16834
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
16722
16835
|
handler: async (_args) => {
|
|
16723
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16836
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join11(homedir5(), ".hindsight", "coding-agent.json");
|
|
16724
16837
|
const harness = opts.harness ?? "unknown";
|
|
16725
16838
|
const cfg = applyBankConfig(
|
|
16726
16839
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16856,7 +16969,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16856
16969
|
}
|
|
16857
16970
|
|
|
16858
16971
|
// src/core/retain-cursor.ts
|
|
16859
|
-
import { createHash as
|
|
16972
|
+
import { createHash as createHash3 } from "crypto";
|
|
16860
16973
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16861
16974
|
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16862
16975
|
function pendingReplayable(cursor, now) {
|
|
@@ -16866,7 +16979,7 @@ function pendingReplayable(cursor, now) {
|
|
|
16866
16979
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16867
16980
|
}
|
|
16868
16981
|
function fingerprintTurns(turns, count) {
|
|
16869
|
-
const h =
|
|
16982
|
+
const h = createHash3("sha1").update(String(count));
|
|
16870
16983
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16871
16984
|
return h.digest("hex");
|
|
16872
16985
|
}
|
|
@@ -16889,13 +17002,13 @@ function memoryCursorStore() {
|
|
|
16889
17002
|
}
|
|
16890
17003
|
|
|
16891
17004
|
// src/core/uuid.ts
|
|
16892
|
-
import { createHash as
|
|
17005
|
+
import { createHash as createHash4 } from "crypto";
|
|
16893
17006
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16894
17007
|
function uuidV5(name2, namespace = HINDSIGHT_NAMESPACE) {
|
|
16895
17008
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16896
17009
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16897
17010
|
const bytes = Buffer.from(
|
|
16898
|
-
|
|
17011
|
+
createHash4("sha1").update(ns).update(Buffer.from(name2, "utf8")).digest().subarray(0, 16)
|
|
16899
17012
|
);
|
|
16900
17013
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16901
17014
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -17099,12 +17212,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17099
17212
|
}
|
|
17100
17213
|
|
|
17101
17214
|
// src/core/session-start.ts
|
|
17102
|
-
import { readFileSync as
|
|
17215
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
17103
17216
|
|
|
17104
17217
|
// src/core/skill-sync.ts
|
|
17105
17218
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
17106
17219
|
import { homedir as homedir6 } from "os";
|
|
17107
|
-
import { dirname as dirname8, join as
|
|
17220
|
+
import { dirname as dirname8, join as join12 } from "path";
|
|
17108
17221
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17109
17222
|
|
|
17110
17223
|
// src/core/brand.ts
|
|
@@ -17121,29 +17234,66 @@ function brandWord() {
|
|
|
17121
17234
|
return `${out}\x1B[0m`;
|
|
17122
17235
|
}
|
|
17123
17236
|
|
|
17237
|
+
// src/core/legacy.ts
|
|
17238
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
17239
|
+
import { homedir as homedir7 } from "os";
|
|
17240
|
+
import { join as join13, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17241
|
+
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17242
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")) {
|
|
17243
|
+
const registry2 = readJson(join13(claudeDir, "plugins", "installed_plugins.json"));
|
|
17244
|
+
const plugins = registry2?.plugins;
|
|
17245
|
+
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17246
|
+
const enabled = readJson(join13(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17247
|
+
for (const [key, raw] of Object.entries(plugins)) {
|
|
17248
|
+
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17249
|
+
if (enabled && enabled[key] === false) continue;
|
|
17250
|
+
const installs = Array.isArray(raw) ? raw : [raw];
|
|
17251
|
+
const active = installs.some((i) => {
|
|
17252
|
+
if (!i || typeof i !== "object") return false;
|
|
17253
|
+
if (typeof i.projectPath !== "string") return true;
|
|
17254
|
+
const rel = relative(i.projectPath, cwd);
|
|
17255
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
17256
|
+
});
|
|
17257
|
+
if (active) return key;
|
|
17258
|
+
}
|
|
17259
|
+
return void 0;
|
|
17260
|
+
}
|
|
17261
|
+
function readJson(path) {
|
|
17262
|
+
try {
|
|
17263
|
+
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
17264
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
17265
|
+
} catch {
|
|
17266
|
+
return void 0;
|
|
17267
|
+
}
|
|
17268
|
+
}
|
|
17269
|
+
function legacyClaudePluginWarning(key) {
|
|
17270
|
+
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.
|
|
17271
|
+
\u21B3 remove it: claude plugin uninstall ${key}`;
|
|
17272
|
+
}
|
|
17273
|
+
|
|
17124
17274
|
// src/core/session-cache.ts
|
|
17125
|
-
import { mkdirSync as
|
|
17126
|
-
import { tmpdir as
|
|
17127
|
-
import { dirname as dirname9, join as
|
|
17275
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17276
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17277
|
+
import { dirname as dirname9, join as join14 } from "path";
|
|
17128
17278
|
function sessionCacheFile(harness, sessionId) {
|
|
17129
|
-
return
|
|
17279
|
+
return join14(tmpdir4(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
17130
17280
|
}
|
|
17131
17281
|
function readSessionCache(cacheFile) {
|
|
17132
17282
|
try {
|
|
17133
|
-
return JSON.parse(
|
|
17283
|
+
return JSON.parse(readFileSync6(cacheFile, "utf8"));
|
|
17134
17284
|
} catch {
|
|
17135
17285
|
return {};
|
|
17136
17286
|
}
|
|
17137
17287
|
}
|
|
17138
17288
|
function writeFileAtomic(path, body) {
|
|
17139
|
-
|
|
17289
|
+
mkdirSync4(dirname9(path), { recursive: true });
|
|
17140
17290
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
17141
17291
|
try {
|
|
17142
|
-
|
|
17143
|
-
|
|
17292
|
+
writeFileSync3(tmp, body);
|
|
17293
|
+
renameSync2(tmp, path);
|
|
17144
17294
|
} catch (e) {
|
|
17145
17295
|
try {
|
|
17146
|
-
|
|
17296
|
+
rmSync2(tmp, { force: true });
|
|
17147
17297
|
} catch {
|
|
17148
17298
|
}
|
|
17149
17299
|
throw e;
|
|
@@ -17236,13 +17386,13 @@ async function buildSessionStartContext(args) {
|
|
|
17236
17386
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
17237
17387
|
if (docIds.size === 0) {
|
|
17238
17388
|
if (cfg.codebaseSurvey !== false) {
|
|
17239
|
-
startSurvey(cwd, {
|
|
17389
|
+
const started = await startSurvey(cwd, {
|
|
17240
17390
|
harness,
|
|
17241
17391
|
model: cfg.surveyModel,
|
|
17242
17392
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17243
17393
|
});
|
|
17244
17394
|
const sha = resolveHeadSha(cwd);
|
|
17245
|
-
if (sha) recordSurveyBaseline(sha);
|
|
17395
|
+
if (started && sha) recordSurveyBaseline(sha);
|
|
17246
17396
|
}
|
|
17247
17397
|
diag(harness, "seed_started", { bank: bankId });
|
|
17248
17398
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
@@ -17259,17 +17409,19 @@ async function buildSessionStartContext(args) {
|
|
|
17259
17409
|
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
17260
17410
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
17261
17411
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
17262
|
-
startSurvey(cwd, {
|
|
17412
|
+
const started = await startSurvey(cwd, {
|
|
17263
17413
|
harness,
|
|
17264
17414
|
model: cfg.surveyModel,
|
|
17265
17415
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17266
17416
|
});
|
|
17267
|
-
|
|
17268
|
-
|
|
17269
|
-
|
|
17270
|
-
|
|
17271
|
-
|
|
17272
|
-
|
|
17417
|
+
if (started) {
|
|
17418
|
+
recordSurveyBaseline(sha);
|
|
17419
|
+
diag(harness, "survey_refresh", {
|
|
17420
|
+
bank: bankId,
|
|
17421
|
+
commits: sinceLast,
|
|
17422
|
+
retry: findingsAbsent
|
|
17423
|
+
});
|
|
17424
|
+
}
|
|
17273
17425
|
} else if (sinceLast === null) {
|
|
17274
17426
|
recordSurveyBaseline(sha);
|
|
17275
17427
|
}
|
|
@@ -17302,12 +17454,19 @@ async function buildSessionStartContext(args) {
|
|
|
17302
17454
|
}).catch(() => void 0);
|
|
17303
17455
|
}
|
|
17304
17456
|
systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
|
|
17457
|
+
const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
|
|
17458
|
+
const legacyPlugin = detectLegacy?.(cwd);
|
|
17459
|
+
if (legacyPlugin) {
|
|
17460
|
+
systemMessage += `
|
|
17461
|
+
${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
17462
|
+
diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
|
|
17463
|
+
}
|
|
17305
17464
|
diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
|
|
17306
17465
|
return { systemMessage, additionalContext, deferInitialReflect };
|
|
17307
17466
|
}
|
|
17308
17467
|
|
|
17309
17468
|
// src/core/hook.ts
|
|
17310
|
-
import { existsSync as
|
|
17469
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
17311
17470
|
|
|
17312
17471
|
// src/core/inject.ts
|
|
17313
17472
|
function buildReflectQuery(prompt) {
|
|
@@ -17339,9 +17498,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17339
17498
|
}
|
|
17340
17499
|
|
|
17341
17500
|
// src/core/turn-journal.ts
|
|
17342
|
-
import { appendFileSync as appendFileSync3, mkdirSync as
|
|
17343
|
-
import { tmpdir as
|
|
17344
|
-
import { dirname as dirname10, join as
|
|
17501
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
|
|
17502
|
+
import { tmpdir as tmpdir5 } from "os";
|
|
17503
|
+
import { dirname as dirname10, join as join15 } from "path";
|
|
17345
17504
|
|
|
17346
17505
|
// src/core/transcript-util.ts
|
|
17347
17506
|
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;
|
|
@@ -17396,13 +17555,14 @@ async function buildHookOutput(args) {
|
|
|
17396
17555
|
} else if (cfg.autoReflect && reflectAnswer === void 0) {
|
|
17397
17556
|
reflectRanThisTurn = true;
|
|
17398
17557
|
const t0 = Date.now();
|
|
17558
|
+
const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
|
|
17399
17559
|
try {
|
|
17400
17560
|
reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
|
|
17401
17561
|
// Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
|
|
17402
17562
|
// supported default for bounded reflect calls; callers that explicitly invoke the MCP
|
|
17403
17563
|
// tool still get the deeper high-budget path.
|
|
17404
17564
|
budget: "low",
|
|
17405
|
-
timeoutMs
|
|
17565
|
+
timeoutMs
|
|
17406
17566
|
});
|
|
17407
17567
|
diag(harness, reflectAnswer ? "reflect_ok" : "reflect_empty", {
|
|
17408
17568
|
ms: Date.now() - t0,
|
|
@@ -17420,7 +17580,10 @@ async function buildHookOutput(args) {
|
|
|
17420
17580
|
});
|
|
17421
17581
|
diag(harness, "reflect_failed", {
|
|
17422
17582
|
ms: Date.now() - t0,
|
|
17423
|
-
|
|
17583
|
+
bank: client.bank,
|
|
17584
|
+
timeoutMs,
|
|
17585
|
+
// Wider than describeError's default: the server's error body is the useful part.
|
|
17586
|
+
error: describeError(e, 1500),
|
|
17424
17587
|
query: prompt.slice(0, 80)
|
|
17425
17588
|
});
|
|
17426
17589
|
}
|
|
@@ -17775,7 +17938,7 @@ function promptOf(messages) {
|
|
|
17775
17938
|
}
|
|
17776
17939
|
function injectionMessage(text) {
|
|
17777
17940
|
return {
|
|
17778
|
-
id:
|
|
17941
|
+
id: randomUUID2(),
|
|
17779
17942
|
role: "user",
|
|
17780
17943
|
content: [{ type: "text", text }],
|
|
17781
17944
|
source: { kind: "plugin", plugin: HINDSIGHT_PLUGIN, form: "recall" }
|