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 convergence/files@0.2.3
Permissions in 0.2.3
Files
panel.ts2.6 KB
// File panel state, filtering and folder-first tree construction.
// Paths and selection remain workspace-relative, matching the kernel tree ids.
import * as z from "zod";
import type { EffectClient } from "convergence/effect";
import type * as Fiber from "effect/Fiber";
import type { AppState } from "convergence";
import type { Tabs } from "../tabs/contract.ts";
// One open folder's names, keyed by its tree id: "" for the top, else its
// path with a trailing "/".
export interface Listing {
files: readonly string[];
folders: readonly string[];
}
export interface FilesState {
workspaceId: string | null;
// The folders listed so far. Only these are in the tree; the others show a
// "Loading…" row until they are opened and listed.
listing: Record<string, Listing>;
// Every path, from a host before per-folder listing; null otherwise.
all: readonly string[] | null;
query: string;
// The host's matches for `query`; the last ones stay until new ones come.
results: readonly string[];
// The convergence/tabs client while its provider runs, the open file it
// last announced, and the fiber following it; selection stays empty
// without it.
tabs: EffectClient<typeof Tabs> | undefined;
activePath: string | null;
follow: Fiber.Fiber<void> | undefined;
}
export const initialState = (): FilesState => ({
workspaceId: null,
listing: {},
all: null,
query: "",
results: [],
tabs: undefined,
activePath: null,
follow: undefined,
});
// The row a folder holds until it is listed: a tree row is a folder only
// when it has children.
export const isPending = (id: string): boolean => id.endsWith("…");
export interface TreeItem {
id: string;
label: string;
children?: TreeItem[];
}
// The listed folders as tree items, with the ids `files` nesting gives them.
export function treeItems(listing: Record<string, Listing>, prefix = ""): TreeItem[] {
const here = listing[prefix];
if (!here) return prefix ? [{ id: `${prefix}…`, label: "Loading…" }] : [];
return [
...here.folders.map((name) => ({
id: `${prefix}${name}/`,
label: name,
children: treeItems(listing, `${prefix}${name}/`),
})),
...here.files.map((name) => ({ id: `${prefix}${name}`, label: name })),
];
}
export function isOpen(app: AppState): boolean {
return app.shared?.rightPanel === "files" || app.shared?.rightPanelPreview === "files";
}
export function selectedPath(activePath: string | null): string | null {
return typeof activePath === "string" ? activePath : null;
}
const finished = z.object({ event: z.literal("run_finished") });
export const runFinished = (kind: unknown): boolean => finished.safeParse(kind).success;
No comments yet.