Skip to content

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.

feat(agentic-ide): open a printed path with a plain click (#853)

Ruben Lütkec36088f6fbe7
diff --git a/docs/code-editor.md b/docs/code-editor.md
index 15161af665..ec5d0b1090 100644
--- a/docs/code-editor.md
+++ b/docs/code-editor.md
@@ -9,6 +9,7 @@ terminals back without closing a file.
| Action | How |
| --- | --- |
| Open a file | Click it in the side panel's **Folder** tab, or **Ctrl+P** and type part of its name (`name:42` jumps to line 42) |
+| Open a file an agent printed | Click its path in a terminal: the file opens here, at the printed line. Dragging across a path to select it does not open it. **Ctrl/Cmd+click** opens web links, and hands a path to the system app when the editor is not on screen |
| Edit and save | Type, then **Ctrl+S** (**Ctrl+Shift+S** saves every open file). A dot on the tab means unsaved changes |
| New file / new folder | The buttons in the Folder tab's header, or right-click. The entry goes into the selected folder, next to the selected file, or into the workspace root when nothing is selected. A name with slashes (`src/new.py`) creates the folders on the way |
| Rename | **F2** or right-click |
diff --git a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 2345aa9835..1d9c78c702 100644
--- a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -1004,9 +1004,10 @@ export function AgenticTerminal({
const linkOptions = {
workspaceId,
onError: (message: string) => onAttachErrorRef.current?.(message),
+ hasSelection: (): boolean => term.hasSelection(),
};
const activateLink = createTerminalLinkActivator(linkOptions);
- const term = new Terminal({
+ const term: Terminal = new Terminal({
convertEol: false,
// A dark pane keeps the canvas clear so the shared section glass and the
// desktop artwork show through. A light pane is opaque: xterm rasterises
@@ -1052,9 +1053,9 @@ export function AgenticTerminal({
// Instant scrolling: an agent that redraws a live status line while
// animating a scroll leaves visible tearing.
smoothScrollDuration: 0,
- // Plain clicks belong to text selection. xterm otherwise treats an
- // ordinary click on an OSC-8 link as navigation and shows a native
- // warning dialog inside the desktop WebView.
+ // Our own activator decides what a click opens (./../../lib/terminalLinks).
+ // xterm otherwise treats an ordinary click on an OSC-8 link as
+ // navigation and shows a native warning dialog inside the desktop WebView.
linkHandler: createTerminalOscLinkHandler(linkOptions),
// Lets Option force a selection on macOS while a CLI has mouse tracking
// on — the chord ./terminalMouseSelection marks every plain press with.
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.tsx
index f0d2735a22..c687689616 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
@@ -491,6 +491,13 @@ describe("terminal path clicks", () => {
expect(useCodeEditorStore.getState().tabs).toEqual([]);
expect(calls.some((call) => call.url.includes("terminal-target"))).toBe(true);
});
+
+ it("open a printed file on a plain click, without the OS opener", async () => {
+ renderHook(() => useExplorerPathRouting());
+ act(() => activateTerminalLink(new MouseEvent("click", { button: 0 }), "README.md", { workspaceId: "w1" }));
+ await waitFor(() => expect(useCodeEditorStore.getState().tabs).toMatchObject([{ path: "README.md" }]));
+ expect(calls.some((call) => call.url.includes("terminal-target"))).toBe(false);
+ });
});
describe("parsePrintedPath", () => {
diff --git a/dodaios/ui/web/frontend/src/lib/terminalLinks.test.ts b/dodaios/ui/web/frontend/src/lib/terminalLinks.test.ts
index b2d2626417..2e9057cf93 100644
--- a/dodaios/ui/web/frontend/src/lib/terminalLinks.test.ts
+++ b/dodaios/ui/web/frontend/src/lib/terminalLinks.test.ts
@@ -19,6 +19,7 @@ import {
createTerminalLinkActivator,
createTerminalOscLinkHandler,
findTerminalPathMatches,
+ OPEN_PATH_EVENT,
TERMINAL_OSC_LINK_HANDLER,
TerminalPathLinksAddon,
} from "./terminalLinks";
@@ -90,6 +91,37 @@ describe("terminal links", () => {
);
});
+ it("offers a plainly clicked path to the app and never to the OS", () => {
+ const seen: unknown[] = [];
+ const onOpen = (event: Event) => seen.push((event as CustomEvent).detail);
+ window.addEventListener(OPEN_PATH_EVENT, onOpen);
+ activateTerminalLink(click(), "C:\\Users\\me\\Downloads\\shot.jpg", {
+ workspaceId: "workspace-1",
+ });
+ window.removeEventListener(OPEN_PATH_EVENT, onOpen);
+
+ expect(seen).toEqual([
+ {
+ workspaceId: "workspace-1",
+ path: "C:\\Users\\me\\Downloads\\shot.jpg",
+ launch: false,
+ },
+ ]);
+ expect(openTarget).not.toHaveBeenCalled();
+ });
+
+ it("keeps the click that ends a text selection from opening a path", () => {
+ const onOpen = vi.fn();
+ window.addEventListener(OPEN_PATH_EVENT, onOpen);
+ activateTerminalLink(click(), "src/main.ts", {
+ workspaceId: "workspace-1",
+ hasSelection: () => true,
+ });
+ window.removeEventListener(OPEN_PATH_EVENT, onOpen);
+
+ expect(onOpen).not.toHaveBeenCalled();
+ });
+
it("allows file OSC-8 links only when a workspace boundary is available", () => {
const handler = createTerminalOscLinkHandler({
workspaceId: "workspace-1",
@@ -154,6 +186,14 @@ describe("terminal links", () => {
).toEqual(["README.md", "./scripts", "../shared", "assets/icons/"]);
});
+ it("recognises bare image and video filenames", () => {
+ expect(
+ findTerminalPathMatches("Saved demo.mp4 and cover.avif").map(
+ (match) => match.text,
+ ),
+ ).toEqual(["demo.mp4", "cover.avif"]);
+ });
+
it("registers detected paths as xterm links with clickable cell ranges", () => {
const text = "Open src/main.ts:42";
const cell = {
diff --git a/dodaios/ui/web/frontend/src/lib/terminalLinks.ts b/dodaios/ui/web/frontend/src/lib/terminalLinks.ts
index 272ac0c5f5..5eafc55ebb 100644
--- a/dodaios/ui/web/frontend/src/lib/terminalLinks.ts
+++ b/dodaios/ui/web/frontend/src/lib/terminalLinks.ts
@@ -13,15 +13,16 @@ import { openExternalUrl } from "@/lib/openExternal";
import { translate } from "@/i18n";
/**
- * Raised for a Ctrl/Cmd-clicked local path before the OS opener runs. A
- * listener that shows the file in the app (the IDE's Explorer) calls
- * `preventDefault()`, and the OS opener is skipped.
+ * Raised for a clicked local path before the OS opener runs. A listener that
+ * shows the file in the app (the IDE's editor and Explorer) calls
+ * `preventDefault()`, and the OS opener is skipped. `detail.launch` says
+ * whether Ctrl/Cmd was held, the only click that may hand a file to the OS.
*/
export const OPEN_PATH_EVENT = "jarvis:ide-open-path";
const MAX_LOGICAL_LINE_CHARS = 4096;
-const BARE_FILE = /^(?:(?:readme|license|makefile|dockerfile|containerfile)|[^/\\]+\.(?:c|cc|cpp|h|hpp|cs|go|rs|java|kt|kts|swift|php|rb|py|pyi|js|mjs|cjs|jsx|ts|mts|cts|tsx|vue|svelte|html?|css|scss|sass|less|json|jsonl|ya?ml|toml|xml|md|mdx|txt|log|csv|tsv|sql|sh|bash|zsh|fish|ps1|bat|cmd|ini|cfg|conf|env|lock|diff|patch|pdf|png|jpe?g|gif|svg|webp))(?::[1-9]\d*(?::[1-9]\d*)?|#L[1-9]\d*(?::[1-9]\d*)?|\([1-9]\d*(?:,[1-9]\d*)?\))?$/i;
+const BARE_FILE = /^(?:(?:readme|license|makefile|dockerfile|containerfile)|[^/\\]+\.(?:c|cc|cpp|h|hpp|cs|go|rs|java|kt|kts|swift|php|rb|py|pyi|js|mjs|cjs|jsx|ts|mts|cts|tsx|vue|svelte|html?|css|scss|sass|less|json|jsonl|ya?ml|toml|xml|md|mdx|txt|log|csv|tsv|sql|sh|bash|zsh|fish|ps1|bat|cmd|ini|cfg|conf|env|lock|diff|patch|pdf|png|jpe?g|gif|svg|webp|bmp|avif|ico|mp4|m4v|mov|webm|ogv|mp3|wav|ogg|m4a|flac))(?::[1-9]\d*(?::[1-9]\d*)?|#L[1-9]\d*(?::[1-9]\d*)?|\([1-9]\d*(?:,[1-9]\d*)?\))?$/i;
const LOCATION_SUFFIX = /(?:#[lL][1-9]\d*(?::[1-9]\d*)?|:[1-9]\d*(?::[1-9]\d*)?|\([1-9]\d*(?:,[1-9]\d*)?\))$/;
@@ -29,6 +30,11 @@ export interface TerminalLinkOptions {
/** Required for local paths; URLs do not need workspace context. */
workspaceId?: string;
onError?: (message: string) => void;
+ /**
+ * Does the terminal hold a text selection? The release that ends a drag
+ * across a path selected text; it did not ask to open the file.
+ */
+ hasSelection?: () => boolean;
}
export interface TerminalPathMatch {
@@ -71,30 +77,35 @@ function errorMessage(error: unknown): string {
}
/**
- * Activate a terminal URL/path only on the conventional Ctrl/Cmd primary click.
+ * Activate a terminal URL or path from a primary click.
*
- * Ordinary clicks stay available for terminal selection. Paths additionally
- * require a workspace id; the backend resolves and confines them there before
- * it invokes the OS opener.
+ * A plain click on a path shows it inside the app: the editor, with its image
+ * and video viewers. Anything that leaves the app stays on the conventional
+ * Ctrl/Cmd-click, since terminal output is untrusted: a web link, and a path
+ * handed to the OS opener, which the backend first confines to the pane's own
+ * workspace. Paths need a workspace id either way.
*/
export function activateTerminalLink(
event: MouseEvent,
uri: string,
options: TerminalLinkOptions = {},
): void {
- if (event.button !== 0 || (!event.ctrlKey && !event.metaKey)) return;
+ if (event.button !== 0) return;
+ const launch = event.ctrlKey || event.metaKey;
if (isHttpUrl(uri)) {
- void openExternalUrl(uri);
+ if (launch) void openExternalUrl(uri);
return;
}
if (!options.workspaceId || !isTerminalPath(uri)) return;
- // The IDE's Explorer shows the file — with its diff — when it is mounted; it
- // answers by cancelling the event. Otherwise the OS opens it as before.
+ if (!launch && options.hasSelection?.()) return;
+ // The IDE shows the file when it is mounted; it answers by cancelling the
+ // event. Otherwise a Ctrl/Cmd-click lets the OS open it as before.
const routed = new CustomEvent(OPEN_PATH_EVENT, {
cancelable: true,
- detail: { workspaceId: options.workspaceId, path: uri },
+ detail: { workspaceId: options.workspaceId, path: uri, launch },
});
if (!window.dispatchEvent(routed)) return;
+ if (!launch) return;
void openTerminalTarget(options.workspaceId, uri).catch((error: unknown) => {
const message = errorMessage(error);
if (options.onError) options.onError(message);