diff --git a/src/main/runtime/orca-runtime-files.test.ts b/src/main/runtime/orca-runtime-files.test.ts index 313b3a7bd..6d8809cf4 100644 --- a/src/main/runtime/orca-runtime-files.test.ts +++ b/src/main/runtime/orca-runtime-files.test.ts @@ -182,7 +182,7 @@ describe('RuntimeFileCommands', () => { vi.useRealTimers() }) - it('opens source control diffs through the renderer host', async () => { + it('opens source control diffs through the renderer host (inheriting active runtime env)', async () => { const openDiff = vi.fn() const { commands } = createRuntimeFileCommands({ openDiff }) @@ -193,7 +193,7 @@ describe('RuntimeFileCommands', () => { '/repo/docs/readme.md', 'docs/readme.md', true, - 'runtime-1' + undefined ) expect(result).toEqual({ worktree: 'wt-1', @@ -203,7 +203,7 @@ describe('RuntimeFileCommands', () => { }) }) - it('opens text files through the renderer host with the runtime owner', async () => { + it('opens text files through the renderer host (inheriting active runtime env)', async () => { const openFile = vi.fn() const { commands } = createRuntimeFileCommands({ openFile }) @@ -213,7 +213,7 @@ describe('RuntimeFileCommands', () => { 'wt-1', '/repo/docs/readme.md', 'docs/readme.md', - 'runtime-1' + undefined ) expect(result).toEqual({ worktree: 'wt-1', diff --git a/src/main/runtime/orca-runtime-files.ts b/src/main/runtime/orca-runtime-files.ts index dc5738a4e..99aab104b 100644 --- a/src/main/runtime/orca-runtime-files.ts +++ b/src/main/runtime/orca-runtime-files.ts @@ -124,14 +124,14 @@ export type RuntimeFileCommandHost = { worktreeId: string, filePath: string, relativePath: string, - runtimeEnvironmentId: string + runtimeEnvironmentId?: string | null ): void openDiff( worktreeId: string, filePath: string, relativePath: string, staged: boolean, - runtimeEnvironmentId: string + runtimeEnvironmentId?: string | null ): void } @@ -184,7 +184,13 @@ export class RuntimeFileCommands { return { worktree: worktree.id, relativePath, kind, opened: false } } const filePath = joinWorktreeRelativePath(worktree.path, relativePath) - this.host.openFile(worktree.id, filePath, relativePath, this.host.getRuntimeId()) + // Why: the service's internal runtimeId is not a registered runtime env selector + // (those live in orca-environments.json). Passing it caused Unknown environment + // errors on content load for CLI-initiated opens (via files.open from orca cli + // used by agents). Instead pass undefined so the renderer openFile falls back to + // the current activeRuntimeEnvironmentId (or null), matching sidebar opens and + // allowing correct routing for local vs remote envs. + this.host.openFile(worktree.id, filePath, relativePath, undefined) return { worktree: worktree.id, relativePath, kind, opened: true } } @@ -203,7 +209,8 @@ export class RuntimeFileCommands { ? 'markdown' : 'text' const filePath = joinWorktreeRelativePath(worktree.path, relativePath) - this.host.openDiff(worktree.id, filePath, relativePath, staged, this.host.getRuntimeId()) + // Why: see openMobileFile; avoid stamping internal runtimeId as runtimeEnvironmentId. + this.host.openDiff(worktree.id, filePath, relativePath, staged, undefined) return { worktree: worktree.id, relativePath, kind, opened: true } } diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index 29a6ab038..2444fe05a 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -790,14 +790,14 @@ type RuntimeNotifier = { worktreeId: string, filePath: string, relativePath: string, - runtimeEnvironmentId: string + runtimeEnvironmentId?: string | null ): void openDiff?( worktreeId: string, filePath: string, relativePath: string, staged: boolean, - runtimeEnvironmentId: string + runtimeEnvironmentId?: string | null ): void readMobileMarkdownTab?(worktreeId: string, tabId: string): Promise saveMobileMarkdownTab?( diff --git a/src/main/window/attach-main-window-services.ts b/src/main/window/attach-main-window-services.ts index 478cc1638..4b03bcdd1 100644 --- a/src/main/window/attach-main-window-services.ts +++ b/src/main/window/attach-main-window-services.ts @@ -272,14 +272,14 @@ function registerRuntimeWindowLifecycle( closeSessionTab: (tabId, worktreeId) => send('ui:closeSessionTab', { tabId, worktreeId }), moveSessionTab: (worktreeId: string, move: RuntimeMobileSessionTabMove) => send('ui:moveSessionTab', { worktreeId, ...move }), - openFile: (worktreeId, filePath, relativePath, runtimeEnvironmentId) => + openFile: (worktreeId, filePath, relativePath, runtimeEnvironmentId?) => send('ui:openFileFromMobile', { worktreeId, filePath, relativePath, runtimeEnvironmentId }), - openDiff: (worktreeId, filePath, relativePath, staged, runtimeEnvironmentId) => + openDiff: (worktreeId, filePath, relativePath, staged, runtimeEnvironmentId?) => send('ui:openDiffFromMobile', { worktreeId, filePath, diff --git a/src/preload/api-types.ts b/src/preload/api-types.ts index 0a735bc10..5d67fda2c 100644 --- a/src/preload/api-types.ts +++ b/src/preload/api-types.ts @@ -2167,7 +2167,7 @@ export type PreloadApi = { worktreeId: string filePath: string relativePath: string - runtimeEnvironmentId: string + runtimeEnvironmentId?: string }) => void ) => () => void onOpenDiffFromMobile: ( @@ -2176,7 +2176,7 @@ export type PreloadApi = { filePath: string relativePath: string staged: boolean - runtimeEnvironmentId: string + runtimeEnvironmentId?: string }) => void ) => () => void onMobileMarkdownRequest: ( diff --git a/src/preload/index.ts b/src/preload/index.ts index b968e9e66..a77c9ecbf 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -2851,7 +2851,7 @@ const api = { worktreeId: string filePath: string relativePath: string - runtimeEnvironmentId: string + runtimeEnvironmentId?: string }) => void ): (() => void) => { const listener = ( @@ -2860,7 +2860,7 @@ const api = { worktreeId: string filePath: string relativePath: string - runtimeEnvironmentId: string + runtimeEnvironmentId?: string } ) => callback(data) ipcRenderer.on('ui:openFileFromMobile', listener) @@ -2872,7 +2872,7 @@ const api = { filePath: string relativePath: string staged: boolean - runtimeEnvironmentId: string + runtimeEnvironmentId?: string }) => void ): (() => void) => { const listener = ( @@ -2882,7 +2882,7 @@ const api = { filePath: string relativePath: string staged: boolean - runtimeEnvironmentId: string + runtimeEnvironmentId?: string } ) => callback(data) ipcRenderer.on('ui:openDiffFromMobile', listener)