@vectorize-io/hindsight-coding-agents 0.5.1 → 0.5.3

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 +84 -9
  2. package/dist/antigravity-hook.js +424 -81
  3. package/dist/antigravity-statusline.js +56 -11
  4. package/dist/antigravity-stop-hook.js +515 -134
  5. package/dist/claude-hook.js +424 -81
  6. package/dist/claude-sessionstart-hook.js +392 -98
  7. package/dist/claude-stop-hook.js +515 -134
  8. package/dist/cline.js +218 -73
  9. package/dist/codex-hook.js +424 -81
  10. package/dist/codex-sessionstart-hook.js +392 -98
  11. package/dist/codex-stop-hook.js +515 -134
  12. package/dist/copilot-hook.js +424 -81
  13. package/dist/copilot-sessionstart-hook.js +392 -98
  14. package/dist/copilot-stop-hook.js +515 -134
  15. package/dist/cursor-hook.js +424 -81
  16. package/dist/cursor-sessionstart-hook.js +392 -98
  17. package/dist/cursor-stop-hook.js +515 -134
  18. package/dist/daemon-start.js +50 -9
  19. package/dist/dcode-hook.js +424 -81
  20. package/dist/dcode-sessionstart-hook.js +392 -98
  21. package/dist/dcode-stop-hook.js +515 -134
  22. package/dist/deepen.js +164 -27
  23. package/dist/devin-hook.js +424 -81
  24. package/dist/devin-sessionstart-hook.js +392 -98
  25. package/dist/devin-stop-hook.js +515 -134
  26. package/dist/droid-hook.js +2920 -0
  27. package/dist/droid-sessionstart-hook.js +3487 -0
  28. package/dist/droid-stop-hook.js +3188 -0
  29. package/dist/dsh.js +260 -109
  30. package/dist/grok-hook.js +424 -81
  31. package/dist/grok-sessionstart-hook.js +392 -98
  32. package/dist/grok-stop-hook.js +515 -134
  33. package/dist/hindsight-seed.js +56 -11
  34. package/dist/index.js +257 -110
  35. package/dist/installer.js +530 -223
  36. package/dist/kilo.js +257 -110
  37. package/dist/mcp-server.js +537 -146
  38. package/dist/opencode2.js +257 -110
  39. package/dist/pi.js +256 -109
  40. package/dist/prime-agent.js +256 -109
  41. package/dist/qwen-hook.js +424 -81
  42. package/dist/qwen-sessionstart-hook.js +392 -98
  43. package/dist/qwen-stop-hook.js +515 -134
  44. package/dist/status.js +128 -20
  45. package/dist/zcode-hook.js +2920 -0
  46. package/dist/zcode-sessionstart-hook.js +3487 -0
  47. package/dist/zcode-stop-hook.js +3188 -0
  48. package/package.json +11 -5
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +42 -8
package/dist/status.js CHANGED
@@ -270,9 +270,13 @@ function isOptedIn(config, directory) {
270
270
  const pathMap = config.mapPathToBank;
271
271
  return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
272
272
  }
273
- function deriveBankId(config, directory, harness = "coding", sessionRoot) {
273
+ function mappedBank(config, directory, sessionRoot) {
274
274
  const pathMap = config.mapPathToBank;
275
- const mapped = directory && pathMap ? lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0) : void 0;
275
+ if (!directory || !pathMap) return void 0;
276
+ return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
277
+ }
278
+ function deriveBankId(config, directory, harness = "coding", sessionRoot) {
279
+ const mapped = mappedBank(config, directory, sessionRoot);
276
280
  if (mapped) return mapped;
277
281
  const dynamic = config.dynamicBankId ?? !config.bankId;
278
282
  if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
@@ -311,6 +315,7 @@ import { fileURLToPath } from "url";
311
315
  var DEFAULT_SEED_LIMIT = 300;
312
316
 
313
317
  // src/core/missions.ts
318
+ import { createHash } from "crypto";
314
319
  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.";
315
320
  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.";
316
321
  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.`;
@@ -422,17 +427,77 @@ function pagesFor(project) {
422
427
  var PAGE_MAX_TOKENS = 4096;
423
428
  var PAGE_TAGS_MATCH = "all";
424
429
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
430
+ var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
431
+ var CRON_FIELD_RANGES = [
432
+ [0, 59],
433
+ // minute
434
+ [0, 23],
435
+ // hour
436
+ [1, 31],
437
+ // day of month
438
+ [1, 12],
439
+ // month
440
+ [0, 6]
441
+ // day of week
442
+ ];
443
+ var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
444
+ function isHashedCron(cron) {
445
+ return /(^|\s)H/.test(cron);
446
+ }
447
+ function parseHashedCron(cron) {
448
+ const fields = cron.trim().split(/\s+/);
449
+ if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
450
+ for (const [i, field] of fields.entries()) {
451
+ if (!field.startsWith("H")) continue;
452
+ const m = HASHED_FIELD.exec(field);
453
+ if (!m) return void 0;
454
+ if (m[1] === void 0) continue;
455
+ const [lo, hi] = [Number(m[1]), Number(m[2])];
456
+ const [min, max] = CRON_FIELD_RANGES[i];
457
+ if (lo > hi || lo < min || hi > max) return void 0;
458
+ }
459
+ return fields;
460
+ }
461
+ function hashedValue(seed, field, lo, hi) {
462
+ const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
463
+ return lo + digest.readUInt32BE(0) % (hi - lo + 1);
464
+ }
465
+ function expandCronHash(cron, seed) {
466
+ if (!isHashedCron(cron)) return cron;
467
+ const fields = parseHashedCron(cron);
468
+ if (!fields) return cron;
469
+ return fields.map((field, i) => {
470
+ const m = HASHED_FIELD.exec(field);
471
+ if (!m) return field;
472
+ const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
473
+ return String(hashedValue(seed, i, lo, hi));
474
+ }).join(" ");
475
+ }
476
+ function pageTriggerFor(trigger, bank, page) {
477
+ const cron = trigger.refresh_cron;
478
+ if (!cron || !isHashedCron(cron)) return trigger;
479
+ return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
480
+ }
425
481
  function buildPageTrigger(cfg2 = {}) {
426
482
  const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
427
483
  switch (cfg2.pageTriggerType) {
428
- case "cron":
429
- return { ...base, refresh_cron: cfg2.pageTriggerCron };
484
+ case "auto-refresh":
485
+ return { ...base, refresh_after_consolidation: true };
430
486
  case "manual":
431
487
  return { ...base, refresh_after_consolidation: false };
488
+ // "cron" and an unset type alike: the default schedule stands in for a missing expression, so
489
+ // a trigger built from a partial config is never a cron trigger with nothing to fire on.
432
490
  default:
433
- return { ...base, refresh_after_consolidation: true };
491
+ return { ...base, refresh_cron: cfg2.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
434
492
  }
435
493
  }
494
+ function pageTriggerDrifted(current2, desired) {
495
+ return current2.tags_match !== desired.tags_match || (current2.refresh_cron ?? null) !== (desired.refresh_cron ?? null) || Boolean(current2.refresh_after_consolidation) !== Boolean(desired.refresh_after_consolidation);
496
+ }
497
+ function pageTriggerPatch(desired) {
498
+ if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
499
+ return desired;
500
+ }
436
501
  var CODING_BANK_TEMPLATE = {
437
502
  version: "1",
438
503
  bank: {
@@ -956,7 +1021,9 @@ var HindsightClient = class {
956
1021
  source_query: page.source_query,
957
1022
  tags: page.tags,
958
1023
  max_tokens: PAGE_MAX_TOKENS,
959
- trigger: pageTrigger
1024
+ // Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
1025
+ // and one trigger is built per session for all of them.
1026
+ trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
960
1027
  };
961
1028
  if (!hit) {
962
1029
  const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
@@ -970,14 +1037,14 @@ var HindsightClient = class {
970
1037
  if (r.status !== 409) created++;
971
1038
  } else {
972
1039
  const sourceDrift = hit.description !== page.source_query;
973
- const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
1040
+ const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
974
1041
  if (!sourceDrift && !triggerDrift) continue;
975
1042
  const patch = {};
976
1043
  if (sourceDrift) {
977
1044
  patch.source_query = page.source_query;
978
1045
  patch.tags = page.tags;
979
1046
  }
980
- if (triggerDrift) patch.trigger = pageTrigger;
1047
+ if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
981
1048
  const r = await this.req(
982
1049
  "PATCH",
983
1050
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
@@ -993,9 +1060,41 @@ var HindsightClient = class {
993
1060
  updated++;
994
1061
  }
995
1062
  }
1063
+ const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
996
1064
  this.log(
997
- `[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
1065
+ `[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` : "")
1066
+ );
1067
+ }
1068
+ /**
1069
+ * Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
1070
+ *
1071
+ * `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
1072
+ * an older default they are the same drift as the taxonomy — and on a real repo they are most of
1073
+ * it: five taxonomy pages against one page per initiative, each an LLM synthesis per
1074
+ * consolidation under the auto-refresh that used to be the default (#3506).
1075
+ *
1076
+ * Only the trigger is touched. Their `name` and `source_query` are written once, from the
1077
+ * initiative's own title, and re-stating either would rebuild a page whose question never
1078
+ * changed. The tree read above is reused rather than re-fetched.
1079
+ */
1080
+ async resyncInitiativeTriggers(roots, pageTrigger) {
1081
+ const folder = roots.find(
1082
+ (n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
998
1083
  );
1084
+ let updated = 0;
1085
+ for (const page of folder?.children ?? []) {
1086
+ if (page.kind !== "page" || page.trigger == null) continue;
1087
+ const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
1088
+ if (!pageTriggerDrifted(page.trigger, desired)) continue;
1089
+ const r = await this.req(
1090
+ "PATCH",
1091
+ this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
1092
+ { trigger: pageTriggerPatch(desired) }
1093
+ );
1094
+ if ([404, 405, 501].includes(r.status)) break;
1095
+ updated++;
1096
+ }
1097
+ return updated;
999
1098
  }
1000
1099
  /** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
1001
1100
  slugify(s) {
@@ -1018,12 +1117,14 @@ var HindsightClient = class {
1018
1117
  let pageId = args.relatesToPageId;
1019
1118
  if (!pageId) {
1020
1119
  const folderId = await this.ensureFolder("Initiatives");
1120
+ const subject = this.project ?? this.bank;
1021
1121
  const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
1022
1122
  name: args.title,
1023
- 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.`,
1123
+ 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),
1024
1124
  parent_id: folderId,
1025
1125
  tags: ["knowledge:feature-work"],
1026
- trigger: args.pageTrigger ?? buildPageTrigger()
1126
+ max_tokens: PAGE_MAX_TOKENS,
1127
+ trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
1027
1128
  });
1028
1129
  try {
1029
1130
  const j = await r.json();
@@ -1065,16 +1166,22 @@ var HindsightClient = class {
1065
1166
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
1066
1167
  var DEFAULT_DAEMON_PORT = 9077;
1067
1168
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1068
- function resolvePageTriggerType(raw) {
1069
- if (raw.pageTriggerType === "manual") return "manual";
1070
- if (raw.pageTriggerType === "cron") {
1071
- if (raw.pageTriggerCron?.trim()) return "cron";
1169
+ function resolvePageTrigger(raw) {
1170
+ if (raw.pageTriggerType === "manual") return { type: "manual" };
1171
+ if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
1172
+ if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
1072
1173
  log.warn(
1073
1174
  "config",
1074
- 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "0 3 * * *") \u2014 falling back to "auto-refresh"'
1175
+ `ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
1075
1176
  );
1076
- }
1077
- return "auto-refresh";
1177
+ const cron = raw.pageTriggerCron?.trim();
1178
+ if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
1179
+ if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
1180
+ log.warn(
1181
+ "config",
1182
+ `pageTriggerCron ${JSON.stringify(cron)} has a malformed hashed field \u2014 write \`H\` or \`H(<lo>-<hi>)\` within the field's own range, e.g. "H H(0-5) * * *" \u2014 falling back to ${JSON.stringify(DEFAULT_PAGE_TRIGGER_CRON)}`
1183
+ );
1184
+ return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
1078
1185
  }
1079
1186
  var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
1080
1187
  var REFLECT_BUDGETS = ["low", "mid", "high"];
@@ -1106,6 +1213,7 @@ function resolveObservationScopes(raw) {
1106
1213
  function resolveConfig(raw = {}) {
1107
1214
  const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
1108
1215
  const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
1216
+ const pageTrigger = resolvePageTrigger(raw);
1109
1217
  return {
1110
1218
  serverMode,
1111
1219
  // Daemon mode resolves the URL HERE rather than at each call site: every entry point already
@@ -1140,8 +1248,8 @@ function resolveConfig(raw = {}) {
1140
1248
  reflectBudget: resolveReflectBudget(raw),
1141
1249
  autoReflect: raw.autoReflect ?? true,
1142
1250
  pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
1143
- pageTriggerType: resolvePageTriggerType(raw),
1144
- pageTriggerCron: raw.pageTriggerCron?.trim() || void 0,
1251
+ pageTriggerType: pageTrigger.type,
1252
+ pageTriggerCron: pageTrigger.cron,
1145
1253
  autoSeed: raw.autoSeed ?? true,
1146
1254
  seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
1147
1255
  codebaseSurvey: raw.codebaseSurvey ?? true,