@vectorize-io/hindsight-coding-agents 0.8.5 → 0.8.7
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 +36 -30
- package/dist/antigravity-hook.js +130 -135
- package/dist/antigravity-statusline.js +1 -1
- package/dist/antigravity-stop-hook.js +113 -114
- package/dist/claude-hook.js +130 -135
- package/dist/claude-sessionstart-hook.js +205 -215
- package/dist/claude-stop-hook.js +113 -114
- package/dist/cline.js +206 -211
- package/dist/codebuddy-hook.js +130 -135
- package/dist/codebuddy-sessionstart-hook.js +205 -215
- package/dist/codebuddy-stop-hook.js +113 -114
- package/dist/codex-hook.js +130 -135
- package/dist/codex-sessionstart-hook.js +205 -215
- package/dist/codex-stop-hook.js +113 -114
- package/dist/copilot-hook.js +130 -135
- package/dist/copilot-sessionstart-hook.js +205 -215
- package/dist/copilot-stop-hook.js +113 -114
- package/dist/cursor-hook.js +130 -135
- package/dist/cursor-sessionstart-hook.js +205 -215
- package/dist/cursor-stop-hook.js +113 -114
- package/dist/daemon-start.js +1 -1
- package/dist/dcode-hook.js +130 -135
- package/dist/dcode-sessionstart-hook.js +205 -215
- package/dist/dcode-stop-hook.js +113 -114
- package/dist/deepen.js +80 -79
- package/dist/devin-hook.js +130 -135
- package/dist/devin-sessionstart-hook.js +205 -215
- package/dist/devin-stop-hook.js +113 -114
- package/dist/droid-hook.js +130 -135
- package/dist/droid-sessionstart-hook.js +205 -215
- package/dist/droid-stop-hook.js +113 -114
- package/dist/dsh.js +235 -248
- package/dist/grok-hook.js +130 -135
- package/dist/grok-sessionstart-hook.js +205 -215
- package/dist/grok-stop-hook.js +113 -114
- package/dist/hindsight-seed.js +1 -1
- package/dist/index.js +236 -249
- package/dist/installer.js +30 -28
- package/dist/kilo.js +236 -249
- package/dist/kimi-hook.js +130 -135
- package/dist/kimi-sessionstart-hook.js +205 -215
- package/dist/kimi-stop-hook.js +113 -114
- package/dist/mcp-server.js +94 -93
- package/dist/opencode2.js +236 -249
- package/dist/pi.js +235 -248
- package/dist/prime-agent.js +235 -248
- package/dist/qwen-hook.js +130 -135
- package/dist/qwen-sessionstart-hook.js +205 -215
- package/dist/qwen-stop-hook.js +113 -114
- package/dist/status.js +80 -79
- package/dist/traecode-hook.js +130 -135
- package/dist/traecode-sessionstart-hook.js +205 -215
- package/dist/traecode-stop-hook.js +113 -114
- package/dist/workbuddy-hook.js +130 -135
- package/dist/workbuddy-sessionstart-hook.js +205 -215
- package/dist/workbuddy-stop-hook.js +113 -114
- package/dist/zcode-hook.js +130 -135
- package/dist/zcode-sessionstart-hook.js +205 -215
- package/dist/zcode-stop-hook.js +113 -114
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +26 -26
|
@@ -457,14 +457,14 @@ var RETAIN_STRATEGIES = {
|
|
|
457
457
|
retain_chunk_size: 12e3
|
|
458
458
|
}
|
|
459
459
|
};
|
|
460
|
-
var
|
|
460
|
+
var PAGE_LABELS = {
|
|
461
461
|
key: "knowledge",
|
|
462
462
|
type: "multi-values",
|
|
463
463
|
// 0, 1, or several — empty is normal
|
|
464
464
|
optional: true,
|
|
465
465
|
tag: true,
|
|
466
466
|
// emits knowledge:<value> onto the fact's tags
|
|
467
|
-
description: "Routing labels for this project's Hindsight
|
|
467
|
+
description: "Routing labels for this project's Hindsight PAGES \u2014 curated, human-readable summaries of the repo's DURABLE engineering knowledge (architecture, key decisions, conventions, ongoing initiatives), each page rebuilt automatically from the facts labeled for it. Mark a fact only when it is durable, reusable knowledge a developer would still want surfaced in future sessions. IMPORTANT: leave this EMPTY for routine, transient, or operational facts \u2014 a passing test, a one-off command, a status update, a debugging dead-end. MOST facts should get no label here. Assign more than one value only when the fact genuinely fits several.",
|
|
468
468
|
values: [
|
|
469
469
|
{
|
|
470
470
|
value: "feature-work",
|
|
@@ -621,7 +621,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
621
621
|
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
622
622
|
retain_default_strategy: "git",
|
|
623
623
|
retain_strategies: RETAIN_STRATEGIES,
|
|
624
|
-
entity_labels: [
|
|
624
|
+
entity_labels: [PAGE_LABELS],
|
|
625
625
|
entities_allow_free_form: true
|
|
626
626
|
}
|
|
627
627
|
};
|
|
@@ -673,7 +673,7 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
// package.json
|
|
676
|
-
var version = "0.8.
|
|
676
|
+
var version = "0.8.7";
|
|
677
677
|
|
|
678
678
|
// src/core/util.ts
|
|
679
679
|
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
@@ -765,11 +765,11 @@ function retryAfterMs(header) {
|
|
|
765
765
|
const at = Date.parse(header);
|
|
766
766
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
767
767
|
}
|
|
768
|
-
var
|
|
769
|
-
code = "
|
|
768
|
+
var PagesUnavailableError = class extends Error {
|
|
769
|
+
code = "pages_unavailable";
|
|
770
770
|
constructor() {
|
|
771
|
-
super("Hindsight server does not support
|
|
772
|
-
this.name = "
|
|
771
|
+
super("Hindsight server does not support pages");
|
|
772
|
+
this.name = "PagesUnavailableError";
|
|
773
773
|
}
|
|
774
774
|
};
|
|
775
775
|
async function isEndpointMissing(r) {
|
|
@@ -780,6 +780,10 @@ async function isEndpointMissing(r) {
|
|
|
780
780
|
return false;
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
|
+
function pagesPath(sub, legacy = false) {
|
|
784
|
+
if (!legacy) return `/pages${sub}`;
|
|
785
|
+
return /^\/(tree|folders|search|export|nodes)\b/.test(sub) ? `/knowledge-base${sub}` : `/knowledge-base/pages${sub}`;
|
|
786
|
+
}
|
|
783
787
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
784
788
|
var ReflectError = class extends Error {
|
|
785
789
|
constructor(message, status, timedOut, options) {
|
|
@@ -848,7 +852,7 @@ var HindsightClient = class {
|
|
|
848
852
|
opIds = [];
|
|
849
853
|
// async operation ids collected by retain(), for drain()
|
|
850
854
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
851
|
-
|
|
855
|
+
pagesSupported;
|
|
852
856
|
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
853
857
|
idempotentRetain;
|
|
854
858
|
log;
|
|
@@ -1077,7 +1081,7 @@ var HindsightClient = class {
|
|
|
1077
1081
|
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
1078
1082
|
}
|
|
1079
1083
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
1080
|
-
* entity labels), then seed
|
|
1084
|
+
* entity labels), then seed pages when the server supports them. Both halves are
|
|
1081
1085
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
1082
1086
|
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
1083
1087
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
@@ -1259,29 +1263,45 @@ var HindsightClient = class {
|
|
|
1259
1263
|
const j = await r.json();
|
|
1260
1264
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
1261
1265
|
}
|
|
1266
|
+
/** Set once a server answered on the deprecated `/knowledge-base/...` paths: one from before the
|
|
1267
|
+
* page routes moved to `/pages/...`. Remove in 2.x. */
|
|
1268
|
+
legacyPagesPaths = false;
|
|
1262
1269
|
/**
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1270
|
+
* Request a page endpoint by its `/pages` sub-path (`""`, `/tree`, `/<id>`, `/nodes/<id>`, …).
|
|
1271
|
+
*
|
|
1272
|
+
* Returns `null` — and latches `pagesSupported = false` — iff the endpoint is really absent: an
|
|
1273
|
+
* unrouted 404 on the `/pages` path AND on its pre-rename `/knowledge-base` twin, which a server
|
|
1274
|
+
* older than the rename still serves (tried once, then remembered). A bank-not-found 404 is NOT
|
|
1275
|
+
* a capability verdict — it is the expected answer before the bank's first retain — so it is
|
|
1276
|
+
* returned as-is and never caches a negative (#4607). A 404's body may already be consumed.
|
|
1266
1277
|
*
|
|
1267
1278
|
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1268
1279
|
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1269
1280
|
*/
|
|
1270
|
-
async
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
return
|
|
1281
|
+
async pagesReq(method, sub, body, tolerate = [], timeoutMs) {
|
|
1282
|
+
const send = (legacy) => this.req(method, this.bankUrl(pagesPath(sub, legacy)), body, tolerate, timeoutMs);
|
|
1283
|
+
let r = await send(this.legacyPagesPaths);
|
|
1284
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return r;
|
|
1285
|
+
if (!this.legacyPagesPaths) {
|
|
1286
|
+
r = await send(true);
|
|
1287
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) {
|
|
1288
|
+
this.legacyPagesPaths = true;
|
|
1289
|
+
return r;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
this.pagesSupported = false;
|
|
1293
|
+
return null;
|
|
1274
1294
|
}
|
|
1275
1295
|
/**
|
|
1276
|
-
* The bank's
|
|
1296
|
+
* The bank's page tree (folders + pages, nested). The tree carries names, source
|
|
1277
1297
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
1278
1298
|
*/
|
|
1279
1299
|
async tree() {
|
|
1280
|
-
if (this.
|
|
1281
|
-
const r = await this.
|
|
1282
|
-
if (
|
|
1300
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1301
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1302
|
+
if (!r) throw new PagesUnavailableError();
|
|
1283
1303
|
if (r.status === 404) return [];
|
|
1284
|
-
this.
|
|
1304
|
+
this.pagesSupported = true;
|
|
1285
1305
|
try {
|
|
1286
1306
|
return (await r.json()).roots ?? [];
|
|
1287
1307
|
} catch {
|
|
@@ -1289,13 +1309,13 @@ var HindsightClient = class {
|
|
|
1289
1309
|
}
|
|
1290
1310
|
}
|
|
1291
1311
|
/**
|
|
1292
|
-
* List
|
|
1312
|
+
* List pages (ids + names only — no synthesized content), flattened out of the tree
|
|
1293
1313
|
* and shaped as `{items:[…]}` for `parsePageList`. Folders are dropped: they carry no content
|
|
1294
1314
|
* to read, and a caller enumerating pages wants leaves, not structure.
|
|
1295
1315
|
*
|
|
1296
|
-
* NOTE the ids are
|
|
1297
|
-
* page read/update in this client goes through the same
|
|
1298
|
-
* here, from `
|
|
1316
|
+
* NOTE the ids are page node ids (`kp-…`), NOT the backing mental-model ids. Every
|
|
1317
|
+
* page read/update in this client goes through the same page ids, so a page id from
|
|
1318
|
+
* here, from `searchPages`, or from a `[[page:<id>]]` link all resolve identically.
|
|
1299
1319
|
*/
|
|
1300
1320
|
async listPages() {
|
|
1301
1321
|
const items = [];
|
|
@@ -1317,34 +1337,26 @@ var HindsightClient = class {
|
|
|
1317
1337
|
return { items };
|
|
1318
1338
|
}
|
|
1319
1339
|
/**
|
|
1320
|
-
* Read one
|
|
1340
|
+
* Read one page's synthesized content by page id, shaped by `shapePage` so
|
|
1321
1341
|
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1322
1342
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1323
1343
|
* token cap.
|
|
1324
1344
|
*/
|
|
1325
1345
|
async getPage(pageId) {
|
|
1326
|
-
if (this.
|
|
1327
|
-
const r = await this.
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
);
|
|
1331
|
-
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1346
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1347
|
+
const r = await this.pagesReq("GET", `/${encodeURIComponent(pageId)}`);
|
|
1348
|
+
if (!r) throw new PagesUnavailableError();
|
|
1349
|
+
if (r.status === 404) throw new Error(`page not found: ${pageId}`);
|
|
1332
1350
|
return shapePage(await r.json());
|
|
1333
1351
|
}
|
|
1334
|
-
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's
|
|
1352
|
+
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's pages.
|
|
1335
1353
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1336
|
-
*
|
|
1337
|
-
async
|
|
1338
|
-
if (this.
|
|
1354
|
+
* hindsight_search_pages. */
|
|
1355
|
+
async searchPages(query, opts = {}) {
|
|
1356
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1339
1357
|
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1340
|
-
const r = await this.
|
|
1341
|
-
|
|
1342
|
-
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1343
|
-
void 0,
|
|
1344
|
-
[],
|
|
1345
|
-
opts.timeoutMs
|
|
1346
|
-
);
|
|
1347
|
-
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1358
|
+
const r = await this.pagesReq("GET", `/search${q}`, void 0, [], opts.timeoutMs);
|
|
1359
|
+
if (!r) throw new PagesUnavailableError();
|
|
1348
1360
|
if (r.status === 404) return [];
|
|
1349
1361
|
const j = await r.json();
|
|
1350
1362
|
return (j.results ?? []).map((x) => ({
|
|
@@ -1356,9 +1368,9 @@ var HindsightClient = class {
|
|
|
1356
1368
|
}));
|
|
1357
1369
|
}
|
|
1358
1370
|
/**
|
|
1359
|
-
* Seed the fixed page taxonomy as
|
|
1371
|
+
* Seed the fixed page taxonomy as pages at the tree root, idempotently.
|
|
1360
1372
|
*
|
|
1361
|
-
* Matched by NAME, not id:
|
|
1373
|
+
* Matched by NAME, not id: `POST /pages` mints its own `kp-…` id, so a stable
|
|
1362
1374
|
* client-chosen id isn't available to match on (unlike the old mental-model path, which keyed
|
|
1363
1375
|
* off a slug). Names are unique per folder server-side, which makes them a sound key.
|
|
1364
1376
|
*
|
|
@@ -1373,8 +1385,8 @@ var HindsightClient = class {
|
|
|
1373
1385
|
try {
|
|
1374
1386
|
roots = await this.tree();
|
|
1375
1387
|
} catch (e) {
|
|
1376
|
-
if (e instanceof
|
|
1377
|
-
this.log(`[bank]
|
|
1388
|
+
if (e instanceof PagesUnavailableError) {
|
|
1389
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1378
1390
|
return;
|
|
1379
1391
|
}
|
|
1380
1392
|
throw e;
|
|
@@ -1397,11 +1409,9 @@ var HindsightClient = class {
|
|
|
1397
1409
|
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1398
1410
|
};
|
|
1399
1411
|
if (!hit) {
|
|
1400
|
-
const r = await this.
|
|
1401
|
-
if (
|
|
1402
|
-
this.log(
|
|
1403
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1404
|
-
);
|
|
1412
|
+
const r = await this.pagesReq("POST", "", body, [409]);
|
|
1413
|
+
if (!r) {
|
|
1414
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1405
1415
|
return;
|
|
1406
1416
|
}
|
|
1407
1417
|
if (r.status === 404) {
|
|
@@ -1422,15 +1432,9 @@ var HindsightClient = class {
|
|
|
1422
1432
|
);
|
|
1423
1433
|
}
|
|
1424
1434
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1425
|
-
const r = await this.
|
|
1426
|
-
|
|
1427
|
-
this.
|
|
1428
|
-
patch
|
|
1429
|
-
);
|
|
1430
|
-
if (await this.pagesUnsupported(r)) {
|
|
1431
|
-
this.log(
|
|
1432
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1433
|
-
);
|
|
1435
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(hit.id)}`, patch);
|
|
1436
|
+
if (!r) {
|
|
1437
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1434
1438
|
return;
|
|
1435
1439
|
}
|
|
1436
1440
|
if (r.status === 404) {
|
|
@@ -1442,7 +1446,7 @@ var HindsightClient = class {
|
|
|
1442
1446
|
}
|
|
1443
1447
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1444
1448
|
this.log(
|
|
1445
|
-
`[bank]
|
|
1449
|
+
`[bank] pages seeded on ${this.bank} (scoped to ${this.project ?? "the shared bank"}): ${created} created, ${updated} re-synced, ${pages.length - created - updated - vanished} unchanged` + (vanished ? `, ${vanished} deleted under us` : "") + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1446
1450
|
);
|
|
1447
1451
|
}
|
|
1448
1452
|
/**
|
|
@@ -1476,12 +1480,8 @@ var HindsightClient = class {
|
|
|
1476
1480
|
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
1477
1481
|
}
|
|
1478
1482
|
if (!patch.trigger && !patch.source_query) continue;
|
|
1479
|
-
const r = await this.
|
|
1480
|
-
|
|
1481
|
-
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1482
|
-
patch
|
|
1483
|
-
);
|
|
1484
|
-
if (r.status === 404) continue;
|
|
1483
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(page.id)}`, patch);
|
|
1484
|
+
if (!r || r.status === 404) continue;
|
|
1485
1485
|
updated++;
|
|
1486
1486
|
}
|
|
1487
1487
|
return updated;
|
|
@@ -1507,7 +1507,7 @@ var HindsightClient = class {
|
|
|
1507
1507
|
let pageId = args.relatesToPageId;
|
|
1508
1508
|
if (!pageId) {
|
|
1509
1509
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1510
|
-
const r = await this.
|
|
1510
|
+
const r = await this.pagesReq("POST", "", {
|
|
1511
1511
|
name: args.title,
|
|
1512
1512
|
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(this.project),
|
|
1513
1513
|
parent_id: folderId,
|
|
@@ -1516,8 +1516,8 @@ var HindsightClient = class {
|
|
|
1516
1516
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1517
1517
|
});
|
|
1518
1518
|
try {
|
|
1519
|
-
const j = await r
|
|
1520
|
-
pageId = j
|
|
1519
|
+
const j = await r?.json();
|
|
1520
|
+
pageId = j?.page_id ?? j?.id;
|
|
1521
1521
|
} catch {
|
|
1522
1522
|
}
|
|
1523
1523
|
pageId ||= `initiative-${this.slugify(args.title)}`;
|
|
@@ -1535,16 +1535,17 @@ var HindsightClient = class {
|
|
|
1535
1535
|
/** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
|
|
1536
1536
|
async ensureFolder(name) {
|
|
1537
1537
|
try {
|
|
1538
|
-
const
|
|
1539
|
-
const
|
|
1538
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1539
|
+
const tree = await r?.json();
|
|
1540
|
+
const hit = (tree?.roots || []).find(
|
|
1540
1541
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === name.toLowerCase()
|
|
1541
1542
|
);
|
|
1542
1543
|
if (hit?.id) return hit.id;
|
|
1543
1544
|
} catch {
|
|
1544
1545
|
}
|
|
1545
1546
|
try {
|
|
1546
|
-
const r = await this.
|
|
1547
|
-
return (await r
|
|
1547
|
+
const r = await this.pagesReq("POST", "/folders", { name });
|
|
1548
|
+
return (await r?.json())?.id;
|
|
1548
1549
|
} catch {
|
|
1549
1550
|
return void 0;
|
|
1550
1551
|
}
|
|
@@ -1942,6 +1943,41 @@ function resolvePartial(cfg, patch) {
|
|
|
1942
1943
|
return out;
|
|
1943
1944
|
}
|
|
1944
1945
|
|
|
1946
|
+
// src/core/transcript-util.ts
|
|
1947
|
+
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_pages|hindsight_page_refresh|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
1948
|
+
function stripInjectedMemory(s) {
|
|
1949
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
1950
|
+
}
|
|
1951
|
+
var TARGET_KEYS = [
|
|
1952
|
+
"file_path",
|
|
1953
|
+
"path",
|
|
1954
|
+
"notebook_path",
|
|
1955
|
+
"command",
|
|
1956
|
+
"pattern",
|
|
1957
|
+
"query",
|
|
1958
|
+
"url",
|
|
1959
|
+
"name",
|
|
1960
|
+
"id"
|
|
1961
|
+
];
|
|
1962
|
+
var ACTION_TARGET_CAP = 100;
|
|
1963
|
+
function actionLine(tool, input) {
|
|
1964
|
+
let target = "";
|
|
1965
|
+
if (input && typeof input === "object") {
|
|
1966
|
+
const rec = input;
|
|
1967
|
+
for (const k of TARGET_KEYS) {
|
|
1968
|
+
const v = rec[k];
|
|
1969
|
+
if (typeof v === "string" && v.trim()) {
|
|
1970
|
+
target = v.trim().split("\n")[0];
|
|
1971
|
+
break;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
} else if (typeof input === "string") {
|
|
1975
|
+
target = input.trim().split("\n")[0];
|
|
1976
|
+
}
|
|
1977
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1978
|
+
return target ? `${tool} ${target}` : tool;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1945
1981
|
// src/core/brand.ts
|
|
1946
1982
|
function brandWord() {
|
|
1947
1983
|
const start = [0, 116, 217];
|
|
@@ -1956,7 +1992,7 @@ function brandWord() {
|
|
|
1956
1992
|
return `${out}\x1B[0m`;
|
|
1957
1993
|
}
|
|
1958
1994
|
|
|
1959
|
-
// src/core/
|
|
1995
|
+
// src/core/page-injection.ts
|
|
1960
1996
|
function parsePageList(raw) {
|
|
1961
1997
|
const items = raw?.items;
|
|
1962
1998
|
if (!Array.isArray(items)) return [];
|
|
@@ -1968,12 +2004,12 @@ function parsePageList(raw) {
|
|
|
1968
2004
|
}
|
|
1969
2005
|
return out;
|
|
1970
2006
|
}
|
|
1971
|
-
var EMPTY_STATE = "No
|
|
2007
|
+
var EMPTY_STATE = "No pages yet \u2014 Hindsight is still learning this repo; they'll appear as it processes.";
|
|
1972
2008
|
function indexLine(pages) {
|
|
1973
|
-
const count = pages.length === 1 ? "1
|
|
1974
|
-
return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call
|
|
2009
|
+
const count = pages.length === 1 ? "1 page covers" : `${pages.length} pages cover`;
|
|
2010
|
+
return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call hindsight_search_pages(query) to find the ones that bear on the current turn, then hindsight_read_page(<id>) on anything the results show is worth reading in full.`;
|
|
1975
2011
|
}
|
|
1976
|
-
var TOOL_GUIDE = `-
|
|
2012
|
+
var TOOL_GUIDE = `- hindsight_search_pages(query) \u2014 FIRST STOP, and the way IN to everything below. The code shows what is true today but not what was decided or why; memory shows what was decided or said back then but not whether it still holds. Work built from either alone goes wrong: from code alone it quietly re-litigates settled questions, from memory alone it acts on stale claims. Search BEFORE you act whenever the turn is one of these \u2014 they are the ones that go wrong silently:
|
|
1977
2013
|
\u2022 the user reports a bug or a wrong response (the intended behaviour, and the status code or value it should return, may already have been decided);
|
|
1978
2014
|
\u2022 you are about to write or change a test (what this project expects a change to ship with, and how it asserts, is a convention, not a preference);
|
|
1979
2015
|
\u2022 you are implementing something new, or two parts have to fit together;
|
|
@@ -1981,25 +2017,25 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, a
|
|
|
1981
2017
|
\u2022 you are about to commit, and need to know what the change was supposed to honour.
|
|
1982
2018
|
It ranks the pages by relevance and returns the matching passage, which a page title cannot tell you. What it returns is a past record, not a live reading: a claim that something was fixed, passes, or works is what someone said then \u2014 check it against the code before you rely on it, and say so when the two disagree.
|
|
1983
2019
|
CREDITING IS NOT OPTIONAL AND NOT A JUDGEMENT CALL. If you called this tool and anything it returned reached your reply \u2014 quoted, paraphrased, or merely confirming what you were about to say \u2014 open that part with a markdown blockquote, exactly: "> \u{1F9E0} **From Hindsight memory (<page>)** \u2014 <the specific facts you drew on>". Rewriting a snippet in your own words does not make it yours. A search that turned up nothing useful needs no mention at all \u2014 just carry on.
|
|
1984
|
-
-
|
|
2020
|
+
- hindsight_list_pages / hindsight_read_page \u2014 BEFORE substantial work, list the pages and read the relevant ones to ground yourself in this repo's architecture, conventions, and past decisions instead of re-deriving them from the code; follow any [[page:<id>]] links you see.
|
|
1985
2021
|
- hindsight_reflect(query) \u2014 when pages are too shallow and you need the WHY: deep reasoning over the repo's full memory for the past decision and exact values that explain a behavior or bug (slower \u2014 use deliberately, and credit results with a blockquote header "> \u{1F9E0} **From Hindsight memory** \u2014 <summary>").
|
|
1986
2022
|
- hindsight_capture_initiative(title, summary) \u2014 right after the user approves a plan or finishes brainstorming a new feature/capability and you are about to start implementing (BEFORE you write any code), call this to record it as a tracked page; then call it AGAIN with relates_to_page_id set to that page whenever the goal, scope, or rationale materially changes mid-work, so the page tracks the current plan and not the opening one. Skip bug fixes, small tweaks, chores, and trivial course-corrections.
|
|
1987
2023
|
- hindsight_ingest_document(title, content) \u2014 save an external document or durable notes/findings you want remembered (not the current conversation \u2014 that is captured automatically at session end).`;
|
|
1988
|
-
var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the
|
|
2024
|
+
var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the pages FIRST with hindsight_search_pages. No synthesis is injected automatically in this configuration; call hindsight_reflect only when those pages are too shallow and deeper reasoning is needed.\n";
|
|
1989
2025
|
function toolGuide(opts) {
|
|
1990
2026
|
const extra = opts?.extra?.trim();
|
|
1991
2027
|
return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE + (extra ? `
|
|
1992
2028
|
${extra}` : "");
|
|
1993
2029
|
}
|
|
1994
|
-
function
|
|
2030
|
+
function buildPagesPreamble(pages, opts) {
|
|
1995
2031
|
const body = pages.length ? indexLine(pages) : EMPTY_STATE;
|
|
1996
|
-
return `<
|
|
1997
|
-
This repository has a Hindsight memory +
|
|
2032
|
+
return `<hindsight_pages>
|
|
2033
|
+
This repository has a Hindsight memory + pages (curated, continuously-updated pages plus the raw memory behind them). The tools below are registered, but you must actually CALL them at the right moments:
|
|
1998
2034
|
${toolGuide(opts)}
|
|
1999
2035
|
ALSO your correction tool: when you verify a Hindsight memory is wrong or stale, ingest a "Correction: <topic>" doc stating what memory claimed, what is true now, and the evidence \u2014 newer facts supersede older ones.
|
|
2000
2036
|
${body}
|
|
2001
2037
|
This tool guide and the page list are re-injected for you periodically as things change.
|
|
2002
|
-
</
|
|
2038
|
+
</hindsight_pages>`;
|
|
2003
2039
|
}
|
|
2004
2040
|
|
|
2005
2041
|
// src/core/session-cache.ts
|
|
@@ -2069,43 +2105,6 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
2069
2105
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
|
|
2070
2106
|
import { tmpdir as tmpdir2 } from "os";
|
|
2071
2107
|
import { dirname as dirname6, join as join9 } from "path";
|
|
2072
|
-
|
|
2073
|
-
// src/core/transcript-util.ts
|
|
2074
|
-
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;
|
|
2075
|
-
function stripInjectedMemory(s) {
|
|
2076
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
2077
|
-
}
|
|
2078
|
-
var TARGET_KEYS = [
|
|
2079
|
-
"file_path",
|
|
2080
|
-
"path",
|
|
2081
|
-
"notebook_path",
|
|
2082
|
-
"command",
|
|
2083
|
-
"pattern",
|
|
2084
|
-
"query",
|
|
2085
|
-
"url",
|
|
2086
|
-
"name",
|
|
2087
|
-
"id"
|
|
2088
|
-
];
|
|
2089
|
-
var ACTION_TARGET_CAP = 100;
|
|
2090
|
-
function actionLine(tool, input) {
|
|
2091
|
-
let target = "";
|
|
2092
|
-
if (input && typeof input === "object") {
|
|
2093
|
-
const rec = input;
|
|
2094
|
-
for (const k of TARGET_KEYS) {
|
|
2095
|
-
const v = rec[k];
|
|
2096
|
-
if (typeof v === "string" && v.trim()) {
|
|
2097
|
-
target = v.trim().split("\n")[0];
|
|
2098
|
-
break;
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
} else if (typeof input === "string") {
|
|
2102
|
-
target = input.trim().split("\n")[0];
|
|
2103
|
-
}
|
|
2104
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
2105
|
-
return target ? `${tool} ${target}` : tool;
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
// src/core/turn-journal.ts
|
|
2109
2108
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
2110
2109
|
|
|
2111
2110
|
// src/core/retain-cursor.ts
|
|
@@ -2864,97 +2863,88 @@ function surveyAttempts(file, sha) {
|
|
|
2864
2863
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
2865
2864
|
try {
|
|
2866
2865
|
const spawnFn = opts.spawn ?? realSpawn4;
|
|
2867
|
-
const resolveBin = opts.resolveBin ?? ((
|
|
2866
|
+
const resolveBin = opts.resolveBin ?? ((bin2) => binOnPath(bin2, { exts: [".exe"] }));
|
|
2868
2867
|
const mcpServerPath = opts.mcpServerPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
|
|
2869
|
-
const
|
|
2870
|
-
const
|
|
2871
|
-
|
|
2872
|
-
"
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
detached: true,
|
|
2925
|
-
stdio: "ignore",
|
|
2926
|
-
windowsHide: true,
|
|
2927
|
-
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
2928
|
-
});
|
|
2929
|
-
let spawned = false;
|
|
2930
|
-
child.on("error", (e) => {
|
|
2931
|
-
if (spawned) return;
|
|
2932
|
-
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
2933
|
-
releaseLease(lease);
|
|
2934
|
-
resolve4(false);
|
|
2935
|
-
});
|
|
2936
|
-
child.once("spawn", () => {
|
|
2937
|
-
spawned = true;
|
|
2938
|
-
child.unref();
|
|
2939
|
-
if (opts.sha) {
|
|
2940
|
-
try {
|
|
2941
|
-
writeFileSync3(
|
|
2942
|
-
attemptsFile,
|
|
2943
|
-
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
2944
|
-
{ mode: 384 }
|
|
2945
|
-
);
|
|
2946
|
-
} catch {
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
resolve4(true);
|
|
2950
|
-
});
|
|
2951
|
-
} catch (e) {
|
|
2868
|
+
const harness = opts.harness ?? "claude-code";
|
|
2869
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
2870
|
+
if (!name) {
|
|
2871
|
+
log.info("survey", `${harness}: no headless survey for this agent, skipping the survey`);
|
|
2872
|
+
return false;
|
|
2873
|
+
}
|
|
2874
|
+
const bin = resolveBin(name);
|
|
2875
|
+
if (!bin) {
|
|
2876
|
+
log.info("survey", `${harness}: ${name} not found, skipping the survey`);
|
|
2877
|
+
return false;
|
|
2878
|
+
}
|
|
2879
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
2880
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, skipping the survey`);
|
|
2881
|
+
return false;
|
|
2882
|
+
}
|
|
2883
|
+
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
2884
|
+
model: opts.model,
|
|
2885
|
+
budgetUsd: opts.budgetUsd,
|
|
2886
|
+
mcpServerPath
|
|
2887
|
+
});
|
|
2888
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
2889
|
+
if (cfg.disabled) return false;
|
|
2890
|
+
const key = createHash4("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
2891
|
+
const leaseDir = opts.lease?.dir ?? join13(tmpdir3(), "hindsight-coding-agent", "surveys");
|
|
2892
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
2893
|
+
if (!lease) return false;
|
|
2894
|
+
const attemptsFile = join13(
|
|
2895
|
+
leaseDir,
|
|
2896
|
+
`attempts-${createHash4("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
2897
|
+
);
|
|
2898
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
2899
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
2900
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
2901
|
+
releaseLease(lease);
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
const spec = {
|
|
2905
|
+
lease,
|
|
2906
|
+
bin: plan.bin,
|
|
2907
|
+
args: plan.args,
|
|
2908
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
2909
|
+
};
|
|
2910
|
+
const supervisorPath = opts.supervisorPath ?? join13(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
|
|
2911
|
+
return await new Promise((resolve4) => {
|
|
2912
|
+
try {
|
|
2913
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
2914
|
+
cwd: repoDir,
|
|
2915
|
+
detached: true,
|
|
2916
|
+
stdio: "ignore",
|
|
2917
|
+
windowsHide: true,
|
|
2918
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
2919
|
+
});
|
|
2920
|
+
let spawned = false;
|
|
2921
|
+
child.on("error", (e) => {
|
|
2922
|
+
if (spawned) return;
|
|
2952
2923
|
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
2953
2924
|
releaseLease(lease);
|
|
2954
2925
|
resolve4(false);
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
|
|
2926
|
+
});
|
|
2927
|
+
child.once("spawn", () => {
|
|
2928
|
+
spawned = true;
|
|
2929
|
+
child.unref();
|
|
2930
|
+
if (opts.sha) {
|
|
2931
|
+
try {
|
|
2932
|
+
writeFileSync3(
|
|
2933
|
+
attemptsFile,
|
|
2934
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
2935
|
+
{ mode: 384 }
|
|
2936
|
+
);
|
|
2937
|
+
} catch {
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
resolve4(true);
|
|
2941
|
+
});
|
|
2942
|
+
} catch (e) {
|
|
2943
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
2944
|
+
releaseLease(lease);
|
|
2945
|
+
resolve4(false);
|
|
2946
|
+
}
|
|
2947
|
+
});
|
|
2958
2948
|
} catch {
|
|
2959
2949
|
}
|
|
2960
2950
|
return false;
|
|
@@ -3463,11 +3453,11 @@ async function buildSessionStartContext(args) {
|
|
|
3463
3453
|
try {
|
|
3464
3454
|
pages = parsePageList(await client.listPages());
|
|
3465
3455
|
} catch {
|
|
3466
|
-
if (client.
|
|
3467
|
-
diag(harness, "
|
|
3456
|
+
if (client.pagesSupported === false) {
|
|
3457
|
+
diag(harness, "pages_unavailable", { bank: bankId });
|
|
3468
3458
|
}
|
|
3469
3459
|
}
|
|
3470
|
-
const additionalContext =
|
|
3460
|
+
const additionalContext = buildPagesPreamble(pages, {
|
|
3471
3461
|
reflectOnNewGoals: cfg.autoInject !== "reflect",
|
|
3472
3462
|
extra: cfg.toolGuideExtra
|
|
3473
3463
|
});
|