@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/opencode2.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";
|
|
@@ -17446,97 +17447,88 @@ function surveyAttempts(file3, sha) {
|
|
|
17446
17447
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17447
17448
|
try {
|
|
17448
17449
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17449
|
-
const resolveBin = opts.resolveBin ?? ((
|
|
17450
|
+
const resolveBin = opts.resolveBin ?? ((bin2) => binOnPath(bin2, { exts: [".exe"] }));
|
|
17450
17451
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17451
|
-
const
|
|
17452
|
-
const
|
|
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
|
-
|
|
17496
|
-
|
|
17497
|
-
|
|
17498
|
-
|
|
17499
|
-
|
|
17500
|
-
|
|
17501
|
-
|
|
17502
|
-
|
|
17503
|
-
|
|
17504
|
-
|
|
17505
|
-
|
|
17506
|
-
detached: true,
|
|
17507
|
-
stdio: "ignore",
|
|
17508
|
-
windowsHide: true,
|
|
17509
|
-
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17510
|
-
});
|
|
17511
|
-
let spawned = false;
|
|
17512
|
-
child.on("error", (e) => {
|
|
17513
|
-
if (spawned) return;
|
|
17514
|
-
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17515
|
-
releaseLease(lease);
|
|
17516
|
-
resolve4(false);
|
|
17517
|
-
});
|
|
17518
|
-
child.once("spawn", () => {
|
|
17519
|
-
spawned = true;
|
|
17520
|
-
child.unref();
|
|
17521
|
-
if (opts.sha) {
|
|
17522
|
-
try {
|
|
17523
|
-
writeFileSync3(
|
|
17524
|
-
attemptsFile,
|
|
17525
|
-
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17526
|
-
{ mode: 384 }
|
|
17527
|
-
);
|
|
17528
|
-
} catch {
|
|
17529
|
-
}
|
|
17530
|
-
}
|
|
17531
|
-
resolve4(true);
|
|
17532
|
-
});
|
|
17533
|
-
} catch (e) {
|
|
17452
|
+
const harness = opts.harness ?? "claude-code";
|
|
17453
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17454
|
+
if (!name) {
|
|
17455
|
+
log.info("survey", `${harness}: no headless survey for this agent, skipping the survey`);
|
|
17456
|
+
return false;
|
|
17457
|
+
}
|
|
17458
|
+
const bin = resolveBin(name);
|
|
17459
|
+
if (!bin) {
|
|
17460
|
+
log.info("survey", `${harness}: ${name} not found, skipping the survey`);
|
|
17461
|
+
return false;
|
|
17462
|
+
}
|
|
17463
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17464
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, skipping the survey`);
|
|
17465
|
+
return false;
|
|
17466
|
+
}
|
|
17467
|
+
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17468
|
+
model: opts.model,
|
|
17469
|
+
budgetUsd: opts.budgetUsd,
|
|
17470
|
+
mcpServerPath
|
|
17471
|
+
});
|
|
17472
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17473
|
+
if (cfg.disabled) return false;
|
|
17474
|
+
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17475
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17476
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17477
|
+
if (!lease) return false;
|
|
17478
|
+
const attemptsFile = join11(
|
|
17479
|
+
leaseDir,
|
|
17480
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17481
|
+
);
|
|
17482
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17483
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17484
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17485
|
+
releaseLease(lease);
|
|
17486
|
+
return false;
|
|
17487
|
+
}
|
|
17488
|
+
const spec = {
|
|
17489
|
+
lease,
|
|
17490
|
+
bin: plan.bin,
|
|
17491
|
+
args: plan.args,
|
|
17492
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17493
|
+
};
|
|
17494
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17495
|
+
return await new Promise((resolve4) => {
|
|
17496
|
+
try {
|
|
17497
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
17498
|
+
cwd: repoDir,
|
|
17499
|
+
detached: true,
|
|
17500
|
+
stdio: "ignore",
|
|
17501
|
+
windowsHide: true,
|
|
17502
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17503
|
+
});
|
|
17504
|
+
let spawned = false;
|
|
17505
|
+
child.on("error", (e) => {
|
|
17506
|
+
if (spawned) return;
|
|
17534
17507
|
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17535
17508
|
releaseLease(lease);
|
|
17536
17509
|
resolve4(false);
|
|
17537
|
-
}
|
|
17538
|
-
|
|
17539
|
-
|
|
17510
|
+
});
|
|
17511
|
+
child.once("spawn", () => {
|
|
17512
|
+
spawned = true;
|
|
17513
|
+
child.unref();
|
|
17514
|
+
if (opts.sha) {
|
|
17515
|
+
try {
|
|
17516
|
+
writeFileSync3(
|
|
17517
|
+
attemptsFile,
|
|
17518
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17519
|
+
{ mode: 384 }
|
|
17520
|
+
);
|
|
17521
|
+
} catch {
|
|
17522
|
+
}
|
|
17523
|
+
}
|
|
17524
|
+
resolve4(true);
|
|
17525
|
+
});
|
|
17526
|
+
} catch (e) {
|
|
17527
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17528
|
+
releaseLease(lease);
|
|
17529
|
+
resolve4(false);
|
|
17530
|
+
}
|
|
17531
|
+
});
|
|
17540
17532
|
} catch {
|
|
17541
17533
|
}
|
|
17542
17534
|
return false;
|
|
@@ -17600,11 +17592,11 @@ async function syncStatus(client, bank, repoDir) {
|
|
|
17600
17592
|
activeOps,
|
|
17601
17593
|
// Older Hindsight servers have no page surface. They are still fully usable for the
|
|
17602
17594
|
// legacy bank/retain pipeline, so page absence must not make syncStatus permanently false.
|
|
17603
|
-
synced: gitlogPresent && (client.
|
|
17595
|
+
synced: gitlogPresent && (client.pagesSupported === false || pages.length > 0) && (activeOps ?? 0) === 0
|
|
17604
17596
|
};
|
|
17605
17597
|
}
|
|
17606
17598
|
|
|
17607
|
-
// src/core/
|
|
17599
|
+
// src/core/page-tools.ts
|
|
17608
17600
|
var READ_ONLY_ANNOTATIONS = {
|
|
17609
17601
|
readOnlyHint: true,
|
|
17610
17602
|
destructiveHint: false,
|
|
@@ -17634,13 +17626,13 @@ function guarded(fn) {
|
|
|
17634
17626
|
}
|
|
17635
17627
|
};
|
|
17636
17628
|
}
|
|
17637
|
-
function
|
|
17629
|
+
function buildPageTools(client, bankId, opts = {}) {
|
|
17638
17630
|
const extra = opts.toolGuideExtra?.trim();
|
|
17639
17631
|
const crediting = extra ? `${CREDIT_REMINDER} ${extra}` : CREDIT_REMINDER;
|
|
17640
17632
|
return [
|
|
17641
17633
|
{
|
|
17642
17634
|
name: "hindsight_sync_status",
|
|
17643
|
-
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,
|
|
17635
|
+
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.",
|
|
17644
17636
|
inputSchema: {},
|
|
17645
17637
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17646
17638
|
handler: async () => {
|
|
@@ -17695,13 +17687,13 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17695
17687
|
}
|
|
17696
17688
|
},
|
|
17697
17689
|
{
|
|
17698
|
-
name: "
|
|
17699
|
-
description: "Search this repository's Hindsight
|
|
17690
|
+
name: "hindsight_search_pages",
|
|
17691
|
+
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,
|
|
17700
17692
|
inputSchema: { query: external_exports.string().describe("what to look for") },
|
|
17701
17693
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17702
17694
|
handler: async (args) => {
|
|
17703
17695
|
try {
|
|
17704
|
-
const hits = await client.
|
|
17696
|
+
const hits = await client.searchPages(args.query);
|
|
17705
17697
|
return ok({
|
|
17706
17698
|
pages: hits.map((h) => ({
|
|
17707
17699
|
page: h.name,
|
|
@@ -17719,22 +17711,22 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17719
17711
|
}
|
|
17720
17712
|
},
|
|
17721
17713
|
{
|
|
17722
|
-
name: "
|
|
17723
|
-
description: "List this repository's Hindsight
|
|
17714
|
+
name: "hindsight_list_pages",
|
|
17715
|
+
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.",
|
|
17724
17716
|
inputSchema: {},
|
|
17725
17717
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17726
17718
|
handler: guarded(async () => client.listPages())
|
|
17727
17719
|
},
|
|
17728
17720
|
{
|
|
17729
|
-
name: "
|
|
17730
|
-
description: "Read the full content of one
|
|
17721
|
+
name: "hindsight_read_page",
|
|
17722
|
+
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.",
|
|
17731
17723
|
inputSchema: { page_id: external_exports.string() },
|
|
17732
17724
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17733
17725
|
handler: guarded(async ({ page_id }) => client.getPage(page_id))
|
|
17734
17726
|
},
|
|
17735
17727
|
{
|
|
17736
17728
|
name: "hindsight_reflect",
|
|
17737
|
-
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
|
|
17729
|
+
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>".`,
|
|
17738
17730
|
inputSchema: { query: external_exports.string().describe("the question to reason over memory about") },
|
|
17739
17731
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17740
17732
|
handler: guarded(
|
|
@@ -17746,7 +17738,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17746
17738
|
},
|
|
17747
17739
|
{
|
|
17748
17740
|
name: "hindsight_capture_initiative",
|
|
17749
|
-
description: "Record a new feature or initiative as a tracked
|
|
17741
|
+
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.",
|
|
17750
17742
|
inputSchema: {
|
|
17751
17743
|
title: external_exports.string(),
|
|
17752
17744
|
summary: external_exports.string(),
|
|
@@ -18498,11 +18490,11 @@ async function buildSessionStartContext(args) {
|
|
|
18498
18490
|
try {
|
|
18499
18491
|
pages = parsePageList(await client.listPages());
|
|
18500
18492
|
} catch {
|
|
18501
|
-
if (client.
|
|
18502
|
-
diag(harness, "
|
|
18493
|
+
if (client.pagesSupported === false) {
|
|
18494
|
+
diag(harness, "pages_unavailable", { bank: bankId });
|
|
18503
18495
|
}
|
|
18504
18496
|
}
|
|
18505
|
-
const additionalContext =
|
|
18497
|
+
const additionalContext = buildPagesPreamble(pages, {
|
|
18506
18498
|
reflectOnNewGoals: cfg.autoInject !== "reflect",
|
|
18507
18499
|
extra: cfg.toolGuideExtra
|
|
18508
18500
|
});
|
|
@@ -18532,6 +18524,41 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
|
18532
18524
|
// src/core/hook.ts
|
|
18533
18525
|
import { existsSync as existsSync8 } from "fs";
|
|
18534
18526
|
|
|
18527
|
+
// src/core/transcript-util.ts
|
|
18528
|
+
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;
|
|
18529
|
+
function stripInjectedMemory(s) {
|
|
18530
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
18531
|
+
}
|
|
18532
|
+
var TARGET_KEYS = [
|
|
18533
|
+
"file_path",
|
|
18534
|
+
"path",
|
|
18535
|
+
"notebook_path",
|
|
18536
|
+
"command",
|
|
18537
|
+
"pattern",
|
|
18538
|
+
"query",
|
|
18539
|
+
"url",
|
|
18540
|
+
"name",
|
|
18541
|
+
"id"
|
|
18542
|
+
];
|
|
18543
|
+
var ACTION_TARGET_CAP = 100;
|
|
18544
|
+
function actionLine(tool2, input) {
|
|
18545
|
+
let target = "";
|
|
18546
|
+
if (input && typeof input === "object") {
|
|
18547
|
+
const rec = input;
|
|
18548
|
+
for (const k of TARGET_KEYS) {
|
|
18549
|
+
const v = rec[k];
|
|
18550
|
+
if (typeof v === "string" && v.trim()) {
|
|
18551
|
+
target = v.trim().split("\n")[0];
|
|
18552
|
+
break;
|
|
18553
|
+
}
|
|
18554
|
+
}
|
|
18555
|
+
} else if (typeof input === "string") {
|
|
18556
|
+
target = input.trim().split("\n")[0];
|
|
18557
|
+
}
|
|
18558
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
18559
|
+
return target ? `${tool2} ${target}` : tool2;
|
|
18560
|
+
}
|
|
18561
|
+
|
|
18535
18562
|
// src/core/inject.ts
|
|
18536
18563
|
function buildReflectQuery(prompt) {
|
|
18537
18564
|
return `A developer is starting a coding session in this repository with this goal:
|
|
@@ -18548,8 +18575,8 @@ Report what this bank's history genuinely bears on that goal. Rendering rules, s
|
|
|
18548
18575
|
- 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.
|
|
18549
18576
|
- If the bank holds nothing that bears on the goal, say so in one line.`;
|
|
18550
18577
|
}
|
|
18551
|
-
var PAGE_FALLBACK_LEAD = "(Hindsight's synthesis was unavailable this turn; these
|
|
18552
|
-
var PAGE_INJECT_LEAD = "(These
|
|
18578
|
+
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.)";
|
|
18579
|
+
var PAGE_INJECT_LEAD = "(These pages matched the goal by search. Read one with hindsight_read_page(<id>) if it looks relevant.)";
|
|
18553
18580
|
function formatPageFallback(hits, lead = PAGE_FALLBACK_LEAD) {
|
|
18554
18581
|
return `${lead}
|
|
18555
18582
|
` + hits.map((h) => {
|
|
@@ -18580,43 +18607,6 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18580
18607
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18581
18608
|
import { tmpdir as tmpdir4 } from "os";
|
|
18582
18609
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18583
|
-
|
|
18584
|
-
// src/core/transcript-util.ts
|
|
18585
|
-
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;
|
|
18586
|
-
function stripInjectedMemory(s) {
|
|
18587
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
18588
|
-
}
|
|
18589
|
-
var TARGET_KEYS = [
|
|
18590
|
-
"file_path",
|
|
18591
|
-
"path",
|
|
18592
|
-
"notebook_path",
|
|
18593
|
-
"command",
|
|
18594
|
-
"pattern",
|
|
18595
|
-
"query",
|
|
18596
|
-
"url",
|
|
18597
|
-
"name",
|
|
18598
|
-
"id"
|
|
18599
|
-
];
|
|
18600
|
-
var ACTION_TARGET_CAP = 100;
|
|
18601
|
-
function actionLine(tool2, input) {
|
|
18602
|
-
let target = "";
|
|
18603
|
-
if (input && typeof input === "object") {
|
|
18604
|
-
const rec = input;
|
|
18605
|
-
for (const k of TARGET_KEYS) {
|
|
18606
|
-
const v = rec[k];
|
|
18607
|
-
if (typeof v === "string" && v.trim()) {
|
|
18608
|
-
target = v.trim().split("\n")[0];
|
|
18609
|
-
break;
|
|
18610
|
-
}
|
|
18611
|
-
}
|
|
18612
|
-
} else if (typeof input === "string") {
|
|
18613
|
-
target = input.trim().split("\n")[0];
|
|
18614
|
-
}
|
|
18615
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
18616
|
-
return target ? `${tool2} ${target}` : tool2;
|
|
18617
|
-
}
|
|
18618
|
-
|
|
18619
|
-
// src/core/turn-journal.ts
|
|
18620
18610
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
18621
18611
|
|
|
18622
18612
|
// src/core/hook.ts
|
|
@@ -18642,7 +18632,7 @@ function boundRecallQuery(prompt) {
|
|
|
18642
18632
|
async function injectPages(harness, prompt, client, timeoutMs, event, lead) {
|
|
18643
18633
|
const t0 = Date.now();
|
|
18644
18634
|
try {
|
|
18645
|
-
const hits = await client.
|
|
18635
|
+
const hits = await client.searchPages(prompt.slice(0, 500), { timeoutMs });
|
|
18646
18636
|
diag(harness, event, { ms: Date.now() - t0, count: hits.length });
|
|
18647
18637
|
return hits.length ? formatPageFallback(hits, lead) : null;
|
|
18648
18638
|
} catch (e) {
|
|
@@ -18756,14 +18746,10 @@ async function buildHookOutput(args) {
|
|
|
18756
18746
|
pages = parsePageList(await client.listPages());
|
|
18757
18747
|
diag(harness, "pages_ok", { ms: Date.now() - t0, count: pages.length });
|
|
18758
18748
|
} catch (e) {
|
|
18759
|
-
diag(
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
ms: Date.now() - t0,
|
|
18764
|
-
error: describeError(e)
|
|
18765
|
-
}
|
|
18766
|
-
);
|
|
18749
|
+
diag(harness, client.pagesSupported === false ? "pages_unavailable" : "pages_failed", {
|
|
18750
|
+
ms: Date.now() - t0,
|
|
18751
|
+
error: describeError(e)
|
|
18752
|
+
});
|
|
18767
18753
|
}
|
|
18768
18754
|
}
|
|
18769
18755
|
writeSessionCache(cacheFile, {
|
|
@@ -18842,9 +18828,9 @@ var RuntimeCore = class {
|
|
|
18842
18828
|
setTranscriptSource(fetch2) {
|
|
18843
18829
|
this.fetchTranscript = fetch2;
|
|
18844
18830
|
}
|
|
18845
|
-
/** The hindsight_*
|
|
18831
|
+
/** The hindsight_* page + recall tools, bound to this bank, for the harness to register natively. */
|
|
18846
18832
|
toolSpecs() {
|
|
18847
|
-
return
|
|
18833
|
+
return buildPageTools(this.client, this.bankId, {
|
|
18848
18834
|
repoDir: this.projectDir,
|
|
18849
18835
|
harness: this.harness,
|
|
18850
18836
|
pageTrigger: buildPageTrigger(this.cfg),
|
|
@@ -18866,7 +18852,7 @@ var RuntimeCore = class {
|
|
|
18866
18852
|
* git-log seed + codebase survey. Reuses the exact hook-harness logic
|
|
18867
18853
|
* (`buildSessionStartContext`) so opencode seeds identically. Never throws.
|
|
18868
18854
|
*
|
|
18869
|
-
* It deliberately does NOT keep that call's
|
|
18855
|
+
* It deliberately does NOT keep that call's pages preamble. This runs once per PROCESS and
|
|
18870
18856
|
* these hosts outlive every session, so a roster captured here is stale for every session but
|
|
18871
18857
|
* the first — `onPrompt` builds its own from the session's live page list (#4607).
|
|
18872
18858
|
*/
|
|
@@ -18897,10 +18883,11 @@ var RuntimeCore = class {
|
|
|
18897
18883
|
* intentionally replaces the old in-memory reflect/page state, keeping lifecycle behavior
|
|
18898
18884
|
* identical across hosts while this adapter retains only delivery-specific state.
|
|
18899
18885
|
*/
|
|
18900
|
-
async onPrompt(sessionId,
|
|
18886
|
+
async onPrompt(sessionId, rawPrompt) {
|
|
18901
18887
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18902
18888
|
if (!sessionId) return;
|
|
18903
|
-
|
|
18889
|
+
const prompt = stripInjectedMemory(rawPrompt).trim();
|
|
18890
|
+
if (!prompt) {
|
|
18904
18891
|
this.injection.delete(sessionId);
|
|
18905
18892
|
return;
|
|
18906
18893
|
}
|
|
@@ -18921,7 +18908,7 @@ var RuntimeCore = class {
|
|
|
18921
18908
|
const blocks = [];
|
|
18922
18909
|
if (turns === 1) {
|
|
18923
18910
|
blocks.push(
|
|
18924
|
-
|
|
18911
|
+
buildPagesPreamble(output.pages, {
|
|
18925
18912
|
reflectOnNewGoals: this.cfg.autoInject !== "reflect",
|
|
18926
18913
|
extra: this.cfg.toolGuideExtra
|
|
18927
18914
|
})
|
|
@@ -31596,7 +31583,7 @@ function createRuntime(core) {
|
|
|
31596
31583
|
...surveyAgentHook,
|
|
31597
31584
|
tool: tools,
|
|
31598
31585
|
// Each user turn: recall on the prompt, then add this turn's injection (recalled memories +
|
|
31599
|
-
// attribution/user-feedback framing, plus the
|
|
31586
|
+
// attribution/user-feedback framing, plus the pages preamble on turn 1 and the roster
|
|
31600
31587
|
// refresh on cadence) to the user message as a synthetic text part. The host saves the parts
|
|
31601
31588
|
// this hook leaves behind, so the block stays in the turn it was made for and every later
|
|
31602
31589
|
// request repeats it byte for byte. It used to be pushed into the system prompt through
|