diff --git a/src/tui/plugin-surface.test.ts b/src/tui/plugin-surface.test.ts new file mode 100644 index 00000000..c818f56b --- /dev/null +++ b/src/tui/plugin-surface.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, test } from "bun:test"; + +import type { PluginModule } from "../plugins/loader.js"; +import { isPluginEnabledForSurface } from "./plugin-surface.js"; + +const bundledSkills: PluginModule = { + origin: "repo", + manifest: { + id: "corbits-skills", + name: "Corbits Skills", + kind: "command", + defaultEnabled: true, + }, +}; + +describe("isPluginEnabledForSurface", () => { + test("projects an unknown plugin as disabled", () => { + expect(isPluginEnabledForSurface(undefined, {})).toBe(false); + }); + + test("projects a bundled default-on plugin as enabled without settings", () => { + expect(isPluginEnabledForSurface(bundledSkills, {})).toBe(true); + }); + + test("projects explicit disabled and enabled settings", () => { + expect( + isPluginEnabledForSurface(bundledSkills, { + "corbits-skills": { enabled: false }, + }), + ).toBe(false); + expect( + isPluginEnabledForSurface(bundledSkills, { + "corbits-skills": { enabled: true }, + }), + ).toBe(true); + }); +}); diff --git a/src/tui/plugin-surface.ts b/src/tui/plugin-surface.ts new file mode 100644 index 00000000..9d5c82a9 --- /dev/null +++ b/src/tui/plugin-surface.ts @@ -0,0 +1,10 @@ +import type { PluginConfig } from "../config/settings.js"; +import type { PluginModule } from "../plugins/loader.js"; +import { isPluginModuleEnabled } from "../plugins/register.js"; + +export function isPluginEnabledForSurface( + plugin: PluginModule | undefined, + config: Record, +): boolean { + return plugin !== undefined && isPluginModuleEnabled(plugin, config); +} diff --git a/src/tui/runner.ts b/src/tui/runner.ts index 82ac5ae5..409b32b7 100644 --- a/src/tui/runner.ts +++ b/src/tui/runner.ts @@ -120,6 +120,7 @@ import { TELEMETRY_NOTICE } from "../telemetry/index.js"; import { captureSlashCommand } from "../telemetry/product-events.js"; import { getTelemetry, liveTelemetry } from "../telemetry/singleton.js"; import { createTelemetryToggleHandler } from "../telemetry/toggle.js"; +import { isPluginEnabledForSurface } from "./plugin-surface.js"; import { loadStartupChangelogMarkdown, stampVersionAfterStartup } from "../changelog/index.js"; import { scheduleUpgradeNotice } from "../upgrade/index.js"; @@ -2511,7 +2512,7 @@ export async function runTUI(initialConfig: Config): Promise { return { id: p.id, name: p.name, - enabled: cfg[p.id]?.enabled === true, + enabled: isPluginEnabledForSurface(mod, cfg), credentials: p.credentials, credentialValues: cfg[p.id]?.credentials ?? {}, ...(p.kind !== undefined ? { kind: p.kind } : {}),