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
chat-import.ts4.2 KB
// Automatic imports belong to the settings plugin, not the host. Reconcile
// ready agent/project pairs at startup and on changes, never on a timer.
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as z from "zod";
import { Host, Notify, Plugin, Settings, promise } from "divergence/effect";
import type { ViewHandle } from "divergence";
const makeChatImport = Effect.fn("ChatImport.make")(function* () {
const host = yield* Host;
const settings = yield* Settings;
const notify = yield* Notify;
const plugin = yield* Plugin;
const state = { enabled: false, running: false, imported: 0, errors: [] as string[] };
const views: ViewHandle[] = [];
const redraw = () => {
for (const view of views) view.update();
};
const attempted = new Set<string>();
let again = false;
let retry = false;
const refresh = Effect.fn("ChatImport.refresh")(function* (force = false) {
retry ||= force;
if (state.running) {
again = true;
return;
}
state.running = true;
redraw();
yield* Effect.gen(function* () {
do {
again = false;
state.enabled = (yield* settings.get("autoImportChats", z.boolean().nullable())) === true;
if (retry || !state.enabled) {
attempted.clear();
state.errors = [];
retry = false;
}
redraw();
if (!state.enabled) continue;
const [agents, workspaces] = yield* Effect.all(
[host.call("host/agents.all", {}), host.call("host/workspaces.list", {})],
{ concurrency: "unbounded" },
);
const pairs = workspaces.workspaces
.filter((w) => !w.mark)
.flatMap((workspace) =>
agents.agents
.filter((a) => a.enabled && a.status?.state === "ready" && a.capabilities?.sessionList)
.map((agent) => ({ workspace, agent, key: JSON.stringify([workspace.id, workspace.path, agent.id]) })),
);
const eligible = new Set(pairs.map((p) => p.key));
for (const key of attempted) if (!eligible.has(key)) attempted.delete(key);
for (const { workspace, agent, key } of pairs) {
// A toggle or agent/workspace change during a slow import must
// be reconciled before admitting another pair from this snapshot.
if (again || !state.enabled) break;
if (attempted.has(key)) continue;
attempted.add(key);
yield* host.call("host/chats.import", { workspaceId: workspace.id, agentId: agent.id }).pipe(
Effect.tap((result) =>
Effect.sync(() => {
state.imported += result.imported;
}),
),
Effect.catch((error) =>
Effect.gen(function* () {
const message = `Could not import ${agent.name} chats into ${workspace.name}: ${error.message}`;
state.errors.push(message);
yield* notify.error(message);
}),
),
);
redraw();
}
} while (again);
}).pipe(
Effect.catch((error) =>
Effect.gen(function* () {
state.errors = [error.message];
yield* notify.error(`Could not refresh automatic chat imports: ${error.message}`);
}),
),
Effect.ensuring(
Effect.sync(() => {
state.running = false;
redraw();
}),
),
);
});
const setEnabled = Effect.fn("ChatImport.setEnabled")(function* (enabled: boolean) {
yield* promise("settings.set", () => plugin.api.settings.set("autoImportChats", enabled)).pipe(
Effect.tap(() =>
Effect.sync(() => {
state.enabled = enabled;
redraw();
}),
),
Effect.andThen(refresh()),
Effect.catch((error) => notify.error(`Could not change automatic chat import: ${error.message}`)),
);
});
return { state, views, refresh, setEnabled, retry: () => refresh(true) };
});
export class ChatImport extends Context.Service<ChatImport, Effect.Success<ReturnType<typeof makeChatImport>>>()(
"settings/ChatImport",
) {
static readonly layer = Layer.effect(ChatImport, makeChatImport());
}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.