The VS Code of video editing, built for agents.
TypeScript
Enhance context reporting in CLI and desktop applications
konstantin-paulusc629822d3f75
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.tsindex 89aff7f5..e8033d55 100644--- a/apps/cli/src/index.ts+++ b/apps/cli/src/index.ts@@ -598,7 +598,7 @@ program.command("context").alias("ctx").description(- `Print the current app context: which project the app has open (id, display name, folder), where its playhead sits, in seconds, and the registered font families.`,+ `Print the current app context: which project the app has open (id, display name, folder), where its playhead sits, in seconds, the registered font families, and where its generations stand.`,).action(() => context());diff --git a/apps/desktop/src/projects.ts b/apps/desktop/src/projects.tsindex 82f0ba0f..7774db23 100644--- a/apps/desktop/src/projects.ts+++ b/apps/desktop/src/projects.ts@@ -419,7 +419,8 @@ export default function Project() {survives the file being relinked), an asset id, a URL, or an absolute path.- Generated assets are declared rather than fetched: \`src={generate.image({ prompt })}\`,and \`generate.video\`, \`generate.voice\`, \`generate.audio\`. They are produced on- mount, in dependency order.+ mount, in dependency order. \`dapi context\` reports where each stands:+ generating, failed with the reason, or done with the asset path it landed as.- Solid is fully available while mounting: \`<For>\`, \`<Show>\`, \`createMemo\`, and\`useTicker()\` for values that follow the playhead.- npm packages work as they normally do. The folder is a real npm package, so@@ -439,7 +440,7 @@ All of them talk to the running app, except \`fonts\` and \`fetch\`.| Script | Command | What it does || ------ | ------- | ------------ || \`open\` | \`dapi open .\` | Launch the app with this project open. |-| \`context\` | \`dapi context\` | Which project the app has open, where its playhead sits, its fonts. |+| \`context\` | \`dapi context\` | Which project the app has open, where its playhead sits, its fonts, where its generations stand. || \`capture\` | \`dapi capture <id>\` | Render one node in isolation to labelled PNG contact sheets. || \`probe\` | \`dapi media probe <id\\|path>\` | Container and per-track metadata, without decoding. || \`transcribe\` | \`dapi media transcribe <id\\|path>\` | Timed speech transcript, word by word. |diff --git a/apps/web/src/context/dapi/context.ts b/apps/web/src/context/dapi/context.tsindex a7193241..19cb34b7 100644--- a/apps/web/src/context/dapi/context.ts+++ b/apps/web/src/context/dapi/context.ts@@ -2,9 +2,9 @@* 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 { Computed, Fonts, FrameRate, getActiveEntity } from "@diffusionstudio/runtime";+import { AssetId, Computed, Fonts, FrameRate, Generating, getActiveEntity, Library, Name, PendingSource, Source, SourceError } from "@diffusionstudio/runtime";-import type { World } from "koota";+import type { Entity, World } from "koota";/*** The open project's identity, as the editor knows it. Structural on purpose:@@ -21,8 +21,8 @@ type OpenProject = {* What `dapi context` reports: what the project's source cannot say. The JSX is* the composition — its scenes, what is selected, which scene is active, the* work area are all in the file, and a caller that wants them reads it. What is- * left over is which project the app has open, where its playhead sits, and- * which font families are actually registered in the world drawing it.+ * left over is which project the app has open, where its playhead sits, which+ * font families are actually registered in the world drawing it*/export function handleContextGet(world: World, project: OpenProject) {return async () => {@@ -41,6 +41,61 @@ export function handleContextGet(world: World, project: OpenProject) {// What text can be drawn with right now: registered in the world, not// merely named in the source. The editor default is always among them.fontFamilies: [...new Set(["Inter", ...(world.get(Fonts)?.list ?? []).map((f) => f.family)])],+ generations: collectGenerations(world),};}}++type GenerationRow = {+ /** The element's source stamp, `<file>:<key or position>`; null for an+ * entity no element produced. */+ element: string | null;+ name: string | null;+ state: "generating" | "failed" | "done";+ /** What the generation failed with, on `failed` rows. */+ error?: string;+ /** The library path the generation landed as, on `done` rows — ready for+ * `dapi media probe` and its siblings. */+ asset?: string;+};++function collectGenerations(world: World): GenerationRow[] {+ const library = world.get(Library);+ const rows: GenerationRow[] = [];+ const seen = new Set<string>();++ const push = (row: GenerationRow) => {+ const key = JSON.stringify(row);+ if (seen.has(key)) return;+ seen.add(key);+ rows.push(row);+ };++ for (const entity of world.query(Generating)) {+ push({ ...describeElement(entity), state: "generating" });+ }++ for (const entity of world.query(SourceError)) {+ const failure = entity.get(SourceError)!;+ if (!failure.generated) continue;+ push({ ...describeElement(entity), state: "failed", error: failure.value });+ }++ for (const entity of world.query(AssetId)) {+ // A stale binding — the element is off generating a new answer or failed+ // getting one — is not a generation that is done.+ if (entity.has(Generating) || entity.has(PendingSource) || entity.has(SourceError)) continue;+ const asset = library?.get(entity.get(AssetId)!.value);+ if (!asset?.generation) continue;+ push({ ...describeElement(entity), state: "done", asset: asset.path });+ }++ return rows;+}++function describeElement(entity: Entity): Pick<GenerationRow, "element" | "name"> {+ return {+ element: entity.get(Source)?.value || null,+ name: entity.get(Name)?.value || null,+ };+}