The VS Code of video editing, built for agents.
TypeScript
Remove agent detection and related functionality
konstantin-paulus50c8375a646d
diff --git a/apps/desktop/src/agent-detect.ts b/apps/desktop/src/agent-detect.tsdeleted file mode 100644index d85927a3..00000000--- a/apps/desktop/src/agent-detect.ts+++ /dev/null@@ -1,47 +0,0 @@-/* This Source Code Form is subject to the terms of the Mozilla Public- * License, v. 2.0. If a copy of the MPL was not distributed with this- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */--import { existsSync } from "node:fs";-import { homedir } from "node:os";-import { isAbsolute, join } from "node:path";--import { AGENTS, agentLink, findAgent, pickVariant } from "./agent-links";--import type { AgentLaunch, AgentVariant } from "./agent-links";-import type { AgentInfo } from "./main-channels";--function markerExists(marker: string): boolean {- return existsSync(isAbsolute(marker) ? marker : join(homedir(), marker));-}--/** Whether this app is on this machine and can answer its link. */-const variantAvailable = (variant: AgentVariant): boolean =>- variant.markers.some(markerExists);--/**- * Every agent we support, in the order they are offered, each saying whether- * anything on this machine answers its link. The unavailable ones are listed- * too: the picker shows them disabled rather than hiding them, so the list- * reads the same everywhere and names what is missing.- */-export function listAgents(): AgentInfo[] {- return AGENTS.map(({ id, label, folder, variants }) => ({- id,- label,- folder,- available: variants.some(variantAvailable),- }));-}--/**- * The deep link for the agent `id` — through the best of its apps that is- * installed — or null when there is no such agent or nothing to open it.- */-export function agentLaunchUrl(id: string, launch: AgentLaunch): string | null {- const agent = findAgent(id);- if (!agent) return null;-- const variant = pickVariant(agent, variantAvailable);- return variant ? agentLink(agent, variant, launch) : null;-}diff --git a/apps/desktop/src/agent-links.test.ts b/apps/desktop/src/agent-links.test.tsdeleted file mode 100644index 6d4b1dd1..00000000--- a/apps/desktop/src/agent-links.test.ts+++ /dev/null@@ -1,117 +0,0 @@-/* This Source Code Form is subject to the terms of the Mozilla Public- * License, v. 2.0. If a copy of the MPL was not distributed with this- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */--import { describe, expect, it } from "vitest";--import { AGENTS, agentLink, findAgent, pickVariant } from "./agent-links";--const agent = (id: string) => {- const found = findAgent(id);- if (!found) throw new Error(`no agent ${id}`);- return found;-};--/** The agent's link through one named app, as if only that one were installed. */-const link = (- id: string,- variantId: string,- prompt: string,- folder: string | null = "/Users/x/Movies/My Film",-) => {- const target = agent(id);- const variant = pickVariant(target, (entry) => entry.id === variantId);- if (!variant) throw new Error(`no variant ${variantId}`);- return agentLink(target, variant, { prompt, folder });-};--describe("agentLink", () => {- it("opens Claude in the desktop app's Code tab with q and folder", () => {- expect(link("claude", "claude-desktop", "cut the intro")).toBe(- "claude://code/new?q=cut%20the%20intro&folder=%2FUsers%2Fx%2FMovies%2FMy%20Film",- );- });-- it("falls back to the CLI handler, which takes the folder as cwd", () => {- expect(link("claude", "claude-code", "cut the intro")).toBe(- "claude-cli://open?cwd=%2FUsers%2Fx%2FMovies%2FMy%20Film&q=cut%20the%20intro",- );- });-- it("prefers the desktop app when both are there", () => {- expect(pickVariant(agent("claude"), () => true)?.id).toBe("claude-desktop");- });-- it("gives Codex prompt and path", () => {- expect(link("codex", "codex", "cut the intro")).toBe(- "codex://new?prompt=cut%20the%20intro&path=%2FUsers%2Fx%2FMovies%2FMy%20Film",- );- });-- it("gives Conductor its params without a query string", () => {- expect(link("conductor", "conductor", "cut the intro")).toBe(- "conductor://prompt=cut%20the%20intro&path=%2FUsers%2Fx%2FMovies%2FMy%20Film",- );- });-- it("names the folder in the prompt for agents whose link cannot carry one", () => {- expect(link("cursor", "cursor", "cut the intro")).toBe(- "cursor://anysphere.cursor-deeplink/prompt?text=Working%20directory%3A%20%2FUsers%2Fx%2FMovies%2FMy%20Film%0A%0Acut%20the%20intro",- );- });-- it("drops the params it has no value for", () => {- expect(link("claude", "claude-code", "hello", null)).toBe(- "claude-cli://open?q=hello",- );- expect(link("codex", "codex", "", null)).toBe("codex://new");- });-- it("keeps line breaks and specials out of the query string", () => {- expect(link("claude", "claude-code", "a&b\nc=d?e#f", null)).toBe(- "claude-cli://open?q=a%26b%0Ac%3Dd%3Fe%23f",- );- });-- it("caps the prompt at what the shortest link accepts", () => {- const url = new URL(link("claude", "claude-code", "x".repeat(6000), null));- expect(url.searchParams.get("q")).toHaveLength(5000);- });-- it("counts the folder line against that cap", () => {- const url = new URL(link("cursor", "cursor", "x".repeat(6000)));- expect(url.searchParams.get("text")).toHaveLength(5000);- });-- it("names dropped files and folders at the end of the prompt", () => {- const target = agent("claude");- const variant = pickVariant(target, (entry) => entry.id === "claude-code")!;- const url = new URL(- agentLink(target, variant, {- prompt: "cut the intro",- folder: null,- attachments: ["/Users/x/clip.mp4", "/Users/x/b-roll"],- }),- );- expect(url.searchParams.get("q")).toBe(- "cut the intro\n\nAttachments:\n- /Users/x/clip.mp4\n- /Users/x/b-roll",- );- });-- it("adds nothing for an empty attachment list", () => {- const target = agent("claude");- const variant = pickVariant(target, (entry) => entry.id === "claude-code")!;- expect(- agentLink(target, variant, { prompt: "hello", folder: null, attachments: [] }),- ).toBe("claude-cli://open?q=hello");- });-- it("gives every agent a unique id and every variant at least one marker", () => {- expect(new Set(AGENTS.map((a) => a.id)).size).toBe(AGENTS.length);- for (const a of AGENTS) {- expect(a.variants.length).toBeGreaterThan(0);- for (const variant of a.variants)- expect(variant.markers.length).toBeGreaterThan(0);- }- });-});diff --git a/apps/desktop/src/agent-links.ts b/apps/desktop/src/agent-links.tsdeleted file mode 100644index 2bc0e069..00000000--- a/apps/desktop/src/agent-links.ts+++ /dev/null@@ -1,177 +0,0 @@-/* This Source Code Form is subject to the terms of the Mozilla Public- * License, v. 2.0. If a copy of the MPL was not distributed with this- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */--/**- * What the user is handing over: the prompt, the folder to work in, and the- * files and folders dropped into the composer alongside it.- */-export type AgentLaunch = {- prompt: string;- /** Absolute path of the project folder, or null when there is none. */- folder: string | null;- /**- * Absolute paths of dropped files and folders. No link can carry these on- * its own, so they are named at the end of the prompt — the agent reads- * them from disk like anything else it is pointed at.- */- attachments?: readonly string[];-};--/**- * One app that can take an agent's link. An agent is usually a single app,- * but Claude is reachable through two — the desktop app and the CLI's URL- * handler — and the user does not care which is behind the button.- */-export type AgentVariant = {- /** Which app this is, for the tests; the renderer only sees the agent id. */- id: string;- /**- * Paths whose presence means this app can take a link on this machine:- * absolute, or home-relative when they do not start with a slash. Any one- * is enough.- */- markers: readonly string[];- link(launch: AgentLaunch): string;-};--export type AgentTarget = {- /** Stable id — what the renderer remembers the user's choice as. */- id: string;- label: string;- /**- * Whether the link can name the working directory itself. The rest get the- * folder as a line of the prompt instead — worse, but not silently wrong.- */- folder: boolean;- /** The apps that can take this agent's link, best first. */- variants: readonly AgentVariant[];-};--/** The non-empty params as one URL-encoded `a=1&b=2`. */-function params(values: Record<string, string | null>): string {- return Object.entries(values)- .filter((entry): entry is [string, string] => !!entry[1])- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)- .join("&");-}--/** `base` with the non-empty params appended as a query string. */-function query(base: string, values: Record<string, string | null>): string {- const search = params(values);- return search ? `${base}?${search}` : base;-}--// Ordered by how well the link fits what this app hands over — a working-// directory and a prompt — so the first available one is the default pick.-export const AGENTS: readonly AgentTarget[] = [- {- id: "claude",- label: "Claude Code",- folder: true,- variants: [- {- id: "claude-desktop",- markers: ["/Applications/Claude.app", "Applications/Claude.app"],- link: ({ prompt, folder }) =>- query("claude://code/new", { q: prompt, folder }),- },- {- id: "claude-code",- markers: [- "Applications/Claude Code URL Handler.app",- ".local/share/applications/claude-code-url-handler.desktop",- ],- link: ({ prompt, folder }) =>- query("claude-cli://open", { cwd: folder, q: prompt }),- },- ],- },- {- id: "codex",- label: "Codex",- folder: true,- variants: [- {- id: "codex",- // Codex ships standalone and inside the ChatGPT desktop app, which- // keeps the `codex://` scheme.- markers: [- "/Applications/Codex.app",- "Applications/Codex.app",- "/Applications/ChatGPT.app",- ],- link: ({ prompt, folder }) =>- query("codex://new", { prompt, path: folder }),- },- ],- },- {- id: "conductor",- label: "Conductor",- folder: true,- variants: [- {- id: "conductor",- markers: ["/Applications/Conductor.app", "Applications/Conductor.app"],- // Not a query string: Conductor reads its params straight off the- // scheme, with no host and no `?` in front of them.- link: ({ prompt, folder }) =>- `conductor://${params({ prompt, path: folder })}`,- },- ],- },- {- id: "cursor",- label: "Cursor",- folder: false,- variants: [- {- id: "cursor",- markers: ["/Applications/Cursor.app", "Applications/Cursor.app"],- link: ({ prompt }) =>- query("cursor://anysphere.cursor-deeplink/prompt", { text: prompt }),- },- ],- },-];--/**- * The shortest cap any of these links puts on its prompt (Claude Code's), so- * one length rule covers them all. A prompt this long is already far past- * what the composer is for.- */-const MAX_PROMPT = 5000;--/** The line naming the folder for agents whose link cannot carry one. */-const folderLine = (folder: string): string =>- `Working directory: ${folder}\n\n`;--/** The block listing the dropped files and folders, one path a line. */-const attachmentsBlock = (paths: readonly string[]): string =>- paths.length- ? `\n\nAttachments:\n${paths.map((path) => `- ${path}`).join("\n")}`- : "";--/** The first variant `available` accepts, or null when none is reachable. */-export const pickVariant = (- agent: AgentTarget,- available: (variant: AgentVariant) => boolean,-): AgentVariant | null => agent.variants.find(available) ?? null;--export function agentLink(- agent: AgentTarget,- variant: AgentVariant,- launch: AgentLaunch,-): string {- const prefix =- !agent.folder && launch.folder ? folderLine(launch.folder) : "";- const suffix = attachmentsBlock(launch.attachments ?? []);- return variant.link({- prompt: `${prefix}${launch.prompt}${suffix}`.slice(0, MAX_PROMPT),- folder: agent.folder ? launch.folder : null,- });-}--export const findAgent = (id: string): AgentTarget | undefined =>- AGENTS.find((agent) => agent.id === id);diff --git a/apps/desktop/src/main-channels.ts b/apps/desktop/src/main-channels.tsindex 025898f7..fa03af4e 100644--- a/apps/desktop/src/main-channels.ts+++ b/apps/desktop/src/main-channels.ts@@ -27,8 +27,6 @@ export type MainWireChannel = (typeof MAIN_WIRE)[keyof typeof MAIN_WIRE];// answered by the renderer's handlers (apps/web/src/dapi).export const MAIN_CHANNELS = {// Renderer→Main requests- AGENTS_LIST: "agents:list",- AGENTS_OPEN: "agents:open",APP_OPEN_EXTERNAL: "app:open-external",APP_SHOW_IN_FOLDER: "app:show-in-folder",AUTH_GET_PENDING_CALLBACK: "auth:get-pending-callback",@@ -105,20 +103,6 @@ export type ProjectInfo = {export type CompileResult ={ ok: true; code: string } | { ok: false; error: string };-/**- * A coding agent a prompt can be handed to over its deep link. Every agent- * we support is reported, installed or not — see `agent-links.ts` for the- * links themselves.- */-export type AgentInfo = {- id: string;- label: string;- /** Whether its link can name the working directory itself. */- folder: boolean;- /** Whether an app that answers its link is on this machine. */- available: boolean;-};-// Outcome of linking the bundled dapi CLI into PATH. "cancelled" means the// user dismissed the macOS admin prompt — not an error, not installed.export type CliInstallResult =@@ -174,16 +158,6 @@ export type DeepLinkChannel =typeof MAIN_CHANNELS.AUTH_CALLBACK | typeof MAIN_CHANNELS.CHECKOUT_CALLBACK;export type MainRequestMap = {- [MAIN_CHANNELS.AGENTS_LIST]: { request: void; response: AgentInfo[] };- [MAIN_CHANNELS.AGENTS_OPEN]: {- request: {- id: string;- prompt: string;- folder: string | null;- attachments?: string[];- };- response: void;- };[MAIN_CHANNELS.APP_OPEN_EXTERNAL]: {request: { url: string };response: void;diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 44c4f7eb..e3a3bc7b 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -11,7 +11,6 @@ import type { FileHandle } from "node:fs/promises";import { updateElectronApp } from "update-electron-app";import { DapiServer } from "./dapi/server";import { enableHeadless, isHeadless } from "./headless";-import { agentLaunchUrl, listAgents } from "./agent-detect";import { ensureSetup, setupStatus, verifySetup } from "./setup";import { trackInstall } from "./analytics";import { refreshAppMenu, setupAppMenu } from "./menu";@@ -284,12 +283,6 @@ if (app.requestSingleInstanceLock()) {deliverDeepLink(url);});- mainBridge.handle(MAIN_CHANNELS.AGENTS_LIST, () => listAgents());- mainBridge.handle(MAIN_CHANNELS.AGENTS_OPEN, async ({ id, prompt, folder, attachments }) => {- const url = agentLaunchUrl(id, { prompt, folder, attachments });- if (!url) throw new Error(`No deep link for the agent "${id}".`);- await shell.openExternal(url);- });mainBridge.handle(MAIN_CHANNELS.APP_OPEN_EXTERNAL, ({ url }) => shell.openExternal(url));mainBridge.handle(MAIN_CHANNELS.APP_SHOW_IN_FOLDER, ({ path }) => shell.showItemInFolder(path));mainBridge.handle(MAIN_CHANNELS.SETUP_ENSURE, ({ cli }) => ensureSetup(cli));diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsxindex e72cdc76..927b10a6 100644--- a/apps/web/src/components/dashboard/home-view.tsx+++ b/apps/web/src/components/dashboard/home-view.tsx@@ -29,7 +29,7 @@ import { Icon } from "@/components/ui/icon";import { RemoveButton } from "@/components/ui/remove-button";import { projectRoute } from "@/hooks/use-project-route";import { store } from "@/init";-import { agentIcon, listAgents, type AgentInfo } from "@/lib/agents";+import { AGENTS, agentIcon, type AgentInfo } from "@/lib/agents";import { track } from "@/lib/analytics";import { generateProjectName } from "@/lib/db";import { createStoredSignal } from "@/lib/store";@@ -122,17 +122,15 @@ export function DashboardHomeView() {projectsRoot,() => listProjects(),);- const [agents] = createResource(listAgents, { initialValue: [] });-// The agent outlives the session, so the next prompt goes where the last one- // did — unless that agent is not installed here, in which case the best one- // that is becomes what the button shows and what submitting uses.+ // did — unless that one is not installed, in which case the first that is+ // becomes what the button shows and what submitting uses.const [preferredAgent, setPreferredAgent] = createStoredSignal(store.define<string | null>("home.agent", null),);const agent = createMemo(() => {- const usable = agents().filter((entry) => entry.available);+ const usable = AGENTS.filter((entry) => entry.installed);return (usable.find((entry) => entry.id === preferredAgent()) ?? usable[0] ?? null);@@ -429,7 +427,6 @@ export function DashboardHomeView() {<div class="flex min-h-4 items-center justify-between"><AgentPicker- agents={agents()}current={agent()}onSelect={(id) => setPreferredAgent(id)}/>@@ -523,73 +520,59 @@ export function DashboardHomeView() {}type AgentPickerProps = {- agents: readonly AgentInfo[];current: AgentInfo | null;onSelect: (id: string) => void;};/**- * Which agent the prompt goes to. Every agent we support is listed, and the- * ones with nothing on this machine to answer their link are shown disabled- * rather than left out: a list that says what else this works with reads- * better than one that silently varies from machine to machine, and a deep- * link to an app that is not installed opens nothing at all.- *- * Off the desktop there is no list to show, only the reason there is none.+ * Which agent the prompt goes to. Every agent in {@link AGENTS} is listed,+ * and the ones not marked installed are shown disabled rather than left out,+ * so the list says what else this works with.*/function AgentPicker(props: AgentPickerProps) {return (- <Show- when={props.agents.length > 0}- fallback={- <p class="flex h-7 items-center px-2 text-xs text-muted-foreground">- No coding agent found- </p>- }- >- <DropdownMenu placement="bottom-start">- <DropdownMenuTrigger- as="button"- type="button"- aria-label="Choose the coding agent"- class="flex h-7 shrink-0 items-center rounded-md pl-0.5 pr-2 text-xs font-450 text-muted-foreground hover:bg-muted focus-ring"- >- <AgentLogo id={props.current?.id} />- <span class="max-w-40 truncate">- {props.current?.label ?? "No agent installed"}- </span>- </DropdownMenuTrigger>- <DropdownMenuPortal>- <DropdownMenuContent class="w-50">- <DropdownMenuGroup>- <For each={props.agents}>- {(entry) => (- <DropdownMenuItem- disabled={!entry.available}- onSelect={() => props.onSelect(entry.id)}+ <DropdownMenu placement="bottom-start">+ <DropdownMenuTrigger+ as="button"+ type="button"+ aria-label="Choose the coding agent"+ class="flex h-7 shrink-0 items-center rounded-md pl-0.5 pr-2 text-xs font-450 text-muted-foreground hover:bg-muted focus-ring"+ >+ <AgentLogo id={props.current?.id} />+ <span class="max-w-40 truncate">+ {props.current?.label ?? "No agent installed"}+ </span>+ </DropdownMenuTrigger>+ <DropdownMenuPortal>+ <DropdownMenuContent class="w-50">+ <DropdownMenuGroup>+ <For each={AGENTS}>+ {(entry) => (+ <DropdownMenuItem+ disabled={!entry.installed}+ onSelect={() => props.onSelect(entry.id)}+ >+ <Icon name={agentIcon(entry.id)} />+ <span class="min-w-0 flex-1 truncate">{entry.label}</span>+ <Show+ when={entry.installed}+ fallback={+ <span class="shrink-0 text-[10px] text-muted-foreground">+ Not installed+ </span>+ }>- <Icon name={agentIcon(entry.id)} />- <span class="min-w-0 flex-1 truncate">{entry.label}</span>- <Show- when={entry.available}- fallback={- <span class="shrink-0 text-[10px] text-muted-foreground">- Not installed- </span>- }- >- <Show when={entry.id === props.current?.id}>- <Icon name="confirm-check" class="size-6" />- </Show>+ <Show when={entry.id === props.current?.id}>+ <Icon name="confirm-check" class="size-6" /></Show>- </DropdownMenuItem>- )}- </For>- </DropdownMenuGroup>- </DropdownMenuContent>- </DropdownMenuPortal>- </DropdownMenu>- </Show>+ </Show>+ </DropdownMenuItem>+ )}+ </For>+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenuPortal>+ </DropdownMenu>);}diff --git a/apps/web/src/lib/agents.ts b/apps/web/src/lib/agents.tsindex 5dc336a0..9a043ee3 100644--- a/apps/web/src/lib/agents.ts+++ b/apps/web/src/lib/agents.ts@@ -2,60 +2,37 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */-// Renderer side of handing a prompt to a coding agent. The agents, their deep-// links, and which are installed all live in main (`agent-links.ts` and-// `agent-detect.ts`); this is the wrapper the dashboard calls.-//-// Off the desktop build there is no agent to reach and no config to write, so-// the list comes back empty and the connect step is a no-op.+// The coding agents the dashboard offers. Nothing is detected: the list, and+// which of them counts as installed, is fixed here.import { MAIN_CHANNELS } from "@desktop/main-channels";import { mainBridge } from "@/lib/ipc";-import type { AgentInfo } from "@desktop/main-channels";+/** A coding agent the home view's picker offers. */+export type AgentInfo = {+ /** Stable id — what the picker remembers the user's choice as. */+ id: string;+ label: string;+ /** Whether the picker offers it, or lists it as not installed. */+ installed: boolean;+};-export type { AgentInfo };+/** Every agent we support, in the order they are offered. */+export const AGENTS: readonly AgentInfo[] = [+ { id: "claude", label: "Claude Code", installed: true },+ { id: "codex", label: "Codex", installed: false },+];-/**- * The icon file for each agent, by the id `agent-links.ts` gives it. Kept on- * this side because the icons are this app's assets: main knows the agents,- * the renderer knows what they look like. An id with no icon of its own —- * a newly added agent, most likely — falls back to a generic mark.- */+/** The icon file for each agent, for {@link Icon}. */const AGENT_ICONS: Record<string, string> = {claude: "claude",codex: "gpt-codex",- conductor: "conductor",- cursor: "cursor",};-/** The icon name for `id`, for {@link Icon}. */+/** The icon name for `id`, falling back to a generic mark. */export const agentIcon = (id: string | undefined): string =>(id && AGENT_ICONS[id]) || "fx";-/**- * Every agent we support, most fitting first, each flagged with whether it is- * installed here. Empty off the desktop, where there is none to reach.- */-export async function listAgents(): Promise<AgentInfo[]> {- if (!window.desktop) return [];- return mainBridge.call(MAIN_CHANNELS.AGENTS_LIST, undefined);-}--/**- * Opens the agent's app with `prompt` in its composer, and — where the link- * can say so — `folder` as the working directory. Dropped files and folders- * go along as absolute paths, named at the end of the prompt. The agent comes- * to the front and leaves the prompt unsent: the user reads it and presses- * enter.- */-export async function launchAgent(- id: string,- launch: { prompt: string; folder: string | null; attachments?: string[] },-): Promise<void> {- await mainBridge.call(MAIN_CHANNELS.AGENTS_OPEN, { id, ...launch });-}-/*** Brings this machine to the state the agent needs: its config pointing at* this app's MCP server, the `dapi` CLI on PATH, and no stale skills left