@vectorize-io/hindsight-coding-agents 0.7.0 → 0.8.0
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 +137 -13
- package/dist/antigravity-hook.js +711 -55
- package/dist/antigravity-statusline.js +68 -7
- package/dist/antigravity-stop-hook.js +771 -57
- package/dist/claude-hook.js +711 -55
- package/dist/claude-sessionstart-hook.js +789 -68
- package/dist/claude-stop-hook.js +771 -57
- package/dist/cline.js +295 -75
- package/dist/codex-hook.js +711 -55
- package/dist/codex-sessionstart-hook.js +789 -68
- package/dist/codex-stop-hook.js +771 -57
- package/dist/copilot-hook.js +711 -55
- package/dist/copilot-sessionstart-hook.js +789 -68
- package/dist/copilot-stop-hook.js +771 -57
- package/dist/cursor-hook.js +711 -55
- package/dist/cursor-sessionstart-hook.js +789 -68
- package/dist/cursor-stop-hook.js +771 -57
- package/dist/daemon-start.js +38 -1
- package/dist/dcode-hook.js +711 -55
- package/dist/dcode-sessionstart-hook.js +789 -68
- package/dist/dcode-stop-hook.js +771 -57
- package/dist/deepen.js +236 -61
- package/dist/devin-hook.js +711 -55
- package/dist/devin-sessionstart-hook.js +789 -68
- package/dist/devin-stop-hook.js +771 -57
- package/dist/droid-hook.js +711 -55
- package/dist/droid-sessionstart-hook.js +789 -68
- package/dist/droid-stop-hook.js +771 -57
- package/dist/dsh.js +296 -76
- package/dist/grok-hook.js +711 -55
- package/dist/grok-sessionstart-hook.js +789 -68
- package/dist/grok-stop-hook.js +771 -57
- package/dist/hindsight-seed.js +41 -4
- package/dist/index.js +295 -75
- package/dist/installer.js +1148 -303
- package/dist/kilo.js +295 -75
- package/dist/kimi-hook.js +3909 -0
- package/dist/kimi-sessionstart-hook.js +4650 -0
- package/dist/kimi-stop-hook.js +4218 -0
- package/dist/mcp-server.js +162 -33
- package/dist/opencode2.js +298 -76
- package/dist/pi.js +299 -75
- package/dist/prime-agent.js +299 -75
- package/dist/qwen-hook.js +711 -55
- package/dist/qwen-sessionstart-hook.js +789 -68
- package/dist/qwen-stop-hook.js +771 -57
- package/dist/status.js +132 -14
- package/dist/traecode-hook.js +3909 -0
- package/dist/traecode-sessionstart-hook.js +4650 -0
- package/dist/traecode-stop-hook.js +4218 -0
- package/dist/zcode-hook.js +711 -55
- package/dist/zcode-sessionstart-hook.js +789 -68
- package/dist/zcode-stop-hook.js +771 -57
- package/package.json +15 -11
- package/plugin.json +1 -1
- package/skill/SKILL.md +70 -11
package/dist/dsh.js
CHANGED
|
@@ -312,13 +312,13 @@ function isWithin(directory, configured) {
|
|
|
312
312
|
function mapLookup(map2, directory) {
|
|
313
313
|
const cwd = normalize(directory);
|
|
314
314
|
let best;
|
|
315
|
-
for (const [dir,
|
|
315
|
+
for (const [dir, value] of Object.entries(map2)) {
|
|
316
316
|
const p = configuredDir(dir);
|
|
317
317
|
if (isWithin(cwd, p)) {
|
|
318
|
-
if (!best || p.length > best.len) best = { len: p.length,
|
|
318
|
+
if (!best || p.length > best.len) best = { len: p.length, value };
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
return best?.
|
|
321
|
+
return best?.value;
|
|
322
322
|
}
|
|
323
323
|
function lookupDirectories(config2, directory, sessionRoot = "") {
|
|
324
324
|
const directories = [normalize(directory)];
|
|
@@ -342,6 +342,10 @@ function isOptedIn(config2, directory) {
|
|
|
342
342
|
const pathMap = config2.mapPathToBank;
|
|
343
343
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
344
344
|
}
|
|
345
|
+
function pathSection(config2, paths, directory) {
|
|
346
|
+
if (!directory || !paths) return void 0;
|
|
347
|
+
return lookupDirectories(config2, directory).map((candidate) => mapLookup(paths, candidate)).find((section) => section !== void 0);
|
|
348
|
+
}
|
|
345
349
|
function mappedBank(config2, directory, sessionRoot) {
|
|
346
350
|
const pathMap = config2.mapPathToBank;
|
|
347
351
|
if (!directory || !pathMap) return void 0;
|
|
@@ -589,12 +593,17 @@ var CODING_BANK_TEMPLATE = {
|
|
|
589
593
|
}
|
|
590
594
|
};
|
|
591
595
|
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
596
|
+
var PLUGIN_GOVERNED_BANK_FIELDS = [
|
|
597
|
+
"retain_strategies",
|
|
598
|
+
"entity_labels",
|
|
599
|
+
"retain_extraction_mode"
|
|
600
|
+
];
|
|
592
601
|
function isSet(v) {
|
|
593
602
|
if (v === null || v === void 0) return false;
|
|
594
603
|
if (typeof v === "string") return v.trim() !== "";
|
|
595
604
|
return true;
|
|
596
605
|
}
|
|
597
|
-
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
606
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, defaults = {}) {
|
|
598
607
|
const current2 = overrides ?? {};
|
|
599
608
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
600
609
|
const bank = {};
|
|
@@ -623,6 +632,10 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
|
623
632
|
const [knowledgeGroup] = template.entity_labels;
|
|
624
633
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
625
634
|
bank.entity_labels = [...labels, knowledgeGroup];
|
|
635
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
636
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key) || !isSet(value) || isSet(current2[key])) continue;
|
|
637
|
+
bank[key] = value;
|
|
638
|
+
}
|
|
626
639
|
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
627
640
|
}
|
|
628
641
|
|
|
@@ -745,6 +758,18 @@ var DEFAULT_RECALL_OPTIONS = {
|
|
|
745
758
|
var POLL_CYCLE_MS = 5e3;
|
|
746
759
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
747
760
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
761
|
+
function shapePage(page) {
|
|
762
|
+
const p = page ?? {};
|
|
763
|
+
const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
|
|
764
|
+
return {
|
|
765
|
+
id: p.id,
|
|
766
|
+
name: p.name,
|
|
767
|
+
...p.description ? { description: p.description } : {},
|
|
768
|
+
...Array.isArray(p.tags) && p.tags.length ? { tags: p.tags } : {},
|
|
769
|
+
...p.timestamp ? { last_updated_at: p.timestamp } : {},
|
|
770
|
+
body
|
|
771
|
+
};
|
|
772
|
+
}
|
|
748
773
|
var HindsightClient = class {
|
|
749
774
|
apiUrl;
|
|
750
775
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -782,7 +807,10 @@ var HindsightClient = class {
|
|
|
782
807
|
return this.token;
|
|
783
808
|
}
|
|
784
809
|
headers() {
|
|
785
|
-
const h = {
|
|
810
|
+
const h = {
|
|
811
|
+
"Content-Type": "application/json",
|
|
812
|
+
"Accept-Encoding": "identity"
|
|
813
|
+
};
|
|
786
814
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
787
815
|
return h;
|
|
788
816
|
}
|
|
@@ -890,6 +918,23 @@ var HindsightClient = class {
|
|
|
890
918
|
return false;
|
|
891
919
|
}
|
|
892
920
|
}
|
|
921
|
+
/**
|
|
922
|
+
* Whether a session write-back may use `update_mode="append"`: the server must dedupe by
|
|
923
|
+
* `operation_id` AND the bank must keep document text, or the server rejects the append in the
|
|
924
|
+
* background (#4613). Only an explicit `store_document_text: false` answers "no" — an unreachable
|
|
925
|
+
* or unparseable config assumes the default (stored), so a flaky probe never downgrades appends.
|
|
926
|
+
*/
|
|
927
|
+
async supportsAppendRetain() {
|
|
928
|
+
if (!await this.supportsIdempotentRetain()) return false;
|
|
929
|
+
try {
|
|
930
|
+
const r = await this.req("GET", this.bankUrl("/config"));
|
|
931
|
+
if (!r.ok) return true;
|
|
932
|
+
const j = await r.json();
|
|
933
|
+
return j.config?.store_document_text !== false;
|
|
934
|
+
} catch {
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
893
938
|
/**
|
|
894
939
|
* Every document_id currently in the bank under a strategy tag (e.g. `source:git`), paginated into a
|
|
895
940
|
* Set. Powers the incremental git-sync's "what's already ingested?" check — since git commits are stored
|
|
@@ -915,6 +960,24 @@ var HindsightClient = class {
|
|
|
915
960
|
}
|
|
916
961
|
return ids;
|
|
917
962
|
}
|
|
963
|
+
/**
|
|
964
|
+
* The tags on one document, or undefined when the bank holds none with that id. Read from the
|
|
965
|
+
* document LISTING narrowed by `q` (a substring match on the id, so the exact id is picked out of
|
|
966
|
+
* the page) rather than GET /documents/{id}, which also sends the document's full text: the
|
|
967
|
+
* caller, the git-log freshness check on SessionStart, reads a ~100k-character document for one tag.
|
|
968
|
+
*/
|
|
969
|
+
async documentTags(documentId) {
|
|
970
|
+
const limit = 100;
|
|
971
|
+
for (let offset = 0; ; offset += limit) {
|
|
972
|
+
const q = `?q=${encodeURIComponent(documentId)}&limit=${limit}&offset=${offset}`;
|
|
973
|
+
const r = await this.req("GET", this.bankUrl(`/documents${q}`));
|
|
974
|
+
const j = await r.json();
|
|
975
|
+
const items = j.items ?? [];
|
|
976
|
+
const hit = items.find((it) => it.id === documentId);
|
|
977
|
+
if (hit) return hit.tags ?? [];
|
|
978
|
+
if (items.length < limit || offset + limit >= (j.total ?? 0)) return void 0;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
918
981
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
919
982
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
920
983
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
@@ -936,7 +999,8 @@ var HindsightClient = class {
|
|
|
936
999
|
} else {
|
|
937
1000
|
const manifest = codingBankManifest(
|
|
938
1001
|
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
939
|
-
opts.extractionMode
|
|
1002
|
+
opts.extractionMode,
|
|
1003
|
+
opts.defaults
|
|
940
1004
|
);
|
|
941
1005
|
if (!manifest) {
|
|
942
1006
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
@@ -1142,8 +1206,8 @@ var HindsightClient = class {
|
|
|
1142
1206
|
return { items };
|
|
1143
1207
|
}
|
|
1144
1208
|
/**
|
|
1145
|
-
* Read one knowledge page's synthesized content by knowledge-base id,
|
|
1146
|
-
*
|
|
1209
|
+
* Read one knowledge page's synthesized content by knowledge-base id, shaped by `shapePage` so
|
|
1210
|
+
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1147
1211
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1148
1212
|
* token cap.
|
|
1149
1213
|
*/
|
|
@@ -1154,7 +1218,7 @@ var HindsightClient = class {
|
|
|
1154
1218
|
this.bankUrl(`/knowledge-base/pages/${encodeURIComponent(pageId)}`)
|
|
1155
1219
|
);
|
|
1156
1220
|
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1157
|
-
return await r.json();
|
|
1221
|
+
return shapePage(await r.json());
|
|
1158
1222
|
}
|
|
1159
1223
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1160
1224
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
@@ -1175,6 +1239,7 @@ var HindsightClient = class {
|
|
|
1175
1239
|
return (j.results ?? []).map((x) => ({
|
|
1176
1240
|
id: x.id,
|
|
1177
1241
|
name: x.name,
|
|
1242
|
+
...x.source_query ? { source_query: x.source_query } : {},
|
|
1178
1243
|
snippet: x.snippet ?? "",
|
|
1179
1244
|
score: x.score ?? 0
|
|
1180
1245
|
}));
|
|
@@ -1445,6 +1510,7 @@ function resolveCustomPages(raw) {
|
|
|
1445
1510
|
}
|
|
1446
1511
|
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1447
1512
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1513
|
+
var DEFAULT_INJECT_TIMEOUT_MS = 7e3;
|
|
1448
1514
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1449
1515
|
function resolveReflectBudget(raw) {
|
|
1450
1516
|
const value = raw.reflectBudget;
|
|
@@ -1471,6 +1537,22 @@ function resolveObservationScopes(raw) {
|
|
|
1471
1537
|
}
|
|
1472
1538
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1473
1539
|
}
|
|
1540
|
+
function resolveDefaultBankConfig(raw) {
|
|
1541
|
+
const value = raw;
|
|
1542
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1543
|
+
const out = {};
|
|
1544
|
+
for (const [key, v] of Object.entries(value)) {
|
|
1545
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key)) {
|
|
1546
|
+
log.warn(
|
|
1547
|
+
"config",
|
|
1548
|
+
`ignoring defaultBankConfig.${key} \u2014 the plugin manages this field itself` + (key === "retain_extraction_mode" ? " (set retainExtractionMode instead)" : "")
|
|
1549
|
+
);
|
|
1550
|
+
continue;
|
|
1551
|
+
}
|
|
1552
|
+
out[key] = v;
|
|
1553
|
+
}
|
|
1554
|
+
return out;
|
|
1555
|
+
}
|
|
1474
1556
|
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1475
1557
|
function resolveAutoInject(raw) {
|
|
1476
1558
|
if (raw.autoReflect !== void 0) {
|
|
@@ -1510,18 +1592,21 @@ function resolveConfig(raw = {}) {
|
|
|
1510
1592
|
// write sessions back by default, every harness
|
|
1511
1593
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1512
1594
|
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1595
|
+
defaultBankConfig: resolveDefaultBankConfig(raw.defaultBankConfig),
|
|
1513
1596
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1514
1597
|
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1515
1598
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1516
1599
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1517
1600
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1518
1601
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1602
|
+
injectTimeoutMs: raw.injectTimeoutMs || DEFAULT_INJECT_TIMEOUT_MS,
|
|
1519
1603
|
reflectBudget: resolveReflectBudget(raw),
|
|
1520
1604
|
autoInject: resolveAutoInject(raw),
|
|
1521
1605
|
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1522
1606
|
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1523
1607
|
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1524
1608
|
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1609
|
+
toolGuideExtra: typeof raw.toolGuideExtra === "string" && raw.toolGuideExtra.trim() ? raw.toolGuideExtra : void 0,
|
|
1525
1610
|
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1526
1611
|
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1527
1612
|
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
@@ -1541,11 +1626,15 @@ function resolveConfig(raw = {}) {
|
|
|
1541
1626
|
// Hostile input is a config typo, not an attack: keep only string entries so a stray number or
|
|
1542
1627
|
// nested object cannot reach the API as a tag and fail the whole retain.
|
|
1543
1628
|
retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
|
|
1629
|
+
// Undefined, not "", when unset or blank: the retain call distinguishes "not configured" (use
|
|
1630
|
+
// the built-in default) from a configured value, and an empty context would strip the default.
|
|
1631
|
+
retainContext: typeof raw.retainContext === "string" && raw.retainContext.trim() !== "" ? raw.retainContext : void 0,
|
|
1544
1632
|
retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
|
|
1545
1633
|
Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
|
|
1546
1634
|
) : {},
|
|
1547
1635
|
observationScopes: resolveObservationScopes(raw.observationScopes),
|
|
1548
1636
|
banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
|
|
1637
|
+
paths: raw.paths && typeof raw.paths === "object" ? raw.paths : {},
|
|
1549
1638
|
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
|
|
1550
1639
|
autoUpdate: raw.autoUpdate ?? true
|
|
1551
1640
|
};
|
|
@@ -1562,7 +1651,12 @@ function readRaw(path) {
|
|
|
1562
1651
|
}
|
|
1563
1652
|
function mergeRaw(a, b) {
|
|
1564
1653
|
const { harnesses: _drop, ...flat } = b;
|
|
1565
|
-
return {
|
|
1654
|
+
return {
|
|
1655
|
+
...a,
|
|
1656
|
+
...flat,
|
|
1657
|
+
banks: { ...a.banks ?? {}, ...b.banks ?? {} },
|
|
1658
|
+
paths: { ...a.paths ?? {}, ...b.paths ?? {} }
|
|
1659
|
+
};
|
|
1566
1660
|
}
|
|
1567
1661
|
function applyLayer(raw, layer, harness) {
|
|
1568
1662
|
let out = mergeRaw(raw, layer);
|
|
@@ -1593,9 +1687,11 @@ var ENV_KEYS = {
|
|
|
1593
1687
|
maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
|
|
1594
1688
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1595
1689
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1690
|
+
injectTimeoutMs: "HINDSIGHT_INJECT_TIMEOUT_MS",
|
|
1596
1691
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1597
1692
|
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1598
1693
|
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1694
|
+
toolGuideExtra: "HINDSIGHT_TOOL_GUIDE_EXTRA",
|
|
1599
1695
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1600
1696
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1601
1697
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1637,6 +1733,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1637
1733
|
"maxParallelRetains",
|
|
1638
1734
|
"reflectTimeoutMs",
|
|
1639
1735
|
"reflectToolTimeoutMs",
|
|
1736
|
+
"injectTimeoutMs",
|
|
1640
1737
|
"pageSearchLimit",
|
|
1641
1738
|
"pageRefreshEveryTurns",
|
|
1642
1739
|
"seedLimit",
|
|
@@ -1685,15 +1782,25 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
1685
1782
|
function applyBankConfig(cfg, resolvedId, directory) {
|
|
1686
1783
|
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
1687
1784
|
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
1785
|
+
const byPath = directory === void 0 ? void 0 : pathSection(cfg, cfg.paths, directory);
|
|
1786
|
+
if (byPath) {
|
|
1787
|
+
const { bank: _rename, ...rest } = overrideFields(byPath);
|
|
1788
|
+
cfg = { ...cfg, ...resolvePartial(cfg, rest) };
|
|
1789
|
+
}
|
|
1688
1790
|
const section = cfg.banks[resolvedId];
|
|
1689
1791
|
if (!section) return { cfg, bankId: resolvedId };
|
|
1690
|
-
const safe =
|
|
1691
|
-
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1692
|
-
delete safe.banks;
|
|
1792
|
+
const safe = overrideFields(section);
|
|
1693
1793
|
const bankId = typeof safe.bank === "string" && safe.bank ? safe.bank : resolvedId;
|
|
1694
1794
|
delete safe.bank;
|
|
1695
1795
|
return { cfg: { ...cfg, ...resolvePartial(cfg, safe) }, bankId };
|
|
1696
1796
|
}
|
|
1797
|
+
function overrideFields(section) {
|
|
1798
|
+
const safe = { ...section };
|
|
1799
|
+
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1800
|
+
delete safe.banks;
|
|
1801
|
+
delete safe.paths;
|
|
1802
|
+
return safe;
|
|
1803
|
+
}
|
|
1697
1804
|
function resolvePartial(cfg, patch) {
|
|
1698
1805
|
const full = resolveConfig(patch);
|
|
1699
1806
|
const out = {};
|
|
@@ -1702,6 +1809,16 @@ function resolvePartial(cfg, patch) {
|
|
|
1702
1809
|
out[key] = full[key];
|
|
1703
1810
|
}
|
|
1704
1811
|
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1812
|
+
if ("serverMode" in patch || "apiUrl" in patch || "apiPort" in patch) {
|
|
1813
|
+
const conn = resolveConfig({
|
|
1814
|
+
serverMode: patch.serverMode ?? cfg.serverMode,
|
|
1815
|
+
apiPort: patch.apiPort ?? cfg.apiPort,
|
|
1816
|
+
apiUrl: patch.apiUrl ?? (cfg.serverMode === "daemon" ? void 0 : cfg.apiUrl)
|
|
1817
|
+
});
|
|
1818
|
+
out.serverMode = conn.serverMode;
|
|
1819
|
+
out.apiUrl = conn.apiUrl;
|
|
1820
|
+
out.apiPort = conn.apiPort;
|
|
1821
|
+
}
|
|
1705
1822
|
return out;
|
|
1706
1823
|
}
|
|
1707
1824
|
|
|
@@ -1730,7 +1847,12 @@ function resolveHostMemory(harness, directory) {
|
|
|
1730
1847
|
// rotate the key mid-session and the snapshot 401s every call until restart (#3600). Read
|
|
1731
1848
|
// through the same pipeline the constructor used, so a per-bank `banks.<id>.apiToken` is
|
|
1732
1849
|
// honoured on re-resolution exactly as it was on the first one.
|
|
1733
|
-
|
|
1850
|
+
// The URL stays the one this client was built with, so a token re-read after the config
|
|
1851
|
+
// moved this directory to ANOTHER server is that server's credential: never send it here.
|
|
1852
|
+
tokenProvider: () => {
|
|
1853
|
+
const live = resolveHostConfig(harness, directory).cfg;
|
|
1854
|
+
return live.apiUrl === cfg.apiUrl ? live.apiToken : cfg.apiToken;
|
|
1855
|
+
}
|
|
1734
1856
|
})
|
|
1735
1857
|
};
|
|
1736
1858
|
}
|
|
@@ -2056,12 +2178,46 @@ function startDaemonDetached(cfg, harness, spawnFn = realSpawn3) {
|
|
|
2056
2178
|
} catch {
|
|
2057
2179
|
}
|
|
2058
2180
|
}
|
|
2181
|
+
var coldStarts = /* @__PURE__ */ new Map();
|
|
2182
|
+
async function waitBounded(p, ms) {
|
|
2183
|
+
let timer;
|
|
2184
|
+
try {
|
|
2185
|
+
await Promise.race([
|
|
2186
|
+
p,
|
|
2187
|
+
new Promise((resolve3) => {
|
|
2188
|
+
timer = setTimeout(resolve3, Math.max(ms, 0));
|
|
2189
|
+
})
|
|
2190
|
+
]);
|
|
2191
|
+
} finally {
|
|
2192
|
+
clearTimeout(timer);
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2059
2195
|
async function ensureDaemon(cfg, harness, opts = {}) {
|
|
2060
2196
|
if (cfg.serverMode !== "daemon") return;
|
|
2061
2197
|
if (await isServerHealthy(cfg.apiUrl)) return;
|
|
2062
2198
|
if (!preflightDaemon(cfg, harness)) return;
|
|
2063
|
-
|
|
2064
|
-
|
|
2199
|
+
const waitMs = opts.waitMs ?? 0;
|
|
2200
|
+
const running = coldStarts.get(cfg.apiUrl);
|
|
2201
|
+
if (running) {
|
|
2202
|
+
const startedAt = Date.now();
|
|
2203
|
+
await waitBounded(
|
|
2204
|
+
running.catch(() => void 0),
|
|
2205
|
+
waitMs
|
|
2206
|
+
);
|
|
2207
|
+
const remaining = waitMs - (Date.now() - startedAt);
|
|
2208
|
+
if (remaining > 0) await waitForHealth(cfg.apiUrl, remaining);
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2211
|
+
const attempt = (async () => {
|
|
2212
|
+
startDaemonDetached(cfg, harness, opts.spawnFn);
|
|
2213
|
+
await waitForHealth(cfg.apiUrl, waitMs);
|
|
2214
|
+
})();
|
|
2215
|
+
coldStarts.set(cfg.apiUrl, attempt);
|
|
2216
|
+
try {
|
|
2217
|
+
await attempt;
|
|
2218
|
+
} finally {
|
|
2219
|
+
if (coldStarts.get(cfg.apiUrl) === attempt) coldStarts.delete(cfg.apiUrl);
|
|
2220
|
+
}
|
|
2065
2221
|
}
|
|
2066
2222
|
async function waitForHealth(baseUrl, budgetMs, pollMs = 1e3) {
|
|
2067
2223
|
const deadline = Date.now() + budgetMs;
|
|
@@ -2113,13 +2269,13 @@ function indexLine(pages) {
|
|
|
2113
2269
|
const count = pages.length === 1 ? "1 knowledge page covers" : `${pages.length} knowledge pages cover`;
|
|
2114
2270
|
return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call hindsight_search_knowledge_pages(query) to find the ones that bear on the current turn, then hindsight_read_knowledge_page(<id>) on anything the results show is worth reading in full.`;
|
|
2115
2271
|
}
|
|
2116
|
-
var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, and the way IN to everything below. The code shows what is true today
|
|
2117
|
-
\u2022 the user reports a bug or a wrong response (the intended behaviour, and the status code or value it should return,
|
|
2272
|
+
var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, and the way IN to everything below. The code shows what is true today but not what was decided or why; memory shows what was decided or said back then but not whether it still holds. Work built from either alone goes wrong: from code alone it quietly re-litigates settled questions, from memory alone it acts on stale claims. Search BEFORE you act whenever the turn is one of these \u2014 they are the ones that go wrong silently:
|
|
2273
|
+
\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);
|
|
2118
2274
|
\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);
|
|
2119
2275
|
\u2022 you are implementing something new, or two parts have to fit together;
|
|
2120
2276
|
\u2022 the user asks why something is the way it is, or what is left to do;
|
|
2121
2277
|
\u2022 you are about to commit, and need to know what the change was supposed to honour.
|
|
2122
|
-
It ranks the pages by relevance and returns the matching passage, which a page title cannot tell you.
|
|
2278
|
+
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.
|
|
2123
2279
|
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.
|
|
2124
2280
|
- hindsight_list_knowledge_pages / hindsight_read_knowledge_page \u2014 BEFORE substantial work, list the pages and read the relevant ones to ground yourself in this repo's architecture, conventions, and past decisions instead of re-deriving them from the code; follow any [[page:<id>]] links you see.
|
|
2125
2281
|
- 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>").
|
|
@@ -2127,7 +2283,9 @@ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, a
|
|
|
2127
2283
|
- 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).`;
|
|
2128
2284
|
var PAGES_FIRST_ON_GOALS = "- The user just set a NEW task or goal \u2192 search the knowledge pages FIRST with hindsight_search_knowledge_pages. No synthesis is injected automatically in this configuration; call hindsight_reflect only when those pages are too shallow and deeper reasoning is needed.\n";
|
|
2129
2285
|
function toolGuide(opts) {
|
|
2130
|
-
|
|
2286
|
+
const extra = opts?.extra?.trim();
|
|
2287
|
+
return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE + (extra ? `
|
|
2288
|
+
${extra}` : "");
|
|
2131
2289
|
}
|
|
2132
2290
|
function buildKnowledgePreamble(pages, opts) {
|
|
2133
2291
|
const body = pages.length ? indexLine(pages) : EMPTY_STATE;
|
|
@@ -16673,6 +16831,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
16673
16831
|
// src/core/git.ts
|
|
16674
16832
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
16675
16833
|
import { resolve as resolve2 } from "path";
|
|
16834
|
+
var GITLOG_HEAD = "gitlog-head:";
|
|
16676
16835
|
function git(repo, ...args) {
|
|
16677
16836
|
return execFileSync2("git", ["-C", repo, ...args], {
|
|
16678
16837
|
encoding: "utf8",
|
|
@@ -16694,6 +16853,7 @@ function gitHeadSha(dir) {
|
|
|
16694
16853
|
}
|
|
16695
16854
|
}
|
|
16696
16855
|
function commitsSince(dir, sinceSha) {
|
|
16856
|
+
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16697
16857
|
try {
|
|
16698
16858
|
const n = Number.parseInt(git(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16699
16859
|
return Number.isFinite(n) ? n : null;
|
|
@@ -16708,6 +16868,15 @@ function hasGitHistory(dir) {
|
|
|
16708
16868
|
return false;
|
|
16709
16869
|
}
|
|
16710
16870
|
}
|
|
16871
|
+
async function gitLogIsCurrent(client, repo, head) {
|
|
16872
|
+
const canonical2 = `gitlog:${repoNameOf(repo)}`;
|
|
16873
|
+
if ((await client.listDocumentIds(`${GITLOG_HEAD}${head}`, "all_strict")).has(canonical2))
|
|
16874
|
+
return true;
|
|
16875
|
+
const tags = await client.documentTags?.(canonical2) ?? [];
|
|
16876
|
+
return tags.some(
|
|
16877
|
+
(tag) => tag.startsWith(GITLOG_HEAD) && commitsSince(repo, tag.slice(GITLOG_HEAD.length)) === 0
|
|
16878
|
+
);
|
|
16879
|
+
}
|
|
16711
16880
|
|
|
16712
16881
|
// src/core/survey.ts
|
|
16713
16882
|
import { spawn as realSpawn5 } from "child_process";
|
|
@@ -17059,19 +17228,7 @@ var NON_DESTRUCTIVE_WRITE_ANNOTATIONS = {
|
|
|
17059
17228
|
idempotentHint: false,
|
|
17060
17229
|
openWorldHint: false
|
|
17061
17230
|
};
|
|
17062
|
-
var CREDIT_REMINDER = 'Crediting is mandatory, not a judgement call: if anything these results contribute reaches your reply \u2014 quoted, paraphrased, or merely confirming what you were going to say \u2014 open that part with "> \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. If none of them bear on the turn, ignore them silently \u2014 an unhelpful search needs no mention.';
|
|
17063
|
-
function shapePage(page) {
|
|
17064
|
-
const p = page ?? {};
|
|
17065
|
-
const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
|
|
17066
|
-
return {
|
|
17067
|
-
id: p.id,
|
|
17068
|
-
name: p.name,
|
|
17069
|
-
...p.description ? { description: p.description } : {},
|
|
17070
|
-
...Array.isArray(p.tags) && p.tags.length ? { tags: p.tags } : {},
|
|
17071
|
-
...p.timestamp ? { last_updated_at: p.timestamp } : {},
|
|
17072
|
-
body
|
|
17073
|
-
};
|
|
17074
|
-
}
|
|
17231
|
+
var CREDIT_REMINDER = 'Crediting is mandatory, not a judgement call: if anything these results contribute reaches your reply \u2014 quoted, paraphrased, or merely confirming what you were going to say \u2014 open that part with "> \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. If none of them bear on the turn, ignore them silently \u2014 an unhelpful search needs no mention. These are past records: check a claim that something was fixed or works against the code before relying on it.';
|
|
17075
17232
|
function ok(value) {
|
|
17076
17233
|
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
17077
17234
|
}
|
|
@@ -17089,6 +17246,8 @@ function guarded(fn) {
|
|
|
17089
17246
|
};
|
|
17090
17247
|
}
|
|
17091
17248
|
function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
17249
|
+
const extra = opts.toolGuideExtra?.trim();
|
|
17250
|
+
const crediting = extra ? `${CREDIT_REMINDER} ${extra}` : CREDIT_REMINDER;
|
|
17092
17251
|
return [
|
|
17093
17252
|
{
|
|
17094
17253
|
name: "hindsight_sync_status",
|
|
@@ -17148,7 +17307,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17148
17307
|
},
|
|
17149
17308
|
{
|
|
17150
17309
|
name: "hindsight_search_knowledge_pages",
|
|
17151
|
-
description: "Search this repository's Hindsight knowledge 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_knowledge_page. " +
|
|
17310
|
+
description: "Search this repository's Hindsight knowledge 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_knowledge_page. " + crediting,
|
|
17152
17311
|
inputSchema: { query: external_exports.string().describe("what to look for") },
|
|
17153
17312
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17154
17313
|
handler: async (args) => {
|
|
@@ -17158,9 +17317,12 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17158
17317
|
pages: hits.map((h) => ({
|
|
17159
17318
|
page: h.name,
|
|
17160
17319
|
page_id: h.id,
|
|
17320
|
+
// The question the page answers — the same `description` the list and read tools
|
|
17321
|
+
// carry, so a hit says what the page is FOR, not just how it opens.
|
|
17322
|
+
...h.source_query ? { description: h.source_query } : {},
|
|
17161
17323
|
snippet: h.snippet
|
|
17162
17324
|
})),
|
|
17163
|
-
crediting
|
|
17325
|
+
crediting
|
|
17164
17326
|
});
|
|
17165
17327
|
} catch (e) {
|
|
17166
17328
|
return err(e);
|
|
@@ -17179,7 +17341,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17179
17341
|
description: "Read the full content of one knowledge page by its id (from hindsight_list_knowledge_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.",
|
|
17180
17342
|
inputSchema: { page_id: external_exports.string() },
|
|
17181
17343
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
17182
|
-
handler: guarded(async ({ page_id }) =>
|
|
17344
|
+
handler: guarded(async ({ page_id }) => client.getPage(page_id))
|
|
17183
17345
|
},
|
|
17184
17346
|
{
|
|
17185
17347
|
name: "hindsight_reflect",
|
|
@@ -17249,6 +17411,11 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17249
17411
|
import { createHash as createHash4 } from "crypto";
|
|
17250
17412
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
17251
17413
|
var PENDING_MAX_BYTES = 256 * 1024;
|
|
17414
|
+
var MAX_CURSOR_PATHS = 16;
|
|
17415
|
+
function advancePaths(seen, path) {
|
|
17416
|
+
if (!path) return seen;
|
|
17417
|
+
return [...(seen ?? []).filter((p) => p !== path), path].slice(-MAX_CURSOR_PATHS);
|
|
17418
|
+
}
|
|
17252
17419
|
function pendingReplayable(cursor, now) {
|
|
17253
17420
|
const pending = cursor.pending ?? [];
|
|
17254
17421
|
if (!pending.length) return true;
|
|
@@ -17265,8 +17432,10 @@ function planRetain(turns, cursor, opts) {
|
|
|
17265
17432
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17266
17433
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17267
17434
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
17268
|
-
|
|
17269
|
-
|
|
17435
|
+
const seen = cursor.paths ?? [];
|
|
17436
|
+
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17437
|
+
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
17438
|
+
if (!continues) return newFile ? { mode: "append", fromTurn: 0 } : { mode: "replace" };
|
|
17270
17439
|
if (cursor.turns === turns.length) return { mode: "skip" };
|
|
17271
17440
|
return { mode: "append", fromTurn: cursor.turns };
|
|
17272
17441
|
}
|
|
@@ -17308,7 +17477,7 @@ function renderSessionJsonl(refId, turns, baseTs) {
|
|
|
17308
17477
|
}
|
|
17309
17478
|
async function supportsAppend(client) {
|
|
17310
17479
|
try {
|
|
17311
|
-
return await client.
|
|
17480
|
+
return await client.supportsAppendRetain();
|
|
17312
17481
|
} catch {
|
|
17313
17482
|
return false;
|
|
17314
17483
|
}
|
|
@@ -17342,6 +17511,7 @@ function serialize(cursors, sessionId, write2) {
|
|
|
17342
17511
|
});
|
|
17343
17512
|
return next;
|
|
17344
17513
|
}
|
|
17514
|
+
var DEFAULT_RETAIN_CONTEXT = `conversation between the user and you (the coding agent): user turns are the user's words and decisions, assistant turns are yours. When an assistant turn says something is fixed, passes or works, record it as the agent's claim ("the agent reported X fixed"), not as an established fact.`;
|
|
17345
17515
|
async function retainLiveSession(client, sessionId, turns, startTs, harness, opts = {}) {
|
|
17346
17516
|
const cursors = opts.cursors;
|
|
17347
17517
|
if (!cursors)
|
|
@@ -17353,20 +17523,36 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
17353
17523
|
harness,
|
|
17354
17524
|
opts.stamp,
|
|
17355
17525
|
void 0,
|
|
17356
|
-
opts.retryUntil
|
|
17526
|
+
opts.retryUntil,
|
|
17527
|
+
opts.transcriptPath
|
|
17357
17528
|
);
|
|
17358
17529
|
return serialize(
|
|
17359
17530
|
cursors,
|
|
17360
17531
|
sessionId,
|
|
17361
|
-
() => writeSession(
|
|
17532
|
+
() => writeSession(
|
|
17533
|
+
client,
|
|
17534
|
+
sessionId,
|
|
17535
|
+
turns,
|
|
17536
|
+
startTs,
|
|
17537
|
+
harness,
|
|
17538
|
+
opts.stamp,
|
|
17539
|
+
cursors,
|
|
17540
|
+
opts.retryUntil,
|
|
17541
|
+
opts.transcriptPath
|
|
17542
|
+
)
|
|
17362
17543
|
);
|
|
17363
17544
|
}
|
|
17364
|
-
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
17545
|
+
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS, transcriptPath) {
|
|
17365
17546
|
if (!turns.length) return;
|
|
17366
17547
|
const refId = `conversation:${sessionId}`;
|
|
17367
17548
|
const cursor = cursors?.read(sessionId);
|
|
17368
17549
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17369
|
-
const plan = planRetain(turns, cursor, {
|
|
17550
|
+
const plan = planRetain(turns, cursor, {
|
|
17551
|
+
appendSupported,
|
|
17552
|
+
bank: client.bank,
|
|
17553
|
+
path: transcriptPath
|
|
17554
|
+
});
|
|
17555
|
+
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17370
17556
|
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17371
17557
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17372
17558
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
@@ -17375,7 +17561,10 @@ ${mode}
|
|
|
17375
17561
|
${content}`);
|
|
17376
17562
|
const submit = (content, operationId, append) => client.retain(
|
|
17377
17563
|
content,
|
|
17378
|
-
|
|
17564
|
+
// Configured context wins. Extraction reads this to decide whose claim a sentence is, so the
|
|
17565
|
+
// default names both speakers: the previous "coding agent session" said nothing about
|
|
17566
|
+
// authorship and let an assistant's proposal be recorded as the user's decision.
|
|
17567
|
+
stamp?.context ?? DEFAULT_RETAIN_CONTEXT,
|
|
17379
17568
|
refId,
|
|
17380
17569
|
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
17381
17570
|
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
@@ -17405,6 +17594,7 @@ ${content}`);
|
|
|
17405
17594
|
turns: turns.length,
|
|
17406
17595
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17407
17596
|
bank: client.bank,
|
|
17597
|
+
...paths ? { paths } : {},
|
|
17408
17598
|
...appendSupported ? { appendSupported: true } : {}
|
|
17409
17599
|
};
|
|
17410
17600
|
const stillOurs = () => {
|
|
@@ -17521,7 +17711,8 @@ function resolversFor(ctx) {
|
|
|
17521
17711
|
function buildRetainStamp(cfg, ctx) {
|
|
17522
17712
|
const hasTags = Boolean(cfg.retainTags?.length);
|
|
17523
17713
|
const hasMetadata = Boolean(cfg.retainMetadata && Object.keys(cfg.retainMetadata).length);
|
|
17524
|
-
|
|
17714
|
+
const hasContext = Boolean(cfg.retainContext?.trim());
|
|
17715
|
+
if (!hasTags && !hasMetadata && !hasContext) return { tags: [], metadata: {} };
|
|
17525
17716
|
const base = resolversFor(ctx);
|
|
17526
17717
|
const cache = /* @__PURE__ */ new Map();
|
|
17527
17718
|
const resolvers = Object.fromEntries(
|
|
@@ -17545,19 +17736,22 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17545
17736
|
for (const [key, value] of Object.entries(cfg.retainMetadata ?? {})) {
|
|
17546
17737
|
metadata[key] = applyTemplate(value, resolvers, "retainMetadata");
|
|
17547
17738
|
}
|
|
17548
|
-
|
|
17739
|
+
const context = hasContext ? applyTemplate(cfg.retainContext, resolvers, "retainContext").trim() || void 0 : void 0;
|
|
17740
|
+
return { tags, metadata, context };
|
|
17549
17741
|
}
|
|
17550
17742
|
|
|
17551
17743
|
// src/core/session-start.ts
|
|
17552
17744
|
import { readFileSync as readFileSync8 } from "fs";
|
|
17553
17745
|
|
|
17554
17746
|
// src/core/skill-sync.ts
|
|
17555
|
-
import { cpSync, existsSync as
|
|
17747
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
|
|
17556
17748
|
import { homedir as homedir7 } from "os";
|
|
17557
|
-
import { dirname as dirname8, join as
|
|
17749
|
+
import { dirname as dirname8, join as join15 } from "path";
|
|
17558
17750
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
17559
17751
|
|
|
17560
17752
|
// src/core/skill-dirs.ts
|
|
17753
|
+
import { existsSync as existsSync5 } from "fs";
|
|
17754
|
+
import { join as join14 } from "path";
|
|
17561
17755
|
var SKILL_DIRS = {
|
|
17562
17756
|
"claude-code": [".claude", "skills"],
|
|
17563
17757
|
// Codex and dsh share the agentskills-standard root; uninstalling either removes the one copy.
|
|
@@ -17570,6 +17764,8 @@ var SKILL_DIRS = {
|
|
|
17570
17764
|
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
17571
17765
|
"qwen-code": [".qwen", "skills"],
|
|
17572
17766
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
17767
|
+
// Kimi Code's user-level skills root, alongside its config.toml and mcp.json.
|
|
17768
|
+
"kimi-code": [".kimi-code", "skills"],
|
|
17573
17769
|
"factory-droid": [".factory", "skills"],
|
|
17574
17770
|
// Droid's user-level skills root
|
|
17575
17771
|
// ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
|
|
@@ -17577,29 +17773,46 @@ var SKILL_DIRS = {
|
|
|
17577
17773
|
// skill removal is by fixed directory name, so installing into the shared root would make
|
|
17578
17774
|
// `uninstall zcode` take Codex's and dsh's copy with it.
|
|
17579
17775
|
zcode: [".zcode", "skills"],
|
|
17776
|
+
// TraeCode's user-level skills root, resolved per edition by traecodeDotDir below — like ZCode's
|
|
17777
|
+
// its own, never the shared agentskills root other hosts install into.
|
|
17778
|
+
traecode: [".trae-cn", "skills"],
|
|
17580
17779
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
17581
17780
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
17582
17781
|
// and dsh's copy with it.
|
|
17583
17782
|
pi: [".pi", "agent", "skills"],
|
|
17584
17783
|
"prime-agent": [".prime", "agent", "skills"]
|
|
17585
17784
|
};
|
|
17785
|
+
var TRAE_DOT_DIRS = [".trae-cn", ".trae"];
|
|
17786
|
+
var traecodeDotDirName = (home, exists = existsSync5) => {
|
|
17787
|
+
for (const dir of TRAE_DOT_DIRS) {
|
|
17788
|
+
if (exists(join14(home, dir))) return dir;
|
|
17789
|
+
}
|
|
17790
|
+
return ".trae-cn";
|
|
17791
|
+
};
|
|
17792
|
+
var resolveSkillDirs = (harness, home) => {
|
|
17793
|
+
const parts = SKILL_DIRS[harness];
|
|
17794
|
+
if (harness === "traecode" && parts) {
|
|
17795
|
+
return [traecodeDotDirName(home), ...parts.slice(1)];
|
|
17796
|
+
}
|
|
17797
|
+
return parts;
|
|
17798
|
+
};
|
|
17586
17799
|
|
|
17587
17800
|
// src/core/skill-sync.ts
|
|
17588
17801
|
function packagedSkillDir() {
|
|
17589
17802
|
const here = dirname8(fileURLToPath5(import.meta.url));
|
|
17590
|
-
const dist =
|
|
17591
|
-
return
|
|
17803
|
+
const dist = join15(here, "..", "skill");
|
|
17804
|
+
return existsSync6(join15(dist, "SKILL.md")) ? dist : join15(here, "..", "..", "skill");
|
|
17592
17805
|
}
|
|
17593
17806
|
function syncCompanionSkill(harness, opts = {}) {
|
|
17594
17807
|
try {
|
|
17595
|
-
const parts =
|
|
17808
|
+
const parts = resolveSkillDirs(harness, opts.home ?? homedir7());
|
|
17596
17809
|
if (!parts) return;
|
|
17597
17810
|
const src = opts.srcDir ?? packagedSkillDir();
|
|
17598
|
-
const srcMd =
|
|
17599
|
-
if (!
|
|
17600
|
-
const dst =
|
|
17601
|
-
const dstMd =
|
|
17602
|
-
const installed =
|
|
17811
|
+
const srcMd = join15(src, "SKILL.md");
|
|
17812
|
+
if (!existsSync6(srcMd)) return;
|
|
17813
|
+
const dst = join15(opts.home ?? homedir7(), ...parts, "hindsight-coding-agent");
|
|
17814
|
+
const dstMd = join15(dst, "SKILL.md");
|
|
17815
|
+
const installed = existsSync6(dstMd);
|
|
17603
17816
|
if (!installed && !opts.install) return;
|
|
17604
17817
|
if (!installed || readFileSync5(srcMd, "utf8") !== readFileSync5(dstMd, "utf8")) {
|
|
17605
17818
|
cpSync(src, dst, { recursive: true });
|
|
@@ -17623,15 +17836,15 @@ function brandWord() {
|
|
|
17623
17836
|
}
|
|
17624
17837
|
|
|
17625
17838
|
// src/core/legacy.ts
|
|
17626
|
-
import { existsSync as
|
|
17839
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
|
|
17627
17840
|
import { homedir as homedir8 } from "os";
|
|
17628
|
-
import { join as
|
|
17841
|
+
import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
|
|
17629
17842
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17630
|
-
function detectLegacyClaudePlugin(cwd, claudeDir =
|
|
17631
|
-
const registry2 = readJson(
|
|
17843
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
17844
|
+
const registry2 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
17632
17845
|
const plugins = registry2?.plugins;
|
|
17633
17846
|
if (!plugins || typeof plugins !== "object") return void 0;
|
|
17634
|
-
const enabled = readJson(
|
|
17847
|
+
const enabled = readJson(join16(claudeDir, "settings.json"))?.enabledPlugins;
|
|
17635
17848
|
for (const [key, raw] of Object.entries(plugins)) {
|
|
17636
17849
|
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
17637
17850
|
if (enabled && enabled[key] === false) continue;
|
|
@@ -17662,9 +17875,9 @@ function legacyClaudePluginWarning(key) {
|
|
|
17662
17875
|
// src/core/session-cache.ts
|
|
17663
17876
|
import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
17664
17877
|
import { tmpdir as tmpdir3 } from "os";
|
|
17665
|
-
import { dirname as dirname9, join as
|
|
17878
|
+
import { dirname as dirname9, join as join17 } from "path";
|
|
17666
17879
|
function sessionCacheFile(harness, sessionId) {
|
|
17667
|
-
return
|
|
17880
|
+
return join17(tmpdir3(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
17668
17881
|
}
|
|
17669
17882
|
function readSessionCache(cacheFile) {
|
|
17670
17883
|
try {
|
|
@@ -17706,7 +17919,7 @@ async function gitSyncNote(args) {
|
|
|
17706
17919
|
if (mode === "none" || cold) return void 0;
|
|
17707
17920
|
const head = gitHeadSha(cwd);
|
|
17708
17921
|
if (!head) return void 0;
|
|
17709
|
-
const gitlogCurrent = await client
|
|
17922
|
+
const gitlogCurrent = await gitLogIsCurrent(client, cwd, head).catch(() => void 0);
|
|
17710
17923
|
if (gitlogCurrent === void 0) return void 0;
|
|
17711
17924
|
if (mode === "message") return gitlogCurrent ? "git in sync" : "catching up on new commits";
|
|
17712
17925
|
const deepened = [...gitIds].filter((id) => id.startsWith("git:")).length;
|
|
@@ -17832,7 +18045,8 @@ async function buildSessionStartContext(args) {
|
|
|
17832
18045
|
}
|
|
17833
18046
|
}
|
|
17834
18047
|
const additionalContext = buildKnowledgePreamble(pages, {
|
|
17835
|
-
reflectOnNewGoals: cfg.autoInject !== "reflect"
|
|
18048
|
+
reflectOnNewGoals: cfg.autoInject !== "reflect",
|
|
18049
|
+
extra: cfg.toolGuideExtra
|
|
17836
18050
|
});
|
|
17837
18051
|
const deferInitialReflect = cold === true || pageListKnown && pages.length === 0;
|
|
17838
18052
|
let gitNote;
|
|
@@ -17858,7 +18072,7 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
|
17858
18072
|
}
|
|
17859
18073
|
|
|
17860
18074
|
// src/core/hook.ts
|
|
17861
|
-
import { existsSync as
|
|
18075
|
+
import { existsSync as existsSync8, readFileSync as readFileSync10 } from "fs";
|
|
17862
18076
|
|
|
17863
18077
|
// src/core/inject.ts
|
|
17864
18078
|
function buildReflectQuery(prompt) {
|
|
@@ -17907,7 +18121,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17907
18121
|
// src/core/turn-journal.ts
|
|
17908
18122
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
|
|
17909
18123
|
import { tmpdir as tmpdir4 } from "os";
|
|
17910
|
-
import { dirname as dirname10, join as
|
|
18124
|
+
import { dirname as dirname10, join as join18 } from "path";
|
|
17911
18125
|
|
|
17912
18126
|
// src/core/transcript-util.ts
|
|
17913
18127
|
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;
|
|
@@ -17948,7 +18162,6 @@ function actionLine(tool, input) {
|
|
|
17948
18162
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17949
18163
|
|
|
17950
18164
|
// src/core/hook.ts
|
|
17951
|
-
var HOOK_FALLBACK_BUDGET_MS = 7e3;
|
|
17952
18165
|
var HOOK_INJECT_ATTEMPTS = 2;
|
|
17953
18166
|
function resolveInjection(got, attempts) {
|
|
17954
18167
|
if (got != null) return got;
|
|
@@ -17976,8 +18189,8 @@ async function injectRecall(harness, prompt, client, timeoutMs, event, lead) {
|
|
|
17976
18189
|
return void 0;
|
|
17977
18190
|
}
|
|
17978
18191
|
}
|
|
17979
|
-
async function reflectFallback(harness, prompt, client) {
|
|
17980
|
-
const deadline = Date.now() +
|
|
18192
|
+
async function reflectFallback(harness, prompt, client, timeoutMs) {
|
|
18193
|
+
const deadline = Date.now() + timeoutMs;
|
|
17981
18194
|
const remaining = () => Math.max(deadline - Date.now(), 1);
|
|
17982
18195
|
return await injectPages(harness, prompt, client, remaining(), "reflect_fallback_pages") ?? // Event name predates the `injectRecall` rename and is kept: it is a logged contract that
|
|
17983
18196
|
// other tools read, so renaming it would silently break them.
|
|
@@ -18002,7 +18215,7 @@ async function buildHookOutput(args) {
|
|
|
18002
18215
|
harness,
|
|
18003
18216
|
prompt,
|
|
18004
18217
|
client,
|
|
18005
|
-
|
|
18218
|
+
cfg.injectTimeoutMs,
|
|
18006
18219
|
"inject_pages",
|
|
18007
18220
|
PAGE_INJECT_LEAD
|
|
18008
18221
|
);
|
|
@@ -18015,7 +18228,7 @@ async function buildHookOutput(args) {
|
|
|
18015
18228
|
harness,
|
|
18016
18229
|
prompt,
|
|
18017
18230
|
client,
|
|
18018
|
-
|
|
18231
|
+
cfg.injectTimeoutMs,
|
|
18019
18232
|
"inject_recall",
|
|
18020
18233
|
RECALL_INJECT_LEAD
|
|
18021
18234
|
);
|
|
@@ -18057,7 +18270,7 @@ async function buildHookOutput(args) {
|
|
|
18057
18270
|
query: prompt.slice(0, 80)
|
|
18058
18271
|
});
|
|
18059
18272
|
if (e instanceof ReflectError && e.fallbackEligible) {
|
|
18060
|
-
fallback = await reflectFallback(harness, prompt, client);
|
|
18273
|
+
fallback = await reflectFallback(harness, prompt, client, cfg.injectTimeoutMs);
|
|
18061
18274
|
if (fallback) reflectAnswer = fallback;
|
|
18062
18275
|
}
|
|
18063
18276
|
}
|
|
@@ -18090,7 +18303,12 @@ async function buildHookOutput(args) {
|
|
|
18090
18303
|
const blocks = [];
|
|
18091
18304
|
if (reflectAnswer && reflectRanThisTurn) blocks.push(buildSystemInjection(reflectAnswer));
|
|
18092
18305
|
if (cadence > 0 && turns % cadence === 0) {
|
|
18093
|
-
blocks.push(
|
|
18306
|
+
blocks.push(
|
|
18307
|
+
buildRosterRefresh(pages, {
|
|
18308
|
+
reflectOnNewGoals: cfg.autoInject !== "reflect",
|
|
18309
|
+
extra: cfg.toolGuideExtra
|
|
18310
|
+
})
|
|
18311
|
+
);
|
|
18094
18312
|
}
|
|
18095
18313
|
const kept = blocks.filter(Boolean);
|
|
18096
18314
|
let notice;
|
|
@@ -18159,6 +18377,7 @@ var RuntimeCore = class {
|
|
|
18159
18377
|
pageTrigger: buildPageTrigger(this.cfg),
|
|
18160
18378
|
reflectTimeoutMs: this.cfg.reflectToolTimeoutMs,
|
|
18161
18379
|
reflectBudget: this.cfg.reflectBudget,
|
|
18380
|
+
toolGuideExtra: this.cfg.toolGuideExtra,
|
|
18162
18381
|
stampFor: () => buildRetainStamp(this.cfg, {
|
|
18163
18382
|
directory: this.projectDir,
|
|
18164
18383
|
harness: this.harness,
|
|
@@ -18226,7 +18445,8 @@ var RuntimeCore = class {
|
|
|
18226
18445
|
if (turns === 1) {
|
|
18227
18446
|
blocks.push(
|
|
18228
18447
|
buildKnowledgePreamble(output.pages, {
|
|
18229
|
-
reflectOnNewGoals: this.cfg.autoInject !== "reflect"
|
|
18448
|
+
reflectOnNewGoals: this.cfg.autoInject !== "reflect",
|
|
18449
|
+
extra: this.cfg.toolGuideExtra
|
|
18230
18450
|
})
|
|
18231
18451
|
);
|
|
18232
18452
|
}
|
|
@@ -18443,7 +18663,7 @@ function injectionMessage(text) {
|
|
|
18443
18663
|
id: randomUUID2(),
|
|
18444
18664
|
role: "user",
|
|
18445
18665
|
content: [{ type: "text", text }],
|
|
18446
|
-
source: { kind:
|
|
18666
|
+
source: { kind: `plugin:${HINDSIGHT_PLUGIN}`, form: "recall" }
|
|
18447
18667
|
};
|
|
18448
18668
|
}
|
|
18449
18669
|
function createDshHooks(resolve3) {
|