Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): Ctrl+click on a drive-less path opens the file, not the folder tree (#803)
Ruben Lütkeaf828b32cfe9
diff --git a/dodaios/ui/web/agentic_ide_routes.py b/dodaios/ui/web/agentic_ide_routes.pyindex 09b01ee721..01084957e0 100644--- a/dodaios/ui/web/agentic_ide_routes.py+++ b/dodaios/ui/web/agentic_ide_routes.py@@ -2759,22 +2759,29 @@ async def reveal_terminal_target(return await _launch_terminal_target(request, req, reveal=True)-def _grant_outside_file(folder: str, printed: str) -> str:- """The editor path for a modifier-clicked file, granting it if it is outside."""+def _grant_outside_file(folder: str, printed: str) -> tuple[str, str]:+ """What a modifier-clicked path is: (editor path, "file" or "directory").++ A file outside the workspace is granted to the editor. A folder only counts+ inside the workspace, where the Folder tab can show it.+ """candidate = _printed_path(printed)root = Path(folder).expanduser().resolve(strict=True)if not candidate.is_absolute():# Agents often name a file in the person's home folder without it# ("Downloads\notes.md"); the workspace still wins when both exist.- inside = root / candidate+ local = root / candidatehome = Path.home() / candidate- candidate = inside if inside.exists() or not home.is_file() else home+ candidate = local if local.exists() or not home.is_file() else hometarget = candidate.resolve(strict=True)+ inside = target.is_relative_to(root)+ if inside and target.is_dir() and target != root:+ return target.relative_to(root).as_posix(), "directory"if not target.is_file():raise ValueError("not a file")- if target.is_relative_to(root):- return target.relative_to(root).as_posix()- return outside_files.grant(folder, target)+ if inside:+ return target.relative_to(root).as_posix(), "file"+ return outside_files.grant(folder, target), "file"@router.post(@@ -2798,12 +2805,12 @@ async def grant_outside_file()folder = _workspace_folder(workspace_id)try:- path = await asyncio.to_thread(_grant_outside_file, folder, req.path)+ path, kind = await asyncio.to_thread(_grant_outside_file, folder, req.path)except (OSError, RuntimeError, ValueError) as exc:# EditError is a ValueError too. One answer for every refusal.raise HTTPException(status_code=404, detail="That file is unavailable.") from exclog.info("Agentic IDE editor: opened file workspace=%s path=%s", workspace_id, path)- return {"workspace_id": workspace_id, "path": path}+ return {"workspace_id": workspace_id, "path": path, "kind": kind}@router.get("/recents", response_model=RecentsResponse, summary="Recently opened workspaces")diff --git a/dodaios/ui/web/frontend/src/components/agentic/editor/editorApi.ts b/dodaios/ui/web/frontend/src/components/agentic/editor/editorApi.tsindex c66d614583..b7c362a67a 100644--- a/dodaios/ui/web/frontend/src/components/agentic/editor/editorApi.ts+++ b/dodaios/ui/web/frontend/src/components/agentic/editor/editorApi.ts@@ -81,13 +81,19 @@ export function isOutsidePath(path: string): boolean {}/**- * Let the editor open a file Ctrl+clicked in a terminal, even outside the- * workspace. Answers the path the editor names it by: relative for a- * workspace file, absolute for one outside it.+ * Let the editor open a path Ctrl+clicked in a terminal, even a file outside+ * the workspace. Answers the path the editor names it by (relative inside+ * the workspace, absolute outside) and whether it is a file or a folder.*/-export async function openOutsideFile(workspaceId: string, printed: string): Promise<string> {- const answer = await send<{ path: string }>(`${base(workspaceId)}/outside-files`, json("POST", { path: printed }));- return answer.path;+export async function openOutsideFile(+ workspaceId: string,+ printed: string,+): Promise<{ path: string; kind: "file" | "directory" }> {+ const answer = await send<{ path: string; kind?: "file" | "directory" }>(+ `${base(workspaceId)}/outside-files`,+ json("POST", { path: printed }),+ );+ return { path: answer.path, kind: answer.kind ?? "file" };}/** `encoding` forces how the bytes are read ("Reopen with encoding"). */diff --git a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/explorer/ExplorerPanel.test.tsx b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/explorer/ExplorerPanel.test.tsxindex 06f3f6cf8e..f0d2735a22 100644--- a/dodaios/ui/web/frontend/src/components/agentic/sidePanel/explorer/ExplorerPanel.test.tsx+++ b/dodaios/ui/web/frontend/src/components/agentic/sidePanel/explorer/ExplorerPanel.test.tsx@@ -36,8 +36,13 @@ const TOKEN = "0123456789abcdef01234567";function respond(url: string, body: string): unknown {if (url.includes("/changes")) return CHANGES;- if (url.endsWith("/outside-files")) return { path: JSON.parse(body).path.replace(/:\d+$/, "").replace(/\\/g, "/") };- if (url.includes("/text-file/version")) return { version: url.includes("src") ? null : "v1" };+ if (url.endsWith("/outside-files")) {+ const printed: string = JSON.parse(body).path.replace(/:\d+$/, "").replace(/\\/g, "/");+ if (printed.includes("missing")) return { __status: 404, detail: "That file is unavailable." };+ if (/^src\/?$/.test(printed)) return { path: "src", kind: "directory" };+ return { path: printed.startsWith("Downloads/") ? `C:/Users/me/${printed}` : printed, kind: "file" };+ }+ if (url.includes("/text-file/version")) return { version: /src|Downloads|missing/.test(url) ? null : "v1" };if (url.endsWith("/entries/move")) return { path: JSON.parse(body).destination };if (url.endsWith("/entries/copy")) return { path: JSON.parse(body).destination.replace(/(\.\w+)$/, " copy$1") };if (url.endsWith("/entries/delete")) return { path: JSON.parse(body).path, trashed: true, undo_token: TOKEN };@@ -64,7 +69,9 @@ beforeEach(() => {const url = String(input);const body = String(init?.body ?? "");calls.push({ url, body });- return new Response(JSON.stringify(respond(url, body)), { status: 200, headers: { "Content-Type": "application/json" } });+ const answer = respond(url, body) as { __status?: number } | null;+ const status = answer && typeof answer === "object" && answer.__status ? answer.__status : 200;+ return new Response(JSON.stringify(answer), { status, headers: { "Content-Type": "application/json" } });}));useEventStore.setState({ activeSection: "agentic-ide" });useIdeChatStore.setState({ workspace: { id: "w1", name: "App", path: "/code/app" }, stagedPane: null });@@ -459,6 +466,25 @@ describe("terminal path clicks", () => {expect(calls.some((call) => call.url.includes("terminal-target"))).toBe(false);});+ it("open a home-folder file named without its drive, not the workspace tree", async () => {+ renderHook(() => useExplorerPathRouting());+ act(() =>+ activateTerminalLink(new MouseEvent("click", { button: 0, ctrlKey: true }), "Downloads\\TODO.md", { workspaceId: "w1" }),+ );+ await waitFor(() => expect(useCodeEditorStore.getState().tabs.map((tab) => tab.path)).toEqual(["C:/Users/me/Downloads/TODO.md"]));+ expect(useIdeSidePanelStore.getState().active).not.toBe("files");+ });++ it("report a missing file instead of showing the folder tree", async () => {+ renderHook(() => useExplorerPathRouting());+ act(() =>+ activateTerminalLink(new MouseEvent("click", { button: 0, ctrlKey: true }), "docs/missing.md", { workspaceId: "w1" }),+ );+ await waitFor(() => expect(useEventStore.getState().toasts.some((toast) => toast.message === "That file is unavailable.")).toBe(true));+ expect(useCodeEditorStore.getState().tabs).toEqual([]);+ expect(useIdeSidePanelStore.getState().active).not.toBe("files");+ });+it("fall back to the OS for another workspace's pane", () => {renderHook(() => useExplorerPathRouting());activateTerminalLink(new MouseEvent("click", { button: 0, ctrlKey: true }), "src/app.ts", { workspaceId: "w9" });diff --git a/dodaios/ui/web/frontend/src/store/ideExplorer.ts b/dodaios/ui/web/frontend/src/store/ideExplorer.tsindex 4cee011341..31985d8b45 100644--- a/dodaios/ui/web/frontend/src/store/ideExplorer.ts+++ b/dodaios/ui/web/frontend/src/store/ideExplorer.ts@@ -2,7 +2,6 @@ import { useEffect } from "react";import { create } from "zustand";import { fetchFileVersion, openOutsideFile } from "@/components/agentic/editor/editorApi";-import { openTerminalTarget } from "@/lib/agenticIdeApi";import { OPEN_PATH_EVENT } from "@/lib/terminalLinks";import { useCodeEditorStore } from "@/store/codeEditor";import { useEventStore } from "@/store/events";@@ -104,45 +103,39 @@ export function parsePrintedPath(workspaceRoot: string, printed: string): Printe/*** Open what a terminal path points at: a file in the editor (at its line), a* folder in the Folder tab. A file outside the workspace (a note saved to- * Downloads) opens in the editor too; anything else goes to the system app.+ * Downloads) opens in the editor too; a path that is not there is reported.*/export async function openPrintedPath(workspaceId: string, workspaceRoot: string, printed: string): Promise<void> {const parsed = parsePrintedPath(workspaceRoot, printed);- const external = () =>- openTerminalTarget(workspaceId, printed).catch((error: unknown) =>- useEventStore.getState().pushToast("error", (error as Error).message),- );- if (parsed.path === null) {- let path: string;- try {- path = await openOutsideFile(workspaceId, printed);- } catch {- await external();- return;- }+ const open = (path: string) =>useCodeEditorStore.getState().openFile(workspaceId, path, {preview: false,line: parsed.line,column: parsed.column,});- return;+ if (parsed.path !== null) {+ // The common case: a file inside the workspace opens straight away.+ try {+ if ((await fetchFileVersion(workspaceId, parsed.path)) !== null) {+ open(parsed.path);+ return;+ }+ } catch {+ /* the server decides below */+ }}- let version: string | null;+ // Anything else: the server finds the file, in the workspace, by absolute+ // path, or in the home folder (Downloads/notes.md), and says what it is.+ // A missing file is reported, never shown as the workspace's folder tree.+ let found: { path: string; kind: "file" | "directory" };try {- version = await fetchFileVersion(workspaceId, parsed.path);- } catch {- await external();- return;- }- if (version === null) {- revealInExplorer({ workspaceId, path: parsed.path });+ found = await openOutsideFile(workspaceId, printed);+ } catch (error) {+ useEventStore.getState().pushToast("error", (error as Error).message);return;}- useCodeEditorStore.getState().openFile(workspaceId, parsed.path, {- preview: false,- line: parsed.line,- column: parsed.column,- });+ if (found.kind === "directory") revealInExplorer({ workspaceId, path: found.path });+ else open(found.path);}/**diff --git a/tests/unit/agentic_ide/test_outside_files.py b/tests/unit/agentic_ide/test_outside_files.pyindex 58bf885960..fa00082125 100644--- a/tests/unit/agentic_ide/test_outside_files.py+++ b/tests/unit/agentic_ide/test_outside_files.py@@ -134,7 +134,13 @@ def test_a_file_inside_the_workspace_answers_its_relative_path(workspace: Path)inner = workspace / "src" / "app.py"inner.parent.mkdir()inner.write_text("x = 1\n", encoding="utf-8")- assert _grant(str(inner))["path"] == "src/app.py"+ assert _grant(str(inner)) == {"workspace_id": "w1", "path": "src/app.py", "kind": "file"}+ # A folder inside the workspace is named for the Folder tab, not granted.+ assert _grant("src/")["kind"] == "directory"+ assert _grant("src")["path"] == "src"+ # The workspace root itself is not a target.+ with pytest.raises(HTTPException):+ _grant(".")def test_a_home_relative_path_finds_the_file_in_the_home_folder(