@vectorize-io/hindsight-coding-agents 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +179 -40
  2. package/dist/antigravity-hook.js +343 -158
  3. package/dist/antigravity-statusline.js +117 -4
  4. package/dist/antigravity-stop-hook.js +262 -113
  5. package/dist/claude-hook.js +343 -158
  6. package/dist/claude-sessionstart-hook.js +348 -136
  7. package/dist/claude-stop-hook.js +262 -113
  8. package/dist/cline.js +493 -173
  9. package/dist/codex-hook.js +343 -158
  10. package/dist/codex-sessionstart-hook.js +348 -136
  11. package/dist/codex-stop-hook.js +262 -113
  12. package/dist/copilot-hook.js +343 -158
  13. package/dist/copilot-sessionstart-hook.js +348 -136
  14. package/dist/copilot-stop-hook.js +262 -113
  15. package/dist/cursor-hook.js +343 -158
  16. package/dist/cursor-sessionstart-hook.js +348 -136
  17. package/dist/cursor-stop-hook.js +262 -113
  18. package/dist/daemon-start.js +116 -4
  19. package/dist/dcode-hook.js +343 -158
  20. package/dist/dcode-sessionstart-hook.js +348 -136
  21. package/dist/dcode-stop-hook.js +262 -113
  22. package/dist/deepen.js +204 -47
  23. package/dist/devin-hook.js +343 -158
  24. package/dist/devin-sessionstart-hook.js +348 -136
  25. package/dist/devin-stop-hook.js +262 -113
  26. package/dist/droid-hook.js +343 -158
  27. package/dist/droid-sessionstart-hook.js +348 -136
  28. package/dist/droid-stop-hook.js +262 -113
  29. package/dist/dsh.js +493 -173
  30. package/dist/grok-hook.js +343 -158
  31. package/dist/grok-sessionstart-hook.js +348 -136
  32. package/dist/grok-stop-hook.js +262 -113
  33. package/dist/hindsight-seed.js +116 -4
  34. package/dist/index.js +493 -173
  35. package/dist/installer.js +92 -70
  36. package/dist/kilo.js +493 -173
  37. package/dist/mcp-server.js +230 -57
  38. package/dist/opencode2.js +520 -173
  39. package/dist/pi.js +494 -175
  40. package/dist/prime-agent.js +494 -175
  41. package/dist/qwen-hook.js +343 -158
  42. package/dist/qwen-sessionstart-hook.js +348 -136
  43. package/dist/qwen-stop-hook.js +262 -113
  44. package/dist/status.js +203 -47
  45. package/dist/zcode-hook.js +343 -158
  46. package/dist/zcode-sessionstart-hook.js +348 -136
  47. package/dist/zcode-stop-hook.js +262 -113
  48. package/package.json +2 -2
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +173 -39
@@ -53,6 +53,20 @@ var log = {
53
53
  warn: (scope, msg, extra) => write("warn", scope, msg, extra),
54
54
  error: (scope, msg, extra) => write("error", scope, msg, extra)
55
55
  };
56
+ function describeError(value, maxChars = 200) {
57
+ const parts = [];
58
+ const seen = /* @__PURE__ */ new Set();
59
+ let current2 = value;
60
+ while (current2 && !seen.has(current2)) {
61
+ seen.add(current2);
62
+ const error = current2;
63
+ const text = typeof error.message === "string" ? error.message : String(current2);
64
+ const withCode = error.code ? `${text} (${String(error.code)})` : text;
65
+ if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
66
+ current2 = error.cause;
67
+ }
68
+ return (parts.join(": ") || String(value)).slice(0, maxChars);
69
+ }
56
70
 
57
71
  // src/core/diag.ts
58
72
  function diagFilePath() {
@@ -365,13 +379,15 @@ var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSON
365
379
  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.";
366
380
  var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
367
381
  var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
382
+ var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
383
+ var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
368
384
  var RETAIN_STRATEGIES = {
369
- git: { retain_mission: GIT_MISSION, retain_extraction_mode: "verbose" },
385
+ git: { retain_mission: GIT_MISSION, retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE },
370
386
  // ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
371
387
  // in as few chunks as possible and the extractor sees the whole history arc at once.
372
388
  gitlog: {
373
389
  retain_mission: GITLOG_MISSION,
374
- retain_extraction_mode: "verbose",
390
+ retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
375
391
  retain_chunk_size: 12e3
376
392
  },
377
393
  // ONE strategy for ALL developer conversations — backfilled decision chats and live working
@@ -382,15 +398,15 @@ var RETAIN_STRATEGIES = {
382
398
  // the consolidation layer.
383
399
  conversation: {
384
400
  retain_mission: CONVERSATION_MISSION,
385
- retain_extraction_mode: "verbose",
401
+ retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
386
402
  retain_chunk_size: 12e3
387
403
  },
388
404
  // Structural documents (e.g. the codebase survey's ingested findings) aren't dialogue — the
389
- // chat strategy's "final decision vs rejected proposal" extraction doesn't apply. Verbose mode
390
- // with a bigger chunk size (documents can run long) captures the concrete facts/structure instead.
405
+ // chat strategy's "final decision vs rejected proposal" extraction doesn't apply. A bigger chunk
406
+ // size (documents can run long) keeps the concrete facts/structure together instead.
391
407
  document: {
392
408
  retain_mission: DOCUMENT_MISSION,
393
- retain_extraction_mode: "verbose",
409
+ retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
394
410
  retain_chunk_size: 12e3
395
411
  },
396
412
  // Codebase-SURVEY lifecycle documents, ONE strategy with conditional rules: the survey's
@@ -463,9 +479,22 @@ var PAGE_TAXONOMY = [
463
479
  tags: ["knowledge:feature-work"]
464
480
  }
465
481
  ];
466
- function pagesFor(project) {
482
+ var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
483
+ function pagesFor(project, pages = {}, customPages = {}) {
467
484
  const scope = pageScopeRule(project);
468
- return PAGE_TAXONOMY.map((page) => ({ ...page, source_query: page.source_query + scope }));
485
+ const byName = new Map(
486
+ Object.entries(pages).map(([name, override]) => [name.trim().toLowerCase(), override])
487
+ );
488
+ const out = [];
489
+ for (const page of PAGE_TAXONOMY) {
490
+ const override = byName.get(page.name.toLowerCase());
491
+ if (override === false) continue;
492
+ out.push({ ...page, source_query: (override?.source_query || page.source_query) + scope });
493
+ }
494
+ for (const [name, page] of Object.entries(customPages)) {
495
+ out.push({ name: name.trim(), source_query: page.source_query + scope, tags: page.tags ?? [] });
496
+ }
497
+ return out;
469
498
  }
470
499
  var PAGE_MAX_TOKENS = 4096;
471
500
  var PAGE_TAGS_MATCH = "all";
@@ -548,7 +577,7 @@ var CODING_BANK_TEMPLATE = {
548
577
  enable_observations: true,
549
578
  observations_mission: OBSERVATIONS_MISSION,
550
579
  retain_mission: GIT_MISSION,
551
- retain_extraction_mode: "verbose",
580
+ retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
552
581
  retain_default_strategy: "git",
553
582
  retain_strategies: RETAIN_STRATEGIES,
554
583
  entity_labels: [KNOWLEDGE_LABELS],
@@ -561,7 +590,7 @@ function isSet(v) {
561
590
  if (typeof v === "string") return v.trim() !== "";
562
591
  return true;
563
592
  }
564
- function codingBankManifest(overrides) {
593
+ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
565
594
  const current2 = overrides ?? {};
566
595
  const template = CODING_BANK_TEMPLATE.bank;
567
596
  const bank = {};
@@ -570,16 +599,22 @@ function codingBankManifest(overrides) {
570
599
  bank.enable_observations = template.enable_observations;
571
600
  bank.observations_mission = template.observations_mission;
572
601
  bank.retain_mission = template.retain_mission;
573
- bank.retain_extraction_mode = template.retain_extraction_mode;
602
+ bank.retain_extraction_mode = mode;
574
603
  }
575
604
  if (!isSet(current2.retain_default_strategy))
576
605
  bank.retain_default_strategy = template.retain_default_strategy;
577
606
  if (!isSet(current2.entities_allow_free_form))
578
607
  bank.entities_allow_free_form = template.entities_allow_free_form;
579
608
  const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
580
- const missing = Object.entries(template.retain_strategies).filter(([n]) => !(n in strategies));
581
- if (missing.length > 0)
582
- bank.retain_strategies = { ...strategies, ...Object.fromEntries(missing) };
609
+ const updates = {};
610
+ for (const [name, def] of Object.entries(template.retain_strategies)) {
611
+ const synced = def.retain_extraction_mode === "custom" ? {} : { retain_extraction_mode: mode };
612
+ const have = strategies[name];
613
+ if (!have || typeof have !== "object") updates[name] = { ...def, ...synced };
614
+ else if ("retain_extraction_mode" in synced && have.retain_extraction_mode !== mode)
615
+ updates[name] = { ...have, ...synced };
616
+ }
617
+ if (Object.keys(updates).length > 0) bank.retain_strategies = { ...strategies, ...updates };
583
618
  const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
584
619
  const [knowledgeGroup] = template.entity_labels;
585
620
  if (!labels.some((g) => g?.key === knowledgeGroup.key))
@@ -670,6 +705,14 @@ var KnowledgePagesUnavailableError = class extends Error {
670
705
  this.name = "KnowledgePagesUnavailableError";
671
706
  }
672
707
  };
708
+ async function isEndpointMissing(r) {
709
+ try {
710
+ const j = await r.json();
711
+ return String(j?.detail ?? "").trim().toLowerCase() === "not found";
712
+ } catch {
713
+ return true;
714
+ }
715
+ }
673
716
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
674
717
  var ReflectError = class extends Error {
675
718
  constructor(message, status, timedOut, options) {
@@ -688,6 +731,13 @@ var ReflectError = class extends Error {
688
731
  }
689
732
  };
690
733
  var DEFAULT_MAX_PARALLEL_RETAINS = 10;
734
+ var DEFAULT_PAGE_SEARCH_LIMIT = 10;
735
+ var DEFAULT_RECALL_OPTIONS = {
736
+ types: ["observation"],
737
+ budget: "low",
738
+ max_tokens: 2e3,
739
+ include: { entities: null }
740
+ };
691
741
  var POLL_CYCLE_MS = 5e3;
692
742
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
693
743
  var RETRY_AFTER_CEILING_MS = 60 * 1e3;
@@ -708,6 +758,8 @@ var HindsightClient = class {
708
758
  log;
709
759
  maxParallelRetains;
710
760
  observationScopes;
761
+ pageSearchLimit;
762
+ recallOptions;
711
763
  constructor(o) {
712
764
  this.apiUrl = o.apiUrl.replace(/\/$/, "");
713
765
  this.token = o.apiToken;
@@ -718,6 +770,8 @@ var HindsightClient = class {
718
770
  });
719
771
  this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
720
772
  this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
773
+ this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
774
+ this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
721
775
  }
722
776
  /** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
723
777
  get apiToken() {
@@ -859,7 +913,8 @@ var HindsightClient = class {
859
913
  }
860
914
  /** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
861
915
  * entity labels), then seed knowledge pages when the server supports them. Both halves are
862
- * idempotent and strictly ADDITIVE — nothing the bank already says is overwritten (#3927) — so
916
+ * idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
917
+ * extraction mode of the plugin's own strategies, which follows its config (#4560) — so
863
918
  * the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
864
919
  * continue with the template-only path.
865
920
  *
@@ -875,7 +930,10 @@ var HindsightClient = class {
875
930
  if (opts.manage === false) {
876
931
  this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
877
932
  } else {
878
- const manifest = codingBankManifest(opts.reset ? void 0 : await this.readBankOverrides());
933
+ const manifest = codingBankManifest(
934
+ opts.reset ? void 0 : await this.readBankOverrides(),
935
+ opts.extractionMode
936
+ );
879
937
  if (!manifest) {
880
938
  this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
881
939
  } else {
@@ -883,7 +941,7 @@ var HindsightClient = class {
883
941
  this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
884
942
  }
885
943
  }
886
- await this.seedPages(opts.pageTrigger);
944
+ await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
887
945
  }
888
946
  /**
889
947
  * This bank's own config OVERRIDES, or undefined when there are none to read.
@@ -999,20 +1057,22 @@ var HindsightClient = class {
999
1057
  }
1000
1058
  }
1001
1059
  /**
1002
- * Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
1003
- * when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
1060
+ * Raw recall with no LLM in the loop, so it still answers when reflect's synthesis times out or
1061
+ * 5xxs. The body is `recallOptions` (consolidated observations by default) — a bank that grows
1062
+ * no observations widens it rather than getting nothing back. Returns the texts in rank order.
1063
+ *
1064
+ * The name predates `recallOptions` (the observation type used to be hardcoded here) and is
1065
+ * kept deliberately: this is the client's published surface, so renaming it would break
1066
+ * importers for a cosmetic gain. The doc above is the contract, not the name.
1004
1067
  */
1005
1068
  async recallObservations(query, opts) {
1006
1069
  const r = await this.req(
1007
1070
  "POST",
1008
1071
  this.bankUrl("/memories/recall"),
1009
- {
1010
- query,
1011
- types: ["observation"],
1012
- budget: "low",
1013
- max_tokens: opts.maxTokens,
1014
- include: { entities: null }
1015
- },
1072
+ // `query` is applied AFTER the spread: everything else is the caller's to override, but a
1073
+ // config that could replace the goal with a fixed string would silently recall for the
1074
+ // wrong question on every turn.
1075
+ { ...this.recallOptions, query },
1016
1076
  [],
1017
1077
  opts.timeoutMs
1018
1078
  );
@@ -1020,6 +1080,19 @@ var HindsightClient = class {
1020
1080
  const j = await r.json();
1021
1081
  return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
1022
1082
  }
1083
+ /**
1084
+ * Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
1085
+ * Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
1086
+ * expected answer before the bank's first retain — so it must never cache a negative (#4607).
1087
+ *
1088
+ * Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
1089
+ * the 405/501 this used to check for never reach a caller in the first place.
1090
+ */
1091
+ async pagesUnsupported(r) {
1092
+ if (r.status !== 404 || !await isEndpointMissing(r)) return false;
1093
+ this.knowledgePagesSupported = false;
1094
+ return true;
1095
+ }
1023
1096
  /**
1024
1097
  * The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
1025
1098
  * queries and staleness but NOT synthesized content, so it is cheap enough to poll.
@@ -1027,10 +1100,8 @@ var HindsightClient = class {
1027
1100
  async tree() {
1028
1101
  if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1029
1102
  const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
1030
- if ([404, 405, 501].includes(r.status)) {
1031
- this.knowledgePagesSupported = false;
1032
- throw new KnowledgePagesUnavailableError();
1033
- }
1103
+ if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
1104
+ if (r.status === 404) return [];
1034
1105
  this.knowledgePagesSupported = true;
1035
1106
  try {
1036
1107
  return (await r.json()).roots ?? [];
@@ -1084,16 +1155,18 @@ var HindsightClient = class {
1084
1155
  /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
1085
1156
  * Returns page-level hits with a relevance snippet — the real search behind
1086
1157
  * hindsight_search_knowledge_pages. */
1087
- async searchKnowledgePages(query, limit = 3, timeoutMs) {
1158
+ async searchKnowledgePages(query, opts = {}) {
1088
1159
  if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
1089
- const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
1160
+ const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
1090
1161
  const r = await this.req(
1091
1162
  "GET",
1092
1163
  this.bankUrl(`/knowledge-base/search${q}`),
1093
1164
  void 0,
1094
1165
  [],
1095
- timeoutMs
1166
+ opts.timeoutMs
1096
1167
  );
1168
+ if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
1169
+ if (r.status === 404) return [];
1097
1170
  const j = await r.json();
1098
1171
  return (j.results ?? []).map((x) => ({
1099
1172
  id: x.id,
@@ -1113,8 +1186,8 @@ var HindsightClient = class {
1113
1186
  * `source_query` re-syncs onto the live page instead of orphaning its synthesized content —
1114
1187
  * which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
1115
1188
  */
1116
- async seedPages(pageTrigger = buildPageTrigger()) {
1117
- const pages = pagesFor(this.project ?? this.bank);
1189
+ async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
1190
+ const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
1118
1191
  const existing = /* @__PURE__ */ new Map();
1119
1192
  let roots;
1120
1193
  try {
@@ -1131,6 +1204,7 @@ var HindsightClient = class {
1131
1204
  }
1132
1205
  let created = 0;
1133
1206
  let updated = 0;
1207
+ let vanished = 0;
1134
1208
  for (const page of pages) {
1135
1209
  const hit = existing.get(page.name.toLowerCase());
1136
1210
  const body = {
@@ -1144,13 +1218,16 @@ var HindsightClient = class {
1144
1218
  };
1145
1219
  if (!hit) {
1146
1220
  const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
1147
- if ([404, 405, 501].includes(r.status)) {
1148
- this.knowledgePagesSupported = false;
1221
+ if (await this.pagesUnsupported(r)) {
1149
1222
  this.log(
1150
1223
  `[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
1151
1224
  );
1152
1225
  return;
1153
1226
  }
1227
+ if (r.status === 404) {
1228
+ this.log(`[bank] ${this.bank} does not exist yet; pages seed on the next session`);
1229
+ return;
1230
+ }
1154
1231
  if (r.status !== 409) created++;
1155
1232
  } else {
1156
1233
  const sourceDrift = hit.description !== page.source_query;
@@ -1160,6 +1237,9 @@ var HindsightClient = class {
1160
1237
  if (sourceDrift) {
1161
1238
  patch.source_query = page.source_query;
1162
1239
  patch.tags = page.tags;
1240
+ this.log(
1241
+ `[bank] re-syncing "${page.name}" to its configured source_query \u2014 set pages[${JSON.stringify(page.name)}].source_query to keep your own wording`
1242
+ );
1163
1243
  }
1164
1244
  if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
1165
1245
  const r = await this.req(
@@ -1167,19 +1247,22 @@ var HindsightClient = class {
1167
1247
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
1168
1248
  patch
1169
1249
  );
1170
- if ([404, 405, 501].includes(r.status)) {
1171
- this.knowledgePagesSupported = false;
1250
+ if (await this.pagesUnsupported(r)) {
1172
1251
  this.log(
1173
1252
  `[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
1174
1253
  );
1175
1254
  return;
1176
1255
  }
1256
+ if (r.status === 404) {
1257
+ vanished++;
1258
+ continue;
1259
+ }
1177
1260
  updated++;
1178
1261
  }
1179
1262
  }
1180
1263
  const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
1181
1264
  this.log(
1182
- `[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged` + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
1265
+ `[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` : "")
1183
1266
  );
1184
1267
  }
1185
1268
  /**
@@ -1208,7 +1291,7 @@ var HindsightClient = class {
1208
1291
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
1209
1292
  { trigger: pageTriggerPatch(desired) }
1210
1293
  );
1211
- if ([404, 405, 501].includes(r.status)) break;
1294
+ if (r.status === 404) continue;
1212
1295
  updated++;
1213
1296
  }
1214
1297
  return updated;
@@ -1300,6 +1383,63 @@ function resolvePageTrigger(raw) {
1300
1383
  );
1301
1384
  return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
1302
1385
  }
1386
+ function resolvePages(raw) {
1387
+ const value = raw;
1388
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
1389
+ const out = {};
1390
+ for (const [name, entry] of Object.entries(value)) {
1391
+ if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
1392
+ log.warn(
1393
+ "config",
1394
+ `ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
1395
+ );
1396
+ continue;
1397
+ }
1398
+ if (entry === false) {
1399
+ out[name] = false;
1400
+ continue;
1401
+ }
1402
+ const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
1403
+ if (typeof query === "string" && query.trim()) {
1404
+ out[name] = { source_query: query };
1405
+ continue;
1406
+ }
1407
+ log.warn(
1408
+ "config",
1409
+ `ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
1410
+ );
1411
+ }
1412
+ return out;
1413
+ }
1414
+ function resolveCustomPages(raw) {
1415
+ const value = raw;
1416
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
1417
+ const out = {};
1418
+ for (const [rawName, entry] of Object.entries(value)) {
1419
+ const name = rawName.trim();
1420
+ if (!name) continue;
1421
+ if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
1422
+ log.warn(
1423
+ "config",
1424
+ `ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
1425
+ );
1426
+ continue;
1427
+ }
1428
+ const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
1429
+ if (typeof query !== "string" || !query.trim()) {
1430
+ log.warn(
1431
+ "config",
1432
+ `ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
1433
+ );
1434
+ continue;
1435
+ }
1436
+ const rawTags = entry.tags;
1437
+ const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
1438
+ out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
1439
+ }
1440
+ return out;
1441
+ }
1442
+ var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
1303
1443
  var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
1304
1444
  var REFLECT_BUDGETS = ["low", "mid", "high"];
1305
1445
  function resolveReflectBudget(raw) {
@@ -1327,6 +1467,15 @@ function resolveObservationScopes(raw) {
1327
1467
  }
1328
1468
  return DEFAULT_OBSERVATION_SCOPES;
1329
1469
  }
1470
+ var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
1471
+ function resolveAutoInject(raw) {
1472
+ if (raw.autoReflect !== void 0) {
1473
+ const replacement = raw.autoReflect === false ? "none" : "reflect";
1474
+ log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
1475
+ }
1476
+ if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
1477
+ return raw.autoReflect === false ? "none" : "reflect";
1478
+ }
1330
1479
  function resolveConfig(raw = {}) {
1331
1480
  const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
1332
1481
  const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
@@ -1356,17 +1505,28 @@ function resolveConfig(raw = {}) {
1356
1505
  retainSessions: raw.retainSessions ?? true,
1357
1506
  // write sessions back by default, every harness
1358
1507
  manageBankConfig: raw.manageBankConfig ?? true,
1508
+ retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
1359
1509
  maxParallelRetains: raw.maxParallelRetains || 10,
1360
- reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
1510
+ reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
1361
1511
  // Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
1362
1512
  // reflect already set), but never let it LOWER the tool below the default — a short window is
1363
1513
  // set to bound the automatic hook, not to cut off a call the agent is waiting on.
1364
1514
  reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
1365
1515
  reflectBudget: resolveReflectBudget(raw),
1366
- autoReflect: raw.autoReflect ?? true,
1367
- pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
1516
+ autoInject: resolveAutoInject(raw),
1517
+ pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
1518
+ // Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
1519
+ // keys and reach the API as garbage, so it is rejected like any other non-object.
1520
+ recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
1521
+ // Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
1522
+ // at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
1523
+ // 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
1524
+ // with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
1525
+ pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
1368
1526
  pageTriggerType: pageTrigger.type,
1369
1527
  pageTriggerCron: pageTrigger.cron,
1528
+ pages: resolvePages(raw.pages),
1529
+ customPages: resolveCustomPages(raw.customPages),
1370
1530
  autoSeed: raw.autoSeed ?? true,
1371
1531
  seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
1372
1532
  codebaseSurvey: raw.codebaseSurvey ?? true,
@@ -1430,6 +1590,8 @@ var ENV_KEYS = {
1430
1590
  reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
1431
1591
  reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
1432
1592
  reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
1593
+ autoInject: "HINDSIGHT_AUTO_INJECT",
1594
+ pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
1433
1595
  autoReflect: "HINDSIGHT_AUTO_REFLECT",
1434
1596
  pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
1435
1597
  pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
@@ -1449,7 +1611,8 @@ var ENV_KEYS = {
1449
1611
  // Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
1450
1612
  // a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
1451
1613
  retainTags: "HINDSIGHT_RETAIN_TAGS",
1452
- manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
1614
+ manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
1615
+ retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
1453
1616
  };
1454
1617
  var ENV_BOOLEANS = /* @__PURE__ */ new Set([
1455
1618
  "dynamicBankId",
@@ -1470,6 +1633,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
1470
1633
  "maxParallelRetains",
1471
1634
  "reflectTimeoutMs",
1472
1635
  "reflectToolTimeoutMs",
1636
+ "pageSearchLimit",
1473
1637
  "pageRefreshEveryTurns",
1474
1638
  "seedLimit",
1475
1639
  "surveyBudgetUsd",
@@ -1533,6 +1697,7 @@ function resolvePartial(cfg, patch) {
1533
1697
  if (key in full)
1534
1698
  out[key] = full[key];
1535
1699
  }
1700
+ if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
1536
1701
  return out;
1537
1702
  }
1538
1703
 
@@ -1562,10 +1727,19 @@ function parsePageList(raw) {
1562
1727
  }
1563
1728
  return out;
1564
1729
  }
1565
- function roster(pages) {
1566
- return pages.map((p) => `- ${p.title} (${p.id})`).join("\n");
1567
- }
1568
- var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP for any question the project's accumulated knowledge might answer (components, conventions, past decisions, initiatives): search the knowledge pages and credit results visibly with a markdown blockquote so it renders as a callout, exactly: "> \u{1F9E0} **From Hindsight memory (<page>)** \u2014 <the specific facts you drew on>".
1730
+ var EMPTY_STATE = "No knowledge pages yet \u2014 Hindsight is still learning this repo; they'll appear as it processes.";
1731
+ function indexLine(pages) {
1732
+ const count = pages.length === 1 ? "1 knowledge page covers" : `${pages.length} knowledge pages cover`;
1733
+ return `${count} this repository \u2014 architecture, conventions, past decisions and in-flight initiatives. They are deliberately NOT listed here: call hindsight_search_knowledge_pages(query) to find the ones that bear on the current turn, then hindsight_read_knowledge_page(<id>) on anything the results show is worth reading in full.`;
1734
+ }
1735
+ var TOOL_GUIDE = `- hindsight_search_knowledge_pages(query) \u2014 FIRST STOP, and the way IN to everything below. The code shows what is true today, never what was decided or why, so work built from code alone quietly re-litigates settled questions. Search BEFORE you act whenever the turn is one of these \u2014 they are the ones that go wrong silently:
1736
+ \u2022 the user reports a bug or a wrong response (the intended behaviour, and the status code or value it should return, is usually already decided);
1737
+ \u2022 you are about to write or change a test (what this project expects a change to ship with, and how it asserts, is a convention, not a preference);
1738
+ \u2022 you are implementing something new, or two parts have to fit together;
1739
+ \u2022 the user asks why something is the way it is, or what is left to do;
1740
+ \u2022 you are about to commit, and need to know what the change was supposed to honour.
1741
+ It ranks the pages by relevance and returns the matching passage, which a page title cannot tell you.
1742
+ CREDITING IS NOT OPTIONAL AND NOT A JUDGEMENT CALL. If you called this tool and anything it returned reached your reply \u2014 quoted, paraphrased, or merely confirming what you were about to say \u2014 open that part with a markdown blockquote, exactly: "> \u{1F9E0} **From Hindsight memory (<page>)** \u2014 <the specific facts you drew on>". Rewriting a snippet in your own words does not make it yours. A search that turned up nothing useful needs no mention at all \u2014 just carry on.
1569
1743
  - hindsight_list_knowledge_pages / hindsight_read_knowledge_page \u2014 BEFORE substantial work, list the pages and read the relevant ones to ground yourself in this repo's architecture, conventions, and past decisions instead of re-deriving them from the code; follow any [[page:<id>]] links you see.
1570
1744
  - hindsight_reflect(query) \u2014 when pages are too shallow and you need the WHY: deep reasoning over the repo's full memory for the past decision and exact values that explain a behavior or bug (slower \u2014 use deliberately, and credit results with a blockquote header "> \u{1F9E0} **From Hindsight memory** \u2014 <summary>").
1571
1745
  - hindsight_capture_initiative(title, summary) \u2014 right after the user approves a plan or finishes brainstorming a new feature/capability and you are about to start implementing (BEFORE you write any code), call this to record it as a tracked page; then call it AGAIN with relates_to_page_id set to that page whenever the goal, scope, or rationale materially changes mid-work, so the page tracks the current plan and not the opening one. Skip bug fixes, small tweaks, chores, and trivial course-corrections.
@@ -1575,8 +1749,7 @@ function toolGuide(opts) {
1575
1749
  return (opts?.reflectOnNewGoals ? PAGES_FIRST_ON_GOALS : "") + TOOL_GUIDE;
1576
1750
  }
1577
1751
  function buildKnowledgePreamble(pages, opts) {
1578
- const body = pages.length ? `Knowledge pages currently in this repository:
1579
- ${roster(pages)}` : "No knowledge pages yet \u2014 Hindsight is still learning this repo; they'll appear as it processes.";
1752
+ const body = pages.length ? indexLine(pages) : EMPTY_STATE;
1580
1753
  return `<hindsight_knowledge>
1581
1754
  This repository has a Hindsight memory + knowledge base (curated, continuously-updated pages plus the raw memory behind them). The tools below are registered, but you must actually CALL them at the right moments:
1582
1755
  ${toolGuide(opts)}
@@ -1862,31 +2035,10 @@ function buildRetainStamp(cfg, ctx) {
1862
2035
  }
1863
2036
 
1864
2037
  // src/core/jsonl.ts
1865
- import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
2038
+ import { closeSync, openSync, readSync } from "fs";
1866
2039
  import { StringDecoder } from "string_decoder";
1867
2040
  var CHUNK_BYTES = 64 * 1024;
1868
- var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
1869
- function readJsonlTail(path, opts) {
1870
- const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1871
- let size;
1872
- try {
1873
- size = statSync3(path).size;
1874
- } catch {
1875
- return { lines: emptyLines(), skippedBytes: 0 };
1876
- }
1877
- const skippedBytes = size > maxBytes ? size - maxBytes : 0;
1878
- if (skippedBytes > 0) {
1879
- log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
1880
- path,
1881
- sizeBytes: size,
1882
- skippedBytes
1883
- });
1884
- }
1885
- return { lines: streamLines(path, skippedBytes), skippedBytes };
1886
- }
1887
- function* emptyLines() {
1888
- }
1889
- function* streamLines(path, start) {
2041
+ function* readJsonl(path) {
1890
2042
  let fd;
1891
2043
  try {
1892
2044
  fd = openSync(path, "r");
@@ -1897,8 +2049,7 @@ function* streamLines(path, start) {
1897
2049
  const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
1898
2050
  const decoder = new StringDecoder("utf8");
1899
2051
  let pending = "";
1900
- let position = start > 0 ? start - 1 : 0;
1901
- let dropPartial = start > 0;
2052
+ let position = 0;
1902
2053
  for (; ; ) {
1903
2054
  const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
1904
2055
  if (bytesRead <= 0) break;
@@ -1906,17 +2057,12 @@ function* streamLines(path, start) {
1906
2057
  pending += decoder.write(buffer.subarray(0, bytesRead));
1907
2058
  let newline;
1908
2059
  while ((newline = pending.indexOf("\n")) !== -1) {
1909
- const line = pending.slice(0, newline);
2060
+ yield pending.slice(0, newline);
1910
2061
  pending = pending.slice(newline + 1);
1911
- if (dropPartial) {
1912
- dropPartial = false;
1913
- continue;
1914
- }
1915
- yield line;
1916
2062
  }
1917
2063
  }
1918
2064
  pending += decoder.end();
1919
- if (pending && !dropPartial) yield pending;
2065
+ if (pending) yield pending;
1920
2066
  } finally {
1921
2067
  closeSync(fd);
1922
2068
  }
@@ -1936,7 +2082,10 @@ function git(repo, ...args) {
1936
2082
  return execFileSync2("git", ["-C", repo, ...args], {
1937
2083
  encoding: "utf8",
1938
2084
  maxBuffer: 1 << 28,
1939
- windowsHide: true
2085
+ windowsHide: true,
2086
+ // execFileSync otherwise forwards failed git stderr into the host's TUI,
2087
+ // even when callers catch the error. Keep diagnostics on the error instead.
2088
+ stdio: ["ignore", "pipe", "pipe"]
1940
2089
  });
1941
2090
  }
1942
2091
  function repoNameOf(repo) {
@@ -1995,7 +2144,7 @@ import {
1995
2144
  renameSync as renameSync3,
1996
2145
  rmdirSync,
1997
2146
  rmSync as rmSync2,
1998
- statSync as statSync4,
2147
+ statSync as statSync3,
1999
2148
  unlinkSync,
2000
2149
  utimesSync,
2001
2150
  writeFileSync as writeFileSync2
@@ -2032,7 +2181,7 @@ function reclaimIfStale(directory, staleMs) {
2032
2181
  return true;
2033
2182
  }
2034
2183
  if (owners.length !== 1) return false;
2035
- const age = Date.now() - statSync4(join12(directory, owners[0])).mtimeMs;
2184
+ const age = Date.now() - statSync3(join12(directory, owners[0])).mtimeMs;
2036
2185
  if (Math.abs(age) <= staleMs) return false;
2037
2186
  releaseLease({ directory, owner: owners[0] });
2038
2187
  return true;
@@ -2269,8 +2418,10 @@ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2269
2418
  import { dirname as dirname9, join as join14 } from "path";
2270
2419
  import { fileURLToPath as fileURLToPath4 } from "url";
2271
2420
  var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
2421
+ var RELEASE_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/;
2272
2422
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2273
- var FETCH_TIMEOUT_MS = 5e3;
2423
+ var NPM_VIEW_TIMEOUT_MS = 5e3;
2424
+ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
2274
2425
  function stateFile(runtimeDir) {
2275
2426
  return join14(runtimeDir, ".update-check.json");
2276
2427
  }
@@ -2377,17 +2528,53 @@ function stampCheck(file, now, latest) {
2377
2528
  } catch {
2378
2529
  }
2379
2530
  }
2380
- async function latestVersion(fetchImpl) {
2381
- try {
2382
- const r = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
2383
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
2384
- });
2385
- if (!r.ok) return "";
2386
- const body = await r.json();
2387
- return typeof body.version === "string" ? body.version : "";
2388
- } catch {
2389
- return "";
2390
- }
2531
+ async function npmViewVersion(pkg, spawnImpl = realSpawn5) {
2532
+ return new Promise((resolve3) => {
2533
+ let out = "";
2534
+ let settled = false;
2535
+ let deadline;
2536
+ const done = (v, reason) => {
2537
+ if (settled) return;
2538
+ settled = true;
2539
+ if (deadline) clearTimeout(deadline);
2540
+ if (reason) log.info("auto-update", `version check failed: ${reason}`);
2541
+ resolve3(v);
2542
+ };
2543
+ try {
2544
+ const child = spawnImpl("npm", ["view", pkg, "version", "--json"], {
2545
+ timeout: NPM_VIEW_TIMEOUT_MS,
2546
+ stdio: ["ignore", "pipe", "ignore"],
2547
+ windowsHide: true
2548
+ });
2549
+ child.stdout?.setEncoding("utf8");
2550
+ child.stdout?.on("data", (d) => {
2551
+ out += d;
2552
+ });
2553
+ child.stdout?.on("error", (e) => done("", describeError(e)));
2554
+ child.on("error", (e) => done("", describeError(e)));
2555
+ child.on("close", (code, signal) => {
2556
+ if (code !== 0) return done("", `npm view exited ${code ?? signal}`);
2557
+ try {
2558
+ const v = JSON.parse(out.trim());
2559
+ if (typeof v !== "string")
2560
+ return done("", `unparsable npm output: ${out.trim().slice(0, 80)}`);
2561
+ if (!RELEASE_RE.test(v)) return done("", `not a release: ${v.slice(0, 40)}`);
2562
+ done(v);
2563
+ } catch {
2564
+ done("", `unparsable npm output: ${out.trim().slice(0, 80)}`);
2565
+ }
2566
+ });
2567
+ deadline = setTimeout(() => {
2568
+ try {
2569
+ child.kill("SIGKILL");
2570
+ } catch {
2571
+ }
2572
+ done("", "npm view never exited \u2014 hard deadline");
2573
+ }, NPM_VIEW_HARD_DEADLINE_MS);
2574
+ } catch (e) {
2575
+ done("", describeError(e));
2576
+ }
2577
+ });
2391
2578
  }
2392
2579
  async function maybeAutoUpdate(cfg, opts = {}) {
2393
2580
  try {
@@ -2407,15 +2594,16 @@ async function maybeAutoUpdate(cfg, opts = {}) {
2407
2594
  stampCheck(file, now, "");
2408
2595
  return "";
2409
2596
  }
2410
- if (!(opts.binOnPath ?? binOnPath)("npx")) {
2411
- log.info("auto-update", "npx is not on PATH \u2014 skipping the update check");
2597
+ const binOk = opts.binOnPath ?? binOnPath;
2598
+ if (!binOk("npx") || !binOk("npm")) {
2599
+ log.info("auto-update", "npx/npm is not on PATH \u2014 skipping the update check");
2412
2600
  stampCheck(file, now, "");
2413
2601
  return "";
2414
2602
  }
2415
2603
  const lock = opts.lockFile ?? lockFile();
2416
2604
  if (!acquireUpdateLock(lock, now)) return "";
2417
2605
  try {
2418
- const latest = await latestVersion(opts.fetch ?? fetch);
2606
+ const latest = await (opts.npmView ?? npmViewVersion)(PACKAGE_NAME);
2419
2607
  stampCheck(file, now, latest);
2420
2608
  if (!latest || !isNewer(latest, current2)) {
2421
2609
  releaseUpdateLock(lock);
@@ -2482,7 +2670,9 @@ var SKILL_DIRS = {
2482
2670
 
2483
2671
  // src/core/skill-sync.ts
2484
2672
  function packagedSkillDir() {
2485
- return join15(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
2673
+ const here = dirname10(fileURLToPath5(import.meta.url));
2674
+ const dist = join15(here, "..", "skill");
2675
+ return existsSync5(join15(dist, "SKILL.md")) ? dist : join15(here, "..", "..", "skill");
2486
2676
  }
2487
2677
  function syncCompanionSkill(harness, opts = {}) {
2488
2678
  try {
@@ -2493,8 +2683,9 @@ function syncCompanionSkill(harness, opts = {}) {
2493
2683
  if (!existsSync5(srcMd)) return;
2494
2684
  const dst = join15(opts.home ?? homedir6(), ...parts, "hindsight-coding-agent");
2495
2685
  const dstMd = join15(dst, "SKILL.md");
2496
- if (!existsSync5(dstMd)) return;
2497
- if (readFileSync9(srcMd, "utf8") !== readFileSync9(dstMd, "utf8")) {
2686
+ const installed = existsSync5(dstMd);
2687
+ if (!installed && !opts.install) return;
2688
+ if (!installed || readFileSync9(srcMd, "utf8") !== readFileSync9(dstMd, "utf8")) {
2498
2689
  cpSync(src, dst, { recursive: true });
2499
2690
  }
2500
2691
  } catch {
@@ -2560,7 +2751,9 @@ async function gitSyncNote(args) {
2560
2751
  const n = Number(
2561
2752
  execFileSync4("git", ["-C", cwd, "rev-list", "--count", "HEAD"], {
2562
2753
  encoding: "utf8",
2563
- windowsHide: true
2754
+ windowsHide: true,
2755
+ stdio: ["ignore", "pipe", "pipe"]
2756
+ // do not corrupt the host banner on a late git failure
2564
2757
  }).trim()
2565
2758
  );
2566
2759
  if (n > 0) target = Math.min(DEEPEN_DIFF_TARGET, n);
@@ -2673,7 +2866,9 @@ async function buildSessionStartContext(args) {
2673
2866
  diag(harness, "knowledge_pages_unavailable", { bank: bankId });
2674
2867
  }
2675
2868
  }
2676
- const additionalContext = buildKnowledgePreamble(pages, { reflectOnNewGoals: !cfg.autoReflect });
2869
+ const additionalContext = buildKnowledgePreamble(pages, {
2870
+ reflectOnNewGoals: cfg.autoInject !== "reflect"
2871
+ });
2677
2872
  const deferInitialReflect = cold === true || pageListKnown && pages.length === 0;
2678
2873
  let gitNote;
2679
2874
  if (gitDocIds) {
@@ -2741,43 +2936,60 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
2741
2936
  }
2742
2937
 
2743
2938
  // src/core/transcript-codex.ts
2939
+ function stampOf(line) {
2940
+ return typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
2941
+ }
2744
2942
  function isSyntheticUserText(text) {
2745
2943
  const s = text.trimStart();
2746
2944
  return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
2747
2945
  }
2748
- function messageText(payload) {
2749
- return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
2946
+ function contentText(content) {
2947
+ return (content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
2948
+ }
2949
+ function isUserMessageEvent(line) {
2950
+ return line.type === "event_msg" && line.payload?.type === "item_completed" && line.payload.item?.type === "UserMessage";
2750
2951
  }
2751
2952
  function readCodexTranscript(path) {
2752
- const turns = [];
2753
- for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
2953
+ const lines = [];
2954
+ for (const rawLine of readJsonl(path)) {
2754
2955
  const trimmed = rawLine.trim();
2755
2956
  if (!trimmed) continue;
2756
- let parsed;
2757
2957
  try {
2758
- parsed = JSON.parse(trimmed);
2958
+ const parsed = JSON.parse(trimmed);
2959
+ if (typeof parsed === "object" && parsed !== null) lines.push(parsed);
2759
2960
  } catch {
2760
2961
  continue;
2761
2962
  }
2762
- if (typeof parsed !== "object" || parsed === null) continue;
2763
- const line = parsed;
2963
+ }
2964
+ const userFromEvents = lines.some(isUserMessageEvent);
2965
+ const turns = [];
2966
+ const push = (role, raw, stamp = {}) => {
2967
+ const text = stripInjectedMemory(raw).trim();
2968
+ if (text) turns.push({ role, content: text, ...stamp });
2969
+ };
2970
+ for (const line of lines) {
2971
+ if (isUserMessageEvent(line)) {
2972
+ push("user", contentText(line.payload?.item?.content), stampOf(line));
2973
+ continue;
2974
+ }
2764
2975
  if (line.type !== "response_item") continue;
2765
2976
  const p = line.payload;
2766
2977
  if (!p || typeof p !== "object") continue;
2767
2978
  if (p.type === "message") {
2768
- if (p.role !== "user" && p.role !== "assistant") continue;
2769
- const text = stripInjectedMemory(messageText(p)).trim();
2770
- if (!text) continue;
2771
- if (p.role === "user" && isSyntheticUserText(text)) continue;
2772
- turns.push({ role: p.role, content: text });
2773
- } else if (p.type === "function_call" && typeof p.name === "string") {
2979
+ if (p.role === "assistant") push("assistant", contentText(p.content), stampOf(line));
2980
+ else if (p.role === "user" && !userFromEvents) {
2981
+ const text = contentText(p.content);
2982
+ if (!isSyntheticUserText(stripInjectedMemory(text))) push("user", text, stampOf(line));
2983
+ }
2984
+ } else if ((p.type === "function_call" || p.type === "custom_tool_call") && typeof p.name === "string") {
2985
+ const rawInput = p.type === "function_call" ? p.arguments : p.input;
2774
2986
  let input;
2775
2987
  try {
2776
- input = JSON.parse(p.arguments || "");
2988
+ input = JSON.parse(rawInput || "");
2777
2989
  } catch {
2778
2990
  input = void 0;
2779
2991
  }
2780
- turns.push({ role: "action", content: actionLine(p.name, input) });
2992
+ turns.push({ role: "action", content: actionLine(p.name, input), ...stampOf(line) });
2781
2993
  }
2782
2994
  }
2783
2995
  return turns;
@@ -2794,7 +3006,7 @@ function textFrom(content) {
2794
3006
  }
2795
3007
  function readCursorTranscript(path) {
2796
3008
  const turns = [];
2797
- for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
3009
+ for (const rawLine of readJsonl(path)) {
2798
3010
  let parsed;
2799
3011
  try {
2800
3012
  parsed = JSON.parse(rawLine);
@@ -2833,7 +3045,7 @@ function readCursorTranscript(path) {
2833
3045
  function readAntigravityTranscript(path) {
2834
3046
  if (!path) return [];
2835
3047
  const turns = [];
2836
- for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
3048
+ for (const line of readJsonl(path)) {
2837
3049
  try {
2838
3050
  const event = JSON.parse(line);
2839
3051
  const role = event.role ?? event.message?.role ?? event.type;
@@ -2856,7 +3068,7 @@ function readAntigravityTranscript(path) {
2856
3068
  // src/core/transcript-copilot.ts
2857
3069
  function readCopilotTranscript(path) {
2858
3070
  const turns = [];
2859
- for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
3071
+ for (const rawLine of readJsonl(path)) {
2860
3072
  try {
2861
3073
  const event = JSON.parse(rawLine);
2862
3074
  const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
@@ -2891,7 +3103,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
2891
3103
  }
2892
3104
  function readGrokTranscript(path) {
2893
3105
  const turns = [];
2894
- for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
3106
+ for (const rawLine of readJsonl(path)) {
2895
3107
  try {
2896
3108
  const event = JSON.parse(rawLine);
2897
3109
  if (event.type !== "user" && event.type !== "assistant") continue;
@@ -2983,7 +3195,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
2983
3195
 
2984
3196
  // src/core/transcript-dcode.ts
2985
3197
  var BLOCK_JOIN = "\n";
2986
- function contentText(content) {
3198
+ function contentText2(content) {
2987
3199
  if (typeof content === "string") return content;
2988
3200
  if (!Array.isArray(content)) return "";
2989
3201
  return content.flatMap((block) => {
@@ -3076,11 +3288,11 @@ function dcodeAssistantText(raw) {
3076
3288
  const parsed = readPyValue(trimmed, 0);
3077
3289
  if (!parsed || readPyValue(trimmed, parsed.end) !== null) return "";
3078
3290
  if (!Array.isArray(parsed.value)) return "";
3079
- return contentText(parsed.value);
3291
+ return contentText2(parsed.value);
3080
3292
  }
3081
3293
  function readDcodeTranscript(path) {
3082
3294
  const turns = [];
3083
- for (const rawLine of readJsonlTail(path, { scope: "dcode" }).lines) {
3295
+ for (const rawLine of readJsonl(path)) {
3084
3296
  if (!rawLine.trim()) continue;
3085
3297
  let parsed;
3086
3298
  try {
@@ -3094,7 +3306,7 @@ function readDcodeTranscript(path) {
3094
3306
  const role = record.role;
3095
3307
  const stamp = typeof record.timestamp === "string" && record.timestamp ? { timestamp: record.timestamp } : {};
3096
3308
  if (role === "user" || role === "assistant") {
3097
- const text = stripInjectedMemory(contentText(record.content)).trim();
3309
+ const text = stripInjectedMemory(contentText2(record.content)).trim();
3098
3310
  if (text) turns.push({ role, content: text, ...stamp });
3099
3311
  } else if (role === "tool" && typeof record.name === "string" && record.name.trim()) {
3100
3312
  turns.push({ role: "action", content: actionLine(record.name, record.content), ...stamp });
@@ -3155,7 +3367,7 @@ function readQwenTranscript(path) {
3155
3367
  return turns;
3156
3368
  }
3157
3369
  function collectQwenTurns(path, turns) {
3158
- for (const rawLine of readJsonlTail(path, { scope: "qwen-code" }).lines) {
3370
+ for (const rawLine of readJsonl(path)) {
3159
3371
  const trimmed = rawLine.trim();
3160
3372
  if (!trimmed) continue;
3161
3373
  let parsed;
@@ -3210,7 +3422,7 @@ function renderContent(content, role) {
3210
3422
  }
3211
3423
  function readDroidTranscript(path) {
3212
3424
  const turns = [];
3213
- for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
3425
+ for (const rawLine of readJsonl(path)) {
3214
3426
  if (!rawLine.trim()) continue;
3215
3427
  let parsed;
3216
3428
  try {
@@ -3233,7 +3445,7 @@ function readDroidTranscript(path) {
3233
3445
 
3234
3446
  // src/core/transcript-zcode.ts
3235
3447
  import { readFileSync as readFileSync13 } from "fs";
3236
- function messageText2(content) {
3448
+ function messageText(content) {
3237
3449
  if (typeof content === "string") return content.trim();
3238
3450
  if (!Array.isArray(content)) return "";
3239
3451
  return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
@@ -3261,7 +3473,7 @@ function readZcodeTranscript(path) {
3261
3473
  const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
3262
3474
  const role = typeof message?.role === "string" ? message.role : record.type;
3263
3475
  if (role !== "user" && role !== "assistant") continue;
3264
- const content = stripInjectedMemory(messageText2(message?.content)).trim();
3476
+ const content = stripInjectedMemory(messageText(message?.content)).trim();
3265
3477
  if (!content) continue;
3266
3478
  turns.push({
3267
3479
  role,
@@ -3614,7 +3826,7 @@ var HOOK_HARNESSES = {
3614
3826
  // `detached` and terminates the whole process TREE on timeout, so the retain is genuinely lost
3615
3827
  // rather than merely orphaned. `retain.hostTimeoutSec` below stays SECONDS, as its name says;
3616
3828
  // these two numbers are the same budget in different units for this harness alone.
3617
- // The prompt timeout must also stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3829
+ // The prompt timeout must also stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
3618
3830
  install: {
3619
3831
  sessionStart: { event: "SessionStart", entry: "qwen-sessionstart-hook.js", timeout: 3e4 },
3620
3832
  prompt: { event: "UserPromptSubmit", entry: "qwen-hook.js", timeout: 3e4 },
@@ -3676,7 +3888,7 @@ var HOOK_HARNESSES = {
3676
3888
  zcode: {
3677
3889
  configStyle: "process",
3678
3890
  // ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
3679
- // prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3891
+ // prompt budget must stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
3680
3892
  timeoutUnit: "milliseconds",
3681
3893
  install: {
3682
3894
  sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },