@vectorize-io/hindsight-coding-agents 0.5.2 → 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 +42 -8
  2. package/dist/antigravity-hook.js +286 -76
  3. package/dist/antigravity-statusline.js +17 -10
  4. package/dist/antigravity-stop-hook.js +297 -79
  5. package/dist/claude-hook.js +286 -76
  6. package/dist/claude-sessionstart-hook.js +252 -93
  7. package/dist/claude-stop-hook.js +297 -79
  8. package/dist/cline.js +74 -18
  9. package/dist/codex-hook.js +286 -76
  10. package/dist/codex-sessionstart-hook.js +252 -93
  11. package/dist/codex-stop-hook.js +297 -79
  12. package/dist/copilot-hook.js +286 -76
  13. package/dist/copilot-sessionstart-hook.js +252 -93
  14. package/dist/copilot-stop-hook.js +297 -79
  15. package/dist/cursor-hook.js +286 -76
  16. package/dist/cursor-sessionstart-hook.js +252 -93
  17. package/dist/cursor-stop-hook.js +297 -79
  18. package/dist/daemon-start.js +17 -10
  19. package/dist/dcode-hook.js +286 -76
  20. package/dist/dcode-sessionstart-hook.js +252 -93
  21. package/dist/dcode-stop-hook.js +297 -79
  22. package/dist/deepen.js +73 -19
  23. package/dist/devin-hook.js +286 -76
  24. package/dist/devin-sessionstart-hook.js +252 -93
  25. package/dist/devin-stop-hook.js +297 -79
  26. package/dist/droid-hook.js +286 -76
  27. package/dist/droid-sessionstart-hook.js +252 -93
  28. package/dist/droid-stop-hook.js +297 -79
  29. package/dist/dsh.js +111 -53
  30. package/dist/grok-hook.js +286 -76
  31. package/dist/grok-sessionstart-hook.js +252 -93
  32. package/dist/grok-stop-hook.js +297 -79
  33. package/dist/hindsight-seed.js +17 -10
  34. package/dist/index.js +113 -55
  35. package/dist/installer.js +383 -218
  36. package/dist/kilo.js +113 -55
  37. package/dist/mcp-server.js +67 -17
  38. package/dist/opencode2.js +113 -55
  39. package/dist/pi.js +112 -54
  40. package/dist/prime-agent.js +112 -54
  41. package/dist/qwen-hook.js +286 -76
  42. package/dist/qwen-sessionstart-hook.js +252 -93
  43. package/dist/qwen-stop-hook.js +297 -79
  44. package/dist/status.js +67 -17
  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 +6 -3
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +17 -7
@@ -313,6 +313,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
313
313
 
314
314
  // src/core/missions.ts
315
315
  import { createHash } from "crypto";
316
+ var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
316
317
  var CRON_FIELD_RANGES = [
317
318
  [0, 59],
318
319
  // minute
@@ -357,17 +358,22 @@ var RETRY_AFTER_CEILING_MS = 60 * 1e3;
357
358
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
358
359
  var DEFAULT_DAEMON_PORT = 9077;
359
360
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
360
- function resolvePageTriggerType(raw) {
361
- if (raw.pageTriggerType === "manual") return "manual";
362
- if (raw.pageTriggerType === "cron") {
363
- const cron = raw.pageTriggerCron?.trim();
364
- if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
361
+ function resolvePageTrigger(raw) {
362
+ if (raw.pageTriggerType === "manual") return { type: "manual" };
363
+ if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
364
+ if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
365
365
  log.warn(
366
366
  "config",
367
- cron ? `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 "auto-refresh"` : 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "H H * * *") \u2014 falling back to "auto-refresh"'
367
+ `ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
368
368
  );
369
- }
370
- return "auto-refresh";
369
+ const cron = raw.pageTriggerCron?.trim();
370
+ if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
371
+ if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
372
+ log.warn(
373
+ "config",
374
+ `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)}`
375
+ );
376
+ return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
371
377
  }
372
378
  var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
373
379
  var REFLECT_BUDGETS = ["low", "mid", "high"];
@@ -399,6 +405,7 @@ function resolveObservationScopes(raw) {
399
405
  function resolveConfig(raw = {}) {
400
406
  const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
401
407
  const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
408
+ const pageTrigger = resolvePageTrigger(raw);
402
409
  return {
403
410
  serverMode,
404
411
  // Daemon mode resolves the URL HERE rather than at each call site: every entry point already
@@ -433,8 +440,8 @@ function resolveConfig(raw = {}) {
433
440
  reflectBudget: resolveReflectBudget(raw),
434
441
  autoReflect: raw.autoReflect ?? true,
435
442
  pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
436
- pageTriggerType: resolvePageTriggerType(raw),
437
- pageTriggerCron: raw.pageTriggerCron?.trim() || void 0,
443
+ pageTriggerType: pageTrigger.type,
444
+ pageTriggerCron: pageTrigger.cron,
438
445
  autoSeed: raw.autoSeed ?? true,
439
446
  seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
440
447
  codebaseSurvey: raw.codebaseSurvey ?? true,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/core/hook.ts
4
- import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
4
+ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
5
5
 
6
6
  // src/core/bank.ts
7
7
  import { existsSync } from "fs";
@@ -447,6 +447,7 @@ function pagesFor(project) {
447
447
  var PAGE_MAX_TOKENS = 4096;
448
448
  var PAGE_TAGS_MATCH = "all";
449
449
  var PAGE_FACT_TYPES = ["world", "experience", "observation"];
450
+ var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
450
451
  var CRON_FIELD_RANGES = [
451
452
  [0, 59],
452
453
  // minute
@@ -500,14 +501,23 @@ function pageTriggerFor(trigger, bank, page) {
500
501
  function buildPageTrigger(cfg = {}) {
501
502
  const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
502
503
  switch (cfg.pageTriggerType) {
503
- case "cron":
504
- return { ...base, refresh_cron: cfg.pageTriggerCron };
504
+ case "auto-refresh":
505
+ return { ...base, refresh_after_consolidation: true };
505
506
  case "manual":
506
507
  return { ...base, refresh_after_consolidation: false };
508
+ // "cron" and an unset type alike: the default schedule stands in for a missing expression, so
509
+ // a trigger built from a partial config is never a cron trigger with nothing to fire on.
507
510
  default:
508
- return { ...base, refresh_after_consolidation: true };
511
+ return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
509
512
  }
510
513
  }
514
+ function pageTriggerDrifted(current2, desired) {
515
+ 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);
516
+ }
517
+ function pageTriggerPatch(desired) {
518
+ if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
519
+ return desired;
520
+ }
511
521
  var CODING_BANK_TEMPLATE = {
512
522
  version: "1",
513
523
  bank: {
@@ -1047,14 +1057,14 @@ var HindsightClient = class {
1047
1057
  if (r.status !== 409) created++;
1048
1058
  } else {
1049
1059
  const sourceDrift = hit.description !== page.source_query;
1050
- const triggerDrift = hit.trigger != null && hit.trigger.tags_match !== pageTrigger.tags_match;
1060
+ const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
1051
1061
  if (!sourceDrift && !triggerDrift) continue;
1052
1062
  const patch = {};
1053
1063
  if (sourceDrift) {
1054
1064
  patch.source_query = page.source_query;
1055
1065
  patch.tags = page.tags;
1056
1066
  }
1057
- if (triggerDrift) patch.trigger = pageTrigger;
1067
+ if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
1058
1068
  const r = await this.req(
1059
1069
  "PATCH",
1060
1070
  this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
@@ -1070,10 +1080,42 @@ var HindsightClient = class {
1070
1080
  updated++;
1071
1081
  }
1072
1082
  }
1083
+ const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
1073
1084
  this.log(
1074
- `[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
1085
+ `[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` : "")
1075
1086
  );
1076
1087
  }
1088
+ /**
1089
+ * Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
1090
+ *
1091
+ * `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
1092
+ * an older default they are the same drift as the taxonomy — and on a real repo they are most of
1093
+ * it: five taxonomy pages against one page per initiative, each an LLM synthesis per
1094
+ * consolidation under the auto-refresh that used to be the default (#3506).
1095
+ *
1096
+ * Only the trigger is touched. Their `name` and `source_query` are written once, from the
1097
+ * initiative's own title, and re-stating either would rebuild a page whose question never
1098
+ * changed. The tree read above is reused rather than re-fetched.
1099
+ */
1100
+ async resyncInitiativeTriggers(roots, pageTrigger) {
1101
+ const folder = roots.find(
1102
+ (n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
1103
+ );
1104
+ let updated = 0;
1105
+ for (const page of folder?.children ?? []) {
1106
+ if (page.kind !== "page" || page.trigger == null) continue;
1107
+ const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
1108
+ if (!pageTriggerDrifted(page.trigger, desired)) continue;
1109
+ const r = await this.req(
1110
+ "PATCH",
1111
+ this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
1112
+ { trigger: pageTriggerPatch(desired) }
1113
+ );
1114
+ if ([404, 405, 501].includes(r.status)) break;
1115
+ updated++;
1116
+ }
1117
+ return updated;
1118
+ }
1077
1119
  /** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
1078
1120
  slugify(s) {
1079
1121
  return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
@@ -1095,11 +1137,13 @@ var HindsightClient = class {
1095
1137
  let pageId = args.relatesToPageId;
1096
1138
  if (!pageId) {
1097
1139
  const folderId = await this.ensureFolder("Initiatives");
1140
+ const subject = this.project ?? this.bank;
1098
1141
  const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
1099
1142
  name: args.title,
1100
- 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.`,
1143
+ 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),
1101
1144
  parent_id: folderId,
1102
1145
  tags: ["knowledge:feature-work"],
1146
+ max_tokens: PAGE_MAX_TOKENS,
1103
1147
  trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
1104
1148
  });
1105
1149
  try {
@@ -1142,17 +1186,22 @@ var HindsightClient = class {
1142
1186
  var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
1143
1187
  var DEFAULT_DAEMON_PORT = 9077;
1144
1188
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
1145
- function resolvePageTriggerType(raw) {
1146
- if (raw.pageTriggerType === "manual") return "manual";
1147
- if (raw.pageTriggerType === "cron") {
1148
- const cron = raw.pageTriggerCron?.trim();
1149
- if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
1189
+ function resolvePageTrigger(raw) {
1190
+ if (raw.pageTriggerType === "manual") return { type: "manual" };
1191
+ if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
1192
+ if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
1150
1193
  log.warn(
1151
1194
  "config",
1152
- cron ? `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 "auto-refresh"` : 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "H H * * *") \u2014 falling back to "auto-refresh"'
1195
+ `ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
1153
1196
  );
1154
- }
1155
- return "auto-refresh";
1197
+ const cron = raw.pageTriggerCron?.trim();
1198
+ if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
1199
+ if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
1200
+ log.warn(
1201
+ "config",
1202
+ `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)}`
1203
+ );
1204
+ return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
1156
1205
  }
1157
1206
  var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
1158
1207
  var REFLECT_BUDGETS = ["low", "mid", "high"];
@@ -1184,6 +1233,7 @@ function resolveObservationScopes(raw) {
1184
1233
  function resolveConfig(raw = {}) {
1185
1234
  const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
1186
1235
  const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
1236
+ const pageTrigger = resolvePageTrigger(raw);
1187
1237
  return {
1188
1238
  serverMode,
1189
1239
  // Daemon mode resolves the URL HERE rather than at each call site: every entry point already
@@ -1218,8 +1268,8 @@ function resolveConfig(raw = {}) {
1218
1268
  reflectBudget: resolveReflectBudget(raw),
1219
1269
  autoReflect: raw.autoReflect ?? true,
1220
1270
  pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
1221
- pageTriggerType: resolvePageTriggerType(raw),
1222
- pageTriggerCron: raw.pageTriggerCron?.trim() || void 0,
1271
+ pageTriggerType: pageTrigger.type,
1272
+ pageTriggerCron: pageTrigger.cron,
1223
1273
  autoSeed: raw.autoSeed ?? true,
1224
1274
  seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
1225
1275
  codebaseSurvey: raw.codebaseSurvey ?? true,
@@ -1445,8 +1495,104 @@ function fileCursorStore(harness) {
1445
1495
  };
1446
1496
  }
1447
1497
 
1498
+ // src/core/turn-journal.ts
1499
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
1500
+ import { tmpdir as tmpdir3 } from "os";
1501
+ import { dirname as dirname6, join as join8 } from "path";
1502
+
1503
+ // src/core/transcript-util.ts
1504
+ var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
1505
+ function stripInjectedMemory(s) {
1506
+ return s.replace(MEMORY_TAG_RE, "");
1507
+ }
1508
+ var TARGET_KEYS = [
1509
+ "file_path",
1510
+ "path",
1511
+ "notebook_path",
1512
+ "command",
1513
+ "pattern",
1514
+ "query",
1515
+ "url",
1516
+ "name",
1517
+ "id"
1518
+ ];
1519
+ var ACTION_TARGET_CAP = 100;
1520
+ function actionLine(tool, input) {
1521
+ let target = "";
1522
+ if (input && typeof input === "object") {
1523
+ const rec = input;
1524
+ for (const k of TARGET_KEYS) {
1525
+ const v = rec[k];
1526
+ if (typeof v === "string" && v.trim()) {
1527
+ target = v.trim().split("\n")[0];
1528
+ break;
1529
+ }
1530
+ }
1531
+ } else if (typeof input === "string") {
1532
+ target = input.trim().split("\n")[0];
1533
+ }
1534
+ if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1535
+ return target ? `${tool} ${target}` : tool;
1536
+ }
1537
+
1538
+ // src/core/turn-journal.ts
1539
+ var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
1540
+ function journalPath(harness, sessionId) {
1541
+ return join8(tmpdir3(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
1542
+ }
1543
+ function appendJournalTurn(path, turn) {
1544
+ const content = stripInjectedMemory(turn.content ?? "").trim();
1545
+ if (!content) return;
1546
+ try {
1547
+ if (statSync(path).size >= JOURNAL_MAX_BYTES) return;
1548
+ } catch {
1549
+ }
1550
+ const last = readJournalTranscript(path).at(-1);
1551
+ if (last && last.role === turn.role && last.content === content) return;
1552
+ try {
1553
+ mkdirSync3(dirname6(path), { recursive: true });
1554
+ appendFileSync3(
1555
+ path,
1556
+ JSON.stringify({
1557
+ role: turn.role,
1558
+ content,
1559
+ timestamp: turn.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
1560
+ }) + "\n"
1561
+ );
1562
+ } catch {
1563
+ }
1564
+ }
1565
+ function readJournalTranscript(path) {
1566
+ let body;
1567
+ try {
1568
+ body = readFileSync4(path, "utf8");
1569
+ } catch {
1570
+ return [];
1571
+ }
1572
+ const turns = [];
1573
+ for (const line of body.split("\n")) {
1574
+ const trimmed = line.trim();
1575
+ if (!trimmed) continue;
1576
+ let parsed;
1577
+ try {
1578
+ parsed = JSON.parse(trimmed);
1579
+ } catch {
1580
+ continue;
1581
+ }
1582
+ if (typeof parsed !== "object" || parsed === null) continue;
1583
+ const { role, content, timestamp } = parsed;
1584
+ if (typeof role !== "string" || typeof content !== "string" || !content) continue;
1585
+ turns.push({
1586
+ role,
1587
+ content,
1588
+ ...typeof timestamp === "string" ? { timestamp } : {}
1589
+ });
1590
+ }
1591
+ return turns;
1592
+ }
1593
+
1448
1594
  // src/core/retain-hook.ts
1449
- import { readFileSync as readFileSync5 } from "fs";
1595
+ import { readFileSync as readFileSync6 } from "fs";
1450
1596
 
1451
1597
  // src/core/retain-cursor.ts
1452
1598
  import { createHash as createHash2 } from "crypto";
@@ -1639,7 +1785,7 @@ ${content}`);
1639
1785
 
1640
1786
  // src/core/daemon.ts
1641
1787
  import { execFileSync, spawn as realSpawn2 } from "child_process";
1642
- import { dirname as dirname6, join as join8 } from "path";
1788
+ import { dirname as dirname7, join as join9 } from "path";
1643
1789
  import { fileURLToPath as fileURLToPath2 } from "url";
1644
1790
  var DAEMON_WAIT_RETAIN_MS = 4e4;
1645
1791
  async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
@@ -1713,7 +1859,7 @@ function onPath(bin) {
1713
1859
  }
1714
1860
  function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
1715
1861
  try {
1716
- const starter = join8(dirname6(fileURLToPath2(import.meta.url)), "daemon-start.js");
1862
+ const starter = join9(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
1717
1863
  const child = spawnFn("node", [starter, "--harness", harness], {
1718
1864
  detached: true,
1719
1865
  stdio: "ignore",
@@ -1814,7 +1960,7 @@ function buildRetainStamp(cfg, ctx) {
1814
1960
  }
1815
1961
 
1816
1962
  // src/core/jsonl.ts
1817
- import { closeSync, openSync, readSync, statSync } from "fs";
1963
+ import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1818
1964
  import { StringDecoder } from "string_decoder";
1819
1965
  var CHUNK_BYTES = 64 * 1024;
1820
1966
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -1822,7 +1968,7 @@ function readJsonlTail(path, opts) {
1822
1968
  const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1823
1969
  let size;
1824
1970
  try {
1825
- size = statSync(path).size;
1971
+ size = statSync2(path).size;
1826
1972
  } catch {
1827
1973
  return { lines: emptyLines(), skippedBytes: 0 };
1828
1974
  }
@@ -1874,41 +2020,6 @@ function* streamLines(path, start) {
1874
2020
  }
1875
2021
  }
1876
2022
 
1877
- // src/core/transcript-util.ts
1878
- var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
1879
- function stripInjectedMemory(s) {
1880
- return s.replace(MEMORY_TAG_RE, "");
1881
- }
1882
- var TARGET_KEYS = [
1883
- "file_path",
1884
- "path",
1885
- "notebook_path",
1886
- "command",
1887
- "pattern",
1888
- "query",
1889
- "url",
1890
- "name",
1891
- "id"
1892
- ];
1893
- var ACTION_TARGET_CAP = 100;
1894
- function actionLine(tool, input) {
1895
- let target = "";
1896
- if (input && typeof input === "object") {
1897
- const rec = input;
1898
- for (const k of TARGET_KEYS) {
1899
- const v = rec[k];
1900
- if (typeof v === "string" && v.trim()) {
1901
- target = v.trim().split("\n")[0];
1902
- break;
1903
- }
1904
- }
1905
- } else if (typeof input === "string") {
1906
- target = input.trim().split("\n")[0];
1907
- }
1908
- if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
1909
- return target ? `${tool} ${target}` : tool;
1910
- }
1911
-
1912
2023
  // src/core/transcript.ts
1913
2024
  function renderLine(content, type) {
1914
2025
  if (typeof content === "string") {
@@ -2001,16 +2112,27 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
2001
2112
  const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
2002
2113
  let ev = {};
2003
2114
  try {
2004
- ev = JSON.parse(readFileSync5(0, "utf8"));
2115
+ ev = JSON.parse(readFileSync6(0, "utf8"));
2005
2116
  } catch {
2006
2117
  return;
2007
2118
  }
2008
2119
  if (spec.accept && !spec.accept(ev)) return;
2009
- const { sessionId, transcriptPath, cwd: rawCwd, lastAssistantMessage } = spec.parse(ev);
2120
+ const parsed = spec.parse(ev);
2121
+ const { sessionId, cwd: rawCwd, lastAssistantMessage } = parsed;
2010
2122
  const cwd = rawCwd || process.cwd();
2123
+ let transcriptPath = parsed.transcriptPath;
2124
+ let readTranscript = spec.readTranscript;
2011
2125
  let cfg = loadConfig({ harness: spec.harness });
2012
2126
  setLogLevel(cfg.logLevel);
2013
2127
  if (cfg.disabled) return;
2128
+ if (spec.journal) {
2129
+ transcriptPath = journalPath(spec.harness, sessionId);
2130
+ readTranscript = readJournalTranscript;
2131
+ appendJournalTurn(transcriptPath, {
2132
+ role: "assistant",
2133
+ content: spec.journal.assistantText(ev)
2134
+ });
2135
+ }
2014
2136
  if (!transcriptPath) return;
2015
2137
  const sessionRoot = sessionRootDir(spec.harness, sessionId, cwd);
2016
2138
  const derived = deriveBankIdOrSkip(cfg, cwd, spec.harness, sessionRoot);
@@ -2036,7 +2158,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
2036
2158
  sessionId: sessionId || "no-session",
2037
2159
  transcriptPath,
2038
2160
  client,
2039
- readTranscript: spec.readTranscript,
2161
+ readTranscript,
2040
2162
  lastAssistantMessage,
2041
2163
  readLastMessage: spec.readLastMessage,
2042
2164
  retryUntil: hostDeadline,
@@ -2051,7 +2173,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
2051
2173
  }
2052
2174
 
2053
2175
  // src/core/session-start.ts
2054
- import { readFileSync as readFileSync8 } from "fs";
2176
+ import { readFileSync as readFileSync9 } from "fs";
2055
2177
 
2056
2178
  // src/core/git.ts
2057
2179
  import { execFileSync as execFileSync2 } from "child_process";
@@ -2064,29 +2186,29 @@ import { execFileSync as execFileSync3 } from "child_process";
2064
2186
  import { spawn as realSpawn3 } from "child_process";
2065
2187
  import { existsSync as existsSync3 } from "fs";
2066
2188
  import { homedir as homedir3 } from "os";
2067
- import { dirname as dirname7, join as join9 } from "path";
2189
+ import { dirname as dirname8, join as join10 } from "path";
2068
2190
  import { fileURLToPath as fileURLToPath3 } from "url";
2069
2191
 
2070
2192
  // src/core/auto-update.ts
2071
2193
  import { spawn as realSpawn4 } from "child_process";
2072
2194
  import {
2073
2195
  existsSync as existsSync4,
2074
- mkdirSync as mkdirSync3,
2075
- readFileSync as readFileSync6,
2196
+ mkdirSync as mkdirSync4,
2197
+ readFileSync as readFileSync7,
2076
2198
  realpathSync as realpathSync2,
2077
2199
  unlinkSync,
2078
2200
  writeFileSync as writeFileSync2
2079
2201
  } from "fs";
2080
- import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
2081
- import { dirname as dirname8, join as join10 } from "path";
2202
+ import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
2203
+ import { dirname as dirname9, join as join11 } from "path";
2082
2204
  import { fileURLToPath as fileURLToPath4 } from "url";
2083
2205
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2084
2206
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2085
2207
 
2086
2208
  // src/core/skill-sync.ts
2087
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
2209
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
2088
2210
  import { homedir as homedir5 } from "os";
2089
- import { dirname as dirname9, join as join11 } from "path";
2211
+ import { dirname as dirname10, join as join12 } from "path";
2090
2212
  import { fileURLToPath as fileURLToPath5 } from "url";
2091
2213
 
2092
2214
  // src/core/transcript-codex.ts
@@ -2219,19 +2341,19 @@ function readCopilotTranscript(path) {
2219
2341
  }
2220
2342
 
2221
2343
  // src/core/transcript-grok.ts
2222
- import { existsSync as existsSync6, readFileSync as readFileSync9, readdirSync } from "fs";
2344
+ import { existsSync as existsSync6, readFileSync as readFileSync10, readdirSync } from "fs";
2223
2345
  import { homedir as homedir6 } from "os";
2224
- import { join as join12 } from "path";
2346
+ import { join as join13 } from "path";
2225
2347
  var CHAT_HISTORY = "chat_history.jsonl";
2226
- function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join12(homedir6(), ".grok")) {
2227
- const sessionsDir = join12(grokHome, "sessions");
2228
- const direct = join12(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2348
+ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join13(homedir6(), ".grok")) {
2349
+ const sessionsDir = join13(grokHome, "sessions");
2350
+ const direct = join13(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
2229
2351
  if (existsSync6(direct)) return direct;
2230
2352
  try {
2231
2353
  for (const candidate of readdirSync(sessionsDir)) {
2232
- const directory = join12(sessionsDir, candidate);
2233
- if (readFileSync9(join12(directory, ".cwd"), "utf8").trim() === cwd) {
2234
- return join12(directory, sessionId, CHAT_HISTORY);
2354
+ const directory = join13(sessionsDir, candidate);
2355
+ if (readFileSync10(join13(directory, ".cwd"), "utf8").trim() === cwd) {
2356
+ return join13(directory, sessionId, CHAT_HISTORY);
2235
2357
  }
2236
2358
  }
2237
2359
  } catch {
@@ -2269,9 +2391,9 @@ function readGrokTranscript(path) {
2269
2391
  import { existsSync as existsSync7 } from "fs";
2270
2392
  import { createRequire } from "module";
2271
2393
  import { homedir as homedir7 } from "os";
2272
- import { join as join13 } from "path";
2394
+ import { join as join14 } from "path";
2273
2395
  function devinSessionDb(home = homedir7()) {
2274
- return join13(home, ".local", "share", "devin", "cli", "sessions.db");
2396
+ return join14(home, ".local", "share", "devin", "cli", "sessions.db");
2275
2397
  }
2276
2398
  function parseDevinMessages(nodes) {
2277
2399
  const messages = /* @__PURE__ */ new Map();
@@ -2580,6 +2702,51 @@ function readDroidTranscript(path) {
2580
2702
  return turns;
2581
2703
  }
2582
2704
 
2705
+ // src/core/transcript-zcode.ts
2706
+ import { readFileSync as readFileSync11 } from "fs";
2707
+ function messageText2(content) {
2708
+ if (typeof content === "string") return content.trim();
2709
+ if (!Array.isArray(content)) return "";
2710
+ return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
2711
+ }
2712
+ function readZcodeTranscript(path) {
2713
+ if (!path) return [];
2714
+ let body;
2715
+ try {
2716
+ body = readFileSync11(path, "utf8");
2717
+ } catch {
2718
+ return [];
2719
+ }
2720
+ const turns = [];
2721
+ for (const line of body.split("\n")) {
2722
+ const trimmed = line.trim();
2723
+ if (!trimmed) continue;
2724
+ let parsed;
2725
+ try {
2726
+ parsed = JSON.parse(trimmed);
2727
+ } catch {
2728
+ continue;
2729
+ }
2730
+ if (typeof parsed !== "object" || parsed === null) continue;
2731
+ const record = parsed;
2732
+ const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
2733
+ const role = typeof message?.role === "string" ? message.role : record.type;
2734
+ if (role !== "user" && role !== "assistant") continue;
2735
+ const content = stripInjectedMemory(messageText2(message?.content)).trim();
2736
+ if (!content) continue;
2737
+ turns.push({
2738
+ role,
2739
+ content,
2740
+ ...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
2741
+ });
2742
+ }
2743
+ return turns;
2744
+ }
2745
+ function zcodeAssistantText(path) {
2746
+ if (!path) return "";
2747
+ return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
2748
+ }
2749
+
2583
2750
  // src/harness/hook-lifecycle.ts
2584
2751
  var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
2585
2752
  var claudePrompt = {
@@ -2620,6 +2787,7 @@ var qwenPrompt = {
2620
2787
  sessionId: ev.session_id
2621
2788
  })
2622
2789
  };
2790
+ var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
2623
2791
  var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
2624
2792
  var antigravityPrompt = {
2625
2793
  harness: "antigravity-cli",
@@ -2962,6 +3130,56 @@ var HOOK_HARNESSES = {
2962
3130
  }),
2963
3131
  readTranscript: readDroidTranscript
2964
3132
  }
3133
+ },
3134
+ /**
3135
+ * ZCode (Z.ai's GLM coding agent) embeds the Claude Code agent runtime, so its hook PROTOCOL is
3136
+ * Claude's — `prompt`/`cwd` in, `hookSpecificOutput.additionalContext` + `systemMessage` out —
3137
+ * with `sessionId` accepted alongside `session_id`, which its Stop payload sends instead.
3138
+ *
3139
+ * What is not Claude's is the TRANSCRIPT, and that is the whole of the difference here. ZCode
3140
+ * keeps no durable session file: `Stop` carries the reply in `responseText` plus a temp,
3141
+ * assistant-only transcript it deletes as soon as the hook returns, and no user prompt at all.
3142
+ * So this is the one harness that retains from the plugin's own journal (core/turn-journal.ts) —
3143
+ * the prompt hook appends the user turn, `journal.assistantText` closes it with the reply — and
3144
+ * everything downstream (cursor, append, stamping) sees the same full conversation as any host
3145
+ * transcript.
3146
+ */
3147
+ zcode: {
3148
+ configStyle: "process",
3149
+ // ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
3150
+ // prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
3151
+ timeoutUnit: "milliseconds",
3152
+ install: {
3153
+ sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
3154
+ prompt: { event: "UserPromptSubmit", entry: "zcode-hook.js", timeout: 3e4 },
3155
+ stop: { event: "Stop", entry: "zcode-stop-hook.js", timeout: 6e4 }
3156
+ },
3157
+ sessionStart: {
3158
+ ...standardSessionStart("zcode"),
3159
+ parse: (ev) => ({ cwd: ev.cwd, sessionId: zcodeSessionId(ev) })
3160
+ },
3161
+ prompt: {
3162
+ ...claudePrompt,
3163
+ harness: "zcode",
3164
+ journalPrompt: true,
3165
+ parse: (ev) => ({
3166
+ prompt: ev.prompt ?? ev.user_prompt,
3167
+ cwd: ev.cwd,
3168
+ sessionId: zcodeSessionId(ev)
3169
+ })
3170
+ },
3171
+ retain: {
3172
+ hostTimeoutSec: 60,
3173
+ harness: "zcode",
3174
+ // No transcriptPath: the journal supplies it (see `journal` below).
3175
+ parse: (ev) => ({ sessionId: zcodeSessionId(ev), cwd: ev.cwd }),
3176
+ journal: {
3177
+ // `responseText` is the full reply and is what ZCode sends in practice. The ephemeral
3178
+ // transcript is the fallback when it is absent, and `responsePreview` — which is
3179
+ // TRUNCATED — is the last resort, preferred only over losing the turn entirely.
3180
+ assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
3181
+ }
3182
+ }
2965
3183
  }
2966
3184
  };
2967
3185
  var runHarnessRetain = (harness) => runRetainHook(HOOK_HARNESSES[harness].retain);