Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance agent link functionality to support file and folder attachments

konstantin-paulusbdc10b212fab
diff --git a/apps/desktop/src/agent-links.test.ts b/apps/desktop/src/agent-links.test.ts
index f3ffc351..6d4b1dd1 100644
--- a/apps/desktop/src/agent-links.test.ts
+++ b/apps/desktop/src/agent-links.test.ts
@@ -83,6 +83,29 @@ describe("agentLink", () => {
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) {
diff --git a/apps/desktop/src/agent-links.ts b/apps/desktop/src/agent-links.ts
index 020034d3..2bc0e069 100644
--- a/apps/desktop/src/agent-links.ts
+++ b/apps/desktop/src/agent-links.ts
@@ -2,11 +2,20 @@
* 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, and the folder to work in. */
+/**
+ * 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[];
};
/**
@@ -138,6 +147,12 @@ const MAX_PROMPT = 5000;
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,
@@ -151,8 +166,9 @@ export function agentLink(
): string {
const prefix =
!agent.folder && launch.folder ? folderLine(launch.folder) : "";
+ const suffix = attachmentsBlock(launch.attachments ?? []);
return variant.link({
- prompt: `${prefix}${launch.prompt}`.slice(0, MAX_PROMPT),
+ prompt: `${prefix}${launch.prompt}${suffix}`.slice(0, MAX_PROMPT),
folder: agent.folder ? launch.folder : null,
});
}
diff --git a/apps/desktop/src/main-channels.ts b/apps/desktop/src/main-channels.ts
index 6b615aad..025898f7 100644
--- a/apps/desktop/src/main-channels.ts
+++ b/apps/desktop/src/main-channels.ts
@@ -176,7 +176,12 @@ export type DeepLinkChannel =
export type MainRequestMap = {
[MAIN_CHANNELS.AGENTS_LIST]: { request: void; response: AgentInfo[] };
[MAIN_CHANNELS.AGENTS_OPEN]: {
- request: { id: string; prompt: string; folder: string | null };
+ request: {
+ id: string;
+ prompt: string;
+ folder: string | null;
+ attachments?: string[];
+ };
response: void;
};
[MAIN_CHANNELS.APP_OPEN_EXTERNAL]: {
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 6a9a1a15..a230818f 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -285,8 +285,8 @@ if (app.requestSingleInstanceLock()) {
});
mainBridge.handle(MAIN_CHANNELS.AGENTS_LIST, () => listAgents());
- mainBridge.handle(MAIN_CHANNELS.AGENTS_OPEN, async ({ id, prompt, folder }) => {
- const url = agentLaunchUrl(id, { prompt, folder });
+ 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);
});
diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsx
index 2954601a..aac90ccc 100644
--- a/apps/web/src/components/dashboard/home-view.tsx
+++ b/apps/web/src/components/dashboard/home-view.tsx
@@ -2,17 +2,6 @@
* 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/. */
-// The dashboard's landing view: a prompt, the folder it is about, and the
-// coding agent it goes to. Submitting does three things in order — connects
-// the agents to this app's MCP server if none is connected yet, settles on a
-// project folder (a chosen one, a picked folder, or a fresh project under the
-// application folder), then opens the agent's own app on that folder with the
-// prompt in its composer. The editor follows into the project.
-//
-// The agent is opened over its deep link, in the foreground, with the prompt
-// left unsent: the user sees what is being asked and sends it themselves. See
-// `@/lib/agents` and `agent-links.ts` in the desktop app.
-
import { useNavigate } from "@solidjs/router";
import {
For,
@@ -82,6 +71,19 @@ type PromptTarget =
| { kind: "project"; project: ProjectInfo }
| { kind: "folder"; dir: string };
+/**
+ * A file or folder dropped onto the composer. Only what the tile and the
+ * handoff need: the name to label it, the kind and extension to draw it, and
+ * the path to send — null off the desktop, where the browser will not say
+ * where a dropped file lives.
+ */
+type PromptAttachment = {
+ key: string;
+ name: string;
+ kind: "file" | "folder";
+ path: string | null;
+};
+
/** Cards that fit the one row the design gives recents, the new one included. */
const RECENT_COLUMNS = 5;
@@ -116,6 +118,12 @@ export function DashboardHomeView() {
null,
);
const [busy, setBusy] = createSignal(false);
+ const [attachments, setAttachments] = createSignal<PromptAttachment[]>([]);
+
+ // Drag events fire on every child the pointer crosses, so the overlay is
+ // held up by a count of nested enters rather than the last event seen.
+ let dragCounter = 0;
+ const [isDragging, setIsDragging] = createSignal(false);
// Only worth animating while the field is empty — the placeholder is not on
// screen behind text the user has typed.
@@ -194,6 +202,7 @@ export function DashboardHomeView() {
const text = prompt().trim();
const chosen = agent()!;
+ const paths = attachments().flatMap((entry) => (entry.path ? [entry.path] : []));
setBusy(true);
try {
@@ -205,10 +214,19 @@ export function DashboardHomeView() {
const project = await resolveTarget();
if (!project) return;
- await launchAgent(chosen.id, { prompt: text, folder: project.dir });
+ await launchAgent(chosen.id, {
+ prompt: text,
+ folder: project.dir,
+ attachments: paths,
+ });
- track("home_prompt_sent", { agent: chosen.id, target: target().kind });
+ track("home_prompt_sent", {
+ agent: chosen.id,
+ target: target().kind,
+ attachments: paths.length,
+ });
setPrompt("");
+ setAttachments([]);
setTarget({ kind: "new" });
refetchProjects();
navigate(projectRoute(projectKey(project)));
@@ -221,6 +239,48 @@ export function DashboardHomeView() {
}
};
+ const handleDragOver = (event: DragEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ };
+
+ const handleDragEnter = (event: DragEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ dragCounter++;
+ setIsDragging(true);
+ };
+
+ const handleDragLeave = (event: DragEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ dragCounter--;
+ if (dragCounter <= 0) {
+ dragCounter = 0;
+ setIsDragging(false);
+ }
+ };
+
+ const handleDrop = (event: DragEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ dragCounter = 0;
+ setIsDragging(false);
+
+ const dropped = droppedAttachments(event);
+ if (dropped.length === 0) return;
+
+ // The same file dropped twice is one attachment, not two tiles.
+ setAttachments((current) => {
+ const known = new Set(current.map((entry) => entry.key));
+ return [...current, ...dropped.filter((entry) => !known.has(entry.key))];
+ });
+ };
+
+ const removeAttachment = (key: string) => {
+ setAttachments((current) => current.filter((entry) => entry.key !== key));
+ };
+
// Enter sends, shift+enter breaks the line — and the dashboard's global
// shortcuts have no business reading what is typed here.
const handleKeyDown = (event: KeyboardEvent) => {
@@ -342,7 +402,29 @@ export function DashboardHomeView() {
</DropdownMenu>
</div>
- <div class="z-10 flex w-149 flex-col gap-2 rounded-[20px] border border-border bg-accent p-2 focus-within:border-border-input">
+ <div
+ class="relative z-10 flex w-149 flex-col gap-2 rounded-[20px] border border-border bg-accent p-2 focus-within:border-border-input"
+ onDragOver={handleDragOver}
+ onDragEnter={handleDragEnter}
+ onDragLeave={handleDragLeave}
+ onDrop={handleDrop}
+ >
+ <Show when={attachments().length > 0}>
+ {/* The remove buttons overhang the tiles' corners, and a
+ scrolling row clips at its edge — so the row pads for them
+ and pulls itself back up by the same amount. */}
+ <div class="-mt-2 flex w-full items-start gap-2 overflow-x-auto pt-2 pr-2">
+ <For each={attachments()}>
+ {(entry) => (
+ <AttachmentTile
+ attachment={entry}
+ onRemove={() => removeAttachment(entry.key)}
+ />
+ )}
+ </For>
+ </div>
+ </Show>
+
<textarea
value={prompt()}
onInput={(event) => setPrompt(event.currentTarget.value)}
@@ -373,6 +455,33 @@ export function DashboardHomeView() {
</Show>
</button>
</div>
+
+ <Show when={isDragging()}>
+ <div class="absolute inset-0 z-20 overflow-hidden rounded-[20px] border border-primary bg-background p-2">
+ <div class="absolute inset-0 rounded-[20px] bg-muted" />
+ <div class="relative flex size-full items-center justify-center gap-1 rounded-xl">
+ <svg
+ aria-hidden="true"
+ class="pointer-events-none absolute inset-[0.5px] size-[calc(100%-1px)] overflow-visible text-border-input opacity-15"
+ >
+ <rect
+ width="100%"
+ height="100%"
+ rx="12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1"
+ stroke-dasharray="8 4"
+ shape-rendering="crispEdges"
+ />
+ </svg>
+ <Icon name="attachment" class="size-6 text-muted-foreground" />
+ <span class="text-xs font-450 text-muted-foreground">
+ Drop files or folders here
+ </span>
+ </div>
+ </div>
+ </Show>
</div>
</div>
</div>
@@ -567,6 +676,82 @@ function createTypedPlaceholder(active: () => boolean) {
return () => composePlaceholder(text());
}
+type AttachmentTileProps = {
+ attachment: PromptAttachment;
+ onRemove(): void;
+};
+
+/**
+ * One dropped file or folder: a grey square with a folder mark, or the file's
+ * type in the middle. There is no thumbnail to show — nothing is loaded — so
+ * the name is in the tooltip and the remove button appears on hover, as it
+ * does on the generation composer's reference images.
+ */
+function AttachmentTile(props: AttachmentTileProps) {
+ return (
+ <div class="group relative size-10 shrink-0" title={props.attachment.name}>
+ <div class="grid size-full place-items-center overflow-hidden rounded-md bg-input text-muted-foreground">
+ <Show
+ when={props.attachment.kind === "folder"}
+ fallback={
+ <span class="max-w-9 truncate px-0.5 text-[9px] font-500 uppercase tracking-wide">
+ {fileType(props.attachment.name)}
+ </span>
+ }
+ >
+ <Icon name="navigation.folder" class="size-6" />
+ </Show>
+ </div>
+ <button
+ type="button"
+ aria-label={`Remove ${props.attachment.name}`}
+ class="absolute -right-2 -top-2 z-10 grid size-5 place-items-center opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
+ onClick={props.onRemove}
+ >
+ <div class="flex size-4 items-center justify-center overflow-hidden rounded-full border border-border bg-background">
+ <Icon name="close-remove-small" class="size-5 min-h-5 min-w-5" />
+ </div>
+ </button>
+ </div>
+ );
+}
+
+/** `MP4` for `clip.mp4`, `FILE` for a name with no extension to speak of. */
+function fileType(name: string): string {
+ const dot = name.lastIndexOf(".");
+ const ext = dot > 0 ? name.slice(dot + 1) : "";
+ return ext && ext.length <= 8 ? ext : "FILE";
+}
+
+/**
+ * The files and folders in a drop, in the order they were dragged. Folders
+ * are told apart through the entry API, the only thing a drop says about a
+ * directory; the path comes from the desktop shell, which is the only one
+ * that knows it. Nothing is opened or read.
+ */
+function droppedAttachments(event: DragEvent): PromptAttachment[] {
+ const items = Array.from(event.dataTransfer?.items ?? []);
+ const result: PromptAttachment[] = [];
+
+ for (const item of items) {
+ if (item.kind !== "file") continue;
+ const entry = item.webkitGetAsEntry?.();
+ const file = item.getAsFile();
+ if (!file) continue;
+
+ const path = window.desktop?.getPathForFile(file) || null;
+ const name = entry?.name || file.name;
+ result.push({
+ key: path ?? `${name}:${file.size}:${file.lastModified}`,
+ name,
+ kind: entry?.isDirectory ? "folder" : "file",
+ path,
+ });
+ }
+
+ return result;
+}
+
/** The last segment of a path, for naming a folder the user picked. */
function folderName(dir: string): string {
return (
diff --git a/apps/web/src/lib/agents.ts b/apps/web/src/lib/agents.ts
index f5889b8d..175c9e3e 100644
--- a/apps/web/src/lib/agents.ts
+++ b/apps/web/src/lib/agents.ts
@@ -44,12 +44,14 @@ export async function listAgents(): Promise<AgentInfo[]> {
/**
* Opens the agent's app with `prompt` in its composer, and — where the link
- * can say so — `folder` as the working directory. The agent comes to the
- * front and leaves the prompt unsent: the user reads it and presses enter.
+ * 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 },
+ launch: { prompt: string; folder: string | null; attachments?: string[] },
): Promise<void> {
await mainBridge.call(MAIN_CHANNELS.AGENTS_OPEN, { id, ...launch });
}