Skip to content

The VS Code of video editing, built for agents.

TypeScript

Add CLI and skills installation functionality

konstantin-paulus60cc903be405
diff --git a/apps/desktop/src/cli-install.ts b/apps/desktop/src/cli-install.ts
new file mode 100644
index 00000000..8e7d800d
--- /dev/null
+++ b/apps/desktop/src/cli-install.ts
@@ -0,0 +1,47 @@
+/* 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 { app } from "electron";
+import { execFile } from "node:child_process";
+import { existsSync } from "node:fs";
+import { join } from "node:path";
+import type { CliInstallResult } from "./main-channels";
+
+export const CLI_LINK_PATH = "/usr/local/bin/dapi";
+
+// The dev workflow links the workspace build into Homebrew's bin instead
+// (`symlink:create` in apps/cli), so both locations count as installed.
+const DEV_LINK_PATH = "/opt/homebrew/bin/dapi";
+
+export function isCliInstalled(): boolean {
+ return existsSync(CLI_LINK_PATH) || existsSync(DEV_LINK_PATH);
+}
+
+// Linking into /usr/local/bin needs elevation; osascript shows the standard
+// macOS admin prompt so the app itself never asks for credentials.
+function linkCli(): Promise<void> {
+ const wrapper = join(process.resourcesPath, "cli", "bin", "dapi");
+ const shell = `mkdir -p /usr/local/bin && ln -sf '${wrapper}' '${CLI_LINK_PATH}'`;
+ const script = `do shell script "${shell.replaceAll('"', '\\"')}" with administrator privileges`;
+ return new Promise((resolve, reject) => {
+ execFile("osascript", ["-e", script], (err) => (err ? reject(err) : resolve()));
+ });
+}
+
+export async function installCli(): Promise<CliInstallResult> {
+ if (!app.isPackaged) {
+ return {
+ status: "error",
+ error: "Installing the CLI is only available in the packaged app. Use `npm run symlink:create` in development.",
+ };
+ }
+ try {
+ await linkCli();
+ return { status: "installed" };
+ } catch (e) {
+ const message = (e as Error).message ?? "";
+ if (message.includes("-128")) return { status: "cancelled" }; // user cancelled the admin prompt
+ return { status: "error", error: message };
+ }
+}
diff --git a/apps/desktop/src/main-channels.ts b/apps/desktop/src/main-channels.ts
index 63022d45..78017ae9 100644
--- a/apps/desktop/src/main-channels.ts
+++ b/apps/desktop/src/main-channels.ts
@@ -31,6 +31,10 @@ export const MAIN_CHANNELS = {
APP_SHOW_IN_FOLDER: "app:show-in-folder",
AUTH_GET_PENDING_CALLBACK: "auth:get-pending-callback",
CHECKOUT_GET_PENDING_CALLBACK: "checkout:get-pending-callback",
+ CLI_IS_INSTALLED: "cli:is-installed",
+ CLI_INSTALL: "cli:install",
+ SKILLS_IS_INSTALLED: "skills:is-installed",
+ SKILLS_INSTALL: "skills:install",
WINDOW_IS_FULLSCREEN: "window:is-fullscreen",
WINDOW_CAPTURE: "window:capture",
FILE_TRANSFER: "file:transfer",
@@ -101,6 +105,19 @@ export type CompileResult =
| { ok: true; code: string }
| { ok: false; error: string };
+// 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 =
+ | { status: "installed" }
+ | { status: "cancelled" }
+ | { status: "error"; error: string };
+
+// Outcome of running the skills CLI. `npxMissing` marks a machine without a
+// usable Node/npx, where the renderer falls back to copy-the-command.
+export type SkillsInstallResult =
+ | { status: "installed" }
+ | { status: "error"; error: string; npxMissing: boolean };
+
export type { SourceEdit, WriteResult };
export type MainChannel = (typeof MAIN_CHANNELS)[keyof typeof MAIN_CHANNELS];
@@ -115,6 +132,10 @@ 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.CLI_IS_INSTALLED]: { request: void; response: boolean };
+ [MAIN_CHANNELS.CLI_INSTALL]: { request: void; response: CliInstallResult };
+ [MAIN_CHANNELS.SKILLS_IS_INSTALLED]: { request: void; response: boolean };
+ [MAIN_CHANNELS.SKILLS_INSTALL]: { request: void; response: SkillsInstallResult };
[MAIN_CHANNELS.WINDOW_IS_FULLSCREEN]: { request: void; response: boolean };
[MAIN_CHANNELS.WINDOW_CAPTURE]: { request: void; response: ScreenshotResult };
[MAIN_CHANNELS.FILE_TRANSFER]: {
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 837aa009..044ea250 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -9,6 +9,8 @@ import { randomUUID } from "node:crypto";
import type { FileHandle } from "node:fs/promises";
import { updateElectronApp } from "update-electron-app";
import { startCliServer, stopCliServer, isHeadless } from "./cli-server";
+import { installCli, isCliInstalled } from "./cli-install";
+import { installSkills, isSkillsInstalled } from "./skills-install";
import { trackInstall } from "./analytics";
import { setupAppMenu } from "./menu";
import { mainBridge } from "./main-manager";
@@ -258,6 +260,10 @@ if (app.requestSingleInstanceLock()) {
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());
+ mainBridge.handle(MAIN_CHANNELS.CLI_INSTALL, () => installCli());
+ mainBridge.handle(MAIN_CHANNELS.SKILLS_IS_INSTALLED, () => isSkillsInstalled());
+ mainBridge.handle(MAIN_CHANNELS.SKILLS_INSTALL, () => installSkills());
mainBridge.handle(MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK, () =>
takePendingDeepLink(MAIN_CHANNELS.AUTH_CALLBACK),
);
diff --git a/apps/desktop/src/menu.ts b/apps/desktop/src/menu.ts
index 45e600b1..31bef6aa 100644
--- a/apps/desktop/src/menu.ts
+++ b/apps/desktop/src/menu.ts
@@ -3,38 +3,24 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app, dialog, Menu } from "electron";
-import { execFile } from "node:child_process";
-import { join } from "node:path";
import type { MenuItemConstructorOptions } from "electron";
-const CLI_LINK_PATH = "/usr/local/bin/dapi";
+import { CLI_LINK_PATH, installCli } from "./cli-install";
-// Linking into /usr/local/bin needs elevation; osascript shows the standard
-// macOS admin prompt so the app itself never asks for credentials.
-function linkCli(): Promise<void> {
- const wrapper = join(process.resourcesPath, "cli", "bin", "dapi");
- const shell = `mkdir -p /usr/local/bin && ln -sf '${wrapper}' '${CLI_LINK_PATH}'`;
- const script = `do shell script "${shell.replaceAll('"', '\\"')}" with administrator privileges`;
- return new Promise((resolve, reject) => {
- execFile("osascript", ["-e", script], (err) => (err ? reject(err) : resolve()));
- });
-}
-
-async function installCli() {
- try {
- await linkCli();
+async function installCliFromMenu() {
+ const result = await installCli();
+ if (result.status === "cancelled") return;
+ if (result.status === "installed") {
await dialog.showMessageBox({
type: "info",
message: "The dapi command line tool was installed.",
detail: `Linked at ${CLI_LINK_PATH}. Run "dapi --help" in a terminal to get started.`,
});
- } catch (e) {
- const message = (e as Error).message ?? "";
- if (message.includes("-128")) return; // user cancelled the admin prompt
+ } else {
await dialog.showMessageBox({
type: "error",
message: "Could not install the dapi command line tool.",
- detail: message,
+ detail: result.error,
});
}
}
@@ -51,7 +37,7 @@ export function setupAppMenu() {
{
label: "Install dapi Command Line Tool…",
enabled: app.isPackaged,
- click: installCli,
+ click: installCliFromMenu,
},
{ type: "separator" },
{ role: "services" },
diff --git a/apps/desktop/src/skills-install.ts b/apps/desktop/src/skills-install.ts
new file mode 100644
index 00000000..4ad257e3
--- /dev/null
+++ b/apps/desktop/src/skills-install.ts
@@ -0,0 +1,42 @@
+/* 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 { execFile } from "node:child_process";
+import { existsSync } from "node:fs";
+import { homedir } from "node:os";
+import { join } from "node:path";
+import type { SkillsInstallResult } from "./main-channels";
+
+// The skills CLI (github.com/vercel-labs/skills) installs global skills into
+// ~/<agent>/skills/. `editor` is this product's main skill, so its presence
+// under any known agent directory counts as installed.
+const AGENT_DIRS = [".claude", ".codex", ".cursor", ".gemini", ".copilot"];
+
+export const SKILLS_INSTALL_COMMAND = "npx -y skills add diffusionstudio/skills -g -y --all";
+
+const INSTALL_TIMEOUT_MS = 180_000;
+
+export function isSkillsInstalled(): boolean {
+ const home = homedir();
+ return AGENT_DIRS.some((dir) => existsSync(join(home, dir, "skills", "editor")));
+}
+
+// npx comes from the user's own Node install, which a Finder-launched app
+// doesn't have on PATH — so the command runs through the user's login shell.
+export function installSkills(): Promise<SkillsInstallResult> {
+ const shell = process.env.SHELL || "/bin/zsh";
+ return new Promise((resolve) => {
+ execFile(
+ shell,
+ ["-lc", SKILLS_INSTALL_COMMAND],
+ { timeout: INSTALL_TIMEOUT_MS },
+ (err, _stdout, stderr) => {
+ if (!err) return resolve({ status: "installed" });
+ const message = stderr.trim() || err.message;
+ const npxMissing = /command not found|not recognized|ENOENT/i.test(message);
+ resolve({ status: "error", error: message, npxMissing });
+ },
+ );
+ });
+}
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx
index a1a58616..bb490a29 100644
--- a/apps/web/src/app.tsx
+++ b/apps/web/src/app.tsx
@@ -17,6 +17,7 @@ import { ScreenTooSmall } from '@/components/screen-too-small';
import { UnsupportedBrowser } from '@/components/unsupported-browser';
import { ProjectPage } from '@/pages/project';
import { LoginPage } from '@/pages/login';
+import { OnboardingPage, onboardingCompleted } from '@/pages/onboarding';
import { AuthCallbackPage } from '@/pages/auth-callback';
import { NotFoundPage } from '@/pages/not-found';
import { DashboardPage } from '@/pages/dashboard';
@@ -27,7 +28,12 @@ function AuthGate(props: { children: JSX.Element }) {
return (
<Show when={!auth.isLoading()}>
<Show when={auth.isAuthenticated() || auth.headless()}>
- {props.children}
+ <Show
+ when={onboardingCompleted() || auth.headless()}
+ fallback={<OnboardingPage />}
+ >
+ {props.children}
+ </Show>
</Show>
<Show when={!auth.isAuthenticated()}>
<LoginPage />
diff --git a/apps/web/src/lib/desktop-app.ts b/apps/web/src/lib/desktop-app.ts
index 160e4e49..ba502898 100644
--- a/apps/web/src/lib/desktop-app.ts
+++ b/apps/web/src/lib/desktop-app.ts
@@ -16,7 +16,7 @@ const DOWNLOAD_URL =
"https://github.com/diffusionstudio/editor/releases/latest/download/Diffusion-Studio-arm64.dmg";
/** Where a download was started from, so the promos can be compared. */
-export type DesktopAppDownloadSource = "canvas_banner" | "dashboard_footer" | "main_menu";
+export type DesktopAppDownloadSource = "canvas_banner" | "dashboard_footer" | "main_menu" | "onboarding";
function isMacOS() {
const uaData = (navigator as { userAgentData?: { platform?: string } }).userAgentData;
diff --git a/apps/web/src/pages/onboarding.tsx b/apps/web/src/pages/onboarding.tsx
new file mode 100644
index 00000000..10ab508d
--- /dev/null
+++ b/apps/web/src/pages/onboarding.tsx
@@ -0,0 +1,273 @@
+/* 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 { createSignal, onMount, Show } from 'solid-js';
+import type { JSX } from 'solid-js';
+import { toast } from 'somoto';
+
+import { MAIN_CHANNELS } from '@desktop/main-channels';
+import { Button } from '@/components/ui/button';
+import { Icon } from '@/components/ui/icon';
+import { downloadDesktopApp } from '@/lib/desktop-app';
+import { createStoredSignal } from '@/lib/store';
+import { mainBridge } from '@/lib/ipc';
+import { track } from '@/lib/analytics';
+import { store } from '@/init';
+
+const SKILLS_COMMAND = 'npx skills add diffusionstudio/skills -g -y --all';
+
+const [onboardingCompleted, setOnboardingCompleted] = createStoredSignal(
+ store.define('onboarding.completed', false),
+);
+
+export { onboardingCompleted };
+
+type StepState = 'todo' | 'busy' | 'done';
+
+type SetupRowProps = {
+ title: string;
+ description: string;
+ action: JSX.Element;
+};
+
+function SetupRow(props: SetupRowProps) {
+ return (
+ <div class="flex items-center gap-4">
+ <div class="flex min-w-0 flex-1 flex-col gap-1">
+ <p class="text-xs text-foreground">{props.title}</p>
+ <p class="text-xs text-muted-foreground">{props.description}</p>
+ </div>
+ {props.action}
+ </div>
+ );
+}
+
+type StepButtonProps = {
+ state: StepState;
+ label: string;
+ busyLabel?: string;
+ doneLabel: string;
+ onClick: () => void;
+};
+
+function StepButton(props: StepButtonProps) {
+ return (
+ <Show
+ when={props.state !== 'done'}
+ fallback={
+ <Button variant="on" class="pointer-events-none">
+ {props.doneLabel}
+ </Button>
+ }
+ >
+ <Button
+ variant="secondary"
+ disabled={props.state === 'busy'}
+ onClick={props.onClick}
+ >
+ {props.state === 'busy' ? props.busyLabel ?? props.label : props.label}
+ </Button>
+ </Show>
+ );
+}
+
+/**
+ * Post-signup screen for setting up the agent dependencies: the dapi CLI and
+ * the agent skills. Shown by AuthGate until dismissed; the dismissal is
+ * per-device (same store as the promo banners).
+ *
+ * On desktop the CLI button links the bundled CLI into PATH via main (the
+ * same flow as the "Install dapi Command Line Tool…" menu item); on the web,
+ * where the CLI can't be installed, it offers the desktop app instead.
+ */
+export function OnboardingPage() {
+ const isDesktop = !!window.desktop;
+ const [cliState, setCliState] = createSignal<StepState>('todo');
+ const [skillsState, setSkillsState] = createSignal<StepState>('todo');
+ // On the web (and on desktop machines without Node) the skills CLI can't
+ // run, so the button degrades to copying the command.
+ const [skillsMode, setSkillsMode] = createSignal<'install' | 'copy'>(
+ isDesktop ? 'install' : 'copy',
+ );
+
+ onMount(async () => {
+ if (!isDesktop) return;
+ try {
+ const [cli, skills] = await Promise.all([
+ mainBridge.call(MAIN_CHANNELS.CLI_IS_INSTALLED, undefined),
+ mainBridge.call(MAIN_CHANNELS.SKILLS_IS_INSTALLED, undefined),
+ ]);
+ if (cli) setCliState('done');
+ if (skills) setSkillsState('done');
+ } catch {
+ // Can't tell — leave the install buttons available.
+ }
+ });
+
+ const installCli = async () => {
+ setCliState('busy');
+ try {
+ const result = await mainBridge.call(MAIN_CHANNELS.CLI_INSTALL, undefined);
+ if (result.status === 'installed') {
+ track('onboarding_cli_installed');
+ setCliState('done');
+ } else {
+ setCliState('todo');
+ if (result.status === 'error') {
+ toast('Could not install the dapi CLI', { description: result.error });
+ }
+ }
+ } catch (error) {
+ setCliState('todo');
+ toast('Could not install the dapi CLI', {
+ description: error instanceof Error ? error.message : 'Unknown error',
+ });
+ }
+ };
+
+ const downloadApp = () => {
+ downloadDesktopApp('onboarding');
+ setCliState('done');
+ };
+
+ const copySkillsCommand = async () => {
+ try {
+ await navigator.clipboard.writeText(SKILLS_COMMAND);
+ track('onboarding_skills_copied');
+ setSkillsState('done');
+ toast('Copied!', {
+ description: 'Run the command in your terminal to install the agent skills.',
+ });
+ } catch (error) {
+ toast('Failed to copy', {
+ description: error instanceof Error ? error.message : 'Unknown error',
+ });
+ }
+ };
+
+ const installSkills = async () => {
+ setSkillsState('busy');
+ try {
+ const result = await mainBridge.call(MAIN_CHANNELS.SKILLS_INSTALL, undefined);
+ if (result.status === 'installed') {
+ track('onboarding_skills_installed');
+ setSkillsState('done');
+ return;
+ }
+ setSkillsState('todo');
+ if (result.npxMissing) {
+ setSkillsMode('copy');
+ toast('Node.js required', {
+ description:
+ 'Installing needs npx, which was not found. Copy the command and run it where Node.js is available.',
+ });
+ } else {
+ toast('Could not install the agent skills', { description: result.error });
+ }
+ } catch (error) {
+ setSkillsState('todo');
+ toast('Could not install the agent skills', {
+ description: error instanceof Error ? error.message : 'Unknown error',
+ });
+ }
+ };
+
+ const allDone = () => cliState() === 'done' && skillsState() === 'done';
+
+ const finish = (event: 'onboarding_completed' | 'onboarding_skipped') => {
+ track(event);
+ setOnboardingCompleted(true);
+ };
+
+ return (
+ <div class="flex flex-col bg-background fixed inset-0 z-999">
+ <Show when={!isDesktop}>
+ <div class="flex items-center gap-1 p-4">
+ <Icon name="diffusion-logo" class="size-6" />
+ <span class="text-sm font-450 text-foreground">Diffusion Studio</span>
+ </div>
+ </Show>
+
+ <div class="flex flex-1 items-center justify-center pb-16">
+ <div class="flex w-124 max-w-[calc(100vw-2rem)] flex-col gap-6">
+ <div class="flex flex-col">
+ <div class="flex flex-col gap-1 px-2 pt-2 pb-3">
+ <h2 class="text-[12px] font-450 text-foreground">Connect your agent</h2>
+ <p class="text-xs text-muted-foreground">
+ Edit videos with coding agents like Claude Code, Codex, or Cursor.
+ </p>
+ </div>
+
+ <div class="flex flex-col gap-3 rounded-xl bg-accent/40 p-4">
+ <SetupRow
+ title="dapi CLI"
+ description={
+ isDesktop
+ ? 'The command line tool for agents to control the editor.'
+ : 'The command line tool for agents. Ships with the desktop app.'
+ }
+ action={
+ isDesktop ? (
+ <StepButton
+ state={cliState()}
+ label="Install"
+ busyLabel="Installing…"
+ doneLabel="Installed"
+ onClick={installCli}
+ />
+ ) : (
+ <StepButton
+ state={cliState()}
+ label="Get app"
+ doneLabel="Downloaded"
+ onClick={downloadApp}
+ />
+ )
+ }
+ />
+
+ <div class="h-px w-full bg-border" />
+
+ <SetupRow
+ title="Agent skills"
+ description="Instructions that help agents edit videos through dapi."
+ action={
+ skillsMode() === 'install' ? (
+ <StepButton
+ state={skillsState()}
+ label="Install"
+ busyLabel="Installing…"
+ doneLabel="Installed"
+ onClick={installSkills}
+ />
+ ) : (
+ <StepButton
+ state={skillsState()}
+ label="Copy command"
+ doneLabel="Copied"
+ onClick={copySkillsCommand}
+ />
+ )
+ }
+ />
+ </div>
+ </div>
+
+ <div class="flex items-center gap-2 px-2">
+ <Button disabled={!allDone()} onClick={() => finish('onboarding_completed')}>
+ Get started
+ </Button>
+ <Button
+ variant="ghost"
+ class="text-muted-foreground"
+ onClick={() => finish('onboarding_skipped')}
+ >
+ Setup later
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}