@vectorize-io/hindsight-coding-agents 0.5.4 → 0.6.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 +24 -7
  2. package/dist/antigravity-hook.js +205 -81
  3. package/dist/antigravity-statusline.js +32 -22
  4. package/dist/antigravity-stop-hook.js +216 -79
  5. package/dist/claude-hook.js +205 -81
  6. package/dist/claude-sessionstart-hook.js +167 -105
  7. package/dist/claude-stop-hook.js +216 -79
  8. package/dist/cline.js +279 -86
  9. package/dist/codex-hook.js +205 -81
  10. package/dist/codex-sessionstart-hook.js +167 -105
  11. package/dist/codex-stop-hook.js +216 -79
  12. package/dist/copilot-hook.js +205 -81
  13. package/dist/copilot-sessionstart-hook.js +167 -105
  14. package/dist/copilot-stop-hook.js +216 -79
  15. package/dist/cursor-hook.js +205 -81
  16. package/dist/cursor-sessionstart-hook.js +167 -105
  17. package/dist/cursor-stop-hook.js +216 -79
  18. package/dist/daemon-start.js +28 -18
  19. package/dist/dcode-hook.js +205 -81
  20. package/dist/dcode-sessionstart-hook.js +167 -105
  21. package/dist/dcode-stop-hook.js +216 -79
  22. package/dist/deepen.js +98 -40
  23. package/dist/devin-hook.js +205 -81
  24. package/dist/devin-sessionstart-hook.js +167 -105
  25. package/dist/devin-stop-hook.js +216 -79
  26. package/dist/droid-hook.js +205 -81
  27. package/dist/droid-sessionstart-hook.js +167 -105
  28. package/dist/droid-stop-hook.js +216 -79
  29. package/dist/dsh.js +277 -85
  30. package/dist/grok-hook.js +205 -81
  31. package/dist/grok-sessionstart-hook.js +167 -105
  32. package/dist/grok-stop-hook.js +216 -79
  33. package/dist/hindsight-seed.js +32 -22
  34. package/dist/index.js +280 -88
  35. package/dist/installer.js +308 -214
  36. package/dist/kilo.js +280 -88
  37. package/dist/mcp-server.js +97 -39
  38. package/dist/opencode2.js +279 -87
  39. package/dist/pi.js +279 -87
  40. package/dist/prime-agent.js +279 -87
  41. package/dist/qwen-hook.js +205 -81
  42. package/dist/qwen-sessionstart-hook.js +167 -105
  43. package/dist/qwen-stop-hook.js +216 -79
  44. package/dist/status.js +94 -36
  45. package/dist/zcode-hook.js +205 -81
  46. package/dist/zcode-sessionstart-hook.js +167 -105
  47. package/dist/zcode-stop-hook.js +216 -79
  48. package/package.json +1 -1
  49. package/plugin.json +1 -1
  50. package/skill/SKILL.md +24 -7
package/dist/pi.js CHANGED
@@ -14520,8 +14520,8 @@ config(en_default());
14520
14520
 
14521
14521
  // src/core/config.ts
14522
14522
  import { readFileSync as readFileSync2 } from "fs";
14523
- import { homedir as homedir2 } from "os";
14524
- import { join as join6 } from "path";
14523
+ import { homedir as homedir3 } from "os";
14524
+ import { join as join7 } from "path";
14525
14525
 
14526
14526
  // src/core/seed.ts
14527
14527
  import { spawn as realSpawn } from "child_process";
@@ -14558,16 +14558,28 @@ function startBackgroundSeed(repoDir, opts = {}) {
14558
14558
 
14559
14559
  // src/core/bank.ts
14560
14560
  import { existsSync } from "fs";
14561
- import { homedir } from "os";
14562
- import { basename, dirname as dirname4, join as join4, normalize, sep } from "path";
14561
+ import { homedir as homedir2 } from "os";
14562
+ import { basename, dirname as dirname4, join as join5, normalize, sep } from "path";
14563
14563
 
14564
14564
  // src/core/diag.ts
14565
- import { appendFileSync as appendFileSync2 } from "fs";
14565
+ import { join as join3 } from "path";
14566
14566
 
14567
14567
  // src/core/log.ts
14568
- import { appendFileSync, mkdirSync } from "fs";
14569
- import { tmpdir } from "os";
14568
+ import { appendFileSync, mkdirSync, renameSync, statSync } from "fs";
14569
+ import { homedir } from "os";
14570
14570
  import { dirname as dirname2, join as join2 } from "path";
14571
+ function logsDir() {
14572
+ return join2(homedir(), ".hindsight", "coding-agents-logs");
14573
+ }
14574
+ var LOG_MAX_BYTES = 10 * 1024 * 1024;
14575
+ function appendLogLine(file2, text) {
14576
+ mkdirSync(dirname2(file2), { recursive: true, mode: 448 });
14577
+ try {
14578
+ if (statSync(file2).size >= LOG_MAX_BYTES) renameSync(file2, `${file2}.1`);
14579
+ } catch {
14580
+ }
14581
+ appendFileSync(file2, text, { mode: 384 });
14582
+ }
14571
14583
  var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
14572
14584
  var current = ["debug", "info", "warn", "error"].find(
14573
14585
  (l) => l === process.env.HINDSIGHT_LOG_LEVEL
@@ -14576,15 +14588,13 @@ function setLogLevel(level) {
14576
14588
  if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
14577
14589
  }
14578
14590
  function logFilePath() {
14579
- return process.env.HINDSIGHT_LOG_FILE || join2(tmpdir(), "hindsight-coding-agent", "plugin.log");
14591
+ return process.env.HINDSIGHT_LOG_FILE || join2(logsDir(), "plugin.log");
14580
14592
  }
14581
14593
  function write(level, scope, msg, extra) {
14582
14594
  if (WEIGHT[level] < WEIGHT[current]) return;
14583
14595
  try {
14584
- const file2 = logFilePath();
14585
- mkdirSync(dirname2(file2), { recursive: true });
14586
- appendFileSync(
14587
- file2,
14596
+ appendLogLine(
14597
+ logFilePath(),
14588
14598
  `${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
14589
14599
  );
14590
14600
  } catch {
@@ -14613,12 +14623,12 @@ function describeError(value, maxChars = 200) {
14613
14623
 
14614
14624
  // src/core/diag.ts
14615
14625
  function diagFilePath() {
14616
- return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
14626
+ return process.env.HINDSIGHT_DIAG_FILE || join3(logsDir(), "diag.jsonl");
14617
14627
  }
14618
14628
  function diag(harness, event, extra = {}) {
14619
14629
  log.debug(harness, `diag:${event}`, extra);
14620
14630
  try {
14621
- appendFileSync2(
14631
+ appendLogLine(
14622
14632
  diagFilePath(),
14623
14633
  JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
14624
14634
  );
@@ -14628,7 +14638,7 @@ function diag(harness, event, extra = {}) {
14628
14638
 
14629
14639
  // src/core/git-layout.ts
14630
14640
  import { lstatSync, readFileSync, realpathSync } from "fs";
14631
- import { dirname as dirname3, isAbsolute, join as join3, resolve } from "path";
14641
+ import { dirname as dirname3, isAbsolute, join as join4, resolve } from "path";
14632
14642
  var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
14633
14643
  var ATTEMPTS = 3;
14634
14644
  var BACKOFF_MS = 20;
@@ -14664,16 +14674,16 @@ function gitDirFromPointer(text, holder) {
14664
14674
  return isAbsolute(target) ? target : resolve(holder, target);
14665
14675
  }
14666
14676
  function commonDirOf(gitDir) {
14667
- const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
14677
+ const pointer = entryKind(join4(gitDir, "commondir")) === "file" ? readTextOrNull(join4(gitDir, "commondir"))?.trim() : null;
14668
14678
  if (!pointer) return gitDir;
14669
14679
  return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
14670
14680
  }
14671
14681
  function isBare(commonDir) {
14672
- const config2 = readTextOrNull(join3(commonDir, "config"));
14682
+ const config2 = readTextOrNull(join4(commonDir, "config"));
14673
14683
  return config2 !== null && /^\s*bare\s*=\s*true\s*$/im.test(config2);
14674
14684
  }
14675
14685
  function looksLikeBareRepository(directory) {
14676
- return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
14686
+ return entryKind(join4(directory, "HEAD")) === "file" && entryKind(join4(directory, "objects")) === "dir" && entryKind(join4(directory, "refs")) === "dir";
14677
14687
  }
14678
14688
  function canonical(path) {
14679
14689
  try {
@@ -14690,7 +14700,7 @@ function resolved(commonDir) {
14690
14700
  function probeOnce(directory) {
14691
14701
  let current2 = resolve(directory);
14692
14702
  for (; ; ) {
14693
- const dotGit = join3(current2, ".git");
14703
+ const dotGit = join4(current2, ".git");
14694
14704
  const kind = entryKind(dotGit);
14695
14705
  if (kind === "dir") {
14696
14706
  const layout = resolved(commonDirOf(dotGit));
@@ -14804,7 +14814,7 @@ function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
14804
14814
  return dirName(sessionRoot || directory);
14805
14815
  }
14806
14816
  function configuredDir(dir) {
14807
- const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir(), dir.slice(1)) : dir;
14817
+ const expanded = dir === "~" || dir.startsWith("~/") ? join5(homedir2(), dir.slice(1)) : dir;
14808
14818
  return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
14809
14819
  }
14810
14820
  function isWithin(directory, configured) {
@@ -15108,7 +15118,7 @@ function codingBankManifest(overrides) {
15108
15118
 
15109
15119
  // src/core/util.ts
15110
15120
  import { accessSync, constants } from "fs";
15111
- import { delimiter, join as join5 } from "path";
15121
+ import { delimiter, join as join6 } from "path";
15112
15122
  function binOnPath(bin) {
15113
15123
  try {
15114
15124
  if (bin.includes("/")) {
@@ -15118,7 +15128,7 @@ function binOnPath(bin) {
15118
15128
  for (const dir of (process.env.PATH || "").split(delimiter)) {
15119
15129
  if (!dir) continue;
15120
15130
  try {
15121
- accessSync(join5(dir, bin), constants.X_OK);
15131
+ accessSync(join6(dir, bin), constants.X_OK);
15122
15132
  return true;
15123
15133
  } catch {
15124
15134
  }
@@ -15190,6 +15200,22 @@ var KnowledgePagesUnavailableError = class extends Error {
15190
15200
  }
15191
15201
  };
15192
15202
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
15203
+ var ReflectError = class extends Error {
15204
+ constructor(message, status, timedOut, options) {
15205
+ super(message, options);
15206
+ this.status = status;
15207
+ this.timedOut = timedOut;
15208
+ this.name = "ReflectError";
15209
+ }
15210
+ status;
15211
+ timedOut;
15212
+ /** A timeout or a 5xx means reflect's synthesis (the slow LLM path) broke, while the cheap
15213
+ * retrieval endpoints may still answer — worth falling back. A 4xx will fail the same way on
15214
+ * every endpoint (auth, missing bank), so it is not. */
15215
+ get fallbackEligible() {
15216
+ return this.timedOut || this.status !== void 0 && this.status >= 500;
15217
+ }
15218
+ };
15193
15219
  var DEFAULT_MAX_PARALLEL_RETAINS = 10;
15194
15220
  var POLL_CYCLE_MS = 5e3;
15195
15221
  var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
@@ -15273,11 +15299,11 @@ var HindsightClient = class {
15273
15299
  return `${this.apiUrl}/v1/default/banks/${encodeURIComponent(this.bank)}${suffix}`;
15274
15300
  }
15275
15301
  /** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
15276
- async req(method, url2, body, tolerate = []) {
15302
+ async req(method, url2, body, tolerate = [], timeoutMs = 15e3) {
15277
15303
  const r = await this.fetchWithAuth(url2, {
15278
15304
  method,
15279
15305
  body: body ? JSON.stringify(body) : void 0,
15280
- signal: AbortSignal.timeout(15e3)
15306
+ signal: AbortSignal.timeout(timeoutMs)
15281
15307
  });
15282
15308
  if (r.status === 429 && !tolerate.includes(429))
15283
15309
  throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
@@ -15470,7 +15496,7 @@ var HindsightClient = class {
15470
15496
  /**
15471
15497
  * Reflect: synthesized, root-cause answer over the bank. Bounded so a slow server never hangs a
15472
15498
  * caller — but `timeoutMs` is REQUIRED, deliberately: the right deadline differs by an order of
15473
- * magnitude between the automatic hook (25s, to fit the host's window) and the agent-invoked
15499
+ * magnitude between the automatic hook (20s, to fit the host's window) and the agent-invoked
15474
15500
  * tool (minutes, on a populated bank). This used to default to 120s, which silently overrode the
15475
15501
  * tool's configured window and aborted every high-budget synthesis mid-flight (#3590).
15476
15502
  */
@@ -15484,19 +15510,45 @@ var HindsightClient = class {
15484
15510
  signal: ctrl.signal
15485
15511
  });
15486
15512
  if (!resp.ok)
15487
- throw new Error(
15488
- `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
15513
+ throw new ReflectError(
15514
+ `reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`,
15515
+ resp.status,
15516
+ false
15489
15517
  );
15490
15518
  const data = await resp.json();
15491
15519
  return (data.text || "").trim();
15492
15520
  } catch (e) {
15493
15521
  if (ctrl.signal.aborted)
15494
- throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
15522
+ throw new ReflectError(`reflect timed out after ${opts.timeoutMs}ms`, void 0, true, {
15523
+ cause: e
15524
+ });
15495
15525
  throw e;
15496
15526
  } finally {
15497
15527
  clearTimeout(timer);
15498
15528
  }
15499
15529
  }
15530
+ /**
15531
+ * Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
15532
+ * when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
15533
+ */
15534
+ async recallObservations(query, opts) {
15535
+ const r = await this.req(
15536
+ "POST",
15537
+ this.bankUrl("/memories/recall"),
15538
+ {
15539
+ query,
15540
+ types: ["observation"],
15541
+ budget: "low",
15542
+ max_tokens: opts.maxTokens,
15543
+ include: { entities: null }
15544
+ },
15545
+ [],
15546
+ opts.timeoutMs
15547
+ );
15548
+ if (r.status === 404) return [];
15549
+ const j = await r.json();
15550
+ return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
15551
+ }
15500
15552
  /**
15501
15553
  * The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
15502
15554
  * queries and staleness but NOT synthesized content, so it is cheap enough to poll.
@@ -15561,10 +15613,16 @@ var HindsightClient = class {
15561
15613
  /** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
15562
15614
  * Returns page-level hits with a relevance snippet — the real search behind
15563
15615
  * hindsight_search_knowledge_pages. */
15564
- async searchKnowledgePages(query, limit = 3) {
15616
+ async searchKnowledgePages(query, limit = 3, timeoutMs) {
15565
15617
  if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
15566
15618
  const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
15567
- const r = await this.req("GET", this.bankUrl(`/knowledge-base/search${q}`));
15619
+ const r = await this.req(
15620
+ "GET",
15621
+ this.bankUrl(`/knowledge-base/search${q}`),
15622
+ void 0,
15623
+ [],
15624
+ timeoutMs
15625
+ );
15568
15626
  const j = await r.json();
15569
15627
  return (j.results ?? []).map((x) => ({
15570
15628
  id: x.id,
@@ -15751,7 +15809,7 @@ var HindsightClient = class {
15751
15809
  };
15752
15810
 
15753
15811
  // src/core/config.ts
15754
- var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
15812
+ var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join7(homedir3(), ".hindsight", "coding-agent.json");
15755
15813
  var DEFAULT_DAEMON_PORT = 9077;
15756
15814
  var DEFAULT_DAEMON_PROFILE = "coding-agent";
15757
15815
  function resolvePageTrigger(raw) {
@@ -16045,20 +16103,20 @@ import {
16045
16103
  unlinkSync,
16046
16104
  writeFileSync
16047
16105
  } from "fs";
16048
- import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
16049
- import { dirname as dirname5, join as join7 } from "path";
16106
+ import { homedir as homedir4, tmpdir } from "os";
16107
+ import { dirname as dirname5, join as join8 } from "path";
16050
16108
  import { fileURLToPath as fileURLToPath2 } from "url";
16051
16109
  var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
16052
16110
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
16053
16111
  var FETCH_TIMEOUT_MS = 5e3;
16054
16112
  function stateFile(runtimeDir) {
16055
- return join7(runtimeDir, ".update-check.json");
16113
+ return join8(runtimeDir, ".update-check.json");
16056
16114
  }
16057
16115
  function packageRoot() {
16058
- return join7(dirname5(fileURLToPath2(import.meta.url)), "..");
16116
+ return join8(dirname5(fileURLToPath2(import.meta.url)), "..");
16059
16117
  }
16060
16118
  function stagedRuntimeDir() {
16061
- return join7(homedir3(), ".hindsight", "coding-agents");
16119
+ return join8(homedir4(), ".hindsight", "coding-agents");
16062
16120
  }
16063
16121
  function sameDir(a, b) {
16064
16122
  try {
@@ -16069,7 +16127,7 @@ function sameDir(a, b) {
16069
16127
  }
16070
16128
  function stagedVersion(pkgRoot) {
16071
16129
  try {
16072
- const pkg = JSON.parse(readFileSync3(join7(pkgRoot, "package.json"), "utf8"));
16130
+ const pkg = JSON.parse(readFileSync3(join8(pkgRoot, "package.json"), "utf8"));
16073
16131
  return typeof pkg.version === "string" ? pkg.version : "";
16074
16132
  } catch {
16075
16133
  return "";
@@ -16103,7 +16161,7 @@ function dueForCheck(file2, now) {
16103
16161
  var ORIGIN_FILE = ".install-origin.json";
16104
16162
  function selfUpdatable(runtimeDir) {
16105
16163
  try {
16106
- const origin = JSON.parse(readFileSync3(join7(runtimeDir, ORIGIN_FILE), "utf8"));
16164
+ const origin = JSON.parse(readFileSync3(join8(runtimeDir, ORIGIN_FILE), "utf8"));
16107
16165
  if (typeof origin.source !== "string" || !origin.source) return false;
16108
16166
  return origin.source.split(/[\\/]/).includes("_npx");
16109
16167
  } catch {
@@ -16112,7 +16170,7 @@ function selfUpdatable(runtimeDir) {
16112
16170
  }
16113
16171
  var LOCK_STALE_MS = 10 * 60 * 1e3;
16114
16172
  function lockFile() {
16115
- return join7(tmpdir2(), "hindsight-coding-agent", "auto-update.lock");
16173
+ return join8(tmpdir(), "hindsight-coding-agent", "auto-update.lock");
16116
16174
  }
16117
16175
  function acquireUpdateLock(file2, now) {
16118
16176
  try {
@@ -16229,7 +16287,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
16229
16287
 
16230
16288
  // src/core/daemon.ts
16231
16289
  import { execFileSync, spawn as realSpawn3 } from "child_process";
16232
- import { dirname as dirname6, join as join8 } from "path";
16290
+ import { dirname as dirname6, join as join9 } from "path";
16233
16291
  import { fileURLToPath as fileURLToPath3 } from "url";
16234
16292
  var DAEMON_WAIT_SESSION_START_MS = 12e3;
16235
16293
  var DAEMON_WAIT_RETAIN_MS = 4e4;
@@ -16304,7 +16362,7 @@ function onPath(bin) {
16304
16362
  }
16305
16363
  function startDaemonDetached(cfg, harness, spawnFn = realSpawn3) {
16306
16364
  try {
16307
- const starter = join8(dirname6(fileURLToPath3(import.meta.url)), "daemon-start.js");
16365
+ const starter = join9(dirname6(fileURLToPath3(import.meta.url)), "daemon-start.js");
16308
16366
  const child = spawnFn("node", [starter, "--harness", harness], {
16309
16367
  detached: true,
16310
16368
  stdio: "ignore",
@@ -16359,8 +16417,8 @@ function preflightDaemon(cfg, harness) {
16359
16417
 
16360
16418
  // src/core/knowledge-tools.ts
16361
16419
  import { existsSync as existsSync4 } from "fs";
16362
- import { homedir as homedir5 } from "os";
16363
- import { join as join11 } from "path";
16420
+ import { homedir as homedir6 } from "os";
16421
+ import { join as join12 } from "path";
16364
16422
 
16365
16423
  // src/core/status.ts
16366
16424
  import { execFileSync as execFileSync3 } from "child_process";
@@ -16449,8 +16507,8 @@ ${toolGuide(opts)}
16449
16507
  import { spawn as realSpawn5 } from "child_process";
16450
16508
  import { createHash as createHash2 } from "crypto";
16451
16509
  import { existsSync as existsSync3 } from "fs";
16452
- import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
16453
- import { dirname as dirname7, join as join10 } from "path";
16510
+ import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
16511
+ import { dirname as dirname7, join as join11 } from "path";
16454
16512
  import { fileURLToPath as fileURLToPath4 } from "url";
16455
16513
 
16456
16514
  // src/core/survey-lease.ts
@@ -16460,20 +16518,20 @@ import {
16460
16518
  mkdirSync as mkdirSync3,
16461
16519
  mkdtempSync,
16462
16520
  readdirSync,
16463
- renameSync,
16521
+ renameSync as renameSync2,
16464
16522
  rmdirSync,
16465
16523
  rmSync,
16466
- statSync,
16524
+ statSync as statSync2,
16467
16525
  unlinkSync as unlinkSync2,
16468
16526
  utimesSync,
16469
16527
  writeFileSync as writeFileSync2
16470
16528
  } from "fs";
16471
- import { join as join9 } from "path";
16529
+ import { join as join10 } from "path";
16472
16530
  var LEASE_STALE_MS = 3e4;
16473
16531
  var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
16474
16532
  function tryRename(from, to) {
16475
16533
  try {
16476
- renameSync(from, to);
16534
+ renameSync2(from, to);
16477
16535
  return true;
16478
16536
  } catch {
16479
16537
  return false;
@@ -16481,7 +16539,7 @@ function tryRename(from, to) {
16481
16539
  }
16482
16540
  function releaseLease(lease) {
16483
16541
  try {
16484
- unlinkSync2(join9(lease.directory, lease.owner));
16542
+ unlinkSync2(join10(lease.directory, lease.owner));
16485
16543
  } catch {
16486
16544
  return;
16487
16545
  }
@@ -16500,7 +16558,7 @@ function reclaimIfStale(directory, staleMs) {
16500
16558
  return true;
16501
16559
  }
16502
16560
  if (owners.length !== 1) return false;
16503
- const age = Date.now() - statSync(join9(directory, owners[0])).mtimeMs;
16561
+ const age = Date.now() - statSync2(join10(directory, owners[0])).mtimeMs;
16504
16562
  if (Math.abs(age) <= staleMs) return false;
16505
16563
  releaseLease({ directory, owner: owners[0] });
16506
16564
  return true;
@@ -16509,10 +16567,10 @@ function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
16509
16567
  let staging;
16510
16568
  try {
16511
16569
  mkdirSync3(root, { recursive: true, mode: 448 });
16512
- staging = mkdtempSync(join9(root, "claim-"));
16570
+ staging = mkdtempSync(join10(root, "claim-"));
16513
16571
  const owner = randomUUID();
16514
- writeFileSync2(join9(staging, owner), "", { flag: "wx", mode: 384 });
16515
- const directory = join9(root, `survey-${key}.lock`);
16572
+ writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
16573
+ const directory = join10(root, `survey-${key}.lock`);
16516
16574
  if (!tryRename(staging, directory)) {
16517
16575
  if (!reclaimIfStale(directory, staleMs)) return void 0;
16518
16576
  if (!tryRename(staging, directory)) return void 0;
@@ -16535,7 +16593,7 @@ var SURVEY_DOC_IDS = [
16535
16593
  function resolveClaudeBin(explicit) {
16536
16594
  if (explicit) return explicit;
16537
16595
  if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
16538
- const nativeInstallPath = join10(homedir4(), ".claude", "local", "claude");
16596
+ const nativeInstallPath = join11(homedir5(), ".claude", "local", "claude");
16539
16597
  try {
16540
16598
  if (existsSync3(nativeInstallPath)) return nativeInstallPath;
16541
16599
  } catch {
@@ -16653,7 +16711,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
16653
16711
  try {
16654
16712
  const spawnFn = opts.spawn ?? realSpawn5;
16655
16713
  const exists = opts.exists ?? binOnPath;
16656
- const mcpServerPath = opts.mcpServerPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
16714
+ const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
16657
16715
  const preferred = opts.harness ?? "claude-code";
16658
16716
  const order = [
16659
16717
  preferred,
@@ -16677,7 +16735,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
16677
16735
  if (cfg.disabled) return false;
16678
16736
  const key = createHash2("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
16679
16737
  const lease = acquireLease(
16680
- opts.lease?.dir ?? join10(tmpdir3(), "hindsight-coding-agent", "surveys"),
16738
+ opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys"),
16681
16739
  key,
16682
16740
  opts.lease?.staleMs ?? LEASE_STALE_MS
16683
16741
  );
@@ -16688,7 +16746,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
16688
16746
  args: plan.args,
16689
16747
  ...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
16690
16748
  };
16691
- const supervisorPath = opts.supervisorPath ?? join10(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
16749
+ const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
16692
16750
  return await new Promise((resolve3) => {
16693
16751
  try {
16694
16752
  const child = spawnFn("node", [supervisorPath], {
@@ -16830,7 +16888,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
16830
16888
  inputSchema: {},
16831
16889
  annotations: READ_ONLY_ANNOTATIONS,
16832
16890
  handler: async (_args) => {
16833
- const configPath = process.env.HINDSIGHT_CONFIG || join11(homedir5(), ".hindsight", "coding-agent.json");
16891
+ const configPath = process.env.HINDSIGHT_CONFIG || join12(homedir6(), ".hindsight", "coding-agent.json");
16834
16892
  const harness = opts.harness ?? "unknown";
16835
16893
  const cfg = applyBankConfig(
16836
16894
  loadConfig({ harness: opts.harness }),
@@ -16860,7 +16918,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
16860
16918
  config_override: Boolean(process.env.HINDSIGHT_CONFIG),
16861
16919
  hooks_disabled: Boolean(process.env.HINDSIGHT_DISABLE_HOOKS),
16862
16920
  log_level: process.env.HINDSIGHT_LOG_LEVEL ?? null,
16863
- diagnostics_file: process.env.HINDSIGHT_DIAG_FILE ?? "/tmp/hindsight-plugin.log",
16921
+ diagnostics_file: diagFilePath(),
16864
16922
  channel_id_configured: Boolean(process.env.HINDSIGHT_CHANNEL_ID),
16865
16923
  user_id_configured: Boolean(process.env.HINDSIGHT_USER_ID)
16866
16924
  }
@@ -17161,6 +17219,64 @@ ${content}`);
17161
17219
  }
17162
17220
  }
17163
17221
 
17222
+ // src/core/usage.ts
17223
+ import { readFileSync as readFileSync4 } from "fs";
17224
+ import { join as join13 } from "path";
17225
+ function usageFilePath() {
17226
+ return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
17227
+ }
17228
+ var HINDSIGHT_TOOL_RE = /hindsight_(?:[a-z]+_)*[a-z]+$/;
17229
+ var CREDIT_RE = /from hindsight memory/i;
17230
+ var ASSISTANT_ROLES = /* @__PURE__ */ new Set(["assistant", "model"]);
17231
+ function summarizeTurns(turns) {
17232
+ const out = [];
17233
+ for (const t of turns) {
17234
+ if (t.role === "user") {
17235
+ out.push({ turn: out.length + 1, calls: [], credited: false });
17236
+ continue;
17237
+ }
17238
+ const current2 = out.at(-1);
17239
+ if (!current2) continue;
17240
+ if (t.role === "action") {
17241
+ const tool = t.content.split(" ", 1)[0].match(HINDSIGHT_TOOL_RE)?.[0];
17242
+ if (tool) current2.calls.push(tool);
17243
+ } else if (ASSISTANT_ROLES.has(t.role) && CREDIT_RE.test(t.content)) {
17244
+ current2.credited = true;
17245
+ }
17246
+ }
17247
+ return out;
17248
+ }
17249
+ function memoryUsageCursorStore() {
17250
+ const recorded = /* @__PURE__ */ new Map();
17251
+ return {
17252
+ read: (sessionId) => recorded.get(sessionId),
17253
+ write: (sessionId, turns) => void recorded.set(sessionId, turns)
17254
+ };
17255
+ }
17256
+ function recordUsage(args) {
17257
+ const summary = summarizeTurns(args.turns);
17258
+ const finished = args.lastTurnComplete ? summary : summary.slice(0, -1);
17259
+ const from = args.cursors.read(args.sessionId) ?? 0;
17260
+ if (finished.length <= from) return;
17261
+ const ts = (/* @__PURE__ */ new Date()).toISOString();
17262
+ const lines = finished.slice(from).map(
17263
+ (u) => JSON.stringify({
17264
+ ts,
17265
+ harness: args.harness,
17266
+ session: args.sessionId,
17267
+ bank: args.bankId,
17268
+ turn: u.turn,
17269
+ calls: u.calls,
17270
+ credited: u.credited
17271
+ }) + "\n"
17272
+ ).join("");
17273
+ try {
17274
+ appendLogLine(usageFilePath(), lines);
17275
+ args.cursors.write(args.sessionId, finished.length);
17276
+ } catch {
17277
+ }
17278
+ }
17279
+
17164
17280
  // src/core/retain-stamp.ts
17165
17281
  import { basename as basename2 } from "path";
17166
17282
  var RESERVED_TAG_PREFIX = /^(source|harness):/;
@@ -17209,12 +17325,12 @@ function buildRetainStamp(cfg, ctx) {
17209
17325
  }
17210
17326
 
17211
17327
  // src/core/session-start.ts
17212
- import { readFileSync as readFileSync7 } from "fs";
17328
+ import { readFileSync as readFileSync8 } from "fs";
17213
17329
 
17214
17330
  // src/core/skill-sync.ts
17215
- import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
17216
- import { homedir as homedir6 } from "os";
17217
- import { dirname as dirname8, join as join12 } from "path";
17331
+ import { cpSync, existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
17332
+ import { homedir as homedir7 } from "os";
17333
+ import { dirname as dirname8, join as join14 } from "path";
17218
17334
  import { fileURLToPath as fileURLToPath5 } from "url";
17219
17335
 
17220
17336
  // src/core/brand.ts
@@ -17232,15 +17348,15 @@ function brandWord() {
17232
17348
  }
17233
17349
 
17234
17350
  // src/core/legacy.ts
17235
- import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
17236
- import { homedir as homedir7 } from "os";
17237
- import { join as join13, relative, isAbsolute as isAbsolute2 } from "path";
17351
+ import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
17352
+ import { homedir as homedir8 } from "os";
17353
+ import { join as join15, relative, isAbsolute as isAbsolute2 } from "path";
17238
17354
  var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
17239
- function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")) {
17240
- const registry2 = readJson(join13(claudeDir, "plugins", "installed_plugins.json"));
17355
+ function detectLegacyClaudePlugin(cwd, claudeDir = join15(homedir8(), ".claude")) {
17356
+ const registry2 = readJson(join15(claudeDir, "plugins", "installed_plugins.json"));
17241
17357
  const plugins = registry2?.plugins;
17242
17358
  if (!plugins || typeof plugins !== "object") return void 0;
17243
- const enabled = readJson(join13(claudeDir, "settings.json"))?.enabledPlugins;
17359
+ const enabled = readJson(join15(claudeDir, "settings.json"))?.enabledPlugins;
17244
17360
  for (const [key, raw] of Object.entries(plugins)) {
17245
17361
  if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
17246
17362
  if (enabled && enabled[key] === false) continue;
@@ -17257,7 +17373,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join13(homedir7(), ".claude")
17257
17373
  }
17258
17374
  function readJson(path) {
17259
17375
  try {
17260
- const parsed = JSON.parse(readFileSync5(path, "utf8"));
17376
+ const parsed = JSON.parse(readFileSync6(path, "utf8"));
17261
17377
  return parsed && typeof parsed === "object" ? parsed : void 0;
17262
17378
  } catch {
17263
17379
  return void 0;
@@ -17269,15 +17385,15 @@ function legacyClaudePluginWarning(key) {
17269
17385
  }
17270
17386
 
17271
17387
  // src/core/session-cache.ts
17272
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
17273
- import { tmpdir as tmpdir4 } from "os";
17274
- import { dirname as dirname9, join as join14 } from "path";
17388
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
17389
+ import { tmpdir as tmpdir3 } from "os";
17390
+ import { dirname as dirname9, join as join16 } from "path";
17275
17391
  function sessionCacheFile(harness, sessionId) {
17276
- return join14(tmpdir4(), `hindsight-${harness}`, `${sessionId}.json`);
17392
+ return join16(tmpdir3(), `hindsight-${harness}`, `${sessionId}.json`);
17277
17393
  }
17278
17394
  function readSessionCache(cacheFile) {
17279
17395
  try {
17280
- return JSON.parse(readFileSync6(cacheFile, "utf8"));
17396
+ return JSON.parse(readFileSync7(cacheFile, "utf8"));
17281
17397
  } catch {
17282
17398
  return {};
17283
17399
  }
@@ -17287,7 +17403,7 @@ function writeFileAtomic(path, body) {
17287
17403
  const tmp = `${path}.${process.pid}.tmp`;
17288
17404
  try {
17289
17405
  writeFileSync3(tmp, body);
17290
- renameSync2(tmp, path);
17406
+ renameSync3(tmp, path);
17291
17407
  } catch (e) {
17292
17408
  try {
17293
17409
  rmSync2(tmp, { force: true });
@@ -17463,7 +17579,7 @@ ${legacyClaudePluginWarning(legacyPlugin)}`;
17463
17579
  }
17464
17580
 
17465
17581
  // src/core/hook.ts
17466
- import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
17582
+ import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
17467
17583
 
17468
17584
  // src/core/inject.ts
17469
17585
  function buildReflectQuery(prompt) {
@@ -17481,6 +17597,15 @@ Report what this bank's history genuinely bears on that goal. Rendering rules, s
17481
17597
  - Do not connect unrelated episodes into one narrative; if two facts are not explicitly linked in the record, report them separately or leave the weaker one out.
17482
17598
  - If the bank holds nothing that bears on the goal, say so in one line.`;
17483
17599
  }
17600
+ function formatPageFallback(hits) {
17601
+ return "(Hindsight's synthesis was unavailable this turn; these knowledge pages matched the goal by search. Read one with hindsight_read_knowledge_page(<id>) if it looks relevant.)\n" + hits.map((h) => {
17602
+ const snippet = h.snippet.replace(/\s+/g, " ").trim();
17603
+ return `- ${h.name} (${h.id})${snippet ? `: ${snippet}` : ""}`;
17604
+ }).join("\n");
17605
+ }
17606
+ function formatObservationFallback(observations) {
17607
+ return "(Hindsight's synthesis was unavailable this turn; these consolidated observations were recalled from the bank for the goal, unsynthesized.)\n" + observations.map((o) => `- ${o.replace(/\s+/g, " ").trim()}`).join("\n");
17608
+ }
17484
17609
  function buildSystemInjection(memory) {
17485
17610
  return `<hindsight_memory>
17486
17611
  Automatically retrieved by Hindsight from THIS repository's own history (git rationale and past developer sessions) \u2014 real memory, but retrieval is heuristic: it may or may not bear on the current task.
@@ -17495,9 +17620,9 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
17495
17620
  }
17496
17621
 
17497
17622
  // src/core/turn-journal.ts
17498
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
17499
- import { tmpdir as tmpdir5 } from "os";
17500
- import { dirname as dirname10, join as join15 } from "path";
17623
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
17624
+ import { tmpdir as tmpdir4 } from "os";
17625
+ import { dirname as dirname10, join as join17 } from "path";
17501
17626
 
17502
17627
  // src/core/transcript-util.ts
17503
17628
  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;
@@ -17538,7 +17663,52 @@ function actionLine(tool, input) {
17538
17663
  var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
17539
17664
 
17540
17665
  // src/core/hook.ts
17541
- var HOOK_REFLECT_CAP_MS = 25e3;
17666
+ var HOOK_REFLECT_CAP_MS = 2e4;
17667
+ var HOOK_FALLBACK_BUDGET_MS = 7e3;
17668
+ var FALLBACK_PAGE_LIMIT = 3;
17669
+ var FALLBACK_RECALL_MAX_TOKENS = 2e3;
17670
+ async function reflectFallback(harness, prompt, client) {
17671
+ const deadline = Date.now() + HOOK_FALLBACK_BUDGET_MS;
17672
+ const remaining = () => Math.max(deadline - Date.now(), 1);
17673
+ const query = prompt.slice(0, 500);
17674
+ let t0 = Date.now();
17675
+ try {
17676
+ const hits = await client.searchKnowledgePages(query, FALLBACK_PAGE_LIMIT, remaining());
17677
+ diag(harness, "reflect_fallback_pages", { ms: Date.now() - t0, count: hits.length });
17678
+ if (hits.length) {
17679
+ return { memory: formatPageFallback(hits), source: "knowledge_pages", count: hits.length };
17680
+ }
17681
+ } catch (e) {
17682
+ diag(harness, "reflect_fallback_pages_failed", {
17683
+ ms: Date.now() - t0,
17684
+ error: describeError(e)
17685
+ });
17686
+ }
17687
+ t0 = Date.now();
17688
+ try {
17689
+ const observations = await client.recallObservations(prompt.slice(0, 2e3), {
17690
+ maxTokens: FALLBACK_RECALL_MAX_TOKENS,
17691
+ timeoutMs: remaining()
17692
+ });
17693
+ diag(harness, "reflect_fallback_observations", {
17694
+ ms: Date.now() - t0,
17695
+ count: observations.length
17696
+ });
17697
+ if (observations.length) {
17698
+ return {
17699
+ memory: formatObservationFallback(observations),
17700
+ source: "observations",
17701
+ count: observations.length
17702
+ };
17703
+ }
17704
+ } catch (e) {
17705
+ diag(harness, "reflect_fallback_observations_failed", {
17706
+ ms: Date.now() - t0,
17707
+ error: describeError(e)
17708
+ });
17709
+ }
17710
+ return void 0;
17711
+ }
17542
17712
  async function buildHookOutput(args) {
17543
17713
  const { harness, prompt, cfg, client, cacheFile } = args;
17544
17714
  const cached2 = readSessionCache(cacheFile);
@@ -17546,6 +17716,7 @@ async function buildHookOutput(args) {
17546
17716
  let reflectAnswer = cached2.reflectAnswer;
17547
17717
  let reflectRanThisTurn = false;
17548
17718
  let reflectFailed = false;
17719
+ let fallback;
17549
17720
  const deferInitialReflect = cached2.deferInitialReflect === true;
17550
17721
  if (deferInitialReflect) {
17551
17722
  diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
@@ -17555,7 +17726,7 @@ async function buildHookOutput(args) {
17555
17726
  const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
17556
17727
  try {
17557
17728
  reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
17558
- // Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
17729
+ // Automatic reflection runs inside a hard 20s slot of the hook window. Hindsight's low budget is the
17559
17730
  // supported default for bounded reflect calls; callers that explicitly invoke the MCP
17560
17731
  // tool still get the deeper high-budget path.
17561
17732
  budget: "low",
@@ -17583,6 +17754,10 @@ async function buildHookOutput(args) {
17583
17754
  error: describeError(e, 1500),
17584
17755
  query: prompt.slice(0, 80)
17585
17756
  });
17757
+ if (e instanceof ReflectError && e.fallbackEligible) {
17758
+ fallback = await reflectFallback(harness, prompt, client);
17759
+ if (fallback) reflectAnswer = fallback.memory;
17760
+ }
17586
17761
  }
17587
17762
  }
17588
17763
  const cadence = cfg.pageRefreshEveryTurns;
@@ -17616,7 +17791,10 @@ async function buildHookOutput(args) {
17616
17791
  }
17617
17792
  const kept = blocks.filter(Boolean);
17618
17793
  let notice;
17619
- if (reflectRanThisTurn && reflectAnswer) {
17794
+ if (fallback) {
17795
+ const what = fallback.source === "knowledge_pages" ? "knowledge page" : "observation";
17796
+ notice = `${brandWord()} \xB7 reflect unavailable \u2014 fell back to ${fallback.count} ${what}${fallback.count === 1 ? "" : "s"} (see ${diagFilePath()})`;
17797
+ } else if (reflectRanThisTurn && reflectAnswer) {
17620
17798
  const q = prompt.replace(/\s+/g, " ").trim();
17621
17799
  const excerpt = q.length > 48 ? `${q.slice(0, 48)}\u2026` : q;
17622
17800
  const preview = reflectAnswer.replace(/\s+/g, " ").trim();
@@ -17652,6 +17830,8 @@ var RuntimeCore = class {
17652
17830
  sessionState = /* @__PURE__ */ new Map();
17653
17831
  /** Live write-back cursors. In memory, unlike the hook harnesses': this host outlives the session. */
17654
17832
  cursors = memoryCursorStore();
17833
+ /** Turns already written to the usage log (core/usage.ts), per session. */
17834
+ usageCursors = memoryUsageCursorStore();
17655
17835
  /** Pulls a session's CURRENT transcript from the host (set by the adapter); see onSessionIdle. */
17656
17836
  fetchTranscript;
17657
17837
  lastInjection = "";
@@ -17774,9 +17954,10 @@ var RuntimeCore = class {
17774
17954
  * (`engine.retain.fold`), so submitting every turn costs one extraction, not one per turn, and
17775
17955
  * nothing is ever held somewhere it can be lost.
17776
17956
  */
17777
- async onTranscript(sessionId, turns) {
17957
+ async onTranscript(sessionId, turns, lastTurnComplete) {
17778
17958
  if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
17779
17959
  if (!this.writeBackEnabled || !sessionId || !turns.length) return;
17960
+ this.recordUsage(sessionId, turns, lastTurnComplete);
17780
17961
  const st = this.stateFor(sessionId);
17781
17962
  this.retain(sessionId, turns, st.startTs);
17782
17963
  }
@@ -17806,11 +17987,22 @@ var RuntimeCore = class {
17806
17987
  return;
17807
17988
  }
17808
17989
  if (!turns.length) return;
17990
+ this.recordUsage(sessionId, turns, true);
17809
17991
  const st = this.stateFor(sessionId);
17810
17992
  if (turns.length <= st.retainedTurns) return;
17811
17993
  st.retainedTurns = turns.length;
17812
17994
  this.retain(sessionId, turns, st.startTs, "idle");
17813
17995
  }
17996
+ recordUsage(sessionId, turns, lastTurnComplete) {
17997
+ recordUsage({
17998
+ harness: this.harness,
17999
+ sessionId,
18000
+ bankId: this.bankId,
18001
+ turns,
18002
+ cursors: this.usageCursors,
18003
+ lastTurnComplete
18004
+ });
18005
+ }
17814
18006
  stateFor(sessionId) {
17815
18007
  let st = this.sessionState.get(sessionId);
17816
18008
  if (!st) {
@@ -17851,7 +18043,7 @@ var RuntimeCore = class {
17851
18043
  };
17852
18044
 
17853
18045
  // src/core/jsonl.ts
17854
- import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
18046
+ import { closeSync, openSync, readSync, statSync as statSync4 } from "fs";
17855
18047
  import { StringDecoder } from "string_decoder";
17856
18048
  var CHUNK_BYTES = 64 * 1024;
17857
18049
  var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
@@ -17925,7 +18117,7 @@ ${injection}` };
17925
18117
  },
17926
18118
  async agentEnd(event, sessionId) {
17927
18119
  const turns = readPiMessages(event.messages);
17928
- if (turns.length) await core.onTranscript(sessionId, turns);
18120
+ if (turns.length) await core.onTranscript(sessionId, turns, true);
17929
18121
  }
17930
18122
  };
17931
18123
  }