mcpick 0.0.8 → 0.0.10

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,259 @@
1
+ import { exec } from 'node:child_process';
2
+ import { readdir, readFile, rm, writeFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ import { get_installed_plugins_path, get_known_marketplaces_path, get_marketplace_manifest_path, get_plugin_cache_dir, } from '../utils/paths.js';
6
+ const execAsync = promisify(exec);
7
+ const EMPTY_INSTALLED = {
8
+ version: 2,
9
+ plugins: {},
10
+ };
11
+ // --- Data reading ---
12
+ export async function read_installed_plugins() {
13
+ try {
14
+ const content = await readFile(get_installed_plugins_path(), 'utf-8');
15
+ return JSON.parse(content);
16
+ }
17
+ catch {
18
+ return { ...EMPTY_INSTALLED, plugins: {} };
19
+ }
20
+ }
21
+ export async function write_installed_plugins(data) {
22
+ await writeFile(get_installed_plugins_path(), JSON.stringify(data, null, 2), 'utf-8');
23
+ }
24
+ export async function read_known_marketplaces() {
25
+ try {
26
+ const content = await readFile(get_known_marketplaces_path(), 'utf-8');
27
+ return JSON.parse(content);
28
+ }
29
+ catch {
30
+ return {};
31
+ }
32
+ }
33
+ export async function read_marketplace_manifest(name) {
34
+ try {
35
+ const content = await readFile(get_marketplace_manifest_path(name), 'utf-8');
36
+ return JSON.parse(content);
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ // --- Git operations ---
43
+ async function get_marketplace_head_sha(marketplace_path) {
44
+ try {
45
+ const { stdout } = await execAsync(`git -C ${JSON.stringify(marketplace_path)} rev-parse HEAD`, { timeout: 10_000 });
46
+ return stdout.trim() || null;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ export async function refresh_marketplace(name, marketplace) {
53
+ const dir = marketplace.installLocation;
54
+ try {
55
+ await execAsync(`git -C ${JSON.stringify(dir)} pull --ff-only`, {
56
+ timeout: 30_000,
57
+ });
58
+ return { success: true };
59
+ }
60
+ catch (err) {
61
+ const message = err instanceof Error ? err.message : 'Unknown error';
62
+ return { success: false, error: `${name}: ${message}` };
63
+ }
64
+ }
65
+ export async function refresh_all_marketplaces() {
66
+ const marketplaces = await read_known_marketplaces();
67
+ const results = new Map();
68
+ for (const [name, info] of Object.entries(marketplaces)) {
69
+ results.set(name, await refresh_marketplace(name, info));
70
+ }
71
+ return results;
72
+ }
73
+ // --- Orphaned version detection ---
74
+ async function find_orphaned_versions(marketplace, plugin_name) {
75
+ const cache_dir = get_plugin_cache_dir();
76
+ const plugin_dir = join(cache_dir, marketplace, plugin_name);
77
+ const orphaned = [];
78
+ try {
79
+ const versions = await readdir(plugin_dir, {
80
+ withFileTypes: true,
81
+ });
82
+ for (const entry of versions) {
83
+ if (!entry.isDirectory())
84
+ continue;
85
+ try {
86
+ const marker = join(plugin_dir, entry.name, '.orphaned_at');
87
+ await readFile(marker);
88
+ orphaned.push(entry.name);
89
+ }
90
+ catch {
91
+ // No .orphaned_at marker — not orphaned
92
+ }
93
+ }
94
+ }
95
+ catch {
96
+ // Plugin dir doesn't exist
97
+ }
98
+ return orphaned;
99
+ }
100
+ // --- Staleness analysis ---
101
+ function parse_plugin_key(key) {
102
+ const at_index = key.lastIndexOf('@');
103
+ return {
104
+ name: at_index > 0 ? key.substring(0, at_index) : key,
105
+ marketplace: at_index > 0 ? key.substring(at_index + 1) : 'unknown',
106
+ };
107
+ }
108
+ export async function get_cached_plugins_info() {
109
+ const installed = await read_installed_plugins();
110
+ const marketplaces = await read_known_marketplaces();
111
+ // Load all marketplace manifests
112
+ const manifests = new Map();
113
+ for (const name of Object.keys(marketplaces)) {
114
+ const manifest = await read_marketplace_manifest(name);
115
+ if (manifest)
116
+ manifests.set(name, manifest);
117
+ }
118
+ // Get HEAD SHAs for each marketplace clone
119
+ const sha_cache = new Map();
120
+ for (const [name, info] of Object.entries(marketplaces)) {
121
+ sha_cache.set(name, await get_marketplace_head_sha(info.installLocation));
122
+ }
123
+ const results = [];
124
+ for (const [key, entries] of Object.entries(installed.plugins)) {
125
+ const entry = entries[0];
126
+ if (!entry)
127
+ continue;
128
+ const { name, marketplace } = parse_plugin_key(key);
129
+ // Version comparison
130
+ const manifest = manifests.get(marketplace);
131
+ const manifest_plugin = manifest?.plugins.find((p) => p.name === name);
132
+ const latest_version = manifest_plugin?.version ?? null;
133
+ const is_version_stale = latest_version !== null && latest_version !== entry.version;
134
+ // SHA comparison
135
+ const remote_sha = sha_cache.get(marketplace) ?? null;
136
+ const is_sha_stale = remote_sha !== null &&
137
+ entry.gitCommitSha !== '' &&
138
+ remote_sha !== entry.gitCommitSha;
139
+ // Orphaned versions
140
+ const orphaned = await find_orphaned_versions(marketplace, name);
141
+ results.push({
142
+ key,
143
+ name,
144
+ marketplace,
145
+ installedVersion: entry.version,
146
+ latestVersion: latest_version,
147
+ installedSha: entry.gitCommitSha,
148
+ remoteSha: remote_sha,
149
+ isVersionStale: is_version_stale,
150
+ isShaStale: is_sha_stale,
151
+ orphanedVersions: orphaned,
152
+ installPath: entry.installPath,
153
+ });
154
+ }
155
+ return results;
156
+ }
157
+ // --- Cache clearing ---
158
+ function is_safe_cache_path(path) {
159
+ const cache_dir = resolve(get_plugin_cache_dir());
160
+ const target = resolve(path);
161
+ return target.startsWith(cache_dir + '/');
162
+ }
163
+ export async function clear_plugin_caches(keys) {
164
+ const installed = await read_installed_plugins();
165
+ const marketplaces = await read_known_marketplaces();
166
+ const cleared = [];
167
+ const errors = [];
168
+ // Collect unique marketplaces to refresh
169
+ const marketplace_names = new Set();
170
+ for (const key of keys) {
171
+ const { marketplace } = parse_plugin_key(key);
172
+ marketplace_names.add(marketplace);
173
+ }
174
+ // Refresh relevant marketplaces first
175
+ for (const mkt_name of marketplace_names) {
176
+ const mkt_info = marketplaces[mkt_name];
177
+ if (mkt_info) {
178
+ const result = await refresh_marketplace(mkt_name, mkt_info);
179
+ if (!result.success) {
180
+ errors.push(`Marketplace refresh failed: ${result.error}`);
181
+ }
182
+ }
183
+ }
184
+ // Delete cache dirs and remove from installed_plugins.json
185
+ const cache_dir = get_plugin_cache_dir();
186
+ for (const key of keys) {
187
+ const { name, marketplace } = parse_plugin_key(key);
188
+ const plugin_cache_path = join(cache_dir, marketplace, name);
189
+ if (!is_safe_cache_path(plugin_cache_path)) {
190
+ errors.push(`Unsafe path, skipped: ${plugin_cache_path}`);
191
+ continue;
192
+ }
193
+ try {
194
+ await rm(plugin_cache_path, {
195
+ recursive: true,
196
+ force: true,
197
+ });
198
+ delete installed.plugins[key];
199
+ cleared.push(key);
200
+ }
201
+ catch (err) {
202
+ const msg = err instanceof Error ? err.message : 'Unknown error';
203
+ errors.push(`Failed to clear ${key}: ${msg}`);
204
+ }
205
+ }
206
+ // Write back updated installed_plugins.json
207
+ await write_installed_plugins(installed);
208
+ return { cleared, errors };
209
+ }
210
+ // --- Orphaned cleanup ---
211
+ export async function clean_orphaned_versions() {
212
+ const cache_dir = get_plugin_cache_dir();
213
+ const cleaned_paths = [];
214
+ try {
215
+ const marketplaces = await readdir(cache_dir, {
216
+ withFileTypes: true,
217
+ });
218
+ for (const mkt of marketplaces) {
219
+ if (!mkt.isDirectory())
220
+ continue;
221
+ const mkt_path = join(cache_dir, mkt.name);
222
+ const plugins = await readdir(mkt_path, {
223
+ withFileTypes: true,
224
+ });
225
+ for (const plugin of plugins) {
226
+ if (!plugin.isDirectory())
227
+ continue;
228
+ const plugin_path = join(mkt_path, plugin.name);
229
+ const versions = await readdir(plugin_path, {
230
+ withFileTypes: true,
231
+ });
232
+ for (const version of versions) {
233
+ if (!version.isDirectory())
234
+ continue;
235
+ const version_path = join(plugin_path, version.name);
236
+ try {
237
+ await readFile(join(version_path, '.orphaned_at'));
238
+ // Has orphaned marker — safe to delete
239
+ if (is_safe_cache_path(version_path)) {
240
+ await rm(version_path, {
241
+ recursive: true,
242
+ force: true,
243
+ });
244
+ cleaned_paths.push(`${mkt.name}/${plugin.name}/${version.name}`);
245
+ }
246
+ }
247
+ catch {
248
+ // No marker — keep it
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ catch {
255
+ // Cache dir doesn't exist
256
+ }
257
+ return { cleaned: cleaned_paths.length, paths: cleaned_paths };
258
+ }
259
+ //# sourceMappingURL=plugin-cache.js.map
@@ -0,0 +1,59 @@
1
+ import { access, readFile, writeFile } from 'node:fs/promises';
2
+ import { get_claude_settings_path } from '../utils/paths.js';
3
+ export async function read_claude_settings() {
4
+ const settings_path = get_claude_settings_path();
5
+ try {
6
+ await access(settings_path);
7
+ const content = await readFile(settings_path, 'utf-8');
8
+ return JSON.parse(content);
9
+ }
10
+ catch (error) {
11
+ if (error instanceof Error &&
12
+ 'code' in error &&
13
+ error.code === 'ENOENT') {
14
+ return {};
15
+ }
16
+ throw error;
17
+ }
18
+ }
19
+ export async function write_claude_settings(updates) {
20
+ const settings_path = get_claude_settings_path();
21
+ let existing = {};
22
+ try {
23
+ const content = await readFile(settings_path, 'utf-8');
24
+ existing = JSON.parse(content);
25
+ }
26
+ catch {
27
+ // Start with empty if file doesn't exist
28
+ }
29
+ // Merge only the keys we're updating
30
+ for (const [key, value] of Object.entries(updates)) {
31
+ existing[key] = value;
32
+ }
33
+ await writeFile(settings_path, JSON.stringify(existing, null, 2), 'utf-8');
34
+ }
35
+ /**
36
+ * Parse enabledPlugins into structured list.
37
+ * Keys are in format "plugin-name@marketplace-name"
38
+ */
39
+ export function get_all_plugins(settings) {
40
+ const enabled_plugins = settings.enabledPlugins || {};
41
+ return Object.entries(enabled_plugins).map(([key, enabled]) => {
42
+ const at_index = key.lastIndexOf('@');
43
+ const name = at_index > 0 ? key.substring(0, at_index) : key;
44
+ const marketplace = at_index > 0 ? key.substring(at_index + 1) : 'unknown';
45
+ return { name, marketplace, enabled };
46
+ });
47
+ }
48
+ /**
49
+ * Build the enabledPlugins record from a list of PluginInfo
50
+ */
51
+ export function build_enabled_plugins(plugins) {
52
+ const result = {};
53
+ for (const plugin of plugins) {
54
+ const key = `${plugin.name}@${plugin.marketplace}`;
55
+ result[key] = plugin.enabled;
56
+ }
57
+ return result;
58
+ }
59
+ //# sourceMappingURL=settings.js.map
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ import { cancel, intro, isCancel, log, outro, select, text, } from '@clack/promp
3
3
  import { add_server } from './commands/add-server.js';
4
4
  import { backup_config } from './commands/backup.js';
5
5
  import { edit_config } from './commands/edit-config.js';
6
+ import { edit_plugins } from './commands/edit-plugins.js';
7
+ import { manage_cache } from './commands/manage-cache.js';
6
8
  import { restore_config } from './commands/restore.js';
7
9
  import { write_claude_config } from './core/config.js';
8
10
  import { list_profiles, load_profile, save_profile, } from './core/profile.js';
@@ -142,6 +144,16 @@ async function main() {
142
144
  label: 'Enable / Disable MCP servers',
143
145
  hint: 'Toggle MCP servers on/off',
144
146
  },
147
+ {
148
+ value: 'edit-plugins',
149
+ label: 'Enable / Disable plugins',
150
+ hint: 'Toggle Claude Code plugins on/off',
151
+ },
152
+ {
153
+ value: 'manage-cache',
154
+ label: 'Manage plugin cache',
155
+ hint: 'View, clear, or refresh plugin caches',
156
+ },
145
157
  {
146
158
  value: 'backup',
147
159
  label: 'Backup config',
@@ -182,6 +194,12 @@ async function main() {
182
194
  case 'edit-config':
183
195
  await edit_config();
184
196
  break;
197
+ case 'edit-plugins':
198
+ await edit_plugins();
199
+ break;
200
+ case 'manage-cache':
201
+ await manage_cache();
202
+ break;
185
203
  case 'backup':
186
204
  await backup_config();
187
205
  break;
@@ -223,8 +241,28 @@ async function main() {
223
241
  }
224
242
  }
225
243
  }
226
- main().catch((error) => {
227
- console.error('Fatal error:', error);
228
- process.exit(1);
229
- });
244
+ const SUBCOMMANDS = new Set([
245
+ 'list',
246
+ 'enable',
247
+ 'disable',
248
+ 'remove',
249
+ 'add',
250
+ 'backup',
251
+ 'restore',
252
+ 'profile',
253
+ 'plugins',
254
+ 'cache',
255
+ ]);
256
+ const arg = process.argv[2];
257
+ if ((arg && SUBCOMMANDS.has(arg)) ||
258
+ arg === '--help' ||
259
+ arg === '-h') {
260
+ import('./cli/index.js').then((m) => m.run());
261
+ }
262
+ else {
263
+ main().catch((error) => {
264
+ console.error('Fatal error:', error);
265
+ process.exit(1);
266
+ });
267
+ }
230
268
  //# sourceMappingURL=index.js.map
@@ -25,6 +25,9 @@ export function get_claude_config_path() {
25
25
  }
26
26
  return join(parentDir, '.claude.json');
27
27
  }
28
+ export function get_claude_settings_path() {
29
+ return join(get_base_dir().baseDir, 'settings.json');
30
+ }
28
31
  export function get_mcpick_dir() {
29
32
  return join(get_base_dir().baseDir, 'mcpick');
30
33
  }
@@ -78,4 +81,22 @@ export function get_project_mcp_json_path() {
78
81
  export function get_global_mcp_json_path() {
79
82
  return join(homedir(), '.mcp.json');
80
83
  }
84
+ export function get_plugins_dir() {
85
+ return join(get_base_dir().baseDir, 'plugins');
86
+ }
87
+ export function get_installed_plugins_path() {
88
+ return join(get_plugins_dir(), 'installed_plugins.json');
89
+ }
90
+ export function get_known_marketplaces_path() {
91
+ return join(get_plugins_dir(), 'known_marketplaces.json');
92
+ }
93
+ export function get_plugin_cache_dir() {
94
+ return join(get_plugins_dir(), 'cache');
95
+ }
96
+ export function get_marketplaces_dir() {
97
+ return join(get_plugins_dir(), 'marketplaces');
98
+ }
99
+ export function get_marketplace_manifest_path(name) {
100
+ return join(get_marketplaces_dir(), name, '.claude-plugin', 'marketplace.json');
101
+ }
81
102
  //# sourceMappingURL=paths.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcpick",
3
- "version": "0.0.8",
4
- "description": "Dynamic MCP server configuration manager for Claude Code",
3
+ "version": "0.0.10",
4
+ "description": "Dynamic MCP server and plugin configuration manager for Claude Code",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "bin": {
@@ -20,13 +20,14 @@
20
20
  "author": "",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@clack/prompts": "^0.11.0",
24
- "valibot": "^1.2.0"
23
+ "@clack/prompts": "^1.1.0",
24
+ "citty": "^0.2.1",
25
+ "valibot": "^1.3.1"
25
26
  },
26
27
  "devDependencies": {
27
- "@changesets/cli": "^2.29.8",
28
- "@types/node": "^24.10.1",
29
- "prettier": "^3.7.4",
28
+ "@changesets/cli": "^2.30.0",
29
+ "@types/node": "^25.5.0",
30
+ "prettier": "^3.8.1",
30
31
  "typescript": "^5.9.3"
31
32
  },
32
33
  "scripts": {
@@ -1,21 +0,0 @@
1
- import { outro } from '@clack/prompts';
2
- import { execSync } from 'node:child_process';
3
- export async function launch_claude_code() {
4
- try {
5
- outro('Launching Claude Code...');
6
- // Replace the current process with claude using exec
7
- // This ensures the terminal stays valid and Claude gets full control
8
- execSync('claude', {
9
- stdio: 'inherit',
10
- });
11
- }
12
- catch (error) {
13
- if (error instanceof Error && 'status' in error) {
14
- // Claude exited normally, just return
15
- return;
16
- }
17
- // Only throw for actual errors (not exit codes)
18
- throw new Error(`Failed to launch Claude Code: ${error instanceof Error ? error.message : 'Unknown error'}`);
19
- }
20
- }
21
- //# sourceMappingURL=launch.js.map