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.6
Permissions in 0.2.6
Files
main.ts6.1 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, 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 { Upkeep } from "./upkeep.ts";
import { ArchivedChats } from "./archived.ts";
import { renderUpdatesButton } from "./views/upkeep.tsx";
// The sidebar draws, left of Options, every view a plugin publishes under a
// key starting with `sidebarButton.`.
const SIDEBAR_BUTTON = "sidebarButton.updates";
const program = Effect.gen(function* () {
const page = yield* SettingsPage;
const onboarding = yield* Onboarding;
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"] }));
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 button in the sidebar's footer.
const upkeep = yield* Upkeep;
const button = yield* views.add("sidebar-item", { slot: "sidebar-item", render: (ctx) => renderUpdatesButton(ctx, upkeep), on: ["app_state"] });
// Settings > Updates draws the same jobs.
upkeep.views.push(button, ...page.views);
// The sidebar keeps the button's room while the key holds the view, so it
// holds it only while something is behind.
const app = yield* App;
let published: number | null = null;
const publish = (any: boolean) => {
const next = any ? button.id : null;
if (next === published) return;
published = next;
Effect.runFork(app.update({ shared: { [SIDEBAR_BUTTON]: next } }));
};
yield* Effect.acquireRelease(Effect.sync(() => upkeep.watchers.push(publish)), () =>
Effect.suspend(() => {
upkeep.watchers.splice(upkeep.watchers.indexOf(publish), 1);
return published === null ? Effect.void : app.update({ shared: { [SIDEBAR_BUTTON]: 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("inputs_changed", (event) => upkeep.inputsChanged(event.snapshot));
yield* upkeep.followServices().pipe(
Effect.ignore({ log: "Error", message: "settings: following the market and chat plugins stopped" }),
Effect.forkScoped({ startImmediately: true }),
);
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* onboarding.initialize().pipe(Effect.forkScoped({ startImmediately: true }));
});
export default runPlugin(
Layer.mergeAll(SettingsPage.layer, Onboarding.layer).pipe(
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.