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): a typed path is read like cd, and checked before it is chosen
Harald193bb3ac5079
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.pyindex 88010333f4..b27da287a4 100644--- a/jarvis/ui/web/agentic_ide_routes.py+++ b/jarvis/ui/web/agentic_ide_routes.py@@ -56,6 +56,7 @@ from __future__ import annotationsimport asyncioimport loggingimport mimetypes+import osimport reimport timefrom dataclasses import asdict@@ -1262,7 +1263,10 @@ async def get_folders(path: str | None = None, include_hidden: bool = False) ->)found, error = await asyncio.to_thread(list_dir, path, include_hidden=include_hidden)- resolved = Path(path).expanduser() # noqa: ASYNC240 - no filesystem call+ # Lexical only (no filesystem call): `~` becomes the home folder and a typed+ # `..` folds away, so the path handed back — and chosen as the workspace —+ # is the folder itself, not the route someone took to it.+ resolved = Path(os.path.normpath(Path(path).expanduser())) # noqa: ASYNC240parent = str(resolved.parent) if resolved.parent != resolved else Nonereturn FoldersResponse(path=str(resolved),diff --git a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.test.tsxindex 6ba8a19d8d..89f1033435 100644--- a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.test.tsx@@ -14,7 +14,10 @@ vi.mock("@/lib/agenticIdeApi", () => ({import {FolderPicker,extractDropPayload,+ isAbsolutePath,joinPath,+ normalizeTypedPath,+ resolveTypedPath,separatorOf,splitTypedPath,} from "./FolderPicker";@@ -400,12 +403,51 @@ describe("typing a path", () => {await waitFor(() => expect(input.value).toBe("/home/ruben/webshop/"));});+ it("reads what was typed the way a shell would", () => {+ // The field says "like cd" — so people type the cd. It is not part of the+ // path, and neither are the quotes around a path pasted from a terminal.+ expect(normalizeTypedPath("cd haral\\.personal-jarvis")).toBe(+ "haral\\.personal-jarvis",+ );+ expect(normalizeTypedPath("CD /d D:\\work")).toBe("D:\\work");+ expect(normalizeTypedPath('cd "C:\\My Projects\\shop"')).toBe(+ "C:\\My Projects\\shop",+ );+ expect(normalizeTypedPath(" notes ")).toBe("notes");+ expect(normalizeTypedPath("cd")).toBe("");+ // A folder that happens to start with "cd" is left alone.+ expect(normalizeTypedPath("cdrom")).toBe("cdrom");+ });++ it("knows which paths name their own root", () => {+ expect(isAbsolutePath("/srv/deploy")).toBe(true);+ expect(isAbsolutePath("C:\\work")).toBe(true);+ expect(isAbsolutePath("c:/work")).toBe(true);+ expect(isAbsolutePath("\\\\server\\share")).toBe(true);+ expect(isAbsolutePath("~/code")).toBe(true);+ expect(isAbsolutePath("haral\\.personal-jarvis")).toBe(false);+ expect(isAbsolutePath("notes")).toBe(false);+ });++ it("resolves a relative path against the folder on screen, like cd", () => {+ // The report: "cd haral\.personal-jarvis" typed while looking at C:\Users+ // used to be taken verbatim and reached the review step as the workspace.+ expect(resolveTypedPath("cd haral\\.personal-jarvis", "C:\\Users")).toBe(+ "C:\\Users\\haral\\.personal-jarvis",+ );+ expect(resolveTypedPath("notes", "/home/ruben")).toBe("/home/ruben/notes");+ expect(resolveTypedPath("/srv/deploy", "/home/ruben")).toBe("/srv/deploy");+ // Nothing on screen yet: the text goes through as typed.+ expect(resolveTypedPath("projects/shop", null)).toBe("projects/shop");+ expect(resolveTypedPath("cd", "/home/ruben")).toBe("");+ });+it("treats a bare name as relative to the folder on screen", async () => {- vi.mocked(api.fetchFolders).mockResolvedValue({+ vi.mocked(api.fetchFolders).mockImplementation(async (target) => ({...LISTING,- path: "/home/ruben",+ path: target ?? "/home/ruben",parent: "/home",- });+ }));const onSelect = vi.fn();render(<FolderPicker selected={null} onSelect={onSelect} />);await screen.findByText("webshop");@@ -428,4 +470,30 @@ describe("typing a path", () => {await waitFor(() => expect(onSelect).toHaveBeenCalledWith("/srv/deploy"));});++ it("does not choose a typed path that is not a folder", async () => {+ // Before: the text was selected first and listed second, so a typo — or a+ // whole "cd …" command — became the workspace with an error beside it.+ vi.mocked(api.fetchFolders).mockImplementation(async (target) =>+ target === "/home/ruben/nope"+ ? {+ path: "/home/ruben/nope",+ parent: "/home/ruben",+ entries: [],+ error: "Not a folder: /home/ruben/nope",+ device_name: "Rubens MacBook",+ }+ : { ...LISTING, path: "/home/ruben", parent: "/home" },+ );+ const onSelect = vi.fn();+ render(<FolderPicker selected={null} onSelect={onSelect} />);+ await screen.findByText("webshop");++ const input = screen.getByTestId("folder-path-input");+ fireEvent.change(input, { target: { value: "nope" } });+ fireEvent.keyDown(input, { key: "Enter" });++ expect(await screen.findByText(/Not a folder/)).toBeTruthy();+ expect(onSelect).not.toHaveBeenCalled();+ });});diff --git a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsxindex a7f0b2ace2..35ae957ba3 100644--- a/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/FolderPicker.tsx@@ -258,11 +258,32 @@ export function FolderPicker({void load(item.path);};+ /**+ * A typed path is checked before it is chosen. The old order — select first,+ * then list — let "cd haral\.personal-jarvis" (not a folder anywhere) reach+ * the review step as the workspace, with the error shown next to it. Now the+ * folder is listed first; only when it really is one does it become the+ * selection, and otherwise the message stays and the previous choice stands.+ */const usePath = (raw: string) => {const value = raw.trim();if (!value) return;- onSelect(value);- void load(value);+ setLoading(true);+ setError(null);+ fetchFolders(value)+ .then((res) => {+ if (res.device_name) setDeviceName(res.device_name);+ if (res.error) {+ setError(res.error);+ return;+ }+ setPath(res.path);+ setParent(res.parent);+ setEntries(res.entries);+ onSelect(res.path ?? value);+ })+ .catch((e) => setError((e as Error).message))+ .finally(() => setLoading(false));};const pickRecent = (recent: RecentWorkspace) => {@@ -644,6 +665,41 @@ export function joinPath(base: string, name: string): string {return base.endsWith(sep) ? `${base}${name}` : `${base}${sep}${name}`;}+/**+ * What was typed, read the way a shell would read it.+ *+ * The field says "like cd", so people type `cd projects` — the command word is+ * not part of the path and is dropped (with cmd's `/d`), and so are quotes+ * around a path pasted from a terminal.+ */+export function normalizeTypedPath(raw: string): string {+ let value = raw.trim();+ value = value.replace(/^cd(?:\s+\/d)?(?:\s+|$)/i, "").trim();+ const quoted = value.match(/^(["'])(.*)\1$/);+ if (quoted) value = quoted[2].trim();+ return value;+}++/** A path that names its own root: `/…`, `~…`, `C:\…`, or a UNC `\\server`. */+export function isAbsolutePath(value: string): boolean {+ return /^(?:[a-zA-Z]:[\\/]|[\\/]|~)/.test(value);+}++/**+ * The folder a typed path means, given the folder on screen.+ *+ * Anything that does not name its own root is relative to what the list shows+ * — `haral\.personal-jarvis` typed while looking at `C:\Users` is+ * `C:\Users\haral\.personal-jarvis`, exactly as `cd` would read it.+ * Without a folder on screen (the start view) the text is passed on as typed.+ */+export function resolveTypedPath(raw: string, base: string | null): string {+ const typed = normalizeTypedPath(raw);+ if (!typed) return "";+ if (isAbsolutePath(typed) || !base) return typed;+ return joinPath(base, typed);+}+/*** A path field that completes as you type, the way `cd` does in a terminal.*@@ -669,10 +725,15 @@ function PathInput({const [active, setActive] = useState(-1);const [open, setOpen] = useState(false);- const { dir, leaf } = splitTypedPath(value);+ const { dir, leaf } = splitTypedPath(normalizeTypedPath(value));// An empty `dir` means a bare name was typed: complete inside the folder the- // list is showing, which is what makes `cd projects` work.- const lookupDir = dir || base || "";+ // list is showing, which is what makes `cd projects` work; a relative folder+ // part completes inside that folder below the one on screen.+ const lookupDir = dir+ ? isAbsolutePath(dir) || !base+ ? dir+ : joinPath(base, dir)+ : base || "";useEffect(() => {if (!value.trim() && !base) {@@ -712,11 +773,10 @@ function PathInput({const submit = () => {if (active >= 0 && options[active]) {onUse(options[active].path);- } else if (value.trim()) {- // A bare name is relative to what is on screen, exactly as typed.- const typed = value.trim();- const absolute = dir || !base ? typed : joinPath(base, typed);- onUse(absolute);+ } else {+ // A relative path is relative to what is on screen, the way cd reads it.+ const absolute = resolveTypedPath(value, base);+ if (absolute) onUse(absolute);}setOpen(false);};diff --git a/tests/unit/web/test_agentic_ide_folders_route.py b/tests/unit/web/test_agentic_ide_folders_route.pynew file mode 100644index 0000000000..da9e0310a3--- /dev/null+++ b/tests/unit/web/test_agentic_ide_folders_route.py@@ -0,0 +1,35 @@+"""Browsing folders by a typed path — the answer is the folder, not the route.++The path field reads like ``cd``, so what arrives here can be ``~/code`` or+``projects/..``. The listing itself already coped; the PATH handed back is what+becomes the workspace, so it must be the folder's own name — home spelled out,+``..`` folded away — never the text someone happened to type.+"""++from __future__ import annotations++from pathlib import Path++from jarvis.ui.web import agentic_ide_routes as routes+++async def test_a_typed_dot_dot_folds_away(tmp_path: Path) -> None:+ (tmp_path / "sub").mkdir()++ res = await routes.get_folders(path=str(tmp_path / "sub" / ".."))++ assert res.error is None+ assert res.path == str(tmp_path)+++async def test_a_typed_tilde_becomes_the_home_folder() -> None:+ res = await routes.get_folders(path="~")++ assert res.path == str(Path.home())+++async def test_a_path_that_is_not_a_folder_is_reported_not_listed(tmp_path: Path) -> None:+ res = await routes.get_folders(path=str(tmp_path / "cd haral"))++ assert res.error and "Not a folder" in res.error+ assert res.entries == []