@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.
Files changed (62) hide show
  1. package/README.md +67 -6
  2. package/dist/antigravity-hook.js +441 -80
  3. package/dist/antigravity-statusline.js +9 -4
  4. package/dist/antigravity-stop-hook.js +441 -95
  5. package/dist/claude-hook.js +441 -80
  6. package/dist/claude-sessionstart-hook.js +473 -93
  7. package/dist/claude-stop-hook.js +441 -95
  8. package/dist/cline.js +290 -95
  9. package/dist/codebuddy-hook.js +4270 -0
  10. package/dist/codebuddy-sessionstart-hook.js +5030 -0
  11. package/dist/codebuddy-stop-hook.js +4564 -0
  12. package/dist/codex-hook.js +441 -80
  13. package/dist/codex-sessionstart-hook.js +473 -93
  14. package/dist/codex-stop-hook.js +441 -95
  15. package/dist/copilot-hook.js +441 -80
  16. package/dist/copilot-sessionstart-hook.js +473 -93
  17. package/dist/copilot-stop-hook.js +441 -95
  18. package/dist/cursor-hook.js +441 -80
  19. package/dist/cursor-sessionstart-hook.js +473 -93
  20. package/dist/cursor-stop-hook.js +441 -95
  21. package/dist/daemon-start.js +16 -8
  22. package/dist/dcode-hook.js +441 -80
  23. package/dist/dcode-sessionstart-hook.js +473 -93
  24. package/dist/dcode-stop-hook.js +441 -95
  25. package/dist/deepen.js +140 -49
  26. package/dist/devin-hook.js +441 -80
  27. package/dist/devin-sessionstart-hook.js +473 -93
  28. package/dist/devin-stop-hook.js +441 -95
  29. package/dist/droid-hook.js +441 -80
  30. package/dist/droid-sessionstart-hook.js +473 -93
  31. package/dist/droid-stop-hook.js +441 -95
  32. package/dist/dsh.js +297 -95
  33. package/dist/grok-hook.js +441 -80
  34. package/dist/grok-sessionstart-hook.js +473 -93
  35. package/dist/grok-stop-hook.js +441 -95
  36. package/dist/hindsight-seed.js +9 -4
  37. package/dist/index.js +299 -104
  38. package/dist/installer.js +1043 -647
  39. package/dist/kilo.js +299 -104
  40. package/dist/kimi-hook.js +441 -80
  41. package/dist/kimi-sessionstart-hook.js +473 -93
  42. package/dist/kimi-stop-hook.js +441 -95
  43. package/dist/mcp-server.js +261 -86
  44. package/dist/opencode2.js +296 -101
  45. package/dist/pi.js +352 -107
  46. package/dist/prime-agent.js +352 -107
  47. package/dist/qwen-hook.js +441 -80
  48. package/dist/qwen-sessionstart-hook.js +473 -93
  49. package/dist/qwen-stop-hook.js +441 -95
  50. package/dist/status.js +115 -42
  51. package/dist/traecode-hook.js +441 -80
  52. package/dist/traecode-sessionstart-hook.js +473 -93
  53. package/dist/traecode-stop-hook.js +441 -95
  54. package/dist/workbuddy-hook.js +4270 -0
  55. package/dist/workbuddy-sessionstart-hook.js +5030 -0
  56. package/dist/workbuddy-stop-hook.js +4564 -0
  57. package/dist/zcode-hook.js +441 -80
  58. package/dist/zcode-sessionstart-hook.js +473 -93
  59. package/dist/zcode-stop-hook.js +441 -95
  60. package/package.json +9 -3
  61. package/plugin.json +1 -1
  62. package/skill/SKILL.md +4 -4
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 readFileSync(path, "utf8");
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;
@@ -318,7 +319,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
318
319
  }
319
320
 
320
321
  // src/core/config.ts
321
- import { readFileSync as readFileSync2 } from "fs";
322
+ import { readFileSync as readFileSync3 } from "fs";
322
323
  import { homedir as homedir3 } from "os";
323
324
  import { join as join7 } from "path";
324
325
 
@@ -331,7 +332,7 @@ var DEFAULT_SEED_LIMIT = 300;
331
332
  // src/core/missions.ts
332
333
  import { createHash } from "crypto";
333
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.";
334
- var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, newest 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.";
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.";
335
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.`;
336
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.";
337
338
  var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
@@ -407,6 +408,8 @@ var KNOWLEDGE_LABELS = {
407
408
  ]
408
409
  };
409
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.`;
410
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.`;
411
414
  }
412
415
  var PAGE_TAXONOMY = [
@@ -588,16 +591,19 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
588
591
  return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
589
592
  }
590
593
 
594
+ // package.json
595
+ var version = "0.8.1";
596
+
591
597
  // src/core/util.ts
592
598
  import { accessSync, constants } from "fs";
593
599
  import { delimiter, join as join6 } from "path";
594
600
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
595
- function semverGte(version, min) {
601
+ function semverGte(version2, min) {
596
602
  const parts = (v) => {
597
603
  const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
598
604
  return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
599
605
  };
600
- const a = version ? parts(version) : void 0;
606
+ const a = version2 ? parts(version2) : void 0;
601
607
  const b = parts(min);
602
608
  if (!a || !b) return false;
603
609
  for (let i = 0; i < 3; i++) {
@@ -622,6 +628,7 @@ async function pool(items, n, fn, onError, onProgress) {
622
628
  }
623
629
 
624
630
  // src/core/hindsight.ts
631
+ var USER_AGENT = `hindsight-coding-agents/${version}`;
625
632
  function resolveRetainScopes(tags, configured) {
626
633
  if (configured !== "per_source") return configured;
627
634
  const sources = [...new Set((tags ?? []).filter((t) => t.startsWith("source:")))].sort();
@@ -657,7 +664,7 @@ async function isEndpointMissing(r) {
657
664
  const j = await r.json();
658
665
  return String(j?.detail ?? "").trim().toLowerCase() === "not found";
659
666
  } catch {
660
- return true;
667
+ return false;
661
668
  }
662
669
  }
663
670
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
@@ -676,6 +683,12 @@ var ReflectError = class extends Error {
676
683
  get fallbackEligible() {
677
684
  return this.timedOut || this.status !== void 0 && this.status >= 500;
678
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
+ }
679
692
  };
680
693
  var DEFAULT_MAX_PARALLEL_RETAINS = 10;
681
694
  var DEFAULT_PAGE_SEARCH_LIMIT = 10;
@@ -686,8 +699,10 @@ var DEFAULT_RECALL_OPTIONS = {
686
699
  include: { entities: null }
687
700
  };
688
701
  var POLL_CYCLE_MS = 5e3;
702
+ var POLL_MAX_SERVER_ERRORS = 12;
689
703
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
690
704
  var RETRY_AFTER_CEILING_MS = 60 * 1e3;
705
+ var RATE_LIMIT_BACKOFF_MS = 1e3;
691
706
  function shapePage(page) {
692
707
  const p = page ?? {};
693
708
  const body = typeof p.body === "string" && p.body.trim() ? p.body : p.markdown;
@@ -700,6 +715,15 @@ function shapePage(page) {
700
715
  body
701
716
  };
702
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
+ }
703
727
  var HindsightClient = class {
704
728
  apiUrl;
705
729
  /** The credential the NEXT request will sign with — NOT the one the config file holds. The two
@@ -719,6 +743,7 @@ var HindsightClient = class {
719
743
  observationScopes;
720
744
  pageSearchLimit;
721
745
  recallOptions;
746
+ rateLimitPatienceMs;
722
747
  constructor(o) {
723
748
  this.apiUrl = o.apiUrl.replace(/\/$/, "");
724
749
  this.token = o.apiToken;
@@ -731,6 +756,7 @@ var HindsightClient = class {
731
756
  this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
732
757
  this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
733
758
  this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
759
+ this.rateLimitPatienceMs = o.rateLimitPatienceMs ?? 0;
734
760
  }
735
761
  /** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
736
762
  get apiToken() {
@@ -739,7 +765,8 @@ var HindsightClient = class {
739
765
  headers() {
740
766
  const h = {
741
767
  "Content-Type": "application/json",
742
- "Accept-Encoding": "identity"
768
+ "Accept-Encoding": "identity",
769
+ "User-Agent": USER_AGENT
743
770
  };
744
771
  if (this.token) h["Authorization"] = `Bearer ${this.token}`;
745
772
  return h;
@@ -771,7 +798,8 @@ var HindsightClient = class {
771
798
  * bounds the whole call.
772
799
  */
773
800
  async fetchWithAuth(url, init) {
774
- const send = () => fetch(url, { ...init, headers: this.headers() });
801
+ const dispatcher = init.signal ? signalOnlyDispatcher() : void 0;
802
+ const send = () => fetch(url, { ...init, headers: this.headers(), ...dispatcher ? { dispatcher } : {} });
775
803
  const r = await send();
776
804
  if (r.status !== 401 || !this.refreshToken()) return r;
777
805
  return send();
@@ -787,13 +815,22 @@ var HindsightClient = class {
787
815
  }
788
816
  /** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
789
817
  async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
790
- const r = await this.fetchWithAuth(url, {
791
- method,
792
- body: body ? JSON.stringify(body) : void 0,
793
- signal: AbortSignal.timeout(timeoutMs)
794
- });
795
- if (r.status === 429 && !tolerate.includes(429))
796
- throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
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
+ }
797
834
  if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
798
835
  throw new Error(
799
836
  `${method} ${url} -> ${r.status} ${await r.text()}${this.authHint(r.status)}`
@@ -828,7 +865,7 @@ var HindsightClient = class {
828
865
  }
829
866
  /**
830
867
  * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
831
- * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
868
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
832
869
  * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
833
870
  */
834
871
  async supportsIdempotentRetain() {
@@ -838,15 +875,21 @@ var HindsightClient = class {
838
875
  }
839
876
  return this.idempotentRetain;
840
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. */
841
882
  async probeIdempotentRetain() {
842
- try {
843
- const r = await this.req("GET", `${this.apiUrl}/version`);
844
- if (!r.ok) return false;
845
- const j = await r.json();
846
- return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
847
- } catch {
848
- return false;
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
+ }
849
891
  }
892
+ return false;
850
893
  }
851
894
  /**
852
895
  * Whether a session write-back may use `update_mode="append"`: the server must dedupe by
@@ -908,6 +951,14 @@ var HindsightClient = class {
908
951
  if (items.length < limit || offset + limit >= (j.total ?? 0)) return void 0;
909
952
  }
910
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
+ }
911
962
  /** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
912
963
  * entity labels), then seed knowledge pages when the server supports them. Both halves are
913
964
  * idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
@@ -989,7 +1040,13 @@ var HindsightClient = class {
989
1040
  this.log(`[wait] draining ${ids.length} ${label} operations \u2026`);
990
1041
  const start = Date.now();
991
1042
  const pending = new Set(ids);
1043
+ const serverErrors = /* @__PURE__ */ new Map();
992
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
+ };
993
1050
  while (pending.size && Date.now() - start < maxMs) {
994
1051
  let backoffMs = POLL_CYCLE_MS;
995
1052
  await pool([...pending], this.maxParallelRetains, async (id) => {
@@ -1002,7 +1059,14 @@ var HindsightClient = class {
1002
1059
  );
1003
1060
  return;
1004
1061
  }
1005
- if (!r.ok) return;
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);
1006
1070
  const st = ((await r.json()).status || "").toLowerCase();
1007
1071
  if (TERMINAL.has(st)) {
1008
1072
  pending.delete(id);
@@ -1186,7 +1250,7 @@ var HindsightClient = class {
1186
1250
  * which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
1187
1251
  */
1188
1252
  async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
1189
- const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
1253
+ const pages = pagesFor(this.project, pagesConfig, customPages);
1190
1254
  const existing = /* @__PURE__ */ new Map();
1191
1255
  let roots;
1192
1256
  try {
@@ -1261,7 +1325,7 @@ var HindsightClient = class {
1261
1325
  }
1262
1326
  const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
1263
1327
  this.log(
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` : "")
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` : "")
1265
1329
  );
1266
1330
  }
1267
1331
  /**
@@ -1272,23 +1336,33 @@ var HindsightClient = class {
1272
1336
  * it: five taxonomy pages against one page per initiative, each an LLM synthesis per
1273
1337
  * consolidation under the auto-refresh that used to be the default (#3506).
1274
1338
  *
1275
- * Only the trigger is touched. Their `name` and `source_query` are written once, from the
1276
- * initiative's own title, and re-stating either would rebuild a page whose question never
1277
- * changed. The tree read above is reused rather than re-fetched.
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.
1278
1345
  */
1279
1346
  async resyncInitiativeTriggers(roots, pageTrigger) {
1280
1347
  const folder = roots.find(
1281
1348
  (n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
1282
1349
  );
1350
+ const bankScope = pageScopeRule(this.bank);
1283
1351
  let updated = 0;
1284
1352
  for (const page of folder?.children ?? []) {
1285
- if (page.kind !== "page" || page.trigger == null) continue;
1286
- const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
1287
- if (!pageTriggerDrifted(page.trigger, desired)) continue;
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;
1288
1362
  const r = await this.req(
1289
1363
  "PATCH",
1290
1364
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
1291
- { trigger: pageTriggerPatch(desired) }
1365
+ patch
1292
1366
  );
1293
1367
  if (r.status === 404) continue;
1294
1368
  updated++;
@@ -1316,10 +1390,9 @@ var HindsightClient = class {
1316
1390
  let pageId = args.relatesToPageId;
1317
1391
  if (!pageId) {
1318
1392
  const folderId = await this.ensureFolder("Initiatives");
1319
- const subject = this.project ?? this.bank;
1320
1393
  const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
1321
1394
  name: args.title,
1322
- 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(subject),
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),
1323
1396
  parent_id: folderId,
1324
1397
  tags: ["knowledge:feature-work"],
1325
1398
  max_tokens: PAGE_MAX_TOKENS,
@@ -1334,7 +1407,7 @@ var HindsightClient = class {
1334
1407
  }
1335
1408
  const verb = args.relatesToPageId ? "Update to an existing initiative" : "New initiative";
1336
1409
  const content = `${verb}: ${args.title}. ${args.summary}`;
1337
- const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
1410
+ const markerId = `initiative-marker-${this.slugify(pageId)}${args.relatesToPageId ? "-update" : ""}`;
1338
1411
  const tags = [.../* @__PURE__ */ new Set([...args.stamp?.tags ?? [], "knowledge:feature-work"])];
1339
1412
  const context = `initiative marker for [[page:${pageId}]]`;
1340
1413
  await this.retain(content, context, markerId, tags, "document", {
@@ -1571,7 +1644,7 @@ function resolveConfig(raw = {}) {
1571
1644
  }
1572
1645
  function readRaw(path) {
1573
1646
  try {
1574
- return JSON.parse(readFileSync2(path, "utf8"));
1647
+ return JSON.parse(readFileSync3(path, "utf8"));
1575
1648
  } catch (e) {
1576
1649
  if (e?.code !== "ENOENT") {
1577
1650
  console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
@@ -1753,13 +1826,13 @@ function resolvePartial(cfg2, patch) {
1753
1826
  }
1754
1827
 
1755
1828
  // src/core/status.ts
1756
- import { execFileSync as execFileSync2 } from "child_process";
1829
+ import { execFileSync as execFileSync3 } from "child_process";
1757
1830
 
1758
1831
  // src/core/git.ts
1759
1832
  import { execFileSync } from "child_process";
1760
1833
  import { resolve as resolve2 } from "path";
1761
1834
  function git(repo, ...args) {
1762
- return execFileSync("git", ["-C", repo, ...args], {
1835
+ return execFileSync("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
1763
1836
  encoding: "utf8",
1764
1837
  maxBuffer: 1 << 28,
1765
1838
  windowsHide: true,
@@ -1795,7 +1868,7 @@ function parsePageList(raw) {
1795
1868
  }
1796
1869
 
1797
1870
  // src/core/survey.ts
1798
- import { spawn as realSpawn3 } from "child_process";
1871
+ import { execFileSync as execFileSync2, spawn as realSpawn3 } from "child_process";
1799
1872
  import { createHash as createHash2 } from "crypto";
1800
1873
  import { existsSync as existsSync2 } from "fs";
1801
1874
  import { homedir as homedir4, tmpdir } from "os";
@@ -1831,7 +1904,7 @@ var SURVEY_DOC_IDS = [
1831
1904
  var DEEPEN_DIFF_TARGET = 300;
1832
1905
  function commitCount(repoDir) {
1833
1906
  try {
1834
- const out = execFileSync2("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
1907
+ const out = execFileSync3("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
1835
1908
  encoding: "utf8",
1836
1909
  windowsHide: true,
1837
1910
  stdio: ["ignore", "pipe", "pipe"]