Official
settings
Built-in settings 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/settings@0.2.5
Permissions in 0.2.5
Files
main.ts5.9 KB
// Register the settings page, then the divergence/settings service, then
// the host events that change what the page shows. The page loads at
// activation, so Settings opens on its section at once.
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";
import { App, Commands, Events, Services, Settings, Views, runPlugin } from "divergence/effect";
import type { HostEvents } from "divergence";
import { SettingsPage } from "./controller.ts";
import { APP_SECTIONS } from "./model.ts";
import { Settings as SettingsService } from "./contract.ts";
import { renderSettings, renderSettingsSidebar } from "./views/page.tsx";
import { Onboarding } from "./onboarding.ts";
import { renderOnboarding } from "./views/onboarding.tsx";
import { ChatImport } from "./chat-import.ts";
import { Upkeep } from "./upkeep.ts";
import { ArchivedChats } from "./archived.ts";
import { renderUpdatesRow } from "./views/upkeep.tsx";
// The sidebar draws, above Settings, every view a plugin publishes under a
// key starting with `sidebarItem.`.
const SIDEBAR_ITEM = "sidebarItem.updates";
const program = Effect.gen(function* () {
const page = yield* SettingsPage;
const onboarding = yield* Onboarding;
const imports = yield* ChatImport;
const views = yield* Views;
page.views.push(
yield* views.add("center", { slot: "center", render: (ctx) => renderSettings(ctx, page), on: [
"app_state",
"agents_changed",
"plugins_changed",
"updates_changed",
"keybindings_changed",
"plugin_settings_changed",
] }),
);
// Its list of sections, in the sidebar's place while Settings is open.
page.views.push(
yield* views.add("left", { slot: "left", render: (ctx) => renderSettingsSidebar(ctx, page), on: ["app_state", "plugins_changed", "updates_changed"] }),
);
onboarding.views.push(yield* views.add("center-2", { slot: "center", render: (ctx) => renderOnboarding(ctx, onboarding), on: ["app_state"] }));
imports.views.push(...page.views, ...onboarding.views);
const archived = yield* ArchivedChats;
archived.views.push(...page.views);
const commands = yield* Commands;
yield* commands.register("settings.onboarding", onboarding.restart());
for (const section of APP_SECTIONS) yield* commands.register(`settings.${section.id}`, page.showSection(section.id));
const services = yield* Services;
yield* services.provide(SettingsService, {
showShortcuts: ({ query }) => page.showShortcuts(query),
});
const events = yield* Events;
// Every listener fires its effect as its own fork, as the original's
// async listeners did; a failure is logged with its cause, not
// propagated (a bare `Effect.ignore` would drop it without a word).
const follow = <E extends keyof HostEvents, R>(
name: E,
run: (event: HostEvents[E]) => Effect.Effect<void, unknown, R>,
) =>
events.stream(name).pipe(
Stream.runForEach((event) =>
Effect.forkScoped(run(event).pipe(Effect.ignore({ log: "Error", message: `settings: handling ${name} failed` })), {
startImmediately: true,
}),
),
Effect.ignore({ log: "Error", message: `settings: the ${name} events stopped` }),
Effect.forkScoped({ startImmediately: true }),
);
// The update row in the sidebar's footer.
const upkeep = yield* Upkeep;
const row = yield* views.add("sidebar-item", { slot: "sidebar-item", render: (ctx) => renderUpdatesRow(ctx, upkeep), on: ["app_state"] });
// Settings > Updates draws the same jobs.
upkeep.views.push(row, ...page.views);
const app = yield* App;
yield* Effect.acquireRelease(app.update({ shared: { [SIDEBAR_ITEM]: row.id } }), () =>
app.update({ shared: { [SIDEBAR_ITEM]: null } }),
);
yield* follow("agents_changed", () => upkeep.agentsChanged());
yield* follow("updates_changed", () => upkeep.loadUpdates());
yield* follow("chat_changed", (event) => upkeep.chatChanged(event.chat));
yield* follow("chat_removed", (event) => upkeep.chatRemoved(event.chatId));
yield* follow("chat_changed", (event) => archived.chatChanged(event.chat));
yield* follow("chat_removed", (event) => archived.chatRemoved(event.chatId));
yield* upkeep.load().pipe(Effect.forkScoped({ startImmediately: true }));
yield* follow("keybindings_changed", () => page.loadKeys());
yield* follow("plugin_settings_changed", (event) =>
page.state.sections[event.plugin] ? page.loadSection(event.plugin) : Effect.void,
);
yield* follow("agents_changed", () => page.load());
yield* follow("plugins_changed", () => page.load());
// A plugin enabled or turned off, or a grant given or taken back.
yield* follow("access_changed", () => page.load());
yield* follow("workspaces_changed", () => page.load());
yield* follow("updates_changed", () => page.refreshUpdates());
yield* page.load().pipe(
Effect.ignore({ log: "Error", message: "settings: loading the page failed" }),
Effect.forkScoped({ startImmediately: true }),
);
yield* follow("agents_changed", () => onboarding.refresh());
yield* follow("workspaces_changed", () => onboarding.refresh());
yield* follow("plugins_changed", () => onboarding.refresh());
yield* follow("access_changed", () => onboarding.refresh());
yield* follow("agents_changed", () => imports.refresh());
yield* follow("workspaces_changed", () => imports.refresh());
const settings = yield* Settings;
yield* settings.changes.pipe(
Stream.runForEach(() => imports.refresh()),
Effect.forkScoped({ startImmediately: true }),
);
yield* imports.refresh().pipe(Effect.forkScoped({ startImmediately: true }));
yield* onboarding.initialize().pipe(Effect.forkScoped({ startImmediately: true }));
});
export default runPlugin(
Layer.mergeAll(SettingsPage.layer, Onboarding.layer).pipe(
Layer.provideMerge(ChatImport.layer),
Layer.provideMerge(Upkeep.layer),
Layer.provideMerge(ArchivedChats.layer),
),
program,
);Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.8latest | Nov 21, 2026 | >=5 <6 | 68.5 KB | 7 permissions | Listed |
| 0.2.7 | Nov 18, 2026 | >=5 <6 | 68 KB | 7 permissions | Listed |
| 0.2.6 | Nov 16, 2026 | >=5 <6 | 66.3 KB | 7 permissions | Listed |
| 0.2.5 | Nov 11, 2026 | >=5 <6 | 63.6 KB | 7 permissions | Listed |
| 0.2.4 | Nov 9, 2026 | >=5 <6 | 61.6 KB | 7 permissions | Listed |
| 0.2.3 | Oct 27, 2026 | >=2 <4 | 46.8 KB | 7 permissions | Listed |
No comments yet.