Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance context reporting in CLI and DAPI

konstantin-paulus0e68a5d8e4d3
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index aa6874e1..2f0a6906 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -597,7 +597,7 @@ program
.command("context")
.alias("ctx")
.description(
- `Print the current app context: which project the app has open (id, display name, folder — or null when none is), where its playhead sits, in seconds, the registered font families, and where its generations stand.`,
+ `Print the current app context: the application root folder (always reported), the folder of the project the app has open (null when none is), where its playhead sits, in seconds, the registered font families, and where its generations stand.`,
)
.action(() => context());
diff --git a/apps/web/src/context/dapi/context.ts b/apps/web/src/context/dapi/context.ts
index dc5a8e7a..1f6a7bb8 100644
--- a/apps/web/src/context/dapi/context.ts
+++ b/apps/web/src/context/dapi/context.ts
@@ -4,6 +4,8 @@
import { AssetId, Computed, Fonts, FrameRate, Generating, getActiveEntity, Library, Name, PendingSource, Source, SourceError } from "@diffusionstudio/runtime";
+import { getProjectsRoot } from "@/projects";
+
import type { Accessor } from "solid-js";
import type { Entity, World } from "koota";
import type { EditorSession } from "./session";
@@ -12,25 +14,25 @@ import type { EditorSession } from "./session";
* 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, which
- * font families are actually registered in the world drawing it. With no
- * project open there is none of that to report, and the report says so.
+ * left over is which folder projects live under, which project folder the app
+ * has open, where its playhead sits, which font families are actually
+ * registered in the world drawing it. With no project open only the root is
+ * left to report, and the report says so.
*/
export function handleContextGet(session: Accessor<EditorSession | null>) {
return async () => {
+ const rootDir = await getProjectsRoot();
+
const open = session();
- if (!open) return { project: null };
+ if (!open) return { rootDir, projectDir: null };
const { world, project } = open;
const frameRate = world.get(FrameRate)?.value || 30;
const active = getActiveEntity(world);
return {
- project: {
- id: project.id(),
- name: project.name(),
- dir: project.dir(),
- },
+ rootDir,
+ projectDir: project.dir(),
// Seconds, the unit the source places clips in; null when no scene is
// active, which is when there is no playhead to report.
currentTime: active ? (active.get(Computed)?.localTime ?? 0) / frameRate : null,
diff --git a/apps/web/src/context/dapi/session.ts b/apps/web/src/context/dapi/session.ts
index b2601b38..55b67460 100644
--- a/apps/web/src/context/dapi/session.ts
+++ b/apps/web/src/context/dapi/session.ts
@@ -14,14 +14,12 @@ import type { Accessor } from "solid-js";
import type { World } from "koota";
/**
- * The open project's identity, as the editor knows it. Structural on purpose:
- * this is the project context's shape, without the handlers having to depend
- * on the Solid context it comes from.
+ * The open project, as the editor knows it. Structural on purpose: this is
+ * the slice of the project context the handlers read, without depending on
+ * the Solid context it comes from.
*/
export type OpenProject = {
- id: () => string;
dir: () => string;
- name: () => string;
};
/** What only an open project can offer: the world drawing it, and which project that is. */
diff --git a/apps/web/src/projects/host.ts b/apps/web/src/projects/host.ts
index dce3137a..e7529c9c 100644
--- a/apps/web/src/projects/host.ts
+++ b/apps/web/src/projects/host.ts
@@ -55,6 +55,12 @@ const ready = new Promise<void>((resolve) => {
export const isDesktop = (): boolean => !!window.desktop;
+/** The projects root, waited for: null off the desktop and until one is picked. */
+export async function getProjectsRoot(): Promise<string | null> {
+ await ready;
+ return projectsRoot();
+}
+
/** Opens the native folder picker and remembers the chosen root. */
export async function pickProjectsRoot(): Promise<string | null> {
const root = await mainBridge.call(MAIN_CHANNELS.PROJECTS_PICK_ROOT, undefined);
diff --git a/reference/context.md b/reference/context.md
index 6bd9fc96..89f1277d 100644
--- a/reference/context.md
+++ b/reference/context.md
@@ -15,11 +15,8 @@ One JSON object:
```ts
{
- project: {
- id: string; // package.json `projectId`, stable across renames
- name: string; // package.json `displayName`, what the user calls it
- dir: string; // absolute project folder — where the JSX being edited lives
- };
+ rootDir: string | null; // absolute folder projects live under; null until one is picked
+ projectDir: string | null; // absolute open project folder — where the JSX being edited lives; null when none is open
currentTime: number | null; // playhead in the active scene, in seconds; null if no scene is active
fontFamilies: string[]; // families registered in the running world, valid as `fontFamily`
generations: { // every generated source in the project, and where it stands
@@ -33,13 +30,16 @@ One JSON object:
```
With no project open (the app sits at the dashboard) the report is just
-`{ project: null }`: there is no playhead, no world, and no fonts to speak of.
-Open one with [`dapi open`](./open.md).
+`{ rootDir, projectDir: null }`: there is no playhead, no world, and no fonts
+to speak of. Open one with [`dapi open`](./open.md).
+
+`rootDir` is reported whether or not a project is open — it is where a caller
+with nothing open goes to create or find one.
`currentTime` is local to the active scene, the same origin a clip's `start`
and `end` are placed against, and in the same unit.
-`project.dir` is the folder the app is editing, which is not necessarily the
+`projectDir` is the folder the app is editing, which is not necessarily the
one a command was run from: check it before writing to source files.
`fontFamilies` is what text can be drawn with right now — loaded into the world,