@vectorize-io/hindsight-coding-agents 0.1.0 → 0.1.2

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.
package/README.md CHANGED
@@ -15,14 +15,13 @@ in front of the agent at the moment it starts working, and keeps a curated set o
15
15
  ## Install
16
16
 
17
17
  ```bash
18
- npm install -g @vectorize-io/hindsight-coding-agents
19
- hindsight-coding-agents install all # every detected agent, wired natively
20
- hindsight-coding-agents install claude-code # or just one
21
- hindsight-coding-agents uninstall all # removes exactly what install added
18
+ npx @vectorize-io/hindsight-coding-agents install all # every detected agent, wired natively
19
+ npx @vectorize-io/hindsight-coding-agents install claude-code # or just one
20
+ npx @vectorize-io/hindsight-coding-agents uninstall all # removes exactly what install added
22
21
  ```
23
22
 
24
23
  `install` takes an explicit target — `all`, or one or more harness names. A bare
25
- `hindsight-coding-agents install` changes nothing and prints the choice, so wiring every agent on
24
+ `npx @vectorize-io/hindsight-coding-agents install` changes nothing and prints the choice, so wiring every agent on
26
25
  the machine is never something that happens by accident.
27
26
 
28
27
  On a terminal it also asks **where memory should live** — Hindsight Cloud, a server you run, or a
@@ -33,30 +32,96 @@ local daemon on this machine (see [Where memory lives](#where-memory-lives)). Sc
33
32
 
34
33
  Same command, only the harness name changes. Run after installing the package globally.
35
34
 
36
- | agent | command | what it wires |
37
- | ------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------ |
38
- | Claude Code | `hindsight-coding-agents install claude-code` | 3 hooks in `~/.claude/settings.json` + MCP (`claude mcp add`, user scope) + companion skill |
39
- | opencode | `hindsight-coding-agents install opencode` | plugin entry in `~/.config/opencode/opencode.json` (native tools, no MCP needed) |
40
- | Kilo CLI | `hindsight-coding-agents install kilo` | plugin entry in `~/.config/kilo/kilo.json[c]` |
41
- | Codex CLI | `hindsight-coding-agents install codex` | 3 hooks in `~/.codex/hooks.json` + `[mcp_servers]` in `config.toml` (needs `codex_hooks = true`) |
42
- | Cursor CLI | `hindsight-coding-agents install cursor-cli` | hooks in `~/.cursor/hooks.json` + `~/.cursor/mcp.json` + skill |
43
- | GitHub Copilot CLI | `hindsight-coding-agents install copilot-cli` | `~/.copilot/hooks/` + `mcp-config.json` + skill |
44
- | Grok Build | `hindsight-coding-agents install grok-build` | native hooks + MCP in `~/.grok/config.toml` + skill |
45
- | Antigravity CLI | `hindsight-coding-agents install agy` | lifecycle hooks + MCP + the `Hindsight · <bank>` status line |
46
- | Devin CLI | `hindsight-coding-agents install devin-cli` | hooks in `~/.config/devin/config.json` + MCP (needs Node 22.5+, see below) |
47
- | Cline CLI | `hindsight-coding-agents install cline-cli` | native plugin via `cline plugin install` + MCP + skill |
48
-
49
- Uninstall the same way: `hindsight-coding-agents uninstall claude-code` (or `uninstall all`).
35
+ #### <img src="https://hindsight.vectorize.io/img/harness/claude-code.png" alt="" width="20" height="20" /> Claude Code
36
+
37
+ ```bash
38
+ npx @vectorize-io/hindsight-coding-agents install claude-code
39
+ ```
40
+
41
+ 3 hooks in `~/.claude/settings.json`, MCP via `claude mcp add` (user scope), and the companion skill.
42
+
43
+ #### <img src="https://hindsight.vectorize.io/img/harness/codex.svg" alt="" width="20" height="20" /> Codex CLI
44
+
45
+ ```bash
46
+ npx @vectorize-io/hindsight-coding-agents install codex
47
+ ```
48
+
49
+ 3 hooks in `~/.codex/hooks.json` plus `[mcp_servers]` in `config.toml` (needs `codex_hooks = true`).
50
+
51
+ #### <img src="https://hindsight.vectorize.io/img/harness/opencode.png" alt="" width="20" height="20" /> opencode
52
+
53
+ ```bash
54
+ npx @vectorize-io/hindsight-coding-agents install opencode
55
+ ```
56
+
57
+ A plugin entry in `~/.config/opencode/opencode.json` — native tools, no MCP needed.
58
+
59
+ #### <img src="https://hindsight.vectorize.io/img/harness/kilo.svg" alt="" width="20" height="20" /> Kilo CLI
60
+
61
+ ```bash
62
+ npx @vectorize-io/hindsight-coding-agents install kilo
63
+ ```
64
+
65
+ A plugin entry in `~/.config/kilo/kilo.json[c]`.
66
+
67
+ #### <img src="https://hindsight.vectorize.io/img/harness/cursor-cli.svg" alt="" width="20" height="20" /> Cursor CLI
68
+
69
+ ```bash
70
+ npx @vectorize-io/hindsight-coding-agents install cursor-cli
71
+ ```
72
+
73
+ Hooks in `~/.cursor/hooks.json`, `~/.cursor/mcp.json`, and the companion skill.
74
+
75
+ #### <img src="https://hindsight.vectorize.io/img/harness/copilot-cli.svg" alt="" width="20" height="20" /> GitHub Copilot CLI
76
+
77
+ ```bash
78
+ npx @vectorize-io/hindsight-coding-agents install copilot-cli
79
+ ```
80
+
81
+ `~/.copilot/hooks/`, `mcp-config.json`, and the companion skill.
82
+
83
+ #### <img src="https://hindsight.vectorize.io/img/harness/grok-build.svg" alt="" width="20" height="20" /> Grok Build
84
+
85
+ ```bash
86
+ npx @vectorize-io/hindsight-coding-agents install grok-build
87
+ ```
88
+
89
+ Native hooks and MCP in `~/.grok/config.toml`, plus the companion skill.
90
+
91
+ #### <img src="https://hindsight.vectorize.io/img/harness/antigravity-cli.png" alt="" width="20" height="20" /> Antigravity CLI
92
+
93
+ ```bash
94
+ npx @vectorize-io/hindsight-coding-agents install agy
95
+ ```
96
+
97
+ Lifecycle hooks, MCP, and the `Hindsight · <bank>` status line.
98
+
99
+ #### <img src="https://hindsight.vectorize.io/img/harness/devin-cli.svg" alt="" width="20" height="20" /> Devin CLI
100
+
101
+ ```bash
102
+ npx @vectorize-io/hindsight-coding-agents install devin-cli
103
+ ```
104
+
105
+ Hooks in `~/.config/devin/config.json` plus MCP. Needs Node 22.5+ — see below.
106
+
107
+ #### <img src="https://hindsight.vectorize.io/img/harness/cline-cli.svg" alt="" width="20" height="20" /> Cline CLI
108
+
109
+ ```bash
110
+ npx @vectorize-io/hindsight-coding-agents install cline-cli
111
+ ```
112
+
113
+ A native plugin via `cline plugin install`, plus MCP and the companion skill.
114
+
115
+ Uninstall the same way: `npx @vectorize-io/hindsight-coding-agents uninstall claude-code` (or `uninstall all`).
50
116
 
51
117
  **Devin CLI needs Node 22.5 or newer.** Its hooks pass only a session id — the conversation itself
52
118
  lives in `~/.local/share/devin/cli/sessions.db` — so reading it depends on Node's built-in
53
119
  `node:sqlite`. Installing `devin-cli` checks for this first and refuses (with the reason) rather
54
120
  than wiring hooks that could never retain anything. Every other agent works on any supported Node.
55
121
 
56
- Install globally (not `npx`): the wiring points at this package's files, so it must live at a
57
- stable path — the installer refuses to run from an npx cache. **Updating** is just
58
- `npm update -g @vectorize-io/hindsight-coding-agents`: the wired paths stay valid, every new session runs the
59
- new version; re-run `install` (idempotent) only when a release note says the wiring changed.
122
+ `install` copies what it needs into `~/.hindsight/coding-agents` and points each agent's wiring
123
+ there, so nothing depends on where you ran it from. **Updating** is the same command again — it
124
+ re-copies the runtime in place, leaving the wiring valid and every new session on the new version.
60
125
 
61
126
  `install` merges the native wiring (hooks + MCP registration where the host wants them) into each
62
127
  agent's own config, preserving everything already there; it is idempotent (re-run after moving the
@@ -73,7 +138,7 @@ can ask the agent itself. Manual wiring per harness, if you prefer:
73
138
  ```
74
139
 
75
140
  **Claude Code** and **Codex** get their full three-hook + MCP wiring from this package's own
76
- installer — `hindsight-coding-agents install claude-code` / `install codex`. This package's `bin`
141
+ installer — `npx @vectorize-io/hindsight-coding-agents install claude-code` / `install codex`. This package's `bin`
77
142
  entries (`hindsight-claude-hook`, `hindsight-codex-hook`,
78
143
  `hindsight-cursor-hook`) are the individual injection-only `UserPromptSubmit` entrypoints for a
79
144
  minimal, hand-wired setup.
@@ -98,7 +163,7 @@ that shipped a user config — Cursor CLI, Copilot CLI, opencode and Cline have
98
163
 
99
164
  ```bash
100
165
  cd /path/to/your/repo
101
- hindsight-coding-agents install claude-code --import-conversations # or: install codex --import-conversations
166
+ npx @vectorize-io/hindsight-coding-agents install claude-code --import-conversations # or: install codex --import-conversations
102
167
  ```
103
168
 
104
169
  This re-extracts the transcripts the agent already wrote, so it costs tokens roughly in proportion
@@ -141,9 +206,9 @@ Three modes, chosen once when you install (`install` asks on a terminal; pass `-
141
206
  | `daemon` | a local `hindsight-embed` on this machine | `uv` on PATH + an LLM key for extraction |
142
207
 
143
208
  ```bash
144
- hindsight-coding-agents install claude-code --server daemon
145
- hindsight-coding-agents install claude-code --server self-hosted --api-url http://localhost:8888
146
- hindsight-coding-agents install claude-code --server cloud --api-token <token>
209
+ npx @vectorize-io/hindsight-coding-agents install claude-code --server daemon
210
+ npx @vectorize-io/hindsight-coding-agents install claude-code --server self-hosted --api-url http://localhost:8888
211
+ npx @vectorize-io/hindsight-coding-agents install claude-code --server cloud --api-token <token>
147
212
  ```
148
213
 
149
214
  Re-running `install` never re-asks: a config that already names a server is left alone.
@@ -238,7 +238,9 @@ function readEnvConfig(env = process.env) {
238
238
  function loadConfig(opts = {}) {
239
239
  const o = typeof opts === "string" ? { path: opts } : opts;
240
240
  const withEnv = applyLayer({}, readEnvConfig(), o.harness);
241
- return resolveConfig(applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness));
241
+ const raw = applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness);
242
+ if (!raw.harness && o.harness) raw.harness = o.harness;
243
+ return resolveConfig(raw);
242
244
  }
243
245
  var BANK_OVERRIDE_EXCLUDED = [
244
246
  "bankId",
@@ -322,7 +324,7 @@ var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAG
322
324
  var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Do not invent; capture only what was actually settled.`;
323
325
  var REFLECT_MISSION = "You are a debugging assistant with the project's past decisions in memory (git rationale and developer chats). Given a bug's SYMPTOM, find the past decision whose rationale explains the ROOT CAUSE \u2014 not one that merely shares vocabulary. Answer with the PRECISE fix: state the EXACT rule and the LITERAL values, identifiers, strings, numbers, or set members that were decided \u2014 quote them VERBATIM, never paraphrase, generalize, or omit them (give the actual decided value, not 'the project standard'). If memories CONFLICT on the same rule, the LATEST decision wins \u2014 prefer facts that explicitly amend or supersede an earlier one, state the superseded rule as no longer in effect, and never present it as the fix. Name the function/file to change and cite the REF-ID(s). If NOTHING in memory genuinely explains THIS symptom, say exactly that in one short sentence \u2014 a wrong-but-confident nearest match is worse than an honest miss; never stretch an unrelated decision to fit.";
324
326
  var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
325
- var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details.";
327
+ var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
326
328
  var RETAIN_STRATEGIES = {
327
329
  git: { retain_mission: GIT_MISSION, retain_extraction_mode: "verbose" },
328
330
  // ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
@@ -440,8 +442,22 @@ var CODING_BANK_TEMPLATE = {
440
442
 
441
443
  // src/core/util.ts
442
444
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
445
+ function semverGte(version, min) {
446
+ const parts = (v) => {
447
+ const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
448
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
449
+ };
450
+ const a = version ? parts(version) : void 0;
451
+ const b = parts(min);
452
+ if (!a || !b) return false;
453
+ for (let i = 0; i < 3; i++) {
454
+ if (a[i] !== b[i]) return a[i] > b[i];
455
+ }
456
+ return true;
457
+ }
443
458
 
444
459
  // src/core/hindsight.ts
460
+ var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
445
461
  var KnowledgePagesUnavailableError = class extends Error {
446
462
  code = "knowledge_pages_unavailable";
447
463
  constructor() {
@@ -458,6 +474,8 @@ var HindsightClient = class {
458
474
  // async operation ids collected by retain(), for drain()
459
475
  /** Tri-state capability probe: unknown until the first page request, then cached. */
460
476
  knowledgePagesSupported;
477
+ /** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
478
+ idempotentRetain;
461
479
  log;
462
480
  constructor(o) {
463
481
  this.apiUrl = o.apiUrl.replace(/\/$/, "");
@@ -486,7 +504,8 @@ var HindsightClient = class {
486
504
  throw new Error(`${method} ${url} -> ${r.status} ${await r.text()}`);
487
505
  return r;
488
506
  }
489
- /** Retain one memory. Async by default: enqueue extraction server-side and collect its op-id for drain(). */
507
+ /** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
508
+ * drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
490
509
  async retain(content, context, documentId, tags, strategy, opts = {}) {
491
510
  const item = {
492
511
  content,
@@ -497,14 +516,36 @@ var HindsightClient = class {
497
516
  };
498
517
  if (opts.timestamp) item.timestamp = opts.timestamp;
499
518
  if (opts.metadata) item.metadata = opts.metadata;
500
- const isAsync = opts.async !== false;
501
- const r = await this.req("POST", this.bankUrl("/memories"), { items: [item], async: isAsync });
502
- if (isAsync) {
503
- try {
504
- const j = await r.json();
505
- if (j.operation_id) this.opIds.push(j.operation_id);
506
- } catch {
507
- }
519
+ if (opts.updateMode) item.update_mode = opts.updateMode;
520
+ const body = { items: [item], async: true };
521
+ if (opts.operationId) body.operation_id = opts.operationId;
522
+ const r = await this.req("POST", this.bankUrl("/memories"), body);
523
+ try {
524
+ const j = await r.json();
525
+ if (j.operation_id) this.opIds.push(j.operation_id);
526
+ } catch {
527
+ }
528
+ }
529
+ /**
530
+ * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
531
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
532
+ * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
533
+ */
534
+ async supportsIdempotentRetain() {
535
+ if (this.idempotentRetain === void 0) {
536
+ this.idempotentRetain = await this.probeIdempotentRetain();
537
+ this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
538
+ }
539
+ return this.idempotentRetain;
540
+ }
541
+ async probeIdempotentRetain() {
542
+ try {
543
+ const r = await this.req("GET", `${this.apiUrl}/version`);
544
+ if (!r.ok) return false;
545
+ const j = await r.json();
546
+ return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
547
+ } catch {
548
+ return false;
508
549
  }
509
550
  }
510
551
  /**
@@ -792,8 +833,7 @@ var HindsightClient = class {
792
833
  "initiative marker",
793
834
  markerId,
794
835
  ["knowledge:feature-work", `relatedPageId:${pageId}`],
795
- "document",
796
- { async: true }
836
+ "document"
797
837
  );
798
838
  return { page_id: pageId };
799
839
  }
@@ -1033,15 +1073,79 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
1033
1073
  }
1034
1074
 
1035
1075
  // src/core/retain-hook.ts
1036
- import { readFileSync as readFileSync5 } from "fs";
1076
+ import { readFileSync as readFileSync4 } from "fs";
1077
+
1078
+ // src/core/retain-cursor.ts
1079
+ import { createHash } from "crypto";
1080
+
1081
+ // src/core/uuid.ts
1082
+ import { createHash as createHash2 } from "crypto";
1037
1083
 
1038
1084
  // src/core/daemon.ts
1039
1085
  import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
1040
1086
  import { dirname as dirname5, join as join6 } from "path";
1041
1087
  import { fileURLToPath as fileURLToPath2 } from "url";
1042
1088
 
1043
- // src/core/transcript.ts
1044
- import { readFileSync as readFileSync4 } from "fs";
1089
+ // src/core/jsonl.ts
1090
+ import { closeSync, openSync, readSync, statSync } from "fs";
1091
+ import { StringDecoder } from "string_decoder";
1092
+ var CHUNK_BYTES = 64 * 1024;
1093
+ var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
1094
+ function readJsonlTail(path, opts) {
1095
+ const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
1096
+ let size;
1097
+ try {
1098
+ size = statSync(path).size;
1099
+ } catch {
1100
+ return { lines: emptyLines(), skippedBytes: 0 };
1101
+ }
1102
+ const skippedBytes = size > maxBytes ? size - maxBytes : 0;
1103
+ if (skippedBytes > 0) {
1104
+ log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
1105
+ path,
1106
+ sizeBytes: size,
1107
+ skippedBytes
1108
+ });
1109
+ }
1110
+ return { lines: streamLines(path, skippedBytes), skippedBytes };
1111
+ }
1112
+ function* emptyLines() {
1113
+ }
1114
+ function* streamLines(path, start) {
1115
+ let fd;
1116
+ try {
1117
+ fd = openSync(path, "r");
1118
+ } catch {
1119
+ return;
1120
+ }
1121
+ try {
1122
+ const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
1123
+ const decoder = new StringDecoder("utf8");
1124
+ let pending = "";
1125
+ let position = start > 0 ? start - 1 : 0;
1126
+ let dropPartial = start > 0;
1127
+ for (; ; ) {
1128
+ const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
1129
+ if (bytesRead <= 0) break;
1130
+ position += bytesRead;
1131
+ pending += decoder.write(buffer.subarray(0, bytesRead));
1132
+ let newline;
1133
+ while ((newline = pending.indexOf("\n")) !== -1) {
1134
+ const line = pending.slice(0, newline);
1135
+ pending = pending.slice(newline + 1);
1136
+ if (dropPartial) {
1137
+ dropPartial = false;
1138
+ continue;
1139
+ }
1140
+ yield line;
1141
+ }
1142
+ }
1143
+ pending += decoder.end();
1144
+ if (pending && !dropPartial) yield pending;
1145
+ } finally {
1146
+ closeSync(fd);
1147
+ }
1148
+ }
1045
1149
 
1046
1150
  // src/core/transcript-util.ts
1047
1151
  var MEMORY_TAG_RE = /<(hook_prompt|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
@@ -1079,7 +1183,7 @@ function actionLine(tool, input) {
1079
1183
  }
1080
1184
 
1081
1185
  // src/core/session-start.ts
1082
- import { readFileSync as readFileSync7 } from "fs";
1186
+ import { readFileSync as readFileSync6 } from "fs";
1083
1187
 
1084
1188
  // src/core/git.ts
1085
1189
  import { execFileSync as execFileSync3 } from "child_process";
@@ -1096,13 +1200,12 @@ import { delimiter, dirname as dirname6, join as join7 } from "path";
1096
1200
  import { fileURLToPath as fileURLToPath3 } from "url";
1097
1201
 
1098
1202
  // src/core/skill-sync.ts
1099
- import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
1203
+ import { cpSync, existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
1100
1204
  import { homedir as homedir4 } from "os";
1101
1205
  import { dirname as dirname7, join as join8 } from "path";
1102
1206
  import { fileURLToPath as fileURLToPath4 } from "url";
1103
1207
 
1104
1208
  // src/core/transcript-codex.ts
1105
- import { readFileSync as readFileSync8 } from "fs";
1106
1209
  function isSyntheticUserText(text) {
1107
1210
  const s = text.trimStart();
1108
1211
  return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
@@ -1111,14 +1214,8 @@ function messageText(payload) {
1111
1214
  return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
1112
1215
  }
1113
1216
  function readCodexTranscript(path) {
1114
- let raw;
1115
- try {
1116
- raw = readFileSync8(path, "utf8");
1117
- } catch {
1118
- return [];
1119
- }
1120
1217
  const turns = [];
1121
- for (const rawLine of raw.split("\n")) {
1218
+ for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
1122
1219
  const trimmed = rawLine.trim();
1123
1220
  if (!trimmed) continue;
1124
1221
  let parsed;
@@ -1152,7 +1249,6 @@ function readCodexTranscript(path) {
1152
1249
  }
1153
1250
 
1154
1251
  // src/core/transcript-cursor.ts
1155
- import { readFileSync as readFileSync9 } from "fs";
1156
1252
  function withTimestamp(turn, timestamp) {
1157
1253
  return timestamp ? { ...turn, timestamp } : turn;
1158
1254
  }
@@ -1162,14 +1258,8 @@ function textFrom(content) {
1162
1258
  return content.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
1163
1259
  }
1164
1260
  function readCursorTranscript(path) {
1165
- let raw;
1166
- try {
1167
- raw = readFileSync9(path, "utf8");
1168
- } catch {
1169
- return [];
1170
- }
1171
1261
  const turns = [];
1172
- for (const rawLine of raw.split("\n")) {
1262
+ for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
1173
1263
  let parsed;
1174
1264
  try {
1175
1265
  parsed = JSON.parse(rawLine);
@@ -1205,17 +1295,10 @@ function readCursorTranscript(path) {
1205
1295
  }
1206
1296
 
1207
1297
  // src/core/transcript-antigravity.ts
1208
- import { readFileSync as readFileSync10 } from "fs";
1209
1298
  function readAntigravityTranscript(path) {
1210
1299
  if (!path) return [];
1211
- let raw;
1212
- try {
1213
- raw = readFileSync10(path, "utf8");
1214
- } catch {
1215
- return [];
1216
- }
1217
1300
  const turns = [];
1218
- for (const line of raw.split("\n")) {
1301
+ for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
1219
1302
  try {
1220
1303
  const event = JSON.parse(line);
1221
1304
  const role = event.role ?? event.message?.role ?? event.type;
@@ -1236,16 +1319,9 @@ function readAntigravityTranscript(path) {
1236
1319
  }
1237
1320
 
1238
1321
  // src/core/transcript-copilot.ts
1239
- import { readFileSync as readFileSync11 } from "fs";
1240
1322
  function readCopilotTranscript(path) {
1241
- let raw;
1242
- try {
1243
- raw = readFileSync11(path, "utf8");
1244
- } catch {
1245
- return [];
1246
- }
1247
1323
  const turns = [];
1248
- for (const rawLine of raw.split("\n")) {
1324
+ for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
1249
1325
  try {
1250
1326
  const event = JSON.parse(rawLine);
1251
1327
  const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
@@ -1259,7 +1335,7 @@ function readCopilotTranscript(path) {
1259
1335
  }
1260
1336
 
1261
1337
  // src/core/transcript-grok.ts
1262
- import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
1338
+ import { existsSync as existsSync4, readFileSync as readFileSync7, readdirSync } from "fs";
1263
1339
  import { homedir as homedir5 } from "os";
1264
1340
  import { join as join9 } from "path";
1265
1341
  var CHAT_HISTORY = "chat_history.jsonl";
@@ -1270,7 +1346,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
1270
1346
  try {
1271
1347
  for (const candidate of readdirSync(sessionsDir)) {
1272
1348
  const directory = join9(sessionsDir, candidate);
1273
- if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
1349
+ if (readFileSync7(join9(directory, ".cwd"), "utf8").trim() === cwd) {
1274
1350
  return join9(directory, sessionId, CHAT_HISTORY);
1275
1351
  }
1276
1352
  }
@@ -1279,14 +1355,8 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
1279
1355
  return direct;
1280
1356
  }
1281
1357
  function readGrokTranscript(path) {
1282
- let raw;
1283
- try {
1284
- raw = readFileSync12(path, "utf8");
1285
- } catch {
1286
- return [];
1287
- }
1288
1358
  const turns = [];
1289
- for (const rawLine of raw.split("\n")) {
1359
+ for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
1290
1360
  try {
1291
1361
  const event = JSON.parse(rawLine);
1292
1362
  if (event.type !== "user" && event.type !== "assistant") continue;
@@ -145,7 +145,9 @@ function readEnvConfig(env = process.env) {
145
145
  function loadConfig(opts = {}) {
146
146
  const o = typeof opts === "string" ? { path: opts } : opts;
147
147
  const withEnv = applyLayer({}, readEnvConfig(), o.harness);
148
- return resolveConfig(applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness));
148
+ const raw = applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness);
149
+ if (!raw.harness && o.harness) raw.harness = o.harness;
150
+ return resolveConfig(raw);
149
151
  }
150
152
  var BANK_OVERRIDE_EXCLUDED = [
151
153
  "bankId",