Skip to content

Commit abf4535

Browse files
authored
feat(studio): open local project directories
Closes #45
1 parent 3fc99cc commit abf4535

8 files changed

Lines changed: 1321 additions & 12 deletions

File tree

‎apps/studio/src-tauri/src/lib.rs‎

Lines changed: 646 additions & 2 deletions
Large diffs are not rendered by default.

‎apps/studio/src/App.test.tsx‎

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
StudioWorkspaceView,
1414
} from "@ignitionrl/sdk";
1515
import { App } from "./App";
16-
import type { NativeStudioApi } from "./native";
16+
import type { NativeIgnitionProjectDirectory, NativeStudioApi } from "./native";
1717
import { sampleWorkspace } from "./sample-workspace";
1818

1919
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -222,6 +222,7 @@ describe("Studio app shell", () => {
222222
};
223223
const nativeApi: NativeStudioApi = {
224224
isAvailable: () => true,
225+
openIgnitionProjectDirectory: async () => undefined,
225226
openStudioArtifactFile: async () => ({
226227
path: "/tmp/native-workspace.json",
227228
fileName: "native-workspace.json",
@@ -253,6 +254,73 @@ describe("Studio app shell", () => {
253254
act(() => renderer?.unmount());
254255
});
255256

257+
test("opens a local IgnitionRL project directory through the native Tauri API", async () => {
258+
let renderer: ReactTestRenderer | undefined;
259+
const nativeApi: NativeStudioApi = {
260+
isAvailable: () => true,
261+
openIgnitionProjectDirectory: async () => nativeProjectDirectory(),
262+
openStudioArtifactFile: async () => undefined,
263+
};
264+
265+
act(() => {
266+
renderer = create(React.createElement(App, {
267+
initialWorkspace: sampleWorkspace,
268+
nativeApi,
269+
}));
270+
});
271+
272+
const openButton = renderer?.root.findByProps({
273+
"aria-label": "Open native project directory",
274+
});
275+
276+
await act(async () => {
277+
await openButton?.props.onClick();
278+
});
279+
280+
const text = JSON.stringify(renderer?.toJSON());
281+
282+
expect(text).toContain("Native Project Directory");
283+
expect(text).toContain("native-run");
284+
expect(text).toContain("Target2D-v0");
285+
expect(text).toContain("final");
286+
expect(text).toContain("project.ignitionrl");
287+
288+
act(() => renderer?.unmount());
289+
});
290+
291+
test("shows native project directory validation errors", async () => {
292+
let renderer: ReactTestRenderer | undefined;
293+
const nativeApi: NativeStudioApi = {
294+
isAvailable: () => true,
295+
openIgnitionProjectDirectory: async () => {
296+
throw new Error("Selected folder is not an IgnitionRL project: missing ignitionrl.project.json.");
297+
},
298+
openStudioArtifactFile: async () => undefined,
299+
};
300+
301+
act(() => {
302+
renderer = create(React.createElement(App, {
303+
initialWorkspace: sampleWorkspace,
304+
nativeApi,
305+
}));
306+
});
307+
308+
const openButton = renderer?.root.findByProps({
309+
"aria-label": "Open native project directory",
310+
});
311+
312+
await act(async () => {
313+
await openButton?.props.onClick();
314+
});
315+
316+
const text = JSON.stringify(renderer?.toJSON());
317+
318+
expect(text).toContain("missing ignitionrl.project.json");
319+
expect(text).toContain("DroneTarget Demo");
320+
321+
act(() => renderer?.unmount());
322+
});
323+
256324
test("loads another run episode artifact and switches replay plus reward views", async () => {
257325
let renderer: ReactTestRenderer | undefined;
258326
const episodeOneView = secondEpisodeRunView();
@@ -591,6 +659,115 @@ describe("Studio app shell", () => {
591659
});
592660
});
593661

662+
function nativeProjectDirectory(): NativeIgnitionProjectDirectory {
663+
const createdAt = "2026-05-28T00:00:00.000Z";
664+
const runUpdatedAt = "2026-05-28T00:01:00.000Z";
665+
666+
return {
667+
path: "/tmp/project.ignitionrl",
668+
directoryName: "project.ignitionrl",
669+
byteLength: 2048,
670+
manifest: {
671+
schemaVersion: 1,
672+
id: "native-project",
673+
name: "Native Project Directory",
674+
createdAt,
675+
updatedAt: runUpdatedAt,
676+
environments: [{
677+
id: "Target2D-v0",
678+
packageName: "@ignitionrl/examples",
679+
exportName: "Target2D",
680+
metadata: {
681+
observationLabels: ["agent.x", "agent.y", "target.x", "target.y"],
682+
actionLabels: ["up", "down", "left", "right"],
683+
},
684+
}],
685+
},
686+
runs: [{
687+
id: "native-run",
688+
path: "runs/native-run",
689+
run: {
690+
schemaVersion: 1,
691+
id: "native-run",
692+
projectId: "native-project",
693+
envId: "Target2D-v0",
694+
algorithm: "random",
695+
status: "completed",
696+
createdAt,
697+
updatedAt: runUpdatedAt,
698+
summary: {
699+
episodes: 1,
700+
totalSteps: 1,
701+
totalReward: 1,
702+
successRate: 1,
703+
bestReward: 1,
704+
lastReward: 1,
705+
},
706+
},
707+
metrics: [{
708+
t: 0,
709+
episode: 0,
710+
values: {
711+
totalReward: 1,
712+
success: 1,
713+
},
714+
createdAt: runUpdatedAt,
715+
}],
716+
traces: [{
717+
path: "runs/native-run/traces/episode-0.json",
718+
episodeId: "episode-0",
719+
contents: {
720+
runId: "native-run",
721+
episodeId: "episode-0",
722+
envId: "Target2D-v0",
723+
seed: 7,
724+
startedAt: createdAt,
725+
steps: [{
726+
t: 0,
727+
observation: [0, 0, 1, 0],
728+
nextObservation: [1, 0, 1, 0],
729+
action: "right",
730+
encodedAction: [3],
731+
reward: 1,
732+
rewardTerms: {
733+
target_reached: 1,
734+
},
735+
done: true,
736+
reason: "target_reached",
737+
}],
738+
summary: {
739+
totalReward: 1,
740+
length: 1,
741+
success: true,
742+
terminated: true,
743+
truncated: false,
744+
reason: "target_reached",
745+
},
746+
},
747+
}],
748+
checkpoints: [{
749+
path: "runs/native-run/checkpoints/final.json",
750+
entry: {
751+
id: "final",
752+
runId: "native-run",
753+
envId: "Target2D-v0",
754+
algorithm: "random",
755+
path: "runs/native-run/checkpoints/final.json",
756+
createdAt: runUpdatedAt,
757+
},
758+
}],
759+
}],
760+
artifacts: [{
761+
kind: "episode-replay",
762+
path: "exports/runs/native-run/replays/episode-0.json",
763+
fileName: "episode-0.json",
764+
sizeBytes: 512,
765+
modifiedAt: runUpdatedAt,
766+
runId: "native-run",
767+
}],
768+
};
769+
}
770+
594771
function secondEpisodeRunView(): StudioRunView {
595772
const base = sampleWorkspace.selectedRun!;
596773
const episodeId = "drone-target-linear-policy-search-inference:episode:1";

‎apps/studio/src/App.tsx‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
StoredCheckpoint,
1717
} from "@ignitionrl/sdk";
1818
import { defaultNativeStudioApi, type NativeStudioApi } from "./native";
19+
import { studioWorkspaceFromNativeProjectDirectory } from "./native-project";
1920
import { sampleWorkspace } from "./sample-workspace";
2021
import { StudioViewportPanel } from "./StudioViewportPanel";
2122
import "./styles.css";
@@ -240,6 +241,21 @@ export function App({
240241
}
241242
}
242243

244+
async function openNativeProjectDirectory() {
245+
try {
246+
const directory = await nativeApi.openIgnitionProjectDirectory();
247+
248+
if (directory === undefined) {
249+
return;
250+
}
251+
252+
applyStudioArtifact(studioWorkspaceFromNativeProjectDirectory(directory));
253+
setLoadedSource(directory.directoryName);
254+
} catch (error) {
255+
setLoadError(error instanceof Error ? error.message : String(error));
256+
}
257+
}
258+
243259
async function loadWorkspaceFile(event: ChangeEvent<HTMLInputElement>) {
244260
const file = event.target.files?.[0];
245261

@@ -268,15 +284,26 @@ export function App({
268284
</div>
269285
<div className="topbar-actions">
270286
{isNativeRuntime ? (
271-
<button
272-
aria-label="Open native Studio JSON"
273-
className="file-command"
274-
onClick={openNativeWorkspaceFile}
275-
type="button"
276-
>
277-
<FolderOpen aria-hidden="true" size={16} />
278-
Open JSON
279-
</button>
287+
<>
288+
<button
289+
aria-label="Open native project directory"
290+
className="file-command"
291+
onClick={openNativeProjectDirectory}
292+
type="button"
293+
>
294+
<FolderOpen aria-hidden="true" size={16} />
295+
Open Project
296+
</button>
297+
<button
298+
aria-label="Open native Studio JSON"
299+
className="file-command"
300+
onClick={openNativeWorkspaceFile}
301+
type="button"
302+
>
303+
<Upload aria-hidden="true" size={16} />
304+
Open JSON
305+
</button>
306+
</>
280307
) : null}
281308
<label className="file-command">
282309
<input

0 commit comments

Comments
 (0)