The VS Code of video editing, built for agents.
TypeScript
Refactor asset and folder command outputs for consistency and clarity
konstantin-paulus67dcb6fdccbb
diff --git a/apps/cli/reference/README.md b/apps/cli/reference/README.mdindex a9bec575..8119f399 100644--- a/apps/cli/reference/README.md+++ b/apps/cli/reference/README.md@@ -116,6 +116,7 @@ Time inputs take the `Time` format unless noted otherwise. Times in **outputs**## Conventions- **Stdout is JSON.** Commands that return a single record emit one JSON value. Commands that return a collection emit JSON Lines (one object per line, no surrounding array) so per-item results stay streamable. `node tree` and `asset tree` emit one nested object per root. Exceptions: `open` for file / URL / no-target writes nothing; `fonts --names-only` writes plain family names; `mount` and `node insert` write nothing.+- **Batch commands are fail-fast** (`node rm`, `node patch`, `asset add`, …): one invalid input fails the whole command with a single stderr message and exit `1`. Ids are validated before anything changes, so a failed `rm`/`mv`/`cp` changes nothing; there are no per-item partial results.- **Unix-style names are canonical:** list/read is `ls`, delete is `rm`, duplicate is `cp`, move/reparent is `mv`, search is `grep`. The longer English forms (`list`, `remove`, `duplicate`, `move`) are aliases of the Unix forms, not the other way around. `get` is a universal alias for `ls`. Commands without a natural Unix equivalent (`tree`, `rename`, `patch`, `add`, `create`, `active`, `context`, `whoami`, `open`, `focus`, `set`) keep their descriptive names.- **Stderr:** human-readable error messages.- **Exit codes:** `0` on success, `1` on any error (missing file, app not running, invalid input, IPC error).diff --git a/apps/cli/reference/asset/add.md b/apps/cli/reference/asset/add.mdindex dd67dce6..b9d39b04 100644--- a/apps/cli/reference/asset/add.md+++ b/apps/cli/reference/asset/add.md@@ -9,13 +9,8 @@ Adds one or more local files as assets in the open project. The counterpart of [## Output-JSON Lines, one per input path:--```ts-| ({ status: "fulfilled"; path: string } & Asset)-| { status: "rejected"; path: string; error: string }-```+JSON Lines on stdout, one `AssetRecord` per added file (the same shape [`asset ls`](./ls.md) prints).## Errors-Exits non-zero before importing anything if `--folder` doesn't resolve to a folder.+Exits non-zero before importing anything if `--folder` doesn't resolve to a folder. A file that fails to import fails the whole command with `<path>: <reason>` on stderr; files imported before the failure stay in the library.diff --git a/apps/cli/reference/asset/export.md b/apps/cli/reference/asset/export.mdindex 4bc20652..cdb8827d 100644--- a/apps/cli/reference/asset/export.md+++ b/apps/cli/reference/asset/export.md@@ -11,13 +11,12 @@ Writes one or more assets' original file bytes to a location on the file system:## Output-JSON Lines, one per input id, in the requested order:+JSON Lines on stdout, one per exported asset, in the requested order:```ts-| { status: "fulfilled"; id: string; path: string } // path = the file actually written-| { status: "rejected"; id: string; error: string }+{ id: string; path: string } // path = the file actually written```## Errors-Exits non-zero before writing anything if `--output` must be a directory (multiple ids, or a trailing path separator) but resolves to an existing file, or if the output directory can't be created. An unknown id, or an image-sequence asset, rejects that id only; a rejected asset leaves no partial file behind.+Exits non-zero before writing anything if `--output` must be a directory (multiple ids, or a trailing path separator) but resolves to an existing file, if the output directory can't be created, if an id is unknown, or if an id is an image-sequence asset. An I/O failure mid-batch aborts the remaining writes and leaves no partial file for the failing asset; files written before it stay.diff --git a/apps/cli/reference/asset/ls.md b/apps/cli/reference/asset/ls.mdindex b316fab7..425856a8 100644--- a/apps/cli/reference/asset/ls.md+++ b/apps/cli/reference/asset/ls.md@@ -17,4 +17,4 @@ AssetRecord = { id: string } & { [property: string]: unknown }## Errors-If any input id fails to resolve, writes a per-id message to stderr and exits non-zero after emitting all successful records to stdout.+An unknown id fails the whole command: nothing is printed to stdout and it exits non-zero with `No such asset: <id>` on stderr.diff --git a/apps/cli/reference/asset/mv.md b/apps/cli/reference/asset/mv.mdindex bab227be..0305f6a2 100644--- a/apps/cli/reference/asset/mv.md+++ b/apps/cli/reference/asset/mv.md@@ -9,13 +9,12 @@ Moves one or more assets into a folder. Alias: `move`.## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per moved asset:```ts-| { status: "fulfilled"; id: string; folderId: string | null }-| { status: "rejected"; id: string; error: string }+{ id: string; folderId: string | null }```## Errors-Exits non-zero before moving anything if `--to` doesn't resolve to a folder; an unknown asset id rejects that id only.+An unknown asset id, or a `--to` that doesn't resolve to a folder, fails the whole command before anything is moved.diff --git a/apps/cli/reference/asset/rm.md b/apps/cli/reference/asset/rm.mdindex eef45210..6236b1c0 100644--- a/apps/cli/reference/asset/rm.md+++ b/apps/cli/reference/asset/rm.md@@ -8,9 +8,12 @@ Deletes one or more assets from the open project by id. Alias: `remove`.## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per deleted asset:```ts-| { status: "fulfilled"; id: string; name: string }-| { status: "rejected"; id: string; error: string }+{ id: string; name: string }```++## Errors++An unknown id fails the whole command before anything is deleted.diff --git a/apps/cli/reference/folder/mv.md b/apps/cli/reference/folder/mv.mdindex 721e971d..c409aee5 100644--- a/apps/cli/reference/folder/mv.md+++ b/apps/cli/reference/folder/mv.md@@ -1,6 +1,6 @@# `dapi folder mv <ids...> [--to <folderId>]`-Moves one or more folders under a new parent. A folder cannot be moved into itself or any of its descendants; such a move rejects that id and leaves it where it was. Alias: `move`.+Moves one or more folders under a new parent. A folder cannot be moved into itself or any of its descendants; such a move fails the command. Alias: `move`.## Input@@ -9,13 +9,12 @@ Moves one or more folders under a new parent. A folder cannot be moved into itse## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per moved folder:```ts-| { status: "fulfilled"; id: string; parentId: string | null }-| { status: "rejected"; id: string; error: string } // unknown id, or a cycle+{ id: string; parentId: string | null }```## Errors-Exits non-zero before moving anything if `--to` doesn't resolve to a folder.+An unknown id, a cycle, or a `--to` that doesn't resolve to a folder fails the whole command before anything is moved.diff --git a/apps/cli/reference/folder/rm.md b/apps/cli/reference/folder/rm.mdindex 909fb169..6deaad12 100644--- a/apps/cli/reference/folder/rm.md+++ b/apps/cli/reference/folder/rm.md@@ -8,10 +8,13 @@ Deletes one or more folders. **Deletion cascades:** every descendant folder and## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per deleted folder:```ts-| { status: "fulfilled"; id: string; deletedFolders: number; deletedAssets: number }- // deletedFolders counts the folder itself plus all descendants-| { status: "rejected"; id: string; error: string }+{ id: string; deletedFolders: number; deletedAssets: number }+// deletedFolders counts the folder itself plus all descendants```++## Errors++An unknown id fails the whole command before anything is deleted.diff --git a/apps/cli/reference/node/cp.md b/apps/cli/reference/node/cp.mdindex d7c888eb..f80d5516 100644--- a/apps/cli/reference/node/cp.md+++ b/apps/cli/reference/node/cp.md@@ -8,9 +8,12 @@ Deep-clones one or more nodes, including all descendants. Alias: `duplicate`.## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per cloned node:```ts-| { status: "fulfilled"; sourceId: number; newId: number }-| { status: "rejected"; sourceId: number; error: string }+{ sourceId: number; newId: number }```++## Errors++An unknown id fails the whole command before anything is cloned.diff --git a/apps/cli/reference/node/ls.md b/apps/cli/reference/node/ls.mdindex c0ea9dcd..6f4696c1 100644--- a/apps/cli/reference/node/ls.md+++ b/apps/cli/reference/node/ls.md@@ -19,4 +19,4 @@ Records are raw engine data: times are frames at 30 fps, colors are packed `0xRR## Errors-If any input id fails to resolve, writes a per-id message to stderr and exits non-zero after emitting all successful records to stdout.+An unknown id fails the whole command: nothing is printed to stdout and it exits non-zero with `No such entity: <id>` on stderr.diff --git a/apps/cli/reference/node/patch.md b/apps/cli/reference/node/patch.mdindex e121db8f..20b7becb 100644--- a/apps/cli/reference/node/patch.md+++ b/apps/cli/reference/node/patch.md@@ -17,10 +17,10 @@ Payload shape:Array<{ id: number } & PatchProps>```-All props are optional; a patch may set any subset. An unsupported property or an out-of-range value rejects that entity; a rejected patch applies none of its props (no half-applied patches). Notes beyond the JSX table:+All props are optional; a patch may set any subset. An unsupported property or an out-of-range value fails the command at that entity; the failing patch applies none of its props (no half-applied patches). Notes beyond the JSX table:- `fill` recolors the entity's existing solid fill(s), or creates one if the entity has none.-- `src` takes a path, URL, or asset id (`generate.*` declarations are JSX-only). The source resolves asynchronously after the other props land; if resolution fails, the entity is reported rejected even though its other props were applied. Patch `src` on its own to avoid ambiguity.+- `src` takes a path, URL, or asset id (`generate.*` declarations are JSX-only). The source resolves asynchronously after the other props land; if resolution fails, the command fails at that entity even though its other props were applied. Patch `src` on its own to avoid ambiguity.- `syncTo` re-runs audio alignment against the document node carrying the given key and writes the entity's `start` from the measured offset (see [jsx/audio-sync.md](../jsx/audio-sync.md)). The command blocks until alignment settles; a failed alignment rejects the entity.- `transition` sets, merges into, or (with `null`) removes the clip's transition into the next clip (see [jsx/transitions.md](../jsx/transitions.md)).- Keyframe lists are accepted wherever the property is animatable, with the same semantics as mount (see [jsx/keyframes.md](../jsx/keyframes.md)); a static value replaces any existing keyframes.@@ -28,9 +28,12 @@ All props are optional; a patch may set any subset. An unsupported property or a## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per patched entity:```ts-| { status: "fulfilled"; id: number }-| { status: "rejected"; id: number; error: string }+{ id: number }```++## Errors++An unknown id fails the whole command before anything is patched. A patch that fails to apply aborts the command at that entity with `Entity <id>: <reason>` on stderr: the failing entity applies none of its props, entities patched before it stay patched, and later entries are not applied.diff --git a/apps/cli/reference/node/rm.md b/apps/cli/reference/node/rm.mdindex 0eb02535..c39c5dac 100644--- a/apps/cli/reference/node/rm.md+++ b/apps/cli/reference/node/rm.md@@ -8,9 +8,12 @@ Deletes one or more entities and all their descendants. Alias: `remove`.## Output-JSON Lines, one per input id:+JSON Lines on stdout, one per deleted entity:```ts-| { status: "fulfilled"; id: number }-| { status: "rejected"; id: number; error: string }+{ id: number }```++## Errors++An unknown id fails the whole command before anything is deleted.diff --git a/apps/cli/src/cli-channels.ts b/apps/cli/src/cli-channels.tsindex 08cfb96d..e390b66f 100644--- a/apps/cli/src/cli-channels.ts+++ b/apps/cli/src/cli-channels.ts@@ -36,9 +36,6 @@ export type NodeRef = { id: number; name: string; type: string };export type EntityRecord = { id: string; eid: number } & Record<string, unknown>;-export type NodeListResult =- | { status: "fulfilled"; node: EntityRecord }- | { status: "rejected"; id: number; error: string };export type NodeTree = NodeRef & {description: string;@@ -67,18 +64,12 @@ export type NodeGrepMatch = { component: string; value: string };export type NodeGrepResult = NodeRef & { matches: NodeGrepMatch[] };-export type NodeDeleteResult =- | { status: "fulfilled"; id: number }- | { status: "rejected"; id: number; error: string };+export type NodeDeleteResult = { id: number };export type MountRequest = {code: string;};-export type MountResult =- | { status: "fulfilled" }- | { status: "rejected"; error: string };-export type NodeInsertRequest = {code: string;parentId: number;@@ -87,13 +78,9 @@ export type NodeInsertRequest = {export type NodePatch = { id: number } & PatchProps;-export type NodePatchResult =- | { status: "fulfilled"; id: number }- | { status: "rejected"; id: number; error: string };+export type NodePatchResult = { id: number };-export type NodeDuplicateResult =- | { status: "fulfilled"; sourceId: number; newId: number }- | { status: "rejected"; sourceId: number; error: string };+export type NodeDuplicateResult = { sourceId: number; newId: number };export type EncoderConfigInput = {format?: "mp4" | "webm" | "ogg" | "mov";@@ -158,27 +145,15 @@ export type AssetTreeEntry = { id: string; name: string; type: string; children?export type AssetRecord = { id: string } & Record<string, unknown>;-export type AssetListResult =- | { status: "fulfilled"; asset: AssetRecord }- | { status: "rejected"; id: string; error: string };--export type AssetMoveResult =- | { status: "fulfilled"; id: string; folderId: string | null }- | { status: "rejected"; id: string; error: string };+export type AssetMoveResult = { id: string; folderId: string | null };export type AssetsExportRequest = { ids: string[]; output: string; isDir: boolean };-export type AssetExportResult =- | { status: "fulfilled"; id: string; path: string }- | { status: "rejected"; id: string; error: string };+export type AssetExportResult = { id: string; path: string };-export type FolderMoveResult =- | { status: "fulfilled"; id: string; parentId: string | null }- | { status: "rejected"; id: string; error: string };+export type FolderMoveResult = { id: string; parentId: string | null };-export type FolderDeleteResult =- | { status: "fulfilled"; id: string; deletedFolders: number; deletedAssets: number }- | { status: "rejected"; id: string; error: string };+export type FolderDeleteResult = { id: string; deletedFolders: number; deletedAssets: number };export type ModelsRequest = { type?: "image" | "video" | "audio" };diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.tsindex c1eb109e..ab3a903e 100644--- a/apps/cli/src/index.ts+++ b/apps/cli/src/index.ts@@ -145,7 +145,9 @@ async function addAssets(paths: string[], opts: AssetAddOptions): Promise<void>try {const results = await editor.asset.add.mutate({ paths: absolutePaths, folderId: opts.folder });- for (const result of results) console.log(JSON.stringify(result));+ for (const result of results) {+ console.log(JSON.stringify(result));+ }} catch (e) {handleSocketError(e);}@@ -155,16 +157,9 @@ async function listAssets(ids: string[]): Promise<void> {try {// No ids → every asset in the library; with ids → those specific assets.const results = await editor.asset.list.query({ ids: ids.length ? ids : undefined });- let failed = false;for (const result of results) {- if (result.status === "fulfilled") {- console.log(JSON.stringify(result.asset));- } else {- console.error(result.error);- failed = true;- }+ console.log(JSON.stringify(result));}- if (failed) process.exit(1);} catch (e) {handleSocketError(e);}@@ -337,7 +332,9 @@ async function setSelection(ids: string[]): Promise<void> {async function focusSelection(): Promise<void> {try {const results = await editor.selection.focus.mutate();- for (const result of results) console.log(JSON.stringify(result));+ for (const result of results) {+ console.log(JSON.stringify(result));+ }} catch (e) {handleSocketError(e);}@@ -347,16 +344,9 @@ async function listNodes(ids: string[]): Promise<void> {try {// No ids → root scenes; with ids → those specific nodes.const results = await editor.node.list.query({ ids: ids.length ? parseNodeIds(ids) : undefined });- let failed = false;for (const result of results) {- if (result.status === "fulfilled") {- console.log(JSON.stringify(result.node));- } else {- console.error(result.error);- failed = true;- }+ console.log(JSON.stringify(result));}- if (failed) process.exit(1);} catch (e) {handleSocketError(e);}@@ -718,12 +708,8 @@ async function mountProject(path: string | undefined, opts: MountOptions): Promiconst stop = startSpinner("Mounting project");try {- const result = await editor.mount.mutate({ code }, GENERATE);+ await editor.mount.mutate({ code }, GENERATE);stop();- if (result.status === "rejected") {- console.error(result.error);- process.exit(1);- }} catch (e) {stop();handleSocketError(e);@@ -749,12 +735,8 @@ async function nodeInsert(parentId: string, path: string | undefined, opts: Nodeconst stop = startSpinner("Inserting entities");try {- const result = await editor.node.insert.mutate({ code, parentId: eid, index }, GENERATE);+ await editor.node.insert.mutate({ code, parentId: eid, index }, GENERATE);stop();- if (result.status === "rejected") {- console.error(result.error);- process.exit(1);- }} catch (e) {stop();handleSocketError(e);@@ -1263,7 +1245,7 @@ folder.command("mv").alias("move").description(- `Move one or more folders under a new parent. A folder cannot move into itself or a descendant; such a move rejects that id.`,+ `Move one or more folders under a new parent. A folder cannot move into itself or a descendant; such a move fails the command before anything moves.`,).argument("<ids...>", "folder ids to move").option("--to <folderId>", "destination parent folder (default: the library root); fails before moving anything if it doesn't resolve to a folder")diff --git a/apps/cli/src/open-folder.ts b/apps/cli/src/open-folder.tsindex e6e455ba..598cd369 100644--- a/apps/cli/src/open-folder.ts+++ b/apps/cli/src/open-folder.ts@@ -148,11 +148,7 @@ export async function openFolder(folderPath: string): Promise<OpenFolderResult>for (const { segments, paths } of assetDirs) {const folderId = await ensureFolder(segments, folderIds);const results = await editor.asset.add.mutate({ paths, folderId });- if (Array.isArray(results)) {- imported += results.filter(- (r: { status?: string }) => r?.status === "fulfilled",- ).length;- }+ imported += results.length;}writeMarker(folderPath, project.id);diff --git a/apps/web/src/context/editor-api/assets.ts b/apps/web/src/context/editor-api/assets.tsindex 265e8869..bdbcc036 100644--- a/apps/web/src/context/editor-api/assets.ts+++ b/apps/web/src/context/editor-api/assets.ts@@ -14,25 +14,25 @@ import {import type { Engine } from "@/components/engine";import type { Asset } from "@/components/engine/db";-import type { AssetExportResult, AssetListResult, AssetMoveResult, AssetRecord, AssetsExportRequest, AssetTreeEntry } from "@diffusionstudio/cli/channels";+import type { AssetExportResult, AssetMoveResult, AssetRecord, AssetsExportRequest, AssetTreeEntry } from "@diffusionstudio/cli/channels";import type { Accessor } from "solid-js";export function handleAssetsAdd(engine: Accessor<Engine>) {- return async ({ paths, folderId }: { paths: string[]; folderId?: string }) => {+ return async ({ paths, folderId }: { paths: string[]; folderId?: string }): Promise<AssetRecord[]> => {const { world } = engine();if (folderId !== undefined) {assert(world.folders.has(folderId), `Folder ${folderId} not found.`);}- const settled = await Promise.allSettled(- paths.map((path) => loadAsset(world, new ElectronFileHandle(path), { folderId }))+ const assets = await Promise.all(+ paths.map(async (path) => {+ try {+ return await loadAsset(world, new ElectronFileHandle(path), { folderId });+ } catch (e) {+ throw new Error(`${path}: ${(e as Error)?.message ?? String(e)}`);+ }+ }));-- const results = settled.map((r, i) =>- r.status === 'rejected'- ? { status: "rejected", path: paths[i], error: (r.reason as Error)?.message ?? String(r.reason) }- : { status: "fulfilled", ...toAssetRecord(r.value) }- );- return results;+ return assets.map(toAssetRecord);}}@@ -49,26 +49,26 @@ function toAssetRecord(asset: Asset): AssetRecord {}export function handleAssetsList(engine: Accessor<Engine>) {- return async ({ ids }: { ids?: string[] }): Promise<AssetListResult[]> => {+ return async ({ ids }: { ids?: string[] }): Promise<AssetRecord[]> => {const { world } = engine();// No ids → every asset in the libraryif (ids === undefined || ids.length === 0) {- return Array.from(world.assets.values()).map((asset) => ({- status: "fulfilled",- asset: toAssetRecord(asset),- }));+ return Array.from(world.assets.values()).map(toAssetRecord);}- return ids.map((id) => {- const asset = world.assets.get(id);- return asset- ? { status: "fulfilled", asset: toAssetRecord(asset) }- : { status: "rejected", id, error: `No such asset: ${id}` };- });+ return resolveAssets(world, ids).map(toAssetRecord);};}+function resolveAssets(world: Engine["world"], ids: string[]): Asset[] {+ return ids.map((id) => {+ const asset = world.assets.get(id);+ assert(asset, `No such asset: ${id}`);+ return asset;+ });+}+export function handleAssetTree(engine: Accessor<Engine>) {return async ({ folderId, depth }: { folderId?: string; depth?: number }): Promise<AssetTreeEntry[]> => {const { world } = engine();@@ -112,27 +112,17 @@ export function handleAssetsMove(engine: Accessor<Engine>) {assert(world.folders.has(to), `Folder ${to} not found.`);}const folderId = to ?? null;- const results: AssetMoveResult[] = ids.map((id) =>- world.assets.has(id)- ? { status: "fulfilled", id, folderId }- : { status: "rejected", id, error: "Not found" });- const foundIds = results.filter((r) => r.status === "fulfilled").map((r) => r.id);- if (foundIds.length > 0) await moveAssetsToFolder(world, foundIds, folderId);- return results;+ resolveAssets(world, ids);+ await moveAssetsToFolder(world, ids, folderId);+ return ids.map((id) => ({ id, folderId }));}}export function handleAssetsDelete(engine: Accessor<Engine>) {- return async ({ ids }: { ids: string[] }) => {+ return async ({ ids }: { ids: string[] }): Promise<Array<{ id: string; name: string }>> => {const { world } = engine();- const results = ids.map((id) => {- const asset = world.assets.get(id);- return asset- ? { status: "fulfilled", id, name: asset.name }- : { status: "rejected", id, error: "Not found" };- });- const foundIds = results.filter((r) => r.status === "fulfilled").map((r) => r.id);- if (foundIds.length > 0) await removeAsset(world, ...foundIds);+ const results = resolveAssets(world, ids).map((asset) => ({ id: asset.id, name: asset.name }));+ await removeAsset(world, ...ids);return results;}}@@ -140,20 +130,17 @@ export function handleAssetsDelete(engine: Accessor<Engine>) {export function handleAssetsExport(engine: Accessor<Engine>) {return async ({ ids, output, isDir }: AssetsExportRequest): Promise<AssetExportResult[]> => {const { world } = engine();+ const assets = resolveAssets(world, ids);+ for (const asset of assets) {+ assert(asset.type !== "SEQUENCE", `Asset ${asset.id} is an image sequence; export is not supported.`);+ }const results: AssetExportResult[] = [];- for (const id of ids) {- try {- const asset = world.assets.get(id);- assert(asset, `Asset ${id} not found.`);- assert(asset.type !== "SEQUENCE", `Asset ${id} is an image sequence; export is not supported.`);- const blob = await getAssetFile(asset);- const path = isDir- ? await streamBlobToDir(blob, output, exportFileName(asset))- : await streamBlobToFile(blob, output);- results.push({ status: "fulfilled", id, path });- } catch (e) {- results.push({ status: "rejected", id, error: (e as Error)?.message ?? String(e) });- }+ for (const asset of assets) {+ const blob = await getAssetFile(asset);+ const path = isDir+ ? await streamBlobToDir(blob, output, exportFileName(asset))+ : await streamBlobToFile(blob, output);+ results.push({ id: asset.id, path });}return results;};diff --git a/apps/web/src/context/editor-api/folders.ts b/apps/web/src/context/editor-api/folders.tsindex 268c1083..51545a87 100644--- a/apps/web/src/context/editor-api/folders.ts+++ b/apps/web/src/context/editor-api/folders.ts@@ -6,6 +6,7 @@ import { assert } from '@/utils';import {createFolder,deleteFolder,+ isDescendantFolder,moveFolder,renameFolder,useFolders,@@ -58,32 +59,31 @@ export function handleFoldersMove(engine: Accessor<Engine>) {assert(world.folders.has(to), `Folder ${to} not found.`);}const parentId = to ?? null;- const results: FolderMoveResult[] = [];+ // Validate every move before applying any, so a bad id changes nothing.for (const id of ids) {- if (!world.folders.has(id)) {- results.push({ status: "rejected", id, error: "Not found" });- continue;- }- const moved = await moveFolder(world, id, parentId);- results.push(moved- ? { status: "fulfilled", id, parentId }- : { status: "rejected", id, error: "Cannot move a folder into itself or one of its descendants" });+ assert(world.folders.has(id), `No such folder: ${id}`);+ assert(+ parentId === null || (parentId !== id && !isDescendantFolder(world, parentId, id)),+ `Cannot move folder ${id} into itself or one of its descendants`,+ );}- return results;+ for (const id of ids) {+ await moveFolder(world, id, parentId);+ }+ return ids.map((id) => ({ id, parentId }));}}export function handleFoldersDelete(engine: Accessor<Engine>) {return async ({ ids }: { ids: string[] }): Promise<FolderDeleteResult[]> => {const { world } = engine();+ for (const id of ids) {+ assert(world.folders.has(id), `No such folder: ${id}`);+ }const results: FolderDeleteResult[] = [];for (const id of ids) {- if (!world.folders.has(id)) {- results.push({ status: "rejected", id, error: "Not found" });- continue;- }const { deletedFolders, deletedAssets } = await deleteFolder(world, id);- results.push({ status: "fulfilled", id, deletedFolders, deletedAssets });+ results.push({ id, deletedFolders, deletedAssets });}return results;}diff --git a/apps/web/src/context/editor-api/mount.ts b/apps/web/src/context/editor-api/mount.tsindex 0e6023e4..9666ca1e 100644--- a/apps/web/src/context/editor-api/mount.ts+++ b/apps/web/src/context/editor-api/mount.ts@@ -11,14 +11,14 @@ import { resolveEntityEid } from "./node";import { hasComponent } from "bitecs";import type { Accessor } from "solid-js";-import type { MountRequest, MountResult, NodeInsertRequest } from "@diffusionstudio/cli/channels";+import type { MountRequest, NodeInsertRequest } from "@diffusionstudio/cli/channels";import type { Engine } from "@/components/engine";/*** `dapi mount` — evaluates a compiled project module and renders it directly into the ECS world*/export function handleMount(engine: Accessor<Engine>) {- return async ({ code }: MountRequest): Promise<MountResult> => {+ return async ({ code }: MountRequest): Promise<void> => {const e = engine();const world = e.world;const c = world.components;@@ -52,13 +52,9 @@ export function handleMount(engine: Accessor<Engine>) {switchActiveScene(world, document.rootEid);e.camera.fitToActiveScene();}- } catch (error) {- return { status: "rejected", error: error instanceof Error ? error.message : String(error) };} finally {dispose?.();}-- return { status: "fulfilled" };};}@@ -70,7 +66,7 @@ export function handleMount(engine: Accessor<Engine>) {* `<colorStop>` roots.*/export function handleNodeInsert(engine: Accessor<Engine>) {- return async ({ code, parentId, index }: NodeInsertRequest): Promise<MountResult> => {+ return async ({ code, parentId, index }: NodeInsertRequest): Promise<void> => {const e = engine();const world = e.world;let dispose = () => { };@@ -101,12 +97,8 @@ export function handleNodeInsert(engine: Accessor<Engine>) {} finally {world.history.commitTransaction();}- } catch (error) {- return { status: "rejected", error: error instanceof Error ? error.message : String(error) };} finally {dispose?.();}-- return { status: "fulfilled" };};}diff --git a/apps/web/src/context/editor-api/node.ts b/apps/web/src/context/editor-api/node.tsindex c8907884..a3e57a4b 100644--- a/apps/web/src/context/editor-api/node.ts+++ b/apps/web/src/context/editor-api/node.ts@@ -28,7 +28,6 @@ import type {NodeGrepMatch,NodeGrepRequest,NodeGrepResult,- NodeListResult,NodePatch,NodePatchResult,NodeRef,@@ -73,29 +72,17 @@ export function resolveNodeEid(world: EngineWorld, eid: number): number {}export function handleNodeList(engine: Accessor<Engine>) {- return async ({ ids }: { ids?: number[] }): Promise<NodeListResult[]> => {+ return async ({ ids }: { ids?: number[] }): Promise<EntityRecord[]> => {const { world } = engine();const c = world.components;// No ids → the root: top-level nodesif (ids === undefined || ids.length === 0) {const roots = [...query(world, [c.Geometry, Not(ChildOf("*")), Not(c.Deleted)])];- return roots.map((eid) => ({- status: "fulfilled",- node: serializeEntity(world, eid) as EntityRecord,- }));+ return roots.map((eid) => serializeEntity(world, eid) as EntityRecord);}- return ids.map((id) => {- try {- return {- status: "fulfilled",- node: serializeEntity(world, resolveEntityEid(world, id)) as EntityRecord,- };- } catch (e) {- return { status: "rejected", id, error: (e as Error).message };- }- });+ return ids.map((id) => serializeEntity(world, resolveEntityEid(world, id)) as EntityRecord);};}@@ -340,59 +327,34 @@ export function handleNodeRender(engine: Accessor<Engine>) {export function handleNodeDelete(engine: Accessor<Engine>) {return async ({ ids }: { ids: number[] }): Promise<NodeDeleteResult[]> => {const { world } = engine();- const resolved = ids.map((id) => {- try {- return { id, eid: resolveEntityEid(world, id) };- } catch (e) {- return { id, error: (e as Error).message };- }- });+ const eids = ids.map((id) => resolveEntityEid(world, id));- const toDelete = resolved.filter((r): r is { id: number; eid: number } => "eid" in r);world.history.transaction("deleting nodes", () => {- for (const { eid } of toDelete) {+ for (const eid of eids) {deleteEntity(world, eid);}});- return resolved.map((r) =>- "eid" in r- ? { status: "fulfilled", id: r.id }- : { status: "rejected", id: r.id, error: r.error },- );+ return ids.map((id) => ({ id }));};}export function handleNodeDuplicate(engine: Accessor<Engine>) {return async ({ ids }: { ids: number[] }): Promise<NodeDuplicateResult[]> => {const { world } = engine();- const resolved = ids.map((id) => {- try {- const eid = resolveNodeEid(world, id);- return { id, tree: getEntityTree(world, eid) };- } catch (e) {- return { id, error: (e as Error).message };- }- });-- const toClone = resolved.filter(- (r): r is { id: number; tree: number[] } => "tree" in r,- );+ const resolved = ids.map((id) => ({+ id,+ tree: getEntityTree(world, resolveNodeEid(world, id)),+ }));const newRootEids = new Map<number, number>();- if (toClone.length > 0) {- world.history.transaction("duplicating nodes", () => {- for (const { id, tree } of toClone) {- newRootEids.set(id, cloneSubtree(world, tree).get(id)!);- }- });- }+ world.history.transaction("duplicating nodes", () => {+ for (const { id, tree } of resolved) {+ newRootEids.set(id, cloneSubtree(world, tree).get(id)!);+ }+ });- return resolved.map((r) =>- "tree" in r- ? { status: "fulfilled", sourceId: r.id, newId: newRootEids.get(r.id)! }- : { status: "rejected", sourceId: r.id, error: r.error },- );+ return ids.map((id) => ({ sourceId: id, newId: newRootEids.get(id)! }));};}@@ -401,16 +363,21 @@ export function handleNodePatch(engine: Accessor<Engine>) {const e = engine();const world = e.world;+ // Entity ids are validated upfront; a failing patch still aborts the+ // batch mid-way, leaving earlier patches applied (and its own props+ // rolled back).+ for (const patch of patches) {+ resolveEntityEid(world, patch.id);+ }+const results: NodePatchResult[] = [];for (const patch of patches) {const doc = new WorldDocument(e);try {- const eid = resolveEntityEid(world, patch.id);-world.history.startTransaction("patching node");try {- const node = doc.element(eid);+ const node = doc.element(resolveEntityEid(world, patch.id));for (const [key, value] of Object.entries(patch)) {if (key === "id") continue;doc.setProperty(node, key, value);@@ -429,11 +396,11 @@ export function handleNodePatch(engine: Accessor<Engine>) {} finally {world.history.commitTransaction();}-- results.push({ status: "fulfilled", id: patch.id });} catch (error) {- results.push({ status: "rejected", id: patch.id, error: (error as Error).message });+ throw new Error(`Entity ${patch.id}: ${(error as Error).message}`);}++ results.push({ id: patch.id });}return results;diff --git a/docs/cli.md b/docs/cli.mdindex af146c05..e464c434 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -9,7 +9,7 @@- **Exit codes:** `0` on success, `1` on any error.- **Unix names are canonical:** `ls`, `rm`, `cp`, `mv`, `grep`. The English forms (`list`, `remove`, `duplicate`, `move`) are aliases, and `get` is an alias for every `ls`.- **Group aliases:** `selection`→`sel`, `node`→`n`, `project`→`p`, `asset`→`a`, `folder`→`fld`, `context`→`ctx`.-- **Batch commands** (`node rm`, `node patch`, `asset add`, …) emit one `{ status: "fulfilled" | "rejected", … }` line per input, so partial failures are visible per item.+- **Batch commands are fail-fast** (`node rm`, `node patch`, `asset add`, …): one invalid input fails the whole command with a single stderr message and exit `1`. Ids are validated before anything changes, so a failed `rm`/`mv`/`cp` changes nothing; there are no per-item partial results.### Time values@@ -69,7 +69,7 @@ dapi node insert <paintId> --code '<colorStop offset={0.5} color="#FF0055" />'dapi node patch ([path.json] | --json <str>)```-Assigns JSX props on existing entities. The payload is an array of `{ id, …props }`, taking exactly the props a JSX element takes (see the [element reference](composition.md#elements)). A rejected entry applies none of its props. Renaming is patching `name`; recoloring is patching `fill`; paints and color stops are patchable too. A [transition](composition.md#transitions) is patched as a `transition` prop on the outgoing clip (`null` removes it).+Assigns JSX props on existing entities. The payload is an array of `{ id, …props }`, taking exactly the props a JSX element takes (see the [element reference](composition.md#elements)). A failing entry applies none of its props and aborts the command. Renaming is patching `name`; recoloring is patching `fill`; paints and color stops are patchable too. A [transition](composition.md#transitions) is patched as a `transition` prop on the outgoing clip (`null` removes it).```shdapi node patch --json '[{ "id": 42, "x": 100, "opacity": 0.5 }]'