@spences10/pi-skills 0.0.8 → 0.0.9
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/commands.d.ts +2 -0
- package/dist/commands.js +444 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +11 -1
- package/dist/config.js +73 -4
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -720
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +20 -1
- package/dist/manager.js +183 -22
- package/dist/manager.js.map +1 -1
- package/dist/skill-utils.d.ts +23 -0
- package/dist/skill-utils.js +221 -0
- package/dist/skill-utils.js.map +1 -0
- package/dist/skills-ui.d.ts +16 -0
- package/dist/skills-ui.js +374 -0
- package/dist/skills-ui.js.map +1 -0
- package/package.json +11 -8
package/dist/index.js
CHANGED
|
@@ -1,722 +1,3 @@
|
|
|
1
|
-
import { show_picker_modal, show_settings_modal, show_text_modal, } from '@spences10/pi-tui-modal';
|
|
2
|
-
import { create_skills_manager, } from './manager.js';
|
|
3
1
|
export { create_skills_manager } from './manager.js';
|
|
4
|
-
|
|
5
|
-
const DISABLED = '○ disabled';
|
|
6
|
-
const SYNC = '↻ sync';
|
|
7
|
-
const IMPORTED_LABEL = '✓ imported';
|
|
8
|
-
function sort_skills(skills) {
|
|
9
|
-
return [...skills].sort((a, b) => {
|
|
10
|
-
const by_name = a.name.localeCompare(b.name);
|
|
11
|
-
if (by_name !== 0)
|
|
12
|
-
return by_name;
|
|
13
|
-
const by_source = a.source.localeCompare(b.source);
|
|
14
|
-
if (by_source !== 0)
|
|
15
|
-
return by_source;
|
|
16
|
-
return a.key.localeCompare(b.key);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function find_matching_imported_skill(managed_skills, skill) {
|
|
20
|
-
const exact_match = managed_skills.find((candidate) => candidate.import_meta?.source === skill.source &&
|
|
21
|
-
(candidate.import_meta.upstream_skill_path ===
|
|
22
|
-
skill.skillPath ||
|
|
23
|
-
candidate.import_meta.upstream_base_dir === skill.baseDir));
|
|
24
|
-
if (exact_match)
|
|
25
|
-
return exact_match;
|
|
26
|
-
return managed_skills.find((candidate) => candidate.import_meta?.source === skill.source &&
|
|
27
|
-
candidate.name === skill.name);
|
|
28
|
-
}
|
|
29
|
-
function get_importable_state(managed_skills, skill) {
|
|
30
|
-
const imported = find_matching_imported_skill(managed_skills, skill);
|
|
31
|
-
if (imported?.import_meta) {
|
|
32
|
-
const version_changed = Boolean(skill.plugin?.version &&
|
|
33
|
-
imported.import_meta.upstream_version &&
|
|
34
|
-
skill.plugin.version !== imported.import_meta.upstream_version);
|
|
35
|
-
const sha_changed = Boolean(skill.plugin?.gitCommitSha &&
|
|
36
|
-
imported.import_meta.upstream_git_commit_sha &&
|
|
37
|
-
skill.plugin.gitCommitSha !==
|
|
38
|
-
imported.import_meta.upstream_git_commit_sha);
|
|
39
|
-
if (version_changed || sha_changed) {
|
|
40
|
-
return {
|
|
41
|
-
label: 'sync',
|
|
42
|
-
detail: 'Press Enter to sync the imported copy and reload',
|
|
43
|
-
action: 'sync',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
label: 'imported',
|
|
48
|
-
detail: `Already imported to ${imported.baseDir}`,
|
|
49
|
-
action: null,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const managed_conflict = managed_skills.find((candidate) => candidate.name === skill.name);
|
|
53
|
-
if (managed_conflict) {
|
|
54
|
-
return {
|
|
55
|
-
label: 'managed',
|
|
56
|
-
detail: `Already managed at ${managed_conflict.baseDir}`,
|
|
57
|
-
action: null,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
label: 'import',
|
|
62
|
-
detail: 'Press Enter to import into pi-native skills and reload',
|
|
63
|
-
action: 'import',
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function to_setting_item(skill) {
|
|
67
|
-
const detail_lines = [
|
|
68
|
-
`${skill.source} • ${skill.key}`,
|
|
69
|
-
skill.description,
|
|
70
|
-
skill.baseDir,
|
|
71
|
-
];
|
|
72
|
-
if (skill.import_meta?.upstream_version) {
|
|
73
|
-
detail_lines.push(`upstream: ${skill.import_meta.upstream_version}${skill.import_meta.upstream_git_commit_sha ? ` • ${skill.import_meta.upstream_git_commit_sha.slice(0, 12)}` : ''}`);
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
id: skill.key,
|
|
77
|
-
label: skill.name,
|
|
78
|
-
description: detail_lines.join('\n'),
|
|
79
|
-
currentValue: skill.enabled ? ENABLED : DISABLED,
|
|
80
|
-
values: [ENABLED, DISABLED],
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function to_importable_setting_item(managed_skills, skill) {
|
|
84
|
-
const state = get_importable_state(managed_skills, skill);
|
|
85
|
-
const detail_lines = [
|
|
86
|
-
`${skill.source} • ${skill.key}`,
|
|
87
|
-
skill.description,
|
|
88
|
-
skill.baseDir,
|
|
89
|
-
];
|
|
90
|
-
if (skill.plugin?.version) {
|
|
91
|
-
detail_lines.push(`plugin: ${skill.plugin.version}${skill.plugin.gitCommitSha ? ` • ${skill.plugin.gitCommitSha.slice(0, 12)}` : ''}`);
|
|
92
|
-
}
|
|
93
|
-
if (state.action === 'import') {
|
|
94
|
-
return {
|
|
95
|
-
id: skill.key,
|
|
96
|
-
label: skill.name,
|
|
97
|
-
description: detail_lines.join('\n'),
|
|
98
|
-
currentValue: DISABLED,
|
|
99
|
-
values: [ENABLED, DISABLED],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
if (state.action === 'sync') {
|
|
103
|
-
detail_lines.push('enter to sync');
|
|
104
|
-
return {
|
|
105
|
-
id: skill.key,
|
|
106
|
-
label: skill.name,
|
|
107
|
-
description: detail_lines.join('\n'),
|
|
108
|
-
currentValue: SYNC,
|
|
109
|
-
values: [SYNC],
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
detail_lines.push(state.detail);
|
|
113
|
-
return {
|
|
114
|
-
id: skill.key,
|
|
115
|
-
label: skill.name,
|
|
116
|
-
description: detail_lines.join('\n'),
|
|
117
|
-
currentValue: IMPORTED_LABEL,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function sets_equal(a, b) {
|
|
121
|
-
if (a.size !== b.size)
|
|
122
|
-
return false;
|
|
123
|
-
for (const value of a) {
|
|
124
|
-
if (!b.has(value))
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
async function show_skills_home_modal(ctx, managed_count, importable_count) {
|
|
130
|
-
return await show_picker_modal(ctx, {
|
|
131
|
-
title: 'Skills',
|
|
132
|
-
subtitle: `${managed_count} managed • ${importable_count} importable`,
|
|
133
|
-
items: [
|
|
134
|
-
{
|
|
135
|
-
value: 'manage',
|
|
136
|
-
label: 'Manage skills',
|
|
137
|
-
description: 'Enable, disable, import, and sync skills',
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
value: 'browse',
|
|
141
|
-
label: 'Browse details',
|
|
142
|
-
description: 'Open read-only detail views for discovered skills',
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
value: 'import',
|
|
146
|
-
label: 'Import skill',
|
|
147
|
-
description: 'Copy an external skill into Pi-native storage',
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
value: 'sync',
|
|
151
|
-
label: 'Sync imported skill',
|
|
152
|
-
description: 'Update an imported skill from its upstream source',
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
value: 'refresh',
|
|
156
|
-
label: 'Refresh discovery',
|
|
157
|
-
description: 'Rescan managed and importable skills',
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
value: 'defaults',
|
|
161
|
-
label: 'Default policy',
|
|
162
|
-
description: 'Choose whether new skills default enabled or disabled',
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
footer: 'enter opens • esc close/back',
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
async function show_skills_manager_modal(ctx, mgr) {
|
|
169
|
-
const discovered = sort_skills(mgr.discover());
|
|
170
|
-
const importable = sort_skills(mgr.discover_importable());
|
|
171
|
-
if (discovered.length === 0 && importable.length === 0) {
|
|
172
|
-
ctx.ui.notify('No managed or importable skills found');
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
const initial_enabled = new Set(discovered
|
|
176
|
-
.filter((skill) => skill.enabled)
|
|
177
|
-
.map((skill) => skill.key));
|
|
178
|
-
const current_enabled = new Set(initial_enabled);
|
|
179
|
-
const queued_imports = new Set();
|
|
180
|
-
let reload_notice = null;
|
|
181
|
-
const managed_items = discovered.map(to_setting_item);
|
|
182
|
-
const importable_items = importable.map((skill) => to_importable_setting_item(discovered, skill));
|
|
183
|
-
const all_items = [];
|
|
184
|
-
if (managed_items.length > 0) {
|
|
185
|
-
all_items.push({
|
|
186
|
-
id: '__header_managed__',
|
|
187
|
-
label: `── Managed (${managed_items.length}) ──`,
|
|
188
|
-
description: '',
|
|
189
|
-
currentValue: '',
|
|
190
|
-
});
|
|
191
|
-
all_items.push(...managed_items);
|
|
192
|
-
}
|
|
193
|
-
if (importable_items.length > 0) {
|
|
194
|
-
all_items.push({
|
|
195
|
-
id: '__header_importable__',
|
|
196
|
-
label: `── Importable (${importable_items.length}) ──`,
|
|
197
|
-
description: '',
|
|
198
|
-
currentValue: '',
|
|
199
|
-
});
|
|
200
|
-
all_items.push(...importable_items);
|
|
201
|
-
}
|
|
202
|
-
const metadata_by_id = new Map(all_items.map((item) => [item.id, item.description ?? '']));
|
|
203
|
-
for (const item of all_items) {
|
|
204
|
-
if (!item.id.startsWith('__header_'))
|
|
205
|
-
item.description = '';
|
|
206
|
-
}
|
|
207
|
-
const managed_keys = new Set(discovered.map((skill) => skill.key));
|
|
208
|
-
const importable_map = new Map(importable.map((skill) => [skill.key, skill]));
|
|
209
|
-
await show_settings_modal(ctx, {
|
|
210
|
-
title: 'Skills',
|
|
211
|
-
subtitle: () => {
|
|
212
|
-
const enabled = current_enabled.size;
|
|
213
|
-
const disabled = discovered.length - enabled;
|
|
214
|
-
const queued = queued_imports.size;
|
|
215
|
-
const parts = [`${enabled} enabled`, `${disabled} disabled`];
|
|
216
|
-
if (importable.length > 0)
|
|
217
|
-
parts.push(`${importable.length} importable`);
|
|
218
|
-
if (queued > 0)
|
|
219
|
-
parts.push(`${queued} queued for import`);
|
|
220
|
-
return parts.join(' • ');
|
|
221
|
-
},
|
|
222
|
-
items: all_items,
|
|
223
|
-
max_visible: Math.min(Math.max(all_items.length + 4, 8), 12),
|
|
224
|
-
enable_search: true,
|
|
225
|
-
metadata: (item) => item ? metadata_by_id.get(item.id)?.split('\n') : undefined,
|
|
226
|
-
on_change: (id, new_value) => {
|
|
227
|
-
if (id.startsWith('__header_'))
|
|
228
|
-
return;
|
|
229
|
-
if (managed_keys.has(id)) {
|
|
230
|
-
if (new_value === ENABLED) {
|
|
231
|
-
current_enabled.add(id);
|
|
232
|
-
mgr.enable(id);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
current_enabled.delete(id);
|
|
236
|
-
mgr.disable(id);
|
|
237
|
-
}
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const import_skill = importable_map.get(id);
|
|
241
|
-
if (!import_skill)
|
|
242
|
-
return;
|
|
243
|
-
const state = get_importable_state(discovered, import_skill);
|
|
244
|
-
if (state.action === 'import') {
|
|
245
|
-
if (new_value === ENABLED)
|
|
246
|
-
queued_imports.add(id);
|
|
247
|
-
else
|
|
248
|
-
queued_imports.delete(id);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (state.action !== 'sync')
|
|
252
|
-
return;
|
|
253
|
-
const imported_skill = find_matching_imported_skill(discovered, import_skill);
|
|
254
|
-
if (!imported_skill) {
|
|
255
|
-
ctx.ui.notify(`Imported copy for ${import_skill.name} was not found`, 'warning');
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
const result = mgr.sync_skill(imported_skill.key);
|
|
260
|
-
if (result.changed) {
|
|
261
|
-
reload_notice = `Synced ${import_skill.name}. Reloading...`;
|
|
262
|
-
return true;
|
|
263
|
-
}
|
|
264
|
-
ctx.ui.notify(`${import_skill.name} is already up to date.`, 'info');
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'warning');
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
});
|
|
271
|
-
if (queued_imports.size > 0) {
|
|
272
|
-
const imported_names = [];
|
|
273
|
-
for (const key of queued_imports) {
|
|
274
|
-
try {
|
|
275
|
-
mgr.import_skill(key);
|
|
276
|
-
imported_names.push(key);
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'warning');
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (imported_names.length > 0) {
|
|
283
|
-
reload_notice = `Imported ${imported_names.length} skill(s). Reloading...`;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (reload_notice) {
|
|
287
|
-
ctx.ui.notify(reload_notice, 'info');
|
|
288
|
-
await ctx.reload();
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
if (!sets_equal(initial_enabled, current_enabled)) {
|
|
292
|
-
ctx.ui.notify('Reloading to apply updated skills...', 'info');
|
|
293
|
-
await ctx.reload();
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
function skill_status(skill) {
|
|
299
|
-
if (skill.kind === 'external')
|
|
300
|
-
return 'importable';
|
|
301
|
-
return skill.enabled ? 'enabled' : 'disabled';
|
|
302
|
-
}
|
|
303
|
-
function format_skill_detail(skill) {
|
|
304
|
-
const lines = [
|
|
305
|
-
`# ${skill.name}`,
|
|
306
|
-
'',
|
|
307
|
-
`Status: ${skill_status(skill)}`,
|
|
308
|
-
`Source: ${skill.source}`,
|
|
309
|
-
`Key: ${skill.key}`,
|
|
310
|
-
`Kind: ${skill.kind}`,
|
|
311
|
-
'',
|
|
312
|
-
skill.description,
|
|
313
|
-
'',
|
|
314
|
-
`Base directory: ${skill.baseDir}`,
|
|
315
|
-
`Skill file: ${skill.skillPath}`,
|
|
316
|
-
];
|
|
317
|
-
if (skill.plugin) {
|
|
318
|
-
lines.push('', 'Plugin', `- ID: ${skill.plugin.pluginId}`, `- Version: ${skill.plugin.version}`, `- Install path: ${skill.plugin.installPath}`);
|
|
319
|
-
if (skill.plugin.gitCommitSha) {
|
|
320
|
-
lines.push(`- Commit: ${skill.plugin.gitCommitSha}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
if (skill.import_meta) {
|
|
324
|
-
lines.push('', 'Import metadata', `- Upstream source: ${skill.import_meta.source}`, `- Imported at: ${skill.import_meta.imported_at}`, `- Last synced at: ${skill.import_meta.last_synced_at}`, `- Upstream path: ${skill.import_meta.upstream_skill_path}`);
|
|
325
|
-
if (skill.import_meta.upstream_version) {
|
|
326
|
-
lines.push(`- Upstream version: ${skill.import_meta.upstream_version}`);
|
|
327
|
-
}
|
|
328
|
-
if (skill.import_meta.upstream_git_commit_sha) {
|
|
329
|
-
lines.push(`- Upstream commit: ${skill.import_meta.upstream_git_commit_sha}`);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return lines.join('\n');
|
|
333
|
-
}
|
|
334
|
-
function format_skill_list(skills) {
|
|
335
|
-
if (skills.length === 0)
|
|
336
|
-
return 'No skills found.';
|
|
337
|
-
return sort_skills(skills)
|
|
338
|
-
.map((skill) => `${skill_status(skill).padEnd(10)} ${skill.name} (${skill.key})`)
|
|
339
|
-
.join('\n');
|
|
340
|
-
}
|
|
341
|
-
function find_skill(skills, key_or_name) {
|
|
342
|
-
const query = key_or_name.trim();
|
|
343
|
-
const exact_key = skills.find((skill) => skill.key === query);
|
|
344
|
-
if (exact_key)
|
|
345
|
-
return exact_key;
|
|
346
|
-
const exact_name = skills.filter((skill) => skill.name === query);
|
|
347
|
-
if (exact_name.length === 1)
|
|
348
|
-
return exact_name[0];
|
|
349
|
-
if (exact_name.length > 1) {
|
|
350
|
-
throw new Error(`Multiple skills named ${query}. Use an exact key instead.`);
|
|
351
|
-
}
|
|
352
|
-
const lower = query.toLowerCase();
|
|
353
|
-
const fuzzy = skills.filter((skill) => skill.key.toLowerCase() === lower ||
|
|
354
|
-
skill.name.toLowerCase() === lower);
|
|
355
|
-
if (fuzzy.length === 1)
|
|
356
|
-
return fuzzy[0];
|
|
357
|
-
if (fuzzy.length > 1) {
|
|
358
|
-
throw new Error(`Multiple skills matched ${query}. Use an exact key instead.`);
|
|
359
|
-
}
|
|
360
|
-
throw new Error(`Unknown skill: ${query}`);
|
|
361
|
-
}
|
|
362
|
-
async function pick_skill(ctx, options) {
|
|
363
|
-
return await show_picker_modal(ctx, {
|
|
364
|
-
title: options.title,
|
|
365
|
-
subtitle: options.subtitle,
|
|
366
|
-
items: options.skills.map((skill) => ({
|
|
367
|
-
value: skill.key,
|
|
368
|
-
label: skill.name,
|
|
369
|
-
description: `${skill_status(skill)} • ${skill.source} • ${skill.key}`,
|
|
370
|
-
})),
|
|
371
|
-
empty_message: options.empty_message,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
async function show_skill_detail_modal(ctx, skill) {
|
|
375
|
-
await show_text_modal(ctx, {
|
|
376
|
-
title: skill.name,
|
|
377
|
-
subtitle: `${skill_status(skill)} • ${skill.source}`,
|
|
378
|
-
text: format_skill_detail(skill),
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
async function show_skill_list_modal(ctx, mgr) {
|
|
382
|
-
while (true) {
|
|
383
|
-
const skills = sort_skills([
|
|
384
|
-
...mgr.discover(),
|
|
385
|
-
...mgr.discover_importable(),
|
|
386
|
-
]);
|
|
387
|
-
const key = await pick_skill(ctx, {
|
|
388
|
-
title: 'Browse skills',
|
|
389
|
-
subtitle: `${mgr.discover().length} managed • ${mgr.discover_importable().length} importable`,
|
|
390
|
-
skills,
|
|
391
|
-
empty_message: 'No skills found',
|
|
392
|
-
});
|
|
393
|
-
if (!key)
|
|
394
|
-
return;
|
|
395
|
-
await show_skill_detail_modal(ctx, find_skill(skills, key));
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
async function show_refresh_summary(ctx, mgr) {
|
|
399
|
-
mgr.refresh();
|
|
400
|
-
await show_text_modal(ctx, {
|
|
401
|
-
title: 'Skills refreshed',
|
|
402
|
-
text: `${mgr.discover().length} managed skills\n${mgr.discover_importable().length} importable skills found`,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
async function show_defaults_modal(ctx, mgr) {
|
|
406
|
-
const selected = await show_picker_modal(ctx, {
|
|
407
|
-
title: 'Skill default policy',
|
|
408
|
-
subtitle: 'Choose how newly discovered skills start',
|
|
409
|
-
items: [
|
|
410
|
-
{
|
|
411
|
-
value: 'all-enabled',
|
|
412
|
-
label: 'All enabled',
|
|
413
|
-
description: 'New skills are enabled by default',
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
value: 'all-disabled',
|
|
417
|
-
label: 'All disabled',
|
|
418
|
-
description: 'New skills require explicit enablement',
|
|
419
|
-
},
|
|
420
|
-
],
|
|
421
|
-
});
|
|
422
|
-
if (!selected)
|
|
423
|
-
return;
|
|
424
|
-
mgr.set_defaults(selected);
|
|
425
|
-
await show_text_modal(ctx, {
|
|
426
|
-
title: 'Skill defaults updated',
|
|
427
|
-
text: `Default policy: ${selected}`,
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
// Default export for Pi Package / additionalExtensionPaths loading
|
|
431
|
-
export default async function skills(pi) {
|
|
432
|
-
const mgr = create_skills_manager();
|
|
433
|
-
const subs = [
|
|
434
|
-
'list',
|
|
435
|
-
'show',
|
|
436
|
-
'import',
|
|
437
|
-
'sync',
|
|
438
|
-
'refresh',
|
|
439
|
-
'defaults',
|
|
440
|
-
];
|
|
441
|
-
pi.registerCommand('skills', {
|
|
442
|
-
description: 'Manage pi-native skills and import external skills',
|
|
443
|
-
getArgumentCompletions: (prefix) => {
|
|
444
|
-
const parts = prefix.trimStart().split(/\s+/);
|
|
445
|
-
const has_trailing_space = /\s$/.test(prefix);
|
|
446
|
-
if (parts.length <= 1 && !has_trailing_space) {
|
|
447
|
-
return subs
|
|
448
|
-
.filter((s) => s.startsWith(parts[0] || ''))
|
|
449
|
-
.map((s) => ({ value: s, label: s }));
|
|
450
|
-
}
|
|
451
|
-
if (parts[0] === 'show') {
|
|
452
|
-
const q = parts.slice(1).join(' ').toLowerCase();
|
|
453
|
-
return sort_skills([
|
|
454
|
-
...mgr.discover(),
|
|
455
|
-
...mgr.discover_importable(),
|
|
456
|
-
])
|
|
457
|
-
.filter((s) => s.key.toLowerCase().includes(q) ||
|
|
458
|
-
s.name.toLowerCase().includes(q))
|
|
459
|
-
.slice(0, 20)
|
|
460
|
-
.map((s) => ({
|
|
461
|
-
value: `${parts[0]} ${s.key}`,
|
|
462
|
-
label: s.key,
|
|
463
|
-
}));
|
|
464
|
-
}
|
|
465
|
-
if (parts[0] === 'import') {
|
|
466
|
-
const q = parts.slice(1).join(' ').toLowerCase();
|
|
467
|
-
return sort_skills(mgr.discover_importable())
|
|
468
|
-
.filter((s) => s.key.toLowerCase().includes(q) ||
|
|
469
|
-
s.name.toLowerCase().includes(q))
|
|
470
|
-
.slice(0, 20)
|
|
471
|
-
.map((s) => ({
|
|
472
|
-
value: `${parts[0]} ${s.key}`,
|
|
473
|
-
label: s.key,
|
|
474
|
-
}));
|
|
475
|
-
}
|
|
476
|
-
if (parts[0] === 'sync') {
|
|
477
|
-
const q = parts.slice(1).join(' ').toLowerCase();
|
|
478
|
-
return sort_skills(mgr
|
|
479
|
-
.discover()
|
|
480
|
-
.filter((skill) => Boolean(skill.import_meta)))
|
|
481
|
-
.filter((s) => s.key.toLowerCase().includes(q) ||
|
|
482
|
-
s.name.toLowerCase().includes(q))
|
|
483
|
-
.slice(0, 20)
|
|
484
|
-
.map((s) => ({
|
|
485
|
-
value: `${parts[0]} ${s.key}`,
|
|
486
|
-
label: s.key,
|
|
487
|
-
}));
|
|
488
|
-
}
|
|
489
|
-
return null;
|
|
490
|
-
},
|
|
491
|
-
handler: async (args, ctx) => {
|
|
492
|
-
const trimmed = args.trim();
|
|
493
|
-
if (!trimmed && ctx.hasUI) {
|
|
494
|
-
while (true) {
|
|
495
|
-
const managed_count = mgr.discover().length;
|
|
496
|
-
const importable_count = mgr.discover_importable().length;
|
|
497
|
-
const selected = await show_skills_home_modal(ctx, managed_count, importable_count);
|
|
498
|
-
if (!selected)
|
|
499
|
-
return;
|
|
500
|
-
if (selected === 'manage') {
|
|
501
|
-
if (await show_skills_manager_modal(ctx, mgr))
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
else if (selected === 'browse') {
|
|
505
|
-
await show_skill_list_modal(ctx, mgr);
|
|
506
|
-
}
|
|
507
|
-
else if (selected === 'import') {
|
|
508
|
-
const key = await pick_skill(ctx, {
|
|
509
|
-
title: 'Import skill',
|
|
510
|
-
subtitle: 'Copy an external skill into Pi-native storage',
|
|
511
|
-
skills: sort_skills(mgr.discover_importable()),
|
|
512
|
-
empty_message: 'No importable skills found',
|
|
513
|
-
});
|
|
514
|
-
if (!key)
|
|
515
|
-
continue;
|
|
516
|
-
try {
|
|
517
|
-
const result = mgr.import_skill(key);
|
|
518
|
-
ctx.ui.notify(`Imported ${key} to ${result.skillDir}. Reloading...`, 'info');
|
|
519
|
-
await ctx.reload();
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
catch (error) {
|
|
523
|
-
ctx.ui.notify(error instanceof Error
|
|
524
|
-
? error.message
|
|
525
|
-
: String(error), 'warning');
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
else if (selected === 'sync') {
|
|
529
|
-
const key = await pick_skill(ctx, {
|
|
530
|
-
title: 'Sync imported skill',
|
|
531
|
-
subtitle: 'Update an imported skill from its upstream source',
|
|
532
|
-
skills: sort_skills(mgr
|
|
533
|
-
.discover()
|
|
534
|
-
.filter((skill) => Boolean(skill.import_meta))),
|
|
535
|
-
empty_message: 'No imported skills found',
|
|
536
|
-
});
|
|
537
|
-
if (!key)
|
|
538
|
-
continue;
|
|
539
|
-
try {
|
|
540
|
-
const result = mgr.sync_skill(key);
|
|
541
|
-
if (result.changed) {
|
|
542
|
-
ctx.ui.notify(`Synced ${key}. Reloading...`, 'info');
|
|
543
|
-
await ctx.reload();
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
await show_text_modal(ctx, {
|
|
547
|
-
title: 'Skill already up to date',
|
|
548
|
-
text: `${key} is already up to date.`,
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
catch (error) {
|
|
552
|
-
ctx.ui.notify(error instanceof Error
|
|
553
|
-
? error.message
|
|
554
|
-
: String(error), 'warning');
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
else if (selected === 'refresh') {
|
|
558
|
-
await show_refresh_summary(ctx, mgr);
|
|
559
|
-
}
|
|
560
|
-
else if (selected === 'defaults') {
|
|
561
|
-
await show_defaults_modal(ctx, mgr);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
const [sub, ...rest] = (trimmed || 'list').split(/\s+/);
|
|
566
|
-
const arg = rest.join(' ');
|
|
567
|
-
switch (sub) {
|
|
568
|
-
case 'list': {
|
|
569
|
-
const skills = [
|
|
570
|
-
...mgr.discover(),
|
|
571
|
-
...mgr.discover_importable(),
|
|
572
|
-
];
|
|
573
|
-
if (ctx.hasUI) {
|
|
574
|
-
await show_skill_list_modal(ctx, mgr);
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
ctx.ui.notify(format_skill_list(skills));
|
|
578
|
-
}
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
case 'show': {
|
|
582
|
-
const skills = [
|
|
583
|
-
...mgr.discover(),
|
|
584
|
-
...mgr.discover_importable(),
|
|
585
|
-
];
|
|
586
|
-
let target = arg;
|
|
587
|
-
if (!target && ctx.hasUI) {
|
|
588
|
-
target =
|
|
589
|
-
(await pick_skill(ctx, {
|
|
590
|
-
title: 'Show skill details',
|
|
591
|
-
subtitle: 'Open a read-only skill detail view',
|
|
592
|
-
skills: sort_skills(skills),
|
|
593
|
-
empty_message: 'No skills found',
|
|
594
|
-
})) ?? '';
|
|
595
|
-
if (!target)
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
if (!target) {
|
|
599
|
-
ctx.ui.notify('Usage: /skills show <key|name>', 'warning');
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
try {
|
|
603
|
-
const skill = find_skill(skills, target);
|
|
604
|
-
if (ctx.hasUI) {
|
|
605
|
-
await show_skill_detail_modal(ctx, skill);
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
ctx.ui.notify(format_skill_detail(skill));
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
catch (error) {
|
|
612
|
-
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'warning');
|
|
613
|
-
}
|
|
614
|
-
break;
|
|
615
|
-
}
|
|
616
|
-
case 'import': {
|
|
617
|
-
let target = arg;
|
|
618
|
-
if (!target && ctx.hasUI) {
|
|
619
|
-
target =
|
|
620
|
-
(await pick_skill(ctx, {
|
|
621
|
-
title: 'Import skill',
|
|
622
|
-
subtitle: 'Copy an external skill into Pi-native storage',
|
|
623
|
-
skills: sort_skills(mgr.discover_importable()),
|
|
624
|
-
empty_message: 'No importable skills found',
|
|
625
|
-
})) ?? '';
|
|
626
|
-
if (!target)
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
if (!target) {
|
|
630
|
-
ctx.ui.notify('Usage: /skills import <key|name>', 'warning');
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
try {
|
|
634
|
-
const result = mgr.import_skill(target);
|
|
635
|
-
ctx.ui.notify(`Imported ${target} to ${result.skillDir}. Reloading...`, 'info');
|
|
636
|
-
await ctx.reload();
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
catch (error) {
|
|
640
|
-
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'warning');
|
|
641
|
-
return;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
case 'sync': {
|
|
645
|
-
let target = arg;
|
|
646
|
-
if (!target && ctx.hasUI) {
|
|
647
|
-
target =
|
|
648
|
-
(await pick_skill(ctx, {
|
|
649
|
-
title: 'Sync imported skill',
|
|
650
|
-
subtitle: 'Update an imported skill from its upstream source',
|
|
651
|
-
skills: sort_skills(mgr
|
|
652
|
-
.discover()
|
|
653
|
-
.filter((skill) => Boolean(skill.import_meta))),
|
|
654
|
-
empty_message: 'No imported skills found',
|
|
655
|
-
})) ?? '';
|
|
656
|
-
if (!target)
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
if (!target) {
|
|
660
|
-
ctx.ui.notify('Usage: /skills sync <key|name>', 'warning');
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
try {
|
|
664
|
-
const result = mgr.sync_skill(target);
|
|
665
|
-
if (result.changed) {
|
|
666
|
-
ctx.ui.notify(`Synced ${target}. Reloading...`, 'info');
|
|
667
|
-
await ctx.reload();
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
if (ctx.hasUI) {
|
|
671
|
-
await show_text_modal(ctx, {
|
|
672
|
-
title: 'Skill already up to date',
|
|
673
|
-
text: `${target} is already up to date.`,
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
ctx.ui.notify(`${target} is already up to date.`, 'info');
|
|
678
|
-
}
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
catch (error) {
|
|
682
|
-
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'warning');
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
case 'refresh': {
|
|
687
|
-
if (ctx.hasUI) {
|
|
688
|
-
await show_refresh_summary(ctx, mgr);
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
mgr.refresh();
|
|
692
|
-
ctx.ui.notify(`Rescanned: ${mgr.discover().length} managed skills, ${mgr.discover_importable().length} importable skills found`);
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
case 'defaults': {
|
|
696
|
-
if (!arg && ctx.hasUI) {
|
|
697
|
-
await show_defaults_modal(ctx, mgr);
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
if (arg !== 'all-enabled' && arg !== 'all-disabled') {
|
|
701
|
-
ctx.ui.notify('Usage: /skills defaults <all-enabled|all-disabled>', 'warning');
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
mgr.set_defaults(arg);
|
|
705
|
-
if (ctx.hasUI) {
|
|
706
|
-
await show_text_modal(ctx, {
|
|
707
|
-
title: 'Skill defaults updated',
|
|
708
|
-
text: `Default policy: ${arg}`,
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
ctx.ui.notify(`Default policy: ${arg}`);
|
|
713
|
-
}
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
default:
|
|
717
|
-
ctx.ui.notify(`Unknown: ${sub}. Use: ${subs.join(', ')}`, 'warning');
|
|
718
|
-
}
|
|
719
|
-
},
|
|
720
|
-
});
|
|
721
|
-
}
|
|
2
|
+
export { default } from './commands.js';
|
|
722
3
|
//# sourceMappingURL=index.js.map
|