@vectorize-io/hindsight-coding-agents 0.6.1 → 0.7.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 +179 -40
- package/dist/antigravity-hook.js +343 -158
- package/dist/antigravity-statusline.js +117 -4
- package/dist/antigravity-stop-hook.js +262 -113
- package/dist/claude-hook.js +343 -158
- package/dist/claude-sessionstart-hook.js +348 -136
- package/dist/claude-stop-hook.js +262 -113
- package/dist/cline.js +493 -173
- package/dist/codex-hook.js +343 -158
- package/dist/codex-sessionstart-hook.js +348 -136
- package/dist/codex-stop-hook.js +262 -113
- package/dist/copilot-hook.js +343 -158
- package/dist/copilot-sessionstart-hook.js +348 -136
- package/dist/copilot-stop-hook.js +262 -113
- package/dist/cursor-hook.js +343 -158
- package/dist/cursor-sessionstart-hook.js +348 -136
- package/dist/cursor-stop-hook.js +262 -113
- package/dist/daemon-start.js +116 -4
- package/dist/dcode-hook.js +343 -158
- package/dist/dcode-sessionstart-hook.js +348 -136
- package/dist/dcode-stop-hook.js +262 -113
- package/dist/deepen.js +204 -47
- package/dist/devin-hook.js +343 -158
- package/dist/devin-sessionstart-hook.js +348 -136
- package/dist/devin-stop-hook.js +262 -113
- package/dist/droid-hook.js +343 -158
- package/dist/droid-sessionstart-hook.js +348 -136
- package/dist/droid-stop-hook.js +262 -113
- package/dist/dsh.js +493 -173
- package/dist/grok-hook.js +343 -158
- package/dist/grok-sessionstart-hook.js +348 -136
- package/dist/grok-stop-hook.js +262 -113
- package/dist/hindsight-seed.js +116 -4
- package/dist/index.js +493 -173
- package/dist/installer.js +92 -70
- package/dist/kilo.js +493 -173
- package/dist/mcp-server.js +230 -57
- package/dist/opencode2.js +520 -173
- package/dist/pi.js +494 -175
- package/dist/prime-agent.js +494 -175
- package/dist/qwen-hook.js +343 -158
- package/dist/qwen-sessionstart-hook.js +348 -136
- package/dist/qwen-stop-hook.js +262 -113
- package/dist/status.js +203 -47
- package/dist/zcode-hook.js +343 -158
- package/dist/zcode-sessionstart-hook.js +348 -136
- package/dist/zcode-stop-hook.js +262 -113
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/skill/SKILL.md +173 -39
package/dist/deepen.js
CHANGED
|
@@ -357,13 +357,15 @@ var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSON
|
|
|
357
357
|
var REFLECT_MISSION = "You are a debugging assistant with the project's past decisions in memory (git rationale and developer chats). Given a bug's SYMPTOM, find the past decision whose rationale explains the ROOT CAUSE \u2014 not one that merely shares vocabulary. Answer with the PRECISE fix: state the EXACT rule and the LITERAL values, identifiers, strings, numbers, or set members that were decided \u2014 quote them VERBATIM, never paraphrase, generalize, or omit them (give the actual decided value, not 'the project standard'). If memories CONFLICT on the same rule, the LATEST decision wins \u2014 prefer facts that explicitly amend or supersede an earlier one, state the superseded rule as no longer in effect, and never present it as the fix. Name the function/file to change and cite the REF-ID(s). If NOTHING in memory genuinely explains THIS symptom, say exactly that in one short sentence \u2014 a wrong-but-confident nearest match is worse than an honest miss; never stretch an unrelated decision to fit.";
|
|
358
358
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
359
359
|
var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
|
|
360
|
+
var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
|
|
361
|
+
var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
|
|
360
362
|
var RETAIN_STRATEGIES = {
|
|
361
|
-
git: { retain_mission: GIT_MISSION, retain_extraction_mode:
|
|
363
|
+
git: { retain_mission: GIT_MISSION, retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE },
|
|
362
364
|
// ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
|
|
363
365
|
// in as few chunks as possible and the extractor sees the whole history arc at once.
|
|
364
366
|
gitlog: {
|
|
365
367
|
retain_mission: GITLOG_MISSION,
|
|
366
|
-
retain_extraction_mode:
|
|
368
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
367
369
|
retain_chunk_size: 12e3
|
|
368
370
|
},
|
|
369
371
|
// ONE strategy for ALL developer conversations — backfilled decision chats and live working
|
|
@@ -374,15 +376,15 @@ var RETAIN_STRATEGIES = {
|
|
|
374
376
|
// the consolidation layer.
|
|
375
377
|
conversation: {
|
|
376
378
|
retain_mission: CONVERSATION_MISSION,
|
|
377
|
-
retain_extraction_mode:
|
|
379
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
378
380
|
retain_chunk_size: 12e3
|
|
379
381
|
},
|
|
380
382
|
// Structural documents (e.g. the codebase survey's ingested findings) aren't dialogue — the
|
|
381
|
-
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply.
|
|
382
|
-
//
|
|
383
|
+
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply. A bigger chunk
|
|
384
|
+
// size (documents can run long) keeps the concrete facts/structure together instead.
|
|
383
385
|
document: {
|
|
384
386
|
retain_mission: DOCUMENT_MISSION,
|
|
385
|
-
retain_extraction_mode:
|
|
387
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
386
388
|
retain_chunk_size: 12e3
|
|
387
389
|
},
|
|
388
390
|
// Codebase-SURVEY lifecycle documents, ONE strategy with conditional rules: the survey's
|
|
@@ -455,9 +457,22 @@ var PAGE_TAXONOMY = [
|
|
|
455
457
|
tags: ["knowledge:feature-work"]
|
|
456
458
|
}
|
|
457
459
|
];
|
|
458
|
-
|
|
460
|
+
var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
461
|
+
function pagesFor(project, pages = {}, customPages = {}) {
|
|
459
462
|
const scope = pageScopeRule(project);
|
|
460
|
-
|
|
463
|
+
const byName = new Map(
|
|
464
|
+
Object.entries(pages).map(([name, override]) => [name.trim().toLowerCase(), override])
|
|
465
|
+
);
|
|
466
|
+
const out = [];
|
|
467
|
+
for (const page of PAGE_TAXONOMY) {
|
|
468
|
+
const override = byName.get(page.name.toLowerCase());
|
|
469
|
+
if (override === false) continue;
|
|
470
|
+
out.push({ ...page, source_query: (override?.source_query || page.source_query) + scope });
|
|
471
|
+
}
|
|
472
|
+
for (const [name, page] of Object.entries(customPages)) {
|
|
473
|
+
out.push({ name: name.trim(), source_query: page.source_query + scope, tags: page.tags ?? [] });
|
|
474
|
+
}
|
|
475
|
+
return out;
|
|
461
476
|
}
|
|
462
477
|
var PAGE_MAX_TOKENS = 4096;
|
|
463
478
|
var PAGE_TAGS_MATCH = "all";
|
|
@@ -540,7 +555,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
540
555
|
enable_observations: true,
|
|
541
556
|
observations_mission: OBSERVATIONS_MISSION,
|
|
542
557
|
retain_mission: GIT_MISSION,
|
|
543
|
-
retain_extraction_mode:
|
|
558
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
544
559
|
retain_default_strategy: "git",
|
|
545
560
|
retain_strategies: RETAIN_STRATEGIES,
|
|
546
561
|
entity_labels: [KNOWLEDGE_LABELS],
|
|
@@ -553,7 +568,7 @@ function isSet(v) {
|
|
|
553
568
|
if (typeof v === "string") return v.trim() !== "";
|
|
554
569
|
return true;
|
|
555
570
|
}
|
|
556
|
-
function codingBankManifest(overrides) {
|
|
571
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
557
572
|
const current2 = overrides ?? {};
|
|
558
573
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
559
574
|
const bank = {};
|
|
@@ -562,16 +577,22 @@ function codingBankManifest(overrides) {
|
|
|
562
577
|
bank.enable_observations = template.enable_observations;
|
|
563
578
|
bank.observations_mission = template.observations_mission;
|
|
564
579
|
bank.retain_mission = template.retain_mission;
|
|
565
|
-
bank.retain_extraction_mode =
|
|
580
|
+
bank.retain_extraction_mode = mode;
|
|
566
581
|
}
|
|
567
582
|
if (!isSet(current2.retain_default_strategy))
|
|
568
583
|
bank.retain_default_strategy = template.retain_default_strategy;
|
|
569
584
|
if (!isSet(current2.entities_allow_free_form))
|
|
570
585
|
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
571
586
|
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
587
|
+
const updates = {};
|
|
588
|
+
for (const [name, def] of Object.entries(template.retain_strategies)) {
|
|
589
|
+
const synced = def.retain_extraction_mode === "custom" ? {} : { retain_extraction_mode: mode };
|
|
590
|
+
const have = strategies[name];
|
|
591
|
+
if (!have || typeof have !== "object") updates[name] = { ...def, ...synced };
|
|
592
|
+
else if ("retain_extraction_mode" in synced && have.retain_extraction_mode !== mode)
|
|
593
|
+
updates[name] = { ...have, ...synced };
|
|
594
|
+
}
|
|
595
|
+
if (Object.keys(updates).length > 0) bank.retain_strategies = { ...strategies, ...updates };
|
|
575
596
|
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
576
597
|
const [knowledgeGroup] = template.entity_labels;
|
|
577
598
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
@@ -643,6 +664,14 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
643
664
|
this.name = "KnowledgePagesUnavailableError";
|
|
644
665
|
}
|
|
645
666
|
};
|
|
667
|
+
async function isEndpointMissing(r) {
|
|
668
|
+
try {
|
|
669
|
+
const j = await r.json();
|
|
670
|
+
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
671
|
+
} catch {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
646
675
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
647
676
|
var ReflectError = class extends Error {
|
|
648
677
|
constructor(message, status, timedOut, options) {
|
|
@@ -661,6 +690,13 @@ var ReflectError = class extends Error {
|
|
|
661
690
|
}
|
|
662
691
|
};
|
|
663
692
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
693
|
+
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
694
|
+
var DEFAULT_RECALL_OPTIONS = {
|
|
695
|
+
types: ["observation"],
|
|
696
|
+
budget: "low",
|
|
697
|
+
max_tokens: 2e3,
|
|
698
|
+
include: { entities: null }
|
|
699
|
+
};
|
|
664
700
|
var POLL_CYCLE_MS = 5e3;
|
|
665
701
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
666
702
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
@@ -681,6 +717,8 @@ var HindsightClient = class {
|
|
|
681
717
|
log;
|
|
682
718
|
maxParallelRetains;
|
|
683
719
|
observationScopes;
|
|
720
|
+
pageSearchLimit;
|
|
721
|
+
recallOptions;
|
|
684
722
|
constructor(o) {
|
|
685
723
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
686
724
|
this.token = o.apiToken;
|
|
@@ -691,6 +729,8 @@ var HindsightClient = class {
|
|
|
691
729
|
});
|
|
692
730
|
this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
|
|
693
731
|
this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
|
|
732
|
+
this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
|
|
733
|
+
this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
|
|
694
734
|
}
|
|
695
735
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
696
736
|
get apiToken() {
|
|
@@ -832,7 +872,8 @@ var HindsightClient = class {
|
|
|
832
872
|
}
|
|
833
873
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
834
874
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
835
|
-
* idempotent and
|
|
875
|
+
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
876
|
+
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
836
877
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
837
878
|
* continue with the template-only path.
|
|
838
879
|
*
|
|
@@ -848,7 +889,10 @@ var HindsightClient = class {
|
|
|
848
889
|
if (opts.manage === false) {
|
|
849
890
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
850
891
|
} else {
|
|
851
|
-
const manifest = codingBankManifest(
|
|
892
|
+
const manifest = codingBankManifest(
|
|
893
|
+
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
894
|
+
opts.extractionMode
|
|
895
|
+
);
|
|
852
896
|
if (!manifest) {
|
|
853
897
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
854
898
|
} else {
|
|
@@ -856,7 +900,7 @@ var HindsightClient = class {
|
|
|
856
900
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
857
901
|
}
|
|
858
902
|
}
|
|
859
|
-
await this.seedPages(opts.pageTrigger);
|
|
903
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
860
904
|
}
|
|
861
905
|
/**
|
|
862
906
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -972,20 +1016,22 @@ var HindsightClient = class {
|
|
|
972
1016
|
}
|
|
973
1017
|
}
|
|
974
1018
|
/**
|
|
975
|
-
* Raw recall
|
|
976
|
-
*
|
|
1019
|
+
* Raw recall with no LLM in the loop, so it still answers when reflect's synthesis times out or
|
|
1020
|
+
* 5xxs. The body is `recallOptions` (consolidated observations by default) — a bank that grows
|
|
1021
|
+
* no observations widens it rather than getting nothing back. Returns the texts in rank order.
|
|
1022
|
+
*
|
|
1023
|
+
* The name predates `recallOptions` (the observation type used to be hardcoded here) and is
|
|
1024
|
+
* kept deliberately: this is the client's published surface, so renaming it would break
|
|
1025
|
+
* importers for a cosmetic gain. The doc above is the contract, not the name.
|
|
977
1026
|
*/
|
|
978
1027
|
async recallObservations(query, opts) {
|
|
979
1028
|
const r = await this.req(
|
|
980
1029
|
"POST",
|
|
981
1030
|
this.bankUrl("/memories/recall"),
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
max_tokens: opts.maxTokens,
|
|
987
|
-
include: { entities: null }
|
|
988
|
-
},
|
|
1031
|
+
// `query` is applied AFTER the spread: everything else is the caller's to override, but a
|
|
1032
|
+
// config that could replace the goal with a fixed string would silently recall for the
|
|
1033
|
+
// wrong question on every turn.
|
|
1034
|
+
{ ...this.recallOptions, query },
|
|
989
1035
|
[],
|
|
990
1036
|
opts.timeoutMs
|
|
991
1037
|
);
|
|
@@ -993,6 +1039,19 @@ var HindsightClient = class {
|
|
|
993
1039
|
const j = await r.json();
|
|
994
1040
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
995
1041
|
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
|
|
1044
|
+
* Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
|
|
1045
|
+
* expected answer before the bank's first retain — so it must never cache a negative (#4607).
|
|
1046
|
+
*
|
|
1047
|
+
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1048
|
+
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1049
|
+
*/
|
|
1050
|
+
async pagesUnsupported(r) {
|
|
1051
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return false;
|
|
1052
|
+
this.knowledgePagesSupported = false;
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
996
1055
|
/**
|
|
997
1056
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
998
1057
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -1000,10 +1059,8 @@ var HindsightClient = class {
|
|
|
1000
1059
|
async tree() {
|
|
1001
1060
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1002
1061
|
const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
|
|
1003
|
-
if (
|
|
1004
|
-
|
|
1005
|
-
throw new KnowledgePagesUnavailableError();
|
|
1006
|
-
}
|
|
1062
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1063
|
+
if (r.status === 404) return [];
|
|
1007
1064
|
this.knowledgePagesSupported = true;
|
|
1008
1065
|
try {
|
|
1009
1066
|
return (await r.json()).roots ?? [];
|
|
@@ -1057,16 +1114,18 @@ var HindsightClient = class {
|
|
|
1057
1114
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1058
1115
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1059
1116
|
* hindsight_search_knowledge_pages. */
|
|
1060
|
-
async searchKnowledgePages(query,
|
|
1117
|
+
async searchKnowledgePages(query, opts = {}) {
|
|
1061
1118
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1062
|
-
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1119
|
+
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1063
1120
|
const r = await this.req(
|
|
1064
1121
|
"GET",
|
|
1065
1122
|
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1066
1123
|
void 0,
|
|
1067
1124
|
[],
|
|
1068
|
-
timeoutMs
|
|
1125
|
+
opts.timeoutMs
|
|
1069
1126
|
);
|
|
1127
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1128
|
+
if (r.status === 404) return [];
|
|
1070
1129
|
const j = await r.json();
|
|
1071
1130
|
return (j.results ?? []).map((x) => ({
|
|
1072
1131
|
id: x.id,
|
|
@@ -1086,8 +1145,8 @@ var HindsightClient = class {
|
|
|
1086
1145
|
* `source_query` re-syncs onto the live page instead of orphaning its synthesized content —
|
|
1087
1146
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1088
1147
|
*/
|
|
1089
|
-
async seedPages(pageTrigger = buildPageTrigger()) {
|
|
1090
|
-
const pages = pagesFor(this.project ?? this.bank);
|
|
1148
|
+
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1149
|
+
const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
|
|
1091
1150
|
const existing = /* @__PURE__ */ new Map();
|
|
1092
1151
|
let roots;
|
|
1093
1152
|
try {
|
|
@@ -1104,6 +1163,7 @@ var HindsightClient = class {
|
|
|
1104
1163
|
}
|
|
1105
1164
|
let created = 0;
|
|
1106
1165
|
let updated = 0;
|
|
1166
|
+
let vanished = 0;
|
|
1107
1167
|
for (const page of pages) {
|
|
1108
1168
|
const hit = existing.get(page.name.toLowerCase());
|
|
1109
1169
|
const body = {
|
|
@@ -1117,13 +1177,16 @@ var HindsightClient = class {
|
|
|
1117
1177
|
};
|
|
1118
1178
|
if (!hit) {
|
|
1119
1179
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
1120
|
-
if (
|
|
1121
|
-
this.knowledgePagesSupported = false;
|
|
1180
|
+
if (await this.pagesUnsupported(r)) {
|
|
1122
1181
|
this.log(
|
|
1123
1182
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1124
1183
|
);
|
|
1125
1184
|
return;
|
|
1126
1185
|
}
|
|
1186
|
+
if (r.status === 404) {
|
|
1187
|
+
this.log(`[bank] ${this.bank} does not exist yet; pages seed on the next session`);
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1127
1190
|
if (r.status !== 409) created++;
|
|
1128
1191
|
} else {
|
|
1129
1192
|
const sourceDrift = hit.description !== page.source_query;
|
|
@@ -1133,6 +1196,9 @@ var HindsightClient = class {
|
|
|
1133
1196
|
if (sourceDrift) {
|
|
1134
1197
|
patch.source_query = page.source_query;
|
|
1135
1198
|
patch.tags = page.tags;
|
|
1199
|
+
this.log(
|
|
1200
|
+
`[bank] re-syncing "${page.name}" to its configured source_query \u2014 set pages[${JSON.stringify(page.name)}].source_query to keep your own wording`
|
|
1201
|
+
);
|
|
1136
1202
|
}
|
|
1137
1203
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1138
1204
|
const r = await this.req(
|
|
@@ -1140,19 +1206,22 @@ var HindsightClient = class {
|
|
|
1140
1206
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
1141
1207
|
patch
|
|
1142
1208
|
);
|
|
1143
|
-
if (
|
|
1144
|
-
this.knowledgePagesSupported = false;
|
|
1209
|
+
if (await this.pagesUnsupported(r)) {
|
|
1145
1210
|
this.log(
|
|
1146
1211
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1147
1212
|
);
|
|
1148
1213
|
return;
|
|
1149
1214
|
}
|
|
1215
|
+
if (r.status === 404) {
|
|
1216
|
+
vanished++;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1150
1219
|
updated++;
|
|
1151
1220
|
}
|
|
1152
1221
|
}
|
|
1153
1222
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1154
1223
|
this.log(
|
|
1155
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged` + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1224
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated - vanished} unchanged` + (vanished ? `, ${vanished} deleted under us` : "") + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1156
1225
|
);
|
|
1157
1226
|
}
|
|
1158
1227
|
/**
|
|
@@ -1181,7 +1250,7 @@ var HindsightClient = class {
|
|
|
1181
1250
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1182
1251
|
{ trigger: pageTriggerPatch(desired) }
|
|
1183
1252
|
);
|
|
1184
|
-
if (
|
|
1253
|
+
if (r.status === 404) continue;
|
|
1185
1254
|
updated++;
|
|
1186
1255
|
}
|
|
1187
1256
|
return updated;
|
|
@@ -1349,6 +1418,63 @@ function resolvePageTrigger(raw) {
|
|
|
1349
1418
|
);
|
|
1350
1419
|
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1351
1420
|
}
|
|
1421
|
+
function resolvePages(raw) {
|
|
1422
|
+
const value = raw;
|
|
1423
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1424
|
+
const out = {};
|
|
1425
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
1426
|
+
if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
|
|
1427
|
+
log.warn(
|
|
1428
|
+
"config",
|
|
1429
|
+
`ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
|
|
1430
|
+
);
|
|
1431
|
+
continue;
|
|
1432
|
+
}
|
|
1433
|
+
if (entry === false) {
|
|
1434
|
+
out[name] = false;
|
|
1435
|
+
continue;
|
|
1436
|
+
}
|
|
1437
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1438
|
+
if (typeof query === "string" && query.trim()) {
|
|
1439
|
+
out[name] = { source_query: query };
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
log.warn(
|
|
1443
|
+
"config",
|
|
1444
|
+
`ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
|
|
1445
|
+
);
|
|
1446
|
+
}
|
|
1447
|
+
return out;
|
|
1448
|
+
}
|
|
1449
|
+
function resolveCustomPages(raw) {
|
|
1450
|
+
const value = raw;
|
|
1451
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1452
|
+
const out = {};
|
|
1453
|
+
for (const [rawName, entry] of Object.entries(value)) {
|
|
1454
|
+
const name = rawName.trim();
|
|
1455
|
+
if (!name) continue;
|
|
1456
|
+
if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
|
|
1457
|
+
log.warn(
|
|
1458
|
+
"config",
|
|
1459
|
+
`ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
|
|
1460
|
+
);
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1464
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
1465
|
+
log.warn(
|
|
1466
|
+
"config",
|
|
1467
|
+
`ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
|
|
1468
|
+
);
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
const rawTags = entry.tags;
|
|
1472
|
+
const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
|
|
1473
|
+
out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
|
|
1474
|
+
}
|
|
1475
|
+
return out;
|
|
1476
|
+
}
|
|
1477
|
+
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1352
1478
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1353
1479
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1354
1480
|
function resolveReflectBudget(raw) {
|
|
@@ -1376,6 +1502,15 @@ function resolveObservationScopes(raw) {
|
|
|
1376
1502
|
}
|
|
1377
1503
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1378
1504
|
}
|
|
1505
|
+
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1506
|
+
function resolveAutoInject(raw) {
|
|
1507
|
+
if (raw.autoReflect !== void 0) {
|
|
1508
|
+
const replacement = raw.autoReflect === false ? "none" : "reflect";
|
|
1509
|
+
log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
|
|
1510
|
+
}
|
|
1511
|
+
if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
|
|
1512
|
+
return raw.autoReflect === false ? "none" : "reflect";
|
|
1513
|
+
}
|
|
1379
1514
|
function resolveConfig(raw = {}) {
|
|
1380
1515
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1381
1516
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
@@ -1405,17 +1540,28 @@ function resolveConfig(raw = {}) {
|
|
|
1405
1540
|
retainSessions: raw.retainSessions ?? true,
|
|
1406
1541
|
// write sessions back by default, every harness
|
|
1407
1542
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1543
|
+
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1408
1544
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1409
|
-
reflectTimeoutMs: raw.reflectTimeoutMs ||
|
|
1545
|
+
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1410
1546
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1411
1547
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1412
1548
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1413
1549
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1414
1550
|
reflectBudget: resolveReflectBudget(raw),
|
|
1415
|
-
|
|
1416
|
-
|
|
1551
|
+
autoInject: resolveAutoInject(raw),
|
|
1552
|
+
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1553
|
+
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1554
|
+
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1555
|
+
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1556
|
+
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1557
|
+
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1558
|
+
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
1559
|
+
// with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
|
|
1560
|
+
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
|
|
1417
1561
|
pageTriggerType: pageTrigger.type,
|
|
1418
1562
|
pageTriggerCron: pageTrigger.cron,
|
|
1563
|
+
pages: resolvePages(raw.pages),
|
|
1564
|
+
customPages: resolveCustomPages(raw.customPages),
|
|
1419
1565
|
autoSeed: raw.autoSeed ?? true,
|
|
1420
1566
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1421
1567
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1479,6 +1625,8 @@ var ENV_KEYS = {
|
|
|
1479
1625
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1480
1626
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1481
1627
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1628
|
+
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1629
|
+
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1482
1630
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1483
1631
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1484
1632
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1498,7 +1646,8 @@ var ENV_KEYS = {
|
|
|
1498
1646
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1499
1647
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1500
1648
|
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1501
|
-
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1649
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
|
|
1650
|
+
retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
|
|
1502
1651
|
};
|
|
1503
1652
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1504
1653
|
"dynamicBankId",
|
|
@@ -1519,6 +1668,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1519
1668
|
"maxParallelRetains",
|
|
1520
1669
|
"reflectTimeoutMs",
|
|
1521
1670
|
"reflectToolTimeoutMs",
|
|
1671
|
+
"pageSearchLimit",
|
|
1522
1672
|
"pageRefreshEveryTurns",
|
|
1523
1673
|
"seedLimit",
|
|
1524
1674
|
"surveyBudgetUsd",
|
|
@@ -1582,6 +1732,7 @@ function resolvePartial(cfg2, patch) {
|
|
|
1582
1732
|
if (key in full)
|
|
1583
1733
|
out[key] = full[key];
|
|
1584
1734
|
}
|
|
1735
|
+
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1585
1736
|
return out;
|
|
1586
1737
|
}
|
|
1587
1738
|
|
|
@@ -1594,7 +1745,10 @@ function git(repo, ...args) {
|
|
|
1594
1745
|
return execFileSync("git", ["-C", repo, ...args], {
|
|
1595
1746
|
encoding: "utf8",
|
|
1596
1747
|
maxBuffer: 1 << 28,
|
|
1597
|
-
windowsHide: true
|
|
1748
|
+
windowsHide: true,
|
|
1749
|
+
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
1750
|
+
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
1751
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1598
1752
|
});
|
|
1599
1753
|
}
|
|
1600
1754
|
function repoNameOf(repo) {
|
|
@@ -2017,7 +2171,10 @@ async function main() {
|
|
|
2017
2171
|
});
|
|
2018
2172
|
await client.configureBank({
|
|
2019
2173
|
pageTrigger: buildPageTrigger(cfg),
|
|
2020
|
-
|
|
2174
|
+
pages: cfg.pages,
|
|
2175
|
+
customPages: cfg.customPages,
|
|
2176
|
+
manage: cfg.manageBankConfig,
|
|
2177
|
+
extractionMode: cfg.retainExtractionMode
|
|
2021
2178
|
});
|
|
2022
2179
|
if (client.knowledgePagesSupported === false) {
|
|
2023
2180
|
diag(harness.name, "knowledge_pages_unavailable", {
|