@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.
Files changed (62) hide show
  1. package/README.md +36 -30
  2. package/dist/antigravity-hook.js +130 -135
  3. package/dist/antigravity-statusline.js +1 -1
  4. package/dist/antigravity-stop-hook.js +113 -114
  5. package/dist/claude-hook.js +130 -135
  6. package/dist/claude-sessionstart-hook.js +205 -215
  7. package/dist/claude-stop-hook.js +113 -114
  8. package/dist/cline.js +206 -211
  9. package/dist/codebuddy-hook.js +130 -135
  10. package/dist/codebuddy-sessionstart-hook.js +205 -215
  11. package/dist/codebuddy-stop-hook.js +113 -114
  12. package/dist/codex-hook.js +130 -135
  13. package/dist/codex-sessionstart-hook.js +205 -215
  14. package/dist/codex-stop-hook.js +113 -114
  15. package/dist/copilot-hook.js +130 -135
  16. package/dist/copilot-sessionstart-hook.js +205 -215
  17. package/dist/copilot-stop-hook.js +113 -114
  18. package/dist/cursor-hook.js +130 -135
  19. package/dist/cursor-sessionstart-hook.js +205 -215
  20. package/dist/cursor-stop-hook.js +113 -114
  21. package/dist/daemon-start.js +1 -1
  22. package/dist/dcode-hook.js +130 -135
  23. package/dist/dcode-sessionstart-hook.js +205 -215
  24. package/dist/dcode-stop-hook.js +113 -114
  25. package/dist/deepen.js +80 -79
  26. package/dist/devin-hook.js +130 -135
  27. package/dist/devin-sessionstart-hook.js +205 -215
  28. package/dist/devin-stop-hook.js +113 -114
  29. package/dist/droid-hook.js +130 -135
  30. package/dist/droid-sessionstart-hook.js +205 -215
  31. package/dist/droid-stop-hook.js +113 -114
  32. package/dist/dsh.js +235 -248
  33. package/dist/grok-hook.js +130 -135
  34. package/dist/grok-sessionstart-hook.js +205 -215
  35. package/dist/grok-stop-hook.js +113 -114
  36. package/dist/hindsight-seed.js +1 -1
  37. package/dist/index.js +236 -249
  38. package/dist/installer.js +30 -28
  39. package/dist/kilo.js +236 -249
  40. package/dist/kimi-hook.js +130 -135
  41. package/dist/kimi-sessionstart-hook.js +205 -215
  42. package/dist/kimi-stop-hook.js +113 -114
  43. package/dist/mcp-server.js +94 -93
  44. package/dist/opencode2.js +236 -249
  45. package/dist/pi.js +235 -248
  46. package/dist/prime-agent.js +235 -248
  47. package/dist/qwen-hook.js +130 -135
  48. package/dist/qwen-sessionstart-hook.js +205 -215
  49. package/dist/qwen-stop-hook.js +113 -114
  50. package/dist/status.js +80 -79
  51. package/dist/traecode-hook.js +130 -135
  52. package/dist/traecode-sessionstart-hook.js +205 -215
  53. package/dist/traecode-stop-hook.js +113 -114
  54. package/dist/workbuddy-hook.js +130 -135
  55. package/dist/workbuddy-sessionstart-hook.js +205 -215
  56. package/dist/workbuddy-stop-hook.js +113 -114
  57. package/dist/zcode-hook.js +130 -135
  58. package/dist/zcode-sessionstart-hook.js +205 -215
  59. package/dist/zcode-stop-hook.js +113 -114
  60. package/package.json +2 -1
  61. package/plugin.json +1 -1
  62. package/skill/SKILL.md +26 -26
package/dist/grok-hook.js CHANGED
@@ -441,14 +441,14 @@ var RETAIN_STRATEGIES = {
441
441
  retain_chunk_size: 12e3
442
442
  }
443
443
  };
444
- var KNOWLEDGE_LABELS = {
444
+ var PAGE_LABELS = {
445
445
  key: "knowledge",
446
446
  type: "multi-values",
447
447
  // 0, 1, or several — empty is normal
448
448
  optional: true,
449
449
  tag: true,
450
450
  // emits knowledge:<value> onto the fact's tags
451
- description: "Routing labels for this project's Hindsight KNOWLEDGE 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.",
451
+ 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.",
452
452
  values: [
453
453
  {
454
454
  value: "feature-work",
@@ -605,7 +605,7 @@ var CODING_BANK_TEMPLATE = {
605
605
  retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
606
606
  retain_default_strategy: "git",
607
607
  retain_strategies: RETAIN_STRATEGIES,
608
- entity_labels: [KNOWLEDGE_LABELS],
608
+ entity_labels: [PAGE_LABELS],
609
609
  entities_allow_free_form: true
610
610
  }
611
611
  };
@@ -657,7 +657,7 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
657
657
  }
658
658
 
659
659
  // package.json
660
- var version = "0.8.5";
660
+ var version = "0.8.7";
661
661
 
662
662
  // src/core/util.ts
663
663
  import { accessSync, constants, statSync as statSync2 } from "fs";
@@ -726,11 +726,11 @@ function retryAfterMs(header) {
726
726
  const at = Date.parse(header);
727
727
  return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
728
728
  }
729
- var KnowledgePagesUnavailableError = class extends Error {
730
- code = "knowledge_pages_unavailable";
729
+ var PagesUnavailableError = class extends Error {
730
+ code = "pages_unavailable";
731
731
  constructor() {
732
- super("Hindsight server does not support knowledge pages");
733
- this.name = "KnowledgePagesUnavailableError";
732
+ super("Hindsight server does not support pages");
733
+ this.name = "PagesUnavailableError";
734
734
  }
735
735
  };
736
736
  async function isEndpointMissing(r) {
@@ -741,6 +741,10 @@ async function isEndpointMissing(r) {
741
741
  return false;
742
742
  }
743
743
  }
744
+ function pagesPath(sub, legacy = false) {
745
+ if (!legacy) return `/pages${sub}`;
746
+ return /^\/(tree|folders|search|export|nodes)\b/.test(sub) ? `/knowledge-base${sub}` : `/knowledge-base/pages${sub}`;
747
+ }
744
748
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
745
749
  var ReflectError = class extends Error {
746
750
  constructor(message, status, timedOut, options) {
@@ -809,7 +813,7 @@ var HindsightClient = class {
809
813
  opIds = [];
810
814
  // async operation ids collected by retain(), for drain()
811
815
  /** Tri-state capability probe: unknown until the first page request, then cached. */
812
- knowledgePagesSupported;
816
+ pagesSupported;
813
817
  /** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
814
818
  idempotentRetain;
815
819
  log;
@@ -1038,7 +1042,7 @@ var HindsightClient = class {
1038
1042
  return (j.total ?? j.items?.length ?? 0) > 0;
1039
1043
  }
1040
1044
  /** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
1041
- * entity labels), then seed knowledge pages when the server supports them. Both halves are
1045
+ * entity labels), then seed pages when the server supports them. Both halves are
1042
1046
  * idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
1043
1047
  * extraction mode of the plugin's own strategies, which follows its config (#4560) — so
1044
1048
  * the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
@@ -1220,29 +1224,45 @@ var HindsightClient = class {
1220
1224
  const j = await r.json();
1221
1225
  return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
1222
1226
  }
1227
+ /** Set once a server answered on the deprecated `/knowledge-base/...` paths: one from before the
1228
+ * page routes moved to `/pages/...`. Remove in 2.x. */
1229
+ legacyPagesPaths = false;
1223
1230
  /**
1224
- * Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
1225
- * Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
1226
- * expected answer before the bank's first retain — so it must never cache a negative (#4607).
1231
+ * Request a page endpoint by its `/pages` sub-path (`""`, `/tree`, `/<id>`, `/nodes/<id>`, …).
1232
+ *
1233
+ * Returns `null` — and latches `pagesSupported = false` — iff the endpoint is really absent: an
1234
+ * unrouted 404 on the `/pages` path AND on its pre-rename `/knowledge-base` twin, which a server
1235
+ * older than the rename still serves (tried once, then remembered). A bank-not-found 404 is NOT
1236
+ * a capability verdict — it is the expected answer before the bank's first retain — so it is
1237
+ * returned as-is and never caches a negative (#4607). A 404's body may already be consumed.
1227
1238
  *
1228
1239
  * Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
1229
1240
  * the 405/501 this used to check for never reach a caller in the first place.
1230
1241
  */
1231
- async pagesUnsupported(r) {
1232
- if (r.status !== 404 || !await isEndpointMissing(r)) return false;
1233
- this.knowledgePagesSupported = false;
1234
- return true;
1242
+ async pagesReq(method, sub, body, tolerate = [], timeoutMs) {
1243
+ const send = (legacy) => this.req(method, this.bankUrl(pagesPath(sub, legacy)), body, tolerate, timeoutMs);
1244
+ let r = await send(this.legacyPagesPaths);
1245
+ if (r.status !== 404 || !await isEndpointMissing(r)) return r;
1246
+ if (!this.legacyPagesPaths) {
1247
+ r = await send(true);
1248
+ if (r.status !== 404 || !await isEndpointMissing(r)) {
1249
+ this.legacyPagesPaths = true;
1250
+ return r;
1251
+ }
1252
+ }
1253
+ this.pagesSupported = false;
1254
+ return null;
1235
1255
  }
1236
1256
  /**
1237
- * The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
1257
+ * The bank's page tree (folders + pages, nested). The tree carries names, source
1238
1258
  * queries and staleness but NOT synthesized content, so it is cheap enough to poll.
1239
1259
  */
1240
1260
  async tree() {
1241
- if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1242
- const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
1243
- if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
1261
+ if (this.pagesSupported === false) throw new PagesUnavailableError();
1262
+ const r = await this.pagesReq("GET", "/tree");
1263
+ if (!r) throw new PagesUnavailableError();
1244
1264
  if (r.status === 404) return [];
1245
- this.knowledgePagesSupported = true;
1265
+ this.pagesSupported = true;
1246
1266
  try {
1247
1267
  return (await r.json()).roots ?? [];
1248
1268
  } catch {
@@ -1250,13 +1270,13 @@ var HindsightClient = class {
1250
1270
  }
1251
1271
  }
1252
1272
  /**
1253
- * List knowledge pages (ids + names only — no synthesized content), flattened out of the tree
1273
+ * List pages (ids + names only — no synthesized content), flattened out of the tree
1254
1274
  * and shaped as `{items:[…]}` for `parsePageList`. Folders are dropped: they carry no content
1255
1275
  * to read, and a caller enumerating pages wants leaves, not structure.
1256
1276
  *
1257
- * NOTE the ids are knowledge-base node ids (`kp-…`), NOT the backing mental-model ids. Every
1258
- * page read/update in this client goes through the same knowledge-base ids, so a page id from
1259
- * here, from `searchKnowledgePages`, or from a `[[page:<id>]]` link all resolve identically.
1277
+ * NOTE the ids are page node ids (`kp-…`), NOT the backing mental-model ids. Every
1278
+ * page read/update in this client goes through the same page ids, so a page id from
1279
+ * here, from `searchPages`, or from a `[[page:<id>]]` link all resolve identically.
1260
1280
  */
1261
1281
  async listPages() {
1262
1282
  const items = [];
@@ -1278,34 +1298,26 @@ var HindsightClient = class {
1278
1298
  return { items };
1279
1299
  }
1280
1300
  /**
1281
- * Read one knowledge page's synthesized content by knowledge-base id, shaped by `shapePage` so
1301
+ * Read one page's synthesized content by page id, shaped by `shapePage` so
1282
1302
  * the body arrives once. The endpoint omits the internal reflect trace that built
1283
1303
  * the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
1284
1304
  * token cap.
1285
1305
  */
1286
1306
  async getPage(pageId) {
1287
- if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1288
- const r = await this.req(
1289
- "GET",
1290
- this.bankUrl(`/knowledge-base/pages/${encodeURIComponent(pageId)}`)
1291
- );
1292
- if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
1307
+ if (this.pagesSupported === false) throw new PagesUnavailableError();
1308
+ const r = await this.pagesReq("GET", `/${encodeURIComponent(pageId)}`);
1309
+ if (!r) throw new PagesUnavailableError();
1310
+ if (r.status === 404) throw new Error(`page not found: ${pageId}`);
1293
1311
  return shapePage(await r.json());
1294
1312
  }
1295
- /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
1313
+ /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's pages.
1296
1314
  * Returns page-level hits with a relevance snippet — the real search behind
1297
- * hindsight_search_knowledge_pages. */
1298
- async searchKnowledgePages(query, opts = {}) {
1299
- if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1315
+ * hindsight_search_pages. */
1316
+ async searchPages(query, opts = {}) {
1317
+ if (this.pagesSupported === false) throw new PagesUnavailableError();
1300
1318
  const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
1301
- const r = await this.req(
1302
- "GET",
1303
- this.bankUrl(`/knowledge-base/search${q}`),
1304
- void 0,
1305
- [],
1306
- opts.timeoutMs
1307
- );
1308
- if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
1319
+ const r = await this.pagesReq("GET", `/search${q}`, void 0, [], opts.timeoutMs);
1320
+ if (!r) throw new PagesUnavailableError();
1309
1321
  if (r.status === 404) return [];
1310
1322
  const j = await r.json();
1311
1323
  return (j.results ?? []).map((x) => ({
@@ -1317,9 +1329,9 @@ var HindsightClient = class {
1317
1329
  }));
1318
1330
  }
1319
1331
  /**
1320
- * Seed the fixed page taxonomy as knowledge-base pages at the tree root, idempotently.
1332
+ * Seed the fixed page taxonomy as pages at the tree root, idempotently.
1321
1333
  *
1322
- * Matched by NAME, not id: `/knowledge-base/pages` mints its own `kp-…` id, so a stable
1334
+ * Matched by NAME, not id: `POST /pages` mints its own `kp-…` id, so a stable
1323
1335
  * client-chosen id isn't available to match on (unlike the old mental-model path, which keyed
1324
1336
  * off a slug). Names are unique per folder server-side, which makes them a sound key.
1325
1337
  *
@@ -1334,8 +1346,8 @@ var HindsightClient = class {
1334
1346
  try {
1335
1347
  roots = await this.tree();
1336
1348
  } catch (e) {
1337
- if (e instanceof KnowledgePagesUnavailableError) {
1338
- this.log(`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`);
1349
+ if (e instanceof PagesUnavailableError) {
1350
+ this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
1339
1351
  return;
1340
1352
  }
1341
1353
  throw e;
@@ -1358,11 +1370,9 @@ var HindsightClient = class {
1358
1370
  trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
1359
1371
  };
1360
1372
  if (!hit) {
1361
- const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
1362
- if (await this.pagesUnsupported(r)) {
1363
- this.log(
1364
- `[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
1365
- );
1373
+ const r = await this.pagesReq("POST", "", body, [409]);
1374
+ if (!r) {
1375
+ this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
1366
1376
  return;
1367
1377
  }
1368
1378
  if (r.status === 404) {
@@ -1383,15 +1393,9 @@ var HindsightClient = class {
1383
1393
  );
1384
1394
  }
1385
1395
  if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
1386
- const r = await this.req(
1387
- "PATCH",
1388
- this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
1389
- patch
1390
- );
1391
- if (await this.pagesUnsupported(r)) {
1392
- this.log(
1393
- `[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
1394
- );
1396
+ const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(hit.id)}`, patch);
1397
+ if (!r) {
1398
+ this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
1395
1399
  return;
1396
1400
  }
1397
1401
  if (r.status === 404) {
@@ -1403,7 +1407,7 @@ var HindsightClient = class {
1403
1407
  }
1404
1408
  const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
1405
1409
  this.log(
1406
- `[bank] knowledge 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` : "")
1410
+ `[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` : "")
1407
1411
  );
1408
1412
  }
1409
1413
  /**
@@ -1437,12 +1441,8 @@ var HindsightClient = class {
1437
1441
  if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
1438
1442
  }
1439
1443
  if (!patch.trigger && !patch.source_query) continue;
1440
- const r = await this.req(
1441
- "PATCH",
1442
- this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
1443
- patch
1444
- );
1445
- if (r.status === 404) continue;
1444
+ const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(page.id)}`, patch);
1445
+ if (!r || r.status === 404) continue;
1446
1446
  updated++;
1447
1447
  }
1448
1448
  return updated;
@@ -1468,7 +1468,7 @@ var HindsightClient = class {
1468
1468
  let pageId = args.relatesToPageId;
1469
1469
  if (!pageId) {
1470
1470
  const folderId = await this.ensureFolder("Initiatives");
1471
- const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
1471
+ const r = await this.pagesReq("POST", "", {
1472
1472
  name: args.title,
1473
1473
  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),
1474
1474
  parent_id: folderId,
@@ -1477,8 +1477,8 @@ var HindsightClient = class {
1477
1477
  trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
1478
1478
  });
1479
1479
  try {
1480
- const j = await r.json();
1481
- pageId = j.page_id ?? j.id;
1480
+ const j = await r?.json();
1481
+ pageId = j?.page_id ?? j?.id;
1482
1482
  } catch {
1483
1483
  }
1484
1484
  pageId ||= `initiative-${this.slugify(args.title)}`;
@@ -1496,16 +1496,17 @@ var HindsightClient = class {
1496
1496
  /** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
1497
1497
  async ensureFolder(name) {
1498
1498
  try {
1499
- const tree = await (await this.req("GET", this.bankUrl("/knowledge-base/tree"))).json();
1500
- const hit = (tree.roots || []).find(
1499
+ const r = await this.pagesReq("GET", "/tree");
1500
+ const tree = await r?.json();
1501
+ const hit = (tree?.roots || []).find(
1501
1502
  (n) => n.kind === "folder" && (n.name || "").toLowerCase() === name.toLowerCase()
1502
1503
  );
1503
1504
  if (hit?.id) return hit.id;
1504
1505
  } catch {
1505
1506
  }
1506
1507
  try {
1507
- const r = await this.req("POST", this.bankUrl("/knowledge-base/folders"), { name });
1508
- return (await r.json()).id;
1508
+ const r = await this.pagesReq("POST", "/folders", { name });
1509
+ return (await r?.json())?.id;
1509
1510
  } catch {
1510
1511
  return void 0;
1511
1512
  }
@@ -1903,6 +1904,41 @@ function resolvePartial(cfg, patch) {
1903
1904
  return out;
1904
1905
  }
1905
1906
 
1907
+ // src/core/transcript-util.ts
1908
+ 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;
1909
+ function stripInjectedMemory(s) {
1910
+ return s.replace(MEMORY_TAG_RE, "");
1911
+ }
1912
+ var TARGET_KEYS = [
1913
+ "file_path",
1914
+ "path",
1915
+ "notebook_path",
1916
+ "command",
1917
+ "pattern",
1918
+ "query",
1919
+ "url",
1920
+ "name",
1921
+ "id"
1922
+ ];
1923
+ var ACTION_TARGET_CAP = 100;
1924
+ function actionLine(tool, input) {
1925
+ let target = "";
1926
+ if (input && typeof input === "object") {
1927
+ const rec = input;
1928
+ for (const k of TARGET_KEYS) {
1929
+ const v = rec[k];
1930
+ if (typeof v === "string" && v.trim()) {
1931
+ target = v.trim().split("\n")[0];
1932
+ break;
1933
+ }
1934
+ }
1935
+ } else if (typeof input === "string") {
1936
+ target = input.trim().split("\n")[0];
1937
+ }
1938
+ if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1939
+ return target ? `${tool} ${target}` : tool;
1940
+ }
1941
+
1906
1942
  // src/core/brand.ts
1907
1943
  function brandWord() {
1908
1944
  const start = [0, 116, 217];
@@ -1933,8 +1969,8 @@ Report what this bank's history genuinely bears on that goal. Rendering rules, s
1933
1969
  - Do not connect unrelated episodes into one narrative; if two facts are not explicitly linked in the record, report them separately or leave the weaker one out.
1934
1970
  - If the bank holds nothing that bears on the goal, say so in one line.`;
1935
1971
  }
1936
- var PAGE_FALLBACK_LEAD = "(Hindsight's synthesis was unavailable this turn; these knowledge pages matched the goal by search. Read one with hindsight_read_knowledge_page(<id>) if it looks relevant.)";
1937
- var PAGE_INJECT_LEAD = "(These knowledge pages matched the goal by search. Read one with hindsight_read_knowledge_page(<id>) if it looks relevant.)";
1972
+ var PAGE_FALLBACK_LEAD = "(Hindsight's synthesis was unavailable this turn; these pages matched the goal by search. Read one with hindsight_read_page(<id>) if it looks relevant.)";
1973
+ var PAGE_INJECT_LEAD = "(These pages matched the goal by search. Read one with hindsight_read_page(<id>) if it looks relevant.)";
1938
1974
  function formatPageFallback(hits, lead = PAGE_FALLBACK_LEAD) {
1939
1975
  return `${lead}
1940
1976
  ` + hits.map((h) => {
@@ -1961,7 +1997,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
1961
1997
  ` + memory + "\n</hindsight_memory>";
1962
1998
  }
1963
1999
 
1964
- // src/core/knowledge-injection.ts
2000
+ // src/core/page-injection.ts
1965
2001
  function parsePageList(raw) {
1966
2002
  const items = raw?.items;
1967
2003
  if (!Array.isArray(items)) return [];
@@ -1974,10 +2010,10 @@ function parsePageList(raw) {
1974
2010
  return out;
1975
2011
  }
1976
2012
  function indexLine(pages) {
1977
- const count = pages.length === 1 ? "1 knowledge page covers" : `${pages.length} knowledge pages cover`;
1978
- return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call hindsight_search_knowledge_pages(query) to find the ones that bear on the current turn, then hindsight_read_knowledge_page(<id>) on anything the results show is worth reading in full.`;
2013
+ const count = pages.length === 1 ? "1 page covers" : `${pages.length} pages cover`;
2014
+ 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.`;
1979
2015
  }
1980
- var TOOL_GUIDE = `- hindsight_search_knowledge_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:
2016
+ 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:
1981
2017
  \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);
1982
2018
  \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);
1983
2019
  \u2022 you are implementing something new, or two parts have to fit together;
@@ -1985,11 +2021,11 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, a
1985
2021
  \u2022 you are about to commit, and need to know what the change was supposed to honour.
1986
2022
  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.
1987
2023
  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.
1988
- - hindsight_list_knowledge_pages / hindsight_read_knowledge_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.
2024
+ - 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.
1989
2025
  - 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>").
1990
2026
  - 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.
1991
2027
  - 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).`;
1992
- var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the knowledge pages FIRST with hindsight_search_knowledge_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";
2028
+ 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";
1993
2029
  function toolGuide(opts) {
1994
2030
  const extra = opts?.extra?.trim();
1995
2031
  return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE + (extra ? `
@@ -1998,9 +2034,9 @@ ${extra}` : "");
1998
2034
  function buildRosterRefresh(pages, opts) {
1999
2035
  const rosterBlock = pages.length ? `${indexLine(pages)}
2000
2036
  ` : "";
2001
- return "<hindsight_knowledge_refresh>\n" + rosterBlock + `Reminder \u2014 this repo's Hindsight tools are available; call them at the right moments:
2037
+ return "<hindsight_page_refresh>\n" + rosterBlock + `Reminder \u2014 this repo's Hindsight tools are available; call them at the right moments:
2002
2038
  ${toolGuide(opts)}
2003
- </hindsight_knowledge_refresh>`;
2039
+ </hindsight_page_refresh>`;
2004
2040
  }
2005
2041
 
2006
2042
  // src/core/session-cache.ts
@@ -2089,43 +2125,6 @@ function sessionRootDir(harness, sessionId, cwd) {
2089
2125
  import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
2090
2126
  import { tmpdir as tmpdir2 } from "os";
2091
2127
  import { dirname as dirname6, join as join9 } from "path";
2092
-
2093
- // src/core/transcript-util.ts
2094
- 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;
2095
- function stripInjectedMemory(s) {
2096
- return s.replace(MEMORY_TAG_RE, "");
2097
- }
2098
- var TARGET_KEYS = [
2099
- "file_path",
2100
- "path",
2101
- "notebook_path",
2102
- "command",
2103
- "pattern",
2104
- "query",
2105
- "url",
2106
- "name",
2107
- "id"
2108
- ];
2109
- var ACTION_TARGET_CAP = 100;
2110
- function actionLine(tool, input) {
2111
- let target = "";
2112
- if (input && typeof input === "object") {
2113
- const rec = input;
2114
- for (const k of TARGET_KEYS) {
2115
- const v = rec[k];
2116
- if (typeof v === "string" && v.trim()) {
2117
- target = v.trim().split("\n")[0];
2118
- break;
2119
- }
2120
- }
2121
- } else if (typeof input === "string") {
2122
- target = input.trim().split("\n")[0];
2123
- }
2124
- if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
2125
- return target ? `${tool} ${target}` : tool;
2126
- }
2127
-
2128
- // src/core/turn-journal.ts
2129
2128
  var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
2130
2129
  function journalPath(harness, sessionId) {
2131
2130
  return join9(tmpdir2(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
@@ -2204,7 +2203,7 @@ function boundRecallQuery(prompt) {
2204
2203
  async function injectPages(harness, prompt, client, timeoutMs, event, lead) {
2205
2204
  const t0 = Date.now();
2206
2205
  try {
2207
- const hits = await client.searchKnowledgePages(prompt.slice(0, 500), { timeoutMs });
2206
+ const hits = await client.searchPages(prompt.slice(0, 500), { timeoutMs });
2208
2207
  diag(harness, event, { ms: Date.now() - t0, count: hits.length });
2209
2208
  return hits.length ? formatPageFallback(hits, lead) : null;
2210
2209
  } catch (e) {
@@ -2318,14 +2317,10 @@ async function buildHookOutput(args) {
2318
2317
  pages = parsePageList(await client.listPages());
2319
2318
  diag(harness, "pages_ok", { ms: Date.now() - t0, count: pages.length });
2320
2319
  } catch (e) {
2321
- diag(
2322
- harness,
2323
- client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
2324
- {
2325
- ms: Date.now() - t0,
2326
- error: describeError(e)
2327
- }
2328
- );
2320
+ diag(harness, client.pagesSupported === false ? "pages_unavailable" : "pages_failed", {
2321
+ ms: Date.now() - t0,
2322
+ error: describeError(e)
2323
+ });
2329
2324
  }
2330
2325
  }
2331
2326
  writeSessionCache(cacheFile, {
@@ -2372,7 +2367,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
2372
2367
  }
2373
2368
  if (spec.requireCwd && !rawCwd) return;
2374
2369
  const cwd = rawCwd || process.cwd();
2375
- const prompt = (rawPrompt || "").trim();
2370
+ const prompt = stripInjectedMemory(rawPrompt || "").trim();
2376
2371
  if (!prompt) return;
2377
2372
  let cfg = loadConfig({ harness: spec.harness });
2378
2373
  setLogLevel(cfg.logLevel);
@@ -2408,7 +2403,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
2408
2403
  startBackgroundSeed(cwd, { limit: cfg.seedLimit, harness: spec.harness });
2409
2404
  }
2410
2405
  const output = await buildHookOutput({ harness: spec.harness, prompt, cfg, client, cacheFile });
2411
- if (cfg.autoSeed !== false && client.knowledgePagesSupported !== false && output.pages.length === 0) {
2406
+ if (cfg.autoSeed !== false && client.pagesSupported !== false && output.pages.length === 0) {
2412
2407
  startBackgroundSeed(cwd, { limit: cfg.seedLimit, harness: spec.harness });
2413
2408
  }
2414
2409
  let context = output.context;