The VS Code of video editing, built for agents.
TypeScript
Add agent detection and linking functionality
konstantin-paulus0e3a1e02f880
diff --git a/apps/desktop/src/agent-detect.ts b/apps/desktop/src/agent-detect.tsnew file mode 100644index 00000000..736eb392--- /dev/null+++ b/apps/desktop/src/agent-detect.ts@@ -0,0 +1,58 @@+/* 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, readdirSync } from "node:fs";+import { homedir } from "node:os";+import { basename, dirname, 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 {+ 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;+ }+}++/** 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));++/**+ * 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.tsnew file mode 100644index 00000000..29767a99--- /dev/null+++ b/apps/desktop/src/agent-links.test.ts@@ -0,0 +1,104 @@+/* 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",+ );+ 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", () => {+ 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("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) {+ 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.tsnew file mode 100644index 00000000..cf6c5f44--- /dev/null+++ b/apps/desktop/src/agent-links.ts@@ -0,0 +1,187 @@+/* 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, and the folder to work in. */+export type AgentLaunch = {+ prompt: string;+ /** Absolute path of the project folder, or null when there is none. */+ folder: string | null;+};++/**+ * 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. 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.+ */+ 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;+};++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 }),+ },+ ],+ },+ {+ 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 }),+ },+ ],+ },+];++/**+ * 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 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) : "";+ return variant.link({+ prompt: `${prefix}${launch.prompt}`.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 79e17eac..fa2a18eb 100644--- a/apps/desktop/src/main-channels.ts+++ b/apps/desktop/src/main-channels.ts@@ -27,6 +27,8 @@ 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",@@ -45,6 +47,7 @@ export const MAIN_CHANNELS = {HEADLESS_GET_MODE: "headless:get-mode",LOGS_GET: "logs:get",PROJECTS_PICK_ROOT: "projects:pick-root",+ PROJECTS_PICK_FOLDER: "projects:pick-folder",PROJECTS_DEFAULT_ROOT: "projects:default-root",PROJECTS_LIST: "projects:list",PROJECTS_GET: "projects:get",@@ -102,8 +105,21 @@ export type ProjectInfo = {};export type CompileResult =- | { ok: true; code: string }- | { ok: false; error: string };+ { 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.@@ -117,7 +133,12 @@ export type CliInstallResult =// most of them got, `command` the stdio proxy the rest run (null when this// build has no dapi binary).export type McpRegisterResult =- | { status: "registered"; agents: string[]; url: string; command: string | null }+ | {+ status: "registered";+ agents: string[];+ url: string;+ command: string | null;+ }| { status: "error"; error: string };export type { SourceEdit, WriteResult };@@ -127,13 +148,26 @@ export type MainChannel = (typeof MAIN_CHANNELS)[keyof typeof MAIN_CHANNELS];// Events fed by a `diffusion://` deep link. Main routes each link to exactly// one of these by its host, so auth and checkout never consume each other's.export type DeepLinkChannel =- | typeof MAIN_CHANNELS.AUTH_CALLBACK- | typeof MAIN_CHANNELS.CHECKOUT_CALLBACK;+ typeof MAIN_CHANNELS.AUTH_CALLBACK | typeof MAIN_CHANNELS.CHECKOUT_CALLBACK;export type MainRequestMap = {- [MAIN_CHANNELS.APP_OPEN_EXTERNAL]: { request: { url: string }; response: void };- [MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK]: { request: void; response: string | null };- [MAIN_CHANNELS.CHECKOUT_GET_PENDING_CALLBACK]: { request: void; response: string | null };+ [MAIN_CHANNELS.AGENTS_LIST]: { request: void; response: AgentInfo[] };+ [MAIN_CHANNELS.AGENTS_OPEN]: {+ request: { id: string; prompt: string; folder: string | null };+ response: void;+ };+ [MAIN_CHANNELS.APP_OPEN_EXTERNAL]: {+ request: { url: string };+ response: void;+ };+ [MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK]: {+ request: void;+ response: string | null;+ };+ [MAIN_CHANNELS.CHECKOUT_GET_PENDING_CALLBACK]: {+ request: void;+ response: string | null;+ };[MAIN_CHANNELS.CLI_IS_INSTALLED]: { request: void; response: boolean };[MAIN_CHANNELS.CLI_INSTALL]: { request: void; response: CliInstallResult };[MAIN_CHANNELS.MCP_IS_REGISTERED]: { request: void; response: boolean };@@ -161,14 +195,36 @@ export type MainRequestMap = {response: void;};// Reveals a file or folder in the OS file manager (Finder on macOS).- [MAIN_CHANNELS.APP_SHOW_IN_FOLDER]: { request: { path: string }; response: void };+ [MAIN_CHANNELS.APP_SHOW_IN_FOLDER]: {+ request: { path: string };+ response: void;+ };[MAIN_CHANNELS.HEADLESS_GET_MODE]: { request: void; response: boolean };[MAIN_CHANNELS.LOGS_GET]: { request: void; response: LogEntry[] };- [MAIN_CHANNELS.PROJECTS_PICK_ROOT]: { request: void; response: string | null };- [MAIN_CHANNELS.PROJECTS_DEFAULT_ROOT]: { request: void; response: string | null };- [MAIN_CHANNELS.PROJECTS_LIST]: { request: { root: string }; response: ProjectInfo[] };- [MAIN_CHANNELS.PROJECTS_GET]: { request: { dir: string }; response: ProjectInfo | null };- [MAIN_CHANNELS.PROJECTS_INIT]: { request: { dir: string }; response: ProjectInfo };+ [MAIN_CHANNELS.PROJECTS_PICK_ROOT]: {+ request: void;+ response: string | null;+ };+ [MAIN_CHANNELS.PROJECTS_PICK_FOLDER]: {+ request: void;+ response: string | null;+ };+ [MAIN_CHANNELS.PROJECTS_DEFAULT_ROOT]: {+ request: void;+ response: string | null;+ };+ [MAIN_CHANNELS.PROJECTS_LIST]: {+ request: { root: string };+ response: ProjectInfo[];+ };+ [MAIN_CHANNELS.PROJECTS_GET]: {+ request: { dir: string };+ response: ProjectInfo | null;+ };+ [MAIN_CHANNELS.PROJECTS_INIT]: {+ request: { dir: string };+ response: ProjectInfo;+ };[MAIN_CHANNELS.PROJECTS_RESOLVE]: {request: { root: string; ref: string };response: ProjectInfo | null;@@ -182,30 +238,63 @@ export type MainRequestMap = {request: { dir: string; displayName: string };response: ProjectInfo;};- [MAIN_CHANNELS.PROJECTS_DUPLICATE]: { request: { dir: string }; response: ProjectInfo };+ [MAIN_CHANNELS.PROJECTS_DUPLICATE]: {+ request: { dir: string };+ response: ProjectInfo;+ };[MAIN_CHANNELS.PROJECTS_DELETE]: { request: { dir: string }; response: void };- [MAIN_CHANNELS.PROJECTS_COMPILE]: { request: { dir: string }; response: CompileResult };+ [MAIN_CHANNELS.PROJECTS_COMPILE]: {+ request: { dir: string };+ response: CompileResult;+ };[MAIN_CHANNELS.PROJECTS_WRITE]: {request: { dir: string; edits: SourceEdit[] };response: WriteResult;};[MAIN_CHANNELS.PROJECTS_WATCH]: { request: { dir: string }; response: void };- [MAIN_CHANNELS.PROJECTS_UNWATCH]: { request: { dir: string }; response: void };+ [MAIN_CHANNELS.PROJECTS_UNWATCH]: {+ request: { dir: string };+ response: void;+ };// The asset manifest (`assets.yml`) as plain data; null when there is none.- [MAIN_CHANNELS.PROJECTS_MANIFEST_READ]: { request: { dir: string }; response: unknown };- [MAIN_CHANNELS.PROJECTS_MANIFEST_WRITE]: { request: { dir: string; manifest: unknown }; response: void };+ [MAIN_CHANNELS.PROJECTS_MANIFEST_READ]: {+ request: { dir: string };+ response: unknown;+ };+ [MAIN_CHANNELS.PROJECTS_MANIFEST_WRITE]: {+ request: { dir: string; manifest: unknown };+ response: void;+ };// The project's config: the `diffusion` field of its package.json, as// parsed (null when absent). The renderer owns its shape; see// `engine/project-config` in the web app.- [MAIN_CHANNELS.PROJECTS_CONFIG_READ]: { request: { dir: string }; response: unknown };- [MAIN_CHANNELS.PROJECTS_CONFIG_WRITE]: { request: { dir: string; config: unknown }; response: void };+ [MAIN_CHANNELS.PROJECTS_CONFIG_READ]: {+ request: { dir: string };+ response: unknown;+ };+ [MAIN_CHANNELS.PROJECTS_CONFIG_WRITE]: {+ request: { dir: string; config: unknown };+ response: void;+ };// Project file system, for the asset library. `source` is project-relative// or absolute; `path` is always project-relative. Writes stream through the// FILE_WRITE_* channels (which create parent directories).- [MAIN_CHANNELS.PROJECTS_FS_LIST]: { request: { dir: string; source: string }; response: FsEntry[] };- [MAIN_CHANNELS.PROJECTS_FS_STAT]: { request: { dir: string; source: string }; response: FsStat | null };- [MAIN_CHANNELS.PROJECTS_FS_REMOVE]: { request: { dir: string; path: string }; response: void };- [MAIN_CHANNELS.PROJECTS_FS_REAL_PATH]: { request: { dir: string; source: string }; response: string | null };+ [MAIN_CHANNELS.PROJECTS_FS_LIST]: {+ request: { dir: string; source: string };+ response: FsEntry[];+ };+ [MAIN_CHANNELS.PROJECTS_FS_STAT]: {+ request: { dir: string; source: string };+ response: FsStat | null;+ };+ [MAIN_CHANNELS.PROJECTS_FS_REMOVE]: {+ request: { dir: string; path: string };+ response: void;+ };+ [MAIN_CHANNELS.PROJECTS_FS_REAL_PATH]: {+ request: { dir: string; source: string };+ response: string | null;+ };};export type FsEntry = {diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 3cadaec0..72c6ec6e 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -11,6 +11,7 @@ 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 { installCli, isCliInstalled } from "./cli-install";import { healMcpRegistrations, isMcpRegistered, registerMcp } from "./mcp-install";import { trackInstall } from "./analytics";@@ -26,6 +27,7 @@ import {getProject,initProject,listProjects,+ pickFolder,pickRoot,renameProject,resolveProject,@@ -283,6 +285,12 @@ if (app.requestSingleInstanceLock()) {deliverDeepLink(url);});+ mainBridge.handle(MAIN_CHANNELS.AGENTS_LIST, () => listAgents());+ mainBridge.handle(MAIN_CHANNELS.AGENTS_OPEN, async ({ id, prompt, folder }) => {+ const url = agentLaunchUrl(id, { prompt, folder });+ 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.CLI_IS_INSTALLED, () => isCliInstalled());@@ -307,6 +315,7 @@ if (app.requestSingleInstanceLock()) {mainBridge.handle(MAIN_CHANNELS.HEADLESS_GET_MODE, () => isHeadless());mainBridge.handle(MAIN_CHANNELS.LOGS_GET, () => logBuffer);mainBridge.handle(MAIN_CHANNELS.PROJECTS_PICK_ROOT, () => pickRoot(mainWindow));+ mainBridge.handle(MAIN_CHANNELS.PROJECTS_PICK_FOLDER, () => pickFolder(mainWindow));mainBridge.handle(MAIN_CHANNELS.PROJECTS_DEFAULT_ROOT, () => defaultRoot(mainWindow));mainBridge.handle(MAIN_CHANNELS.PROJECTS_LIST, ({ root }) => listProjects(root));mainBridge.handle(MAIN_CHANNELS.PROJECTS_GET, ({ dir }) => getProject(dir));diff --git a/apps/desktop/src/projects.ts b/apps/desktop/src/projects.tsindex 6b93c379..b1c9eb2c 100644--- a/apps/desktop/src/projects.ts+++ b/apps/desktop/src/projects.ts@@ -189,6 +189,24 @@ export async function pickRoot(window: BrowserWindow | null): Promise<string | n}}+/**+ * A folder to open as a single project, wherever it lives. Unlike `pickRoot`+ * this leaves the projects root alone, and it does not vet the location: the+ * folder goes through `initProject`, which asks about a synced one there.+ */+export async function pickFolder(window: BrowserWindow | null): Promise<string | null> {+ const options: Electron.OpenDialogOptions = {+ title: "Choose project folder",+ defaultPath: app.getPath("videos"),+ properties: ["openDirectory", "createDirectory"],+ };++ const { canceled, filePaths } = window+ ? await dialog.showOpenDialog(window, options)+ : await dialog.showOpenDialog(options);+ return canceled ? null : filePaths[0] ?? null;+}+/*** The attribute macOS puts on a folder that a sync service owns. This is what* finding a synced folder comes down to: a synced Desktop or Documents is andiff --git a/apps/web/src/assets/icons/arrow-top.svg b/apps/web/src/assets/icons/arrow-top.svgnew file mode 100644index 00000000..0abb4e51--- /dev/null+++ b/apps/web/src/assets/icons/arrow-top.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M7.64645 11.3536C7.45118 11.1583 7.45118 10.8417 7.64645 10.6465L11.6465 6.6464C11.8417 6.4512 12.1583 6.4512 12.3536 6.6464L16.3536 10.6465C16.5488 10.8417 16.5488 11.1583 16.3536 11.3536C16.1583 11.5488 15.8417 11.5488 15.6464 11.3536L12.5 8.2071L12.5 17C12.5 17.2761 12.2761 17.5 12 17.5C11.7239 17.5 11.5 17.2761 11.5 17L11.5 8.2071L8.35355 11.3536C8.15829 11.5488 7.84171 11.5488 7.64645 11.3536Z" fill="currentColor"/>+</svg>diff --git a/apps/web/src/assets/icons/home.svg b/apps/web/src/assets/icons/home.svgnew file mode 100644index 00000000..3bca9297--- /dev/null+++ b/apps/web/src/assets/icons/home.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M11.6074 5.20717C11.8253 4.99279 12.1749 4.99279 12.3929 5.20717L18.6929 11.4045C18.9133 11.6214 18.9162 11.976 18.6994 12.1964C18.4825 12.4169 18.1279 12.4198 17.9075 12.2029L17.1334 11.4416V16.6664C17.1334 16.9241 16.9246 17.1331 16.6668 17.1331H7.33347C7.07574 17.1331 6.8668 16.9241 6.8668 16.6664V11.4416L6.09285 12.2029C5.87237 12.4198 5.51781 12.4169 5.30092 12.1964C5.08403 11.976 5.08694 11.6214 5.30742 11.4045L11.6074 5.20717ZM12.0001 6.39192L16.2001 10.5235V16.1997H14V12.9331C14 12.6753 13.7911 12.4664 13.5334 12.4664H10.7334C10.4756 12.4664 10.2667 12.6753 10.2667 12.9331V16.1997H7.80013V10.5235L12.0001 6.39192ZM11.2 16.1997H13.0667V13.3997H11.2V16.1997Z" fill="currentColor" />+</svg>diff --git a/apps/web/src/components/dashboard/home-view.tsx b/apps/web/src/components/dashboard/home-view.tsxnew file mode 100644index 00000000..e2b65cc3--- /dev/null+++ b/apps/web/src/components/dashboard/home-view.tsx@@ -0,0 +1,557 @@+/* 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/. */++// 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,+ Show,+ createEffect,+ createMemo,+ createResource,+ createSignal,+ onCleanup,+ type JSX,+} from "solid-js";+import { isServer } from "solid-js/web";+import { toast } from "somoto";++import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuGroupLabel,+ DropdownMenuItem,+ DropdownMenuPortal,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+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 { track } from "@/lib/analytics";+import { generateProjectName } from "@/lib/db";+import { createStoredSignal } from "@/lib/store";+import {+ createProject,+ ensureProjectsRoot,+ isDesktop,+ listProjects,+ openProjectFolder,+ pickProjectFolder,+ projectKey,+ projectsRoot,+ type ProjectInfo,+} from "@/projects";++import {+ DashboardCardButton,+ DashboardCardMeta,+ DashboardCardPreview,+ DashboardProjectThumbnail,+} from "./shared";+import { formatEditedAt, parseTimestamp } from "./utils";++/**+ * Where the prompt lands: a project chosen from the recents, a folder chosen+ * from the picker — any folder will do, `resolveTarget` makes it a Diffusion+ * Studio project — or, until either is chosen, a fresh project under the+ * application folder.+ */+type PromptTarget =+ | { kind: "new" }+ | { kind: "project"; project: ProjectInfo }+ | { kind: "folder"; dir: string };++/** Cards that fit the one row the design gives recents, the new one included. */+const RECENT_COLUMNS = 5;++/** Recent projects the target menu offers before it gets unwieldy. */+const MENU_PROJECTS = 8;++/** The half of the placeholder that stays put; the rest is typed after it. */+const PROMPT_PREFIX = "Ask Diffusion Studio to";++/** The edits the placeholder types its way through, one line at a time. */+const PROMPT_EXAMPLES = [+ "cut this interview down to 90 seconds",+ "add subtitles to every clip",+ "remove the silences from this recording",+ "grade the beach footage warmer",+ "animate a lower third for each speaker",+ "reframe the edit to 9:16 for social",+ "drop b-roll over the voiceover",+];++/** Milliseconds a typed character, an erased one, and a finished line take. */+const TYPE_MS = 42;+const ERASE_MS = 22;+const HOLD_MS = 2200;++export function DashboardHomeView() {+ const navigate = useNavigate();++ const [prompt, setPrompt] = createSignal("");+ const [target, setTarget] = createSignal<PromptTarget>({ kind: "new" });+ const [selectedProject, setSelectedProject] = createSignal<string | null>(+ null,+ );+ const [busy, setBusy] = createSignal(false);++ // Only worth animating while the field is empty — the placeholder is not on+ // screen behind text the user has typed.+ const placeholder = createTypedPlaceholder(() => prompt().length === 0);++ const [projects, { refetch: refetchProjects }] = createResource(+ 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.+ const [preferredAgent, setPreferredAgent] = createStoredSignal(+ store.define<string | null>("home.agent", null),+ );++ const agent = createMemo(() => {+ const usable = agents().filter((entry) => entry.available);+ return (+ usable.find((entry) => entry.id === preferredAgent()) ?? usable[0] ?? null+ );+ });++ const recentProjects = createMemo(() =>+ [...(projects() ?? [])].sort(+ (a, b) => parseTimestamp(b.modifiedAt) - parseTimestamp(a.modifiedAt),+ ),+ );++ const targetLabel = () => {+ const current = target();+ if (current.kind === "project") return current.project.displayName;+ if (current.kind === "folder") return folderName(current.dir);+ return "Choose project";+ };++ const canSubmit = () => prompt().trim().length > 0 && !!agent() && !busy();++ const handlePickFolder = async () => {+ try {+ const dir = await pickProjectFolder();+ if (dir) setTarget({ kind: "folder", dir });+ } catch (e) {+ toast.error("Failed to choose folder", {+ description: (e as Error).message,+ });+ }+ };++ /**+ * The folder the agent will work in. A picked folder is opened as a project,+ * which scaffolds an entry into it when it is not one already — so any+ * folder on disk can be the answer, not only a project we made. With none+ * picked, a fresh project under the application folder.+ */+ const resolveTarget = async (): Promise<ProjectInfo | null> => {+ const current = target();+ if (current.kind === "project") return current.project;+ if (current.kind === "folder") return openProjectFolder(current.dir);++ // Waits for the roots to come back from the database, and asks for one+ // when there is none to wait for.+ if (!(await ensureProjectsRoot())) return null;+ return createProject(generateProjectName());+ };++ const handleSubmit = async () => {+ if (!canSubmit()) return;++ if (!isDesktop()) {+ toast.error("Handing a prompt to a coding agent needs the desktop app");+ return;+ }++ const text = prompt().trim();+ const chosen = agent()!;+ setBusy(true);++ try {+ // Before anything else: the agent is no use on this project without the+ // app's MCP server in its config, and it reads that config at startup —+ // so it has to be there before the link opens it.+ await connectAgents();++ const project = await resolveTarget();+ if (!project) return;++ await launchAgent(chosen.id, { prompt: text, folder: project.dir });++ track("home_prompt_sent", { agent: chosen.id, target: target().kind });+ setPrompt("");+ setTarget({ kind: "new" });+ refetchProjects();+ navigate(projectRoute(projectKey(project)));+ } catch (e) {+ toast.error("Could not hand the prompt over", {+ description: (e as Error).message,+ });+ } finally {+ setBusy(false);+ }+ };++ // 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) => {+ event.stopPropagation();+ if (event.key !== "Enter" || event.shiftKey) return;++ event.preventDefault();+ void handleSubmit();+ };++ // Only the grid's own background clears the selection — a click that landed+ // on a card is that card's to handle.+ const clearSelection: JSX.EventHandlerUnion<HTMLDivElement, MouseEvent> = (+ event,+ ) => {+ if (event.target !== event.currentTarget) return;+ setSelectedProject(null);+ };++ const openProject = (project: ProjectInfo) => {+ track("project_opened");+ navigate(projectRoute(projectKey(project)));+ };++ const handleCreateProject = async () => {+ if (busy()) return;+ setBusy(true);++ try {+ if (!isDesktop()) {+ toast.error("Projects on disk are only available in the desktop app");+ return;+ }+ if (!(await ensureProjectsRoot())) return;++ const project = await createProject(generateProjectName());+ setSelectedProject(null);+ track("project_created");+ refetchProjects();+ openProject(project);+ } catch (e) {+ toast.error("Failed to create project", {+ description: (e as Error).message,+ });+ } finally {+ setBusy(false);+ }+ };++ return (+ <>+ <div class="flex min-h-0 flex-1 flex-col overflow-y-auto">+ <div class="flex flex-1 flex-col items-center justify-center gap-6.5 px-6 py-8 pt-[15%]">+ <h1 class="w-full text-center text-5xl leading-normal font-450 tracking-[0.0864px] text-muted-foreground">+ What should we edit?+ </h1>++ <div class="flex flex-col items-center">+ <div class="flex w-139 flex-col items-start rounded-t-xl border border-b-0 border-border bg-accent/50 px-1 pt-1 pb-0.5">+ <DropdownMenu placement="bottom-start">+ <DropdownMenuTrigger+ as="button"+ type="button"+ aria-label="Choose the folder to work in"+ class="flex h-7 shrink-0 items-center rounded-md pl-0.5 pr-2 text-xs font-450 text-muted-foreground hover:bg-accent focus-ring"+ >+ <span class="grid size-6 shrink-0 place-items-center overflow-clip">+ <Icon name="navigation.folder" />+ </span>+ <span class="max-w-60 truncate">{targetLabel()}</span>+ <span class="grid h-7 w-5 shrink-0 place-items-center overflow-clip">+ <Icon name="chevron-down" />+ </span>+ </DropdownMenuTrigger>+ <DropdownMenuPortal>+ <DropdownMenuContent class="w-60">+ {/* One action, not a new/open pair: the picker takes any+ folder, and a folder that is not a project yet becomes+ one when the prompt is sent. */}+ <DropdownMenuGroup>+ <DropdownMenuItem onSelect={handlePickFolder}>+ <Icon name="plus-add" />+ <span class="min-w-0 flex-1 truncate">+ Create project...+ </span>+ </DropdownMenuItem>+ </DropdownMenuGroup>+ <Show when={recentProjects().length > 0}>+ <DropdownMenuSeparator />+ <DropdownMenuGroup>+ <DropdownMenuGroupLabel>+ Recent projects+ </DropdownMenuGroupLabel>+ <For each={recentProjects().slice(0, MENU_PROJECTS)}>+ {(project) => (+ <DropdownMenuItem+ onSelect={() =>+ setTarget({ kind: "project", project })+ }+ >+ <Icon name="navigation.folder" />+ <span class="min-w-0 flex-1 truncate">+ {project.displayName}+ </span>+ </DropdownMenuItem>+ )}+ </For>+ </DropdownMenuGroup>+ </Show>+ </DropdownMenuContent>+ </DropdownMenuPortal>+ </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">+ <textarea+ value={prompt()}+ onInput={(event) => setPrompt(event.currentTarget.value)}+ onKeyDown={handleKeyDown}+ onKeyUp={(event) => event.stopPropagation()}+ placeholder={placeholder()}+ aria-label="Describe the edit you want"+ rows={2}+ class="max-h-60 min-h-12 w-full resize-none overflow-auto bg-transparent p-1 text-[12px] leading-5 text-foreground outline-none placeholder:text-muted-foreground selection:bg-selection selection:text-selection-foreground"+ />++ <div class="flex min-h-4 items-center justify-between">+ <AgentPicker+ agents={agents()}+ current={agent()}+ onSelect={(id) => setPreferredAgent(id)}+ />++ <button+ type="button"+ onClick={handleSubmit}+ disabled={!canSubmit()}+ aria-label="Send to the coding agent"+ class="grid size-7 shrink-0 place-items-center rounded-full bg-primary text-primary-foreground transition-opacity hover:bg-primary-hover disabled:pointer-events-none disabled:opacity-40 focus-ring"+ >+ <Show when={busy()} fallback={<Icon name="arrow-top" />}>+ <Icon name="spinner-loader" class="animate-spin" />+ </Show>+ </button>+ </div>+ </div>+ </div>+ </div>++ <div class="flex shrink-0 flex-col">+ <div class="flex items-end gap-6 px-6 pt-4 pb-3">+ <h2 class="min-w-0 flex-1 text-2xl leading-6 font-450 text-foreground">+ Recent+ </h2>+ </div>+ <div+ data-slot="card-grid"+ onClick={clearSelection}+ class="grid grid-cols-5 items-start gap-x-0.5 gap-y-3 px-4 pb-4"+ >+ <DashboardCardButton onClick={handleCreateProject}>+ <DashboardCardPreview class="bg-overlay-soft group-hover:bg-overlay">+ <Icon+ name="plus-add"+ class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-muted-foreground"+ />+ </DashboardCardPreview>+ <DashboardCardMeta title="New project" />+ </DashboardCardButton>+ <For each={recentProjects().slice(0, RECENT_COLUMNS - 1)}>+ {(project) => (+ <DashboardCardButton+ active={selectedProject() === project.dir}+ onClick={() => setSelectedProject(project.dir)}+ onDoubleClick={() => openProject(project)}+ onEscape={() => setSelectedProject(null)}+ >+ <DashboardCardPreview>+ <DashboardProjectThumbnail dir={project.dir} />+ </DashboardCardPreview>+ <DashboardCardMeta+ title={project.displayName}+ subtitle={formatEditedAt(project.modifiedAt)}+ />+ </DashboardCardButton>+ )}+ </For>+ </div>+ </div>+ </div>+ </>+ );+}++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.+ */+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 />+ <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)}+ >+ <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>+ </DropdownMenuItem>+ )}+ </For>+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenuPortal>+ </DropdownMenu>+ </Show>+ );+}++/** Placeholder for the per-agent logos, which the icon set does not have yet. */+function AgentLogo() {+ return (+ <span class="grid size-6 shrink-0 place-items-center overflow-clip">+ <Icon name="fx" />+ </span>+ );+}++/** An example with the trailing dots the typing works its way through too. */+function fullLine(index: number): string {+ return `${PROMPT_EXAMPLES[index]}...`;+}++/** `Ask Diffusion Studio to cut this`, however far the typing has got. */+function composePlaceholder(typed: string): string {+ return typed ? `${PROMPT_PREFIX} ${typed}` : PROMPT_PREFIX;+}++/**+ * The composer's placeholder: {@link PROMPT_PREFIX} stands still while the+ * rest types itself through {@link PROMPT_EXAMPLES} — a line arrives a+ * character at a time, trailing dots and all, holds long enough to be read,+ * erases, and the next one follows. It stops whenever `active` goes false, and for anyone who asked the+ * system for less motion it settles on the first line and stays there.+ */+function createTypedPlaceholder(active: () => boolean) {+ if (+ isServer ||+ window.matchMedia("(prefers-reduced-motion: reduce)").matches+ ) {+ return () => composePlaceholder(fullLine(0));+ }++ const [text, setText] = createSignal("");+ let line = 0;+ let erasing = false;+ let timer: ReturnType<typeof setTimeout> | undefined;++ const step = () => {+ const shown = text();+ const full = fullLine(line);++ if (!erasing && shown.length < full.length) {+ setText(full.slice(0, shown.length + 1));+ timer = setTimeout(step, TYPE_MS);+ } else if (!erasing) {+ erasing = true;+ timer = setTimeout(step, HOLD_MS);+ } else if (shown.length > 0) {+ setText(shown.slice(0, -1));+ timer = setTimeout(step, ERASE_MS);+ } else {+ erasing = false;+ line = (line + 1) % PROMPT_EXAMPLES.length;+ timer = setTimeout(step, TYPE_MS);+ }+ };++ createEffect(() => {+ clearTimeout(timer);+ if (active()) timer = setTimeout(step, TYPE_MS);+ });+ onCleanup(() => clearTimeout(timer));++ return () => composePlaceholder(text());+}++/** The last segment of a path, for naming a folder the user picked. */+function folderName(dir: string): string {+ return (+ dir+ .replace(/[/\\]+$/, "")+ .split(/[/\\]/)+ .pop() || dir+ );+}diff --git a/apps/web/src/components/dashboard/projects-view.tsx b/apps/web/src/components/dashboard/projects-view.tsxindex d74f52ca..f2bbc201 100644--- a/apps/web/src/components/dashboard/projects-view.tsx+++ b/apps/web/src/components/dashboard/projects-view.tsx@@ -22,7 +22,7 @@ import {AlertDialogTitle,} from "@/components/ui/alert-dialog";import { toast } from "somoto";-import { For, Show, batch, createMemo, createResource, createSignal, onCleanup } from "solid-js";+import { For, Show, batch, createMemo, createResource, createSignal } from "solid-js";import { useNavigate } from "@solidjs/router";import {@@ -37,8 +37,10 @@ import {DashboardCardMeta,DashboardCardButton,DashboardCardPreview,+ DashboardProjectThumbnail,DashboardViewSection,} from "./shared";+import { formatEditedAt, parseTimestamp } from "./utils";import { DashboardSearchPanel } from "./search-bar";import { DashboardProjectsFolderBar } from "./projects-folder-bar";import { projectRoute } from "@/hooks/use-project-route";@@ -52,9 +54,7 @@ import {isDesktop,listProjects,projectKey,- projectCoverKey,projectsRoot,- readProjectCover,renameProject,type ProjectInfo,} from "@/projects";@@ -299,7 +299,7 @@ export function DashboardProjectsView() {onDelete={() => setPendingDelete(project)}><DashboardCardPreview>- <ProjectThumbnail dir={project.dir} />+ <DashboardProjectThumbnail dir={project.dir} /></DashboardCardPreview><div class="flex flex-col gap-1 px-2"><div class="relative h-4 w-full">@@ -389,36 +389,6 @@ export function DashboardProjectsView() {);}-function ProjectThumbnail(props: { dir: string }) {- const [cover] = createResource(- () => projectCoverKey(props.dir),- () => readProjectCover(props.dir),- );-- // The URL the last cover was under is released as this one takes its place.- const url = createMemo<string | null>((previous) => {- if (previous) URL.revokeObjectURL(previous);- const blob = cover();- return blob ? URL.createObjectURL(blob) : null;- }, null);-- onCleanup(() => {- const current = url();- if (current) URL.revokeObjectURL(current);- });-- return (- <Show when={url()}>- <img- src={url()!}- alt=""- class="h-full w-full object-cover"- draggable={false}- />- </Show>- );-}-const SORT_OPTIONS: Array<{ id: ProjectSortOption; label: string }> = [{ id: "last-viewed", label: "Last modified" },{ id: "alphabetical", label: "Alphabetical" },@@ -426,31 +396,3 @@ const SORT_OPTIONS: Array<{ id: ProjectSortOption; label: string }> = [];const MAX_VISIBLE_PROJECTS = 11;--function parseTimestamp(value: string): number {- const parsed = Date.parse(value);- return Number.isNaN(parsed) ? 0 : parsed;-}--function formatEditedAt(modifiedAt: string): string {- const timestamp = parseTimestamp(modifiedAt);- if (!timestamp) return "Edited just now";-- const elapsedMs = Date.now() - timestamp;- if (elapsedMs < 60_000) return "Edited just now";-- const minutes = Math.floor(elapsedMs / 60_000);- if (minutes < 60) return `Edited ${minutes} minute${minutes === 1 ? "" : "s"} ago`;-- const hours = Math.floor(minutes / 60);- if (hours < 24) return `Edited ${hours} hour${hours === 1 ? "" : "s"} ago`;-- const days = Math.floor(hours / 24);- if (days < 30) return `Edited ${days} day${days === 1 ? "" : "s"} ago`;-- const months = Math.floor(days / 30);- if (months < 12) return `Edited ${months} month${months === 1 ? "" : "s"} ago`;-- const years = Math.floor(days / 365);- return `Edited ${years} year${years === 1 ? "" : "s"} ago`;-}diff --git a/apps/web/src/components/dashboard/shared.tsx b/apps/web/src/components/dashboard/shared.tsxindex 717948b0..56153e86 100644--- a/apps/web/src/components/dashboard/shared.tsx+++ b/apps/web/src/components/dashboard/shared.tsx@@ -8,7 +8,8 @@ import { Icon } from "@/components/ui/icon";import { useAuth } from "@/context/auth";import { cx } from "@/lib/cva";import { trpc } from "@/lib/trpc";-import { For, Show, children, createResource, type JSX } from "solid-js";+import { For, Show, children, createMemo, createResource, onCleanup, type JSX } from "solid-js";+import { projectCoverKey, readProjectCover } from "@/projects";import { Separator } from "../ui/separator";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";@@ -536,3 +537,33 @@ export function DashboardViewSection(props: DashboardViewSectionProps) {);}+/** The saved cover of the project in `dir`, or nothing when it has none yet. */+export function DashboardProjectThumbnail(props: { dir: string }) {+ const [cover] = createResource(+ () => projectCoverKey(props.dir),+ () => readProjectCover(props.dir),+ );++ // The URL the last cover was under is released as this one takes its place.+ const url = createMemo<string | null>((previous) => {+ if (previous) URL.revokeObjectURL(previous);+ const blob = cover();+ return blob ? URL.createObjectURL(blob) : null;+ }, null);++ onCleanup(() => {+ const current = url();+ if (current) URL.revokeObjectURL(current);+ });++ return (+ <Show when={url()}>+ <img+ src={url()!}+ alt=""+ class="h-full w-full object-cover"+ draggable={false}+ />+ </Show>+ );+}diff --git a/apps/web/src/components/dashboard/types.ts b/apps/web/src/components/dashboard/types.tsindex e2d5f362..29f35b7c 100644--- a/apps/web/src/components/dashboard/types.ts+++ b/apps/web/src/components/dashboard/types.ts@@ -2,7 +2,7 @@* 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/. */-export type DashboardView = | "projects" | "templates" | "ai-credits" | "billing" | "account" | "settings" | "preferences" | "help";+export type DashboardView = "home" | "projects" | "templates" | "ai-credits" | "billing" | "account" | "settings" | "preferences" | "help";export type ProjectSortOption = | "last-viewed" | "alphabetical" | "date-created";export type TemplateSourceOption = "official" | "custom";export type TemplatePreviewKind = "landscape" | "portrait" | "square";diff --git a/apps/web/src/components/dashboard/utils.ts b/apps/web/src/components/dashboard/utils.tsindex eaab72b2..ed2bcbae 100644--- a/apps/web/src/components/dashboard/utils.ts+++ b/apps/web/src/components/dashboard/utils.ts@@ -2,6 +2,34 @@* 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/. */+export function parseTimestamp(value: string): number {+ const parsed = Date.parse(value);+ return Number.isNaN(parsed) ? 0 : parsed;+}++export function formatEditedAt(modifiedAt: string): string {+ const timestamp = parseTimestamp(modifiedAt);+ if (!timestamp) return "Edited just now";++ const elapsedMs = Date.now() - timestamp;+ if (elapsedMs < 60_000) return "Edited just now";++ const minutes = Math.floor(elapsedMs / 60_000);+ if (minutes < 60) return `Edited ${minutes} minute${minutes === 1 ? "" : "s"} ago`;++ const hours = Math.floor(minutes / 60);+ if (hours < 24) return `Edited ${hours} hour${hours === 1 ? "" : "s"} ago`;++ const days = Math.floor(hours / 24);+ if (days < 30) return `Edited ${days} day${days === 1 ? "" : "s"} ago`;++ const months = Math.floor(days / 30);+ if (months < 12) return `Edited ${months} month${months === 1 ? "" : "s"} ago`;++ const years = Math.floor(days / 365);+ return `Edited ${years} year${years === 1 ? "" : "s"} ago`;+}+const AVATAR_MAX_SIZE = 256;export async function cropAndResizeAvatar(file: File): Promise<Blob> {diff --git a/apps/web/src/components/sidebar-left/project-menu/index.tsx b/apps/web/src/components/sidebar-left/project-menu/index.tsxindex d9838de6..92a896b9 100644--- a/apps/web/src/components/sidebar-left/project-menu/index.tsx+++ b/apps/web/src/components/sidebar-left/project-menu/index.tsx@@ -34,7 +34,7 @@ export function ProjectMenu() {const handleOpenDashboard = () => {(document.activeElement as HTMLElement)?.blur?.();- navigate("/?dashboard=projects");+ navigate("/");};const handleOpenAccount = () => {diff --git a/apps/web/src/lib/agents.ts b/apps/web/src/lib/agents.tsnew file mode 100644index 00000000..99a48aca--- /dev/null+++ b/apps/web/src/lib/agents.ts@@ -0,0 +1,53 @@+/* 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/. */++// 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.++import { MAIN_CHANNELS } from "@desktop/main-channels";+import { mainBridge } from "@/lib/ipc";++import type { AgentInfo } from "@desktop/main-channels";++export type { AgentInfo };++/**+ * 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. 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 },+): Promise<void> {+ await mainBridge.call(MAIN_CHANNELS.AGENTS_OPEN, { id, ...launch });+}++/**+ * Points the agents on this machine at this app's MCP server, unless one+ * already is. Without it the agent opens with the prompt but has no way to+ * touch the project, so this runs before the prompt is handed over rather+ * than at some quieter moment — and it throws when it cannot, because+ * carrying on would send the agent off without its tools.+ */+export async function connectAgents(): Promise<void> {+ if (!window.desktop) return;+ if (await mainBridge.call(MAIN_CHANNELS.MCP_IS_REGISTERED, undefined)) return;++ const result = await mainBridge.call(MAIN_CHANNELS.MCP_REGISTER, undefined);+ if (result.status === "error") throw new Error(result.error);+}diff --git a/apps/web/src/pages/dashboard.tsx b/apps/web/src/pages/dashboard.tsxindex 935097be..03353b51 100644--- a/apps/web/src/pages/dashboard.tsx+++ b/apps/web/src/pages/dashboard.tsx@@ -10,6 +10,7 @@ import { DashboardAiCreditsView } from "@/components/dashboard/ai-credits-view";import { DashboardBillingView } from "@/components/dashboard/billing-view";import { DashboardGetDesktopApp } from "@/components/dashboard/get-desktop-app";import { DashboardHelpView } from "@/components/dashboard/help-view";+import { DashboardHomeView } from "@/components/dashboard/home-view";import { DashboardProjectsView } from "@/components/dashboard/projects-view";import { DashboardSettingsView } from "@/components/dashboard/settings-view";import { DashboardSidebarHeader, DashboardSidebarNav, DashboardSidebarUser, DashboardSidebarItem } from "@/components/dashboard/sidebar";@@ -19,6 +20,7 @@ import { useFullscreenState } from "@/hooks/use-fullscreen-state";import type { DashboardView } from "@/components/dashboard/types";const DASHBOARD_VIEWS: readonly DashboardView[] = [+ "home","projects","templates","ai-credits",@@ -31,7 +33,7 @@ const DASHBOARD_VIEWS: readonly DashboardView[] = [function parseView(value: string | string[] | undefined): DashboardView {const raw = Array.isArray(value) ? value[0] : value;- return DASHBOARD_VIEWS.find((v) => v === raw) ?? "projects";+ return DASHBOARD_VIEWS.find((v) => v === raw) ?? "home";}export function DashboardPage() {@@ -58,6 +60,7 @@ export function DashboardPage() {</>}>+ <DashboardSidebarItem active={view() === "home"} onClick={() => setView("home")} icon="home" label="Home" /><DashboardSidebarItem active={view() === "projects"} onClick={() => setView("projects")} icon="diffusion-project-file" label="Projects" /></DashboardSidebarNav><DashboardSidebarUser active={view() === "account"} onClick={() => setView("account")} />@@ -67,6 +70,9 @@ export function DashboardPage() {<section class="flex min-h-0 flex-1 flex-col bg-overlay-soft"><Switch>+ <Match when={view() === "home"}>+ <DashboardHomeView />+ </Match><Match when={view() === "projects"}><DashboardProjectsView /></Match>diff --git a/apps/web/src/projects/host.ts b/apps/web/src/projects/host.tsindex e7529c9c..4519f86a 100644--- a/apps/web/src/projects/host.ts+++ b/apps/web/src/projects/host.ts@@ -71,6 +71,16 @@ export async function pickProjectsRoot(): Promise<string | null> {return root;}+/**+ * Opens the native folder picker for a folder to open as a single project.+ * Unlike `pickProjectsRoot` it changes nothing on its own — hand the path to+ * `openProjectFolder`, which is what makes the folder a project.+ */+export async function pickProjectFolder(): Promise<string | null> {+ if (!isDesktop()) return null;+ return mainBridge.call(MAIN_CHANNELS.PROJECTS_PICK_FOLDER, undefined);+}+/*** The root to work against, waited for and — when there is none to wait for —* defaulted to. Null off the desktop, where there is no folder at all, and