Official
files
Built-in files UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/files@0.2.4
Permissions in 0.2.4
Files
main.ts2 KB
// Register file views before starting app and agent subscriptions.
// Background reads start from app changes, never from rendering.
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { App, Commands, Events, Views, runPlugin } from "divergence/effect";
import { Files } from "./controller.ts";
import { runFinished } from "./panel.ts";
import { renderRail, renderPanel } from "./views.tsx";
const program = Effect.gen(function* () {
const files = yield* Files;
const app = yield* App;
const commands = yield* Commands;
const views = yield* Views;
// Opened by its key, the panel's tree takes the keyboard (the rail's
// button only shows it).
yield* commands.register(
"files.toggle",
Effect.gen(function* () {
const state = yield* app.state;
yield* files.toggle(state);
if (state.shared?.rightPanel !== "files" && state.workspaceId) yield* views.focus(`files-${state.workspaceId}`);
}),
);
yield* commands.register("files.collapseAll", files.collapseAll());
files.views.push(yield* views.add("rail", { slot: "rail", render: (ctx) => renderRail(ctx, files), on: ["app_state"], order: 10 }));
files.views.push(
yield* views.add("right", { slot: "right", render: (ctx) => renderPanel(ctx, files), on: ["app_state"], order: 10, title: "Files" }),
);
const events = yield* Events;
yield* app.changes.pipe(
Stream.runForEach((next) => Effect.forkScoped(files.followApp(next), { startImmediately: true })),
Effect.forkScoped({ startImmediately: true }),
);
// Only finished runs are asked for; an older runtime sends every agent event.
yield* events.stream("agent", { kinds: ["run_finished"] }).pipe(
Stream.runForEach((event) =>
Effect.forkScoped(
runFinished(event.kind) && files.state.workspaceId ? files.refresh(files.state.workspaceId) : Effect.void,
{ startImmediately: true },
),
),
Effect.forkScoped({ startImmediately: true }),
);
yield* files.followApp(yield* app.state);
});
export default runPlugin(Files.layer, program);
No comments yet.