@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
package/dist/installer.js CHANGED
@@ -2074,6 +2074,34 @@ import { fileURLToPath } from "url";
2074
2074
 
2075
2075
  // src/core/missions.ts
2076
2076
  import { createHash } from "crypto";
2077
+ var PAGE_TAXONOMY = [
2078
+ {
2079
+ name: "Component map",
2080
+ 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.",
2081
+ tags: ["knowledge:component"]
2082
+ },
2083
+ {
2084
+ name: "Core concepts",
2085
+ 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.",
2086
+ tags: ["knowledge:concept"]
2087
+ },
2088
+ {
2089
+ name: "Conventions and patterns",
2090
+ 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.",
2091
+ tags: ["knowledge:convention"]
2092
+ },
2093
+ {
2094
+ name: "Key decisions and rationale",
2095
+ 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.",
2096
+ tags: ["knowledge:decision"]
2097
+ },
2098
+ {
2099
+ name: "Initiatives and enhancements",
2100
+ 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.",
2101
+ tags: ["knowledge:feature-work"]
2102
+ }
2103
+ ];
2104
+ var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
2077
2105
 
2078
2106
  // src/core/util.ts
2079
2107
  import { accessSync, constants } from "fs";
@@ -2230,31 +2258,10 @@ function onPath(bin) {
2230
2258
  import { basename as basename2 } from "path";
2231
2259
 
2232
2260
  // src/core/jsonl.ts
2233
- import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
2261
+ import { closeSync, openSync, readSync } from "fs";
2234
2262
  import { StringDecoder } from "string_decoder";
2235
2263
  var CHUNK_BYTES = 64 * 1024;
2236
- var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
2237
- function readJsonlTail(path, opts) {
2238
- const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
2239
- let size;
2240
- try {
2241
- size = statSync3(path).size;
2242
- } catch {
2243
- return { lines: emptyLines(), skippedBytes: 0 };
2244
- }
2245
- const skippedBytes = size > maxBytes ? size - maxBytes : 0;
2246
- if (skippedBytes > 0) {
2247
- log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
2248
- path,
2249
- sizeBytes: size,
2250
- skippedBytes
2251
- });
2252
- }
2253
- return { lines: streamLines(path, skippedBytes), skippedBytes };
2254
- }
2255
- function* emptyLines() {
2256
- }
2257
- function* streamLines(path, start) {
2264
+ function* readJsonl(path) {
2258
2265
  let fd;
2259
2266
  try {
2260
2267
  fd = openSync(path, "r");
@@ -2265,8 +2272,7 @@ function* streamLines(path, start) {
2265
2272
  const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
2266
2273
  const decoder = new StringDecoder("utf8");
2267
2274
  let pending = "";
2268
- let position = start > 0 ? start - 1 : 0;
2269
- let dropPartial = start > 0;
2275
+ let position = 0;
2270
2276
  for (; ; ) {
2271
2277
  const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
2272
2278
  if (bytesRead <= 0) break;
@@ -2274,17 +2280,12 @@ function* streamLines(path, start) {
2274
2280
  pending += decoder.write(buffer.subarray(0, bytesRead));
2275
2281
  let newline;
2276
2282
  while ((newline = pending.indexOf("\n")) !== -1) {
2277
- const line = pending.slice(0, newline);
2283
+ yield pending.slice(0, newline);
2278
2284
  pending = pending.slice(newline + 1);
2279
- if (dropPartial) {
2280
- dropPartial = false;
2281
- continue;
2282
- }
2283
- yield line;
2284
2285
  }
2285
2286
  }
2286
2287
  pending += decoder.end();
2287
- if (pending && !dropPartial) yield pending;
2288
+ if (pending) yield pending;
2288
2289
  } finally {
2289
2290
  closeSync(fd);
2290
2291
  }
@@ -2316,7 +2317,7 @@ function renderLine(content, type) {
2316
2317
  }
2317
2318
  function readClaudeTranscript(path) {
2318
2319
  const turns = [];
2319
- for (const rawLine of readJsonlTail(path, { scope: "claude-code" }).lines) {
2320
+ for (const rawLine of readJsonl(path)) {
2320
2321
  const trimmed = rawLine.trim();
2321
2322
  if (!trimmed) continue;
2322
2323
  let parsed;
@@ -2448,7 +2449,7 @@ import {
2448
2449
  renameSync as renameSync3,
2449
2450
  rmdirSync,
2450
2451
  rmSync as rmSync2,
2451
- statSync as statSync4,
2452
+ statSync as statSync3,
2452
2453
  unlinkSync,
2453
2454
  utimesSync,
2454
2455
  writeFileSync as writeFileSync2
@@ -2469,6 +2470,8 @@ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
2469
2470
  import { dirname as dirname9, join as join14 } from "path";
2470
2471
  import { fileURLToPath as fileURLToPath4 } from "url";
2471
2472
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2473
+ var NPM_VIEW_TIMEOUT_MS = 5e3;
2474
+ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
2472
2475
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2473
2476
 
2474
2477
  // src/core/skill-sync.ts
@@ -2558,43 +2561,60 @@ function readOne(harness, home) {
2558
2561
  }
2559
2562
 
2560
2563
  // src/core/transcript-codex.ts
2564
+ function stampOf(line) {
2565
+ return typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
2566
+ }
2561
2567
  function isSyntheticUserText(text) {
2562
2568
  const s = text.trimStart();
2563
2569
  return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
2564
2570
  }
2565
- function messageText(payload) {
2566
- return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
2571
+ function contentText(content) {
2572
+ return (content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
2573
+ }
2574
+ function isUserMessageEvent(line) {
2575
+ return line.type === "event_msg" && line.payload?.type === "item_completed" && line.payload.item?.type === "UserMessage";
2567
2576
  }
2568
2577
  function readCodexTranscript(path) {
2569
- const turns = [];
2570
- for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
2578
+ const lines = [];
2579
+ for (const rawLine of readJsonl(path)) {
2571
2580
  const trimmed = rawLine.trim();
2572
2581
  if (!trimmed) continue;
2573
- let parsed;
2574
2582
  try {
2575
- parsed = JSON.parse(trimmed);
2583
+ const parsed = JSON.parse(trimmed);
2584
+ if (typeof parsed === "object" && parsed !== null) lines.push(parsed);
2576
2585
  } catch {
2577
2586
  continue;
2578
2587
  }
2579
- if (typeof parsed !== "object" || parsed === null) continue;
2580
- const line = parsed;
2588
+ }
2589
+ const userFromEvents = lines.some(isUserMessageEvent);
2590
+ const turns = [];
2591
+ const push = (role, raw, stamp = {}) => {
2592
+ const text = stripInjectedMemory(raw).trim();
2593
+ if (text) turns.push({ role, content: text, ...stamp });
2594
+ };
2595
+ for (const line of lines) {
2596
+ if (isUserMessageEvent(line)) {
2597
+ push("user", contentText(line.payload?.item?.content), stampOf(line));
2598
+ continue;
2599
+ }
2581
2600
  if (line.type !== "response_item") continue;
2582
2601
  const p = line.payload;
2583
2602
  if (!p || typeof p !== "object") continue;
2584
2603
  if (p.type === "message") {
2585
- if (p.role !== "user" && p.role !== "assistant") continue;
2586
- const text = stripInjectedMemory(messageText(p)).trim();
2587
- if (!text) continue;
2588
- if (p.role === "user" && isSyntheticUserText(text)) continue;
2589
- turns.push({ role: p.role, content: text });
2590
- } else if (p.type === "function_call" && typeof p.name === "string") {
2604
+ if (p.role === "assistant") push("assistant", contentText(p.content), stampOf(line));
2605
+ else if (p.role === "user" && !userFromEvents) {
2606
+ const text = contentText(p.content);
2607
+ if (!isSyntheticUserText(stripInjectedMemory(text))) push("user", text, stampOf(line));
2608
+ }
2609
+ } else if ((p.type === "function_call" || p.type === "custom_tool_call") && typeof p.name === "string") {
2610
+ const rawInput = p.type === "function_call" ? p.arguments : p.input;
2591
2611
  let input;
2592
2612
  try {
2593
- input = JSON.parse(p.arguments || "");
2613
+ input = JSON.parse(rawInput || "");
2594
2614
  } catch {
2595
2615
  input = void 0;
2596
2616
  }
2597
- turns.push({ role: "action", content: actionLine(p.name, input) });
2617
+ turns.push({ role: "action", content: actionLine(p.name, input), ...stampOf(line) });
2598
2618
  }
2599
2619
  }
2600
2620
  return turns;
@@ -2611,7 +2631,7 @@ function textFrom(content) {
2611
2631
  }
2612
2632
  function readCursorTranscript(path) {
2613
2633
  const turns = [];
2614
- for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
2634
+ for (const rawLine of readJsonl(path)) {
2615
2635
  let parsed;
2616
2636
  try {
2617
2637
  parsed = JSON.parse(rawLine);
@@ -2650,7 +2670,7 @@ function readCursorTranscript(path) {
2650
2670
  function readAntigravityTranscript(path) {
2651
2671
  if (!path) return [];
2652
2672
  const turns = [];
2653
- for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
2673
+ for (const line of readJsonl(path)) {
2654
2674
  try {
2655
2675
  const event = JSON.parse(line);
2656
2676
  const role = event.role ?? event.message?.role ?? event.type;
@@ -2673,7 +2693,7 @@ function readAntigravityTranscript(path) {
2673
2693
  // src/core/transcript-copilot.ts
2674
2694
  function readCopilotTranscript(path) {
2675
2695
  const turns = [];
2676
- for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
2696
+ for (const rawLine of readJsonl(path)) {
2677
2697
  try {
2678
2698
  const event = JSON.parse(rawLine);
2679
2699
  const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
@@ -2708,7 +2728,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
2708
2728
  }
2709
2729
  function readGrokTranscript(path) {
2710
2730
  const turns = [];
2711
- for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
2731
+ for (const rawLine of readJsonl(path)) {
2712
2732
  try {
2713
2733
  const event = JSON.parse(rawLine);
2714
2734
  if (event.type !== "user" && event.type !== "assistant") continue;
@@ -2800,7 +2820,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
2800
2820
 
2801
2821
  // src/core/transcript-dcode.ts
2802
2822
  var BLOCK_JOIN = "\n";
2803
- function contentText(content) {
2823
+ function contentText2(content) {
2804
2824
  if (typeof content === "string") return content;
2805
2825
  if (!Array.isArray(content)) return "";
2806
2826
  return content.flatMap((block) => {
@@ -2893,11 +2913,11 @@ function dcodeAssistantText(raw) {
2893
2913
  const parsed = readPyValue(trimmed, 0);
2894
2914
  if (!parsed || readPyValue(trimmed, parsed.end) !== null) return "";
2895
2915
  if (!Array.isArray(parsed.value)) return "";
2896
- return contentText(parsed.value);
2916
+ return contentText2(parsed.value);
2897
2917
  }
2898
2918
  function readDcodeTranscript(path) {
2899
2919
  const turns = [];
2900
- for (const rawLine of readJsonlTail(path, { scope: "dcode" }).lines) {
2920
+ for (const rawLine of readJsonl(path)) {
2901
2921
  if (!rawLine.trim()) continue;
2902
2922
  let parsed;
2903
2923
  try {
@@ -2911,7 +2931,7 @@ function readDcodeTranscript(path) {
2911
2931
  const role = record.role;
2912
2932
  const stamp = typeof record.timestamp === "string" && record.timestamp ? { timestamp: record.timestamp } : {};
2913
2933
  if (role === "user" || role === "assistant") {
2914
- const text = stripInjectedMemory(contentText(record.content)).trim();
2934
+ const text = stripInjectedMemory(contentText2(record.content)).trim();
2915
2935
  if (text) turns.push({ role, content: text, ...stamp });
2916
2936
  } else if (role === "tool" && typeof record.name === "string" && record.name.trim()) {
2917
2937
  turns.push({ role: "action", content: actionLine(record.name, record.content), ...stamp });
@@ -2972,7 +2992,7 @@ function readQwenTranscript(path) {
2972
2992
  return turns;
2973
2993
  }
2974
2994
  function collectQwenTurns(path, turns) {
2975
- for (const rawLine of readJsonlTail(path, { scope: "qwen-code" }).lines) {
2995
+ for (const rawLine of readJsonl(path)) {
2976
2996
  const trimmed = rawLine.trim();
2977
2997
  if (!trimmed) continue;
2978
2998
  let parsed;
@@ -3027,7 +3047,7 @@ function renderContent(content, role) {
3027
3047
  }
3028
3048
  function readDroidTranscript(path) {
3029
3049
  const turns = [];
3030
- for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
3050
+ for (const rawLine of readJsonl(path)) {
3031
3051
  if (!rawLine.trim()) continue;
3032
3052
  let parsed;
3033
3053
  try {
@@ -3050,7 +3070,7 @@ function readDroidTranscript(path) {
3050
3070
 
3051
3071
  // src/core/transcript-zcode.ts
3052
3072
  import { readFileSync as readFileSync13 } from "fs";
3053
- function messageText2(content) {
3073
+ function messageText(content) {
3054
3074
  if (typeof content === "string") return content.trim();
3055
3075
  if (!Array.isArray(content)) return "";
3056
3076
  return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
@@ -3078,7 +3098,7 @@ function readZcodeTranscript(path) {
3078
3098
  const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
3079
3099
  const role = typeof message?.role === "string" ? message.role : record.type;
3080
3100
  if (role !== "user" && role !== "assistant") continue;
3081
- const content = stripInjectedMemory(messageText2(message?.content)).trim();
3101
+ const content = stripInjectedMemory(messageText(message?.content)).trim();
3082
3102
  if (!content) continue;
3083
3103
  turns.push({
3084
3104
  role,
@@ -3431,7 +3451,7 @@ var HOOK_HARNESSES = {
3431
3451
  // `detached` and terminates the whole process TREE on timeout, so the retain is genuinely lost
3432
3452
  // rather than merely orphaned. `retain.hostTimeoutSec` below stays SECONDS, as its name says;
3433
3453
  // these two numbers are the same budget in different units for this harness alone.
3434
- // The prompt timeout must also stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3454
+ // The prompt timeout must also stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
3435
3455
  install: {
3436
3456
  sessionStart: { event: "SessionStart", entry: "qwen-sessionstart-hook.js", timeout: 3e4 },
3437
3457
  prompt: { event: "UserPromptSubmit", entry: "qwen-hook.js", timeout: 3e4 },
@@ -3493,7 +3513,7 @@ var HOOK_HARNESSES = {
3493
3513
  zcode: {
3494
3514
  configStyle: "process",
3495
3515
  // ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
3496
- // prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3516
+ // prompt budget must stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
3497
3517
  timeoutUnit: "milliseconds",
3498
3518
  install: {
3499
3519
  sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
@@ -3538,7 +3558,7 @@ import {
3538
3558
  readdirSync as readdirSync3,
3539
3559
  readFileSync as readFileSync14,
3540
3560
  readSync as readSync2,
3541
- statSync as statSync5
3561
+ statSync as statSync4
3542
3562
  } from "fs";
3543
3563
  import { createHash as createHash5 } from "crypto";
3544
3564
  import { homedir as homedir10 } from "os";
@@ -3549,14 +3569,14 @@ import * as zlib2 from "zlib";
3549
3569
  function textOf(message) {
3550
3570
  return (message.content || []).filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
3551
3571
  }
3552
- function stampOf(event) {
3572
+ function stampOf2(event) {
3553
3573
  return typeof event.time === "number" ? { timestamp: new Date(event.time).toISOString() } : {};
3554
3574
  }
3555
3575
  function readDshEvents(events) {
3556
3576
  const turns = [];
3557
3577
  for (const event of events || []) {
3558
3578
  if (!event || typeof event !== "object") continue;
3559
- const stamp = stampOf(event);
3579
+ const stamp = stampOf2(event);
3560
3580
  if (event.type === "user/message") {
3561
3581
  const message = event.data;
3562
3582
  if (!message || message.source?.kind !== "user") continue;
@@ -3618,7 +3638,7 @@ function renderMessage(m) {
3618
3638
  }
3619
3639
  function readPiTranscript(path) {
3620
3640
  const turns = [];
3621
- for (const rawLine of readJsonlTail(path, { scope: "pi" }).lines) {
3641
+ for (const rawLine of readJsonl(path)) {
3622
3642
  const trimmed = rawLine.trim();
3623
3643
  if (!trimmed) continue;
3624
3644
  let parsed;
@@ -3771,7 +3791,7 @@ function codexHistory(repoDir, home) {
3771
3791
  const walk = (dir) => {
3772
3792
  for (const entry of readdirSync3(dir)) {
3773
3793
  const p = join19(dir, entry);
3774
- if (statSync5(p).isDirectory()) walk(p);
3794
+ if (statSync4(p).isDirectory()) walk(p);
3775
3795
  else if (entry.endsWith(".jsonl")) files.push(p);
3776
3796
  }
3777
3797
  };
@@ -5252,7 +5272,9 @@ ${DSH_MARKER_END}
5252
5272
 
5253
5273
  ${block}` : block);
5254
5274
  installSkill(c, "dsh");
5255
- c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
5275
+ c.log?.(
5276
+ `dsh: plugin registered in ${path} (applies to every dsh profile; start new sessions \u2014 ones already open would gain the tools mid-conversation)`
5277
+ );
5256
5278
  },
5257
5279
  uninstall(c) {
5258
5280
  const path = join20(dshHome(c), "cordis.patch.yml");