Skip to content

Commit 224ab4f

Browse files
committed
Project effective plugin enablement in the Plugins surface
1 parent 6bab08a commit 224ab4f

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/tui/plugin-surface.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, test } from "bun:test";
2+
3+
import type { PluginModule } from "../plugins/loader.js";
4+
import { isPluginEnabledForSurface } from "./plugin-surface.js";
5+
6+
const bundledSkills: PluginModule = {
7+
origin: "repo",
8+
manifest: {
9+
id: "corbits-skills",
10+
name: "Corbits Skills",
11+
kind: "command",
12+
defaultEnabled: true,
13+
},
14+
};
15+
16+
describe("isPluginEnabledForSurface", () => {
17+
test("projects a bundled default-on plugin as enabled without settings", () => {
18+
expect(isPluginEnabledForSurface(bundledSkills, {})).toBe(true);
19+
});
20+
21+
test("projects explicit disabled and enabled settings", () => {
22+
expect(
23+
isPluginEnabledForSurface(bundledSkills, {
24+
"corbits-skills": { enabled: false },
25+
}),
26+
).toBe(false);
27+
expect(
28+
isPluginEnabledForSurface(bundledSkills, {
29+
"corbits-skills": { enabled: true },
30+
}),
31+
).toBe(true);
32+
});
33+
});

src/tui/plugin-surface.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { PluginConfig } from "../config/settings.js";
2+
import type { PluginModule } from "../plugins/loader.js";
3+
import { isPluginModuleEnabled } from "../plugins/register.js";
4+
5+
export function isPluginEnabledForSurface(
6+
plugin: PluginModule | undefined,
7+
config: Record<string, PluginConfig | undefined>,
8+
): boolean {
9+
return plugin !== undefined && isPluginModuleEnabled(plugin, config);
10+
}

src/tui/runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import { TELEMETRY_NOTICE } from "../telemetry/index.js";
120120
import { captureSlashCommand } from "../telemetry/product-events.js";
121121
import { getTelemetry, liveTelemetry } from "../telemetry/singleton.js";
122122
import { createTelemetryToggleHandler } from "../telemetry/toggle.js";
123+
import { isPluginEnabledForSurface } from "./plugin-surface.js";
123124

124125
import { loadStartupChangelogMarkdown, stampVersionAfterStartup } from "../changelog/index.js";
125126
import { scheduleUpgradeNotice } from "../upgrade/index.js";
@@ -2470,7 +2471,7 @@ export async function runTUI(initialConfig: Config): Promise<number> {
24702471
return {
24712472
id: p.id,
24722473
name: p.name,
2473-
enabled: cfg[p.id]?.enabled === true,
2474+
enabled: isPluginEnabledForSurface(mod, cfg),
24742475
credentials: p.credentials,
24752476
credentialValues: cfg[p.id]?.credentials ?? {},
24762477
...(p.kind !== undefined ? { kind: p.kind } : {}),

0 commit comments

Comments
 (0)