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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +314 -51
  2. package/dist/antigravity-hook.js +1039 -198
  3. package/dist/antigravity-statusline.js +185 -11
  4. package/dist/antigravity-stop-hook.js +1026 -163
  5. package/dist/claude-hook.js +1039 -198
  6. package/dist/claude-sessionstart-hook.js +1123 -190
  7. package/dist/claude-stop-hook.js +1026 -163
  8. package/dist/cline.js +749 -209
  9. package/dist/codex-hook.js +1039 -198
  10. package/dist/codex-sessionstart-hook.js +1123 -190
  11. package/dist/codex-stop-hook.js +1026 -163
  12. package/dist/copilot-hook.js +1039 -198
  13. package/dist/copilot-sessionstart-hook.js +1123 -190
  14. package/dist/copilot-stop-hook.js +1026 -163
  15. package/dist/cursor-hook.js +1039 -198
  16. package/dist/cursor-sessionstart-hook.js +1123 -190
  17. package/dist/cursor-stop-hook.js +1026 -163
  18. package/dist/daemon-start.js +154 -5
  19. package/dist/dcode-hook.js +1039 -198
  20. package/dist/dcode-sessionstart-hook.js +1123 -190
  21. package/dist/dcode-stop-hook.js +1026 -163
  22. package/dist/deepen.js +437 -105
  23. package/dist/devin-hook.js +1039 -198
  24. package/dist/devin-sessionstart-hook.js +1123 -190
  25. package/dist/devin-stop-hook.js +1026 -163
  26. package/dist/droid-hook.js +1039 -198
  27. package/dist/droid-sessionstart-hook.js +1123 -190
  28. package/dist/droid-stop-hook.js +1026 -163
  29. package/dist/dsh.js +750 -210
  30. package/dist/grok-hook.js +1039 -198
  31. package/dist/grok-sessionstart-hook.js +1123 -190
  32. package/dist/grok-stop-hook.js +1026 -163
  33. package/dist/hindsight-seed.js +157 -8
  34. package/dist/index.js +749 -209
  35. package/dist/installer.js +1233 -366
  36. package/dist/kilo.js +749 -209
  37. package/dist/kimi-hook.js +3909 -0
  38. package/dist/kimi-sessionstart-hook.js +4650 -0
  39. package/dist/kimi-stop-hook.js +4218 -0
  40. package/dist/mcp-server.js +373 -71
  41. package/dist/opencode2.js +778 -209
  42. package/dist/pi.js +754 -211
  43. package/dist/prime-agent.js +754 -211
  44. package/dist/qwen-hook.js +1039 -198
  45. package/dist/qwen-sessionstart-hook.js +1123 -190
  46. package/dist/qwen-stop-hook.js +1026 -163
  47. package/dist/status.js +333 -59
  48. package/dist/traecode-hook.js +3909 -0
  49. package/dist/traecode-sessionstart-hook.js +4650 -0
  50. package/dist/traecode-stop-hook.js +4218 -0
  51. package/dist/zcode-hook.js +1039 -198
  52. package/dist/zcode-sessionstart-hook.js +1123 -190
  53. package/dist/zcode-stop-hook.js +1026 -163
  54. package/package.json +15 -11
  55. package/plugin.json +1 -1
  56. package/skill/SKILL.md +241 -48
@@ -258,13 +258,13 @@ function isWithin(directory, configured) {
258
258
  function mapLookup(map, directory) {
259
259
  const cwd = normalize(directory);
260
260
  let best;
261
- for (const [dir, bank] of Object.entries(map)) {
261
+ for (const [dir, value] of Object.entries(map)) {
262
262
  const p = configuredDir(dir);
263
263
  if (isWithin(cwd, p)) {
264
- if (!best || p.length > best.len) best = { len: p.length, bank };
264
+ if (!best || p.length > best.len) best = { len: p.length, value };
265
265
  }
266
266
  }
267
- return best?.bank;
267
+ return best?.value;
268
268
  }
269
269
  function lookupDirectories(config, directory, sessionRoot = "") {
270
270
  const directories = [normalize(directory)];
@@ -288,6 +288,10 @@ function isOptedIn(config, directory) {
288
288
  const pathMap = config.mapPathToBank;
289
289
  return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
290
290
  }
291
+ function pathSection(config, paths, directory) {
292
+ if (!directory || !paths) return void 0;
293
+ return lookupDirectories(config, directory).map((candidate) => mapLookup(paths, candidate)).find((section) => section !== void 0);
294
+ }
291
295
  function mappedBank(config, directory, sessionRoot) {
292
296
  const pathMap = config.mapPathToBank;
293
297
  if (!directory || !pathMap) return void 0;
@@ -323,6 +327,36 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
323
327
 
324
328
  // src/core/missions.ts
325
329
  import { createHash } from "crypto";
330
+ var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
331
+ var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
332
+ var PAGE_TAXONOMY = [
333
+ {
334
+ name: "Component map",
335
+ source_query: "From this project's commit history and past discussions, what are the main components/modules/subsystems, what is each responsible for, and how do they relate to or depend on one another? Describe the structure and responsibilities.",
336
+ tags: ["knowledge:component"]
337
+ },
338
+ {
339
+ name: "Core concepts",
340
+ source_query: "What are the core concepts, domain abstractions, and key entities in this project \u2014 the vocabulary a developer must understand? For each, explain what it represents and its role, drawn from how they are introduced and discussed across the history and conversations.",
341
+ tags: ["knowledge:concept"]
342
+ },
343
+ {
344
+ name: "Conventions and patterns",
345
+ source_query: "What conventions, idioms, and recurring patterns does this project follow \u2014 its approach to testing, error handling, naming, structure, and how changes are typically made? Describe how THIS project does things, as evidenced across its history and discussions.",
346
+ tags: ["knowledge:convention"]
347
+ },
348
+ {
349
+ name: "Key decisions and rationale",
350
+ source_query: "What are the significant technical decisions made in this project and the rationale behind them \u2014 the durable 'why we do it this way' a developer should know? Summarize the decisions and their reasoning from the commit rationales and past conversations.",
351
+ tags: ["knowledge:decision"]
352
+ },
353
+ {
354
+ name: "Initiatives and enhancements",
355
+ source_query: "Based on this repository's commit history, what are the major initiatives, features, and enhancements the project has worked on? Summarize the themes and notable changes over time. When a source memory's context carries a `[[page:<id>]]` link, repeat that link in the summary of what it describes, so each initiative links to its detailed page.",
356
+ tags: ["knowledge:feature-work"]
357
+ }
358
+ ];
359
+ var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
326
360
  var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
327
361
  var CRON_FIELD_RANGES = [
328
362
  [0, 59],
@@ -354,6 +388,11 @@ function parseHashedCron(cron) {
354
388
  }
355
389
  return fields;
356
390
  }
391
+ var PLUGIN_GOVERNED_BANK_FIELDS = [
392
+ "retain_strategies",
393
+ "entity_labels",
394
+ "retain_extraction_mode"
395
+ ];
357
396
 
358
397
  // src/core/util.ts
359
398
  import { accessSync, constants } from "fs";
@@ -361,6 +400,7 @@ import { delimiter, join as join6 } from "path";
361
400
 
362
401
  // src/core/hindsight.ts
363
402
  var DEFAULT_OBSERVATION_SCOPES = "shared";
403
+ var DEFAULT_PAGE_SEARCH_LIMIT = 10;
364
404
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
365
405
  var RETRY_AFTER_CEILING_MS = 60 * 1e3;
366
406
 
@@ -385,7 +425,65 @@ function resolvePageTrigger(raw) {
385
425
  );
386
426
  return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
387
427
  }
428
+ function resolvePages(raw) {
429
+ const value = raw;
430
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
431
+ const out = {};
432
+ for (const [name, entry] of Object.entries(value)) {
433
+ if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
434
+ log.warn(
435
+ "config",
436
+ `ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
437
+ );
438
+ continue;
439
+ }
440
+ if (entry === false) {
441
+ out[name] = false;
442
+ continue;
443
+ }
444
+ const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
445
+ if (typeof query === "string" && query.trim()) {
446
+ out[name] = { source_query: query };
447
+ continue;
448
+ }
449
+ log.warn(
450
+ "config",
451
+ `ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
452
+ );
453
+ }
454
+ return out;
455
+ }
456
+ function resolveCustomPages(raw) {
457
+ const value = raw;
458
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
459
+ const out = {};
460
+ for (const [rawName, entry] of Object.entries(value)) {
461
+ const name = rawName.trim();
462
+ if (!name) continue;
463
+ if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
464
+ log.warn(
465
+ "config",
466
+ `ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
467
+ );
468
+ continue;
469
+ }
470
+ const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
471
+ if (typeof query !== "string" || !query.trim()) {
472
+ log.warn(
473
+ "config",
474
+ `ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
475
+ );
476
+ continue;
477
+ }
478
+ const rawTags = entry.tags;
479
+ const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
480
+ out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
481
+ }
482
+ return out;
483
+ }
484
+ var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
388
485
  var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
486
+ var DEFAULT_INJECT_TIMEOUT_MS = 7e3;
389
487
  var REFLECT_BUDGETS = ["low", "mid", "high"];
390
488
  function resolveReflectBudget(raw) {
391
489
  const value = raw.reflectBudget;
@@ -412,6 +510,31 @@ function resolveObservationScopes(raw) {
412
510
  }
413
511
  return DEFAULT_OBSERVATION_SCOPES;
414
512
  }
513
+ function resolveDefaultBankConfig(raw) {
514
+ const value = raw;
515
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
516
+ const out = {};
517
+ for (const [key, v] of Object.entries(value)) {
518
+ if (PLUGIN_GOVERNED_BANK_FIELDS.includes(key)) {
519
+ log.warn(
520
+ "config",
521
+ `ignoring defaultBankConfig.${key} \u2014 the plugin manages this field itself` + (key === "retain_extraction_mode" ? " (set retainExtractionMode instead)" : "")
522
+ );
523
+ continue;
524
+ }
525
+ out[key] = v;
526
+ }
527
+ return out;
528
+ }
529
+ var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
530
+ function resolveAutoInject(raw) {
531
+ if (raw.autoReflect !== void 0) {
532
+ const replacement = raw.autoReflect === false ? "none" : "reflect";
533
+ log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
534
+ }
535
+ if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
536
+ return raw.autoReflect === false ? "none" : "reflect";
537
+ }
415
538
  function resolveConfig(raw = {}) {
416
539
  const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
417
540
  const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
@@ -441,17 +564,31 @@ function resolveConfig(raw = {}) {
441
564
  retainSessions: raw.retainSessions ?? true,
442
565
  // write sessions back by default, every harness
443
566
  manageBankConfig: raw.manageBankConfig ?? true,
567
+ retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
568
+ defaultBankConfig: resolveDefaultBankConfig(raw.defaultBankConfig),
444
569
  maxParallelRetains: raw.maxParallelRetains || 10,
445
- reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
570
+ reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
446
571
  // Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
447
572
  // reflect already set), but never let it LOWER the tool below the default — a short window is
448
573
  // set to bound the automatic hook, not to cut off a call the agent is waiting on.
449
574
  reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
575
+ injectTimeoutMs: raw.injectTimeoutMs || DEFAULT_INJECT_TIMEOUT_MS,
450
576
  reflectBudget: resolveReflectBudget(raw),
451
- autoReflect: raw.autoReflect ?? true,
452
- pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
577
+ autoInject: resolveAutoInject(raw),
578
+ pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
579
+ // Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
580
+ // keys and reach the API as garbage, so it is rejected like any other non-object.
581
+ recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
582
+ toolGuideExtra: typeof raw.toolGuideExtra === "string" && raw.toolGuideExtra.trim() ? raw.toolGuideExtra : void 0,
583
+ // Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
584
+ // at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
585
+ // 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
586
+ // with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
587
+ pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
453
588
  pageTriggerType: pageTrigger.type,
454
589
  pageTriggerCron: pageTrigger.cron,
590
+ pages: resolvePages(raw.pages),
591
+ customPages: resolveCustomPages(raw.customPages),
455
592
  autoSeed: raw.autoSeed ?? true,
456
593
  seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
457
594
  codebaseSurvey: raw.codebaseSurvey ?? true,
@@ -462,11 +599,15 @@ function resolveConfig(raw = {}) {
462
599
  // Hostile input is a config typo, not an attack: keep only string entries so a stray number or
463
600
  // nested object cannot reach the API as a tag and fail the whole retain.
464
601
  retainTags: Array.isArray(raw.retainTags) ? raw.retainTags.filter((t) => typeof t === "string" && t.trim() !== "") : [],
602
+ // Undefined, not "", when unset or blank: the retain call distinguishes "not configured" (use
603
+ // the built-in default) from a configured value, and an empty context would strip the default.
604
+ retainContext: typeof raw.retainContext === "string" && raw.retainContext.trim() !== "" ? raw.retainContext : void 0,
465
605
  retainMetadata: raw.retainMetadata && typeof raw.retainMetadata === "object" ? Object.fromEntries(
466
606
  Object.entries(raw.retainMetadata).filter(([, v]) => typeof v === "string")
467
607
  ) : {},
468
608
  observationScopes: resolveObservationScopes(raw.observationScopes),
469
609
  banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
610
+ paths: raw.paths && typeof raw.paths === "object" ? raw.paths : {},
470
611
  logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
471
612
  autoUpdate: raw.autoUpdate ?? true
472
613
  };
@@ -483,7 +624,12 @@ function readRaw(path) {
483
624
  }
484
625
  function mergeRaw(a, b) {
485
626
  const { harnesses: _drop, ...flat } = b;
486
- return { ...a, ...flat, banks: { ...a.banks ?? {}, ...b.banks ?? {} } };
627
+ return {
628
+ ...a,
629
+ ...flat,
630
+ banks: { ...a.banks ?? {}, ...b.banks ?? {} },
631
+ paths: { ...a.paths ?? {}, ...b.paths ?? {} }
632
+ };
487
633
  }
488
634
  function applyLayer(raw, layer, harness) {
489
635
  let out = mergeRaw(raw, layer);
@@ -514,7 +660,11 @@ var ENV_KEYS = {
514
660
  maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
515
661
  reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
516
662
  reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
663
+ injectTimeoutMs: "HINDSIGHT_INJECT_TIMEOUT_MS",
517
664
  reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
665
+ autoInject: "HINDSIGHT_AUTO_INJECT",
666
+ pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
667
+ toolGuideExtra: "HINDSIGHT_TOOL_GUIDE_EXTRA",
518
668
  autoReflect: "HINDSIGHT_AUTO_REFLECT",
519
669
  pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
520
670
  pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
@@ -534,7 +684,8 @@ var ENV_KEYS = {
534
684
  // Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
535
685
  // a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
536
686
  retainTags: "HINDSIGHT_RETAIN_TAGS",
537
- manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
687
+ manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
688
+ retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
538
689
  };
539
690
  var ENV_BOOLEANS = /* @__PURE__ */ new Set([
540
691
  "dynamicBankId",
@@ -555,6 +706,8 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
555
706
  "maxParallelRetains",
556
707
  "reflectTimeoutMs",
557
708
  "reflectToolTimeoutMs",
709
+ "injectTimeoutMs",
710
+ "pageSearchLimit",
558
711
  "pageRefreshEveryTurns",
559
712
  "seedLimit",
560
713
  "surveyBudgetUsd",
@@ -602,15 +755,25 @@ var BANK_OVERRIDE_EXCLUDED = [
602
755
  function applyBankConfig(cfg, resolvedId, directory) {
603
756
  if (directory !== void 0 && !isOptedIn(cfg, directory))
604
757
  return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
758
+ const byPath = directory === void 0 ? void 0 : pathSection(cfg, cfg.paths, directory);
759
+ if (byPath) {
760
+ const { bank: _rename, ...rest } = overrideFields(byPath);
761
+ cfg = { ...cfg, ...resolvePartial(cfg, rest) };
762
+ }
605
763
  const section = cfg.banks[resolvedId];
606
764
  if (!section) return { cfg, bankId: resolvedId };
607
- const safe = { ...section };
608
- for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
609
- delete safe.banks;
765
+ const safe = overrideFields(section);
610
766
  const bankId = typeof safe.bank === "string" && safe.bank ? safe.bank : resolvedId;
611
767
  delete safe.bank;
612
768
  return { cfg: { ...cfg, ...resolvePartial(cfg, safe) }, bankId };
613
769
  }
770
+ function overrideFields(section) {
771
+ const safe = { ...section };
772
+ for (const k of BANK_OVERRIDE_EXCLUDED) delete safe[k];
773
+ delete safe.banks;
774
+ delete safe.paths;
775
+ return safe;
776
+ }
614
777
  function resolvePartial(cfg, patch) {
615
778
  const full = resolveConfig(patch);
616
779
  const out = {};
@@ -618,6 +781,17 @@ function resolvePartial(cfg, patch) {
618
781
  if (key in full)
619
782
  out[key] = full[key];
620
783
  }
784
+ if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
785
+ if ("serverMode" in patch || "apiUrl" in patch || "apiPort" in patch) {
786
+ const conn = resolveConfig({
787
+ serverMode: patch.serverMode ?? cfg.serverMode,
788
+ apiPort: patch.apiPort ?? cfg.apiPort,
789
+ apiUrl: patch.apiUrl ?? (cfg.serverMode === "daemon" ? void 0 : cfg.apiUrl)
790
+ });
791
+ out.serverMode = conn.serverMode;
792
+ out.apiUrl = conn.apiUrl;
793
+ out.apiPort = conn.apiPort;
794
+ }
621
795
  return out;
622
796
  }
623
797