@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/deepen.js
CHANGED
|
@@ -267,7 +267,11 @@ function configuredDir(dir) {
|
|
|
267
267
|
const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir2(), dir.slice(1)) : dir;
|
|
268
268
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
269
269
|
}
|
|
270
|
-
function isWithin(directory, configured) {
|
|
270
|
+
function isWithin(directory, configured, platform = process.platform) {
|
|
271
|
+
if (platform === "win32") {
|
|
272
|
+
directory = directory.toLowerCase();
|
|
273
|
+
configured = configured.toLowerCase();
|
|
274
|
+
}
|
|
271
275
|
return directory === configured || directory.startsWith(configured + sep);
|
|
272
276
|
}
|
|
273
277
|
function mapLookup(map, directory) {
|
|
@@ -357,7 +361,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
|
|
|
357
361
|
import { createHash } from "crypto";
|
|
358
362
|
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.";
|
|
359
363
|
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.";
|
|
360
|
-
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.`;
|
|
364
|
+
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.`;
|
|
361
365
|
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.";
|
|
362
366
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
363
367
|
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.";
|
|
@@ -400,14 +404,14 @@ var RETAIN_STRATEGIES = {
|
|
|
400
404
|
retain_chunk_size: 12e3
|
|
401
405
|
}
|
|
402
406
|
};
|
|
403
|
-
var
|
|
407
|
+
var PAGE_LABELS = {
|
|
404
408
|
key: "knowledge",
|
|
405
409
|
type: "multi-values",
|
|
406
410
|
// 0, 1, or several — empty is normal
|
|
407
411
|
optional: true,
|
|
408
412
|
tag: true,
|
|
409
413
|
// emits knowledge:<value> onto the fact's tags
|
|
410
|
-
description: "Routing labels for this project's Hindsight
|
|
414
|
+
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.",
|
|
411
415
|
values: [
|
|
412
416
|
{
|
|
413
417
|
value: "feature-work",
|
|
@@ -564,7 +568,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
564
568
|
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
565
569
|
retain_default_strategy: "git",
|
|
566
570
|
retain_strategies: RETAIN_STRATEGIES,
|
|
567
|
-
entity_labels: [
|
|
571
|
+
entity_labels: [PAGE_LABELS],
|
|
568
572
|
entities_allow_free_form: true
|
|
569
573
|
}
|
|
570
574
|
};
|
|
@@ -616,7 +620,7 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
616
620
|
}
|
|
617
621
|
|
|
618
622
|
// package.json
|
|
619
|
-
var version = "0.8.
|
|
623
|
+
var version = "0.8.8";
|
|
620
624
|
|
|
621
625
|
// src/core/util.ts
|
|
622
626
|
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
@@ -676,11 +680,11 @@ function retryAfterMs(header) {
|
|
|
676
680
|
const at = Date.parse(header);
|
|
677
681
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
678
682
|
}
|
|
679
|
-
var
|
|
680
|
-
code = "
|
|
683
|
+
var PagesUnavailableError = class extends Error {
|
|
684
|
+
code = "pages_unavailable";
|
|
681
685
|
constructor() {
|
|
682
|
-
super("Hindsight server does not support
|
|
683
|
-
this.name = "
|
|
686
|
+
super("Hindsight server does not support pages");
|
|
687
|
+
this.name = "PagesUnavailableError";
|
|
684
688
|
}
|
|
685
689
|
};
|
|
686
690
|
async function isEndpointMissing(r) {
|
|
@@ -691,6 +695,10 @@ async function isEndpointMissing(r) {
|
|
|
691
695
|
return false;
|
|
692
696
|
}
|
|
693
697
|
}
|
|
698
|
+
function pagesPath(sub, legacy = false) {
|
|
699
|
+
if (!legacy) return `/pages${sub}`;
|
|
700
|
+
return /^\/(tree|folders|search|export|nodes)\b/.test(sub) ? `/knowledge-base${sub}` : `/knowledge-base/pages${sub}`;
|
|
701
|
+
}
|
|
694
702
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
695
703
|
var ReflectError = class extends Error {
|
|
696
704
|
constructor(message, status, timedOut, options) {
|
|
@@ -759,7 +767,7 @@ var HindsightClient = class {
|
|
|
759
767
|
opIds = [];
|
|
760
768
|
// async operation ids collected by retain(), for drain()
|
|
761
769
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
762
|
-
|
|
770
|
+
pagesSupported;
|
|
763
771
|
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
764
772
|
idempotentRetain;
|
|
765
773
|
log;
|
|
@@ -857,7 +865,9 @@ var HindsightClient = class {
|
|
|
857
865
|
}
|
|
858
866
|
if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
|
|
859
867
|
throw new Error(
|
|
860
|
-
|
|
868
|
+
// Query dropped: an encoded search query filled the 200-char error cap and pushed the
|
|
869
|
+
// status and the server's reason out of the tool error (#6341).
|
|
870
|
+
`${method} ${url.split("?")[0]} -> ${r.status} ${await r.text()}${this.authHint(r.status)}`
|
|
861
871
|
);
|
|
862
872
|
return r;
|
|
863
873
|
}
|
|
@@ -988,7 +998,7 @@ var HindsightClient = class {
|
|
|
988
998
|
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
989
999
|
}
|
|
990
1000
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
991
|
-
* entity labels), then seed
|
|
1001
|
+
* entity labels), then seed pages when the server supports them. Both halves are
|
|
992
1002
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
993
1003
|
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
994
1004
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
@@ -1003,6 +1013,15 @@ var HindsightClient = class {
|
|
|
1003
1013
|
await this.req("DELETE", this.bankUrl());
|
|
1004
1014
|
this.log(`[bank] reset ${this.bank}`);
|
|
1005
1015
|
}
|
|
1016
|
+
await this.configureBankSettings(opts);
|
|
1017
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
1018
|
+
}
|
|
1019
|
+
/** The config half of `configureBank` (missions, retain strategies, entity labels), without
|
|
1020
|
+
* seeding pages. Session start calls it directly when the deepen engine — the usual caller of
|
|
1021
|
+
* `configureBank` — will not run (`autoSeed: false`, or a directory with no git history):
|
|
1022
|
+
* without it such a bank never got the `conversation` strategy, and every session write-back
|
|
1023
|
+
* was extracted with the server's generic rules instead of the plugin's mission. */
|
|
1024
|
+
async configureBankSettings(opts = {}) {
|
|
1006
1025
|
if (opts.manage === false) {
|
|
1007
1026
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
1008
1027
|
} else {
|
|
@@ -1018,7 +1037,6 @@ var HindsightClient = class {
|
|
|
1018
1037
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
1019
1038
|
}
|
|
1020
1039
|
}
|
|
1021
|
-
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
1022
1040
|
}
|
|
1023
1041
|
/**
|
|
1024
1042
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -1170,29 +1188,45 @@ var HindsightClient = class {
|
|
|
1170
1188
|
const j = await r.json();
|
|
1171
1189
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
1172
1190
|
}
|
|
1191
|
+
/** Set once a server answered on the deprecated `/knowledge-base/...` paths: one from before the
|
|
1192
|
+
* page routes moved to `/pages/...`. Remove in 2.x. */
|
|
1193
|
+
legacyPagesPaths = false;
|
|
1173
1194
|
/**
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1195
|
+
* Request a page endpoint by its `/pages` sub-path (`""`, `/tree`, `/<id>`, `/nodes/<id>`, …).
|
|
1196
|
+
*
|
|
1197
|
+
* Returns `null` — and latches `pagesSupported = false` — iff the endpoint is really absent: an
|
|
1198
|
+
* unrouted 404 on the `/pages` path AND on its pre-rename `/knowledge-base` twin, which a server
|
|
1199
|
+
* older than the rename still serves (tried once, then remembered). A bank-not-found 404 is NOT
|
|
1200
|
+
* a capability verdict — it is the expected answer before the bank's first retain — so it is
|
|
1201
|
+
* returned as-is and never caches a negative (#4607). A 404's body may already be consumed.
|
|
1177
1202
|
*
|
|
1178
1203
|
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1179
1204
|
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1180
1205
|
*/
|
|
1181
|
-
async
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
return
|
|
1206
|
+
async pagesReq(method, sub, body, tolerate = [], timeoutMs) {
|
|
1207
|
+
const send = (legacy) => this.req(method, this.bankUrl(pagesPath(sub, legacy)), body, tolerate, timeoutMs);
|
|
1208
|
+
let r = await send(this.legacyPagesPaths);
|
|
1209
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return r;
|
|
1210
|
+
if (!this.legacyPagesPaths) {
|
|
1211
|
+
r = await send(true);
|
|
1212
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) {
|
|
1213
|
+
this.legacyPagesPaths = true;
|
|
1214
|
+
return r;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
this.pagesSupported = false;
|
|
1218
|
+
return null;
|
|
1185
1219
|
}
|
|
1186
1220
|
/**
|
|
1187
|
-
* The bank's
|
|
1221
|
+
* The bank's page tree (folders + pages, nested). The tree carries names, source
|
|
1188
1222
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
1189
1223
|
*/
|
|
1190
1224
|
async tree() {
|
|
1191
|
-
if (this.
|
|
1192
|
-
const r = await this.
|
|
1193
|
-
if (
|
|
1225
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1226
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1227
|
+
if (!r) throw new PagesUnavailableError();
|
|
1194
1228
|
if (r.status === 404) return [];
|
|
1195
|
-
this.
|
|
1229
|
+
this.pagesSupported = true;
|
|
1196
1230
|
try {
|
|
1197
1231
|
return (await r.json()).roots ?? [];
|
|
1198
1232
|
} catch {
|
|
@@ -1200,13 +1234,13 @@ var HindsightClient = class {
|
|
|
1200
1234
|
}
|
|
1201
1235
|
}
|
|
1202
1236
|
/**
|
|
1203
|
-
* List
|
|
1237
|
+
* List pages (ids + names only — no synthesized content), flattened out of the tree
|
|
1204
1238
|
* and shaped as `{items:[…]}` for `parsePageList`. Folders are dropped: they carry no content
|
|
1205
1239
|
* to read, and a caller enumerating pages wants leaves, not structure.
|
|
1206
1240
|
*
|
|
1207
|
-
* NOTE the ids are
|
|
1208
|
-
* page read/update in this client goes through the same
|
|
1209
|
-
* here, from `
|
|
1241
|
+
* NOTE the ids are page node ids (`kp-…`), NOT the backing mental-model ids. Every
|
|
1242
|
+
* page read/update in this client goes through the same page ids, so a page id from
|
|
1243
|
+
* here, from `searchPages`, or from a `[[page:<id>]]` link all resolve identically.
|
|
1210
1244
|
*/
|
|
1211
1245
|
async listPages() {
|
|
1212
1246
|
const items = [];
|
|
@@ -1228,34 +1262,26 @@ var HindsightClient = class {
|
|
|
1228
1262
|
return { items };
|
|
1229
1263
|
}
|
|
1230
1264
|
/**
|
|
1231
|
-
* Read one
|
|
1265
|
+
* Read one page's synthesized content by page id, shaped by `shapePage` so
|
|
1232
1266
|
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1233
1267
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1234
1268
|
* token cap.
|
|
1235
1269
|
*/
|
|
1236
1270
|
async getPage(pageId) {
|
|
1237
|
-
if (this.
|
|
1238
|
-
const r = await this.
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
);
|
|
1242
|
-
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1271
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1272
|
+
const r = await this.pagesReq("GET", `/${encodeURIComponent(pageId)}`);
|
|
1273
|
+
if (!r) throw new PagesUnavailableError();
|
|
1274
|
+
if (r.status === 404) throw new Error(`page not found: ${pageId}`);
|
|
1243
1275
|
return shapePage(await r.json());
|
|
1244
1276
|
}
|
|
1245
|
-
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's
|
|
1277
|
+
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's pages.
|
|
1246
1278
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1247
|
-
*
|
|
1248
|
-
async
|
|
1249
|
-
if (this.
|
|
1279
|
+
* hindsight_search_pages. */
|
|
1280
|
+
async searchPages(query, opts = {}) {
|
|
1281
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
1250
1282
|
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1251
|
-
const r = await this.
|
|
1252
|
-
|
|
1253
|
-
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1254
|
-
void 0,
|
|
1255
|
-
[],
|
|
1256
|
-
opts.timeoutMs
|
|
1257
|
-
);
|
|
1258
|
-
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1283
|
+
const r = await this.pagesReq("GET", `/search${q}`, void 0, [], opts.timeoutMs);
|
|
1284
|
+
if (!r) throw new PagesUnavailableError();
|
|
1259
1285
|
if (r.status === 404) return [];
|
|
1260
1286
|
const j = await r.json();
|
|
1261
1287
|
return (j.results ?? []).map((x) => ({
|
|
@@ -1267,9 +1293,9 @@ var HindsightClient = class {
|
|
|
1267
1293
|
}));
|
|
1268
1294
|
}
|
|
1269
1295
|
/**
|
|
1270
|
-
* Seed the fixed page taxonomy as
|
|
1296
|
+
* Seed the fixed page taxonomy as pages at the tree root, idempotently.
|
|
1271
1297
|
*
|
|
1272
|
-
* Matched by NAME, not id:
|
|
1298
|
+
* Matched by NAME, not id: `POST /pages` mints its own `kp-…` id, so a stable
|
|
1273
1299
|
* client-chosen id isn't available to match on (unlike the old mental-model path, which keyed
|
|
1274
1300
|
* off a slug). Names are unique per folder server-side, which makes them a sound key.
|
|
1275
1301
|
*
|
|
@@ -1284,8 +1310,8 @@ var HindsightClient = class {
|
|
|
1284
1310
|
try {
|
|
1285
1311
|
roots = await this.tree();
|
|
1286
1312
|
} catch (e) {
|
|
1287
|
-
if (e instanceof
|
|
1288
|
-
this.log(`[bank]
|
|
1313
|
+
if (e instanceof PagesUnavailableError) {
|
|
1314
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1289
1315
|
return;
|
|
1290
1316
|
}
|
|
1291
1317
|
throw e;
|
|
@@ -1308,11 +1334,9 @@ var HindsightClient = class {
|
|
|
1308
1334
|
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1309
1335
|
};
|
|
1310
1336
|
if (!hit) {
|
|
1311
|
-
const r = await this.
|
|
1312
|
-
if (
|
|
1313
|
-
this.log(
|
|
1314
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1315
|
-
);
|
|
1337
|
+
const r = await this.pagesReq("POST", "", body, [409]);
|
|
1338
|
+
if (!r) {
|
|
1339
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1316
1340
|
return;
|
|
1317
1341
|
}
|
|
1318
1342
|
if (r.status === 404) {
|
|
@@ -1333,15 +1357,9 @@ var HindsightClient = class {
|
|
|
1333
1357
|
);
|
|
1334
1358
|
}
|
|
1335
1359
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1336
|
-
const r = await this.
|
|
1337
|
-
|
|
1338
|
-
this.
|
|
1339
|
-
patch
|
|
1340
|
-
);
|
|
1341
|
-
if (await this.pagesUnsupported(r)) {
|
|
1342
|
-
this.log(
|
|
1343
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1344
|
-
);
|
|
1360
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(hit.id)}`, patch);
|
|
1361
|
+
if (!r) {
|
|
1362
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
1345
1363
|
return;
|
|
1346
1364
|
}
|
|
1347
1365
|
if (r.status === 404) {
|
|
@@ -1353,7 +1371,7 @@ var HindsightClient = class {
|
|
|
1353
1371
|
}
|
|
1354
1372
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1355
1373
|
this.log(
|
|
1356
|
-
`[bank]
|
|
1374
|
+
`[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` : "")
|
|
1357
1375
|
);
|
|
1358
1376
|
}
|
|
1359
1377
|
/**
|
|
@@ -1387,12 +1405,8 @@ var HindsightClient = class {
|
|
|
1387
1405
|
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
1388
1406
|
}
|
|
1389
1407
|
if (!patch.trigger && !patch.source_query) continue;
|
|
1390
|
-
const r = await this.
|
|
1391
|
-
|
|
1392
|
-
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1393
|
-
patch
|
|
1394
|
-
);
|
|
1395
|
-
if (r.status === 404) continue;
|
|
1408
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(page.id)}`, patch);
|
|
1409
|
+
if (!r || r.status === 404) continue;
|
|
1396
1410
|
updated++;
|
|
1397
1411
|
}
|
|
1398
1412
|
return updated;
|
|
@@ -1418,7 +1432,7 @@ var HindsightClient = class {
|
|
|
1418
1432
|
let pageId = args.relatesToPageId;
|
|
1419
1433
|
if (!pageId) {
|
|
1420
1434
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1421
|
-
const r = await this.
|
|
1435
|
+
const r = await this.pagesReq("POST", "", {
|
|
1422
1436
|
name: args.title,
|
|
1423
1437
|
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),
|
|
1424
1438
|
parent_id: folderId,
|
|
@@ -1427,8 +1441,8 @@ var HindsightClient = class {
|
|
|
1427
1441
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1428
1442
|
});
|
|
1429
1443
|
try {
|
|
1430
|
-
const j = await r
|
|
1431
|
-
pageId = j
|
|
1444
|
+
const j = await r?.json();
|
|
1445
|
+
pageId = j?.page_id ?? j?.id;
|
|
1432
1446
|
} catch {
|
|
1433
1447
|
}
|
|
1434
1448
|
pageId ||= `initiative-${this.slugify(args.title)}`;
|
|
@@ -1446,16 +1460,17 @@ var HindsightClient = class {
|
|
|
1446
1460
|
/** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
|
|
1447
1461
|
async ensureFolder(name) {
|
|
1448
1462
|
try {
|
|
1449
|
-
const
|
|
1450
|
-
const
|
|
1463
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
1464
|
+
const tree = await r?.json();
|
|
1465
|
+
const hit = (tree?.roots || []).find(
|
|
1451
1466
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === name.toLowerCase()
|
|
1452
1467
|
);
|
|
1453
1468
|
if (hit?.id) return hit.id;
|
|
1454
1469
|
} catch {
|
|
1455
1470
|
}
|
|
1456
1471
|
try {
|
|
1457
|
-
const r = await this.
|
|
1458
|
-
return (await r
|
|
1472
|
+
const r = await this.pagesReq("POST", "/folders", { name });
|
|
1473
|
+
return (await r?.json())?.id;
|
|
1459
1474
|
} catch {
|
|
1460
1475
|
return void 0;
|
|
1461
1476
|
}
|
|
@@ -2549,8 +2564,8 @@ async function main() {
|
|
|
2549
2564
|
extractionMode: cfg.retainExtractionMode,
|
|
2550
2565
|
defaults: cfg.defaultBankConfig
|
|
2551
2566
|
});
|
|
2552
|
-
if (client.
|
|
2553
|
-
diag(harness.name, "
|
|
2567
|
+
if (client.pagesSupported === false) {
|
|
2568
|
+
diag(harness.name, "pages_unavailable", {
|
|
2554
2569
|
bank: FINAL_BANK,
|
|
2555
2570
|
apiUrl: client.apiUrl
|
|
2556
2571
|
});
|