@vectorize-io/hindsight-coding-agents 0.6.1 → 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 +314 -51
- package/dist/antigravity-hook.js +1039 -198
- package/dist/antigravity-statusline.js +185 -11
- package/dist/antigravity-stop-hook.js +1026 -163
- package/dist/claude-hook.js +1039 -198
- package/dist/claude-sessionstart-hook.js +1123 -190
- package/dist/claude-stop-hook.js +1026 -163
- package/dist/cline.js +749 -209
- package/dist/codex-hook.js +1039 -198
- package/dist/codex-sessionstart-hook.js +1123 -190
- package/dist/codex-stop-hook.js +1026 -163
- package/dist/copilot-hook.js +1039 -198
- package/dist/copilot-sessionstart-hook.js +1123 -190
- package/dist/copilot-stop-hook.js +1026 -163
- package/dist/cursor-hook.js +1039 -198
- package/dist/cursor-sessionstart-hook.js +1123 -190
- package/dist/cursor-stop-hook.js +1026 -163
- package/dist/daemon-start.js +154 -5
- package/dist/dcode-hook.js +1039 -198
- package/dist/dcode-sessionstart-hook.js +1123 -190
- package/dist/dcode-stop-hook.js +1026 -163
- package/dist/deepen.js +437 -105
- package/dist/devin-hook.js +1039 -198
- package/dist/devin-sessionstart-hook.js +1123 -190
- package/dist/devin-stop-hook.js +1026 -163
- package/dist/droid-hook.js +1039 -198
- package/dist/droid-sessionstart-hook.js +1123 -190
- package/dist/droid-stop-hook.js +1026 -163
- package/dist/dsh.js +750 -210
- package/dist/grok-hook.js +1039 -198
- package/dist/grok-sessionstart-hook.js +1123 -190
- package/dist/grok-stop-hook.js +1026 -163
- package/dist/hindsight-seed.js +157 -8
- package/dist/index.js +749 -209
- package/dist/installer.js +1233 -366
- package/dist/kilo.js +749 -209
- 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 +373 -71
- package/dist/opencode2.js +778 -209
- package/dist/pi.js +754 -211
- package/dist/prime-agent.js +754 -211
- package/dist/qwen-hook.js +1039 -198
- package/dist/qwen-sessionstart-hook.js +1123 -190
- package/dist/qwen-stop-hook.js +1026 -163
- package/dist/status.js +333 -59
- 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 +1039 -198
- package/dist/zcode-sessionstart-hook.js +1123 -190
- package/dist/zcode-stop-hook.js +1026 -163
- package/package.json +15 -11
- package/plugin.json +1 -1
- package/skill/SKILL.md +241 -48
package/dist/status.js
CHANGED
|
@@ -250,13 +250,13 @@ function isWithin(directory, configured) {
|
|
|
250
250
|
function mapLookup(map, directory) {
|
|
251
251
|
const cwd = normalize(directory);
|
|
252
252
|
let best;
|
|
253
|
-
for (const [dir,
|
|
253
|
+
for (const [dir, value] of Object.entries(map)) {
|
|
254
254
|
const p = configuredDir(dir);
|
|
255
255
|
if (isWithin(cwd, p)) {
|
|
256
|
-
if (!best || p.length > best.len) best = { len: p.length,
|
|
256
|
+
if (!best || p.length > best.len) best = { len: p.length, value };
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
return best?.
|
|
259
|
+
return best?.value;
|
|
260
260
|
}
|
|
261
261
|
function lookupDirectories(config, directory, sessionRoot = "") {
|
|
262
262
|
const directories = [normalize(directory)];
|
|
@@ -280,6 +280,10 @@ function isOptedIn(config, directory) {
|
|
|
280
280
|
const pathMap = config.mapPathToBank;
|
|
281
281
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
282
282
|
}
|
|
283
|
+
function pathSection(config, paths, directory) {
|
|
284
|
+
if (!directory || !paths) return void 0;
|
|
285
|
+
return lookupDirectories(config, directory).map((candidate) => mapLookup(paths, candidate)).find((section) => section !== void 0);
|
|
286
|
+
}
|
|
283
287
|
function mappedBank(config, directory, sessionRoot) {
|
|
284
288
|
const pathMap = config.mapPathToBank;
|
|
285
289
|
if (!directory || !pathMap) return void 0;
|
|
@@ -332,13 +336,15 @@ var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSON
|
|
|
332
336
|
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
337
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
334
338
|
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.";
|
|
339
|
+
var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
|
|
340
|
+
var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
|
|
335
341
|
var RETAIN_STRATEGIES = {
|
|
336
|
-
git: { retain_mission: GIT_MISSION, retain_extraction_mode:
|
|
342
|
+
git: { retain_mission: GIT_MISSION, retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE },
|
|
337
343
|
// ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
|
|
338
344
|
// in as few chunks as possible and the extractor sees the whole history arc at once.
|
|
339
345
|
gitlog: {
|
|
340
346
|
retain_mission: GITLOG_MISSION,
|
|
341
|
-
retain_extraction_mode:
|
|
347
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
342
348
|
retain_chunk_size: 12e3
|
|
343
349
|
},
|
|
344
350
|
// ONE strategy for ALL developer conversations — backfilled decision chats and live working
|
|
@@ -349,15 +355,15 @@ var RETAIN_STRATEGIES = {
|
|
|
349
355
|
// the consolidation layer.
|
|
350
356
|
conversation: {
|
|
351
357
|
retain_mission: CONVERSATION_MISSION,
|
|
352
|
-
retain_extraction_mode:
|
|
358
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
353
359
|
retain_chunk_size: 12e3
|
|
354
360
|
},
|
|
355
361
|
// 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
|
-
//
|
|
362
|
+
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply. A bigger chunk
|
|
363
|
+
// size (documents can run long) keeps the concrete facts/structure together instead.
|
|
358
364
|
document: {
|
|
359
365
|
retain_mission: DOCUMENT_MISSION,
|
|
360
|
-
retain_extraction_mode:
|
|
366
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
361
367
|
retain_chunk_size: 12e3
|
|
362
368
|
},
|
|
363
369
|
// Codebase-SURVEY lifecycle documents, ONE strategy with conditional rules: the survey's
|
|
@@ -430,9 +436,22 @@ var PAGE_TAXONOMY = [
|
|
|
430
436
|
tags: ["knowledge:feature-work"]
|
|
431
437
|
}
|
|
432
438
|
];
|
|
433
|
-
|
|
439
|
+
var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
440
|
+
function pagesFor(project, pages = {}, customPages = {}) {
|
|
434
441
|
const scope = pageScopeRule(project);
|
|
435
|
-
|
|
442
|
+
const byName = new Map(
|
|
443
|
+
Object.entries(pages).map(([name, override]) => [name.trim().toLowerCase(), override])
|
|
444
|
+
);
|
|
445
|
+
const out = [];
|
|
446
|
+
for (const page of PAGE_TAXONOMY) {
|
|
447
|
+
const override = byName.get(page.name.toLowerCase());
|
|
448
|
+
if (override === false) continue;
|
|
449
|
+
out.push({ ...page, source_query: (override?.source_query || page.source_query) + scope });
|
|
450
|
+
}
|
|
451
|
+
for (const [name, page] of Object.entries(customPages)) {
|
|
452
|
+
out.push({ name: name.trim(), source_query: page.source_query + scope, tags: page.tags ?? [] });
|
|
453
|
+
}
|
|
454
|
+
return out;
|
|
436
455
|
}
|
|
437
456
|
var PAGE_MAX_TOKENS = 4096;
|
|
438
457
|
var PAGE_TAGS_MATCH = "all";
|
|
@@ -515,7 +534,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
515
534
|
enable_observations: true,
|
|
516
535
|
observations_mission: OBSERVATIONS_MISSION,
|
|
517
536
|
retain_mission: GIT_MISSION,
|
|
518
|
-
retain_extraction_mode:
|
|
537
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
519
538
|
retain_default_strategy: "git",
|
|
520
539
|
retain_strategies: RETAIN_STRATEGIES,
|
|
521
540
|
entity_labels: [KNOWLEDGE_LABELS],
|
|
@@ -523,12 +542,17 @@ var CODING_BANK_TEMPLATE = {
|
|
|
523
542
|
}
|
|
524
543
|
};
|
|
525
544
|
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
545
|
+
var PLUGIN_GOVERNED_BANK_FIELDS = [
|
|
546
|
+
"retain_strategies",
|
|
547
|
+
"entity_labels",
|
|
548
|
+
"retain_extraction_mode"
|
|
549
|
+
];
|
|
526
550
|
function isSet(v) {
|
|
527
551
|
if (v === null || v === void 0) return false;
|
|
528
552
|
if (typeof v === "string") return v.trim() !== "";
|
|
529
553
|
return true;
|
|
530
554
|
}
|
|
531
|
-
function codingBankManifest(overrides) {
|
|
555
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, defaults = {}) {
|
|
532
556
|
const current2 = overrides ?? {};
|
|
533
557
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
534
558
|
const bank = {};
|
|
@@ -537,20 +561,30 @@ function codingBankManifest(overrides) {
|
|
|
537
561
|
bank.enable_observations = template.enable_observations;
|
|
538
562
|
bank.observations_mission = template.observations_mission;
|
|
539
563
|
bank.retain_mission = template.retain_mission;
|
|
540
|
-
bank.retain_extraction_mode =
|
|
564
|
+
bank.retain_extraction_mode = mode;
|
|
541
565
|
}
|
|
542
566
|
if (!isSet(current2.retain_default_strategy))
|
|
543
567
|
bank.retain_default_strategy = template.retain_default_strategy;
|
|
544
568
|
if (!isSet(current2.entities_allow_free_form))
|
|
545
569
|
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
546
570
|
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
571
|
+
const updates = {};
|
|
572
|
+
for (const [name, def] of Object.entries(template.retain_strategies)) {
|
|
573
|
+
const synced = def.retain_extraction_mode === "custom" ? {} : { retain_extraction_mode: mode };
|
|
574
|
+
const have = strategies[name];
|
|
575
|
+
if (!have || typeof have !== "object") updates[name] = { ...def, ...synced };
|
|
576
|
+
else if ("retain_extraction_mode" in synced && have.retain_extraction_mode !== mode)
|
|
577
|
+
updates[name] = { ...have, ...synced };
|
|
578
|
+
}
|
|
579
|
+
if (Object.keys(updates).length > 0) bank.retain_strategies = { ...strategies, ...updates };
|
|
550
580
|
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
551
581
|
const [knowledgeGroup] = template.entity_labels;
|
|
552
582
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
553
583
|
bank.entity_labels = [...labels, knowledgeGroup];
|
|
584
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
585
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key) || !isSet(value) || isSet(current2[key])) continue;
|
|
586
|
+
bank[key] = value;
|
|
587
|
+
}
|
|
554
588
|
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
555
589
|
}
|
|
556
590
|
|
|
@@ -618,6 +652,14 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
618
652
|
this.name = "KnowledgePagesUnavailableError";
|
|
619
653
|
}
|
|
620
654
|
};
|
|
655
|
+
async function isEndpointMissing(r) {
|
|
656
|
+
try {
|
|
657
|
+
const j = await r.json();
|
|
658
|
+
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
659
|
+
} catch {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
621
663
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
622
664
|
var ReflectError = class extends Error {
|
|
623
665
|
constructor(message, status, timedOut, options) {
|
|
@@ -636,9 +678,28 @@ var ReflectError = class extends Error {
|
|
|
636
678
|
}
|
|
637
679
|
};
|
|
638
680
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
681
|
+
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
682
|
+
var DEFAULT_RECALL_OPTIONS = {
|
|
683
|
+
types: ["observation"],
|
|
684
|
+
budget: "low",
|
|
685
|
+
max_tokens: 2e3,
|
|
686
|
+
include: { entities: null }
|
|
687
|
+
};
|
|
639
688
|
var POLL_CYCLE_MS = 5e3;
|
|
640
689
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
641
690
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
691
|
+
function shapePage(page) {
|
|
692
|
+
const p = page ?? {};
|
|
693
|
+
const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
|
|
694
|
+
return {
|
|
695
|
+
id: p.id,
|
|
696
|
+
name: p.name,
|
|
697
|
+
...p.description ? { description: p.description } : {},
|
|
698
|
+
...Array.isArray(p.tags) && p.tags.length ? { tags: p.tags } : {},
|
|
699
|
+
...p.timestamp ? { last_updated_at: p.timestamp } : {},
|
|
700
|
+
body
|
|
701
|
+
};
|
|
702
|
+
}
|
|
642
703
|
var HindsightClient = class {
|
|
643
704
|
apiUrl;
|
|
644
705
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -656,6 +717,8 @@ var HindsightClient = class {
|
|
|
656
717
|
log;
|
|
657
718
|
maxParallelRetains;
|
|
658
719
|
observationScopes;
|
|
720
|
+
pageSearchLimit;
|
|
721
|
+
recallOptions;
|
|
659
722
|
constructor(o) {
|
|
660
723
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
661
724
|
this.token = o.apiToken;
|
|
@@ -666,13 +729,18 @@ var HindsightClient = class {
|
|
|
666
729
|
});
|
|
667
730
|
this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
|
|
668
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 };
|
|
669
734
|
}
|
|
670
735
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
671
736
|
get apiToken() {
|
|
672
737
|
return this.token;
|
|
673
738
|
}
|
|
674
739
|
headers() {
|
|
675
|
-
const h = {
|
|
740
|
+
const h = {
|
|
741
|
+
"Content-Type": "application/json",
|
|
742
|
+
"Accept-Encoding": "identity"
|
|
743
|
+
};
|
|
676
744
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
677
745
|
return h;
|
|
678
746
|
}
|
|
@@ -780,6 +848,23 @@ var HindsightClient = class {
|
|
|
780
848
|
return false;
|
|
781
849
|
}
|
|
782
850
|
}
|
|
851
|
+
/**
|
|
852
|
+
* Whether a session write-back may use `update_mode="append"`: the server must dedupe by
|
|
853
|
+
* `operation_id` AND the bank must keep document text, or the server rejects the append in the
|
|
854
|
+
* background (#4613). Only an explicit `store_document_text: false` answers "no" — an unreachable
|
|
855
|
+
* or unparseable config assumes the default (stored), so a flaky probe never downgrades appends.
|
|
856
|
+
*/
|
|
857
|
+
async supportsAppendRetain() {
|
|
858
|
+
if (!await this.supportsIdempotentRetain()) return false;
|
|
859
|
+
try {
|
|
860
|
+
const r = await this.req("GET", this.bankUrl("/config"));
|
|
861
|
+
if (!r.ok) return true;
|
|
862
|
+
const j = await r.json();
|
|
863
|
+
return j.config?.store_document_text !== false;
|
|
864
|
+
} catch {
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
783
868
|
/**
|
|
784
869
|
* Every document_id currently in the bank under a strategy tag (e.g. `source:git`), paginated into a
|
|
785
870
|
* Set. Powers the incremental git-sync's "what's already ingested?" check — since git commits are stored
|
|
@@ -805,9 +890,28 @@ var HindsightClient = class {
|
|
|
805
890
|
}
|
|
806
891
|
return ids;
|
|
807
892
|
}
|
|
893
|
+
/**
|
|
894
|
+
* The tags on one document, or undefined when the bank holds none with that id. Read from the
|
|
895
|
+
* document LISTING narrowed by `q` (a substring match on the id, so the exact id is picked out of
|
|
896
|
+
* the page) rather than GET /documents/{id}, which also sends the document's full text: the
|
|
897
|
+
* caller, the git-log freshness check on SessionStart, reads a ~100k-character document for one tag.
|
|
898
|
+
*/
|
|
899
|
+
async documentTags(documentId) {
|
|
900
|
+
const limit = 100;
|
|
901
|
+
for (let offset = 0; ; offset += limit) {
|
|
902
|
+
const q = `?q=${encodeURIComponent(documentId)}&limit=${limit}&offset=${offset}`;
|
|
903
|
+
const r = await this.req("GET", this.bankUrl(`/documents${q}`));
|
|
904
|
+
const j = await r.json();
|
|
905
|
+
const items = j.items ?? [];
|
|
906
|
+
const hit = items.find((it) => it.id === documentId);
|
|
907
|
+
if (hit) return hit.tags ?? [];
|
|
908
|
+
if (items.length < limit || offset + limit >= (j.total ?? 0)) return void 0;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
808
911
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
809
912
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
810
|
-
* idempotent and
|
|
913
|
+
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
914
|
+
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
811
915
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
812
916
|
* continue with the template-only path.
|
|
813
917
|
*
|
|
@@ -823,7 +927,11 @@ var HindsightClient = class {
|
|
|
823
927
|
if (opts.manage === false) {
|
|
824
928
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
825
929
|
} else {
|
|
826
|
-
const manifest = codingBankManifest(
|
|
930
|
+
const manifest = codingBankManifest(
|
|
931
|
+
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
932
|
+
opts.extractionMode,
|
|
933
|
+
opts.defaults
|
|
934
|
+
);
|
|
827
935
|
if (!manifest) {
|
|
828
936
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
829
937
|
} else {
|
|
@@ -831,7 +939,7 @@ var HindsightClient = class {
|
|
|
831
939
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
832
940
|
}
|
|
833
941
|
}
|
|
834
|
-
await this.seedPages(opts.pageTrigger);
|
|
942
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
835
943
|
}
|
|
836
944
|
/**
|
|
837
945
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -947,20 +1055,22 @@ var HindsightClient = class {
|
|
|
947
1055
|
}
|
|
948
1056
|
}
|
|
949
1057
|
/**
|
|
950
|
-
* Raw recall
|
|
951
|
-
*
|
|
1058
|
+
* Raw recall with no LLM in the loop, so it still answers when reflect's synthesis times out or
|
|
1059
|
+
* 5xxs. The body is `recallOptions` (consolidated observations by default) — a bank that grows
|
|
1060
|
+
* no observations widens it rather than getting nothing back. Returns the texts in rank order.
|
|
1061
|
+
*
|
|
1062
|
+
* The name predates `recallOptions` (the observation type used to be hardcoded here) and is
|
|
1063
|
+
* kept deliberately: this is the client's published surface, so renaming it would break
|
|
1064
|
+
* importers for a cosmetic gain. The doc above is the contract, not the name.
|
|
952
1065
|
*/
|
|
953
1066
|
async recallObservations(query, opts) {
|
|
954
1067
|
const r = await this.req(
|
|
955
1068
|
"POST",
|
|
956
1069
|
this.bankUrl("/memories/recall"),
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
max_tokens: opts.maxTokens,
|
|
962
|
-
include: { entities: null }
|
|
963
|
-
},
|
|
1070
|
+
// `query` is applied AFTER the spread: everything else is the caller's to override, but a
|
|
1071
|
+
// config that could replace the goal with a fixed string would silently recall for the
|
|
1072
|
+
// wrong question on every turn.
|
|
1073
|
+
{ ...this.recallOptions, query },
|
|
964
1074
|
[],
|
|
965
1075
|
opts.timeoutMs
|
|
966
1076
|
);
|
|
@@ -968,6 +1078,19 @@ var HindsightClient = class {
|
|
|
968
1078
|
const j = await r.json();
|
|
969
1079
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
970
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
|
|
1083
|
+
* Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
|
|
1084
|
+
* expected answer before the bank's first retain — so it must never cache a negative (#4607).
|
|
1085
|
+
*
|
|
1086
|
+
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1087
|
+
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1088
|
+
*/
|
|
1089
|
+
async pagesUnsupported(r) {
|
|
1090
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return false;
|
|
1091
|
+
this.knowledgePagesSupported = false;
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
971
1094
|
/**
|
|
972
1095
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
973
1096
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -975,10 +1098,8 @@ var HindsightClient = class {
|
|
|
975
1098
|
async tree() {
|
|
976
1099
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
977
1100
|
const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
throw new KnowledgePagesUnavailableError();
|
|
981
|
-
}
|
|
1101
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1102
|
+
if (r.status === 404) return [];
|
|
982
1103
|
this.knowledgePagesSupported = true;
|
|
983
1104
|
try {
|
|
984
1105
|
return (await r.json()).roots ?? [];
|
|
@@ -1015,8 +1136,8 @@ var HindsightClient = class {
|
|
|
1015
1136
|
return { items };
|
|
1016
1137
|
}
|
|
1017
1138
|
/**
|
|
1018
|
-
* Read one knowledge page's synthesized content by knowledge-base id,
|
|
1019
|
-
*
|
|
1139
|
+
* Read one knowledge page's synthesized content by knowledge-base id, shaped by `shapePage` so
|
|
1140
|
+
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1020
1141
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1021
1142
|
* token cap.
|
|
1022
1143
|
*/
|
|
@@ -1027,25 +1148,28 @@ var HindsightClient = class {
|
|
|
1027
1148
|
this.bankUrl(`/knowledge-base/pages/${encodeURIComponent(pageId)}`)
|
|
1028
1149
|
);
|
|
1029
1150
|
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1030
|
-
return await r.json();
|
|
1151
|
+
return shapePage(await r.json());
|
|
1031
1152
|
}
|
|
1032
1153
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1033
1154
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1034
1155
|
* hindsight_search_knowledge_pages. */
|
|
1035
|
-
async searchKnowledgePages(query,
|
|
1156
|
+
async searchKnowledgePages(query, opts = {}) {
|
|
1036
1157
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1037
|
-
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1158
|
+
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1038
1159
|
const r = await this.req(
|
|
1039
1160
|
"GET",
|
|
1040
1161
|
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1041
1162
|
void 0,
|
|
1042
1163
|
[],
|
|
1043
|
-
timeoutMs
|
|
1164
|
+
opts.timeoutMs
|
|
1044
1165
|
);
|
|
1166
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1167
|
+
if (r.status === 404) return [];
|
|
1045
1168
|
const j = await r.json();
|
|
1046
1169
|
return (j.results ?? []).map((x) => ({
|
|
1047
1170
|
id: x.id,
|
|
1048
1171
|
name: x.name,
|
|
1172
|
+
...x.source_query ? { source_query: x.source_query } : {},
|
|
1049
1173
|
snippet: x.snippet ?? "",
|
|
1050
1174
|
score: x.score ?? 0
|
|
1051
1175
|
}));
|
|
@@ -1061,8 +1185,8 @@ var HindsightClient = class {
|
|
|
1061
1185
|
* `source_query` re-syncs onto the live page instead of orphaning its synthesized content —
|
|
1062
1186
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1063
1187
|
*/
|
|
1064
|
-
async seedPages(pageTrigger = buildPageTrigger()) {
|
|
1065
|
-
const pages = pagesFor(this.project ?? this.bank);
|
|
1188
|
+
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1189
|
+
const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
|
|
1066
1190
|
const existing = /* @__PURE__ */ new Map();
|
|
1067
1191
|
let roots;
|
|
1068
1192
|
try {
|
|
@@ -1079,6 +1203,7 @@ var HindsightClient = class {
|
|
|
1079
1203
|
}
|
|
1080
1204
|
let created = 0;
|
|
1081
1205
|
let updated = 0;
|
|
1206
|
+
let vanished = 0;
|
|
1082
1207
|
for (const page of pages) {
|
|
1083
1208
|
const hit = existing.get(page.name.toLowerCase());
|
|
1084
1209
|
const body = {
|
|
@@ -1092,13 +1217,16 @@ var HindsightClient = class {
|
|
|
1092
1217
|
};
|
|
1093
1218
|
if (!hit) {
|
|
1094
1219
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
1095
|
-
if (
|
|
1096
|
-
this.knowledgePagesSupported = false;
|
|
1220
|
+
if (await this.pagesUnsupported(r)) {
|
|
1097
1221
|
this.log(
|
|
1098
1222
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1099
1223
|
);
|
|
1100
1224
|
return;
|
|
1101
1225
|
}
|
|
1226
|
+
if (r.status === 404) {
|
|
1227
|
+
this.log(`[bank] ${this.bank} does not exist yet; pages seed on the next session`);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1102
1230
|
if (r.status !== 409) created++;
|
|
1103
1231
|
} else {
|
|
1104
1232
|
const sourceDrift = hit.description !== page.source_query;
|
|
@@ -1108,6 +1236,9 @@ var HindsightClient = class {
|
|
|
1108
1236
|
if (sourceDrift) {
|
|
1109
1237
|
patch.source_query = page.source_query;
|
|
1110
1238
|
patch.tags = page.tags;
|
|
1239
|
+
this.log(
|
|
1240
|
+
`[bank] re-syncing "${page.name}" to its configured source_query \u2014 set pages[${JSON.stringify(page.name)}].source_query to keep your own wording`
|
|
1241
|
+
);
|
|
1111
1242
|
}
|
|
1112
1243
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1113
1244
|
const r = await this.req(
|
|
@@ -1115,19 +1246,22 @@ var HindsightClient = class {
|
|
|
1115
1246
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
1116
1247
|
patch
|
|
1117
1248
|
);
|
|
1118
|
-
if (
|
|
1119
|
-
this.knowledgePagesSupported = false;
|
|
1249
|
+
if (await this.pagesUnsupported(r)) {
|
|
1120
1250
|
this.log(
|
|
1121
1251
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1122
1252
|
);
|
|
1123
1253
|
return;
|
|
1124
1254
|
}
|
|
1255
|
+
if (r.status === 404) {
|
|
1256
|
+
vanished++;
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1125
1259
|
updated++;
|
|
1126
1260
|
}
|
|
1127
1261
|
}
|
|
1128
1262
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1129
1263
|
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` : "")
|
|
1264
|
+
`[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
1265
|
);
|
|
1132
1266
|
}
|
|
1133
1267
|
/**
|
|
@@ -1156,7 +1290,7 @@ var HindsightClient = class {
|
|
|
1156
1290
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1157
1291
|
{ trigger: pageTriggerPatch(desired) }
|
|
1158
1292
|
);
|
|
1159
|
-
if (
|
|
1293
|
+
if (r.status === 404) continue;
|
|
1160
1294
|
updated++;
|
|
1161
1295
|
}
|
|
1162
1296
|
return updated;
|
|
@@ -1248,7 +1382,65 @@ function resolvePageTrigger(raw) {
|
|
|
1248
1382
|
);
|
|
1249
1383
|
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1250
1384
|
}
|
|
1385
|
+
function resolvePages(raw) {
|
|
1386
|
+
const value = raw;
|
|
1387
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1388
|
+
const out = {};
|
|
1389
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
1390
|
+
if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
|
|
1391
|
+
log.warn(
|
|
1392
|
+
"config",
|
|
1393
|
+
`ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
|
|
1394
|
+
);
|
|
1395
|
+
continue;
|
|
1396
|
+
}
|
|
1397
|
+
if (entry === false) {
|
|
1398
|
+
out[name] = false;
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1402
|
+
if (typeof query === "string" && query.trim()) {
|
|
1403
|
+
out[name] = { source_query: query };
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
log.warn(
|
|
1407
|
+
"config",
|
|
1408
|
+
`ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
return out;
|
|
1412
|
+
}
|
|
1413
|
+
function resolveCustomPages(raw) {
|
|
1414
|
+
const value = raw;
|
|
1415
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1416
|
+
const out = {};
|
|
1417
|
+
for (const [rawName, entry] of Object.entries(value)) {
|
|
1418
|
+
const name = rawName.trim();
|
|
1419
|
+
if (!name) continue;
|
|
1420
|
+
if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
|
|
1421
|
+
log.warn(
|
|
1422
|
+
"config",
|
|
1423
|
+
`ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
|
|
1424
|
+
);
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1428
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
1429
|
+
log.warn(
|
|
1430
|
+
"config",
|
|
1431
|
+
`ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
|
|
1432
|
+
);
|
|
1433
|
+
continue;
|
|
1434
|
+
}
|
|
1435
|
+
const rawTags = entry.tags;
|
|
1436
|
+
const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
|
|
1437
|
+
out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
|
|
1438
|
+
}
|
|
1439
|
+
return out;
|
|
1440
|
+
}
|
|
1441
|
+
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1251
1442
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1443
|
+
var DEFAULT_INJECT_TIMEOUT_MS = 7e3;
|
|
1252
1444
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1253
1445
|
function resolveReflectBudget(raw) {
|
|
1254
1446
|
const value = raw.reflectBudget;
|
|
@@ -1275,6 +1467,31 @@ function resolveObservationScopes(raw) {
|
|
|
1275
1467
|
}
|
|
1276
1468
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1277
1469
|
}
|
|
1470
|
+
function resolveDefaultBankConfig(raw) {
|
|
1471
|
+
const value = raw;
|
|
1472
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1473
|
+
const out = {};
|
|
1474
|
+
for (const [key, v] of Object.entries(value)) {
|
|
1475
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key)) {
|
|
1476
|
+
log.warn(
|
|
1477
|
+
"config",
|
|
1478
|
+
`ignoring defaultBankConfig.${key} \u2014 the plugin manages this field itself` + (key === "retain_extraction_mode" ? " (set retainExtractionMode instead)" : "")
|
|
1479
|
+
);
|
|
1480
|
+
continue;
|
|
1481
|
+
}
|
|
1482
|
+
out[key] = v;
|
|
1483
|
+
}
|
|
1484
|
+
return out;
|
|
1485
|
+
}
|
|
1486
|
+
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1487
|
+
function resolveAutoInject(raw) {
|
|
1488
|
+
if (raw.autoReflect !== void 0) {
|
|
1489
|
+
const replacement = raw.autoReflect === false ? "none" : "reflect";
|
|
1490
|
+
log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
|
|
1491
|
+
}
|
|
1492
|
+
if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
|
|
1493
|
+
return raw.autoReflect === false ? "none" : "reflect";
|
|
1494
|
+
}
|
|
1278
1495
|
function resolveConfig(raw = {}) {
|
|
1279
1496
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1280
1497
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
@@ -1304,17 +1521,31 @@ function resolveConfig(raw = {}) {
|
|
|
1304
1521
|
retainSessions: raw.retainSessions ?? true,
|
|
1305
1522
|
// write sessions back by default, every harness
|
|
1306
1523
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1524
|
+
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1525
|
+
defaultBankConfig: resolveDefaultBankConfig(raw.defaultBankConfig),
|
|
1307
1526
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1308
|
-
reflectTimeoutMs: raw.reflectTimeoutMs ||
|
|
1527
|
+
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1309
1528
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1310
1529
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1311
1530
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1312
1531
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1532
|
+
injectTimeoutMs: raw.injectTimeoutMs || DEFAULT_INJECT_TIMEOUT_MS,
|
|
1313
1533
|
reflectBudget: resolveReflectBudget(raw),
|
|
1314
|
-
|
|
1315
|
-
|
|
1534
|
+
autoInject: resolveAutoInject(raw),
|
|
1535
|
+
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1536
|
+
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1537
|
+
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1538
|
+
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1539
|
+
toolGuideExtra: typeof raw.toolGuideExtra === "string" && raw.toolGuideExtra.trim() ? raw.toolGuideExtra : void 0,
|
|
1540
|
+
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1541
|
+
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1542
|
+
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
1543
|
+
// with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
|
|
1544
|
+
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
|
|
1316
1545
|
pageTriggerType: pageTrigger.type,
|
|
1317
1546
|
pageTriggerCron: pageTrigger.cron,
|
|
1547
|
+
pages: resolvePages(raw.pages),
|
|
1548
|
+
customPages: resolveCustomPages(raw.customPages),
|
|
1318
1549
|
autoSeed: raw.autoSeed ?? true,
|
|
1319
1550
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1320
1551
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1325,11 +1556,15 @@ function resolveConfig(raw = {}) {
|
|
|
1325
1556
|
// Hostile input is a config typo, not an attack: keep only string entries so a stray number or
|
|
1326
1557
|
// nested object cannot reach the API as a tag and fail the whole retain.
|
|
1327
1558
|
retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
|
|
1559
|
+
// Undefined, not "", when unset or blank: the retain call distinguishes "not configured" (use
|
|
1560
|
+
// the built-in default) from a configured value, and an empty context would strip the default.
|
|
1561
|
+
retainContext: typeof raw.retainContext === "string" && raw.retainContext.trim() !== "" ? raw.retainContext : void 0,
|
|
1328
1562
|
retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
|
|
1329
1563
|
Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
|
|
1330
1564
|
) : {},
|
|
1331
1565
|
observationScopes: resolveObservationScopes(raw.observationScopes),
|
|
1332
1566
|
banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
|
|
1567
|
+
paths: raw.paths && typeof raw.paths === "object" ? raw.paths : {},
|
|
1333
1568
|
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
|
|
1334
1569
|
autoUpdate: raw.autoUpdate ?? true
|
|
1335
1570
|
};
|
|
@@ -1346,7 +1581,12 @@ function readRaw(path) {
|
|
|
1346
1581
|
}
|
|
1347
1582
|
function mergeRaw(a, b) {
|
|
1348
1583
|
const { harnesses: _drop, ...flat } = b;
|
|
1349
|
-
return {
|
|
1584
|
+
return {
|
|
1585
|
+
...a,
|
|
1586
|
+
...flat,
|
|
1587
|
+
banks: { ...a.banks ?? {}, ...b.banks ?? {} },
|
|
1588
|
+
paths: { ...a.paths ?? {}, ...b.paths ?? {} }
|
|
1589
|
+
};
|
|
1350
1590
|
}
|
|
1351
1591
|
function applyLayer(raw, layer, harness) {
|
|
1352
1592
|
let out = mergeRaw(raw, layer);
|
|
@@ -1377,7 +1617,11 @@ var ENV_KEYS = {
|
|
|
1377
1617
|
maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
|
|
1378
1618
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1379
1619
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1620
|
+
injectTimeoutMs: "HINDSIGHT_INJECT_TIMEOUT_MS",
|
|
1380
1621
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1622
|
+
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1623
|
+
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1624
|
+
toolGuideExtra: "HINDSIGHT_TOOL_GUIDE_EXTRA",
|
|
1381
1625
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1382
1626
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1383
1627
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1397,7 +1641,8 @@ var ENV_KEYS = {
|
|
|
1397
1641
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1398
1642
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1399
1643
|
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1400
|
-
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1644
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
|
|
1645
|
+
retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
|
|
1401
1646
|
};
|
|
1402
1647
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1403
1648
|
"dynamicBankId",
|
|
@@ -1418,6 +1663,8 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1418
1663
|
"maxParallelRetains",
|
|
1419
1664
|
"reflectTimeoutMs",
|
|
1420
1665
|
"reflectToolTimeoutMs",
|
|
1666
|
+
"injectTimeoutMs",
|
|
1667
|
+
"pageSearchLimit",
|
|
1421
1668
|
"pageRefreshEveryTurns",
|
|
1422
1669
|
"seedLimit",
|
|
1423
1670
|
"surveyBudgetUsd",
|
|
@@ -1465,15 +1712,25 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
1465
1712
|
function applyBankConfig(cfg2, resolvedId, directory) {
|
|
1466
1713
|
if (directory !== void 0 && !isOptedIn(cfg2, directory))
|
|
1467
1714
|
return { cfg: { ...cfg2, disabled: true }, bankId: resolvedId };
|
|
1715
|
+
const byPath = directory === void 0 ? void 0 : pathSection(cfg2, cfg2.paths, directory);
|
|
1716
|
+
if (byPath) {
|
|
1717
|
+
const { bank: _rename, ...rest } = overrideFields(byPath);
|
|
1718
|
+
cfg2 = { ...cfg2, ...resolvePartial(cfg2, rest) };
|
|
1719
|
+
}
|
|
1468
1720
|
const section = cfg2.banks[resolvedId];
|
|
1469
1721
|
if (!section) return { cfg: cfg2, bankId: resolvedId };
|
|
1470
|
-
const safe =
|
|
1471
|
-
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1472
|
-
delete safe.banks;
|
|
1722
|
+
const safe = overrideFields(section);
|
|
1473
1723
|
const bankId = typeof safe.bank === "string" && safe.bank ? safe.bank : resolvedId;
|
|
1474
1724
|
delete safe.bank;
|
|
1475
1725
|
return { cfg: { ...cfg2, ...resolvePartial(cfg2, safe) }, bankId };
|
|
1476
1726
|
}
|
|
1727
|
+
function overrideFields(section) {
|
|
1728
|
+
const safe = { ...section };
|
|
1729
|
+
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1730
|
+
delete safe.banks;
|
|
1731
|
+
delete safe.paths;
|
|
1732
|
+
return safe;
|
|
1733
|
+
}
|
|
1477
1734
|
function resolvePartial(cfg2, patch) {
|
|
1478
1735
|
const full = resolveConfig(patch);
|
|
1479
1736
|
const out = {};
|
|
@@ -1481,6 +1738,17 @@ function resolvePartial(cfg2, patch) {
|
|
|
1481
1738
|
if (key in full)
|
|
1482
1739
|
out[key] = full[key];
|
|
1483
1740
|
}
|
|
1741
|
+
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1742
|
+
if ("serverMode" in patch || "apiUrl" in patch || "apiPort" in patch) {
|
|
1743
|
+
const conn = resolveConfig({
|
|
1744
|
+
serverMode: patch.serverMode ?? cfg2.serverMode,
|
|
1745
|
+
apiPort: patch.apiPort ?? cfg2.apiPort,
|
|
1746
|
+
apiUrl: patch.apiUrl ?? (cfg2.serverMode === "daemon" ? void 0 : cfg2.apiUrl)
|
|
1747
|
+
});
|
|
1748
|
+
out.serverMode = conn.serverMode;
|
|
1749
|
+
out.apiUrl = conn.apiUrl;
|
|
1750
|
+
out.apiPort = conn.apiPort;
|
|
1751
|
+
}
|
|
1484
1752
|
return out;
|
|
1485
1753
|
}
|
|
1486
1754
|
|
|
@@ -1494,13 +1762,17 @@ function git(repo, ...args) {
|
|
|
1494
1762
|
return execFileSync("git", ["-C", repo, ...args], {
|
|
1495
1763
|
encoding: "utf8",
|
|
1496
1764
|
maxBuffer: 1 << 28,
|
|
1497
|
-
windowsHide: true
|
|
1765
|
+
windowsHide: true,
|
|
1766
|
+
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
1767
|
+
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
1768
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1498
1769
|
});
|
|
1499
1770
|
}
|
|
1500
1771
|
function repoNameOf(repo) {
|
|
1501
1772
|
return projectNameOf(resolve2(repo));
|
|
1502
1773
|
}
|
|
1503
1774
|
function commitsSince(dir, sinceSha) {
|
|
1775
|
+
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
1504
1776
|
try {
|
|
1505
1777
|
const n = Number.parseInt(git(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
1506
1778
|
return Number.isFinite(n) ? n : null;
|
|
@@ -1561,7 +1833,9 @@ function commitCount(repoDir) {
|
|
|
1561
1833
|
try {
|
|
1562
1834
|
const out = execFileSync2("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
|
|
1563
1835
|
encoding: "utf8",
|
|
1564
|
-
windowsHide: true
|
|
1836
|
+
windowsHide: true,
|
|
1837
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1838
|
+
// failed probes must not write into the host TUI
|
|
1565
1839
|
});
|
|
1566
1840
|
return Number(out.trim()) || 0;
|
|
1567
1841
|
} catch {
|
|
@@ -1628,7 +1902,7 @@ if (!BANK) {
|
|
|
1628
1902
|
console.error("usage: node status.js --repo <path> [--bank <id>] [--api-url U]");
|
|
1629
1903
|
process.exit(1);
|
|
1630
1904
|
}
|
|
1631
|
-
var resolved0 = BANK ? applyBankConfig(cfg0, BANK) : { cfg: cfg0, bankId: BANK };
|
|
1905
|
+
var resolved0 = BANK ? applyBankConfig(cfg0, BANK, REPO) : { cfg: cfg0, bankId: BANK };
|
|
1632
1906
|
var cfg = resolved0.cfg;
|
|
1633
1907
|
var FINAL_BANK = resolved0.bankId ?? BANK;
|
|
1634
1908
|
var client = new HindsightClient({
|