opencode-claude-code-acpbridge 0.12.0 → 0.13.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.
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/provider/model.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,yBAAyB,EACzB,6BAA6B,EAG9B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAoFjC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM;QAAE,KAAK,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CACjH;AAsOD;;;yFAGyF;AACzF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGxD;AAED;;iEAEiE;AACjE,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAmBjE;AAED;;;sEAGsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,G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27
  import { Writable, Readable } from "node:stream";
28
28
  import { randomBytes } from "node:crypto";
29
- import { closeSync, fstatSync, openSync, readSync } from "node:fs";
30
29
  import { homedir } from "node:os";
31
30
  import { join } from "node:path";
32
31
  import { ClientSideConnection, ndJsonStream, PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
@@ -37,7 +36,8 @@ import { setLink, updateUsage } from "../plugin/sessions.js";
37
36
  import { addAlwaysRule, evaluate as evaluateBridge } from "../plugin/bridge-rules.js";
38
37
  import { DEBUG, logger } from "../log.js";
39
38
  import { record, recording, sanitizePrompt } from "./recorder.js";
40
- import { anchorsOf, classifyAnchors, classifyHistory, firstUserText, hashText, historyOf, isTransient, msgKey, stripInjected, systemText, } from "./history.js";
39
+ import { anchorsHash, anchorsOf, classifyAnchors, classifyHistory, firstUserText, hashText, historyOf, isTransient, msgKey, pickCheckpoint, prefixHash, sharedExtent, stripInjected, systemText, verifiedCheckpoint, } from "./history.js";
40
+ import { lastAssistantUuid, transcriptPath, userAfter } from "./transcript.js";
41
41
  const log = logger("acp-orchestrator");
42
42
  const dbg = log.dbg;
43
43
  /** Always-on notices (session lifecycle) — the user needs these without ACP_DEBUG. */
@@ -58,6 +58,10 @@ const CATCHUP_RESULT_CHARS = 8000;
58
58
  /** Ceiling for a full-history replay into a new session (~100k tokens): beyond it the
59
59
  * oldest turns are dropped — a 656k-char replay was seen in the wild. */
60
60
  const REPLAY_BUDGET_CHARS = 400_000;
61
+ /** A full replay smaller than this goes out in one prompt (re-replaying it is cheap). */
62
+ const SPLIT_REPLAY_MIN_CHARS = 20_000;
63
+ /** Longest a context-only replay turn may take before the replay is sent whole instead. */
64
+ const PRIME_TIMEOUT_MS = 5 * 60_000;
61
65
  /** Tope del buffer `pending` (chunks emitidos sin controller vivo): sin cap un turno
62
66
  * largo con el stream cerrado lo haría crecer sin límite (OOM). */
63
67
  const MAX_PENDING_PARTS = 1000;
@@ -107,6 +111,19 @@ function isInterrupted(output) {
107
111
  return true;
108
112
  return /^(Tool execution interrupted|Tool result missing)/.test(text.trim());
109
113
  }
114
+ /** Whether the agent cuts a fork at an ACP cursor (see `forkByCursor`). `auto` decides by the
115
+ * agent's version: the cursor fork arrived in claude-agent-acp 0.109; an agent that doesn't
116
+ * report one keeps the `resumeSessionAt` way. */
117
+ export function forkUsesCursor(setting, version) {
118
+ if (setting === "cursor")
119
+ return true;
120
+ if (setting === "resumeSessionAt")
121
+ return false;
122
+ const m = /^(\d+)\.(\d+)\.(\d+)/.exec(String(version ?? ""));
123
+ if (!m)
124
+ return false;
125
+ return Number(m[1]) > 0 || Number(m[2]) >= 109;
126
+ }
110
127
  function ownTextKey(text) {
111
128
  return hashText(stripInjected(text).trim());
112
129
  }
@@ -261,6 +278,10 @@ export class ACPOrchestratorModel {
261
278
  promptCaps = {};
262
279
  /** The agent merges a prompt sent mid-turn into the running turn (claude-agent-acp). */
263
280
  promptQueueing = false;
281
+ /** How a fork is cut at a checkpoint: by ACP `cursorId` (claude-agent-acp ≥ 0.109: the fork
282
+ * copies the transcript with FRESH uuids, so `resumeSessionAt` of the source no longer
283
+ * exists in it) or by `resumeSessionAt` in the creation options (older agents). */
284
+ forkByCursor = false;
264
285
  /** The agent has no session/set_model: models go through the `model` config option. */
265
286
  modelByConfig = false;
266
287
  constructor(config) {
@@ -341,8 +362,7 @@ export class ACPOrchestratorModel {
341
362
  // Without queueing it rides on the last tool result instead.
342
363
  // Keep the registry in step mid-turn too: a restart now resumes right here
343
364
  // instead of replaying every tool round-trip since the user's message.
344
- if (t.ocSession)
345
- setLink(t.ocSession, t.sessionId, t.sentKeys.length, t.convKey, t.ownPrefixes, t.cwd);
365
+ this.persistLink(t, t.sentKeys.length, t.sentAnchors);
346
366
  const extraBlocks = continuation.extras.length ? this.midTurnBlocks(t, continuation.extras) : [];
347
367
  const results = continuation.results;
348
368
  const lastTool = results.map((r) => !t.pendingPermissions.has(r.toolCallId)).lastIndexOf(true);
@@ -513,12 +533,20 @@ export class ACPOrchestratorModel {
513
533
  // fork the session at Claude's state right before it. Nothing is replayed and the
514
534
  // shared prefix stays cached; anything unexpected falls back to a new session.
515
535
  if (cls.kind !== "append" && ctrl.smartRevert !== false) {
516
- const at = classifyHistory(t.sentKeys, keys).fromIndex;
517
- const cp = t.checkpoints.find((c) => c.at === at);
518
- if (cp && (await this.forkInPlace(t, ctrl, tools, systemMode, options.prompt, cfgKey, { resumeSessionAt: cp.uuid }, "revert"))) {
536
+ // Anchors (not the legacy per-message keys) locate the rewind point in v2/shadow-v2:
537
+ // the legacy key of an old, re-rendered message would put it far too early.
538
+ const cur = t;
539
+ const legacyAt = classifyHistory(cur.sentKeys, keys).fromIndex;
540
+ const cp = mode === "v2"
541
+ ? pickCheckpoint(cur.checkpoints, sharedExtent(cur.sentAnchors, hist))
542
+ : cur.checkpoints.find((c) => c.at === legacyAt);
543
+ if (!cp)
544
+ dbg(`smartRevert: no checkpoint for the rewind (extent ${mode === "v2" ? sharedExtent(cur.sentAnchors, hist) : legacyAt}, hist ${hist.length}, checkpoints [${cur.checkpoints.map((c) => c.at).join(",")}])`);
545
+ if (cp && (await this.forkInPlace(t, ctrl, tools, systemMode, options.prompt, cfgKey, undefined, "revert", cp))) {
546
+ const at = cp.at;
519
547
  this.markKnown(t, hist.slice(0, at));
520
548
  t.checkpoints = t.checkpoints.filter((c) => c.at < at);
521
- this.decide(options, { decision: "smart-revert", session: t.sessionId, at, uuid: cp.uuid });
549
+ this.decide(options, { decision: "smart-revert", session: t.sessionId, at, uuid: cp.uuid, from: cp.sid });
522
550
  cls = { kind: "append", fromIndex: at };
523
551
  }
524
552
  }
@@ -565,8 +593,7 @@ export class ACPOrchestratorModel {
565
593
  if (ctrl.smartRevert !== false)
566
594
  this.recordCheckpoint(live, hist, cls.fromIndex);
567
595
  this.markKnown(live, hist);
568
- if (ocSession)
569
- setLink(ocSession, live.sessionId, hist.length, convKey, live.ownPrefixes, live.cwd);
596
+ this.persistLink(live, hist.length, live.sentAnchors);
570
597
  this.sendPrompt(live, blocks.length ? blocks : [{ type: "text", text: "" }]);
571
598
  return;
572
599
  }
@@ -597,11 +624,15 @@ export class ACPOrchestratorModel {
597
624
  // history grew rather than diverged) → no history replay (saves tokens). Else
598
625
  // create a fresh session and replay the full history.
599
626
  const resumeId = po.resumeId;
600
- const resumeLen = typeof po.resumeLen === "number" ? po.resumeLen : 0;
627
+ let resumeLen = typeof po.resumeLen === "number" ? po.resumeLen : 0;
601
628
  const resumePrefixes = Array.isArray(po.resumeIdPrefixes) ? po.resumeIdPrefixes.map(String) : [];
629
+ const resumeCps = Array.isArray(po.resumeCheckpoints)
630
+ ? po.resumeCheckpoints.filter((c) => c && typeof c.uuid === "string" && typeof c.sid === "string" && typeof c.at === "number")
631
+ : [];
602
632
  let sessionId;
603
633
  let replayFull = true;
604
634
  let defaultEffort;
635
+ let carriedCps = [];
605
636
  // A registry entry for a DIFFERENT conversation (first message changed: compaction,
606
637
  // or a reused id) must not be resumed — the agent would carry the wrong context.
607
638
  const sameConv = !po.resumeConvKey || po.resumeConvKey === convKey;
@@ -611,27 +642,69 @@ export class ACPOrchestratorModel {
611
642
  // resumed where it was created: its transcript lives under that directory's slug, and
612
643
  // entries from before the registry kept one were all created in the default.
613
644
  let cwd = this.sessionCwd(po);
614
- if (resumeId && sameConv && resumeLen > 0 && hist.length > resumeLen) {
645
+ if (resumeId && sameConv && resumeLen > 0) {
615
646
  const resumeCwd = typeof po.resumeCwd === "string" && po.resumeCwd ? po.resumeCwd : this.defaultCwd();
616
- try {
617
- const resumed = await this.connection.unstable_resumeSession({
618
- sessionId: resumeId,
619
- cwd: resumeCwd,
620
- mcpServers: [serverConfig],
621
- // Re-apply the clean-brain options on resume too. Without this the agent
622
- // falls back to its defaults (--tools default, --setting-sources=user,
623
- // project,local, no --strict-mcp-config) and the resumed session regains
624
- // native tools + the claude.ai connectors.
625
- _meta: { claudeCode: { options: buildClaudeCodeOptions(ctrl) } },
626
- });
627
- sessionId = resumeId;
628
- replayFull = false;
629
- cwd = resumeCwd;
630
- defaultEffort = effortOption(resumed);
631
- dbg(`resume ${resumeId} (oc=${ocSession ?? "?"}) — no history replay`);
647
+ // The registry proves what the agent session holds (`sentHash`): a history that no
648
+ // longer starts with it was rewound, and resuming would bring the undone turns back.
649
+ const rewound = typeof po.resumeSentHash === "string" && prefixHash(hist, resumeLen) !== po.resumeSentHash;
650
+ if (!rewound && hist.length > resumeLen) {
651
+ try {
652
+ const resumed = await this.connection.unstable_resumeSession({
653
+ sessionId: resumeId,
654
+ cwd: resumeCwd,
655
+ mcpServers: [serverConfig],
656
+ // Re-apply the clean-brain options on resume too. Without this the agent
657
+ // falls back to its defaults (--tools default, --setting-sources=user,
658
+ // project,local, no --strict-mcp-config) and the resumed session regains
659
+ // native tools + the claude.ai connectors.
660
+ _meta: { claudeCode: { options: buildClaudeCodeOptions(ctrl) } },
661
+ });
662
+ sessionId = resumeId;
663
+ replayFull = false;
664
+ cwd = resumeCwd;
665
+ carriedCps = resumeCps;
666
+ defaultEffort = effortOption(resumed);
667
+ dbg(`resume ${resumeId} (oc=${ocSession ?? "?"}) — no history replay`);
668
+ }
669
+ catch (e) {
670
+ dbg(`resume ${resumeId} failed (${e instanceof Error ? e.message : String(e)}) — fresh session`);
671
+ }
632
672
  }
633
- catch (e) {
634
- dbg(`resume ${resumeId} failed (${e instanceof Error ? e.message : String(e)}) — fresh session`);
673
+ else if (rewound && ctrl.smartRevert !== false) {
674
+ // Rewound while no process held the session (restart, idle eviction): fork the
675
+ // transcript at the newest rewind point the history still matches.
676
+ const cp = verifiedCheckpoint(resumeCps, hist);
677
+ if (!cp) {
678
+ // Why no rewind point matched: each checkpoint's recorded prefix hash against the incoming one.
679
+ const anchors = anchorsOf(hist);
680
+ const seen = resumeCps.map((c) => {
681
+ const n = anchors.filter((x) => x.at < c.at).length;
682
+ return `${c.at}:${c.h ?? "-"}→${anchorsHash(anchors.slice(0, n).map((x) => x.key))}`;
683
+ });
684
+ dbg(`smartRevert: no registry checkpoint matches (hist ${hist.length}, sent ${resumeLen}, ${po.resumeSentHash}→${prefixHash(hist, resumeLen)}; checkpoints ${seen.join(" ") || "none"})`);
685
+ }
686
+ if (cp) {
687
+ const meta = { claudeCode: { options: buildClaudeCodeOptions(ctrl) } };
688
+ const sysMeta = this.buildSystemPromptMeta(options.prompt, systemMode);
689
+ if (sysMeta !== undefined)
690
+ meta.systemPrompt = sysMeta;
691
+ try {
692
+ const forked = await this.forkSessionAt(resumeId, resumeCwd, [serverConfig], meta, cp);
693
+ if (!forked?.sessionId)
694
+ throw new Error("fork returned no sessionId");
695
+ sessionId = forked.sessionId;
696
+ replayFull = false;
697
+ cwd = resumeCwd;
698
+ resumeLen = cp.at;
699
+ carriedCps = resumeCps.filter((c) => c.at < cp.at);
700
+ defaultEffort = effortOption(forked);
701
+ this.decide(options, { decision: "smart-revert", session: sessionId, at: cp.at, uuid: cp.uuid, from: cp.sid, source: "registry" });
702
+ note(`session ${cp.sid} → fork ${sessionId} (revert after a restart, context kept) — resumable with: claude --resume ${sessionId}`);
703
+ }
704
+ catch (e) {
705
+ dbg(`fork of ${cp.sid} at ${cp.uuid} failed (${e instanceof Error ? e.message : String(e)}) — fresh session`);
706
+ }
707
+ }
635
708
  }
636
709
  }
637
710
  if (!sessionId) {
@@ -699,7 +772,7 @@ export class ACPOrchestratorModel {
699
772
  stepTimer: null,
700
773
  queuedItems: [],
701
774
  nativeCalls: new Map(),
702
- checkpoints: [],
775
+ checkpoints: carriedCps,
703
776
  compacting: null,
704
777
  hidden: false,
705
778
  adoptCheckpoint: false,
@@ -715,17 +788,44 @@ export class ACPOrchestratorModel {
715
788
  this.evictIdleSessions();
716
789
  this.startSweeper();
717
790
  await this.applySessionConfig(t, ctrl);
718
- if (ocSession)
719
- setLink(ocSession, sessionId, hist.length, convKey, t.ownPrefixes, t.cwd);
791
+ // The state of the agent before the tail goes out: where a later revert can rewind to.
792
+ if (!replayFull && ctrl.smartRevert !== false)
793
+ this.recordCheckpoint(t, hist, resumeLen);
794
+ this.persistLink(t, hist.length, anchorsOf(hist).map((a) => a.key));
720
795
  // Resume: the registry may lag behind (process died mid-turn), and the agent's own
721
796
  // last answer follows the recorded point — the resumed session already has it.
722
797
  const tail = replayFull ? hist : this.dropOwnLead(t, hist.slice(resumeLen));
723
798
  if (DEBUG && !replayFull)
724
799
  dbg(`resume — catch-up ${tail.length} msg(s)`);
800
+ const ctxBlocks = this.contextBlocks(t, options.prompt, ctrl);
725
801
  const promptBlocks = [
726
- ...this.contextBlocks(t, options.prompt, ctrl),
802
+ ...ctxBlocks,
727
803
  ...(tail.length ? this.blocksFor(tail, t, replayFull ? "replay" : "tail") : [{ type: "text", text: "" }]),
728
804
  ];
805
+ // Split replay: a replayed history is ONE transcript entry, so a later revert to the
806
+ // prompt that came with it had nowhere to fork and replayed everything again (and again).
807
+ // The history goes first as a hidden, context-only turn; the prompt follows as a normal
808
+ // turn, with a checkpoint right before it.
809
+ const split = replayFull ? this.replaySplit(hist, ctrl, promptBlocks) : -1;
810
+ if (split > 0) {
811
+ const histBlocks = [...ctxBlocks, ...this.replayBlocks(hist.slice(0, split), t, true)];
812
+ this.decide(options, {
813
+ decision: "new", session: sessionId, keys: keys.length, tail: tail.length,
814
+ chars: blocksChars(promptBlocks), split, primeChars: blocksChars(histBlocks),
815
+ });
816
+ this.markKnown(t, hist);
817
+ if (await this.primeReplay(t, histBlocks)) {
818
+ this.recordCheckpoint(t, hist, split);
819
+ this.persistLink(t, hist.length, anchorsOf(hist).map((a) => a.key));
820
+ this.sendPrompt(t, this.blocksFor(hist.slice(split), t, "tail"));
821
+ return;
822
+ }
823
+ if (t.aborted)
824
+ return;
825
+ note(`session ${sessionId}: context-only replay turn failed — sending the whole replay at once`);
826
+ this.sendPrompt(t, promptBlocks);
827
+ return;
828
+ }
729
829
  this.decide(options, {
730
830
  decision: replayFull ? "new" : "resume", session: sessionId, keys: keys.length,
731
831
  tail: tail.length, chars: blocksChars(promptBlocks),
@@ -733,10 +833,75 @@ export class ACPOrchestratorModel {
733
833
  this.markKnown(t, hist);
734
834
  this.sendPrompt(t, promptBlocks);
735
835
  }
836
+ /** Where a full replay is split (index of the trailing user messages = the new prompt), or
837
+ * -1: only when smartRevert is on, the history ends with the user's prompt and what comes
838
+ * before it is worth a fork point (`splitReplayMinChars`, default 20 000). */
839
+ replaySplit(hist, ctrl, blocks) {
840
+ if (ctrl.smartRevert === false || ctrl.splitReplay === false)
841
+ return -1;
842
+ let cut = hist.length;
843
+ while (cut > 0 && hist[cut - 1].role === "user")
844
+ cut--;
845
+ if (cut === 0 || cut === hist.length)
846
+ return -1;
847
+ return blocksChars(blocks) >= (ctrl.splitReplayMinChars ?? SPLIT_REPLAY_MIN_CHARS) ? cut : -1;
848
+ }
849
+ /** Context-only turn (output hidden, tools refused): the replayed history lands in the
850
+ * agent's session as a turn of its own. False when it didn't end normally in time. */
851
+ async primeReplay(t, blocks) {
852
+ t.hidden = true;
853
+ t.priming = true;
854
+ let timer;
855
+ try {
856
+ const timeout = new Promise((r) => { timer = setTimeout(() => r("timeout"), PRIME_TIMEOUT_MS); });
857
+ const resp = await Promise.race([this.connection.prompt({ sessionId: t.sessionId, prompt: blocks }), timeout]);
858
+ if (resp === "timeout") {
859
+ try {
860
+ await this.connection.cancel({ sessionId: t.sessionId });
861
+ }
862
+ catch { /* ignore */ }
863
+ return false;
864
+ }
865
+ dbg(`context-only replay turn of ${t.sessionId}: ${resp?.stopReason}`);
866
+ return resp?.stopReason === "end_turn";
867
+ }
868
+ catch (e) {
869
+ dbg(`context-only replay turn of ${t.sessionId} failed (${errorText(e)})`);
870
+ return false;
871
+ }
872
+ finally {
873
+ if (timer)
874
+ clearTimeout(timer);
875
+ t.hidden = false;
876
+ t.priming = false;
877
+ }
878
+ }
879
+ /** Directory Claude Code keeps its projects (and transcripts) in. */
880
+ claudeConfigDir() {
881
+ return resolveConfigDir(this.config.claudeCode ?? {}) ?? join(homedir(), ".claude");
882
+ }
883
+ /** `session/fork`. Without `at`: the whole session of `sessionId`. With a checkpoint: the
884
+ * session the checkpoint was taken in (`at.sid`), cut right before the turn that followed it.
885
+ * Throws when the point can't be located (the caller falls back to a new session). */
886
+ async forkSessionAt(sessionId, cwd, mcpServers, meta, at) {
887
+ const params = { sessionId: at?.sid ?? sessionId, cwd, mcpServers, _meta: meta };
888
+ if (at) {
889
+ if (this.forkByCursor) {
890
+ const user = userAfter(transcriptPath(this.claudeConfigDir(), cwd, at.sid), at.uuid);
891
+ if (!user)
892
+ throw new Error(`no prompt after transcript entry ${at.uuid} of ${at.sid}`);
893
+ params.cursorId = `before:${user}`;
894
+ }
895
+ else {
896
+ meta.claudeCode = { ...meta.claudeCode, options: { ...meta.claudeCode?.options, resumeSessionAt: at.uuid } };
897
+ }
898
+ }
899
+ return this.connection.unstable_forkSession(params);
900
+ }
736
901
  /** Swap `t` onto a fork of its ACP session created with the current profile. The
737
902
  * fork carries the whole transcript, so what `t` knows (sentKeys, own output) still
738
903
  * holds; it gets its own MCP host. The old session is closed. */
739
- async forkInPlace(t, ctrl, tools, systemMode, prompt, cfgKey, extra, why = "agent profile changed") {
904
+ async forkInPlace(t, ctrl, tools, systemMode, prompt, cfgKey, extra, why = "agent profile changed", at) {
740
905
  if (t.inflight || t.pendingTools.size || t.pendingPermissions.size) {
741
906
  this.abortTurn(t, why);
742
907
  await this.settle(t);
@@ -750,12 +915,7 @@ export class ACPOrchestratorModel {
750
915
  const sysMeta = this.buildSystemPromptMeta(prompt, systemMode);
751
916
  if (sysMeta !== undefined)
752
917
  meta.systemPrompt = sysMeta;
753
- const res = await this.connection.unstable_forkSession({
754
- sessionId: t.sessionId,
755
- cwd: t.cwd, // the source transcript is found under its own directory's slug
756
- mcpServers: [host.getServerConfig()],
757
- _meta: meta,
758
- });
918
+ const res = await this.forkSessionAt(t.sessionId, t.cwd, [host.getServerConfig()], meta, at);
759
919
  if (!res?.sessionId)
760
920
  throw new Error("fork returned no sessionId");
761
921
  const old = { id: t.sessionId, host: t.host };
@@ -854,39 +1014,19 @@ export class ACPOrchestratorModel {
854
1014
  at++;
855
1015
  if (at >= hist.length || t.checkpoints.some((c) => c.at === at))
856
1016
  return;
857
- const uuid = this.lastAssistantUuid(t);
1017
+ const uuid = lastAssistantUuid(transcriptPath(this.claudeConfigDir(), t.cwd, t.sessionId));
858
1018
  if (uuid)
859
- t.checkpoints.push({ at, uuid });
1019
+ t.checkpoints.push({ at, uuid, sid: t.sessionId, h: prefixHash(hist, at) });
860
1020
  }
861
- /** uuid of the last main-thread assistant entry in the session's transcript
862
- * (`<configDir>/projects/<cwd as slug>/<sessionId>.jsonl`), read from its tail. */
863
- lastAssistantUuid(t) {
864
- try {
865
- const dir = resolveConfigDir(this.config.claudeCode ?? {}) ?? join(homedir(), ".claude");
866
- const slug = t.cwd.replace(/[^a-zA-Z0-9]/g, "-");
867
- const file = join(dir, "projects", slug, `${t.sessionId}.jsonl`);
868
- const fd = openSync(file, "r");
869
- try {
870
- const size = fstatSync(fd).size;
871
- const len = Math.min(size, 256 * 1024);
872
- const buf = Buffer.alloc(len);
873
- readSync(fd, buf, 0, len, size - len);
874
- const lines = buf.toString("utf8").split("\n");
875
- for (let i = lines.length - 1; i >= 0; i--) {
876
- try {
877
- const e = JSON.parse(lines[i]);
878
- if (e?.type === "assistant" && typeof e.uuid === "string" && !e.isSidechain)
879
- return e.uuid;
880
- }
881
- catch { /* partial first line */ }
882
- }
883
- }
884
- finally {
885
- closeSync(fd);
886
- }
887
- }
888
- catch { /* no transcript (other configDir, agent not writing one) */ }
889
- return undefined;
1021
+ /** Keep the registry in step: where the agent session is up to (length + proof) and its
1022
+ * rewind points, so a new process can resume it — or fork it at a revert. */
1023
+ persistLink(t, len, anchorKeys) {
1024
+ if (!t.ocSession)
1025
+ return;
1026
+ setLink(t.ocSession, t.sessionId, len, t.convKey, t.ownPrefixes, t.cwd, {
1027
+ sentHash: anchorsHash(anchorKeys),
1028
+ checkpoints: t.checkpoints.slice(-48),
1029
+ });
890
1030
  }
891
1031
  /** Free the agent-side session (its Claude Code process and MCP servers). The client
892
1032
  * SDK has no method for it; the agent implements `session/close`. */
@@ -915,6 +1055,26 @@ export class ACPOrchestratorModel {
915
1055
  this.sendPrompt(t, this.lastUserBlocks(options.prompt));
916
1056
  return true;
917
1057
  }
1058
+ /** Claude Code compacts at `autoCompactPct` on its own — except in a fork (it ignores
1059
+ * CLAUDE_AUTOCOMPACT_PCT_OVERRIDE there) and in a few other cases where it waits for the
1060
+ * model's whole window. Every request re-reads the context, so a session left to grow
1061
+ * to ~1M is the most expensive kind. After a turn whose context is past the threshold,
1062
+ * the session is compacted here (hidden `/compact`; the next turn waits for it). */
1063
+ selfCompact(t) {
1064
+ const ctrl = this.config.claudeCode ?? {};
1065
+ const pct = ctrl.autoCompactPct ?? 75;
1066
+ const used = t.contextUsed, size = t.contextSize;
1067
+ if (!pct || ctrl.selfCompact === false || !used || !size || t.compacting || t.hidden)
1068
+ return;
1069
+ if (used < (size * pct) / 100)
1070
+ return;
1071
+ // Didn't shrink last time: try again only once it has grown another 10 %.
1072
+ if (t.selfCompactedAt && used < t.selfCompactedAt * 1.1)
1073
+ return;
1074
+ t.selfCompactedAt = used;
1075
+ note(`session ${t.sessionId}: context ${used}/${size} past ${pct}% — compacting it (native /compact)`);
1076
+ this.nativeCompact(t);
1077
+ }
918
1078
  /** Native `/compact` of the live session, output hidden. */
919
1079
  nativeCompact(t) {
920
1080
  t.hidden = true;
@@ -1200,6 +1360,8 @@ export class ACPOrchestratorModel {
1200
1360
  const after = t.afterTurn;
1201
1361
  t.afterTurn = null;
1202
1362
  after?.();
1363
+ if (!after)
1364
+ this.selfCompact(t);
1203
1365
  // A tool-less side call (title/summary in programmatic use) never continues.
1204
1366
  if (t.key.endsWith(":notools"))
1205
1367
  queueMicrotask(() => this.endTurn(t));
@@ -1243,6 +1405,10 @@ export class ACPOrchestratorModel {
1243
1405
  t.host.rejectToolCall(call.toolCallId, "Turn aborted");
1244
1406
  return;
1245
1407
  }
1408
+ if (t.priming) {
1409
+ t.host.rejectToolCall(call.toolCallId, "Context-only turn: no tools now. Reply with exactly: OK");
1410
+ return;
1411
+ }
1246
1412
  dbg(`agent → tool-call ${call.name} (${call.toolCallId}) → emit to OpenCode`);
1247
1413
  t.pendingTools.add(call.toolCallId);
1248
1414
  // `call.args` puede traer refs circulares/BigInt → JSON.stringify lanzaría y
@@ -1541,6 +1707,8 @@ export class ACPOrchestratorModel {
1541
1707
  case "usage_update":
1542
1708
  if (typeof update.used === "number")
1543
1709
  t.contextUsed = update.used;
1710
+ if (typeof update.size === "number" && update.size > 0)
1711
+ t.contextSize = update.size;
1544
1712
  break;
1545
1713
  case "agent_message_chunk":
1546
1714
  if (update.content?.type === "text") {
@@ -1853,6 +2021,7 @@ export class ACPOrchestratorModel {
1853
2021
  });
1854
2022
  this.promptCaps = (initResult?.agentCapabilities?.promptCapabilities ?? {});
1855
2023
  this.promptQueueing = !!initResult?.agentCapabilities?._meta?.claudeCode?.promptQueueing;
2024
+ this.forkByCursor = forkUsesCursor(this.config.claudeCode?.smartRevertFork, initResult?.agentInfo?.version);
1856
2025
  dbg(`connected to agent — promptCapabilities: ${JSON.stringify(this.promptCaps)}`);
1857
2026
  }
1858
2027
  openTransport() {
@@ -2031,10 +2200,11 @@ export class ACPOrchestratorModel {
2031
2200
  }
2032
2201
  return blocks;
2033
2202
  }
2034
- replayBlocks(msgs, t) {
2203
+ replayBlocks(msgs, t, contextOnly = false) {
2035
2204
  let cut = msgs.length;
2036
- while (cut > 0 && msgs[cut - 1].role === "user")
2037
- cut--;
2205
+ if (!contextOnly)
2206
+ while (cut > 0 && msgs[cut - 1].role === "user")
2207
+ cut--;
2038
2208
  const current = msgs.slice(cut).flatMap((m) => this.messageToBlocks(m, false, t));
2039
2209
  let rendered = msgs.slice(0, cut).map((m) => this.renderMessage(m, t)).filter((b) => b.length);
2040
2210
  if (!rendered.length)
@@ -2051,7 +2221,9 @@ export class ACPOrchestratorModel {
2051
2221
  ...(omitted ? [{ type: "text", text: `<omitted messages="${omitted}" reason="replay budget"/>` }] : []),
2052
2222
  ...rendered.slice(1).flat(),
2053
2223
  { type: "text", text: "</conversation_history>" },
2054
- ...(current.length ? current : [{ type: "text", text: "(Continue the conversation above.)" }]),
2224
+ ...(contextOnly
2225
+ ? [{ type: "text", text: "(This turn only restores context; the user's next message follows. Do not run any tool and do not act on the history. Reply with exactly: OK)" }]
2226
+ : current.length ? current : [{ type: "text", text: "(Continue the conversation above.)" }]),
2055
2227
  ];
2056
2228
  }
2057
2229
  /** One message as tagged blocks (for history and other models' turns). Reasoning and