@vectorize-io/hindsight-coding-agents 0.6.0 → 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 +344 -169
- package/dist/antigravity-statusline.js +117 -4
- package/dist/antigravity-stop-hook.js +262 -113
- package/dist/claude-hook.js +344 -169
- package/dist/claude-sessionstart-hook.js +348 -136
- package/dist/claude-stop-hook.js +262 -113
- package/dist/cline.js +494 -184
- package/dist/codex-hook.js +344 -169
- package/dist/codex-sessionstart-hook.js +348 -136
- package/dist/codex-stop-hook.js +262 -113
- package/dist/copilot-hook.js +344 -169
- package/dist/copilot-sessionstart-hook.js +348 -136
- package/dist/copilot-stop-hook.js +262 -113
- package/dist/cursor-hook.js +344 -169
- 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 +344 -169
- 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 +344 -169
- package/dist/devin-sessionstart-hook.js +348 -136
- package/dist/devin-stop-hook.js +262 -113
- package/dist/droid-hook.js +344 -169
- package/dist/droid-sessionstart-hook.js +348 -136
- package/dist/droid-stop-hook.js +262 -113
- package/dist/dsh.js +494 -184
- package/dist/grok-hook.js +344 -169
- 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 +494 -184
- package/dist/installer.js +92 -70
- package/dist/kilo.js +494 -184
- package/dist/mcp-server.js +230 -57
- package/dist/opencode2.js +521 -184
- package/dist/pi.js +495 -186
- package/dist/prime-agent.js +495 -186
- package/dist/qwen-hook.js +344 -169
- 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 +344 -169
- 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/status.js
CHANGED
|
@@ -332,13 +332,15 @@ var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSON
|
|
|
332
332
|
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.";
|
|
333
333
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
334
334
|
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.";
|
|
335
|
+
var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
|
|
336
|
+
var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
|
|
335
337
|
var RETAIN_STRATEGIES = {
|
|
336
|
-
git: { retain_mission: GIT_MISSION, retain_extraction_mode:
|
|
338
|
+
git: { retain_mission: GIT_MISSION, retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE },
|
|
337
339
|
// ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
|
|
338
340
|
// in as few chunks as possible and the extractor sees the whole history arc at once.
|
|
339
341
|
gitlog: {
|
|
340
342
|
retain_mission: GITLOG_MISSION,
|
|
341
|
-
retain_extraction_mode:
|
|
343
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
342
344
|
retain_chunk_size: 12e3
|
|
343
345
|
},
|
|
344
346
|
// ONE strategy for ALL developer conversations — backfilled decision chats and live working
|
|
@@ -349,15 +351,15 @@ var RETAIN_STRATEGIES = {
|
|
|
349
351
|
// the consolidation layer.
|
|
350
352
|
conversation: {
|
|
351
353
|
retain_mission: CONVERSATION_MISSION,
|
|
352
|
-
retain_extraction_mode:
|
|
354
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
353
355
|
retain_chunk_size: 12e3
|
|
354
356
|
},
|
|
355
357
|
// Structural documents (e.g. the codebase survey's ingested findings) aren't dialogue — the
|
|
356
|
-
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply.
|
|
357
|
-
//
|
|
358
|
+
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply. A bigger chunk
|
|
359
|
+
// size (documents can run long) keeps the concrete facts/structure together instead.
|
|
358
360
|
document: {
|
|
359
361
|
retain_mission: DOCUMENT_MISSION,
|
|
360
|
-
retain_extraction_mode:
|
|
362
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
361
363
|
retain_chunk_size: 12e3
|
|
362
364
|
},
|
|
363
365
|
// Codebase-SURVEY lifecycle documents, ONE strategy with conditional rules: the survey's
|
|
@@ -430,9 +432,22 @@ var PAGE_TAXONOMY = [
|
|
|
430
432
|
tags: ["knowledge:feature-work"]
|
|
431
433
|
}
|
|
432
434
|
];
|
|
433
|
-
|
|
435
|
+
var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
436
|
+
function pagesFor(project, pages = {}, customPages = {}) {
|
|
434
437
|
const scope = pageScopeRule(project);
|
|
435
|
-
|
|
438
|
+
const byName = new Map(
|
|
439
|
+
Object.entries(pages).map(([name, override]) => [name.trim().toLowerCase(), override])
|
|
440
|
+
);
|
|
441
|
+
const out = [];
|
|
442
|
+
for (const page of PAGE_TAXONOMY) {
|
|
443
|
+
const override = byName.get(page.name.toLowerCase());
|
|
444
|
+
if (override === false) continue;
|
|
445
|
+
out.push({ ...page, source_query: (override?.source_query || page.source_query) + scope });
|
|
446
|
+
}
|
|
447
|
+
for (const [name, page] of Object.entries(customPages)) {
|
|
448
|
+
out.push({ name: name.trim(), source_query: page.source_query + scope, tags: page.tags ?? [] });
|
|
449
|
+
}
|
|
450
|
+
return out;
|
|
436
451
|
}
|
|
437
452
|
var PAGE_MAX_TOKENS = 4096;
|
|
438
453
|
var PAGE_TAGS_MATCH = "all";
|
|
@@ -515,7 +530,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
515
530
|
enable_observations: true,
|
|
516
531
|
observations_mission: OBSERVATIONS_MISSION,
|
|
517
532
|
retain_mission: GIT_MISSION,
|
|
518
|
-
retain_extraction_mode:
|
|
533
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
519
534
|
retain_default_strategy: "git",
|
|
520
535
|
retain_strategies: RETAIN_STRATEGIES,
|
|
521
536
|
entity_labels: [KNOWLEDGE_LABELS],
|
|
@@ -528,7 +543,7 @@ function isSet(v) {
|
|
|
528
543
|
if (typeof v === "string") return v.trim() !== "";
|
|
529
544
|
return true;
|
|
530
545
|
}
|
|
531
|
-
function codingBankManifest(overrides) {
|
|
546
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
532
547
|
const current2 = overrides ?? {};
|
|
533
548
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
534
549
|
const bank = {};
|
|
@@ -537,16 +552,22 @@ function codingBankManifest(overrides) {
|
|
|
537
552
|
bank.enable_observations = template.enable_observations;
|
|
538
553
|
bank.observations_mission = template.observations_mission;
|
|
539
554
|
bank.retain_mission = template.retain_mission;
|
|
540
|
-
bank.retain_extraction_mode =
|
|
555
|
+
bank.retain_extraction_mode = mode;
|
|
541
556
|
}
|
|
542
557
|
if (!isSet(current2.retain_default_strategy))
|
|
543
558
|
bank.retain_default_strategy = template.retain_default_strategy;
|
|
544
559
|
if (!isSet(current2.entities_allow_free_form))
|
|
545
560
|
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
546
561
|
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
562
|
+
const updates = {};
|
|
563
|
+
for (const [name, def] of Object.entries(template.retain_strategies)) {
|
|
564
|
+
const synced = def.retain_extraction_mode === "custom" ? {} : { retain_extraction_mode: mode };
|
|
565
|
+
const have = strategies[name];
|
|
566
|
+
if (!have || typeof have !== "object") updates[name] = { ...def, ...synced };
|
|
567
|
+
else if ("retain_extraction_mode" in synced && have.retain_extraction_mode !== mode)
|
|
568
|
+
updates[name] = { ...have, ...synced };
|
|
569
|
+
}
|
|
570
|
+
if (Object.keys(updates).length > 0) bank.retain_strategies = { ...strategies, ...updates };
|
|
550
571
|
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
551
572
|
const [knowledgeGroup] = template.entity_labels;
|
|
552
573
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
@@ -618,6 +639,14 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
618
639
|
this.name = "KnowledgePagesUnavailableError";
|
|
619
640
|
}
|
|
620
641
|
};
|
|
642
|
+
async function isEndpointMissing(r) {
|
|
643
|
+
try {
|
|
644
|
+
const j = await r.json();
|
|
645
|
+
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
646
|
+
} catch {
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
621
650
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
622
651
|
var ReflectError = class extends Error {
|
|
623
652
|
constructor(message, status, timedOut, options) {
|
|
@@ -636,6 +665,13 @@ var ReflectError = class extends Error {
|
|
|
636
665
|
}
|
|
637
666
|
};
|
|
638
667
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
668
|
+
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
669
|
+
var DEFAULT_RECALL_OPTIONS = {
|
|
670
|
+
types: ["observation"],
|
|
671
|
+
budget: "low",
|
|
672
|
+
max_tokens: 2e3,
|
|
673
|
+
include: { entities: null }
|
|
674
|
+
};
|
|
639
675
|
var POLL_CYCLE_MS = 5e3;
|
|
640
676
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
641
677
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
@@ -656,6 +692,8 @@ var HindsightClient = class {
|
|
|
656
692
|
log;
|
|
657
693
|
maxParallelRetains;
|
|
658
694
|
observationScopes;
|
|
695
|
+
pageSearchLimit;
|
|
696
|
+
recallOptions;
|
|
659
697
|
constructor(o) {
|
|
660
698
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
661
699
|
this.token = o.apiToken;
|
|
@@ -666,6 +704,8 @@ var HindsightClient = class {
|
|
|
666
704
|
});
|
|
667
705
|
this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
|
|
668
706
|
this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
|
|
707
|
+
this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
|
|
708
|
+
this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
|
|
669
709
|
}
|
|
670
710
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
671
711
|
get apiToken() {
|
|
@@ -807,7 +847,8 @@ var HindsightClient = class {
|
|
|
807
847
|
}
|
|
808
848
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
809
849
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
810
|
-
* idempotent and
|
|
850
|
+
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
851
|
+
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
811
852
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
812
853
|
* continue with the template-only path.
|
|
813
854
|
*
|
|
@@ -823,7 +864,10 @@ var HindsightClient = class {
|
|
|
823
864
|
if (opts.manage === false) {
|
|
824
865
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
825
866
|
} else {
|
|
826
|
-
const manifest = codingBankManifest(
|
|
867
|
+
const manifest = codingBankManifest(
|
|
868
|
+
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
869
|
+
opts.extractionMode
|
|
870
|
+
);
|
|
827
871
|
if (!manifest) {
|
|
828
872
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
829
873
|
} else {
|
|
@@ -831,7 +875,7 @@ var HindsightClient = class {
|
|
|
831
875
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
832
876
|
}
|
|
833
877
|
}
|
|
834
|
-
await this.seedPages(opts.pageTrigger);
|
|
878
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
835
879
|
}
|
|
836
880
|
/**
|
|
837
881
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -947,20 +991,22 @@ var HindsightClient = class {
|
|
|
947
991
|
}
|
|
948
992
|
}
|
|
949
993
|
/**
|
|
950
|
-
* Raw recall
|
|
951
|
-
*
|
|
994
|
+
* Raw recall with no LLM in the loop, so it still answers when reflect's synthesis times out or
|
|
995
|
+
* 5xxs. The body is `recallOptions` (consolidated observations by default) — a bank that grows
|
|
996
|
+
* no observations widens it rather than getting nothing back. Returns the texts in rank order.
|
|
997
|
+
*
|
|
998
|
+
* The name predates `recallOptions` (the observation type used to be hardcoded here) and is
|
|
999
|
+
* kept deliberately: this is the client's published surface, so renaming it would break
|
|
1000
|
+
* importers for a cosmetic gain. The doc above is the contract, not the name.
|
|
952
1001
|
*/
|
|
953
1002
|
async recallObservations(query, opts) {
|
|
954
1003
|
const r = await this.req(
|
|
955
1004
|
"POST",
|
|
956
1005
|
this.bankUrl("/memories/recall"),
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
max_tokens: opts.maxTokens,
|
|
962
|
-
include: { entities: null }
|
|
963
|
-
},
|
|
1006
|
+
// `query` is applied AFTER the spread: everything else is the caller's to override, but a
|
|
1007
|
+
// config that could replace the goal with a fixed string would silently recall for the
|
|
1008
|
+
// wrong question on every turn.
|
|
1009
|
+
{ ...this.recallOptions, query },
|
|
964
1010
|
[],
|
|
965
1011
|
opts.timeoutMs
|
|
966
1012
|
);
|
|
@@ -968,6 +1014,19 @@ var HindsightClient = class {
|
|
|
968
1014
|
const j = await r.json();
|
|
969
1015
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
970
1016
|
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
|
|
1019
|
+
* Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
|
|
1020
|
+
* expected answer before the bank's first retain — so it must never cache a negative (#4607).
|
|
1021
|
+
*
|
|
1022
|
+
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1023
|
+
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1024
|
+
*/
|
|
1025
|
+
async pagesUnsupported(r) {
|
|
1026
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return false;
|
|
1027
|
+
this.knowledgePagesSupported = false;
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
971
1030
|
/**
|
|
972
1031
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
973
1032
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -975,10 +1034,8 @@ var HindsightClient = class {
|
|
|
975
1034
|
async tree() {
|
|
976
1035
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
977
1036
|
const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
throw new KnowledgePagesUnavailableError();
|
|
981
|
-
}
|
|
1037
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1038
|
+
if (r.status === 404) return [];
|
|
982
1039
|
this.knowledgePagesSupported = true;
|
|
983
1040
|
try {
|
|
984
1041
|
return (await r.json()).roots ?? [];
|
|
@@ -1032,16 +1089,18 @@ var HindsightClient = class {
|
|
|
1032
1089
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1033
1090
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1034
1091
|
* hindsight_search_knowledge_pages. */
|
|
1035
|
-
async searchKnowledgePages(query,
|
|
1092
|
+
async searchKnowledgePages(query, opts = {}) {
|
|
1036
1093
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1037
|
-
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1094
|
+
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1038
1095
|
const r = await this.req(
|
|
1039
1096
|
"GET",
|
|
1040
1097
|
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1041
1098
|
void 0,
|
|
1042
1099
|
[],
|
|
1043
|
-
timeoutMs
|
|
1100
|
+
opts.timeoutMs
|
|
1044
1101
|
);
|
|
1102
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1103
|
+
if (r.status === 404) return [];
|
|
1045
1104
|
const j = await r.json();
|
|
1046
1105
|
return (j.results ?? []).map((x) => ({
|
|
1047
1106
|
id: x.id,
|
|
@@ -1061,8 +1120,8 @@ var HindsightClient = class {
|
|
|
1061
1120
|
* `source_query` re-syncs onto the live page instead of orphaning its synthesized content —
|
|
1062
1121
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1063
1122
|
*/
|
|
1064
|
-
async seedPages(pageTrigger = buildPageTrigger()) {
|
|
1065
|
-
const pages = pagesFor(this.project ?? this.bank);
|
|
1123
|
+
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1124
|
+
const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
|
|
1066
1125
|
const existing = /* @__PURE__ */ new Map();
|
|
1067
1126
|
let roots;
|
|
1068
1127
|
try {
|
|
@@ -1079,6 +1138,7 @@ var HindsightClient = class {
|
|
|
1079
1138
|
}
|
|
1080
1139
|
let created = 0;
|
|
1081
1140
|
let updated = 0;
|
|
1141
|
+
let vanished = 0;
|
|
1082
1142
|
for (const page of pages) {
|
|
1083
1143
|
const hit = existing.get(page.name.toLowerCase());
|
|
1084
1144
|
const body = {
|
|
@@ -1092,13 +1152,16 @@ var HindsightClient = class {
|
|
|
1092
1152
|
};
|
|
1093
1153
|
if (!hit) {
|
|
1094
1154
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
1095
|
-
if (
|
|
1096
|
-
this.knowledgePagesSupported = false;
|
|
1155
|
+
if (await this.pagesUnsupported(r)) {
|
|
1097
1156
|
this.log(
|
|
1098
1157
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1099
1158
|
);
|
|
1100
1159
|
return;
|
|
1101
1160
|
}
|
|
1161
|
+
if (r.status === 404) {
|
|
1162
|
+
this.log(`[bank] ${this.bank} does not exist yet; pages seed on the next session`);
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1102
1165
|
if (r.status !== 409) created++;
|
|
1103
1166
|
} else {
|
|
1104
1167
|
const sourceDrift = hit.description !== page.source_query;
|
|
@@ -1108,6 +1171,9 @@ var HindsightClient = class {
|
|
|
1108
1171
|
if (sourceDrift) {
|
|
1109
1172
|
patch.source_query = page.source_query;
|
|
1110
1173
|
patch.tags = page.tags;
|
|
1174
|
+
this.log(
|
|
1175
|
+
`[bank] re-syncing "${page.name}" to its configured source_query \u2014 set pages[${JSON.stringify(page.name)}].source_query to keep your own wording`
|
|
1176
|
+
);
|
|
1111
1177
|
}
|
|
1112
1178
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1113
1179
|
const r = await this.req(
|
|
@@ -1115,19 +1181,22 @@ var HindsightClient = class {
|
|
|
1115
1181
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
1116
1182
|
patch
|
|
1117
1183
|
);
|
|
1118
|
-
if (
|
|
1119
|
-
this.knowledgePagesSupported = false;
|
|
1184
|
+
if (await this.pagesUnsupported(r)) {
|
|
1120
1185
|
this.log(
|
|
1121
1186
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1122
1187
|
);
|
|
1123
1188
|
return;
|
|
1124
1189
|
}
|
|
1190
|
+
if (r.status === 404) {
|
|
1191
|
+
vanished++;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1125
1194
|
updated++;
|
|
1126
1195
|
}
|
|
1127
1196
|
}
|
|
1128
1197
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1129
1198
|
this.log(
|
|
1130
|
-
`[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` : "")
|
|
1199
|
+
`[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` : "")
|
|
1131
1200
|
);
|
|
1132
1201
|
}
|
|
1133
1202
|
/**
|
|
@@ -1156,7 +1225,7 @@ var HindsightClient = class {
|
|
|
1156
1225
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1157
1226
|
{ trigger: pageTriggerPatch(desired) }
|
|
1158
1227
|
);
|
|
1159
|
-
if (
|
|
1228
|
+
if (r.status === 404) continue;
|
|
1160
1229
|
updated++;
|
|
1161
1230
|
}
|
|
1162
1231
|
return updated;
|
|
@@ -1248,6 +1317,63 @@ function resolvePageTrigger(raw) {
|
|
|
1248
1317
|
);
|
|
1249
1318
|
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1250
1319
|
}
|
|
1320
|
+
function resolvePages(raw) {
|
|
1321
|
+
const value = raw;
|
|
1322
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1323
|
+
const out = {};
|
|
1324
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
1325
|
+
if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
|
|
1326
|
+
log.warn(
|
|
1327
|
+
"config",
|
|
1328
|
+
`ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
|
|
1329
|
+
);
|
|
1330
|
+
continue;
|
|
1331
|
+
}
|
|
1332
|
+
if (entry === false) {
|
|
1333
|
+
out[name] = false;
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1337
|
+
if (typeof query === "string" && query.trim()) {
|
|
1338
|
+
out[name] = { source_query: query };
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
log.warn(
|
|
1342
|
+
"config",
|
|
1343
|
+
`ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
return out;
|
|
1347
|
+
}
|
|
1348
|
+
function resolveCustomPages(raw) {
|
|
1349
|
+
const value = raw;
|
|
1350
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1351
|
+
const out = {};
|
|
1352
|
+
for (const [rawName, entry] of Object.entries(value)) {
|
|
1353
|
+
const name = rawName.trim();
|
|
1354
|
+
if (!name) continue;
|
|
1355
|
+
if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
|
|
1356
|
+
log.warn(
|
|
1357
|
+
"config",
|
|
1358
|
+
`ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
|
|
1359
|
+
);
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1363
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
1364
|
+
log.warn(
|
|
1365
|
+
"config",
|
|
1366
|
+
`ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
|
|
1367
|
+
);
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
const rawTags = entry.tags;
|
|
1371
|
+
const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
|
|
1372
|
+
out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
|
|
1373
|
+
}
|
|
1374
|
+
return out;
|
|
1375
|
+
}
|
|
1376
|
+
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1251
1377
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1252
1378
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1253
1379
|
function resolveReflectBudget(raw) {
|
|
@@ -1275,6 +1401,15 @@ function resolveObservationScopes(raw) {
|
|
|
1275
1401
|
}
|
|
1276
1402
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1277
1403
|
}
|
|
1404
|
+
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1405
|
+
function resolveAutoInject(raw) {
|
|
1406
|
+
if (raw.autoReflect !== void 0) {
|
|
1407
|
+
const replacement = raw.autoReflect === false ? "none" : "reflect";
|
|
1408
|
+
log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
|
|
1409
|
+
}
|
|
1410
|
+
if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
|
|
1411
|
+
return raw.autoReflect === false ? "none" : "reflect";
|
|
1412
|
+
}
|
|
1278
1413
|
function resolveConfig(raw = {}) {
|
|
1279
1414
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1280
1415
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
@@ -1304,17 +1439,28 @@ function resolveConfig(raw = {}) {
|
|
|
1304
1439
|
retainSessions: raw.retainSessions ?? true,
|
|
1305
1440
|
// write sessions back by default, every harness
|
|
1306
1441
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1442
|
+
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1307
1443
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1308
|
-
reflectTimeoutMs: raw.reflectTimeoutMs ||
|
|
1444
|
+
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1309
1445
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1310
1446
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1311
1447
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1312
1448
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1313
1449
|
reflectBudget: resolveReflectBudget(raw),
|
|
1314
|
-
|
|
1315
|
-
|
|
1450
|
+
autoInject: resolveAutoInject(raw),
|
|
1451
|
+
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1452
|
+
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1453
|
+
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1454
|
+
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1455
|
+
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1456
|
+
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1457
|
+
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
1458
|
+
// with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
|
|
1459
|
+
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
|
|
1316
1460
|
pageTriggerType: pageTrigger.type,
|
|
1317
1461
|
pageTriggerCron: pageTrigger.cron,
|
|
1462
|
+
pages: resolvePages(raw.pages),
|
|
1463
|
+
customPages: resolveCustomPages(raw.customPages),
|
|
1318
1464
|
autoSeed: raw.autoSeed ?? true,
|
|
1319
1465
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1320
1466
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1378,6 +1524,8 @@ var ENV_KEYS = {
|
|
|
1378
1524
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1379
1525
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1380
1526
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1527
|
+
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1528
|
+
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1381
1529
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1382
1530
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1383
1531
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1397,7 +1545,8 @@ var ENV_KEYS = {
|
|
|
1397
1545
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1398
1546
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1399
1547
|
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1400
|
-
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1548
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
|
|
1549
|
+
retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
|
|
1401
1550
|
};
|
|
1402
1551
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1403
1552
|
"dynamicBankId",
|
|
@@ -1418,6 +1567,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1418
1567
|
"maxParallelRetains",
|
|
1419
1568
|
"reflectTimeoutMs",
|
|
1420
1569
|
"reflectToolTimeoutMs",
|
|
1570
|
+
"pageSearchLimit",
|
|
1421
1571
|
"pageRefreshEveryTurns",
|
|
1422
1572
|
"seedLimit",
|
|
1423
1573
|
"surveyBudgetUsd",
|
|
@@ -1481,6 +1631,7 @@ function resolvePartial(cfg2, patch) {
|
|
|
1481
1631
|
if (key in full)
|
|
1482
1632
|
out[key] = full[key];
|
|
1483
1633
|
}
|
|
1634
|
+
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1484
1635
|
return out;
|
|
1485
1636
|
}
|
|
1486
1637
|
|
|
@@ -1494,7 +1645,10 @@ function git(repo, ...args) {
|
|
|
1494
1645
|
return execFileSync("git", ["-C", repo, ...args], {
|
|
1495
1646
|
encoding: "utf8",
|
|
1496
1647
|
maxBuffer: 1 << 28,
|
|
1497
|
-
windowsHide: true
|
|
1648
|
+
windowsHide: true,
|
|
1649
|
+
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
1650
|
+
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
1651
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1498
1652
|
});
|
|
1499
1653
|
}
|
|
1500
1654
|
function repoNameOf(repo) {
|
|
@@ -1561,7 +1715,9 @@ function commitCount(repoDir) {
|
|
|
1561
1715
|
try {
|
|
1562
1716
|
const out = execFileSync2("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
|
|
1563
1717
|
encoding: "utf8",
|
|
1564
|
-
windowsHide: true
|
|
1718
|
+
windowsHide: true,
|
|
1719
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1720
|
+
// failed probes must not write into the host TUI
|
|
1565
1721
|
});
|
|
1566
1722
|
return Number(out.trim()) || 0;
|
|
1567
1723
|
} catch {
|