Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: open workspace files in the IDE editor

ogsamrat009f516bf86c
diff --git a/apps/app/src/react-app/domains/session/artifacts/resolve-open-target.ts b/apps/app/src/react-app/domains/session/artifacts/resolve-open-target.ts
index ede03650..86e22d20 100644
--- a/apps/app/src/react-app/domains/session/artifacts/resolve-open-target.ts
+++ b/apps/app/src/react-app/domains/session/artifacts/resolve-open-target.ts
@@ -13,6 +13,11 @@ export function isWorkspaceContainedArtifactTarget(target: OpenTarget) {
return normalized.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
}
+/** A workspace file the IDE editor shows itself (code, Markdown, HTML), rather than the artifact side panel. */
+export function opensInIdeEditor(target: OpenTarget) {
+ return isWorkspaceContainedArtifactTarget(target) && ["code", "markdown", "html"].includes(target.preview);
+}
+
export async function resolveCollectibleOpenTarget(
client: ArtifactTargetResolver,
workspaceId: string,
diff --git a/apps/app/src/react-app/domains/session/chat/session-page.tsx b/apps/app/src/react-app/domains/session/chat/session-page.tsx
index 037a9f7d..cd265de1 100644
--- a/apps/app/src/react-app/domains/session/chat/session-page.tsx
+++ b/apps/app/src/react-app/domains/session/chat/session-page.tsx
@@ -83,14 +83,14 @@ import {
import { isElectronRuntime } from "../../../../app/utils";
import { isCollectibleArtifactTarget, isLocalhostBrowserTarget, isOpenableFileTarget, type OpenTarget } from "../artifacts/open-target";
-import { resolveCollectibleOpenTarget } from "../artifacts/resolve-open-target";
+import { opensInIdeEditor, resolveCollectibleOpenTarget } from "../artifacts/resolve-open-target";
import type { OpenTargetOptions } from "@/lib/target-provider";
import { SidePanel } from "../panel/side-panel";
import { getSidePanelSessionKey } from "../panel/side-panel-session";
import { useCreateTab } from "../panel/use-side-panel-tabs";
import { TerminalDock } from "../terminal/terminal-dock";
import { LazyEditorPanel } from "../editor/editor-entry";
-import { DEFAULT_IDE_CHAT_WIDTH, useEditorStore, type LayoutMode } from "../editor/editor-store";
+import { DEFAULT_IDE_CHAT_WIDTH, tabId, useEditorStore, type EditorTab, type LayoutMode } from "../editor/editor-store";
import { ChatPanelButton, ChatSwitcher, LayoutModeToggle, RailDestinations, shortcutLabel, WorkspaceSwitcher, type RailDestination } from "../editor/ide-chrome";
import { useActivePanelTab, usePanelTabStore, useSessionPanelState } from "../panel/panel-tab-store";
import { useWorkspaceShellLayout } from "../../../shell/workspace-shell-layout";
@@ -747,6 +747,18 @@ export function SessionPage(props: SessionPageProps) {
return;
}
+ if (ideMode && !options?.auto && runtime.runtimeWorkspaceId === props.runtimeWorkspaceId
+ && runtime.runtimeWorkspaceId && runtime.workspaceType !== "remote"
+ && opensInIdeEditor(fileTarget)) {
+ const path = fileTarget.value.replace(/\\/g, "/");
+ const editor = useEditorStore.getState();
+ const tab: EditorTab = { id: tabId({ kind: "file", path }), kind: "file", path };
+ if (editor.focusedGroup === 2 && editor.byWorkspace[runtime.runtimeWorkspaceId]?.group2) editor.openTab2(runtime.runtimeWorkspaceId, tab);
+ else editor.openTab(runtime.runtimeWorkspaceId, tab);
+ setCurrentSidePanel(null);
+ return;
+ }
+
if (!isCollectibleArtifactTarget(fileTarget)) {
if (isOpenableFileTarget(fileTarget)) {
if (runtime.workspaceType === "remote" && runtime.client && runtime.runtimeWorkspaceId) {
@@ -793,7 +805,7 @@ export function SessionPage(props: SessionPageProps) {
}
openFileTarget(target);
- }, [activePanelTab?.id, browserUrlForTarget, createBrowserTab, openOwnerSidePanel, openTab, props.selectedSessionId, setCurrentSidePanel]);
+ }, [activePanelTab?.id, browserUrlForTarget, createBrowserTab, ideMode, openOwnerSidePanel, openTab, props.runtimeWorkspaceId, props.selectedSessionId, setCurrentSidePanel]);
const openTarget = useCallback((target: OpenTarget, options?: OpenTargetOptions, sourceSessionId?: string) => {
openTargetForRuntime({
client: props.omnirushServerClient,
diff --git a/apps/app/src/react-app/domains/session/editor/editor-panel.tsx b/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
index b41c2a9a..ebf4bb12 100644
--- a/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
+++ b/apps/app/src/react-app/domains/session/editor/editor-panel.tsx
@@ -134,6 +134,7 @@ async function loadAgentChanges(input: {
}): Promise<ReviewData> {
const { opencodeClient, sessionId, directory, scope, docs } = input;
const messagesResult = await opencodeClient.session.messages({ sessionID: sessionId, directory });
+ if (messagesResult.error) throw new Error("Could not load this chat's changes. Try Refresh changes.");
const messages = (messagesResult.data ?? []) as Array<{ info: { id: string; role: string } }>;
const userIds = messages.filter((message) => message.info.role === "user").map((message) => message.info.id);
const root = input.workspaceRoot.replace(/[/\\]+$/, "").replace(/\\/g, "/");
@@ -148,6 +149,7 @@ async function loadAgentChanges(input: {
// Newest first until the scope is filled: the last turn that changed files, or every turn of the chat.
for (const id of [...userIds].reverse().slice(0, MAX_REVIEW_TURNS)) {
const result = await opencodeClient.session.diff({ sessionID: sessionId, messageID: id, directory });
+ if (result.error) throw new Error("Could not load this turn's file changes. Try Refresh changes.");
const changes = ((result.data ?? []) as unknown[])
.map(turnFileChange)
.filter((change): change is TurnFileChange => change !== null)
@@ -605,7 +607,8 @@ export default function EditorPanel(props: EditorPanelProps) {
queryKey: ["editor-changes", workspaceId, sessionId, reviewScope] as const,
queryFn: () => loadAgentChanges({ opencodeClient: opencodeClient!, sessionId: sessionId!, directory: workspaceRoot, scope: reviewScope, docs, workspaceRoot }),
enabled: Boolean(opencodeClient && sessionId && !sessionBusy),
- staleTime: Infinity,
+ // Edits can finish while IDE mode is closed; that mount never observes the busy-to-idle transition.
+ staleTime: 0,
refetchOnWindowFocus: false,
});
const review = changesQuery.data;
diff --git a/apps/app/tests/resolve-open-target.test.ts b/apps/app/tests/resolve-open-target.test.ts
index 00c4dbbc..290a920d 100644
--- a/apps/app/tests/resolve-open-target.test.ts
+++ b/apps/app/tests/resolve-open-target.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, test } from "bun:test";
import type { OpenTarget } from "../src/react-app/domains/session/artifacts/open-target";
import {
isWorkspaceContainedArtifactTarget,
+ opensInIdeEditor,
resolveCollectibleOpenTarget,
} from "../src/react-app/domains/session/artifacts/resolve-open-target";
@@ -34,4 +35,14 @@ describe("on-demand artifact target resolution", () => {
expect(isWorkspaceContainedArtifactTarget({ ...target, value: "/tmp/main.ts", exists: true })).toBe(false);
expect(isWorkspaceContainedArtifactTarget({ ...target, value: "../main.ts", exists: true })).toBe(false);
});
+
+ test("the IDE editor opens workspace code, Markdown and HTML; other previews and outside paths keep the panel", () => {
+ const found = { ...target, exists: true };
+ expect(opensInIdeEditor(found)).toBe(true);
+ expect(opensInIdeEditor({ ...found, value: "docs/a.md", preview: "markdown" })).toBe(true);
+ expect(opensInIdeEditor({ ...found, value: "shot.png", preview: "image" } as OpenTarget)).toBe(false);
+ expect(opensInIdeEditor({ ...found, value: "/etc/hosts" })).toBe(false);
+ expect(opensInIdeEditor({ ...found, value: "../x.ts" })).toBe(false);
+ expect(opensInIdeEditor(target)).toBe(false);
+ });
});
diff --git a/evals/specs/artifact-code-browser.e2e.test.ts b/evals/specs/artifact-code-browser.e2e.test.ts
index 08c9a691..7227108b 100644
--- a/evals/specs/artifact-code-browser.e2e.test.ts
+++ b/evals/specs/artifact-code-browser.e2e.test.ts
@@ -55,4 +55,26 @@ test("artifact editor renders code with Pierre and browses workspace files", asy
"No error dialog, blank artifact surface, or crash message is visible",
]);
});
+
+ await step("A resolved code target opens in the IDE editor and still previews in Chat layout", async () => {
+ await user.click("IDE");
+ await user.see("Editor views");
+ await world.openCodeTarget();
+ const ide = await eventually(() => world.fileOpenSurface(), {
+ within: 30_000,
+ until: (value) => value.ide && value.editorFile && !value.artifactVisible,
+ });
+ expect(ide).toEqual({ ide: true, editorFile: true, artifactVisible: false });
+ evidence.recordAssertionEvidence("Code file targets use the active IDE editor instead of the artifact side panel", JSON.stringify(ide), true);
+
+ await user.click("Chat");
+ await world.openCodeTarget();
+ const chat = await eventually(() => world.fileOpenSurface(), {
+ within: 30_000,
+ until: (value) => !value.ide && value.artifactVisible,
+ });
+ expect(chat.ide).toBe(false);
+ expect(chat.artifactVisible).toBe(true);
+ evidence.recordAssertionEvidence("Chat layout retains its file preview", JSON.stringify(chat), true);
+ });
});
diff --git a/evals/worlds/first-run.ts b/evals/worlds/first-run.ts
index 99df9353..d088a3e2 100644
--- a/evals/worlds/first-run.ts
+++ b/evals/worlds/first-run.ts
@@ -327,6 +327,22 @@ export async function artifactCodeBrowserWorld(seed: Seed) {
if (!isRecord(tabs) || tabs.ok !== true) throw new Error(`Could not seed artifact tabs: ${JSON.stringify(tabs)}`);
return {
...base,
+ async openCodeTarget() {
+ await seed.evalIn(base.app, () => {
+ window.dispatchEvent(new CustomEvent("omnirush-open-accessible-target", { detail: {
+ id: "file:src/omnirush-artifact-proof.ts", kind: "file", value: "src/omnirush-artifact-proof.ts",
+ name: "omnirush-artifact-proof.ts", preview: "code", confidence: 100, reason: "tool output",
+ } }));
+ });
+ },
+ async fileOpenSurface() {
+ return seed.evalIn(base.app, () => ({
+ ide: Boolean(document.querySelector('[data-layout="ide"]')),
+ editorFile: Boolean(document.querySelector('[data-editor-tab="file:src/omnirush-artifact-proof.ts"][aria-selected="true"]')),
+ artifactVisible: [...document.querySelectorAll<HTMLElement>("[data-artifact-code-view]")]
+ .some((node) => node.getBoundingClientRect().height > 0),
+ }));
+ },
async visibleArtifactCode() {
return seed.evalIn(base.app, () => {
const root = document.querySelector<HTMLElement>("[data-artifact-code-view]");