wave-agent-sdk 1.0.4 → 1.0.6
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.
- package/dist/agent.d.ts +23 -1
- package/dist/agent.js +34 -4
- package/dist/managers/aiManager.d.ts +36 -0
- package/dist/managers/aiManager.js +240 -8
- package/dist/managers/messageManager.d.ts +1 -3
- package/dist/managers/messageManager.js +19 -9
- package/dist/managers/slashCommandManager.js +28 -0
- package/dist/managers/subagentManager.d.ts +0 -2
- package/dist/services/session.js +2 -9
- package/dist/telemetry/instrumentation.d.ts +1 -1
- package/dist/telemetry/instrumentation.js +57 -28
- package/dist/tools/bashTool.js +16 -6
- package/dist/tools/grepTool.js +11 -3
- package/dist/types/index.d.ts +3 -0
- package/dist/types/messaging.d.ts +2 -0
- package/dist/utils/containerSetup.js +0 -3
- package/dist/utils/messageOperations.d.ts +10 -1
- package/dist/utils/messageOperations.js +19 -1
- package/dist/utils/notificationXml.js +5 -0
- package/dist/utils/ripgrep.d.ts +4 -4
- package/dist/utils/ripgrep.js +4 -27
- package/package.json +20 -8
- package/bin/rg +0 -79
- package/dist/managers/forkedAgentManager.d.ts +0 -50
- package/dist/managers/forkedAgentManager.js +0 -130
- package/scripts/install_ripgrep.js +0 -111
- package/scripts/postinstall.js +0 -38
- package/src/agent.ts +0 -1271
- package/src/constants/subagents.ts +0 -4
- package/src/constants/toolLimits.ts +0 -15
- package/src/constants/tools.ts +0 -24
- package/src/core/plugin.ts +0 -237
- package/src/core/session.ts +0 -9
- package/src/index.ts +0 -38
- package/src/managers/MemoryRuleManager.ts +0 -198
- package/src/managers/aiManager.ts +0 -2429
- package/src/managers/backgroundTaskManager.ts +0 -480
- package/src/managers/bangManager.ts +0 -119
- package/src/managers/cronManager.ts +0 -401
- package/src/managers/foregroundTaskManager.ts +0 -30
- package/src/managers/forkedAgentManager.ts +0 -216
- package/src/managers/hookManager.ts +0 -1089
- package/src/managers/liveConfigManager.ts +0 -445
- package/src/managers/lspManager.ts +0 -470
- package/src/managers/mcpManager.ts +0 -1010
- package/src/managers/messageManager.ts +0 -1180
- package/src/managers/messageQueue.ts +0 -157
- package/src/managers/permissionManager.ts +0 -1140
- package/src/managers/planManager.ts +0 -112
- package/src/managers/pluginManager.ts +0 -330
- package/src/managers/pluginScopeManager.ts +0 -124
- package/src/managers/reversionManager.ts +0 -178
- package/src/managers/skillManager.ts +0 -578
- package/src/managers/slashCommandManager.ts +0 -564
- package/src/managers/subagentManager.ts +0 -915
- package/src/managers/toolManager.ts +0 -489
- package/src/managers/workflowManager.ts +0 -493
- package/src/prompts/autoMemory.ts +0 -33
- package/src/prompts/autoMemoryExtraction.ts +0 -146
- package/src/prompts/index.ts +0 -506
- package/src/prompts/planModeReminders.ts +0 -126
- package/src/services/GitService.ts +0 -131
- package/src/services/MarketplaceService.ts +0 -1052
- package/src/services/MemoryRuleService.ts +0 -71
- package/src/services/aiService.ts +0 -919
- package/src/services/authService.ts +0 -565
- package/src/services/autoMemoryService.ts +0 -280
- package/src/services/configurationService.ts +0 -1520
- package/src/services/fileWatcher.ts +0 -319
- package/src/services/hook.ts +0 -348
- package/src/services/initializationService.ts +0 -357
- package/src/services/interactionService.ts +0 -229
- package/src/services/jsonlHandler.ts +0 -295
- package/src/services/memory.ts +0 -234
- package/src/services/pluginLoader.ts +0 -252
- package/src/services/remoteSettingsService.ts +0 -366
- package/src/services/reversionService.ts +0 -122
- package/src/services/session.ts +0 -922
- package/src/services/taskManager.ts +0 -321
- package/src/telemetry/events.ts +0 -65
- package/src/telemetry/instrumentation.ts +0 -499
- package/src/telemetry/sessionTracing.ts +0 -348
- package/src/tools/agentTool.ts +0 -322
- package/src/tools/askUserQuestion.ts +0 -160
- package/src/tools/bashTool.ts +0 -621
- package/src/tools/buildTool.ts +0 -61
- package/src/tools/cronCreateTool.ts +0 -161
- package/src/tools/cronDeleteTool.ts +0 -51
- package/src/tools/cronListTool.ts +0 -47
- package/src/tools/editTool.ts +0 -313
- package/src/tools/enterPlanMode.ts +0 -124
- package/src/tools/enterWorktreeTool.ts +0 -190
- package/src/tools/exitPlanMode.ts +0 -139
- package/src/tools/exitWorktreeTool.ts +0 -236
- package/src/tools/globTool.ts +0 -167
- package/src/tools/grepTool.ts +0 -399
- package/src/tools/lspTool.ts +0 -883
- package/src/tools/readTool.ts +0 -426
- package/src/tools/skillTool.ts +0 -248
- package/src/tools/taskManagementTools.ts +0 -574
- package/src/tools/taskStopTool.ts +0 -78
- package/src/tools/types.ts +0 -137
- package/src/tools/webFetchTool.ts +0 -373
- package/src/tools/workflowTool.ts +0 -205
- package/src/tools/writeTool.ts +0 -267
- package/src/types/agent.ts +0 -128
- package/src/types/auth.ts +0 -19
- package/src/types/commands.ts +0 -30
- package/src/types/config.ts +0 -43
- package/src/types/configuration.ts +0 -168
- package/src/types/core.ts +0 -105
- package/src/types/cron.ts +0 -13
- package/src/types/environment.ts +0 -106
- package/src/types/fileSearch.ts +0 -4
- package/src/types/history.ts +0 -7
- package/src/types/hooks.ts +0 -256
- package/src/types/index.ts +0 -41
- package/src/types/lsp.ts +0 -98
- package/src/types/marketplace.ts +0 -71
- package/src/types/mcp.ts +0 -43
- package/src/types/memoryRule.ts +0 -31
- package/src/types/messaging.ts +0 -114
- package/src/types/permissions.ts +0 -80
- package/src/types/plugins.ts +0 -39
- package/src/types/processes.ts +0 -99
- package/src/types/reversion.ts +0 -29
- package/src/types/session.ts +0 -12
- package/src/types/skills.ts +0 -108
- package/src/types/tasks.ts +0 -13
- package/src/types/telemetry.ts +0 -98
- package/src/types/tools.ts +0 -44
- package/src/types/workflow.ts +0 -6
- package/src/utils/abortUtils.ts +0 -118
- package/src/utils/atomicWrite.ts +0 -61
- package/src/utils/bashParser.ts +0 -899
- package/src/utils/cacheControlUtils.ts +0 -426
- package/src/utils/commandArgumentParser.ts +0 -161
- package/src/utils/commandPathResolver.ts +0 -88
- package/src/utils/configPaths.ts +0 -220
- package/src/utils/configValidator.ts +0 -100
- package/src/utils/constants.ts +0 -39
- package/src/utils/container.ts +0 -92
- package/src/utils/containerSetup.ts +0 -371
- package/src/utils/convertMessagesForAPI.ts +0 -326
- package/src/utils/cronTasks.ts +0 -128
- package/src/utils/cronTasksLock.ts +0 -182
- package/src/utils/cronToHuman.ts +0 -99
- package/src/utils/customCommands.ts +0 -95
- package/src/utils/editUtils.ts +0 -20
- package/src/utils/fileFormat.ts +0 -40
- package/src/utils/fileSearch.ts +0 -151
- package/src/utils/fileUtils.ts +0 -223
- package/src/utils/gitUtils.ts +0 -315
- package/src/utils/globalLogger.ts +0 -128
- package/src/utils/groupMessagesByApiRound.ts +0 -121
- package/src/utils/hookMatcher.ts +0 -176
- package/src/utils/markdownParser.ts +0 -317
- package/src/utils/mcpUtils.ts +0 -138
- package/src/utils/messageOperations.ts +0 -641
- package/src/utils/modelCapabilities.ts +0 -30
- package/src/utils/nameGenerator.ts +0 -99
- package/src/utils/notificationXml.ts +0 -57
- package/src/utils/openaiClient.ts +0 -251
- package/src/utils/parseCronExpression.ts +0 -78
- package/src/utils/path.ts +0 -72
- package/src/utils/pathEncoder.ts +0 -400
- package/src/utils/pathSafety.ts +0 -40
- package/src/utils/promptHistory.ts +0 -168
- package/src/utils/ripgrep.ts +0 -35
- package/src/utils/shellResolver.ts +0 -190
- package/src/utils/skillParser.ts +0 -246
- package/src/utils/stringUtils.ts +0 -156
- package/src/utils/subagentParser.ts +0 -279
- package/src/utils/taskReminder.ts +0 -96
- package/src/utils/tokenCalculation.ts +0 -43
- package/src/utils/tokenEstimate.ts +0 -34
- package/src/utils/toolResultStorage.ts +0 -117
- package/src/utils/worktreeSession.ts +0 -26
- package/src/utils/worktreeUtils.ts +0 -786
- package/src/workflow/budgetTracker.ts +0 -34
- package/src/workflow/concurrencyLimiter.ts +0 -47
- package/src/workflow/journal.ts +0 -95
- package/src/workflow/progressReporter.ts +0 -141
- package/src/workflow/runState.ts +0 -65
- package/src/workflow/scriptRuntime.ts +0 -274
- package/src/workflow/structuredOutput.ts +0 -123
- package/src/workflow/types.ts +0 -101
- package/src/workflow/workflowApis.ts +0 -410
- package/vendor/ripgrep/linux-aarch64/rg +0 -0
- package/vendor/ripgrep/linux-x86_64/rg +0 -0
- package/vendor/ripgrep/macos-aarch64/rg +0 -0
- package/vendor/ripgrep/macos-x86_64/rg +0 -0
- package/vendor/ripgrep/windows-aarch64/rg.exe +0 -0
- package/vendor/ripgrep/windows-x86_64/rg.exe +0 -0
|
@@ -1,1052 +0,0 @@
|
|
|
1
|
-
import { promises as fs, existsSync, mkdirSync } from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import * as crypto from "crypto";
|
|
4
|
-
import { getPluginsDir } from "../utils/configPaths.js";
|
|
5
|
-
import {
|
|
6
|
-
KnownMarketplace,
|
|
7
|
-
KnownMarketplacesRegistry,
|
|
8
|
-
InstalledPlugin,
|
|
9
|
-
InstalledPluginsRegistry,
|
|
10
|
-
MarketplaceManifest,
|
|
11
|
-
MarketplaceSource,
|
|
12
|
-
} from "../types/marketplace.js";
|
|
13
|
-
import { GitService } from "./GitService.js";
|
|
14
|
-
import { ConfigurationService } from "./configurationService.js";
|
|
15
|
-
import type { MarketplaceConfig, Scope } from "../types/configuration.js";
|
|
16
|
-
import { logger } from "../utils/globalLogger.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Marketplace Service
|
|
20
|
-
*
|
|
21
|
-
* Handles local plugin marketplace registration, plugin installation,
|
|
22
|
-
* and state management for installed plugins.
|
|
23
|
-
*
|
|
24
|
-
* Marketplace declarations are now scoped (user/project/local) via settings files.
|
|
25
|
-
* known_marketplaces.json is kept as a cache for installLocation/lastUpdated metadata.
|
|
26
|
-
*/
|
|
27
|
-
export class MarketplaceService {
|
|
28
|
-
private static isLockedInProcess = false;
|
|
29
|
-
private pluginsDir: string;
|
|
30
|
-
private knownMarketplacesPath: string;
|
|
31
|
-
private installedPluginsPath: string;
|
|
32
|
-
private lockPath: string;
|
|
33
|
-
private tmpDir: string;
|
|
34
|
-
private cacheDir: string;
|
|
35
|
-
private marketplacesDir: string;
|
|
36
|
-
private gitService: GitService;
|
|
37
|
-
private configurationService: ConfigurationService;
|
|
38
|
-
private workdir: string;
|
|
39
|
-
private static readonly BUILTIN_MARKETPLACE: KnownMarketplace = {
|
|
40
|
-
name: "wave-plugins-official",
|
|
41
|
-
source: {
|
|
42
|
-
source: "github",
|
|
43
|
-
repo: "netease-lcap/wave-plugins-official",
|
|
44
|
-
},
|
|
45
|
-
autoUpdate: true,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
constructor(
|
|
49
|
-
workdir: string = process.cwd(),
|
|
50
|
-
configurationService: ConfigurationService = new ConfigurationService(),
|
|
51
|
-
) {
|
|
52
|
-
this.workdir = workdir;
|
|
53
|
-
this.configurationService = configurationService;
|
|
54
|
-
this.pluginsDir = getPluginsDir();
|
|
55
|
-
this.knownMarketplacesPath = path.join(
|
|
56
|
-
this.pluginsDir,
|
|
57
|
-
"known_marketplaces.json",
|
|
58
|
-
);
|
|
59
|
-
this.installedPluginsPath = path.join(
|
|
60
|
-
this.pluginsDir,
|
|
61
|
-
"installed_plugins.json",
|
|
62
|
-
);
|
|
63
|
-
this.lockPath = path.join(this.pluginsDir, ".lock");
|
|
64
|
-
this.tmpDir = path.join(this.pluginsDir, "tmp");
|
|
65
|
-
this.cacheDir = path.join(this.pluginsDir, "cache");
|
|
66
|
-
this.marketplacesDir = path.join(this.pluginsDir, "marketplaces");
|
|
67
|
-
this.gitService = new GitService();
|
|
68
|
-
|
|
69
|
-
this.ensureDirectoryStructure();
|
|
70
|
-
this.runMigration();
|
|
71
|
-
// Stored dynamically to avoid widening keyof MarketplaceService
|
|
72
|
-
(this as Record<string, unknown>)._seedComplete =
|
|
73
|
-
this.seedBuiltinMarketplace();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Ensures the required directory structure exists in ~/.wave/plugins
|
|
78
|
-
*/
|
|
79
|
-
private ensureDirectoryStructure() {
|
|
80
|
-
[this.pluginsDir, this.tmpDir, this.cacheDir, this.marketplacesDir].forEach(
|
|
81
|
-
(dir) => {
|
|
82
|
-
if (!existsSync(dir)) {
|
|
83
|
-
mkdirSync(dir, { recursive: true });
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Backwards compatibility migration: migrate entries from known_marketplaces.json
|
|
91
|
-
* to user-level settings if they aren't already declared there.
|
|
92
|
-
*/
|
|
93
|
-
private async runMigration(): Promise<void> {
|
|
94
|
-
try {
|
|
95
|
-
const cacheRegistry = await this.getCacheRegistry();
|
|
96
|
-
const scopedMarketplaces =
|
|
97
|
-
this.configurationService.getMergedMarketplaces(this.workdir);
|
|
98
|
-
const userMarketplaces = this.configurationService.getScopedMarketplaces(
|
|
99
|
-
this.workdir,
|
|
100
|
-
"user",
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const entriesToMigrate = (cacheRegistry?.marketplaces ?? []).filter(
|
|
104
|
-
(m) => !scopedMarketplaces[m.name] && !userMarketplaces[m.name],
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (entriesToMigrate.length > 0) {
|
|
108
|
-
for (const m of entriesToMigrate) {
|
|
109
|
-
if (m.name === MarketplaceService.BUILTIN_MARKETPLACE.name) continue;
|
|
110
|
-
const config: MarketplaceConfig = {
|
|
111
|
-
source: m.source,
|
|
112
|
-
autoUpdate: m.autoUpdate,
|
|
113
|
-
};
|
|
114
|
-
await this.configurationService.addMarketplaceToScope(
|
|
115
|
-
this.workdir,
|
|
116
|
-
"user",
|
|
117
|
-
m.name,
|
|
118
|
-
config,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} catch {
|
|
123
|
-
// Migration failure should not block startup
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Seeds the builtin marketplace on first startup.
|
|
129
|
-
* Adds it to user-scope settings and marks the cache as seeded.
|
|
130
|
-
*/
|
|
131
|
-
private async seedBuiltinMarketplace(): Promise<void> {
|
|
132
|
-
try {
|
|
133
|
-
const cache = await this.getCacheRegistry();
|
|
134
|
-
if (cache?.builtinSeeded) return;
|
|
135
|
-
|
|
136
|
-
const builtin = MarketplaceService.BUILTIN_MARKETPLACE;
|
|
137
|
-
|
|
138
|
-
// Add to user-scope settings if not already in any scope
|
|
139
|
-
const scoped = this.configurationService.getMergedMarketplaces(
|
|
140
|
-
this.workdir,
|
|
141
|
-
);
|
|
142
|
-
if (!scoped[builtin.name]) {
|
|
143
|
-
await this.configurationService.addMarketplaceToScope(
|
|
144
|
-
this.workdir,
|
|
145
|
-
"user",
|
|
146
|
-
builtin.name,
|
|
147
|
-
{ source: builtin.source, autoUpdate: builtin.autoUpdate },
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Update cache: add entry + set builtinSeeded flag
|
|
152
|
-
await this.updateCacheMarketplace(builtin.name, {
|
|
153
|
-
source: builtin.source,
|
|
154
|
-
autoUpdate: builtin.autoUpdate,
|
|
155
|
-
isBuiltin: true,
|
|
156
|
-
declaredScope: "builtin",
|
|
157
|
-
});
|
|
158
|
-
await this.setBuiltinSeeded(true);
|
|
159
|
-
} catch {
|
|
160
|
-
// Seeding failure should not block startup
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Sets the builtinSeeded flag in the cache registry, preserving all other fields.
|
|
166
|
-
*/
|
|
167
|
-
private async setBuiltinSeeded(value: boolean): Promise<void> {
|
|
168
|
-
const registry = await this.getCacheRegistry();
|
|
169
|
-
const tmpPath = `${this.knownMarketplacesPath}.tmp`;
|
|
170
|
-
await fs.writeFile(
|
|
171
|
-
tmpPath,
|
|
172
|
-
JSON.stringify(
|
|
173
|
-
{
|
|
174
|
-
builtinSeeded: value,
|
|
175
|
-
marketplaces: registry?.marketplaces ?? [],
|
|
176
|
-
},
|
|
177
|
-
null,
|
|
178
|
-
2,
|
|
179
|
-
),
|
|
180
|
-
);
|
|
181
|
-
await fs.rename(tmpPath, this.knownMarketplacesPath);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Check if a lock file is stale by reading its PID and checking if the process is alive.
|
|
186
|
-
* Returns true if the lock is stale and safe to remove.
|
|
187
|
-
*/
|
|
188
|
-
private async isStaleLock(): Promise<boolean> {
|
|
189
|
-
try {
|
|
190
|
-
const content = await fs.readFile(this.lockPath, "utf-8");
|
|
191
|
-
const pid = parseInt(content.trim(), 10);
|
|
192
|
-
if (isNaN(pid)) return true;
|
|
193
|
-
try {
|
|
194
|
-
process.kill(pid, 0);
|
|
195
|
-
return false;
|
|
196
|
-
} catch {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
} catch {
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Acquires a file-based lock (with PID tracking for stale lock detection) and executes the provided function.
|
|
206
|
-
* Supports re-entrancy within the same process.
|
|
207
|
-
*/
|
|
208
|
-
private async withLock<T>(fn: () => Promise<T>): Promise<T> {
|
|
209
|
-
if (MarketplaceService.isLockedInProcess) {
|
|
210
|
-
return await fn();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
let lockFd: Awaited<ReturnType<typeof fs.open>> | undefined;
|
|
214
|
-
const maxRetries = 600;
|
|
215
|
-
const retryDelay = 100;
|
|
216
|
-
|
|
217
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
218
|
-
try {
|
|
219
|
-
lockFd = await fs.open(this.lockPath, "wx");
|
|
220
|
-
break;
|
|
221
|
-
} catch (error) {
|
|
222
|
-
if (
|
|
223
|
-
error &&
|
|
224
|
-
typeof error === "object" &&
|
|
225
|
-
"code" in error &&
|
|
226
|
-
error.code === "EEXIST"
|
|
227
|
-
) {
|
|
228
|
-
if (i > 0 && i % 60 === 0) {
|
|
229
|
-
const stale = await this.isStaleLock();
|
|
230
|
-
if (stale) {
|
|
231
|
-
await fs.unlink(this.lockPath).catch(() => {});
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (!lockFd) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
`Failed to acquire marketplace lock after ${maxRetries} retries. If no other wave-agent process is running, please delete ${this.lockPath}`,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
await fs.writeFile(this.lockPath, String(process.pid), "utf-8");
|
|
249
|
-
|
|
250
|
-
MarketplaceService.isLockedInProcess = true;
|
|
251
|
-
try {
|
|
252
|
-
return await fn();
|
|
253
|
-
} finally {
|
|
254
|
-
MarketplaceService.isLockedInProcess = false;
|
|
255
|
-
await lockFd.close();
|
|
256
|
-
await fs.unlink(this.lockPath).catch(() => {});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Loads the cache registry from known_marketplaces.json
|
|
262
|
-
* Returns null if the file doesn't exist or has no parseable content (for first-run detection).
|
|
263
|
-
*/
|
|
264
|
-
async getCacheRegistry(): Promise<KnownMarketplacesRegistry | null> {
|
|
265
|
-
if (!existsSync(this.knownMarketplacesPath)) {
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
try {
|
|
269
|
-
const content = await fs.readFile(this.knownMarketplacesPath, "utf-8");
|
|
270
|
-
if (!content.trim()) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
return JSON.parse(content);
|
|
274
|
-
} catch {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Legacy method: loads known marketplaces from cache.
|
|
281
|
-
* @deprecated Use listMarketplaces() instead, which combines scoped settings.
|
|
282
|
-
*/
|
|
283
|
-
async getKnownMarketplaces(): Promise<KnownMarketplacesRegistry> {
|
|
284
|
-
const cache = await this.getCacheRegistry();
|
|
285
|
-
if (cache === null) {
|
|
286
|
-
return { marketplaces: [] };
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
marketplaces: cache.marketplaces.map((m) => ({
|
|
290
|
-
...m,
|
|
291
|
-
isBuiltin:
|
|
292
|
-
m.isBuiltin || m.name === MarketplaceService.BUILTIN_MARKETPLACE.name,
|
|
293
|
-
declaredScope: m.declaredScope ?? "user",
|
|
294
|
-
})),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Updates the cache registry with metadata for a marketplace
|
|
300
|
-
*/
|
|
301
|
-
private async updateCacheMarketplace(
|
|
302
|
-
name: string,
|
|
303
|
-
metadata: Partial<KnownMarketplace>,
|
|
304
|
-
): Promise<void> {
|
|
305
|
-
const registry = await this.getCacheRegistry();
|
|
306
|
-
const marketplaces = registry?.marketplaces ?? [];
|
|
307
|
-
const existingIndex = marketplaces.findIndex((m) => m.name === name);
|
|
308
|
-
if (existingIndex >= 0) {
|
|
309
|
-
marketplaces[existingIndex] = {
|
|
310
|
-
...marketplaces[existingIndex],
|
|
311
|
-
...metadata,
|
|
312
|
-
};
|
|
313
|
-
} else {
|
|
314
|
-
marketplaces.push({
|
|
315
|
-
name,
|
|
316
|
-
source: metadata.source || { source: "directory", path: "" },
|
|
317
|
-
...metadata,
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
const tmpPath = `${this.knownMarketplacesPath}.tmp`;
|
|
321
|
-
await fs.writeFile(
|
|
322
|
-
tmpPath,
|
|
323
|
-
JSON.stringify(
|
|
324
|
-
{
|
|
325
|
-
builtinSeeded: registry?.builtinSeeded ?? false,
|
|
326
|
-
marketplaces,
|
|
327
|
-
},
|
|
328
|
-
null,
|
|
329
|
-
2,
|
|
330
|
-
),
|
|
331
|
-
);
|
|
332
|
-
await fs.rename(tmpPath, this.knownMarketplacesPath);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Removes a marketplace from the cache registry
|
|
337
|
-
*/
|
|
338
|
-
private async removeFromCache(name: string): Promise<void> {
|
|
339
|
-
const registry = await this.getCacheRegistry();
|
|
340
|
-
const marketplaces = registry?.marketplaces ?? [];
|
|
341
|
-
const filtered = marketplaces.filter((m) => m.name !== name);
|
|
342
|
-
const tmpPath = `${this.knownMarketplacesPath}.tmp`;
|
|
343
|
-
await fs.writeFile(
|
|
344
|
-
tmpPath,
|
|
345
|
-
JSON.stringify(
|
|
346
|
-
{
|
|
347
|
-
builtinSeeded: registry?.builtinSeeded ?? false,
|
|
348
|
-
marketplaces: filtered,
|
|
349
|
-
},
|
|
350
|
-
null,
|
|
351
|
-
2,
|
|
352
|
-
),
|
|
353
|
-
);
|
|
354
|
-
await fs.rename(tmpPath, this.knownMarketplacesPath);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Loads the installed plugins registry
|
|
359
|
-
*/
|
|
360
|
-
async getInstalledPlugins(): Promise<InstalledPluginsRegistry> {
|
|
361
|
-
if (!existsSync(this.installedPluginsPath)) {
|
|
362
|
-
return { plugins: [] };
|
|
363
|
-
}
|
|
364
|
-
try {
|
|
365
|
-
const content = await fs.readFile(this.installedPluginsPath, "utf-8");
|
|
366
|
-
if (!content.trim()) {
|
|
367
|
-
return { plugins: [] };
|
|
368
|
-
}
|
|
369
|
-
return JSON.parse(content);
|
|
370
|
-
} catch (error) {
|
|
371
|
-
console.error("Failed to load installed plugins:", error);
|
|
372
|
-
return { plugins: [] };
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Saves the installed plugins registry
|
|
378
|
-
*/
|
|
379
|
-
async saveInstalledPlugins(
|
|
380
|
-
registry: InstalledPluginsRegistry,
|
|
381
|
-
): Promise<void> {
|
|
382
|
-
const tmpPath = `${this.installedPluginsPath}.tmp`;
|
|
383
|
-
await fs.writeFile(tmpPath, JSON.stringify(registry, null, 2));
|
|
384
|
-
await fs.rename(tmpPath, this.installedPluginsPath);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Loads a marketplace manifest from a local path
|
|
389
|
-
*/
|
|
390
|
-
async loadMarketplaceManifest(
|
|
391
|
-
marketplacePath: string,
|
|
392
|
-
): Promise<MarketplaceManifest> {
|
|
393
|
-
let manifestPath = path.join(
|
|
394
|
-
marketplacePath,
|
|
395
|
-
".wave-plugin",
|
|
396
|
-
"marketplace.json",
|
|
397
|
-
);
|
|
398
|
-
if (!existsSync(manifestPath)) {
|
|
399
|
-
// Fallback to .claude-plugin/marketplace.json
|
|
400
|
-
manifestPath = path.join(
|
|
401
|
-
marketplacePath,
|
|
402
|
-
".claude-plugin",
|
|
403
|
-
"marketplace.json",
|
|
404
|
-
);
|
|
405
|
-
if (!existsSync(manifestPath)) {
|
|
406
|
-
throw new Error(`Marketplace manifest not found at ${manifestPath}`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
const content = await fs.readFile(manifestPath, "utf-8");
|
|
410
|
-
const manifest = JSON.parse(content);
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
!manifest.name ||
|
|
414
|
-
!manifest.plugins ||
|
|
415
|
-
!Array.isArray(manifest.plugins)
|
|
416
|
-
) {
|
|
417
|
-
throw new Error(`Invalid marketplace manifest at ${manifestPath}`);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return manifest;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Resolves the local path for a marketplace
|
|
425
|
-
*/
|
|
426
|
-
public getMarketplacePath(source: MarketplaceSource): string {
|
|
427
|
-
if (source.source === "directory") {
|
|
428
|
-
return source.path;
|
|
429
|
-
} else if (source.source === "github") {
|
|
430
|
-
return path.join(this.marketplacesDir, source.repo);
|
|
431
|
-
} else {
|
|
432
|
-
const hash = crypto.createHash("md5").update(source.url).digest("hex");
|
|
433
|
-
return path.join(this.marketplacesDir, hash);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Builds a KnownMarketplace from a scoped config, enriched with cache metadata
|
|
439
|
-
*/
|
|
440
|
-
private async buildMarketplaceEntry(
|
|
441
|
-
name: string,
|
|
442
|
-
config: MarketplaceConfig,
|
|
443
|
-
cache: KnownMarketplace | undefined,
|
|
444
|
-
declaredScope: "user" | "project" | "local" | "builtin",
|
|
445
|
-
): Promise<KnownMarketplace> {
|
|
446
|
-
return {
|
|
447
|
-
name,
|
|
448
|
-
source: config.source,
|
|
449
|
-
autoUpdate: config.autoUpdate ?? cache?.autoUpdate,
|
|
450
|
-
lastUpdated: cache?.lastUpdated,
|
|
451
|
-
isBuiltin: name === MarketplaceService.BUILTIN_MARKETPLACE.name,
|
|
452
|
-
declaredScope,
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Finds which scope declared a marketplace (user, project, local, or builtin)
|
|
458
|
-
*/
|
|
459
|
-
getMarketplaceDeclaringSource(name: string): Scope | "builtin" | null {
|
|
460
|
-
const scopes: Scope[] = ["local", "project", "user"];
|
|
461
|
-
for (const scope of scopes) {
|
|
462
|
-
const scoped = this.configurationService.getScopedMarketplaces(
|
|
463
|
-
this.workdir,
|
|
464
|
-
scope,
|
|
465
|
-
);
|
|
466
|
-
if (scoped[name]) return scope;
|
|
467
|
-
}
|
|
468
|
-
if (name === MarketplaceService.BUILTIN_MARKETPLACE.name) return "builtin";
|
|
469
|
-
return null;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Adds a new marketplace (local directory, GitHub repo, or Git URL)
|
|
474
|
-
*/
|
|
475
|
-
async addMarketplace(
|
|
476
|
-
input: string,
|
|
477
|
-
scope: Scope = "user",
|
|
478
|
-
): Promise<KnownMarketplace> {
|
|
479
|
-
return this.withLock(async () => {
|
|
480
|
-
let marketplace: KnownMarketplace;
|
|
481
|
-
|
|
482
|
-
const isFullUrl =
|
|
483
|
-
input.startsWith("http://") ||
|
|
484
|
-
input.startsWith("https://") ||
|
|
485
|
-
input.startsWith("git@") ||
|
|
486
|
-
input.startsWith("ssh://");
|
|
487
|
-
|
|
488
|
-
if (
|
|
489
|
-
isFullUrl ||
|
|
490
|
-
(input.includes("/") &&
|
|
491
|
-
!path.isAbsolute(input) &&
|
|
492
|
-
!input.startsWith("."))
|
|
493
|
-
) {
|
|
494
|
-
let urlOrRepo = input;
|
|
495
|
-
let ref: string | undefined;
|
|
496
|
-
|
|
497
|
-
if (input.includes("#")) {
|
|
498
|
-
[urlOrRepo, ref] = input.split("#");
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
const tempSource: MarketplaceSource = isFullUrl
|
|
502
|
-
? { source: "git", url: urlOrRepo, ref }
|
|
503
|
-
: { source: "github", repo: urlOrRepo, ref };
|
|
504
|
-
|
|
505
|
-
const targetPath = this.getMarketplacePath(tempSource);
|
|
506
|
-
|
|
507
|
-
if (!existsSync(targetPath)) {
|
|
508
|
-
try {
|
|
509
|
-
await this.gitService.clone(urlOrRepo, targetPath, ref);
|
|
510
|
-
} catch (error) {
|
|
511
|
-
throw new Error(
|
|
512
|
-
`Failed to add marketplace from Git: ${error instanceof Error ? error.message : String(error)}`,
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
let manifest: MarketplaceManifest;
|
|
518
|
-
try {
|
|
519
|
-
manifest = await this.loadMarketplaceManifest(targetPath);
|
|
520
|
-
} catch (error) {
|
|
521
|
-
throw new Error(
|
|
522
|
-
`Failed to load manifest from cloned repository: ${error instanceof Error ? error.message : String(error)}`,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
marketplace = {
|
|
527
|
-
name: manifest.name,
|
|
528
|
-
source: isFullUrl
|
|
529
|
-
? { source: "git", url: urlOrRepo, ref }
|
|
530
|
-
: { source: "github", repo: urlOrRepo, ref },
|
|
531
|
-
autoUpdate: false,
|
|
532
|
-
lastUpdated: new Date().toISOString(),
|
|
533
|
-
};
|
|
534
|
-
} else {
|
|
535
|
-
const absolutePath = path.resolve(input);
|
|
536
|
-
let manifest: MarketplaceManifest;
|
|
537
|
-
try {
|
|
538
|
-
manifest = await this.loadMarketplaceManifest(absolutePath);
|
|
539
|
-
} catch (error) {
|
|
540
|
-
throw new Error(
|
|
541
|
-
`Failed to load manifest from directory: ${error instanceof Error ? error.message : String(error)}`,
|
|
542
|
-
);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
marketplace = {
|
|
546
|
-
name: manifest.name,
|
|
547
|
-
source: { source: "directory", path: absolutePath },
|
|
548
|
-
autoUpdate: false,
|
|
549
|
-
lastUpdated: new Date().toISOString(),
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const config: MarketplaceConfig = {
|
|
554
|
-
source: marketplace.source,
|
|
555
|
-
autoUpdate: marketplace.autoUpdate,
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
await this.configurationService.addMarketplaceToScope(
|
|
559
|
-
this.workdir,
|
|
560
|
-
scope,
|
|
561
|
-
marketplace.name,
|
|
562
|
-
config,
|
|
563
|
-
);
|
|
564
|
-
|
|
565
|
-
// Update cache with metadata
|
|
566
|
-
await this.updateCacheMarketplace(marketplace.name, {
|
|
567
|
-
source: marketplace.source,
|
|
568
|
-
autoUpdate: marketplace.autoUpdate,
|
|
569
|
-
lastUpdated: marketplace.lastUpdated,
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
return marketplace;
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Lists all registered marketplaces by combining scoped settings + cache
|
|
578
|
-
*/
|
|
579
|
-
async listMarketplaces(): Promise<KnownMarketplace[]> {
|
|
580
|
-
const scopedMarketplaces = this.configurationService.getMergedMarketplaces(
|
|
581
|
-
this.workdir,
|
|
582
|
-
);
|
|
583
|
-
const cacheRegistry = await this.getCacheRegistry();
|
|
584
|
-
const cacheMap = new Map(
|
|
585
|
-
(cacheRegistry?.marketplaces ?? []).map((m) => [m.name, m]),
|
|
586
|
-
);
|
|
587
|
-
|
|
588
|
-
const result: KnownMarketplace[] = [];
|
|
589
|
-
|
|
590
|
-
// Add all scoped marketplaces (local overrides project overrides user)
|
|
591
|
-
for (const [name, config] of Object.entries(scopedMarketplaces)) {
|
|
592
|
-
const cache = cacheMap.get(name);
|
|
593
|
-
const declaredScope = this.getMarketplaceDeclaringSource(name) as
|
|
594
|
-
| "user"
|
|
595
|
-
| "project"
|
|
596
|
-
| "local";
|
|
597
|
-
result.push(
|
|
598
|
-
await this.buildMarketplaceEntry(name, config, cache, declaredScope),
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// Add cache entries not yet in scoped settings (backwards compatibility)
|
|
603
|
-
for (const [name, cache] of cacheMap.entries()) {
|
|
604
|
-
if (scopedMarketplaces[name]) continue;
|
|
605
|
-
const isBuiltin = name === MarketplaceService.BUILTIN_MARKETPLACE.name;
|
|
606
|
-
result.push({
|
|
607
|
-
...cache,
|
|
608
|
-
isBuiltin,
|
|
609
|
-
declaredScope: cache.declaredScope ?? (isBuiltin ? "builtin" : "user"),
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return result;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Removes a marketplace by name from the specified scope
|
|
618
|
-
*/
|
|
619
|
-
async removeMarketplace(name: string, scope?: Scope): Promise<void> {
|
|
620
|
-
return this.withLock(async () => {
|
|
621
|
-
const targetScope =
|
|
622
|
-
scope || this.getMarketplaceDeclaringSource(name) || "user";
|
|
623
|
-
|
|
624
|
-
// Uninstall all plugins from this marketplace
|
|
625
|
-
await this.uninstallPluginsByMarketplace(name);
|
|
626
|
-
|
|
627
|
-
if (targetScope !== "builtin") {
|
|
628
|
-
await this.configurationService.removeMarketplaceFromScope(
|
|
629
|
-
this.workdir,
|
|
630
|
-
targetScope,
|
|
631
|
-
name,
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// Also remove from cache
|
|
636
|
-
await this.removeFromCache(name);
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* Uninstalls all plugins belonging to a given marketplace.
|
|
642
|
-
* Removes them from installed_plugins.json, deletes cache files,
|
|
643
|
-
* and cleans up enabledPlugins entries from all scopes.
|
|
644
|
-
*/
|
|
645
|
-
private async uninstallPluginsByMarketplace(
|
|
646
|
-
marketplaceName: string,
|
|
647
|
-
): Promise<void> {
|
|
648
|
-
const installedRegistry = await this.getInstalledPlugins();
|
|
649
|
-
const pluginsFromMarketplace = installedRegistry.plugins.filter(
|
|
650
|
-
(p) => p.marketplace === marketplaceName,
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
if (pluginsFromMarketplace.length === 0) return;
|
|
654
|
-
|
|
655
|
-
// Remove all plugins from this marketplace from the registry
|
|
656
|
-
installedRegistry.plugins = installedRegistry.plugins.filter(
|
|
657
|
-
(p) => p.marketplace !== marketplaceName,
|
|
658
|
-
);
|
|
659
|
-
await this.saveInstalledPlugins(installedRegistry);
|
|
660
|
-
|
|
661
|
-
// Delete cache files that are no longer referenced
|
|
662
|
-
const remainingCachePaths = new Set(
|
|
663
|
-
installedRegistry.plugins.map((p) => p.cachePath),
|
|
664
|
-
);
|
|
665
|
-
for (const plugin of pluginsFromMarketplace) {
|
|
666
|
-
if (
|
|
667
|
-
!remainingCachePaths.has(plugin.cachePath) &&
|
|
668
|
-
existsSync(plugin.cachePath)
|
|
669
|
-
) {
|
|
670
|
-
await fs.rm(plugin.cachePath, { recursive: true, force: true });
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// Remove enabledPlugins entries from all scopes
|
|
675
|
-
const scopes: Scope[] = ["user", "project", "local"];
|
|
676
|
-
for (const plugin of pluginsFromMarketplace) {
|
|
677
|
-
const pluginId = `${plugin.name}@${plugin.marketplace}`;
|
|
678
|
-
for (const s of scopes) {
|
|
679
|
-
await this.configurationService.removeEnabledPlugin(
|
|
680
|
-
this.workdir,
|
|
681
|
-
s,
|
|
682
|
-
pluginId,
|
|
683
|
-
);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Updates a specific marketplace or all marketplaces
|
|
690
|
-
*/
|
|
691
|
-
async updateMarketplace(
|
|
692
|
-
name?: string,
|
|
693
|
-
options?: { updatePlugins?: boolean },
|
|
694
|
-
): Promise<void> {
|
|
695
|
-
return this.withLock(async () => {
|
|
696
|
-
const marketplaces = await this.listMarketplaces();
|
|
697
|
-
const toUpdate = name
|
|
698
|
-
? marketplaces.filter((m) => m.name === name)
|
|
699
|
-
: marketplaces;
|
|
700
|
-
|
|
701
|
-
if (name && toUpdate.length === 0) {
|
|
702
|
-
throw new Error(`Marketplace ${name} not found`);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
const isGitAvailable = await this.gitService.isGitAvailable();
|
|
706
|
-
const errors: string[] = [];
|
|
707
|
-
for (const marketplace of toUpdate) {
|
|
708
|
-
try {
|
|
709
|
-
if (
|
|
710
|
-
marketplace.source.source === "github" ||
|
|
711
|
-
marketplace.source.source === "git"
|
|
712
|
-
) {
|
|
713
|
-
if (!isGitAvailable) {
|
|
714
|
-
console.warn(
|
|
715
|
-
`Skipping update for Git/GitHub marketplace "${marketplace.name}" because Git is not installed.`,
|
|
716
|
-
);
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
const targetPath = this.getMarketplacePath(marketplace.source);
|
|
720
|
-
if (existsSync(targetPath)) {
|
|
721
|
-
await this.gitService.pull(targetPath);
|
|
722
|
-
} else {
|
|
723
|
-
let url: string;
|
|
724
|
-
if (marketplace.source.source === "github") {
|
|
725
|
-
url = marketplace.source.repo;
|
|
726
|
-
} else {
|
|
727
|
-
url = marketplace.source.url;
|
|
728
|
-
}
|
|
729
|
-
await this.gitService.clone(
|
|
730
|
-
url,
|
|
731
|
-
targetPath,
|
|
732
|
-
marketplace.source.ref,
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
const manifest = await this.loadMarketplaceManifest(
|
|
737
|
-
this.getMarketplacePath(marketplace.source),
|
|
738
|
-
);
|
|
739
|
-
|
|
740
|
-
marketplace.lastUpdated = new Date().toISOString();
|
|
741
|
-
|
|
742
|
-
// Update cache metadata
|
|
743
|
-
await this.updateCacheMarketplace(marketplace.name, {
|
|
744
|
-
lastUpdated: marketplace.lastUpdated,
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
if (options?.updatePlugins) {
|
|
748
|
-
const installedRegistry = await this.getInstalledPlugins();
|
|
749
|
-
const pluginsToUpdate = installedRegistry.plugins.filter(
|
|
750
|
-
(p) => p.marketplace === marketplace.name,
|
|
751
|
-
);
|
|
752
|
-
for (const plugin of pluginsToUpdate) {
|
|
753
|
-
const pluginEntry = manifest.plugins.find(
|
|
754
|
-
(p) => p.name === plugin.name,
|
|
755
|
-
);
|
|
756
|
-
if (!pluginEntry) {
|
|
757
|
-
logger.warn(
|
|
758
|
-
`Plugin "${plugin.name}" no longer found in marketplace "${marketplace.name}". Uninstalling...`,
|
|
759
|
-
);
|
|
760
|
-
try {
|
|
761
|
-
await this.uninstallPlugin(
|
|
762
|
-
`${plugin.name}@${plugin.marketplace}`,
|
|
763
|
-
plugin.projectPath,
|
|
764
|
-
);
|
|
765
|
-
} catch (error) {
|
|
766
|
-
console.error(
|
|
767
|
-
`Failed to uninstall orphaned plugin "${plugin.name}" from marketplace "${marketplace.name}":`,
|
|
768
|
-
error,
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
continue;
|
|
772
|
-
}
|
|
773
|
-
try {
|
|
774
|
-
await this.installPlugin(
|
|
775
|
-
`${plugin.name}@${plugin.marketplace}`,
|
|
776
|
-
plugin.projectPath,
|
|
777
|
-
);
|
|
778
|
-
} catch (error) {
|
|
779
|
-
console.error(
|
|
780
|
-
`Failed to update plugin "${plugin.name}" from marketplace "${marketplace.name}":`,
|
|
781
|
-
error,
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
} catch (error) {
|
|
787
|
-
const msg = `Failed to update marketplace "${marketplace.name}": ${error instanceof Error ? error.message : String(error)}`;
|
|
788
|
-
console.error(msg);
|
|
789
|
-
errors.push(msg);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
if (errors.length > 0) {
|
|
794
|
-
throw new Error(
|
|
795
|
-
`Some marketplaces failed to update:\n${errors.join("\n")}`,
|
|
796
|
-
);
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* Automatically updates all marketplaces that have auto-update enabled
|
|
803
|
-
*/
|
|
804
|
-
async autoUpdateAll(): Promise<void> {
|
|
805
|
-
return this.withLock(async () => {
|
|
806
|
-
const scopedMarketplaces =
|
|
807
|
-
this.configurationService.getMergedMarketplaces(this.workdir);
|
|
808
|
-
const toAutoUpdate = Object.entries(scopedMarketplaces)
|
|
809
|
-
.filter(([, config]) => config.autoUpdate)
|
|
810
|
-
.map(([name]) => name);
|
|
811
|
-
|
|
812
|
-
for (const marketplaceName of toAutoUpdate) {
|
|
813
|
-
try {
|
|
814
|
-
await this.updateMarketplace(marketplaceName, {
|
|
815
|
-
updatePlugins: true,
|
|
816
|
-
});
|
|
817
|
-
} catch (error) {
|
|
818
|
-
console.error(
|
|
819
|
-
`Auto-update failed for marketplace "${marketplaceName}":`,
|
|
820
|
-
error,
|
|
821
|
-
);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Toggles auto-update for a marketplace
|
|
829
|
-
*/
|
|
830
|
-
async toggleAutoUpdate(name: string, enabled: boolean): Promise<void> {
|
|
831
|
-
return this.withLock(async () => {
|
|
832
|
-
const declaringSource = this.getMarketplaceDeclaringSource(name);
|
|
833
|
-
if (!declaringSource || declaringSource === "builtin") {
|
|
834
|
-
throw new Error(`Marketplace ${name} not found`);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
const scoped = this.configurationService.getScopedMarketplaces(
|
|
838
|
-
this.workdir,
|
|
839
|
-
declaringSource,
|
|
840
|
-
);
|
|
841
|
-
const config = scoped[name];
|
|
842
|
-
if (!config) {
|
|
843
|
-
throw new Error(`Marketplace ${name} not found`);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
config.autoUpdate = enabled;
|
|
847
|
-
await this.configurationService.addMarketplaceToScope(
|
|
848
|
-
this.workdir,
|
|
849
|
-
declaringSource,
|
|
850
|
-
name,
|
|
851
|
-
config,
|
|
852
|
-
);
|
|
853
|
-
|
|
854
|
-
// Also update cache
|
|
855
|
-
await this.updateCacheMarketplace(name, { autoUpdate: enabled });
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
/**
|
|
860
|
-
* Installs a plugin from a marketplace
|
|
861
|
-
*/
|
|
862
|
-
async installPlugin(
|
|
863
|
-
pluginAtMarketplace: string,
|
|
864
|
-
projectPath?: string,
|
|
865
|
-
): Promise<InstalledPlugin> {
|
|
866
|
-
return this.withLock(async () => {
|
|
867
|
-
const [pluginName, marketplaceName] = pluginAtMarketplace.split("@");
|
|
868
|
-
if (!pluginName || !marketplaceName) {
|
|
869
|
-
throw new Error("Invalid plugin format. Use name@marketplace");
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
const marketplaces = await this.listMarketplaces();
|
|
873
|
-
const marketplace = marketplaces.find((m) => m.name === marketplaceName);
|
|
874
|
-
if (!marketplace) {
|
|
875
|
-
throw new Error(`Marketplace ${marketplaceName} not found`);
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
const marketplacePath = this.getMarketplacePath(marketplace.source);
|
|
879
|
-
const manifest = await this.loadMarketplaceManifest(marketplacePath);
|
|
880
|
-
const pluginEntry = manifest.plugins.find((p) => p.name === pluginName);
|
|
881
|
-
if (!pluginEntry) {
|
|
882
|
-
throw new Error(
|
|
883
|
-
`Plugin ${pluginName} not found in marketplace ${marketplaceName}`,
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
const isGitSource =
|
|
888
|
-
pluginEntry.source.startsWith("http://") ||
|
|
889
|
-
pluginEntry.source.startsWith("https://") ||
|
|
890
|
-
pluginEntry.source.startsWith("git@") ||
|
|
891
|
-
pluginEntry.source.startsWith("ssh://");
|
|
892
|
-
|
|
893
|
-
let pluginSrcPath: string;
|
|
894
|
-
let tempCloneDir: string | undefined;
|
|
895
|
-
|
|
896
|
-
try {
|
|
897
|
-
if (isGitSource) {
|
|
898
|
-
tempCloneDir = path.join(this.tmpDir, `clone-${Date.now()}`);
|
|
899
|
-
let url = pluginEntry.source;
|
|
900
|
-
let ref: string | undefined;
|
|
901
|
-
if (url.includes("#")) {
|
|
902
|
-
[url, ref] = url.split("#");
|
|
903
|
-
}
|
|
904
|
-
await this.gitService.clone(url, tempCloneDir, ref);
|
|
905
|
-
pluginSrcPath = tempCloneDir;
|
|
906
|
-
} else {
|
|
907
|
-
pluginSrcPath = path.resolve(marketplacePath, pluginEntry.source);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
let pluginManifestPath = path.join(
|
|
911
|
-
pluginSrcPath,
|
|
912
|
-
".wave-plugin",
|
|
913
|
-
"plugin.json",
|
|
914
|
-
);
|
|
915
|
-
if (!existsSync(pluginManifestPath)) {
|
|
916
|
-
// Fallback to .claude-plugin/plugin.json
|
|
917
|
-
pluginManifestPath = path.join(
|
|
918
|
-
pluginSrcPath,
|
|
919
|
-
".claude-plugin",
|
|
920
|
-
"plugin.json",
|
|
921
|
-
);
|
|
922
|
-
if (!existsSync(pluginManifestPath)) {
|
|
923
|
-
throw new Error(
|
|
924
|
-
`Plugin manifest not found at ${pluginManifestPath}`,
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
const pluginManifestContent = await fs.readFile(
|
|
930
|
-
pluginManifestPath,
|
|
931
|
-
"utf-8",
|
|
932
|
-
);
|
|
933
|
-
const pluginManifest = JSON.parse(pluginManifestContent);
|
|
934
|
-
const version = pluginManifest.version || "1.0.0";
|
|
935
|
-
|
|
936
|
-
const tmpPluginDir = path.join(
|
|
937
|
-
this.tmpDir,
|
|
938
|
-
`${pluginName}-${Date.now()}`,
|
|
939
|
-
);
|
|
940
|
-
try {
|
|
941
|
-
if (isGitSource) {
|
|
942
|
-
await fs.rename(pluginSrcPath, tmpPluginDir);
|
|
943
|
-
tempCloneDir = undefined;
|
|
944
|
-
} else {
|
|
945
|
-
await fs.cp(pluginSrcPath, tmpPluginDir, { recursive: true });
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
const cachePath = path.join(
|
|
949
|
-
this.cacheDir,
|
|
950
|
-
marketplaceName,
|
|
951
|
-
pluginName,
|
|
952
|
-
version,
|
|
953
|
-
);
|
|
954
|
-
if (existsSync(cachePath)) {
|
|
955
|
-
await fs.rm(cachePath, { recursive: true, force: true });
|
|
956
|
-
}
|
|
957
|
-
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
958
|
-
await fs.rename(tmpPluginDir, cachePath);
|
|
959
|
-
|
|
960
|
-
const installedRegistry = await this.getInstalledPlugins();
|
|
961
|
-
const existingIndex = installedRegistry.plugins.findIndex(
|
|
962
|
-
(p) =>
|
|
963
|
-
p.name === pluginName &&
|
|
964
|
-
p.marketplace === marketplaceName &&
|
|
965
|
-
p.projectPath === projectPath,
|
|
966
|
-
);
|
|
967
|
-
|
|
968
|
-
const installedPlugin: InstalledPlugin = {
|
|
969
|
-
name: pluginName,
|
|
970
|
-
marketplace: marketplaceName,
|
|
971
|
-
version,
|
|
972
|
-
cachePath,
|
|
973
|
-
projectPath,
|
|
974
|
-
};
|
|
975
|
-
|
|
976
|
-
if (existingIndex >= 0) {
|
|
977
|
-
installedRegistry.plugins[existingIndex] = installedPlugin;
|
|
978
|
-
} else {
|
|
979
|
-
installedRegistry.plugins.push(installedPlugin);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
await this.saveInstalledPlugins(installedRegistry);
|
|
983
|
-
return installedPlugin;
|
|
984
|
-
} catch (error) {
|
|
985
|
-
if (existsSync(tmpPluginDir)) {
|
|
986
|
-
await fs.rm(tmpPluginDir, { recursive: true, force: true });
|
|
987
|
-
}
|
|
988
|
-
throw error;
|
|
989
|
-
}
|
|
990
|
-
} catch (error) {
|
|
991
|
-
if (tempCloneDir && existsSync(tempCloneDir)) {
|
|
992
|
-
await fs.rm(tempCloneDir, { recursive: true, force: true });
|
|
993
|
-
}
|
|
994
|
-
throw new Error(
|
|
995
|
-
`Failed to install plugin ${pluginName}: ${error instanceof Error ? error.message : String(error)}`,
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
/**
|
|
1002
|
-
* Uninstalls a plugin
|
|
1003
|
-
*/
|
|
1004
|
-
async uninstallPlugin(
|
|
1005
|
-
pluginAtMarketplace: string,
|
|
1006
|
-
projectPath?: string,
|
|
1007
|
-
): Promise<void> {
|
|
1008
|
-
return this.withLock(async () => {
|
|
1009
|
-
const [pluginName, marketplaceName] = pluginAtMarketplace.split("@");
|
|
1010
|
-
if (!pluginName || !marketplaceName) {
|
|
1011
|
-
throw new Error("Invalid plugin format. Use name@marketplace");
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
const installedRegistry = await this.getInstalledPlugins();
|
|
1015
|
-
const pluginIndex = installedRegistry.plugins.findIndex(
|
|
1016
|
-
(p) =>
|
|
1017
|
-
p.name === pluginName &&
|
|
1018
|
-
p.marketplace === marketplaceName &&
|
|
1019
|
-
p.projectPath === projectPath,
|
|
1020
|
-
);
|
|
1021
|
-
|
|
1022
|
-
if (pluginIndex === -1) {
|
|
1023
|
-
throw new Error(
|
|
1024
|
-
`Plugin ${pluginName}@${marketplaceName} is not installed${projectPath ? ` for project ${projectPath}` : ""}`,
|
|
1025
|
-
);
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
const pluginToRemove = installedRegistry.plugins[pluginIndex];
|
|
1029
|
-
|
|
1030
|
-
installedRegistry.plugins.splice(pluginIndex, 1);
|
|
1031
|
-
await this.saveInstalledPlugins(installedRegistry);
|
|
1032
|
-
|
|
1033
|
-
const isStillReferenced = installedRegistry.plugins.some(
|
|
1034
|
-
(p) => p.cachePath === pluginToRemove.cachePath,
|
|
1035
|
-
);
|
|
1036
|
-
|
|
1037
|
-
if (!isStillReferenced && existsSync(pluginToRemove.cachePath)) {
|
|
1038
|
-
await fs.rm(pluginToRemove.cachePath, { recursive: true, force: true });
|
|
1039
|
-
}
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Updates a plugin (uninstall followed by install)
|
|
1045
|
-
*/
|
|
1046
|
-
async updatePlugin(pluginAtMarketplace: string): Promise<InstalledPlugin> {
|
|
1047
|
-
return this.withLock(async () => {
|
|
1048
|
-
await this.uninstallPlugin(pluginAtMarketplace);
|
|
1049
|
-
return this.installPlugin(pluginAtMarketplace);
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
}
|