playcanvas-agent-bridge-cli 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,567 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { existsSync } from "node:fs";
4
+ import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
5
+ import { dirname, isAbsolute, join, resolve, sep } from "node:path";
6
+ import { x as extractTar } from "tar";
7
+ import { compareSemver, copyDir, DEFAULT_PCBRIDGE_REF, DEFAULT_PCBRIDGE_REPOSITORY, findPackageRoot, UPDATE_STATE_FILE, VERSION, } from "../config.js";
8
+ export const PLUGIN_MANIFEST = "pcbridge-plugin.json";
9
+ export const PLUGIN_CATALOG_FILE = "index.json";
10
+ export const PLUGIN_API_VERSION = 1;
11
+ export const PLUGIN_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,48}$/;
12
+ export class PluginError extends Error {
13
+ code;
14
+ constructor(code, message) {
15
+ super(message);
16
+ this.name = "PluginError";
17
+ this.code = code;
18
+ }
19
+ }
20
+ function invalid(message) {
21
+ return new PluginError("PLUGIN_MANIFEST_INVALID", message);
22
+ }
23
+ function requireEntry(directory, value, label) {
24
+ if (typeof value !== "string" || !value)
25
+ throw invalid(`${label} must be a relative file path.`);
26
+ const file = resolve(directory, value);
27
+ if (!file.startsWith(`${resolve(directory)}${sep}`)) {
28
+ throw invalid(`${label} must stay inside the plugin directory.`);
29
+ }
30
+ if (!existsSync(file))
31
+ throw invalid(`${label} file does not exist: ${value}`);
32
+ }
33
+ export async function readPluginManifest(directory) {
34
+ let manifest;
35
+ try {
36
+ manifest = JSON.parse(await readFile(join(directory, PLUGIN_MANIFEST), "utf8"));
37
+ }
38
+ catch (error) {
39
+ throw invalid(`Cannot read ${PLUGIN_MANIFEST} in ${directory}: ${String(error)}`);
40
+ }
41
+ if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) {
42
+ throw invalid(`${PLUGIN_MANIFEST} must be a JSON object.`);
43
+ }
44
+ if (typeof manifest.id !== "string" || !PLUGIN_ID_PATTERN.test(manifest.id)) {
45
+ throw invalid("id must be 2-49 characters of lowercase letters, digits, and hyphens.");
46
+ }
47
+ if (typeof manifest.name !== "string" || !manifest.name.trim())
48
+ throw invalid("name is required.");
49
+ if (typeof manifest.version !== "string" || !/^\d+\.\d+\.\d+/.test(manifest.version)) {
50
+ throw invalid("version must be a semantic version such as 1.0.0.");
51
+ }
52
+ if (manifest.apiVersion !== PLUGIN_API_VERSION) {
53
+ throw invalid(`apiVersion ${String(manifest.apiVersion)} is not supported; this pcbridge supports ${PLUGIN_API_VERSION}.`);
54
+ }
55
+ if (manifest.minPcbridgeVersion !== undefined &&
56
+ (typeof manifest.minPcbridgeVersion !== "string" || !/^\d+\.\d+\.\d+/.test(manifest.minPcbridgeVersion))) {
57
+ throw invalid("minPcbridgeVersion must be a semantic version such as 0.7.0.");
58
+ }
59
+ const page = manifest.page;
60
+ if (page !== undefined && (!page || typeof page !== "object" || Array.isArray(page))) {
61
+ throw invalid("page must be an object with editor and/or launch entries.");
62
+ }
63
+ if (manifest.node === undefined && page?.editor === undefined && page?.launch === undefined) {
64
+ throw invalid("At least one of node, page.editor, or page.launch is required.");
65
+ }
66
+ if (manifest.node !== undefined)
67
+ requireEntry(directory, manifest.node, "node");
68
+ if (page?.editor !== undefined)
69
+ requireEntry(directory, page.editor, "page.editor");
70
+ if (page?.launch !== undefined)
71
+ requireEntry(directory, page.launch, "page.launch");
72
+ const actions = manifest.actions;
73
+ if (actions !== undefined && (!actions || typeof actions !== "object" || Array.isArray(actions))) {
74
+ throw invalid("actions must be an object keyed by action name.");
75
+ }
76
+ return manifest;
77
+ }
78
+ export function isPluginCompatible(item, hostVersion = VERSION) {
79
+ if (item.apiVersion !== undefined && item.apiVersion !== PLUGIN_API_VERSION) {
80
+ return false;
81
+ }
82
+ if (item.minPcbridgeVersion && compareSemver(hostVersion, item.minPcbridgeVersion) < 0) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ function assertPluginCompatible(item, hostVersion = VERSION) {
88
+ if (item.apiVersion !== undefined && item.apiVersion !== PLUGIN_API_VERSION) {
89
+ throw new PluginError("PLUGIN_MANIFEST_INVALID", `apiVersion ${String(item.apiVersion)} is not supported; this pcbridge supports ${PLUGIN_API_VERSION}.`);
90
+ }
91
+ if (item.minPcbridgeVersion && compareSemver(hostVersion, item.minPcbridgeVersion) < 0) {
92
+ throw new PluginError("PLUGIN_REQUIRES_NEWER_PCBRIDGE", `Plugin ${item.id} v${item.version} requires pcbridge v${item.minPcbridgeVersion} or newer (current v${hostVersion}). Run pcbridge update first.`);
93
+ }
94
+ }
95
+ export function parsePluginSource(value, link = false) {
96
+ const github = value.match(/^github:([\w.-]+\/[\w.-]+)((?:\/[^#]+)?)(?:#([\w./-]+))?$/);
97
+ let source;
98
+ if (github) {
99
+ source = {
100
+ type: "github",
101
+ repo: github[1],
102
+ subdir: github[2].split("/").filter(Boolean).join("/"),
103
+ ref: github[3] || "HEAD",
104
+ };
105
+ }
106
+ else if (PLUGIN_ID_PATTERN.test(value)) {
107
+ source = { type: "official", name: value };
108
+ }
109
+ else if (isAbsolute(value)) {
110
+ source = { type: link ? "link" : "directory", path: resolve(value) };
111
+ }
112
+ else {
113
+ throw new PluginError("PLUGIN_SOURCE_INVALID", "Plugin source must be an official plugin name, github:owner/repo[/subdir][#ref], or an absolute directory path.");
114
+ }
115
+ if (link && source.type !== "link") {
116
+ throw new PluginError("PLUGIN_SOURCE_INVALID", "--link requires a local plugin directory.");
117
+ }
118
+ return source;
119
+ }
120
+ export function summarizePlugin(plugin, catalog) {
121
+ const manifest = plugin.manifest;
122
+ const currentVersion = manifest?.version || null;
123
+ const officialEntry = plugin.source.type === "official"
124
+ ? catalog?.get(plugin.source.name) || catalog?.get(plugin.id)
125
+ : undefined;
126
+ const latestVersion = officialEntry?.version || currentVersion;
127
+ const minPcbridgeVersion = officialEntry?.minPcbridgeVersion || manifest?.minPcbridgeVersion || null;
128
+ const compatible = isPluginCompatible({
129
+ apiVersion: officialEntry?.apiVersion ?? manifest?.apiVersion,
130
+ minPcbridgeVersion,
131
+ });
132
+ const updateAvailable = Boolean(currentVersion &&
133
+ latestVersion &&
134
+ compareSemver(latestVersion, currentVersion) > 0);
135
+ return {
136
+ id: plugin.id,
137
+ name: manifest?.name || plugin.id,
138
+ version: currentVersion,
139
+ latestVersion,
140
+ updateAvailable,
141
+ compatible,
142
+ minPcbridgeVersion,
143
+ description: manifest?.description || "",
144
+ enabled: plugin.enabled,
145
+ state: plugin.error ? "error" : plugin.enabled ? "stopped" : "disabled",
146
+ error: plugin.error,
147
+ source: plugin.source,
148
+ path: plugin.path,
149
+ runtimes: {
150
+ node: Boolean(manifest?.node),
151
+ editor: Boolean(manifest?.page?.editor),
152
+ launch: Boolean(manifest?.page?.launch),
153
+ },
154
+ actions: manifest?.actions || {},
155
+ };
156
+ }
157
+ function runBunInstall(directory) {
158
+ return new Promise((resolveInstall, reject) => {
159
+ const child = spawn(process.execPath, ["install", "--production"], {
160
+ cwd: directory,
161
+ stdio: ["ignore", "ignore", "pipe"],
162
+ });
163
+ let stderr = "";
164
+ child.stderr.on("data", (chunk) => { stderr = `${stderr}${chunk}`.slice(-2000); });
165
+ child.on("error", reject);
166
+ child.on("close", (code) => {
167
+ if (code === 0)
168
+ resolveInstall();
169
+ else
170
+ reject(new PluginError("PLUGIN_INSTALL_FAILED", `bun install failed (exit ${code}): ${stderr.trim()}`));
171
+ });
172
+ });
173
+ }
174
+ async function installDependencies(directory) {
175
+ const packagePath = join(directory, "package.json");
176
+ if (!existsSync(packagePath))
177
+ return;
178
+ const dependencies = JSON.parse(await readFile(packagePath, "utf8")).dependencies;
179
+ if (dependencies && Object.keys(dependencies).length > 0)
180
+ await runBunInstall(directory);
181
+ }
182
+ export class PluginStore {
183
+ rootDir;
184
+ #fetch;
185
+ #officialDir;
186
+ #hasCustomOfficialDir;
187
+ #remoteCatalogUrl;
188
+ #repo;
189
+ #ref;
190
+ #catalogCache = null;
191
+ constructor(rootDir, options = {}) {
192
+ this.rootDir = rootDir;
193
+ this.#fetch = options.fetch || fetch;
194
+ this.#officialDir = options.officialDir;
195
+ this.#hasCustomOfficialDir = Boolean(options.officialDir);
196
+ this.#remoteCatalogUrl = options.remoteCatalogUrl;
197
+ this.#repo = options.repo || DEFAULT_PCBRIDGE_REPOSITORY;
198
+ this.#ref = options.ref || DEFAULT_PCBRIDGE_REF;
199
+ }
200
+ get #registryPath() {
201
+ return join(this.rootDir, "plugins.json");
202
+ }
203
+ get #installedDir() {
204
+ return join(this.rootDir, "installed");
205
+ }
206
+ async #records() {
207
+ if (!existsSync(this.#registryPath))
208
+ return {};
209
+ return JSON.parse(await readFile(this.#registryPath, "utf8")).plugins;
210
+ }
211
+ async #save(plugins) {
212
+ await mkdir(this.rootDir, { recursive: true });
213
+ await writeFile(this.#registryPath, `${JSON.stringify({ version: 1, plugins }, null, 2)}\n`);
214
+ }
215
+ async #official() {
216
+ this.#officialDir ||= join(await findPackageRoot(), "plugins");
217
+ return this.#officialDir;
218
+ }
219
+ #resolvedRemoteCatalogUrl() {
220
+ if (this.#remoteCatalogUrl !== undefined)
221
+ return this.#remoteCatalogUrl;
222
+ if (process.env.PCBRIDGE_PLUGINS_INDEX_URL !== undefined) {
223
+ return process.env.PCBRIDGE_PLUGINS_INDEX_URL || null;
224
+ }
225
+ if (this.#hasCustomOfficialDir)
226
+ return null;
227
+ return `https://raw.githubusercontent.com/${this.#repo}/${this.#ref}/plugins/index.json`;
228
+ }
229
+ async #localCatalog() {
230
+ const official = await this.#official();
231
+ const entries = new Map();
232
+ if (!existsSync(official))
233
+ return entries;
234
+ const indexPath = join(official, PLUGIN_CATALOG_FILE);
235
+ if (existsSync(indexPath)) {
236
+ try {
237
+ const parsed = JSON.parse(await readFile(indexPath, "utf8"));
238
+ if (Array.isArray(parsed.plugins)) {
239
+ for (const item of parsed.plugins) {
240
+ if (item && typeof item.id === "string" && typeof item.version === "string") {
241
+ entries.set(item.id, {
242
+ id: item.id,
243
+ name: item.name || item.id,
244
+ version: item.version,
245
+ apiVersion: item.apiVersion ?? PLUGIN_API_VERSION,
246
+ ...(item.minPcbridgeVersion ? { minPcbridgeVersion: item.minPcbridgeVersion } : {}),
247
+ description: item.description || "",
248
+ subdir: item.subdir || `plugins/${item.id}`,
249
+ ...(item.repo ? { repo: item.repo } : {}),
250
+ ...(item.ref ? { ref: item.ref } : {}),
251
+ });
252
+ }
253
+ }
254
+ }
255
+ }
256
+ catch {
257
+ // Fall back to scanning directories below.
258
+ }
259
+ }
260
+ for (const entry of await readdir(official, { withFileTypes: true })) {
261
+ if (!entry.isDirectory() || entry.name.startsWith("."))
262
+ continue;
263
+ try {
264
+ const manifest = await readPluginManifest(join(official, entry.name));
265
+ const existing = entries.get(manifest.id);
266
+ if (!existing || compareSemver(manifest.version, existing.version) >= 0) {
267
+ entries.set(manifest.id, {
268
+ id: manifest.id,
269
+ name: manifest.name,
270
+ version: manifest.version,
271
+ apiVersion: manifest.apiVersion,
272
+ ...(manifest.minPcbridgeVersion ? { minPcbridgeVersion: manifest.minPcbridgeVersion } : {}),
273
+ description: manifest.description || "",
274
+ subdir: `plugins/${entry.name}`,
275
+ });
276
+ }
277
+ }
278
+ catch {
279
+ // Ignore non-plugin folders.
280
+ }
281
+ }
282
+ return entries;
283
+ }
284
+ async #cachedRemoteCatalogFromState() {
285
+ const stateFile = join(dirname(this.rootDir), "update-state.json");
286
+ const candidates = [stateFile, UPDATE_STATE_FILE];
287
+ for (const candidate of candidates) {
288
+ if (!existsSync(candidate))
289
+ continue;
290
+ try {
291
+ const parsed = JSON.parse(await readFile(candidate, "utf8"));
292
+ if (Array.isArray(parsed.officialCatalog))
293
+ return parsed.officialCatalog;
294
+ }
295
+ catch {
296
+ // Ignore unreadable state cache.
297
+ }
298
+ }
299
+ return [];
300
+ }
301
+ async #fetchRemoteCatalog() {
302
+ const url = this.#resolvedRemoteCatalogUrl();
303
+ if (!url)
304
+ return null;
305
+ try {
306
+ const response = await this.#fetch(url, {
307
+ headers: { Accept: "application/json" },
308
+ signal: AbortSignal.timeout(5000),
309
+ });
310
+ if (!response.ok)
311
+ return null;
312
+ const parsed = (await response.json());
313
+ if (!parsed || !Array.isArray(parsed.plugins))
314
+ return null;
315
+ return parsed.plugins.filter((item) => Boolean(item &&
316
+ typeof item.id === "string" &&
317
+ PLUGIN_ID_PATTERN.test(item.id) &&
318
+ typeof item.name === "string" &&
319
+ typeof item.version === "string" &&
320
+ /^\d+\.\d+\.\d+/.test(item.version)));
321
+ }
322
+ catch {
323
+ return null;
324
+ }
325
+ }
326
+ async catalog(options = {}) {
327
+ const now = Date.now();
328
+ if (!options.refresh && this.#catalogCache && now - this.#catalogCache.at < 60_000) {
329
+ return new Map(this.#catalogCache.entries);
330
+ }
331
+ const merged = await this.#localCatalog();
332
+ const mergeEntries = (items) => {
333
+ for (const item of items) {
334
+ const current = merged.get(item.id);
335
+ if (!current || compareSemver(item.version, current.version) >= 0) {
336
+ merged.set(item.id, {
337
+ id: item.id,
338
+ name: item.name,
339
+ version: item.version,
340
+ apiVersion: item.apiVersion ?? PLUGIN_API_VERSION,
341
+ ...(item.minPcbridgeVersion ? { minPcbridgeVersion: item.minPcbridgeVersion } : {}),
342
+ description: item.description || "",
343
+ subdir: item.subdir || `plugins/${item.id}`,
344
+ ...(item.repo ? { repo: item.repo } : {}),
345
+ ...(item.ref ? { ref: item.ref } : {}),
346
+ });
347
+ }
348
+ }
349
+ };
350
+ const cachedStateEntries = await this.#cachedRemoteCatalogFromState();
351
+ if (cachedStateEntries.length > 0) {
352
+ mergeEntries(cachedStateEntries);
353
+ }
354
+ if (options.refresh || this.#remoteCatalogUrl !== undefined || process.env.PCBRIDGE_PLUGINS_INDEX_URL) {
355
+ const remote = await this.#fetchRemoteCatalog();
356
+ if (remote)
357
+ mergeEntries(remote);
358
+ }
359
+ this.#catalogCache = { at: now, entries: new Map(merged) };
360
+ return merged;
361
+ }
362
+ #directory(id, source) {
363
+ return source.type === "link" ? source.path : join(this.#installedDir, id);
364
+ }
365
+ async #describe(id, record) {
366
+ const path = this.#directory(id, record.source);
367
+ try {
368
+ return { id, ...record, path, manifest: await readPluginManifest(path), error: null };
369
+ }
370
+ catch (error) {
371
+ return { id, ...record, path, manifest: null, error: error.message };
372
+ }
373
+ }
374
+ async list() {
375
+ const records = await this.#records();
376
+ return Promise.all(Object.entries(records).map(([id, record]) => this.#describe(id, record)));
377
+ }
378
+ async summaries(options = {}) {
379
+ const [installed, catalog] = await Promise.all([
380
+ this.list(),
381
+ this.catalog(options),
382
+ ]);
383
+ return installed.map((plugin) => summarizePlugin(plugin, catalog));
384
+ }
385
+ async get(id) {
386
+ const record = (await this.#records())[id];
387
+ if (!record)
388
+ throw new PluginError("PLUGIN_NOT_FOUND", `Plugin ${id} is not installed.`);
389
+ return this.#describe(id, record);
390
+ }
391
+ async available(options = {}) {
392
+ const [records, catalog] = await Promise.all([
393
+ this.#records(),
394
+ this.catalog(options),
395
+ ]);
396
+ const result = [];
397
+ for (const [id, entry] of catalog.entries()) {
398
+ if (records[id])
399
+ continue;
400
+ const minPcbridgeVersion = entry.minPcbridgeVersion || null;
401
+ result.push({
402
+ id: entry.id,
403
+ name: entry.name,
404
+ version: entry.version,
405
+ minPcbridgeVersion,
406
+ compatible: isPluginCompatible(entry),
407
+ description: entry.description || "",
408
+ source: entry.id,
409
+ });
410
+ }
411
+ return result;
412
+ }
413
+ async #download(source, staging) {
414
+ const url = `https://codeload.github.com/${source.repo}/tar.gz/${source.ref}`;
415
+ const response = await this.#fetch(url);
416
+ if (!response.ok) {
417
+ throw new PluginError("PLUGIN_DOWNLOAD_FAILED", `GitHub returned HTTP ${response.status} for ${url}.`);
418
+ }
419
+ const archive = `${staging}.tar.gz`;
420
+ await writeFile(archive, Buffer.from(await response.arrayBuffer()));
421
+ const segments = source.subdir ? source.subdir.split("/") : [];
422
+ try {
423
+ await extractTar({
424
+ file: archive,
425
+ cwd: staging,
426
+ strip: 1 + segments.length,
427
+ filter: (path) => segments.every((segment, index) => path.split("/")[index + 1] === segment),
428
+ });
429
+ }
430
+ finally {
431
+ await rm(archive, { force: true });
432
+ }
433
+ }
434
+ async #stage(source, staging) {
435
+ await mkdir(staging, { recursive: true });
436
+ if (source.type === "github") {
437
+ await this.#download(source, staging);
438
+ if (!existsSync(join(staging, PLUGIN_MANIFEST))) {
439
+ const location = `github:${source.repo}${source.subdir ? `/${source.subdir}` : ""}#${source.ref}`;
440
+ throw new PluginError("PLUGIN_SOURCE_NOT_FOUND", `${location} does not contain ${PLUGIN_MANIFEST}.`);
441
+ }
442
+ return;
443
+ }
444
+ if (source.type === "official") {
445
+ const localDir = join(await this.#official(), source.name);
446
+ const hasLocal = existsSync(join(localDir, PLUGIN_MANIFEST));
447
+ const localManifest = hasLocal ? await readPluginManifest(localDir) : null;
448
+ const catalog = await this.catalog({ refresh: true });
449
+ const remoteEntry = catalog.get(source.name);
450
+ if (remoteEntry) {
451
+ assertPluginCompatible(remoteEntry);
452
+ }
453
+ const needsRemoteDownload = Boolean(remoteEntry &&
454
+ (!localManifest || compareSemver(remoteEntry.version, localManifest.version) > 0));
455
+ if (needsRemoteDownload && remoteEntry) {
456
+ await this.#download({
457
+ type: "github",
458
+ repo: remoteEntry.repo || this.#repo,
459
+ subdir: remoteEntry.subdir || `plugins/${source.name}`,
460
+ ref: remoteEntry.ref || this.#ref,
461
+ }, staging);
462
+ if (!existsSync(join(staging, PLUGIN_MANIFEST))) {
463
+ throw new PluginError("PLUGIN_SOURCE_NOT_FOUND", `Remote official plugin ${source.name} does not contain ${PLUGIN_MANIFEST}.`);
464
+ }
465
+ return;
466
+ }
467
+ if (!hasLocal) {
468
+ throw new PluginError("PLUGIN_SOURCE_NOT_FOUND", `No official plugin named ${source.name}. Use an absolute or ./relative path for a local directory.`);
469
+ }
470
+ await copyDir(localDir, staging, { ignore: new Set(["node_modules", ".git"]) });
471
+ return;
472
+ }
473
+ const from = source.path;
474
+ if (!existsSync(join(from, PLUGIN_MANIFEST))) {
475
+ throw new PluginError("PLUGIN_SOURCE_NOT_FOUND", `${from} does not contain ${PLUGIN_MANIFEST}.`);
476
+ }
477
+ await copyDir(from, staging, { ignore: new Set(["node_modules", ".git"]) });
478
+ }
479
+ async #install(source, expectedId) {
480
+ const records = await this.#records();
481
+ const check = (manifest) => {
482
+ if (expectedId && manifest.id !== expectedId) {
483
+ throw new PluginError("PLUGIN_ID_MISMATCH", `Source now provides plugin ${manifest.id}, not ${expectedId}.`);
484
+ }
485
+ if (!expectedId && records[manifest.id]) {
486
+ throw new PluginError("PLUGIN_EXISTS", `Plugin ${manifest.id} is already installed. Use plugin update ${manifest.id} or remove it first.`);
487
+ }
488
+ assertPluginCompatible(manifest);
489
+ };
490
+ if (source.type === "link") {
491
+ const manifest = await readPluginManifest(source.path);
492
+ check(manifest);
493
+ return manifest;
494
+ }
495
+ const staging = join(this.#installedDir, `.staging-${randomUUID()}`);
496
+ try {
497
+ await this.#stage(source, staging);
498
+ const manifest = await readPluginManifest(staging);
499
+ check(manifest);
500
+ await installDependencies(staging);
501
+ const destination = join(this.#installedDir, manifest.id);
502
+ await rm(destination, { force: true, recursive: true });
503
+ await rename(staging, destination);
504
+ return manifest;
505
+ }
506
+ finally {
507
+ await rm(staging, { force: true, recursive: true });
508
+ }
509
+ }
510
+ async add(source) {
511
+ const manifest = await this.#install(source);
512
+ const record = { enabled: true, source, installedAt: new Date().toISOString() };
513
+ await this.#save({ ...(await this.#records()), [manifest.id]: record });
514
+ return this.#describe(manifest.id, record);
515
+ }
516
+ async update(id) {
517
+ const current = await this.get(id);
518
+ const manifest = await this.#install(current.source, id);
519
+ return { previousVersion: current.manifest?.version || null, version: manifest.version };
520
+ }
521
+ async updateAll() {
522
+ const summaries = await this.summaries({ refresh: true });
523
+ const updated = [];
524
+ const skipped = [];
525
+ for (const item of summaries) {
526
+ if (item.source.type === "link") {
527
+ skipped.push({ id: item.id, reason: "Linked development plugin; use plugin reload." });
528
+ continue;
529
+ }
530
+ if (!item.compatible) {
531
+ skipped.push({
532
+ id: item.id,
533
+ reason: item.minPcbridgeVersion
534
+ ? `Requires pcbridge v${item.minPcbridgeVersion} or newer.`
535
+ : "Incompatible plugin apiVersion.",
536
+ });
537
+ continue;
538
+ }
539
+ if (item.source.type === "official" && !item.updateAvailable) {
540
+ continue;
541
+ }
542
+ const result = await this.update(item.id);
543
+ if (result.previousVersion !== result.version || item.source.type !== "official") {
544
+ updated.push({ id: item.id, ...result });
545
+ }
546
+ }
547
+ return { updated, skipped };
548
+ }
549
+ async remove(id) {
550
+ const records = await this.#records();
551
+ const record = records[id];
552
+ if (!record)
553
+ throw new PluginError("PLUGIN_NOT_FOUND", `Plugin ${id} is not installed.`);
554
+ if (record.source.type !== "link") {
555
+ await rm(join(this.#installedDir, id), { force: true, recursive: true });
556
+ }
557
+ delete records[id];
558
+ await this.#save(records);
559
+ }
560
+ async setEnabled(id, enabled) {
561
+ const records = await this.#records();
562
+ if (!records[id])
563
+ throw new PluginError("PLUGIN_NOT_FOUND", `Plugin ${id} is not installed.`);
564
+ records[id].enabled = enabled;
565
+ await this.#save(records);
566
+ }
567
+ }