A desktop coding agent with free access to frontier models.
TypeScript
fix: claude chats compact with claude's own /compact
ogsamrat016ab64db0a1
diff --git a/apps/server/src/opencode-plugins/claude-provider/PARITY.sha256 b/apps/server/src/opencode-plugins/claude-provider/PARITY.sha256index 84556b01..9ddef780 100644--- a/apps/server/src/opencode-plugins/claude-provider/PARITY.sha256+++ b/apps/server/src/opencode-plugins/claude-provider/PARITY.sha256@@ -1,3 +1,3 @@# The Claude provider: the same files in omnirush-cli (assets/claude-provider/) and omnirush-gui. A change to one must be ported to the other and this list updated in both.-9fbef38bd2f38ddc801321d52bbd387910a3778f993f543e5445613bc84f1144 index.js-9ded3990ef5261543634da710ecbec3956de25b2cf4ae86d5b80f44ef6b9372c map.js+8cbdea84cc316dd23a01968fc2b50e03d1f27cf1ea0cef7ca7beb4de3c044816 index.js+3018991c25910011fd1387d311aaf5c128971b0f1ba3f1627c7b0126729d1d2a map.jsdiff --git a/apps/server/src/opencode-plugins/claude-provider/index.js b/apps/server/src/opencode-plugins/claude-provider/index.jsindex 4179bb26..36ff171e 100644--- a/apps/server/src/opencode-plugins/claude-provider/index.js+++ b/apps/server/src/opencode-plugins/claude-provider/index.js@@ -216,7 +216,7 @@ class ClaudeCodeModel {try { await ensureClaude({ shell, env, cwd: root, home: boxHome, run }); } catch (error) { throw apiError(error?.message || "Claude Code could not be installed in the sandbox."); }const child = spawn(shell, ["-c", 'exec "$0" "$@"', BOX_BIN, ...claudeArgs({ model: this.modelId, uuid, resume })], { cwd: root, env, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });- const mapper = new ClaudeStreamMapper();+ const mapper = new ClaudeStreamMapper({ compaction });let stderr = "";let done = false;let stopped = false;diff --git a/apps/server/src/opencode-plugins/claude-provider/map.js b/apps/server/src/opencode-plugins/claude-provider/map.jsindex e8d85da8..451995f7 100644--- a/apps/server/src/opencode-plugins/claude-provider/map.js+++ b/apps/server/src/opencode-plugins/claude-provider/map.js@@ -15,6 +15,8 @@// status-less error is retried, and the turn would run twice).export const NOTE_COMPACTED = "Claude compacted the conversation.";+/** A template heading of the engine's compaction summary: without one the engine asks again (and Claude would compact twice). */+export const COMPACTION_HEADING = "## Important Context";const ERROR_MARK = Symbol.for("vercel.ai.error");const API_ERROR_MARK = Symbol.for("vercel.ai.error.AI_APICallError");@@ -78,7 +80,10 @@ function failure(result) {}export class ClaudeStreamMapper {- constructor() {+ /** `compaction`: the turn is the engine's compaction, run as Claude's /compact; its summary is the turn's text. */+ constructor({ compaction = false } = {}) {+ this.compaction = compaction;+ this.summary = null;this.message = null;this.blocks = new Map();this.streamed = new Set();@@ -93,12 +98,25 @@ export class ClaudeStreamMapper {if (!event || typeof event !== "object" || event.parent_tool_use_id) return [];if (event.type === "stream_event") return this.streamEvent(event.event ?? {});if (event.type === "assistant") return this.assistant(event.message ?? {});- if (event.type === "user") return this.user(event.message ?? {});- if (event.type === "system" && event.subtype === "compact_boundary") return this.note(NOTE_COMPACTED);+ if (event.type === "user") return this.compaction ? this.compacted(event.message ?? {}) : this.user(event.message ?? {});+ if (event.type === "system" && event.subtype === "compact_boundary") return this.compaction ? [] : this.note(NOTE_COMPACTED);+ if (event.type === "system" && event.subtype === "status" && typeof event.compact_error === "string") this.compactError = event.compact_error;if (event.type === "result") this.result = event;return [];}+ /** /compact's summary (the synthetic user message after the boundary) as the engine's summary text. */+ compacted(message) {+ const content = typeof message.content === "string" ? message.content : "";+ if (this.summary !== null || !content || content.startsWith("<local-command")) return [];+ const at = content.indexOf("Summary:");+ const summary = at >= 0 ? content.slice(at + "Summary:".length) : content;+ // What follows the summary is Claude's own note to itself (where the transcript is, carry on).+ const tail = summary.search(/\n\s*If you need specific details from before compaction/);+ this.summary = (tail >= 0 ? summary.slice(0, tail) : summary).trim();+ return this.note(`${COMPACTION_HEADING}\n${NOTE_COMPACTED} Its summary:\n\n${this.summary}\n`);+ }+note(text) {const id = `note-${++this.notes}`;return [{ type: "text-start", id }, { type: "text-delta", id, delta: text }, { type: "text-end", id }];@@ -177,6 +195,7 @@ export class ClaudeStreamMapper {const result = this.result;if (!result) return { type: "error", error: apiError(why) };if (result.is_error || result.subtype !== "success") return { type: "error", error: apiError(failure(result)) };+ if (this.compaction && this.summary === null) return { type: "error", error: apiError(`Claude could not compact the conversation${this.compactError ? `: ${this.compactError}` : "."}`) };return { type: "finish", finishReason: { unified: "stop", raw: result.stop_reason ?? "end_turn" }, usage: turnUsage(this.usage, result.usage ?? {}) };}}