The VS Code of video editing, built for agents.
TypeScript
Add `screenshot` command to CLI and implement screenshot functionality
konstantin-paulusd083cd76ed24
diff --git a/apps/cli/reference/README.md b/apps/cli/reference/README.mdindex 5b713c28..fde58918 100644--- a/apps/cli/reference/README.md+++ b/apps/cli/reference/README.md@@ -6,7 +6,7 @@ Each feature command has its own file (linked below). The JSX code syntax consum## Groups-**Top-level:** [`open`](./open.md), [`whoami`](./whoami.md), [`logs`](./logs.md), [`context`](./context.md) (alias `ctx`), [`mount`](./mount.md), [`models`](./models.md), [`voices`](./voices.md), [`fonts`](./fonts.md), [`fetch`](./fetch.md).+**Top-level:** [`open`](./open.md), [`whoami`](./whoami.md), [`logs`](./logs.md), [`screenshot`](./screenshot.md), [`context`](./context.md) (alias `ctx`), [`mount`](./mount.md), [`models`](./models.md), [`voices`](./voices.md), [`fonts`](./fonts.md), [`fetch`](./fetch.md).| Group | Alias | Scope || ----- | ----- | ----- |@@ -31,6 +31,7 @@ How the surface is divided:- [`dapi open`](./open.md): launch the app, or open a file, folder, or deep link- [`dapi whoami`](./whoami.md): print the authenticated account- [`dapi logs`](./logs.md): recent console output from the running app+- [`dapi screenshot`](./screenshot.md): capture the entire application window as a PNG### Documentdiff --git a/apps/cli/reference/screenshot.md b/apps/cli/reference/screenshot.mdnew file mode 100644index 00000000..a3be05e4--- /dev/null+++ b/apps/cli/reference/screenshot.md@@ -0,0 +1,21 @@+# `dapi screenshot`++Captures the entire application window as a PNG: the full UI as the user sees it (panels, timeline, asset library, canvas viewport), at the window's current size. Use it to check what the app itself looks like; to render a node or scene cleanly for composition checks use [`node capture`](./node/capture.md) instead.++The shot is taken from the app's own window buffer, so it works even when the window is hidden (launched with `open --background`) or covered by other windows, and never includes anything outside the app.++## Options++- `-o, --output <dir>`: directory to write the PNG into (default: the system temp directory)++## Output++One JSON object: the absolute path to a freshly written PNG with a uuid filename, plus the image's pixel dimensions.++```ts+{ path: string, width: number, height: number }+```++## Errors++Exits non-zero if the app is not running.diff --git a/apps/cli/src/cli-channels.ts b/apps/cli/src/cli-channels.tsindex 3539d248..50043d32 100644--- a/apps/cli/src/cli-channels.ts+++ b/apps/cli/src/cli-channels.ts@@ -175,6 +175,8 @@ export type ProjectSummary = {lastAccessedAt: string;};+export type ScreenshotResult = { base64: string; width: number; height: number };+export type LogLevel = "debug" | "info" | "warning" | "error";export type LogEntry = { ts: number; level: LogLevel; message: string; source: string };diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.tsindex e9a2fa90..ab6db483 100644--- a/apps/cli/src/index.ts+++ b/apps/cli/src/index.ts@@ -986,6 +986,21 @@ async function showLogs(opts: LogsOptions): Promise<void> {}}+type ScreenshotOptions = { output?: string };++async function appScreenshot(opts: ScreenshotOptions): Promise<void> {+ const dir = opts.output ?? tmpdir();+ mkdirSync(dir, { recursive: true });+ try {+ const { base64, width, height } = await editor.screenshot.query();+ const path = join(dir, `${randomUUID()}.png`);+ writeFileSync(path, Buffer.from(base64, "base64"));+ console.log(JSON.stringify({ path, width, height }));+ } catch (e) {+ handleSocketError(e);+ }+}+function startSpinner(label: string): () => void {if (!process.stderr.isTTY) {process.stderr.write(`${label}…\n`);@@ -1490,6 +1505,14 @@ program.option("-l, --level <level>", `minimum level to include: "debug", "info", "warning", or "error"`).action((opts: LogsOptions) => showLogs(opts));+program+ .command("screenshot")+ .description(+ `Capture the entire application window as a PNG — the full UI as the user sees it (panels, timeline, asset library, canvas viewport), at the window's current size. The tool for checking what the app itself looks like; to render a node or scene cleanly for composition checks use \`node capture\` instead. Works even when the app was launched hidden (\`open --background\`).`,+ )+ .option("-o, --output <dir>", "directory to write the PNG into (default: system temp dir)")+ .action((opts: ScreenshotOptions) => appScreenshot(opts));+program.command("fonts").description(diff --git a/apps/desktop/src/main-channels.ts b/apps/desktop/src/main-channels.tsindex 660408de..ad78c885 100644--- a/apps/desktop/src/main-channels.ts+++ b/apps/desktop/src/main-channels.ts@@ -9,7 +9,7 @@//// CLI traffic uses a separate wire pair (CLI_WIRE in @diffusionstudio/cli/protocol);// main forwards it opaquely without inspecting channel names.-import type { LogEntry } from "@diffusionstudio/cli/protocol";+import type { LogEntry, ScreenshotResult } from "@diffusionstudio/cli/protocol";export const MAIN_WIRE = {REQUEST: "main:request",@@ -29,6 +29,7 @@ export const MAIN_CHANNELS = {APP_OPEN_EXTERNAL: "app:open-external",AUTH_GET_PENDING_CALLBACK: "auth:get-pending-callback",WINDOW_IS_FULLSCREEN: "window:is-fullscreen",+ WINDOW_CAPTURE: "window:capture",FILE_TRANSFER: "file:transfer",FILE_WRITE_OPEN: "file:write-open",FILE_WRITE_CHUNK: "file:write-chunk",@@ -49,6 +50,7 @@ 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.WINDOW_IS_FULLSCREEN]: { request: void; response: boolean };+ [MAIN_CHANNELS.WINDOW_CAPTURE]: { request: void; response: ScreenshotResult };[MAIN_CHANNELS.FILE_TRANSFER]: {request: { selector: string; absolutePath: string };response: void;diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 3f1e33ef..81be8579 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -208,6 +208,12 @@ if (app.requestSingleInstanceLock()) {return url;});mainBridge.handle(MAIN_CHANNELS.WINDOW_IS_FULLSCREEN, () => mainWindow?.isFullScreen() ?? false);+ mainBridge.handle(MAIN_CHANNELS.WINDOW_CAPTURE, async () => {+ if (!mainWindow || mainWindow.isDestroyed()) throw new Error("No main window");+ const image = await mainWindow.webContents.capturePage(undefined, { stayHidden: true });+ const { width, height } = image.getSize();+ return { base64: image.toPNG().toString("base64"), width, height };+ });mainBridge.handle(MAIN_CHANNELS.HEADLESS_GET_MODE, () => isHeadless());mainBridge.handle(MAIN_CHANNELS.LOGS_GET, () => logBuffer);mainBridge.handle(MAIN_CHANNELS.FILE_TRANSFER, ({ selector, absolutePath }) =>diff --git a/apps/web/src/context/editor-api/api.tsx b/apps/web/src/context/editor-api/api.tsxindex c7e8b353..a1c374c0 100644--- a/apps/web/src/context/editor-api/api.tsx+++ b/apps/web/src/context/editor-api/api.tsx@@ -22,7 +22,7 @@ import { cliBridge, mainBridge } from '@/lib/ipc';import { createRouterCaller } from '@/lib/cli-rpc';import { MAIN_CHANNELS } from '@desktop/main-channels';import { assert } from "@/utils/common";-import { handleGetFullscreenState, handleWindowFullscreenChange } from "./window";+import { handleGetFullscreenState, handleWindowFullscreenChange, handleWindowScreenshot } from "./window";import type { JSX, Accessor } from 'solid-js';import type { User } from '@supabase/supabase-js';@@ -101,6 +101,7 @@ function createAppRouter({ getEngine, getUser, requireAuth, setParams }: AppRoutmount: m(handleMount(getEngine)),models: q(handleModels()),logs: q(handleLogs()),+ screenshot: q0(handleWindowScreenshot()),voices: q0(handleVoices()),asset: t.router({add: m(handleAssetsAdd(getEngine)),diff --git a/apps/web/src/context/editor-api/window.ts b/apps/web/src/context/editor-api/window.tsindex d431e1ff..721f9ec3 100644--- a/apps/web/src/context/editor-api/window.ts+++ b/apps/web/src/context/editor-api/window.ts@@ -9,6 +9,10 @@ export function handleGetFullscreenState() {return mainBridge.call(MAIN_CHANNELS.WINDOW_IS_FULLSCREEN, undefined);}+export function handleWindowScreenshot() {+ return () => mainBridge.call(MAIN_CHANNELS.WINDOW_CAPTURE, undefined);+}+export function handleWindowFullscreenChange(mutate: (fullscreen: boolean) => void) {return ({ fullscreen }: { fullscreen: boolean }) => mutate(fullscreen);}