@vectorize-io/hindsight-coding-agents 0.8.6 → 0.8.8
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 +31 -21
- package/dist/antigravity-hook.js +278 -190
- package/dist/antigravity-statusline.js +30 -24
- package/dist/antigravity-stop-hook.js +271 -169
- package/dist/claude-hook.js +278 -190
- package/dist/claude-sessionstart-hook.js +301 -212
- package/dist/claude-stop-hook.js +271 -169
- package/dist/cline.js +258 -214
- package/dist/codebuddy-hook.js +278 -190
- package/dist/codebuddy-sessionstart-hook.js +301 -212
- package/dist/codebuddy-stop-hook.js +271 -169
- package/dist/codex-hook.js +278 -190
- package/dist/codex-sessionstart-hook.js +301 -212
- package/dist/codex-stop-hook.js +271 -169
- package/dist/copilot-hook.js +278 -190
- package/dist/copilot-sessionstart-hook.js +301 -212
- package/dist/copilot-stop-hook.js +271 -169
- package/dist/cursor-hook.js +278 -190
- package/dist/cursor-sessionstart-hook.js +301 -212
- package/dist/cursor-stop-hook.js +271 -169
- package/dist/daemon-start.js +20 -16
- package/dist/dcode-hook.js +278 -190
- package/dist/dcode-sessionstart-hook.js +301 -212
- package/dist/dcode-stop-hook.js +271 -169
- package/dist/deepen.js +98 -83
- package/dist/devin-hook.js +278 -190
- package/dist/devin-sessionstart-hook.js +301 -212
- package/dist/devin-stop-hook.js +271 -169
- package/dist/droid-hook.js +278 -190
- package/dist/droid-sessionstart-hook.js +301 -212
- package/dist/droid-stop-hook.js +271 -169
- package/dist/dsh.js +309 -251
- package/dist/grok-hook.js +278 -190
- package/dist/grok-sessionstart-hook.js +301 -212
- package/dist/grok-stop-hook.js +271 -169
- package/dist/hindsight-seed.js +35 -26
- package/dist/index.js +310 -252
- package/dist/installer.js +172 -68
- package/dist/kilo.js +310 -252
- package/dist/kimi-hook.js +278 -190
- package/dist/kimi-sessionstart-hook.js +301 -212
- package/dist/kimi-stop-hook.js +271 -169
- package/dist/mcp-server.js +165 -148
- package/dist/opencode2.js +310 -252
- package/dist/pi.js +309 -251
- package/dist/prime-agent.js +309 -251
- package/dist/qwen-hook.js +278 -190
- package/dist/qwen-sessionstart-hook.js +301 -212
- package/dist/qwen-stop-hook.js +271 -169
- package/dist/status.js +134 -117
- package/dist/traecode-hook.js +278 -190
- package/dist/traecode-sessionstart-hook.js +301 -212
- package/dist/traecode-stop-hook.js +271 -169
- package/dist/workbuddy-hook.js +278 -190
- package/dist/workbuddy-sessionstart-hook.js +301 -212
- package/dist/workbuddy-stop-hook.js +271 -169
- package/dist/zcode-hook.js +278 -190
- package/dist/zcode-sessionstart-hook.js +301 -212
- package/dist/zcode-stop-hook.js +271 -169
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +31 -26
package/dist/status.js
CHANGED
|
@@ -245,7 +245,11 @@ function configuredDir(dir) {
|
|
|
245
245
|
const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
|
|
246
246
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
247
247
|
}
|
|
248
|
-
function isWithin(directory, configured) {
|
|
248
|
+
function isWithin(directory, configured, platform = process.platform) {
|
|
249
|
+
if (platform === "win32") {
|
|
250
|
+
directory = directory.toLowerCase();
|
|
251
|
+
configured = configured.toLowerCase();
|
|
252
|
+
}
|
|
249
253
|
return directory === configured || directory.startsWith(configured + sep);
|
|
250
254
|
}
|
|
251
255
|
function mapLookup(map, directory) {
|
|
@@ -325,15 +329,50 @@ import { join as join7 } from "path";
|
|
|
325
329
|
|
|
326
330
|
// src/core/seed.ts
|
|
327
331
|
import { spawn as realSpawn } from "child_process";
|
|
328
|
-
import { dirname as dirname4, join as
|
|
332
|
+
import { dirname as dirname4, join as join6 } from "path";
|
|
329
333
|
import { fileURLToPath } from "url";
|
|
334
|
+
|
|
335
|
+
// src/core/util.ts
|
|
336
|
+
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
337
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join5, resolve as resolve2 } from "path";
|
|
338
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
339
|
+
function semverGte(version2, min) {
|
|
340
|
+
const parts = (v) => {
|
|
341
|
+
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
342
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
343
|
+
};
|
|
344
|
+
const a = version2 ? parts(version2) : void 0;
|
|
345
|
+
const b = parts(min);
|
|
346
|
+
if (!a || !b) return false;
|
|
347
|
+
for (let i = 0; i < 3; i++) {
|
|
348
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
349
|
+
}
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
async function pool(items, n, fn, onError, onProgress) {
|
|
353
|
+
let i = 0, done = 0;
|
|
354
|
+
async function worker() {
|
|
355
|
+
while (i < items.length) {
|
|
356
|
+
const idx = i++;
|
|
357
|
+
try {
|
|
358
|
+
await fn(items[idx], idx);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
onError?.(idx, e);
|
|
361
|
+
}
|
|
362
|
+
onProgress?.(++done, items.length);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, worker));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/core/seed.ts
|
|
330
369
|
var DEFAULT_SEED_LIMIT = 300;
|
|
331
370
|
|
|
332
371
|
// src/core/missions.ts
|
|
333
372
|
import { createHash } from "crypto";
|
|
334
373
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
335
374
|
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, oldest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
336
|
-
var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Do not invent; capture only what was actually settled.`;
|
|
375
|
+
var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. When the session checked its work (a test passed or failed, a result was judged right or wrong), record the exact METHOD behind that outcome \u2014 which file, table, column, command or formula \u2014 and any caveat the session found in the data or code (a column mostly empty, a value in other units), so the same work repeats what worked and avoids what failed. Do not invent; capture only what was actually settled.`;
|
|
337
376
|
var REFLECT_MISSION = "You are a debugging assistant with the project's past decisions in memory (git rationale and developer chats). Given a bug's SYMPTOM, find the past decision whose rationale explains the ROOT CAUSE \u2014 not one that merely shares vocabulary. Answer with the PRECISE fix: state the EXACT rule and the LITERAL values, identifiers, strings, numbers, or set members that were decided \u2014 quote them VERBATIM, never paraphrase, generalize, or omit them (give the actual decided value, not 'the project standard'). If memories CONFLICT on the same rule, the LATEST decision wins \u2014 prefer facts that explicitly amend or supersede an earlier one, state the superseded rule as no longer in effect, and never present it as the fix. Name the function/file to change and cite the REF-ID(s). If NOTHING in memory genuinely explains THIS symptom, say exactly that in one short sentence \u2014 a wrong-but-confident nearest match is worse than an honest miss; never stretch an unrelated decision to fit.";
|
|
338
377
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
339
378
|
var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
|
|
@@ -376,14 +415,14 @@ var RETAIN_STRATEGIES = {
|
|
|
376
415
|
retain_chunk_size: 12e3
|
|
377
416
|
}
|
|
378
417
|
};
|
|
379
|
-
var
|
|
418
|
+
var PAGE_LABELS = {
|
|
380
419
|
key: "knowledge",
|
|
381
420
|
type: "multi-values",
|
|
382
421
|
// 0, 1, or several — empty is normal
|
|
383
422
|
optional: true,
|
|
384
423
|
tag: true,
|
|
385
424
|
// emits knowledge:<value> onto the fact's tags
|
|
386
|
-
description: "Routing labels for this project's Hindsight
|
|
425
|
+
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.",
|
|
387
426
|
values: [
|
|
388
427
|
{
|
|
389
428
|
value: "feature-work",
|
|
@@ -540,7 +579,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
540
579
|
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
541
580
|
retain_default_strategy: "git",
|
|
542
581
|
retain_strategies: RETAIN_STRATEGIES,
|
|
543
|
-
entity_labels: [
|
|
582
|
+
entity_labels: [PAGE_LABELS],
|
|
544
583
|
entities_allow_free_form: true
|
|
545
584
|
}
|
|
546
585
|
};
|
|
@@ -592,40 +631,7 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
592
631
|
}
|
|
593
632
|
|
|
594
633
|
// package.json
|
|
595
|
-
var version = "0.8.
|
|
596
|
-
|
|
597
|
-
// src/core/util.ts
|
|
598
|
-
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
599
|
-
import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
|
|
600
|
-
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
601
|
-
function semverGte(version2, min) {
|
|
602
|
-
const parts = (v) => {
|
|
603
|
-
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
604
|
-
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
605
|
-
};
|
|
606
|
-
const a = version2 ? parts(version2) : void 0;
|
|
607
|
-
const b = parts(min);
|
|
608
|
-
if (!a || !b) return false;
|
|
609
|
-
for (let i = 0; i < 3; i++) {
|
|
610
|
-
if (a[i] !== b[i]) return a[i] > b[i];
|
|
611
|
-
}
|
|
612
|
-
return true;
|
|
613
|
-
}
|
|
614
|
-
async function pool(items, n, fn, onError, onProgress) {
|
|
615
|
-
let i = 0, done = 0;
|
|
616
|
-
async function worker() {
|
|
617
|
-
while (i < items.length) {
|
|
618
|
-
const idx = i++;
|
|
619
|
-
try {
|
|
620
|
-
await fn(items[idx], idx);
|
|
621
|
-
} catch (e) {
|
|
622
|
-
onError?.(idx, e);
|
|
623
|
-
}
|
|
624
|
-
onProgress?.(++done, items.length);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
await Promise.all(Array.from({ length: Math.min(n, items.length) }, worker));
|
|
628
|
-
}
|
|
634
|
+
var version = "0.8.8";
|
|
629
635
|
|
|
630
636
|
// src/core/hindsight.ts
|
|
631
637
|
var USER_AGENT = `hindsight-coding-agents/${version}`;
|
|
@@ -652,11 +658,11 @@ function retryAfterMs(header) {
|
|
|
652
658
|
const at = Date.parse(header);
|
|
653
659
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
654
660
|
}
|
|
655
|
-
var
|
|
656
|
-
code = "
|
|
661
|
+
var PagesUnavailableError = class extends Error {
|
|
662
|
+
code = "pages_unavailable";
|
|
657
663
|
constructor() {
|
|
658
|
-
super("Hindsight server does not support
|
|
659
|
-
this.name = "
|
|
664
|
+
super("Hindsight server does not support pages");
|
|
665
|
+
this.name = "PagesUnavailableError";
|
|
660
666
|
}
|
|
661
667
|
};
|
|
662
668
|
async function isEndpointMissing(r) {
|
|
@@ -667,6 +673,10 @@ async function isEndpointMissing(r) {
|
|
|
667
673
|
return false;
|
|
668
674
|
}
|
|
669
675
|
}
|
|
676
|
+
function pagesPath(sub, legacy = false) {
|
|
677
|
+
if (!legacy) return `/pages${sub}`;
|
|
678
|
+
return /^\/(tree|folders|search|export|nodes)\b/.test(sub) ? `/knowledge-base${sub}` : `/knowledge-base/pages${sub}`;
|
|
679
|
+
}
|
|
670
680
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
671
681
|
var ReflectError = class extends Error {
|
|
672
682
|
constructor(message, status, timedOut, options) {
|
|
@@ -735,7 +745,7 @@ var HindsightClient = class {
|
|
|
735
745
|
opIds = [];
|
|
736
746
|
// async operation ids collected by retain(), for drain()
|
|
737
747
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
738
|
-
|
|
748
|
+
pagesSupported;
|
|
739
749
|
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
740
750
|
idempotentRetain;
|
|
741
751
|
log;
|
|
@@ -833,7 +843,9 @@ var HindsightClient = class {
|
|
|
833
843
|
}
|
|
834
844
|
if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
|
|
835
845
|
throw new Error(
|
|
836
|
-
|
|
846
|
+
// Query dropped: an encoded search query filled the 200-char error cap and pushed the
|
|
847
|
+
// status and the server's reason out of the tool error (#6341).
|
|
848
|
+
`${method} ${url.split("?")[0]} -> ${r.status} ${await r.text()}${this.authHint(r.status)}`
|
|
837
849
|
);
|
|
838
850
|
return r;
|
|
839
851
|
}
|
|
@@ -964,7 +976,7 @@ var HindsightClient = class {
|
|
|
964
976
|
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
965
977
|
}
|
|
966
978
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
967
|
-
* entity labels), then seed
|
|
979
|
+
* entity labels), then seed pages when the server supports them. Both halves are
|
|
968
980
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
969
981
|
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
970
982
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
@@ -979,6 +991,15 @@ var HindsightClient = class {
|
|
|
979
991
|
await this.req("DELETE", this.bankUrl());
|
|
980
992
|
this.log(`[bank] reset ${this.bank}`);
|
|
981
993
|
}
|
|
994
|
+
await this.configureBankSettings(opts);
|
|
995
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
996
|
+
}
|
|
997
|
+
/** The config half of `configureBank` (missions, retain strategies, entity labels), without
|
|
998
|
+
* seeding pages. Session start calls it directly when the deepen engine — the usual caller of
|
|
999
|
+
* `configureBank` — will not run (`autoSeed: false`, or a directory with no git history):
|
|
1000
|
+
* without it such a bank never got the `conversation` strategy, and every session write-back
|
|
1001
|
+
* was extracted with the server's generic rules instead of the plugin's mission. */
|
|
1002
|
+
async configureBankSettings(opts = {}) {
|
|
982
1003
|
if (opts.manage === false) {
|
|
983
1004
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
984
1005
|
} else {
|
|
@@ -994,7 +1015,6 @@ var HindsightClient = class {
|
|
|
994
1015
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
995
1016
|
}
|
|
996
1017
|
}
|
|
997
|
-
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
998
1018
|
}
|
|
999
1019
|
/**
|
|
1000
1020
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -1146,29 +1166,45 @@ var HindsightClient = class {
|
|
|
1146
1166
|
const j = await r.json();
|
|
1147
1167
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
1148
1168
|
}
|
|
1169
|
+
/** Set once a server answered on the deprecated `/knowledge-base/...` paths: one from before the
|
|
1170
|
+
* page routes moved to `/pages/...`. Remove in 2.x. */
|
|
1171
|
+
legacyPagesPaths = false;
|
|
1149
1172
|
/**
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1173
|
+
* Request a page endpoint by its `/pages` sub-path (`""`, `/tree`, `/<id>`, `/nodes/<id>`, …).
|
|
1174
|
+
*
|
|
1175
|
+
* Returns `null` — and latches `pagesSupported = false` — iff the endpoint is really absent: an
|
|
1176
|
+
* unrouted 404 on the `/pages` path AND on its pre-rename `/knowledge-base` twin, which a server
|
|
1177
|
+
* older than the rename still serves (tried once, then remembered). A bank-not-found 404 is NOT
|
|
1178
|
+
* a capability verdict — it is the expected answer before the bank's first retain — so it is
|
|
1179
|
+
* returned as-is and never caches a negative (#4607). A 404's body may already be consumed.
|
|
1153
1180
|
*
|
|
1154
1181
|
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1155
1182
|
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1156
1183
|
*/
|
|
1157
|
-
async
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
return
|
|
1184
|
+
async pagesReq(method, sub, body, tolerate = [], timeoutMs) {
|
|
1185
|
+
const send = (legacy) => this.req(method, this.bankUrl(pagesPath(sub, legacy)), body, tolerate, timeoutMs);
|
|
1186
|
+
let r = await send(this.legacyPagesPaths);
|
|
1187
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return r;
|
|
1188
|
+
if (!this.legacyPagesPaths) {
|
|
1189
|
+
r = await send(true);
|
|
1190
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) {
|
|
1191
|
+
this.legacyPagesPaths = true;
|
|
1192
|
+
return r;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
this.pagesSupported = false;
|
|
1196
|
+
return null;
|
|
1161
1197
|
}
|
|
1162
1198
|
/**
|
|
1163
|
-
* The bank's
|
|
1199
|
+
* The bank's page tree (folders + pages, nested). The tree carries names, source
|
|
1164
1200
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
1165
1201
|
*/
|
|
1166
1202
|
async tree() {
|
|
1167
|
-
if (this.
|
|
1168
|
-
const r = await this.
|
|
1169
|
-
if (
|
|
1203
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1204
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1205
|
+
if (!r) throw new PagesUnavailableError();
|
|
1170
1206
|
if (r.status === 404) return [];
|
|
1171
|
-
this.
|
|
1207
|
+
this.pagesSupported = true;
|
|
1172
1208
|
try {
|
|
1173
1209
|
return (await r.json()).roots ?? [];
|
|
1174
1210
|
} catch {
|
|
@@ -1176,13 +1212,13 @@ var HindsightClient = class {
|
|
|
1176
1212
|
}
|
|
1177
1213
|
}
|
|
1178
1214
|
/**
|
|
1179
|
-
* List
|
|
1215
|
+
* List pages (ids + names only — no synthesized content), flattened out of the tree
|
|
1180
1216
|
* and shaped as `{items:[…]}` for `parsePageList`. Folders are dropped: they carry no content
|
|
1181
1217
|
* to read, and a caller enumerating pages wants leaves, not structure.
|
|
1182
1218
|
*
|
|
1183
|
-
* NOTE the ids are
|
|
1184
|
-
* page read/update in this client goes through the same
|
|
1185
|
-
* here, from `
|
|
1219
|
+
* NOTE the ids are page node ids (`kp-…`), NOT the backing mental-model ids. Every
|
|
1220
|
+
* page read/update in this client goes through the same page ids, so a page id from
|
|
1221
|
+
* here, from `searchPages`, or from a `[[page:<id>]]` link all resolve identically.
|
|
1186
1222
|
*/
|
|
1187
1223
|
async listPages() {
|
|
1188
1224
|
const items = [];
|
|
@@ -1204,34 +1240,26 @@ var HindsightClient = class {
|
|
|
1204
1240
|
return { items };
|
|
1205
1241
|
}
|
|
1206
1242
|
/**
|
|
1207
|
-
* Read one
|
|
1243
|
+
* Read one page's synthesized content by page id, shaped by `shapePage` so
|
|
1208
1244
|
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1209
1245
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1210
1246
|
* token cap.
|
|
1211
1247
|
*/
|
|
1212
1248
|
async getPage(pageId) {
|
|
1213
|
-
if (this.
|
|
1214
|
-
const r = await this.
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
);
|
|
1218
|
-
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1249
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1250
|
+
const r = await this.pagesReq("GET", `/${encodeURIComponent(pageId)}`);
|
|
1251
|
+
if (!r) throw new PagesUnavailableError();
|
|
1252
|
+
if (r.status === 404) throw new Error(`page not found: ${pageId}`);
|
|
1219
1253
|
return shapePage(await r.json());
|
|
1220
1254
|
}
|
|
1221
|
-
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's
|
|
1255
|
+
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's pages.
|
|
1222
1256
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1223
|
-
*
|
|
1224
|
-
async
|
|
1225
|
-
if (this.
|
|
1257
|
+
* hindsight_search_pages. */
|
|
1258
|
+
async searchPages(query, opts = {}) {
|
|
1259
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1226
1260
|
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1227
|
-
const r = await this.
|
|
1228
|
-
|
|
1229
|
-
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1230
|
-
void 0,
|
|
1231
|
-
[],
|
|
1232
|
-
opts.timeoutMs
|
|
1233
|
-
);
|
|
1234
|
-
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1261
|
+
const r = await this.pagesReq("GET", `/search${q}`, void 0, [], opts.timeoutMs);
|
|
1262
|
+
if (!r) throw new PagesUnavailableError();
|
|
1235
1263
|
if (r.status === 404) return [];
|
|
1236
1264
|
const j = await r.json();
|
|
1237
1265
|
return (j.results ?? []).map((x) => ({
|
|
@@ -1243,9 +1271,9 @@ var HindsightClient = class {
|
|
|
1243
1271
|
}));
|
|
1244
1272
|
}
|
|
1245
1273
|
/**
|
|
1246
|
-
* Seed the fixed page taxonomy as
|
|
1274
|
+
* Seed the fixed page taxonomy as pages at the tree root, idempotently.
|
|
1247
1275
|
*
|
|
1248
|
-
* Matched by NAME, not id:
|
|
1276
|
+
* Matched by NAME, not id: `POST /pages` mints its own `kp-…` id, so a stable
|
|
1249
1277
|
* client-chosen id isn't available to match on (unlike the old mental-model path, which keyed
|
|
1250
1278
|
* off a slug). Names are unique per folder server-side, which makes them a sound key.
|
|
1251
1279
|
*
|
|
@@ -1260,8 +1288,8 @@ var HindsightClient = class {
|
|
|
1260
1288
|
try {
|
|
1261
1289
|
roots = await this.tree();
|
|
1262
1290
|
} catch (e) {
|
|
1263
|
-
if (e instanceof
|
|
1264
|
-
this.log(`[bank]
|
|
1291
|
+
if (e instanceof PagesUnavailableError) {
|
|
1292
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1265
1293
|
return;
|
|
1266
1294
|
}
|
|
1267
1295
|
throw e;
|
|
@@ -1284,11 +1312,9 @@ var HindsightClient = class {
|
|
|
1284
1312
|
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1285
1313
|
};
|
|
1286
1314
|
if (!hit) {
|
|
1287
|
-
const r = await this.
|
|
1288
|
-
if (
|
|
1289
|
-
this.log(
|
|
1290
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1291
|
-
);
|
|
1315
|
+
const r = await this.pagesReq("POST", "", body, [409]);
|
|
1316
|
+
if (!r) {
|
|
1317
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1292
1318
|
return;
|
|
1293
1319
|
}
|
|
1294
1320
|
if (r.status === 404) {
|
|
@@ -1309,15 +1335,9 @@ var HindsightClient = class {
|
|
|
1309
1335
|
);
|
|
1310
1336
|
}
|
|
1311
1337
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1312
|
-
const r = await this.
|
|
1313
|
-
|
|
1314
|
-
this.
|
|
1315
|
-
patch
|
|
1316
|
-
);
|
|
1317
|
-
if (await this.pagesUnsupported(r)) {
|
|
1318
|
-
this.log(
|
|
1319
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1320
|
-
);
|
|
1338
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(hit.id)}`, patch);
|
|
1339
|
+
if (!r) {
|
|
1340
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1321
1341
|
return;
|
|
1322
1342
|
}
|
|
1323
1343
|
if (r.status === 404) {
|
|
@@ -1329,7 +1349,7 @@ var HindsightClient = class {
|
|
|
1329
1349
|
}
|
|
1330
1350
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1331
1351
|
this.log(
|
|
1332
|
-
`[bank]
|
|
1352
|
+
`[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` : "")
|
|
1333
1353
|
);
|
|
1334
1354
|
}
|
|
1335
1355
|
/**
|
|
@@ -1363,12 +1383,8 @@ var HindsightClient = class {
|
|
|
1363
1383
|
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
1364
1384
|
}
|
|
1365
1385
|
if (!patch.trigger && !patch.source_query) continue;
|
|
1366
|
-
const r = await this.
|
|
1367
|
-
|
|
1368
|
-
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1369
|
-
patch
|
|
1370
|
-
);
|
|
1371
|
-
if (r.status === 404) continue;
|
|
1386
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(page.id)}`, patch);
|
|
1387
|
+
if (!r || r.status === 404) continue;
|
|
1372
1388
|
updated++;
|
|
1373
1389
|
}
|
|
1374
1390
|
return updated;
|
|
@@ -1394,7 +1410,7 @@ var HindsightClient = class {
|
|
|
1394
1410
|
let pageId = args.relatesToPageId;
|
|
1395
1411
|
if (!pageId) {
|
|
1396
1412
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1397
|
-
const r = await this.
|
|
1413
|
+
const r = await this.pagesReq("POST", "", {
|
|
1398
1414
|
name: args.title,
|
|
1399
1415
|
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),
|
|
1400
1416
|
parent_id: folderId,
|
|
@@ -1403,8 +1419,8 @@ var HindsightClient = class {
|
|
|
1403
1419
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1404
1420
|
});
|
|
1405
1421
|
try {
|
|
1406
|
-
const j = await r
|
|
1407
|
-
pageId = j
|
|
1422
|
+
const j = await r?.json();
|
|
1423
|
+
pageId = j?.page_id ?? j?.id;
|
|
1408
1424
|
} catch {
|
|
1409
1425
|
}
|
|
1410
1426
|
pageId ||= `initiative-${this.slugify(args.title)}`;
|
|
@@ -1422,16 +1438,17 @@ var HindsightClient = class {
|
|
|
1422
1438
|
/** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
|
|
1423
1439
|
async ensureFolder(name) {
|
|
1424
1440
|
try {
|
|
1425
|
-
const
|
|
1426
|
-
const
|
|
1441
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1442
|
+
const tree = await r?.json();
|
|
1443
|
+
const hit = (tree?.roots || []).find(
|
|
1427
1444
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === name.toLowerCase()
|
|
1428
1445
|
);
|
|
1429
1446
|
if (hit?.id) return hit.id;
|
|
1430
1447
|
} catch {
|
|
1431
1448
|
}
|
|
1432
1449
|
try {
|
|
1433
|
-
const r = await this.
|
|
1434
|
-
return (await r
|
|
1450
|
+
const r = await this.pagesReq("POST", "/folders", { name });
|
|
1451
|
+
return (await r?.json())?.id;
|
|
1435
1452
|
} catch {
|
|
1436
1453
|
return void 0;
|
|
1437
1454
|
}
|
|
@@ -1870,7 +1887,7 @@ function commitsSince(dir, sinceSha) {
|
|
|
1870
1887
|
}
|
|
1871
1888
|
}
|
|
1872
1889
|
|
|
1873
|
-
// src/core/
|
|
1890
|
+
// src/core/page-injection.ts
|
|
1874
1891
|
function parsePageList(raw) {
|
|
1875
1892
|
const items = raw?.items;
|
|
1876
1893
|
if (!Array.isArray(items)) return [];
|
|
@@ -1977,7 +1994,7 @@ async function syncStatus(client2, bank, repoDir) {
|
|
|
1977
1994
|
activeOps,
|
|
1978
1995
|
// Older Hindsight servers have no page surface. They are still fully usable for the
|
|
1979
1996
|
// legacy bank/retain pipeline, so page absence must not make syncStatus permanently false.
|
|
1980
|
-
synced: gitlogPresent && (client2.
|
|
1997
|
+
synced: gitlogPresent && (client2.pagesSupported === false || pages.length > 0) && (activeOps ?? 0) === 0
|
|
1981
1998
|
};
|
|
1982
1999
|
}
|
|
1983
2000
|
|