@vectorize-io/hindsight-coding-agents 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -30
- package/dist/antigravity-hook.js +130 -135
- package/dist/antigravity-statusline.js +1 -1
- package/dist/antigravity-stop-hook.js +113 -114
- package/dist/claude-hook.js +130 -135
- package/dist/claude-sessionstart-hook.js +205 -215
- package/dist/claude-stop-hook.js +113 -114
- package/dist/cline.js +206 -211
- package/dist/codebuddy-hook.js +130 -135
- package/dist/codebuddy-sessionstart-hook.js +205 -215
- package/dist/codebuddy-stop-hook.js +113 -114
- package/dist/codex-hook.js +130 -135
- package/dist/codex-sessionstart-hook.js +205 -215
- package/dist/codex-stop-hook.js +113 -114
- package/dist/copilot-hook.js +130 -135
- package/dist/copilot-sessionstart-hook.js +205 -215
- package/dist/copilot-stop-hook.js +113 -114
- package/dist/cursor-hook.js +130 -135
- package/dist/cursor-sessionstart-hook.js +205 -215
- package/dist/cursor-stop-hook.js +113 -114
- package/dist/daemon-start.js +1 -1
- package/dist/dcode-hook.js +130 -135
- package/dist/dcode-sessionstart-hook.js +205 -215
- package/dist/dcode-stop-hook.js +113 -114
- package/dist/deepen.js +80 -79
- package/dist/devin-hook.js +130 -135
- package/dist/devin-sessionstart-hook.js +205 -215
- package/dist/devin-stop-hook.js +113 -114
- package/dist/droid-hook.js +130 -135
- package/dist/droid-sessionstart-hook.js +205 -215
- package/dist/droid-stop-hook.js +113 -114
- package/dist/dsh.js +235 -248
- package/dist/grok-hook.js +130 -135
- package/dist/grok-sessionstart-hook.js +205 -215
- package/dist/grok-stop-hook.js +113 -114
- package/dist/hindsight-seed.js +1 -1
- package/dist/index.js +236 -249
- package/dist/installer.js +30 -28
- package/dist/kilo.js +236 -249
- package/dist/kimi-hook.js +130 -135
- package/dist/kimi-sessionstart-hook.js +205 -215
- package/dist/kimi-stop-hook.js +113 -114
- package/dist/mcp-server.js +94 -93
- package/dist/opencode2.js +236 -249
- package/dist/pi.js +235 -248
- package/dist/prime-agent.js +235 -248
- package/dist/qwen-hook.js +130 -135
- package/dist/qwen-sessionstart-hook.js +205 -215
- package/dist/qwen-stop-hook.js +113 -114
- package/dist/status.js +80 -79
- package/dist/traecode-hook.js +130 -135
- package/dist/traecode-sessionstart-hook.js +205 -215
- package/dist/traecode-stop-hook.js +113 -114
- package/dist/workbuddy-hook.js +130 -135
- package/dist/workbuddy-sessionstart-hook.js +205 -215
- package/dist/workbuddy-stop-hook.js +113 -114
- package/dist/zcode-hook.js +130 -135
- package/dist/zcode-sessionstart-hook.js +205 -215
- package/dist/zcode-stop-hook.js +113 -114
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +26 -26
package/dist/prime-agent.js
CHANGED
|
@@ -14951,14 +14951,14 @@ var RETAIN_STRATEGIES = {
|
|
|
14951
14951
|
retain_chunk_size: 12e3
|
|
14952
14952
|
}
|
|
14953
14953
|
};
|
|
14954
|
-
var
|
|
14954
|
+
var PAGE_LABELS = {
|
|
14955
14955
|
key: "knowledge",
|
|
14956
14956
|
type: "multi-values",
|
|
14957
14957
|
// 0, 1, or several — empty is normal
|
|
14958
14958
|
optional: true,
|
|
14959
14959
|
tag: true,
|
|
14960
14960
|
// emits knowledge:<value> onto the fact's tags
|
|
14961
|
-
description: "Routing labels for this project's Hindsight
|
|
14961
|
+
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.",
|
|
14962
14962
|
values: [
|
|
14963
14963
|
{
|
|
14964
14964
|
value: "feature-work",
|
|
@@ -15115,7 +15115,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
15115
15115
|
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
15116
15116
|
retain_default_strategy: "git",
|
|
15117
15117
|
retain_strategies: RETAIN_STRATEGIES,
|
|
15118
|
-
entity_labels: [
|
|
15118
|
+
entity_labels: [PAGE_LABELS],
|
|
15119
15119
|
entities_allow_free_form: true
|
|
15120
15120
|
}
|
|
15121
15121
|
};
|
|
@@ -15167,7 +15167,7 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
15167
15167
|
}
|
|
15168
15168
|
|
|
15169
15169
|
// package.json
|
|
15170
|
-
var version2 = "0.8.
|
|
15170
|
+
var version2 = "0.8.7";
|
|
15171
15171
|
|
|
15172
15172
|
// src/core/util.ts
|
|
15173
15173
|
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
@@ -15250,11 +15250,11 @@ function retryAfterMs(header) {
|
|
|
15250
15250
|
const at = Date.parse(header);
|
|
15251
15251
|
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
15252
15252
|
}
|
|
15253
|
-
var
|
|
15254
|
-
code = "
|
|
15253
|
+
var PagesUnavailableError = class extends Error {
|
|
15254
|
+
code = "pages_unavailable";
|
|
15255
15255
|
constructor() {
|
|
15256
|
-
super("Hindsight server does not support
|
|
15257
|
-
this.name = "
|
|
15256
|
+
super("Hindsight server does not support pages");
|
|
15257
|
+
this.name = "PagesUnavailableError";
|
|
15258
15258
|
}
|
|
15259
15259
|
};
|
|
15260
15260
|
async function isEndpointMissing(r) {
|
|
@@ -15265,6 +15265,10 @@ async function isEndpointMissing(r) {
|
|
|
15265
15265
|
return false;
|
|
15266
15266
|
}
|
|
15267
15267
|
}
|
|
15268
|
+
function pagesPath(sub, legacy = false) {
|
|
15269
|
+
if (!legacy) return `/pages${sub}`;
|
|
15270
|
+
return /^\/(tree|folders|search|export|nodes)\b/.test(sub) ? `/knowledge-base${sub}` : `/knowledge-base/pages${sub}`;
|
|
15271
|
+
}
|
|
15268
15272
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
15269
15273
|
var ReflectError = class extends Error {
|
|
15270
15274
|
constructor(message, status, timedOut, options) {
|
|
@@ -15333,7 +15337,7 @@ var HindsightClient = class {
|
|
|
15333
15337
|
opIds = [];
|
|
15334
15338
|
// async operation ids collected by retain(), for drain()
|
|
15335
15339
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
15336
|
-
|
|
15340
|
+
pagesSupported;
|
|
15337
15341
|
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
15338
15342
|
idempotentRetain;
|
|
15339
15343
|
log;
|
|
@@ -15562,7 +15566,7 @@ var HindsightClient = class {
|
|
|
15562
15566
|
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
15563
15567
|
}
|
|
15564
15568
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
15565
|
-
* entity labels), then seed
|
|
15569
|
+
* entity labels), then seed pages when the server supports them. Both halves are
|
|
15566
15570
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
15567
15571
|
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
15568
15572
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
@@ -15744,29 +15748,45 @@ var HindsightClient = class {
|
|
|
15744
15748
|
const j = await r.json();
|
|
15745
15749
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
15746
15750
|
}
|
|
15751
|
+
/** Set once a server answered on the deprecated `/knowledge-base/...` paths: one from before the
|
|
15752
|
+
* page routes moved to `/pages/...`. Remove in 2.x. */
|
|
15753
|
+
legacyPagesPaths = false;
|
|
15747
15754
|
/**
|
|
15748
|
-
*
|
|
15749
|
-
*
|
|
15750
|
-
*
|
|
15755
|
+
* Request a page endpoint by its `/pages` sub-path (`""`, `/tree`, `/<id>`, `/nodes/<id>`, …).
|
|
15756
|
+
*
|
|
15757
|
+
* Returns `null` — and latches `pagesSupported = false` — iff the endpoint is really absent: an
|
|
15758
|
+
* unrouted 404 on the `/pages` path AND on its pre-rename `/knowledge-base` twin, which a server
|
|
15759
|
+
* older than the rename still serves (tried once, then remembered). A bank-not-found 404 is NOT
|
|
15760
|
+
* a capability verdict — it is the expected answer before the bank's first retain — so it is
|
|
15761
|
+
* returned as-is and never caches a negative (#4607). A 404's body may already be consumed.
|
|
15751
15762
|
*
|
|
15752
15763
|
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
15753
15764
|
* the 405/501 this used to check for never reach a caller in the first place.
|
|
15754
15765
|
*/
|
|
15755
|
-
async
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
return
|
|
15766
|
+
async pagesReq(method, sub, body, tolerate = [], timeoutMs) {
|
|
15767
|
+
const send = (legacy) => this.req(method, this.bankUrl(pagesPath(sub, legacy)), body, tolerate, timeoutMs);
|
|
15768
|
+
let r = await send(this.legacyPagesPaths);
|
|
15769
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return r;
|
|
15770
|
+
if (!this.legacyPagesPaths) {
|
|
15771
|
+
r = await send(true);
|
|
15772
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) {
|
|
15773
|
+
this.legacyPagesPaths = true;
|
|
15774
|
+
return r;
|
|
15775
|
+
}
|
|
15776
|
+
}
|
|
15777
|
+
this.pagesSupported = false;
|
|
15778
|
+
return null;
|
|
15759
15779
|
}
|
|
15760
15780
|
/**
|
|
15761
|
-
* The bank's
|
|
15781
|
+
* The bank's page tree (folders + pages, nested). The tree carries names, source
|
|
15762
15782
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
15763
15783
|
*/
|
|
15764
15784
|
async tree() {
|
|
15765
|
-
if (this.
|
|
15766
|
-
const r = await this.
|
|
15767
|
-
if (
|
|
15785
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
15786
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
15787
|
+
if (!r) throw new PagesUnavailableError();
|
|
15768
15788
|
if (r.status === 404) return [];
|
|
15769
|
-
this.
|
|
15789
|
+
this.pagesSupported = true;
|
|
15770
15790
|
try {
|
|
15771
15791
|
return (await r.json()).roots ?? [];
|
|
15772
15792
|
} catch {
|
|
@@ -15774,13 +15794,13 @@ var HindsightClient = class {
|
|
|
15774
15794
|
}
|
|
15775
15795
|
}
|
|
15776
15796
|
/**
|
|
15777
|
-
* List
|
|
15797
|
+
* List pages (ids + names only — no synthesized content), flattened out of the tree
|
|
15778
15798
|
* and shaped as `{items:[…]}` for `parsePageList`. Folders are dropped: they carry no content
|
|
15779
15799
|
* to read, and a caller enumerating pages wants leaves, not structure.
|
|
15780
15800
|
*
|
|
15781
|
-
* NOTE the ids are
|
|
15782
|
-
* page read/update in this client goes through the same
|
|
15783
|
-
* here, from `
|
|
15801
|
+
* NOTE the ids are page node ids (`kp-…`), NOT the backing mental-model ids. Every
|
|
15802
|
+
* page read/update in this client goes through the same page ids, so a page id from
|
|
15803
|
+
* here, from `searchPages`, or from a `[[page:<id>]]` link all resolve identically.
|
|
15784
15804
|
*/
|
|
15785
15805
|
async listPages() {
|
|
15786
15806
|
const items = [];
|
|
@@ -15802,34 +15822,26 @@ var HindsightClient = class {
|
|
|
15802
15822
|
return { items };
|
|
15803
15823
|
}
|
|
15804
15824
|
/**
|
|
15805
|
-
* Read one
|
|
15825
|
+
* Read one page's synthesized content by page id, shaped by `shapePage` so
|
|
15806
15826
|
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
15807
15827
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
15808
15828
|
* token cap.
|
|
15809
15829
|
*/
|
|
15810
15830
|
async getPage(pageId) {
|
|
15811
|
-
if (this.
|
|
15812
|
-
const r = await this.
|
|
15813
|
-
|
|
15814
|
-
|
|
15815
|
-
);
|
|
15816
|
-
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
15831
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
15832
|
+
const r = await this.pagesReq("GET", `/${encodeURIComponent(pageId)}`);
|
|
15833
|
+
if (!r) throw new PagesUnavailableError();
|
|
15834
|
+
if (r.status === 404) throw new Error(`page not found: ${pageId}`);
|
|
15817
15835
|
return shapePage(await r.json());
|
|
15818
15836
|
}
|
|
15819
|
-
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's
|
|
15837
|
+
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's pages.
|
|
15820
15838
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
15821
|
-
*
|
|
15822
|
-
async
|
|
15823
|
-
if (this.
|
|
15839
|
+
* hindsight_search_pages. */
|
|
15840
|
+
async searchPages(query, opts = {}) {
|
|
15841
|
+
if (this.pagesSupported === false) throw new PagesUnavailableError();
|
|
15824
15842
|
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
15825
|
-
const r = await this.
|
|
15826
|
-
|
|
15827
|
-
this.bankUrl(`/knowledge-base/search${q}`),
|
|
15828
|
-
void 0,
|
|
15829
|
-
[],
|
|
15830
|
-
opts.timeoutMs
|
|
15831
|
-
);
|
|
15832
|
-
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
15843
|
+
const r = await this.pagesReq("GET", `/search${q}`, void 0, [], opts.timeoutMs);
|
|
15844
|
+
if (!r) throw new PagesUnavailableError();
|
|
15833
15845
|
if (r.status === 404) return [];
|
|
15834
15846
|
const j = await r.json();
|
|
15835
15847
|
return (j.results ?? []).map((x) => ({
|
|
@@ -15841,9 +15853,9 @@ var HindsightClient = class {
|
|
|
15841
15853
|
}));
|
|
15842
15854
|
}
|
|
15843
15855
|
/**
|
|
15844
|
-
* Seed the fixed page taxonomy as
|
|
15856
|
+
* Seed the fixed page taxonomy as pages at the tree root, idempotently.
|
|
15845
15857
|
*
|
|
15846
|
-
* Matched by NAME, not id:
|
|
15858
|
+
* Matched by NAME, not id: `POST /pages` mints its own `kp-…` id, so a stable
|
|
15847
15859
|
* client-chosen id isn't available to match on (unlike the old mental-model path, which keyed
|
|
15848
15860
|
* off a slug). Names are unique per folder server-side, which makes them a sound key.
|
|
15849
15861
|
*
|
|
@@ -15858,8 +15870,8 @@ var HindsightClient = class {
|
|
|
15858
15870
|
try {
|
|
15859
15871
|
roots = await this.tree();
|
|
15860
15872
|
} catch (e) {
|
|
15861
|
-
if (e instanceof
|
|
15862
|
-
this.log(`[bank]
|
|
15873
|
+
if (e instanceof PagesUnavailableError) {
|
|
15874
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
15863
15875
|
return;
|
|
15864
15876
|
}
|
|
15865
15877
|
throw e;
|
|
@@ -15882,11 +15894,9 @@ var HindsightClient = class {
|
|
|
15882
15894
|
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
15883
15895
|
};
|
|
15884
15896
|
if (!hit) {
|
|
15885
|
-
const r = await this.
|
|
15886
|
-
if (
|
|
15887
|
-
this.log(
|
|
15888
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
15889
|
-
);
|
|
15897
|
+
const r = await this.pagesReq("POST", "", body, [409]);
|
|
15898
|
+
if (!r) {
|
|
15899
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
15890
15900
|
return;
|
|
15891
15901
|
}
|
|
15892
15902
|
if (r.status === 404) {
|
|
@@ -15907,15 +15917,9 @@ var HindsightClient = class {
|
|
|
15907
15917
|
);
|
|
15908
15918
|
}
|
|
15909
15919
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
15910
|
-
const r = await this.
|
|
15911
|
-
|
|
15912
|
-
this.
|
|
15913
|
-
patch
|
|
15914
|
-
);
|
|
15915
|
-
if (await this.pagesUnsupported(r)) {
|
|
15916
|
-
this.log(
|
|
15917
|
-
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
15918
|
-
);
|
|
15920
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(hit.id)}`, patch);
|
|
15921
|
+
if (!r) {
|
|
15922
|
+
this.log(`[bank] pages unavailable on ${this.apiUrl}; continuing without them`);
|
|
15919
15923
|
return;
|
|
15920
15924
|
}
|
|
15921
15925
|
if (r.status === 404) {
|
|
@@ -15927,7 +15931,7 @@ var HindsightClient = class {
|
|
|
15927
15931
|
}
|
|
15928
15932
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
15929
15933
|
this.log(
|
|
15930
|
-
`[bank]
|
|
15934
|
+
`[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` : "")
|
|
15931
15935
|
);
|
|
15932
15936
|
}
|
|
15933
15937
|
/**
|
|
@@ -15961,12 +15965,8 @@ var HindsightClient = class {
|
|
|
15961
15965
|
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
15962
15966
|
}
|
|
15963
15967
|
if (!patch.trigger && !patch.source_query) continue;
|
|
15964
|
-
const r = await this.
|
|
15965
|
-
|
|
15966
|
-
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
15967
|
-
patch
|
|
15968
|
-
);
|
|
15969
|
-
if (r.status === 404) continue;
|
|
15968
|
+
const r = await this.pagesReq("PATCH", `/nodes/${encodeURIComponent(page.id)}`, patch);
|
|
15969
|
+
if (!r || r.status === 404) continue;
|
|
15970
15970
|
updated++;
|
|
15971
15971
|
}
|
|
15972
15972
|
return updated;
|
|
@@ -15992,7 +15992,7 @@ var HindsightClient = class {
|
|
|
15992
15992
|
let pageId = args.relatesToPageId;
|
|
15993
15993
|
if (!pageId) {
|
|
15994
15994
|
const folderId = await this.ensureFolder("Initiatives");
|
|
15995
|
-
const r = await this.
|
|
15995
|
+
const r = await this.pagesReq("POST", "", {
|
|
15996
15996
|
name: args.title,
|
|
15997
15997
|
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),
|
|
15998
15998
|
parent_id: folderId,
|
|
@@ -16001,8 +16001,8 @@ var HindsightClient = class {
|
|
|
16001
16001
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
16002
16002
|
});
|
|
16003
16003
|
try {
|
|
16004
|
-
const j = await r
|
|
16005
|
-
pageId = j
|
|
16004
|
+
const j = await r?.json();
|
|
16005
|
+
pageId = j?.page_id ?? j?.id;
|
|
16006
16006
|
} catch {
|
|
16007
16007
|
}
|
|
16008
16008
|
pageId ||= `initiative-${this.slugify(args.title)}`;
|
|
@@ -16020,16 +16020,17 @@ var HindsightClient = class {
|
|
|
16020
16020
|
/** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
|
|
16021
16021
|
async ensureFolder(name) {
|
|
16022
16022
|
try {
|
|
16023
|
-
const
|
|
16024
|
-
const
|
|
16023
|
+
const r = await this.pagesReq("GET", "/tree");
|
|
16024
|
+
const tree = await r?.json();
|
|
16025
|
+
const hit = (tree?.roots || []).find(
|
|
16025
16026
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === name.toLowerCase()
|
|
16026
16027
|
);
|
|
16027
16028
|
if (hit?.id) return hit.id;
|
|
16028
16029
|
} catch {
|
|
16029
16030
|
}
|
|
16030
16031
|
try {
|
|
16031
|
-
const r = await this.
|
|
16032
|
-
return (await r
|
|
16032
|
+
const r = await this.pagesReq("POST", "/folders", { name });
|
|
16033
|
+
return (await r?.json())?.id;
|
|
16033
16034
|
} catch {
|
|
16034
16035
|
return void 0;
|
|
16035
16036
|
}
|
|
@@ -16869,7 +16870,7 @@ function preflightDaemon(cfg, harness) {
|
|
|
16869
16870
|
return true;
|
|
16870
16871
|
}
|
|
16871
16872
|
|
|
16872
|
-
// src/core/
|
|
16873
|
+
// src/core/page-injection.ts
|
|
16873
16874
|
function parsePageList(raw) {
|
|
16874
16875
|
const items = raw?.items;
|
|
16875
16876
|
if (!Array.isArray(items)) return [];
|
|
@@ -16881,12 +16882,12 @@ function parsePageList(raw) {
|
|
|
16881
16882
|
}
|
|
16882
16883
|
return out;
|
|
16883
16884
|
}
|
|
16884
|
-
var EMPTY_STATE = "No
|
|
16885
|
+
var EMPTY_STATE = "No pages yet \u2014 Hindsight is still learning this repo; they'll appear as it processes.";
|
|
16885
16886
|
function indexLine(pages) {
|
|
16886
|
-
const count = pages.length === 1 ? "1
|
|
16887
|
-
return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call
|
|
16887
|
+
const count = pages.length === 1 ? "1 page covers" : `${pages.length} pages cover`;
|
|
16888
|
+
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.`;
|
|
16888
16889
|
}
|
|
16889
|
-
var TOOL_GUIDE = `-
|
|
16890
|
+
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:
|
|
16890
16891
|
\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);
|
|
16891
16892
|
\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);
|
|
16892
16893
|
\u2022 you are implementing something new, or two parts have to fit together;
|
|
@@ -16894,35 +16895,35 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, a
|
|
|
16894
16895
|
\u2022 you are about to commit, and need to know what the change was supposed to honour.
|
|
16895
16896
|
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.
|
|
16896
16897
|
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.
|
|
16897
|
-
-
|
|
16898
|
+
- 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.
|
|
16898
16899
|
- 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>").
|
|
16899
16900
|
- 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.
|
|
16900
16901
|
- 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).`;
|
|
16901
|
-
var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the
|
|
16902
|
+
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";
|
|
16902
16903
|
function toolGuide(opts) {
|
|
16903
16904
|
const extra = opts?.extra?.trim();
|
|
16904
16905
|
return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE + (extra ? `
|
|
16905
16906
|
${extra}` : "");
|
|
16906
16907
|
}
|
|
16907
|
-
function
|
|
16908
|
+
function buildPagesPreamble(pages, opts) {
|
|
16908
16909
|
const body = pages.length ? indexLine(pages) : EMPTY_STATE;
|
|
16909
|
-
return `<
|
|
16910
|
-
This repository has a Hindsight memory +
|
|
16910
|
+
return `<hindsight_pages>
|
|
16911
|
+
This repository has a Hindsight memory + pages (curated, continuously-updated pages plus the raw memory behind them). The tools below are registered, but you must actually CALL them at the right moments:
|
|
16911
16912
|
${toolGuide(opts)}
|
|
16912
16913
|
ALSO your correction tool: when you verify a Hindsight memory is wrong or stale, ingest a "Correction: <topic>" doc stating what memory claimed, what is true now, and the evidence \u2014 newer facts supersede older ones.
|
|
16913
16914
|
${body}
|
|
16914
16915
|
This tool guide and the page list are re-injected for you periodically as things change.
|
|
16915
|
-
</
|
|
16916
|
+
</hindsight_pages>`;
|
|
16916
16917
|
}
|
|
16917
16918
|
function buildRosterRefresh(pages, opts) {
|
|
16918
16919
|
const rosterBlock = pages.length ? `${indexLine(pages)}
|
|
16919
16920
|
` : "";
|
|
16920
|
-
return "<
|
|
16921
|
+
return "<hindsight_page_refresh>\n" + rosterBlock + `Reminder \u2014 this repo's Hindsight tools are available; call them at the right moments:
|
|
16921
16922
|
${toolGuide(opts)}
|
|
16922
|
-
</
|
|
16923
|
+
</hindsight_page_refresh>`;
|
|
16923
16924
|
}
|
|
16924
16925
|
|
|
16925
|
-
// src/core/
|
|
16926
|
+
// src/core/page-tools.ts
|
|
16926
16927
|
import { createHash as createHash4 } from "crypto";
|
|
16927
16928
|
import { existsSync as existsSync4 } from "fs";
|
|
16928
16929
|
import { homedir as homedir6 } from "os";
|
|
@@ -17435,97 +17436,88 @@ function surveyAttempts(file2, sha) {
|
|
|
17435
17436
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17436
17437
|
try {
|
|
17437
17438
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17438
|
-
const resolveBin = opts.resolveBin ?? ((
|
|
17439
|
+
const resolveBin = opts.resolveBin ?? ((bin2) => binOnPath(bin2, { exts: [".exe"] }));
|
|
17439
17440
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17440
|
-
const
|
|
17441
|
-
const
|
|
17442
|
-
|
|
17443
|
-
"
|
|
17444
|
-
|
|
17445
|
-
|
|
17446
|
-
|
|
17447
|
-
|
|
17448
|
-
|
|
17449
|
-
|
|
17450
|
-
|
|
17451
|
-
|
|
17452
|
-
|
|
17453
|
-
|
|
17454
|
-
|
|
17455
|
-
|
|
17456
|
-
|
|
17457
|
-
|
|
17458
|
-
|
|
17459
|
-
|
|
17460
|
-
|
|
17461
|
-
|
|
17462
|
-
|
|
17463
|
-
|
|
17464
|
-
|
|
17465
|
-
|
|
17466
|
-
|
|
17467
|
-
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17481
|
-
|
|
17482
|
-
|
|
17483
|
-
|
|
17484
|
-
|
|
17485
|
-
|
|
17486
|
-
|
|
17487
|
-
|
|
17488
|
-
|
|
17489
|
-
|
|
17490
|
-
|
|
17491
|
-
|
|
17492
|
-
|
|
17493
|
-
|
|
17494
|
-
|
|
17495
|
-
detached: true,
|
|
17496
|
-
stdio: "ignore",
|
|
17497
|
-
windowsHide: true,
|
|
17498
|
-
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17499
|
-
});
|
|
17500
|
-
let spawned = false;
|
|
17501
|
-
child.on("error", (e) => {
|
|
17502
|
-
if (spawned) return;
|
|
17503
|
-
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17504
|
-
releaseLease(lease);
|
|
17505
|
-
resolve4(false);
|
|
17506
|
-
});
|
|
17507
|
-
child.once("spawn", () => {
|
|
17508
|
-
spawned = true;
|
|
17509
|
-
child.unref();
|
|
17510
|
-
if (opts.sha) {
|
|
17511
|
-
try {
|
|
17512
|
-
writeFileSync3(
|
|
17513
|
-
attemptsFile,
|
|
17514
|
-
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17515
|
-
{ mode: 384 }
|
|
17516
|
-
);
|
|
17517
|
-
} catch {
|
|
17518
|
-
}
|
|
17519
|
-
}
|
|
17520
|
-
resolve4(true);
|
|
17521
|
-
});
|
|
17522
|
-
} catch (e) {
|
|
17441
|
+
const harness = opts.harness ?? "claude-code";
|
|
17442
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17443
|
+
if (!name) {
|
|
17444
|
+
log.info("survey", `${harness}: no headless survey for this agent, skipping the survey`);
|
|
17445
|
+
return false;
|
|
17446
|
+
}
|
|
17447
|
+
const bin = resolveBin(name);
|
|
17448
|
+
if (!bin) {
|
|
17449
|
+
log.info("survey", `${harness}: ${name} not found, skipping the survey`);
|
|
17450
|
+
return false;
|
|
17451
|
+
}
|
|
17452
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17453
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, skipping the survey`);
|
|
17454
|
+
return false;
|
|
17455
|
+
}
|
|
17456
|
+
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17457
|
+
model: opts.model,
|
|
17458
|
+
budgetUsd: opts.budgetUsd,
|
|
17459
|
+
mcpServerPath
|
|
17460
|
+
});
|
|
17461
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17462
|
+
if (cfg.disabled) return false;
|
|
17463
|
+
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17464
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17465
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17466
|
+
if (!lease) return false;
|
|
17467
|
+
const attemptsFile = join11(
|
|
17468
|
+
leaseDir,
|
|
17469
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17470
|
+
);
|
|
17471
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17472
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17473
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17474
|
+
releaseLease(lease);
|
|
17475
|
+
return false;
|
|
17476
|
+
}
|
|
17477
|
+
const spec = {
|
|
17478
|
+
lease,
|
|
17479
|
+
bin: plan.bin,
|
|
17480
|
+
args: plan.args,
|
|
17481
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17482
|
+
};
|
|
17483
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17484
|
+
return await new Promise((resolve4) => {
|
|
17485
|
+
try {
|
|
17486
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
17487
|
+
cwd: repoDir,
|
|
17488
|
+
detached: true,
|
|
17489
|
+
stdio: "ignore",
|
|
17490
|
+
windowsHide: true,
|
|
17491
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17492
|
+
});
|
|
17493
|
+
let spawned = false;
|
|
17494
|
+
child.on("error", (e) => {
|
|
17495
|
+
if (spawned) return;
|
|
17523
17496
|
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17524
17497
|
releaseLease(lease);
|
|
17525
17498
|
resolve4(false);
|
|
17526
|
-
}
|
|
17527
|
-
|
|
17528
|
-
|
|
17499
|
+
});
|
|
17500
|
+
child.once("spawn", () => {
|
|
17501
|
+
spawned = true;
|
|
17502
|
+
child.unref();
|
|
17503
|
+
if (opts.sha) {
|
|
17504
|
+
try {
|
|
17505
|
+
writeFileSync3(
|
|
17506
|
+
attemptsFile,
|
|
17507
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17508
|
+
{ mode: 384 }
|
|
17509
|
+
);
|
|
17510
|
+
} catch {
|
|
17511
|
+
}
|
|
17512
|
+
}
|
|
17513
|
+
resolve4(true);
|
|
17514
|
+
});
|
|
17515
|
+
} catch (e) {
|
|
17516
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17517
|
+
releaseLease(lease);
|
|
17518
|
+
resolve4(false);
|
|
17519
|
+
}
|
|
17520
|
+
});
|
|
17529
17521
|
} catch {
|
|
17530
17522
|
}
|
|
17531
17523
|
return false;
|
|
@@ -17589,11 +17581,11 @@ async function syncStatus(client, bank, repoDir) {
|
|
|
17589
17581
|
activeOps,
|
|
17590
17582
|
// Older Hindsight servers have no page surface. They are still fully usable for the
|
|
17591
17583
|
// legacy bank/retain pipeline, so page absence must not make syncStatus permanently false.
|
|
17592
|
-
synced: gitlogPresent && (client.
|
|
17584
|
+
synced: gitlogPresent && (client.pagesSupported === false || pages.length > 0) && (activeOps ?? 0) === 0
|
|
17593
17585
|
};
|
|
17594
17586
|
}
|
|
17595
17587
|
|
|
17596
|
-
// src/core/
|
|
17588
|
+
// src/core/page-tools.ts
|
|
17597
17589
|
var READ_ONLY_ANNOTATIONS = {
|
|
17598
17590
|
readOnlyHint: true,
|
|
17599
17591
|
destructiveHint: false,
|
|
@@ -17623,13 +17615,13 @@ function guarded(fn) {
|
|
|
17623
17615
|
}
|
|
17624
17616
|
};
|
|
17625
17617
|
}
|
|
17626
|
-
function
|
|
17618
|
+
function buildPageTools(client, bankId, opts = {}) {
|
|
17627
17619
|
const extra = opts.toolGuideExtra?.trim();
|
|
17628
17620
|
const crediting = extra ? `${CREDIT_REMINDER} ${extra}` : CREDIT_REMINDER;
|
|
17629
17621
|
return [
|
|
17630
17622
|
{
|
|
17631
17623
|
name: "hindsight_sync_status",
|
|
17632
|
-
description: "Report whether this repo's memory bank is in sync: gitlog seed present, how much recent history has been deepened with full diffs, conversations ingested,
|
|
17624
|
+
description: "Report whether this repo's memory bank is in sync: gitlog seed present, how much recent history has been deepened with full diffs, conversations ingested, pages created, and extractions still running. `synced: true` means the seeded memory is fully queryable. Ingestion is automatic and background \u2014 if not synced, it is in progress; nothing to run.",
|
|
17633
17625
|
inputSchema: {},
|
|
17634
17626
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17635
17627
|
handler: async () => {
|
|
@@ -17684,13 +17676,13 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17684
17676
|
}
|
|
17685
17677
|
},
|
|
17686
17678
|
{
|
|
17687
|
-
name: "
|
|
17688
|
-
description: "Search this repository's Hindsight
|
|
17679
|
+
name: "hindsight_search_pages",
|
|
17680
|
+
description: "Search this repository's Hindsight pages for content relevant to a query \u2014 hybrid full-text + semantic search, server-side. Call this when the user's question may be answered by the project's accumulated knowledge (architecture, conventions, decisions, initiatives) rather than by reading code. Returns ranked pages with a relevance snippet; read a full page with hindsight_read_page. " + crediting,
|
|
17689
17681
|
inputSchema: { query: external_exports.string().describe("what to look for") },
|
|
17690
17682
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17691
17683
|
handler: async (args) => {
|
|
17692
17684
|
try {
|
|
17693
|
-
const hits = await client.
|
|
17685
|
+
const hits = await client.searchPages(args.query);
|
|
17694
17686
|
return ok({
|
|
17695
17687
|
pages: hits.map((h) => ({
|
|
17696
17688
|
page: h.name,
|
|
@@ -17708,22 +17700,22 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17708
17700
|
}
|
|
17709
17701
|
},
|
|
17710
17702
|
{
|
|
17711
|
-
name: "
|
|
17712
|
-
description: "List this repository's Hindsight
|
|
17703
|
+
name: "hindsight_list_pages",
|
|
17704
|
+
description: "List this repository's Hindsight pages \u2014 curated, continuously-updated summaries of the project's durable knowledge (architecture, components, conventions, key decisions, and in-flight initiatives). Returns each page's id, title, and a one-line description of what it covers. Call this at the start of any non-trivial task, and again periodically in long sessions, to see what the project already knows before you read code or ask the user. The list changes as work is captured, so re-check it occasionally.",
|
|
17713
17705
|
inputSchema: {},
|
|
17714
17706
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17715
17707
|
handler: guarded(async () => client.listPages())
|
|
17716
17708
|
},
|
|
17717
17709
|
{
|
|
17718
|
-
name: "
|
|
17719
|
-
description: "Read the full content of one
|
|
17710
|
+
name: "hindsight_read_page",
|
|
17711
|
+
description: "Read the full content of one page by its id (from hindsight_list_pages). Call this whenever a listed page is relevant to what you're about to do \u2014 e.g. read Conventions before writing new code, Component map before changing a subsystem, or an initiative's page before continuing that feature. A page may contain [[page:<id>]] links to related pages; follow one by calling this tool again with that id. Prefer reading a page over re-deriving the same understanding from source.",
|
|
17720
17712
|
inputSchema: { page_id: external_exports.string() },
|
|
17721
17713
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17722
17714
|
handler: guarded(async ({ page_id }) => client.getPage(page_id))
|
|
17723
17715
|
},
|
|
17724
17716
|
{
|
|
17725
17717
|
name: "hindsight_reflect",
|
|
17726
|
-
description: `Deep memory reasoning: an agentic synthesis over this repository's FULL memory (git decisions, past sessions, ingested knowledge) that answers WHY questions \u2014 the past decision and exact rule/values that explain a behavior, bug, or convention. Slower than
|
|
17718
|
+
description: `Deep memory reasoning: an agentic synthesis over this repository's FULL memory (git decisions, past sessions, ingested knowledge) that answers WHY questions \u2014 the past decision and exact rule/values that explain a behavior, bug, or convention. Slower than hindsight_search_pages (several seconds): reach for it when pages are too shallow and you need the root cause or the decided literals. When the answer informs your reply, credit it visibly with a blockquote header: "> \u{1F9E0} **From Hindsight memory** \u2014 <summary>".`,
|
|
17727
17719
|
inputSchema: { query: external_exports.string().describe("the question to reason over memory about") },
|
|
17728
17720
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17729
17721
|
handler: guarded(
|
|
@@ -17735,7 +17727,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17735
17727
|
},
|
|
17736
17728
|
{
|
|
17737
17729
|
name: "hindsight_capture_initiative",
|
|
17738
|
-
description: "Record a new feature or initiative as a tracked
|
|
17730
|
+
description: "Record a new feature or initiative as a tracked page, so future sessions know it exists and can build on it \u2014 and keep that page tracking the plan as it moves.\n\nWHEN TO CALL:\n- Starting one: right after the user approves a plan or finishes brainstorming a new feature/capability and you are about to start implementing \u2014 BEFORE you write any code. Leave relates_to_page_id empty.\n- Plan changed: call it AGAIN \u2014 mid-implementation is fine and expected \u2014 whenever the goal, scope, or rationale of an initiative you already captured materially changes (an approach is dropped, scope grows or shrinks, the why is rewritten). Pass relates_to_page_id = that initiative's page id so the change lands on the existing page. Never mint a second page for the same initiative.\n\nWHEN TO SKIP: bug fixes, small tweaks, refactors, chores, and trivial course-corrections that leave the goal intact are not initiatives \u2014 skip them.\n\n- title: short, specific name (e.g. 'Newsletter refinement chat'). On a recapture, reuse the initiative's existing title.\n- summary: 2-3 sentences on what you're building and why \u2014 the CURRENT intent, not the originally approved plan (on a recapture, say what changed and why).\n- relates_to_page_id: leave empty for a new initiative. Set it to an existing initiative's page id \u2014 from hindsight_list_pages, or the id this tool returned earlier \u2014 to record a plan change or an enhancement to it.\n\nReturns the page id. The page is generated for you \u2014 you never format one yourself.",
|
|
17739
17731
|
inputSchema: {
|
|
17740
17732
|
title: external_exports.string(),
|
|
17741
17733
|
summary: external_exports.string(),
|
|
@@ -18472,11 +18464,11 @@ async function buildSessionStartContext(args) {
|
|
|
18472
18464
|
try {
|
|
18473
18465
|
pages = parsePageList(await client.listPages());
|
|
18474
18466
|
} catch {
|
|
18475
|
-
if (client.
|
|
18476
|
-
diag(harness, "
|
|
18467
|
+
if (client.pagesSupported === false) {
|
|
18468
|
+
diag(harness, "pages_unavailable", { bank: bankId });
|
|
18477
18469
|
}
|
|
18478
18470
|
}
|
|
18479
|
-
const additionalContext =
|
|
18471
|
+
const additionalContext = buildPagesPreamble(pages, {
|
|
18480
18472
|
reflectOnNewGoals: cfg.autoInject !== "reflect",
|
|
18481
18473
|
extra: cfg.toolGuideExtra
|
|
18482
18474
|
});
|
|
@@ -18506,6 +18498,41 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
|
18506
18498
|
// src/core/hook.ts
|
|
18507
18499
|
import { existsSync as existsSync8 } from "fs";
|
|
18508
18500
|
|
|
18501
|
+
// src/core/transcript-util.ts
|
|
18502
|
+
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;
|
|
18503
|
+
function stripInjectedMemory(s) {
|
|
18504
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
18505
|
+
}
|
|
18506
|
+
var TARGET_KEYS = [
|
|
18507
|
+
"file_path",
|
|
18508
|
+
"path",
|
|
18509
|
+
"notebook_path",
|
|
18510
|
+
"command",
|
|
18511
|
+
"pattern",
|
|
18512
|
+
"query",
|
|
18513
|
+
"url",
|
|
18514
|
+
"name",
|
|
18515
|
+
"id"
|
|
18516
|
+
];
|
|
18517
|
+
var ACTION_TARGET_CAP = 100;
|
|
18518
|
+
function actionLine(tool, input) {
|
|
18519
|
+
let target = "";
|
|
18520
|
+
if (input && typeof input === "object") {
|
|
18521
|
+
const rec = input;
|
|
18522
|
+
for (const k of TARGET_KEYS) {
|
|
18523
|
+
const v = rec[k];
|
|
18524
|
+
if (typeof v === "string" && v.trim()) {
|
|
18525
|
+
target = v.trim().split("\n")[0];
|
|
18526
|
+
break;
|
|
18527
|
+
}
|
|
18528
|
+
}
|
|
18529
|
+
} else if (typeof input === "string") {
|
|
18530
|
+
target = input.trim().split("\n")[0];
|
|
18531
|
+
}
|
|
18532
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
18533
|
+
return target ? `${tool} ${target}` : tool;
|
|
18534
|
+
}
|
|
18535
|
+
|
|
18509
18536
|
// src/core/inject.ts
|
|
18510
18537
|
function buildReflectQuery(prompt) {
|
|
18511
18538
|
return `A developer is starting a coding session in this repository with this goal:
|
|
@@ -18522,8 +18549,8 @@ Report what this bank's history genuinely bears on that goal. Rendering rules, s
|
|
|
18522
18549
|
- 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.
|
|
18523
18550
|
- If the bank holds nothing that bears on the goal, say so in one line.`;
|
|
18524
18551
|
}
|
|
18525
|
-
var PAGE_FALLBACK_LEAD = "(Hindsight's synthesis was unavailable this turn; these
|
|
18526
|
-
var PAGE_INJECT_LEAD = "(These
|
|
18552
|
+
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.)";
|
|
18553
|
+
var PAGE_INJECT_LEAD = "(These pages matched the goal by search. Read one with hindsight_read_page(<id>) if it looks relevant.)";
|
|
18527
18554
|
function formatPageFallback(hits, lead = PAGE_FALLBACK_LEAD) {
|
|
18528
18555
|
return `${lead}
|
|
18529
18556
|
` + hits.map((h) => {
|
|
@@ -18554,43 +18581,6 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18554
18581
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18555
18582
|
import { tmpdir as tmpdir4 } from "os";
|
|
18556
18583
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18557
|
-
|
|
18558
|
-
// src/core/transcript-util.ts
|
|
18559
|
-
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;
|
|
18560
|
-
function stripInjectedMemory(s) {
|
|
18561
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
18562
|
-
}
|
|
18563
|
-
var TARGET_KEYS = [
|
|
18564
|
-
"file_path",
|
|
18565
|
-
"path",
|
|
18566
|
-
"notebook_path",
|
|
18567
|
-
"command",
|
|
18568
|
-
"pattern",
|
|
18569
|
-
"query",
|
|
18570
|
-
"url",
|
|
18571
|
-
"name",
|
|
18572
|
-
"id"
|
|
18573
|
-
];
|
|
18574
|
-
var ACTION_TARGET_CAP = 100;
|
|
18575
|
-
function actionLine(tool, input) {
|
|
18576
|
-
let target = "";
|
|
18577
|
-
if (input && typeof input === "object") {
|
|
18578
|
-
const rec = input;
|
|
18579
|
-
for (const k of TARGET_KEYS) {
|
|
18580
|
-
const v = rec[k];
|
|
18581
|
-
if (typeof v === "string" && v.trim()) {
|
|
18582
|
-
target = v.trim().split("\n")[0];
|
|
18583
|
-
break;
|
|
18584
|
-
}
|
|
18585
|
-
}
|
|
18586
|
-
} else if (typeof input === "string") {
|
|
18587
|
-
target = input.trim().split("\n")[0];
|
|
18588
|
-
}
|
|
18589
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
18590
|
-
return target ? `${tool} ${target}` : tool;
|
|
18591
|
-
}
|
|
18592
|
-
|
|
18593
|
-
// src/core/turn-journal.ts
|
|
18594
18584
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
18595
18585
|
|
|
18596
18586
|
// src/core/hook.ts
|
|
@@ -18616,7 +18606,7 @@ function boundRecallQuery(prompt) {
|
|
|
18616
18606
|
async function injectPages(harness, prompt, client, timeoutMs, event, lead) {
|
|
18617
18607
|
const t0 = Date.now();
|
|
18618
18608
|
try {
|
|
18619
|
-
const hits = await client.
|
|
18609
|
+
const hits = await client.searchPages(prompt.slice(0, 500), { timeoutMs });
|
|
18620
18610
|
diag(harness, event, { ms: Date.now() - t0, count: hits.length });
|
|
18621
18611
|
return hits.length ? formatPageFallback(hits, lead) : null;
|
|
18622
18612
|
} catch (e) {
|
|
@@ -18730,14 +18720,10 @@ async function buildHookOutput(args) {
|
|
|
18730
18720
|
pages = parsePageList(await client.listPages());
|
|
18731
18721
|
diag(harness, "pages_ok", { ms: Date.now() - t0, count: pages.length });
|
|
18732
18722
|
} catch (e) {
|
|
18733
|
-
diag(
|
|
18734
|
-
|
|
18735
|
-
|
|
18736
|
-
|
|
18737
|
-
ms: Date.now() - t0,
|
|
18738
|
-
error: describeError(e)
|
|
18739
|
-
}
|
|
18740
|
-
);
|
|
18723
|
+
diag(harness, client.pagesSupported === false ? "pages_unavailable" : "pages_failed", {
|
|
18724
|
+
ms: Date.now() - t0,
|
|
18725
|
+
error: describeError(e)
|
|
18726
|
+
});
|
|
18741
18727
|
}
|
|
18742
18728
|
}
|
|
18743
18729
|
writeSessionCache(cacheFile, {
|
|
@@ -18816,9 +18802,9 @@ var RuntimeCore = class {
|
|
|
18816
18802
|
setTranscriptSource(fetch2) {
|
|
18817
18803
|
this.fetchTranscript = fetch2;
|
|
18818
18804
|
}
|
|
18819
|
-
/** The hindsight_*
|
|
18805
|
+
/** The hindsight_* page + recall tools, bound to this bank, for the harness to register natively. */
|
|
18820
18806
|
toolSpecs() {
|
|
18821
|
-
return
|
|
18807
|
+
return buildPageTools(this.client, this.bankId, {
|
|
18822
18808
|
repoDir: this.projectDir,
|
|
18823
18809
|
harness: this.harness,
|
|
18824
18810
|
pageTrigger: buildPageTrigger(this.cfg),
|
|
@@ -18840,7 +18826,7 @@ var RuntimeCore = class {
|
|
|
18840
18826
|
* git-log seed + codebase survey. Reuses the exact hook-harness logic
|
|
18841
18827
|
* (`buildSessionStartContext`) so opencode seeds identically. Never throws.
|
|
18842
18828
|
*
|
|
18843
|
-
* It deliberately does NOT keep that call's
|
|
18829
|
+
* It deliberately does NOT keep that call's pages preamble. This runs once per PROCESS and
|
|
18844
18830
|
* these hosts outlive every session, so a roster captured here is stale for every session but
|
|
18845
18831
|
* the first — `onPrompt` builds its own from the session's live page list (#4607).
|
|
18846
18832
|
*/
|
|
@@ -18871,10 +18857,11 @@ var RuntimeCore = class {
|
|
|
18871
18857
|
* intentionally replaces the old in-memory reflect/page state, keeping lifecycle behavior
|
|
18872
18858
|
* identical across hosts while this adapter retains only delivery-specific state.
|
|
18873
18859
|
*/
|
|
18874
|
-
async onPrompt(sessionId,
|
|
18860
|
+
async onPrompt(sessionId, rawPrompt) {
|
|
18875
18861
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18876
18862
|
if (!sessionId) return;
|
|
18877
|
-
|
|
18863
|
+
const prompt = stripInjectedMemory(rawPrompt).trim();
|
|
18864
|
+
if (!prompt) {
|
|
18878
18865
|
this.injection.delete(sessionId);
|
|
18879
18866
|
return;
|
|
18880
18867
|
}
|
|
@@ -18895,7 +18882,7 @@ var RuntimeCore = class {
|
|
|
18895
18882
|
const blocks = [];
|
|
18896
18883
|
if (turns === 1) {
|
|
18897
18884
|
blocks.push(
|
|
18898
|
-
|
|
18885
|
+
buildPagesPreamble(output.pages, {
|
|
18899
18886
|
reflectOnNewGoals: this.cfg.autoInject !== "reflect",
|
|
18900
18887
|
extra: this.cfg.toolGuideExtra
|
|
18901
18888
|
})
|