A desktop coding agent with free access to frontier models.
TypeScript
fix: claude chats name claude code from the first upload
ogsamrat7330fbf55cab
diff --git a/apps/server/src/opencode-proxy-gate.test.ts b/apps/server/src/opencode-proxy-gate.test.tsindex 174ee815..f3850803 100644--- a/apps/server/src/opencode-proxy-gate.test.ts+++ b/apps/server/src/opencode-proxy-gate.test.ts@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";import {assertOpencodeProxyAllowed,+ engineChatProvider,engineHasSession,normalizeOpencodeDirectory,proxyOpencodeRequest,@@ -189,3 +190,27 @@ describe("engineHasSession", () => {}}, 15_000);});++describe("engineChatProvider", () => {+ test("the 2.x chat's provider from its engine session; null when unreadable", async () => {+ const engine = Bun.serve({+ port: 0,+ hostname: "127.0.0.1",+ fetch: (request) => {+ const url = new URL(request.url);+ if (url.pathname === "/api/session/ses_claude") return Response.json({ data: { id: "ses_claude", model: { id: "claude-opus-5-5", providerID: "omnirush-claude" } } });+ if (url.pathname === "/api/session/ses_astra") return Response.json({ data: { id: "ses_astra", model: { id: "gpt-6-astra", providerID: "omnirush" } } });+ return Response.json({ name: "NotFoundError" }, { status: 404 });+ },+ });+ try {+ const target = { baseUrl: `http://127.0.0.1:${engine.port}`, headers: [], search: "", engine: "v2" as const };+ expect(await engineChatProvider(target, "ses_claude")).toBe("omnirush-claude");+ expect(await engineChatProvider(target, "ses_astra")).toBe("omnirush");+ expect(await engineChatProvider(target, "ses_gone")).toBeNull();+ expect(await engineChatProvider({ ...target, baseUrl: "http://127.0.0.1:1" }, "ses_claude")).toBeNull();+ } finally {+ engine.stop(true);+ }+ });+});diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex 1201cda6..ca24b65e 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -258,7 +258,7 @@ import { GOOD_SESSION_ID_PATTERN, readGoodSession } from "./omnirush-good-sessioimport { PROJECT_ARCHIVE_BASE_IDLE_MS, PROJECT_ARCHIVE_BASE_MAX_DEFER_MS, projectArchiveSettings } from "./project-archive.js";import type { ArchiveApiRequestInit } from "./session-archive/upload.js";import { runtimeStorageDir } from "./runtime-db.js";-import { CLAUDE_AUTO_NOTE, CLAUDE_CODE_VERSION, claudeChatRoute, type ClaudeChatInput } from "./claude-code/chat.js";+import { CLAUDE_AUTO_NOTE, CLAUDE_CODE_VERSION, CLAUDE_PROVIDER_ID, claudeChatRoute, type ClaudeChatInput } from "./claude-code/chat.js";import { claudeConfigDirOf, uploadClaudeTurn } from "./claude-code/native.js";import { prepareDesktopInstallLog } from "./install-log-host.js";import pkg from "../package.json" with { type: "json" };@@ -1212,6 +1212,22 @@ export async function engineHasSession(baseUrl: string, auth: string | null, dir}}+/** The provider a 2.x chat runs on (its engine session's model), or null when unreadable. */+export async function engineChatProvider(engine: EngineTarget, sessionId: string): Promise<string | null> {+ try {+ const response = await loopbackFetch(buildOpencodeProxyUrl(engine.baseUrl, `/api/session/${encodeURIComponent(sessionId)}`, engine.search), { headers: new Headers(engine.headers), signal: AbortSignal.timeout(ENGINE_SESSION_CHECK_TIMEOUT_MS) });+ if (!response.ok) {+ await response.body?.cancel().catch(() => undefined);+ return null;+ }+ const body: unknown = await response.json();+ const model = isRecord(body) && isRecord(body.data) && isRecord(body.data.model) ? body.data.model : null;+ return typeof model?.providerID === "string" ? model.providerID : null;+ } catch {+ return null;+ }+}+/** The message a chat's undo currently rewinds to (its revert point), or null: read before an undo or redo. */async function engineRevertPoint(baseUrl: string, auth: string | null, directory: string | null, sessionId: string): Promise<string | null> {const headers = new Headers();@@ -2407,6 +2423,8 @@ export async function proxyOpencodeV2Request(input: {if (capture && uploadedSessionId && engine && !steer) {capture.boxSession(uploadedSessionId, boxInfo);capture.permissionMode(await capturePermissionMode(input.config));+ // A Claude chat's uploads name Claude Code from its first one, also after a restart (its grant comes later). CLI: beforePromptDispatch.+ if (await engineChatProvider(engine, uploadedSessionId) === CLAUDE_PROVIDER_ID) capture.markClaude(uploadedSessionId, CLAUDE_CODE_VERSION);capture.startSession(uploadedSessionId, input.workspace.id, input.workspace.path, turnsBefore);// The turn before's background processes finish writing (at most 10 s after it ended), its project// delta is taken (at most 5 s more, only when it ended a moment ago), then capture v2's session-startdiff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.tsindex f901940d..9498195c 100644--- a/apps/server/src/session-uploader.test.ts+++ b/apps/server/src/session-uploader.test.ts@@ -2552,6 +2552,44 @@ describe("session uploader trace additions", () => {await second.stop();});+ test("a Claude chat names Claude Code from its first upload, and after a restart before its next grant", async () => {+ const root = await mkdtemp(join(tmpdir(), "omnirush-upload-claude-"));+ const stateDir = await mkdtemp(join(tmpdir(), "omnirush-upload-claude-state-"));+ roots.push(root, stateDir);+ await writeFile(join(root, "app.txt"), "hello\n");+ const { uploads, upload } = makeUploads();+ const makeUploader = () => new SessionUploader({ stateDir, upload, fallbackScanMs: 60_000 });+ const sessionId = "session-claude-identity-1";+ const identity = (item: Envelope) => [item.environment.engine_version, (item.environment.harness as { name?: string }).name];++ // The prompt path marks the chat before its start (server.ts engineChatProvider): no grant yet.+ const first = makeUploader();+ first.markClaude(sessionId, "2.1.306");+ first.startSession(sessionId, "workspace-claude", root);+ await first.idle(sessionId);+ first.recordSessionModel(sessionId, { provider_id: "omnirush-claude", model_id: "claude-opus-5-5", variant: null, agent: "build" });+ first.flushTrace(sessionId);+ await first.idle(sessionId);+ await first.stop();+ expect(uploads.map(identity)).toEqual(uploads.map(() => ["claude-code/2.1.306", "claude-code"]));++ // Reopened in a new process, nothing marked: the stored model still names Claude Code.+ const before = uploads.length;+ const second = makeUploader();+ second.startSession(sessionId, "workspace-claude", root);+ await second.idle(sessionId);+ await second.stop();+ expect(uploads.length).toBeGreaterThan(before);+ expect(uploads.slice(before).map(identity)).toEqual(uploads.slice(before).map(() => ["claude-code/2.1.306", "claude-code"]));++ // Any other chat keeps the engine's identity.+ const other = makeUploader();+ other.startSession("session-astra-identity-1", "workspace-claude", root);+ await other.idle("session-astra-identity-1");+ await other.stop();+ expect(identity(uploads.at(-1)!)[0]).not.toContain("claude-code");+ });+test("child ids noted while the turn runs are listed at once, deduped, and kept across a restart without a transcript event", async () => {const root = await mkdtemp(join(tmpdir(), "omnirush-upload-child-ids-"));const stateDir = await mkdtemp(join(tmpdir(), "omnirush-upload-child-ids-state-"));diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex a700d094..8ff81675 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -44,6 +44,7 @@ import { maskWindowsProfiles } from "./context/privacy.js";import bundledBestPractices from "./bundled-best-practices.json" with { type: "json" };import serverPackage from "../package.json" with { type: "json" };import { BUNDLED_ENGINE_VERSION, BUNDLED_HARNESS, type Harness } from "./engine-identity.js";+import { CLAUDE_CODE_VERSION, CLAUDE_PROVIDER_ID } from "./claude-code/chat.js";import { mcpServersInUse, workspaceMcpReport, type McpServerUse } from "./mcp-allow/state.js";import type { ComputerUseEnvironment } from "./computer-use/desktop.js";import { gatewayUrlAllowed } from "./release-guard.js";@@ -5278,7 +5279,8 @@ export class SessionUploader {// Only a chat that used computer use gets the field.const computerUse = this.computerUse.get(sessionId) ?? null;// A Claude chat: Claude Code is the harness, run in the box under this engine, whose stored events the upload holds (the CLI: the same).- const claude = this.claudeChats.get(sessionId);+ // Also a reopened chat before its next prompt: the model its stored messages name.+ const claude = this.claudeChats.get(sessionId) ?? (this.sessions.get(sessionId)?.model?.provider_id === CLAUDE_PROVIDER_ID ? CLAUDE_CODE_VERSION : undefined);const harness = claude ? { engine_version: `claude-code/${claude}`, harness: { name: "claude-code", engine: "claude-code", version: claude, build_tag: environment.harness.build_tag, host_engine: environment.engine_version, runtime: "box", engine_schema: "opencode-v2" }, engine_schema: "opencode-v2" } as unknown as Partial<UploadEnvironment> : {};return { ...environment, ...harness, ...boxEnvironment(environment, box?.label ?? null), ...(toolchain ? { toolchain } : {}), ...(box ? { sandbox: box.label } : {}), ...(importedFrom ? { imported_from: importedFrom } : {}), ...(mcpServers ? { mcp_servers: mcpServers } : {}), ...(computerUse ? { computer_use: computerUse } : {}) };}