The VS Code of video editing, built for agents.
TypeScript
Refactor agent detection and linking logic
konstantin-paulusada3dcb3bc34
diff --git a/apps/desktop/src/agent-detect.ts b/apps/desktop/src/agent-detect.tsindex 736eb392..d85927a3 100644--- a/apps/desktop/src/agent-detect.ts+++ b/apps/desktop/src/agent-detect.ts@@ -2,9 +2,9 @@* 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, readdirSync } from "node:fs";+import { existsSync } from "node:fs";import { homedir } from "node:os";-import { basename, dirname, isAbsolute, join } from "node:path";+import { isAbsolute, join } from "node:path";import { AGENTS, agentLink, findAgent, pickVariant } from "./agent-links";@@ -12,23 +12,12 @@ import type { AgentLaunch, AgentVariant } from "./agent-links";import type { AgentInfo } from "./main-channels";function markerExists(marker: string): boolean {- const path = isAbsolute(marker) ? marker : join(homedir(), marker);- if (!path.endsWith("*")) return existsSync(path);-- // A prefix marker: some entry of the parent directory starts with it, which- // is what finds a folder whose name carries a version.- const prefix = basename(path).slice(0, -1);- try {- return readdirSync(dirname(path)).some((entry) => entry.startsWith(prefix));- } catch {- return false;- }+ 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) &&- (!variant.requires || variant.requires.some(markerExists));+ variant.markers.some(markerExists);/*** Every agent we support, in the order they are offered, each saying whetherdiff --git a/apps/desktop/src/agent-links.test.ts b/apps/desktop/src/agent-links.test.tsindex 29767a99..f3ffc351 100644--- a/apps/desktop/src/agent-links.test.ts+++ b/apps/desktop/src/agent-links.test.ts@@ -58,9 +58,6 @@ describe("agentLink", () => {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",);- expect(link("vscode", "vscode", "cut the intro")).toBe(- "vscode://anthropic.claude-code/open?prompt=Working%20directory%3A%20%2FUsers%2Fx%2FMovies%2FMy%20Film%0A%0Acut%20the%20intro",- );});it("drops the params it has no value for", () => {@@ -86,13 +83,6 @@ describe("agentLink", () => {expect(url.searchParams.get("text")).toHaveLength(5000);});- it("only asks for a second condition where one app is not the whole of it", () => {- // VS Code's handler comes from the extension, and the extension folder- // outlives the editor — so neither half alone is the agent being there.- expect(agent("vscode").variants[0].requires?.length).toBeGreaterThan(0);- expect(agent("claude").variants[0].requires).toBeUndefined();- });-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) {diff --git a/apps/desktop/src/agent-links.ts b/apps/desktop/src/agent-links.tsindex cf6c5f44..020034d3 100644--- a/apps/desktop/src/agent-links.ts+++ b/apps/desktop/src/agent-links.ts@@ -19,19 +19,10 @@ export type AgentVariant = {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. A- * trailing `*` matches any entry of the parent directory with that prefix,- * which is how a versioned extension folder is found. Any one is enough.+ * absolute, or home-relative when they do not start with a slash. Any one+ * is enough.*/markers: readonly string[];- /**- * Further paths, one of which must exist as well. For apps that are the- * whole condition on their own this is unset; an editor plus the extension- * that registers its handler needs both, and an extension folder left- * behind by an uninstalled editor is exactly the case that would otherwise- * offer a link nothing answers.- */- requires?: readonly string[];link(launch: AgentLaunch): string;};@@ -134,23 +125,6 @@ export const AGENTS: readonly AgentTarget[] = [},],},- {- id: "vscode",- label: "VS Code",- folder: false,- variants: [- {- id: "vscode",- markers: [".vscode/extensions/anthropic.claude-code-*"],- requires: [- "/Applications/Visual Studio Code.app",- "Applications/Visual Studio Code.app",- ],- link: ({ prompt }) =>- query("vscode://anthropic.claude-code/open", { prompt }),- },- ],- },];/**diff --git a/apps/web/src/assets/icons/claude.svg b/apps/web/src/assets/icons/claude.svgnew file mode 100644index 00000000..dd885e27--- /dev/null+++ b/apps/web/src/assets/icons/claude.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M7.62882 14.3924L10.4818 12.7926L10.5288 12.6525L10.4818 12.5745H10.3407L9.86261 12.5454L8.23234 12.5018L6.82153 12.4436L5.44991 12.3709L5.10504 12.2981L4.78369 11.8691L4.81504 11.6582L5.10504 11.4619L5.52045 11.4982L6.43748 11.5637L7.81693 11.6582L8.81234 11.7164L10.2937 11.8691H10.5288L10.5602 11.7746L10.4818 11.7164L10.4191 11.6582L8.99261 10.6911L7.44856 9.67301L6.64126 9.084L6.21018 8.78586L5.99072 8.50953L5.89666 7.8987L6.28856 7.46238L6.82153 7.49874L6.95477 7.5351L7.49558 7.94961L8.64774 8.84403L10.1526 9.94935L10.3721 10.1311L10.4604 10.0715L10.474 10.0293L10.3721 9.86209L9.55693 8.38591L8.68693 6.88065L8.29505 6.25527L8.19316 5.8844C8.15369 5.72877 8.13045 5.60001 8.13045 5.44082L8.57721 4.82999L8.82801 4.75L9.43153 4.82999L9.68234 5.04814L10.0586 5.90622L10.6621 7.2515L11.6026 9.084L11.8769 9.62939L12.0259 10.1311L12.0807 10.2839H12.1748V10.1966L12.2532 9.164L12.3942 7.8987L12.5353 6.26981L12.5823 5.81169L12.8096 5.25903L13.2642 4.96088L13.6169 5.12813L13.9069 5.54263L13.8677 5.81169L13.6953 6.93154L13.3583 8.68405L13.1388 9.86209H13.2642L13.4132 9.70937L14.0088 8.92402L15.0042 7.67327L15.4431 7.17878L15.9604 6.6334L16.2896 6.37161H16.9167L17.3713 7.05516L17.1675 7.76053L16.5248 8.57498L15.9918 9.26579L15.2276 10.2896L14.7534 11.1128L14.7959 11.1807L14.9102 11.171L16.6345 10.8002L17.5672 10.6329L18.6802 10.4438L19.1818 10.6765L19.2367 10.9165L19.0407 11.4037L17.8494 11.6946L16.4542 11.9782L14.3767 12.4673L14.3537 12.4857L14.3808 12.526L15.3177 12.6108L15.7175 12.6326H16.6972L18.5234 12.7708L19.0015 13.0835L19.2837 13.4689L19.2367 13.767L18.4999 14.1379L17.5123 13.9052L15.2002 13.3526L14.4086 13.1562H14.2988V13.2217L14.9572 13.8689L16.1721 14.9596L17.6848 16.3704L17.7631 16.7194L17.5672 16.9957L17.3634 16.9667L16.031 15.9631L15.5137 15.5123L14.3537 14.5306H14.2753V14.6324L14.5418 15.0251L15.9604 17.1557L16.031 17.8102L15.9291 18.0211L15.5607 18.1519L15.161 18.0792L14.3223 16.9085L13.468 15.5995L12.7783 14.4215L12.695 14.4741L12.2845 18.8573L12.0964 19.0828L11.6575 19.25L11.2891 18.9737L11.0932 18.5228L11.2891 17.6284L11.5242 16.4649L11.7123 15.5414L11.8848 14.3924L11.9901 14.0086L11.9808 13.9829L11.8967 13.9971L11.0304 15.1851L9.71369 16.9667L8.67126 18.0792L8.42045 18.181L7.98937 17.9556L8.02856 17.5557L8.27153 17.1993L9.71369 15.3669L10.5837 14.2252L11.1444 13.5698L11.139 13.475L11.108 13.4724L7.27613 15.9704L6.59424 16.0577L6.2964 15.7813L6.33558 15.3305L6.47666 15.1851L7.62882 14.3924Z" fill="currentColor" />+</svg>diff --git a/apps/web/src/assets/icons/conductor.svg b/apps/web/src/assets/icons/conductor.svgnew file mode 100644index 00000000..b4d0a6e5--- /dev/null+++ b/apps/web/src/assets/icons/conductor.svg@@ -0,0 +1,9 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M14.6238 16.7961C14.7254 16.7961 14.808 16.878 14.8082 16.9795V18.822C14.8082 18.9236 14.7255 19.0063 14.6238 19.0063H9.09719C8.99567 19.0062 8.91379 18.9235 8.91377 18.822V16.9795C8.91395 16.8781 8.99578 16.7963 9.09719 16.7961H14.6238Z" fill="currentColor" />+<path d="M10.2023 13.8493C10.3039 13.8493 10.3865 13.9313 10.3867 14.0327V15.8753C10.3864 15.9768 10.3038 16.0595 10.2023 16.0596H7.62336C7.52203 16.0593 7.4402 15.9767 7.43994 15.8753V14.0327C7.44012 13.9314 7.52195 13.8495 7.62336 13.8493H10.2023Z" fill="currentColor" />+<path d="M16.0977 13.8493C16.1992 13.8493 16.2818 13.9313 16.282 14.0327V15.8753C16.2817 15.9768 16.1991 16.0595 16.0977 16.0596H13.5187C13.4174 16.0593 13.3355 15.9767 13.3353 15.8753V14.0327C13.3354 13.9314 13.4173 13.8495 13.5187 13.8493H16.0977Z" fill="currentColor" />+<path d="M10.2023 10.9017C10.3039 10.9017 10.3865 10.9836 10.3867 11.0851V12.9276C10.3864 13.029 10.3039 13.112 10.2023 13.112H7.62336C7.52199 13.1118 7.4402 13.0289 7.43994 12.9276V11.0851C7.44013 10.9837 7.52196 10.9019 7.62336 10.9017H10.2023Z" fill="currentColor" />+<path d="M10.2023 7.95401C10.3039 7.95402 10.3865 8.0359 10.3867 8.13743V9.97995C10.3867 10.0816 10.304 10.1643 10.2023 10.1643H7.62336C7.52185 10.1641 7.43996 10.0815 7.43994 9.97995V8.13743C7.44013 8.03601 7.52196 7.9542 7.62336 7.95401H10.2023Z" fill="currentColor" />+<path d="M16.0977 7.95401C16.1992 7.95402 16.2818 8.0359 16.282 8.13743V9.97995C16.282 10.0816 16.1993 10.1643 16.0977 10.1643H13.5187C13.4172 10.1641 13.3353 10.0815 13.3353 9.97995V8.13743C13.3355 8.03601 13.4173 7.9542 13.5187 7.95401H16.0977Z" fill="currentColor" />+<path d="M16.0977 5.00635C16.1992 5.00636 16.2818 5.08823 16.282 5.18977V7.03229C16.282 7.13397 16.1993 7.21661 16.0977 7.21663H9.09719C8.99569 7.21643 8.91379 7.13384 8.91377 7.03229V5.18977C8.91396 5.08835 8.9958 5.00655 9.09719 5.00635H16.0977Z" fill="currentColor" />+</svg>diff --git a/apps/web/src/assets/icons/cursor.svg b/apps/web/src/assets/icons/cursor.svgnew file mode 100644index 00000000..b589952a--- /dev/null+++ b/apps/web/src/assets/icons/cursor.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M18.5048 8.06383L12.4998 4.59662C12.405 4.54196 12.2974 4.51318 12.188 4.51318C12.0785 4.51318 11.971 4.54196 11.8762 4.59662L5.87188 8.06383C5.79216 8.10986 5.72594 8.17604 5.67987 8.25574C5.63379 8.33543 5.60948 8.42584 5.60938 8.5179V15.5084C5.60948 15.6004 5.63379 15.6908 5.67987 15.7705C5.72594 15.8502 5.79216 15.9164 5.87188 15.9624L11.8769 19.4296C11.9717 19.4844 12.0792 19.5132 12.1887 19.5132C12.2982 19.5132 12.4057 19.4844 12.5005 19.4296L18.5055 15.9631C18.5852 15.9171 18.6515 15.8509 18.6975 15.7712C18.7436 15.6915 18.7679 15.6011 18.768 15.5091V8.51719C18.7679 8.42513 18.7436 8.33472 18.6975 8.25503C18.6515 8.17533 18.5852 8.10915 18.5055 8.06312L18.5048 8.06383ZM18.1281 8.79814L12.3309 18.8386C12.2919 18.906 12.1883 18.8784 12.1883 18.7996V12.2256C12.1883 12.1609 12.1712 12.0973 12.1389 12.0413C12.1065 11.9852 12.0599 11.9387 12.0039 11.9064L6.31105 8.62077C6.24294 8.58104 6.27061 8.47746 6.34936 8.47746H17.9422C18.1075 8.47746 18.2104 8.65554 18.1281 8.79814Z" fill="currentColor" />+</svg>diff --git a/apps/web/src/assets/icons/gpt-codex.svg b/apps/web/src/assets/icons/gpt-codex.svgnew file mode 100644index 00000000..a305a9d4--- /dev/null+++ b/apps/web/src/assets/icons/gpt-codex.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M18.3761 10.2834C18.7156 9.01107 18.3863 7.59724 17.3881 6.59905C16.39 5.60091 14.9762 5.27162 13.7038 5.61115C12.7716 4.68093 11.3827 4.25919 10.0191 4.62459C8.65548 4.98991 7.66347 6.04968 7.32133 7.32136C6.04964 7.66351 4.98988 8.65565 4.62456 10.0191C4.25923 11.3827 4.68089 12.7716 5.61119 13.7038C5.27167 14.9762 5.601 16.39 6.59914 17.3882C7.59729 18.3864 9.01103 18.7157 10.2835 18.3761C11.2157 19.3063 12.6047 19.7281 13.9682 19.3628C15.3318 18.9974 16.3238 17.9377 16.666 16.666C17.9377 16.3238 18.9974 15.3317 19.3627 13.9682C19.728 12.6047 19.3064 11.2157 18.3761 10.2836V10.2834ZM16.7753 7.21204C17.4517 7.88846 17.7307 8.81175 17.6122 9.69189L14.4356 7.85784C14.3017 7.78053 14.1367 7.78053 14.0029 7.85784L10.2835 10.0052V8.59711C10.2835 8.49836 10.3364 8.40591 10.422 8.35651L13.2543 6.72136C14.3765 6.09455 15.8215 6.25822 16.7754 7.21204H16.7753ZM11.9937 10.0189L13.7039 11.0063V12.9811L11.9937 13.9685L10.2834 12.9811V11.0063L11.9937 10.0189ZM8.05789 8.26584C8.07612 6.98066 8.94045 5.81102 10.2434 5.46185C11.1674 5.21432 12.1065 5.43441 12.8095 5.97697L9.63277 7.81094C9.49888 7.88821 9.41641 8.03116 9.41641 8.18569V12.4804L8.19699 11.7764C8.11148 11.727 8.05789 11.6348 8.05789 11.5361V8.26575V8.26584ZM5.46178 10.2435C5.70931 9.31955 6.3695 8.61623 7.1909 8.27878V11.9468C7.1909 12.1014 7.27337 12.2443 7.40727 12.3216L11.1267 14.4689L9.90721 15.173C9.82169 15.2224 9.71512 15.2227 9.6296 15.1733L6.79737 13.5382C5.69341 12.8798 5.11274 11.5464 5.46178 10.2435ZM7.212 16.7754C6.53558 16.0989 6.25666 15.1756 6.37508 14.2955L9.55166 16.1296C9.6856 16.2068 9.85058 16.2068 9.98439 16.1296L13.7038 13.9822V15.3902C13.7038 15.489 13.6509 15.5815 13.5652 15.6309L10.733 17.266C9.61083 17.8928 8.16578 17.7291 7.21188 16.7754H7.212ZM15.9294 15.7215C15.9112 17.0067 15.0468 18.1764 13.7438 18.5255C12.8199 18.7731 11.8808 18.553 11.1778 18.0104L14.3545 16.1764C14.4884 16.0991 14.5709 15.9562 14.5709 15.8017V11.507L15.7903 12.211C15.8758 12.2604 15.9294 12.3525 15.9294 12.4513V15.7216V15.7215ZM18.5255 13.7439C18.278 14.6678 17.6178 15.3711 16.7964 15.7086V12.0406C16.7964 11.886 16.714 11.7431 16.58 11.6658L12.8606 9.51845L14.0801 8.81437C14.1656 8.76497 14.2722 8.76463 14.3577 8.81403L17.1899 10.4492C18.2939 11.1076 18.8746 12.441 18.5255 13.7439Z" fill="currentColor" />+</svg>diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsxindex e2b65cc3..ca3986ee 100644--- a/apps/web/src/components/dashboard/home-view.tsx+++ b/apps/web/src/components/dashboard/home-view.tsx@@ -40,7 +40,13 @@ import {import { Icon } from "@/components/ui/icon";import { projectRoute } from "@/hooks/use-project-route";import { store } from "@/init";-import { connectAgents, launchAgent, listAgents, type AgentInfo } from "@/lib/agents";+import {+ agentIcon,+ connectAgents,+ launchAgent,+ listAgents,+ type AgentInfo,+} from "@/lib/agents";import { track } from "@/lib/analytics";import { generateProjectName } from "@/lib/db";import { createStoredSignal } from "@/lib/store";@@ -440,7 +446,7 @@ function AgentPicker(props: AgentPickerProps) {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 />+ <AgentLogo id={props.current?.id} /><span class="max-w-40 truncate">{props.current?.label ?? "No agent installed"}</span>@@ -454,6 +460,7 @@ function AgentPicker(props: AgentPickerProps) {disabled={!entry.available}onSelect={() => props.onSelect(entry.id)}>+ <Icon name={agentIcon(entry.id)} /><span class="min-w-0 flex-1 truncate">{entry.label}</span><Showwhen={entry.available}@@ -478,11 +485,11 @@ function AgentPicker(props: AgentPickerProps) {);}-/** Placeholder for the per-agent logos, which the icon set does not have yet. */-function AgentLogo() {+/** The agent's mark in the composer, in the same box the folder icon sits in. */+function AgentLogo(props: { id?: string }) {return (<span class="grid size-6 shrink-0 place-items-center overflow-clip">- <Icon name="fx" />+ <Icon name={agentIcon(props.id)} /></span>);}diff --git a/apps/web/src/lib/agents.ts b/apps/web/src/lib/agents.tsindex 99a48aca..ae8bcc17 100644--- a/apps/web/src/lib/agents.ts+++ b/apps/web/src/lib/agents.ts@@ -16,6 +16,23 @@ import type { AgentInfo } from "@desktop/main-channels";export type { AgentInfo };+/**+ * 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.+ */+const AGENT_ICONS: Record<string, string> = {+ claude: "claude",+ codex: "gpt-codex",+ conductor: "conductor",+ cursor: "cursor",+};++/** The icon name for `id`, for {@link Icon}. */+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.