Skip to content

Commit 4a81b15

Browse files
authored
fix(extensions): show directory-based project plugins (anomalyco#1535)
* fix(extensions): show directory-based project plugins * fix(extensions): make discovered plugins read-only
1 parent cc2a726 commit 4a81b15

2 files changed

Lines changed: 89 additions & 27 deletions

File tree

‎apps/app/src/react-app/domains/settings/pages/plugins-view.tsx‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export type PluginsExtensionsStore = {
1515
refreshPlugins: (scope?: "project" | "global") => void | Promise<void>;
1616
pluginConfigPath: () => string | null;
1717
pluginConfig: () => { path?: string | null } | null;
18-
pluginList: () => string[];
18+
pluginList: () => Array<{
19+
name: string;
20+
source: "config" | "dir.project" | "dir.global";
21+
removable: boolean;
22+
}>;
1923
pluginInput: () => string;
2024
setPluginInput: (value: string) => void;
2125
pluginStatus: () => string | null;
@@ -247,27 +251,38 @@ export function PluginsView(props: PluginsViewProps) {
247251
</div>
248252
) : (
249253
<div className="grid gap-2">
250-
{extensions.pluginList().map((pluginName) => (
254+
{extensions.pluginList().map((plugin) => (
251255
<div
252-
key={pluginName}
256+
key={plugin.name}
253257
className="flex items-center justify-between rounded-xl border border-gray-6/60 bg-gray-1/40 px-4 py-2.5"
254258
>
255-
<div className="text-sm text-gray-12 font-mono flex items-center gap-2">
256-
<Cpu size={14} className="text-gray-10" />
257-
{pluginName}
259+
<div>
260+
<div className="text-sm text-gray-12 font-mono flex items-center gap-2">
261+
<Cpu size={14} className="text-gray-10" />
262+
{plugin.name}
263+
</div>
264+
{!plugin.removable ? (
265+
<div className="mt-1 text-xs text-gray-10">
266+
{plugin.source === "dir.global"
267+
? "Discovered from a global plugin folder."
268+
: "Discovered from the workspace plugin folder."}
269+
</div>
270+
) : null}
258271
</div>
259272
<div className="flex items-center gap-2">
260273
<div className="text-[10px] uppercase tracking-wide text-gray-10">
261-
{t("plugins.enabled")}
274+
{plugin.removable ? t("plugins.enabled") : t("settings.cap_read_only")}
262275
</div>
263-
<Button
264-
variant="ghost"
265-
className="h-7 px-2 text-[11px] text-red-11 hover:text-red-12"
266-
onClick={() => extensions.removePlugin(pluginName)}
267-
disabled={props.busy || !props.canEditPlugins}
268-
>
269-
{t("plugins.remove")}
270-
</Button>
276+
{plugin.removable ? (
277+
<Button
278+
variant="ghost"
279+
className="h-7 px-2 text-[11px] text-red-11 hover:text-red-12"
280+
onClick={() => extensions.removePlugin(plugin.name)}
281+
disabled={props.busy || !props.canEditPlugins}
282+
>
283+
{t("plugins.remove")}
284+
</Button>
285+
) : null}
271286
</div>
272287
</div>
273288
))}

‎apps/app/src/react-app/domains/settings/state/extensions-store.ts‎

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ const HUB_REPOS_STORAGE_KEY = "openwork.skills.hubRepos.v1";
7373

7474
type SetStateAction<T> = T | ((current: T) => T);
7575

76+
type PluginListEntry = {
77+
name: string;
78+
source: "config" | "dir.project" | "dir.global";
79+
removable: boolean;
80+
};
81+
7682
export type ExtensionsStoreSnapshot = {
7783
workspaceContextKey: string;
7884
skills: SkillCard[];
@@ -93,7 +99,7 @@ export type ExtensionsStoreSnapshot = {
9399
pluginScope: PluginScope;
94100
pluginConfig: OpencodeConfigFile | null;
95101
pluginConfigPath: string | null;
96-
pluginList: string[];
102+
pluginList: PluginListEntry[];
97103
pluginInput: string;
98104
pluginStatus: string | null;
99105
activePluginGuide: string | null;
@@ -128,7 +134,7 @@ type MutableState = {
128134
pluginScope: PluginScope;
129135
pluginConfig: OpencodeConfigFile | null;
130136
pluginConfigPath: string | null;
131-
pluginList: string[];
137+
pluginList: PluginListEntry[];
132138
pluginInput: string;
133139
pluginStatus: string | null;
134140
activePluginGuide: string | null;
@@ -172,6 +178,42 @@ function uniqueSkillInstallName(base: string, taken: Set<string>, stableSuffix:
172178
return `skill-${suffixSource}`.slice(0, 64);
173179
}
174180

181+
function toConfigPluginListEntries(names: string[]): PluginListEntry[] {
182+
const next: PluginListEntry[] = [];
183+
const seen = new Set<string>();
184+
for (const rawName of names) {
185+
const name = rawName.trim();
186+
if (!name || seen.has(name)) continue;
187+
seen.add(name);
188+
next.push({ name, source: "config", removable: true });
189+
}
190+
return next;
191+
}
192+
193+
function toProjectPluginListEntries(
194+
items: Array<{ spec: string; source: string }>,
195+
): PluginListEntry[] {
196+
const byName = new Map<string, PluginListEntry>();
197+
for (const item of items) {
198+
const name = item.spec.trim();
199+
if (!name) continue;
200+
const source: PluginListEntry["source"] =
201+
item.source === "dir.project" || item.source === "dir.global"
202+
? item.source
203+
: "config";
204+
const entry: PluginListEntry = {
205+
name,
206+
source,
207+
removable: source === "config",
208+
};
209+
const existing = byName.get(name);
210+
if (!existing || (entry.removable && !existing.removable)) {
211+
byName.set(name, entry);
212+
}
213+
}
214+
return [...byName.values()];
215+
}
216+
175217
export function createExtensionsStore(options: {
176218
client: () => Client | null;
177219
projectDir: () => string;
@@ -1399,23 +1441,23 @@ export function createExtensionsStore(options: {
13991441
}
14001442

14011443
const isPluginInstalledByName = (pluginName: string, aliases: string[] = []) =>
1402-
isPluginInstalled(snapshot.pluginList, pluginName, aliases);
1444+
isPluginInstalled(snapshot.pluginList.map((entry) => entry.name), pluginName, aliases);
14031445

14041446
const loadPluginsFromConfig = (config: OpencodeConfigFile | null) => {
1405-
const nextPluginList: string[] = [];
1447+
const nextPluginNames: string[] = [];
14061448
let nextPluginStatus: string | null = null;
14071449
loadPluginsFromConfigHelpers(
14081450
config,
14091451
(value) => {
1410-
nextPluginList.splice(0, nextPluginList.length, ...applyStateAction(nextPluginList, value));
1452+
nextPluginNames.splice(0, nextPluginNames.length, ...applyStateAction(nextPluginNames, value));
14111453
},
14121454
(message) => {
14131455
nextPluginStatus = message;
14141456
},
14151457
);
14161458
mutateState((current) => ({
14171459
...current,
1418-
pluginList: nextPluginList,
1460+
pluginList: toConfigPluginListEntries(nextPluginNames),
14191461
pluginStatus: nextPluginStatus,
14201462
}));
14211463
};
@@ -1622,12 +1664,12 @@ export function createExtensionsStore(options: {
16221664
if (refreshPluginsAborted) return;
16231665
const result = await openworkClient.listPlugins(openworkWorkspaceId, { includeGlobal: false });
16241666
if (refreshPluginsAborted) return;
1625-
const configItems = result.items.filter((item) => item.source === "config" && item.scope === "project");
1626-
const list = configItems.map((item) => item.spec);
1667+
const projectItems = result.items.filter((item) => item.scope === "project");
1668+
const list = toProjectPluginListEntries(projectItems);
16271669
mutateState((current) => ({
16281670
...current,
16291671
pluginList: list,
1630-
sidebarPluginList: list,
1672+
sidebarPluginList: list.map((entry) => entry.name),
16311673
pluginStatus: list.length ? null : "No plugins configured yet.",
16321674
sidebarPluginStatus: null,
16331675
pluginsContextKey: getWorkspaceContextKey(),
@@ -1710,12 +1752,12 @@ export function createExtensionsStore(options: {
17101752
nextSidebarPluginStatus = t("skills.failed_parse_opencode");
17111753
}
17121754

1713-
const nextPluginList: string[] = [];
1755+
const nextPluginNames: string[] = [];
17141756
let nextPluginStatus: string | null = null;
17151757
loadPluginsFromConfigHelpers(
17161758
config,
17171759
(value) => {
1718-
nextPluginList.splice(0, nextPluginList.length, ...applyStateAction(nextPluginList, value));
1760+
nextPluginNames.splice(0, nextPluginNames.length, ...applyStateAction(nextPluginNames, value));
17191761
},
17201762
(message) => {
17211763
nextPluginStatus = message;
@@ -1724,7 +1766,7 @@ export function createExtensionsStore(options: {
17241766

17251767
mutateState((current) => ({
17261768
...current,
1727-
pluginList: nextPluginList,
1769+
pluginList: toConfigPluginListEntries(nextPluginNames),
17281770
pluginStatus: nextPluginStatus,
17291771
sidebarPluginList: nextSidebarPluginList,
17301772
sidebarPluginStatus: nextSidebarPluginStatus,
@@ -1840,6 +1882,11 @@ export function createExtensionsStore(options: {
18401882
const name = pluginName.trim();
18411883
if (!name) return;
18421884
const triggerName = stripPluginVersion(name);
1885+
const existingPlugin = snapshot.pluginList.find((entry) => entry.name === name);
1886+
if (existingPlugin && !existingPlugin.removable) {
1887+
setStateField("pluginStatus", "Directory-discovered plugins are read-only.");
1888+
return;
1889+
}
18431890

18441891
const isLocalWorkspace = options.workspaceType() === "local";
18451892
const openworkSnapshot = getOpenworkServerSnapshot();

0 commit comments

Comments
 (0)