@vectorize-io/hindsight-coding-agents 0.8.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 +67 -6
- package/dist/antigravity-hook.js +441 -80
- package/dist/antigravity-statusline.js +9 -4
- package/dist/antigravity-stop-hook.js +441 -95
- package/dist/claude-hook.js +441 -80
- package/dist/claude-sessionstart-hook.js +473 -93
- package/dist/claude-stop-hook.js +441 -95
- package/dist/cline.js +290 -95
- 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 +441 -80
- package/dist/codex-sessionstart-hook.js +473 -93
- package/dist/codex-stop-hook.js +441 -95
- package/dist/copilot-hook.js +441 -80
- package/dist/copilot-sessionstart-hook.js +473 -93
- package/dist/copilot-stop-hook.js +441 -95
- package/dist/cursor-hook.js +441 -80
- package/dist/cursor-sessionstart-hook.js +473 -93
- package/dist/cursor-stop-hook.js +441 -95
- package/dist/daemon-start.js +16 -8
- package/dist/dcode-hook.js +441 -80
- package/dist/dcode-sessionstart-hook.js +473 -93
- package/dist/dcode-stop-hook.js +441 -95
- package/dist/deepen.js +140 -49
- package/dist/devin-hook.js +441 -80
- package/dist/devin-sessionstart-hook.js +473 -93
- package/dist/devin-stop-hook.js +441 -95
- package/dist/droid-hook.js +441 -80
- package/dist/droid-sessionstart-hook.js +473 -93
- package/dist/droid-stop-hook.js +441 -95
- package/dist/dsh.js +297 -95
- package/dist/grok-hook.js +441 -80
- package/dist/grok-sessionstart-hook.js +473 -93
- package/dist/grok-stop-hook.js +441 -95
- package/dist/hindsight-seed.js +9 -4
- package/dist/index.js +299 -104
- package/dist/installer.js +1043 -647
- package/dist/kilo.js +299 -104
- package/dist/kimi-hook.js +441 -80
- package/dist/kimi-sessionstart-hook.js +473 -93
- package/dist/kimi-stop-hook.js +441 -95
- package/dist/mcp-server.js +261 -86
- package/dist/opencode2.js +296 -101
- package/dist/pi.js +352 -107
- package/dist/prime-agent.js +352 -107
- package/dist/qwen-hook.js +441 -80
- package/dist/qwen-sessionstart-hook.js +473 -93
- package/dist/qwen-stop-hook.js +441 -95
- package/dist/status.js +115 -42
- package/dist/traecode-hook.js +441 -80
- package/dist/traecode-sessionstart-hook.js +473 -93
- package/dist/traecode-stop-hook.js +441 -95
- 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 +441 -80
- package/dist/zcode-sessionstart-hook.js +473 -93
- package/dist/zcode-stop-hook.js +441 -95
- package/package.json +9 -3
- package/plugin.json +1 -1
- package/skill/SKILL.md +4 -4
package/dist/deepen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/deepen.ts
|
|
4
|
-
import { execFileSync as
|
|
4
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
5
5
|
import { tmpdir as tmpdir2 } from "os";
|
|
6
6
|
import { join as join10 } from "path";
|
|
7
7
|
|
|
@@ -11,6 +11,7 @@ import { homedir as homedir2 } from "os";
|
|
|
11
11
|
import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
|
|
12
12
|
|
|
13
13
|
// src/core/diag.ts
|
|
14
|
+
import { readFileSync } from "fs";
|
|
14
15
|
import { join as join2 } from "path";
|
|
15
16
|
|
|
16
17
|
// src/core/log.ts
|
|
@@ -86,7 +87,7 @@ function diag(harness, event, extra = {}) {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
// src/core/git-layout.ts
|
|
89
|
-
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
90
|
+
import { lstatSync, readFileSync as readFileSync2, realpathSync } from "fs";
|
|
90
91
|
import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
|
|
91
92
|
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
92
93
|
var ATTEMPTS = 3;
|
|
@@ -110,7 +111,7 @@ function entryKind(path) {
|
|
|
110
111
|
}
|
|
111
112
|
function readTextOrNull(path) {
|
|
112
113
|
try {
|
|
113
|
-
return
|
|
114
|
+
return readFileSync2(path, "utf8");
|
|
114
115
|
} catch (error) {
|
|
115
116
|
if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
|
|
116
117
|
return null;
|
|
@@ -355,7 +356,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
|
|
|
355
356
|
// src/core/missions.ts
|
|
356
357
|
import { createHash } from "crypto";
|
|
357
358
|
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.";
|
|
358
|
-
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history,
|
|
359
|
+
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.";
|
|
359
360
|
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.`;
|
|
360
361
|
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.";
|
|
361
362
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
@@ -431,6 +432,8 @@ var KNOWLEDGE_LABELS = {
|
|
|
431
432
|
]
|
|
432
433
|
};
|
|
433
434
|
function pageScopeRule(project) {
|
|
435
|
+
if (project === void 0)
|
|
436
|
+
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.`;
|
|
434
437
|
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.`;
|
|
435
438
|
}
|
|
436
439
|
var PAGE_TAXONOMY = [
|
|
@@ -612,16 +615,19 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
612
615
|
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
613
616
|
}
|
|
614
617
|
|
|
618
|
+
// package.json
|
|
619
|
+
var version = "0.8.1";
|
|
620
|
+
|
|
615
621
|
// src/core/util.ts
|
|
616
622
|
import { accessSync, constants } from "fs";
|
|
617
623
|
import { delimiter, join as join5 } from "path";
|
|
618
624
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
619
|
-
function semverGte(
|
|
625
|
+
function semverGte(version2, min) {
|
|
620
626
|
const parts = (v) => {
|
|
621
627
|
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
622
628
|
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
623
629
|
};
|
|
624
|
-
const a =
|
|
630
|
+
const a = version2 ? parts(version2) : void 0;
|
|
625
631
|
const b = parts(min);
|
|
626
632
|
if (!a || !b) return false;
|
|
627
633
|
for (let i = 0; i < 3; i++) {
|
|
@@ -646,6 +652,7 @@ async function pool(items, n, fn, onError, onProgress) {
|
|
|
646
652
|
}
|
|
647
653
|
|
|
648
654
|
// src/core/hindsight.ts
|
|
655
|
+
var USER_AGENT = `hindsight-coding-agents/${version}`;
|
|
649
656
|
function resolveRetainScopes(tags, configured) {
|
|
650
657
|
if (configured !== "per_source") return configured;
|
|
651
658
|
const sources = [...new Set((tags ?? []).filter((t) => t.startsWith("source:")))].sort();
|
|
@@ -681,7 +688,7 @@ async function isEndpointMissing(r) {
|
|
|
681
688
|
const j = await r.json();
|
|
682
689
|
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
683
690
|
} catch {
|
|
684
|
-
return
|
|
691
|
+
return false;
|
|
685
692
|
}
|
|
686
693
|
}
|
|
687
694
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
@@ -700,6 +707,12 @@ var ReflectError = class extends Error {
|
|
|
700
707
|
get fallbackEligible() {
|
|
701
708
|
return this.timedOut || this.status !== void 0 && this.status >= 500;
|
|
702
709
|
}
|
|
710
|
+
/** A 4xx the next attempt would get again (bad key, missing bank, rejected body) — retrying it
|
|
711
|
+
* only spends another doomed call (#5207). 408/429 are "not now", so they stay retryable. */
|
|
712
|
+
get permanent() {
|
|
713
|
+
const s = this.status;
|
|
714
|
+
return s !== void 0 && s >= 400 && s < 500 && s !== 408 && s !== 429;
|
|
715
|
+
}
|
|
703
716
|
};
|
|
704
717
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
705
718
|
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
@@ -710,8 +723,10 @@ var DEFAULT_RECALL_OPTIONS = {
|
|
|
710
723
|
include: { entities: null }
|
|
711
724
|
};
|
|
712
725
|
var POLL_CYCLE_MS = 5e3;
|
|
726
|
+
var POLL_MAX_SERVER_ERRORS = 12;
|
|
713
727
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
714
728
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
729
|
+
var RATE_LIMIT_BACKOFF_MS = 1e3;
|
|
715
730
|
function shapePage(page) {
|
|
716
731
|
const p = page ?? {};
|
|
717
732
|
const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
|
|
@@ -724,6 +739,15 @@ function shapePage(page) {
|
|
|
724
739
|
body
|
|
725
740
|
};
|
|
726
741
|
}
|
|
742
|
+
var GLOBAL_DISPATCHER = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
|
|
743
|
+
function signalOnlyDispatcher() {
|
|
744
|
+
void globalThis.Headers;
|
|
745
|
+
const d = globalThis[GLOBAL_DISPATCHER];
|
|
746
|
+
if (typeof d?.compose !== "function") return void 0;
|
|
747
|
+
return d.compose(
|
|
748
|
+
(dispatch) => (opts, handler) => dispatch({ ...opts, headersTimeout: 0, bodyTimeout: 0 }, handler)
|
|
749
|
+
);
|
|
750
|
+
}
|
|
727
751
|
var HindsightClient = class {
|
|
728
752
|
apiUrl;
|
|
729
753
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -743,6 +767,7 @@ var HindsightClient = class {
|
|
|
743
767
|
observationScopes;
|
|
744
768
|
pageSearchLimit;
|
|
745
769
|
recallOptions;
|
|
770
|
+
rateLimitPatienceMs;
|
|
746
771
|
constructor(o) {
|
|
747
772
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
748
773
|
this.token = o.apiToken;
|
|
@@ -755,6 +780,7 @@ var HindsightClient = class {
|
|
|
755
780
|
this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
|
|
756
781
|
this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
|
|
757
782
|
this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
|
|
783
|
+
this.rateLimitPatienceMs = o.rateLimitPatienceMs ?? 0;
|
|
758
784
|
}
|
|
759
785
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
760
786
|
get apiToken() {
|
|
@@ -763,7 +789,8 @@ var HindsightClient = class {
|
|
|
763
789
|
headers() {
|
|
764
790
|
const h = {
|
|
765
791
|
"Content-Type": "application/json",
|
|
766
|
-
"Accept-Encoding": "identity"
|
|
792
|
+
"Accept-Encoding": "identity",
|
|
793
|
+
"User-Agent": USER_AGENT
|
|
767
794
|
};
|
|
768
795
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
769
796
|
return h;
|
|
@@ -795,7 +822,8 @@ var HindsightClient = class {
|
|
|
795
822
|
* bounds the whole call.
|
|
796
823
|
*/
|
|
797
824
|
async fetchWithAuth(url, init) {
|
|
798
|
-
const
|
|
825
|
+
const dispatcher = init.signal ? signalOnlyDispatcher() : void 0;
|
|
826
|
+
const send = () => fetch(url, { ...init, headers: this.headers(), ...dispatcher ? { dispatcher } : {} });
|
|
799
827
|
const r = await send();
|
|
800
828
|
if (r.status !== 401 || !this.refreshToken()) return r;
|
|
801
829
|
return send();
|
|
@@ -811,13 +839,22 @@ var HindsightClient = class {
|
|
|
811
839
|
}
|
|
812
840
|
/** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
|
|
813
841
|
async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
|
|
814
|
-
const
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
842
|
+
const payload = body ? JSON.stringify(body) : void 0;
|
|
843
|
+
let r;
|
|
844
|
+
for (let attempt = 0, waited = 0; ; attempt++) {
|
|
845
|
+
r = await this.fetchWithAuth(url, {
|
|
846
|
+
method,
|
|
847
|
+
body: payload,
|
|
848
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
849
|
+
});
|
|
850
|
+
if (r.status !== 429 || tolerate.includes(429)) break;
|
|
851
|
+
const asked = retryAfterMs(r.headers.get("retry-after"));
|
|
852
|
+
const backoff = Math.min(RETRY_AFTER_CEILING_MS, RATE_LIMIT_BACKOFF_MS * 2 ** attempt);
|
|
853
|
+
const wait = Math.min(RETRY_AFTER_CEILING_MS, Math.max(asked, backoff)) * (1 + Math.random() / 2);
|
|
854
|
+
if (waited + wait > this.rateLimitPatienceMs) throw new RateLimitedError(asked);
|
|
855
|
+
await sleep(wait);
|
|
856
|
+
waited += wait;
|
|
857
|
+
}
|
|
821
858
|
if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
|
|
822
859
|
throw new Error(
|
|
823
860
|
`${method} ${url} -> ${r.status} ${await r.text()}${this.authHint(r.status)}`
|
|
@@ -852,7 +889,7 @@ var HindsightClient = class {
|
|
|
852
889
|
}
|
|
853
890
|
/**
|
|
854
891
|
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
855
|
-
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via
|
|
892
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
|
|
856
893
|
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
857
894
|
*/
|
|
858
895
|
async supportsIdempotentRetain() {
|
|
@@ -862,15 +899,21 @@ var HindsightClient = class {
|
|
|
862
899
|
}
|
|
863
900
|
return this.idempotentRetain;
|
|
864
901
|
}
|
|
902
|
+
/** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
|
|
903
|
+
* hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
|
|
904
|
+
* so append silently never turned on (#5286). Servers that predate the alias still answer
|
|
905
|
+
* `/version`, so that stays as the fallback. */
|
|
865
906
|
async probeIdempotentRetain() {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
907
|
+
for (const path of ["/v1/version", "/version"]) {
|
|
908
|
+
try {
|
|
909
|
+
const r = await this.req("GET", `${this.apiUrl}${path}`);
|
|
910
|
+
if (!r.ok) continue;
|
|
911
|
+
const j = await r.json();
|
|
912
|
+
return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
|
|
913
|
+
} catch {
|
|
914
|
+
}
|
|
873
915
|
}
|
|
916
|
+
return false;
|
|
874
917
|
}
|
|
875
918
|
/**
|
|
876
919
|
* Whether a session write-back may use `update_mode="append"`: the server must dedupe by
|
|
@@ -932,6 +975,14 @@ var HindsightClient = class {
|
|
|
932
975
|
if (items.length < limit || offset + limit >= (j.total ?? 0)) return void 0;
|
|
933
976
|
}
|
|
934
977
|
}
|
|
978
|
+
/** Whether the bank holds any document at all — a one-row listing. A bank that does not exist
|
|
979
|
+
* yet (404) holds none; any other failure throws, so a caller can tell "empty" from "unknown". */
|
|
980
|
+
async hasDocuments() {
|
|
981
|
+
const r = await this.req("GET", this.bankUrl("/documents?limit=1"));
|
|
982
|
+
if (r.status === 404) return false;
|
|
983
|
+
const j = await r.json();
|
|
984
|
+
return (j.total ?? j.items?.length ?? 0) > 0;
|
|
985
|
+
}
|
|
935
986
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
936
987
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
937
988
|
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
@@ -1013,7 +1064,13 @@ var HindsightClient = class {
|
|
|
1013
1064
|
this.log(`[wait] draining ${ids.length} ${label} operations \u2026`);
|
|
1014
1065
|
const start = Date.now();
|
|
1015
1066
|
const pending = new Set(ids);
|
|
1067
|
+
const serverErrors = /* @__PURE__ */ new Map();
|
|
1016
1068
|
let failed = 0;
|
|
1069
|
+
const giveUp = (id, status) => {
|
|
1070
|
+
pending.delete(id);
|
|
1071
|
+
failed++;
|
|
1072
|
+
this.log(` \u2026 ${label} op ${id} -> HTTP ${status}, counted as failed`);
|
|
1073
|
+
};
|
|
1017
1074
|
while (pending.size && Date.now() - start < maxMs) {
|
|
1018
1075
|
let backoffMs = POLL_CYCLE_MS;
|
|
1019
1076
|
await pool([...pending], this.maxParallelRetains, async (id) => {
|
|
@@ -1026,7 +1083,14 @@ var HindsightClient = class {
|
|
|
1026
1083
|
);
|
|
1027
1084
|
return;
|
|
1028
1085
|
}
|
|
1029
|
-
if (
|
|
1086
|
+
if (r.status >= 500) {
|
|
1087
|
+
const n = (serverErrors.get(id) ?? 0) + 1;
|
|
1088
|
+
serverErrors.set(id, n);
|
|
1089
|
+
if (n >= POLL_MAX_SERVER_ERRORS) giveUp(id, r.status);
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
if (!r.ok) return giveUp(id, r.status);
|
|
1093
|
+
serverErrors.delete(id);
|
|
1030
1094
|
const st = ((await r.json()).status || "").toLowerCase();
|
|
1031
1095
|
if (TERMINAL.has(st)) {
|
|
1032
1096
|
pending.delete(id);
|
|
@@ -1210,7 +1274,7 @@ var HindsightClient = class {
|
|
|
1210
1274
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1211
1275
|
*/
|
|
1212
1276
|
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1213
|
-
const pages = pagesFor(this.project
|
|
1277
|
+
const pages = pagesFor(this.project, pagesConfig, customPages);
|
|
1214
1278
|
const existing = /* @__PURE__ */ new Map();
|
|
1215
1279
|
let roots;
|
|
1216
1280
|
try {
|
|
@@ -1285,7 +1349,7 @@ var HindsightClient = class {
|
|
|
1285
1349
|
}
|
|
1286
1350
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1287
1351
|
this.log(
|
|
1288
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ??
|
|
1352
|
+
`[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` : "")
|
|
1289
1353
|
);
|
|
1290
1354
|
}
|
|
1291
1355
|
/**
|
|
@@ -1296,23 +1360,33 @@ var HindsightClient = class {
|
|
|
1296
1360
|
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1297
1361
|
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1298
1362
|
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1301
|
-
*
|
|
1363
|
+
* Their `name` and `source_query` are written once, from the initiative's own title, and
|
|
1364
|
+
* re-stating either would rebuild a page whose question never changed. The one exception is
|
|
1365
|
+
* the scope clause: a page captured while the clause named the BANK is scoped to a project no
|
|
1366
|
+
* memory is about and comes out empty (#4490), so exactly that clause is swapped for the current
|
|
1367
|
+
* one — the rest of the query, the user's wording included, is kept. The tree read above is
|
|
1368
|
+
* reused rather than re-fetched.
|
|
1302
1369
|
*/
|
|
1303
1370
|
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1304
1371
|
const folder = roots.find(
|
|
1305
1372
|
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1306
1373
|
);
|
|
1374
|
+
const bankScope = pageScopeRule(this.bank);
|
|
1307
1375
|
let updated = 0;
|
|
1308
1376
|
for (const page of folder?.children ?? []) {
|
|
1309
|
-
if (page.kind !== "page"
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1377
|
+
if (page.kind !== "page") continue;
|
|
1378
|
+
const patch = {};
|
|
1379
|
+
const query = page.description?.replace(bankScope, pageScopeRule(this.project));
|
|
1380
|
+
if (query !== page.description) patch.source_query = query;
|
|
1381
|
+
if (page.trigger != null) {
|
|
1382
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1383
|
+
if (pageTriggerDrifted(page.trigger, desired)) patch.trigger = pageTriggerPatch(desired);
|
|
1384
|
+
}
|
|
1385
|
+
if (!patch.trigger && !patch.source_query) continue;
|
|
1312
1386
|
const r = await this.req(
|
|
1313
1387
|
"PATCH",
|
|
1314
1388
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1315
|
-
|
|
1389
|
+
patch
|
|
1316
1390
|
);
|
|
1317
1391
|
if (r.status === 404) continue;
|
|
1318
1392
|
updated++;
|
|
@@ -1340,10 +1414,9 @@ var HindsightClient = class {
|
|
|
1340
1414
|
let pageId = args.relatesToPageId;
|
|
1341
1415
|
if (!pageId) {
|
|
1342
1416
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1343
|
-
const subject = this.project ?? this.bank;
|
|
1344
1417
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1345
1418
|
name: args.title,
|
|
1346
|
-
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(
|
|
1419
|
+
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),
|
|
1347
1420
|
parent_id: folderId,
|
|
1348
1421
|
tags: ["knowledge:feature-work"],
|
|
1349
1422
|
max_tokens: PAGE_MAX_TOKENS,
|
|
@@ -1358,7 +1431,7 @@ var HindsightClient = class {
|
|
|
1358
1431
|
}
|
|
1359
1432
|
const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
|
|
1360
1433
|
const content = `${verb}: ${args.title}. ${args.summary}`;
|
|
1361
|
-
const markerId = `initiative-marker-${this.slugify(
|
|
1434
|
+
const markerId = `initiative-marker-${this.slugify(pageId)}${args.relatesToPageId ? "-update" : ""}`;
|
|
1362
1435
|
const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
|
|
1363
1436
|
const context = `initiative marker for [[page:${pageId}]]`;
|
|
1364
1437
|
await this.retain(content, context, markerId, tags, "document", {
|
|
@@ -1453,7 +1526,7 @@ async function ingestChats(client, sessions, opts = {}) {
|
|
|
1453
1526
|
}
|
|
1454
1527
|
|
|
1455
1528
|
// src/core/config.ts
|
|
1456
|
-
import { readFileSync as
|
|
1529
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1457
1530
|
import { homedir as homedir3 } from "os";
|
|
1458
1531
|
import { join as join7 } from "path";
|
|
1459
1532
|
|
|
@@ -1673,7 +1746,7 @@ function resolveConfig(raw = {}) {
|
|
|
1673
1746
|
}
|
|
1674
1747
|
function readRaw(path) {
|
|
1675
1748
|
try {
|
|
1676
|
-
return JSON.parse(
|
|
1749
|
+
return JSON.parse(readFileSync3(path, "utf8"));
|
|
1677
1750
|
} catch (e) {
|
|
1678
1751
|
if (e?.code !== "ENOENT") {
|
|
1679
1752
|
console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
|
|
@@ -1861,7 +1934,7 @@ var US = "";
|
|
|
1861
1934
|
var RS = "";
|
|
1862
1935
|
var GITLOG_HEAD = "gitlog-head:";
|
|
1863
1936
|
function git(repo, ...args) {
|
|
1864
|
-
return execFileSync("git", ["-C", repo, ...args], {
|
|
1937
|
+
return execFileSync("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
1865
1938
|
encoding: "utf8",
|
|
1866
1939
|
maxBuffer: 1 << 28,
|
|
1867
1940
|
windowsHide: true,
|
|
@@ -1934,12 +2007,17 @@ ${diff}`;
|
|
|
1934
2007
|
function gitLogText(repo, limit) {
|
|
1935
2008
|
let raw;
|
|
1936
2009
|
try {
|
|
2010
|
+
const total = Number(git(repo, "rev-list", "--count", "--no-merges", "HEAD").trim());
|
|
2011
|
+
const step = Math.max(1, Math.ceil(limit / 2));
|
|
2012
|
+
const start = total > limit ? Math.ceil((total - limit) / step) * step : 0;
|
|
1937
2013
|
raw = git(
|
|
1938
2014
|
repo,
|
|
1939
2015
|
"log",
|
|
1940
2016
|
`-n`,
|
|
1941
|
-
String(
|
|
2017
|
+
String(total - start),
|
|
1942
2018
|
"--no-merges",
|
|
2019
|
+
"--reverse",
|
|
2020
|
+
// applied after -n: the newest N, printed oldest first
|
|
1943
2021
|
"--date=short",
|
|
1944
2022
|
`--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`
|
|
1945
2023
|
);
|
|
@@ -2028,7 +2106,7 @@ async function syncGitLog(client, repo, opts) {
|
|
|
2028
2106
|
}
|
|
2029
2107
|
|
|
2030
2108
|
// src/core/survey.ts
|
|
2031
|
-
import { spawn as realSpawn3 } from "child_process";
|
|
2109
|
+
import { execFileSync as execFileSync2, spawn as realSpawn3 } from "child_process";
|
|
2032
2110
|
import { createHash as createHash4 } from "crypto";
|
|
2033
2111
|
import { existsSync as existsSync2 } from "fs";
|
|
2034
2112
|
import { homedir as homedir4, tmpdir } from "os";
|
|
@@ -2125,16 +2203,16 @@ var SURVEY_DOC_IDS = [
|
|
|
2125
2203
|
];
|
|
2126
2204
|
|
|
2127
2205
|
// src/core/status.ts
|
|
2128
|
-
import { execFileSync as
|
|
2206
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
2129
2207
|
var DEEPEN_DIFF_TARGET = 300;
|
|
2130
2208
|
|
|
2131
2209
|
// src/harness/registry.ts
|
|
2132
|
-
import { readFileSync as
|
|
2210
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
2133
2211
|
var jsonChatReader = (harness) => ({
|
|
2134
2212
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
2135
2213
|
async read(opts) {
|
|
2136
2214
|
if (!opts.conversations) return [];
|
|
2137
|
-
return JSON.parse(
|
|
2215
|
+
return JSON.parse(readFileSync4(opts.conversations, "utf8"));
|
|
2138
2216
|
}
|
|
2139
2217
|
});
|
|
2140
2218
|
var noRuntimeAdapter = (name, hint) => ({
|
|
@@ -2178,7 +2256,15 @@ var HARNESS_NAMES = [
|
|
|
2178
2256
|
"zcode",
|
|
2179
2257
|
// TraeCode is a per-prompt HOOK host registered in ~/.trae-cn/hooks.json (see src/installer.ts).
|
|
2180
2258
|
"traecode",
|
|
2181
|
-
"kimi-code"
|
|
2259
|
+
"kimi-code",
|
|
2260
|
+
// WorkBuddy is a per-prompt HOOK host too: the installer wires ~/.workbuddy/settings.json and
|
|
2261
|
+
// the stdio MCP registration in ~/.workbuddy/mcp.json (see src/installer.ts).
|
|
2262
|
+
"workbuddy",
|
|
2263
|
+
// CodeBuddy Code is the SAME @genie/agent-cli HOOK host, one product config apart (WorkBuddy only
|
|
2264
|
+
// renames the home folder): the installer wires ~/.codebuddy/settings.json and the stdio MCP
|
|
2265
|
+
// registration in CodeBuddy's priority-chained MCP file (see src/installer.ts). The CLI
|
|
2266
|
+
// writes WorkBuddy's transcript format; the CodeBuddy IDE has a reader of its own.
|
|
2267
|
+
"codebuddy"
|
|
2182
2268
|
];
|
|
2183
2269
|
var HOOK_BINS = {
|
|
2184
2270
|
"claude-code": "hindsight-claude-hook",
|
|
@@ -2193,7 +2279,9 @@ var HOOK_BINS = {
|
|
|
2193
2279
|
"factory-droid": "hindsight-droid-hook",
|
|
2194
2280
|
zcode: "hindsight-zcode-hook",
|
|
2195
2281
|
traecode: "hindsight-traecode-hook",
|
|
2196
|
-
"kimi-code": "hindsight-kimi-hook"
|
|
2282
|
+
"kimi-code": "hindsight-kimi-hook",
|
|
2283
|
+
workbuddy: "hindsight-workbuddy-hook",
|
|
2284
|
+
codebuddy: "hindsight-codebuddy-hook"
|
|
2197
2285
|
// more hook harnesses: add a HookSpec entry point (see src/cursor-hook.ts) + a registration here.
|
|
2198
2286
|
};
|
|
2199
2287
|
var PLUGIN_ENTRYPOINTS = {
|
|
@@ -2335,10 +2423,13 @@ async function main() {
|
|
|
2335
2423
|
// outlive the session, so a bank several repos share must not be told it is whichever one
|
|
2336
2424
|
// ran last (#4146). `bankProjectName` answers only when the bank IS this repo's; the
|
|
2337
2425
|
// `banks.<id>.bank` rename below it can point many repos at one destination, so a renamed
|
|
2338
|
-
// bank is not this repo's either. Undefined
|
|
2426
|
+
// bank is not this repo's either. Undefined gives the shared-bank scope (#4490).
|
|
2339
2427
|
project: PAGE_PROJECT,
|
|
2340
2428
|
maxParallelRetains: cfg.maxParallelRetains,
|
|
2341
2429
|
observationScopes: cfg.observationScopes,
|
|
2430
|
+
// Nobody waits on a background seed, and a 429 it gives up on is history missing from the
|
|
2431
|
+
// bank until some later session happens to re-run it.
|
|
2432
|
+
rateLimitPatienceMs: 10 * 60 * 1e3,
|
|
2342
2433
|
log: log2
|
|
2343
2434
|
});
|
|
2344
2435
|
log2(`deepen -> ${client.apiUrl} bank=${FINAL_BANK} harness=${harness.name}`);
|
|
@@ -2387,7 +2478,7 @@ async function main() {
|
|
|
2387
2478
|
gitFails += await syncGitLog(client, REPO, { limit: GITLOG_LIMIT, log: log2, stampFor });
|
|
2388
2479
|
if (GIT_INGEST === "full") {
|
|
2389
2480
|
try {
|
|
2390
|
-
const shas =
|
|
2481
|
+
const shas = execFileSync4(
|
|
2391
2482
|
"git",
|
|
2392
2483
|
["-C", REPO, "rev-list", `-n`, String(DEEPEN_DIFF_TARGET), "HEAD"],
|
|
2393
2484
|
// `install` runs this with inherited stdio: an empty repo's HEAD error must not print.
|