@vectorize-io/hindsight-coding-agents 0.7.0 → 0.8.1
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 +201 -16
- package/dist/antigravity-hook.js +1132 -115
- package/dist/antigravity-statusline.js +77 -11
- package/dist/antigravity-stop-hook.js +1193 -133
- package/dist/claude-hook.js +1132 -115
- package/dist/claude-sessionstart-hook.js +1241 -140
- package/dist/claude-stop-hook.js +1193 -133
- package/dist/cline.js +578 -163
- package/dist/codebuddy-hook.js +4270 -0
- package/dist/codebuddy-sessionstart-hook.js +5030 -0
- package/dist/codebuddy-stop-hook.js +4564 -0
- package/dist/codex-hook.js +1132 -115
- package/dist/codex-sessionstart-hook.js +1241 -140
- package/dist/codex-stop-hook.js +1193 -133
- package/dist/copilot-hook.js +1132 -115
- package/dist/copilot-sessionstart-hook.js +1241 -140
- package/dist/copilot-stop-hook.js +1193 -133
- package/dist/cursor-hook.js +1132 -115
- package/dist/cursor-sessionstart-hook.js +1241 -140
- package/dist/cursor-stop-hook.js +1193 -133
- package/dist/daemon-start.js +54 -9
- package/dist/dcode-hook.js +1132 -115
- package/dist/dcode-sessionstart-hook.js +1241 -140
- package/dist/dcode-stop-hook.js +1193 -133
- package/dist/deepen.js +370 -104
- package/dist/devin-hook.js +1132 -115
- package/dist/devin-sessionstart-hook.js +1241 -140
- package/dist/devin-stop-hook.js +1193 -133
- package/dist/droid-hook.js +1132 -115
- package/dist/droid-sessionstart-hook.js +1241 -140
- package/dist/droid-stop-hook.js +1193 -133
- package/dist/dsh.js +586 -164
- package/dist/grok-hook.js +1132 -115
- package/dist/grok-sessionstart-hook.js +1241 -140
- package/dist/grok-stop-hook.js +1193 -133
- package/dist/hindsight-seed.js +50 -8
- package/dist/index.js +587 -172
- package/dist/installer.js +2010 -769
- package/dist/kilo.js +587 -172
- package/dist/kimi-hook.js +4270 -0
- package/dist/kimi-sessionstart-hook.js +5030 -0
- package/dist/kimi-stop-hook.js +4564 -0
- package/dist/mcp-server.js +419 -115
- package/dist/opencode2.js +586 -169
- package/dist/pi.js +644 -175
- package/dist/prime-agent.js +644 -175
- package/dist/qwen-hook.js +1132 -115
- package/dist/qwen-sessionstart-hook.js +1241 -140
- package/dist/qwen-stop-hook.js +1193 -133
- package/dist/status.js +243 -52
- package/dist/traecode-hook.js +4270 -0
- package/dist/traecode-sessionstart-hook.js +5030 -0
- package/dist/traecode-stop-hook.js +4564 -0
- package/dist/workbuddy-hook.js +4270 -0
- package/dist/workbuddy-sessionstart-hook.js +5030 -0
- package/dist/workbuddy-stop-hook.js +4564 -0
- package/dist/zcode-hook.js +1132 -115
- package/dist/zcode-sessionstart-hook.js +1241 -140
- package/dist/zcode-stop-hook.js +1193 -133
- package/package.json +22 -12
- package/plugin.json +1 -1
- package/skill/SKILL.md +73 -14
package/dist/status.js
CHANGED
|
@@ -6,6 +6,7 @@ import { homedir as homedir2 } from "os";
|
|
|
6
6
|
import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
|
|
7
7
|
|
|
8
8
|
// src/core/diag.ts
|
|
9
|
+
import { readFileSync } from "fs";
|
|
9
10
|
import { join as join2 } from "path";
|
|
10
11
|
|
|
11
12
|
// src/core/log.ts
|
|
@@ -64,7 +65,7 @@ function diag(harness, event, extra = {}) {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// src/core/git-layout.ts
|
|
67
|
-
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
68
|
+
import { lstatSync, readFileSync as readFileSync2, realpathSync } from "fs";
|
|
68
69
|
import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
|
|
69
70
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
70
71
|
var ATTEMPTS = 3;
|
|
@@ -88,7 +89,7 @@ function entryKind(path) {
|
|
|
88
89
|
}
|
|
89
90
|
function readTextOrNull(path) {
|
|
90
91
|
try {
|
|
91
|
-
return
|
|
92
|
+
return readFileSync2(path, "utf8");
|
|
92
93
|
} catch (error) {
|
|
93
94
|
if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
|
|
94
95
|
return null;
|
|
@@ -250,13 +251,13 @@ function isWithin(directory, configured) {
|
|
|
250
251
|
function mapLookup(map, directory) {
|
|
251
252
|
const cwd = normalize(directory);
|
|
252
253
|
let best;
|
|
253
|
-
for (const [dir,
|
|
254
|
+
for (const [dir, value] of Object.entries(map)) {
|
|
254
255
|
const p = configuredDir(dir);
|
|
255
256
|
if (isWithin(cwd, p)) {
|
|
256
|
-
if (!best || p.length > best.len) best = { len: p.length,
|
|
257
|
+
if (!best || p.length > best.len) best = { len: p.length, value };
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
|
-
return best?.
|
|
260
|
+
return best?.value;
|
|
260
261
|
}
|
|
261
262
|
function lookupDirectories(config, directory, sessionRoot = "") {
|
|
262
263
|
const directories = [normalize(directory)];
|
|
@@ -280,6 +281,10 @@ function isOptedIn(config, directory) {
|
|
|
280
281
|
const pathMap = config.mapPathToBank;
|
|
281
282
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
282
283
|
}
|
|
284
|
+
function pathSection(config, paths, directory) {
|
|
285
|
+
if (!directory || !paths) return void 0;
|
|
286
|
+
return lookupDirectories(config, directory).map((candidate) => mapLookup(paths, candidate)).find((section) => section !== void 0);
|
|
287
|
+
}
|
|
283
288
|
function mappedBank(config, directory, sessionRoot) {
|
|
284
289
|
const pathMap = config.mapPathToBank;
|
|
285
290
|
if (!directory || !pathMap) return void 0;
|
|
@@ -314,7 +319,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
|
|
|
314
319
|
}
|
|
315
320
|
|
|
316
321
|
// src/core/config.ts
|
|
317
|
-
import { readFileSync as
|
|
322
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
318
323
|
import { homedir as homedir3 } from "os";
|
|
319
324
|
import { join as join7 } from "path";
|
|
320
325
|
|
|
@@ -327,7 +332,7 @@ var DEFAULT_SEED_LIMIT = 300;
|
|
|
327
332
|
// src/core/missions.ts
|
|
328
333
|
import { createHash } from "crypto";
|
|
329
334
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
330
|
-
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history,
|
|
335
|
+
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, oldest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
331
336
|
var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Do not invent; capture only what was actually settled.`;
|
|
332
337
|
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
338
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
@@ -403,6 +408,8 @@ var KNOWLEDGE_LABELS = {
|
|
|
403
408
|
]
|
|
404
409
|
};
|
|
405
410
|
function pageScopeRule(project) {
|
|
411
|
+
if (project === void 0)
|
|
412
|
+
return ` This bank is shared by several projects: attribute each thing you include to the repository or project its sources name, and group by project where that helps. Leave out facts about external tools, libraries and services those projects merely use, configure, deploy or discuss \u2014 they belong to somebody else's codebase \u2014 including any commit SHA or identifier from such a dependency's repository.`;
|
|
406
413
|
return ` Scope this page to ${project} ITSELF: the bank also holds facts about external tools, libraries and services that ${project} merely uses, configures, deploys or discusses, and those belong to somebody else's codebase. Include something only when its subject is ${project}'s own code, configuration or process; when it is about a dependency, leave it out however well-evidenced it looks \u2014 including any commit SHA or identifier that belongs to that dependency's repository rather than this one.`;
|
|
407
414
|
}
|
|
408
415
|
var PAGE_TAXONOMY = [
|
|
@@ -538,12 +545,17 @@ var CODING_BANK_TEMPLATE = {
|
|
|
538
545
|
}
|
|
539
546
|
};
|
|
540
547
|
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
548
|
+
var PLUGIN_GOVERNED_BANK_FIELDS = [
|
|
549
|
+
"retain_strategies",
|
|
550
|
+
"entity_labels",
|
|
551
|
+
"retain_extraction_mode"
|
|
552
|
+
];
|
|
541
553
|
function isSet(v) {
|
|
542
554
|
if (v === null || v === void 0) return false;
|
|
543
555
|
if (typeof v === "string") return v.trim() !== "";
|
|
544
556
|
return true;
|
|
545
557
|
}
|
|
546
|
-
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
558
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, defaults = {}) {
|
|
547
559
|
const current2 = overrides ?? {};
|
|
548
560
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
549
561
|
const bank = {};
|
|
@@ -572,19 +584,26 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
|
572
584
|
const [knowledgeGroup] = template.entity_labels;
|
|
573
585
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
574
586
|
bank.entity_labels = [...labels, knowledgeGroup];
|
|
587
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
588
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key) || !isSet(value) || isSet(current2[key])) continue;
|
|
589
|
+
bank[key] = value;
|
|
590
|
+
}
|
|
575
591
|
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
576
592
|
}
|
|
577
593
|
|
|
594
|
+
// package.json
|
|
595
|
+
var version = "0.8.1";
|
|
596
|
+
|
|
578
597
|
// src/core/util.ts
|
|
579
598
|
import { accessSync, constants } from "fs";
|
|
580
599
|
import { delimiter, join as join6 } from "path";
|
|
581
600
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
582
|
-
function semverGte(
|
|
601
|
+
function semverGte(version2, min) {
|
|
583
602
|
const parts = (v) => {
|
|
584
603
|
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
585
604
|
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
586
605
|
};
|
|
587
|
-
const a =
|
|
606
|
+
const a = version2 ? parts(version2) : void 0;
|
|
588
607
|
const b = parts(min);
|
|
589
608
|
if (!a || !b) return false;
|
|
590
609
|
for (let i = 0; i < 3; i++) {
|
|
@@ -609,6 +628,7 @@ async function pool(items, n, fn, onError, onProgress) {
|
|
|
609
628
|
}
|
|
610
629
|
|
|
611
630
|
// src/core/hindsight.ts
|
|
631
|
+
var USER_AGENT = `hindsight-coding-agents/${version}`;
|
|
612
632
|
function resolveRetainScopes(tags, configured) {
|
|
613
633
|
if (configured !== "per_source") return configured;
|
|
614
634
|
const sources = [...new Set((tags ?? []).filter((t) => t.startsWith("source:")))].sort();
|
|
@@ -644,7 +664,7 @@ async function isEndpointMissing(r) {
|
|
|
644
664
|
const j = await r.json();
|
|
645
665
|
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
646
666
|
} catch {
|
|
647
|
-
return
|
|
667
|
+
return false;
|
|
648
668
|
}
|
|
649
669
|
}
|
|
650
670
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
@@ -663,6 +683,12 @@ var ReflectError = class extends Error {
|
|
|
663
683
|
get fallbackEligible() {
|
|
664
684
|
return this.timedOut || this.status !== void 0 && this.status >= 500;
|
|
665
685
|
}
|
|
686
|
+
/** A 4xx the next attempt would get again (bad key, missing bank, rejected body) — retrying it
|
|
687
|
+
* only spends another doomed call (#5207). 408/429 are "not now", so they stay retryable. */
|
|
688
|
+
get permanent() {
|
|
689
|
+
const s = this.status;
|
|
690
|
+
return s !== void 0 && s >= 400 && s < 500 && s !== 408 && s !== 429;
|
|
691
|
+
}
|
|
666
692
|
};
|
|
667
693
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
668
694
|
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
@@ -673,8 +699,31 @@ var DEFAULT_RECALL_OPTIONS = {
|
|
|
673
699
|
include: { entities: null }
|
|
674
700
|
};
|
|
675
701
|
var POLL_CYCLE_MS = 5e3;
|
|
702
|
+
var POLL_MAX_SERVER_ERRORS = 12;
|
|
676
703
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
677
704
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
705
|
+
var RATE_LIMIT_BACKOFF_MS = 1e3;
|
|
706
|
+
function shapePage(page) {
|
|
707
|
+
const p = page ?? {};
|
|
708
|
+
const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
|
|
709
|
+
return {
|
|
710
|
+
id: p.id,
|
|
711
|
+
name: p.name,
|
|
712
|
+
...p.description ? { description: p.description } : {},
|
|
713
|
+
...Array.isArray(p.tags) && p.tags.length ? { tags: p.tags } : {},
|
|
714
|
+
...p.timestamp ? { last_updated_at: p.timestamp } : {},
|
|
715
|
+
body
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
var GLOBAL_DISPATCHER = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
|
|
719
|
+
function signalOnlyDispatcher() {
|
|
720
|
+
void globalThis.Headers;
|
|
721
|
+
const d = globalThis[GLOBAL_DISPATCHER];
|
|
722
|
+
if (typeof d?.compose !== "function") return void 0;
|
|
723
|
+
return d.compose(
|
|
724
|
+
(dispatch) => (opts, handler) => dispatch({ ...opts, headersTimeout: 0, bodyTimeout: 0 }, handler)
|
|
725
|
+
);
|
|
726
|
+
}
|
|
678
727
|
var HindsightClient = class {
|
|
679
728
|
apiUrl;
|
|
680
729
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -694,6 +743,7 @@ var HindsightClient = class {
|
|
|
694
743
|
observationScopes;
|
|
695
744
|
pageSearchLimit;
|
|
696
745
|
recallOptions;
|
|
746
|
+
rateLimitPatienceMs;
|
|
697
747
|
constructor(o) {
|
|
698
748
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
699
749
|
this.token = o.apiToken;
|
|
@@ -706,13 +756,18 @@ var HindsightClient = class {
|
|
|
706
756
|
this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
|
|
707
757
|
this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
|
|
708
758
|
this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
|
|
759
|
+
this.rateLimitPatienceMs = o.rateLimitPatienceMs ?? 0;
|
|
709
760
|
}
|
|
710
761
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
711
762
|
get apiToken() {
|
|
712
763
|
return this.token;
|
|
713
764
|
}
|
|
714
765
|
headers() {
|
|
715
|
-
const h = {
|
|
766
|
+
const h = {
|
|
767
|
+
"Content-Type": "application/json",
|
|
768
|
+
"Accept-Encoding": "identity",
|
|
769
|
+
"User-Agent": USER_AGENT
|
|
770
|
+
};
|
|
716
771
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
717
772
|
return h;
|
|
718
773
|
}
|
|
@@ -743,7 +798,8 @@ var HindsightClient = class {
|
|
|
743
798
|
* bounds the whole call.
|
|
744
799
|
*/
|
|
745
800
|
async fetchWithAuth(url, init) {
|
|
746
|
-
const
|
|
801
|
+
const dispatcher = init.signal ? signalOnlyDispatcher() : void 0;
|
|
802
|
+
const send = () => fetch(url, { ...init, headers: this.headers(), ...dispatcher ? { dispatcher } : {} });
|
|
747
803
|
const r = await send();
|
|
748
804
|
if (r.status !== 401 || !this.refreshToken()) return r;
|
|
749
805
|
return send();
|
|
@@ -759,13 +815,22 @@ var HindsightClient = class {
|
|
|
759
815
|
}
|
|
760
816
|
/** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
|
|
761
817
|
async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
818
|
+
const payload = body ? JSON.stringify(body) : void 0;
|
|
819
|
+
let r;
|
|
820
|
+
for (let attempt = 0, waited = 0; ; attempt++) {
|
|
821
|
+
r = await this.fetchWithAuth(url, {
|
|
822
|
+
method,
|
|
823
|
+
body: payload,
|
|
824
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
825
|
+
});
|
|
826
|
+
if (r.status !== 429 || tolerate.includes(429)) break;
|
|
827
|
+
const asked = retryAfterMs(r.headers.get("retry-after"));
|
|
828
|
+
const backoff = Math.min(RETRY_AFTER_CEILING_MS, RATE_LIMIT_BACKOFF_MS * 2 ** attempt);
|
|
829
|
+
const wait = Math.min(RETRY_AFTER_CEILING_MS, Math.max(asked, backoff)) * (1 + Math.random() / 2);
|
|
830
|
+
if (waited + wait > this.rateLimitPatienceMs) throw new RateLimitedError(asked);
|
|
831
|
+
await sleep(wait);
|
|
832
|
+
waited += wait;
|
|
833
|
+
}
|
|
769
834
|
if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
|
|
770
835
|
throw new Error(
|
|
771
836
|
`${method} ${url} -> ${r.status} ${await r.text()}${this.authHint(r.status)}`
|
|
@@ -800,7 +865,7 @@ var HindsightClient = class {
|
|
|
800
865
|
}
|
|
801
866
|
/**
|
|
802
867
|
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
803
|
-
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via
|
|
868
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
|
|
804
869
|
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
805
870
|
*/
|
|
806
871
|
async supportsIdempotentRetain() {
|
|
@@ -810,14 +875,37 @@ var HindsightClient = class {
|
|
|
810
875
|
}
|
|
811
876
|
return this.idempotentRetain;
|
|
812
877
|
}
|
|
878
|
+
/** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
|
|
879
|
+
* hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
|
|
880
|
+
* so append silently never turned on (#5286). Servers that predate the alias still answer
|
|
881
|
+
* `/version`, so that stays as the fallback. */
|
|
813
882
|
async probeIdempotentRetain() {
|
|
883
|
+
for (const path of ["/v1/version", "/version"]) {
|
|
884
|
+
try {
|
|
885
|
+
const r = await this.req("GET", `${this.apiUrl}${path}`);
|
|
886
|
+
if (!r.ok) continue;
|
|
887
|
+
const j = await r.json();
|
|
888
|
+
return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
|
|
889
|
+
} catch {
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Whether a session write-back may use `update_mode="append"`: the server must dedupe by
|
|
896
|
+
* `operation_id` AND the bank must keep document text, or the server rejects the append in the
|
|
897
|
+
* background (#4613). Only an explicit `store_document_text: false` answers "no" — an unreachable
|
|
898
|
+
* or unparseable config assumes the default (stored), so a flaky probe never downgrades appends.
|
|
899
|
+
*/
|
|
900
|
+
async supportsAppendRetain() {
|
|
901
|
+
if (!await this.supportsIdempotentRetain()) return false;
|
|
814
902
|
try {
|
|
815
|
-
const r = await this.req("GET",
|
|
816
|
-
if (!r.ok) return
|
|
903
|
+
const r = await this.req("GET", this.bankUrl("/config"));
|
|
904
|
+
if (!r.ok) return true;
|
|
817
905
|
const j = await r.json();
|
|
818
|
-
return
|
|
906
|
+
return j.config?.store_document_text !== false;
|
|
819
907
|
} catch {
|
|
820
|
-
return
|
|
908
|
+
return true;
|
|
821
909
|
}
|
|
822
910
|
}
|
|
823
911
|
/**
|
|
@@ -845,6 +933,32 @@ var HindsightClient = class {
|
|
|
845
933
|
}
|
|
846
934
|
return ids;
|
|
847
935
|
}
|
|
936
|
+
/**
|
|
937
|
+
* The tags on one document, or undefined when the bank holds none with that id. Read from the
|
|
938
|
+
* document LISTING narrowed by `q` (a substring match on the id, so the exact id is picked out of
|
|
939
|
+
* the page) rather than GET /documents/{id}, which also sends the document's full text: the
|
|
940
|
+
* caller, the git-log freshness check on SessionStart, reads a ~100k-character document for one tag.
|
|
941
|
+
*/
|
|
942
|
+
async documentTags(documentId) {
|
|
943
|
+
const limit = 100;
|
|
944
|
+
for (let offset = 0; ; offset += limit) {
|
|
945
|
+
const q = `?q=${encodeURIComponent(documentId)}&limit=${limit}&offset=${offset}`;
|
|
946
|
+
const r = await this.req("GET", this.bankUrl(`/documents${q}`));
|
|
947
|
+
const j = await r.json();
|
|
948
|
+
const items = j.items ?? [];
|
|
949
|
+
const hit = items.find((it) => it.id === documentId);
|
|
950
|
+
if (hit) return hit.tags ?? [];
|
|
951
|
+
if (items.length < limit || offset + limit >= (j.total ?? 0)) return void 0;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
/** Whether the bank holds any document at all — a one-row listing. A bank that does not exist
|
|
955
|
+
* yet (404) holds none; any other failure throws, so a caller can tell "empty" from "unknown". */
|
|
956
|
+
async hasDocuments() {
|
|
957
|
+
const r = await this.req("GET", this.bankUrl("/documents?limit=1"));
|
|
958
|
+
if (r.status === 404) return false;
|
|
959
|
+
const j = await r.json();
|
|
960
|
+
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
961
|
+
}
|
|
848
962
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
849
963
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
850
964
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
@@ -866,7 +980,8 @@ var HindsightClient = class {
|
|
|
866
980
|
} else {
|
|
867
981
|
const manifest = codingBankManifest(
|
|
868
982
|
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
869
|
-
opts.extractionMode
|
|
983
|
+
opts.extractionMode,
|
|
984
|
+
opts.defaults
|
|
870
985
|
);
|
|
871
986
|
if (!manifest) {
|
|
872
987
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
@@ -925,7 +1040,13 @@ var HindsightClient = class {
|
|
|
925
1040
|
this.log(`[wait] draining ${ids.length} ${label} operations \u2026`);
|
|
926
1041
|
const start = Date.now();
|
|
927
1042
|
const pending = new Set(ids);
|
|
1043
|
+
const serverErrors = /* @__PURE__ */ new Map();
|
|
928
1044
|
let failed = 0;
|
|
1045
|
+
const giveUp = (id, status) => {
|
|
1046
|
+
pending.delete(id);
|
|
1047
|
+
failed++;
|
|
1048
|
+
this.log(` \u2026 ${label} op ${id} -> HTTP ${status}, counted as failed`);
|
|
1049
|
+
};
|
|
929
1050
|
while (pending.size && Date.now() - start < maxMs) {
|
|
930
1051
|
let backoffMs = POLL_CYCLE_MS;
|
|
931
1052
|
await pool([...pending], this.maxParallelRetains, async (id) => {
|
|
@@ -938,7 +1059,14 @@ var HindsightClient = class {
|
|
|
938
1059
|
);
|
|
939
1060
|
return;
|
|
940
1061
|
}
|
|
941
|
-
if (
|
|
1062
|
+
if (r.status >= 500) {
|
|
1063
|
+
const n = (serverErrors.get(id) ?? 0) + 1;
|
|
1064
|
+
serverErrors.set(id, n);
|
|
1065
|
+
if (n >= POLL_MAX_SERVER_ERRORS) giveUp(id, r.status);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (!r.ok) return giveUp(id, r.status);
|
|
1069
|
+
serverErrors.delete(id);
|
|
942
1070
|
const st = ((await r.json()).status || "").toLowerCase();
|
|
943
1071
|
if (TERMINAL.has(st)) {
|
|
944
1072
|
pending.delete(id);
|
|
@@ -1072,8 +1200,8 @@ var HindsightClient = class {
|
|
|
1072
1200
|
return { items };
|
|
1073
1201
|
}
|
|
1074
1202
|
/**
|
|
1075
|
-
* Read one knowledge page's synthesized content by knowledge-base id,
|
|
1076
|
-
*
|
|
1203
|
+
* Read one knowledge page's synthesized content by knowledge-base id, shaped by `shapePage` so
|
|
1204
|
+
* the body arrives once. The endpoint omits the internal reflect trace that built
|
|
1077
1205
|
* the page — that is 70-95% of the raw bytes and can blow past an MCP host's per-tool-result
|
|
1078
1206
|
* token cap.
|
|
1079
1207
|
*/
|
|
@@ -1084,7 +1212,7 @@ var HindsightClient = class {
|
|
|
1084
1212
|
this.bankUrl(`/knowledge-base/pages/${encodeURIComponent(pageId)}`)
|
|
1085
1213
|
);
|
|
1086
1214
|
if (r.status === 404) throw new Error(`knowledge page not found: ${pageId}`);
|
|
1087
|
-
return await r.json();
|
|
1215
|
+
return shapePage(await r.json());
|
|
1088
1216
|
}
|
|
1089
1217
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1090
1218
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
@@ -1105,6 +1233,7 @@ var HindsightClient = class {
|
|
|
1105
1233
|
return (j.results ?? []).map((x) => ({
|
|
1106
1234
|
id: x.id,
|
|
1107
1235
|
name: x.name,
|
|
1236
|
+
...x.source_query ? { source_query: x.source_query } : {},
|
|
1108
1237
|
snippet: x.snippet ?? "",
|
|
1109
1238
|
score: x.score ?? 0
|
|
1110
1239
|
}));
|
|
@@ -1121,7 +1250,7 @@ var HindsightClient = class {
|
|
|
1121
1250
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1122
1251
|
*/
|
|
1123
1252
|
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1124
|
-
const pages = pagesFor(this.project
|
|
1253
|
+
const pages = pagesFor(this.project, pagesConfig, customPages);
|
|
1125
1254
|
const existing = /* @__PURE__ */ new Map();
|
|
1126
1255
|
let roots;
|
|
1127
1256
|
try {
|
|
@@ -1196,7 +1325,7 @@ var HindsightClient = class {
|
|
|
1196
1325
|
}
|
|
1197
1326
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1198
1327
|
this.log(
|
|
1199
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ??
|
|
1328
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? "the shared bank"}): ${created} created, ${updated} re-synced, ${pages.length - created - updated - vanished} unchanged` + (vanished ? `, ${vanished} deleted under us` : "") + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1200
1329
|
);
|
|
1201
1330
|
}
|
|
1202
1331
|
/**
|
|
@@ -1207,23 +1336,33 @@ var HindsightClient = class {
|
|
|
1207
1336
|
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1208
1337
|
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1209
1338
|
*
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1339
|
+
* Their `name` and `source_query` are written once, from the initiative's own title, and
|
|
1340
|
+
* re-stating either would rebuild a page whose question never changed. The one exception is
|
|
1341
|
+
* the scope clause: a page captured while the clause named the BANK is scoped to a project no
|
|
1342
|
+
* memory is about and comes out empty (#4490), so exactly that clause is swapped for the current
|
|
1343
|
+
* one — the rest of the query, the user's wording included, is kept. The tree read above is
|
|
1344
|
+
* reused rather than re-fetched.
|
|
1213
1345
|
*/
|
|
1214
1346
|
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1215
1347
|
const folder = roots.find(
|
|
1216
1348
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1217
1349
|
);
|
|
1350
|
+
const bankScope = pageScopeRule(this.bank);
|
|
1218
1351
|
let updated = 0;
|
|
1219
1352
|
for (const page of folder?.children ?? []) {
|
|
1220
|
-
if (page.kind !== "page"
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1353
|
+
if (page.kind !== "page") continue;
|
|
1354
|
+
const patch = {};
|
|
1355
|
+
const query = page.description?.replace(bankScope, pageScopeRule(this.project));
|
|
1356
|
+
if (query !== page.description) patch.source_query = query;
|
|
1357
|
+
if (page.trigger != null) {
|
|
1358
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1359
|
+
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
1360
|
+
}
|
|
1361
|
+
if (!patch.trigger && !patch.source_query) continue;
|
|
1223
1362
|
const r = await this.req(
|
|
1224
1363
|
"PATCH",
|
|
1225
1364
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1226
|
-
|
|
1365
|
+
patch
|
|
1227
1366
|
);
|
|
1228
1367
|
if (r.status === 404) continue;
|
|
1229
1368
|
updated++;
|
|
@@ -1251,10 +1390,9 @@ var HindsightClient = class {
|
|
|
1251
1390
|
let pageId = args.relatesToPageId;
|
|
1252
1391
|
if (!pageId) {
|
|
1253
1392
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1254
|
-
const subject = this.project ?? this.bank;
|
|
1255
1393
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1256
1394
|
name: args.title,
|
|
1257
|
-
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory.` + pageScopeRule(
|
|
1395
|
+
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory.` + pageScopeRule(this.project),
|
|
1258
1396
|
parent_id: folderId,
|
|
1259
1397
|
tags: ["knowledge:feature-work"],
|
|
1260
1398
|
max_tokens: PAGE_MAX_TOKENS,
|
|
@@ -1269,7 +1407,7 @@ var HindsightClient = class {
|
|
|
1269
1407
|
}
|
|
1270
1408
|
const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
|
|
1271
1409
|
const content = `${verb}: ${args.title}. ${args.summary}`;
|
|
1272
|
-
const markerId = `initiative-marker-${this.slugify(
|
|
1410
|
+
const markerId = `initiative-marker-${this.slugify(pageId)}${args.relatesToPageId ? "-update" : ""}`;
|
|
1273
1411
|
const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
|
|
1274
1412
|
const context = `initiative marker for [[page:${pageId}]]`;
|
|
1275
1413
|
await this.retain(content, context, markerId, tags, "document", {
|
|
@@ -1375,6 +1513,7 @@ function resolveCustomPages(raw) {
|
|
|
1375
1513
|
}
|
|
1376
1514
|
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1377
1515
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1516
|
+
var DEFAULT_INJECT_TIMEOUT_MS = 7e3;
|
|
1378
1517
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1379
1518
|
function resolveReflectBudget(raw) {
|
|
1380
1519
|
const value = raw.reflectBudget;
|
|
@@ -1401,6 +1540,22 @@ function resolveObservationScopes(raw) {
|
|
|
1401
1540
|
}
|
|
1402
1541
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1403
1542
|
}
|
|
1543
|
+
function resolveDefaultBankConfig(raw) {
|
|
1544
|
+
const value = raw;
|
|
1545
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1546
|
+
const out = {};
|
|
1547
|
+
for (const [key, v] of Object.entries(value)) {
|
|
1548
|
+
if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key)) {
|
|
1549
|
+
log.warn(
|
|
1550
|
+
"config",
|
|
1551
|
+
`ignoring defaultBankConfig.${key} \u2014 the plugin manages this field itself` + (key === "retain_extraction_mode" ? " (set retainExtractionMode instead)" : "")
|
|
1552
|
+
);
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
out[key] = v;
|
|
1556
|
+
}
|
|
1557
|
+
return out;
|
|
1558
|
+
}
|
|
1404
1559
|
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1405
1560
|
function resolveAutoInject(raw) {
|
|
1406
1561
|
if (raw.autoReflect !== void 0) {
|
|
@@ -1440,18 +1595,21 @@ function resolveConfig(raw = {}) {
|
|
|
1440
1595
|
// write sessions back by default, every harness
|
|
1441
1596
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1442
1597
|
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1598
|
+
defaultBankConfig: resolveDefaultBankConfig(raw.defaultBankConfig),
|
|
1443
1599
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1444
1600
|
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1445
1601
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1446
1602
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1447
1603
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1448
1604
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1605
|
+
injectTimeoutMs: raw.injectTimeoutMs || DEFAULT_INJECT_TIMEOUT_MS,
|
|
1449
1606
|
reflectBudget: resolveReflectBudget(raw),
|
|
1450
1607
|
autoInject: resolveAutoInject(raw),
|
|
1451
1608
|
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1452
1609
|
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1453
1610
|
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1454
1611
|
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1612
|
+
toolGuideExtra: typeof raw.toolGuideExtra === "string" && raw.toolGuideExtra.trim() ? raw.toolGuideExtra : void 0,
|
|
1455
1613
|
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1456
1614
|
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1457
1615
|
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
@@ -1471,18 +1629,22 @@ function resolveConfig(raw = {}) {
|
|
|
1471
1629
|
// Hostile input is a config typo, not an attack: keep only string entries so a stray number or
|
|
1472
1630
|
// nested object cannot reach the API as a tag and fail the whole retain.
|
|
1473
1631
|
retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
|
|
1632
|
+
// Undefined, not "", when unset or blank: the retain call distinguishes "not configured" (use
|
|
1633
|
+
// the built-in default) from a configured value, and an empty context would strip the default.
|
|
1634
|
+
retainContext: typeof raw.retainContext === "string" && raw.retainContext.trim() !== "" ? raw.retainContext : void 0,
|
|
1474
1635
|
retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
|
|
1475
1636
|
Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
|
|
1476
1637
|
) : {},
|
|
1477
1638
|
observationScopes: resolveObservationScopes(raw.observationScopes),
|
|
1478
1639
|
banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
|
|
1640
|
+
paths: raw.paths && typeof raw.paths === "object" ? raw.paths : {},
|
|
1479
1641
|
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
|
|
1480
1642
|
autoUpdate: raw.autoUpdate ?? true
|
|
1481
1643
|
};
|
|
1482
1644
|
}
|
|
1483
1645
|
function readRaw(path) {
|
|
1484
1646
|
try {
|
|
1485
|
-
return JSON.parse(
|
|
1647
|
+
return JSON.parse(readFileSync3(path, "utf8"));
|
|
1486
1648
|
} catch (e) {
|
|
1487
1649
|
if (e?.code !== "ENOENT") {
|
|
1488
1650
|
console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
|
|
@@ -1492,7 +1654,12 @@ function readRaw(path) {
|
|
|
1492
1654
|
}
|
|
1493
1655
|
function mergeRaw(a, b) {
|
|
1494
1656
|
const { harnesses: _drop, ...flat } = b;
|
|
1495
|
-
return {
|
|
1657
|
+
return {
|
|
1658
|
+
...a,
|
|
1659
|
+
...flat,
|
|
1660
|
+
banks: { ...a.banks ?? {}, ...b.banks ?? {} },
|
|
1661
|
+
paths: { ...a.paths ?? {}, ...b.paths ?? {} }
|
|
1662
|
+
};
|
|
1496
1663
|
}
|
|
1497
1664
|
function applyLayer(raw, layer, harness) {
|
|
1498
1665
|
let out = mergeRaw(raw, layer);
|
|
@@ -1523,9 +1690,11 @@ var ENV_KEYS = {
|
|
|
1523
1690
|
maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
|
|
1524
1691
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1525
1692
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1693
|
+
injectTimeoutMs: "HINDSIGHT_INJECT_TIMEOUT_MS",
|
|
1526
1694
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1527
1695
|
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1528
1696
|
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1697
|
+
toolGuideExtra: "HINDSIGHT_TOOL_GUIDE_EXTRA",
|
|
1529
1698
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1530
1699
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1531
1700
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1567,6 +1736,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1567
1736
|
"maxParallelRetains",
|
|
1568
1737
|
"reflectTimeoutMs",
|
|
1569
1738
|
"reflectToolTimeoutMs",
|
|
1739
|
+
"injectTimeoutMs",
|
|
1570
1740
|
"pageSearchLimit",
|
|
1571
1741
|
"pageRefreshEveryTurns",
|
|
1572
1742
|
"seedLimit",
|
|
@@ -1615,15 +1785,25 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
1615
1785
|
function applyBankConfig(cfg2, resolvedId, directory) {
|
|
1616
1786
|
if (directory !== void 0 && !isOptedIn(cfg2, directory))
|
|
1617
1787
|
return { cfg: { ...cfg2, disabled: true }, bankId: resolvedId };
|
|
1788
|
+
const byPath = directory === void 0 ? void 0 : pathSection(cfg2, cfg2.paths, directory);
|
|
1789
|
+
if (byPath) {
|
|
1790
|
+
const { bank: _rename, ...rest } = overrideFields(byPath);
|
|
1791
|
+
cfg2 = { ...cfg2, ...resolvePartial(cfg2, rest) };
|
|
1792
|
+
}
|
|
1618
1793
|
const section = cfg2.banks[resolvedId];
|
|
1619
1794
|
if (!section) return { cfg: cfg2, bankId: resolvedId };
|
|
1620
|
-
const safe =
|
|
1621
|
-
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1622
|
-
delete safe.banks;
|
|
1795
|
+
const safe = overrideFields(section);
|
|
1623
1796
|
const bankId = typeof safe.bank === "string" && safe.bank ? safe.bank : resolvedId;
|
|
1624
1797
|
delete safe.bank;
|
|
1625
1798
|
return { cfg: { ...cfg2, ...resolvePartial(cfg2, safe) }, bankId };
|
|
1626
1799
|
}
|
|
1800
|
+
function overrideFields(section) {
|
|
1801
|
+
const safe = { ...section };
|
|
1802
|
+
for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
|
|
1803
|
+
delete safe.banks;
|
|
1804
|
+
delete safe.paths;
|
|
1805
|
+
return safe;
|
|
1806
|
+
}
|
|
1627
1807
|
function resolvePartial(cfg2, patch) {
|
|
1628
1808
|
const full = resolveConfig(patch);
|
|
1629
1809
|
const out = {};
|
|
@@ -1632,17 +1812,27 @@ function resolvePartial(cfg2, patch) {
|
|
|
1632
1812
|
out[key] = full[key];
|
|
1633
1813
|
}
|
|
1634
1814
|
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1815
|
+
if ("serverMode" in patch || "apiUrl" in patch || "apiPort" in patch) {
|
|
1816
|
+
const conn = resolveConfig({
|
|
1817
|
+
serverMode: patch.serverMode ?? cfg2.serverMode,
|
|
1818
|
+
apiPort: patch.apiPort ?? cfg2.apiPort,
|
|
1819
|
+
apiUrl: patch.apiUrl ?? (cfg2.serverMode === "daemon" ? void 0 : cfg2.apiUrl)
|
|
1820
|
+
});
|
|
1821
|
+
out.serverMode = conn.serverMode;
|
|
1822
|
+
out.apiUrl = conn.apiUrl;
|
|
1823
|
+
out.apiPort = conn.apiPort;
|
|
1824
|
+
}
|
|
1635
1825
|
return out;
|
|
1636
1826
|
}
|
|
1637
1827
|
|
|
1638
1828
|
// src/core/status.ts
|
|
1639
|
-
import { execFileSync as
|
|
1829
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
1640
1830
|
|
|
1641
1831
|
// src/core/git.ts
|
|
1642
1832
|
import { execFileSync } from "child_process";
|
|
1643
1833
|
import { resolve as resolve2 } from "path";
|
|
1644
1834
|
function git(repo, ...args) {
|
|
1645
|
-
return execFileSync("git", ["-C", repo, ...args], {
|
|
1835
|
+
return execFileSync("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
1646
1836
|
encoding: "utf8",
|
|
1647
1837
|
maxBuffer: 1 << 28,
|
|
1648
1838
|
windowsHide: true,
|
|
@@ -1655,6 +1845,7 @@ function repoNameOf(repo) {
|
|
|
1655
1845
|
return projectNameOf(resolve2(repo));
|
|
1656
1846
|
}
|
|
1657
1847
|
function commitsSince(dir, sinceSha) {
|
|
1848
|
+
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
1658
1849
|
try {
|
|
1659
1850
|
const n = Number.parseInt(git(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
1660
1851
|
return Number.isFinite(n) ? n : null;
|
|
@@ -1677,7 +1868,7 @@ function parsePageList(raw) {
|
|
|
1677
1868
|
}
|
|
1678
1869
|
|
|
1679
1870
|
// src/core/survey.ts
|
|
1680
|
-
import { spawn as realSpawn3 } from "child_process";
|
|
1871
|
+
import { execFileSync as execFileSync2, spawn as realSpawn3 } from "child_process";
|
|
1681
1872
|
import { createHash as createHash2 } from "crypto";
|
|
1682
1873
|
import { existsSync as existsSync2 } from "fs";
|
|
1683
1874
|
import { homedir as homedir4, tmpdir } from "os";
|
|
@@ -1713,7 +1904,7 @@ var SURVEY_DOC_IDS = [
|
|
|
1713
1904
|
var DEEPEN_DIFF_TARGET = 300;
|
|
1714
1905
|
function commitCount(repoDir) {
|
|
1715
1906
|
try {
|
|
1716
|
-
const out =
|
|
1907
|
+
const out = execFileSync3("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
|
|
1717
1908
|
encoding: "utf8",
|
|
1718
1909
|
windowsHide: true,
|
|
1719
1910
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -1784,7 +1975,7 @@ if (!BANK) {
|
|
|
1784
1975
|
console.error("usage: node status.js --repo <path> [--bank <id>] [--api-url U]");
|
|
1785
1976
|
process.exit(1);
|
|
1786
1977
|
}
|
|
1787
|
-
var resolved0 = BANK ? applyBankConfig(cfg0, BANK) : { cfg: cfg0, bankId: BANK };
|
|
1978
|
+
var resolved0 = BANK ? applyBankConfig(cfg0, BANK, REPO) : { cfg: cfg0, bankId: BANK };
|
|
1788
1979
|
var cfg = resolved0.cfg;
|
|
1789
1980
|
var FINAL_BANK = resolved0.bankId ?? BANK;
|
|
1790
1981
|
var client = new HindsightClient({
|