@vectorize-io/hindsight-coding-agents 0.5.2 → 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/README.md +42 -8
- package/dist/antigravity-hook.js +335 -91
- package/dist/antigravity-statusline.js +17 -10
- package/dist/antigravity-stop-hook.js +340 -92
- package/dist/claude-hook.js +335 -91
- package/dist/claude-sessionstart-hook.js +459 -132
- package/dist/claude-stop-hook.js +340 -92
- package/dist/cline.js +283 -64
- package/dist/codex-hook.js +335 -91
- package/dist/codex-sessionstart-hook.js +459 -132
- package/dist/codex-stop-hook.js +340 -92
- package/dist/copilot-hook.js +335 -91
- package/dist/copilot-sessionstart-hook.js +459 -132
- package/dist/copilot-stop-hook.js +340 -92
- package/dist/cursor-hook.js +335 -91
- package/dist/cursor-sessionstart-hook.js +459 -132
- package/dist/cursor-stop-hook.js +340 -92
- package/dist/daemon-start.js +17 -10
- package/dist/dcode-hook.js +335 -91
- package/dist/dcode-sessionstart-hook.js +459 -132
- package/dist/dcode-stop-hook.js +340 -92
- package/dist/deepen.js +113 -32
- package/dist/devin-hook.js +335 -91
- package/dist/devin-sessionstart-hook.js +459 -132
- package/dist/devin-stop-hook.js +340 -92
- package/dist/droid-hook.js +335 -91
- package/dist/droid-sessionstart-hook.js +459 -132
- package/dist/droid-stop-hook.js +340 -92
- package/dist/dsh.js +322 -101
- package/dist/grok-hook.js +335 -91
- package/dist/grok-sessionstart-hook.js +459 -132
- package/dist/grok-stop-hook.js +340 -92
- package/dist/hindsight-seed.js +17 -10
- package/dist/index.js +322 -101
- package/dist/installer.js +1252 -325
- package/dist/kilo.js +322 -101
- package/dist/mcp-server.js +100 -23
- package/dist/opencode2.js +322 -101
- package/dist/pi.js +321 -100
- package/dist/prime-agent.js +321 -100
- package/dist/qwen-hook.js +335 -91
- package/dist/qwen-sessionstart-hook.js +459 -132
- package/dist/qwen-stop-hook.js +340 -92
- package/dist/status.js +98 -21
- package/dist/survey-supervisor.js +81 -0
- package/dist/zcode-hook.js +2954 -0
- package/dist/zcode-sessionstart-hook.js +3655 -0
- package/dist/zcode-stop-hook.js +3218 -0
- package/package.json +7 -3
- package/plugin.json +1 -1
- package/skill/SKILL.md +17 -7
package/dist/kilo.js
CHANGED
|
@@ -478,6 +478,7 @@ function pagesFor(project) {
|
|
|
478
478
|
var PAGE_MAX_TOKENS = 4096;
|
|
479
479
|
var PAGE_TAGS_MATCH = "all";
|
|
480
480
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
481
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
481
482
|
var CRON_FIELD_RANGES = [
|
|
482
483
|
[0, 59],
|
|
483
484
|
// minute
|
|
@@ -531,14 +532,23 @@ function pageTriggerFor(trigger, bank, page) {
|
|
|
531
532
|
function buildPageTrigger(cfg = {}) {
|
|
532
533
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
533
534
|
switch (cfg.pageTriggerType) {
|
|
534
|
-
case "
|
|
535
|
-
return { ...base,
|
|
535
|
+
case "auto-refresh":
|
|
536
|
+
return { ...base, refresh_after_consolidation: true };
|
|
536
537
|
case "manual":
|
|
537
538
|
return { ...base, refresh_after_consolidation: false };
|
|
539
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
540
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
538
541
|
default:
|
|
539
|
-
return { ...base,
|
|
542
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
540
543
|
}
|
|
541
544
|
}
|
|
545
|
+
function pageTriggerDrifted(current2, desired) {
|
|
546
|
+
return current2.tags_match !== desired.tags_match || (current2.refresh_cron ?? null) !== (desired.refresh_cron ?? null) || Boolean(current2.refresh_after_consolidation) !== Boolean(desired.refresh_after_consolidation);
|
|
547
|
+
}
|
|
548
|
+
function pageTriggerPatch(desired) {
|
|
549
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
550
|
+
return desired;
|
|
551
|
+
}
|
|
542
552
|
var CODING_BANK_TEMPLATE = {
|
|
543
553
|
version: "1",
|
|
544
554
|
bank: {
|
|
@@ -962,9 +972,16 @@ var HindsightClient = class {
|
|
|
962
972
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
963
973
|
signal: ctrl.signal
|
|
964
974
|
});
|
|
965
|
-
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
|
+
);
|
|
966
979
|
const data = await resp.json();
|
|
967
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;
|
|
968
985
|
} finally {
|
|
969
986
|
clearTimeout(timer);
|
|
970
987
|
}
|
|
@@ -1097,14 +1114,14 @@ var HindsightClient = class {
|
|
|
1097
1114
|
if (r.status !== 409) created++;
|
|
1098
1115
|
} else {
|
|
1099
1116
|
const sourceDrift = hit.description !== page.source_query;
|
|
1100
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1117
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1101
1118
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1102
1119
|
const patch = {};
|
|
1103
1120
|
if (sourceDrift) {
|
|
1104
1121
|
patch.source_query = page.source_query;
|
|
1105
1122
|
patch.tags = page.tags;
|
|
1106
1123
|
}
|
|
1107
|
-
if (triggerDrift) patch.trigger =
|
|
1124
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1108
1125
|
const r = await this.req(
|
|
1109
1126
|
"PATCH",
|
|
1110
1127
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1120,9 +1137,41 @@ var HindsightClient = class {
|
|
|
1120
1137
|
updated++;
|
|
1121
1138
|
}
|
|
1122
1139
|
}
|
|
1140
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1123
1141
|
this.log(
|
|
1124
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1142
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged` + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1147
|
+
*
|
|
1148
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1149
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1150
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1151
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1152
|
+
*
|
|
1153
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1154
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1155
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1156
|
+
*/
|
|
1157
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1158
|
+
const folder = roots.find(
|
|
1159
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1125
1160
|
);
|
|
1161
|
+
let updated = 0;
|
|
1162
|
+
for (const page of folder?.children ?? []) {
|
|
1163
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1164
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1165
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1166
|
+
const r = await this.req(
|
|
1167
|
+
"PATCH",
|
|
1168
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1169
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1170
|
+
);
|
|
1171
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1172
|
+
updated++;
|
|
1173
|
+
}
|
|
1174
|
+
return updated;
|
|
1126
1175
|
}
|
|
1127
1176
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1128
1177
|
slugify(s) {
|
|
@@ -1145,11 +1194,13 @@ var HindsightClient = class {
|
|
|
1145
1194
|
let pageId = args.relatesToPageId;
|
|
1146
1195
|
if (!pageId) {
|
|
1147
1196
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1197
|
+
const subject = this.project ?? this.bank;
|
|
1148
1198
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1149
1199
|
name: args.title,
|
|
1150
|
-
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory
|
|
1200
|
+
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory.` + pageScopeRule(subject),
|
|
1151
1201
|
parent_id: folderId,
|
|
1152
1202
|
tags: ["knowledge:feature-work"],
|
|
1203
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1153
1204
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1154
1205
|
});
|
|
1155
1206
|
try {
|
|
@@ -1192,17 +1243,22 @@ var HindsightClient = class {
|
|
|
1192
1243
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1193
1244
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1194
1245
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1195
|
-
function
|
|
1196
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1197
|
-
if (raw.pageTriggerType === "
|
|
1198
|
-
|
|
1199
|
-
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1246
|
+
function resolvePageTrigger(raw) {
|
|
1247
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1248
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1249
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1200
1250
|
log.warn(
|
|
1201
1251
|
"config",
|
|
1202
|
-
|
|
1252
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1203
1253
|
);
|
|
1204
|
-
|
|
1205
|
-
return "
|
|
1254
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1255
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1256
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1257
|
+
log.warn(
|
|
1258
|
+
"config",
|
|
1259
|
+
`pageTriggerCron ${JSON.stringify(cron)} has a malformed hashed field \u2014 write \`H\` or \`H(<lo>-<hi>)\` within the field's own range, e.g. "H H(0-5) * * *" \u2014 falling back to ${JSON.stringify(DEFAULT_PAGE_TRIGGER_CRON)}`
|
|
1260
|
+
);
|
|
1261
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1206
1262
|
}
|
|
1207
1263
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1208
1264
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1234,6 +1290,7 @@ function resolveObservationScopes(raw) {
|
|
|
1234
1290
|
function resolveConfig(raw = {}) {
|
|
1235
1291
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1236
1292
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1293
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1237
1294
|
return {
|
|
1238
1295
|
serverMode,
|
|
1239
1296
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1268,8 +1325,8 @@ function resolveConfig(raw = {}) {
|
|
|
1268
1325
|
reflectBudget: resolveReflectBudget(raw),
|
|
1269
1326
|
autoReflect: raw.autoReflect ?? true,
|
|
1270
1327
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1271
|
-
pageTriggerType:
|
|
1272
|
-
pageTriggerCron:
|
|
1328
|
+
pageTriggerType: pageTrigger.type,
|
|
1329
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1273
1330
|
autoSeed: raw.autoSeed ?? true,
|
|
1274
1331
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1275
1332
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -16306,7 +16363,7 @@ config(en_default());
|
|
|
16306
16363
|
// src/core/knowledge-tools.ts
|
|
16307
16364
|
import { existsSync as existsSync4 } from "fs";
|
|
16308
16365
|
import { homedir as homedir5 } from "os";
|
|
16309
|
-
import { join as
|
|
16366
|
+
import { join as join11 } from "path";
|
|
16310
16367
|
|
|
16311
16368
|
// src/core/status.ts
|
|
16312
16369
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -16392,11 +16449,86 @@ ${toolGuide(opts)}
|
|
|
16392
16449
|
}
|
|
16393
16450
|
|
|
16394
16451
|
// src/core/survey.ts
|
|
16395
|
-
import { spawn as
|
|
16452
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
16453
|
+
import { createHash as createHash2 } from "crypto";
|
|
16396
16454
|
import { existsSync as existsSync3 } from "fs";
|
|
16397
|
-
import { homedir as homedir4 } from "os";
|
|
16398
|
-
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";
|
|
16399
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
|
|
16400
16532
|
var SURVEY_DOC_IDS = [
|
|
16401
16533
|
"repository-component-map",
|
|
16402
16534
|
"repository-core-concepts",
|
|
@@ -16406,7 +16538,7 @@ var SURVEY_DOC_IDS = [
|
|
|
16406
16538
|
function resolveClaudeBin(explicit) {
|
|
16407
16539
|
if (explicit) return explicit;
|
|
16408
16540
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
16409
|
-
const nativeInstallPath =
|
|
16541
|
+
const nativeInstallPath = join10(homedir4(), ".claude", "local", "claude");
|
|
16410
16542
|
try {
|
|
16411
16543
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
16412
16544
|
} catch {
|
|
@@ -16531,11 +16663,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
16531
16663
|
}
|
|
16532
16664
|
}
|
|
16533
16665
|
}
|
|
16534
|
-
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16666
|
+
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16535
16667
|
try {
|
|
16536
|
-
const spawnFn = opts.spawn ??
|
|
16668
|
+
const spawnFn = opts.spawn ?? realSpawn5;
|
|
16537
16669
|
const exists = opts.exists ?? binOnPath;
|
|
16538
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16670
|
+
const mcpServerPath = opts.mcpServerPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16539
16671
|
const preferred = opts.harness ?? "claude-code";
|
|
16540
16672
|
const order = [
|
|
16541
16673
|
preferred,
|
|
@@ -16555,20 +16687,51 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16555
16687
|
budgetUsd: opts.budgetUsd,
|
|
16556
16688
|
mcpServerPath
|
|
16557
16689
|
});
|
|
16558
|
-
const
|
|
16559
|
-
|
|
16560
|
-
|
|
16561
|
-
|
|
16562
|
-
|
|
16563
|
-
|
|
16564
|
-
|
|
16565
|
-
|
|
16690
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
16691
|
+
if (cfg.disabled) return false;
|
|
16692
|
+
const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
16693
|
+
const lease = acquireLease(
|
|
16694
|
+
opts.lease?.dir ?? join10(tmpdir3(), "hindsight-coding-agent", "surveys"),
|
|
16695
|
+
key,
|
|
16696
|
+
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
16697
|
+
);
|
|
16698
|
+
if (!lease) return false;
|
|
16699
|
+
const spec = {
|
|
16700
|
+
lease,
|
|
16701
|
+
bin: plan.bin,
|
|
16702
|
+
args: plan.args,
|
|
16703
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
16704
|
+
};
|
|
16705
|
+
const supervisorPath = opts.supervisorPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
16706
|
+
return await new Promise((resolve3) => {
|
|
16707
|
+
try {
|
|
16708
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
16709
|
+
cwd: repoDir,
|
|
16710
|
+
detached: true,
|
|
16711
|
+
stdio: "ignore",
|
|
16712
|
+
windowsHide: true,
|
|
16713
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
16714
|
+
});
|
|
16715
|
+
let spawned = false;
|
|
16716
|
+
child.on("error", () => {
|
|
16717
|
+
if (spawned) return;
|
|
16718
|
+
releaseLease(lease);
|
|
16719
|
+
resolve3(false);
|
|
16720
|
+
});
|
|
16721
|
+
child.once("spawn", () => {
|
|
16722
|
+
spawned = true;
|
|
16723
|
+
child.unref();
|
|
16724
|
+
resolve3(true);
|
|
16725
|
+
});
|
|
16726
|
+
} catch {
|
|
16727
|
+
releaseLease(lease);
|
|
16728
|
+
resolve3(false);
|
|
16729
|
+
}
|
|
16566
16730
|
});
|
|
16567
|
-
child.unref();
|
|
16568
|
-
return;
|
|
16569
16731
|
}
|
|
16570
16732
|
} catch {
|
|
16571
16733
|
}
|
|
16734
|
+
return false;
|
|
16572
16735
|
}
|
|
16573
16736
|
|
|
16574
16737
|
// src/core/status.ts
|
|
@@ -16681,7 +16844,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16681
16844
|
inputSchema: {},
|
|
16682
16845
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
16683
16846
|
handler: async (_args) => {
|
|
16684
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16847
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join11(homedir5(), ".hindsight", "coding-agent.json");
|
|
16685
16848
|
const harness = opts.harness ?? "unknown";
|
|
16686
16849
|
const cfg = applyBankConfig(
|
|
16687
16850
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16817,7 +16980,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16817
16980
|
}
|
|
16818
16981
|
|
|
16819
16982
|
// src/core/retain-cursor.ts
|
|
16820
|
-
import { createHash as
|
|
16983
|
+
import { createHash as createHash3 } from "crypto";
|
|
16821
16984
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16822
16985
|
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16823
16986
|
function pendingReplayable(cursor, now) {
|
|
@@ -16827,7 +16990,7 @@ function pendingReplayable(cursor, now) {
|
|
|
16827
16990
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16828
16991
|
}
|
|
16829
16992
|
function fingerprintTurns(turns, count) {
|
|
16830
|
-
const h =
|
|
16993
|
+
const h = createHash3("sha1").update(String(count));
|
|
16831
16994
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16832
16995
|
return h.digest("hex");
|
|
16833
16996
|
}
|
|
@@ -16850,13 +17013,13 @@ function memoryCursorStore() {
|
|
|
16850
17013
|
}
|
|
16851
17014
|
|
|
16852
17015
|
// src/core/uuid.ts
|
|
16853
|
-
import { createHash as
|
|
17016
|
+
import { createHash as createHash4 } from "crypto";
|
|
16854
17017
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16855
17018
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16856
17019
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16857
17020
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16858
17021
|
const bytes = Buffer.from(
|
|
16859
|
-
|
|
17022
|
+
createHash4("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16860
17023
|
);
|
|
16861
17024
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16862
17025
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -17060,12 +17223,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17060
17223
|
}
|
|
17061
17224
|
|
|
17062
17225
|
// src/core/session-start.ts
|
|
17063
|
-
import { readFileSync as
|
|
17226
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
17064
17227
|
|
|
17065
17228
|
// src/core/skill-sync.ts
|
|
17066
17229
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
17067
17230
|
import { homedir as homedir6 } from "os";
|
|
17068
|
-
import { dirname as dirname8, join as
|
|
17231
|
+
import { dirname as dirname8, join as join12 } from "path";
|
|
17069
17232
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17070
17233
|
|
|
17071
17234
|
// src/core/brand.ts
|
|
@@ -17082,29 +17245,66 @@ function brandWord() {
|
|
|
17082
17245
|
return `${out}\x1B[0m`;
|
|
17083
17246
|
}
|
|
17084
17247
|
|
|
17248
|
+
// src/core/legacy.ts
|
|
17249
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
17250
|
+
import { homedir as homedir7 } from "os";
|
|
17251
|
+
import { join as join13, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17252
|
+
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17253
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")) {
|
|
17254
|
+
const registry3 = readJson(join13(claudeDir, "plugins", "installed_plugins.json"));
|
|
17255
|
+
const plugins = registry3?.plugins;
|
|
17256
|
+
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17257
|
+
const enabled = readJson(join13(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17258
|
+
for (const [key, raw] of Object.entries(plugins)) {
|
|
17259
|
+
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17260
|
+
if (enabled && enabled[key] === false) continue;
|
|
17261
|
+
const installs = Array.isArray(raw) ? raw : [raw];
|
|
17262
|
+
const active = installs.some((i) => {
|
|
17263
|
+
if (!i || typeof i !== "object") return false;
|
|
17264
|
+
if (typeof i.projectPath !== "string") return true;
|
|
17265
|
+
const rel = relative(i.projectPath, cwd);
|
|
17266
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
17267
|
+
});
|
|
17268
|
+
if (active) return key;
|
|
17269
|
+
}
|
|
17270
|
+
return void 0;
|
|
17271
|
+
}
|
|
17272
|
+
function readJson(path) {
|
|
17273
|
+
try {
|
|
17274
|
+
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
17275
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
17276
|
+
} catch {
|
|
17277
|
+
return void 0;
|
|
17278
|
+
}
|
|
17279
|
+
}
|
|
17280
|
+
function legacyClaudePluginWarning(key) {
|
|
17281
|
+
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.
|
|
17282
|
+
\u21B3 remove it: claude plugin uninstall ${key}`;
|
|
17283
|
+
}
|
|
17284
|
+
|
|
17085
17285
|
// src/core/session-cache.ts
|
|
17086
|
-
import { mkdirSync as
|
|
17087
|
-
import { tmpdir as
|
|
17088
|
-
import { dirname as dirname9, join as
|
|
17286
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17287
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17288
|
+
import { dirname as dirname9, join as join14 } from "path";
|
|
17089
17289
|
function sessionCacheFile(harness, sessionId) {
|
|
17090
|
-
return
|
|
17290
|
+
return join14(tmpdir4(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
17091
17291
|
}
|
|
17092
17292
|
function readSessionCache(cacheFile) {
|
|
17093
17293
|
try {
|
|
17094
|
-
return JSON.parse(
|
|
17294
|
+
return JSON.parse(readFileSync6(cacheFile, "utf8"));
|
|
17095
17295
|
} catch {
|
|
17096
17296
|
return {};
|
|
17097
17297
|
}
|
|
17098
17298
|
}
|
|
17099
17299
|
function writeFileAtomic(path, body) {
|
|
17100
|
-
|
|
17300
|
+
mkdirSync4(dirname9(path), { recursive: true });
|
|
17101
17301
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
17102
17302
|
try {
|
|
17103
|
-
|
|
17104
|
-
|
|
17303
|
+
writeFileSync3(tmp, body);
|
|
17304
|
+
renameSync2(tmp, path);
|
|
17105
17305
|
} catch (e) {
|
|
17106
17306
|
try {
|
|
17107
|
-
|
|
17307
|
+
rmSync2(tmp, { force: true });
|
|
17108
17308
|
} catch {
|
|
17109
17309
|
}
|
|
17110
17310
|
throw e;
|
|
@@ -17197,13 +17397,13 @@ async function buildSessionStartContext(args) {
|
|
|
17197
17397
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
17198
17398
|
if (docIds.size === 0) {
|
|
17199
17399
|
if (cfg.codebaseSurvey !== false) {
|
|
17200
|
-
startSurvey(cwd, {
|
|
17400
|
+
const started = await startSurvey(cwd, {
|
|
17201
17401
|
harness,
|
|
17202
17402
|
model: cfg.surveyModel,
|
|
17203
17403
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17204
17404
|
});
|
|
17205
17405
|
const sha = resolveHeadSha(cwd);
|
|
17206
|
-
if (sha) recordSurveyBaseline(sha);
|
|
17406
|
+
if (started && sha) recordSurveyBaseline(sha);
|
|
17207
17407
|
}
|
|
17208
17408
|
diag(harness, "seed_started", { bank: bankId });
|
|
17209
17409
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
@@ -17220,17 +17420,19 @@ async function buildSessionStartContext(args) {
|
|
|
17220
17420
|
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
17221
17421
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
17222
17422
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
17223
|
-
startSurvey(cwd, {
|
|
17423
|
+
const started = await startSurvey(cwd, {
|
|
17224
17424
|
harness,
|
|
17225
17425
|
model: cfg.surveyModel,
|
|
17226
17426
|
budgetUsd: cfg.surveyBudgetUsd
|
|
17227
17427
|
});
|
|
17228
|
-
|
|
17229
|
-
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17428
|
+
if (started) {
|
|
17429
|
+
recordSurveyBaseline(sha);
|
|
17430
|
+
diag(harness, "survey_refresh", {
|
|
17431
|
+
bank: bankId,
|
|
17432
|
+
commits: sinceLast,
|
|
17433
|
+
retry: findingsAbsent
|
|
17434
|
+
});
|
|
17435
|
+
}
|
|
17234
17436
|
} else if (sinceLast === null) {
|
|
17235
17437
|
recordSurveyBaseline(sha);
|
|
17236
17438
|
}
|
|
@@ -17263,12 +17465,19 @@ async function buildSessionStartContext(args) {
|
|
|
17263
17465
|
}).catch(() => void 0);
|
|
17264
17466
|
}
|
|
17265
17467
|
systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
|
|
17468
|
+
const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
|
|
17469
|
+
const legacyPlugin = detectLegacy?.(cwd);
|
|
17470
|
+
if (legacyPlugin) {
|
|
17471
|
+
systemMessage += `
|
|
17472
|
+
${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
17473
|
+
diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
|
|
17474
|
+
}
|
|
17266
17475
|
diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
|
|
17267
17476
|
return { systemMessage, additionalContext, deferInitialReflect };
|
|
17268
17477
|
}
|
|
17269
17478
|
|
|
17270
17479
|
// src/core/hook.ts
|
|
17271
|
-
import { existsSync as
|
|
17480
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
17272
17481
|
|
|
17273
17482
|
// src/core/inject.ts
|
|
17274
17483
|
function buildReflectQuery(prompt) {
|
|
@@ -17299,6 +17508,49 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17299
17508
|
` + memory + "\n</hindsight_memory>";
|
|
17300
17509
|
}
|
|
17301
17510
|
|
|
17511
|
+
// src/core/turn-journal.ts
|
|
17512
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
|
|
17513
|
+
import { tmpdir as tmpdir5 } from "os";
|
|
17514
|
+
import { dirname as dirname10, join as join15 } from "path";
|
|
17515
|
+
|
|
17516
|
+
// src/core/transcript-util.ts
|
|
17517
|
+
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;
|
|
17518
|
+
function stripInjectedMemory(s) {
|
|
17519
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
17520
|
+
}
|
|
17521
|
+
var TARGET_KEYS = [
|
|
17522
|
+
"file_path",
|
|
17523
|
+
"path",
|
|
17524
|
+
"notebook_path",
|
|
17525
|
+
"command",
|
|
17526
|
+
"pattern",
|
|
17527
|
+
"query",
|
|
17528
|
+
"url",
|
|
17529
|
+
"name",
|
|
17530
|
+
"id"
|
|
17531
|
+
];
|
|
17532
|
+
var ACTION_TARGET_CAP = 100;
|
|
17533
|
+
function actionLine(tool2, input) {
|
|
17534
|
+
let target = "";
|
|
17535
|
+
if (input && typeof input === "object") {
|
|
17536
|
+
const rec = input;
|
|
17537
|
+
for (const k of TARGET_KEYS) {
|
|
17538
|
+
const v = rec[k];
|
|
17539
|
+
if (typeof v === "string" && v.trim()) {
|
|
17540
|
+
target = v.trim().split("\n")[0];
|
|
17541
|
+
break;
|
|
17542
|
+
}
|
|
17543
|
+
}
|
|
17544
|
+
} else if (typeof input === "string") {
|
|
17545
|
+
target = input.trim().split("\n")[0];
|
|
17546
|
+
}
|
|
17547
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17548
|
+
return target ? `${tool2} ${target}` : tool2;
|
|
17549
|
+
}
|
|
17550
|
+
|
|
17551
|
+
// src/core/turn-journal.ts
|
|
17552
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17553
|
+
|
|
17302
17554
|
// src/core/hook.ts
|
|
17303
17555
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
17304
17556
|
async function buildHookOutput(args) {
|
|
@@ -17314,13 +17566,14 @@ async function buildHookOutput(args) {
|
|
|
17314
17566
|
} else if (cfg.autoReflect && reflectAnswer === void 0) {
|
|
17315
17567
|
reflectRanThisTurn = true;
|
|
17316
17568
|
const t0 = Date.now();
|
|
17569
|
+
const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
|
|
17317
17570
|
try {
|
|
17318
17571
|
reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
|
|
17319
17572
|
// Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
|
|
17320
17573
|
// supported default for bounded reflect calls; callers that explicitly invoke the MCP
|
|
17321
17574
|
// tool still get the deeper high-budget path.
|
|
17322
17575
|
budget: "low",
|
|
17323
|
-
timeoutMs
|
|
17576
|
+
timeoutMs
|
|
17324
17577
|
});
|
|
17325
17578
|
diag(harness, reflectAnswer ? "reflect_ok" : "reflect_empty", {
|
|
17326
17579
|
ms: Date.now() - t0,
|
|
@@ -17338,7 +17591,10 @@ async function buildHookOutput(args) {
|
|
|
17338
17591
|
});
|
|
17339
17592
|
diag(harness, "reflect_failed", {
|
|
17340
17593
|
ms: Date.now() - t0,
|
|
17341
|
-
|
|
17594
|
+
bank: client.bank,
|
|
17595
|
+
timeoutMs,
|
|
17596
|
+
// Wider than describeError's default: the server's error body is the useful part.
|
|
17597
|
+
error: describeError(e, 1500),
|
|
17342
17598
|
query: prompt.slice(0, 80)
|
|
17343
17599
|
});
|
|
17344
17600
|
}
|
|
@@ -17608,41 +17864,6 @@ var RuntimeCore = class {
|
|
|
17608
17864
|
}
|
|
17609
17865
|
};
|
|
17610
17866
|
|
|
17611
|
-
// src/core/transcript-util.ts
|
|
17612
|
-
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;
|
|
17613
|
-
function stripInjectedMemory(s) {
|
|
17614
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
17615
|
-
}
|
|
17616
|
-
var TARGET_KEYS = [
|
|
17617
|
-
"file_path",
|
|
17618
|
-
"path",
|
|
17619
|
-
"notebook_path",
|
|
17620
|
-
"command",
|
|
17621
|
-
"pattern",
|
|
17622
|
-
"query",
|
|
17623
|
-
"url",
|
|
17624
|
-
"name",
|
|
17625
|
-
"id"
|
|
17626
|
-
];
|
|
17627
|
-
var ACTION_TARGET_CAP = 100;
|
|
17628
|
-
function actionLine(tool2, input) {
|
|
17629
|
-
let target = "";
|
|
17630
|
-
if (input && typeof input === "object") {
|
|
17631
|
-
const rec = input;
|
|
17632
|
-
for (const k of TARGET_KEYS) {
|
|
17633
|
-
const v = rec[k];
|
|
17634
|
-
if (typeof v === "string" && v.trim()) {
|
|
17635
|
-
target = v.trim().split("\n")[0];
|
|
17636
|
-
break;
|
|
17637
|
-
}
|
|
17638
|
-
}
|
|
17639
|
-
} else if (typeof input === "string") {
|
|
17640
|
-
target = input.trim().split("\n")[0];
|
|
17641
|
-
}
|
|
17642
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17643
|
-
return target ? `${tool2} ${target}` : tool2;
|
|
17644
|
-
}
|
|
17645
|
-
|
|
17646
17867
|
// src/core/transcript-opencode.ts
|
|
17647
17868
|
function renderMessage(m) {
|
|
17648
17869
|
const role = m.info?.role;
|
|
@@ -30096,12 +30317,12 @@ function tool(input) {
|
|
|
30096
30317
|
tool.schema = external_exports2;
|
|
30097
30318
|
|
|
30098
30319
|
// src/harness/registry.ts
|
|
30099
|
-
import { readFileSync as
|
|
30320
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
30100
30321
|
var jsonChatReader = (harness) => ({
|
|
30101
30322
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
30102
30323
|
async read(opts) {
|
|
30103
30324
|
if (!opts.conversations) return [];
|
|
30104
|
-
return JSON.parse(
|
|
30325
|
+
return JSON.parse(readFileSync10(opts.conversations, "utf8"));
|
|
30105
30326
|
}
|
|
30106
30327
|
});
|
|
30107
30328
|
|